]> git.lizzy.rs Git - nothing.git/blobdiff - src/game.c
(#541) Remove debug code
[nothing.git] / src / game.c
index a452faaaa93060bf5750289a545847c2dea1bfed..0dc0d2b8ef715ca6c49ec0d4003e9f6979e26125 100644 (file)
@@ -4,13 +4,13 @@
 #include <stdio.h>
 
 #include "game.h"
-#include "game/debug_tree.h"
-#include "game/edit_field.h"
 #include "game/level.h"
-#include "game/level/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 +30,6 @@ typedef struct Game {
     Sound_samples *sound_samples;
     Camera *camera;
     Sprite_font *font;
-    Debug_tree *debug_tree;
     Console *console;
     SDL_Renderer *renderer;
 } Game;
@@ -47,9 +46,8 @@ 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);
     }
     game->lt = lt;
@@ -64,9 +62,8 @@ 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);
     }
     strcpy(game->level_file_path, level_file_path);
@@ -79,14 +76,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 +122,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;
@@ -168,6 +153,10 @@ int game_update(Game *game, float delta_time)
         if (level_enter_camera_event(game->level, game->camera) < 0) {
             return -1;
         }
+
+        if (console_update(game->console, delta_time) < 0) {
+            return -1;
+        }
     }
 
     return 0;
@@ -194,7 +183,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;
@@ -216,7 +204,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,
@@ -225,7 +213,7 @@ static int game_event_running(Game *game, const SDL_Event *event)
                     game->level_file_path));
 
             if (game->level == NULL) {
-                print_current_error_msg("Could not reload the level");
+                log_fail("Could not reload level %s\n", game->level_file_path);
                 game->state = GAME_STATE_QUIT;
                 return -1;
             }
@@ -235,9 +223,9 @@ 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");
+                log_fail("Could not reload level %s\n", game->level_file_path);
                 game->state = GAME_STATE_QUIT;
                 return -1;
             }
@@ -252,11 +240,16 @@ 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;
+            console_slide_down(game->console);
             break;
         }
         break;
@@ -276,7 +269,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;