diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2019-02-23 12:15:46 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2019-02-23 12:15:46 -0500 |
commit | 3504fd5080dbcfd0172299c5c6d13895e53ad163 (patch) | |
tree | caab8e868566262b3aa4d80aa6a06cdf13e7c21d /src/simulation.cpp | |
parent | 15b511e694f976686fdec1fb9f959f8a92f3b594 (diff) | |
download | dispatcher-3504fd5080dbcfd0172299c5c6d13895e53ad163.tar.gz dispatcher-3504fd5080dbcfd0172299c5c6d13895e53ad163.tar.bz2 dispatcher-3504fd5080dbcfd0172299c5c6d13895e53ad163.zip |
Removed position caches
There aren't going to be enough entities at once for position checking to ever really be a bottleneck, I don't think. Removing the caches makes the range logic a bit more intuitive, and it removes the possibility of accidentally not updating a cache when it needs to be.
Diffstat (limited to 'src/simulation.cpp')
-rw-r--r-- | src/simulation.cpp | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/src/simulation.cpp b/src/simulation.cpp index f75bd3d..27ac6ab 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp | |||
@@ -89,12 +89,6 @@ Simulation::Simulation( | |||
89 | crate2.canBePushedBy.insert(ColliderType::crate); | 89 | crate2.canBePushedBy.insert(ColliderType::crate); |
90 | crate2.canBePushedBy.insert(ColliderType::train); | 90 | crate2.canBePushedBy.insert(ColliderType::train); |
91 | crate2.gridPos = vec2s { 6, 7 }; | 91 | crate2.gridPos = vec2s { 6, 7 }; |
92 | |||
93 | |||
94 | for (Entity& entity : active_ | entityView()) | ||
95 | { | ||
96 | posCache_.set(entity.id, entity.gridPos); | ||
97 | } | ||
98 | } | 92 | } |
99 | 93 | ||
100 | void Simulation::tick( | 94 | void Simulation::tick( |
@@ -132,8 +126,9 @@ void Simulation::tick( | |||
132 | vec2s lookPos = posInDir(entity.gridPos, lookDir); | 126 | vec2s lookPos = posInDir(entity.gridPos, lookDir); |
133 | 127 | ||
134 | for (Entity& block : | 128 | for (Entity& block : |
135 | posCache_.at(lookPos) | | 129 | active_ | |
136 | entityView() | | 130 | entityView() | |
131 | views::atGridPos(lookPos) | | ||
137 | views::isNotMoving() | | 132 | views::isNotMoving() | |
138 | views::canBePushedBy(entity.colliderType) | | 133 | views::canBePushedBy(entity.colliderType) | |
139 | views::isOnLayer(entity.layer)) | 134 | views::isOnLayer(entity.layer)) |
@@ -185,8 +180,9 @@ void Simulation::tick( | |||
185 | views::isNotMoving()) | 180 | views::isNotMoving()) |
186 | { | 181 | { |
187 | auto tracks = | 182 | auto tracks = |
188 | posCache_.at(entity.gridPos) | | 183 | active_ | |
189 | entityView() | | 184 | entityView() | |
185 | views::atGridPos(entity.gridPos) | | ||
190 | views::isTrack(); | 186 | views::isTrack(); |
191 | 187 | ||
192 | if (!ranges::empty(tracks)) | 188 | if (!ranges::empty(tracks)) |
@@ -233,8 +229,6 @@ void Simulation::tick( | |||
233 | { | 229 | { |
234 | entity.moving = false; | 230 | entity.moving = false; |
235 | entity.gridPos = entity.destPos; | 231 | entity.gridPos = entity.destPos; |
236 | posCache_.set(entity.id, entity.gridPos); | ||
237 | moveToCache_.remove(entity.id); | ||
238 | } | 232 | } |
239 | } | 233 | } |
240 | 234 | ||
@@ -340,16 +334,18 @@ bool Simulation::moveEntityOnGrid( | |||
340 | 334 | ||
341 | // Can't move into a space that something else is already moving into. | 335 | // Can't move into a space that something else is already moving into. |
342 | if (!ranges::empty( | 336 | if (!ranges::empty( |
343 | moveToCache_.at(shouldMoveTo) | | 337 | active_ | |
344 | entityView() | | 338 | entityView() | |
339 | views::isMovingTo(shouldMoveTo) | | ||
345 | views::isOnLayer(entity.layer))) | 340 | views::isOnLayer(entity.layer))) |
346 | { | 341 | { |
347 | return false; | 342 | return false; |
348 | } | 343 | } |
349 | 344 | ||
350 | for (Entity& block : | 345 | for (Entity& block : |
351 | posCache_.at(shouldMoveTo) | | 346 | active_ | |
352 | entityView() | | 347 | entityView() | |
348 | views::atGridPos(shouldMoveTo) | | ||
353 | views::isOnLayer(entity.layer)) | 349 | views::isOnLayer(entity.layer)) |
354 | { | 350 | { |
355 | if (!block.moving) | 351 | if (!block.moving) |
@@ -389,8 +385,6 @@ bool Simulation::moveEntityOnGrid( | |||
389 | entity.destPos = shouldMoveTo; | 385 | entity.destPos = shouldMoveTo; |
390 | entity.movementTween = 0.0; | 386 | entity.movementTween = 0.0; |
391 | entity.moveDir = moveDir; | 387 | entity.moveDir = moveDir; |
392 | |||
393 | moveToCache_.set(entity.id, entity.destPos); | ||
394 | } | 388 | } |
395 | 389 | ||
396 | return true; | 390 | return true; |