Quellcode durchsuchen

Pass the map around as a pointer

Streetwalrus Einstein vor 10 Jahren
Ursprung
Commit
2b2dd769b2
3 geänderte Dateien mit 8 neuen und 8 gelöschten Zeilen
  1. 3 3
      include/map.h
  2. 1 1
      src/main.c
  3. 4 4
      src/map.c

+ 3 - 3
include/map.h

@@ -10,8 +10,8 @@ struct Map
 	unsigned *layer1;
 };
 
-void map_draw(unsigned x, unsigned y, const Map_t map);
-unsigned map_collide(unsigned x, unsigned y, const Map_t map);
-void map_walk(unsigned x, unsigned y, Map_t map);
+void map_draw(unsigned x, unsigned y, const Map_t *map);
+unsigned map_collide(unsigned x, unsigned y, const Map_t *map);
+void map_walk(unsigned x, unsigned y, Map_t *map);
 
 #endif

+ 1 - 1
src/main.c

@@ -69,7 +69,7 @@ int main(int argc, char *argv[])
 	map.layer0 = mapdata0;
 	map.layer1 = mapdata1;
 
-	map_walk(7, 5, map);
+	map_walk(7, 5, &map);
 
 	timer_restore(0);
 	buffer_free();

+ 4 - 4
src/map.c

@@ -7,7 +7,7 @@
 static void map_walk_speed_load(unsigned time);
 static unsigned map_walk_speed_read(unsigned time, unsigned div);
 
-void map_draw(unsigned x, unsigned y, const Map_t map)
+void map_draw(unsigned x, unsigned y, const Map_t *map)
 {
 	x += 20;
 	y += 12;
@@ -23,12 +23,12 @@ void map_draw(unsigned x, unsigned y, const Map_t map)
 	for (unsigned j = 0; j < 11; j++)
 	for (unsigned i = 0; i < 15; i++)
 	{
-		sprite.x = map.layer0[(x / 24 - 7 + i) + (y / 24 - 5 + j) * map.w] * 24;
+		sprite.x = map->layer0[(x / 24 - 7 + i) + (y / 24 - 5 + j) * map->w] * 24;
 		draw_sprite_sheet(tiles, offset_x + i * 24, offset_y + j * 24, &sprite);
 	}
 }
 
-unsigned map_collide(unsigned x, unsigned y, const Map_t map)
+unsigned map_collide(unsigned x, unsigned y, const Map_t *map)
 {
 	(void) x;
 	(void) y;
@@ -47,7 +47,7 @@ static unsigned map_walk_speed_read(unsigned time, unsigned div)
 	return (time - timer_read(0)) / div;
 }
 
-void map_walk(unsigned x, unsigned y, Map_t map)
+void map_walk(unsigned x, unsigned y, Map_t *map)
 {
 	unsigned walk_time, walk_div;