bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Increase type safety and clarity for change detection

Open joseph-gio opened this issue 2 years ago • 1 comments

Objective

  • We have the type Tick for dealing with change ticks, but most of the engine still just uses u32.
  • The names last_change_tick and change_tick often appear together, however the meaning of these names is unclear.

Solution

  • Use the Tick type throughout the engine.
  • Rename last_change_tick and change_tick to last_run and this_run, respectively.

Changelog

  • Change detection now uses the strongly-typed Tick instead of u32.

Migration Guide

The engine now uses the type Tick for dealing with change ticks, instead of u32. Any code that interfaced with engine internals will need to be updated, including:

  • The traits SystemParam, WorldQuery, DetectChanges, and DetectChangesMut.
  • The methods World::change_tick and read_change_tick.
  • System::set_last_change_tick and get_last_change_tick. Also, these methods have also been renamed to set_last_run and get_last_run, respectively.
  • The methods SystemChangeTick::change_tick and last_change_tick. These methods have been renamed to this_run and last_run, respectively.
  • The method Tick::set_changed, which has been renamed to just set.

joseph-gio avatar Mar 05 '23 14:03 joseph-gio

I've encapsulated the field on Tick, which I think makes this even cleaner. I want to do a bit of file re-organization, but I'll leave it for a follow-up so the diffs aren't horrible.

joseph-gio avatar Mar 05 '23 16:03 joseph-gio

I have no idea why CI is failing now.

joseph-gio avatar Mar 09 '23 15:03 joseph-gio

CI failure looks like #8002.

alice-i-cecile avatar Mar 09 '23 17:03 alice-i-cecile