Skip to content

Commit

Permalink
[Codechange] Implements proper truck deletion in multiplayer
Browse files Browse the repository at this point in the history
  • Loading branch information
ulteq committed May 19, 2016
1 parent ed7fcdb commit 5908ff8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 29 deletions.
40 changes: 22 additions & 18 deletions source/main/physics/Beam.cpp
Expand Up @@ -101,6 +101,11 @@ using namespace RoR;

Beam::~Beam()
{
if (gEnv->network && state != NETWORKED)
{
NetworkStreamManager::getSingleton().removeStream(this->getSourceID(), this->getStreamID());
}

// TODO: IMPROVE below: delete/destroy prop entities, etc

deleting = true;
Expand Down Expand Up @@ -634,9 +639,15 @@ void Beam::pushNetwork(char* data, int size)

void Beam::calcNetwork()
{
if (netcounter != m_last_netcounter)
{
m_last_netcounter = netcounter;
m_last_net_update_time = getTruckTime();
}

BES_GFX_START(BES_GFX_calcNetwork);
if (netcounter < 4) return;
Vector3 apos=Vector3::ZERO;
if (netcounter<4) return;
//we must update Nodes positions from available network informations
//we must lock as long as we use oob1, oob2, netb1, netb2
std::lock_guard<std::mutex> net_lock(m_net_mutex);
Expand Down Expand Up @@ -1886,15 +1897,15 @@ void Beam::sendStreamData()

void Beam::receiveStreamData(unsigned int &type, int &source, unsigned int &_streamid, char *buffer, unsigned int &len)
{
BES_GFX_START(BES_GFX_receiveStreamData);
if (state != NETWORKED) return; // this should not happen
// TODO: FIX
//if (this->source != source || this->streamid != streamid) return; // data not for us

BES_GFX_START(BES_GFX_receiveStreamData);

if (type == MSG2_STREAM_DATA && source == (int)this->getSourceID() && _streamid == this->getStreamID())
{
pushNetwork(buffer, len);
}

BES_GFX_STOP(BES_GFX_receiveStreamData);
}

Expand Down Expand Up @@ -4709,20 +4720,6 @@ void Beam::updateNetworkInfo()
#endif //SOCKETW
}

void Beam::deleteNetTruck()
{
// TODO: properly delete things ...
//park and recycle vehicle
state = RECYCLE;
if (netMT) netMT->setVisible(false);
resetPosition(100000, 100000, false, 100000);
if (netLabelNode) netLabelNode->setVisible(false);
updateFlexbodiesPrepare();
updateFlexbodiesFinal();
updateVisual();
StopAllSounds();
}

float Beam::getHeadingDirectionAngle()
{
if (cameranodepos[0] >= 0 && cameranodedir[0] >= 0)
Expand Down Expand Up @@ -5532,6 +5529,8 @@ Beam::Beam(
, velocity(Ogre::Vector3::ZERO)
, m_custom_camera_node(-1)
, m_hide_own_net_label(BSETTING("HideOwnNetLabel", false))
, m_last_netcounter(0)
, m_last_net_update_time(0)
, m_request_skeletonview_change(0)
, m_reset_request(REQUEST_RESET_NONE)
, m_skeletonview_is_active(false)
Expand Down Expand Up @@ -6367,6 +6366,11 @@ int Beam::getTruckTime()
return netTimer.getMilliseconds();
}

int Beam::getTimeSinceLastNetUpdate()
{
return getTruckTime() - m_last_net_update_time;
}

int Beam::getNetTruckTimeOffset()
{
return net_toffset;
Expand Down
7 changes: 5 additions & 2 deletions source/main/physics/Beam.h
Expand Up @@ -493,8 +493,7 @@ class Beam :
bool getBeaconMode();
void setBlinkType(blinktype blink);
blinktype getBlinkType();
void deleteNetTruck();


float getHeadingDirectionAngle();
bool getCustomParticleMode();
int getLowestNode();
Expand Down Expand Up @@ -555,6 +554,8 @@ class Beam :

void updateDashBoards(float dt);

int getTimeSinceLastNetUpdate();

//! @{ physic related functions
bool calcForcesEulerPrepare(int doUpdate, Ogre::Real dt, int step = 0, int maxsteps = 1);

Expand Down Expand Up @@ -691,6 +692,8 @@ class Beam :
std::mutex m_net_mutex;
int net_toffset;
int netcounter;
int m_last_netcounter;
int m_last_net_update_time;
Ogre::MovableText *netMT; //, *netDist;
bool m_hide_own_net_label;

Expand Down
24 changes: 15 additions & 9 deletions source/main/physics/BeamFactory.cpp
Expand Up @@ -697,14 +697,9 @@ void BeamFactory::DeleteTruck(Beam *b)

this->SyncWithSimThread();

if (!b->networking)
{
m_trucks[b->trucknum] = 0;
delete b;
} else
{
b->deleteNetTruck();
}
m_trucks[b->trucknum] = 0;
delete b;
b = 0;

#ifdef USE_MYGUI
GUI_MainMenu::getSingleton().triggerUpdateVehicleList();
Expand Down Expand Up @@ -909,12 +904,23 @@ void BeamFactory::calcPhysics(float dt)
switch(m_trucks[t]->state)
{
case NETWORKED:
m_trucks[t]->calcNetwork();
if (m_trucks[t]->getTimeSinceLastNetUpdate() < 5000)
{
m_trucks[t]->calcNetwork();
} else
{
//StreamableFactory::deleteRemote(m_trucks[t]->getSourceID(), m_trucks[t]->getStreamID());
NetworkStreamManager::getSingleton().removeStream(m_trucks[t]->getSourceID(), m_trucks[t]->getStreamID());
m_trucks[t] = 0;
}
break;

case NETWORKED_INVALID:
break;

case RECYCLE:
break;

case DELETED:
break;

Expand Down

0 comments on commit 5908ff8

Please sign in to comment.