-#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
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);
}
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);
}
int background_render(const Background *background,
Camera *camera)
{
- assert(background);
- assert(camera);
+ trace_assert(background);
+ trace_assert(camera);
if (camera_clear_background(
camera,
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);
}