Skip to content

Commit

Permalink
feat: configure the disabling of PC physics when in 1st person view (#17
Browse files Browse the repository at this point in the history
)


to save on performance if the player doesn't care about simulating PC physics when in 1st person view.
  • Loading branch information
DaymareOn authored Feb 27, 2022
1 parent 3527928 commit 32d97f5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
3 changes: 3 additions & 0 deletions configs/configs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
calculate the maximumActiveSkeletons. Increasing sample size will flatten outliers but can slow adjustment responsiveness.
Default is 5. -->
<sampleSize>5</sampleSize>
<!-- disable1stPersonViewPhysics: if set to true, the physics of the PC won't be calculated when in 1st person view, to save performance.
Default is false. -->
<disable1stPersonViewPhysics>false</disable1stPersonViewPhysics>
<!-- enableCuda: experimental GPU collision algorithm. Try this if you have a slow CPU and fast GPU -->
<enableCuda>true</enableCuda>
</smp>
Expand Down
12 changes: 9 additions & 3 deletions hdtSMP64/ActorManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ namespace hdt
i.skeleton = nullptr;
}
else if (i.hasPhysics && i.updateAttachedState(playerCell, activeSkeletons >= maxActiveSkeletons))
activeSkeletons++;
activeSkeletons++;
}

m_skeletons.erase(
Expand Down Expand Up @@ -752,8 +752,14 @@ namespace hdt
{
if (isPlayerCharacter())
{
isActive = true;
state = SkeletonState::e_ActiveIsPlayer;
// That setting defines whether we don't set the PC skeleton as active
// when it is in 1st person view, to avoid calculating physics uselessly.
if (!(instance()->m_disable1stPersonViewPhysics // disabling?
&& PlayerCamera::GetSingleton()->cameraState == PlayerCamera::GetSingleton()->cameraStates[0])) // 1st person view
{
isActive = true;
state = SkeletonState::e_ActiveIsPlayer;
}
}
else if (isInPlayerView())
{
Expand Down
4 changes: 4 additions & 0 deletions hdtSMP64/ActorManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ namespace hdt
bool m_autoAdjustMaxSkeletons = true; // Whether to dynamically change the maxActive skeletons to maintain min_fps
int m_maxActiveSkeletons = 20; // The maximum active skeletons; hard limit
int m_sampleSize = 5; // how many samples (each sample taken every second) for determining average time per activeSkeleton.

// @brief Depending on this setting, we avoid to calculate the physics of the PC when it is in 1st person view.
bool m_disable1stPersonViewPhysics = false;

private:
void setSkeletonsActive();
};
Expand Down
2 changes: 2 additions & 0 deletions hdtSMP64/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ namespace hdt
}
else if (reader.GetLocalName() == "sampleSize")
ActorManager::instance()->m_sampleSize = std::max(reader.readInt(), 1);
else if (reader.GetLocalName() == "disable1stPersonViewPhysics")
ActorManager::instance()->m_disable1stPersonViewPhysics = reader.readBool();
else
{
_WARNING("Unknown config : %s", reader.GetLocalName());
Expand Down

0 comments on commit 32d97f5

Please sign in to comment.