bugfix(audiomanager): Fix dummy audio manager implementation for failing audio length script conditions in headless mode#2313
Conversation
Renamed dummy to 'MilesAudioManagerDummy'.
7751f9e to
477d80b
Compare
|
| Filename | Overview |
|---|---|
| Core/GameEngine/Include/Common/GameAudio.h | Removed AudioManagerDummy class from shared header, breaking Generals build which still references it |
| Core/GameEngineDevice/Include/MilesAudioDevice/MilesAudioManager.h | Added MilesAudioManagerDummy inheriting from MilesAudioManager to enable audio file length queries in headless mode; contains commented-out code for documentation |
| GeneralsMD/Code/GameEngineDevice/Include/Win32Device/Common/Win32GameEngine.h | Implemented createAudioManager(Bool headless) to return MilesAudioManagerDummy when headless, otherwise MilesAudioManager |
Class Diagram
%%{init: {'theme': 'neutral'}}%%
classDiagram
class AudioManager {
<<interface>>
+getFileLengthMS(string) Real
+openDevice() void
+closeDevice() void
+getDevice() void*
}
class MilesAudioManager {
-m_digitalHandle
+openDevice() void
+closeDevice() void
+getDevice() void*
+getFileLengthMS(string) Real
}
class MilesAudioManagerDummy {
+stopAudio() void
+pauseAudio() void
+isMusicPlaying() bool
Note: Inherits openDevice, closeDevice, getFileLengthMS from parent
}
class AudioManagerDummy_OLD {
<<removed>>
+getFileLengthMS() returns -1
}
AudioManager <|-- MilesAudioManager
MilesAudioManager <|-- MilesAudioManagerDummy
AudioManager <|.. AudioManagerDummy_OLD : "Before (removed)"
note for MilesAudioManagerDummy "Uses parent's Miles device initialization\nto query actual audio file lengths"
Last reviewed commit: 487a865
Core/GameEngineDevice/Include/MilesAudioDevice/MilesAudioManager.h
Outdated
Show resolved
Hide resolved
| //virtual void openDevice() {} | ||
| //virtual void closeDevice() {} | ||
| //virtual void* getDevice() { return nullptr; } |
There was a problem hiding this comment.
Remove commented-out code. The existing comment at line 335 already explains why these methods aren't overridden.
Prompt To Fix With AI
This is a comment left during a code review.
Path: Core/GameEngineDevice/Include/MilesAudioDevice/MilesAudioManager.h
Line: 351-353
Comment:
Remove commented-out code. The existing comment at line 335 already explains why these methods aren't overridden.
How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
I think there's value in providing a complete implementation of AudioManager. The functions that are commented out show clearly, more so than the comment, which functions are not overridden for this dummy implementation.
There was a problem hiding this comment.
That's a fair point. Commented-out method signatures can serve as inline documentation showing what's intentionally not overridden, especially in a class that overrides most other virtual methods.
However, this approach has a trade-off: it creates ambiguity about whether the code is temporarily disabled or intentionally documented. A clearer alternative would be to add these method names to the existing comment at line 335, making it explicit which methods are intentionally not overridden without leaving commented code.
For example:
// Methods intentionally not overridden: openDevice(), closeDevice(), getDevice()This gives you the same clarity without the "is this dead code?" question. But if you prefer the visual clarity of seeing the signatures, keeping them commented is also reasonable—just be aware that most linters and style guides flag commented-out code as a smell.
Your call on which approach better serves future maintainers.
| virtual Radar *createRadar(); ///< Factory for radar | ||
| virtual WebBrowser *createWebBrowser(); ///< Factory for embedded browser | ||
| virtual AudioManager *createAudioManager(); ///< Factory for audio device | ||
| virtual AudioManager *createAudioManager(Bool headless); ///< Factory for audio device |
There was a problem hiding this comment.
Maybe do Bool dummy ? Because it may not just be headless that want's to use a dummy in the future, aka the Dummy class should not care in what context it is used.
|
|
||
| }; | ||
|
|
||
| // TheSuperHackers @feature helmutbuhler 17/05/2025 AudioManager that does almost nothing. Used for Headless Mode. |
| @@ -77,7 +77,7 @@ class Win32GameEngine : public GameEngine | |||
| virtual NetworkInterface *createNetwork(); ///< Factory for the network | |||
| virtual Radar *createRadar(); ///< Factory for radar | |||
There was a problem hiding this comment.
Perhaps mirror the implemention for createRadar?
It currently also does TheGlobalData->m_headless ? NEW RadarDummy : createRadar()
| }; | ||
|
|
||
| // TheSuperHackers @feature helmutbuhler 17/05/2025 AudioManager that does almost nothing. Used for Headless Mode. | ||
| // @bugfix Caball009 16/02/2026 Scripts may require the actual audio file length to function properly. |
There was a problem hiding this comment.
Perhaps clarify that this is CRC relevant
Our current implementation of dummy audio manager is incomplete, because it cannot return the actual length of audio files. Replays will mismatch if they contain scripts that rely on this.
TODO: