Skip to content
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

Extend motion prediction support #177

Open
wants to merge 52 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
f1caf23
Add motion prediction support to 1.10
Jarcho Sep 7, 2022
fcb2daa
Extend text prediction to all versions
Jarcho Sep 7, 2022
a33f846
Fix Belt items jiggling on v1.09-v1.12
Jarcho Sep 8, 2022
2d71c96
Maybe fix motion prediction failure after long sessions
Jarcho Sep 23, 2022
f3e63d6
Use the game size as the render target size. Allows free resolution s…
Jarcho Oct 18, 2022
7698131
Load resolution mod on 1.10f and 1.12
Jarcho Oct 18, 2022
6ee7f02
Use full screen size for cinematics
Jarcho Oct 19, 2022
b61c119
Fix alt-tab
Jarcho Oct 19, 2022
0150d30
Fix text prediction in 1.09 and 1.10
Jarcho Oct 19, 2022
6f4d951
Correct cinematic rendering
Jarcho Oct 21, 2022
ccb4f8e
Add `nokeepaspectratio` option
Jarcho Nov 2, 2022
b533429
Remove accidentally commited testing code
Jarcho Nov 18, 2022
2e446fa
Remove unneeded `FeatureFlags`
Jarcho Nov 22, 2022
d40a2a6
Reduce length of some stalls
Jarcho Nov 22, 2022
2df73b5
Fix percision lost when calculating the frame time. Started after ~4 …
Jarcho Nov 22, 2022
0aa44e2
Update to vs2022
Jarcho Nov 22, 2022
006b89d
Update internal sg2dfreeres
Jarcho Nov 22, 2022
cecd1d9
Fix mispredictions in the unit motion prediction at low frame rates.
Jarcho Nov 23, 2022
e3a7f82
Limit cursor clipping to the render view
Jarcho Nov 24, 2022
1fa7e4a
Add basic profiling
Jarcho Nov 24, 2022
3644d8b
Smoothen out frame jitter for motion prediction
Jarcho Nov 24, 2022
0fe5eba
Fix unit motion predictor
Jarcho Nov 24, 2022
6478bf8
Fix internal sgd2freeres
Jarcho Nov 24, 2022
1599a16
Smoothen unit motion prediciton
Jarcho Nov 25, 2022
81de347
Don't bounce player back when they stop moving
Jarcho Nov 25, 2022
c648ef3
Make builtin sgd2freeres optional
Jarcho Nov 25, 2022
52e790f
Another attempt at reducing jitter in the unit motion predictor
Jarcho Nov 28, 2022
b068ef1
Add more profiling info
Jarcho Nov 28, 2022
4c97b9e
Continue to remove jitter from unit motion prediction.
Jarcho Nov 28, 2022
b271fae
Fix `DrawText` ordinal for 1.13c
Jarcho Nov 28, 2022
8df7b03
More work on improving motion prediction
Jarcho Dec 5, 2022
405a623
Add some more profiling
Jarcho Dec 5, 2022
f54fe5d
Rename `UnitMotionPredictor` to `MotionPredictor`
Jarcho Dec 6, 2022
5ee2d38
Use `FrameLatencyWaitableObject` when available
Jarcho Dec 6, 2022
e4d1625
Merge the text and unit motion predictors
Jarcho Dec 6, 2022
a9f59a2
Only predict a quarter frame ahead
Jarcho Dec 6, 2022
8dd9fed
Fix frame time correction in the motion predictor
Jarcho Dec 6, 2022
ae2a74c
Use sub-pixel precision for motion prediction
Jarcho Dec 7, 2022
7180c6e
Replace `Length` with `RealLength`
Jarcho Dec 7, 2022
e8d5367
Correct line drawing math
Jarcho Dec 7, 2022
2fc3d51
Add an option to render at the display size
Jarcho Dec 7, 2022
50db719
Adjust profiling info
Jarcho Dec 8, 2022
c3f443b
Profile sleep calls
Jarcho Dec 8, 2022
ac3d588
Add command line option to set the upscale filter
Jarcho Dec 8, 2022
d6d516d
Fix crash on shutdown in profiled builds
Jarcho Dec 11, 2022
31ef2f5
Use `FrameLatencyWaitableObject` in conjuction with `Inverval1`
Jarcho Dec 11, 2022
1cd2765
More precise frame rollover in the unit predictor
Jarcho Dec 11, 2022
621b56b
Fix rendering at an upscaled resolution
Jarcho Dec 18, 2022
cd5cf36
Capture the player's position during the draw call
Jarcho Dec 18, 2022
37a5c45
Fix some jiggling text labels
Jarcho Dec 23, 2022
04b4d4b
Fix more jiggling text labels
Jarcho Dec 24, 2022
09f6c18
Improve smoothness at lower frame rates
Jarcho Dec 24, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@
publish/
**_dxbc.txt
/.vs/
**/Profile
**/Release (ResMod)
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ Update July 2021: I have been too busy to work on D2DX for a while, but hope to

## Compatibility
Game versions supported:
- All features: 1.09d, 1.13c, 1.13d and 1.14d.
- Without resolution switching: 1.10f, 1.12.
- All features: 1.09d, 1.10f, 1.12, 1.13c, 1.13d and 1.14d.
- Other versions are unsupported, will display a warning at startup and exhibit glitches.

For compatibility with mods, see the [wiki](https://github.com/bolrog/d2dx/wiki/Compatibility-with-other-mods).
Expand Down
1 change: 1 addition & 0 deletions d2dx-defaults.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ noaa=false # if true, will not apply anti-aliasing to jagged edges
nocompatmodefix=false # if true, will not block the use of "Windows XP compatibility mode"
notitlechange=false # if true, will not change the window title text
nomotionprediction=false # if true, will not run the game graphics at high fps
nokeepaspectratio=false # if true, will not keep the aspect ratio when drawing to the screen
72 changes: 41 additions & 31 deletions src/d2dx.sln
Original file line number Diff line number Diff line change
@@ -1,31 +1,41 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30517.126
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "d2dx", "d2dx\d2dx.vcxproj", "{93A28F27-8D56-470C-B699-15B0CF2C926A}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "d2dxtests", "d2dxtests\d2dxtests.vcxproj", "{64214704-FE00-4DB6-BEFA-1E622F7262A1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{93A28F27-8D56-470C-B699-15B0CF2C926A}.Debug|x86.ActiveCfg = Debug|Win32
{93A28F27-8D56-470C-B699-15B0CF2C926A}.Debug|x86.Build.0 = Debug|Win32
{93A28F27-8D56-470C-B699-15B0CF2C926A}.Release|x86.ActiveCfg = Release|Win32
{93A28F27-8D56-470C-B699-15B0CF2C926A}.Release|x86.Build.0 = Release|Win32
{64214704-FE00-4DB6-BEFA-1E622F7262A1}.Debug|x86.ActiveCfg = Debug|Win32
{64214704-FE00-4DB6-BEFA-1E622F7262A1}.Debug|x86.Build.0 = Debug|Win32
{64214704-FE00-4DB6-BEFA-1E622F7262A1}.Release|x86.ActiveCfg = Release|Win32
{64214704-FE00-4DB6-BEFA-1E622F7262A1}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {680244CF-729A-4310-A2CA-D9ABD4923671}
EndGlobalSection
EndGlobal

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32901.215
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "d2dx", "d2dx\d2dx.vcxproj", "{93A28F27-8D56-470C-B699-15B0CF2C926A}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "d2dxtests", "d2dxtests\d2dxtests.vcxproj", "{64214704-FE00-4DB6-BEFA-1E622F7262A1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Profile|x86 = Profile|x86
Release (ResMod)|x86 = Release (ResMod)|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{93A28F27-8D56-470C-B699-15B0CF2C926A}.Debug|x86.ActiveCfg = Debug|Win32
{93A28F27-8D56-470C-B699-15B0CF2C926A}.Debug|x86.Build.0 = Debug|Win32
{93A28F27-8D56-470C-B699-15B0CF2C926A}.Profile|x86.ActiveCfg = Profile|Win32
{93A28F27-8D56-470C-B699-15B0CF2C926A}.Profile|x86.Build.0 = Profile|Win32
{93A28F27-8D56-470C-B699-15B0CF2C926A}.Release (ResMod)|x86.ActiveCfg = Release (ResMod)|Win32
{93A28F27-8D56-470C-B699-15B0CF2C926A}.Release (ResMod)|x86.Build.0 = Release (ResMod)|Win32
{93A28F27-8D56-470C-B699-15B0CF2C926A}.Release|x86.ActiveCfg = Release|Win32
{93A28F27-8D56-470C-B699-15B0CF2C926A}.Release|x86.Build.0 = Release|Win32
{64214704-FE00-4DB6-BEFA-1E622F7262A1}.Debug|x86.ActiveCfg = Debug|Win32
{64214704-FE00-4DB6-BEFA-1E622F7262A1}.Debug|x86.Build.0 = Debug|Win32
{64214704-FE00-4DB6-BEFA-1E622F7262A1}.Profile|x86.ActiveCfg = Profile|Win32
{64214704-FE00-4DB6-BEFA-1E622F7262A1}.Profile|x86.Build.0 = Profile|Win32
{64214704-FE00-4DB6-BEFA-1E622F7262A1}.Release (ResMod)|x86.ActiveCfg = Release (ResMod)|Win32
{64214704-FE00-4DB6-BEFA-1E622F7262A1}.Release (ResMod)|x86.Build.0 = Release (ResMod)|Win32
{64214704-FE00-4DB6-BEFA-1E622F7262A1}.Release|x86.ActiveCfg = Release|Win32
{64214704-FE00-4DB6-BEFA-1E622F7262A1}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {680244CF-729A-4310-A2CA-D9ABD4923671}
EndGlobalSection
EndGlobal
156 changes: 86 additions & 70 deletions src/d2dx/BuiltinResMod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,73 +24,9 @@

using namespace d2dx;

_Use_decl_annotations_
BuiltinResMod::BuiltinResMod(
HMODULE hModule,
Size gameSize,
const std::shared_ptr<IGameHelper>& gameHelper)
{
if (!hModule || !gameHelper)
{
D2DX_CHECK_HR(E_INVALIDARG);
}

_isActive = false;

#ifndef D2DX_UNITTEST
if (IsCompatible(gameHelper.get()))
{
D2DX_LOG("Writing SGD2FreeRes files.");

if (!WriteResourceToFile(hModule, IDR_SGD2FR_MPQ, "mpq", "d2dx_sgd2freeres.mpq"))
{
D2DX_LOG("Failed to write d2dx_sgd2freeres.mpq");
}

if (!WriteResourceToFile(hModule, IDR_SGD2FR_DLL, "dll", "d2dx_sgd2freeres.dll"))
{
D2DX_LOG("Failed to write d2dx_sgd2freeres.mpq");
}

if (!WriteConfig(gameSize))
{
D2DX_LOG("Failed to write SGD2FreeRes configuration.");
}

D2DX_LOG("Initializing SGD2FreeRes.");
LoadLibraryA("d2dx_sgd2freeres.dll");

_isActive = true;
return;
}
#endif
}

bool BuiltinResMod::IsActive() const
{
return _isActive;
}

_Use_decl_annotations_
bool BuiltinResMod::IsCompatible(
IGameHelper* gameHelper)
{
auto gameVersion = gameHelper->GetVersion();

if (gameVersion != d2dx::GameVersion::Lod109d &&
gameVersion != d2dx::GameVersion::Lod113c &&
gameVersion != d2dx::GameVersion::Lod113d &&
gameVersion != d2dx::GameVersion::Lod114d)
{
D2DX_LOG("Unsupported game version, won't use built-in resolution mod.");
return false;
}

return true;
}

_Use_decl_annotations_
bool BuiltinResMod::WriteResourceToFile(
#ifdef D2DX_INTERNAL_RES_MOD
bool WriteResourceToFile(
HMODULE hModule,
int32_t resourceId,
const char* ext,
Expand All @@ -113,7 +49,7 @@ bool BuiltinResMod::WriteResourceToFile(

resourceData = LoadResource(hModule, resourceInfo);
if (!resourceData)
{
{
succeeded = false;
goto end;
}
Expand All @@ -125,7 +61,7 @@ bool BuiltinResMod::WriteResourceToFile(
succeeded = false;
goto end;
}

succeeded = DecompressLZMAToFile((const uint8_t*)payloadPtr, payloadSize, filename);

end:
Expand All @@ -141,8 +77,7 @@ bool BuiltinResMod::WriteResourceToFile(
return succeeded;
}

_Use_decl_annotations_
bool BuiltinResMod::WriteConfig(
bool WriteConfig(
_In_ Size gameSize)
{
HANDLE file = nullptr;
Expand Down Expand Up @@ -200,3 +135,84 @@ bool BuiltinResMod::WriteConfig(

return succeeded;
}
#endif

_Use_decl_annotations_
BuiltinResMod::BuiltinResMod(
HMODULE hModule,
Size gameSize,
const std::shared_ptr<IGameHelper>& gameHelper)
{
if (!hModule || !gameHelper)
{
D2DX_CHECK_HR(E_INVALIDARG);
}

_isActive = false;

#ifndef D2DX_UNITTEST
if (IsCompatible(gameHelper.get()))
{
#ifdef D2DX_INTERNAL_RES_MOD
D2DX_LOG("Writing SGD2FreeRes files.");

if (!WriteResourceToFile(hModule, IDR_SGD2FR_MPQ, "mpq", "d2dx_sgd2freeres.mpq"))
{
D2DX_LOG("Failed to write d2dx_sgd2freeres.mpq");
}

if (!WriteResourceToFile(hModule, IDR_SGD2FR_DLL, "dll", "d2dx_sgd2freeres.dll"))
{
D2DX_LOG("Failed to write d2dx_sgd2freeres.dll");
}

if (!WriteConfig(gameSize))
{
D2DX_LOG("Failed to write SGD2FreeRes configuration.");
}

D2DX_LOG("Initializing SGD2FreeRes.");
if (LoadLibraryA("d2dx_sgd2freeres.dll") == 0)
{
D2DX_LOG("Failed to load d2dx_sgd2freeres.dll.");
return;
}
#else
D2DX_LOG("Initializing SGD2FreeRes.");
if (LoadLibraryA("SGD2FreeRes.dll") == 0)
{
D2DX_LOG("Failed to load SGD2FreeRes.dll.");
return;
}
#endif

_isActive = true;
return;
}
#endif
}

bool BuiltinResMod::IsActive() const
{
return _isActive;
}

_Use_decl_annotations_
bool BuiltinResMod::IsCompatible(
IGameHelper* gameHelper)
{
auto gameVersion = gameHelper->GetVersion();

if (gameVersion != d2dx::GameVersion::Lod109d &&
gameVersion != d2dx::GameVersion::Lod110f &&
gameVersion != d2dx::GameVersion::Lod112 &&
gameVersion != d2dx::GameVersion::Lod113c &&
gameVersion != d2dx::GameVersion::Lod113d &&
gameVersion != d2dx::GameVersion::Lod114d)
{
D2DX_LOG("Unsupported game version, won't use built-in resolution mod.");
return false;
}

return true;
}
9 changes: 0 additions & 9 deletions src/d2dx/BuiltinResMod.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,6 @@ namespace d2dx
bool IsCompatible(
_In_ IGameHelper* gameHelper);

bool WriteResourceToFile(
_In_ HMODULE hModule,
_In_ int32_t resourceId,
_In_z_ const char* ext,
_In_z_ const char* filename);

bool WriteConfig(
_In_ Size gameSize);

bool _isActive = false;
};
}
Loading