From 953782576764dc42ba2abfc1097255f53060ce71 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Tue, 19 Feb 2013 14:27:16 -0500 Subject: Add struct map * member to struct area. --- diff --git a/src/area.c b/src/area.c index c01d826..12cbc6c 100644 --- a/src/area.c +++ b/src/area.c @@ -4,9 +4,8 @@ #include "resources/map.h" #include "logging.h" -static void blit_map_layers(struct map *, struct area *); -static void blit_map_layer(struct map *, enum map_layer_id, - struct area *, enum area_layer_id); +static void blit_map_layers(struct area *); +static void blit_map_layer(struct area *, enum map_layer, enum area_layer); struct area * area_new(struct map *map) @@ -18,40 +17,41 @@ area_new(struct map *map) return NULL; } - blit_map_layers(map, a); + a->map = map; + blit_map_layers(a); return a; } static void -blit_map_layers(struct map *map, struct area *area) +blit_map_layers(struct area *area) { area->map_layers[AREA_LAYER_BOT] = SDL_CreateRGBSurface( SDL_HWSURFACE | SDL_SRCCOLORKEY, - map->width * map->tilewidth, - map->height * map->tileheight, + area->map->width * area->map->tilewidth, + area->map->height * area->map->tileheight, 32, 0, 0, 0, 0); - blit_map_layer(map, MAP_LAYER_GROUND, area, AREA_LAYER_BOT); - blit_map_layer(map, MAP_LAYER_OBJ_LOW, area, AREA_LAYER_BOT); + blit_map_layer(area, MAP_LAYER_GROUND, AREA_LAYER_BOT); + blit_map_layer(area, MAP_LAYER_OBJ_LOW, AREA_LAYER_BOT); area->map_layers[AREA_LAYER_MID] = SDL_CreateRGBSurface( SDL_HWSURFACE | SDL_SRCCOLORKEY, - map->width * map->tilewidth, - map->height * map->tileheight, + area->map->width * area->map->tilewidth, + area->map->height * area->map->tileheight, 32, 0, 0, 0, 0); - blit_map_layer(map, MAP_LAYER_OBJ_MID, area, AREA_LAYER_MID); + blit_map_layer(area, MAP_LAYER_OBJ_MID, AREA_LAYER_MID); area->map_layers[AREA_LAYER_TOP] = SDL_CreateRGBSurface( SDL_HWSURFACE | SDL_SRCCOLORKEY, - map->width * map->tilewidth, - map->height * map->tileheight, + area->map->width * area->map->tilewidth, + area->map->height * area->map->tileheight, 32, 0, 0, 0, 0); - blit_map_layer(map, MAP_LAYER_OBJ_HIGH, area, AREA_LAYER_TOP); + blit_map_layer(area, MAP_LAYER_OBJ_HIGH, AREA_LAYER_TOP); } static void -blit_map_layer(struct map *map, enum map_layer_id map_layer, - struct area *area, enum area_layer_id area_layer) +blit_map_layer(struct area *area, enum map_layer map_layer, + enum area_layer area_layer) { int i; Uint32 gid; @@ -61,13 +61,14 @@ blit_map_layer(struct map *map, enum map_layer_id map_layer, SDL_Rect tilerect, layerrect; SDL_SetColorKey(area->map_layers[area_layer], SDL_SRCCOLORKEY, 0); - for (i = 0; i < map->width * map->height; ++i) { - gid = map->layers[map_layer].tiles[i]; + for (i = 0; i < area->map->width * area->map->height; ++i) { + gid = area->map->layers[map_layer].tiles[i]; if (gid == 0) { continue; } tile_found = 0; - for (mts = map->tilesets_head; mts != NULL; mts = mts->next) { + for (mts = area->map->tilesets_head; + mts != NULL; mts = mts->next) { mts_lastgid = mts->firstgid + mts->tileset->width * mts->tileset->height; if (gid >= mts->firstgid && gid < mts_lastgid) { @@ -78,8 +79,8 @@ blit_map_layer(struct map *map, enum map_layer_id map_layer, tilerect.h = mts->tileset->tileheight; tilerect.x *= tilerect.w; tilerect.y *= tilerect.h; - layerrect.x = i % map->width; - layerrect.y = i / map->width; + layerrect.x = i % area->map->width; + layerrect.y = i / area->map->width; layerrect.w = mts->tileset->tilewidth; layerrect.h = mts->tileset->tileheight; layerrect.x *= layerrect.w; diff --git a/src/area.h b/src/area.h index 84987b7..8fee049 100644 --- a/src/area.h +++ b/src/area.h @@ -5,13 +5,14 @@ #include "viewport.h" #include "resources/map.h" -enum area_layer_id { +enum area_layer { AREA_LAYER_BOT = 0, AREA_LAYER_MID, AREA_LAYER_TOP, AREA_LAYERS_MAX }; struct area { + struct map *map; SDL_Surface *map_layers[AREA_LAYERS_MAX]; }; diff --git a/src/resources/map.h b/src/resources/map.h index 267eb30..2f4a60e 100644 --- a/src/resources/map.h +++ b/src/resources/map.h @@ -5,7 +5,7 @@ #include "resource.h" #include "image.h" -enum map_layer_id { +enum map_layer { MAP_LAYER_GROUND = 0, MAP_LAYER_OBJ_LOW, MAP_LAYER_OBJ_MID, -- cgit v0.9.1