diff options
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | CollisionContext.cpp | 22 | ||||
-rw-r--r-- | CollisionContext.h | 6 | ||||
-rw-r--r-- | CycleCollisionMethodCommand.cpp | 9 | ||||
-rw-r--r-- | CycleCollisionMethodCommand.h | 17 | ||||
-rw-r--r-- | NaiveCollisionChecker.cpp | 1 | ||||
-rw-r--r-- | NullCollisionChecker.h | 12 | ||||
-rw-r--r-- | QuadTreeCollisionChecker.cpp | 1 | ||||
-rw-r--r-- | ViewController.cpp | 3 | ||||
-rw-r--r-- | ViewController.h | 2 | ||||
-rw-r--r-- | docs/class-diag.puml | 4 | ||||
-rw-r--r-- | readme.md | 6 |
12 files changed, 72 insertions, 12 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index cf2f157..d43e54a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,6 +53,7 @@ add_executable(main ControlBooleanCommand.cpp CollisionChecker.cpp NaiveCollisionChecker.cpp + CycleCollisionMethodCommand.cpp ) target_link_libraries(main diff --git a/CollisionContext.cpp b/CollisionContext.cpp index ec608b5..6df5d3b 100644 --- a/CollisionContext.cpp +++ b/CollisionContext.cpp @@ -2,7 +2,9 @@ #include "CollisionContext.h" #include "Museum.h" + #include "NaiveCollisionChecker.h" +#include "NullCollisionChecker.h" #include "QuadTreeCollisionChecker.h" using namespace std; @@ -13,9 +15,25 @@ shared_ptr<CollisionChecker> CollisionContext::get_checker() { return this->checker; } +shared_ptr<CollisionChecker> CollisionContext::create_checker() { + switch(this->checker_index) { + case 0: return make_shared<NullCollisionChecker>(this->museum); + case 1: return make_shared<QuadTreeCollisionChecker>(this->museum); + case 2: return make_shared<NaiveCollisionChecker>(this->museum); + } + + this->checker_index = 0; + return this->create_checker(); +} + void CollisionContext::update() { - this->checker = std::make_shared<QuadTreeCollisionChecker>(this->museum); - // this->checker = std::make_shared<NaiveCollisionChecker>(this->museum); + for (Artist * artist : this->museum.people.get_artists()) + artist->colliding = false; + this->checker = this->create_checker(); this->checker->check(); } +void CollisionContext::cycle_method() { + this->checker_index++; +} + diff --git a/CollisionContext.h b/CollisionContext.h index e35c373..0dd37c0 100644 --- a/CollisionContext.h +++ b/CollisionContext.h @@ -1,4 +1,5 @@ #pragma once + #include <memory> #include "CollisionChecker.h" @@ -12,11 +13,16 @@ public: void update(); 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; }; diff --git a/CycleCollisionMethodCommand.cpp b/CycleCollisionMethodCommand.cpp new file mode 100644 index 0000000..cc7b7f0 --- /dev/null +++ b/CycleCollisionMethodCommand.cpp @@ -0,0 +1,9 @@ +#include "CycleCollisionMethodCommand.h" +#include "Museum.h" + +CycleCollisionMethodCommand::CycleCollisionMethodCommand(Museum & m) : museum(m) { } + +void CycleCollisionMethodCommand::execute() { + this->museum.collision.cycle_method(); +} + diff --git a/CycleCollisionMethodCommand.h b/CycleCollisionMethodCommand.h new file mode 100644 index 0000000..1caee53 --- /dev/null +++ b/CycleCollisionMethodCommand.h @@ -0,0 +1,17 @@ +#pragma once + +#include "Command.h" + +class Museum; + +class CycleCollisionMethodCommand : public Command { +public: + CycleCollisionMethodCommand(Museum & m); + +public: + virtual void execute(); + +private: + Museum & museum; +}; + diff --git a/NaiveCollisionChecker.cpp b/NaiveCollisionChecker.cpp index db277ab..e26c3d2 100644 --- a/NaiveCollisionChecker.cpp +++ b/NaiveCollisionChecker.cpp @@ -5,7 +5,6 @@ void NaiveCollisionChecker::check() { auto artists = this->museum.people.get_artists(); - for (Artist * artist : artists) artist->colliding = false; auto begin = artists.begin(); auto end = artists.end(); for (auto it1 = begin; it1 != end; ++it1) { diff --git a/NullCollisionChecker.h b/NullCollisionChecker.h new file mode 100644 index 0000000..f6b4af2 --- /dev/null +++ b/NullCollisionChecker.h @@ -0,0 +1,12 @@ +#pragma once + +#include "CollisionChecker.h" + +class NullCollisionChecker : public CollisionChecker { + using CollisionChecker::CollisionChecker; + +public: + virtual void check() {}; + +}; + diff --git a/QuadTreeCollisionChecker.cpp b/QuadTreeCollisionChecker.cpp index 0d211c0..72337ee 100644 --- a/QuadTreeCollisionChecker.cpp +++ b/QuadTreeCollisionChecker.cpp @@ -86,7 +86,6 @@ void QuadTreeCollisionChecker::check() { if (this->artists_size > 0) { auto begin = this->artists.begin(); auto end = this->artists.end(); - for (Artist * artist : this->artists) artist->colliding = false; for (auto it1 = begin; it1 != end; ++it1) { auto it2 = it1; ++it2; diff --git a/ViewController.cpp b/ViewController.cpp index 7f3fdfc..989f11a 100644 --- a/ViewController.cpp +++ b/ViewController.cpp @@ -3,6 +3,7 @@ #include "ViewController.h" #include "CollisionChecker.h" #include "ControlBooleanCommand.h" +#include "CycleCollisionMethodCommand.h" #include "QuadTreeCollisionChecker.h" #include "Exception.h" #include "KeyboardCode.h" @@ -121,7 +122,7 @@ void ViewController::ev_keydown(KeyboardCode key) { break; } case KEY_C: { - // CycleCollisionMethodCommand(this->museum).execute(); + CycleCollisionMethodCommand(this->museum).execute(); break; } case KEY_Q: { diff --git a/ViewController.h b/ViewController.h index 4ff73c5..162ae19 100644 --- a/ViewController.h +++ b/ViewController.h @@ -37,7 +37,7 @@ private: private: bool draw_artists = true; bool draw_pathfinding = false; - bool draw_quadtree = false; + bool draw_quadtree = true; private: unsigned int scale = 16; diff --git a/docs/class-diag.puml b/docs/class-diag.puml index 58ed950..9a37256 100644 --- a/docs/class-diag.puml +++ b/docs/class-diag.puml @@ -388,6 +388,9 @@ rectangle Group_Commands as "Commands" <<group>> { - value : bool - target : bool & } + class CycleCollisionMethodCommand { + + constructor(Museum &) + } Command <|-d- ToggleMuseumPauseCommand Command <|-u- OpenFileGUICommand @@ -395,6 +398,7 @@ rectangle Group_Commands as "Commands" <<group>> { Command <|-d- StepTileCommand Command <|-d- LoadFilesCommand Command <|-d- TimeTravelCommand + Command <|-u- CycleCollisionMethodCommand } } /' LAYOUT '/ @@ -12,9 +12,3 @@ ALGA: - show {shortest,fastest,no} path toggle - vast meer -TODO: - -- low-binding factories naar high-binding factories -- prototype met geen factory maar map ofzo fixen -- txt file parser - |