aboutsummaryrefslogtreecommitdiff
path: root/ViewController.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ViewController.cpp')
-rw-r--r--ViewController.cpp60
1 files changed, 42 insertions, 18 deletions
diff --git a/ViewController.cpp b/ViewController.cpp
index b1fd795..3238f0f 100644
--- a/ViewController.cpp
+++ b/ViewController.cpp
@@ -4,6 +4,7 @@
#include "CollisionChecker.h"
#include "ControlBooleanCommand.h"
#include "CycleCollisionMethodCommand.h"
+#include "CyclePathfindingMethodCommand.h"
#include "QuadTreeCollisionChecker.h"
#include "Exception.h"
#include "KeyboardCode.h"
@@ -27,9 +28,9 @@ ViewController::~ViewController() {
void ViewController::update() {
this->update_size();
this->update_tiles();
- if (this->draw_artists) this->update_artists();
- if (this->draw_pathfinding) this->update_pathfinding();
- if (this->draw_quadtree) this->update_quadtree();
+ this->update_artists();
+ this->update_pathfinding();
+ this->update_quadtree();
}
void ViewController::update_size() {
@@ -55,6 +56,8 @@ void ViewController::update_tiles() {
}
void ViewController::update_artists() {
+ if (!this->draw_artists) return;
+
People & people = this->museum.people;
for (Artist * artist : people.get_artists()) {
Rectangle rect = {
@@ -80,25 +83,28 @@ void ViewController::update_pathfinding() {
PathfindingContext & ctx = this->museum.pathfinding;
Pathfinder & solver = ctx.get_solver();
- for (int y = 0; y < this->museum.canvas.data.rows; y++) {
- for (int x = 0; x < this->museum.canvas.data.columns; x++) {
- if (!solver.is_visited({ x, y })) continue;
- Rectangle rect = {
- .x = x * scale,
- .y = y * scale,
- .width = scale,
- .height = scale,
- };
- this->view.draw_rect(rect, { 0, 0, 0 }, 2);
+ if (this->draw_visited) {
+ for (int y = 0; y < this->museum.canvas.data.rows; y++) {
+ for (int x = 0; x < this->museum.canvas.data.columns; x++) {
+ if (!solver.is_visited({ x, y })) continue;
+ Rectangle rect = {
+ .x = x * scale,
+ .y = y * scale,
+ .width = scale,
+ .height = scale,
+ };
+ this->view.draw_rect(rect, { 0, 0, 0 }, 2);
+ }
}
}
- const Pathfinder::Path & solution = solver.get_path();
- for (const XY & point : solution) {
- this->draw_pathfinding_dot(point, { 0, 0, 0 });
+ if (this->draw_path) {
+ const Pathfinder::Path & solution = solver.get_path();
+ for (const XY & point : solution) {
+ this->draw_pathfinding_dot(point, { 0, 0, 0 });
+ }
+ this->draw_pathfinding_dot(ctx.get_start(), { 0xff, 0xff, 0xff });
}
-
- this->draw_pathfinding_dot(ctx.get_start(), { 0xff, 0xff, 0xff });
}
void ViewController::update_quadtree_recursive(QuadTreeCollisionChecker * tree) {
@@ -120,6 +126,7 @@ void ViewController::update_quadtree_recursive(QuadTreeCollisionChecker * tree)
}
void ViewController::update_quadtree() {
+ if (!this->draw_quadtree) return;
shared_ptr<CollisionChecker> checker = this->museum.collision.get_checker();
auto tree = dynamic_cast<QuadTreeCollisionChecker*>(checker.get());
if (tree == nullptr) return;
@@ -161,6 +168,22 @@ void ViewController::ev_keydown(KeyboardCode key) {
ControlBooleanCommand(this->draw_quadtree).execute();
break;
}
+ case KEY_P: {
+ ControlBooleanCommand(this->draw_path).execute();
+ break;
+ }
+ case KEY_V: {
+ ControlBooleanCommand(this->draw_visited).execute();
+ break;
+ }
+ case KEY_D: {
+ CyclePathfindingMethodCommand(this->museum).execute();
+ break;
+ }
+ case KEY_W: {
+ // TODO: toggle collision calculation between artist and path
+ break;
+ }
default: break;
}
} catch (Exception & e) {
@@ -172,6 +195,7 @@ void ViewController::ev_mousedown(MouseCode button) {
try {
switch (button) {
case MOUSE_LEFT: {
+ // TODO: call through command
this->museum.pathfinding.set_start(this->mouse_pos);
break;
}