From 3be3bfaa17773550a696ed2b756136debfe79ae2 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 1 Apr 2024 05:16:14 +0200 Subject: 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. --- StarsEx/Starshatter.cpp | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) (limited to 'StarsEx/Starshatter.cpp') diff --git a/StarsEx/Starshatter.cpp b/StarsEx/Starshatter.cpp index 7663148..1a373cc 100644 --- a/StarsEx/Starshatter.cpp +++ b/StarsEx/Starshatter.cpp @@ -7,7 +7,6 @@ */ - #include "Starshatter.h" #include "MenuScreen.h" @@ -108,6 +107,7 @@ #include "Universe.h" #include "Video.h" #include "VideoSettings.h" +#include "Stardate.h" // +--------------------------------------------------------------------+ @@ -121,7 +121,9 @@ Starshatter* Starshatter::instance {nullptr}; static Mission* current_mission = 0; static Mission* cutscene_mission = 0; -static double cutscene_basetime = 0; +static long double cutscene_operation_start = 0; +static long double cutscene_mission_start = 0; +static double cutscene_game_time = 0; static int cut_efx_volume = 100; static int cut_wrn_volume = 100; static double time_til_change = 0; @@ -592,7 +594,7 @@ Starshatter::SetGameMode(int m) Clock::GetInstance()->SetTimeCompression(1.0); Pause(false); - Print(" Stardate: %.1Lf\n", StarSystem::GetBaseTime()); + Print(" Stardate: %.1Lf\n", starshatter::engine::CurrentTime().value); } else if (m == PLAN_MODE) { @@ -603,7 +605,7 @@ Starshatter::SetGameMode(int m) StopNetGame(); Pause(true); - Print(" Stardate: %.1Lf\n", StarSystem::GetBaseTime()); + Print(" Stardate: %.1Lf\n", starshatter::engine::CurrentTime().value); } } @@ -630,7 +632,7 @@ Starshatter::SetGameMode(int m) StopNetGame(); } - Print(" Stardate: %.1Lf\n", StarSystem::GetBaseTime()); + Print(" Stardate: %.1Lf\n", starshatter::engine::CurrentTime().value); Print(" Bitmap Cache Footprint: %d KB\n", Bitmap::CacheMemoryFootprint() / 1024); paused = true; @@ -1600,11 +1602,11 @@ Starshatter::DoGameKeys() /*** For Debug Convenience Only: ***/ else if (KeyDown(KEY_INC_STARDATE)) { - StarSystem::SetBaseTime(StarSystem::GetBaseTime() + 600, true); + starshatter::engine::SetOperationStart(300.0, true); } else if (KeyDown(KEY_DEC_STARDATE)) { - StarSystem::SetBaseTime(StarSystem::GetBaseTime() - 600, true); + starshatter::engine::SetOperationStart(-300.0, true); } /***/ } @@ -2556,7 +2558,9 @@ Starshatter::ExecCutscene(const char* msn_file, const char* path) CreateWorld(); cutscene_mission = new Mission(0); - cutscene_basetime = StarSystem::GetBaseTime(); + cutscene_operation_start = starshatter::engine::OperationStart(); + cutscene_mission_start = starshatter::engine::MissionStart(); + cutscene_game_time = Clock::GetInstance()->GameTime() / 1000.0; if (cutscene_mission->Load(msn_file, path)) { Sim* sim = (Sim*) world; @@ -2582,7 +2586,9 @@ Starshatter::ExecCutscene(const char* msn_file, const char* path) else { delete cutscene_mission; cutscene_mission = 0; - cutscene_basetime = 0; + cutscene_operation_start = 0; + cutscene_mission_start = 0; + cutscene_game_time = 0; } } @@ -2659,15 +2665,14 @@ Starshatter::EndMission() if (sim && sim->GetMission() == cutscene_mission) { ShipStats::Initialize(); sim->UnloadMission(); - - // restore world clock (true => absolute time reference) - if (cutscene_basetime != 0) - StarSystem::SetBaseTime(cutscene_basetime, true); - + starshatter::engine::SetOperationStart(cutscene_operation_start); + starshatter::engine::SetMissionStart(cutscene_mission_start); + Clock::GetInstance()->ResetGameTime(cutscene_game_time); delete cutscene_mission; - cutscene_mission = 0; - cutscene_basetime = 0; - + cutscene_mission = nullptr; + cutscene_operation_start = 0; + cutscene_mission_start = 0; + cutscene_game_time = 0; return; } } -- cgit v1.1