Add projectile state feed and diagnostics counters
- Include active projectiles in DUNGEON_STATE payload, spatially filtered - Track per-ability projectile diagnostics (spawn/hit/expiry) in simulation - Log periodic projectile diagnostics for ability troubleshooting - Update pending-clientChanges.md with required projectile rendering update
This commit is contained in:
@@ -2951,6 +2951,32 @@ public sealed partial class DungeonHandler : IClientMessageHandler
|
|||||||
y = i.Y
|
y = i.Y
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
projectiles = (sendSpatialThisTick ? sim.Projectiles.Values.Where(p => !spatialFiltering || IsNearby(p.X, p.Y)) : Enumerable.Empty<ProjectileInstance>())
|
||||||
|
.Select(p => new
|
||||||
|
{
|
||||||
|
id = p.Id,
|
||||||
|
sourceType = p.SourceType.ToString().ToLower(),
|
||||||
|
sourceMobId = p.SourceMobId,
|
||||||
|
sourcePlayerId = p.SourcePlayerId,
|
||||||
|
abilityId = p.AbilityId,
|
||||||
|
x = p.X,
|
||||||
|
y = p.Y,
|
||||||
|
targetX = p.TargetX,
|
||||||
|
targetY = p.TargetY,
|
||||||
|
velocityX = p.VelocityX,
|
||||||
|
velocityY = p.VelocityY,
|
||||||
|
speed = p.Speed,
|
||||||
|
damage = p.Damage,
|
||||||
|
damageTypeKey = p.DamageTypeKey,
|
||||||
|
aoeRadius = p.AoeRadius,
|
||||||
|
spriteKey = p.SpriteKey,
|
||||||
|
isLinear = p.IsLinear,
|
||||||
|
frontX = p.FrontX,
|
||||||
|
frontY = p.FrontY,
|
||||||
|
backX = p.BackX,
|
||||||
|
backY = p.BackY
|
||||||
|
}),
|
||||||
|
|
||||||
portals = sim.Portals.Values
|
portals = sim.Portals.Values
|
||||||
.Where(p => p.IsActive)
|
.Where(p => p.IsActive)
|
||||||
.Select(p => new
|
.Select(p => new
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ public partial class DungeonSimulation
|
|||||||
private readonly List<AbilityEvent> _pendingAbilityEvents = new();
|
private readonly List<AbilityEvent> _pendingAbilityEvents = new();
|
||||||
private readonly List<ProjectileHitEvent> _pendingProjectileHitEvents = new();
|
private readonly List<ProjectileHitEvent> _pendingProjectileHitEvents = new();
|
||||||
private readonly List<ProjectileExpiredEvent> _pendingProjectileExpiredEvents = new();
|
private readonly List<ProjectileExpiredEvent> _pendingProjectileExpiredEvents = new();
|
||||||
|
private readonly Dictionary<string, ProjectileAbilityDiagnostics> _projectileDiagnostics = new(StringComparer.OrdinalIgnoreCase);
|
||||||
|
private long _lastProjectileDiagnosticsLogTick;
|
||||||
|
|
||||||
private int _nextDroppedItemId = 1;
|
private int _nextDroppedItemId = 1;
|
||||||
private int _nextMobId = 10000; // Start summoned mobs at high ID to avoid conflicts
|
private int _nextMobId = 10000; // Start summoned mobs at high ID to avoid conflicts
|
||||||
@@ -735,6 +737,7 @@ public partial class DungeonSimulation
|
|||||||
}
|
}
|
||||||
|
|
||||||
Projectiles[projectile.Id] = projectile;
|
Projectiles[projectile.Id] = projectile;
|
||||||
|
IncrementProjectileDiagnostic(ability.Key, d => d.Spawned++);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateProjectiles()
|
private void UpdateProjectiles()
|
||||||
@@ -766,6 +769,7 @@ public partial class DungeonSimulation
|
|||||||
Y = projectile.Y,
|
Y = projectile.Y,
|
||||||
Reason = "range"
|
Reason = "range"
|
||||||
});
|
});
|
||||||
|
IncrementProjectileDiagnostic(ResolveProjectileAbilityKey(projectile), d => d.ExpiredRange++);
|
||||||
toRemove.Add(projectile.Id);
|
toRemove.Add(projectile.Id);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -864,6 +868,7 @@ public partial class DungeonSimulation
|
|||||||
X = projectile.X,
|
X = projectile.X,
|
||||||
Y = projectile.Y
|
Y = projectile.Y
|
||||||
});
|
});
|
||||||
|
IncrementProjectileDiagnostic(ResolveProjectileAbilityKey(projectile), d => d.HitMob++);
|
||||||
|
|
||||||
toRemove.Add(projectile.Id);
|
toRemove.Add(projectile.Id);
|
||||||
break;
|
break;
|
||||||
@@ -904,6 +909,7 @@ public partial class DungeonSimulation
|
|||||||
X = projectile.X,
|
X = projectile.X,
|
||||||
Y = projectile.Y
|
Y = projectile.Y
|
||||||
});
|
});
|
||||||
|
IncrementProjectileDiagnostic(ResolveProjectileAbilityKey(projectile), d => d.HitPlayer++);
|
||||||
|
|
||||||
toRemove.Add(projectile.Id);
|
toRemove.Add(projectile.Id);
|
||||||
break;
|
break;
|
||||||
@@ -926,6 +932,7 @@ public partial class DungeonSimulation
|
|||||||
Y = projectile.Y,
|
Y = projectile.Y,
|
||||||
Reason = "wall"
|
Reason = "wall"
|
||||||
});
|
});
|
||||||
|
IncrementProjectileDiagnostic(ResolveProjectileAbilityKey(projectile), d => d.ExpiredWall++);
|
||||||
toRemove.Add(projectile.Id);
|
toRemove.Add(projectile.Id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -934,6 +941,50 @@ public partial class DungeonSimulation
|
|||||||
{
|
{
|
||||||
Projectiles.TryRemove(id, out _);
|
Projectiles.TryRemove(id, out _);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LogProjectileDiagnosticsIfNeeded();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void IncrementProjectileDiagnostic(string abilityKey, Action<ProjectileAbilityDiagnostics> increment)
|
||||||
|
{
|
||||||
|
string key = string.IsNullOrWhiteSpace(abilityKey) ? "unknown" : abilityKey;
|
||||||
|
if (!_projectileDiagnostics.TryGetValue(key, out var diag))
|
||||||
|
{
|
||||||
|
diag = new ProjectileAbilityDiagnostics();
|
||||||
|
_projectileDiagnostics[key] = diag;
|
||||||
|
}
|
||||||
|
|
||||||
|
increment(diag);
|
||||||
|
}
|
||||||
|
|
||||||
|
private string ResolveProjectileAbilityKey(ProjectileInstance projectile)
|
||||||
|
{
|
||||||
|
if (projectile.AbilityId > 0 &&
|
||||||
|
_abilityDefinitions != null &&
|
||||||
|
_abilityDefinitions.TryGetValue(projectile.AbilityId, out var def))
|
||||||
|
{
|
||||||
|
return string.IsNullOrWhiteSpace(def.Key) ? $"ability_{projectile.AbilityId}" : def.Key;
|
||||||
|
}
|
||||||
|
|
||||||
|
return projectile.SourceType == ProjectileSource.Player ? "player_projectile" : "mob_projectile";
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LogProjectileDiagnosticsIfNeeded()
|
||||||
|
{
|
||||||
|
if (CurrentTick - _lastProjectileDiagnosticsLogTick < TicksPerSecond * 5) return;
|
||||||
|
_lastProjectileDiagnosticsLogTick = CurrentTick;
|
||||||
|
|
||||||
|
if (_projectileDiagnostics.Count == 0) return;
|
||||||
|
|
||||||
|
var parts = _projectileDiagnostics
|
||||||
|
.OrderBy(kvp => kvp.Key)
|
||||||
|
.Select(kvp =>
|
||||||
|
{
|
||||||
|
var d = kvp.Value;
|
||||||
|
return $"{kvp.Key}: spawned={d.Spawned}, hitP={d.HitPlayer}, hitM={d.HitMob}, expWall={d.ExpiredWall}, expRange={d.ExpiredRange}";
|
||||||
|
});
|
||||||
|
|
||||||
|
Console.WriteLine($"[ProjectileDiag][Tick {CurrentTick}] {string.Join(" | ", parts)}");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ProcessAoeAbility(MobInstance mob, MobAbilityDefinition ability, float targetX, float targetY)
|
private void ProcessAoeAbility(MobInstance mob, MobAbilityDefinition ability, float targetX, float targetY)
|
||||||
@@ -1583,4 +1634,13 @@ public partial class DungeonSimulation
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private sealed class ProjectileAbilityDiagnostics
|
||||||
|
{
|
||||||
|
public long Spawned { get; set; }
|
||||||
|
public long HitPlayer { get; set; }
|
||||||
|
public long HitMob { get; set; }
|
||||||
|
public long ExpiredWall { get; set; }
|
||||||
|
public long ExpiredRange { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# Pending Client Changes
|
# Pending Client Changes
|
||||||
|
|
||||||
## Status
|
## Status
|
||||||
Two client-side updates are still required for animation/loot interaction consistency.
|
Three client-side updates are still required for animation/loot/projectile consistency.
|
||||||
|
|
||||||
## Required Client Update
|
## Required Client Update
|
||||||
1. Gate loot prompt (`E`) by `hasLoot`.
|
1. Gate loot prompt (`E`) by `hasLoot`.
|
||||||
@@ -16,6 +16,11 @@ Two client-side updates are still required for animation/loot interaction consis
|
|||||||
- On each update for an existing mob entity, client should apply server animation directly.
|
- On each update for an existing mob entity, client should apply server animation directly.
|
||||||
- Do not keep a previous local animation state when server sends a different value.
|
- Do not keep a previous local animation state when server sends a different value.
|
||||||
|
|
||||||
|
3. Render active projectiles from `projectiles` in `DUNGEON_STATE`.
|
||||||
|
- Server now sends active projectile entities each tick (spatial-filtered).
|
||||||
|
- Use `x/y`, `velocityX/velocityY`, `spriteKey`, and linear metadata (`isLinear`, `frontX/frontY`, `backX/backY`) for rendering.
|
||||||
|
- Keep existing `events.projectileHits` / `events.projectileExpired` handling for impact/cleanup effects.
|
||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
1. Server now includes `isAlive`/`hasLoot`/`currentAnimation` consistently in mob payloads and sends `mobCatalog` on dungeon-enter responses and one-time in dungeon state.
|
1. Server now includes `isAlive`/`hasLoot`/`currentAnimation` consistently in mob payloads and sends `mobCatalog` on dungeon-enter responses and one-time in dungeon state.
|
||||||
2. If invisible mobs still occur, keep a fallback render path when `spriteConfig` is null:
|
2. If invisible mobs still occur, keep a fallback render path when `spriteConfig` is null:
|
||||||
|
|||||||
Reference in New Issue
Block a user