Make sure all karts has the same position before go phase

This commit is contained in:
Benau 2018-08-20 15:40:29 +08:00
parent 2fa233179c
commit f48491c279
4 changed files with 32 additions and 13 deletions

View File

@ -143,16 +143,6 @@ void AbstractKart::setKartAnimation(AbstractKartAnimation *ka)
m_kart_animation = ka;
} // setKartAnimation
// ----------------------------------------------------------------------------
/** Moves the current physical transform into this kart's position.
*/
void AbstractKart::kartIsInRestNow()
{
// Update the kart transforms with the newly computed position
// after all karts are reset
setTrans(getBody()->getWorldTransform());
} // kartIsInRest
// ----------------------------------------------------------------------------
/** Returns the time at which the kart was at a given distance.
* Returns -1.0f if none */
@ -160,3 +150,27 @@ float AbstractKart::getTimeForDistance(float distance)
{
return -1.0f;
} // getTimeForDistance
// ----------------------------------------------------------------------------
/** Moves the current physical transform into this kart's position.
*/
void AbstractKart::kartIsInRestNow()
{
// Update the kart transforms with the newly computed position
// after all karts are reset
m_starting_transform = getBody()->getWorldTransform();
setTrans(m_starting_transform);
} // kartIsInRest
// ------------------------------------------------------------------------
/** Called before go phase to make sure all karts start at the same
* position in case there is a slope. */
void AbstractKart::makeKartRest()
{
btRigidBody *body = getBody();
body->clearForces();
body->setLinearVelocity(Vec3(0.0f));
body->setAngularVelocity(Vec3(0.0f));
body->proceedToTransform(m_starting_transform);
setTrans(m_starting_transform);
} // makeKartRest

View File

@ -74,7 +74,7 @@ private:
/** Index of kart in world. */
unsigned int m_world_kart_id;
btTransform m_starting_transform;
protected:
/** The kart properties. */
std::unique_ptr<KartProperties> m_kart_properties;
@ -509,6 +509,9 @@ public:
virtual void playSound(SFXBuffer* buffer) = 0;
// ------------------------------------------------------------------------
virtual bool isVisible() = 0;
// ------------------------------------------------------------------------
virtual void makeKartRest();
}; // AbstractKart

View File

@ -98,9 +98,9 @@ public:
float getTimeForEggs(int egg_number);
// ------------------------------------------------------------------------
virtual void kartIsInRestNow() OVERRIDE {};
virtual void kartIsInRestNow() OVERRIDE {}
// ------------------------------------------------------------------------
virtual void makeKartRest() OVERRIDE {}
}; // GhostKart
#endif

View File

@ -1064,6 +1064,8 @@ void World::update(int ticks)
// Update all karts that are not eliminated
if(!m_karts[i]->isEliminated() || (sta && sta->isMoving()))
m_karts[i]->update(ticks);
if (isStartPhase())
m_karts[i]->makeKartRest();
}
PROFILER_POP_CPU_MARKER();
if(race_manager->isRecordingRace()) ReplayRecorder::get()->update(ticks);