diff options
author | P. J. McDermott <pjm@nac.net> | 2013-02-19 14:27:16 (EST) |
---|---|---|
committer | P. J. McDermott <pjm@nac.net> | 2013-02-19 14:27:16 (EST) |
commit | 953782576764dc42ba2abfc1097255f53060ce71 (patch) | |
tree | 730af40e39c8a5532a502c85693f182cc0db8883 /src | |
parent | 8a133b5f181e7b6e7f89e5d9f1a362e8ad87e3ad (diff) | |
download | overworld-rpg-953782576764dc42ba2abfc1097255f53060ce71.zip overworld-rpg-953782576764dc42ba2abfc1097255f53060ce71.tar.gz overworld-rpg-953782576764dc42ba2abfc1097255f53060ce71.tar.bz2 |
Add struct map * member to struct area.
Diffstat (limited to 'src')
-rw-r--r-- | src/area.c | 45 | ||||
-rw-r--r-- | src/area.h | 3 | ||||
-rw-r--r-- | src/resources/map.h | 2 |
3 files changed, 26 insertions, 24 deletions
@@ -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; @@ -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, |