diff options
| -rw-r--r-- | game.c | 43 | ||||
| -rw-r--r-- | sdl3_main.c | 1 |
2 files changed, 31 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; + } +} diff --git a/sdl3_main.c b/sdl3_main.c index a2d12f7..7a0435a 100644 --- a/sdl3_main.c +++ b/sdl3_main.c @@ -36,6 +36,7 @@ main() fprintf(stderr, "SDL_CreateWindowAndRenderer: %s\n", SDL_GetError()); return -1; } + SDL_SetRenderVSync(renderer, 1); entinit(); running = true; |
