Explorar o código

Added a status sub-system for another platform and to allow alleviate Select from being the exit key.

Eiyeron Fulmincendii %!s(int64=9) %!d(string=hai) anos
pai
achega
43bd7ad0f9

+ 14 - 0
platform/include/Status.h

@@ -0,0 +1,14 @@
+#ifndef INCLUDE_STATUS_H
+#define INCLUDE_STATUS_H
+namespace WalrusRPG
+{
+    namespace Status
+    {
+        void init();
+        void update();
+        bool mustQuit();
+        void deinit();
+    }
+}
+
+#endif

+ 30 - 0
platform/nspire/Status.cpp

@@ -0,0 +1,30 @@
+#include "Status.h"
+#include "Quirks.h"
+#include "Logger.h"
+
+using namespace WalrusRPG; /*Status*/
+
+namespace
+{
+    static bool askedForQuit;
+}
+
+void Status::init()
+{
+    Logger::log("Logger init");
+    askedForQuit = false;
+}
+
+void Status::deinit()
+{
+    Logger::log("Logger deinit");
+}
+
+void Status::update()
+{
+}
+
+bool Status::mustQuit()
+{
+    return WalrusRPG::Quirks::get_key(KEY_NSPIRE_ESC);
+}

+ 0 - 5
platform/sfml/Graphics.cpp

@@ -39,13 +39,8 @@ void Graphics::frame_end()
 {
     sf::Sprite sprite(buffer.getTexture());
     sf::Vector2u winsize = window.getSize();
-    sf::Event event;
     float scale = min(winsize.x / 320.f, winsize.y / 240.f);
 
-    while (window.pollEvent(event))
-    {
-    }
-
     window.setView(view = sf::View(sf::FloatRect(0, 0, winsize.x, winsize.y)));
 
     buffer.display();

+ 41 - 0
platform/sfml/Status.cpp

@@ -0,0 +1,41 @@
+#include "Status.h"
+#include "Logger.h"
+#include "Quirks.h"
+#include "sfwindow.h"
+#include <SFML/Window/Event.hpp>
+#include "platform.h"
+
+using namespace WalrusRPG;
+
+namespace
+{
+    static bool askedToQuit;
+}
+
+void Status::init()
+{
+    Logger::log("Status init");
+    askedToQuit = false;
+}
+
+void Status::deinit()
+{
+    Logger::log("Status deinit");
+}
+
+void Status::update()
+{
+    sf::Event event;
+    while (window.pollEvent(event))
+    {
+        if (event.type == sf::Event::Closed)
+            askedToQuit = true;
+    }
+    if (Quirks::get_key(sf::Keyboard::Escape))
+        askedToQuit = true;
+}
+
+bool Status::mustQuit()
+{
+    return askedToQuit;
+}

+ 3 - 9
src/engine/StateMachine.cpp

@@ -3,6 +3,7 @@
 #include "Timing.h"
 #include "platform.h"
 #include "Graphics.h"
+#include "Status.h"
 #include "render/Text.h"
 #include "version.h"
 #include "input/Input.h"
@@ -99,8 +100,9 @@ void StateMachine::run()
 
     // 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() && !Status::mustQuit())
     {
+        Status::update();
         update_stamp = Timing::gettime();
         update_time = update_stamp - last_update;
         Input::key_poll();
@@ -127,14 +129,6 @@ void StateMachine::run()
             Graphics::frame_end();
         }
 
-        // TODO : better exit handling.
-        if (Input::key_pressed(Key::K_SELECT))
-        {
-            while (Input::key_down(Key::K_SELECT))
-                Input::key_poll();
-            StateMachine::pop();
-        }
-
 #ifdef ACTIVE_WAIT
         while (Timing::gettime() < loop_next)
             ;

+ 3 - 0
src/engine/main.cpp

@@ -4,6 +4,7 @@
 #include "render/Text.h"
 #include "Graphics.h"
 #include "Quirks.h"
+#include "Status.h"
 #include "map/Map.h"
 #include "map/StateMap.h"
 #include "piaf/Archive.h"
@@ -18,6 +19,7 @@ int main(int argc, char *argv[])
 {
     UNUSED(argc);
     Logger::log("WalrusRPG Init");
+    Status::init();
     Graphics::init();
     Timing::init();
     Quirks::init(argv[0]);
@@ -60,6 +62,7 @@ int main(int argc, char *argv[])
     Quirks::deinit();
     Timing::deinit();
     Graphics::deinit();
+    Status::deinit();
     delete[] dungeonTest;
     delete[] dungeonTest2;
     Logger::log("WalrusRPG Exit");

+ 1 - 1
src/input/Input.cpp

@@ -40,7 +40,7 @@ static InputMap key_map[] = {
     {Key::K_UP, KEY_NSPIRE_8},      {Key::K_DOWN, KEY_NSPIRE_5},
     {Key::K_LEFT, KEY_NSPIRE_4},    {Key::K_RIGHT, KEY_NSPIRE_6},
 
-    {Key::K_START, KEY_NSPIRE_DOC}, {Key::K_SELECT, KEY_NSPIRE_ESC},
+    {Key::K_START, KEY_NSPIRE_DOC}, {Key::K_SELECT, KEY_NSPIRE_SCRATCHPAD},
 };
 #endif