Skip to content
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

Improve addEvent when sharing events over multiple resources #2333

Merged

Conversation

Pieter-Dewachter
Copy link
Contributor

@Pieter-Dewachter Pieter-Dewachter commented Aug 31, 2021

Fixes #2448

When adding event handlers for a custom event in multiple resources, you have to use addEvent to make sure the event is already registered when adding the handler. The problem with the existing system happens in a situation where the first resource that used addEvent, is stopped. It is still possible that other resources had handlers for that specific event (and also used addEvent, for that matter), but still the event will never get triggered again. The reason is that the addEvent calls that came after the initial one, immediately returned false and didn't actually do anything.

This PR changes that behaviour, keeping a list of all resources that added a certain event and only removing an event when all resources that used addEvent are stopped. For security reasons, addEvent will return false and not do anything in case the allowRemoteTrigger argument would have been altered between different calls to the function.

Small note: I noticed that the strArguments member of SEvent is never used for anything, perhaps it could be an idea to clean this and remove the unused member?

Client/mods/deathmatch/logic/CEvents.cpp Outdated Show resolved Hide resolved
Client/mods/deathmatch/logic/CEvents.h Outdated Show resolved Hide resolved
Server/mods/deathmatch/logic/CEvents.cpp Outdated Show resolved Hide resolved
… won't be that many resources and memory layout is preferred over raw speed
@patrikjuvonen patrikjuvonen added the enhancement New feature or request label Sep 5, 2021
@Pieter-Dewachter
Copy link
Contributor Author

Totally forgot to respond here, I have changed my implementation according to your suggestions.

Copy link
Member

@Lpsd Lpsd left a comment

Choose a reason for hiding this comment

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

Looks good, tested and working as expected :shipit:

@Lpsd Lpsd merged commit f3811cb into multitheftauto:master Dec 26, 2021
@Pieter-Dewachter Pieter-Dewachter deleted the feature/addevent_multires branch December 30, 2021 17:14
@patrikjuvonen patrikjuvonen added this to the Next Release (1.6.0) milestone Aug 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

triggerEvent/addEvent issue
5 participants