]> git.lizzy.rs Git - nothing.git/blobdiff - src/game.c
Use wrong_argument_type everywhere
[nothing.git] / src / game.c
index 0b43f3b4be970ce7785dab9eba339445fcc6d90a..0b373f9d38c9189e0f7b79dc01c5446cb64a4329 100644 (file)
@@ -4,13 +4,14 @@
 #include <stdio.h>
 
 #include "game.h"
-#include "game/debug_tree.h"
-#include "ui/edit_field.h"
 #include "game/level.h"
-#include "ui/console.h"
 #include "game/sound_samples.h"
 #include "system/error.h"
+#include "system/log.h"
 #include "system/lt.h"
+#include "system/nth_alloc.h"
+#include "ui/console.h"
+#include "ui/edit_field.h"
 
 typedef enum Game_state {
     GAME_STATE_RUNNING = 0,
@@ -30,7 +31,6 @@ typedef struct Game {
     Sound_samples *sound_samples;
     Camera *camera;
     Sprite_font *font;
-    Debug_tree *debug_tree;
     Console *console;
     SDL_Renderer *renderer;
 } Game;
@@ -47,7 +47,7 @@ Game *create_game(const char *level_file_path,
         return NULL;
     }
 
-    Game *game = PUSH_LT(lt, malloc(sizeof(Game)), free);
+    Game *game = PUSH_LT(lt, nth_alloc(sizeof(Game)), free);
     if (game == NULL) {
         throw_error(ERROR_TYPE_LIBC);
         RETURN_LT(lt, NULL);
@@ -64,7 +64,7 @@ Game *create_game(const char *level_file_path,
         RETURN_LT(lt, NULL);
     }
 
-    game->level_file_path = PUSH_LT(lt, malloc(sizeof(char) * (strlen(level_file_path) + 1)), free);
+    game->level_file_path = PUSH_LT(lt, nth_alloc(sizeof(char) * (strlen(level_file_path) + 1)), free);
     if (game->level_file_path == NULL) {
         throw_error(ERROR_TYPE_LIBC);
         RETURN_LT(lt, NULL);
@@ -79,14 +79,6 @@ Game *create_game(const char *level_file_path,
         RETURN_LT(lt, NULL);
     }
 
-    game->debug_tree = PUSH_LT(
-        lt,
-        create_debug_tree(game->font),
-        destroy_debug_tree);
-    if (game->debug_tree == NULL) {
-        RETURN_LT(lt, NULL);
-    }
-
     game->camera = PUSH_LT(lt, create_camera(renderer, game->font), destroy_camera);
     if (game->camera == NULL) {
         RETURN_LT(lt, NULL);
@@ -133,10 +125,6 @@ int game_render(const Game *game)
         return -1;
     }
 
-    if (debug_tree_render(game->debug_tree, game->renderer) < 0) {
-        return -1;
-    }
-
     if (game->state == GAME_STATE_CONSOLE) {
         if (console_render(game->console, game->renderer) < 0) {
             return -1;
@@ -198,7 +186,6 @@ static int game_event_pause(Game *game, const SDL_Event *event)
         case SDLK_l:
             camera_toggle_debug_mode(game->camera);
             level_toggle_debug_mode(game->level);
-            debug_tree_toggle_enabled(game->debug_tree);
             break;
         }
         break;
@@ -220,7 +207,7 @@ static int game_event_running(Game *game, const SDL_Event *event)
     case SDL_KEYDOWN:
         switch (event->key.keysym.sym) {
         case SDLK_r:
-            printf("Reloading the level from '%s'...\n", game->level_file_path);
+            log_info("Reloading the level from '%s'...\n", game->level_file_path);
 
             game->level = RESET_LT(
                 game->lt,
@@ -239,7 +226,7 @@ static int game_event_running(Game *game, const SDL_Event *event)
             break;
 
         case SDLK_q:
-            printf("Reloading the level's platforms from '%s'...\n", game->level_file_path);
+            log_info("Reloading the level's platforms from '%s'...\n", game->level_file_path);
             if (level_reload_preserve_player(game->level, game->level_file_path) < 0) {
                 print_current_error_msg("Could not reload the level");
                 game->state = GAME_STATE_QUIT;
@@ -256,12 +243,15 @@ static int game_event_running(Game *game, const SDL_Event *event)
         case SDLK_l:
             camera_toggle_debug_mode(game->camera);
             level_toggle_debug_mode(game->level);
-            debug_tree_toggle_enabled(game->debug_tree);
             break;
-
+        }
+        break;
+    case SDL_KEYUP:
+        switch (event->key.keysym.sym) {
         case SDLK_BACKQUOTE:
+        case SDLK_c:
+            SDL_StartTextInput();
             game->state = GAME_STATE_CONSOLE;
-            /* TODO(#404): when console is enabled a backquote pressed event sneaks into edit_field a gets inserted */
             console_slide_down(game->console);
             break;
         }
@@ -282,7 +272,7 @@ static int game_event_console(Game *game, const SDL_Event *event)
     case SDL_KEYDOWN:
         switch (event->key.keysym.sym) {
         case SDLK_ESCAPE:
-        case SDLK_BACKQUOTE:
+            SDL_StopTextInput();
             game->state = GAME_STATE_RUNNING;
             return 0;