diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-25 14:34:40 +0200 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-25 14:34:40 +0200 |
commit | c9f5ac8722190efeb58fda1eec9e6160d5204127 (patch) | |
tree | da9015f230d96d7abf30060de5099664c2189809 | |
parent | 8cf389aaf748c77aecda0b3a3773c45053b0f231 (diff) |
update class-diag.puml
-rw-r--r-- | BreadthFirstPathfinder.h | 4 | ||||
-rw-r--r-- | CollisionChecker.h | 5 | ||||
-rw-r--r-- | CollisionContext.h | 11 | ||||
-rw-r--r-- | DijkstraPathfinder.cpp | 5 | ||||
-rw-r--r-- | DijkstraPathfinder.h | 4 | ||||
-rw-r--r-- | Pathfinder.h | 3 | ||||
-rw-r--r-- | PathfindingContext.h | 7 | ||||
-rw-r--r-- | docs/class-diag.puml | 70 |
8 files changed, 64 insertions, 45 deletions
diff --git a/BreadthFirstPathfinder.h b/BreadthFirstPathfinder.h index c8b9fe5..3b1c75c 100644 --- a/BreadthFirstPathfinder.h +++ b/BreadthFirstPathfinder.h @@ -6,13 +6,11 @@ class BreadthFirstPathfinder : public Pathfinder { using Pathfinder::Pathfinder; - public: virtual void find_between(const XY &, const XY &); private: - XY end; - std::vector<Path> find_step(const std::vector<Path> &); + XY end; }; diff --git a/CollisionChecker.h b/CollisionChecker.h index 646aa42..6671cba 100644 --- a/CollisionChecker.h +++ b/CollisionChecker.h @@ -6,10 +6,11 @@ class Artist; class CollisionChecker { public: CollisionChecker(Museum &); - void compare(Artist & a, Artist & b); - virtual void check() = 0; +public: + void compare(Artist & a, Artist & b); + protected: Museum & museum; diff --git a/CollisionContext.h b/CollisionContext.h index 0dd37c0..49397f0 100644 --- a/CollisionContext.h +++ b/CollisionContext.h @@ -9,20 +9,17 @@ class Museum; class CollisionContext { public: CollisionContext(Museum &); - void update(); +public: std::shared_ptr<CollisionChecker> get_checker(); void cycle_method(); - -private: - Museum & museum; - private: std::shared_ptr<CollisionChecker> checker = nullptr; - -private: std::shared_ptr<CollisionChecker> create_checker(); size_t checker_index = 0; + +private: + Museum & museum; }; diff --git a/DijkstraPathfinder.cpp b/DijkstraPathfinder.cpp index d920fc9..e8f0132 100644 --- a/DijkstraPathfinder.cpp +++ b/DijkstraPathfinder.cpp @@ -5,6 +5,11 @@ using namespace std; +struct Neighbor { + unsigned int distance = -1; + XY position; +}; + void DijkstraPathfinder::clear() { Pathfinder::clear(); this->map.clear(); diff --git a/DijkstraPathfinder.h b/DijkstraPathfinder.h index 93e6943..ab21361 100644 --- a/DijkstraPathfinder.h +++ b/DijkstraPathfinder.h @@ -20,10 +20,6 @@ private: unsigned int distance = -1; XY parent; }; - struct Neighbor { - unsigned int distance = -1; - XY position; - }; Node & map_get(const XY &); std::unordered_map<XY, Node> map; diff --git a/Pathfinder.h b/Pathfinder.h index 503423e..30144f9 100644 --- a/Pathfinder.h +++ b/Pathfinder.h @@ -14,12 +14,10 @@ public: public: Pathfinder(Museum &); - virtual void find_between(const XY &, const XY &) = 0; virtual bool is_visited(const XY &); virtual bool is_solution(const XY &); - virtual bool is_solved() { return this->solved; } virtual const Path & get_solution() { return this->path; } @@ -27,7 +25,6 @@ protected: virtual void clear(); virtual void set_visited(const XY &); virtual void set_solved(const Path &); - private: size_t pos_to_idx(const XY &); std::vector<bool> visisted; diff --git a/PathfindingContext.h b/PathfindingContext.h index c2c591c..aae02cd 100644 --- a/PathfindingContext.h +++ b/PathfindingContext.h @@ -14,6 +14,9 @@ public: PathfindingContext(Museum &); void update(); +private: + XY start_point = { -1, -1 }; + XY end_point = { -1, -1 }; public: void set_start(const XY & point); const XY & get_start() { return this->start_point; } @@ -28,10 +31,6 @@ public: private: std::unordered_map<std::string, unsigned int> weight_map; -private: - XY start_point = { -1, -1 }; - XY end_point = { -1, -1 }; - public: Pathfinder & get_solver(); void cycle_solver(); diff --git a/docs/class-diag.puml b/docs/class-diag.puml index bf19cf3..9ce43eb 100644 --- a/docs/class-diag.puml +++ b/docs/class-diag.puml @@ -102,19 +102,21 @@ rectangle Group_Collisions as "Collisions" <<group>> { class CollisionContext { + CollisionContext(Museum &) + update() + -- + get_checker() : shared<CollisionChecker> + cycle_method() - -- - - museum : Museum & - checker : shared<CollisionChecker> - - checker_index : size_t - create_checker() : shared<CollisionChecker> + - checker_index : size_t + -- + - museum : Museum & } class CollisionChecker <<abstract>> { + CollisionChecker(Museum &) - + compare(Artist & a, Artist & b) + check() <<pure virtual>> -- + + compare(Artist & a, Artist & b) + -- # museum : Museum & } class QuadTreeCollisionChecker { @@ -148,11 +150,11 @@ rectangle Group_Collisions as "Collisions" <<group>> { rectangle Group_Pathfinding as "Pathfinding" <<group>> { class PathfindingContext { + PathfindingContext(Museum &) + + update() -- - start_point : XY <<+get>> <<+set>> - end_point : XY <<+get>> <<+set>> - + valid_point(const XY &) : bool - + update() + + empty_point(const XY &) : bool -- + register_weight(type : const string &, weight : unsigned int) + get_weight(type : const string &) : unsigned int @@ -160,37 +162,47 @@ rectangle Group_Pathfinding as "Pathfinding" <<group>> { -- + get_solver() : Pathfinder & + cycle_solver() - -- - solvers : vec<uniq<Pathfinder>> - solver_index : size_t + -- + + has_collision : bool + -- - museum : Museum & } class Pathfinder <<abstract>> { + Pathfinder(Museum &) + find_between(const XY &, const XY &) <<pure virtual> - + get_path() : const forward_list<XY> & <<pure virtual>> -- + is_visited(const XY &) : bool - # set_visited(const XY &) + + is_solution(const XY &) : bool + + is_solved() : bool + + get_solution() : const forward_list<XY> & -- # clear() + # set_visited(const XY &) + # set_solved(const forward_list<XY> &) + -- - visited : vec<bool> + - solution : vec<bool> + - path : forward_list<XY> + - solved : bool -- # museum : Museum & } class BreadthFirstPathfinder { + find_between(const XY &, const XY &) - + get_path() : const forward_list<XY> & -- - find_step(const vec<forward_list<XY>> &) : vec<forward_list<XY>> - - solution : forward_list<XY> - end : XY - -- - # clear() } class DijkstraPathfinder { + find_between(const XY &, const XY &) - + get_path() : const forward_list<XY> & + -- + # clear() + - end : XY + - map_get(const XY &) : Node & + - map : unordered_map<XY, Node> + - dijkstra(const XY &) } Pathfinder <|-- BreadthFirstPathfinder @@ -238,6 +250,7 @@ rectangle Group_Model as "Model" <<group>> { } class People { + People(Museum &) + + update(tick : bool) -- + add_artist(ArtistData) + remove_artist(Artist &) @@ -266,7 +279,7 @@ rectangle Group_Model as "Model" <<group>> { + type : string } class Artist { - + update() + + update(tick : bool) + step : bool + color : Color + data : ArtistData @@ -423,9 +436,6 @@ rectangle Group_Commands as "Commands" <<group>> { class ToggleMuseumPauseCommand { + constructor(Museum &) + constructor(Museum &, set : bool) - -- - toggle : bool - value : bool } class OpenFileGUICommand { + constructor(Museum &, View &) @@ -464,14 +474,30 @@ rectangle Group_Commands as "Commands" <<group>> { class CycleCollisionMethodCommand { + constructor(Museum &) } + class ToggleArtistPathCollisionCommand { + + constructor(Museum &) + } + class SetPathfindingStartPointCommand { + + constructor(Museum &) + - museum : Museum & + - point : XY + } + class SetPathfindingEndPointCommand { + + constructor(Museum &) + - museum : Museum & + - point : XY + } - Command <|-d- ToggleMuseumPauseCommand - Command <|-u- OpenFileGUICommand - Command <|-u- ControlBooleanCommand Command <|-d- StepTileCommand Command <|-d- LoadFilesCommand Command <|-d- TimeTravelCommand - Command <|-u- CycleCollisionMethodCommand + Command <|-d- CycleCollisionMethodCommand + Command <|-u- OpenFileGUICommand + Command <|-u- ControlBooleanCommand + Command <|-u- SetPathfindingStartPointCommand + Command <|-u- SetPathfindingEndPointCommand + ControlBooleanCommand <|-u- ToggleMuseumPauseCommand + ControlBooleanCommand <|-u- ToggleArtistPathCollisionCommand } } /' LAYOUT '/ |