JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
minimum frame time: 100ms, sprites grid includes just off the right/bottom,
authorJason Woofenden <jason183@herkamire.com>
Tue, 1 May 2007 10:14:10 +0000 (06:14 -0400)
committerJason Woofenden <jason183@herkamire.com>
Tue, 1 May 2007 10:14:10 +0000 (06:14 -0400)
file.c
main.c
sprite.c
sprite.h

diff --git a/file.c b/file.c
index 3a02b81..40d11fa 100644 (file)
--- a/file.c
+++ b/file.c
@@ -113,7 +113,7 @@ find_data_dir(void)
 
        fprintf(stderr, "Can't find VoR data! Tried:\n");
        for(i=0; i<3; i++) {
-               fprintf(stderr, "\t%s\n", data_options[i]);
+               if(data_options[i]) fprintf(stderr, "\t%s\n", data_options[i]);
        }
        return false;
 }
diff --git a/main.c b/main.c
index 1bb6bc1..276cf3a 100644 (file)
--- a/main.c
+++ b/main.c
@@ -619,8 +619,8 @@ gameloop() {
        for(;;) {
                ms_frame = SDL_GetTicks() - ms_end;
                ms_end += ms_frame;
-               if(ms_frame > 1000) {
-                       ms_frame = 1000;
+               if(ms_frame > 100) {
+                       ms_frame = 100;
                }
                t_frame = gamespeed * ms_frame / 50;
                frames++;
@@ -770,7 +770,7 @@ main(int argc, char **argv) {
        frames = 0;
        gameloop();
        end = SDL_GetTicks();
-       // printf("%ld frames in %ld ms, %.2f fps.\n", frames, end-start, frames * 1000.0 / (end-start));
+       printf("%ld frames in %ld ms, %.2f fps.\n", frames, end-start, frames * 1000.0 / (end-start));
 
        return 0;
 }
index 3898123..4e249c3 100644 (file)
--- a/sprite.c
+++ b/sprite.c
@@ -88,8 +88,8 @@ init_sprites(void)
        load_sprites();
 
        grid_size = grid_size * 3 / 2;
-       gw = (XSIZE-1 + 2*grid_size) / grid_size;
-       gh = (YSIZE-1 + 2*grid_size) / grid_size;
+       gw = (XSIZE + 2*grid_size) / grid_size; // -grid-size to XSIZE inclusive (so sprites can be just off either edge)
+       gh = (YSIZE + 2*grid_size) / grid_size;
 
        sprites[0] = malloc(2 * gw * gh * sizeof(Sprite *));
        sprites[1] = (void *)sprites[0] + gw * gh * sizeof(Sprite *);
@@ -105,6 +105,10 @@ static inline Sprite **
 square(int x, int y, int set)
 {
        int b = (x+grid_size)/grid_size + gw*((y+grid_size)/grid_size);
+       if(b >= gw*gh || b < 0) {
+               fprintf(stderr, "square(%i, %i, %i) = %i\n", x, y, set, b);
+               ((int*)0)[0] = 0;
+       }
        return &sprites[set][b];
 }
 
@@ -165,6 +169,8 @@ move_sprites(void)
 }
 
 
+// xov: number of bits of overlap
+// bit: number of bits in from the left edge of amask where bmask is
 static int
 line_collide(int xov, unsigned bit, uint32_t *amask, uint32_t *bmask)
 {
@@ -182,6 +188,8 @@ line_collide(int xov, unsigned bit, uint32_t *amask, uint32_t *bmask)
        return false;
 }
 
+// xov: number of bits/pixels of horizontal overlap
+// yov: number of bits/pixels of vertical overlap
 static int
 mask_collide(int xov, int yov, Sprite *a, Sprite *b)
 {
@@ -250,44 +258,6 @@ collisions(void)
        }
 }
 
-Sprite *
-hit_in_square(Sprite *r, Sprite *s)
-{
-       for(; r; r=r->next)
-               if(collide(r, s)) break;
-       return r;
-}
-
-Sprite *
-collides(Sprite *s)
-{
-       int l, r, t, b;
-       Sprite **sq;
-       Sprite *c;
-
-       l = (s->x + grid_size) / grid_size;
-       r = (s->x + s->w + grid_size) / grid_size;
-       t = (s->y + grid_size) / grid_size;
-       b = (s->y + s->h + grid_size) / grid_size;
-       sq = &sprites[set][l + t*gw];
-
-       if((c = hit_in_square(*sq, s))) return c;
-       if(l > 0 && (c = hit_in_square(*(sq-1), s))) return c;
-       if(t > 0 && (c = hit_in_square(*(sq-gw), s))) return c;
-       if(l > 0 && t > 0 && (c = hit_in_square(*(sq-1-gw), s))) return c;
-
-       if(r > l) {
-               if((c = hit_in_square(*(sq+1), s))) return c;
-               if(t > 0 && hit_in_square(*(sq+1-gw), s)) return c;
-       }
-       if(b > t) {
-               if((c = hit_in_square(*(sq+gw), s))) return c;
-               if(l > 0 && (c = hit_in_square(*(sq-1+gw), s))) return c;
-       }
-       if(r > l && b > t && (c = hit_in_square(*(sq+1+gw), s))) return c;
-       return NULL;
-}
-
 int
 pixel_collide(Sprite *s, int x, int y)
 {
index c95db83..b858e5a 100644 (file)
--- a/sprite.h
+++ b/sprite.h
@@ -44,7 +44,6 @@ void add_sprite(Sprite *s);
 void move_sprite(Sprite *s);
 void move_sprites(void);
 
-Sprite *collides(Sprite *s);
 Sprite * pixel_collides(float x, float y);
 void load_sprite(Sprite *sprite, char *filename);