aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/game.c1
-rw-r--r--src/main.c5
-rw-r--r--src/physics.c46
3 files changed, 34 insertions, 18 deletions
diff --git a/src/game.c b/src/game.c
index 0834dfb..bf301c4 100644
--- a/src/game.c
+++ b/src/game.c
@@ -14,6 +14,7 @@
#endif
#include <stdlib.h>
+#include <SDL.h>
#include "types.h"
#include "model.h"
diff --git a/src/main.c b/src/main.c
index dc1925f..26f0cb6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -168,13 +168,12 @@ int main(int argc, char *argv[]) {
/* Main loop */
finished = 0;
- t = SDL_GetTicks();
while ( !finished ) {
/* Timer advances only when game is not paused */
- t = SDL_GetTicks();
- if ( game->paused ) {
+ if ( !game->paused ) {
game->tlast = t;
+ t = SDL_GetTicks();
}
SDL_PollEvent(&event);
diff --git a/src/physics.c b/src/physics.c
index cfbdf7e..ec4334f 100644
--- a/src/physics.c
+++ b/src/physics.c
@@ -200,7 +200,7 @@ static int physics_check_collide(ModelInstance *obj, ModelInstance *other, Uint3
const double vy = obj->vy;
const double vz = obj->vz;
- double ttc_lowest = 100000.0;
+ double ttc_lowest = +INFINITY;
double nxc = 0.0;
double nyc = 0.0;
double nzc = 0.0;
@@ -226,7 +226,12 @@ static int physics_check_collide(ModelInstance *obj, ModelInstance *other, Uint3
}
}
- if ( ttc_lowest < dt ) return 0;
+ if ( ttc_lowest == +INFINITY ) return 0;
+
+ if ( ttc_lowest > dt ) {
+ printf("will collide with %s/%8p, but too far in the future at %5.2f ms\n", other->model->name, other, ttc_lowest);
+ return 0;
+ }
if ( (nxc == 0.0) && (nyc == 0.0) && (nzc == 1.0) ) {
obj->x += obj->vx * ttc_lowest;
@@ -234,34 +239,42 @@ static int physics_check_collide(ModelInstance *obj, ModelInstance *other, Uint3
obj->z += obj->vz * ttc_lowest;
obj->vz = 0.0;
obj->landed = 1;
+ printf("Landed!\n");
} else {
obj->vx = -obj->vx;
obj->vy = -obj->vy;
obj->vz = -obj->vz;
obj->yawspeed = 0.0;
+ printf("Bounce!\n");
}
-
- return 0;
+ return 1;
}
/* Called once for each object which isn't just "scenery" */
static void physics_process(ModelInstance *obj, Uint32 dt, Game *game) {
- Room *room;
+ int collided = 0;
+ do {
- /* Consider only the current room */
- room = game_find_room(game, game->cur_room_x, game->cur_room_y, game->cur_room_z);
- if ( room != NULL ) {
- /* Consider all the objects in this room */
- int j;
- for ( j=0; j<room->num_objects; j++ ) {
- if ( physics_check_collide(obj, room->objects[j], dt) ) {
- return;
+ Room *room;
+
+ collided = 0;
+
+ /* Consider only the current room */
+ room = game_find_room(game, game->cur_room_x, game->cur_room_y, game->cur_room_z);
+ if ( room != NULL ) {
+ /* Consider all the objects in this room */
+ int j;
+ for ( j=0; j<room->num_objects; j++ ) {
+ if ( physics_check_collide(obj, room->objects[j], dt) ) { /* Should be dt - ttc */
+ collided = 1;
+ }
}
}
- }
+
+ } while ( collided );
/* Air friction */
if ( obj->vx > 0.0 ) {
@@ -297,7 +310,10 @@ static void physics_process(ModelInstance *obj, Uint32 dt, Game *game) {
}
/* Gravity */
- if ( (obj->attribs & OBJ_GRAVITY) && (!obj->landed) ) obj->vz -= GRAVITY * dt;
+ if ( (obj->attribs & OBJ_GRAVITY) && (!obj->landed) ) {
+ printf("Gravity\n");
+ obj->vz -= GRAVITY * dt;
+ }
/* Take a step */
obj->x += obj->vx * dt;