carxt / JohnnyGuitarNVSE

JohnnyGuitar is a library extending NVSE's functionality. Please check the README provided for more information.
GNU Lesser General Public License v2.1
55 stars 9 forks source link

Make Event Filters easier to make, and more. #19

Closed Demorome closed 3 years ago

Demorome commented 3 years ago

New filters should be easier to make now, thanks to an abuse of std::variant and std::visit in order to support multiple variable types. See CustomEventFilters.h for what making a new filter looks like.

While RefIDs are currently the only elements that fully utilize the RefIDSet type by having more than 1 elem if a formlist is passed (elements from that get dumped into the set), the other typed sets could easily find use if arrays were to be passed as filters. For example, an array of formType int codes could be used to declare that the event should only run for X, Y and Z formTypes.

Every event is now templated with the filter they'll be using, in order to enforce passing the right amount and type of arguments. This also let me remove the numMaxFilters field from the EventInformation class. I have refactored every JG event to use this system. A downside to this is that more code will have to be generated upon compilation, increasing the DLL size. I have no idea how much of an issue this'll be, but by comparing the nexus JG .dll to the .dll I have, it has increased by ~20kb.

I've also fixed EventInformation::RemoveEvent not mass-unregistering UDFs when called with default values, See examples on Discord. I did this by calling an alternative filter comparison function that skips checking for equality for default-value filters.

I've added the eFlag_FlushOnLoad flag, in order to make flush-on-load events easier to maintain (don't have to go look elsewhere to see if the event is being flushed, just check the declaration). A drawback is that every event will need to be looped over on load, but it's already being looped over every frame in kMessage_MainGameLoop so it shouldn't matter much.

I have also made RegisterEvent return a bool, though that's unused for now. Perhaps in the future, RemoveEvent could return how many UDFs were cleared. I think that would be handy info for the JG event functions to return.

In order to do these changes, I also got rid of the JGCreate/RemoveEvent export. Not sure if it could be added back later. But if it really requires working with raw data pointers, I'd rather just port this whole code entirely rather than use the exports so I can get some type safety and convenience.

carxt commented 3 years ago

Had to revert for the meantime, will give proper feedback.