Commit graph

163 commits

Author SHA1 Message Date
Ralph Sennhauser
0c0552a428
Replace M_PI with C++ numbers
C++20 added π (pi) to the standard, replace the C macro globally.

Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2026-06-04 20:29:48 +02:00
phosit
e2ed4afe00
SoundManager: reintroduce manual memory management
This reverts commit 94c907342a.

It introduced multiple errors and is to big to find the actual errors.

Fixes: #8342
Fixes: #8426
2025-10-13 20:42:32 +02:00
trompetin17
94c907342a
SoundManager: Replace manual memory with unorderedmap
Remove manual memory management throughout the SoundManager subsystem
in favor of unorderedmap.

Key changes:
- Eliminate manual new/delete calls and potential memory leaks
- Update all sound item classes to use SoundManager factory
- Modernize resource management in OggData and related components
- Ensure exception-safe memory handling across the audio pipeline

This refactoring improves code maintainability, reduces crash risk from
memory errors, and aligns with modern C++ best practices.
2025-08-25 09:45:14 -05:00
Ralph Sennhauser
2cedb48de2
Remove custom span and use std::span
With C++20 the custom container PS:span, which was a backport of
std::span is no longer needed.

Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-08-24 11:09:57 +02:00
Ralph Sennhauser
5b5f678e3f
Fix some includes all over the place
Make include-what-you-use happy with some files in source and fix what
needs to be fixed.

Add markers to precompiled.h header includes to avoid
include-what-you-use wanting them to be removed.

Ref: #8086
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-08-14 20:15:30 +02:00
Ralph Sennhauser
3647921bed
Fix some includes all over the place
Make include-what-you-use happy with some files in source and fix what
needs to be fixed.

Ref: #8086
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-08-13 19:38:21 +02:00
Ralph Sennhauser
827116cd35
Fix issues pointed out by cppcheck
For the memleak warning actually wx will free it for us, so just
suppress the warning.

```
source/soundmanager/data/SoundData.cpp:48:29: error: Iterators of different containers 'CSoundData::sSoundData' and 'sSoundData' are used together. [mismatchingContainers]
  if ((itemFind = CSoundData::sSoundData.find( theData->GetFileName().string() )) != sSoundData.end())
                            ^
source/soundmanager/data/SoundData.cpp:62:28: error: Iterators of different containers 'CSoundData::sSoundData' and 'sSoundData' are used together. [mismatchingContainers]
 if ((itemFind = CSoundData::sSoundData.find(itemPath.string())) != sSoundData.end())
                           ^
source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Terrain/Terrain.cpp:145:3: error: Memory leak: buf [memleak]
  }
  ^
```

Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-08-13 17:09:36 +02:00
phosit
eb3f0166f8 Prefer [[maybe_unused]] over UNUSED2
`[[maybe_unused]]` is in the C++ standard.
2025-07-28 13:16:37 +02:00
phosit
5be02743fa Don't use UNUSED2 on always unused variables
Not introducing a variable enforces that the variable is not used.
`UNUSED2` on the other hand is used to silence the warning.
2025-07-28 13:16:37 +02:00
trompetin17
8ed40553c8
Update SetFormatAndFreq method to use ALenum type in format parameter 2025-07-22 08:41:03 -05:00
trompetin17
019514a9cf
Refactor COggData class: make destructor non-virtual, adjust method declarations for consistency 2025-07-22 08:41:02 -05:00
trompetin17
000304a402
Rename m_BuffersUsed to m_BuffersCount for consistency in COggData class 2025-07-22 08:41:02 -05:00
trompetin17
ef28d5222a
Use 'using' instead of 'typedef' for OggStreamPtr definition 2025-07-22 08:41:01 -05:00
trompetin17
c40aada404
Rename atFileEOF to AtFileEOF for consistency in Ogg classes 2025-07-22 08:41:01 -05:00
trompetin17
586d02838a
Refactor Ogg buffer logic to use span and vector
Modernized COggData::FetchDataIntoBuffer and OggStream
interface:

- Replaced raw buffer pointer with std::vector<u8> in COggData
- Updated GetNextChunk to use PS::span<u8>
- Removed manual new/delete and memset usage
- Replaced long with ALsizei for m_Frequency to match OpenAL API
- Simplified type usage with size_t where appropriate
- Eliminated unnecessary casting and improved code clarity

These changes improve safety, readability, and bring the
code closer to modern C++ standards.
2025-07-22 08:41:00 -05:00
trompetin17
325bedcf3f
Use std::array for OggData buffer handling
Replaced the raw C array for m_Buffer with std::array
to improve bounds safety and code clarity.

- Used .data() and .at() for buffer access
- Added check for bufferCount exceeding OGG_MAX_BUFFER_COUNT
- Left FetchDataIntoBuffer unchanged to avoid breaking external usage
  (e.g. CStreamItem)

This refactor improves safety while keeping external API stable.
2025-07-22 08:41:00 -05:00
trompetin17
21f26455f5
Decouple buffer config from SoundManager
OggData now manages its own buffer size and count directly,
instead of relying on SoundManager to provide those values.

- Removed unused GetBufferCount() and GetBufferSize()
- Use default values for buffer size and count in OggData
- Documented buffer settings for clarity

This change centralizes control in OggData and improves encapsulation.
2025-07-22 08:40:59 -05:00
trompetin17
50dbd5ca2d
Remove unused AddDataBuffer declaration
The AddDataBuffer method was declared but never defined
in any implementation of CSoundData or its derived classes.

It is also not used anywhere in the codebase, so this
commit removes the dead declaration to clean up the
interface.
2025-07-22 08:40:59 -05:00
trompetin17
95fc9bd2ed
Standardize OggData fields and variable naming
This commit renames ogg to m_OggStreamPtr for clarity and consistency
with naming conventions. Additionally, it moves the m_Format and
m_Frequency fields to the private section to ensure proper
encapsulation.

Local variables like pcmout have been renamed to PCMOut to match style
conventions, and all member fields now follow a consistent m_ prefix
style, placed at the end of the class definition for clarity.

These changes help improve code readability, enforce privacy, and align
with the rest of the codebase's naming standards.
2025-07-22 08:40:58 -05:00
trompetin17
e95829494c
Ensure brace initialization variables in OggData
This commit updates the OggData-related classes to use uniform brace
initialization ({}) for member variables where applicable. Brace
initialization improves clarity and prevents potential narrowing
conversions or unintended behavior caused by default constructor
ambiguity.

This change improves consistency and aligns with modern C++ best
practices, especially in C++11 and later where brace initialization is
recommended for safer initialization semantics.
2025-07-22 08:40:57 -05:00
trompetin17
e97292430d
Remove manual Close method from OggStream
The OggStream interface no longer needs the Close() method.
OpenOggNonstream returns a smart pointer (OggStreamPtr),
so resource cleanup is automatically handled by the destructor.

OggStreamImpl now calls ov_clear in its destructor, making
manual cleanup unnecessary. This commit removes the Close()
method from the interface and its implementation.
2025-07-22 08:40:48 -05:00
Ralph Sennhauser
8398f1baf4
Fix some includes in source/graphics
Make include-what-you-use happy with some files in source/graphics and
fix what needs to be fixed.

Ref: #8086
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-07-20 17:28:48 +02:00
Ralph Sennhauser
ad3f6e3119
Dissolve external_libraries/openal.h
This header was used to overcome macos openal vs openal-soft header name
difference, for the migration to openal 1.1 and to pass arguments to the
linker on windows in the past. None of this is used anymore so dissolve
the header.

Also fix related headers so one can run include-what-you-use on the
changed files.

Ref: #8086
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-07-08 19:33:36 +02:00
phosit
891908b801 Remove UNUSED
The `UNUSED` macro is used to mark a variable as unused but with a name.
Those usages are replaced with comments so that `UNUSED` can be removed.

https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-unused
2025-06-26 17:25:05 +02:00
trompetin17
0ebcc45237
Refactor GetNextChunk for clarity and safety
Replaces the for(;;) loop in GetNextChunk with a clearer while
(bytesRead < size) loop for better readability and intent.

Other improvements:
- Uses constexpr for constant audio format parameters
- Replaces C-style cast with reinterpret_cast
- Ensures consistent use of static_cast for type conversions
- Improves comment formatting

This refactor maintains the original logic while aligning with modern
C++ best practices.
2025-06-20 10:49:23 -05:00
trompetin17
0396d67d26
Apply consistent naming to member variables in ogg.cpp
Renames local variables in the class to follow the member naming
convention using the m_ prefix (e.g., m_Adapter, m_VF, m_FileEOF).
2025-06-20 10:49:16 -05:00
trompetin17
6b9652050c
Use std::copy_n in VorbisBufferAdapter::Read
Replaces a raw memcpy call with std::copy_n in VorbisBufferAdapter::Read
for improved type safety and readability. This ensures cleaner buffer
copying using standard C++ algorithms, avoiding manual pointer
arithmetic on void*.

The change is functionally equivalent but aligns better with modern
C++17 practices.
2025-06-20 09:04:09 -05:00
trompetin17
1d20adc3b9
Ensure brace initialization for member variables in Ogg classes
This commit updates the Ogg-related classes to use uniform brace
initialization ({}) for member variables where applicable. Brace
initialization improves clarity and prevents potential narrowing
conversions or unintended behavior caused by default constructor
ambiguity.

This change improves consistency and aligns with modern C++ best
practices, especially in C++11 and later where brace initialization is
recommended for safer initialization semantics.
2025-06-20 09:04:01 -05:00
trompetin17
2ae95d3c49
Refactor OggStreamImpl to use exceptions for error handling
Introduce a new `Open` method in `OggStreamImpl` that encapsulates the
logic for opening Ogg Vorbis files. This method replaces the previous
`Open` method and utilizes `std::runtime_error` for error reporting
instead of returning error codes. The constructor has been updated to
call this new method, ensuring files are opened upon instantiation. The
changes streamline the code and improve error handling.
2025-06-20 08:51:39 -05:00
trompetin17
336ff333ed
Remove unused OpenOggStream method
OpenOggStream was previously used to stream Ogg files directly from the
file system. It operated on raw file paths (OsPath) and assumed
uncompressed, unarchived files, which made it unsuitable for working
with files inside archives or VFS layers.

However, its usage has been fully replaced by OpenOggNonstream, which:
- Reads the entire file into memory (non-streaming),
- Works with virtual file systems (VFS),
- Supports both archived and compressed assets,

Is already used consistently across debug and release builds.

There are no remaining references to OpenOggStream in the codebase, so
this commit removes the unused function and its associated logic.
2025-06-20 08:41:39 -05:00
phosit
d9795d29fe Remove the name of some unused arguments
Remove some usage of the `UNUSED` macro. Remove only those cases where
the names can be deduced from their type.

https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-unused
2025-06-18 12:49:59 +02:00
Dunedan
8482f25800
Fix a bunch of spelling mistakes
This fixes a bunch of spelling mistakes found in user facing strings.

Fixes #7716
2025-04-11 06:24:32 +02:00
phosit
1a8757660f Get config values without using return parameters
Many temporaries can be removed.
2025-04-09 12:51:21 +02:00
Lancelot de Ferrière
fba5a23aad Fix sounds playing in the wrong places of the map
Introduced by a typo in f8afd49ae1.
Fixes #7345, reported by wowgetoffyourcellphone
2025-01-04 11:53:26 +01:00
scuti
a81c38bab9 Skip playing audio of corrupted files.
Prints a warning instead of crashing.

Fixes #7150
2024-12-26 16:14:38 +01:00
Ralph Sennhauser
49507c04e0
Make failed audio device query non fatal
Querring the audio device name may fail. The name is only used for the
sake of logging it for debugging. Avoid querry failure to be fatal and
insted just log the issue.

Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2024-11-21 15:08:04 +01:00
Ralph Sennhauser
bb1910ff4c
Fix segfault with openal-1.24.0
With version 1.24.0 alcIsExtensionPresent() has dropped case insensitive
string comparison [1], use upper case names.

The internal strings are uppercase since the first git commit importing
openal 17 years ago.

[1] upstream commit 785f794141d62a4c308db26aa4a4819e6a92525e

Report: https://wildfiregames.com/forum/topic/125203-crash-on-start-due-to-soundmanager
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2024-11-21 15:08:03 +01:00
phosit
f8afd49ae1 Return by value from CCamera::GetScreenCoordinates
Pack the two `float`s in to a `CVector2D`.
Rename some variables to not use underscore.
2024-11-17 20:27:58 +01:00
phosit
256152df6d Add CXeromycesEngine
This way the destructor can be used for clean up and `Singleton` can be
used.
2024-11-17 18:03:49 +01:00
phosit
9c6f2e592e Don't check memory allocation made using new
Refs: #5288

Patch By: @animus
Accepted By: @phosit
Comments By: @vladislavbelov
Differential Revision: https://code.wildfiregames.com/D5234
This was SVN commit r28014.
2024-01-21 14:29:30 +00:00
vladislavbelov
ffc4a56b9f Revert non-ASCII characters from source and configuration files introduced in 157c6af18e.
Fixes #6846

Differential Revision: https://code.wildfiregames.com/D5185
This was SVN commit r27965.
2023-12-03 00:30:12 +00:00
bb
157c6af18e Make the space in 0 A.D. non-breaking throughout the codebase.
Avoid cases of filenames
Update years in terms and other legal(ish) documents
Don't update years in license headers, since change is not meaningful

Will add linter rule in seperate commit

Happy recompiling everyone!

Original Patch By: Nescio
Comment By: Gallaecio
Differential Revision: D2620
This was SVN commit r27786.
2023-07-27 20:54:46 +00:00
vladislavbelov
04bd96cee0 Moves uniform and texture binding to CDeviceCommandContext.
Tested By: Langbart
Differential Revision: https://code.wildfiregames.com/D4631
This was SVN commit r26848.
2022-05-02 20:57:22 +00:00
vladislavbelov
d8d736f0eb Allows tex clients decide how to handle invalid textures instead of assertions. Fixes #6436
This was SVN commit r26783.
2022-04-12 17:39:05 +00:00
vladislavbelov
31a6ffdd3a Removes mentions of legacy and unused GL calls, unifies AsFloatArray.
This was SVN commit r25961.
2021-10-11 12:39:01 +00:00
vladislavbelov
96708cc6a5 Adds header for forward declarations of CStr.
This was SVN commit r25905.
2021-09-09 17:39:08 +00:00
vladislavbelov
a5c82a4ef6 Removes unused forward declarations of class and struct.
This was SVN commit r25903.
2021-09-08 19:43:01 +00:00
wraitii
863ef0f88a Tweak sound distance attenuation & add configurability
Following D3108 / 876f6d5e50, sounds are attenuated by their actual
distance. However, as noted by players on A24, the dropoff is stark and,
when zoomed out, can easily result in not hearing things that are
happening in the middle of the screen.

The new default settings almost double the max-range, change the minimum
range to have greater dynamic range, and reduce the stereo depth
slightly to better match the default camera FOV.

These are stored per sound-grounp, possibly allowing future tweaks on a
per-soundgroup basis, and are configurable.

Tested by: Imarok
Discussed over mail with: Samulis, Porru

Differential Revision: https://code.wildfiregames.com/D3612
This was SVN commit r25547.
2021-05-25 06:19:25 +00:00
vladislavbelov
babfd913fb Adds std namespace to shared_ptr usages in gui and sound.
This was SVN commit r25526.
2021-05-22 19:23:03 +00:00
wraitii
cdd75deafb XMB Improvements, parse JS into XMB, make strings more efficient.
XMB format is bumped to 4, invalidating all cached files. The
differences are:
 - element/attribute names are stored after the elements themselves, and
not before. This allows writing XMB data in one pass instead of two.
 - names themselves becomes offsets (instead of arbitrary integers),
making getting the string from the int name much more efficient.

XMBFile is renamed to XMBData to clarify that it does not, in fact,
refer to a file on disk.

XMBData::GetElementString is also changed to return a const char*, thus
not creating an std::string. A string_view version is added where
convenient.

The XML->XMB and JS->XMB conversion functions and the corresponding
storage are moved to `ps/XMB`, since that format doesn't particularly
relate to XML. CXeromyces becomes lighter and more focused as a result.
The XML->XMB conversion also benefits from the above streamlining.

Note that in a few cases, string_view gets printed to CLogger via
data(), which is generally not legal, but we know that the strings are
null-terminated here. Our libfmt (version 4) doesn't support
string_view, that would be v5.

Differential Revision: https://code.wildfiregames.com/D3909
This was SVN commit r25375.
2021-05-04 13:02:34 +00:00