Skip to content

Minor ClientAnimator refactor#73

Open
tehtelev wants to merge 5 commits intoanegostudios:masterfrom
tehtelev:patch-6
Open

Minor ClientAnimator refactor#73
tehtelev wants to merge 5 commits intoanegostudios:masterfrom
tehtelev:patch-6

Conversation

@tehtelev
Copy link

@tehtelev tehtelev commented Feb 12, 2026

The following improvements have been made to the animation system:
1) ClientAnimator:

  • More comments about the code logic in calculateMatrices;
  • Matrix copying is done in chunks using Buffer;
  • Protections have been implemented against potential errors like this issues related to array bounds violations;

2) ShapeElement:

  • A working caching system for base element matrices has been implemented, significantly speeding up animation calculations for block entity animations overall (reduced from 14 seconds to 9 seconds on a 30-second benchmark). This is due to the fact that in block entity animations, only a small portion of the model elements are often animated, so there is no need to recalculate transformation matrices for non-animated elements. For entities, the increase is almost imperceptible. An increase of about 5% is only observed if the animations are made in version 1.

3) Mat4f:

  • the Multiply method has been switched to unsafe pointer usage for direct memory access, resulting in speedups in busy areas.

On my test map with a large number of block entities with animations, we get the following results:

image image

Refactor ShapeElement class to improve caching and transformation handling.
Refactor ClientAnimator class to improve structure and performance. Update matrix calculations and optimize animation handling.
Enhance caching and transformation logic in ShapeElement
@tehtelev tehtelev marked this pull request as ready for review February 12, 2026 19:10
/// <summary>
/// Flag indicating that the cache is stale
/// </summary>
private bool _isCacheDirty = true;
Copy link
Contributor

@tyronx tyronx Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey, i don't quite understand what this flag is for. This only seems to be set to true when a ShapeElement object was created and then never again? Why not just null check the matrixes then?

bool _isCacheDirty => _cachedBaseMatrixV0==null || _cachedBaseMatrixV1==null;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I missed that moment.

/// Cached base matrices for different animation versions
/// </summary>
private float[] _cachedBaseMatrixV0;
private float[] _cachedBaseMatrixV1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please no _ prefixes, we don't use these in our code base

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