]> git.lizzy.rs Git - nothing.git/commitdiff
Remove dynarray_count and dynarray_data
authorrexim <reximkut@gmail.com>
Sun, 8 Dec 2019 22:08:22 +0000 (05:08 +0700)
committerrexim <reximkut@gmail.com>
Sun, 8 Dec 2019 22:08:22 +0000 (05:08 +0700)
src/dynarray.c
src/dynarray.h
src/game/level/boxes.c
src/game/level/level_editor/label_layer.c
src/game/level/level_editor/point_layer.c
src/game/level/level_editor/rect_layer.c

index 87a34c80b89a2044b1d88ed7a1ee760623b18e60..4b2aa9c3d07a5316839830debf079ad21834db87 100644 (file)
@@ -15,18 +15,6 @@ void *dynarray_pointer_at(Dynarray *dynarray, size_t index)
     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);
index 624ea6790d03f69928e139fde66021f1c022a011..aa961defdc8dce4b58879d46b23c4233681eae22 100644 (file)
@@ -23,8 +23,6 @@ Dynarray create_dynarray(size_t element_size)
     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);
index 8b99cc806b8215e2c44ea8c119c2238226b4b995..64bdd893f8eca25add81184c21960e7f9b65f7d8 100644 (file)
@@ -77,9 +77,9 @@ int boxes_render(Boxes *boxes, const Camera *camera)
     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(
@@ -99,8 +99,8 @@ int boxes_update(Boxes *boxes,
 {
     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) {
@@ -116,8 +116,8 @@ void boxes_float_in_lava(Boxes *boxes, Lava *lava)
     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]);
@@ -139,8 +139,8 @@ int boxes_delete_at(Boxes *boxes, Vec2f position)
 {
     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(
index 2fb0b3f2c1494dbf74bfde0a5959baa2c2034be0..12291293f3be0834f9840dc30ee827f98f8bc74c 100644 (file)
@@ -409,9 +409,9 @@ int label_layer_element_at(LabelLayer *label_layer,
 {
     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(
@@ -458,7 +458,7 @@ int label_layer_add_label(LabelLayer *label_layer,
              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);
@@ -481,8 +481,8 @@ void label_layer_swap_elements(LabelLayer *label_layer,
 {
     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);
@@ -520,10 +520,10 @@ int label_layer_idle_event(LabelLayer *label_layer,
         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: {
@@ -573,7 +573,7 @@ int label_layer_idle_event(LabelLayer *label_layer,
         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,
@@ -586,7 +586,7 @@ int label_layer_idle_event(LabelLayer *label_layer,
         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,
@@ -669,8 +669,8 @@ void snap_inter_position(LabelLayer *label_layer, float snap_threshold)
     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,
@@ -705,7 +705,7 @@ int label_layer_move_event(LabelLayer *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: {
@@ -778,7 +778,7 @@ int label_layer_edit_text_event(LabelLayer *label_layer,
             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;
@@ -817,7 +817,7 @@ int label_layer_edit_id_event(LabelLayer *label_layer,
             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;
index 6d536f4ee37ede9f1ca703ae89acc3d229809fcd..0050d95edb7e9b70286dfc2f9499d0331015e226 100644 (file)
@@ -73,8 +73,8 @@ PointUndoContext create_point_undo_swap_context(PointLayer *point_layer,
                                      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;
@@ -96,7 +96,7 @@ PointUndoContext create_point_undo_context(PointLayer *point_layer,
 
     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;
@@ -383,8 +383,8 @@ void point_layer_swap_elements(PointLayer *point_layer,
 {
     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);
@@ -456,8 +456,8 @@ int point_layer_idle_event(PointLayer *point_layer,
                     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 =
@@ -473,7 +473,7 @@ int point_layer_idle_event(PointLayer *point_layer,
         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,
@@ -486,7 +486,7 @@ int point_layer_idle_event(PointLayer *point_layer,
         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,
@@ -497,7 +497,7 @@ int point_layer_idle_event(PointLayer *point_layer,
         } 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,
@@ -508,7 +508,7 @@ int point_layer_idle_event(PointLayer *point_layer,
 
         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,
@@ -598,7 +598,7 @@ int point_layer_move_event(PointLayer *point_layer,
     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: {
index 076335a91b9de8b83a38d249eac2036b457a1038..aa4f75c8f40d07d6e53979415b5267ec92c71088 100644 (file)
@@ -264,7 +264,7 @@ static int rect_layer_rect_at(RectLayer *layer, Vec2f position)
     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)) {
@@ -339,7 +339,7 @@ static int rect_layer_event_idle(RectLayer *layer,
         return 0;
     }
 
-    Rect *rects = dynarray_data(&layer->rects);
+    Rect *rects = (Rect*)layer->rects.data;
 
     switch (event->type) {
     case SDL_MOUSEBUTTONDOWN: {
@@ -353,7 +353,7 @@ static int rect_layer_event_idle(RectLayer *layer,
                 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 &&
@@ -445,8 +445,8 @@ static int rect_layer_event_idle(RectLayer *layer,
 
         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,
@@ -542,8 +542,8 @@ void snap_rect_resize_if_enabled(RectLayer *layer, Rect *a, float snapping_thres
 
     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;
@@ -570,7 +570,7 @@ static int rect_layer_event_resize(RectLayer *layer,
     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;
 
@@ -716,8 +716,8 @@ void snap_rect_move_if_enabled(RectLayer *layer, Rect *a,
 
     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;
@@ -744,7 +744,7 @@ static int rect_layer_event_move(RectLayer *layer,
     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: {