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

Script hooks fixes and script hook manager #192

Merged
merged 2 commits into from
Jul 23, 2022

Conversation

samisalreadytaken
Copy link

The first commit simplifies the purpose of IScriptVM::LookupHookFunction() by merging it with IScriptVM::ScopeIsHooked() and making it only return the hook function instead of also calling LookupFunction(), fixes ScriptHook_t::Call() always returning true even when callbacks fail, gives the new hook system priority over legacy support by checking the new system before function name which reduces the amount of unnecessary script lookup on each hook call.

When I wrote the Hooks functions I did not expect it to be added as is - it was more of an example; I've re-structured the storage to store event names first, which reduces the amount of tables created, and also swapped the parameters of Hooks.Remove(), as eventname, context is more natural and in-line with the Add() function.

The second commit implements CScriptHookManager which caches script hook events and the hook function in C++ to reduce 3 consecutive script function lookup on each ScriptHook_t::CanRunInScope() check - which is run for each hook, often every frame on every entity - to 2 RB tree lookups on C++ and a legacy script function lookup fallback. Though I'm not entirely sure if CUtlMap is the right container to use for this purpose.

I highly suggest adding a flag on ScriptHook_t (or creating a legacy hook class) for all hooks implemented before mapbase 7.0 that enables the legacy fallback. Otherwise all future unused hooks will keep polling the script VM for a hook function.


PR Checklist

  • My PR follows all guidelines in the CONTRIBUTING.md file
  • My PR targets a develop branch OR targets another branch with a specific goal in mind

@Blixibon Blixibon merged commit 1f4d5b4 into mapbase-source:develop Jul 23, 2022
VDeltaGabriel pushed a commit to Project-P2009/p2009_sdk that referenced this pull request Apr 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants