1 #include "Application.hpp"
10 Application::Application()
14 Application::~Application() {
18 void Application::PushState(State *s) {
19 if (!states.empty()) {
20 states.top()->OnPause();
24 if (s->ref_count == 1) {
30 State *Application::PopState() {
31 State *s = states.top();
35 if (!states.empty()) {
36 states.top()->OnResume();
41 State *Application::SwitchState(State *s_new) {
42 State *s_old = states.top();
47 if (s_old->ref_count == 0) {
50 if (s_new->ref_count == 1) {
57 State &Application::GetState() {
61 bool Application::HasState() const noexcept {
62 return !states.empty();
66 void Application::Run() {
67 Uint32 last = SDL_GetTicks();
69 Uint32 now = SDL_GetTicks();
70 int delta = now - last;
76 void Application::Loop(int dt) {
78 if (!HasState()) return;
79 GetState().Update(dt);
80 if (!HasState()) return;
84 void Application::HandleEvents() {
86 while (HasState() && SDL_PollEvent(&event)) {
87 GetState().Handle(event);
91 void State::Handle(const SDL_Event &event) {
102 void State::Handle(const SDL_WindowEvent &event) {
103 switch (event.event) {
104 case SDL_WINDOWEVENT_FOCUS_GAINED:
107 case SDL_WINDOWEVENT_FOCUS_LOST:
110 case SDL_WINDOWEVENT_RESIZED:
111 //env.viewport.Resize(event.data1, event.data2);
119 void State::Update(int dt) {
123 void State::Render() {