From 8cf389aaf748c77aecda0b3a3773c45053b0f231 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Fri, 25 Oct 2024 13:02:38 +0200 Subject: implement all ALGA features --- ViewController.cpp | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) (limited to 'ViewController.cpp') diff --git a/ViewController.cpp b/ViewController.cpp index 3238f0f..d1e519a 100644 --- a/ViewController.cpp +++ b/ViewController.cpp @@ -9,6 +9,9 @@ #include "Exception.h" #include "KeyboardCode.h" #include "MouseCode.h" +#include "SetPathfindingEndPointCommand.h" +#include "SetPathfindingStartPointCommand.h" +#include "ToggleArtistPathCollisionCommand.h" #include "ToggleMuseumPauseCommand.h" #include "OpenFileGUICommand.h" #include "StepTileCommand.h" @@ -80,31 +83,25 @@ void ViewController::draw_pathfinding_dot(const XY & point, const Color & color) } void ViewController::update_pathfinding() { - PathfindingContext & ctx = this->museum.pathfinding; + PathfindingContext & ctx = this->museum.pathfinding; Pathfinder & solver = ctx.get_solver(); - 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 = { + for (int y = 0; y < this->museum.canvas.data.rows; y++) { + for (int x = 0; x < this->museum.canvas.data.columns; x++) { + if (this->draw_visited && solver.is_visited({ x, y })) + this->view.draw_rect({ .x = x * scale, .y = y * scale, .width = scale, .height = scale, - }; - this->view.draw_rect(rect, { 0, 0, 0 }, 2); - } + }, { 0, 0, 0 }, 2); + if (this->draw_path && solver.is_solution({ x, y })) + this->draw_pathfinding_dot({ x, y }, { 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 }); - } + if (this->draw_path) this->draw_pathfinding_dot(ctx.get_start(), { 0xff, 0xff, 0xff }); - } } void ViewController::update_quadtree_recursive(QuadTreeCollisionChecker * tree) { @@ -181,7 +178,7 @@ void ViewController::ev_keydown(KeyboardCode key) { break; } case KEY_W: { - // TODO: toggle collision calculation between artist and path + ToggleArtistPathCollisionCommand(this->museum).execute(); break; } default: break; @@ -195,12 +192,11 @@ void ViewController::ev_mousedown(MouseCode button) { try { switch (button) { case MOUSE_LEFT: { - // TODO: call through command - this->museum.pathfinding.set_start(this->mouse_pos); + SetPathfindingStartPointCommand(this->museum, this->mouse_pos).execute(); break; } case MOUSE_RIGHT: { - this->museum.pathfinding.set_end(this->mouse_pos); + SetPathfindingEndPointCommand(this->museum, this->mouse_pos).execute(); break; } default: break; @@ -218,8 +214,8 @@ void ViewController::ev_mousemove(unsigned x, unsigned y) { } Rectangle ViewController::center(Rectangle rect) { - rect.x += (scale - rect.width) / 2; - rect.y += (scale - rect.height) / 2; - return rect; + rect.x += (scale - rect.width) / 2; + rect.y += (scale - rect.height) / 2; + return rect; } -- cgit v1.2.3