|
@@ -17,6 +17,9 @@ using WalrusRPG::States::State;
|
|
|
|
|
|
|
|
namespace
|
|
namespace
|
|
|
{
|
|
{
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Debug function showing a button state.
|
|
|
|
|
+ */
|
|
|
void draw_button(signed x, signed y, KeyState state)
|
|
void draw_button(signed x, signed y, KeyState state)
|
|
|
{
|
|
{
|
|
|
put_horizontal_line(x + 1, x + 5, y, Gray);
|
|
put_horizontal_line(x + 1, x + 5, y, Gray);
|
|
@@ -39,6 +42,9 @@ namespace
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Draws WRPG's buttons states.
|
|
|
|
|
+ */
|
|
|
void draw_buttons()
|
|
void draw_buttons()
|
|
|
{
|
|
{
|
|
|
draw_button(0, 24, key_get_state(Key::K_L));
|
|
draw_button(0, 24, key_get_state(Key::K_L));
|
|
@@ -56,6 +62,7 @@ namespace
|
|
|
draw_button(56, 36, key_get_state(Key::K_A));
|
|
draw_button(56, 36, key_get_state(Key::K_A));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // State stack. Pointer because polymorphism.
|
|
|
static tinystl::vector<WalrusRPG::States::State *> stack;
|
|
static tinystl::vector<WalrusRPG::States::State *> stack;
|
|
|
|
|
|
|
|
} /* namespace */
|
|
} /* namespace */
|
|
@@ -78,6 +85,7 @@ void StateMachine::push(State *state)
|
|
|
|
|
|
|
|
void StateMachine::pop()
|
|
void StateMachine::pop()
|
|
|
{
|
|
{
|
|
|
|
|
+ // Mmmh, should StateMachine manage the state's destruction?...
|
|
|
delete stack.back();
|
|
delete stack.back();
|
|
|
stack.pop_back();
|
|
stack.pop_back();
|
|
|
}
|
|
}
|
|
@@ -89,6 +97,8 @@ void StateMachine::run()
|
|
|
unsigned last_update = 0, update_stamp, update_time;
|
|
unsigned last_update = 0, update_stamp, update_time;
|
|
|
unsigned last_frame = 0, frame_stamp, frame_time;
|
|
unsigned last_frame = 0, frame_stamp, frame_time;
|
|
|
|
|
|
|
|
|
|
+ // TODO : Better way to handle FPS while not breaking anything. There are some issues
|
|
|
|
|
+ // if the update loop takes too much time.
|
|
|
while (!stack.empty())
|
|
while (!stack.empty())
|
|
|
{
|
|
{
|
|
|
update_stamp = Timing::gettime();
|
|
update_stamp = Timing::gettime();
|
|
@@ -102,6 +112,7 @@ void StateMachine::run()
|
|
|
frame_stamp = Timing::gettime();
|
|
frame_stamp = Timing::gettime();
|
|
|
frame_time = frame_stamp - last_frame;
|
|
frame_time = frame_stamp - last_frame;
|
|
|
Graphics::frame_begin();
|
|
Graphics::frame_begin();
|
|
|
|
|
+ // Update the current state
|
|
|
stack.back()->render(100 * frame_time / TIMER_FREQ);
|
|
stack.back()->render(100 * frame_time / TIMER_FREQ);
|
|
|
last_frame = frame_stamp;
|
|
last_frame = frame_stamp;
|
|
|
|
|
|
|
@@ -111,10 +122,12 @@ void StateMachine::run()
|
|
|
Text::print_format(0, 240 - 8, "%ufps, %uups", TIMER_FREQ / frame_time,
|
|
Text::print_format(0, 240 - 8, "%ufps, %uups", TIMER_FREQ / frame_time,
|
|
|
TIMER_FREQ / update_time);
|
|
TIMER_FREQ / update_time);
|
|
|
}
|
|
}
|
|
|
|
|
+ // TODO : use a boolean to show/hide and to avoid that frigging wanring.
|
|
|
// draw_buttons();
|
|
// draw_buttons();
|
|
|
Graphics::frame_end();
|
|
Graphics::frame_end();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // TODO : better exit handling.
|
|
|
if (Input::key_pressed(Key::K_SELECT))
|
|
if (Input::key_pressed(Key::K_SELECT))
|
|
|
{
|
|
{
|
|
|
while (Input::key_down(Key::K_SELECT))
|
|
while (Input::key_down(Key::K_SELECT))
|