Explorar o código

truncate methods/properties to save space

jblanked hai 1 ano
pai
achega
dc6edc34ba
Modificáronse 6 ficheiros con 100 adicións e 100 borrados
  1. 43 43
      callback/callback.c
  2. 8 8
      flip_world.c
  3. 8 8
      flip_world.h
  4. 5 5
      game/enemy.c
  5. 1 1
      game/game.c
  6. 35 35
      game/player.c

+ 43 - 43
callback/callback.c

@@ -37,9 +37,9 @@ static int32_t game_app(void *p)
 
     // Setup game engine settings...
     GameEngineSettings settings = game_engine_settings_init();
-    settings.target_fps = game_fps_choices_2[game_fps_index];
+    settings.target_fps = fps_choices_2[fps_index];
     settings.show_fps = game.show_fps;
-    settings.always_backlight = strstr(yes_or_no_choices[game_screen_always_on_index], "Yes") != NULL;
+    settings.always_backlight = strstr(yes_or_no_choices[screen_always_on_index], "Yes") != NULL;
     settings.frame_callback = frame_cb;
     settings.context = game_manager;
     GameEngine *engine = game_engine_alloc(settings);
@@ -91,11 +91,11 @@ static int32_t game_app(void *p)
     return 0;
 }
 
-static void flip_world_request_error_draw(Canvas *canvas, DataLoaderModel *model)
+static void error_draw(Canvas *canvas, DataLoaderModel *model)
 {
     if (canvas == NULL)
     {
-        FURI_LOG_E(TAG, "flip_world_request_error_draw - canvas is NULL");
+        FURI_LOG_E(TAG, "error_draw - canvas is NULL");
         DEV_CRASH();
         return;
     }
@@ -149,10 +149,10 @@ static bool alloc_text_input_view(void *context, char *title);
 static bool alloc_variable_item_list(void *context, uint32_t view_id);
 //
 static void wifi_settings_item_selected(void *context, uint32_t index);
-static void text_updated_wifi_ssid(void *context);
-static void text_updated_wifi_pass(void *context);
-static void text_updated_username(void *context);
-static void text_updated_password(void *context);
+static void updated_wifi_ssid(void *context);
+static void updated_wifi_pass(void *context);
+static void updated_username(void *context);
+static void updated_password(void *context);
 //
 static void fps_change(VariableItem *item);
 static void game_settings_item_selected(void *context, uint32_t index);
@@ -178,7 +178,7 @@ static uint32_t callback_to_settings(void *context)
     return FlipWorldViewSettings;
 }
 
-static void flip_world_view_about_draw_callback(Canvas *canvas, void *model)
+static void about_draw_callback(Canvas *canvas, void *model)
 {
     UNUSED(model);
     canvas_clear(canvas);
@@ -204,7 +204,7 @@ static bool alloc_about_view(void *context)
     }
     if (!app->view_about)
     {
-        if (!easy_flipper_set_view(&app->view_about, FlipWorldViewAbout, flip_world_view_about_draw_callback, NULL, callback_to_submenu, &app->view_dispatcher, app))
+        if (!easy_flipper_set_view(&app->view_about, FlipWorldViewAbout, about_draw_callback, NULL, callback_to_submenu, &app->view_dispatcher, app))
         {
             return false;
         }
@@ -252,9 +252,9 @@ static bool alloc_text_input_view(void *context, char *title)
                 title,
                 app->text_input_temp_buffer,
                 app->text_input_buffer_size,
-                strcmp(title, "SSID") == 0 ? text_updated_wifi_ssid : strcmp(title, "Password") == 0     ? text_updated_wifi_pass
-                                                                  : strcmp(title, "Username-Login") == 0 ? text_updated_username
-                                                                                                         : text_updated_password,
+                strcmp(title, "SSID") == 0 ? updated_wifi_ssid : strcmp(title, "Password") == 0     ? updated_wifi_pass
+                                                             : strcmp(title, "Username-Login") == 0 ? updated_username
+                                                                                                    : updated_password,
                 callback_to_wifi_settings,
                 &app->view_dispatcher,
                 app))
@@ -362,13 +362,13 @@ static bool alloc_variable_item_list(void *context, uint32_t view_id)
             {
                 app->variable_item_game_player_sprite = variable_item_list_add(app->variable_item_list, "Weapon", 4, player_on_change, NULL);
                 variable_item_set_current_value_index(app->variable_item_game_player_sprite, 1);
-                variable_item_set_current_value_text(app->variable_item_game_player_sprite, game_player_sprite_choices[1]);
+                variable_item_set_current_value_text(app->variable_item_game_player_sprite, player_sprite_choices[1]);
             }
             if (!app->variable_item_game_fps)
             {
                 app->variable_item_game_fps = variable_item_list_add(app->variable_item_list, "FPS", 4, fps_change, NULL);
                 variable_item_set_current_value_index(app->variable_item_game_fps, 0);
-                variable_item_set_current_value_text(app->variable_item_game_fps, game_fps_choices[0]);
+                variable_item_set_current_value_text(app->variable_item_game_fps, fps_choices[0]);
             }
             if (!app->variable_item_game_screen_always_on)
             {
@@ -398,7 +398,7 @@ static bool alloc_variable_item_list(void *context, uint32_t view_id)
                 variable_item_set_current_value_index(app->variable_item_game_player_sprite, index);
                 variable_item_set_current_value_text(
                     app->variable_item_game_player_sprite,
-                    strcmp(game_player_sprite_choices[index], "naked") == 0 ? "None" : game_player_sprite_choices[index]);
+                    strcmp(player_sprite_choices[index], "naked") == 0 ? "None" : player_sprite_choices[index]);
             }
             char _game_fps[8];
             if (load_char("Game-FPS", _game_fps, sizeof(_game_fps)))
@@ -407,7 +407,7 @@ static bool alloc_variable_item_list(void *context, uint32_t view_id)
                                                            : strcmp(_game_fps, "120") == 0  ? 2
                                                            : strcmp(_game_fps, "240") == 0  ? 3
                                                                                             : 0;
-                variable_item_set_current_value_text(app->variable_item_game_fps, game_fps_choices[index]);
+                variable_item_set_current_value_text(app->variable_item_game_fps, fps_choices[index]);
                 variable_item_set_current_value_index(app->variable_item_game_fps, index);
             }
             char _game_screen_always_on[8];
@@ -1166,7 +1166,7 @@ void callback_submenu_choices(void *context, uint32_t index)
     }
 }
 
-static void text_updated_wifi_ssid(void *context)
+static void updated_wifi_ssid(void *context)
 {
     FlipWorldApp *app = (FlipWorldApp *)context;
     if (!app)
@@ -1226,7 +1226,7 @@ static void text_updated_wifi_ssid(void *context)
     // switch to the settings view
     view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewVariableItemList);
 }
-static void text_updated_wifi_pass(void *context)
+static void updated_wifi_pass(void *context)
 {
     FlipWorldApp *app = (FlipWorldApp *)context;
     if (!app)
@@ -1286,7 +1286,7 @@ static void text_updated_wifi_pass(void *context)
     // switch to the settings view
     view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewVariableItemList);
 }
-static void text_updated_username(void *context)
+static void updated_username(void *context)
 {
     FlipWorldApp *app = (FlipWorldApp *)context;
     if (!app)
@@ -1311,7 +1311,7 @@ static void text_updated_username(void *context)
     }
     view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewVariableItemList); // back to user settings
 }
-static void text_updated_password(void *context)
+static void updated_password(void *context)
 {
     FlipWorldApp *app = (FlipWorldApp *)context;
     if (!app)
@@ -1404,15 +1404,15 @@ static void wifi_settings_item_selected(void *context, uint32_t index)
 static void fps_change(VariableItem *item)
 {
     uint8_t index = variable_item_get_current_value_index(item);
-    game_fps_index = index;
-    variable_item_set_current_value_text(item, game_fps_choices[index]);
+    fps_index = index;
+    variable_item_set_current_value_text(item, fps_choices[index]);
     variable_item_set_current_value_index(item, index);
-    save_char("Game-FPS", game_fps_choices[index]);
+    save_char("Game-FPS", fps_choices[index]);
 }
 static void screen_on_change(VariableItem *item)
 {
     uint8_t index = variable_item_get_current_value_index(item);
-    game_screen_always_on_index = index;
+    screen_always_on_index = index;
     variable_item_set_current_value_text(item, yes_or_no_choices[index]);
     variable_item_set_current_value_index(item, index);
     save_char("Game-Screen-Always-On", yes_or_no_choices[index]);
@@ -1420,7 +1420,7 @@ static void screen_on_change(VariableItem *item)
 static void sound_on_change(VariableItem *item)
 {
     uint8_t index = variable_item_get_current_value_index(item);
-    game_sound_on_index = index;
+    sound_on_index = index;
     variable_item_set_current_value_text(item, yes_or_no_choices[index]);
     variable_item_set_current_value_index(item, index);
     save_char("Game-Sound-On", yes_or_no_choices[index]);
@@ -1428,7 +1428,7 @@ static void sound_on_change(VariableItem *item)
 static void vibration_on_change(VariableItem *item)
 {
     uint8_t index = variable_item_get_current_value_index(item);
-    game_vibration_on_index = index;
+    vibration_on_index = index;
     variable_item_set_current_value_text(item, yes_or_no_choices[index]);
     variable_item_set_current_value_index(item, index);
     save_char("Game-Vibration-On", yes_or_no_choices[index]);
@@ -1436,10 +1436,10 @@ static void vibration_on_change(VariableItem *item)
 static void player_on_change(VariableItem *item)
 {
     uint8_t index = variable_item_get_current_value_index(item);
-    game_player_sprite_index = index;
-    variable_item_set_current_value_text(item, strcmp(game_player_sprite_choices[index], "naked") == 0 ? "None" : game_player_sprite_choices[index]);
+    player_sprite_index = index;
+    variable_item_set_current_value_text(item, strcmp(player_sprite_choices[index], "naked") == 0 ? "None" : player_sprite_choices[index]);
     variable_item_set_current_value_index(item, index);
-    save_char("Game-Player-Sprite", game_player_sprite_choices[index]);
+    save_char("Game-Player-Sprite", player_sprite_choices[index]);
 }
 
 static bool _fetch_worlds(DataLoaderModel *model)
@@ -1659,7 +1659,7 @@ void loader_draw_callback(Canvas *canvas, void *model)
 
     if (data_state == DataStateError || data_state == DataStateParseError)
     {
-        flip_world_request_error_draw(canvas, data_loader_model);
+        error_draw(canvas, data_loader_model);
         return;
     }
 
@@ -1696,11 +1696,11 @@ void loader_draw_callback(Canvas *canvas, void *model)
     }
 }
 
-static void flip_world_loader_process_callback(void *context)
+static void loader_process_callback(void *context)
 {
     if (context == NULL)
     {
-        FURI_LOG_E(TAG, "flip_world_loader_process_callback - context is NULL");
+        FURI_LOG_E(TAG, "loader_process_callback - context is NULL");
         DEV_CRASH();
         return;
     }
@@ -1842,11 +1842,11 @@ static void flip_world_loader_process_callback(void *context)
     }
 }
 
-static void flip_world_loader_timer_callback(void *context)
+static void loader_timer_callback(void *context)
 {
     if (context == NULL)
     {
-        FURI_LOG_E(TAG, "flip_world_loader_timer_callback - context is NULL");
+        FURI_LOG_E(TAG, "loader_timer_callback - context is NULL");
         DEV_CRASH();
         return;
     }
@@ -1854,11 +1854,11 @@ static void flip_world_loader_timer_callback(void *context)
     view_dispatcher_send_custom_event(app->view_dispatcher, FlipWorldCustomEventProcess);
 }
 
-static void flip_world_loader_on_enter(void *context)
+static void loader_on_enter(void *context)
 {
     if (context == NULL)
     {
-        FURI_LOG_E(TAG, "flip_world_loader_on_enter - context is NULL");
+        FURI_LOG_E(TAG, "loader_on_enter - context is NULL");
         DEV_CRASH();
         return;
     }
@@ -1871,18 +1871,18 @@ static void flip_world_loader_on_enter(void *context)
             view_set_previous_callback(view, model->back_callback);
             if (model->timer == NULL)
             {
-                model->timer = furi_timer_alloc(flip_world_loader_timer_callback, FuriTimerTypePeriodic, app);
+                model->timer = furi_timer_alloc(loader_timer_callback, FuriTimerTypePeriodic, app);
             }
             furi_timer_start(model->timer, 250);
         },
         true);
 }
 
-static void flip_world_loader_on_exit(void *context)
+static void loader_on_exit(void *context)
 {
     if (context == NULL)
     {
-        FURI_LOG_E(TAG, "flip_world_loader_on_exit - context is NULL");
+        FURI_LOG_E(TAG, "loader_on_exit - context is NULL");
         DEV_CRASH();
         return;
     }
@@ -1909,8 +1909,8 @@ void loader_init(View *view)
         return;
     }
     view_allocate_model(view, ViewModelTypeLocking, sizeof(DataLoaderModel));
-    view_set_enter_callback(view, flip_world_loader_on_enter);
-    view_set_exit_callback(view, flip_world_loader_on_exit);
+    view_set_enter_callback(view, loader_on_enter);
+    view_set_exit_callback(view, loader_on_exit);
 }
 
 void loader_free_model(View *view)
@@ -1957,7 +1957,7 @@ bool custom_event_callback(void *context, uint32_t index)
     switch (index)
     {
     case FlipWorldCustomEventProcess:
-        flip_world_loader_process_callback(context);
+        loader_process_callback(context);
         return true;
     default:
         FURI_LOG_DEV(TAG, "custom_event_callback. Unknown index: %ld", index);

+ 8 - 8
flip_world.c

@@ -1,11 +1,11 @@
 #include <flip_world.h>
-char *game_fps_choices[] = {"30", "60", "120", "240"};
-const float game_fps_choices_2[] = {30.0, 60.0, 120.0, 240.0};
-int game_fps_index = 0;
+char *fps_choices[] = {"30", "60", "120", "240"};
+const float fps_choices_2[] = {30.0, 60.0, 120.0, 240.0};
+int fps_index = 0;
 char *yes_or_no_choices[] = {"No", "Yes"};
-int game_screen_always_on_index = 1;
-int game_sound_on_index = 0;
-int game_vibration_on_index = 0;
-char *game_player_sprite_choices[] = {"naked", "sword", "axe", "bow"};
-int game_player_sprite_index = 1;
+int screen_always_on_index = 1;
+int sound_on_index = 0;
+int vibration_on_index = 0;
+char *player_sprite_choices[] = {"naked", "sword", "axe", "bow"};
+int player_sprite_index = 1;
 bool is_enough_heap(size_t heap_size) { return memmgr_get_free_heap() > (heap_size + 1024); } // 1KB buffer

+ 8 - 8
flip_world.h

@@ -76,13 +76,13 @@ typedef struct
     uint32_t text_input_buffer_size; // Size of the text input buffer
 } FlipWorldApp;
 
-extern char *game_fps_choices[];
-extern const float game_fps_choices_2[];
-extern int game_fps_index;
+extern char *fps_choices[];
+extern const float fps_choices_2[];
+extern int fps_index;
 extern char *yes_or_no_choices[];
-extern int game_screen_always_on_index;
-extern int game_sound_on_index;
-extern int game_vibration_on_index;
-extern char *game_player_sprite_choices[];
-extern int game_player_sprite_index;
+extern int screen_always_on_index;
+extern int sound_on_index;
+extern int vibration_on_index;
+extern char *player_sprite_choices[];
+extern int player_sprite_index;
 bool is_enough_heap(size_t heap_size);

+ 5 - 5
game/enemy.c

@@ -236,7 +236,7 @@ static void enemy_render(Entity *self, GameManager *manager, Canvas *canvas, voi
     }
 }
 
-static void send_attack_notification(GameContext *game_context, EnemyContext *enemy_context, bool player_attacked)
+static void atk_notify(GameContext *game_context, EnemyContext *enemy_context, bool player_attacked)
 {
     if (!game_context || !enemy_context)
     {
@@ -246,8 +246,8 @@ static void send_attack_notification(GameContext *game_context, EnemyContext *en
 
     NotificationApp *notifications = furi_record_open(RECORD_NOTIFICATION);
 
-    const bool vibration_allowed = strstr(yes_or_no_choices[game_vibration_on_index], "Yes") != NULL;
-    const bool sound_allowed = strstr(yes_or_no_choices[game_sound_on_index], "Yes") != NULL;
+    const bool vibration_allowed = strstr(yes_or_no_choices[vibration_on_index], "Yes") != NULL;
+    const bool sound_allowed = strstr(yes_or_no_choices[sound_on_index], "Yes") != NULL;
 
     if (player_attacked)
     {
@@ -355,7 +355,7 @@ static void enemy_collision(Entity *self, Entity *other, GameManager *manager, v
         {
             if (game_context->player_context->elapsed_attack_timer >= game_context->player_context->attack_timer)
             {
-                send_attack_notification(game_context, enemy_context, true);
+                atk_notify(game_context, enemy_context, true);
 
                 // Reset player's elapsed attack timer
                 game_context->player_context->elapsed_attack_timer = 0.0f;
@@ -414,7 +414,7 @@ static void enemy_collision(Entity *self, Entity *other, GameManager *manager, v
         {
             if (enemy_context->elapsed_attack_timer >= enemy_context->attack_timer)
             {
-                send_attack_notification(game_context, enemy_context, false);
+                atk_notify(game_context, enemy_context, false);
 
                 // Reset enemy's elapsed attack timer
                 enemy_context->elapsed_attack_timer = 0.0f;

+ 1 - 1
game/game.c

@@ -11,7 +11,7 @@ static void game_start(GameManager *game_manager, void *ctx)
     // Do some initialization here, for example you can load score from storage.
     // For simplicity, we will just set it to 0.
     GameContext *game_context = ctx;
-    game_context->fps = game_fps_choices_2[game_fps_index];
+    game_context->fps = fps_choices_2[fps_index];
     game_context->player_context = NULL;
     game_context->current_level = 0;
     game_context->ended_early = false;

+ 35 - 35
game/player.c

@@ -1,7 +1,7 @@
 #include <game/player.h>
 #include <game/storage.h>
 /****** Entities: Player ******/
-static Level *get_next_level(GameManager *manager)
+static Level *next_level(GameManager *manager)
 {
     GameContext *game_context = game_manager_game_context_get(manager);
     if (!game_context)
@@ -69,14 +69,14 @@ void player_spawn(Level *level, GameManager *manager)
     entity_collider_add_rect(game_context->player, 13, 11);
 
     // Get player context
-    PlayerContext *player_context = entity_context_get(game_context->player);
-    if (!player_context)
+    PlayerContext *pctx = entity_context_get(game_context->player);
+    if (!pctx)
     {
         FURI_LOG_E(TAG, "Failed to get player context");
         return;
     }
 
-    SpriteContext *sprite_context = get_sprite_context(game_player_sprite_choices[game_player_sprite_index]);
+    SpriteContext *sprite_context = get_sprite_context(player_sprite_choices[player_sprite_index]);
     if (!sprite_context)
     {
         FURI_LOG_E(TAG, "Failed to get sprite context");
@@ -84,40 +84,40 @@ void player_spawn(Level *level, GameManager *manager)
     }
 
     // player context must be set each level or NULL pointer will be dereferenced
-    if (!load_player_context(player_context))
+    if (!load_player_context(pctx))
     {
         FURI_LOG_E(TAG, "Loading player context failed. Initializing default values.");
 
         // Initialize default player context
-        player_context->sprite_right = game_manager_sprite_load(manager, sprite_context->right_file_name);
-        player_context->sprite_left = game_manager_sprite_load(manager, sprite_context->left_file_name);
-        player_context->direction = PLAYER_RIGHT; // default direction
-        player_context->health = 100;
-        player_context->strength = 10;
-        player_context->level = 1;
-        player_context->xp = 0;
-        player_context->start_position = entity_pos_get(game_context->player);
-        player_context->attack_timer = 0.1f;
-        player_context->elapsed_attack_timer = player_context->attack_timer;
-        player_context->health_regen = 1; // 1 health per second
-        player_context->elapsed_health_regen = 0;
-        player_context->max_health = 100 + ((player_context->level - 1) * 10); // 10 health per level
+        pctx->sprite_right = game_manager_sprite_load(manager, sprite_context->right_file_name);
+        pctx->sprite_left = game_manager_sprite_load(manager, sprite_context->left_file_name);
+        pctx->direction = PLAYER_RIGHT; // default direction
+        pctx->health = 100;
+        pctx->strength = 10;
+        pctx->level = 1;
+        pctx->xp = 0;
+        pctx->start_position = entity_pos_get(game_context->player);
+        pctx->attack_timer = 0.1f;
+        pctx->elapsed_attack_timer = pctx->attack_timer;
+        pctx->health_regen = 1; // 1 health per second
+        pctx->elapsed_health_regen = 0;
+        pctx->max_health = 100 + ((pctx->level - 1) * 10); // 10 health per level
 
         // Set player username
-        if (!load_char("Flip-Social-Username", player_context->username, sizeof(player_context->username)))
+        if (!load_char("Flip-Social-Username", pctx->username, sizeof(pctx->username)))
         {
             // check if data/player/username
-            if (!load_char("player/username", player_context->username, sizeof(player_context->username)))
+            if (!load_char("player/username", pctx->username, sizeof(pctx->username)))
             {
                 // If loading username fails, default to "Player"
-                snprintf(player_context->username, sizeof(player_context->username), "Player");
+                snprintf(pctx->username, sizeof(pctx->username), "Player");
             }
         }
 
-        game_context->player_context = player_context;
+        game_context->player_context = pctx;
 
         // Save the initialized context
-        if (!save_player_context(player_context))
+        if (!save_player_context(pctx))
         {
             FURI_LOG_E(TAG, "Failed to save player context after initialization");
         }
@@ -126,10 +126,10 @@ void player_spawn(Level *level, GameManager *manager)
     }
 
     // Load player sprite (we'll add this to the JSON later when players can choose their sprite)
-    player_context->sprite_right = game_manager_sprite_load(manager, sprite_context->right_file_name);
-    player_context->sprite_left = game_manager_sprite_load(manager, sprite_context->left_file_name);
+    pctx->sprite_right = game_manager_sprite_load(manager, sprite_context->right_file_name);
+    pctx->sprite_left = game_manager_sprite_load(manager, sprite_context->left_file_name);
 
-    player_context->start_position = entity_pos_get(game_context->player);
+    pctx->start_position = entity_pos_get(game_context->player);
 
     // Update player stats based on XP using iterative method
     // Function to get the current level based on XP iteratively
@@ -148,20 +148,20 @@ void player_spawn(Level *level, GameManager *manager)
     }
 
     // Determine the player's level based on XP
-    player_context->level = get_player_level_iterative(player_context->xp);
+    pctx->level = get_player_level_iterative(pctx->xp);
 
     // Update strength and max health based on the new level
-    player_context->strength = 10 + (player_context->level * 1);           // 1 strength per level
-    player_context->max_health = 100 + ((player_context->level - 1) * 10); // 10 health per level
+    pctx->strength = 10 + (pctx->level * 1);           // 1 strength per level
+    pctx->max_health = 100 + ((pctx->level - 1) * 10); // 10 health per level
 
     // Assign loaded player context to game context
-    game_context->player_context = player_context;
+    game_context->player_context = pctx;
 }
 
 // code from Derek Jamison
 // eventually we'll add dynamic positioning based on how much pitch/roll is detected
 // instead of assigning a fixed value
-static int player_x_from_pitch(float pitch)
+static int vgm_x(float pitch)
 {
     if (pitch > 6.0)
     {
@@ -174,7 +174,7 @@ static int player_x_from_pitch(float pitch)
     return 0;
 }
 
-static int player_y_from_roll(float roll)
+static int vgm_y(float roll)
 {
     if (roll > 9.0)
     {
@@ -207,8 +207,8 @@ static void player_update(Entity *self, GameManager *manager, void *context)
 
     if (game_context->imu_present)
     {
-        player->dx = player_x_from_pitch(-imu_pitch_get(game_context->imu));
-        player->dy = player_y_from_roll(-imu_roll_get(game_context->imu));
+        player->dx = vgm_x(-imu_pitch_get(game_context->imu));
+        player->dy = vgm_y(-imu_roll_get(game_context->imu));
 
         switch (player->dx)
         {
@@ -356,7 +356,7 @@ static void player_update(Entity *self, GameManager *manager, void *context)
         {
             game_context->is_switching_level = true;
             save_player_context(player);
-            game_manager_next_level_set(manager, get_next_level(manager));
+            game_manager_next_level_set(manager, next_level(manager));
             return;
         }