summaryrefslogtreecommitdiffstats
path: root/src/control
diff options
context:
space:
mode:
Diffstat (limited to 'src/control')
-rw-r--r--src/control/MapContext.cpp15
-rw-r--r--src/control/MapContext.hpp10
-rw-r--r--src/control/RPGEdit.cpp5
-rw-r--r--src/control/RPGEdit.hpp5
4 files changed, 14 insertions, 21 deletions
diff --git a/src/control/MapContext.cpp b/src/control/MapContext.cpp
index e3f9a49..1904db4 100644
--- a/src/control/MapContext.cpp
+++ b/src/control/MapContext.cpp
@@ -31,18 +31,15 @@ namespace RPGEdit {
namespace Control {
-MapContext::MapContext(EventBus *eventBus0, InputHandler *inputHandler0, View::MapView *view0, const std::shared_ptr<const Model::Map> &map0)
- : eventBus(eventBus0), inputHandler(inputHandler0), view(view0), map(map0) {
- for (const Model::Entity &entity : map->getEntities())
- entities.emplace_back(new Model::Entity(entity));
+MapContext::MapContext(EventBus *eventBus0, InputHandler *inputHandler0, const std::shared_ptr<View::Window> &window, const Model::Map &map0)
+ : eventBus(eventBus0), inputHandler(inputHandler0), map(map0) {
+ view = std::unique_ptr<View::MapView>(new View::MapView(window, map.getTileset()));
- playerEntity = new Model::Entity("square");
+ map.getEntities().emplace_back("square");
+ playerEntity = &map.getEntities().back();
playerEntity->moveTo(Model::Position{8, 8});
- entities.emplace_back(playerEntity);
-
- view->updateEntities(entities);
-
+ view->updateEntities(map.getEntities());
inputHandler->registerListener(
[this] (uint16_t key, bool pressed, uint64_t time) {
diff --git a/src/control/MapContext.hpp b/src/control/MapContext.hpp
index a9481a6..a60bdfc 100644
--- a/src/control/MapContext.hpp
+++ b/src/control/MapContext.hpp
@@ -44,11 +44,9 @@ private:
EventBus *const eventBus;
InputHandler *const inputHandler;
- View::MapView *const view;
+ std::unique_ptr<View::MapView> view;
- std::shared_ptr<const Model::Map> map;
-
- std::vector<std::unique_ptr<Model::Entity>> entities;
+ Model::Map map;
Model::Entity *playerEntity;
void movePlayer(Model::Direction dir, uint64_t time);
@@ -60,10 +58,10 @@ private:
}
public:
- MapContext(EventBus *eventBus0, InputHandler *inputHandler0, View::MapView *view0, const std::shared_ptr<const Model::Map> &map0);
+ MapContext(EventBus *eventBus0, InputHandler *inputHandler0, const std::shared_ptr<View::Window> &window, const Model::Map &map0);
void render(uint64_t time) {
- view->render(entities, getViewPosition(time), time);
+ view->render(&map, getViewPosition(time), time);
}
};
diff --git a/src/control/RPGEdit.cpp b/src/control/RPGEdit.cpp
index e22d8fa..257a801 100644
--- a/src/control/RPGEdit.cpp
+++ b/src/control/RPGEdit.cpp
@@ -99,12 +99,11 @@ void RPGEdit::eventLoop() {
}
void RPGEdit::run() {
- std::shared_ptr<Model::Map> map = Model::Map::load("test");
+ std::unique_ptr<Model::Map> map = Model::Map::load("test");
window = std::make_shared<View::Window>();
- mapView = std::make_shared<View::MapView>(window, map);
- ctx = std::make_shared<MapContext>(&eventBus, &inputHandler, mapView.get(), map);
+ ctx = std::make_shared<MapContext>(&eventBus, &inputHandler, window, *map);
eventThread = std::thread([this] { eventLoop(); });
diff --git a/src/control/RPGEdit.hpp b/src/control/RPGEdit.hpp
index d6f3aee..e505597 100644
--- a/src/control/RPGEdit.hpp
+++ b/src/control/RPGEdit.hpp
@@ -46,10 +46,9 @@ private:
EventBus eventBus;
InputHandler inputHandler;
- std::shared_ptr<MapContext> ctx;
-
std::shared_ptr<View::Window> window;
- std::shared_ptr<View::MapView> mapView;
+
+ std::shared_ptr<MapContext> ctx;
std::thread eventThread;
std::mutex modelMutex;