Skip to content

Commit 61301ff

Browse files
authored
Use dynamic physics update rate above 120 FPS (#95)
1 parent 517aba7 commit 61301ff

8 files changed

Lines changed: 69 additions & 0 deletions

File tree

MarathonRecomp/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ set(MARATHON_RECOMP_PATCHES_CXX_SOURCES
138138
"patches/aspect_ratio_patches.cpp"
139139
"patches/audio_patches.cpp"
140140
"patches/camera_patches.cpp"
141+
"patches/fps_patches.cpp"
141142
"patches/frontend_listener.cpp"
142143
"patches/misc_patches.cpp"
143144
"patches/player_patches.cpp"

MarathonRecomp/api/Marathon.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@
5656
#include "Sonicteam/SoX/Engine/Task.h"
5757
#include "Sonicteam/SoX/MessageReceiver.h"
5858
#include "Sonicteam/SoX/Object.h"
59+
#include "Sonicteam/SoX/Physics/Havok/WorldHavok.h"
60+
#include "Sonicteam/SoX/Physics/World.h"
61+
#include "Sonicteam/SoX/RefCountObject.h"
5962
#include "Sonicteam/System/CreateStatic.h"
6063
#include "Sonicteam/System/Singleton.h"
6164
#include "Sonicteam/TitleTask.h"

MarathonRecomp/api/Sonicteam/GameImp.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <Marathon.inl>
4+
#include <Sonicteam/SoX/Physics/World.h>
45

56
namespace Sonicteam
67
{
@@ -29,5 +30,13 @@ namespace Sonicteam
2930

3031
MARATHON_INSERT_PADDING(0xE3C);
3132
PlayerData m_PlayerData[4];
33+
MARATHON_INSERT_PADDING(0xA4C);
34+
xpointer<SoX::Physics::World> m_pPhysicsWorld;
35+
xpointer<void> m_pMyCollisionFilter;
36+
37+
template <typename T>
38+
inline T* GetPhysicsWorld();
3239
};
3340
}
41+
42+
#include <Sonicteam/GameImp.inl>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Sonicteam
2+
{
3+
template <typename T>
4+
inline T* GameImp::GetPhysicsWorld()
5+
{
6+
return (T*)m_pPhysicsWorld.get();
7+
}
8+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma once
2+
3+
#include <Marathon.inl>
4+
#include <Sonicteam/SoX/Physics/World.h>
5+
6+
namespace Sonicteam::SoX::Physics::Havok
7+
{
8+
class WorldHavok : public World
9+
{
10+
public:
11+
MARATHON_INSERT_PADDING(0x18);
12+
bool m_IsDynamicUpdateRate;
13+
};
14+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#pragma once
2+
3+
#include <Marathon.inl>
4+
#include <Sonicteam/SoX/RefCountObject.h>
5+
6+
namespace Sonicteam::SoX::Physics
7+
{
8+
class World : public RefCountObject {};
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
3+
namespace Sonicteam::SoX
4+
{
5+
class RefCountObject
6+
{
7+
public:
8+
xpointer<void> m_pVftable;
9+
be<uint32_t> m_ReferenceCount;
10+
};
11+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <api/Marathon.h>
2+
#include <user/config.h>
3+
4+
// Sonicteam::SoX::Physics::Havok::WorldHavok::Update
5+
PPC_FUNC_IMPL(__imp__sub_82587AA8);
6+
PPC_FUNC(sub_82587AA8)
7+
{
8+
auto pPhysicsWorld = (Sonicteam::SoX::Physics::Havok::WorldHavok*)(base + ctx.r3.u32);
9+
10+
// Use dynamic update rate if the FPS exceeds the fixed rate.
11+
pPhysicsWorld->m_IsDynamicUpdateRate = Config::FPS > 120;
12+
13+
__imp__sub_82587AA8(ctx, base);
14+
}

0 commit comments

Comments
 (0)