2019-12-17 01:55:52 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
using RobocraftX;
|
|
|
|
|
using RobocraftX.Blocks;
|
|
|
|
|
using RobocraftX.Blocks.Ghost;
|
|
|
|
|
using RobocraftX.Common;
|
|
|
|
|
using RobocraftX.Multiplayer;
|
|
|
|
|
using RobocraftX.SimulationModeState;
|
|
|
|
|
using RobocraftX.UECS;
|
|
|
|
|
using Unity.Entities;
|
|
|
|
|
using Svelto.Context;
|
|
|
|
|
using Svelto.ECS;
|
|
|
|
|
using Svelto.ECS.EntityStructs;
|
|
|
|
|
using Unity.Transforms;
|
|
|
|
|
using Unity.Mathematics;
|
|
|
|
|
using UnityEngine;
|
2020-05-12 00:28:26 +00:00
|
|
|
|
using Svelto.DataStructures;
|
2019-12-17 01:55:52 +00:00
|
|
|
|
|
|
|
|
|
using GamecraftModdingAPI.Utility;
|
2020-05-12 00:28:26 +00:00
|
|
|
|
using GamecraftModdingAPI.Engines;
|
2019-12-17 01:55:52 +00:00
|
|
|
|
|
|
|
|
|
namespace GamecraftModdingAPI.Blocks
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Engine which executes block movement actions
|
|
|
|
|
/// </summary>
|
2019-12-19 20:42:50 +00:00
|
|
|
|
public class MovementEngine : IApiEngine
|
2019-12-17 01:55:52 +00:00
|
|
|
|
{
|
|
|
|
|
public string Name { get; } = "GamecraftModdingAPIMovementGameEngine";
|
|
|
|
|
|
2020-03-12 22:36:23 +00:00
|
|
|
|
public EntitiesDB entitiesDB { set; private get; }
|
2019-12-17 01:55:52 +00:00
|
|
|
|
|
2020-05-12 00:28:26 +00:00
|
|
|
|
public bool isRemovable => false;
|
|
|
|
|
|
|
|
|
|
public bool IsInGame = false;
|
2019-12-17 01:55:52 +00:00
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
IsInGame = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Ready()
|
|
|
|
|
{
|
|
|
|
|
IsInGame = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// implementations for Movement static class
|
|
|
|
|
|
|
|
|
|
public float3 MoveBlock(uint blockID, float3 vector)
|
|
|
|
|
{
|
|
|
|
|
ref PositionEntityStruct posStruct = ref this.entitiesDB.QueryEntity<PositionEntityStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP);
|
|
|
|
|
ref GridRotationStruct gridStruct = ref this.entitiesDB.QueryEntity<GridRotationStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP);
|
|
|
|
|
ref LocalTransformEntityStruct transStruct = ref this.entitiesDB.QueryEntity<LocalTransformEntityStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP);
|
|
|
|
|
ref UECSPhysicsEntityStruct phyStruct = ref this.entitiesDB.QueryEntity<UECSPhysicsEntityStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP);
|
|
|
|
|
// main (persistent) position
|
|
|
|
|
posStruct.position += vector;
|
|
|
|
|
// placement grid position
|
|
|
|
|
gridStruct.position += vector;
|
|
|
|
|
// rendered position
|
|
|
|
|
transStruct.position += vector;
|
|
|
|
|
// collision position
|
|
|
|
|
FullGameFields._physicsWorld.EntityManager.SetComponentData(phyStruct.uecsEntity, new Translation
|
|
|
|
|
{
|
|
|
|
|
Value = posStruct.position
|
|
|
|
|
});
|
|
|
|
|
return posStruct.position;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float3 MoveConnectedBlocks(uint blockID, float3 vector)
|
|
|
|
|
{
|
|
|
|
|
Stack<uint> cubeStack = new Stack<uint>();
|
2020-02-07 00:25:31 +00:00
|
|
|
|
FasterList<uint> cubesToMove = new FasterList<uint>();
|
2019-12-17 01:55:52 +00:00
|
|
|
|
ConnectedCubesUtility.TreeTraversal.GetConnectedCubes(entitiesDB, blockID, cubeStack, cubesToMove, (in GridConnectionsEntityStruct g) => { return false; });
|
2020-02-07 00:25:31 +00:00
|
|
|
|
for (int i = 0; i < cubesToMove.count; i++)
|
2019-12-17 01:55:52 +00:00
|
|
|
|
{
|
|
|
|
|
MoveBlock(cubesToMove[i], vector);
|
|
|
|
|
entitiesDB.QueryEntity<GridConnectionsEntityStruct>(cubesToMove[i], CommonExclusiveGroups.OWNED_BLOCKS_GROUP).isProcessed = false;
|
|
|
|
|
}
|
|
|
|
|
return this.entitiesDB.QueryEntity<PositionEntityStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP).position;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|