- Made the PublishEntityChangesDelayed() method use the internals of Svelto.ECS to determine if it should wait -- I had this code for a while but it used too much reflection to my liking -- Now I made the reflection code nicer and a bit safer - Fixed float comparisons: last time I didn't actually used abs() for float3 but I found this even better method
76 lines
2.6 KiB
C#
76 lines
2.6 KiB
C#
using RobocraftX.Common;
|
|
using RobocraftX.DOTS;
|
|
using Svelto.ECS;
|
|
using Svelto.ECS.EntityStructs;
|
|
using Unity.Mathematics;
|
|
using UnityEngine;
|
|
|
|
using TechbloxModdingAPI.Engines;
|
|
using TechbloxModdingAPI.Utility;
|
|
using TechbloxModdingAPI.Utility.ECS;
|
|
|
|
namespace TechbloxModdingAPI.Blocks.Engines
|
|
{
|
|
/// <summary>
|
|
/// Engine which executes block movement actions
|
|
/// </summary>
|
|
public class RotationEngine : IApiEngine
|
|
{
|
|
public string Name { get; } = "TechbloxModdingAPIRotationGameEngine";
|
|
|
|
public EntitiesDB entitiesDB { set; private get; }
|
|
|
|
public bool isRemovable => false;
|
|
|
|
public bool IsInGame = false;
|
|
|
|
public void Dispose()
|
|
{
|
|
IsInGame = false;
|
|
}
|
|
|
|
public void Ready()
|
|
{
|
|
IsInGame = true;
|
|
}
|
|
|
|
// implementations for Rotation static class
|
|
|
|
internal float3 RotateBlock(Block block, Vector3 vector)
|
|
{
|
|
ref RotationEntityStruct rotStruct = ref this.entitiesDB.QueryEntityOrDefault<RotationEntityStruct>(block);
|
|
ref GridRotationStruct gridStruct = ref this.entitiesDB.QueryEntityOrDefault<GridRotationStruct>(block);
|
|
ref LocalTransformEntityStruct transStruct = ref this.entitiesDB.QueryEntityOrDefault<LocalTransformEntityStruct>(block);
|
|
var phyStruct = this.entitiesDB.QueryEntityOptional<DOTSPhysicsEntityStruct>(block);
|
|
// main (persistent) rotation
|
|
Quaternion newRotation = rotStruct.rotation;
|
|
newRotation.eulerAngles = vector;
|
|
rotStruct.rotation = newRotation;
|
|
// placement grid rotation
|
|
gridStruct.rotation = newRotation;
|
|
// rendered rotation
|
|
transStruct.rotation = newRotation;
|
|
// collision rotation
|
|
if (phyStruct)
|
|
{ //It exists
|
|
FullGameFields._physicsWorld.EntityManager.SetComponentData(phyStruct.Get().dotsEntity,
|
|
new Unity.Transforms.Rotation
|
|
{
|
|
Value = rotStruct.rotation
|
|
});
|
|
}
|
|
|
|
// TODO: Connections probably need to be assigned (maybe)
|
|
// They are assigned during machine processing anyway
|
|
entitiesDB.QueryEntityOrDefault<GridConnectionsEntityStruct>(block).areConnectionsAssigned = false;
|
|
return ((Quaternion)rotStruct.rotation).eulerAngles;
|
|
|
|
}
|
|
|
|
internal float3 GetRotation(Block block)
|
|
{
|
|
ref RotationEntityStruct rotStruct = ref entitiesDB.QueryEntityOrDefault<RotationEntityStruct>(block);
|
|
return ((Quaternion) rotStruct.rotation).eulerAngles;
|
|
}
|
|
}
|
|
}
|