2023-06-20 04:33:09 +00:00
|
|
|
#include "StarNetElementSyncGroup.hpp"
|
|
|
|
|
|
|
|
namespace Star {
|
|
|
|
|
|
|
|
void NetElementSyncGroup::enableNetInterpolation(float extrapolationHint) {
|
|
|
|
NetElementGroup::enableNetInterpolation(extrapolationHint);
|
|
|
|
if (m_hasRecentChanges)
|
|
|
|
netElementsNeedLoad(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NetElementSyncGroup::disableNetInterpolation() {
|
|
|
|
NetElementGroup::disableNetInterpolation();
|
|
|
|
if (m_hasRecentChanges)
|
|
|
|
netElementsNeedLoad(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NetElementSyncGroup::tickNetInterpolation(float dt) {
|
|
|
|
NetElementGroup::tickNetInterpolation(dt);
|
|
|
|
if (m_hasRecentChanges) {
|
|
|
|
m_recentDeltaTime -= dt;
|
|
|
|
if (netInterpolationEnabled())
|
|
|
|
netElementsNeedLoad(false);
|
|
|
|
|
|
|
|
if (m_recentDeltaTime < 0.0f && m_recentDeltaWasBlank)
|
|
|
|
m_hasRecentChanges = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void NetElementSyncGroup::netStore(DataStream& ds) const {
|
|
|
|
const_cast<NetElementSyncGroup*>(this)->netElementsNeedStore();
|
|
|
|
return NetElementGroup::netStore(ds);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NetElementSyncGroup::netLoad(DataStream& ds) {
|
|
|
|
NetElementGroup::netLoad(ds);
|
|
|
|
netElementsNeedLoad(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NetElementSyncGroup::writeNetDelta(DataStream& ds, uint64_t fromVersion) const {
|
|
|
|
const_cast<NetElementSyncGroup*>(this)->netElementsNeedStore();
|
|
|
|
return NetElementGroup::writeNetDelta(ds, fromVersion);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NetElementSyncGroup::readNetDelta(DataStream& ds, float interpolationTime) {
|
|
|
|
NetElementGroup::readNetDelta(ds, interpolationTime);
|
|
|
|
|
|
|
|
m_hasRecentChanges = true;
|
|
|
|
m_recentDeltaTime = interpolationTime;
|
|
|
|
m_recentDeltaWasBlank = false;
|
|
|
|
|
|
|
|
netElementsNeedLoad(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NetElementSyncGroup::blankNetDelta(float interpolationTime) {
|
|
|
|
NetElementGroup::blankNetDelta(interpolationTime);
|
|
|
|
|
|
|
|
if (!m_recentDeltaWasBlank) {
|
|
|
|
m_recentDeltaTime = interpolationTime;
|
|
|
|
m_recentDeltaWasBlank = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_hasRecentChanges && netInterpolationEnabled())
|
|
|
|
netElementsNeedLoad(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NetElementSyncGroup::netElementsNeedLoad(bool) {}
|
|
|
|
|
|
|
|
void NetElementSyncGroup::netElementsNeedStore() {}
|
|
|
|
|
|
|
|
void NetElementCallbackGroup::setNeedsLoadCallback(function<void(bool)> needsLoadCallback) {
|
2024-02-19 15:55:19 +00:00
|
|
|
m_netElementsNeedLoad = std::move(needsLoadCallback);
|
2023-06-20 04:33:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NetElementCallbackGroup::setNeedsStoreCallback(function<void()> needsStoreCallback) {
|
2024-02-19 15:55:19 +00:00
|
|
|
m_netElementsNeedStore = std::move(needsStoreCallback);
|
2023-06-20 04:33:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NetElementCallbackGroup::netElementsNeedLoad(bool load) {
|
|
|
|
if (m_netElementsNeedLoad)
|
|
|
|
m_netElementsNeedLoad(load);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NetElementCallbackGroup::netElementsNeedStore() {
|
|
|
|
if (m_netElementsNeedStore)
|
|
|
|
m_netElementsNeedStore();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|