-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActors.cpp
166 lines (141 loc) · 3.47 KB
/
Actors.cpp
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include <glm/glm.hpp>
#include "Actors.hpp"
#include "Util.hpp"
#include "Force.hpp"
#include "Actor.hpp"
#include <iterator>
#include <vector>
// because I'm too lazy to implement an iterator wrapper
std::vector<Actor>& Actors::underlying() {
return actors;
}
Actors::Actors() : selected_index(0) {}
void Actors::apply_force(const Force& force) {
actors[force.id].apply_force(force);
}
bool Actors::insert(const Id& id, Actor a) {
//auto ret = actors.insert(std::make_pair(id,a));
//return ret.second;
auto ret = actors.size();
actors.emplace_back(a);
return id == ret;
}
void Actors::check() {
assert(actors.size() > 0 && "Need actors to select from");
}
Id Actors::selected() {
check();
actors[selected_index].invis(true);
return actors[selected_index].id;
}
Actor& Actors::selectedActor() {
check();
actors[selected_index].invis(true);
return actors[selected_index];
}
void Actors::select(const Id& id) {
check();
actors[selected_index].invis(false);
if (actors[id].selectable) {
selected_index = id;
}
actors[selected_index].invis(true);
}
// gets next selectable actor
void Actors::next() {
check();
actors[selected_index].invis(false);
bool anySelectable = false;
for (const auto& a:actors) {
if (a.selectable == true) {
anySelectable = true;
break;
}
}
if (!anySelectable) {
std::cout << "Cannot select next actor, none selectable\n";
return;
}
do {
++selected_index;
selected_index %= actors.size();
} while (selectedActor().selectable == false);
for (auto& a:actors) {
a.invis(false);
}
actors[selected_index].invis(true);
}
Actor& Actors::operator[](const Id& id) {
return actors[id];
}
int Actors::size() const {
return actors.size();
}
Actors::~Actors() {
/*
for (auto& a: actors) {
delete a.second;
}*/
}
/*
// because I'm too lazy to implement an iterator wrapper
const std::map<Id, Actor*>& Actors::underlying() const {
return actors;
}
Actors::Actors() : selected_index(0) {}
void Actors::apply_force(const Force& force) {
actors[force.id]->apply_force(force);
}
bool Actors::insert(const Id& id, Actor* a) {
auto ret = actors.insert(std::make_pair(id,a));
return ret.second;
}
void Actors::check() {
assert(actors.size() > 0 && "Need actors to select from");
}
Id Actors::selected() {
check();
actors[selected_index]->invis(true);
return actors[selected_index]->id;
}
Actor& Actors::selectedActor() {
check();
actors[selected_index]->invis(true);
return *actors[selected_index];
}
// gets next selectable actor
void Actors::next() {
check();
actors[selected_index]->invis(false);
bool anySelectable = false;
for (const auto& a:actors) {
if (a.second->selectable == true) {
anySelectable = true;
break;
}
}
if (!anySelectable) {
std::cout << "Cannot select next actor, none selectable\n";
return;
}
do {
++selected_index;
selected_index %= actors.size();
} while (selectedActor().selectable == false);
for (const auto& a:actors) {
a.second->invis(false);
}
actors[selected_index]->invis(true);
}
Actor& Actors::operator[](const Id& id) {
return *actors[id];
}
int Actors::size() const {
return actors.size();
}
Actors::~Actors() {
for (auto& a: actors) {
delete a.second;
}
}
*/