aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/Game
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin/Game')
-rw-r--r--src/libjin/Game/Game.cpp112
-rw-r--r--src/libjin/Game/Game.h74
2 files changed, 93 insertions, 93 deletions
diff --git a/src/libjin/Game/Game.cpp b/src/libjin/Game/Game.cpp
index 65baaaa..82597b7 100644
--- a/src/libjin/Game/Game.cpp
+++ b/src/libjin/Game/Game.cpp
@@ -7,66 +7,66 @@
namespace jin
{
-namespace core
-{
+ namespace core
+ {
- using namespace jin::graphics;
- using namespace jin::input;
- using namespace jin::time;
- using namespace jin::math;
+ using namespace jin::graphics;
+ using namespace jin::input;
+ using namespace jin::time;
+ using namespace jin::math;
- Game::Game() :_running(true) {};
+ Game::Game() :_running(true) {};
- /* default game loop */
- void Game::run()
- {
- if (_onLoad != nullptr)
- _onLoad();
- Window* wnd = Window::get();
- const int FPS = wnd ? wnd->getFPS() : 60;
- const int MS_PER_UPDATE = 1000.0f / FPS;
- _running = true;
- Event e;
- int current = getMilliSecond();
- int previous = current;
- int dt = 0;
- while (_running)
- {
- while (jin::input::pollEvent(&e))
- {
- if (_onEvent != nullptr)
- _onEvent(&e);
- if (!_running)
- goto quitloop;
- }
- previous = current;
- current = getMilliSecond();
- dt = current - previous;
- if (_onUpdate != nullptr)
- _onUpdate(dt);
- if (_onDraw != nullptr)
- _onDraw();
- wnd->swapBuffers();
- sleep(1);
- }
- quitloop:;
- }
+ /* default game loop */
+ void Game::run()
+ {
+ if (_onLoad != nullptr)
+ _onLoad();
+ Window* wnd = Window::get();
+ const int FPS = wnd ? wnd->getFPS() : 60;
+ const int MS_PER_UPDATE = 1000.0f / FPS;
+ _running = true;
+ Event e;
+ int current = getMilliSecond();
+ int previous = current;
+ int dt = 0;
+ while (_running)
+ {
+ while (jin::input::pollEvent(&e))
+ {
+ if (_onEvent != nullptr)
+ _onEvent(&e);
+ if (!_running)
+ goto quitloop;
+ }
+ previous = current;
+ current = getMilliSecond();
+ dt = current - previous;
+ if (_onUpdate != nullptr)
+ _onUpdate(dt);
+ if (_onDraw != nullptr)
+ _onDraw();
+ wnd->swapBuffers();
+ sleep(1);
+ }
+ quitloop:;
+ }
- bool Game::initSystem(const SettingBase* setting)
- {
- if (setting == nullptr)
- return false;
- Game::Setting* s = (Game::Setting*) setting;
- _onEvent = s->eventHandler;
- _onUpdate = s->updater;
- _onDraw = s->drawer;
- _onLoad = s->loader;
- return true;
- }
+ bool Game::initSystem(const SettingBase* setting)
+ {
+ if (setting == nullptr)
+ return false;
+ Game::Setting* s = (Game::Setting*) setting;
+ _onEvent = s->eventHandler;
+ _onUpdate = s->updater;
+ _onDraw = s->drawer;
+ _onLoad = s->loader;
+ return true;
+ }
- void Game::quitSystem()
- {
- }
+ void Game::quitSystem()
+ {
+ }
-} // core
+ } // core
} // jin \ No newline at end of file
diff --git a/src/libjin/Game/Game.h b/src/libjin/Game/Game.h
index 725c62c..ede2418 100644
--- a/src/libjin/Game/Game.h
+++ b/src/libjin/Game/Game.h
@@ -9,50 +9,50 @@
namespace jin
{
-namespace core
-{
-
- class Game : public Subsystem<Game>
- {
- public:
-
- typedef void(*onLoad)();
- typedef void(*onEvent)(jin::input::Event* e);
- typedef void(*onUpdate)(int dt);
- typedef void(*onDraw)();
-
- struct Setting : SettingBase
- {
- onEvent eventHandler;
- onUpdate updater;
- onDraw drawer;
- onLoad loader;
- };
-
- void run();
- inline void stop() { _running = false; };
- inline bool running() { return _running; };
-
- private:
+ namespace core
+ {
+
+ class Game : public Subsystem<Game>
+ {
+ public:
+
+ typedef void(*onLoad)();
+ typedef void(*onEvent)(jin::input::Event* e);
+ typedef void(*onUpdate)(int dt);
+ typedef void(*onDraw)();
+
+ struct Setting : SettingBase
+ {
+ onEvent eventHandler;
+ onUpdate updater;
+ onDraw drawer;
+ onLoad loader;
+ };
+
+ void run();
+ inline void stop() { _running = false; };
+ inline bool running() { return _running; };
+
+ private:
- Game();
- ~Game() {};
+ Game();
+ ~Game() {};
- SINGLETON(Game);
+ SINGLETON(Game);
- onEvent _onEvent;
- onUpdate _onUpdate;
- onDraw _onDraw;
- onLoad _onLoad;
+ onEvent _onEvent;
+ onUpdate _onUpdate;
+ onDraw _onDraw;
+ onLoad _onLoad;
- bool _running;
+ bool _running;
- bool initSystem(const SettingBase* setting);
- void quitSystem();
+ bool initSystem(const SettingBase* setting);
+ void quitSystem();
- };
+ };
-} // core
+ } // core
} // jin
#endif // __LIBJIN_CORE_GAME_H