graceful shutdown

This commit is contained in:
Anthony Pesch 2016-01-17 23:58:51 -08:00
parent 6c72c2a3ba
commit 19a188d9c2
4 changed files with 16 additions and 6 deletions

View File

@ -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;
}
}
}

View File

@ -36,6 +36,7 @@ class Emulator {
trace::TraceWriter *trace_writer_;
std::chrono::nanoseconds deltas_[MAX_SCHEDULER_DELTAS];
unsigned delta_seq_;
bool running_;
};
}
}

View File

@ -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;
}
}

View File

@ -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;
};
};