From efa8640aabb3b4df31531ecd41ed1073dda63ed2 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 24 Sep 2014 17:39:36 +0200 Subject: Make MapContext keep a complete copy of the map --- src/view/MapView.cpp | 23 ++++++++++------------- src/view/MapView.hpp | 10 +++++----- 2 files changed, 15 insertions(+), 18 deletions(-) (limited to 'src/view') diff --git a/src/view/MapView.cpp b/src/view/MapView.cpp index c8abab5..dbce5e4 100644 --- a/src/view/MapView.cpp +++ b/src/view/MapView.cpp @@ -31,9 +31,8 @@ namespace RPGEdit { namespace View { -MapView::MapView(const std::shared_ptr &window0, - const std::shared_ptr &map0) - : window(window0), map(map0) { +MapView::MapView(const std::shared_ptr &window0, const std::vector &tileset) + : window(window0) { uint32_t rmask, gmask, bmask, amask; #if SDL_BYTEORDER == SDL_BIG_ENDIAN @@ -50,8 +49,6 @@ MapView::MapView(const std::shared_ptr &window0, SpriteCache *spriteCache = window->getSpriteCache(); - const std::vector &tileset = map->getTileset(); - SDL_Surface *surface = SDL_CreateRGBSurface(0, getTileSize()*tileset.size(), getTileSize(), 32, rmask, gmask, bmask, amask); for (size_t i = 0; i < tileset.size(); i++) { @@ -79,11 +76,11 @@ MapView::~MapView() { clearEntities(); } -void MapView::updateEntities(const std::vector> &entities) { +void MapView::updateEntities(const std::deque &entities) { SpriteCache *spriteCache = window->getSpriteCache(); for (auto &entity : entities) { - const std::string &name = entity->getName(); + const std::string &name = entity.getName(); if (!entitySprites[name]) entitySprites[name] = SDL_CreateTextureFromSurface(window->getRenderer(), spriteCache->get("entity", name)); @@ -91,13 +88,13 @@ void MapView::updateEntities(const std::vector> & } void MapView::clearEntities() { - for (const std::pair &entity : entitySprites) + for (auto &entity : entitySprites) SDL_DestroyTexture(entity.second); entitySprites.clear(); } -void MapView::render(const std::vector> &entities, Model::Position center, uint64_t time) { +void MapView::render(const Model::Map *map, Model::Position center, uint64_t time) { SDL_RenderClear(window->getRenderer()); std::pair viewport = window->getViewport(); @@ -139,9 +136,9 @@ void MapView::render(const std::vector> &entities } } - for (const std::unique_ptr &entity : entities) { - Model::Position pos = entity->getPosition(time); - Model::Direction dir = entity->getDirection(); + for (auto &entity : map->getEntities()) { + Model::Position pos = entity.getPosition(time); + Model::Direction dir = entity.getDirection(); SDL_Rect src = { .x = getTileSize()*dir, @@ -157,7 +154,7 @@ void MapView::render(const std::vector> &entities .h = tilePixels, }; - SDL_RenderCopy(window->getRenderer(), entitySprites[entity->getName()], &src, &dst); + SDL_RenderCopy(window->getRenderer(), entitySprites[entity.getName()], &src, &dst); } } diff --git a/src/view/MapView.hpp b/src/view/MapView.hpp index e128a93..f101c24 100644 --- a/src/view/MapView.hpp +++ b/src/view/MapView.hpp @@ -41,7 +41,6 @@ namespace View { class MapView { private: std::shared_ptr window; - std::shared_ptr map; SDL_Texture *tiles; std::map entitySprites; @@ -51,14 +50,15 @@ private: } public: - MapView(const std::shared_ptr &window0, - const std::shared_ptr &map0); + MapView(const std::shared_ptr &window0, const std::vector &tileset); ~MapView(); - void updateEntities(const std::vector> &entities); + void updateEntities(const std::deque &entities); void clearEntities(); - void render(const std::vector> &entities, Model::Position center, uint64_t time); + void clear(); + + void render(const Model::Map *map, Model::Position center, uint64_t time); }; } -- cgit v1.2.3