Skip to content

Commit

Permalink
Limit CF_OnUpdate rate for perf boost (#130)
Browse files Browse the repository at this point in the history
* Limit CF_OnUpdate rate for perf boost

CF_OnUpdate loop is fairly expensive especially on server. Limit update rate to 25 ms on server and 5 ms on client. Significant performance boost was observed when many modules are using update loops (e.g. COT gained 10% tick rate increase on server with this change).

* Removed rate limit on client, fixed missing var

* Add define

* `timeslice` is inaccurate, use GetIickTime so modules can do accurate time measurement

* Defines moved to config.cpp
  • Loading branch information
lava76 authored Jan 9, 2025
1 parent 98bfe81 commit 7bfa491
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions JM/CF/Scripts/5_Mission/CommunityFramework/Mission/MissionBase.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
modded class MissionBase
{
#ifdef SERVER
float m_CF_UpdateTime;
#endif

protected bool m_bLoaded = false;

void MissionBase()
Expand All @@ -19,17 +23,35 @@ modded class MissionBase

void CF_OnUpdate(float timeslice)
{
if (g_Game.IsLoading())
#ifdef SERVER
float updateTime = GetGame().GetTickTime();
float elapsed = updateTime - m_CF_UpdateTime;
bool update = elapsed >= 0.025;

if (update)
{
return;
m_CF_UpdateTime = updateTime;
}
#endif

if (!m_bLoaded)
{
if (g_Game.IsLoading())
{
return;
}

m_bLoaded = true;
OnMissionLoaded();
}

#ifdef SERVER
if (update)
{
CF_ModuleGameManager.OnUpdate(this, new CF_EventUpdateArgs(elapsed));
}
#else
CF_ModuleGameManager.OnUpdate(this, new CF_EventUpdateArgs(timeslice));
#endif
}
};

0 comments on commit 7bfa491

Please sign in to comment.