diff options
author | Aki <please@ignore.pl> | 2024-04-01 05:16:14 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2024-04-01 05:21:16 +0200 |
commit | 3be3bfaa17773550a696ed2b756136debfe79ae2 (patch) | |
tree | db55a420e43ddaa4a72140d2795892757c1672d3 /StarsEx/StarSystem.cpp | |
parent | 0a3451f251f360267e2927d8320787d59148eadd (diff) | |
download | starshatter-3be3bfaa17773550a696ed2b756136debfe79ae2.zip starshatter-3be3bfaa17773550a696ed2b756136debfe79ae2.tar.gz starshatter-3be3bfaa17773550a696ed2b756136debfe79ae2.tar.bz2 |
Fixed date and time consistency across Campaigns and Missions
This fixes campaign mission generation mostly, but a full playthrough
will be needed. Missions now serialize and accept stardate setting a
bit better. Thanks to this, date is propagated over multiplayer, too.
This seems to break points system?
Code-wise, this does not workaround the problems from before namely
over-reliance on side-effects. Stardate class is at least one small
step into good direction. Now, it'd be nice to attach clocks to
simulation and campaign and whatever else that needs them.
Diffstat (limited to 'StarsEx/StarSystem.cpp')
-rw-r--r-- | StarsEx/StarSystem.cpp | 75 |
1 files changed, 16 insertions, 59 deletions
diff --git a/StarsEx/StarSystem.cpp b/StarsEx/StarSystem.cpp index b8340f6..6641b63 100644 --- a/StarsEx/StarSystem.cpp +++ b/StarsEx/StarSystem.cpp @@ -12,71 +12,31 @@ */ #include "StarSystem.h" -#include "Galaxy.h" -#include "Sky.h" -#include "Starshatter.h" -#include "TerrainRegion.h" -#include "TerrainHaze.h" -#include "Weather.h" +#include "Bitmap.h" +#include "Clock.h" +#include "DataLoader.h" +#include "Galaxy.h" #include "Game.h" #include "GameWinDX9.h" -#include "Clock.h" -#include "Sound.h" -#include "Solid.h" #include "Light.h" -#include "Bitmap.h" -#include "DataLoader.h" -#include "Scene.h" #include "ParseUtil.h" +#include "Scene.h" +#include "Sky.h" +#include "Solid.h" +#include "Sound.h" +#include "Stardate.h" +#include "Starshatter.h" +#include "TerrainHaze.h" +#include "TerrainRegion.h" #include "Video.h" - -const long double epoch = 0.5e9; -long double StarSystem::stardate = 0; +#include "Weather.h" // +====================================================================+ -static long double base_time = 0; static WORD oldcw = 0; static WORD fpcw = 0; -void StarSystem::SetBaseTime(long double t, bool absolute) -{ - if (absolute) { - base_time = t; - CalcStardate(); - } - - else if (t > 0) { - if (t > epoch) t -= epoch; - base_time = t; - CalcStardate(); - } -} - -long double StarSystem::GetBaseTime() -{ - return base_time; -} - -void StarSystem::CalcStardate() -{ - if (base_time < 1) { - time_t clock_seconds; - time(&clock_seconds); - - base_time = clock_seconds; - - while (base_time < 0) - base_time += epoch; - } - - long double gtime = Clock::GetInstance()->GameTime<long double>() / 1000.0; - long double sdate = gtime + base_time + epoch; - - stardate = sdate; -} - static const double GRAV = 6.673e-11; static const int NAMELEN = 64; @@ -119,7 +79,6 @@ static OrbitalBody* primary_moon = 0; void StarSystem::Load() { - CalcStardate(); active_region = 0; BYTE* block = 0; @@ -1386,8 +1345,6 @@ static BYTE min3(BYTE a, BYTE b, BYTE c) void StarSystem::ExecFrame() { - CalcStardate(); - ListIter<OrbitalBody> star = bodies; while (++star) star->Update(); @@ -1843,7 +1800,7 @@ Orbital::Update() double grade = (retro) ? -1 : 1; // orbits are counter clockwise: - phase = -2 * PI * grade * StarSystem::Stardate() / period; + phase = PI * -2.0 * grade * starshatter::engine::CurrentTime() / period; loc = primary->Location() + Point((double) (orbit * cos(phase)), (double) (orbit * sin(phase)), @@ -1871,7 +1828,7 @@ Orbital::PredictLocation(double delta_t) double grade = (retro) ? -1 : 1; // orbits are(?) counter clockwise: - double predicted_phase = (double) (-2 * PI * grade * (StarSystem::Stardate()+delta_t) / period); + const auto predicted_phase = PI * -2.0 * grade * (starshatter::engine::CurrentTime() + delta_t) / period; predicted_loc += Point((double) (orbit * cos(predicted_phase)), (double) (orbit * sin(predicted_phase)), @@ -1917,7 +1874,7 @@ OrbitalBody::Update() theta = 0; if (rotation > 0) - theta = -2 * PI * StarSystem::Stardate() / rotation; + theta = PI * -2.0 * starshatter::engine::CurrentTime() / rotation; ListIter<OrbitalBody> body = satellites; while (++body) |