Moved BaseScene::ProcessEvents() to Application::ProcessEvents()

This is so that events can interact with the window more easily (i.e.
logical resizing).
This commit is contained in:
2015-07-20 14:19:14 +10:00
parent 69aee157b8
commit 13ae560e28
4 changed files with 48 additions and 53 deletions
+42 -1
View File
@@ -94,7 +94,11 @@ void Application::Proc() {
if (simTime < realTime) { if (simTime < realTime) {
while(simTime < realTime) { while(simTime < realTime) {
//call the user defined functions //call the user defined functions
activeScene->RunFrame(); activeScene->FrameStart();
ProcessEvents();
activeScene->Update();
activeScene->FrameEnd();
//step to the next frame //step to the next frame
simTime += frameDelay; simTime += frameDelay;
} }
@@ -125,6 +129,43 @@ void Application::Quit() {
//Scene management //Scene management
//------------------------- //-------------------------
void Application::ProcessEvents() {
SDL_Event event;
while(SDL_PollEvent(&event)) {
switch(event.type) {
case SDL_QUIT:
activeScene->QuitEvent();
break;
case SDL_MOUSEMOTION:
activeScene->MouseMotion(event.motion);
break;
case SDL_MOUSEBUTTONDOWN:
activeScene->MouseButtonDown(event.button);
break;
case SDL_MOUSEBUTTONUP:
activeScene->MouseButtonUp(event.button);
break;
case SDL_MOUSEWHEEL:
activeScene->MouseWheel(event.wheel);
break;
case SDL_KEYDOWN:
activeScene->KeyDown(event.key);
break;
case SDL_KEYUP:
activeScene->KeyUp(event.key);
break;
//TODO: joystick and controller events
}
}
}
//Add the custom scene headers here //Add the custom scene headers here
#include "example_scene.hpp" #include "example_scene.hpp"
+1
View File
@@ -43,6 +43,7 @@ public:
private: private:
//scene management //scene management
void ProcessEvents();
void ProcessSceneSignal(SceneSignal); void ProcessSceneSignal(SceneSignal);
void ClearScene(); void ClearScene();
-44
View File
@@ -31,13 +31,6 @@ BaseScene::~BaseScene() {
//EMPTY //EMPTY
} }
void BaseScene::RunFrame() {
FrameStart();
ProcessEvents();
Update();
FrameEnd();
}
void BaseScene::RenderFrame(SDL_Renderer* renderer) { void BaseScene::RenderFrame(SDL_Renderer* renderer) {
//EMPTY //EMPTY
} }
@@ -66,43 +59,6 @@ void BaseScene::FrameStart() {
//EMPTY //EMPTY
} }
void BaseScene::ProcessEvents() {
SDL_Event event;
while(SDL_PollEvent(&event)) {
switch(event.type) {
case SDL_QUIT:
QuitEvent();
break;
case SDL_MOUSEMOTION:
MouseMotion(event.motion);
break;
case SDL_MOUSEBUTTONDOWN:
MouseButtonDown(event.button);
break;
case SDL_MOUSEBUTTONUP:
MouseButtonUp(event.button);
break;
case SDL_MOUSEWHEEL:
MouseWheel(event.wheel);
break;
case SDL_KEYDOWN:
KeyDown(event.key);
break;
case SDL_KEYUP:
KeyUp(event.key);
break;
//TODO: joystick and controller events
}
}
}
void BaseScene::Update() { void BaseScene::Update() {
//EMPTY //EMPTY
} }
+5 -8
View File
@@ -30,20 +30,12 @@ public:
BaseScene(); BaseScene();
virtual ~BaseScene(); virtual ~BaseScene();
virtual void RunFrame();
virtual void RenderFrame(SDL_Renderer*); virtual void RenderFrame(SDL_Renderer*);
static void SetRenderer(SDL_Renderer*); static void SetRenderer(SDL_Renderer*);
SceneSignal GetSceneSignal(); SceneSignal GetSceneSignal();
protected:
//control
static SDL_Renderer* GetRenderer();
void SetSceneSignal(SceneSignal);
//frame phases //frame phases
virtual void FrameStart(); virtual void FrameStart();
virtual void ProcessEvents();
virtual void Update(); virtual void Update();
virtual void FrameEnd(); virtual void FrameEnd();
@@ -58,6 +50,11 @@ protected:
//TODO: joystick and controller events //TODO: joystick and controller events
protected:
//control
static SDL_Renderer* GetRenderer();
void SetSceneSignal(SceneSignal);
private: private:
static SDL_Renderer* rendererHandle; static SDL_Renderer* rendererHandle;
SceneSignal sceneSignal = SceneSignal::CONTINUE; SceneSignal sceneSignal = SceneSignal::CONTINUE;