]> git.lizzy.rs Git - nothing.git/blobdiff - src/game/level/background.c
(#639) Make rigid bodies interact with platforms
[nothing.git] / src / game / level / background.c
index 881af409353eb7cb8a9bcb32f148ade4e981e311..eaecf20dc00e53be6e1313f910806f99e55a387c 100644 (file)
@@ -1,10 +1,12 @@
-#include <assert.h>
+#include "system/stacktrace.h"
 
 #include "game/level/background.h"
 #include "math/rand.h"
 #include "math/rect.h"
-#include "system/error.h"
+#include "system/line_stream.h"
 #include "system/lt.h"
+#include "system/nth_alloc.h"
+#include "system/log.h"
 
 #define BACKGROUND_CHUNK_COUNT 5
 #define BACKGROUND_CHUNK_WIDTH 250.0f
@@ -33,7 +35,7 @@ Background *create_background(Color base_color)
         return NULL;
     }
 
-    Background *background = PUSH_LT(lt, malloc(sizeof(Background)), free);
+    Background *background = PUSH_LT(lt, nth_alloc(sizeof(Background)), free);
     if (background == NULL) {
         RETURN_LT(lt, NULL);
     }
@@ -46,21 +48,20 @@ Background *create_background(Color base_color)
     return background;
 }
 
-Background *create_background_from_stream(FILE *stream)
+Background *create_background_from_line_stream(LineStream *line_stream)
 {
     char color[7];
-    if (fscanf(stream, "%6s", color) == EOF) {
-        throw_error(ERROR_TYPE_LIBC);
+    if (sscanf(line_stream_next(line_stream), "%6s", color) == EOF) {
+        log_fail("Could not read background's color\n");
         return NULL;
     }
 
-    return create_background(
-        color_from_hexstr(color));
+    return create_background(hexstr(color));
 }
 
 void destroy_background(Background *background)
 {
-    assert(background);
+    trace_assert(background);
     RETURN_LT0(background->lt);
 }
 
@@ -68,8 +69,8 @@ void destroy_background(Background *background)
 int background_render(const Background *background,
                       Camera *camera)
 {
-    assert(background);
-    assert(camera);
+    trace_assert(background);
+    trace_assert(camera);
 
     if (camera_clear_background(
             camera,
@@ -115,8 +116,8 @@ int background_render(const Background *background,
 
 static void chunk_of_point(Point p, int *x, int *y)
 {
-    assert(x);
-    assert(y);
+    trace_assert(x);
+    trace_assert(y);
     *x = (int) (p.x / BACKGROUND_CHUNK_WIDTH);
     *y = (int) (p.y / BACKGROUND_CHUNK_HEIGHT);
 }