#pragma once #include "StarNetElement.hpp" namespace Star { template class NetElementOverride : public BaseNetElement { public: void netStore(DataStream& ds, NetCompatibilityRules rules = {}) const override; void netLoad(DataStream& ds, NetCompatibilityRules rules) override; bool writeNetDelta(DataStream& ds, uint64_t fromVersion, NetCompatibilityRules rules = {}) const override; void readNetDelta(DataStream& ds, float interpolationTime = 0.0f, NetCompatibilityRules rules = {}) override; typedef std::function NetStorer; typedef std::function NetLoader; typedef std::function NetDeltaWriter; typedef std::function NetDeltaReader; void setNetStorer(NetStorer); void setNetLoader(NetLoader); void setNetDeltaWriter(NetDeltaWriter); void setNetDeltaReader(NetDeltaReader); void setOverrides(NetStorer netStorer, NetLoader netLoader, NetDeltaWriter netDeltaWriter, NetDeltaReader netDeltaReader); private: NetStorer m_netStorer; NetLoader m_netLoader; NetDeltaWriter m_netDeltaWriter; NetDeltaReader m_netDeltaReader; }; template void NetElementOverride::netStore(DataStream& ds, NetCompatibilityRules rules) const { if (m_netStorer) m_netStorer(ds, rules); else BaseNetElement::netStore(ds, rules); } template void NetElementOverride::netLoad(DataStream& ds, NetCompatibilityRules rules) { if (m_netLoader) m_netLoader(ds, rules); else BaseNetElement::netLoad(ds, rules); } template bool NetElementOverride::writeNetDelta(DataStream& ds, uint64_t fromVersion, NetCompatibilityRules rules) const { if (m_netDeltaWriter) return m_netDeltaWriter(ds, fromVersion, rules); else return BaseNetElement::writeNetDelta(ds, fromVersion, rules); } template void NetElementOverride::readNetDelta(DataStream& ds, float interpolationTime, NetCompatibilityRules rules) { if (m_netDeltaReader) m_netDeltaReader(ds, interpolationTime, rules); else BaseNetElement::readNetDelta(ds, interpolationTime, rules); } template inline void NetElementOverride::setNetStorer(NetStorer f) { m_netStorer = std::move(f); } template inline void NetElementOverride::setNetLoader(NetLoader f) { m_netLoader = std::move(f); } template inline void NetElementOverride::setNetDeltaWriter(NetDeltaWriter f) { m_netDeltaWriter = std::move(f); } template inline void NetElementOverride::setNetDeltaReader(NetDeltaReader f) { m_netDeltaReader = std::move(f); } template inline void NetElementOverride::setOverrides(NetStorer netStorer, NetLoader netLoader, NetDeltaWriter netDeltaWriter, NetDeltaReader netDeltaReader) { m_netStorer = std::move(netStorer); m_netLoader = std::move(netLoader); m_netDeltaWriter = std::move(netDeltaWriter); m_netDeltaReader = std::move(netDeltaReader); } }