Skip to content

Commit

Permalink
perf: redundant updateTransform() call removed
Browse files Browse the repository at this point in the history
  • Loading branch information
ASGAlex committed Oct 21, 2023
1 parent cdb7caa commit 03b1972
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion example/lib/game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ all collisions are disabled.
buildCellsPerUpdate: buildCellsPerUpdate,
cleanupCellsPerUpdate: cleanupCellsPerUpdate,
suspendedCellLifetime: const Duration(minutes: 10),
scheduledLayerOperationLimit: 5,
scheduledLayerOperationLimit: 1,
cellBuilderNoMap: noMapCellBuilder,
maps: [
DemoMapLoader(Vector2(600, 0)),
Expand Down
2 changes: 1 addition & 1 deletion lib/src/collisions/collision_detection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class SpatialGridCollisionDetection
_listenerCollisionType[item] = listenerCollisionType;

item.defaultCollisionType; //init defaults with current value;
withGridSupportComponent.updateTransform();
_scheduledUpdateAfterTransform.add(item);

broadphase.updateHitboxIndexes(item);
final componentCurrentCell = withGridSupportComponent.currentCell;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/collisions/hitboxes/bounding_hitbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ typedef BoundingHitboxFactory = BoundingHitbox Function();
/// [SpatialGridRectangleHitbox] and [SpatialGridShapeHitbox] extensions
/// provides same functionality for pure Flame hitboxes
class BoundingHitbox extends RectangleHitboxOptimized
with HasGameRef<HasSpatialGridFramework>
with HasGameReference<HasSpatialGridFramework>
implements MacroObjectInterface {
BoundingHitbox({
super.position,
Expand Down
9 changes: 6 additions & 3 deletions lib/src/components/has_grid_support.dart
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,13 @@ mixin HasGridSupport on PositionComponent implements MacroObjectInterface {
if (spatialGrid == null) {
return;
}
boundingBox.aabbCenter = boundingBox.aabb.center;
cachedCenters.remove(boundingBox);
final componentCenter = boundingBox.aabbCenter;
final componentCenter = boundingBox.aabbCenter =
cachedCenters[boundingBox] = boundingBox.aabb.center;
var current = currentCell;
if (kDebugMode && current == null) {
print('better to set currentCell manually. Component: $runtimeType');
}

List<Cell?>? previousCellNeighbours;
current ??= spatialGrid.findExistingCellByPosition(componentCenter) ??
spatialGrid.createNewCellAtPosition(componentCenter);
Expand Down

0 comments on commit 03b1972

Please sign in to comment.