调整部分数据表配置,优化 SpriteCache 功能
This commit is contained in:
@@ -6,6 +6,8 @@ namespace SepCore.EnemyManager
|
||||
public class EnemyRegistry
|
||||
{
|
||||
private readonly Dictionary<int, EntityBase> _enemyById;
|
||||
// PruneInvalidEntries 由 OnUpdate 每帧调用,复用缓冲避免每帧分配。
|
||||
private readonly List<int> _pruneBuffer;
|
||||
|
||||
public int Count => _enemyById.Count;
|
||||
public IReadOnlyCollection<EntityBase> Enemies => _enemyById.Values;
|
||||
@@ -13,11 +15,11 @@ namespace SepCore.EnemyManager
|
||||
public EnemyRegistry()
|
||||
{
|
||||
_enemyById = new Dictionary<int, EntityBase>();
|
||||
_pruneBuffer = new List<int>();
|
||||
}
|
||||
|
||||
public void Register(EnemyBase enemy)
|
||||
{
|
||||
if (enemy == null) return;
|
||||
_enemyById[enemy.Id] = enemy;
|
||||
}
|
||||
|
||||
@@ -35,16 +37,16 @@ namespace SepCore.EnemyManager
|
||||
|
||||
public void PruneInvalidEntries()
|
||||
{
|
||||
var invalidIds = new List<int>();
|
||||
_pruneBuffer.Clear();
|
||||
foreach (var kvp in _enemyById)
|
||||
{
|
||||
if (kvp.Value == null || !kvp.Value.Available)
|
||||
{
|
||||
invalidIds.Add(kvp.Key);
|
||||
_pruneBuffer.Add(kvp.Key);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (int id in invalidIds)
|
||||
foreach (int id in _pruneBuffer)
|
||||
{
|
||||
_enemyById.Remove(id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user