Skip to content

Commit

Permalink
Added customisable update rate for unit quad positions to reduce CPU …
Browse files Browse the repository at this point in the history
…load.
  • Loading branch information
marcushutchings committed Sep 13, 2022
1 parent 7c57e61 commit db68239
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions rts/Sim/Misc/ModInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ void CModInfo::ResetState()
allowHoverUnitStrafing = true;

maxCollisionPushMultiplier = std::numeric_limits<float>::infinity();
unitQuadPositionUpdateRate = 3;
}
{
constructionDecay = true;
Expand Down Expand Up @@ -161,6 +162,7 @@ void CModInfo::Init(const std::string& modFileName)
allowGroundUnitGravity = movementTbl.GetBool("allowGroundUnitGravity", allowGroundUnitGravity);
allowHoverUnitStrafing = movementTbl.GetBool("allowHoverUnitStrafing", (pathFinderSystem == QTPFS_TYPE));
maxCollisionPushMultiplier = movementTbl.GetFloat("maxCollisionPushMultiplier", maxCollisionPushMultiplier);
unitQuadPositionUpdateRate = movementTbl.GetInt("unitQuadPositionUpdateRate", unitQuadPositionUpdateRate);
}

{
Expand Down
4 changes: 4 additions & 0 deletions rts/Sim/Misc/ModInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ class CModInfo
// relative to a unit's maxspeed (default: inf)
float maxCollisionPushMultiplier;

// rate in sim frames that a unit's position in the quad grid is updated (default: 3)
// lower the number will increase CPU load, but increase accuracy of collision detection
int unitQuadPositionUpdateRate;

// Build behaviour
/// Should constructions without builders decay?
bool constructionDecay;
Expand Down
5 changes: 5 additions & 0 deletions rts/Sim/MoveTypes/MoveType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include "MoveType.h"
#include "Map/Ground.h"
#include "Sim/Misc/GlobalSynced.h"
#include "Sim/Misc/ModInfo.h"
#include "Sim/Misc/QuadField.h"
#include "Sim/Units/Unit.h"
#include "Sim/Units/UnitDef.h"
Expand Down Expand Up @@ -72,6 +74,9 @@ AMoveType::AMoveType(CUnit* owner):

void AMoveType::UpdateCollisionMap()
{
if ((gs->frameNum + owner->id) % modInfo.unitQuadPositionUpdateRate)
return;

if (owner->pos != oldSlowUpdatePos) {
const int newMapSquare = CGround::GetSquare(oldSlowUpdatePos = owner->pos);

Expand Down

2 comments on commit db68239

@GoogleFrog
Copy link
Collaborator

@GoogleFrog GoogleFrog commented on db68239 Sep 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If lua could force a quad update then I expect the really critical edge cases would be fixable with a cheap update when particular units fire.

We already did this in ZK for the old version of the bug https://github.com/ZeroK-RTS/Zero-K/blob/master/scripts/spiderantiheavy.lua#L157. A dedicated callout rather than some hax would be an improvement.

@GoogleFrog
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The really critical edge cases could also be solved by giving every weapon type a tag that increases projectile collision search radius. This would have to include beamlasers to be effective.

Please sign in to comment.