Skip to content

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

@BraedonWooding

Description

@BraedonWooding

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?).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions