v0.9.3: improved performance of particle effects from ConeAOEs

This commit is contained in:
Evan Debenham 2021-05-09 17:23:12 -04:00
parent ef8750b326
commit 3a182033d1
5 changed files with 10 additions and 4 deletions

View File

@ -76,7 +76,7 @@ public class Shockwave extends ArmorAbility {
Ballistica.STOP_SOLID | Ballistica.STOP_TARGET); Ballistica.STOP_SOLID | Ballistica.STOP_TARGET);
//cast to cells at the tip, rather than all cells, better performance. //cast to cells at the tip, rather than all cells, better performance.
for (Ballistica ray : cone.rays){ for (Ballistica ray : cone.outerRays){
((MagicMissile)hero.sprite.parent.recycle( MagicMissile.class )).reset( ((MagicMissile)hero.sprite.parent.recycle( MagicMissile.class )).reset(
MagicMissile.FORCE_CONE, MagicMissile.FORCE_CONE,
hero.sprite, hero.sprite,

View File

@ -90,7 +90,7 @@ public class PotionOfDragonsBreath extends ExoticPotion {
final ConeAOE cone = new ConeAOE(bolt, 6, 60, Ballistica.STOP_SOLID | Ballistica.STOP_TARGET | Ballistica.IGNORE_SOFT_SOLID); final ConeAOE cone = new ConeAOE(bolt, 6, 60, Ballistica.STOP_SOLID | Ballistica.STOP_TARGET | Ballistica.IGNORE_SOFT_SOLID);
//cast to cells at the tip, rather than all cells, better performance. //cast to cells at the tip, rather than all cells, better performance.
for (Ballistica ray : cone.rays){ for (Ballistica ray : cone.outerRays){
((MagicMissile)curUser.sprite.parent.recycle( MagicMissile.class )).reset( ((MagicMissile)curUser.sprite.parent.recycle( MagicMissile.class )).reset(
MagicMissile.FIRE_CONE, MagicMissile.FIRE_CONE,
curUser.sprite, curUser.sprite,

View File

@ -151,7 +151,7 @@ public class WandOfFireblast extends DamageWand {
Ballistica.STOP_TARGET | Ballistica.STOP_SOLID | Ballistica.IGNORE_SOFT_SOLID); Ballistica.STOP_TARGET | Ballistica.STOP_SOLID | Ballistica.IGNORE_SOFT_SOLID);
//cast to cells at the tip, rather than all cells, better performance. //cast to cells at the tip, rather than all cells, better performance.
for (Ballistica ray : cone.rays){ for (Ballistica ray : cone.outerRays){
((MagicMissile)curUser.sprite.parent.recycle( MagicMissile.class )).reset( ((MagicMissile)curUser.sprite.parent.recycle( MagicMissile.class )).reset(
MagicMissile.FIRE_CONE, MagicMissile.FIRE_CONE,
curUser.sprite, curUser.sprite,

View File

@ -243,7 +243,7 @@ public class WandOfRegrowth extends Wand {
Ballistica.STOP_SOLID | Ballistica.STOP_TARGET); Ballistica.STOP_SOLID | Ballistica.STOP_TARGET);
//cast to cells at the tip, rather than all cells, better performance. //cast to cells at the tip, rather than all cells, better performance.
for (Ballistica ray : cone.rays){ for (Ballistica ray : cone.outerRays){
((MagicMissile)curUser.sprite.parent.recycle( MagicMissile.class )).reset( ((MagicMissile)curUser.sprite.parent.recycle( MagicMissile.class )).reset(
MagicMissile.FOLIAGE_CONE, MagicMissile.FOLIAGE_CONE,
curUser.sprite, curUser.sprite,

View File

@ -35,6 +35,7 @@ public class ConeAOE {
public Ballistica coreRay; public Ballistica coreRay;
public ArrayList<Ballistica> outerRays = new ArrayList<>();
public ArrayList<Ballistica> rays = new ArrayList<>(); public ArrayList<Ballistica> rays = new ArrayList<>();
public HashSet<Integer> cells = new HashSet<>(); public HashSet<Integer> cells = new HashSet<>();
@ -72,6 +73,7 @@ public class ConeAOE {
float initalAngle = PointF.angle(fromP, toP)/PointF.G2R; float initalAngle = PointF.angle(fromP, toP)/PointF.G2R;
//want to preserve order so that our collection of rays is going clockwise //want to preserve order so that our collection of rays is going clockwise
LinkedHashSet<Integer> targetCells = new LinkedHashSet<>(); LinkedHashSet<Integer> targetCells = new LinkedHashSet<>();
LinkedHashSet<Integer> outerCells = new LinkedHashSet<>();
//cast a ray every 0.5 degrees in a clockwise arc, to find cells along the cone's outer arc //cast a ray every 0.5 degrees in a clockwise arc, to find cells along the cone's outer arc
for (float a = initalAngle+degrees/2f; a >= initalAngle-degrees/2f; a-=0.5f){ for (float a = initalAngle+degrees/2f; a >= initalAngle-degrees/2f; a-=0.5f){
@ -83,6 +85,7 @@ public class ConeAOE {
(int)GameMath.gate(0, (int)Math.floor(scan.x), Dungeon.level.width()-1), (int)GameMath.gate(0, (int)Math.floor(scan.x), Dungeon.level.width()-1),
(int)GameMath.gate(0, (int)Math.floor(scan.y), Dungeon.level.height()-1)); (int)GameMath.gate(0, (int)Math.floor(scan.y), Dungeon.level.height()-1));
targetCells.add(Dungeon.level.pointToCell(scanInt)); targetCells.add(Dungeon.level.pointToCell(scanInt));
outerCells.add(Dungeon.level.pointToCell(scanInt));
//if the cone is large enough, also cast rays to cells just inside of the outer arc //if the cone is large enough, also cast rays to cells just inside of the outer arc
// this helps fill in any holes when casting rays // this helps fill in any holes when casting rays
if (circleRadius >= 4) { if (circleRadius >= 4) {
@ -103,6 +106,9 @@ public class ConeAOE {
Ballistica ray = new Ballistica(core.sourcePos, c, ballisticaParams); Ballistica ray = new Ballistica(core.sourcePos, c, ballisticaParams);
cells.addAll(ray.subPath(1, ray.dist)); cells.addAll(ray.subPath(1, ray.dist));
rays.add(ray); rays.add(ray);
if (outerCells.contains(c)){
outerRays.add(ray);
}
} }
} }