#pragma once #include "util/tree.h" #include "util/vector.h" #include "Types.h" #include #include #ifdef __cplusplus extern "C" { #endif typedef struct _Entity Entity; extern double physics_Gravity; // Position component. // // If not exist, it's like it's at (0,0) typedef struct { Entity *super; Vec2 position; Vec2 velocity; } Component_Position; // Handler called when hitboxes are hit typedef void (*physics_HitHandler)(Entity *me, Entity *other, Vec2 triedDelta); // Box is relative to Position if exists // if not, Box is absolute // // Moving hitboxes only hits fixed hitboxes typedef struct { Entity *super; Box2 box; bool fixed; physics_HitHandler onHit; } Component_Hitbox; // Returns the absolute version of the hitbox. Box2 physics_HitboxAbsolute(Component_Hitbox *hitbox); // Physics manager typedef struct { // Every Position & Hitbox components tree_Tree *pos, *hit; vector_Vector *flaggedDelete; } System_Physics; // Returns an empty physics system. System_Physics *physics_NewSystem(); // Frees a physics system. void physics_DeleteSystem(System_Physics *sys); // Adds an entity. void physics_AddEntity(System_Physics *sys, Entity *e); // Deletes an entity. void physics_DeleteEntity(System_Physics *sys, uintptr_t id); // Advance is called on every frame. void physics_Advance(System_Physics *sys, Duration deltaTime); #ifdef __cplusplus } #endif