Sync spawned units immediately

This commit is contained in:
Anuken
2025-04-22 13:23:53 -04:00
parent d6c2ec85f7
commit bea50d3821
7 changed files with 73 additions and 1 deletions

View File

@@ -34,6 +34,18 @@ public class Units{
return false;
};
public static void notifyUnitSpawn(Unit unit){
if(net.server()){
Call.unitSpawn(new UnitContainer(unit));
}
}
//syncs a unit spawn so that it appears immediately without waiting for a snapshot
@Remote(unreliable = true, priority = PacketPriority.low)
public static void unitSpawn(UnitContainer container){
//doesn't actually do anything, reading calls add()
}
@Remote(called = Loc.server)
public static void unitCapDeath(Unit unit){
if(unit != null){
@@ -488,4 +500,15 @@ public class Units{
public interface BuildingPriorityf{
float priority(Building build);
}
public static class UnitContainer{
public Unit unit;
public UnitContainer(){
}
public UnitContainer(Unit unit){
this.unit = unit;
}
}
}

View File

@@ -590,6 +590,7 @@ public class BulletType extends Content implements Cloneable{
Tmp.v1.rnd(Mathf.random(despawnUnitRadius));
var u = despawnUnit.spawn(b.team, x + Tmp.v1.x, y + Tmp.v1.y);
u.rotation = faceOutwards ? Tmp.v1.angle() : b.rotation();
Units.notifyUnitSpawn(u);
}
}
}
@@ -899,6 +900,7 @@ public class BulletType extends Content implements Cloneable{
}
spawned.add();
Units.notifyUnitSpawn(spawned);
}
//Since bullet init is never called, handle killing shooter here
if(killShooter && owner instanceof Healthc h && !h.dead()) h.kill();