-
-
Notifications
You must be signed in to change notification settings - Fork 535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch AUDIO_SAMPLE
and RES_TYPE/RES_DATA
structures to std::list
#3608
Merged
past-due
merged 9 commits into
Warzone2100:master
from
ManManson:psnext_remove_resources_and_sound
Jan 24, 2024
Merged
Switch AUDIO_SAMPLE
and RES_TYPE/RES_DATA
structures to std::list
#3608
past-due
merged 9 commits into
Warzone2100:master
from
ManManson:psnext_remove_resources_and_sound
Jan 24, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
So that the utility is accessible in base libraries Signed-off-by: Pavel Solodovnikov <[email protected]>
Replace `malloc/free` by `new/delete` to allocate `RES_TYPE` instances, otherwise we'll have problems when replacing `psRes` pointer by a C++ container (e.g. `std::list`), because `malloc` doesn't know anything about C++ constructors. Signed-off-by: Pavel Solodovnikov <[email protected]>
…iterate` Use a compile-time helper with some SFINAE tricks to allow passing callables which take an iterator instead of a pointer type as the argument. This can be quite convenient when one needs to erase from or insert into the list being iterated directly inside the handler's body, avoiding additional lookups to obtain an iterator to the current element. The SFINAE function signature checks are performed using the following trick: std::is_convertible<Callable, std::function<Sig>::value This is based on the ability of raw function pointers and lambda expressions to be converted to the `std::function` type with a matching signature. Paired with a `std::enable_if_t`, this allows to easily compile-time-choose the correct overload of the `Invoke` helper function, which would call the handler and pass the correct argument to it. Signed-off-by: Pavel Solodovnikov <[email protected]>
Change `RES_TYPE::psRes` to use `std::list` instead of a C-style intrusive list. Also, remove `RES_DATA::psNext` pointer as it's not needed anymore. Signed-off-by: Pavel Solodovnikov <[email protected]>
Also, remove now unused `psNext` member field from `RES_TYPE`. Signed-off-by: Pavel Solodovnikov <[email protected]>
Also, remove `psPrev` and `psNext` pointers from `AUDIO_SAMPLE`. Signed-off-by: Pavel Solodovnikov <[email protected]>
This is sort of a hack/workaround to prevent crashes related to `TargetMissing_` static instance of `BASE_OBJECT` defined in the `multibot.cpp`. By the time this object gets destroyed, audio-related global vars are already destroyed and this object references one of them in its destructor via `audio_RemoveObj(this)` call. This should be addressed later, of course. But still, not crashing is better than crashing and early return is never bad. Signed-off-by: Pavel Solodovnikov <[email protected]>
Signed-off-by: Pavel Solodovnikov <[email protected]>
These compilers are more strict than MSVC, so fix the compilation errors coming from the linux build. Signed-off-by: Pavel Solodovnikov <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The changeset does the following things:
mutating_list_iterate
utility function to a separate headerobject_list_iteration.h
and move it up the project hierarchy, so that it's accessible inlib/framework
andlib/sound
.mutating_list_iterate
to be able to accept lambdas which take an iterator, this is used in some places to efficiently erase from list inside of the handler itself.psNext
andpsPrev
pointers fromAUDIO_SAMPLE
,RES_TYPE
andRES_DATA
structures, also convert global listsg_psSampleList
andg_psSampleQueue
tostd::list<AUDIO_SAMPLE*>
.After these changes, there are still some places in WZ code base, which use C-style lists, but it's not much anymore and should be easy to clear it up in a follow up PR a bit later.