return dynarray->data + index * dynarray->element_size;
}
-size_t dynarray_count(const Dynarray *dynarray)
-{
- trace_assert(dynarray);
- return dynarray->count;
-}
-
-void *dynarray_data(Dynarray *dynarray)
-{
- trace_assert(dynarray);
- return dynarray->data;
-}
-
void dynarray_clear(Dynarray *dynarray)
{
trace_assert(dynarray);
return result;
}
-size_t dynarray_count(const Dynarray *dynarray);
-void *dynarray_data(Dynarray *dynarray);
void *dynarray_pointer_at(Dynarray *dynarray, size_t index);
void dynarray_replace_at(Dynarray *dynarray, size_t index, void *element);
void dynarray_copy_to(Dynarray *dynarray, void *dest, size_t index);
trace_assert(boxes);
trace_assert(camera);
- const size_t count = dynarray_count(&boxes->body_ids);
- RigidBodyId *body_ids = dynarray_data(&boxes->body_ids);
- Color *body_colors = dynarray_data(&boxes->body_colors);
+ const size_t count = boxes->body_ids.count;
+ RigidBodyId *body_ids = (RigidBodyId *)boxes->body_ids.data;
+ Color *body_colors = (Color *)boxes->body_colors.data;
for (size_t i = 0; i < count; ++i) {
if (rigid_bodies_render(
{
trace_assert(boxes);
- const size_t count = dynarray_count(&boxes->body_ids);
- RigidBodyId *body_ids = dynarray_data(&boxes->body_ids);
+ const size_t count = boxes->body_ids.count;
+ RigidBodyId *body_ids = (RigidBodyId *)boxes->body_ids.data;
for (size_t i = 0; i < count; ++i) {
if (rigid_bodies_update(boxes->rigid_bodies, body_ids[i], delta_time) < 0) {
trace_assert(boxes);
trace_assert(lava);
- const size_t count = dynarray_count(&boxes->body_ids);
- RigidBodyId *body_ids = dynarray_data(&boxes->body_ids);
+ const size_t count = boxes->body_ids.count;
+ RigidBodyId *body_ids = (RigidBodyId*)boxes->body_ids.data;
for (size_t i = 0; i < count; ++i) {
lava_float_rigid_body(lava, boxes->rigid_bodies, body_ids[i]);
{
trace_assert(boxes);
- const size_t count = dynarray_count(&boxes->body_ids);
- RigidBodyId *body_ids = dynarray_data(&boxes->body_ids);
+ const size_t count = boxes->body_ids.count;
+ RigidBodyId *body_ids = (RigidBodyId*)boxes->body_ids.data;
for (size_t i = 0; i < count; ++i) {
const Rect hitbox = rigid_bodies_hitbox(
{
trace_assert(label_layer);
- Vec2f *positions = dynarray_data(&label_layer->positions);
+ Vec2f *positions = (Vec2f*)label_layer->positions.data;
- const int n = (int) dynarray_count(&label_layer->texts);
+ const int n = (int) label_layer->texts.count;
for (int i = n - 1; i >= 0; --i) {
if (rect_contains_point(
boundary_of_element(
label_layer->id_name_prefix,
label_layer->id_name_counter++);
- size_t n = dynarray_count(&label_layer->ids);
+ size_t n = label_layer->ids.count;
dynarray_push(&label_layer->ids, id);
dynarray_push(&label_layer->positions, &position);
{
trace_assert(label_layer);
trace_assert(undo_history);
- trace_assert(a < dynarray_count(&label_layer->positions));
- trace_assert(b < dynarray_count(&label_layer->positions));
+ trace_assert(a < label_layer->positions.count);
+ trace_assert(b < label_layer->positions.count);
dynarray_swap(&label_layer->ids, a, b);
dynarray_swap(&label_layer->positions, a, b);
return 0;
}
- Color *colors = dynarray_data(&label_layer->colors);
- Vec2f *positions = dynarray_data(&label_layer->positions);
- char *ids = dynarray_data(&label_layer->ids);
- char *texts = dynarray_data(&label_layer->texts);
+ Color *colors = (Color*)label_layer->colors.data;
+ Vec2f *positions = (Vec2f*)label_layer->positions.data;
+ char *ids = (char*)label_layer->ids.data;
+ char *texts = (char*)label_layer->texts.data;
switch (event->type) {
case SDL_MOUSEBUTTONDOWN: {
case SDLK_UP: {
if ((event->key.keysym.mod & KMOD_SHIFT)
&& (label_layer->selection >= 0)
- && ((size_t)(label_layer->selection + 1) < dynarray_count(&label_layer->positions))) {
+ && ((size_t)(label_layer->selection + 1) < label_layer->positions.count)) {
label_layer_swap_elements(
label_layer,
(size_t) label_layer->selection,
case SDLK_DOWN: {
if ((event->key.keysym.mod & KMOD_SHIFT)
&& (label_layer->selection > 0)
- && ((size_t) label_layer->selection < dynarray_count(&label_layer->positions))) {
+ && ((size_t) label_layer->selection < label_layer->positions.count)) {
label_layer_swap_elements(
label_layer,
(size_t) label_layer->selection,
trace_assert(label_layer->selection >= 0);
trace_assert(label_layer->state == LABEL_LAYER_MOVE);
- const size_t n = dynarray_count(&label_layer->positions);
- Vec2f *positions = dynarray_data(&label_layer->positions);
+ const size_t n = label_layer->positions.count;
+ Vec2f *positions = (Vec2f*)label_layer->positions.data;
Rect a = boundary_of_element(
label_layer,
trace_assert(camera);
trace_assert(label_layer->selection >= 0);
- Vec2f *positions = dynarray_data(&label_layer->positions);
+ Vec2f *positions = (Vec2f*)label_layer->positions.data;
switch (event->type) {
case SDL_MOUSEMOTION: {
LABEL_UNDO_PUSH(undo_history, create_label_undo_context(label_layer, LABEL_UNDO_UPDATE));
char *text =
- (char*)dynarray_data(&label_layer->texts) + label_layer->selection * LABEL_LAYER_TEXT_MAX_SIZE;
+ (char*)label_layer->texts.data + label_layer->selection * LABEL_LAYER_TEXT_MAX_SIZE;
memset(text, 0, LABEL_LAYER_TEXT_MAX_SIZE);
memcpy(text, edit_field_as_text(label_layer->edit_field), LABEL_LAYER_TEXT_MAX_SIZE - 1);
label_layer->state = LABEL_LAYER_IDLE;
LABEL_UNDO_PUSH(undo_history, create_label_undo_context(label_layer, LABEL_UNDO_UPDATE));
char *id =
- (char*)dynarray_data(&label_layer->ids) + label_layer->selection * LABEL_LAYER_ID_MAX_SIZE;
+ (char*)label_layer->ids.data + label_layer->selection * LABEL_LAYER_ID_MAX_SIZE;
memset(id, 0, LABEL_LAYER_ID_MAX_SIZE);
memcpy(id, edit_field_as_text(label_layer->edit_field), LABEL_LAYER_ID_MAX_SIZE - 1);
label_layer->state = LABEL_LAYER_IDLE;
size_t index, size_t index2)
{
trace_assert(point_layer);
- trace_assert(index < dynarray_count(&point_layer->positions));
- trace_assert(index2 < dynarray_count(&point_layer->positions));
+ trace_assert(index < point_layer->positions.count);
+ trace_assert(index2 < point_layer->positions.count);
PointUndoContext undo_context;
undo_context.type = POINT_UNDO_SWAP;
size_t index =
type == POINT_UNDO_ADD
- ? dynarray_count(&point_layer->positions) - 1
+ ? point_layer->positions.count - 1
: (size_t) point_layer->selection;
undo_context.type = type;
{
trace_assert(point_layer);
trace_assert(undo_history);
- trace_assert(a < dynarray_count(&point_layer->positions));
- trace_assert(b < dynarray_count(&point_layer->positions));
+ trace_assert(a < point_layer->positions.count);
+ trace_assert(b < point_layer->positions.count);
dynarray_swap(&point_layer->positions, a, b);
dynarray_swap(&point_layer->colors, a, b);
color_picker_rgba(&point_layer->color_picker),
undo_history);
} else {
- Color *colors = dynarray_data(&point_layer->colors);
- Vec2f *positions = dynarray_data(&point_layer->positions);
+ Color *colors = (Color*)point_layer->colors.data;
+ Vec2f *positions = (Vec2f*)point_layer->positions.data;
point_layer->state = POINT_LAYER_MOVE;
point_layer->color_picker =
case SDLK_UP: {
if ((event->key.keysym.mod & KMOD_SHIFT)
&& (point_layer->selection >= 0)
- && ((size_t)(point_layer->selection + 1) < dynarray_count(&point_layer->positions))) {
+ && ((size_t)(point_layer->selection + 1) < point_layer->positions.count)) {
point_layer_swap_elements(
point_layer,
(size_t) point_layer->selection,
case SDLK_DOWN: {
if ((event->key.keysym.mod & KMOD_SHIFT)
&& (point_layer->selection > 0)
- && ((size_t) point_layer->selection < dynarray_count(&point_layer->positions))) {
+ && ((size_t) point_layer->selection < point_layer->positions.count)) {
point_layer_swap_elements(
point_layer,
(size_t) point_layer->selection,
} break;
case SDLK_DELETE: {
- if (0 <= point_layer->selection && point_layer->selection < (int) dynarray_count(&point_layer->positions)) {
+ if (0 <= point_layer->selection && point_layer->selection < (int) point_layer->positions.count) {
point_layer_delete_nth_element(
point_layer,
(size_t)point_layer->selection,
case SDLK_F2: {
if (point_layer->selection >= 0) {
- char *ids = dynarray_data(&point_layer->ids);
+ char *ids = (char*)point_layer->ids.data;
point_layer->state = POINT_LAYER_EDIT_ID;
edit_field_replace(
point_layer->edit_field,
trace_assert(camera);
trace_assert(point_layer->selection >= 0);
- Vec2f *positions = dynarray_data(&point_layer->positions);
+ Vec2f *positions = (Vec2f*)point_layer->positions.data;
switch (event->type) {
case SDL_MOUSEBUTTONUP: {
trace_assert(layer);
int n = (int) layer->rects.count;
- Rect *rects = dynarray_data(&layer->rects);
+ Rect *rects = (Rect*)layer->rects.data;
for (int i = n - 1; i >= 0; --i) {
if (rect_contains_point(rects[i], position)) {
return 0;
}
- Rect *rects = dynarray_data(&layer->rects);
+ Rect *rects = (Rect*)layer->rects.data;
switch (event->type) {
case SDL_MOUSEBUTTONDOWN: {
rect_layer_rect_at(layer, position);
- Color *colors = dynarray_data(&layer->colors);
+ Color *colors = (Color*)layer->colors.data;
if (layer->selection >= 0 &&
layer->selection == rect_at_position &&
case SDLK_F2: {
if (layer->selection >= 0) {
- const char *ids = dynarray_data(&layer->ids);
- Color *colors = dynarray_data(&layer->colors);
+ const char *ids = (char*)layer->ids.data;
+ Color *colors = (Color*)layer->colors.data;
edit_field_restyle(
layer->id_edit_field,
if (!layer->snapping_enabled) return;
- Rect *rects = dynarray_data(&layer->rects);
- size_t rects_size = dynarray_count(&layer->rects);
+ Rect *rects = (Rect*)layer->rects.data;
+ size_t rects_size = layer->rects.count;
for (size_t i = 0; i < rects_size; ++i) {
if (i == (size_t) layer->selection) continue;
trace_assert(camera);
trace_assert(layer->selection >= 0);
- Rect *rects = dynarray_data(&layer->rects);
+ Rect *rects = (Rect*)layer->rects.data;
float scaled_snap_threshold = SNAPPING_THRESHOLD / camera->scale;
if (!layer->snapping_enabled) return;
- Rect *rects = dynarray_data(&layer->rects);
- size_t rects_size = dynarray_count(&layer->rects);
+ Rect *rects = (Rect*)layer->rects.data;
+ size_t rects_size = layer->rects.count;
for (size_t i = 0; i < rects_size; ++i) {
if (i == (size_t) layer->selection) continue;
trace_assert(camera);
trace_assert(layer->selection >= 0);
- Rect *rects = dynarray_data(&layer->rects);
+ Rect *rects = (Rect*)layer->rects.data;
switch (event->type) {
case SDL_MOUSEMOTION: {