]> git.lizzy.rs Git - nothing.git/blobdiff - src/game.c
Use wrong_argument_type everywhere
[nothing.git] / src / game.c
index 801f98d86c5844e627e0bfdb4a91c95bcc6c02e6..0b373f9d38c9189e0f7b79dc01c5446cb64a4329 100644 (file)
@@ -4,12 +4,14 @@
 #include <stdio.h>
 
 #include "game.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,
@@ -45,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);
@@ -62,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);
@@ -205,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,
@@ -224,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;
@@ -242,10 +244,14 @@ static int game_event_running(Game *game, const SDL_Event *event)
             camera_toggle_debug_mode(game->camera);
             level_toggle_debug_mode(game->level);
             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;
         }
@@ -266,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;