rdefeo 1 год назад
Родитель
Сommit
04a638867c
5 измененных файлов с 16 добавлено и 22 удалено
  1. 5 11
      pinball0.cxx
  2. 7 1
      pinball0.h
  3. 2 0
      settings.h
  4. 2 7
      table.cxx
  5. 0 3
      table.h

+ 5 - 11
pinball0.cxx

@@ -19,11 +19,6 @@
 #define MANUAL_ADJUSTMENT 20
 #define IDLE_TIMEOUT      120 * 1000 // 120 seconds * 1000 ticks/sec
 
-namespace {
-uint32_t idle_start; // tracks time of last key press
-
-};
-
 void solve(PinballApp* pb, float dt) {
     Table* table = pb->table;
 
@@ -369,13 +364,12 @@ extern "C" int32_t pinball0_app(void* p) {
 
     float dt = 0.0f;
     uint32_t last_frame_time = furi_get_tick();
-    idle_start = last_frame_time;
+    app->idle_start = last_frame_time;
 
-    FURI_LOG_I(TAG, "Starting event loop");
+    // I'm not thrilled with this event loop - kinda messy but it'll do for now
     PinballEvent event;
     while(app->processing) {
-        FuriStatus event_status =
-            furi_message_queue_get(event_queue, &event, 10); // TODO best rate?
+        FuriStatus event_status = furi_message_queue_get(event_queue, &event, 10);
         furi_mutex_acquire(app->mutex, FuriWaitForever);
 
         if(event_status == FuriStatusOk) {
@@ -565,7 +559,7 @@ extern "C" int32_t pinball0_app(void* p) {
                     }
                 }
                 // a key was pressed, reset idle counter
-                idle_start = furi_get_tick();
+                app->idle_start = furi_get_tick();
             }
         }
         solve(app, dt);
@@ -586,7 +580,7 @@ extern "C" int32_t pinball0_app(void* p) {
 
         // game timing + idle check
         uint32_t current_tick = furi_get_tick();
-        if(current_tick - idle_start >= IDLE_TIMEOUT) {
+        if(current_tick - app->idle_start >= IDLE_TIMEOUT) {
             FURI_LOG_W(TAG, "Idle timeout! Exiting Pinball0...");
             app->processing = false;
             break;

+ 7 - 1
pinball0.h

@@ -48,7 +48,12 @@ typedef enum GameMode {
 class TableList {
 public:
     TableList() = default;
-    ~TableList();
+    ~TableList() {
+        for(auto& mi : menu_items) {
+            furi_string_free(mi.name);
+            furi_string_free(mi.filename);
+        }
+    }
 
     typedef struct {
         FuriString* name;
@@ -76,6 +81,7 @@ typedef struct PinballApp {
     bool gameStarted;
     bool keys[4]; // which key was pressed?
     bool processing; // controls game loop and game objects
+    uint32_t idle_start; // tracks time of last key press
 
     // user settings
     struct {

+ 2 - 0
settings.h

@@ -2,6 +2,8 @@
 
 #include "pinball0.h"
 
+// Read game settings from .pinball0.conf
 void pinball_load_settings(PinballApp* pb);
 
+// Save game settings to .pinball0.conf
 void pinball_save_settings(PinballApp* pb);

+ 2 - 7
table.cxx

@@ -57,10 +57,12 @@ void Table::draw(Canvas* canvas) {
         o->draw(canvas);
     }
 
+    // now draw flippers
     for(auto& f : flippers) {
         f.draw(canvas);
     }
 
+    // is there a plunger in the house?
     if(plunger) {
         plunger->draw(canvas);
     }
@@ -68,13 +70,6 @@ void Table::draw(Canvas* canvas) {
     score.draw(canvas);
 }
 
-TableList::~TableList() {
-    for(auto& mi : menu_items) {
-        furi_string_free(mi.name);
-        furi_string_free(mi.filename);
-    }
-}
-
 Table* table_init_table_select(void* ctx) {
     UNUSED(ctx);
     Table* table = new Table();

+ 0 - 3
table.h

@@ -10,8 +10,6 @@
 #define TABLE_SETTINGS     2
 #define TABLE_INDEX_OFFSET 3
 
-struct PinballApp;
-
 // Table display elements, rendered on the physical display coordinates,
 // not the table's scaled coords
 class DataDisplay {
@@ -77,7 +75,6 @@ public:
     Plunger* plunger;
 
     void draw(Canvas* canvas);
-    bool handle_key_event(const PinballEvent& event);
 };
 
 // Read the list tables from the data folder and store in the state