#include "system/nth_alloc.h"
#include "system/log.h"
#include "undo_history.h"
+#include "system/memory.h"
typedef struct {
PlayerLayer *layer;
return create_player_layer(position, hexstr(colorstr));
}
+PlayerLayer chop_player_layer(Memory *memory, String *input)
+{
+ trace_assert(memory);
+ trace_assert(input);
+
+ String line = chop_by_delim(input, '\n');
+ float x = strtof(string_to_cstr(memory, chop_word(&line)), NULL);
+ float y = strtof(string_to_cstr(memory, chop_word(&line)), NULL);
+ Color color = hexs(chop_word(&line));
+
+ return create_player_layer(vec(x, y), color);
+}
+
LayerPtr player_layer_as_layer(PlayerLayer *player_layer)
{
LayerPtr layer = {
#include "layer.h"
#include "system/lt.h"
#include "system/line_stream.h"
+#include "system/memory.h"
+#include "system/s.h"
typedef struct {
Vec2f position;
PlayerLayer create_player_layer(Vec2f position, Color color);
PlayerLayer create_player_layer_from_line_stream(LineStream *line_stream);
+PlayerLayer chop_player_layer(Memory *memory, String *input);
LayerPtr player_layer_as_layer(PlayerLayer *player_layer);
int player_layer_render(const PlayerLayer *player_layer,
--- /dev/null
+#ifndef MEMORY_H_
+#define MEMORY_H_
+
+#include <assert.h>
+#include <stdint.h>
+
+#define KILO 1024
+#define MEGA (1024 * KILO)
+#define GIGA (1024 * MEGA)
+
+typedef struct {
+ size_t capacity;
+ size_t size;
+ uint8_t *buffer;
+} Memory;
+
+static inline
+void *memory_alloc(Memory *memory, size_t size)
+{
+ assert(memory);
+ assert(memory->size + size <= memory->capacity);
+
+
+ void *result = memory->buffer + memory->size;
+ memory->size += size;
+
+ return result;
+}
+
+static inline
+void memory_clean(Memory *memory)
+{
+ assert(memory);
+ memory->size = 0;
+}
+
+#endif // MEMORY_H_
#ifndef S_H_
#define S_H_
+#include <stdlib.h>
#include <string.h>
#include "system/stacktrace.h"
+#include "system/memory.h"
typedef struct {
size_t count;
return result;
}
+static inline
+char *string_to_cstr(Memory *memory, String s)
+{
+ trace_assert(memory);
+
+ char *result = memory_alloc(memory, s.count + 1);
+ memset(result, 0, s.count + 1);
+ memcpy(result, s.data, s.count);
+ return result;
+}
+
#endif // S_H_