summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-05-04 11:08:48 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2018-05-09 17:59:13 -0400
commit83534176373bd05a13db88ffff095f52cca07a21 (patch)
treeab36e74f2d7ad53284cd875cac56f657d9325cf8 /src
parent893dbf8a235db2b4f1fafacf90290b0821f0048c (diff)
downloadtherapy-83534176373bd05a13db88ffff095f52cca07a21.tar.gz
therapy-83534176373bd05a13db88ffff095f52cca07a21.tar.bz2
therapy-83534176373bd05a13db88ffff095f52cca07a21.zip
Fixed behavior of frozen bodies
Frozen bodies are now still ticked, but their velocities and positions are no longer changed. This change was made so that frozen bodies can still be ungrounded/unferried, and that passengers of frozen bodies can still be ticked.

Also fixes a compile error.
Diffstat (limited to 'src')
-rw-r--r--src/components/ponderable.h5
-rw-r--r--src/systems/pondering.cpp50
2 files changed, 33 insertions, 22 deletions
diff --git a/src/components/ponderable.h b/src/components/ponderable.h index 45150a0..6a01400 100644 --- a/src/components/ponderable.h +++ b/src/components/ponderable.h
@@ -100,7 +100,10 @@ public:
100 std::set<id_type> passengers; 100 std::set<id_type> passengers;
101 101
102 /** 102 /**
103 * If enabled, this will prevent the body from moving. 103 * If enabled, this will prevent the body from moving and accelerating. The
104 * velocity and position of the body can still be affected by sources external
105 * to the PonderingSystem. Enabling this will cause applicable bodies to
106 * become ungrounded and unferried.
104 */ 107 */
105 bool frozen = false; 108 bool frozen = false;
106 109
diff --git a/src/systems/pondering.cpp b/src/systems/pondering.cpp index e6417eb..0be3add 100644 --- a/src/systems/pondering.cpp +++ b/src/systems/pondering.cpp
@@ -91,9 +91,9 @@ void PonderingSystem::tickBody(
91 auto& ponderable = game_.getEntityManager(). 91 auto& ponderable = game_.getEntityManager().
92 getComponent<PonderableComponent>(entity); 92 getComponent<PonderableComponent>(entity);
93 93
94 if (!ponderable.active || ponderable.frozen) 94 if (!ponderable.active)
95 { 95 {
96 continue; 96 return;
97 } 97 }
98 98
99 auto& realizable = game_.getEntityManager(). 99 auto& realizable = game_.getEntityManager().
@@ -109,13 +109,16 @@ void PonderingSystem::tickBody(
109 getComponent<TransformableComponent>(entity); 109 getComponent<TransformableComponent>(entity);
110 110
111 // Accelerate 111 // Accelerate
112 ponderable.velX += ponderable.accelX * dt; 112 if (!ponderable.frozen)
113 ponderable.velY += ponderable.accelY * dt;
114
115 if ((ponderable.type == PonderableComponent::Type::freefalling)
116 && (ponderable.velY > TERMINAL_VELOCITY))
117 { 113 {
118 ponderable.velY = TERMINAL_VELOCITY; 114 ponderable.velX += ponderable.accelX * dt;
115 ponderable.velY += ponderable.accelY * dt;
116
117 if ((ponderable.type == PonderableComponent::Type::freefalling)
118 && (ponderable.velY > TERMINAL_VELOCITY))
119 {
120 ponderable.velY = TERMINAL_VELOCITY;
121 }
119 } 122 }
120 123
121 const double oldX = transformable.x; 124 const double oldX = transformable.x;
@@ -124,21 +127,23 @@ void PonderingSystem::tickBody(
124 const double oldBottom = oldY + transformable.h; 127 const double oldBottom = oldY + transformable.h;
125 128
126 CollisionResult result; 129 CollisionResult result;
130 result.newX = transformable.x;
131 result.newY = transformable.y;
127 132
128 if (ponderable.ferried) 133 if (!ponderable.frozen)
129 { 134 {
130 auto& ferryTrans = game_.getEntityManager(). 135 if (ponderable.ferried)
131 getComponent<TransformableComponent>(ponderable.ferry); 136 {
137 auto& ferryTrans = game_.getEntityManager().
138 getComponent<TransformableComponent>(ponderable.ferry);
132 139
133 result.newX = ferryTrans.x + ponderable.relX; 140 result.newX = ferryTrans.x + ponderable.relX;
134 result.newY = ferryTrans.y + ponderable.relY; 141 result.newY = ferryTrans.y + ponderable.relY;
135 } else { 142 }
136 result.newX = transformable.x;
137 result.newY = transformable.y;
138 }
139 143
140 result.newX += ponderable.velX * dt; 144 result.newX += ponderable.velX * dt;
141 result.newY += ponderable.velY * dt; 145 result.newY += ponderable.velY * dt;
146 }
142 147
143 bool oldGrounded = ponderable.grounded; 148 bool oldGrounded = ponderable.grounded;
144 ponderable.grounded = false; 149 ponderable.grounded = false;
@@ -694,8 +699,11 @@ void PonderingSystem::tickBody(
694 } 699 }
695 700
696 // Move 701 // Move
697 transformable.x = result.newX; 702 if (!ponderable.frozen)
698 transformable.y = result.newY; 703 {
704 transformable.x = result.newX;
705 transformable.y = result.newY;
706 }
699 707
700 // Perform cleanup for orientable entites 708 // Perform cleanup for orientable entites
701 if (game_.getEntityManager().hasComponent<OrientableComponent>(entity)) 709 if (game_.getEntityManager().hasComponent<OrientableComponent>(entity))