aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/game
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2020-02-11 11:29:07 +0800
committerchai <chaifix@163.com>2020-02-11 11:29:07 +0800
commit160e1299ef3d95f8e8c48706d7f61dd3dc6c6b60 (patch)
treeabe5ae5242d9cc6caf6edf103e662c44e978fca0 /src/libjin/game
parente095043485d1d298571af6d9eca7f0db9009ea7a (diff)
*修改 tab大小HEADmaster
Diffstat (limited to 'src/libjin/game')
-rw-r--r--src/libjin/game/application.cpp108
-rw-r--r--src/libjin/game/application.h130
-rw-r--r--src/libjin/game/gameobject.cpp8
-rw-r--r--src/libjin/game/gameobject.h32
4 files changed, 139 insertions, 139 deletions
diff --git a/src/libjin/game/application.cpp b/src/libjin/game/application.cpp
index c198336..ee9d4c0 100644
--- a/src/libjin/game/application.cpp
+++ b/src/libjin/game/application.cpp
@@ -18,65 +18,65 @@ 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);
- glClear(GL_COLOR_BUFFER_BIT);
- if (_onDraw != nullptr)
- _onDraw();
- wnd->present();
- sleep(16);
- }
- quitloop:;
- }
+ /* 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->present();
+ 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()
- {
- SDL_Quit();
- }
+ void Application::quitSystem()
+ {
+ SDL_Quit();
+ }
- } // namespace Core
+ } // namespace Core
} // namespace JinEngine
#endif // jin_game \ No newline at end of file
diff --git a/src/libjin/game/application.h b/src/libjin/game/application.h
index 4c4f48b..7853e2b 100644
--- a/src/libjin/game/application.h
+++ b/src/libjin/game/application.h
@@ -12,71 +12,71 @@
namespace JinEngine
{
- 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)();
-
- Application();
- ~Application() {};
-
- ///
- /// Game setting.
- ///
- struct Setting : SettingBase
- {
- onEvent eventHandler;
- onUpdate updater;
- onDraw drawer;
- onLoad loader;
- };
-
- ///
- /// Main game loop.
- ///
- void run();
-
- ///
- /// Stop game.
- ///
- inline void stop()
- {
- _running = false;
- };
-
- ///
- /// Return if game is running.
- ///
- /// @return True if game is running, otherwise return false.
- ///
- inline bool running()
- {
- return _running;
- };
-
- private:
- onEvent _onEvent;
- onUpdate _onUpdate;
- onDraw _onDraw;
- onLoad _onLoad;
-
- bool _running;
-
- bool startSystem(const SettingBase* setting);
- void quitSystem();
-
- };
-
- } // namespace Core
+ 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)();
+
+ Application();
+ ~Application() {};
+
+ ///
+ /// Game setting.
+ ///
+ struct Setting : SettingBase
+ {
+ onEvent eventHandler;
+ onUpdate updater;
+ onDraw drawer;
+ onLoad loader;
+ };
+
+ ///
+ /// Main game loop.
+ ///
+ void run();
+
+ ///
+ /// Stop game.
+ ///
+ inline void stop()
+ {
+ _running = false;
+ };
+
+ ///
+ /// Return if game is running.
+ ///
+ /// @return True if game is running, otherwise return false.
+ ///
+ inline bool running()
+ {
+ return _running;
+ };
+
+ private:
+ onEvent _onEvent;
+ onUpdate _onUpdate;
+ onDraw _onDraw;
+ onLoad _onLoad;
+
+ bool _running;
+
+ bool startSystem(const SettingBase* setting);
+ void quitSystem();
+
+ };
+
+ } // namespace Core
} // namespace JinEngine
#endif // jin_game
diff --git a/src/libjin/game/gameobject.cpp b/src/libjin/game/gameobject.cpp
index b17c93c..9e09706 100644
--- a/src/libjin/game/gameobject.cpp
+++ b/src/libjin/game/gameobject.cpp
@@ -2,10 +2,10 @@
namespace JinEngine
{
- namespace Game
- {
+ namespace Game
+ {
-
+
- } // namespace Game
+ } // namespace Game
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin/game/gameobject.h b/src/libjin/game/gameobject.h
index 7cb0de2..f81ae75 100644
--- a/src/libjin/game/gameobject.h
+++ b/src/libjin/game/gameobject.h
@@ -13,27 +13,27 @@
namespace JinEngine
{
- namespace Game
- {
+ namespace Game
+ {
- ///
- /// Game object base class.
- ///
- class GameObject : public Object
- {
- public:
+ ///
+ /// Game object base class.
+ ///
+ class GameObject : public Object
+ {
+ public:
- ///
- ///
- ///
- virtual ~GameObject() {};
+ ///
+ ///
+ ///
+ virtual ~GameObject() {};
- protected:
- Math::Transform mTransform;
+ protected:
+ Math::Transform mTransform;
- };
+ };
- } // namespace Game
+ } // namespace Game
} // namespace JinEngine
#endif // jin_game