Tue, 10 Aug 2021 09:31:50 +0300
* Run once is now guarded and allows any function with any number of parameters
764
7c71952bd75b
Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff
changeset
|
1 | #pragma once |
7c71952bd75b
Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff
changeset
|
2 | |
7c71952bd75b
Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff
changeset
|
3 | #include <string> |
7c71952bd75b
Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff
changeset
|
4 | |
789
4de9ca4d7da0
* HTTP transfer using CURL
cemkalyoncu <cemkalyoncu@gmail.com>
parents:
764
diff
changeset
|
5 | #include "Event.h" |
4de9ca4d7da0
* HTTP transfer using CURL
cemkalyoncu <cemkalyoncu@gmail.com>
parents:
764
diff
changeset
|
6 | |
831
c8208074b8fa
* Design document improvements
cemkalyoncu <cemkalyoncu@gmail.com>
parents:
789
diff
changeset
|
7 | ///@page Design |
c8208074b8fa
* Design document improvements
cemkalyoncu <cemkalyoncu@gmail.com>
parents:
789
diff
changeset
|
8 | ///@htmlinclude "Design.html" |
c8208074b8fa
* Design document improvements
cemkalyoncu <cemkalyoncu@gmail.com>
parents:
789
diff
changeset
|
9 | |
764
7c71952bd75b
Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff
changeset
|
10 | /// Root namespace for Gorgon Game Engine. |
7c71952bd75b
Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff
changeset
|
11 | namespace Gorgon { |
7c71952bd75b
Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff
changeset
|
12 | |
7c71952bd75b
Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff
changeset
|
13 | /// @cond INTERNAL |
7c71952bd75b
Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff
changeset
|
14 | namespace internal { |
7c71952bd75b
Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff
changeset
|
15 | extern std::string systemname; |
7c71952bd75b
Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff
changeset
|
16 | } |
7c71952bd75b
Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff
changeset
|
17 | /// @endcond |
7c71952bd75b
Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff
changeset
|
18 | |
1077
97d2ec99a868
* Added documentation for Scene system, still needs an example
cemkalyoncu
parents:
1072
diff
changeset
|
19 | /// Defines the abstract class of Runner. Runners take the control of the code |
1070
d52068ce190d
* Scene support is ready, waiting for unit tests
cemkalyoncu
parents:
831
diff
changeset
|
20 | /// execution, calling any necessary functions as the events occur. |
d52068ce190d
* Scene support is ready, waiting for unit tests
cemkalyoncu
parents:
831
diff
changeset
|
21 | class Runner { |
d52068ce190d
* Scene support is ready, waiting for unit tests
cemkalyoncu
parents:
831
diff
changeset
|
22 | public: |
d52068ce190d
* Scene support is ready, waiting for unit tests
cemkalyoncu
parents:
831
diff
changeset
|
23 | /// Takes the control of the execution until Quit is called. |
d52068ce190d
* Scene support is ready, waiting for unit tests
cemkalyoncu
parents:
831
diff
changeset
|
24 | virtual void Run() = 0; |
d52068ce190d
* Scene support is ready, waiting for unit tests
cemkalyoncu
parents:
831
diff
changeset
|
25 | |
1072 | 26 | /// Runs a single frame |
27 | virtual void Step() = 0; | |
28 | ||
1070
d52068ce190d
* Scene support is ready, waiting for unit tests
cemkalyoncu
parents:
831
diff
changeset
|
29 | /// Should quit after the current frame is completed for a graceful exit. |
d52068ce190d
* Scene support is ready, waiting for unit tests
cemkalyoncu
parents:
831
diff
changeset
|
30 | virtual void Quit() = 0; |
d52068ce190d
* Scene support is ready, waiting for unit tests
cemkalyoncu
parents:
831
diff
changeset
|
31 | }; |
d52068ce190d
* Scene support is ready, waiting for unit tests
cemkalyoncu
parents:
831
diff
changeset
|
32 | |
1387 | 33 | /// Initializes the entire system except for graphics and UI. Graphics should |
34 | /// be initialized after a window is created and UI should be initialized last. | |
764
7c71952bd75b
Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff
changeset
|
35 | void Initialize(const std::string &systemname); |
7c71952bd75b
Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff
changeset
|
36 | |
7c71952bd75b
Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff
changeset
|
37 | /// Returns the name of the current system |
7c71952bd75b
Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff
changeset
|
38 | inline std::string GetSystemName() { return internal::systemname; } |
7c71952bd75b
Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff
changeset
|
39 | |
7c71952bd75b
Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff
changeset
|
40 | /// Performs various operations that are vital to system execution. These include |
7c71952bd75b
Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff
changeset
|
41 | /// OS message handling, animation and sound progressions, time progression and |
7c71952bd75b
Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff
changeset
|
42 | /// delta time calculation. NextFrame function should be preferred if the frame delay |
7c71952bd75b
Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff
changeset
|
43 | /// is tolerable. |
7c71952bd75b
Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff
changeset
|
44 | void Tick(); |
7c71952bd75b
Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff
changeset
|
45 | |
7c71952bd75b
Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff
changeset
|
46 | /// This function calls the starts the rendering pipeline. Rendering should be last |
7c71952bd75b
Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff
changeset
|
47 | /// operation of a frame. |
7c71952bd75b
Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff
changeset
|
48 | void Render(); |
7c71952bd75b
Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff
changeset
|
49 | |
7c71952bd75b
Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff
changeset
|
50 | /// This function marks the end of current frame and starts the next one. This function calls |
7c71952bd75b
Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff
changeset
|
51 | /// the Tick function at start of the next frame. Additionally, this function calls end of |
7c71952bd75b
Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff
changeset
|
52 | /// frame tasks such as rendering. Before starting the next frame, a certain delay is performed. |
7c71952bd75b
Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff
changeset
|
53 | /// This delay aims to set each frame duration to 16ms, this duration sets the frames per second |
7c71952bd75b
Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff
changeset
|
54 | /// to 62.5. This delay greatly reduces the system load of simple games/applications. |
7c71952bd75b
Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff
changeset
|
55 | void NextFrame(); |
7c71952bd75b
Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff
changeset
|
56 | |
7c71952bd75b
Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff
changeset
|
57 | /// This method works similar to next frame, however, no delay is done. This function allows an |
7c71952bd75b
Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff
changeset
|
58 | /// application to update the display and perform OS tasks while still continuing operation. |
789
4de9ca4d7da0
* HTTP transfer using CURL
cemkalyoncu <cemkalyoncu@gmail.com>
parents:
764
diff
changeset
|
59 | inline void UpdateFrame(); |
1288 | 60 | |
61 | /// Registers a function to be run at the start of the next frame. | |
62 | void RegisterOnce(std::function<void()> fn); | |
1728
92bb193f0a6e
* Run once is now guarded and allows any function with any number of parameters
cemkalyoncu
parents:
1387
diff
changeset
|
63 | |
92bb193f0a6e
* Run once is now guarded and allows any function with any number of parameters
cemkalyoncu
parents:
1387
diff
changeset
|
64 | /// Registers a function to be run at the start of the next frame. |
92bb193f0a6e
* Run once is now guarded and allows any function with any number of parameters
cemkalyoncu
parents:
1387
diff
changeset
|
65 | template<class F_, class ...A_> |
92bb193f0a6e
* Run once is now guarded and allows any function with any number of parameters
cemkalyoncu
parents:
1387
diff
changeset
|
66 | void RegisterOnce(F_ fn, A_ && ...args) { |
92bb193f0a6e
* Run once is now guarded and allows any function with any number of parameters
cemkalyoncu
parents:
1387
diff
changeset
|
67 | RegisterOnce(std::function<void()>(std::bind(fn, std::forward<A_>(args)...))); |
92bb193f0a6e
* Run once is now guarded and allows any function with any number of parameters
cemkalyoncu
parents:
1387
diff
changeset
|
68 | } |
92bb193f0a6e
* Run once is now guarded and allows any function with any number of parameters
cemkalyoncu
parents:
1387
diff
changeset
|
69 | |
789
4de9ca4d7da0
* HTTP transfer using CURL
cemkalyoncu <cemkalyoncu@gmail.com>
parents:
764
diff
changeset
|
70 | |
4de9ca4d7da0
* HTTP transfer using CURL
cemkalyoncu <cemkalyoncu@gmail.com>
parents:
764
diff
changeset
|
71 | extern Event<> BeforeFrameEvent; |
764
7c71952bd75b
Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff
changeset
|
72 | } |