summaryrefslogtreecommitdiffstats
path: root/src/view
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2014-09-24 17:39:36 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2014-09-24 17:39:36 +0200
commitefa8640aabb3b4df31531ecd41ed1073dda63ed2 (patch)
tree151ddb75a5866784ce6b65757e0eea68aee6e05b /src/view
parentaadcecf2022ec13d15da5d816567779740a37da7 (diff)
downloadrpgedit-efa8640aabb3b4df31531ecd41ed1073dda63ed2.tar
rpgedit-efa8640aabb3b4df31531ecd41ed1073dda63ed2.zip
Make MapContext keep a complete copy of the map
Diffstat (limited to 'src/view')
-rw-r--r--src/view/MapView.cpp23
-rw-r--r--src/view/MapView.hpp10
2 files changed, 15 insertions, 18 deletions
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<Window> &window0,
- const std::shared_ptr<const Model::Map> &map0)
- : window(window0), map(map0) {
+MapView::MapView(const std::shared_ptr<Window> &window0, const std::vector<std::string> &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<Window> &window0,
SpriteCache *spriteCache = window->getSpriteCache();
- const std::vector<std::string> &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<std::unique_ptr<Model::Entity>> &entities) {
+void MapView::updateEntities(const std::deque<Model::Entity> &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<std::unique_ptr<Model::Entity>> &
}
void MapView::clearEntities() {
- for (const std::pair<std::string, SDL_Texture *> &entity : entitySprites)
+ for (auto &entity : entitySprites)
SDL_DestroyTexture(entity.second);
entitySprites.clear();
}
-void MapView::render(const std::vector<std::unique_ptr<Model::Entity>> &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<int, int> viewport = window->getViewport();
@@ -139,9 +136,9 @@ void MapView::render(const std::vector<std::unique_ptr<Model::Entity>> &entities
}
}
- for (const std::unique_ptr<Model::Entity> &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<std::unique_ptr<Model::Entity>> &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> window;
- std::shared_ptr<const Model::Map> map;
SDL_Texture *tiles;
std::map<std::string, SDL_Texture *> entitySprites;
@@ -51,14 +50,15 @@ private:
}
public:
- MapView(const std::shared_ptr<Window> &window0,
- const std::shared_ptr<const Model::Map> &map0);
+ MapView(const std::shared_ptr<Window> &window0, const std::vector<std::string> &tileset);
~MapView();
- void updateEntities(const std::vector<std::unique_ptr<Model::Entity>> &entities);
+ void updateEntities(const std::deque<Model::Entity> &entities);
void clearEntities();
- void render(const std::vector<std::unique_ptr<Model::Entity>> &entities, Model::Position center, uint64_t time);
+ void clear();
+
+ void render(const Model::Map *map, Model::Position center, uint64_t time);
};
}