Don't add deleting flyable to state
This commit is contained in:
parent
8257f71a60
commit
e6b8163579
@ -609,17 +609,32 @@ void Flyable::moveToInfinity()
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
BareNetworkString* Flyable::saveState(std::vector<std::string>* ru)
|
BareNetworkString* Flyable::saveState(std::vector<std::string>* ru)
|
||||||
{
|
{
|
||||||
|
if (m_has_hit_something)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
ru->push_back(getUniqueIdentity());
|
ru->push_back(getUniqueIdentity());
|
||||||
BareNetworkString *buffer = new BareNetworkString();
|
BareNetworkString *buffer = new BareNetworkString();
|
||||||
CompressNetworkBody::compress(m_body->getWorldTransform(),
|
CompressNetworkBody::compress(m_body->getWorldTransform(),
|
||||||
m_body->getLinearVelocity(), m_body->getAngularVelocity(), buffer,
|
m_body->getLinearVelocity(), m_body->getAngularVelocity(), buffer,
|
||||||
m_body, m_motion_state);
|
m_body, m_motion_state);
|
||||||
uint16_t hit_and_ticks = (m_has_hit_something ? 1 << 15 : 0) |
|
buffer->addUInt16(m_ticks_since_thrown);
|
||||||
m_ticks_since_thrown;
|
|
||||||
buffer->addUInt16(hit_and_ticks);
|
|
||||||
return buffer;
|
return buffer;
|
||||||
} // saveState
|
} // saveState
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
std::function<void()> Flyable::getLocalStateRestoreFunction()
|
||||||
|
{
|
||||||
|
// Avoid circular reference
|
||||||
|
std::weak_ptr<Flyable> fw = getShared<Flyable>();
|
||||||
|
return [fw]()
|
||||||
|
{
|
||||||
|
std::shared_ptr<Flyable> f = fw.lock();
|
||||||
|
if (!f || f->m_has_undone_destruction)
|
||||||
|
return;
|
||||||
|
f->m_has_server_state = false;
|
||||||
|
};
|
||||||
|
} // getLocalStateRestoreFunction
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
void Flyable::restoreState(BareNetworkString *buffer, int count)
|
void Flyable::restoreState(BareNetworkString *buffer, int count)
|
||||||
{
|
{
|
||||||
@ -639,9 +654,8 @@ void Flyable::restoreState(BareNetworkString *buffer, int count)
|
|||||||
setTrans(t);
|
setTrans(t);
|
||||||
}
|
}
|
||||||
uint16_t hit_and_ticks = buffer->getUInt16();
|
uint16_t hit_and_ticks = buffer->getUInt16();
|
||||||
m_has_hit_something = (hit_and_ticks >> 15) == 1;
|
// Next network version remove ~(1 << 15)
|
||||||
m_ticks_since_thrown = hit_and_ticks & ~(1 << 15);
|
m_ticks_since_thrown = hit_and_ticks & ~(1 << 15);
|
||||||
if (!m_has_server_state)
|
|
||||||
m_has_server_state = true;
|
m_has_server_state = true;
|
||||||
} // restoreState
|
} // restoreState
|
||||||
|
|
||||||
@ -721,10 +735,12 @@ void Flyable::handleUndoDestruction()
|
|||||||
RewindInfoEventFunction(World::getWorld()->getTicksSinceStart(),
|
RewindInfoEventFunction(World::getWorld()->getTicksSinceStart(),
|
||||||
/*undo_function*/[f, uid]()
|
/*undo_function*/[f, uid]()
|
||||||
{
|
{
|
||||||
|
f->m_has_hit_something = false;
|
||||||
projectile_manager->addByUID(uid, f);
|
projectile_manager->addByUID(uid, f);
|
||||||
},
|
},
|
||||||
/*replay_function*/[f, uid]()
|
/*replay_function*/[f, uid]()
|
||||||
{
|
{
|
||||||
|
f->m_has_hit_something = true;
|
||||||
projectile_manager->removeByUID(uid);
|
projectile_manager->removeByUID(uid);
|
||||||
f->moveToInfinity();
|
f->moveToInfinity();
|
||||||
}));
|
}));
|
||||||
@ -738,8 +754,8 @@ void Flyable::computeError()
|
|||||||
World::getWorld()->getTicksSinceStart() > m_check_created_ticks)
|
World::getWorld()->getTicksSinceStart() > m_check_created_ticks)
|
||||||
{
|
{
|
||||||
const std::string& uid = getUniqueIdentity();
|
const std::string& uid = getUniqueIdentity();
|
||||||
Log::warn("Flyable", "Item %s failed to be created on server, "
|
Log::warn("Flyable", "Item %s doesn't exist on server, "
|
||||||
"remove it locally", uid.c_str());
|
"remove it locally.", uid.c_str());
|
||||||
projectile_manager->removeByUID(uid);
|
projectile_manager->removeByUID(uid);
|
||||||
}
|
}
|
||||||
} // computeError
|
} // computeError
|
||||||
|
@ -256,6 +256,8 @@ public:
|
|||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
virtual void addRewindInfoEventFunctionAfterFiring();
|
virtual void addRewindInfoEventFunctionAfterFiring();
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
virtual std::function<void()> getLocalStateRestoreFunction() OVERRIDE;
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
bool isUndoCreation() const { return m_undo_creation; }
|
bool isUndoCreation() const { return m_undo_creation; }
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
bool hasUndoneDestruction() const { return m_has_undone_destruction; }
|
bool hasUndoneDestruction() const { return m_has_undone_destruction; }
|
||||||
|
@ -254,6 +254,9 @@ void Plunger::hideNodeWhenUndoDestruction()
|
|||||||
BareNetworkString* Plunger::saveState(std::vector<std::string>* ru)
|
BareNetworkString* Plunger::saveState(std::vector<std::string>* ru)
|
||||||
{
|
{
|
||||||
BareNetworkString* buffer = Flyable::saveState(ru);
|
BareNetworkString* buffer = Flyable::saveState(ru);
|
||||||
|
if (!buffer)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
buffer->addUInt16(m_keep_alive).addUInt8(m_moved_to_infinity ? 1 : 0);
|
buffer->addUInt16(m_keep_alive).addUInt8(m_moved_to_infinity ? 1 : 0);
|
||||||
if (m_rubber_band)
|
if (m_rubber_band)
|
||||||
buffer->addUInt8(m_rubber_band->get8BitState());
|
buffer->addUInt8(m_rubber_band->get8BitState());
|
||||||
|
@ -793,6 +793,9 @@ bool RubberBall::hit(AbstractKart* kart, PhysicalObject* object)
|
|||||||
BareNetworkString* RubberBall::saveState(std::vector<std::string>* ru)
|
BareNetworkString* RubberBall::saveState(std::vector<std::string>* ru)
|
||||||
{
|
{
|
||||||
BareNetworkString* buffer = Flyable::saveState(ru);
|
BareNetworkString* buffer = Flyable::saveState(ru);
|
||||||
|
if (!buffer)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
buffer->addUInt32(m_last_aimed_graph_node);
|
buffer->addUInt32(m_last_aimed_graph_node);
|
||||||
buffer->add(m_control_points[0]);
|
buffer->add(m_control_points[0]);
|
||||||
buffer->add(m_control_points[1]);
|
buffer->add(m_control_points[1]);
|
||||||
|
Loading…
Reference in New Issue
Block a user