diff options
| author | esquizo <esquizo+noreply@esquizo.net> | 2026-05-09 00:29:54 -0300 |
|---|---|---|
| committer | esquizo <esquizo+noreply@esquizo.net> | 2026-05-09 00:30:06 -0300 |
| commit | a21ae8219e67783c52ba5f415e1ca4745755adb5 (patch) | |
| tree | 73858993c3bb049e34adee70fd1ef8576a46e917 /game.c | |
| parent | 2b8cb91ff3347aa57cbee12e66b37d1a57199d59 (diff) | |
iteração de física
Diffstat (limited to 'game.c')
| -rw-r--r-- | game.c | 43 |
1 files changed, 30 insertions, 13 deletions
@@ -6,7 +6,7 @@ #include "dat.h" -#define SPEED 250 +#define SPEED 100 static EntityCollisionProc bulletcollproc; static EntityCollisionProc ghostcollproc; @@ -25,6 +25,8 @@ static EntityUpdateProc *updateprocs[LASTEntity] = { [EBULLET] = bulletproc, }; +static void physics(float delta); + Entity entitybuffer[2048]; int ebufi; @@ -57,18 +59,7 @@ entinit() void entupdate(float delta) { - EntityCollision *coll; - while((coll = deqcoll())) { - Entity *self = coll->self; - Entity *target = coll->target; - - if(collisionProcs[self->type]) - collisionProcs[self->type](self, target); - - if(collisionProcs[target->type]) - collisionProcs[target->type](target, self); - } - + physics(delta); for(int ei = 0; ei < ebufi; ei++) { Entity *e = entitybuffer + ei; if(!e->active) @@ -227,3 +218,29 @@ freeentity(Entity *e) { e->active = false; } + +void +physics(float delta) +{ + #define PHYSICS_TIME (1.0 / 480.0) + + EntityCollision *coll; + + static float time = 0; + + time += delta; + while(time >= PHYSICS_TIME) { + entphysics(PHYSICS_TIME); + while((coll = deqcoll())) { + Entity *self = coll->self; + Entity *target = coll->target; + + if(collisionProcs[self->type]) + collisionProcs[self->type](self, target); + + if(collisionProcs[target->type]) + collisionProcs[target->type](target, self); + } + time -= PHYSICS_TIME; + } +} |
