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" #include "UserManager.h"
#define HIGH 16 //Times are 1 / fps, in ms
#define MEDIUM 33 #define HIGH 16 //60 fps
#define LOW 66 #define MEDIUM 33 //30 fps
#define LOW 66 //15 fps
#define SOCIAL { MEDIUM, LOW } #define SOCIAL { LOW }
#define BATTLE { HIGH, MEDIUM } #define SOCIAL_HUB { MEDIUM } //Added to compensate for the large playercounts in NS and NT
#define BATTLE_INSTANCE { MEDIUM, LOW } #define BATTLE { HIGH }
#define RACE { MEDIUM, LOW } #define BATTLE_INSTANCE { MEDIUM }
#define PROPERTY { LOW, LOW } #define RACE { HIGH }
#define PROPERTY { LOW }
PerformanceProfile PerformanceManager::m_CurrentProfile = SOCIAL; PerformanceProfile PerformanceManager::m_CurrentProfile = SOCIAL;
PerformanceProfile PerformanceManager::m_DefaultProfile = SOCIAL; PerformanceProfile PerformanceManager::m_DefaultProfile = SOCIAL;
PerformanceProfile PerformanceManager::m_InactiveProfile = { LOW, LOW }; PerformanceProfile PerformanceManager::m_InactiveProfile = { LOW };
std::map<LWOMAPID, PerformanceProfile> PerformanceManager::m_Profiles = { std::map<LWOMAPID, PerformanceProfile> PerformanceManager::m_Profiles = {
// VE // VE
{ 1000, SOCIAL }, { 1000, SOCIAL },
// AG // AG
{ 1100, BATTLE }, { 1100, BATTLE },
{ 1101, BATTLE_INSTANCE }, { 1101, BATTLE_INSTANCE },
{ 1102, BATTLE_INSTANCE }, { 1102, BATTLE_INSTANCE },
{ 1150, PROPERTY }, { 1150, PROPERTY },
{ 1151, PROPERTY }, { 1151, PROPERTY },
// NS // NS
{ 1200, SOCIAL }, { 1200, SOCIAL_HUB },
{ 1201, SOCIAL }, { 1201, SOCIAL },
{ 1203, RACE }, { 1203, RACE },
{ 1204, BATTLE_INSTANCE }, { 1204, BATTLE_INSTANCE },
{ 1250, PROPERTY }, { 1250, PROPERTY },
{ 1251, PROPERTY }, { 1251, PROPERTY },
// GF // GF
{ 1300, BATTLE }, { 1300, BATTLE },
{ 1302, BATTLE_INSTANCE }, { 1302, BATTLE_INSTANCE },
{ 1303, BATTLE_INSTANCE }, { 1303, BATTLE_INSTANCE },
{ 1350, PROPERTY }, { 1350, PROPERTY },
// FV // FV
{ 1400, BATTLE }, { 1400, BATTLE },
{ 1402, BATTLE_INSTANCE }, { 1402, BATTLE_INSTANCE },
{ 1403, RACE }, { 1403, RACE },
{ 1450, PROPERTY }, { 1450, PROPERTY },
// LUP // LUP
{ 1600, SOCIAL }, { 1600, SOCIAL },
{ 1601, SOCIAL }, { 1601, SOCIAL },
{ 1602, SOCIAL }, { 1602, SOCIAL },
{ 1603, SOCIAL }, { 1603, SOCIAL },
{ 1604, SOCIAL }, { 1604, SOCIAL },
// LEGO Club // LEGO Club
{ 1700, SOCIAL }, { 1700, SOCIAL },
// AM // AM
{ 1800, BATTLE }, { 1800, BATTLE },
// NT // NT
{ 1900, SOCIAL }, { 1900, SOCIAL_HUB },
// NJ // NJ
{ 2000, BATTLE }, { 2000, BATTLE },
{ 2001, BATTLE_INSTANCE }, { 2001, BATTLE_INSTANCE },
}; };
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);
const auto pair = m_Profiles.find(mapID);
if (pair == m_Profiles.end()) if (pair == m_Profiles.end()) {
{ m_CurrentProfile = m_DefaultProfile;
m_CurrentProfile = m_DefaultProfile;
return; return;
} }
m_CurrentProfile = pair->second; m_CurrentProfile = pair->second;
} }
uint32_t PerformanceManager::GetServerFramerate() uint32_t PerformanceManager::GetServerFramerate() {
{ if (UserManager::Instance()->GetUserCount() == 0) {
if (UserManager::Instance()->GetUserCount() == 0) return m_InactiveProfile.serverFramerate;
{ }
return m_InactiveProfile.serverFramerate;
}
return m_CurrentProfile.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,29 +4,24 @@
#include "dCommonVars.h" #include "dCommonVars.h"
struct PerformanceProfile struct PerformanceProfile {
{ uint32_t serverFramerate;
uint32_t serverFramerate;
uint32_t physicsFramerate;
}; };
class PerformanceManager class PerformanceManager {
{
public: public:
~PerformanceManager(); ~PerformanceManager();
static void SelectProfile(LWOMAPID mapID); static void SelectProfile(LWOMAPID mapID);
static uint32_t GetServerFramerate(); static uint32_t GetServerFramerate();
static uint32_t GetPhysicsFramerate();
static uint32_t GetPhysicsStepRate();
private: private:
PerformanceManager(); PerformanceManager();
static PerformanceProfile m_CurrentProfile; static PerformanceProfile m_CurrentProfile;
static PerformanceProfile m_DefaultProfile; static PerformanceProfile m_DefaultProfile;
static PerformanceProfile m_InactiveProfile; static PerformanceProfile m_InactiveProfile;
static std::map<LWOMAPID, PerformanceProfile> m_Profiles; static std::map<LWOMAPID, PerformanceProfile> m_Profiles;
}; };

View File

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