Test fixes, block event Block property

Fixed Assert.Equal()
Changed tests to reflect changes
Added Block property to the block event args
Completely removed sync things
This commit is contained in:
Norbi Peti 2020-07-19 01:13:39 +02:00 committed by NGnius (Graham)
parent 5e335e78ff
commit 5264d98ce7
9 changed files with 12 additions and 91 deletions

View file

@ -342,10 +342,10 @@ namespace GamecraftModdingAPI
public bool Remove() => RemovalEngine.RemoveBlock(Id);
/// <summary>
/// Returns the rigid body of the cluster of blocks this one belongs to during simulation.
/// Returns the rigid body of the chunk of blocks this one belongs to during simulation.
/// Can be used to apply forces or move the block around while the simulation is running.
/// </summary>
/// <returns>The SimBody of the cluster or null if the block doesn't exist.</returns>
/// <returns>The SimBody of the chunk or null if the block doesn't exist.</returns>
public SimBody GetSimBody()
{
return BlockEngine.GetBlockInfo(this,

View file

@ -25,8 +25,6 @@ namespace GamecraftModdingAPI.Blocks
public bool isRemovable => false;
internal bool Synced = true;
public void Dispose()
{
}

View file

@ -13,14 +13,8 @@ namespace GamecraftModdingAPI.Blocks
public event EventHandler<BlockPlacedRemovedEventArgs> Placed;
public event EventHandler<BlockPlacedRemovedEventArgs> Removed;
public BlockEventsEngine()
{
//Console.WriteLine("Creating BlockEventsEngine\n" + Environment.StackTrace);
}
public void Ready()
{
//Console.WriteLine("BlockEventsEngine registered");
}
public EntitiesDB entitiesDB { get; set; }
@ -50,37 +44,12 @@ namespace GamecraftModdingAPI.Blocks
}
}
/*[HarmonyPatch]
public static class TestPatch
{
public static void Postfix(FasterDictionary<RefWrapper<Type>, FasterList<IEngine>> engines,
ExclusiveGroupStruct? previousGroup, in PlatformProfiler profiler, EGID egid)
{
if (!engines.TryGetValue(new RefWrapper<Type>(TypeSafeDictionary<TValue>._type), out result))
return;
}
public static MethodBase TargetMethod()
{
return AccessTools.Method("Svelto.ECS.Internal.TypeSafeDictionary:AddEntityComponentToEngines");
}
}*/
/*[HarmonyPatch]
public static class TestPatch
{
public static void Postfix(EGID basePartEGID)
{
Console.WriteLine("Patched Add method: " + basePartEGID);
}
public static MethodBase TargetMethod()
{
return AccessTools.Method("RobocraftX.CR.MachineEditing.BuildBlockAdditionalPartEngine:Add");
}
}*/
public struct BlockPlacedRemovedEventArgs
{
public EGID ID;
public BlockIDs Type;
private Block block;
public Block Block => block ?? (block = new Block(ID));
}
}

View file

@ -22,11 +22,11 @@ namespace GamecraftModdingAPI.Blocks
}
[APITestCase(TestType.EditMode)]
public static void TestSync()
public static void TestInitProperty()
{
Block newBlock = Block.PlaceNew(BlockIDs.AluminiumCube, Unity.Mathematics.float3.zero + 2);
if (!Assert.CloseTo(newBlock.Position, (Unity.Mathematics.float3.zero + 2), $"Newly placed block at {newBlock.Position} is expected at {Unity.Mathematics.float3.zero + 2}.", "Newly placed block position matches.")) return;
Assert.Equal(newBlock.Exists, true, "Newly placed block does not exist, possibly because Sync() skipped/missed/failed.", "Newly placed block exists, Sync() successful.");
//Assert.Equal(newBlock.Exists, true, "Newly placed block does not exist, possibly because Sync() skipped/missed/failed.", "Newly placed block exists, Sync() successful.");
}
[APITestCase(TestType.EditMode)]
@ -34,7 +34,7 @@ namespace GamecraftModdingAPI.Blocks
{
TextBlock textBlock = null; // Note: the assignment operation is a lambda, which slightly confuses the compiler
Assert.Errorless(() => { textBlock = Block.PlaceNew<TextBlock>(BlockIDs.TextBlock, Unity.Mathematics.float3.zero + 1); }, "Block.PlaceNew<TextBlock>() raised an exception: ", "Block.PlaceNew<TextBlock>() completed without issue.");
if (!Assert.NotNull(textBlock, "Block.Specialize<TextBlock>() returned null, possibly because it failed silently.", "Specialized TextBlock is not null.")) return;
if (!Assert.NotNull(textBlock, "Block.PlaceNew<TextBlock>() returned null, possibly because it failed silently.", "Specialized TextBlock is not null.")) return;
if (!Assert.NotNull(textBlock.Text, "TextBlock.Text is null, possibly because it failed silently.", "TextBlock.Text is not null.")) return;
if (!Assert.NotNull(textBlock.TextBlockId, "TextBlock.TextBlockId is null, possibly because it failed silently.", "TextBlock.TextBlockId is not null.")) return;
}

View file

@ -107,7 +107,6 @@ namespace GamecraftModdingAPI.Blocks
ref PickedBlockExtraDataStruct pickedBlock = ref entitiesDB.QueryEntity<PickedBlockExtraDataStruct>(playerEGID);
pickedBlock.placedBlockEntityID = structInitializer.EGID;
pickedBlock.placedBlockWasAPickedBlock = false;
Block.BlockEngine.Synced = false; // Block entities will need to be submitted before properties can be used
return structInitializer;
}

View file

@ -9,7 +9,7 @@ using RobocraftX.Physics;
namespace GamecraftModdingAPI
{
/// <summary>
/// A rigid body (like a cluster of connected blocks) during simulation.
/// A rigid body (like a chunk of connected blocks) during simulation.
/// </summary>
public class SimBody : IEquatable<SimBody>, IEquatable<EGID>
{

View file

@ -83,32 +83,12 @@ namespace GamecraftModdingAPI.Tests
{
if (err == null) err = $"{nameof(T)} '{obj1}' is not equal to '{obj2}'.";
if (success == null) success = $"{nameof(T)} '{obj1}' is equal to '{obj2}'.";
if (obj1 == null && obj2 == null)
if ((obj1 == null && obj2 == null)
|| (obj1 != null && obj2 != null && obj1.Equals(obj2) && obj2.Equals(obj1)))
{
// pass
Log(PASS + success);
TestRoot.TestsPassed = true;
return true;
}
else if (!(obj1 == null && obj2 == null) && obj1.Equals(obj2) && obj2.Equals(obj1))
{
// pass
Log(PASS + success);
TestRoot.TestsPassed = true;
return true;
}
else if (obj1 != null && (obj1 != null && !obj1.Equals(obj2)))
{
// pass
Log(PASS + success);
TestRoot.TestsPassed = true;
return true;
}
else if (obj2 != null && !obj2.Equals(obj1))
{
// pass
Log(PASS + success);
TestRoot.TestsPassed = true;
return true;
}
else

View file

@ -234,7 +234,7 @@ namespace GamecraftModdingAPI.Tests
CommandBuilder.Builder()
.Name("PlaceConsole")
.Description("Place a bunch of console block with a given text")
.Description("Place a bunch of console block with a given text - entering simulation with them crashes the game as the cmd doesn't exist")
.Action((float x, float y, float z) =>
{
Stopwatch sw = new Stopwatch();

View file

@ -1,25 +0,0 @@
using System;
using RobocraftX.StateSync;
using Svelto.ECS;
using HarmonyLib;
namespace GamecraftModdingAPI.Utility
{
[HarmonyPatch(typeof(DeterministicStepCompositionRoot), "ResetWorld")]
public static class DeterministicStepCompositionRootPatch
{
private static SimpleEntitiesSubmissionScheduler engineRootScheduler;
public static void Postfix(SimpleEntitiesSubmissionScheduler scheduler)
{
engineRootScheduler = scheduler;
}
internal static void SubmitEntitiesNow()
{
if (engineRootScheduler != null)
engineRootScheduler.SubmitEntities();
}
}
}