Skip to content

Commit

Permalink
feat: remove static property from entities (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtome authored Nov 24, 2024
1 parent ebfa277 commit 3df41be
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 23 deletions.
2 changes: 1 addition & 1 deletion examples/standard_platformer/lib/coin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:leap/leap.dart';
import 'package:tiled/tiled.dart';

class Coin extends PhysicalEntity {
Coin(TiledObject tiledObject, this.animation) : super(static: true) {
Coin(TiledObject tiledObject, this.animation) {
width = 16;
height = 16;
priority = 2;
Expand Down
1 change: 0 additions & 1 deletion examples/standard_platformer/lib/door.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class Door extends PhysicalEntity with HasGameRef<ExamplePlatformerLeapGame> {
: super(
position: Vector2(object.x, object.y),
size: Vector2(object.width, object.height),
static: true,
) {
destinationMap = object.properties.getValue<String>('DestinationMap');
final destinationObjectId =
Expand Down
1 change: 0 additions & 1 deletion examples/standard_platformer/lib/info_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class InfoText extends PhysicalEntity {
: super(
position: Vector2(object.x, object.y),
size: Vector2(object.width, object.height),
static: true,
) {
text = object.properties.getValue<String>('Text') ??
'Lorem ipsum mising text.';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ class CollisionDetectionBehavior extends PhysicalBehavior
prevCollisionInfo.copyFrom(collisionInfo);
collisionInfo.reset();

// NOTE: static entities will never run this behavior, so making entities
// static is important for performance

if (isRemoving ||
parent.statuses
.where((s) => s is IgnoredByWorld || s is IgnoresCollisions)
Expand Down Expand Up @@ -398,7 +395,7 @@ class CollisionDetectionBehavior extends PhysicalBehavior
/// allowing it to pass through another object due to velocity or long
/// time step.
class _HitboxProxyComponent extends PhysicalEntity {
_HitboxProxyComponent() : super(static: true);
_HitboxProxyComponent();

late LeapGame overrideGameRef;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import 'package:leap/leap.dart';
class GravityAccelerationBehavior extends PhysicalBehavior {
@override
void update(double dt) {
if (parent.static ||
parent.statuses
.where((s) => s is IgnoresGravity || s is IgnoredByWorld)
.isNotEmpty) {
if (parent.statuses
.where((s) => s is IgnoresGravity || s is IgnoredByWorld)
.isNotEmpty) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/leap/lib/src/entities/ladder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ abstract class Ladder extends PhysicalEntity {
super.size,
this.topExtraHitbox = 0,
this.tiledObject,
}) : super(static: true) {
}) {
y = y - topExtraHitbox;
height = height + topExtraHitbox;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/leap/lib/src/entities/moving_platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ abstract class MovingPlatform extends PhysicalEntity {
// standing on top of it from the previous frame can be properly moved
// with the platform.
super.priority = 2,
}) : super(static: true) {
}) {
// Behaviors
add(_ApplySpeedBehavior());
add(ApplyVelocityBehavior());
Expand Down
11 changes: 2 additions & 9 deletions packages/leap/lib/src/entities/physical_entity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ import 'package:leap/leap.dart';
/// A component which has a physical representation in the world, with
/// collision detection, movement, etc.
///
/// [static] components can be collided with but never move and have a much
/// smaller performance impact on the game loop.
///
/// Sub-classes should add [GravityAccelerationBehavior],
/// [CollisionDetectionBehavior], and [ApplyVelocityBehavior] unless they
/// are [static]. It is important for acceleration (velocity changes) from
/// [CollisionDetectionBehavior], and [ApplyVelocityBehavior].
/// It is important for acceleration (velocity changes) from
/// gravity and the entity's own movement to be applied in behaviors before
/// collision detection since that is driven off of the entity velocity.
/// [ApplyVelocityBehavior] should come last when after velocty updates
Expand All @@ -23,9 +20,6 @@ import 'package:leap/leap.dart';
/// 4. [ApplyVelocityBehavior]
/// 5. Rendering related state changes (sprite positioning etc.)
abstract class PhysicalEntity extends PositionedEntity {
/// Position object to store the x/y components.
final bool static;

/// Tags for custom logic, also used by [solidTags]
final Set<String> tags = {};

Expand Down Expand Up @@ -79,7 +73,6 @@ abstract class PhysicalEntity extends PositionedEntity {
maxGravityVelocityOverride ?? leapWorld.maxGravityVelocity;

PhysicalEntity({
this.static = false,
super.position,
super.size,
super.scale,
Expand Down
2 changes: 1 addition & 1 deletion packages/leap/lib/src/leap_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class LeapMapGroundTile extends PhysicalEntity {
this._gridY,
this.gameOverride, {
this.tiledOptions = const TiledOptions(),
}) : super(static: true) {
}) {
width = leapGame.tileSize;
height = leapGame.tileSize;
position = Vector2(tileSize * _gridX, tileSize * _gridY);
Expand Down

0 comments on commit 3df41be

Please sign in to comment.