Fix track objects in network

This commit is contained in:
Benau 2018-05-15 15:23:39 +08:00
parent 7f84dd39a6
commit b8982200b6
5 changed files with 32 additions and 2 deletions

View File

@ -27,6 +27,8 @@
#include "network/rewind_info.hpp" #include "network/rewind_info.hpp"
#include "physics/physics.hpp" #include "physics/physics.hpp"
#include "race/history.hpp" #include "race/history.hpp"
#include "tracks/track.hpp"
#include "tracks/track_object_manager.hpp"
#include "utils/log.hpp" #include "utils/log.hpp"
#include "utils/profiler.hpp" #include "utils/profiler.hpp"
@ -318,6 +320,8 @@ void RewindManager::playEventsTill(int world_ticks, int *ticks)
void RewindManager::rewindTo(int rewind_ticks, int now_ticks) void RewindManager::rewindTo(int rewind_ticks, int now_ticks)
{ {
assert(!m_is_rewinding); assert(!m_is_rewinding);
// TODO Do it properly for track objects like soccer ball
Track::getCurrentTrack()->getTrackObjectManager()->removeForRewind();
bool is_history = history->replayHistory(); bool is_history = history->replayHistory();
history->setReplayHistory(false); history->setReplayHistory(false);
@ -384,5 +388,6 @@ void RewindManager::rewindTo(int rewind_ticks, int now_ticks)
} }
history->setReplayHistory(is_history); history->setReplayHistory(is_history);
Track::getCurrentTrack()->getTrackObjectManager()->addForRewind();
m_is_rewinding = false; m_is_rewinding = false;
} // rewindTo } // rewindTo

View File

@ -206,6 +206,8 @@ public:
const Material **material, btVector3 *normal, const Material **material, btVector3 *normal,
bool interpolate_normal) const; bool interpolate_normal) const;
// ------------------------------------------------------------------------
bool isDynamic() const { return m_is_dynamic; }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
/** Returns the ID of this physical object. */ /** Returns the ID of this physical object. */
std::string getID() { return m_id; } std::string getID() { return m_id; }

View File

@ -535,6 +535,7 @@ void TrackObject::updateGraphics(float dt)
// have been converted to use separate updateGraphics() calls. // have been converted to use separate updateGraphics() calls.
if (m_physical_object) m_physical_object->updateGraphics(dt); if (m_physical_object) m_physical_object->updateGraphics(dt);
if (m_animator) m_animator->update(dt);
} // update } // update
@ -546,10 +547,8 @@ void TrackObject::updateGraphics(float dt)
void TrackObject::update(float dt) void TrackObject::update(float dt)
{ {
if (m_presentation) m_presentation->update(dt); if (m_presentation) m_presentation->update(dt);
if (m_physical_object) m_physical_object->update(dt); if (m_physical_object) m_physical_object->update(dt);
if (m_animator) m_animator->update(dt);
} // update } // update
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@ -238,3 +238,25 @@ void TrackObjectManager::removeObject(TrackObject* obj)
m_all_objects.remove(obj); m_all_objects.remove(obj);
delete obj; delete obj;
} // removeObject } // removeObject
// ----------------------------------------------------------------------------
void TrackObjectManager::removeForRewind()
{
for (TrackObject* curr : m_all_objects)
{
if (curr->getPhysicalObject() &&
curr->getPhysicalObject()->isDynamic())
curr->getPhysicalObject()->removeBody();
}
} // removeForRewind
// ----------------------------------------------------------------------------
void TrackObjectManager::addForRewind()
{
for (TrackObject* curr : m_all_objects)
{
if (curr->getPhysicalObject() &&
curr->getPhysicalObject()->isDynamic())
curr->getPhysicalObject()->addBody();
}
} // addForRewind

View File

@ -76,6 +76,8 @@ public:
PtrVector<TrackObject>& getObjects() { return m_all_objects; } PtrVector<TrackObject>& getObjects() { return m_all_objects; }
const PtrVector<TrackObject>& getObjects() const { return m_all_objects; } const PtrVector<TrackObject>& getObjects() const { return m_all_objects; }
void removeForRewind();
void addForRewind();
}; // class TrackObjectManager }; // class TrackObjectManager