Skip to content

Conversation

@IamInnocent3X
Copy link

Modifies the GameLogic to tell handleClientTurretPositioning() and handleClientRecoil() function in W3DModelDraw to only update when Necessary.

Copy link

@Skyaero42 Skyaero42 left a comment

Choose a reason for hiding this comment

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

Any indication on the performance gain?

This may need extensive testing for mismatching.

//-------------------------------------------------------------------------------------------------
void W3DModelDraw::setNeedUpdateTurretPositioning(Bool set)
{
m_needUpdateTurretPosition = set; // A simple function with the dangers of an atomic bomb, misuse and it'll cause desync

Choose a reason for hiding this comment

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

Comment not necessary.

if( xfer->getXferMode() == XFER_LOAD && m_subObjectVec.empty() == FALSE )
updateSubObjects();

#if !RETAIL_COMPATIBLE_CRC

Choose a reason for hiding this comment

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

Does this require a xfer version change?

@IamInnocent3X
Copy link
Author

IamInnocent3X commented Jan 2, 2026

Any indication on the performance gain?

I am not sure, but the devs does mention it being not a major problem.

Line 2494 @todo fix me someday (srj)

handleClientRecoil function are majority just For Loop Checks, each time checks with for loops based on how many Maximum Weapons are in game, (In this case, 3), and checks for each Weapon Slot whether there are any recoil to handle. If it does, it handles the Model Bone Recoil and handles their Muzzle from showing. Every Barrel Bone present will require checks.

handleClientTurretPositioning however, is O(n) based. It calls for all Turrets for each Weapon Slot to update Every Frame regardless if there are any changes. For each turret in the runtime it calls for AIUpdateInterface to get their Turret Pitch and Angle, then Transforms the Matrix up to 2 Times (One for Angle, One for Pitch). This is called every frame.

The changes just add a go/stop variable at the beginning of both functions, (m_doHandleRecoil, and m_needUpdateTurretPosition) to inform W3DModelDraw to allow the calling of the respective functions.

@stephanmeesters
Copy link

I think this can be simplified by removing the changes to xfer and instead forcing a recompute right after you load the savegame, like this (do test it):

diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp
  @@ void Object::loadPostProcess()
   	if( m_xferContainedByID != INVALID_ID )
   		m_containedBy = TheGameLogic->findObjectByID(m_xferContainedByID);
   	else
   		m_containedBy = NULL;
  +
  +	setNeedUpdateTurretPositioning(TRUE);
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp b/GeneralsMD/Code/GameEngineDevice/
  Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp
  @@ void W3DModelDraw::loadPostProcess( void )
   	// extend base class
   	DrawModule::loadPostProcess();
  +
  +	m_needUpdateTurretPosition = TRUE;
  +	m_doHandleRecoil = TRUE;

This may change the CRC right after loading a savegame but I don't see how that would be a problem

@IamInnocent3X
Copy link
Author

I think this can be simplified by removing the changes to xfer and instead forcing a recompute right after you load the savegame, like this (do test it):

diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp
  @@ void Object::loadPostProcess()
   	if( m_xferContainedByID != INVALID_ID )
   		m_containedBy = TheGameLogic->findObjectByID(m_xferContainedByID);
   	else
   		m_containedBy = NULL;
  +
  +	setNeedUpdateTurretPositioning(TRUE);
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp b/GeneralsMD/Code/GameEngineDevice/
  Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp
  @@ void W3DModelDraw::loadPostProcess( void )
   	// extend base class
   	DrawModule::loadPostProcess();
  +
  +	m_needUpdateTurretPosition = TRUE;
  +	m_doHandleRecoil = TRUE;

This may change the CRC right after loading a savegame but I don't see how that would be a problem

This change seems logical, tested on my end from loading a retail compatible save and it seems fine. I'll adjust and update my commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants