-
-
Notifications
You must be signed in to change notification settings - Fork 127
Allow custom FPS values for each GameSpeed index #2092
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,97 +1,115 @@ | ||
| #include <Phobos.h> | ||
| #include <Helpers/Macro.h> | ||
| #include <Utilities/Macro.h> | ||
| #include <algorithm> | ||
| #include <SessionClass.h> | ||
| #include <GameOptionsClass.h> | ||
|
|
||
| namespace GameSpeedTemp | ||
| { | ||
| static int counter = 0; | ||
| } | ||
|
|
||
| DEFINE_HOOK(0x69BAE7, SessionClass_Resume_CampaignGameSpeed, 0xA) | ||
| { | ||
| GameOptionsClass::Instance.GameSpeed = Phobos::Config::CampaignDefaultGameSpeed; | ||
| return 0x69BAF1; | ||
| } | ||
|
|
||
| DEFINE_REFERENCE(CDTimerClass, FrameTimer, 0x887348) | ||
| // For custom game speeds: | ||
| // Add to rulesmd.ini under [General]: | ||
| // EnableCustomFPS=yes ; Enable/disable custom FPS | ||
| // CustomGameSpeedFPS.0=120 ; Per-speed FPS. 0 = vanilla. Vanilla: 0=60, 1=45, 2=30, 3=20, 4=15, 5=12, 6=10 | ||
| // | ||
| // -Each speed slot with a non-zero CustomGameSpeedFPS.N runs at that target FPS | ||
| // -Slots with 0 (or unset) use vanilla FPS for that position | ||
| // -Practical max is ~1000 FPS (timeGetTime() resolution) | ||
|
|
||
| // Queue_AI_Multiplayer | ||
| // Patch v26 to INT_MAX disables the 60fps cap on multiplayer. | ||
| DEFINE_PATCH(0x647C28, 0xBE, 0xFF, 0xFF, 0xFF, 0x7F); // mov esi, INT_MAX | ||
|
|
||
| DEFINE_HOOK(0x55E160, SyncDelay_Start, 0x6) | ||
| // Queue_AI_Multiplayer | ||
| // Override the GameSpeed-to-fps calculation in multiplayer. | ||
| DEFINE_HOOK(0x647C4D, Queue_AI_Multiplayer_CustomFPSCalculation, 0x1F) | ||
| { | ||
| //DEFINE_NONSTATIC_REFERENCE(CDTimerClass, NFTTimer, 0x887328); | ||
| if (!Phobos::Misc::CustomGS || SessionClass::IsMultiplayer()) | ||
| return 0; | ||
| if ((Phobos::Misc::CustomGS_ChangeInterval[FrameTimer.TimeLeft] > 0) | ||
| && (GameSpeedTemp::counter % Phobos::Misc::CustomGS_ChangeInterval[FrameTimer.TimeLeft] == 0)) | ||
| int gameSpeed = GameOptionsClass::Instance.GameSpeed; | ||
| int calculatedFPS; | ||
|
|
||
| if (Phobos::Misc::EnableCustomFPS && Phobos::Misc::CustomGameSpeedFPS[gameSpeed] > 0) | ||
| { | ||
| calculatedFPS = Phobos::Misc::CustomGameSpeedFPS[gameSpeed]; | ||
| } | ||
| else if (gameSpeed == 0) | ||
| { | ||
| FrameTimer.TimeLeft = Phobos::Misc::CustomGS_ChangeDelay[FrameTimer.TimeLeft]; | ||
| GameSpeedTemp::counter = 1; | ||
| // Vanilla: GameSpeed 0 = 60 FPS | ||
| calculatedFPS = 60; | ||
| } | ||
| else if (gameSpeed == 1) | ||
| { | ||
| // Vanilla: GameSpeed 1 = 45 FPS | ||
| calculatedFPS = 45; | ||
| } | ||
| else | ||
| { | ||
| FrameTimer.TimeLeft = Phobos::Misc::CustomGS_DefaultDelay[FrameTimer.TimeLeft]; | ||
| GameSpeedTemp::counter++; | ||
| // Vanilla: GameSpeed 2+ = 60 / GameSpeed | ||
| calculatedFPS = 60 / gameSpeed; | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
| R->EAX(calculatedFPS); | ||
|
|
||
| DEFINE_HOOK(0x55E33B, SyncDelay_End, 0x6) | ||
| { | ||
| if (Phobos::Misc::CustomGS && SessionClass::IsSingleplayer()) | ||
| FrameTimer.TimeLeft = GameOptionsClass::Instance.GameSpeed; | ||
| return 0; | ||
| return 0x647C6C; | ||
| } | ||
|
|
||
| // note: currently vanilla code, doesn't do anything, changing PrecalcDesiredFrameRate doesn't effect anything either | ||
| /* | ||
| void SetNetworkFrameRate() | ||
| // Hook MainLoop skirmish/campaign FPS calculation | ||
| // The normal route FrameTimer.TimeLeft rounds to 0 for >60 FPS (tick-based timeGetTime >> 4), | ||
| // NetworkFrameTimer (ms-based timeGetTime) provides the frame timing that SyncDelay's NetworkFrameTimer loop uses. | ||
| // We need to set up NetworkFrameTimer like multiplayer mode does for >60 FPS support. | ||
| DEFINE_HOOK(0x55D7B6, MainLoop_SkirmishFPSFix, 0xC) | ||
| { | ||
| DEFINE_REFERENCE(int, PrecalcDesiredFrameRate, 0xA8B550u) | ||
| switch (GameOptionsClass::Instance.GameSpeed) | ||
| const DWORD timerValue = R->ECX(); | ||
| const int gameSpeed = R->ESI(); | ||
|
|
||
| const bool shouldUseCustomFPS = Phobos::Misc::EnableCustomFPS | ||
| && Phobos::Misc::CustomGameSpeedFPS[gameSpeed] > 0 | ||
| && (SessionClass::IsSkirmish() || SessionClass::IsCampaign()); | ||
|
|
||
| if (!shouldUseCustomFPS) | ||
| { | ||
| case 0: | ||
| Game::Network.MaxAhead = 40; | ||
| PrecalcDesiredFrameRate = 60; | ||
| Game::Network.FrameSendRate = 10; | ||
| break; | ||
| case 1: | ||
| Game::Network.MaxAhead = 40; | ||
| PrecalcDesiredFrameRate = 45; | ||
| Game::Network.FrameSendRate = 10; | ||
| break; | ||
| case 2: | ||
| Game::Network.MaxAhead = 30; | ||
| PrecalcDesiredFrameRate = 30; | ||
| break; | ||
| case 3: | ||
| Game::Network.MaxAhead = 20; | ||
| PrecalcDesiredFrameRate = 20; | ||
| break; | ||
| case 4: | ||
| Game::Network.MaxAhead = 20; | ||
| PrecalcDesiredFrameRate = 15; | ||
| break; | ||
| case 5: | ||
| Game::Network.MaxAhead = 20; | ||
| PrecalcDesiredFrameRate = 12; | ||
| break; | ||
| default: | ||
| Game::Network.MaxAhead = 10; | ||
| PrecalcDesiredFrameRate = 10; | ||
| break; | ||
| // Use vanilla behavior | ||
| Unsorted::GameFrameTimer.CurrentTime = timerValue; | ||
|
Check failure on line 74 in src/Misc/Hooks.Gamespeed.cpp
|
||
| Unsorted::GameFrameTimer.TimeLeft = gameSpeed; | ||
|
Check failure on line 75 in src/Misc/Hooks.Gamespeed.cpp
|
||
| return 0x55D7C2; | ||
| } | ||
| } | ||
|
|
||
| DEFINE_HOOK(0x5C49A7, MPCooperative_5C46E0_FPS, 0x9) | ||
| { | ||
| SetNetworkFrameRate(); | ||
| return 0x5C4A40; | ||
| const int customFPS = Phobos::Misc::CustomGameSpeedFPS[gameSpeed]; | ||
|
|
||
| // calc frame timings | ||
| const int targetFrameDelayTicks = 60 / customFPS; | ||
| const int targetFrameTimeMs = std::max(1, 1000 / customFPS); // 1ms floor = ~1000 FPS ceiling | ||
|
|
||
| const DWORD currentTime = timeGetTime(); | ||
|
|
||
| // just in case | ||
| Unsorted::GameFrameTimer.CurrentTime = timerValue; | ||
|
Check failure on line 88 in src/Misc/Hooks.Gamespeed.cpp
|
||
| Unsorted::GameFrameTimer.TimeLeft = targetFrameDelayTicks; | ||
|
Check failure on line 89 in src/Misc/Hooks.Gamespeed.cpp
|
||
|
|
||
| // SyncDelay compares elapsed time since CurrentTime against TimeLeft. | ||
| Unsorted::NetworkFrameTimer.StartTime = currentTime; | ||
|
Check failure on line 92 in src/Misc/Hooks.Gamespeed.cpp
|
||
| Unsorted::NetworkFrameTimer.CurrentTime = currentTime; | ||
| Unsorted::NetworkFrameTimer.TimeLeft = targetFrameTimeMs; | ||
|
|
||
| // "Requested FPS" | ||
| SessionClass::Instance.DesiredFrameRate = customFPS; | ||
|
|
||
| return 0x55D7C2; // Past the two MOVs we replaced | ||
| } | ||
|
|
||
| DEFINE_HOOK(0x794F7E, Start_Game_Now_FPS, 0x8) | ||
| // SyncDelay | ||
| // Redirect skirmish/campaign to the NetworkFrameTimer path | ||
| DEFINE_HOOK(0x55E1B6, SyncDelay_RedirectSkirmishToNetworkFrameTimer, 0x6) | ||
| { | ||
| SetNetworkFrameRate(); | ||
| return 0x79501F; | ||
| if (SessionClass::IsSkirmish() || SessionClass::IsCampaign()) | ||
| { | ||
| if (Phobos::Misc::EnableCustomFPS && Phobos::Misc::CustomGameSpeedFPS[GameOptionsClass::Instance.GameSpeed] > 0) | ||
| return 0x55E1BC; // Custom FPS: use NetworkFrameTimer path like multiplayer | ||
|
|
||
| return 0x55E2B4; // Vanilla FrameTimer path | ||
| } | ||
|
|
||
| return 0x55E1BC; | ||
| } | ||
| */ | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should add migration entries to docs and the migration script (see FIXME entries)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
b1e580f
Sorry, not seeing any FIXME?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ctrl+F in migration script (see Phobos Supplementaries repo)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Phobos-developers/PhobosSupplementaries#14