MCPcopy Create free account
hub / github.com/OpenDungeons/OpenDungeons / update

Method update

source/entities/MovableGameEntity.cpp:209–269  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

207}
208
209void MovableGameEntity::update(Ogre::Real timeSinceLastFrame)
210{
211 // Advance the animation
212 double addedTime = static_cast<Ogre::Real>(ODApplication::turnsPerSecond
213 * static_cast<double>(timeSinceLastFrame)
214 * getAnimationSpeedFactor());
215 mAnimationTime += addedTime;
216 if (!getIsOnServerMap() && getAnimationState() != nullptr)
217 {
218 // If the animation has stopped we set it to idle if we have to
219 if(mDestinationPlayIdleWhenAnimationEnds && getAnimationState()->hasEnded())
220 RenderManager::getSingleton().rrSetObjectAnimationState(this, EntityAnimation::idle_anim, true);
221 else
222 getAnimationState()->addTime(static_cast<Ogre::Real>(addedTime));
223 }
224
225 if (mWalkQueue.empty())
226 return;
227
228 // Move the entity
229
230 // Note: When the client and the server are using different frame rates, the entities walk at different speeds
231 // If this happens to become a problem, resyncing mechanisms will be needed.
232 double moveDist = ODApplication::turnsPerSecond
233 * getMoveSpeed()
234 * timeSinceLastFrame;
235 Ogre::Vector3 newPosition = getPosition();
236 Ogre::Vector3 nextDest = mWalkQueue.front();
237 Ogre::Vector3 walkDirection = nextDest - newPosition;
238 walkDirection.normalise();
239
240 while(moveDist > 0.0)
241 {
242 Ogre::Real distToNextDest = newPosition.distance(nextDest);
243 if(distToNextDest > moveDist)
244 {
245 newPosition = newPosition + walkDirection * static_cast<Ogre::Real>(moveDist);
246 break;
247 }
248 else
249 {
250 // We have reached the destination. We go to the next if available
251 newPosition = nextDest;
252 moveDist -= distToNextDest;
253 mWalkQueue.pop_front();
254 if(mWalkQueue.empty())
255 {
256 // Stop walking
257 stopWalking();
258 break;
259 }
260
261 nextDest = mWalkQueue.front();
262 walkDirection = nextDest - newPosition;
263 walkDirection.normalise();
264 }
265 }
266

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected