Skip to content

Conversation

pnstickne
Copy link
Contributor

This change implements the original suggestion of using updateTransform,
but applies so globally instead of within a particular postUpdate
function.

Now the game loop calls updateTransform after each updateLogic call
unconditionally; it is updates that change the world that are accounted
for, not the rendering. This removes some previous checks that were
preventing correct behavior with the previous patch.

This makes the assumption that game objects (eg. Sprites) are only
modified within callbacks triggered before the completion of the
postUpdate walking of the scene graph.

  • User code that runs outside of the "game update", such as a setTimeout
    timer, will need to explicitly update transformations so that the world
    is synced by the next preUpdate: but this is not the expected case and
    is already outside the Phaser update model.
  • If this assumption does not hold or is too weak, the transformations
    could also be applied once at the start of every game update loop
    (before any render or update). This change would at most double the time
    spent on apply the transformations.

The consistent root application of updateTransform passes all reported failing
cases and resolves #1424 just as the original proposal of having the
change performed in the Sprite postUpdate but will work more consistently
across all scene-bound game objects by descending the entire graph for all types.

On a desktop Chrome browser the inclusion also has minimal relative impact
as shown by the summarized results. The percentages given are the summed
CPU time of relevant required operations along with that of the
updateTransform itself:

  • 10,000 non-collision particles:
    • 12% pre/post update, 2.4% updateTransform
  • 100 colliding particles:
    • 2% pre/post update & collision, 0.3% updateTransform
  • 1000 colliding particles:
    • 40% pre/post update & collision, 1% updateTransform

With this update the time is still dominated by required game
updates, and more so, by any actual work like Physics.

This change implements the original suggestion of using `updateTransform`,
but applies so globally instead of within a particular postUpdate
function.

Now the game loop calls `updateTransform` after each `updateLogic` call
unconditionally; it is updates that change the world that are accounted
for, not the rendering. This removes some previous checks that were
preventing correct behavior with the previous patch.

This makes the assumption that game objects (eg. Sprites) are only
modified within callbacks triggered before the completion of the
`postUpdate` walking of the scene graph.
- User code that runs outside of the "game update", such as a `setTimeout`
  timer, will need to explicitly update transformations so that the world
  is synced by the next `preUpdate`: but this is not the expected case and
  is already outside the Phaser update model.
- If this assumption does not hold or is too weak, the transformations
  could also be applied once at the start of every game update loop
  (before any render or update). This change would at most double the time
  spent on apply the transformations.

The constant application of `updateTransform` passes all reported failing
cases and resolves phaserjs#1424 just as the original proposal of having the
change performed in the Sprite postUpdate but will work more consistently
across all scene-bound game objects.

On a desktop Chrome browser the inclusion also has minimal relative impact
as shown by the summarized results. The percentages given are the summed
CPU time of relevant required operations along with that of the
updateTransform itself:

- 10,000 non-collision particles:
  - 12% pre/post update, 2.4% updateTransform
- 100 colliding particles:
  - 2% pre/post update & collision, 0.3% updateTransform
- 1000 colliding particles:
  - 40% pre/post update & collision, 1% updateTransform

With this patch the updateTransform time does creep up _slightly_ (vs just
in `Sprite.postUpdate`) but it is still dominated by required game
updates, and more so, by any actual work like Physics.
photonstorm added a commit that referenced this pull request Jan 2, 2015
Simplified call to updateTransform - unified and verified fix for 1424
@photonstorm photonstorm merged commit 97cf7f7 into phaserjs:dev Jan 2, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants