From d2fc3ad2272f7cc850ef95fbe803c10e8746ad86 Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 2 Oct 2021 21:34:32 +0200 Subject: Switched to long doubles instead of doing manual FPU manipulation --- Stars45/Campaign.cpp | 20 +++++++------------- Stars45/Campaign.h | 24 ++++++++++++------------ Stars45/StarSystem.cpp | 35 +++++++---------------------------- Stars45/StarSystem.h | 8 ++++---- 4 files changed, 30 insertions(+), 57 deletions(-) diff --git a/Stars45/Campaign.cpp b/Stars45/Campaign.cpp index 9a88e5d..1b23d14 100644 --- a/Stars45/Campaign.cpp +++ b/Stars45/Campaign.cpp @@ -1871,7 +1871,7 @@ Campaign::SetMissionId(int id) // +--------------------------------------------------------------------+ -double +long double Campaign::Stardate() { return StarSystem::Stardate(); @@ -2058,8 +2058,6 @@ Campaign::CheckPlayerGroup() // +--------------------------------------------------------------------+ -void FPU2Extended(); -void FPURestore(); void Campaign::StartMission() @@ -2070,14 +2068,12 @@ Campaign::StartMission() ::Print("\n\nCampaign Start Mission - %d. '%s'\n", m->Identity(), m->Name()); if (!scripted) { - FPU2Extended(); - - double gtime = (double) Game::GameTime() / 1000.0; - double base = startTime + m->Start() - 15 - gtime; + long double gtime = (long double) Game::GameTime() / 1000.0; + long double base = startTime + m->Start() - 15 - gtime; StarSystem::SetBaseTime(base); - double current_time = Stardate() - startTime; + long double current_time = Stardate() - startTime; char buffer[32]; FormatDayTime(buffer, current_time); @@ -2099,14 +2095,12 @@ Campaign::RollbackMission() if (m) { if (!scripted) { - FPU2Extended(); - - double gtime = (double) Game::GameTime() / 1000.0; - double base = startTime + m->Start() - 60 - gtime; + long double gtime = (long double) Game::GameTime() / 1000.0; + long double base = startTime + m->Start() - 60 - gtime; StarSystem::SetBaseTime(base); - double current_time = Stardate() - startTime; + long double current_time = Stardate() - startTime; ::Print(" mission start: %d\n", m->Start()); ::Print(" current time: %d\n", (int) current_time); } diff --git a/Stars45/Campaign.h b/Stars45/Campaign.h index a993e84..ecfa236 100644 --- a/Stars45/Campaign.h +++ b/Stars45/Campaign.h @@ -213,13 +213,13 @@ public: void SetMissionId(int id); int GetMissionId() const { return mission_id; } Bitmap* GetImage(int n) { return &image[n]; } - double GetTime() const { return time; } - double GetStartTime() const { return startTime; } - void SetStartTime(double t) { startTime = t; } - double GetLoadTime() const { return loadTime; } - void SetLoadTime(double t) { loadTime = t; } - double GetUpdateTime() const { return updateTime; } - void SetUpdateTime(double t) { updateTime = t; } + long double GetTime() const { return time; } + long double GetStartTime() const { return startTime; } + void SetStartTime(long double t) { startTime = t; } + long double GetLoadTime() const { return loadTime; } + void SetLoadTime(long double t) { loadTime = t; } + long double GetUpdateTime() const { return updateTime; } + void SetUpdateTime(long double t) { updateTime = t; } bool InCutscene() const; bool IsDynamic() const; @@ -246,7 +246,7 @@ public: static Campaign* SelectCampaign(const char* name); static Campaign* CreateCustomCampaign(const char* name, const char* path); - static double Stardate(); + static long double Stardate(); protected: void LoadCampaign(DataLoader* loader, bool full=false); @@ -295,10 +295,10 @@ protected: Mission* mission; Mission* net_mission; - double time; - double loadTime; - double startTime; - double updateTime; + long double time; + long double loadTime; + long double startTime; + long double updateTime; int lockout; }; diff --git a/Stars45/StarSystem.cpp b/Stars45/StarSystem.cpp index 8daed31..3c91f99 100644 --- a/Stars45/StarSystem.cpp +++ b/Stars45/StarSystem.cpp @@ -54,34 +54,17 @@ #include "Scene.h" #include "ParseUtil.h" -const double epoch = 0.5e9; -double StarSystem::stardate = 0; +const long double epoch = 0.5e9; +long double StarSystem::stardate = 0; // +====================================================================+ -static double base_time = 0; +static long double base_time = 0; static WORD oldcw = 0; static WORD fpcw = 0; -void FPU2Extended() +void StarSystem::SetBaseTime(long double t, bool absolute) { - _asm { fstcw oldcw } - fpcw = oldcw | 0x0300; // set 80-bit precision mode - _asm { fldcw fpcw } -} - -void FPURestore() -{ - // well, I don't actually WANT single-precision mode - // so I think I'll just ignore this... - - //_asm { fldcw oldcw } -} - -void StarSystem::SetBaseTime(double t, bool absolute) -{ - FPU2Extended(); - if (absolute) { base_time = t; CalcStardate(); @@ -94,7 +77,7 @@ void StarSystem::SetBaseTime(double t, bool absolute) } } -double StarSystem::GetBaseTime() +long double StarSystem::GetBaseTime() { return base_time; } @@ -111,14 +94,10 @@ void StarSystem::CalcStardate() base_time += epoch; } - FPU2Extended(); - - double gtime = (double) Game::GameTime() / 1000.0; - double sdate = gtime + base_time + epoch; + long double gtime = (long double) Game::GameTime() / 1000.0; + long double sdate = gtime + base_time + epoch; stardate = sdate; - - FPURestore(); } static const double GRAV = 6.673e-11; diff --git a/Stars45/StarSystem.h b/Stars45/StarSystem.h index 295b07b..90b77df 100644 --- a/Stars45/StarSystem.h +++ b/Stars45/StarSystem.h @@ -102,9 +102,9 @@ public: void SetActiveRegion(OrbitalRegion* rgn); - static void SetBaseTime(double t, bool absolute=false); - static double GetBaseTime(); - static double Stardate() { return stardate; } + static void SetBaseTime(long double t, bool absolute=false); + static long double GetBaseTime(); + static long double Stardate() { return stardate; } static void CalcStardate(); double Radius() const { return radius; } @@ -133,7 +133,7 @@ protected: int affiliation; int seq; Point loc; - static double stardate; + static long double stardate; double radius; bool instantiated; -- cgit v1.1