} Dynarray;
static inline
-Dynarray create_dynarray(size_t element_size)
+Dynarray create_dynarray_malloc(size_t element_size)
{
Dynarray result = {
.element_size = element_size,
.count = 0,
.data = malloc(DYNARRAY_CAPACITY * element_size)
};
+ trace_assert(result.data);
return result;
}
static inline
-Dynarray create_dynarray_from_memory(Memory *memory, size_t element_size)
+Dynarray create_dynarray(Memory *memory, size_t element_size)
{
trace_assert(memory);
Dynarray result = {
}
boxes->lt = lt;
- boxes->boxes_ids = create_dynarray(ENTITY_MAX_ID_SIZE);
- boxes->body_ids = create_dynarray(sizeof(RigidBodyId));
- boxes->body_colors = create_dynarray(sizeof(Color));
+ boxes->boxes_ids = create_dynarray_malloc(ENTITY_MAX_ID_SIZE);
+ boxes->body_ids = create_dynarray_malloc(sizeof(RigidBodyId));
+ boxes->body_colors = create_dynarray_malloc(sizeof(Color));
boxes->rigid_bodies = rigid_bodies;
return layer;
}
-LabelLayer create_label_layer(const char *id_name_prefix)
-{
- LabelLayer result = {0};
- result.ids = create_dynarray(sizeof(char) * LABEL_LAYER_ID_MAX_SIZE);
- result.positions = create_dynarray(sizeof(Vec2f));
- result.colors = create_dynarray(sizeof(Color));
- result.texts = create_dynarray(sizeof(char) * LABEL_LAYER_TEXT_MAX_SIZE);
- result.color_picker = create_color_picker_from_rgba(COLOR_RED);
- result.selection = -1;
- result.edit_field.font_size = LABELS_SIZE;
- result.edit_field.font_color = COLOR_RED;
- result.id_name_prefix = id_name_prefix;
- return result;
-}
-
LabelLayer *create_label_layer_from_memory(Memory *memory,
const char *id_name_prefix)
{
LabelLayer *result = memory_alloc(memory, sizeof(LabelLayer));
memset(result, 0, sizeof(LabelLayer));
- result->ids = create_dynarray_from_memory(memory, sizeof(char) * LABEL_LAYER_ID_MAX_SIZE);
- result->positions = create_dynarray_from_memory(memory, sizeof(Vec2f));
- result->colors = create_dynarray_from_memory(memory, sizeof(Color));
- result->texts = create_dynarray_from_memory(memory, sizeof(char) * LABEL_LAYER_TEXT_MAX_SIZE);
+ result->ids = create_dynarray(memory, sizeof(char) * LABEL_LAYER_ID_MAX_SIZE);
+ result->positions = create_dynarray(memory, sizeof(Vec2f));
+ result->colors = create_dynarray(memory, sizeof(Color));
+ result->texts = create_dynarray(memory, sizeof(char) * LABEL_LAYER_TEXT_MAX_SIZE);
result->color_picker = create_color_picker_from_rgba(COLOR_RED);
result->selection = -1;
result->edit_field.font_size = LABELS_SIZE;
return layer;
}
-PointLayer create_point_layer(const char *id_name_prefix)
-{
- PointLayer result = {0};
- result.state = POINT_LAYER_IDLE;
- result.positions = create_dynarray(sizeof(Vec2f));
- result.colors = create_dynarray(sizeof(Color));
- result.ids = create_dynarray(sizeof(char) * ID_MAX_SIZE);
- result.edit_field.font_size = POINT_LAYER_ID_TEXT_SIZE;
- result.edit_field.font_color = POINT_LAYER_ID_TEXT_COLOR;
- result.id_name_prefix = id_name_prefix;
- return result;
-}
-
PointLayer *create_point_layer_from_memory(Memory *memory,
const char *id_name_prefix)
{
PointLayer *result = memory_alloc(memory, sizeof(PointLayer));
memset(result, 0, sizeof(PointLayer));
result->state = POINT_LAYER_IDLE;
- result->positions = create_dynarray_from_memory(memory, sizeof(Vec2f));
- result->colors = create_dynarray_from_memory(memory, sizeof(Color));
- result->ids = create_dynarray_from_memory(memory, sizeof(char) * ID_MAX_SIZE);
+ result->positions = create_dynarray(memory, sizeof(Vec2f));
+ result->colors = create_dynarray(memory, sizeof(Color));
+ result->ids = create_dynarray(memory, sizeof(char) * ID_MAX_SIZE);
result->edit_field.font_size = POINT_LAYER_ID_TEXT_SIZE;
result->edit_field.font_color = POINT_LAYER_ID_TEXT_COLOR;
result->id_name_prefix = id_name_prefix;
RectLayer *rect_layer = memory_alloc(memory, sizeof(RectLayer));
- rect_layer->ids = create_dynarray_from_memory(memory, sizeof(char) * ENTITY_MAX_ID_SIZE);
- rect_layer->rects = create_dynarray_from_memory(memory, sizeof(Rect));
- rect_layer->colors = create_dynarray_from_memory(memory, sizeof(Color));
- rect_layer->actions = create_dynarray_from_memory(memory, sizeof(Action));
+ rect_layer->ids = create_dynarray(memory, sizeof(char) * ENTITY_MAX_ID_SIZE);
+ rect_layer->rects = create_dynarray(memory, sizeof(Rect));
+ rect_layer->colors = create_dynarray(memory, sizeof(Color));
+ rect_layer->actions = create_dynarray(memory, sizeof(Action));
rect_layer->id_edit_field.font_size = RECT_LAYER_ID_LABEL_SIZE;
rect_layer->id_edit_field.font_color = COLOR_BLACK;
rect_layer->color_picker = create_color_picker_from_rgba(rgba(1.0f, 0.0f, 0.0f, 1.0f));
{
dynarray_clear(&level_picker->items);
- level_picker->items = create_dynarray(METADATA_FILEPATH_MAX_SIZE);
+ level_picker->items = create_dynarray_malloc(METADATA_FILEPATH_MAX_SIZE);
DIR *level_dir = opendir(dirpath);
if (level_dir == NULL) {