This Week in Fyrox #11

Fyrox is an open-source (opens new window) Rust game engine with lots of out-of-box game-ready features and a full-featured editor. This week was mostly dedicated to adding some new features and fixing existing functionality.

# Reflection Refactoring

Main downside of the current reflection system in the engine is that it does not support reflection of types with interior mutability. You simply cannot "inspect" fields of a struct/enum of type with interior mutability (such as Mutex<T>, RwLock<T>, RefCell<T>, Arc<Mutex<T>>, etc.), because anything that is located inside these types require to hold some kind of lock while accessing internals (MutexGuard<T> in case of Mutex, Ref<T>/RefMut<T> in case of RefCell and so on). Current API (opens new window) has lots of methods that returns references and such API structure is incompatible with types with interior mutability, because it does not allow you to hold a lock while accessing internals.

Interior mutability support in reflection system is crucial for animation system of the engine. Its main usage is to animate numeric parameters of renderer materials. This ability allows you change shader uniforms via standard animation pipeline.

Initial support for interior mutability was added (opens new window), it is pretty big and breaking change, so it will require some additional testing before merging. The API of Reflect trait was changed completely (opens new window). Now, instead of returning references immediately, every function that previously returned references now has additional parameter. This parameter is a reference to a closure that allows you to do something with a reference to inner value. Such approach allows to hold mutex lock (and analogues) while doing something with data.

# Determinism for Particle Systems

Previously, particle systems used global pseudo-random numbers generator (PRNG), which resulted in non-deterministic behavior. Now, each instance of particle system has its own PRNG and saves its seed, which makes behaviour of particle systems deterministic. It is even possible to rewind particle systems to a particle time and the result will always be the same (until PRNG implementation is not changed).

# Color Gradient Editor

For a long time there was no property editor for Color Over Lifetime field of particle systems. The type of this field is ColorGradient which allows you to define a set of color points and fetch intermediate values at any position at the gradient. Now, the editor has property editor for ColorGradient and it works like so:

# Other

It is now possible to rewind particle systems during preview mode - it removes all generated particles and starts generation over.

Engine's performance statistics now correctly show the time spent in scripts and plugins, allowing you to measure performance of your game.

Previously, ABSM editor had a bug where activation of a state/transition on one layer was shown on the layer being edited, causing confusion while debugging ABSMs.

# Full List of Changes in Random Order

  • Reflection system refactoring to support types with interior mutability.
  • Compound conditions (computational graph) for ABSM transitions.
  • Fixed incorrect activation of transition/states during preview mode in ABSM editor.
  • Improved ColorGradient API.
  • Simplified color_over_lifetime field usage in particle systems (breaking change).
  • Property editor for ColorGradient
  • Improved engine's performance statistics.
  • Fixed rare panic in FormattedText.
  • Fixed ParticleSystem::clear_particles - it was working incorrectly with emitters that have resurrect_particles == false
  • Ability to "rewind" particle systems in particle system control panel.
  • Fixed preview mode for particle systems.
  • Determinism for particle systems.
  • Ability to rewind particle systems to a particular time.
Fyrox Engine 2019 - 2024