From aadcecf2022ec13d15da5d816567779740a37da7 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 24 Sep 2014 15:22:09 +0200 Subject: Keep mutable entity list in the MapContext only --- src/model/Map.cpp | 11 +++-------- src/model/Map.hpp | 17 ++++++++--------- 2 files changed, 11 insertions(+), 17 deletions(-) (limited to 'src/model') diff --git a/src/model/Map.cpp b/src/model/Map.cpp index a770ee4..aff05d1 100644 --- a/src/model/Map.cpp +++ b/src/model/Map.cpp @@ -32,14 +32,11 @@ namespace RPGEdit { namespace Model { std::shared_ptr Map::load(__attribute__((unused)) const std::string &name) { - std::shared_ptr map(new Map(16, 16)); + std::shared_ptr map(new Map(16, 16, 2)); map->tileset.push_back("dirt"); map->tileset.push_back("horizontal_bar"); - for (int i = 0; i < 2; i++) - map->tiles.emplace_back(new uint32_t[16*16]); - for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { if (4 <= i && i < 12 && 4 <= j && j < 12) @@ -54,10 +51,8 @@ std::shared_ptr Map::load(__attribute__((unused)) const std::string &name) } } - map->playerEntity = std::make_shared("square"); - map->playerEntity->moveTo(Model::Position{6, 6}); - - map->entities.push_back(map->playerEntity); + map->entities.emplace_back("square"); + map->entities.back().moveTo(Model::Position{6, 6}); return map; } diff --git a/src/model/Map.hpp b/src/model/Map.hpp index 423c91d..77a67be 100644 --- a/src/model/Map.hpp +++ b/src/model/Map.hpp @@ -27,7 +27,6 @@ #pragma once #include -#include #include #include #include @@ -44,14 +43,14 @@ private: std::vector tileset; size_t width, height; - std::vector> tiles; + std::vector> tiles; + std::vector entities; - std::shared_ptr playerEntity; - mutable std::deque> entities; - - Map(size_t width0, size_t height0) + Map(size_t width0, size_t height0, size_t layers) : width(width0), height(height0) { + for (size_t i = 0; i < layers; i++) + tiles.emplace_back(width*height); } public: @@ -63,12 +62,12 @@ public: return tileset; } - std::deque> & getEntities() const { + std::vector & getEntities() { return entities; } - const std::shared_ptr & getPlayerEntity() const { - return playerEntity; + const std::vector & getEntities() const { + return entities; } size_t getWidth() const { -- cgit v1.2.3