Skip to content

Commit b0c7f0c

Browse files
committed
Update EntityFu.cpp
1 parent 3d6cc7b commit b0c7f0c

1 file changed

Lines changed: 24 additions & 24 deletions

File tree

EntityFu.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ void Entity::alloc()
4545
components = new Component**[max];
4646
minEids = new eidType[max];
4747
maxEids = new eidType[max];
48-
for (int i = 0; i < max; i++)
48+
for (Cid i = 0; i < max; i++)
4949
{
5050
// allocate component array
5151
components[i] = new Component*[kMaxEid];
5252
minEids[i] = kMaxEid - 1;
5353
maxEids[i] = 0;
5454

5555
// zero component pointers
56-
for (int j = 0; j < kMaxEid; j++)
56+
for (Eid j = 0; j < kMaxEid; j++)
5757
components[i][j] = nullptr;
5858
}
5959
}
@@ -68,7 +68,7 @@ void Entity::dealloc()
6868

6969
if (components != nullptr)
7070
{
71-
for (int i = 0; i < Component::numClassIds; i++)
71+
for (Cid i = 0; i < Component::numClassIds; i++)
7272
if (components[i] != nullptr)
7373
delete [] components[i]; // note this doesn't destroy the components, just the array
7474
delete [] components;
@@ -122,7 +122,7 @@ void Entity::destroyNow(eidType eid)
122122
if (verbosity > 0)
123123
{Log("Entity %u being destroyed", eid);}
124124

125-
for (int cid = 0; cid < Component::numClassIds; cid++)
125+
for (Cid cid = 0; cid < Component::numClassIds; cid++)
126126
Entity::removeComponent(eid, cid);
127127
entities[eid] = false;
128128
}
@@ -134,35 +134,35 @@ void Entity::destroyAll()
134134
Entity::destroyNow(eid);
135135
}
136136

137-
Entity::eidType Entity::getMinEid(int cid)
137+
Entity::eidType Entity::getMinEid(Cid cid)
138138
{
139-
if ((unsigned)cid < Component::numClassIds)
139+
if (cid < Component::numClassIds)
140140
return minEids[cid];
141141
return kMaxEid - 1;
142142
}
143143

144-
Entity::eidType Entity::getMaxEid(int cid)
144+
Entity::eidType Entity::getMaxEid(Cid cid)
145145
{
146-
if ((unsigned)cid < Component::numClassIds)
146+
if (cid < Component::numClassIds)
147147
return maxEids[cid];
148148
return 1;
149149
}
150150

151-
void Entity::addComponent(eidType eid, Component* c, int cid)
151+
void Entity::addComponent(eidType eid, Component* c, Cid cid)
152152
{
153153
if (c == nullptr)
154154
return;
155-
if (eid >= kMaxEid && (unsigned)cid >= Component::numClassIds)
155+
if (eid >= kMaxEid && cid >= Component::numClassIds)
156156
{
157-
Assert2(false, "Invalid eid %u or cid %d", eid, cid);
157+
Assert2(false, "Invalid eid %u or cid %u", eid, cid);
158158
return;
159159
}
160160

161161
if (verbosity > 0)
162162
{
163163
Log("");
164164
Entity::log(cid);
165-
Log("Adding component cid %d eid %u (%x)", cid, eid, (int)(long)c);
165+
Log("Adding component cid %u eid %u (%x)", cid, eid, (int)(long)c);
166166
}
167167

168168
// pointers to components are stored in the map
@@ -179,11 +179,11 @@ void Entity::addComponent(eidType eid, Component* c, int cid)
179179
Entity::log(cid);
180180
}
181181

182-
void Entity::removeComponent(eidType eid, int cid)
182+
void Entity::removeComponent(eidType eid, Cid cid)
183183
{
184-
if (eid >= kMaxEid && (unsigned)cid >= Component::numClassIds)
184+
if (eid >= kMaxEid && cid >= Component::numClassIds)
185185
{
186-
Assert2(false, "Invalid eid %u or cid %d", eid, cid);
186+
Assert2(false, "Invalid eid %u or cid %u", eid, cid);
187187
return;
188188
}
189189

@@ -196,7 +196,7 @@ void Entity::removeComponent(eidType eid, int cid)
196196
{
197197
Log("");
198198
Entity::log(cid);
199-
Log("Removing component cid %d eid %u (%x)", cid, eid, (int)(long)ptr);
199+
Log("Removing component cid %u eid %u (%x)", cid, eid, (int)(long)ptr);
200200
}
201201

202202
// pointers to components are deleted
@@ -213,7 +213,7 @@ void Entity::removeComponent(eidType eid, int cid)
213213
for (; i < kMaxEid - 1 && components[cid][i] == nullptr; i++) {}
214214
minEids[cid] = i;
215215
if (verbosity > 1)
216-
{Log("New min eid %u for cid %d component %x", i, cid, (int)(long)components[cid][i]);}
216+
{Log("New min eid %u for cid %u component %x", i, cid, (int)(long)components[cid][i]);}
217217
}
218218

219219
if (eid == maxEids[cid])
@@ -222,17 +222,17 @@ void Entity::removeComponent(eidType eid, int cid)
222222
for (; i > 1 && i < kMaxEid - 1 && components[cid][i] == nullptr; i--) {}
223223
maxEids[cid] = i;
224224
if (verbosity > 1)
225-
{Log("New max eid %u for cid %d component %x", i, cid, (int)(long)components[cid][i]);}
225+
{Log("New max eid %u for cid %u component %x", i, cid, (int)(long)components[cid][i]);}
226226
}
227227

228228
if (verbosity > 1)
229229
Entity::log(cid);
230230
}
231231

232-
Entity::Component* Entity::getComponent(eidType eid, int cid)
232+
Entity::Component* Entity::getComponent(eidType eid, Cid cid)
233233
{
234234
#if (kTrustPointers == 0)
235-
if (eid < kMaxEid && (unsigned)cid < Component::numClassIds)
235+
if (eid < kMaxEid && cid < Component::numClassIds)
236236
{
237237
#endif
238238
return components[cid][eid];
@@ -243,7 +243,7 @@ Entity::Component* Entity::getComponent(eidType eid, int cid)
243243
#endif
244244
}
245245

246-
int Entity::count(int cid)
246+
int Entity::count(Cid cid)
247247
{
248248
int n = 0;
249249
for (auto eid = Entity::getMinEid(cid), eidMax = Entity::getMaxEid(cid); eid <= eidMax; eid++)
@@ -252,15 +252,15 @@ int Entity::count(int cid)
252252
return n;
253253
}
254254

255-
void Entity::log(int cid)
255+
void Entity::log(Cid cid)
256256
{
257257
auto n = Entity::count(cid);
258-
Log("Cid %d has %d entities ranging from %u to %u", cid, n, minEids[cid], maxEids[cid]);
258+
Log("Cid %u has %d entities ranging from %u to %u", cid, n, minEids[cid], maxEids[cid]);
259259
}
260260

261261
void Entity::logAll()
262262
{
263-
for (auto cid = 0, max = Component::numClassIds; cid < max; cid++)
263+
for (Cid cid = 0, max = Component::numClassIds; cid < max; cid++)
264264
Entity::log(cid);
265265
}
266266

0 commit comments

Comments
 (0)