diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-20 14:33:09 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-20 14:33:09 +1000 |
commit | 6352e8e3196f78388b6c771073f9e03eaa612673 (patch) | |
tree | e23772f79a7fbc41bc9108951e9e136857484bf4 /source/game/StarClientContext.cpp | |
parent | 6741a057e5639280d85d0f88ba26f000baa58f61 (diff) |
everything everywhere
all at once
Diffstat (limited to 'source/game/StarClientContext.cpp')
-rw-r--r-- | source/game/StarClientContext.cpp | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/source/game/StarClientContext.cpp b/source/game/StarClientContext.cpp new file mode 100644 index 0000000..1482168 --- /dev/null +++ b/source/game/StarClientContext.cpp @@ -0,0 +1,94 @@ +#include "StarClientContext.hpp" +#include "StarJsonExtra.hpp" +#include "StarDataStreamExtra.hpp" + +namespace Star { + +DataStream& operator>>(DataStream& ds, ShipUpgrades& upgrades) { + ds.read(upgrades.shipLevel); + ds.read(upgrades.maxFuel); + ds.read(upgrades.crewSize); + ds.read(upgrades.fuelEfficiency); + ds.read(upgrades.shipSpeed); + ds.read(upgrades.capabilities); + return ds; +} + +DataStream& operator<<(DataStream& ds, ShipUpgrades const& upgrades) { + ds.write(upgrades.shipLevel); + ds.write(upgrades.maxFuel); + ds.write(upgrades.crewSize); + ds.write(upgrades.fuelEfficiency); + ds.write(upgrades.shipSpeed); + ds.write(upgrades.capabilities); + return ds; +} + +ClientContext::ClientContext(Uuid serverUuid) { + m_serverUuid = move(serverUuid); + m_rpc = make_shared<JsonRpc>(); + + m_netGroup.addNetElement(&m_orbitWarpActionNetState); + m_netGroup.addNetElement(&m_playerWorldIdNetState); + m_netGroup.addNetElement(&m_isAdminNetState); + m_netGroup.addNetElement(&m_teamNetState); + m_netGroup.addNetElement(&m_shipUpgrades); + m_netGroup.addNetElement(&m_shipCoordinate); +} + +Uuid ClientContext::serverUuid() const { + return m_serverUuid; +} + +CelestialCoordinate ClientContext::shipCoordinate() const { + return m_shipCoordinate.get(); +} + +Maybe<pair<WarpAction, WarpMode>> ClientContext::orbitWarpAction() const { + return m_orbitWarpActionNetState.get(); +} + +WorldId ClientContext::playerWorldId() const { + return m_playerWorldIdNetState.get(); +} + +bool ClientContext::isAdmin() const { + return m_isAdminNetState.get(); +} + +EntityDamageTeam ClientContext::team() const { + return m_teamNetState.get(); +} + +JsonRpcInterfacePtr ClientContext::rpcInterface() const { + return m_rpc; +} + +WorldChunks ClientContext::newShipUpdates() { + return take(m_newShipUpdates); +} + +ShipUpgrades ClientContext::shipUpgrades() const { + return m_shipUpgrades.get(); +} + +void ClientContext::readUpdate(ByteArray data) { + if (data.empty()) + return; + + DataStreamBuffer ds(move(data)); + + m_rpc->receive(ds.read<ByteArray>()); + + auto shipUpdates = ds.read<ByteArray>(); + if (!shipUpdates.empty()) + m_newShipUpdates.merge(DataStreamBuffer::deserialize<WorldChunks>(move(shipUpdates)), true); + + m_netGroup.readNetState(ds.read<ByteArray>()); +} + +ByteArray ClientContext::writeUpdate() { + return m_rpc->send(); +} + +} |