Ghost finish times based on replay data (#3262)

* New ghost kart function to compute finish time

* Don't estimate the finish time for ghosts, use replay data
This commit is contained in:
Alayan-stk-2 2018-05-20 01:23:44 +02:00 committed by auriamg
parent b8d2dc9034
commit 4fdd3eee38
3 changed files with 35 additions and 0 deletions

View File

@ -27,6 +27,7 @@
#include "modes/linear_world.hpp"
#include "modes/world.hpp"
#include "replay/replay_recorder.hpp"
#include "tracks/track.hpp"
#include "LinearMath/btQuaternion.h"
@ -234,6 +235,23 @@ float GhostKart::getSpeed() const
+ rd *m_all_physic_info[current_index + 1].m_speed;
} // getSpeed
// ----------------------------------------------------------------------------
/** Compute the time at which the ghost finished the race */
void GhostKart::computeFinishTime()
{
// In egg hunts, the finish time is the moment at which all egs are collected
if (race_manager->isEggHuntMode())
{
m_finish_time = 0; //FIXME : do a real computation
}
else // linear races
{
float full_distance = race_manager->getNumLaps()
* Track::getCurrentTrack()->getTrackLength();
m_finish_time = getTimeForDistance(full_distance);
}
}
// ----------------------------------------------------------------------------
/** Returns the time at which the kart was at a given distance.
* Returns -1.0f if none */

View File

@ -48,6 +48,10 @@ private:
unsigned int m_last_egg_idx = 0;
// ----------------------------------------------------------------------------
/** Compute the time at which the ghost finished the race */
void computeFinishTime();
public:
GhostKart(const std::string& ident, unsigned int world_kart_id,
int position, float color_hue);
@ -82,6 +86,10 @@ public:
/** Returns the speed of the kart in meters/second. */
virtual float getSpeed() const OVERRIDE;
// ------------------------------------------------------------------------
/** Returns the finished time for a ghost kart. */
float getGhostFinishTime() { computeFinishTime(); return m_finish_time; }
// ------------------------------------------------------------------------
/** Returns the time at which the kart was at a given distance.
* Returns -1.0f if none */
@ -93,3 +101,4 @@ public:
}; // GhostKart
#endif

View File

@ -25,6 +25,7 @@
#include "config/user_config.hpp"
#include "karts/abstract_kart.hpp"
#include "karts/controller/controller.hpp"
#include "karts/ghost_kart.hpp"
#include "karts/kart_properties.hpp"
#include "graphics/material.hpp"
#include "guiengine/modaldialog.hpp"
@ -621,6 +622,13 @@ float LinearWorld::estimateFinishTimeForKart(AbstractKart* kart)
float full_distance = race_manager->getNumLaps()
* Track::getCurrentTrack()->getTrackLength();
// For ghost karts, use the replay data rather than estimating
if (kart->isGhostKart())
{
GhostKart* gk = dynamic_cast<GhostKart*>(kart);
return gk->getGhostFinishTime();
}
if(full_distance == 0)
full_distance = 1.0f; // For 0 lap races avoid warning below