-
-
Notifications
You must be signed in to change notification settings - Fork 438
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
Add element/table ignore arg to getElementsWithinRange
#3871
base: master
Are you sure you want to change the base?
Add element/table ignore arg to getElementsWithinRange
#3871
Conversation
Why do we need that? You can simply filter the original output in lua and use optimal algorithms and structures for that. |
I don't like ad hoc solutions, instead universal solution should be created. Make new struct/class called "ElementFilter", make support for it in argument parser. then change function signature and logic inside to: CClientEntityResult CLuaElementDefs::GetElementsWithinRange(CVector pos, float radius, std::optional<std::string> type, std::optional<unsigned short> interior,
std::optional<unsigned short> dimension)
std::optional<unsigned short> dimension, ElementFilter filter){
...
- if (std::find(ignoreEntities.begin(), ignoreEntities.end(), pElement) != ignoreEntities.end())
- return true;
+ return filter.Matches(pElement);
} Now everyone can use "element filter"easily everywhere, old functions should be updated too. It will be easy to add new filters in future and in general maintain it. Lua equivalent of filter can be for now simple: {
ignoredElements = {elementA, elementB, ... }
} but in future can be easily extended by changing code in one place. |
Sure, you can. But having extra ignoreElement would spare you from additional if nesting in loop, or using additional function just for the sake of skipping element(s).
That's not true.
Even after this change, it still will be simple. Adding another argument won't get it nowhere near to level of processLineOfSight/isLineOfSightClear (which also allows you to ignore specific element) |
Also what about memory? If there is a lot of elements the that may also affect performance. IgnoreElement would be very useful here |
This function doesn't produce much memory, and you transfer from LuaVM the same number of elements or more that you filter. You cannot expect a performance boost here. However, the performance will always be terrible for some sets of filtered elements.
This is not a reason to make API complicated. We don't need to add |
First of all, if you have big server all of those extra allocations to later literraly throw away entire table slow down the server. Instead of array, all simillar functions should return iterator that doesn't allocate any memory. |
In this case, you still need to allocate your
It sounds interesting. It would be nice to have a performance check. |
Added new arg to the function clientside and serverside. The
ignore
parameter can be an element or a table of elements.Fixes #3869
Tested and ready.