Fix for changes in latest GC update

This commit is contained in:
NGnius 2019-11-29 20:11:36 -05:00
parent 0eb1ed511d
commit 383519f786
6 changed files with 25 additions and 105 deletions

View file

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using RobocraftX.GUI.CommandLine; using RobocraftX.GUI.CommandLine;
using RobocraftX.Multiplayer; using RobocraftX.Multiplayer;
using RobocraftX.StateSync; using RobocraftX.StateSync;
@ -8,11 +9,14 @@ using Unity.Entities;
using UnityEngine; using UnityEngine;
using uREPL; using uREPL;
using Svelto.Context; using Svelto.Context;
using Svelto.Tasks;
using Svelto.Tasks.ExtraLean;
using RobocraftX; using RobocraftX;
using RobocraftX.Schedulers;
namespace ExtraCommands.Basics namespace ExtraCommands.Basics
{ {
[CustomCommand] [CustomCommand("Chain")]
class ChainCommandEngine : CustomCommandEngine class ChainCommandEngine : CustomCommandEngine
{ {
public ChainCommandEngine(UnityContext<FullGameCompositionRoot> ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams) public ChainCommandEngine(UnityContext<FullGameCompositionRoot> ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams)
@ -22,75 +26,38 @@ namespace ExtraCommands.Basics
public override void Ready() public override void Ready()
{ {
CustomCommandUtility.Register<string, string>("Chain", ChainCommand, "Run two commands, one after the other"); CustomCommandUtility.Register<string, string>("Chain", ChainCommand, "Run two commands, one after the other");
CustomCommandUtility.Register<string, string>("ChainNoFail", ChainNoFailCommand, "Run two commands, one after the other even if the first one is invalid");
CustomCommandUtility.Register<string, string>("ChainQuiet", ChainQuietCommand, "Run two commands, one after the other quietly");
} }
private void ChainCommand(string command1, string command2) private void ChainCommand(string command1, string command2)
{ {
string command1a = decomma(command1); string command1a = decomma(command1);
string command2a = decomma(command2); string command2a = decomma(command2);
bool success1 = uREPL.Evaluator.Evaluate(command1a).type == CompileResult.Type.Success; ScheduleCommands(command1a, command2a).RunOn(ExtraLean.CharacterUpdateScheduler);
if (!success1) {
uREPL.Log.Error("First command was not executed successfully");
return;
}
bool success2 = uREPL.Evaluator.Evaluate(command2a).type == CompileResult.Type.Success;
if (!success2) {
uREPL.Log.Error("Second command was not executed successfully");
}
} }
private void ChainNoFailCommand(string command1, string command2) private IEnumerator<TaskContract> ScheduleCommands(string c1, string c2)
{ {
string command1a = decomma(command1); yield return Yield.It;
string command2a = decomma(command2); bool success1 = uREPL.Evaluator.Evaluate(c1).type == CompileResult.Type.Success;
bool success1 = uREPL.Evaluator.Evaluate(command1a).type == CompileResult.Type.Success; if (!success1)
if (!success1) { {
uREPL.Log.Error("First command was not executed successfully"); uREPL.Log.Error("First command was not executed successfully");
} }
bool success2 = uREPL.Evaluator.Evaluate(command2a).type == CompileResult.Type.Success; bool success2 = uREPL.Evaluator.Evaluate(c2).type == CompileResult.Type.Success;
if (!success2) { if (!success2)
{
uREPL.Log.Error("Second command was not executed successfully"); uREPL.Log.Error("Second command was not executed successfully");
} }
} }
private void ChainQuietCommand(string command1, string command2)
{
string command1a = decomma(command1);
string command2a = decomma(command2);
uREPL.Evaluator.Evaluate(command1a);
uREPL.Evaluator.Evaluate(command2a);
}
private string decomma(string strIn) private string decomma(string strIn)
{ {
string strOut = ""; return strIn.Replace(", ", " ");
bool wasCommaLast = false;
foreach (char c in strIn)
{
if (wasCommaLast)
{
wasCommaLast = false;
if (c == ' ')
{
strOut = strOut.Substring(0, strOut.Length - 1);
}
}
if (c == ',')
{
wasCommaLast = true;
}
strOut += c;
}
return strOut;
} }
public override void Dispose() public override void Dispose()
{ {
CustomCommandUtility.Unregister("Chain"); CustomCommandUtility.Unregister("Chain");
CustomCommandUtility.Unregister("ChainNoFail");
CustomCommandUtility.Unregister("ChainQuiet");
} }
} }
} }

View file

@ -49,6 +49,9 @@
<Reference Include="RobocraftX.MultiplayerInput"> <Reference Include="RobocraftX.MultiplayerInput">
<HintPath>..\ref\RobocraftX.MultiplayerInput.dll</HintPath> <HintPath>..\ref\RobocraftX.MultiplayerInput.dll</HintPath>
</Reference> </Reference>
<Reference Include="RobocraftX.Physics">
<HintPath>..\ref\RobocraftX.Physics.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.StateSync"> <Reference Include="RobocraftX.StateSync">
<HintPath>..\ref\RobocraftX.StateSync.dll</HintPath> <HintPath>..\ref\RobocraftX.StateSync.dll</HintPath>
</Reference> </Reference>

View file

@ -14,7 +14,7 @@ namespace ExtraCommands
public string Name { get; } = "ExtraCommands"; public string Name { get; } = "ExtraCommands";
public string Version { get; } = "v0.0.1"; public string Version { get; } = "v0.0.3";
public string HarmonyID { get; } = "org.git.exmods.extracommands.extracommands"; public string HarmonyID { get; } = "org.git.exmods.extracommands.extracommands";

View file

@ -104,7 +104,7 @@ namespace ExtraCommands.Building
uint connectedBlockID = cubeStack.Pop(); uint connectedBlockID = cubeStack.Pop();
processedCubes.Add(connectedBlockID); processedCubes.Add(connectedBlockID);
ScalingEntityStruct scale = entitiesDB.QueryEntity<ScalingEntityStruct>(connectedBlockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP); ScalingEntityStruct scale = entitiesDB.QueryEntity<ScalingEntityStruct>(connectedBlockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP);
uREPL.Log.Output($"Catching {connectedBlockID} with scale {scale.scale}"); //uREPL.Log.Output($"Catching {connectedBlockID} with scale {scale.scale}");
blockConnections = entitiesDB.QueryEntity<GridConnectionsEntityStruct>(connectedBlockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP); blockConnections = entitiesDB.QueryEntity<GridConnectionsEntityStruct>(connectedBlockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP);
connections = entitiesDB.QueryEntities<MachineGraphConnectionEntityStruct>(blockConnections.connectionGroup, out count); connections = entitiesDB.QueryEntities<MachineGraphConnectionEntityStruct>(blockConnections.connectionGroup, out count);
@ -115,7 +115,7 @@ namespace ExtraCommands.Building
&& (conn.oppositeConnectionEgid.entityID != 0u && (conn.oppositeConnectionEgid.entityID != 0u
|| conn.oppositeConnectionEgid.entityID != conn.connectedBlock.entityID)) || conn.oppositeConnectionEgid.entityID != conn.connectedBlock.entityID))
{ {
uREPL.Log.Output($"Block {connectedBlockID} connects to {conn.connectedBlock.entityID} (opposite {conn.oppositeConnectionEgid.entityID})"); //uREPL.Log.Output($"Block {connectedBlockID} connects to {conn.connectedBlock.entityID} (opposite {conn.oppositeConnectionEgid.entityID})");
cubeStack.Push(conn.connectedBlock.entityID); cubeStack.Push(conn.connectedBlock.entityID);
} }
} }
@ -124,59 +124,10 @@ namespace ExtraCommands.Building
{ {
TranslateSingleBlock(id, translationVector); TranslateSingleBlock(id, translationVector);
} }
uREPL.Log.Output($"Found {processedCubes.Count} connected blocks"); //uREPL.Log.Output($"Found {processedCubes.Count} connected blocks");
return this.entitiesDB.QueryEntity<PositionEntityStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP).position; return this.entitiesDB.QueryEntity<PositionEntityStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP).position;
} }
// 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");

View file

@ -102,15 +102,13 @@ namespace ExtraCommands.Building
switch (ptr.simulationMode) switch (ptr.simulationMode)
{ {
case SimulationMode.Build: case SimulationMode.Build:
ptr.simulationMode = SimulationMode.SwitchToSim; ptr.nextSimulationMode = SimulationMode.SwitchToSim;
ptr.simulationModeChangeFrame = ptr2.simFrame;
return; return;
case SimulationMode.SwitchToSim: case SimulationMode.SwitchToSim:
case SimulationMode.SwitchToBuild: case SimulationMode.SwitchToBuild:
return; return;
case SimulationMode.Simulation: case SimulationMode.Simulation:
ptr.simulationMode = SimulationMode.SwitchToBuild; ptr.nextSimulationMode = SimulationMode.SwitchToBuild;
ptr.simulationModeChangeFrame = ptr2.simFrame;
ptr.rigidBodiesCreated = false; ptr.rigidBodiesCreated = false;
return; return;
default: default:

View file

@ -9,6 +9,7 @@ using Unity.Entities;
using uREPL; using uREPL;
using Svelto.Context; using Svelto.Context;
using RobocraftX; using RobocraftX;
using RobocraftX.Physics;
namespace ExtraCommands.Waypoints namespace ExtraCommands.Waypoints
{ {