diff options
Diffstat (limited to 'src/view/MapView.cpp')
-rw-r--r-- | src/view/MapView.cpp | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/src/view/MapView.cpp b/src/view/MapView.cpp index 5e55290..4938c5d 100644 --- a/src/view/MapView.cpp +++ b/src/view/MapView.cpp @@ -32,9 +32,7 @@ namespace RPGEdit { namespace View { MapView::MapView(const std::shared_ptr<Window> &window0, - const std::shared_ptr<const Model::Map> &map0, - const std::vector<SDL_Surface *> &tiles, - const std::map<std::string, SDL_Surface *> &entities) + const std::shared_ptr<const Model::Map> &map0) : window(window0), map(map0) { uint32_t rmask, gmask, bmask, amask; @@ -50,10 +48,14 @@ MapView::MapView(const std::shared_ptr<Window> &window0, amask = 0xff000000; #endif - SDL_Surface *surface = SDL_CreateRGBSurface(0, getTileSize()*tiles.size(), getTileSize(), 32, rmask, gmask, bmask, amask); + const std::vector<std::string> &tileset = map->getTileset(); + + SDL_Surface *surface = SDL_CreateRGBSurface(0, getTileSize()*tileset.size(), getTileSize(), 32, rmask, gmask, bmask, amask); SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_NONE); - for (size_t i = 0; i < tiles.size(); i++) { + SpriteCache *spriteCache = window->getSpriteCache(); + + for (size_t i = 0; i < tileset.size(); i++) { SDL_Rect rect = { .x = int(getTileSize()*i), .y = 0, @@ -61,21 +63,22 @@ MapView::MapView(const std::shared_ptr<Window> &window0, .h = 0, }; - SDL_BlitSurface(tiles[i], nullptr, surface, &rect); - } + SDL_BlitSurface(spriteCache->get("tile", tileset[i]), nullptr, surface, &rect); + } - tileTexture = SDL_CreateTextureFromSurface(window->getRenderer(), surface); + tiles = SDL_CreateTextureFromSurface(window->getRenderer(), surface); SDL_FreeSurface(surface); - for (const std::pair<std::string, SDL_Surface *> &entity : entities) { - entityTextures[entity.first] = SDL_CreateTextureFromSurface(window->getRenderer(), entity.second); + for (auto &entity : map->getEntities()) { + const std::string &name = entity->getName(); + entities[name] = SDL_CreateTextureFromSurface(window->getRenderer(), spriteCache->get("entity", name)); } } MapView::~MapView() { - SDL_DestroyTexture(tileTexture); + SDL_DestroyTexture(tiles); - for (const std::pair<std::string, SDL_Texture *> &entity : entityTextures) + for (const std::pair<std::string, SDL_Texture *> &entity : entities) SDL_DestroyTexture(entity.second); } @@ -115,7 +118,7 @@ void MapView::render(float centerX, float centerY, uint64_t time) { .h = tilePixels, }; - SDL_RenderCopy(window->getRenderer(), tileTexture, &src, &dst); + SDL_RenderCopy(window->getRenderer(), tiles, &src, &dst); } } @@ -137,7 +140,7 @@ void MapView::render(float centerX, float centerY, uint64_t time) { .h = tilePixels, }; - SDL_RenderCopy(window->getRenderer(), entityTextures[entity->getName()], &src, &dst); + SDL_RenderCopy(window->getRenderer(), entities[entity->getName()], &src, &dst); } } |