Add live join world and kart handling

This commit is contained in:
Benau 2019-01-01 01:01:49 +08:00
parent 220a628f47
commit 564ed41ed3
5 changed files with 69 additions and 8 deletions

View File

@ -58,6 +58,7 @@ AbstractKart::~AbstractKart()
// ----------------------------------------------------------------------------
void AbstractKart::reset()
{
m_live_join_util = 0;
// important to delete animations before calling reset, as some animations
// set the kart velocity in their destructor (e.g. cannon) which "reset"
// can then cancel. See #2738
@ -192,10 +193,17 @@ void AbstractKart::kartIsInRestNow()
* position in case there is a slope. */
void AbstractKart::makeKartRest()
{
btTransform t = m_starting_transform;
if (m_live_join_util != 0)
{
t.setOrigin(t.getOrigin() +
m_starting_transform.getBasis().getColumn(1) * 3.0f);
}
btRigidBody *body = getBody();
body->clearForces();
body->setLinearVelocity(Vec3(0.0f));
body->setAngularVelocity(Vec3(0.0f));
body->proceedToTransform(m_starting_transform);
setTrans(m_starting_transform);
body->proceedToTransform(t);
setTrans(t);
} // makeKartRest

View File

@ -75,12 +75,15 @@ private:
/** Index of kart in world. */
unsigned int m_world_kart_id;
btTransform m_starting_transform;
// ------------------------------------------------------------------------
void loadKartProperties(const std::string& new_ident,
PerPlayerDifficulty difficulty,
std::shared_ptr<RenderInfo> ri);
protected:
btTransform m_starting_transform;
int m_live_join_util;
/** The kart properties. */
std::unique_ptr<KartProperties> m_kart_properties;
@ -532,6 +535,8 @@ public:
virtual float getStartupBoostFromStartTicks(int ticks) const = 0;
// ------------------------------------------------------------------------
virtual Stars* getStarsEffect() const = 0;
// ------------------------------------------------------------------------
void setLiveJoinKart(int util_ticks) { m_live_join_util = util_ticks; }
}; // AbstractKart

View File

@ -1409,6 +1409,23 @@ void Kart::update(int ticks)
Vec3 front(0, 0, getKartLength()*0.5f);
m_xyz_front = getTrans()(front);
// Hover the kart above reset position before entering the game
if (m_live_join_util != 0 &&
(m_live_join_util < World::getWorld()->getTicksSinceStart() ||
World::getWorld()->isLiveJoinWorld()))
{
btRigidBody *body = getBody();
body->clearForces();
body->setLinearVelocity(Vec3(0.0f));
body->setAngularVelocity(Vec3(0.0f));
btTransform hovering = m_starting_transform;
hovering.setOrigin(hovering.getOrigin() +
m_starting_transform.getBasis().getColumn(1) * 3.0f);
body->proceedToTransform(hovering);
setTrans(hovering);
}
// Update the locally maintained speed of the kart (m_speed), which
// is used furthermore for engine power, camera distance etc
updateSpeed();

View File

@ -49,7 +49,7 @@ WorldStatus::WorldStatus()
m_play_track_intro_sound = UserConfigParams::m_music;
m_play_ready_set_go_sounds = true;
m_play_racestart_sounds = true;
m_live_join_world = false;
IrrlichtDevice *device = irr_driver->getDevice();
if (device->getTimer()->isStopped())
@ -253,10 +253,13 @@ void WorldStatus::updateTime(int ticks)
m_phase = WAIT_FOR_SERVER_PHASE;
// In networked races, inform the start game protocol that
// the world has been setup
if (!m_live_join_world)
{
auto lobby = LobbyProtocol::get<LobbyProtocol>();
assert(lobby);
lobby->finishedLoadingWorld();
}
}
else
{
if (m_play_ready_set_go_sounds)
@ -266,6 +269,20 @@ void WorldStatus::updateTime(int ticks)
return; // Don't increase time
case WAIT_FOR_SERVER_PHASE:
{
if (m_live_join_world)
{
m_auxiliary_ticks++;
// Add 3 seconds delay before telling server finish loading
// world, so previous (if any) disconnected player has left
// fully
if (m_auxiliary_ticks == 360)
{
auto lobby = LobbyProtocol::get<LobbyProtocol>();
assert(lobby);
lobby->finishedLoadingWorld();
}
return;
}
return; // Don't increase time
}
case SERVER_READY_PHASE:
@ -522,3 +539,10 @@ void WorldStatus::unpause()
!NetworkConfig::get()->isNetworking())
device->getTimer()->start();
} // unpause
//-----------------------------------------------------------------------------
void WorldStatus::endLiveJoinWorld(int ticks_now)
{
m_live_join_world = false;
m_auxiliary_ticks = 0;
} // endLiveJoinWorld

View File

@ -136,6 +136,8 @@ private:
bool m_engines_started;
bool m_live_join_world;
void startEngines();
public:
@ -212,7 +214,12 @@ public:
int getTicksSinceStart() const { return m_count_up_ticks; }
// ------------------------------------------------------------------------
int getAuxiliaryTicks() const { return m_auxiliary_ticks; }
// ------------------------------------------------------------------------
bool isLiveJoinWorld() const { return m_live_join_world; }
// ------------------------------------------------------------------------
void setLiveJoinWorld(bool val) { m_live_join_world = val; }
// ------------------------------------------------------------------------
void endLiveJoinWorld(int ticks_now);
}; // WorldStatus