mirror of https://github.com/inolen/redream.git
graceful shutdown
This commit is contained in:
parent
6c72c2a3ba
commit
19a188d9c2
|
@ -76,7 +76,9 @@ void Emulator::Run(const char *path) {
|
|||
auto scheduler_remaining = std::chrono::nanoseconds(0);
|
||||
auto frame_remaining = std::chrono::nanoseconds(0);
|
||||
|
||||
while (true) {
|
||||
running_ = true;
|
||||
|
||||
while (running_) {
|
||||
current_time = std::chrono::high_resolution_clock::now();
|
||||
delta_time = current_time - last_time;
|
||||
last_time = current_time;
|
||||
|
@ -231,6 +233,10 @@ void Emulator::PumpEvents() {
|
|||
case WE_RESIZE: {
|
||||
rb_->ResizeVideo(ev.resize.width, ev.resize.height);
|
||||
} break;
|
||||
|
||||
case WE_QUIT: {
|
||||
running_ = false;
|
||||
} break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ class Emulator {
|
|||
trace::TraceWriter *trace_writer_;
|
||||
std::chrono::nanoseconds deltas_[MAX_SCHEDULER_DELTAS];
|
||||
unsigned delta_seq_;
|
||||
bool running_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,12 @@ static inline WindowEvent MakeResizeEvent(int width, int height) {
|
|||
return ev;
|
||||
}
|
||||
|
||||
static inline WindowEvent MakeQuitEvent() {
|
||||
WindowEvent ev;
|
||||
ev.type = WE_QUIT;
|
||||
return ev;
|
||||
}
|
||||
|
||||
Window::Window()
|
||||
: window_(nullptr),
|
||||
width_(DEFAULT_WIDTH),
|
||||
|
@ -736,7 +742,7 @@ void Window::PumpSDLEvents() {
|
|||
break;
|
||||
|
||||
case SDL_QUIT:
|
||||
exit(EXIT_SUCCESS);
|
||||
QueueEvent(MakeQuitEvent());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ enum WindowEventType {
|
|||
WE_KEY,
|
||||
WE_MOUSEMOVE,
|
||||
WE_RESIZE,
|
||||
WE_QUIT,
|
||||
};
|
||||
|
||||
struct WindowEvent {
|
||||
|
@ -36,10 +37,6 @@ struct WindowEvent {
|
|||
int width;
|
||||
int height;
|
||||
} resize;
|
||||
|
||||
struct {
|
||||
const char *buffer;
|
||||
} tty;
|
||||
};
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue