Skip to content

Data Processing

Popax21 edited this page Aug 31, 2022 · 1 revision

Procedurline handles data processing using so called data processors, which are classes implementing I(Async)DataProcessor<T, I, D>. A data processor takes a target (the thing the data belongs to) of type T, a data identifier (what of the target's data is modified) of type I, and the data itself, of type D. It can then modify said data if it wishes to do so. If they didn't modify any data, implementations should return false from their ProcessData(Async) method to allow calling code to potentially implement optimizations, otherwise they should return true.

As an example, for sprite animation processing, the "target" would be a Monocle.Sprite instance, the "data ID" would be the animation ID, and the data would be either a Sprite.Animation, or a SpriteAnimationData instance, depending on where in the pipeline the processor attaches. Some processors, for example, don't have a data ID, and as such that generic type argument is effectively NOP-ed out by making it be VoidBox.

To allow for the caching of processed data, I(Async)DataProcessor<T, I, D> extends IScopeRegistrar<T>, which allows cache-aware code to ask processors to register data scopes on a provided scope key which encapsulate external factors that could influence the way they process data. This key is also passed to the ProcessData(Async) method, or null if none were registered. Processors must act in a way which is consistent with the scopes it registered on a key, if that key was given to ProcessData(Async) - this means that all data with the same scope key and data ID must be processed in the exact same way.

Asynchronous data processors (IAsyncDataProcessor<T, I, D>) allow for longer running processor tasks, which can also efficiently wait on external sources. They don't finish execution immediately, and instead return a Task<bool>. Additionally, it's possible to provide a CancellationToken to cancel them once they started processing. Once that token gets cancelled, the return value or any exceptions thrown by the processor are ignored.

Procedurline ships with a selection of built in processor which can be chained together to easily achieve more complicated effects. See Data Utils for a list.

Clone this wiki locally