aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/Game/je_application.h
blob: f740c22ddec5ee5395dc0a4426e612ec3b6edc11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#ifndef __JE_CORE_GAME_H
#define __JE_CORE_GAME_H

#include "../core/je_configuration.h"
#if defined(jin_game)

#include "../common/je_subsystem.hpp"
#include "../utils/je_macros.h"
#include "../input/je_Event.h"

#include "SDL2/SDL.h"

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)();

            ///
            /// 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:

            Application();
			~Application() {};

			singleton(Application);
        
			onEvent  _onEvent; 
			onUpdate _onUpdate;
			onDraw   _onDraw;
			onLoad   _onLoad;

			bool _running;

			bool initSystem(const SettingBase* setting);
			void quitSystem();

		};

	} // namespace Core
} // namespace JinEngine

#endif // jin_game

#endif // __JE_CORE_GAME_H