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,
35 Log *log = PUSH_LT(lt, malloc(sizeof(Log)), free);
37 throw_error(ERROR_TYPE_LIBC);
42 log->font_size = font_size;
43 log->capacity = capacity;
45 log->buffer = PUSH_LT(lt, calloc(capacity, sizeof(char*)), free);
46 if (log->buffer == NULL) {
47 throw_error(ERROR_TYPE_LIBC);
51 log->colors = PUSH_LT(lt, calloc(capacity, sizeof(Color)), free);
52 if (log->colors == NULL) {
53 throw_error(ERROR_TYPE_LIBC);
62 void destroy_log(Log *log)
65 for (size_t i = 0; i < log->capacity; ++i) {
73 int log_render(const Log *log,
74 SDL_Renderer *renderer,
81 for (size_t i = 0; i < log->capacity; ++i) {
82 const size_t j = (i + log->cursor) % log->capacity;
84 if (sprite_font_render_text(log->font,
87 vec(0.0f, FONT_CHAR_HEIGHT * log->font_size.y * (float) i)),
90 log->buffer[j]) < 0) {
99 int log_push_line(Log *log, const char *line, Color color)
104 const size_t next_cursor = (log->cursor + 1) % log->capacity;
106 if (log->buffer[log->cursor] != NULL) {
107 free(log->buffer[log->cursor]);
110 log->buffer[log->cursor] = string_duplicate(line, NULL);
111 log->colors[log->cursor] = color;
113 if (log->buffer[log->cursor] == NULL) {
117 log->cursor = next_cursor;