src/system/lt/lt_adapters.c
src/system/lt/lt_slot.c
src/ui/console.c
- src/ui/log.c
+ src/ui/console_log.c
src/str.c
src/ui/history.c
src/game/level/regions.c
src/system/lt/lt_adapters.h
src/system/lt/lt_slot.h
src/ui/console.h
- src/ui/log.h
+ src/ui/console_log.h
src/str.h
src/ui/history.h
src/game/level/regions.h
#include "ui/console.h"
#include "ui/edit_field.h"
#include "ui/history.h"
-#include "ui/log.h"
+#include "ui/console_log.h"
#define FONT_WIDTH_SCALE 3.0f
#define FONT_HEIGHT_SCALE 3.0f
-#define LOG_CAPACITY 10
+#define CONSOLE_LOG_CAPACITY 10
#define HISTORY_CAPACITY 20
#define PROMPT_HEIGHT (FONT_HEIGHT_SCALE * FONT_CHAR_HEIGHT)
-#define LOG_HEIGHT (FONT_HEIGHT_SCALE * FONT_CHAR_HEIGHT * LOG_CAPACITY)
+#define CONSOLE_LOG_HEIGHT (FONT_HEIGHT_SCALE * FONT_CHAR_HEIGHT * CONSOLE_LOG_CAPACITY)
-#define CONSOLE_HEIGHT (LOG_HEIGHT + PROMPT_HEIGHT)
+#define CONSOLE_HEIGHT (CONSOLE_LOG_HEIGHT + PROMPT_HEIGHT)
#define SLIDE_DOWN_TIME 0.4f
Gc *gc;
struct Scope scope;
Edit_field *edit_field;
- Log *log;
+ Console_Log *console_log;
Level *level;
History *history;
float a;
RETURN_LT(lt, NULL);
}
- console->log = PUSH_LT(
+ console->console_log = PUSH_LT(
lt,
- create_log(
+ create_console_log(
font,
vec(FONT_WIDTH_SCALE, FONT_HEIGHT_SCALE),
- LOG_CAPACITY),
- destroy_log);
+ CONSOLE_LOG_CAPACITY),
+ destroy_console_log);
console->level = level;
console->a = 0;
return -1;
}
- if (log_push_line(console->log, source_code, CONSOLE_FOREGROUND) < 0) {
+ if (console_log_push_line(console->console_log, source_code, CONSOLE_FOREGROUND) < 0) {
return -1;
}
source_code);
if (parse_result.is_error) {
- if (log_push_line(console->log, parse_result.error_message, CONSOLE_ERROR)) {
+ if (console_log_push_line(console->console_log, parse_result.error_message, CONSOLE_ERROR)) {
return -1;
}
return -1;
}
- if (log_push_line(console->log,
+ if (console_log_push_line(console->console_log,
console->eval_result,
eval_result.is_error ?
CONSOLE_ERROR :
return -1;
}
- if (log_render(console->log,
+ if (console_log_render(console->console_log,
renderer,
vec(0.0f, y)) < 0) {
return -1;
if (edit_field_render(console->edit_field,
renderer,
- vec(0.0f, y + LOG_HEIGHT)) < 0) {
+ vec(0.0f, y + CONSOLE_LOG_HEIGHT)) < 0) {
return -1;
}
--- /dev/null
+#include <assert.h>
+#include <stdlib.h>
+#include <SDL2/SDL.h>
+
+#include "color.h"
+#include "game/sprite_font.h"
+#include "console_log.h"
+#include "math/point.h"
+#include "str.h"
+#include "system/error.h"
+#include "system/lt.h"
+#include "system/nth_alloc.h"
+
+struct Console_Log
+{
+ Lt *lt;
+
+ const Sprite_font *font;
+ Vec font_size;
+
+ Color *colors;
+ char **buffer;
+ size_t cursor;
+ size_t capacity;
+};
+
+Console_Log *create_console_log(const Sprite_font *font,
+ Vec font_size,
+ size_t capacity)
+{
+ Lt *lt = create_lt();
+ if (lt == NULL) {
+ return NULL;
+ }
+
+ Console_Log *console_log = PUSH_LT(lt, nth_alloc(sizeof(Console_Log)), free);
+ if (console_log == NULL) {
+ throw_error(ERROR_TYPE_LIBC);
+ RETURN_LT(lt, NULL);
+ }
+ console_log->lt = lt;
+ console_log->font = font;
+ console_log->font_size = font_size;
+ console_log->capacity = capacity;
+
+ console_log->buffer = PUSH_LT(lt, calloc(capacity, sizeof(char*)), free);
+ if (console_log->buffer == NULL) {
+ throw_error(ERROR_TYPE_LIBC);
+ RETURN_LT(lt, NULL);
+ }
+
+ console_log->colors = PUSH_LT(lt, calloc(capacity, sizeof(Color)), free);
+ if (console_log->colors == NULL) {
+ throw_error(ERROR_TYPE_LIBC);
+ RETURN_LT(lt, NULL);
+ }
+
+ console_log->cursor = 0;
+
+ return console_log;
+}
+
+void destroy_console_log(Console_Log *console_log)
+{
+ assert(console_log);
+ for (size_t i = 0; i < console_log->capacity; ++i) {
+ if (console_log->buffer[i]) {
+ free(console_log->buffer[i]);
+ }
+ }
+ RETURN_LT0(console_log->lt);
+}
+
+int console_log_render(const Console_Log *console_log,
+ SDL_Renderer *renderer,
+ Point position)
+{
+ assert(console_log);
+ assert(renderer);
+ (void) position;
+
+ for (size_t i = 0; i < console_log->capacity; ++i) {
+ const size_t j = (i + console_log->cursor) % console_log->capacity;
+ if (console_log->buffer[j]) {
+ if (sprite_font_render_text(console_log->font,
+ renderer,
+ vec_sum(position,
+ vec(0.0f, FONT_CHAR_HEIGHT * console_log->font_size.y * (float) i)),
+ console_log->font_size,
+ console_log->colors[j],
+ console_log->buffer[j]) < 0) {
+ return -1;
+ }
+ }
+ }
+
+ return 0;
+}
+
+int console_log_push_line(Console_Log *console_log, const char *line, Color color)
+{
+ assert(console_log);
+ assert(line);
+
+ const size_t next_cursor = (console_log->cursor + 1) % console_log->capacity;
+
+ if (console_log->buffer[console_log->cursor] != NULL) {
+ free(console_log->buffer[console_log->cursor]);
+ }
+
+ console_log->buffer[console_log->cursor] = string_duplicate(line, NULL);
+ console_log->colors[console_log->cursor] = color;
+
+ if (console_log->buffer[console_log->cursor] == NULL) {
+ return -1;
+ }
+
+ console_log->cursor = next_cursor;
+
+ return 0;
+}
--- /dev/null
+#ifndef CONSOLE_LOG_H_
+#define CONSOLE_LOG_H_
+
+#include "math/point.h"
+
+typedef struct Console_Log Console_Log;
+
+Console_Log *create_console_log(const Sprite_font *font,
+ Vec font_size,
+ size_t capacity);
+void destroy_console_log(Console_Log *console_log);
+
+int console_log_render(const Console_Log *console_log,
+ SDL_Renderer *renderer,
+ Point position);
+
+int console_log_push_line(Console_Log *console_log,
+ const char *line,
+ Color color);
+
+#endif // CONSOLE_LOG_H_
+++ /dev/null
-#include <assert.h>
-#include <stdlib.h>
-#include <SDL2/SDL.h>
-
-#include "color.h"
-#include "game/sprite_font.h"
-#include "log.h"
-#include "math/point.h"
-#include "str.h"
-#include "system/error.h"
-#include "system/lt.h"
-#include "system/nth_alloc.h"
-
-struct Log
-{
- Lt *lt;
-
- const Sprite_font *font;
- Vec font_size;
-
- Color *colors;
- char **buffer;
- size_t cursor;
- size_t capacity;
-};
-
-Log *create_log(const Sprite_font *font,
- Vec font_size,
- size_t capacity)
-{
- Lt *lt = create_lt();
- if (lt == NULL) {
- return NULL;
- }
-
- Log *log = PUSH_LT(lt, nth_alloc(sizeof(Log)), free);
- if (log == NULL) {
- throw_error(ERROR_TYPE_LIBC);
- RETURN_LT(lt, NULL);
- }
- log->lt = lt;
- log->font = font;
- log->font_size = font_size;
- log->capacity = capacity;
-
- log->buffer = PUSH_LT(lt, calloc(capacity, sizeof(char*)), free);
- if (log->buffer == NULL) {
- throw_error(ERROR_TYPE_LIBC);
- RETURN_LT(lt, NULL);
- }
-
- log->colors = PUSH_LT(lt, calloc(capacity, sizeof(Color)), free);
- if (log->colors == NULL) {
- throw_error(ERROR_TYPE_LIBC);
- RETURN_LT(lt, NULL);
- }
-
- log->cursor = 0;
-
- return log;
-}
-
-void destroy_log(Log *log)
-{
- assert(log);
- for (size_t i = 0; i < log->capacity; ++i) {
- if (log->buffer[i]) {
- free(log->buffer[i]);
- }
- }
- RETURN_LT0(log->lt);
-}
-
-int log_render(const Log *log,
- SDL_Renderer *renderer,
- Point position)
-{
- assert(log);
- assert(renderer);
- (void) position;
-
- for (size_t i = 0; i < log->capacity; ++i) {
- const size_t j = (i + log->cursor) % log->capacity;
- if (log->buffer[j]) {
- if (sprite_font_render_text(log->font,
- renderer,
- vec_sum(position,
- vec(0.0f, FONT_CHAR_HEIGHT * log->font_size.y * (float) i)),
- log->font_size,
- log->colors[j],
- log->buffer[j]) < 0) {
- return -1;
- }
- }
- }
-
- return 0;
-}
-
-int log_push_line(Log *log, const char *line, Color color)
-{
- assert(log);
- assert(line);
-
- const size_t next_cursor = (log->cursor + 1) % log->capacity;
-
- if (log->buffer[log->cursor] != NULL) {
- free(log->buffer[log->cursor]);
- }
-
- log->buffer[log->cursor] = string_duplicate(line, NULL);
- log->colors[log->cursor] = color;
-
- if (log->buffer[log->cursor] == NULL) {
- return -1;
- }
-
- log->cursor = next_cursor;
-
- return 0;
-}
+++ /dev/null
-#ifndef LOG_H_
-#define LOG_H_
-
-#include "math/point.h"
-
-// TODO(#481): ui/log unit may collide with system/log unit
-
-typedef struct Log Log;
-
-Log *create_log(const Sprite_font *font,
- Vec font_size,
- size_t capacity);
-void destroy_log(Log *log);
-
-int log_render(const Log *log,
- SDL_Renderer *renderer,
- Point position);
-
-int log_push_line(Log *log,
- const char *line,
- Color color);
-
-#endif // LOG_H_