diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2024-10-02 14:45:27 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2024-10-02 14:45:27 +1000 |
commit | 25f3edbae301eae0fd87162527e12cbb2630b022 (patch) | |
tree | cedddf9b9bac518ade4ffe0813c785a4594d13b8 /source/game/StarUniverseServer.cpp | |
parent | 80192714b780a09291e00cd41152abef9c249859 (diff) |
shipworlds: store their own epoch time for consistent plant growth
Diffstat (limited to 'source/game/StarUniverseServer.cpp')
-rw-r--r-- | source/game/StarUniverseServer.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/source/game/StarUniverseServer.cpp b/source/game/StarUniverseServer.cpp index 6961ce4..fa728fb 100644 --- a/source/game/StarUniverseServer.cpp +++ b/source/game/StarUniverseServer.cpp @@ -673,7 +673,6 @@ void UniverseServer::updateShips() { Json jOldShipLevel = shipWorld->getProperty("ship.level"); unsigned newShipLevel = min<unsigned>(speciesShips.size() - 1, newShipUpgrades.shipLevel); - if (jOldShipLevel.isType(Json::Type::Int)) { auto oldShipLevel = jOldShipLevel.toUInt(); if (oldShipLevel < newShipLevel) { @@ -2036,10 +2035,21 @@ Maybe<WorkerPoolPromise<WorldServerThreadPtr>> UniverseServer::shipWorldPromise( shipWorld->setProperty("ship.maxFuel", currentUpgrades.maxFuel); shipWorld->setProperty("ship.crewSize", currentUpgrades.crewSize); shipWorld->setProperty("ship.fuelEfficiency", currentUpgrades.fuelEfficiency); + shipWorld->setProperty("ship.epoch", Time::timeSinceEpoch()); + } + + auto shipClock = make_shared<Clock>(); + auto shipTime = shipWorld->getProperty("ship.epoch"); + if (!shipTime.canConvert(Json::Type::Float)) { + auto now = Time::timeSinceEpoch(); + shipWorld->setProperty("ship.epoch", now); + } else { + shipClock->setTime(Time::timeSinceEpoch() - shipTime.toDouble()); } shipWorld->setUniverseSettings(m_universeSettings); - shipWorld->setReferenceClock(universeClock); + shipWorld->setReferenceClock(shipClock); + shipClock->start(); if (auto systemWorld = clientContext->systemWorld()) shipWorld->setOrbitalSky(systemWorld->clientSkyParameters(clientContext->clientId())); |