blob: db300f530dc10506697648948dd761172d0b37c8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
#include <memory>
#include "CollisionContext.h"
#include "Museum.h"
#include "NaiveCollisionChecker.h"
#include "NullCollisionChecker.h"
#include "QuadTreeCollisionChecker.h"
using namespace std;
CollisionContext::CollisionContext(Museum & m) : museum(m) {}
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() {
for (Artist * artist : this->museum.people.get_artists())
artist->colliding = false;
this->checker = this->create_checker();
this->checker->check();
this->museum.people.update(false);
}
void CollisionContext::cycle_method() {
this->checker_index++;
this->update();
}
|