Skip to content

Commit 5c79a30

Browse files
authored
Merge pull request #1881 from nicolasnoble/application-frame
Introducing Application's frame method.
2 parents bb66cf3 + a709799 commit 5c79a30

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

src/mips/psyqo/application.hh

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,30 @@ class Application {
5858
/**
5959
* @brief Prepare the objects for the application
6060
*
61-
* @details This will be called once before creating the first scene,
62-
* and should be used to initialize any other objects necessary. Do
63-
* not try to access any hardware resources during this call.
61+
* @details This will be called once before the main loop, and
62+
* should be used to initialize any other objects necessary. Do
63+
* not try to access any hardware resources during this call,
64+
* as interrupts are disabled at this point.
6465
*/
6566
virtual void prepare() {}
6667

68+
/**
69+
* @brief Start the application.
70+
*
71+
* @details This will be called once before the main loop, and
72+
* after the `prepare` method. It should be used to initialize
73+
* any hardware resources necessary, as interrupts are enabled.
74+
*/
75+
virtual void start() {}
76+
6777
/**
6878
* @brief Create the root scene object.
6979
*
7080
* @details This will be called once before the main loop. It should
71-
* create the root scene object and push it onto the stack.
81+
* create the root scene object and push it onto the stack. This will
82+
* only be called if the `frame` method of the `Application` class
83+
* hasn't been overridden. If you override the `frame` method, you
84+
* are responsible for managing your own scene system.
7285
*/
7386
virtual void createScene() {}
7487

@@ -111,6 +124,18 @@ class Application {
111124
*/
112125
Scene* popScene();
113126

127+
/**
128+
* @brief The frame method.
129+
*
130+
* @details The default implementation of this method will call the
131+
* `createScene` method if the scene stack is empty, and then call
132+
* the `frame` method of the current scene. This method is called
133+
* once per frame, and should be used to update the application
134+
* state. If you override this method, you are responsible for
135+
* managing your own scene system.
136+
*/
137+
virtual void frame();
138+
114139
virtual ~Application() = default;
115140

116141
private:

src/mips/psyqo/src/application.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,22 @@ int psyqo::Application::run() {
5151
clearAllGTERegisters();
5252
prepare();
5353
Kernel::fastLeaveCriticalSection();
54+
start();
5455
while (true) {
55-
if (m_scenesStack.empty()) {
56-
createScene();
57-
}
58-
Kernel::assert(m_scenesStack.size() > 0, "Scenes stack is empty");
59-
getCurrentScene()->frame();
56+
frame();
6057
m_gpu.flip();
6158
}
6259
__builtin_unreachable();
6360
}
6461

62+
void psyqo::Application::frame() {
63+
if (m_scenesStack.empty()) {
64+
createScene();
65+
}
66+
Kernel::assert(m_scenesStack.size() > 0, "Scenes stack is empty");
67+
getCurrentScene()->frame();
68+
}
69+
6570
psyqo::Scene* psyqo::Application::getCurrentScene() {
6671
if (m_scenesStack.empty()) {
6772
return nullptr;

0 commit comments

Comments
 (0)