From f403feb298ff9b6f8d385069229ca79700a0a477 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sat, 11 Jul 2020 00:30:58 +0200 Subject: [PATCH] Update to Gamecraft 2020.06.17.08.41 (preview) Removed BlockIdentifiers.OWNED_BLOCKS as the original got replaced with an array Added the correct group for each supported functional block Removed EntityFactory property from IEntitySerializer as it is provided on deserialization --- .../App/GameBuildSimEventEngine.cs | 8 +++--- GamecraftModdingAPI/App/GameGameEngine.cs | 28 ++++++++----------- GamecraftModdingAPI/Block.cs | 12 ++++---- GamecraftModdingAPI/Blocks/BlockEngine.cs | 25 +++++++++-------- .../Blocks/BlockIdentifiers.cs | 8 +++--- GamecraftModdingAPI/Blocks/ConsoleBlock.cs | 3 +- GamecraftModdingAPI/Blocks/Motor.cs | 3 +- GamecraftModdingAPI/Blocks/MovementEngine.cs | 16 +++++------ .../Blocks/ObjectIdentifier.cs | 3 +- GamecraftModdingAPI/Blocks/Piston.cs | 3 +- GamecraftModdingAPI/Blocks/PlacementEngine.cs | 19 ++----------- GamecraftModdingAPI/Blocks/RotationEngine.cs | 16 +++++------ GamecraftModdingAPI/Blocks/Servo.cs | 3 +- GamecraftModdingAPI/Blocks/SignalEngine.cs | 22 +++++---------- GamecraftModdingAPI/Blocks/SpawnPoint.cs | 3 +- GamecraftModdingAPI/Blocks/TextBlock.cs | 3 +- GamecraftModdingAPI/Blocks/Timer.cs | 3 +- .../Events/GameStateBuildEmitterEngine.cs | 4 +-- .../GameStateSimulationEmitterEngine.cs | 4 +-- .../GamecraftModdingAPI.csproj | 4 --- .../Persistence/IEntitySerializer.cs | 8 +----- .../Persistence/SerializerManager.cs | 3 -- .../Persistence/SimpleEntitySerializer.cs | 6 ++-- GamecraftModdingAPI/Player.cs | 4 +-- GamecraftModdingAPI/Players/PlayerEngine.cs | 8 +++--- 25 files changed, 93 insertions(+), 126 deletions(-) diff --git a/GamecraftModdingAPI/App/GameBuildSimEventEngine.cs b/GamecraftModdingAPI/App/GameBuildSimEventEngine.cs index b4bc049..4c9a536 100644 --- a/GamecraftModdingAPI/App/GameBuildSimEventEngine.cs +++ b/GamecraftModdingAPI/App/GameBuildSimEventEngine.cs @@ -26,16 +26,16 @@ namespace GamecraftModdingAPI.App public void Ready() { } - public JobHandle OnInitializeTimeRunningMode() + public JobHandle OnInitializeTimeRunningMode(JobHandle inputDeps) { ExceptionUtil.InvokeEvent(SimulationMode, this, new GameEventArgs { GameName = GameMode.SaveGameDetails.Name, GamePath = GameMode.SaveGameDetails.Folder }); - return default(JobHandle); + return inputDeps; } - public JobHandle OnInitializeTimeStoppedMode() + public JobHandle OnInitializeTimeStoppedMode(JobHandle inputDeps) { ExceptionUtil.InvokeEvent(BuildMode, this, new GameEventArgs { GameName = GameMode.SaveGameDetails.Name, GamePath = GameMode.SaveGameDetails.Folder }); - return default(JobHandle); + return inputDeps; } } diff --git a/GamecraftModdingAPI/App/GameGameEngine.cs b/GamecraftModdingAPI/App/GameGameEngine.cs index cbb1c79..a616df5 100644 --- a/GamecraftModdingAPI/App/GameGameEngine.cs +++ b/GamecraftModdingAPI/App/GameGameEngine.cs @@ -97,28 +97,22 @@ namespace GamecraftModdingAPI.App public EGID[] GetAllBlocksInGame(BlockIDs filter = BlockIDs.Invalid) { - EntityCollection blocks = entitiesDB.QueryEntities(CommonExclusiveGroups.OWNED_BLOCKS_GROUP); + var allBlocks = entitiesDB.QueryEntities(); + List blockEGIDs = new List(); if (filter == BlockIDs.Invalid) { - EGID[] blockEGIDs = new EGID[blocks.count]; - for (uint b = 0; b < blocks.count; b++) - { - blockEGIDs[b] = blocks[b].ID; - } - return blockEGIDs; + foreach (var (blocks, _) in allBlocks) + foreach (var block in blocks) + blockEGIDs.Add(block.ID); + return blockEGIDs.ToArray(); } else { - uint dbidFilter = (uint)filter; - List blockEGIDs = new List(); - for (uint b = 0; b < blocks.count; b++) - { - if (blocks[b].DBID == dbidFilter) - { - blockEGIDs.Add(blocks[b].ID); - } - } - return blockEGIDs.ToArray(); + foreach (var (blocks, _) in allBlocks) + foreach (var block in blocks) + if (block.DBID == (ulong) filter) + blockEGIDs.Add(block.ID); + return blockEGIDs.ToArray(); } } } diff --git a/GamecraftModdingAPI/Block.cs b/GamecraftModdingAPI/Block.cs index f97c57c..939d16c 100644 --- a/GamecraftModdingAPI/Block.cs +++ b/GamecraftModdingAPI/Block.cs @@ -135,8 +135,8 @@ namespace GamecraftModdingAPI Id = id; } - public Block(uint id) : this(new EGID(id, CommonExclusiveGroups.OWNED_BLOCKS_GROUP)) - { + public Block(uint id) : this(new EGID(id, CommonExclusiveGroups.BUILD_STANDARD_BLOCK_GROUP)) + { //TODO: Figure out the block group based on the id } public EGID Id { get; } @@ -147,10 +147,10 @@ namespace GamecraftModdingAPI /// public float3 Position { - get => Exists ? MovementEngine.GetPosition(Id.entityID) : float3.zero; + get => Exists ? MovementEngine.GetPosition(Id) : float3.zero; set { - if (Exists) MovementEngine.MoveBlock(Id.entityID, value); + if (Exists) MovementEngine.MoveBlock(Id, value); } } @@ -159,10 +159,10 @@ namespace GamecraftModdingAPI /// public float3 Rotation { - get => Exists ? RotationEngine.GetRotation(Id.entityID) : float3.zero; + get => Exists ? RotationEngine.GetRotation(Id) : float3.zero; set { - if (Exists) RotationEngine.RotateBlock(Id.entityID, value); + if (Exists) RotationEngine.RotateBlock(Id, value); } } diff --git a/GamecraftModdingAPI/Blocks/BlockEngine.cs b/GamecraftModdingAPI/Blocks/BlockEngine.cs index 3473106..4a90de7 100644 --- a/GamecraftModdingAPI/Blocks/BlockEngine.cs +++ b/GamecraftModdingAPI/Blocks/BlockEngine.cs @@ -38,14 +38,15 @@ namespace GamecraftModdingAPI.Blocks public Block[] GetConnectedBlocks(EGID blockID) { if (!BlockExists(blockID)) return new Block[0]; - Stack cubeStack = new Stack(); - FasterList cubes = new FasterList(10); - var coll = entitiesDB.QueryEntities(CommonExclusiveGroups - .OWNED_BLOCKS_GROUP); - for (int i = 0; i < coll.count; i++) - coll[i].isProcessed = false; + Stack cubeStack = new Stack(); + FasterList cubes = new FasterList(10); + var coll = entitiesDB.QueryEntities(); + foreach (var (ecoll, _) in coll) + foreach (ref var conn in ecoll) + conn.isProcessed = false; - ConnectedCubesUtility.TreeTraversal.GetConnectedCubes(entitiesDB, blockID.entityID, cubeStack, cubes, (in GridConnectionsEntityStruct g) => { return false; }); + ConnectedCubesUtility.TreeTraversal.GetConnectedCubes(entitiesDB, blockID, cubeStack, cubes, + (in GridConnectionsEntityStruct g) => { return false; }); var ret = new Block[cubes.count]; for (int i = 0; i < cubes.count; i++) @@ -125,10 +126,10 @@ namespace GamecraftModdingAPI.Blocks public SimBody[] GetSimBodiesFromID(byte id) { var ret = new FasterList(4); - if (!entitiesDB.HasAny(CommonExclusiveGroups.OWNED_BLOCKS_GROUP)) + if (!entitiesDB.HasAny(CommonExclusiveGroups.BUILD_OBJID_BLOCK_GROUP)) return new SimBody[0]; - var oids = entitiesDB.QueryEntities(CommonExclusiveGroups.OWNED_BLOCKS_GROUP); - var connections = entitiesDB.QueryMappedEntities(CommonExclusiveGroups.OWNED_BLOCKS_GROUP); + var oids = entitiesDB.QueryEntities(CommonExclusiveGroups.BUILD_OBJID_BLOCK_GROUP); + var connections = entitiesDB.QueryMappedEntities(CommonExclusiveGroups.BUILD_OBJID_BLOCK_GROUP); foreach (ref ObjectIdEntityStruct oid in oids) { if (oid.objectId != id) continue; @@ -147,9 +148,9 @@ namespace GamecraftModdingAPI.Blocks public ObjectIdentifier[] GetObjectIDsFromID(byte id, bool sim) { var ret = new FasterList(4); - if (!entitiesDB.HasAny(CommonExclusiveGroups.OWNED_BLOCKS_GROUP)) + if (!entitiesDB.HasAny(CommonExclusiveGroups.BUILD_OBJID_BLOCK_GROUP)) return new ObjectIdentifier[0]; - var oids = entitiesDB.QueryEntities(CommonExclusiveGroups.OWNED_BLOCKS_GROUP); + var oids = entitiesDB.QueryEntities(CommonExclusiveGroups.BUILD_OBJID_BLOCK_GROUP); foreach (ref ObjectIdEntityStruct oid in oids) if (sim ? oid.simObjectId == id : oid.objectId == id) ret.Add(new ObjectIdentifier(oid.ID)); diff --git a/GamecraftModdingAPI/Blocks/BlockIdentifiers.cs b/GamecraftModdingAPI/Blocks/BlockIdentifiers.cs index eb479c0..0c3222b 100644 --- a/GamecraftModdingAPI/Blocks/BlockIdentifiers.cs +++ b/GamecraftModdingAPI/Blocks/BlockIdentifiers.cs @@ -12,8 +12,8 @@ namespace GamecraftModdingAPI.Blocks { /// /// Blocks placed by the player - /// - public static ExclusiveGroup OWNED_BLOCKS { get { return CommonExclusiveGroups.OWNED_BLOCKS_GROUP; } } + /// - TODO + //public static ExclusiveGroup OWNED_BLOCKS { get { return CommonExclusiveGroups.REAL_BLOCKS_GROUPS_DON_T_USE_IN_NEW_CODE; } } /// /// Extra parts used in functional blocks @@ -23,7 +23,7 @@ namespace GamecraftModdingAPI.Blocks /// /// Blocks which are disabled in Simulation mode /// - public static ExclusiveGroup SIM_BLOCKS_DISABLED { get { return CommonExclusiveGroups.BLOCKS_DISABLED_IN_SIM_GROUP; } } + public static ExclusiveGroup SIM_BLOCKS_DISABLED { get { return CommonExclusiveGroups.DISABLED_JOINTS_IN_SIM_GROUP; } } //public static ExclusiveGroup SPAWN_POINTS { get { return CommonExclusiveGroups.SPAWN_POINTS_GROUP; } } @@ -34,7 +34,7 @@ namespace GamecraftModdingAPI.Blocks /// public static uint LatestBlockID { get - { + { //Need the private field as the property increments itself return ((uint) AccessTools.Field(typeof(CommonExclusiveGroups), "_nextBlockEntityID").GetValue(null)) - 1; } } diff --git a/GamecraftModdingAPI/Blocks/ConsoleBlock.cs b/GamecraftModdingAPI/Blocks/ConsoleBlock.cs index 173b3f6..6d4217d 100644 --- a/GamecraftModdingAPI/Blocks/ConsoleBlock.cs +++ b/GamecraftModdingAPI/Blocks/ConsoleBlock.cs @@ -1,6 +1,7 @@ using System; using RobocraftX.Blocks; +using RobocraftX.Common; using Svelto.ECS; using Unity.Mathematics; @@ -33,7 +34,7 @@ namespace GamecraftModdingAPI.Blocks } } - public ConsoleBlock(uint id): base(id) + public ConsoleBlock(uint id): base(new EGID(id, CommonExclusiveGroups.BUILD_CONSOLE_BLOCK_GROUP)) { if (!BlockEngine.GetBlockInfoExists(this.Id)) { diff --git a/GamecraftModdingAPI/Blocks/Motor.cs b/GamecraftModdingAPI/Blocks/Motor.cs index c900f10..55f3649 100644 --- a/GamecraftModdingAPI/Blocks/Motor.cs +++ b/GamecraftModdingAPI/Blocks/Motor.cs @@ -1,6 +1,7 @@ using System; using RobocraftX.Blocks; +using RobocraftX.Common; using Svelto.ECS; using Unity.Mathematics; @@ -41,7 +42,7 @@ namespace GamecraftModdingAPI.Blocks } } - public Motor(uint id) : base(id) + public Motor(uint id): base(new EGID(id, CommonExclusiveGroups.BUILD_MOTOR_BLOCK_GROUP)) { if (!BlockEngine.GetBlockInfoExists(this.Id)) { diff --git a/GamecraftModdingAPI/Blocks/MovementEngine.cs b/GamecraftModdingAPI/Blocks/MovementEngine.cs index a887763..0ff119a 100644 --- a/GamecraftModdingAPI/Blocks/MovementEngine.cs +++ b/GamecraftModdingAPI/Blocks/MovementEngine.cs @@ -35,12 +35,12 @@ namespace GamecraftModdingAPI.Blocks // implementations for Movement static class - public float3 MoveBlock(uint blockID, float3 vector) + public float3 MoveBlock(EGID blockID, float3 vector) { - ref PositionEntityStruct posStruct = ref this.entitiesDB.QueryEntity(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP); - ref GridRotationStruct gridStruct = ref this.entitiesDB.QueryEntity(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP); - ref LocalTransformEntityStruct transStruct = ref this.entitiesDB.QueryEntity(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP); - ref UECSPhysicsEntityStruct phyStruct = ref this.entitiesDB.QueryEntity(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP); + ref PositionEntityStruct posStruct = ref this.entitiesDB.QueryEntity(blockID); + ref GridRotationStruct gridStruct = ref this.entitiesDB.QueryEntity(blockID); + ref LocalTransformEntityStruct transStruct = ref this.entitiesDB.QueryEntity(blockID); + ref UECSPhysicsEntityStruct phyStruct = ref this.entitiesDB.QueryEntity(blockID); // main (persistent) position posStruct.position = vector; // placement grid position @@ -52,13 +52,13 @@ namespace GamecraftModdingAPI.Blocks { Value = posStruct.position }); - entitiesDB.QueryEntity(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP).isProcessed = false; + entitiesDB.QueryEntity(blockID).isProcessed = false; return posStruct.position; } - public float3 GetPosition(uint blockID) + public float3 GetPosition(EGID blockID) { - ref PositionEntityStruct posStruct = ref this.entitiesDB.QueryEntity(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP); + ref PositionEntityStruct posStruct = ref this.entitiesDB.QueryEntity(blockID); return posStruct.position; } } diff --git a/GamecraftModdingAPI/Blocks/ObjectIdentifier.cs b/GamecraftModdingAPI/Blocks/ObjectIdentifier.cs index 6357053..9af96c2 100644 --- a/GamecraftModdingAPI/Blocks/ObjectIdentifier.cs +++ b/GamecraftModdingAPI/Blocks/ObjectIdentifier.cs @@ -1,4 +1,5 @@ using Gamecraft.Wires; +using RobocraftX.Common; using Svelto.ECS; namespace GamecraftModdingAPI.Blocks @@ -13,7 +14,7 @@ namespace GamecraftModdingAPI.Blocks } } - public ObjectIdentifier(uint id) : base(id) + public ObjectIdentifier(uint id) : base(new EGID(id, CommonExclusiveGroups.BUILD_OBJID_BLOCK_GROUP)) { if (!BlockEngine.GetBlockInfoExists(Id)) { diff --git a/GamecraftModdingAPI/Blocks/Piston.cs b/GamecraftModdingAPI/Blocks/Piston.cs index 00ad273..b96a806 100644 --- a/GamecraftModdingAPI/Blocks/Piston.cs +++ b/GamecraftModdingAPI/Blocks/Piston.cs @@ -5,6 +5,7 @@ using Svelto.ECS; using Unity.Mathematics; using GamecraftModdingAPI.Utility; +using RobocraftX.Common; namespace GamecraftModdingAPI.Blocks { @@ -41,7 +42,7 @@ namespace GamecraftModdingAPI.Blocks } } - public Piston(uint id) : base(id) + public Piston(uint id) : base(new EGID(id, CommonExclusiveGroups.BUILD_PISTON_BLOCK_GROUP)) { if (!BlockEngine.GetBlockInfoExists(this.Id)) { diff --git a/GamecraftModdingAPI/Blocks/PlacementEngine.cs b/GamecraftModdingAPI/Blocks/PlacementEngine.cs index 35f0a92..2297d90 100644 --- a/GamecraftModdingAPI/Blocks/PlacementEngine.cs +++ b/GamecraftModdingAPI/Blocks/PlacementEngine.cs @@ -66,8 +66,6 @@ namespace GamecraftModdingAPI.Blocks RotationEntityStruct rotation = new RotationEntityStruct {rotation = rotQ}; GridRotationStruct gridRotation = new GridRotationStruct {position = position, rotation = rotQ}; - CubeCategoryStruct category = new CubeCategoryStruct - {category = CubeCategory.General, type = CubeType.Block}; DBEntityStruct dbEntity = new DBEntityStruct {DBID = dbid}; BlockPlacementScaleEntityStruct placementScale = new BlockPlacementScaleEntityStruct { @@ -76,21 +74,10 @@ namespace GamecraftModdingAPI.Blocks unitSnapOffset = 0, isUsingUnitSize = true }; EquippedColourStruct colour = new EquippedColourStruct {indexInPalette = color}; - EGID newBlockID; - switch (category.category) - { - case CubeCategory.SpawnPoint: - case CubeCategory.BuildingSpawnPoint: - newBlockID = MachineEditingGroups.NewUncheckedBlockEGID; - break; - default: - newBlockID = MachineEditingGroups.NewBlockID; - break; - } EntityComponentInitializer structInitializer = - _blockEntityFactory.Build(newBlockID, dbid); //The ghost block index is only used for triggers + _blockEntityFactory.Build(CommonExclusiveGroups.nextBlockEntityID, dbid); //The ghost block index is only used for triggers if (colour.indexInPalette != byte.MaxValue) structInitializer.Init(new ColourParameterEntityStruct { @@ -117,10 +104,10 @@ namespace GamecraftModdingAPI.Blocks PrimaryRotationUtility.InitialisePrimaryDirection(rotation.rotation, ref structInitializer); EGID playerEGID = new EGID(playerId, CharacterExclusiveGroups.OnFootGroup); ref PickedBlockExtraDataStruct pickedBlock = ref entitiesDB.QueryEntity(playerEGID); - pickedBlock.placedBlockEntityID = 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 newBlockID; + return structInitializer.EGID; } public string Name { get; } = "GamecraftModdingAPIPlacementGameEngine"; diff --git a/GamecraftModdingAPI/Blocks/RotationEngine.cs b/GamecraftModdingAPI/Blocks/RotationEngine.cs index 88c43d2..e9cd1ef 100644 --- a/GamecraftModdingAPI/Blocks/RotationEngine.cs +++ b/GamecraftModdingAPI/Blocks/RotationEngine.cs @@ -35,12 +35,12 @@ namespace GamecraftModdingAPI.Blocks // implementations for Rotation static class - public float3 RotateBlock(uint blockID, Vector3 vector) + public float3 RotateBlock(EGID blockID, Vector3 vector) { - ref RotationEntityStruct rotStruct = ref this.entitiesDB.QueryEntity(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP); - ref GridRotationStruct gridStruct = ref this.entitiesDB.QueryEntity(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP); - ref LocalTransformEntityStruct transStruct = ref this.entitiesDB.QueryEntity(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP); - ref UECSPhysicsEntityStruct phyStruct = ref this.entitiesDB.QueryEntity(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP); + ref RotationEntityStruct rotStruct = ref this.entitiesDB.QueryEntity(blockID); + ref GridRotationStruct gridStruct = ref this.entitiesDB.QueryEntity(blockID); + ref LocalTransformEntityStruct transStruct = ref this.entitiesDB.QueryEntity(blockID); + ref UECSPhysicsEntityStruct phyStruct = ref this.entitiesDB.QueryEntity(blockID); // main (persistent) position Quaternion newRotation = (Quaternion)rotStruct.rotation; newRotation.eulerAngles += vector; @@ -58,14 +58,14 @@ namespace GamecraftModdingAPI.Blocks { Value = rotStruct.rotation }); - entitiesDB.QueryEntity(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP).isProcessed = false; + entitiesDB.QueryEntity(blockID).isProcessed = false; return ((Quaternion)rotStruct.rotation).eulerAngles; } - public float3 GetRotation(uint blockID) + public float3 GetRotation(EGID blockID) { - ref RotationEntityStruct rotStruct = ref entitiesDB.QueryEntity(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP); + ref RotationEntityStruct rotStruct = ref entitiesDB.QueryEntity(blockID); return ((Quaternion) rotStruct.rotation).eulerAngles; } } diff --git a/GamecraftModdingAPI/Blocks/Servo.cs b/GamecraftModdingAPI/Blocks/Servo.cs index 9a66e3b..ef7225b 100644 --- a/GamecraftModdingAPI/Blocks/Servo.cs +++ b/GamecraftModdingAPI/Blocks/Servo.cs @@ -1,6 +1,7 @@ using System; using RobocraftX.Blocks; +using RobocraftX.Common; using Svelto.ECS; using Unity.Mathematics; @@ -41,7 +42,7 @@ namespace GamecraftModdingAPI.Blocks } } - public Servo(uint id) : base(id) + public Servo(uint id) : base(new EGID(id, CommonExclusiveGroups.BUILD_SERVO_BLOCK_GROUP)) { if (!BlockEngine.GetBlockInfoExists(this.Id)) { diff --git a/GamecraftModdingAPI/Blocks/SignalEngine.cs b/GamecraftModdingAPI/Blocks/SignalEngine.cs index b36e708..13a0b3b 100644 --- a/GamecraftModdingAPI/Blocks/SignalEngine.cs +++ b/GamecraftModdingAPI/Blocks/SignalEngine.cs @@ -1,4 +1,5 @@ using Svelto.ECS; +using Svelto.DataStructures; using Gamecraft.Wires; using GamecraftModdingAPI.Engines; @@ -166,21 +167,12 @@ namespace GamecraftModdingAPI.Blocks } public EGID[] GetElectricBlocks() - { - uint count = entitiesDB.Count(BlockIdentifiers.OWNED_BLOCKS) + entitiesDB.Count(BlockIdentifiers.FUNCTIONAL_BLOCK_PARTS); - uint i = 0; - EGID[] res = new EGID[count]; - foreach (ref BlockPortsStruct s in entitiesDB.QueryEntities(BlockIdentifiers.OWNED_BLOCKS)) - { - res[i] = s.ID; - i++; - } - foreach (ref BlockPortsStruct s in entitiesDB.QueryEntities(BlockIdentifiers.FUNCTIONAL_BLOCK_PARTS)) - { - res[i] = s.ID; - i++; - } - return res; + { + var res = new FasterList(); + foreach (var (coll, _) in entitiesDB.QueryEntities()) + foreach (ref BlockPortsStruct s in coll) + res.Add(s.ID); + return res.ToArray(); } private EntityCollection GetSignalStruct(uint signalID, out uint index, bool input = true) diff --git a/GamecraftModdingAPI/Blocks/SpawnPoint.cs b/GamecraftModdingAPI/Blocks/SpawnPoint.cs index bb3e7f4..65ef750 100644 --- a/GamecraftModdingAPI/Blocks/SpawnPoint.cs +++ b/GamecraftModdingAPI/Blocks/SpawnPoint.cs @@ -1,6 +1,7 @@ using System; using RobocraftX.Blocks; +using RobocraftX.Common; using Gamecraft.CharacterVulnerability; using Svelto.ECS; using Unity.Mathematics; @@ -43,7 +44,7 @@ namespace GamecraftModdingAPI.Blocks } } - public SpawnPoint(uint id) : base(id) + public SpawnPoint(uint id) : base(new EGID(id, CommonExclusiveGroups.BUILD_SPAWNPOINT_BLOCK_GROUP)) { if (!BlockEngine.GetBlockInfoExists(this.Id)) { diff --git a/GamecraftModdingAPI/Blocks/TextBlock.cs b/GamecraftModdingAPI/Blocks/TextBlock.cs index 92f8116..c1a9344 100644 --- a/GamecraftModdingAPI/Blocks/TextBlock.cs +++ b/GamecraftModdingAPI/Blocks/TextBlock.cs @@ -1,6 +1,7 @@ using System; using Gamecraft.Blocks.GUI; +using RobocraftX.Common; using Svelto.ECS; using Unity.Mathematics; @@ -34,7 +35,7 @@ namespace GamecraftModdingAPI.Blocks } } - public TextBlock(uint id) : base(id) + public TextBlock(uint id) : base(new EGID(id, CommonExclusiveGroups.BUILD_TEXT_BLOCK_GROUP)) { if (!BlockEngine.GetBlockInfoExists(this.Id)) { diff --git a/GamecraftModdingAPI/Blocks/Timer.cs b/GamecraftModdingAPI/Blocks/Timer.cs index d26620e..0e7f744 100644 --- a/GamecraftModdingAPI/Blocks/Timer.cs +++ b/GamecraftModdingAPI/Blocks/Timer.cs @@ -1,6 +1,7 @@ using System; using RobocraftX.Blocks; +using RobocraftX.Common; using Gamecraft.Blocks.TimerBlock; using Svelto.ECS; using Unity.Mathematics; @@ -37,7 +38,7 @@ namespace GamecraftModdingAPI.Blocks } } - public Timer(uint id) : base(id) + public Timer(uint id) : base(new EGID(id, CommonExclusiveGroups.BUILD_TIMER_BLOCK_GROUP)) { if (!BlockEngine.GetBlockInfoExists(this.Id)) { diff --git a/GamecraftModdingAPI/Events/GameStateBuildEmitterEngine.cs b/GamecraftModdingAPI/Events/GameStateBuildEmitterEngine.cs index ed89812..a12433a 100644 --- a/GamecraftModdingAPI/Events/GameStateBuildEmitterEngine.cs +++ b/GamecraftModdingAPI/Events/GameStateBuildEmitterEngine.cs @@ -43,10 +43,10 @@ namespace GamecraftModdingAPI.Events } } - public JobHandle OnInitializeTimeStoppedMode() + public JobHandle OnInitializeTimeStoppedMode(JobHandle inputDeps) { Emit(); - return default(JobHandle); + return inputDeps; } public void Ready() { } diff --git a/GamecraftModdingAPI/Events/GameStateSimulationEmitterEngine.cs b/GamecraftModdingAPI/Events/GameStateSimulationEmitterEngine.cs index 165e7c5..5689db9 100644 --- a/GamecraftModdingAPI/Events/GameStateSimulationEmitterEngine.cs +++ b/GamecraftModdingAPI/Events/GameStateSimulationEmitterEngine.cs @@ -42,10 +42,10 @@ namespace GamecraftModdingAPI.Events } } - public JobHandle OnInitializeTimeRunningMode() + public JobHandle OnInitializeTimeRunningMode(JobHandle inputDeps) { Emit(); - return default(JobHandle); + return inputDeps; } public void Ready() { } diff --git a/GamecraftModdingAPI/GamecraftModdingAPI.csproj b/GamecraftModdingAPI/GamecraftModdingAPI.csproj index 199eed6..29cc08f 100644 --- a/GamecraftModdingAPI/GamecraftModdingAPI.csproj +++ b/GamecraftModdingAPI/GamecraftModdingAPI.csproj @@ -80,10 +80,6 @@ ..\ref\Gamecraft_Data\Managed\Blocks.HUDFeedbackBlocks.dll ..\..\ref\Gamecraft_Data\Managed\Blocks.HUDFeedbackBlocks.dll - - ..\ref\Gamecraft_Data\Managed\ClusterToWireConversion.Mock.dll - ..\..\ref\Gamecraft_Data\Managed\ClusterToWireConversion.Mock.dll - ..\ref\Gamecraft_Data\Managed\CommandLine.dll ..\..\ref\Gamecraft_Data\Managed\CommandLine.dll diff --git a/GamecraftModdingAPI/Persistence/IEntitySerializer.cs b/GamecraftModdingAPI/Persistence/IEntitySerializer.cs index a060f3c..5c4fb85 100644 --- a/GamecraftModdingAPI/Persistence/IEntitySerializer.cs +++ b/GamecraftModdingAPI/Persistence/IEntitySerializer.cs @@ -12,13 +12,7 @@ namespace GamecraftModdingAPI.Persistence /// public interface IEntitySerializer : IDeserializationFactory, IQueryingEntitiesEngine { - /// - /// The entity factory used for creating entities and entity components. - /// - /// The entity factory. - IEntityFactory EntityFactory { set; } - - /// + /// /// Serialize the entities. /// /// Whether serialization was successful. diff --git a/GamecraftModdingAPI/Persistence/SerializerManager.cs b/GamecraftModdingAPI/Persistence/SerializerManager.cs index 0584834..161662b 100644 --- a/GamecraftModdingAPI/Persistence/SerializerManager.cs +++ b/GamecraftModdingAPI/Persistence/SerializerManager.cs @@ -29,7 +29,6 @@ namespace GamecraftModdingAPI.Persistence _registrations[name] = (IEntitySerialization ies) => { ies.RegisterSerializationFactory(serializer); }; if (_lastEnginesRoot != null) { - serializer.EntityFactory = _lastEnginesRoot.GenerateEntityFactory(); _registrations[name].Invoke(_lastEnginesRoot.GenerateEntitySerializer()); _lastEnginesRoot.AddEngine(serializer); } @@ -63,12 +62,10 @@ namespace GamecraftModdingAPI.Persistence public static void RegisterSerializers(EnginesRoot enginesRoot) { _lastEnginesRoot = enginesRoot; - IEntityFactory factory = enginesRoot.GenerateEntityFactory(); IEntitySerialization ies = enginesRoot.GenerateEntitySerializer(); foreach (string key in _serializers.Keys) { Logging.MetaDebugLog($"Registering IEntitySerializer for {key}"); - _serializers[key].EntityFactory = factory; _registrations[key].Invoke(ies); enginesRoot.AddEngine(_serializers[key]); } diff --git a/GamecraftModdingAPI/Persistence/SimpleEntitySerializer.cs b/GamecraftModdingAPI/Persistence/SimpleEntitySerializer.cs index 1048edb..3e136ae 100644 --- a/GamecraftModdingAPI/Persistence/SimpleEntitySerializer.cs +++ b/GamecraftModdingAPI/Persistence/SimpleEntitySerializer.cs @@ -21,13 +21,11 @@ namespace GamecraftModdingAPI.Persistence protected int serializationType; - public IEntityFactory EntityFactory { set; protected get; } - public EntitiesDB entitiesDB { set; protected get; } - public EntityComponentInitializer BuildDeserializedEntity(EGID egid, ISerializationData serializationData, ISerializableEntityDescriptor entityDescriptor, int serializationType, IEntitySerialization entitySerialization) + public EntityComponentInitializer BuildDeserializedEntity(EGID egid, ISerializationData serializationData, ISerializableEntityDescriptor entityDescriptor, int serializationType, IEntitySerialization entitySerialization, IEntityFactory factory, bool enginesRootIsDeserializationOnly) { - EntityComponentInitializer esi = EntityFactory.BuildEntity(egid); + EntityComponentInitializer esi = factory.BuildEntity(egid); entitySerialization.DeserializeEntityComponents(serializationData, entityDescriptor, ref esi, serializationType); return esi; } diff --git a/GamecraftModdingAPI/Player.cs b/GamecraftModdingAPI/Player.cs index cff13ff..40dd385 100644 --- a/GamecraftModdingAPI/Player.cs +++ b/GamecraftModdingAPI/Player.cs @@ -51,7 +51,7 @@ namespace GamecraftModdingAPI /// The count. public static uint Count() { - return playerEngine.GetAllPlayerCount(); + return (uint) playerEngine.GetAllPlayerCount(); } /// @@ -357,7 +357,7 @@ namespace GamecraftModdingAPI public Block GetBlockLookedAt(float maxDistance = -1f) { var egid = playerEngine.GetThingLookedAt(Id, maxDistance); - return egid.HasValue && egid.Value.groupID == CommonExclusiveGroups.OWNED_BLOCKS_GROUP + return egid.HasValue && egid.Value.groupID != CommonExclusiveGroups.SIMULATION_BODIES_GROUP ? new Block(egid.Value) : null; } diff --git a/GamecraftModdingAPI/Players/PlayerEngine.cs b/GamecraftModdingAPI/Players/PlayerEngine.cs index d30993c..805ae21 100644 --- a/GamecraftModdingAPI/Players/PlayerEngine.cs +++ b/GamecraftModdingAPI/Players/PlayerEngine.cs @@ -65,10 +65,10 @@ namespace GamecraftModdingAPI.Players return uint.MaxValue; } - public uint GetAllPlayerCount() + public long GetAllPlayerCount() { if (entitiesDB == null) return 0; - uint count = 0; + long count = 0; foreach (ExclusiveGroupStruct eg in PlayersExclusiveGroups.AllPlayers) { count += entitiesDB.Count(eg); @@ -76,13 +76,13 @@ namespace GamecraftModdingAPI.Players return count; } - public uint GetLocalPlayerCount() + public long GetLocalPlayerCount() { if (entitiesDB == null) return 0; return entitiesDB.Count(PlayersExclusiveGroups.LocalPlayers); } - public uint GetRemotePlayerCount() + public long GetRemotePlayerCount() { if (entitiesDB == null) return 0; return entitiesDB.Count(PlayersExclusiveGroups.RemotePlayers);