@@ -74,128 +74,127 @@ int main(int argc, char *argv[]) {
74
74
PANIC (" error while reading history file: %s\n " , std::strerror (err));
75
75
}
76
76
77
- Emulator emulator (argv_map);
78
- m_emu = &emulator;
79
-
80
- // Note: argv_map must be destructed after emulator.
81
-
82
- // Used to signal to the console input thread when to stop.
83
- static std::atomic<bool > running (true );
84
- std::atomic<bool > got_input (false );
85
-
86
- test_gui ();
87
- std::thread console_input_thread ([&] {
88
- while (1 ) {
89
- char *console_input_c_str;
90
- std::thread readline_thread ([&] {
91
- got_input = false ;
92
- console_input_c_str = readline (" > " );
93
- got_input = true ;
94
- });
95
- readline_thread.detach ();
96
-
97
- while (!got_input)
98
- if (!running)
77
+ {
78
+ Emulator emulator (argv_map);
79
+ m_emu = &emulator;
80
+
81
+ // Note: argv_map must be destructed after emulator.
82
+
83
+ // Used to signal to the console input thread when to stop.
84
+ static std::atomic<bool > running (true );
85
+
86
+ test_gui ();
87
+ std::thread console_input_thread ([&] {
88
+ while (1 ) {
89
+ char *console_input_c_str;
90
+ bool got = false ;
91
+ std::thread readline_thread ([&] {
92
+ console_input_c_str = readline (" > " );
93
+ got = true ;
94
+ });
95
+ readline_thread.detach ();
96
+
97
+ while (!got)
98
+ if (!running)
99
+ return ;
100
+
101
+ if (console_input_c_str == NULL ) {
102
+ if (argv_map.find (" exit_on_console_shutdown" ) != argv_map.end ()) {
103
+ SDL_Event event;
104
+ SDL_zero (event);
105
+ event.type = SDL_WINDOWEVENT;
106
+ event.window .event = SDL_WINDOWEVENT_CLOSE;
107
+ SDL_PushEvent (&event);
108
+ } else {
109
+ logger::Info (" Console thread shutting down\n " );
110
+ }
99
111
return ;
112
+ }
113
+
114
+ // Ignore empty lines.
115
+ if (console_input_c_str[0 ] == 0 )
116
+ continue ;
117
+
118
+ add_history (console_input_c_str);
119
+
120
+ std::lock_guard<decltype (emulator.access_mx )> access_lock (emulator.access_mx );
121
+ if (!emulator.Running ())
122
+ return ;
123
+ emulator.ExecuteCommand (console_input_c_str);
124
+ free (console_input_c_str);
100
125
101
- if (console_input_c_str == NULL ) {
102
- if (argv_map.find (" exit_on_console_shutdown" ) != argv_map.end ()) {
126
+ if (!emulator.Running ()) {
103
127
SDL_Event event;
104
128
SDL_zero (event);
105
- event.type = SDL_WINDOWEVENT ;
106
- event.window . event = SDL_WINDOWEVENT_CLOSE ;
129
+ event.type = SDL_USEREVENT ;
130
+ event.user . code = CE_EMU_STOPPED ;
107
131
SDL_PushEvent (&event);
108
- } else {
109
- logger::Info (" Console thread shutting down\n " );
132
+ return ;
110
133
}
111
- return ;
112
134
}
135
+ });
136
+ std::thread t1 ([&]() {
137
+ while (1 ) {
138
+ gui_loop ();
139
+ }
140
+ });
141
+ t1.detach ();
113
142
114
- // Ignore empty lines.
115
- if (console_input_c_str[0 ] == 0 )
143
+ while (emulator.Running ()) {
144
+ SDL_Event event;
145
+ if (!SDL_PollEvent (&event))
116
146
continue ;
117
147
118
- add_history (console_input_c_str);
119
-
120
- std::lock_guard<decltype (emulator.access_mx )> access_lock (emulator.access_mx );
121
- if (!emulator.Running ())
122
- return ;
123
- emulator.ExecuteCommand (console_input_c_str);
124
- free (console_input_c_str);
125
-
126
- if (!emulator.Running ()) {
127
- SDL_Event event;
128
- SDL_zero (event);
129
- event.type = SDL_USEREVENT;
130
- event.user .code = CE_EMU_STOPPED;
131
- SDL_PushEvent (&event);
132
- return ;
133
- }
134
- }
135
- });
136
- std::thread t1 ([&]() {
137
- while (1 ) {
138
- gui_loop ();
139
- }
140
- });
141
- t1.detach ();
142
-
143
- while (emulator.Running ()) {
144
- SDL_Event event;
145
- if (!SDL_PollEvent (&event))
146
- continue ;
147
-
148
- switch (event.type ) {
149
- case SDL_USEREVENT:
150
- switch (event.user .code ) {
151
- case CE_FRAME_REQUEST:
152
- emulator.Frame ();
153
- break ;
154
- case CE_EMU_STOPPED:
155
- if (emulator.Running ())
156
- PANIC (" CE_EMU_STOPPED event received while emulator is still running\n " );
148
+ switch (event.type ) {
149
+ case SDL_USEREVENT:
150
+ switch (event.user .code ) {
151
+ case CE_FRAME_REQUEST:
152
+ emulator.Frame ();
153
+ break ;
154
+ case CE_EMU_STOPPED:
155
+ if (emulator.Running ())
156
+ PANIC (" CE_EMU_STOPPED event received while emulator is still running\n " );
157
+ break ;
158
+ }
157
159
break ;
158
- }
159
- break ;
160
160
161
- case SDL_WINDOWEVENT:
162
- switch (event.window .event ) {
163
- case SDL_WINDOWEVENT_CLOSE:
164
- emulator.Shutdown ();
165
- break ;
166
- case SDL_WINDOWEVENT_RESIZED:
167
- if (event.window .windowID == SDL_GetWindowID (emulator.window )) {
168
- emulator.WindowResize (event.window .data1 , event.window .data2 );
161
+ case SDL_WINDOWEVENT:
162
+ switch (event.window .event ) {
163
+ case SDL_WINDOWEVENT_CLOSE:
164
+ emulator.Shutdown ();
165
+ break ;
166
+ case SDL_WINDOWEVENT_RESIZED:
167
+ if (event.window .windowID == SDL_GetWindowID (emulator.window )) {
168
+ emulator.WindowResize (event.window .data1 , event.window .data2 );
169
+ }
170
+ break ;
171
+ case SDL_WINDOWEVENT_EXPOSED:
172
+ emulator.Repaint ();
173
+ break ;
169
174
}
170
175
break ;
171
- case SDL_WINDOWEVENT_EXPOSED:
172
- emulator.Repaint ();
173
- break ;
174
- }
175
- break ;
176
-
177
- case SDL_MOUSEBUTTONDOWN:
178
- case SDL_MOUSEBUTTONUP:
179
- case SDL_KEYDOWN:
180
- case SDL_KEYUP:
181
- case SDL_TEXTINPUT:
182
- case SDL_MOUSEMOTION:
183
- case SDL_MOUSEWHEEL:
184
- if (SDL_GetKeyboardFocus () != emulator.window || SDL_GetMouseFocus () != emulator.window ) {
185
- ImGui_ImplSDL2_ProcessEvent (&event);
176
+
177
+ case SDL_MOUSEBUTTONDOWN:
178
+ case SDL_MOUSEBUTTONUP:
179
+ case SDL_KEYDOWN:
180
+ case SDL_KEYUP:
181
+ case SDL_TEXTINPUT:
182
+ case SDL_MOUSEMOTION:
183
+ case SDL_MOUSEWHEEL:
184
+ if (SDL_GetKeyboardFocus () != emulator.window || SDL_GetMouseFocus () != emulator.window ) {
185
+ ImGui_ImplSDL2_ProcessEvent (&event);
186
+ break ;
187
+ }
188
+ emulator.UIEvent (event);
186
189
break ;
187
190
}
188
- emulator.UIEvent (event);
189
- break ;
190
191
}
191
- }
192
192
193
- running = false ;
194
- console_input_thread.join ();
193
+ running = false ;
194
+ console_input_thread.join ();
195
+ }
195
196
196
- if (!got_input)
197
- std::cout << std::endl;
198
- std::cout << " Goodbye" << std::endl;
197
+ std::cout << " \n Goodbye" << std::endl;
199
198
200
199
IMG_Quit ();
201
200
SDL_Quit ();
0 commit comments