aboutsummaryrefslogtreecommitdiff
path: root/CollisionContext.cpp
blob: 6df5d3bc51a28cb6825a4bc188e3e59c0afe64aa (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
#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();
}

void CollisionContext::cycle_method() {
	this->checker_index++;
}