]> git.lizzy.rs Git - nothing.git/blobdiff - src/game.c
(#572) Introduce quasiquote special form
[nothing.git] / src / game.c
index cd27daee46bc88e367a7966ecf094311c2385298..0dc0d2b8ef715ca6c49ec0d4003e9f6979e26125 100644 (file)
@@ -4,12 +4,13 @@
 #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,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;
@@ -62,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);
@@ -205,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,
@@ -214,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;
             }
@@ -224,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;
             }