aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/game
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin/game')
-rw-r--r--src/libjin/game/je_application.cpp104
-rw-r--r--src/libjin/game/je_application.h58
2 files changed, 81 insertions, 81 deletions
diff --git a/src/libjin/game/je_application.cpp b/src/libjin/game/je_application.cpp
index 1a3c5ed..19a74a0 100644
--- a/src/libjin/game/je_application.cpp
+++ b/src/libjin/game/je_application.cpp
@@ -18,64 +18,64 @@ using namespace JinEngine::Math;
namespace JinEngine
{
- namespace Game
- {
+ namespace Game
+ {
- Application::Application() :_running(true) {};
+ Application::Application() :_running(true) {};
- /* default game loop */
- void Application::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 (JinEngine::Input::pollEvent(&e))
- {
- if (_onEvent != nullptr)
- _onEvent(&e);
- if (!_running)
- goto quitloop;
- }
- previous = current;
- current = getMilliSecond();
- dt = current - previous;
- if (_onUpdate != nullptr)
- _onUpdate(dt);
+ /* default game loop */
+ void Application::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 (JinEngine::Input::pollEvent(&e))
+ {
+ if (_onEvent != nullptr)
+ _onEvent(&e);
+ if (!_running)
+ goto quitloop;
+ }
+ previous = current;
+ current = getMilliSecond();
+ dt = current - previous;
+ if (_onUpdate != nullptr)
+ _onUpdate(dt);
glClear(GL_COLOR_BUFFER_BIT);
- if (_onDraw != nullptr)
- _onDraw();
- wnd->swapBuffers();
- sleep(16);
- }
- quitloop:;
- }
+ if (_onDraw != nullptr)
+ _onDraw();
+ wnd->swapBuffers();
+ sleep(16);
+ }
+ quitloop:;
+ }
- bool Application::startSystem(const SettingBase* setting)
- {
- if (setting == nullptr)
- return false;
- Application::Setting* s = (Application::Setting*) setting;
- _onEvent = s->eventHandler;
- _onUpdate = s->updater;
- _onDraw = s->drawer;
- _onLoad = s->loader;
- return true;
- }
+ bool Application::startSystem(const SettingBase* setting)
+ {
+ if (setting == nullptr)
+ return false;
+ Application::Setting* s = (Application::Setting*) setting;
+ _onEvent = s->eventHandler;
+ _onUpdate = s->updater;
+ _onDraw = s->drawer;
+ _onLoad = s->loader;
+ return true;
+ }
- void Application::quitSystem()
- {
- }
+ void Application::quitSystem()
+ {
+ }
- } // namespace Core
+ } // namespace Core
} // namespace JinEngine
#endif // jin_game \ No newline at end of file
diff --git a/src/libjin/game/je_application.h b/src/libjin/game/je_application.h
index 9de6e1c..6eb8af2 100644
--- a/src/libjin/game/je_application.h
+++ b/src/libjin/game/je_application.h
@@ -12,19 +12,19 @@
namespace JinEngine
{
- namespace Game
- {
+ namespace Game
+ {
///
/// Game class.
///
- class Application : public Subsystem<Application>
- {
- public:
- typedef void(*onLoad)();
- typedef void(*onEvent)(JinEngine::Input::Event* e);
- typedef void(*onUpdate)(int dt);
- typedef void(*onDraw)();
+ class Application : public Subsystem<Application>
+ {
+ public:
+ typedef void(*onLoad)();
+ typedef void(*onEvent)(JinEngine::Input::Event* e);
+ typedef void(*onUpdate)(int dt);
+ typedef void(*onDraw)();
Application();
~Application() {};
@@ -32,23 +32,23 @@ namespace JinEngine
///
/// Game setting.
///
- struct Setting : SettingBase
- {
- onEvent eventHandler;
- onUpdate updater;
- onDraw drawer;
- onLoad loader;
- };
+ struct Setting : SettingBase
+ {
+ onEvent eventHandler;
+ onUpdate updater;
+ onDraw drawer;
+ onLoad loader;
+ };
///
/// Main game loop.
///
- void run();
+ void run();
///
/// Stop game.
///
- inline void stop()
+ inline void stop()
{
_running = false;
};
@@ -58,25 +58,25 @@ namespace JinEngine
///
/// @return True if game is running, otherwise return false.
///
- inline bool running()
+ inline bool running()
{
return _running;
};
- private:
- onEvent _onEvent;
- onUpdate _onUpdate;
- onDraw _onDraw;
- onLoad _onLoad;
+ private:
+ onEvent _onEvent;
+ onUpdate _onUpdate;
+ onDraw _onDraw;
+ onLoad _onLoad;
- bool _running;
+ bool _running;
- bool startSystem(const SettingBase* setting);
- void quitSystem();
+ bool startSystem(const SettingBase* setting);
+ void quitSystem();
- };
+ };
- } // namespace Core
+ } // namespace Core
} // namespace JinEngine
#endif // jin_game