diff options
| author | pryazha <pryadeiniv@mail.ru> | 2025-10-12 15:25:23 +0500 |
|---|---|---|
| committer | pryazha <pryadeiniv@mail.ru> | 2025-10-12 15:25:23 +0500 |
| commit | 818f818f583881156eb279c71b1359bf2c4f3580 (patch) | |
| tree | 874e8d2fdc5334bc70925aa87923791f7662ddb8 /phys.h | |
| parent | 3cf987880e384140bf996c37f820ddeea38bc60e (diff) | |
change identation, maybe will change back, add own gl functions loading, and glx example
Diffstat (limited to 'phys.h')
| -rw-r--r-- | phys.h | 130 |
1 files changed, 65 insertions, 65 deletions
@@ -1,95 +1,95 @@ i32 add_entity(entity_t entity, elist_t *list) { - assert(list); - i32 i; - for (i = 0; i < MAX_ENTITIES; ++i) - if (!list->nodes[i].id) - break; - if (i == MAX_ENTITIES) { - printf("error: failed to add entity\n"); - return 0; - } - ++list->count; - enode_t *node = list->nodes+i; - node->id = list->count; - node->entity = entity; - dllpushback(list->first, list->last, node); - return node->id; + assert(list); + i32 i; + for (i = 0; i < MAX_ENTITIES; ++i) + if (!list->nodes[i].id) + break; + if (i == MAX_ENTITIES) { + printf("error: failed to add entity\n"); + return 0; + } + ++list->count; + enode_t *node = list->nodes+i; + node->id = list->count; + node->entity = entity; + dllpushback(list->first, list->last, node); + return node->id; } void delete_entity(i32 id, elist_t *list) { - assert(list); - for (enode_t *node = list->first; node; node = node->next) { - if (node->id == id) { - dllremove(list->first, list->last, node); - memzero_struct(node); - list->count--; - printf("info: entity %d deleted\n", id); - return; - } - } - printf("error: entity %d failed to delete\n", id); + assert(list); + for (enode_t *node = list->first; node; node = node->next) { + if (node->id == id) { + dllremove(list->first, list->last, node); + memzero_struct(node); + list->count--; + printf("info: entity %d deleted\n", id); + return; + } + } + printf("error: entity %d failed to delete\n", id); } entity_t *get_entity(elist_t list, i32 id) { - for (enode_t *node = list.first; node; node = node->next) - if (node->id == id) - return &node->entity; - return 0; + for (enode_t *node = list.first; node; node = node->next) + if (node->id == id) + return &node->entity; + return 0; } i32 aabb3d(bbox_t a, bbox_t b) { - i32 result = ((b.start.x <= a.end.x) && (b.end.x >= a.start.x)) && - ((b.start.y <= a.end.y) && (b.end.y >= a.start.y)) && - ((b.start.z <= a.end.z) && (b.end.z >= a.start.z)); - return result; + i32 result = ((b.start.x <= a.end.x) && (b.end.x >= a.start.x)) && + ((b.start.y <= a.end.y) && (b.end.y >= a.start.y)) && + ((b.start.z <= a.end.z) && (b.end.z >= a.start.z)); + return result; } i32 check_collision(entity_t *a, entity_t *b) { - if (!(a->flags & ENTITY_COLLIDE) || !(b->flags & ENTITY_COLLIDE)) - return 0; + if (!(a->flags & ENTITY_COLLIDE) || !(b->flags & ENTITY_COLLIDE)) + return 0; - bbox_t bboxa = { - v3_add(a->bbox.start, a->position), - v3_add(a->bbox.end, a->position) - }; + bbox_t bboxa = { + v3_add(a->bbox.start, a->position), + v3_add(a->bbox.end, a->position) + }; - bbox_t bboxb = { - v3_add(b->bbox.start, b->position), - v3_add(b->bbox.end, b->position) - }; + bbox_t bboxb = { + v3_add(b->bbox.start, b->position), + v3_add(b->bbox.end, b->position) + }; - i32 result = aabb3d(bboxa, bboxb); + i32 result = aabb3d(bboxa, bboxb); - return result; + return result; } entity_t move_entity(entity_t old, v3 acceleration, float dt) { - entity_t new = old; - new.position = v3_add(old.position, v3_scalef(old.velocity, dt)); - new.velocity = v3_add(old.velocity, v3_scalef(acceleration, dt*dt)); - new.velocity = v3_sub(new.velocity, v3_scalef(V3_UP, dt)); - return new; + entity_t new = old; + new.position = v3_add(old.position, v3_scalef(old.velocity, dt)); + new.velocity = v3_add(old.velocity, v3_scalef(acceleration, dt*dt)); + new.velocity = v3_sub(new.velocity, v3_scalef(V3_UP, dt)); + return new; } /* -void update_entities(elist_t list) -{ - for (enode_t *node = list.first; node; node = node->next) { - if (node->entity.flags & ENTITY_MOVE) - move_entity(node->entity, ); - if (node->entity.flags & ENTITY_COLLIDE) { - for (enode_t *test = list.first; test; test = test->next) { - if (check_collision(node->entity, test->entity)) { + void update_entities(elist_t list) + { + for (enode_t *node = list.first; node; node = node->next) { + if (node->entity.flags & ENTITY_MOVE) + move_entity(node->entity, ); + if (node->entity.flags & ENTITY_COLLIDE) { + for (enode_t *test = list.first; test; test = test->next) { + if (check_collision(node->entity, test->entity)) { - } - } - } - } -} -*/ + } + } + } + } + } + */ |
