summaryrefslogtreecommitdiffstats
path: root/src/model
diff options
context:
space:
mode:
Diffstat (limited to 'src/model')
-rw-r--r--src/model/Map.cpp11
-rw-r--r--src/model/Map.hpp17
2 files changed, 11 insertions, 17 deletions
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> Map::load(__attribute__((unused)) const std::string &name) {
- std::shared_ptr<Map> map(new Map(16, 16));
+ std::shared_ptr<Map> 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> Map::load(__attribute__((unused)) const std::string &name)
}
}
- map->playerEntity = std::make_shared<Entity>("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 <cstdint>
-#include <deque>
#include <memory>
#include <stdexcept>
#include <vector>
@@ -44,14 +43,14 @@ private:
std::vector<std::string> tileset;
size_t width, height;
- std::vector<std::unique_ptr<uint32_t[]>> tiles;
+ std::vector<std::vector<uint32_t>> tiles;
+ std::vector<Entity> entities;
- std::shared_ptr<Entity> playerEntity;
- mutable std::deque<std::shared_ptr<Entity>> 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<std::shared_ptr<Entity>> & getEntities() const {
+ std::vector<Entity> & getEntities() {
return entities;
}
- const std::shared_ptr<Entity> & getPlayerEntity() const {
- return playerEntity;
+ const std::vector<Entity> & getEntities() const {
+ return entities;
}
size_t getWidth() const {