Example #1
0
/** Sets the kart position and controls to the recorded history value.
 *  \param dt Time step size.
 */
float History::updateReplayAndGetDT()
{
    m_current++;
    World *world = World::getWorld();
    if(m_current>=(int)m_all_deltas.size())
    {
        Log::info("History", "Replay finished");
        m_current = 0;
        // This is useful to use a reproducable rewind problem:
        // replay it with history, for debugging only
#undef DO_REWIND_AT_END_OF_HISTORY
#ifdef DO_REWIND_AT_END_OF_HISTORY
        RewindManager::get()->rewindTo(5.0f);
        exit(-1);
#else
        // Note that for physics replay all physics parameters
        // need to be reset, e.g. velocity, ...
        world->reset();
#endif
    }
    unsigned int num_karts = world->getNumKarts();
    for(unsigned k=0; k<num_karts; k++)
    {
        AbstractKart *kart = world->getKart(k);
        unsigned int index=m_current*num_karts+k;
        if(m_replay_mode==HISTORY_POSITION)
        {
            kart->setXYZ(m_all_xyz[index]);
            kart->setRotation(m_all_rotations[index]);
        }
        else
        {
            kart->getControls().set(m_all_controls[index]);
        }
    }
    return m_all_deltas[m_current];
}   // updateReplayAndGetDT