From 3504fd5080dbcfd0172299c5c6d13895e53ad163 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sat, 23 Feb 2019 12:15:46 -0500 Subject: 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. --- src/simulation.cpp | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'src/simulation.cpp') 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( crate2.canBePushedBy.insert(ColliderType::crate); crate2.canBePushedBy.insert(ColliderType::train); crate2.gridPos = vec2s { 6, 7 }; - - - for (Entity& entity : active_ | entityView()) - { - posCache_.set(entity.id, entity.gridPos); - } } void Simulation::tick( @@ -132,8 +126,9 @@ void Simulation::tick( vec2s lookPos = posInDir(entity.gridPos, lookDir); for (Entity& block : - posCache_.at(lookPos) | + active_ | entityView() | + views::atGridPos(lookPos) | views::isNotMoving() | views::canBePushedBy(entity.colliderType) | views::isOnLayer(entity.layer)) @@ -185,8 +180,9 @@ void Simulation::tick( views::isNotMoving()) { auto tracks = - posCache_.at(entity.gridPos) | + active_ | entityView() | + views::atGridPos(entity.gridPos) | views::isTrack(); if (!ranges::empty(tracks)) @@ -233,8 +229,6 @@ void Simulation::tick( { entity.moving = false; entity.gridPos = entity.destPos; - posCache_.set(entity.id, entity.gridPos); - moveToCache_.remove(entity.id); } } @@ -340,16 +334,18 @@ bool Simulation::moveEntityOnGrid( // Can't move into a space that something else is already moving into. if (!ranges::empty( - moveToCache_.at(shouldMoveTo) | + active_ | entityView() | + views::isMovingTo(shouldMoveTo) | views::isOnLayer(entity.layer))) { return false; } for (Entity& block : - posCache_.at(shouldMoveTo) | + active_ | entityView() | + views::atGridPos(shouldMoveTo) | views::isOnLayer(entity.layer)) { if (!block.moving) @@ -389,8 +385,6 @@ bool Simulation::moveEntityOnGrid( entity.destPos = shouldMoveTo; entity.movementTween = 0.0; entity.moveDir = moveDir; - - moveToCache_.set(entity.id, entity.destPos); } return true; -- cgit 1.4.1