summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2021-03-02 19:21:36 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2021-03-02 19:21:36 -0500
commit198a13fa1004534538122579dcdac4cf311b8603 (patch)
treedf582c5d30bda091d84b8269d5e690713133502c
parentf0efccecadea6476dde042748d5ed42d4a9b5cb3 (diff)
downloadtanetane-198a13fa1004534538122579dcdac4cf311b8603.tar.gz
tanetane-198a13fa1004534538122579dcdac4cf311b8603.tar.bz2
tanetane-198a13fa1004534538122579dcdac4cf311b8603.zip
Handled case where a pathfollowing sprite overshoots its destination
This may happen due to lag or due to debugging with lldb. What happens is that 60 times a second, the engine will check whether the direction toward the current endpoint is equal to the direction in the pathfinding instruction, and if it isn't (because the sprite has gone past the endpoint) then it sets the sprite's position to the endpoint instantly so that the pathfinding can continue.
-rw-r--r--src/behaviour_system.cpp15
-rw-r--r--src/behaviour_system.h1
2 files changed, 16 insertions, 0 deletions
diff --git a/src/behaviour_system.cpp b/src/behaviour_system.cpp index a05912c..b68cd6d 100644 --- a/src/behaviour_system.cpp +++ b/src/behaviour_system.cpp
@@ -40,6 +40,21 @@ void BehaviourSystem::tick(double dt) {
40 } 40 }
41 } 41 }
42 42
43 overcorrectionTimer_.accumulate(dt);
44 while (overcorrectionTimer_.step()) {
45 for (int spriteId : game_.getSprites()) {
46 Sprite& sprite = game_.getSprite(spriteId);
47 if (!sprite.paused &&
48 sprite.behaviourType == BehaviourType::Path &&
49 !sprite.path.empty() &&
50 sprite.loc != sprite.path.front().endpoint) {
51 if (directionFacingPoint(sprite.path.front().endpoint - sprite.loc) != sprite.path.front().dir) {
52 game_.getSystem<TransformSystem>().moveSprite(spriteId, sprite.path.front().endpoint);
53 }
54 }
55 }
56 }
57
43 for (int spriteId : game_.getSprites()) { 58 for (int spriteId : game_.getSprites()) {
44 Sprite& sprite = game_.getSprite(spriteId); 59 Sprite& sprite = game_.getSprite(spriteId);
45 if (!sprite.paused && sprite.behaviourType == BehaviourType::Path) { 60 if (!sprite.paused && sprite.behaviourType == BehaviourType::Path) {
diff --git a/src/behaviour_system.h b/src/behaviour_system.h index 526a09b..1ddce4a 100644 --- a/src/behaviour_system.h +++ b/src/behaviour_system.h
@@ -31,6 +31,7 @@ private:
31 31
32 Game& game_; 32 Game& game_;
33 Timer timer_ { 500 }; 33 Timer timer_ { 500 };
34 Timer overcorrectionTimer_ { 1000/60 };
34}; 35};
35 36
36#endif /* end of include guard: BEHAVIOUR_SYSTEM_H_FC908ABE */ 37#endif /* end of include guard: BEHAVIOUR_SYSTEM_H_FC908ABE */