aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin/core')
-rw-r--r--src/libjin/core/game.cpp37
-rw-r--r--src/libjin/core/game.h58
-rw-r--r--src/libjin/core/thread.cpp0
-rw-r--r--src/libjin/core/thread.h1
-rw-r--r--src/libjin/core/timer.cpp0
-rw-r--r--src/libjin/core/timer.h1
6 files changed, 59 insertions, 38 deletions
diff --git a/src/libjin/core/game.cpp b/src/libjin/core/game.cpp
index 2090d64..f2223b2 100644
--- a/src/libjin/core/game.cpp
+++ b/src/libjin/core/game.cpp
@@ -1,17 +1,46 @@
#include "game.h"
+#include "../Time/Timer.h"
+#include "../input/Event.h"
namespace jin
{
namespace core
{
- Game::Game() :_run(true) {};
+ using namespace jin::input;
+
+ Game::Game() :_running(true) {};
void Game::run()
{
+ _running = true;
+ Event e;
+ while (_running)
+ {
+ while (jin::input::pollEvent(&e))
+ {
+ if (_instance != nullptr && _onEvent)
+ _onEvent(&e);
+ }
+ if (!_running)
+ break;
+ }
+ }
+
+ 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;
+ 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
index becb780..e9d0340 100644
--- a/src/libjin/core/game.h
+++ b/src/libjin/core/game.h
@@ -1,40 +1,35 @@
#ifndef __JIN_CORE_GAME_H
#define __JIN_CORE_GAME_H
-#include <SDL2/SDL.h>
+#include "SDL2/SDL.h"
-#include "../common/singleton.h"
+#include "../Common/Subsystem.hpp"
#include "../utils/macros.h"
+#include "../Input/Event.h"
namespace jin
{
namespace core
{
- class Game : public Singleton<Game>
+
+ class Game : public Subsystem<Game>
{
public:
- struct Setting
- {
+ typedef void(*onEvent)(jin::input::Event* e);
+ typedef void(*onUpdate)(float dt);
+ typedef void(*onDraw)();
- };
-
- inline void quit()
+ struct Setting : SettingBase
{
- CALLONCE(_quit());
- }
-
- inline bool running()
- {
- return run;
- }
-
- inline void exit()
- {
- CALLONCE(_exit());
- }
+ onEvent eventHandler;
+ onUpdate updater;
+ onDraw drawer;
+ };
void run();
+ inline void stop() { _running = false; };
+ bool running() { return _running; };
private:
@@ -43,19 +38,18 @@ namespace core
SINGLETON(Game);
- bool _run;
+ onEvent _onEvent;
+ onUpdate _onUpdate;
+ onDraw _onDraw;
- inline void _exit()
- {
- SDL_Quit();
- }
+ bool _running;
+
+ onlyonce bool initSystem(const SettingBase* setting);
+ onlyonce void quitSystem();
- inline void _quit()
- {
- _run = false;
- }
};
-}
-}
-#endif \ No newline at end of file
+} // core
+} // jin
+
+#endif // __JIN_CORE_GAME_H \ No newline at end of file
diff --git a/src/libjin/core/thread.cpp b/src/libjin/core/thread.cpp
deleted file mode 100644
index e69de29..0000000
--- a/src/libjin/core/thread.cpp
+++ /dev/null
diff --git a/src/libjin/core/thread.h b/src/libjin/core/thread.h
deleted file mode 100644
index 6f70f09..0000000
--- a/src/libjin/core/thread.h
+++ /dev/null
@@ -1 +0,0 @@
-#pragma once
diff --git a/src/libjin/core/timer.cpp b/src/libjin/core/timer.cpp
deleted file mode 100644
index e69de29..0000000
--- a/src/libjin/core/timer.cpp
+++ /dev/null
diff --git a/src/libjin/core/timer.h b/src/libjin/core/timer.h
deleted file mode 100644
index 6f70f09..0000000
--- a/src/libjin/core/timer.h
+++ /dev/null
@@ -1 +0,0 @@
-#pragma once