-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: some fixes for real game examples
- Loading branch information
Showing
11 changed files
with
167 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
lib/src/collisions/collision_prospect/collision_prospect.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import 'package:flame/collisions.dart'; | ||
import 'package:flame_spatial_grid/flame_spatial_grid.dart'; | ||
|
||
/// A [CollisionProspect] is a tuple that is used to contain two potentially | ||
/// colliding hitboxes. | ||
class CollisionProspectGrouped extends CollisionProspect<ShapeHitbox> { | ||
@override | ||
int get hash => _hashGrouped; | ||
int _hashGrouped; | ||
|
||
CollisionProspectGrouped(super.a, super.b) | ||
: _hashGrouped = a.hashCode ^ | ||
((b is GroupHitbox) ? b.hashCodeForCollisions : b.hashCode); | ||
|
||
@override | ||
void set(ShapeHitbox a, ShapeHitbox b) { | ||
super.set(a, b); | ||
_hashGrouped = a.hashCode ^ | ||
((b is GroupHitbox) ? b.hashCodeForCollisions : b.hashCode); | ||
} | ||
|
||
/// Sets the prospect to contain the content of [other]. | ||
@override | ||
void setFrom(CollisionProspect<ShapeHitbox> other) { | ||
super.setFrom(other); | ||
if (other is CollisionProspectGrouped) { | ||
_hashGrouped = other._hashGrouped; | ||
} | ||
} | ||
|
||
/// Creates a new prospect object with the same content. | ||
@override | ||
CollisionProspect<ShapeHitbox> clone() => CollisionProspectGrouped(a, b); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import 'package:flame/collisions.dart'; | ||
import 'package:flame_spatial_grid/src/collisions/collision_prospect/collision_prospect.dart'; | ||
|
||
/// This pool is used to not create unnecessary [CollisionProspect] objects | ||
/// during collision detection, but to re-use the ones that have already been | ||
/// created. | ||
class ProspectPoolGrouped extends ProspectPool<ShapeHitbox> { | ||
ProspectPoolGrouped({super.incrementSize = 1000}); | ||
|
||
final _storage = <CollisionProspectGrouped>[]; | ||
|
||
@override | ||
int get length => _storage.length; | ||
|
||
/// The size of the pool will expand with [incrementSize] amount of | ||
/// [CollisionProspect]s that are initially populated with two [dummyItem]s. | ||
@override | ||
void expand(ShapeHitbox dummyItem) { | ||
for (var i = 0; i < incrementSize; i++) { | ||
_storage.add(CollisionProspectGrouped(dummyItem, dummyItem)); | ||
} | ||
} | ||
|
||
@override | ||
CollisionProspect<ShapeHitbox> operator [](int index) => _storage[index]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters