Reduce Sync() events

This commit is contained in:
NGnius (Graham) 2020-05-26 10:57:59 -04:00
parent e8ca1fe398
commit d0726b9514
3 changed files with 21 additions and 11 deletions

View file

@ -23,6 +23,6 @@ namespace Pixi.Robots
public float3 scale; public float3 scale;
public string placeholder; public string name;
} }
} }

View file

@ -331,7 +331,7 @@ namespace Pixi.Robots
if (!map.ContainsKey(cubeId)) if (!map.ContainsKey(cubeId))
{ {
result.block = BlockIDs.TextBlock; result.block = BlockIDs.TextBlock;
result.placeholder = "Unknown cube #" + cubeId.ToString(); result.name = "Unknown cube #" + cubeId.ToString();
//result.rotation = float3.zero; //result.rotation = float3.zero;
#if DEBUG #if DEBUG
Logging.MetaLog($"Unknown cubeId {cubeId}"); Logging.MetaLog($"Unknown cubeId {cubeId}");
@ -411,7 +411,7 @@ namespace Pixi.Robots
else else
{ {
result.block = BlockIDs.TextBlock; result.block = BlockIDs.TextBlock;
result.placeholder = cubeName; result.name = cubeName;
} }
} }
} }

View file

@ -58,16 +58,21 @@ namespace Pixi.Robots
float3 position = new Player(PlayerType.Local).Position; float3 position = new Player(PlayerType.Local).Position;
position.y += (float)blockSize; position.y += (float)blockSize;
CubeInfo[] cubes = CubeUtility.ParseCubes(robot.Value); CubeInfo[] cubes = CubeUtility.ParseCubes(robot.Value);
Block[] blocks = new Block[cubes.Length];
for (int c = 0; c < cubes.Length; c++) // sometimes I wish this were C++ for (int c = 0; c < cubes.Length; c++) // sometimes I wish this were C++
{ {
CubeInfo cube = cubes[c]; CubeInfo cube = cubes[c];
float3 realPosition = (cube.position * (float)blockSize) + position; float3 realPosition = (cube.position * (float)blockSize) + position;
Block newBlock = Block.PlaceNew(cube.block, realPosition, cube.rotation, cube.color, cube.darkness, scale: cube.scale); blocks[c] = Block.PlaceNew(cube.block, realPosition, cube.rotation, cube.color, cube.darkness, scale: cube.scale);
}
for (int c = 0; c < cubes.Length; c++)
{
CubeInfo cube = cubes[c];
// the goal is for this to never evaluate to true (ie all cubes are translated correctly) // the goal is for this to never evaluate to true (ie all cubes are translated correctly)
if (!string.IsNullOrEmpty(cube.placeholder) && cube.block == BlockIDs.TextBlock) if (!string.IsNullOrEmpty(cube.name) && cube.block == BlockIDs.TextBlock)
{ {
newBlock.Specialise<TextBlock>().Text = cube.placeholder; blocks[c].Specialise<TextBlock>().Text = cube.name;
} }
} }
Logging.CommandLog($"Placed {robot.Value.name} by {robot.Value.addedByDisplayName} ({cubes.Length} cubes) beside you"); Logging.CommandLog($"Placed {robot.Value.name} by {robot.Value.addedByDisplayName} ({cubes.Length} cubes) beside you");
} }
@ -97,15 +102,20 @@ namespace Pixi.Robots
float3 position = new Player(PlayerType.Local).Position; float3 position = new Player(PlayerType.Local).Position;
position.y += (float)blockSize; position.y += (float)blockSize;
CubeInfo[] cubes = CubeUtility.ParseCubes(robot); CubeInfo[] cubes = CubeUtility.ParseCubes(robot);
Block[] blocks = new Block[cubes.Length];
for (int c = 0; c < cubes.Length; c++) // sometimes I wish this were C++ for (int c = 0; c < cubes.Length; c++) // sometimes I wish this were C++
{ {
CubeInfo cube = cubes[c]; CubeInfo cube = cubes[c];
float3 realPosition = (cube.position * (float)blockSize) + position; float3 realPosition = (cube.position * (float)blockSize) + position;
Block newBlock = Block.PlaceNew(cube.block, realPosition, cube.rotation, cube.color, cube.darkness, scale: cube.scale); blocks[c] = Block.PlaceNew(cube.block, realPosition, cube.rotation, cube.color, cube.darkness, scale: cube.scale);
}
for (int c = 0; c < cubes.Length; c++)
{
CubeInfo cube = cubes[c];
// the goal is for this to never evaluate to true (ie all cubes are translated correctly) // the goal is for this to never evaluate to true (ie all cubes are translated correctly)
if (!string.IsNullOrEmpty(cube.placeholder) && cube.block == BlockIDs.TextBlock) if (!string.IsNullOrEmpty(cube.name) && cube.block == BlockIDs.TextBlock)
{ {
newBlock.Specialise<TextBlock>().Text = cube.placeholder; blocks[c].Specialise<TextBlock>().Text = cube.name;
} }
} }
Logging.CommandLog($"Placed {robot.name} by {robot.addedByDisplayName} ({cubes.Length} cubes) beside you"); Logging.CommandLog($"Placed {robot.name} by {robot.addedByDisplayName} ({cubes.Length} cubes) beside you");