-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPController.cpp
More file actions
128 lines (106 loc) · 2.4 KB
/
Copy pathPController.cpp
File metadata and controls
128 lines (106 loc) · 2.4 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// ---------------------------------------------------------------------
// PController Implementation
// ---------------------------------------------------------------------
#include "PController.h"
// Other includes
#include "random.h"
#include <iostream>
using namespace std;
using namespace CoreStructures;
// ---------------------------------------------------------------------
// PRIVATE
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
// PUBLIC
// ---------------------------------------------------------------------
// Constructor
PController::PController()
{
// The only random seed in the program
seedRandom();
// Current AI
currentAI = 0;
// Map offset of -10, 0, -10 - Centres the map
mapOffset = GUVector4(-10.0, 0.0, -10.0);
}
// Decontructor
PController::~PController()
{
// Empty
}
// Initialise
// Precondition: OpenGL setup
// Postcondition: All project objects initialised
void PController::Initialise()
{
// Initialise Objects
level.Initialise();
pathAI.initialise();
desertAI.initialise();
// Set the path AI as 'in use'
pathAI.setInUse();
}
// Update
// Precondition: Delta
// Postcondition: All project objects updated
void PController::Update(float delta)
{
// Update AI
if(currentAI)
{
desertAI.update(delta);
}
else
{
pathAI.Update(delta);
}
}
// Render
// Precondition: Camer Matrix
// Postcondition: All project objects renderd
void PController::Render(const GUMatrix4& T)
{
// Multiply with offset
GUMatrix4 MVP = T * GUMatrix4::translationMatrix(mapOffset);
// Render the map
level.Render(MVP);
if(currentAI)
{
desertAI.render(MVP);
}
else
{
pathAI.render(MVP);
}
}
// Run AI
// Precondition: DesertAI and PathAI setup/Space is pressed
// Postcondition: Current AI set to run 10 more generations
void PController::runAI()
{
if(currentAI)
desertAI.run();
else
pathAI.run();
}
// Create new population
// Precondition: DesertAI and PathAI setup/'N' is pressed
// Postcondition: Current AI set to refresh population
void PController::refreshPop()
{
if(currentAI)
desertAI.refreshPop();
else
pathAI.refreshPop();
}
// Swap AI
// Precondition: DesertAI and PathAI setup/left or right arrow key is pressed
// Postcondition: Current AI swapped
void PController::swapAI()
{
currentAI = !currentAI;
if(currentAI)
desertAI.setInUse();
else
pathAI.setInUse();
}