aboutsummaryrefslogtreecommitdiff
path: root/ViewController.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-10-21 15:37:31 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-10-21 15:37:31 +0200
commite8601b35b601b0ee1486dfaa12385e71b7f2b300 (patch)
tree244fc97a12ee17e28e6fc407988508bfbc06d89a /ViewController.cpp
parentfe8f7273f0efdfe319a0d3e3b2fc2847992745af (diff)
WIP quadtree visualization scaffolding
Diffstat (limited to 'ViewController.cpp')
-rw-r--r--ViewController.cpp40
1 files changed, 32 insertions, 8 deletions
diff --git a/ViewController.cpp b/ViewController.cpp
index d64ec35..d336b9c 100644
--- a/ViewController.cpp
+++ b/ViewController.cpp
@@ -1,4 +1,7 @@
+#include <memory>
+
#include "ViewController.h"
+#include "QuadTree.h"
#include "ToggleArtistVisibilityCommand.h"
#include "Exception.h"
#include "KeyboardCode.h"
@@ -10,6 +13,8 @@
#include "View.h"
#include "Museum.h"
+using namespace std;
+
ViewController::ViewController(Museum & m, View & v) : museum(m), view(v) {
}
@@ -36,10 +41,10 @@ void ViewController::update_tiles() {
for (unsigned x = 0; x < this->museum.canvas.data.columns; x++) {
Tile & tile = this->museum.canvas.get_tile(x, y);
Rectangle rect = {
- .x = x * scale,
- .y = y * scale,
- .width = scale - line_width,
- .height = scale - line_width,
+ .x = static_cast<float>(x * scale),
+ .y = static_cast<float>(y * scale),
+ .width = static_cast<float>(scale - line_width),
+ .height = static_cast<float>(scale - line_width),
};
this->view.fill_rect(rect, tile.color);
}
@@ -50,10 +55,10 @@ void ViewController::update_artists() {
People & people = this->museum.people;
for (Artist * artist : people.get_artists()) {
Rectangle rect = {
- .x = static_cast<unsigned int>(artist->data.x * scale),
- .y = static_cast<unsigned int>(artist->data.y * scale),
- .width = artist_size,
- .height = artist_size,
+ .x = static_cast<float>(artist->data.x * scale),
+ .y = static_cast<float>(artist->data.y * scale),
+ .width = static_cast<float>(artist_size),
+ .height = static_cast<float>(artist_size),
};
this->view.fill_rect(rect, artist->color);
}
@@ -62,7 +67,26 @@ void ViewController::update_artists() {
void ViewController::update_pathfinding() {
}
+void ViewController::update_quadtree_recursive(QuadTree * tree) {
+ if (tree == nullptr) return;
+
+ Rectangle rect = {
+ .x = tree->boundary.x * scale,
+ .y = tree->boundary.y * scale,
+ .width = tree->boundary.width * scale,
+ .height = tree->boundary.height * scale,
+ };
+ this->view.draw_rect(rect, { .red = 0xff, .green = 0x00, .blue = 0xff, }, 2);
+
+ this->update_quadtree_recursive(tree->subtree[0].get());
+ this->update_quadtree_recursive(tree->subtree[1].get());
+ this->update_quadtree_recursive(tree->subtree[2].get());
+ this->update_quadtree_recursive(tree->subtree[3].get());
+}
+
void ViewController::update_quadtree() {
+ shared_ptr<QuadTree> tree = this->museum.collision.get_quadtree();
+ this->update_quadtree_recursive(tree.get());
}
void ViewController::ev_keydown(KeyboardCode key) {