diff options
Diffstat (limited to 'src/libjin/core')
-rw-r--r-- | src/libjin/core/core.h | 6 | ||||
-rw-r--r-- | src/libjin/core/game.cpp | 72 | ||||
-rw-r--r-- | src/libjin/core/game.h | 58 |
3 files changed, 0 insertions, 136 deletions
diff --git a/src/libjin/core/core.h b/src/libjin/core/core.h deleted file mode 100644 index dd902b4..0000000 --- a/src/libjin/core/core.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef __JIN_CORE_H -#define __JIN_CORE_H - -#include "game.h" - -#endif
\ No newline at end of file diff --git a/src/libjin/core/game.cpp b/src/libjin/core/game.cpp deleted file mode 100644 index b480b12..0000000 --- a/src/libjin/core/game.cpp +++ /dev/null @@ -1,72 +0,0 @@ -#include "game.h" -#include "../Time/Timer.h" -#include "../input/Event.h" -#include "../Graphics/Window.h" -#include "../Math/Math.h" -#include <iostream> - -namespace jin -{ -namespace core -{ - - using namespace jin::graphics; - using namespace jin::input; - using namespace jin::time; - using namespace jin::math; - - Game::Game() :_running(true) {}; - - void Game::run() - { - SAFECALL(_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 previous = getMilliSecond(); - int dt = MS_PER_UPDATE; - while (_running) - { - while (jin::input::pollEvent(&e)) - { - SAFECALL(_onEvent, &e); - if (!_running) goto quitloop; - } - SAFECALL(_onUpdate, dt); - SAFECALL(_onDraw); - wnd->swapBuffers(); - const int current = getMilliSecond(); - dt = current - previous; - const int wait = MS_PER_UPDATE - (current - previous); - previous += MS_PER_UPDATE; - if (wait > 0) - { - sleep(wait); - dt = MS_PER_UPDATE; - } - else - previous = current; - } - 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; - } - - void Game::quitSystem() - { - } - -} // core -} // jin
\ No newline at end of file diff --git a/src/libjin/core/game.h b/src/libjin/core/game.h deleted file mode 100644 index 31f32d8..0000000 --- a/src/libjin/core/game.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef __JIN_CORE_GAME_H -#define __JIN_CORE_GAME_H - -#include "SDL2/SDL.h" - -#include "../Common/Subsystem.hpp" -#include "../utils/macros.h" -#include "../Input/Event.h" - -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: - - Game(); - ~Game() {}; - - SINGLETON(Game); - - onEvent _onEvent; - onUpdate _onUpdate; - onDraw _onDraw; - onLoad _onLoad; - - bool _running; - - bool initSystem(const SettingBase* setting); - void quitSystem(); - - }; - -} // core -} // jin - -#endif // __JIN_CORE_GAME_H
\ No newline at end of file |