6 #include "game/sprite_font.h"
8 #include "math/point.h"
10 #include "system/error.h"
11 #include "system/lt.h"
17 const Sprite_font *font;
26 Log *create_log(const Sprite_font *font,
36 Log *log = PUSH_LT(lt, malloc(sizeof(Log)), free);
38 throw_error(ERROR_TYPE_LIBC);
43 log->font_size = font_size;
44 log->font_color = font_color;
45 log->capacity = capacity;
47 log->buffer = PUSH_LT(lt, calloc(capacity, sizeof(char*)), free);
48 if (log->buffer == NULL) {
49 throw_error(ERROR_TYPE_LIBC);
57 void destroy_log(Log *log)
63 int log_render(const Log *log,
64 SDL_Renderer *renderer,
71 for (size_t i = 0; log->capacity; ++i) {
72 const size_t j = (i + log->cursor) % log->capacity;
74 if (sprite_font_render_text(log->font,
77 vec(0.0f, FONT_CHAR_HEIGHT * log->font_size.y * (float) i)),
80 log->buffer[j]) < 0) {
89 int log_push_line(Log *log, const char *line)
94 if (log->buffer[log->cursor] == NULL) {
95 log->buffer[log->cursor] = string_duplicate(line, NULL);