Use count up ticks on rewinding for time limit in soccer game
This commit is contained in:
parent
724828b031
commit
49d7a2fbbc
@ -302,9 +302,9 @@ void InputManager::handleStaticAction(int key, int value)
|
||||
fgets(s, 256, stdin);
|
||||
int t;
|
||||
StringUtils::fromString(s,t);
|
||||
RewindManager::get()->rewindTo(t, world->getTimeTicks());
|
||||
RewindManager::get()->rewindTo(t, world->getTicksSinceStart());
|
||||
Log::info("Rewind", "Rewinding from %d to %d",
|
||||
world->getTimeTicks(), t);
|
||||
world->getTicksSinceStart(), t);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -345,7 +345,7 @@ void Attachment::hitBanana(ItemState *item_state)
|
||||
// Use this as a basic random number to make sync with server easier.
|
||||
// Divide by 16 to increase probablity to have same time as server in
|
||||
// case of a few physics frames different between client and server.
|
||||
int ticks = World::getWorld()->getTimeTicks() / 16;
|
||||
int ticks = World::getWorld()->getTicksSinceStart() / 16;
|
||||
switch(getType()) // If there already is an attachment, make it worse :)
|
||||
{
|
||||
case ATTACH_BOMB:
|
||||
|
@ -101,7 +101,7 @@ void NetworkItemManager::collectedItem(Item *item, AbstractKart *kart)
|
||||
{
|
||||
// The server saves the collected item as item event info
|
||||
m_item_events.lock();
|
||||
m_item_events.getData().emplace_back(World::getWorld()->getTimeTicks(),
|
||||
m_item_events.getData().emplace_back(World::getWorld()->getTicksSinceStart(),
|
||||
item->getItemId(),
|
||||
kart->getWorldKartId());
|
||||
m_item_events.unlock();
|
||||
@ -136,7 +136,7 @@ Item* NetworkItemManager::dropNewItem(ItemState::ItemType type,
|
||||
|
||||
// Server: store the data for this event:
|
||||
m_item_events.lock();
|
||||
m_item_events.getData().emplace_back(World::getWorld()->getTimeTicks(),
|
||||
m_item_events.getData().emplace_back(World::getWorld()->getTicksSinceStart(),
|
||||
type, item->getItemId(),
|
||||
kart->getWorldKartId(),
|
||||
kart->getXYZ());
|
||||
@ -246,7 +246,7 @@ void NetworkItemManager::forwardTime(int ticks)
|
||||
void NetworkItemManager::restoreState(BareNetworkString *buffer, int count)
|
||||
{
|
||||
assert(NetworkConfig::get()->isClient());
|
||||
// The state at World::getTimeTicks() needs to be restored. The confirmed
|
||||
// The state at World::getTicksSinceStart() needs to be restored. The confirmed
|
||||
// state in this instance was taken at m_confirmed_state_time. First
|
||||
// forward this confirmed state to the current time (i.e. world time).
|
||||
// This is done in several steps:
|
||||
@ -332,10 +332,10 @@ void NetworkItemManager::restoreState(BareNetworkString *buffer, int count)
|
||||
|
||||
// Inform the server which events have been received.
|
||||
if (auto gp = GameProtocol::lock())
|
||||
gp->sendItemEventConfirmation(World::getWorld()->getTimeTicks());
|
||||
gp->sendItemEventConfirmation(World::getWorld()->getTicksSinceStart());
|
||||
|
||||
// Forward the confirmed item state till the world time:
|
||||
int dt = World::getWorld()->getTimeTicks() - current_time;
|
||||
int dt = World::getWorld()->getTicksSinceStart() - current_time;
|
||||
if(dt>0) forwardTime(dt);
|
||||
|
||||
// Restore the state to the current world time:
|
||||
@ -363,6 +363,6 @@ void NetworkItemManager::restoreState(BareNetworkString *buffer, int count)
|
||||
}
|
||||
|
||||
// Now we save the current local
|
||||
m_confirmed_state_time = World::getWorld()->getTimeTicks();
|
||||
m_confirmed_state_time = World::getWorld()->getTicksSinceStart();
|
||||
} // restoreState
|
||||
|
||||
|
@ -504,7 +504,7 @@ void Powerup::hitBonusBox(const ItemState &item_state)
|
||||
// number to spread the random values across the (typically 200)
|
||||
// weights used in the PowerupManager - same for the position.
|
||||
int random_number = item_state.getItemId()*31
|
||||
+ world->getTimeTicks() / 10 + position*23;
|
||||
+ world->getTicksSinceStart() / 10 + position*23;
|
||||
new_powerup =
|
||||
powerup_manager->getRandomPowerup(position, &n, random_number);
|
||||
if (new_powerup != PowerupManager::POWERUP_RUBBERBALL ||
|
||||
@ -514,7 +514,7 @@ void Powerup::hitBonusBox(const ItemState &item_state)
|
||||
}
|
||||
|
||||
if(new_powerup == PowerupManager::POWERUP_RUBBERBALL)
|
||||
powerup_manager->setBallCollectTicks(world->getTimeTicks());
|
||||
powerup_manager->setBallCollectTicks(world->getTicksSinceStart());
|
||||
|
||||
// Always add a new powerup in ITEM_MODE_NEW (or if the kart
|
||||
// doesn't have a powerup atm).
|
||||
|
@ -416,7 +416,7 @@ int PowerupManager::WeightsData::getRandomItem(int rank, int random_number)
|
||||
// We don't do more, because it would need to be decoded from enum later
|
||||
#ifdef ITEM_DISTRIBUTION_DEBUG
|
||||
Log::verbose("Powerup", "World %d rank %d random %d %d item %d",
|
||||
World::getWorld()->getTimeTicks(), rank, random_number,
|
||||
World::getWorld()->getTicksSinceStart(), rank, random_number,
|
||||
original_random_number, powerup);
|
||||
#endif
|
||||
|
||||
|
@ -97,7 +97,7 @@ AbstractKartAnimation::~AbstractKartAnimation()
|
||||
btTransform m_transform;
|
||||
public:
|
||||
AnimationEvent(AbstractKart* kart)
|
||||
: RewindInfo(World::getWorld()->getTimeTicks(),
|
||||
: RewindInfo(World::getWorld()->getTicksSinceStart(),
|
||||
true/*is_confirmed*/)
|
||||
{
|
||||
m_kart = kart;
|
||||
|
@ -1492,7 +1492,7 @@ void Kart::update(int ticks)
|
||||
"maxspeed(35) %f engf(37) %f braketick(39) %d brakes(41) %d heading(43) %f "
|
||||
"noderot(45) %f suslen %f",
|
||||
getIdent().c_str(),
|
||||
World::getWorld()->getTime(), World::getWorld()->getTimeTicks(),
|
||||
World::getWorld()->getTime(), World::getWorld()->getTicksSinceStart(),
|
||||
getXYZ().getX(), getXYZ().getY(), getXYZ().getZ(),
|
||||
m_body->getWorldTransform().getOrigin().getX(),
|
||||
m_body->getWorldTransform().getOrigin().getY(),
|
||||
@ -1604,7 +1604,7 @@ void Kart::update(int ticks)
|
||||
if(UserConfigParams::m_material_debug)
|
||||
{
|
||||
Log::info("Kart","World %d %s\tfraction %f\ttime %d.",
|
||||
World::getWorld()->getTimeTicks(),
|
||||
World::getWorld()->getTicksSinceStart(),
|
||||
material->getTexFname().c_str(),
|
||||
material->getMaxSpeedFraction(),
|
||||
material->getSlowDownTicks() );
|
||||
|
@ -374,7 +374,7 @@ void MainLoop::run()
|
||||
GUIEngine::update(frame_duration);
|
||||
PROFILER_POP_CPU_MARKER();
|
||||
if (World::getWorld() && history->replayHistory())
|
||||
history->updateReplay(World::getWorld()->getTimeTicks());
|
||||
history->updateReplay(World::getWorld()->getTicksSinceStart());
|
||||
PROFILER_PUSH_CPU_MARKER("Music", 0x7F, 0x00, 0x00);
|
||||
SFXManager::get()->update();
|
||||
PROFILER_POP_CPU_MARKER();
|
||||
|
@ -499,6 +499,23 @@ void WorldStatus::setTicks(int ticks)
|
||||
m_time = stk_config->ticks2Time(ticks);
|
||||
} // setTicks
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Sets a new time for the world time (used by rewind), measured in ticks.
|
||||
* \param ticks New time in ticks to set (always count upwards).
|
||||
*/
|
||||
void WorldStatus::setTicksForRewind(int ticks)
|
||||
{
|
||||
m_count_up_ticks = ticks;
|
||||
if (race_manager->hasTimeTarget())
|
||||
{
|
||||
m_time_ticks = stk_config->time2Ticks(race_manager->getTimeTarget()) -
|
||||
m_count_up_ticks;
|
||||
}
|
||||
else
|
||||
m_time_ticks = ticks;
|
||||
m_time = stk_config->ticks2Time(m_time_ticks);
|
||||
} // setTicksForRewind
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Pauses the game and switches to the specified phase.
|
||||
* \param phase Phase to switch to.
|
||||
|
@ -154,7 +154,7 @@ public:
|
||||
virtual void terminateRace();
|
||||
void setTime(const float time);
|
||||
void setTicks(int ticks);
|
||||
|
||||
void setTicksForRewind(int ticks);
|
||||
// ------------------------------------------------------------------------
|
||||
// Note: GO_PHASE is both: start phase and race phase
|
||||
bool isStartPhase() const { return m_phase<GO_PHASE; }
|
||||
|
@ -136,7 +136,7 @@ void GameProtocol::controllerAction(int kart_id, PlayerAction action,
|
||||
a.m_value = value;
|
||||
a.m_value_l = val_l;
|
||||
a.m_value_r = val_r;
|
||||
a.m_ticks = World::getWorld()->getTimeTicks();
|
||||
a.m_ticks = World::getWorld()->getTicksSinceStart();
|
||||
|
||||
m_all_actions.push_back(a);
|
||||
|
||||
@ -147,7 +147,7 @@ void GameProtocol::controllerAction(int kart_id, PlayerAction action,
|
||||
.addUInt32(val_l).addUInt32(val_r);
|
||||
|
||||
RewindManager::get()->addEvent(this, s, /*confirmed*/true,
|
||||
World::getWorld()->getTimeTicks() );
|
||||
World::getWorld()->getTicksSinceStart());
|
||||
} // controllerAction
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -214,7 +214,7 @@ void GameProtocol::handleControllerAction(Event *event)
|
||||
rewind_delta += max_adjustment;
|
||||
Log::info("GameProtocol", "At %d %f %d requesting time adjust"
|
||||
" (speed up) of %d for host %d",
|
||||
World::getWorld()->getTimeTicks(), StkTime::getRealTime(),
|
||||
World::getWorld()->getTicksSinceStart(), StkTime::getRealTime(),
|
||||
not_rewound, rewind_delta, event->getPeer()->getHostId());
|
||||
// This message from a client triggered a rewind in the server.
|
||||
// To avoid this, signal to the client that it should speed up.
|
||||
@ -228,7 +228,7 @@ void GameProtocol::handleControllerAction(Event *event)
|
||||
const int adjustment = ticks_difference - cur_diff;
|
||||
Log::info("GameProtocol", "At %d %f %d requesting time adjust"
|
||||
" (slow down) of %d for host %d",
|
||||
World::getWorld()->getTimeTicks(), StkTime::getRealTime(),
|
||||
World::getWorld()->getTicksSinceStart(), StkTime::getRealTime(),
|
||||
not_rewound, adjustment, event->getPeer()->getHostId());
|
||||
adjustTimeForClient(event->getPeer(), adjustment);
|
||||
}*/
|
||||
@ -310,7 +310,7 @@ void GameProtocol::startNewState()
|
||||
assert(NetworkConfig::get()->isServer());
|
||||
m_data_to_send->clear();
|
||||
m_data_to_send->addUInt8(GP_STATE)
|
||||
.addUInt32(World::getWorld()->getTimeTicks());
|
||||
.addUInt32(World::getWorld()->getTicksSinceStart());
|
||||
} // startNewState
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -29,7 +29,7 @@ void RaceEventManager::update(int ticks)
|
||||
// This might adjust dt - if a new state is being played, the dt is
|
||||
// determined from the last state till 'now'
|
||||
PROFILER_PUSH_CPU_MARKER("RaceEvent:play event", 100, 100, 100);
|
||||
RewindManager::get()->playEventsTill(World::getWorld()->getTimeTicks(),
|
||||
RewindManager::get()->playEventsTill(World::getWorld()->getTicksSinceStart(),
|
||||
&ticks);
|
||||
PROFILER_POP_CPU_MARKER();
|
||||
World::getWorld()->updateWorld(ticks);
|
||||
@ -41,6 +41,7 @@ bool RaceEventManager::isRaceOver()
|
||||
if(!World::getWorld())
|
||||
return false;
|
||||
return (World::getWorld()->getPhase() > WorldStatus::RACE_PHASE &&
|
||||
World::getWorld()->getPhase() != WorldStatus::GOAL_PHASE &&
|
||||
World::getWorld()->getPhase() != WorldStatus::IN_GAME_MENU_PHASE);
|
||||
} // isRaceOver
|
||||
|
||||
|
@ -116,7 +116,7 @@ void RewindManager::addEvent(EventRewinder *event_rewinder,
|
||||
}
|
||||
|
||||
if (ticks < 0)
|
||||
ticks = World::getWorld()->getTimeTicks();
|
||||
ticks = World::getWorld()->getTicksSinceStart();
|
||||
m_rewind_queue.addLocalEvent(event_rewinder, buffer, confirmed, ticks);
|
||||
} // addEvent
|
||||
|
||||
@ -190,7 +190,7 @@ void RewindManager::update(int ticks_not_used)
|
||||
m_all_rewinder.size() == 0 ||
|
||||
m_is_rewinding) return;
|
||||
|
||||
int ticks = World::getWorld()->getTimeTicks();
|
||||
int ticks = World::getWorld()->getTicksSinceStart();
|
||||
|
||||
m_not_rewound_ticks.store(ticks, std::memory_order_relaxed);
|
||||
|
||||
@ -237,7 +237,7 @@ void RewindManager::playEventsTill(int world_ticks, int *ticks)
|
||||
PROFILER_PUSH_CPU_MARKER("Rewind", 128, 128, 128);
|
||||
rewindTo(rewind_ticks, world_ticks);
|
||||
// This should replay everything up to 'now'
|
||||
assert(World::getWorld()->getTimeTicks() == world_ticks);
|
||||
assert(World::getWorld()->getTicksSinceStart() == world_ticks);
|
||||
PROFILER_POP_CPU_MARKER();
|
||||
Log::setPrefix("");
|
||||
}
|
||||
@ -292,7 +292,7 @@ void RewindManager::rewindTo(int rewind_ticks, int now_ticks)
|
||||
// world time is set first, since e.g. the NetworkItem manager relies
|
||||
// on having the access to the 'confirmed' state time using
|
||||
// the world timer.
|
||||
world->setTicks(exact_rewind_ticks);
|
||||
world->setTicksForRewind(exact_rewind_ticks);
|
||||
|
||||
// Get the (first) full state to which we have to rewind
|
||||
RewindInfo *current = m_rewind_queue.getCurrent();
|
||||
@ -332,9 +332,9 @@ void RewindManager::rewindTo(int rewind_ticks, int now_ticks)
|
||||
}
|
||||
|
||||
// Now go forward through the list of rewind infos till we reach 'now':
|
||||
while (world->getTimeTicks() < now_ticks)
|
||||
while (world->getTicksSinceStart() < now_ticks)
|
||||
{
|
||||
m_rewind_queue.replayAllEvents(world->getTimeTicks());
|
||||
m_rewind_queue.replayAllEvents(world->getTicksSinceStart());
|
||||
|
||||
// Now simulate the next time step
|
||||
world->updateWorld(1);
|
||||
|
@ -303,7 +303,7 @@ void RewindQueue::mergeNetworkData(int world_ticks, bool *needs_rewind,
|
||||
{
|
||||
Log::verbose("rewindqueue",
|
||||
"world %d rewindticks %d latest_confirmed %d",
|
||||
World::getWorld()->getTimeTicks(), *rewind_ticks,
|
||||
World::getWorld()->getTicksSinceStart(), *rewind_ticks,
|
||||
m_latest_confirmed_state_time);
|
||||
*rewind_ticks = m_latest_confirmed_state_time;
|
||||
*needs_rewind = m_latest_confirmed_state_time < world_ticks;
|
||||
@ -365,7 +365,7 @@ int RewindQueue::undoUntil(int undo_ticks)
|
||||
// This shouldn't happen, but add some debug info just in case
|
||||
Log::error("undoUntil",
|
||||
"At %d rewinding to %d current = %d = begin",
|
||||
World::getWorld()->getTimeTicks(), undo_ticks,
|
||||
World::getWorld()->getTicksSinceStart(), undo_ticks,
|
||||
(*m_current)->getTicks());
|
||||
}
|
||||
m_current--;
|
||||
|
@ -80,7 +80,7 @@ void History::addEvent(int kart_id, PlayerAction pa, int value)
|
||||
InputEvent ie;
|
||||
// The event is added before m_current is increased. So in order to
|
||||
// save the right index for this event, we need to use m_current+1.
|
||||
ie.m_world_ticks = World::getWorld()->getTimeTicks();
|
||||
ie.m_world_ticks = World::getWorld()->getTicksSinceStart();
|
||||
ie.m_action = pa;
|
||||
ie.m_value = value;
|
||||
ie.m_kart_index = kart_id;
|
||||
@ -102,7 +102,7 @@ void History::updateReplay(int world_ticks)
|
||||
const InputEvent &ie = m_all_input_events[m_event_index];
|
||||
AbstractKart *kart = world->getKart(ie.m_kart_index);
|
||||
Log::verbose("history", "time %d event-time %d action %d %d",
|
||||
world->getTimeTicks(), ie.m_world_ticks, ie.m_action,
|
||||
world->getTicksSinceStart(), ie.m_world_ticks, ie.m_action,
|
||||
ie.m_value);
|
||||
kart->getController()->action(ie.m_action, ie.m_value);
|
||||
m_event_index++;
|
||||
@ -168,7 +168,7 @@ void History::Save()
|
||||
{
|
||||
fprintf(fd, "model %d: %s\n",k, world->getKart(k)->getIdent().c_str());
|
||||
}
|
||||
fprintf(fd, "count: %d\n", m_all_input_events.size());
|
||||
fprintf(fd, "count: %zu\n", m_all_input_events.size());
|
||||
|
||||
for (unsigned int i = 0; i < m_all_input_events.size(); i++)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user