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,123 +2,99 @@
#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
{ 1000, SOCIAL },
// VE
{ 1000, SOCIAL },
// AG
{ 1100, BATTLE },
{ 1101, BATTLE_INSTANCE },
{ 1102, BATTLE_INSTANCE },
{ 1150, PROPERTY },
{ 1151, PROPERTY },
// AG
{ 1100, BATTLE },
{ 1101, BATTLE_INSTANCE },
{ 1102, BATTLE_INSTANCE },
{ 1150, PROPERTY },
{ 1151, PROPERTY },
// NS
{ 1200, SOCIAL },
{ 1201, SOCIAL },
{ 1203, RACE },
{ 1204, BATTLE_INSTANCE },
{ 1250, PROPERTY },
{ 1251, PROPERTY },
// NS
{ 1200, SOCIAL_HUB },
{ 1201, SOCIAL },
{ 1203, RACE },
{ 1204, BATTLE_INSTANCE },
{ 1250, PROPERTY },
{ 1251, PROPERTY },
// GF
{ 1300, BATTLE },
{ 1302, BATTLE_INSTANCE },
{ 1303, BATTLE_INSTANCE },
{ 1350, PROPERTY },
// GF
{ 1300, BATTLE },
{ 1302, BATTLE_INSTANCE },
{ 1303, BATTLE_INSTANCE },
{ 1350, PROPERTY },
// FV
{ 1400, BATTLE },
{ 1402, BATTLE_INSTANCE },
{ 1403, RACE },
{ 1450, PROPERTY },
// FV
{ 1400, BATTLE },
{ 1402, BATTLE_INSTANCE },
{ 1403, RACE },
{ 1450, PROPERTY },
// LUP
{ 1600, SOCIAL },
{ 1601, SOCIAL },
{ 1602, SOCIAL },
{ 1603, SOCIAL },
{ 1604, SOCIAL },
// LUP
{ 1600, SOCIAL },
{ 1601, SOCIAL },
{ 1602, SOCIAL },
{ 1603, SOCIAL },
{ 1604, SOCIAL },
// LEGO Club
{ 1700, SOCIAL },
// LEGO Club
{ 1700, SOCIAL },
// AM
{ 1800, BATTLE },
// AM
{ 1800, BATTLE },
// NT
{ 1900, SOCIAL },
// NT
{ 1900, SOCIAL_HUB },
// NJ
{ 2000, BATTLE },
{ 2001, BATTLE_INSTANCE },
// NJ
{ 2000, BATTLE },
{ 2001, BATTLE_INSTANCE },
};
PerformanceManager::PerformanceManager()
{
PerformanceManager::PerformanceManager() {
}
PerformanceManager::~PerformanceManager()
{
PerformanceManager::~PerformanceManager() {
}
void PerformanceManager::SelectProfile(LWOMAPID mapID)
{
const auto pair = m_Profiles.find(mapID);
void PerformanceManager::SelectProfile(LWOMAPID mapID) {
const auto pair = m_Profiles.find(mapID);
if (pair == m_Profiles.end())
{
m_CurrentProfile = m_DefaultProfile;
if (pair == m_Profiles.end()) {
m_CurrentProfile = m_DefaultProfile;
return;
}
return;
}
m_CurrentProfile = pair->second;
m_CurrentProfile = pair->second;
}
uint32_t PerformanceManager::GetServerFramerate()
{
if (UserManager::Instance()->GetUserCount() == 0)
{
return m_InactiveProfile.serverFramerate;
}
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;
return m_CurrentProfile.serverFramerate;
}

View File

@ -4,29 +4,24 @@
#include "dCommonVars.h"
struct PerformanceProfile
{
uint32_t serverFramerate;
uint32_t physicsFramerate;
struct PerformanceProfile {
uint32_t serverFramerate;
};
class PerformanceManager
{
class PerformanceManager {
public:
~PerformanceManager();
~PerformanceManager();
static void SelectProfile(LWOMAPID mapID);
static void SelectProfile(LWOMAPID mapID);
static uint32_t GetServerFramerate();
static uint32_t GetPhysicsFramerate();
static uint32_t GetPhysicsStepRate();
static uint32_t GetServerFramerate();
private:
PerformanceManager();
PerformanceManager();
static PerformanceProfile m_CurrentProfile;
static PerformanceProfile m_DefaultProfile;
static PerformanceProfile m_InactiveProfile;
static std::map<LWOMAPID, PerformanceProfile> m_Profiles;
static PerformanceProfile m_CurrentProfile;
static PerformanceProfile m_DefaultProfile;
static PerformanceProfile m_InactiveProfile;
static std::map<LWOMAPID, PerformanceProfile> m_Profiles;
};

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;
}
dpWorld::Instance().StepWorld(deltaTime);
Metrics::EndMeasurement(MetricVariable::Physics);
Metrics::StartMeasurement(MetricVariable::UpdateEntities);