Merge pull request #449 from DarkflameUniverse/physics-fix

Rehook dPhysics to main framerate
This commit is contained in:
Gie "Max" Vanommeslaeghe 2022-02-09 10:55:21 +01:00 committed by GitHub
commit 788cd3f807
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 81 additions and 118 deletions

View File

@ -2,21 +2,23 @@
#include "UserManager.h"
#define HIGH 16
#define MEDIUM 33
#define LOW 66
//Times are 1 / fps, in ms
#define HIGH 16 //60 fps
#define MEDIUM 33 //30 fps
#define LOW 66 //15 fps
#define SOCIAL { MEDIUM, LOW }
#define BATTLE { HIGH, MEDIUM }
#define BATTLE_INSTANCE { MEDIUM, LOW }
#define RACE { MEDIUM, LOW }
#define PROPERTY { LOW, LOW }
#define SOCIAL { LOW }
#define SOCIAL_HUB { MEDIUM } //Added to compensate for the large playercounts in NS and NT
#define BATTLE { HIGH }
#define BATTLE_INSTANCE { MEDIUM }
#define RACE { HIGH }
#define PROPERTY { LOW }
PerformanceProfile PerformanceManager::m_CurrentProfile = SOCIAL;
PerformanceProfile PerformanceManager::m_DefaultProfile = SOCIAL;
PerformanceProfile PerformanceManager::m_InactiveProfile = { LOW, LOW };
PerformanceProfile PerformanceManager::m_InactiveProfile = { LOW };
std::map<LWOMAPID, PerformanceProfile> PerformanceManager::m_Profiles = {
// VE
@ -30,7 +32,7 @@ std::map<LWOMAPID, PerformanceProfile> PerformanceManager::m_Profiles = {
{ 1151, PROPERTY },
// NS
{ 1200, SOCIAL },
{ 1200, SOCIAL_HUB },
{ 1201, SOCIAL },
{ 1203, RACE },
{ 1204, BATTLE_INSTANCE },
@ -63,7 +65,7 @@ std::map<LWOMAPID, PerformanceProfile> PerformanceManager::m_Profiles = {
{ 1800, BATTLE },
// NT
{ 1900, SOCIAL },
{ 1900, SOCIAL_HUB },
// NJ
{ 2000, BATTLE },
@ -71,20 +73,16 @@ std::map<LWOMAPID, PerformanceProfile> PerformanceManager::m_Profiles = {
};
PerformanceManager::PerformanceManager()
{
PerformanceManager::PerformanceManager() {
}
PerformanceManager::~PerformanceManager()
{
PerformanceManager::~PerformanceManager() {
}
void PerformanceManager::SelectProfile(LWOMAPID mapID)
{
void PerformanceManager::SelectProfile(LWOMAPID mapID) {
const auto pair = m_Profiles.find(mapID);
if (pair == m_Profiles.end())
{
if (pair == m_Profiles.end()) {
m_CurrentProfile = m_DefaultProfile;
return;
@ -93,32 +91,10 @@ void PerformanceManager::SelectProfile(LWOMAPID mapID)
m_CurrentProfile = pair->second;
}
uint32_t PerformanceManager::GetServerFramerate()
{
if (UserManager::Instance()->GetUserCount() == 0)
{
uint32_t PerformanceManager::GetServerFramerate() {
if (UserManager::Instance()->GetUserCount() == 0) {
return m_InactiveProfile.serverFramerate;
}
return m_CurrentProfile.serverFramerate;
}
uint32_t PerformanceManager::GetPhysicsFramerate()
{
if (UserManager::Instance()->GetUserCount() == 0)
{
return m_InactiveProfile.physicsFramerate;
}
return m_CurrentProfile.physicsFramerate;
}
uint32_t PerformanceManager::GetPhysicsStepRate()
{
if (UserManager::Instance()->GetUserCount() == 0)
{
return 10; // Row physics at a really low framerate if the server is empty
}
return m_CurrentProfile.physicsFramerate / m_CurrentProfile.serverFramerate;
}

View File

@ -4,23 +4,18 @@
#include "dCommonVars.h"
struct PerformanceProfile
{
struct PerformanceProfile {
uint32_t serverFramerate;
uint32_t physicsFramerate;
};
class PerformanceManager
{
class PerformanceManager {
public:
~PerformanceManager();
static void SelectProfile(LWOMAPID mapID);
static uint32_t GetServerFramerate();
static uint32_t GetPhysicsFramerate();
static uint32_t GetPhysicsStepRate();
private:
PerformanceManager();

View File

@ -223,9 +223,7 @@ int main(int argc, char** argv) {
int framesSinceMasterStatus = 0;
int framesSinceShutdownSequence = 0;
int currentFramerate = highFrameRate;
int physicsFramerate = highFrameRate;
int physicsStepRate = 0;
int physicsStepCount = 0;
int ghostingStepCount = 0;
auto ghostingLastTime = std::chrono::high_resolution_clock::now();
@ -301,9 +299,6 @@ int main(int argc, char** argv) {
currentFramerate = PerformanceManager::GetServerFramerate();
}
physicsFramerate = PerformanceManager::GetPhysicsFramerate();
physicsStepRate = PerformanceManager::GetPhysicsStepRate();
//Warning if we ran slow
if (deltaTime > currentFramerate) {
Game::logger->Log("WorldServer", "We're running behind, dT: %f > %f (framerate)\n", deltaTime, currentFramerate);
@ -338,10 +333,7 @@ int main(int argc, char** argv) {
if (zoneID != 0 && deltaTime > 0.0f) {
Metrics::StartMeasurement(MetricVariable::Physics);
if (physicsStepCount++ >= physicsStepRate) {
dpWorld::Instance().StepWorld(deltaTime);
physicsStepCount = 0;
}
Metrics::EndMeasurement(MetricVariable::Physics);
Metrics::StartMeasurement(MetricVariable::UpdateEntities);