Skip to content

Mutation

Jirka Dell'Oro-Friedl edited this page Apr 5, 2022 · 8 revisions

Concept

FUDGE consist of several modules like the core, user interface, network etc. and generalized functionality like animation and serialization. In order for these parts to work with the multitude of classes defined and yet to come, FUDGE uses a generic process to transfer information from and to objects that inherit from a common superclass. The common structure for this transfer is called mutator.

Mutable

Mutable is a common superclass for many classes of FUDGE. It provides the functionality to create mutators from an instance of the subclass, tailor a mutator for specific use cases like animation or user interface control, mutate the instance according to a given mutator and update a given mutator according to the current values of the instance properties.

Mutator

A mutator is just a simple associative array without custom methods that may completely or partially represent an instance of a FUDGE-class.

Standard Mutator

Mutable creates a standard mutator by

  1. copying all the properties of an instance and their values into a new mutator, omitting all methods and all objects that are themselves not subclasses of Mutable,
  2. calling the reduceMutator method of the instance defined in the subclass that strips away unnecessary properties,
  3. replacing the references to nested mutables with their mutators recursively, yielding an object containing a nested structure of properties of simple types representing the original Mutable instance or parts thereof.

Custom Mutator

A subclass may overwrite the creation of a mutator entirely yielding an object that does not reflect the structure of the instance, but is more efficient or suitable to use. For example Matrix4x4 is basically just an array of 16 numbers, but its mutator has the properties translation, rotation and scale in order to be human readable.

Mutation

A mutable may mutate to reflect the contents of a given mutator. Instead of just copying the values into its own properties, it may check them first for validity or process required calculation. The standard mutation recurs through nested mutables.

Mutation of Graphs and GraphInstances

Graphs and their instances listen to the mutate event and share mutation. That means, mutating a graph reflects the mutation to all instances, and mutating an instance reflects the mutation to the graph and from there again to all instances. Directly manipulating a property does not reflect though, since the mutation system does not kick in, creating various options for creators to deal with graphs, their instances and the relationship between both. Suppress reflection alltogether by attaching an active ComponentGraphFilter to the root node.

Clone this wiki locally