Add cube moving commands
This commit is contained in:
parent
d636ebaaf2
commit
8ac64d76b6
3 changed files with 135 additions and 18 deletions
|
@ -7,9 +7,12 @@ namespace ExtraCommands
|
||||||
{
|
{
|
||||||
public string Name { get; protected set; }
|
public string Name { get; protected set; }
|
||||||
|
|
||||||
public CustomCommandAttribute(string name = "")
|
public string Description { get; protected set; }
|
||||||
|
|
||||||
|
public CustomCommandAttribute(string name = "", string description = "")
|
||||||
{
|
{
|
||||||
this.Name = name;
|
this.Name = name;
|
||||||
|
this.Description = description;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,9 @@
|
||||||
<Reference Include="RobocraftX.Character">
|
<Reference Include="RobocraftX.Character">
|
||||||
<HintPath>..\ref\RobocraftX.Input.dll</HintPath>
|
<HintPath>..\ref\RobocraftX.Input.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="RobocraftX.MainGame">
|
||||||
|
<HintPath>..\ref\RobocraftX.MainGame.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="RobocraftX.Multiplayer">
|
<Reference Include="RobocraftX.Multiplayer">
|
||||||
<HintPath>..\ref\RobocraftX.Multiplayer.dll</HintPath>
|
<HintPath>..\ref\RobocraftX.Multiplayer.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
@ -49,6 +52,9 @@
|
||||||
<Reference Include="Svelto.ECS">
|
<Reference Include="Svelto.ECS">
|
||||||
<HintPath>..\ref\Svelto.ECS.dll</HintPath>
|
<HintPath>..\ref\Svelto.ECS.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="Svelto.Tasks">
|
||||||
|
<HintPath>..\ref\Svelto.Tasks.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="Unity.Entities">
|
<Reference Include="Unity.Entities">
|
||||||
<HintPath>..\ref\Unity.Entities.dll</HintPath>
|
<HintPath>..\ref\Unity.Entities.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
@ -70,6 +76,9 @@
|
||||||
<Reference Include="Unity.Mathematics.Extensions.Hybrid">
|
<Reference Include="Unity.Mathematics.Extensions.Hybrid">
|
||||||
<HintPath>..\ref\Unity.Mathematics.Extensions.Hybrid.dll</HintPath>
|
<HintPath>..\ref\Unity.Mathematics.Extensions.Hybrid.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="Unity.Transforms">
|
||||||
|
<HintPath>..\ref\Unity.Transforms.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="UnityEngine">
|
<Reference Include="UnityEngine">
|
||||||
<HintPath>..\ref\UnityEngine.dll</HintPath>
|
<HintPath>..\ref\UnityEngine.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
|
|
@ -1,20 +1,21 @@
|
||||||
using System;
|
using System;
|
||||||
using RobocraftX.GUI.CommandLine;
|
using System.Collections.Generic;
|
||||||
using RobocraftX.Multiplayer;
|
using RobocraftX.Multiplayer;
|
||||||
using RobocraftX.StateSync;
|
|
||||||
using RobocraftX.Character;
|
|
||||||
using RobocraftX.Common;
|
using RobocraftX.Common;
|
||||||
using Svelto.ECS;
|
using Svelto.ECS;
|
||||||
using Svelto.ECS.EntityStructs;
|
using Svelto.ECS.EntityStructs;
|
||||||
using Unity.Entities;
|
using Unity.Entities;
|
||||||
using UnityEngine;
|
|
||||||
using uREPL;
|
|
||||||
using Svelto.Context;
|
using Svelto.Context;
|
||||||
|
using Svelto.Tasks;
|
||||||
using RobocraftX;
|
using RobocraftX;
|
||||||
|
using RobocraftX.SimulationModeState;
|
||||||
|
using RobocraftX.UECS;
|
||||||
|
using Unity.Transforms;
|
||||||
|
|
||||||
namespace ExtraCommands.Building
|
namespace ExtraCommands.Building
|
||||||
{
|
{
|
||||||
//[CustomCommand("MoveBlocks", "Move blocks from their original position")]
|
[CustomCommand("MoveBlocks", "Move all blocks (including ground) from their original position")]
|
||||||
|
[CustomCommand("MoveLastBlock", "Move last block from original position")]
|
||||||
class MoveBlocksCommandEngine : CustomCommandEngine
|
class MoveBlocksCommandEngine : CustomCommandEngine
|
||||||
{
|
{
|
||||||
public MoveBlocksCommandEngine(UnityContext<FullGameCompositionRoot> ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams)
|
public MoveBlocksCommandEngine(UnityContext<FullGameCompositionRoot> ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams)
|
||||||
|
@ -23,30 +24,134 @@ namespace ExtraCommands.Building
|
||||||
|
|
||||||
public override void Ready()
|
public override void Ready()
|
||||||
{
|
{
|
||||||
CustomCommandUtility.Register<float, float, float>("MoveBlocks", MoveBlocksCommand, "Move blocks from their original position");
|
CustomCommandUtility.Register<float, float, float>("MoveBlocks", MoveBlocksCommand, "Move all blocks (including ground) from their original position");
|
||||||
|
CustomCommandUtility.Register<float, float, float>("MoveLastBlock", MoveLastBlockCommand, "Move last block from original position");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Move every block by vector (x,y,z)
|
||||||
private void MoveBlocksCommand(float x, float y, float z)
|
private void MoveBlocksCommand(float x, float y, float z)
|
||||||
{
|
{
|
||||||
uint blockCount;
|
ref SimulationModeStateEntityStruct simMode = ref this.entitiesDB.QueryUniqueEntity<SimulationModeStateEntityStruct>(SimulationModeStateExclusiveGroups.GAME_STATE_GROUP);
|
||||||
PositionEntityStruct[] posStructs = this.entitiesDB.QueryEntities<PositionEntityStruct>(CommonExclusiveGroups.OWNED_BLOCKS_GROUP, out blockCount);
|
if (simMode.simulationMode != SimulationMode.Build)
|
||||||
for (uint i = 0; i < blockCount; i++)
|
|
||||||
{
|
{
|
||||||
ref PositionEntityStruct posStruct = ref posStructs[i];
|
uREPL.Log.Error("Blocks can only be moved in Build Mode");
|
||||||
if (!posStruct.Equals(null) && !posStruct.position.Equals(null))
|
return;
|
||||||
|
}
|
||||||
|
uint posCount, transCount, phyCount;
|
||||||
|
PositionEntityStruct[] posStructs = this.entitiesDB.QueryEntities<PositionEntityStruct>(CommonExclusiveGroups.OWNED_BLOCKS_GROUP, out posCount);
|
||||||
|
LocalTransformEntityStruct[] transStructs = this.entitiesDB.QueryEntities<LocalTransformEntityStruct>(CommonExclusiveGroups.OWNED_BLOCKS_GROUP, out transCount);
|
||||||
|
UECSPhysicsEntityStruct[] phyStructs = this.entitiesDB.QueryEntities<UECSPhysicsEntityStruct>(CommonExclusiveGroups.OWNED_BLOCKS_GROUP, out phyCount);
|
||||||
|
if (posCount != transCount || transCount != phyCount)
|
||||||
|
{
|
||||||
|
uREPL.Log.Error("Block lists returned are not the same length!"); // they're arrays, not lists
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (uint i = 0; i < posCount; i++)
|
||||||
|
{
|
||||||
|
ref PositionEntityStruct posStruct = ref posStructs[i]; // main (persistent) position
|
||||||
|
posStruct.position.x += x;
|
||||||
|
posStruct.position.y += y;
|
||||||
|
posStruct.position.z += z;
|
||||||
|
ref LocalTransformEntityStruct transStruct = ref transStructs[i]; // rendered position
|
||||||
|
transStruct.position.x += x;
|
||||||
|
transStruct.position.y += y;
|
||||||
|
transStruct.position.z += z;
|
||||||
|
ref UECSPhysicsEntityStruct phyStruct = ref phyStructs[i]; // collision position
|
||||||
|
this.physWorld.EntityManager.SetComponentData(phyStruct.uecsEntity, new Translation
|
||||||
{
|
{
|
||||||
posStruct.position.x += x;
|
Value = posStruct.position
|
||||||
posStruct.position.y += y;
|
});
|
||||||
posStruct.position.z += z;
|
}
|
||||||
} else {
|
uREPL.Log.Output($"Moved {posCount} blocks");
|
||||||
uREPL.Log.Warn("Null position found for position "+i);
|
}
|
||||||
|
|
||||||
|
// Move block with highest index by vector (x,y,z)
|
||||||
|
private void MoveLastBlockCommand(float x, float y, float z)
|
||||||
|
{
|
||||||
|
ref SimulationModeStateEntityStruct simMode = ref this.entitiesDB.QueryUniqueEntity<SimulationModeStateEntityStruct>(SimulationModeStateExclusiveGroups.GAME_STATE_GROUP);
|
||||||
|
if (simMode.simulationMode != SimulationMode.Build)
|
||||||
|
{
|
||||||
|
uREPL.Log.Error("Blocks can only be moved in Build Mode");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
uint posCount, transCount, phyCount;
|
||||||
|
PositionEntityStruct[] posStructs = this.entitiesDB.QueryEntities<PositionEntityStruct>(CommonExclusiveGroups.OWNED_BLOCKS_GROUP, out posCount);
|
||||||
|
LocalTransformEntityStruct[] transStructs = this.entitiesDB.QueryEntities<LocalTransformEntityStruct>(CommonExclusiveGroups.OWNED_BLOCKS_GROUP, out transCount);
|
||||||
|
UECSPhysicsEntityStruct[] phyStructs = this.entitiesDB.QueryEntities<UECSPhysicsEntityStruct>(CommonExclusiveGroups.OWNED_BLOCKS_GROUP, out phyCount);
|
||||||
|
if (posCount == 0 || transCount == 0 || phyCount == 0)
|
||||||
|
{
|
||||||
|
uREPL.Log.Error("No block found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ref PositionEntityStruct posStruct = ref posStructs[posCount-1]; // main (persistent) position
|
||||||
|
posStruct.position.x += x;
|
||||||
|
posStruct.position.y += y;
|
||||||
|
posStruct.position.z += z;
|
||||||
|
ref LocalTransformEntityStruct transStruct = ref transStructs[transCount-1]; // rendered position
|
||||||
|
transStruct.position.x += x;
|
||||||
|
transStruct.position.y += y;
|
||||||
|
transStruct.position.z += z;
|
||||||
|
ref UECSPhysicsEntityStruct phyStruct = ref phyStructs[phyCount-1]; // collision position
|
||||||
|
this.physWorld.EntityManager.SetComponentData(phyStruct.uecsEntity, new Translation
|
||||||
|
{
|
||||||
|
Value = posStruct.position
|
||||||
|
});
|
||||||
|
uREPL.Log.Output($"Moved block to ({posStruct.position.x},{posStruct.position.y},{posStruct.position.z})");
|
||||||
|
}
|
||||||
|
|
||||||
|
// unused; for future reference
|
||||||
|
private void ToggleMode()
|
||||||
|
{
|
||||||
|
ref SimulationModeStateEntityStruct ptr = ref this.entitiesDB.QueryUniqueEntity<SimulationModeStateEntityStruct>(SimulationModeStateExclusiveGroups.GAME_STATE_GROUP);
|
||||||
|
ref SimulationFrameEntityStruct ptr2 = ref this.entitiesDB.QueryUniqueEntity<SimulationFrameEntityStruct>(SimulationFrame.SimulationFrameGroup);
|
||||||
|
switch (ptr.simulationMode)
|
||||||
|
{
|
||||||
|
case SimulationMode.Build:
|
||||||
|
ptr.simulationMode = SimulationMode.SwitchToSim;
|
||||||
|
ptr.simulationModeChangeFrame = ptr2.simFrame;
|
||||||
|
return;
|
||||||
|
case SimulationMode.SwitchToSim:
|
||||||
|
case SimulationMode.SwitchToBuild:
|
||||||
|
return;
|
||||||
|
case SimulationMode.Simulation:
|
||||||
|
ptr.simulationMode = SimulationMode.SwitchToBuild;
|
||||||
|
ptr.simulationModeChangeFrame = ptr2.simFrame;
|
||||||
|
ptr.rigidBodiesCreated = false;
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// unused; for future reference
|
||||||
|
private IEnumerator<TaskContract> TriggerSwitchToSimTask()
|
||||||
|
{
|
||||||
|
this.ToggleMode();
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// unused; for future reference
|
||||||
|
private IEnumerator<TaskContract> WaitThenTriggerSwitchToBuildTask()
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
SimulationModeStateEntityStruct modeStruct = this.entitiesDB.QueryUniqueEntity<SimulationModeStateEntityStruct>(SimulationModeStateExclusiveGroups.GAME_STATE_GROUP);
|
||||||
|
if (modeStruct.simulationMode == SimulationMode.Simulation)
|
||||||
|
{
|
||||||
|
this.ToggleMode();
|
||||||
|
break;
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
yield return Yield.It;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
yield break;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Dispose()
|
public override void Dispose()
|
||||||
{
|
{
|
||||||
CustomCommandUtility.Unregister("MoveBlocks");
|
CustomCommandUtility.Unregister("MoveBlocks");
|
||||||
|
CustomCommandUtility.Unregister("MoveLastBlock");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue