简单重构拆分 SimulationWorld
This commit is contained in:
+26
-13
@@ -32,40 +32,53 @@ namespace SepCore.Simulation
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!_world.TryGetEnemyData(enemyEntity.Id, out EnemySimData enemyData))
|
||||
if (!_world._enemies.TryGetSimulationIndex(enemyEntity.Id, out int simulationIndex))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ApplyEnemyPresentation(enemyEntity, enemyData);
|
||||
EnemyTransformSim enemyData = _world._enemies.Transform[simulationIndex];
|
||||
ApplyEnemyPresentation(enemyEntity, in enemyData);
|
||||
}
|
||||
}
|
||||
|
||||
var projectiles = _world._projectiles;
|
||||
for (int i = 0; i < projectiles.Count; i++)
|
||||
{
|
||||
ProjectileSimData projectileData = projectiles[i];
|
||||
if (!projectileData.Active || projectileData.State != ProjectileStateActive)
|
||||
if (!projectiles.Life[i].Active)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
EntityBase projectileEntity = TryGetEntityById(projectileData.EntityId);
|
||||
EntityBase projectileEntity = TryGetEntityById(projectiles.Identity[i].EntityId);
|
||||
if (projectileEntity == null || !projectileEntity.Available)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ApplyProjectilePresentation(projectileEntity, projectileData);
|
||||
ProjectileTransformSim projectileData = projectiles.Transform[i];
|
||||
ApplyProjectilePresentation(projectileEntity, in projectileData);
|
||||
}
|
||||
|
||||
var pickups = _world._pickups;
|
||||
for (int i = 0; i < pickups.Count; i++)
|
||||
{
|
||||
EntityBase pickupEntity = TryGetEntityById(pickups.Identity[i].EntityId);
|
||||
if (pickupEntity == null || !pickupEntity.Available)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
pickupEntity.CachedTransform.position = ToVector3(pickups.Transform[i].Position);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ApplyEnemyPresentation(EnemyBase enemyEntity, in EnemySimData enemyData)
|
||||
private static void ApplyEnemyPresentation(EnemyBase enemyEntity, in EnemyTransformSim enemyData)
|
||||
{
|
||||
Transform enemyTransform = enemyEntity.CachedTransform;
|
||||
enemyTransform.position = enemyData.Position;
|
||||
enemyTransform.position = ToVector3(enemyData.Position);
|
||||
|
||||
Quaternion rotation = enemyData.Rotation;
|
||||
Quaternion rotation = ToQuaternion(enemyData.Rotation);
|
||||
float rotationMagnitude = Mathf.Abs(rotation.x) + Mathf.Abs(rotation.y) + Mathf.Abs(rotation.z) +
|
||||
Mathf.Abs(rotation.w);
|
||||
if (rotationMagnitude > float.Epsilon)
|
||||
@@ -74,7 +87,7 @@ namespace SepCore.Simulation
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 forward = enemyData.Forward;
|
||||
Vector3 forward = ToVector3(enemyData.Forward);
|
||||
forward.y = 0f;
|
||||
if (forward.sqrMagnitude > float.Epsilon)
|
||||
{
|
||||
@@ -83,7 +96,7 @@ namespace SepCore.Simulation
|
||||
}
|
||||
|
||||
private static void ApplyProjectilePresentation(EntityBase projectileEntity,
|
||||
in ProjectileSimData projectileData)
|
||||
in ProjectileTransformSim projectileData)
|
||||
{
|
||||
Transform projectileTransform = projectileEntity.CachedTransform;
|
||||
if (projectileTransform == null)
|
||||
@@ -91,8 +104,8 @@ namespace SepCore.Simulation
|
||||
return;
|
||||
}
|
||||
|
||||
projectileTransform.position = projectileData.Position;
|
||||
Vector3 forward = projectileData.Forward;
|
||||
projectileTransform.position = ToVector3(projectileData.Position);
|
||||
Vector3 forward = ToVector3(projectileData.Forward);
|
||||
if (forward.sqrMagnitude <= float.Epsilon)
|
||||
{
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user