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

[Discussion] Dirty Flags and Invalidation of Cache System #1788

Open
BraedonWooding opened this issue Mar 8, 2017 · 6 comments
Open

[Discussion] Dirty Flags and Invalidation of Cache System #1788

BraedonWooding opened this issue Mar 8, 2017 · 6 comments

Comments

@BraedonWooding
Copy link
Collaborator

Currently if you want to make something reliant on a setting but don't want to do a getSetting every second (aka cache the setting) then you have to edit that settings code to tell you to get the new setting (or do a timing system), this is just a simple example that hopefully illustrates the problem we have, this is a problem that is less relevant for settings (since well timing is at very least a semi-reasonable setting, and if you build the settings yourself you can implement them to trigger your stuff), BUT for a lot of other situations it isn't, this includes pathfinding, jobs...

So I thought what if we implemented a dirty flag system, it would essentially consist of a big enum (and most likely would actually not be an enum but be a similar system so modders could add items, or it would be a precomputer/compiled enum + postcomputed/runtime 'enums') then we could apply bitwise operators (& / |) to chain the enums this could allow users to just essentially do integer operations to check if their flag has been pressed (and we could even implement filters on our end and an array of actions or dictionary of filter to array of actions or whatever).

So I kind of want to gather some discussion on what people think about this? Most likely it would just be a call or xml/json/skon file to hookup to the flag system which would just be a single event (or us simulating that through an array of actions linked to dictionary or whatever) called something like 'InvalidateCache' (though as per with almost all our functions the name isn't important but that is a quite a good name especially for our side), and it would have a signature simply like void InvalidateCache(int cacheFlags). LUA has bitwise so it's not harder/easier to use C# (and actually would be easier with LUA since it has a little more support for runtime enums, since they are implemented as tables).

So wait how would you interface with this? Well I was thinking you would just tell the system that this flagged has changed (i.e. CacheFlags.SetFlag(Flags.SettingsChanged, true)), then the system would do an invalidation cache next frame (or maybe next second tick), but obviously you could also trigger an invalidation cache by maybe doing something like CacheFlags.TriggerInvalidationCache() (again these are just some placeholder names to get across meaning). Then it would go out and tell everything that has filtered to receive the values to update. Then after it'll flip back all the flags, most likely to avoid weird mismatches of updating flags, it will get the current flag values by & all the flags that are true, then it will turn them all to false, then it will do the call with that value calculated.

Anyways what do you guys think? This system could boost performance and cleanup code, it could also help things like pathfinding (maybe each room has an 'enum value' then when a change occurs in a room it dirties pathfinding for that room?).

@crazyfox55
Copy link

Why not just have an event for each setting? Then people can just register to those events. Anytime a setting changes it calls the event.

@BraedonWooding
Copy link
Collaborator Author

BraedonWooding commented Mar 8, 2017 via email

@crazyfox55
Copy link

I must be confusing something on where the settings are. As a side note wouldn't enum flags limit you to 32 settings? Also why would you need to cache a setting, does getting a setting really take that much computation?

@BraedonWooding
Copy link
Collaborator Author

BraedonWooding commented Mar 8, 2017 via email

@crazyfox55
Copy link

An enum mixed with bit array would hold plenty of information. 4 billion settings haha. I agree that it's needless computation and should be optimized out by better program flow.

With one big action that just sends a filter wouldn't that require a lot of checking on which bits are set?

@BraedonWooding
Copy link
Collaborator Author

BraedonWooding commented Mar 8, 2017 via email

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

No branches or pull requests

2 participants