Repository navigation
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughThe changes update tint-envelope access and transfer for Overlord riders. They also add non-retail-compatible handling for powered objects: brownout signaling for qualifying zero-energy objects, disabled tint during initialization, and attack rejection while underpowered. ChangesTint-envelope transfer
Powered-object behavior
Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix · Severity of issue fixed: Medium Suggested labels: Suggested reviewers: Merge Risk:
|
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Organization UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
19178bd7-d94a-4f90-903d-ecfebd6d3e0f
📒 Files selected for processing: 7
Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DOverlordAircraftDraw.cppCore/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DOverlordTankDraw.cppCore/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DOverlordTruckDraw.cppGenerals/Code/GameEngine/Include/GameClient/Drawable.hGenerals/Code/GameEngine/Source/GameLogic/Object/Object.cppGeneralsMD/Code/GameEngine/Include/GameClient/Drawable.hGeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟡 Minor · Underpowered turrets can still rotate through recentering and idle… · Object.cpp:2995-2999
Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp:2995-2999
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winUnderpowered turrets can still rotate through recentering and idle scanning.
The
DISABLED_UNDERPOWEREDcheck inObject::isAbleToAttack()blocks only the object-target attack path. The turret recentering and idle-scan states callfriend_turnTowardsAngle()with no power check. An underpowered turret can therefore keep turning, which Issue#7does not allow.Apply the power check in both
Generals/andGeneralsMD/, because each variant has its ownTurretAI.cpp. A check in the shared turn helper would cover the recentering, idle-scan, and object-aim states in each variant. The body of that helper was not inspected, so no diff is given.
🟡 Minor · Allocate the rider's tint envelope before copying the carrier tint. · Drawable.h:317-318
Generals/Code/GameEngine/Include/GameClient/Drawable.h:317-318
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winAllocate the rider's tint envelope before copying the carrier tint.
When a rider is added after the carrier becomes underpowered, the containment path does not propagate the carrier's existing disabled state. The new rider
Drawablestarts with a null tint envelope. Each Overlord draw path then callssetColorTintEnvelope(...), but the setter skips the copy. The rider can therefore miss the dark underpowered tint.Update the shared setter in both game-variant headers.
Suggested fix
--- a/Generals/Code/GameEngine/Include/GameClient/Drawable.h +++ b/Generals/Code/GameEngine/Include/GameClient/Drawable.h @@ - void setColorTintEnvelope( const TintEnvelope* source ) { if (m_colorTintEnvelope && source) *m_colorTintEnvelope = *source; } + void setColorTintEnvelope( const TintEnvelope* source ) + { + if (source) + { + if (m_colorTintEnvelope == nullptr) + m_colorTintEnvelope = newInstance(TintEnvelope); + *m_colorTintEnvelope = *source; + } + } --- a/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h +++ b/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h @@ - void setColorTintEnvelope( const TintEnvelope* source ) { if (m_colorTintEnvelope && source) *m_colorTintEnvelope = *source; } + void setColorTintEnvelope( const TintEnvelope* source ) + { + if (source) + { + if (m_colorTintEnvelope == nullptr) + m_colorTintEnvelope = newInstance(TintEnvelope); + *m_colorTintEnvelope = *source; + } + }
🧹 Nitpick comments: 2
Generals/Code/GameEngine/Source/Common/RTS/Energy.cpp: 1
128-129: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winLimit zero-energy power updates to the affected object.
A zero-energy
KINDOF_POWEREDobject reachesaddConsumption(0)on both entry and exit. This call still scans all player objects throughPlayer::onPowerBrownOutChange, although the energy state does not change. Apply the current brownout state directly to the entering object. Remove the player-wide refresh from the zero-energy exit path.Suggested fix
#if !RETAIL_COMPATIBLE_CRC - else if (obj->isKindOf(KINDOF_POWERED)) - addConsumption(-energy); + else if (obj->isKindOf(KINDOF_POWERED)) { + if (hasSufficientPower()) + obj->clearDisabled(DISABLED_UNDERPOWERED); + else + obj->setDisabled(DISABLED_UNDERPOWERED); + } #endif @@ -#if !RETAIL_COMPATIBLE_CRC - else if (obj->isKindOf(KINDOF_POWERED)) - addConsumption(energy); -#endifGeneralsMD/Code/GameEngine/Source/Common/RTS/Energy.cpp: 1
147-148: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winAvoid the player-wide refresh for zero-energy powered objects.
When
energy == 0and the object isKINDOF_POWERED,addConsumption(0)still callsPlayer::onPowerBrownOutChange, which iterates the player's objects. The same unnecessary scan occurs when the object leaves.Synchronize only the entering object with
hasSufficientPower(). Remove the zero-energy exit callback. Apply the same change in Generals and GeneralsMD.Suggested fix
#if !RETAIL_COMPATIBLE_CRC - else if (obj->isKindOf(KINDOF_POWERED)) - addConsumption(-energy); + else if (obj->isKindOf(KINDOF_POWERED)) { + if (hasSufficientPower()) + obj->clearDisabled(DISABLED_UNDERPOWERED); + else + obj->setDisabled(DISABLED_UNDERPOWERED); + } #endif-#if !RETAIL_COMPATIBLE_CRC - else if (obj->isKindOf(KINDOF_POWERED)) - addConsumption(energy); -#endif
ℹ️ Review info
⚙️ Run configuration
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Organization UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
fb6eac9b-42e5-433f-891e-4a3f0baa40be
📒 Files selected for processing: 2
Generals/Code/GameEngine/Source/Common/RTS/Energy.cppGeneralsMD/Code/GameEngine/Source/Common/RTS/Energy.cpp
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
311a978 to
be68507
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
-
⚙️ Run configuration
-
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Organization UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
6db375ef-f6e8-4cf0-a696-c4e0e3f4452f
📒 Files selected for processing: 2
-
GeneralsMD/Code/GameEngine/Source/Common/RTS/Energy.cppGeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
-
8b39d33 to
cffe846
Compare
fb56f09 to
08d6abf
Compare
[Medium impact] The changes reach powered-object behavior and its drawable presentation. The PR should wait until newly created special-power modules respect the object's initial underpowered state. Findings
|
08d6abf to
773acdb
Compare
773acdb to
2adabd0
Compare
xezon
left a comment
There was a problem hiding this comment.
Is this meant to be merged with Rebase?
| else if( energy > 0 ) | ||
| addProduction( energy ); | ||
| #if !RETAIL_COMPATIBLE_CRC | ||
| // TheSuperHackers @tweak Add support for powered objects that consume no energy. |
There was a problem hiding this comment.
This looks odd because it is unpaired in objectLeavingInfluence and it does not match the previous intent of the function - see EA comment above the function.
Does this perhaps belong somewhere else?
Was this change needed to make it properly work, for example if a structure is captured and the player has not enough power?
There was a problem hiding this comment.
It could be added here, but it was deemed undesirable (#3574 (comment)).
There was a problem hiding this comment.
Github brings me nowhere good when clicking that link.
There was a problem hiding this comment.
How about now? I unresolved that particular conversation.
There was a problem hiding this comment.
It seems the branch was force pushed after that pull comment, so I am unable to understand the context of the comment, aka where it was placed before.
There was a problem hiding this comment.
I don't think this is relevant anymore now that the code's updated.
… built without sufficient power.
533d79f to
9f3a031
Compare
Yeah, I think that's for the best. |
| else if (!obj->isDisabledByType(DISABLED_UNDERPOWERED)) | ||
| { | ||
| obj->setDisabled(DISABLED_UNDERPOWERED); |
There was a problem hiding this comment.
Special powers charge without power
A zero-energy POWERED object created during a power shortage gets DISABLED_UNDERPOWERED before its modules exist. The call to pauseAllSpecialPowers(TRUE) therefore pauses nothing. SpecialPowerModule later starts its countdown without checking that flag. Restoring power cannot extend the countdown because m_pausedCount is still zero.
The special power charges during the outage and becomes available too soon after power returns. Apply the initial disabled state to the modules after creating them.
There was a problem hiding this comment.
This seems like a larger issue, though, quite possibly outside the scope of this PR. Is there any reason why this wouldn't already be an issue for powered objects that do require energy?
There was a problem hiding this comment.
Yes, that could already affect powered objects that consume energy. Their path goes through addConsumption(), which calls the owner’s onPowerBrownOutChange(!hasSufficientPower()); if that brownout handling disables a newly created object before its special-power modules are ready, the same missed-pause can occur.
The difference is only how the underpowered state is triggered: the new zero-energy branch calls setDisabled() directly, while consumers reach the brownout callback through energy accounting. That difference alone doesn’t establish that consumers avoid the timing issue. I didn’t verify the callback/module-construction ordering, so my previous comment was too narrowly attributed; this looks like a broader lifecycle question and may be outside this PR’s scope.
| // rather than needing to rely on Energy::objectLeavingInfluence. | ||
| if (isKindOf(KINDOF_POWERED)) | ||
| { | ||
| clearDisabled(DISABLED_UNDERPOWERED); |
There was a problem hiding this comment.
I think this one is new behavior. setTeam(nullptr) removes the object from its team before objectLeavingInfluence runs, so doPowerDisable never touched the dying object before. Now a powered structure that's destroyed or sold during low power plays the re-enabled sound through clearDisabled. What goes wrong if the flag is left set on a dying object? If something does, could it be cleared without the audio and tint side effects?
There was a problem hiding this comment.
I think this one is new behavior.
I don't think it is. Put a breakpoint on Energy::objectLeavingInfluence and sell a power plant. You'll see this call stack:
generalszh.exe!Energy::objectLeavingInfluence(Object * obj)
generalszh.exe!Object::friend_adjustPowerForPlayer(bool incoming)
generalszh.exe!Player::becomingTeamMember(Object * obj, bool yes)
generalszh.exe!Object::setOrRestoreTeam(Team * team, bool restoring)
generalszh.exe!Object::setTemporaryTeam(Team * team)
generalszh.exe!Object::setTeam(Team * team)
generalszh.exe!Object::~Object()
There was a problem hiding this comment.
Same goes for destroying an Avenger with and without ini modifications.
There was a problem hiding this comment.
The stack is right, but objectLeavingInfluence only changes the energy totals. The object is already removed from the team list in setOrRestoreTeam (Object.cpp:872-874), so doPowerDisable never reaches it. The new clearDisabled in the destructor is the first thing to touch the dying object, and it plays the re-enabled sound for structures and vehicles (Object.cpp:2283-2304). Is there a case where leaving the flag set on a deleted object causes a problem?
There was a problem hiding this comment.
The stack is right, but objectLeavingInfluence only changes the energy totals.
That's not what I'm seeing.
Should I have my LLM answer yours?
There was a problem hiding this comment.
lol sure why not. Mine says "You're right that it does more than adjust the totals - addProduction/addConsumption call onPowerBrownOutChange, which clears the flag on the remaining objects. It can't reach the dying one though. setOrRestoreTeam removes it from the team member list at Object.cpp:934 before calling becomingTeamMember, and Player::iterateObjects walks those lists. My line numbers were off too, sorry. If you break in doPowerDisable while selling a powered building during low power, is obj ever the building being sold?"
There was a problem hiding this comment.
Looks like you were right.
My line numbers were off too, sorry.
I wasn't seeing what you were seeing and your comment threw me off; sorry about that.
If you break in doPowerDisable while selling a powered building during low power, is obj ever the building being sold?"
No, I don't think so.
Looks like the disabled status is never cleaned up for powered objects, anyway, so this would be new behavior and probably unnecessary. I've removed it for now.
| // rather than needing to rely on Energy::objectLeavingInfluence. | ||
| if (isKindOf(KINDOF_POWERED)) | ||
| { | ||
| clearDisabled(DISABLED_UNDERPOWERED); |
There was a problem hiding this comment.
Despite the comment it is not clear to me why the flag needs unsetting like this.
There was a problem hiding this comment.
Removed. Would be new behavior and doesn't appear necessary.
| { | ||
| obj->clearDisabled(DISABLED_UNDERPOWERED); | ||
| } | ||
| else if (!obj->isDisabledByType(DISABLED_UNDERPOWERED)) |
There was a problem hiding this comment.
Maybe can omit this test? Does not hurt to just write again the same result.
There was a problem hiding this comment.
I added the test here, because there's no early return in Object::setDisabledUntil.
| { | ||
| obj->setDisabled(DISABLED_UNDERPOWERED); | ||
| } | ||
| } |
There was a problem hiding this comment.
Can do
void Object::doPowerDisable( bool disabling )
{
if( isKindOf(KINDOF_POWERED) )
{
if( disabling )
setDisabled( DISABLED_UNDERPOWERED ); //set disabled has a pauseAllSpecialPowers that prevents double pausing
else
clearDisabled( DISABLED_UNDERPOWERED );
}
}
static void Player::doPowerDisable( Object *obj, void *userData )
{
if (obj)
{
Bool disabling = *((Bool*)userData);
obj->doPowerDisable(&disabling);
}
}
void Energy::objectEnteringInfluence( Object *obj )
{
...
else
{
obj->doPowerDisable(!hasSufficientPower());
}
...
}
Or better flip to enablePower to avoid the double negative.
| else if( energy > 0 ) | ||
| addProduction( energy ); | ||
| #if !RETAIL_COMPATIBLE_CRC | ||
| // TheSuperHackers @tweak Add support for powered objects that consume no energy. |
There was a problem hiding this comment.
It seems the branch was force pushed after that pull comment, so I am unable to understand the context of the comment, aka where it was placed before.
There was a problem hiding this comment.
While we are at it, can we do an optimization here for
void Energy::addProduction(Int amt)
{
const Bool hadPower = hasSufficientPower();
m_energyProduction += amt;
if( m_owner == nullptr )
return;
const Bool hasPower = hasSufficientPower();
if( hasPower != hadPower )
{
m_owner->onPowerBrownOutChange( !hasPower );
}
}Maybe can be a follow up. Needs to be careful for Retail compatibility because originally it sets flags for new objects too and with the optimization it does not.
There was a problem hiding this comment.
Seems like a reasonable optimization but not according to the comment in Energy::addProduction:
// A repeated Brownout signal does nothing bad, and we need to handle more than just edge cases.
// Like low power, now even more low power, refresh disable.
I don't see the point of 'even more low power', though, do you?
There was a problem hiding this comment.
I think this is better suited for a separate change, though. Energy::addConsumption can be optimized similarly, but requires a bit larger change.
I've added a new issue / task for it.
There was a problem hiding this comment.
This condition can prevent setting the new DISABLED_UNDERPOWERED in objectEnteringInfluence, indicating that the handling inside objectEnteringInfluence is misplaced.
9f3a031 to
c7d557d
Compare
c7d557d to
daf2959
Compare
This PR makes 4 changes:
nullptrdereference inDrawable::setColorTintEnvelope(see issue). The USA Avenger laser turret now turns dark when underpowered (if set toPOWERED), but no low power icon because the unit itself is still responsive.Object::m_behaviorsfields as nullptr. Strictly unnecessary but would otherwise implicitly rely on the memory manager which by default zeroes out newly allocated memory.Object::pauseAllSpecialPowersneedsm_behaviorsto be initialized.See commits for clean diffs.
TODO: