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
This commit is contained in:
Norbi Peti 2020-07-11 00:30:58 +02:00
parent 6f589f1744
commit f403feb298
25 changed files with 93 additions and 126 deletions

View file

@ -26,16 +26,16 @@ namespace GamecraftModdingAPI.App
public void Ready() { } 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 }); 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 }); ExceptionUtil.InvokeEvent(BuildMode, this, new GameEventArgs { GameName = GameMode.SaveGameDetails.Name, GamePath = GameMode.SaveGameDetails.Folder });
return default(JobHandle); return inputDeps;
} }
} }

View file

@ -97,28 +97,22 @@ namespace GamecraftModdingAPI.App
public EGID[] GetAllBlocksInGame(BlockIDs filter = BlockIDs.Invalid) public EGID[] GetAllBlocksInGame(BlockIDs filter = BlockIDs.Invalid)
{ {
EntityCollection<DBEntityStruct> blocks = entitiesDB.QueryEntities<DBEntityStruct>(CommonExclusiveGroups.OWNED_BLOCKS_GROUP); var allBlocks = entitiesDB.QueryEntities<DBEntityStruct>();
List<EGID> blockEGIDs = new List<EGID>();
if (filter == BlockIDs.Invalid) if (filter == BlockIDs.Invalid)
{ {
EGID[] blockEGIDs = new EGID[blocks.count]; foreach (var (blocks, _) in allBlocks)
for (uint b = 0; b < blocks.count; b++) foreach (var block in blocks)
{ blockEGIDs.Add(block.ID);
blockEGIDs[b] = blocks[b].ID; return blockEGIDs.ToArray();
}
return blockEGIDs;
} }
else else
{ {
uint dbidFilter = (uint)filter; foreach (var (blocks, _) in allBlocks)
List<EGID> blockEGIDs = new List<EGID>(); foreach (var block in blocks)
for (uint b = 0; b < blocks.count; b++) if (block.DBID == (ulong) filter)
{ blockEGIDs.Add(block.ID);
if (blocks[b].DBID == dbidFilter) return blockEGIDs.ToArray();
{
blockEGIDs.Add(blocks[b].ID);
}
}
return blockEGIDs.ToArray();
} }
} }
} }

View file

@ -135,8 +135,8 @@ namespace GamecraftModdingAPI
Id = id; 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; } public EGID Id { get; }
@ -147,10 +147,10 @@ namespace GamecraftModdingAPI
/// </summary> /// </summary>
public float3 Position public float3 Position
{ {
get => Exists ? MovementEngine.GetPosition(Id.entityID) : float3.zero; get => Exists ? MovementEngine.GetPosition(Id) : float3.zero;
set set
{ {
if (Exists) MovementEngine.MoveBlock(Id.entityID, value); if (Exists) MovementEngine.MoveBlock(Id, value);
} }
} }
@ -159,10 +159,10 @@ namespace GamecraftModdingAPI
/// </summary> /// </summary>
public float3 Rotation public float3 Rotation
{ {
get => Exists ? RotationEngine.GetRotation(Id.entityID) : float3.zero; get => Exists ? RotationEngine.GetRotation(Id) : float3.zero;
set set
{ {
if (Exists) RotationEngine.RotateBlock(Id.entityID, value); if (Exists) RotationEngine.RotateBlock(Id, value);
} }
} }

View file

@ -38,14 +38,15 @@ namespace GamecraftModdingAPI.Blocks
public Block[] GetConnectedBlocks(EGID blockID) public Block[] GetConnectedBlocks(EGID blockID)
{ {
if (!BlockExists(blockID)) return new Block[0]; if (!BlockExists(blockID)) return new Block[0];
Stack<uint> cubeStack = new Stack<uint>(); Stack<EGID> cubeStack = new Stack<EGID>();
FasterList<uint> cubes = new FasterList<uint>(10); FasterList<EGID> cubes = new FasterList<EGID>(10);
var coll = entitiesDB.QueryEntities<GridConnectionsEntityStruct>(CommonExclusiveGroups var coll = entitiesDB.QueryEntities<GridConnectionsEntityStruct>();
.OWNED_BLOCKS_GROUP); foreach (var (ecoll, _) in coll)
for (int i = 0; i < coll.count; i++) foreach (ref var conn in ecoll)
coll[i].isProcessed = false; 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]; var ret = new Block[cubes.count];
for (int i = 0; i < cubes.count; i++) for (int i = 0; i < cubes.count; i++)
@ -125,10 +126,10 @@ namespace GamecraftModdingAPI.Blocks
public SimBody[] GetSimBodiesFromID(byte id) public SimBody[] GetSimBodiesFromID(byte id)
{ {
var ret = new FasterList<SimBody>(4); var ret = new FasterList<SimBody>(4);
if (!entitiesDB.HasAny<ObjectIdEntityStruct>(CommonExclusiveGroups.OWNED_BLOCKS_GROUP)) if (!entitiesDB.HasAny<ObjectIdEntityStruct>(CommonExclusiveGroups.BUILD_OBJID_BLOCK_GROUP))
return new SimBody[0]; return new SimBody[0];
var oids = entitiesDB.QueryEntities<ObjectIdEntityStruct>(CommonExclusiveGroups.OWNED_BLOCKS_GROUP); var oids = entitiesDB.QueryEntities<ObjectIdEntityStruct>(CommonExclusiveGroups.BUILD_OBJID_BLOCK_GROUP);
var connections = entitiesDB.QueryMappedEntities<GridConnectionsEntityStruct>(CommonExclusiveGroups.OWNED_BLOCKS_GROUP); var connections = entitiesDB.QueryMappedEntities<GridConnectionsEntityStruct>(CommonExclusiveGroups.BUILD_OBJID_BLOCK_GROUP);
foreach (ref ObjectIdEntityStruct oid in oids) foreach (ref ObjectIdEntityStruct oid in oids)
{ {
if (oid.objectId != id) continue; if (oid.objectId != id) continue;
@ -147,9 +148,9 @@ namespace GamecraftModdingAPI.Blocks
public ObjectIdentifier[] GetObjectIDsFromID(byte id, bool sim) public ObjectIdentifier[] GetObjectIDsFromID(byte id, bool sim)
{ {
var ret = new FasterList<ObjectIdentifier>(4); var ret = new FasterList<ObjectIdentifier>(4);
if (!entitiesDB.HasAny<ObjectIdEntityStruct>(CommonExclusiveGroups.OWNED_BLOCKS_GROUP)) if (!entitiesDB.HasAny<ObjectIdEntityStruct>(CommonExclusiveGroups.BUILD_OBJID_BLOCK_GROUP))
return new ObjectIdentifier[0]; return new ObjectIdentifier[0];
var oids = entitiesDB.QueryEntities<ObjectIdEntityStruct>(CommonExclusiveGroups.OWNED_BLOCKS_GROUP); var oids = entitiesDB.QueryEntities<ObjectIdEntityStruct>(CommonExclusiveGroups.BUILD_OBJID_BLOCK_GROUP);
foreach (ref ObjectIdEntityStruct oid in oids) foreach (ref ObjectIdEntityStruct oid in oids)
if (sim ? oid.simObjectId == id : oid.objectId == id) if (sim ? oid.simObjectId == id : oid.objectId == id)
ret.Add(new ObjectIdentifier(oid.ID)); ret.Add(new ObjectIdentifier(oid.ID));

View file

@ -12,8 +12,8 @@ namespace GamecraftModdingAPI.Blocks
{ {
/// <summary> /// <summary>
/// Blocks placed by the player /// Blocks placed by the player
/// </summary> /// </summary> - TODO
public static ExclusiveGroup OWNED_BLOCKS { get { return CommonExclusiveGroups.OWNED_BLOCKS_GROUP; } } //public static ExclusiveGroup OWNED_BLOCKS { get { return CommonExclusiveGroups.REAL_BLOCKS_GROUPS_DON_T_USE_IN_NEW_CODE; } }
/// <summary> /// <summary>
/// Extra parts used in functional blocks /// Extra parts used in functional blocks
@ -23,7 +23,7 @@ namespace GamecraftModdingAPI.Blocks
/// <summary> /// <summary>
/// Blocks which are disabled in Simulation mode /// Blocks which are disabled in Simulation mode
/// </summary> /// </summary>
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; } } //public static ExclusiveGroup SPAWN_POINTS { get { return CommonExclusiveGroups.SPAWN_POINTS_GROUP; } }
@ -34,7 +34,7 @@ namespace GamecraftModdingAPI.Blocks
/// </summary> /// </summary>
public static uint LatestBlockID { public static uint LatestBlockID {
get get
{ { //Need the private field as the property increments itself
return ((uint) AccessTools.Field(typeof(CommonExclusiveGroups), "_nextBlockEntityID").GetValue(null)) - 1; return ((uint) AccessTools.Field(typeof(CommonExclusiveGroups), "_nextBlockEntityID").GetValue(null)) - 1;
} }
} }

View file

@ -1,6 +1,7 @@
using System; using System;
using RobocraftX.Blocks; using RobocraftX.Blocks;
using RobocraftX.Common;
using Svelto.ECS; using Svelto.ECS;
using Unity.Mathematics; 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<ConsoleBlockEntityStruct>(this.Id)) if (!BlockEngine.GetBlockInfoExists<ConsoleBlockEntityStruct>(this.Id))
{ {

View file

@ -1,6 +1,7 @@
using System; using System;
using RobocraftX.Blocks; using RobocraftX.Blocks;
using RobocraftX.Common;
using Svelto.ECS; using Svelto.ECS;
using Unity.Mathematics; 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<MotorReadOnlyStruct>(this.Id)) if (!BlockEngine.GetBlockInfoExists<MotorReadOnlyStruct>(this.Id))
{ {

View file

@ -35,12 +35,12 @@ namespace GamecraftModdingAPI.Blocks
// implementations for Movement static class // 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<PositionEntityStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP); ref PositionEntityStruct posStruct = ref this.entitiesDB.QueryEntity<PositionEntityStruct>(blockID);
ref GridRotationStruct gridStruct = ref this.entitiesDB.QueryEntity<GridRotationStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP); ref GridRotationStruct gridStruct = ref this.entitiesDB.QueryEntity<GridRotationStruct>(blockID);
ref LocalTransformEntityStruct transStruct = ref this.entitiesDB.QueryEntity<LocalTransformEntityStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP); ref LocalTransformEntityStruct transStruct = ref this.entitiesDB.QueryEntity<LocalTransformEntityStruct>(blockID);
ref UECSPhysicsEntityStruct phyStruct = ref this.entitiesDB.QueryEntity<UECSPhysicsEntityStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP); ref UECSPhysicsEntityStruct phyStruct = ref this.entitiesDB.QueryEntity<UECSPhysicsEntityStruct>(blockID);
// main (persistent) position // main (persistent) position
posStruct.position = vector; posStruct.position = vector;
// placement grid position // placement grid position
@ -52,13 +52,13 @@ namespace GamecraftModdingAPI.Blocks
{ {
Value = posStruct.position Value = posStruct.position
}); });
entitiesDB.QueryEntity<GridConnectionsEntityStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP).isProcessed = false; entitiesDB.QueryEntity<GridConnectionsEntityStruct>(blockID).isProcessed = false;
return posStruct.position; return posStruct.position;
} }
public float3 GetPosition(uint blockID) public float3 GetPosition(EGID blockID)
{ {
ref PositionEntityStruct posStruct = ref this.entitiesDB.QueryEntity<PositionEntityStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP); ref PositionEntityStruct posStruct = ref this.entitiesDB.QueryEntity<PositionEntityStruct>(blockID);
return posStruct.position; return posStruct.position;
} }
} }

View file

@ -1,4 +1,5 @@
using Gamecraft.Wires; using Gamecraft.Wires;
using RobocraftX.Common;
using Svelto.ECS; using Svelto.ECS;
namespace GamecraftModdingAPI.Blocks 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<ObjectIdEntityStruct>(Id)) if (!BlockEngine.GetBlockInfoExists<ObjectIdEntityStruct>(Id))
{ {

View file

@ -5,6 +5,7 @@ using Svelto.ECS;
using Unity.Mathematics; using Unity.Mathematics;
using GamecraftModdingAPI.Utility; using GamecraftModdingAPI.Utility;
using RobocraftX.Common;
namespace GamecraftModdingAPI.Blocks 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<PistonReadOnlyStruct>(this.Id)) if (!BlockEngine.GetBlockInfoExists<PistonReadOnlyStruct>(this.Id))
{ {

View file

@ -66,8 +66,6 @@ namespace GamecraftModdingAPI.Blocks
RotationEntityStruct rotation = new RotationEntityStruct {rotation = rotQ}; RotationEntityStruct rotation = new RotationEntityStruct {rotation = rotQ};
GridRotationStruct gridRotation = new GridRotationStruct GridRotationStruct gridRotation = new GridRotationStruct
{position = position, rotation = rotQ}; {position = position, rotation = rotQ};
CubeCategoryStruct category = new CubeCategoryStruct
{category = CubeCategory.General, type = CubeType.Block};
DBEntityStruct dbEntity = new DBEntityStruct {DBID = dbid}; DBEntityStruct dbEntity = new DBEntityStruct {DBID = dbid};
BlockPlacementScaleEntityStruct placementScale = new BlockPlacementScaleEntityStruct BlockPlacementScaleEntityStruct placementScale = new BlockPlacementScaleEntityStruct
{ {
@ -76,21 +74,10 @@ namespace GamecraftModdingAPI.Blocks
unitSnapOffset = 0, isUsingUnitSize = true unitSnapOffset = 0, isUsingUnitSize = true
}; };
EquippedColourStruct colour = new EquippedColourStruct {indexInPalette = color}; 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 EntityComponentInitializer
structInitializer = 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) if (colour.indexInPalette != byte.MaxValue)
structInitializer.Init(new ColourParameterEntityStruct structInitializer.Init(new ColourParameterEntityStruct
{ {
@ -117,10 +104,10 @@ namespace GamecraftModdingAPI.Blocks
PrimaryRotationUtility.InitialisePrimaryDirection(rotation.rotation, ref structInitializer); PrimaryRotationUtility.InitialisePrimaryDirection(rotation.rotation, ref structInitializer);
EGID playerEGID = new EGID(playerId, CharacterExclusiveGroups.OnFootGroup); EGID playerEGID = new EGID(playerId, CharacterExclusiveGroups.OnFootGroup);
ref PickedBlockExtraDataStruct pickedBlock = ref entitiesDB.QueryEntity<PickedBlockExtraDataStruct>(playerEGID); ref PickedBlockExtraDataStruct pickedBlock = ref entitiesDB.QueryEntity<PickedBlockExtraDataStruct>(playerEGID);
pickedBlock.placedBlockEntityID = playerEGID; pickedBlock.placedBlockEntityID = structInitializer.EGID;
pickedBlock.placedBlockWasAPickedBlock = false; pickedBlock.placedBlockWasAPickedBlock = false;
Block.BlockEngine.Synced = false; // Block entities will need to be submitted before properties can be used 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"; public string Name { get; } = "GamecraftModdingAPIPlacementGameEngine";

View file

@ -35,12 +35,12 @@ namespace GamecraftModdingAPI.Blocks
// implementations for Rotation static class // 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<RotationEntityStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP); ref RotationEntityStruct rotStruct = ref this.entitiesDB.QueryEntity<RotationEntityStruct>(blockID);
ref GridRotationStruct gridStruct = ref this.entitiesDB.QueryEntity<GridRotationStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP); ref GridRotationStruct gridStruct = ref this.entitiesDB.QueryEntity<GridRotationStruct>(blockID);
ref LocalTransformEntityStruct transStruct = ref this.entitiesDB.QueryEntity<LocalTransformEntityStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP); ref LocalTransformEntityStruct transStruct = ref this.entitiesDB.QueryEntity<LocalTransformEntityStruct>(blockID);
ref UECSPhysicsEntityStruct phyStruct = ref this.entitiesDB.QueryEntity<UECSPhysicsEntityStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP); ref UECSPhysicsEntityStruct phyStruct = ref this.entitiesDB.QueryEntity<UECSPhysicsEntityStruct>(blockID);
// main (persistent) position // main (persistent) position
Quaternion newRotation = (Quaternion)rotStruct.rotation; Quaternion newRotation = (Quaternion)rotStruct.rotation;
newRotation.eulerAngles += vector; newRotation.eulerAngles += vector;
@ -58,14 +58,14 @@ namespace GamecraftModdingAPI.Blocks
{ {
Value = rotStruct.rotation Value = rotStruct.rotation
}); });
entitiesDB.QueryEntity<GridConnectionsEntityStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP).isProcessed = false; entitiesDB.QueryEntity<GridConnectionsEntityStruct>(blockID).isProcessed = false;
return ((Quaternion)rotStruct.rotation).eulerAngles; return ((Quaternion)rotStruct.rotation).eulerAngles;
} }
public float3 GetRotation(uint blockID) public float3 GetRotation(EGID blockID)
{ {
ref RotationEntityStruct rotStruct = ref entitiesDB.QueryEntity<RotationEntityStruct>(blockID, CommonExclusiveGroups.OWNED_BLOCKS_GROUP); ref RotationEntityStruct rotStruct = ref entitiesDB.QueryEntity<RotationEntityStruct>(blockID);
return ((Quaternion) rotStruct.rotation).eulerAngles; return ((Quaternion) rotStruct.rotation).eulerAngles;
} }
} }

View file

@ -1,6 +1,7 @@
using System; using System;
using RobocraftX.Blocks; using RobocraftX.Blocks;
using RobocraftX.Common;
using Svelto.ECS; using Svelto.ECS;
using Unity.Mathematics; 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<ServoReadOnlyStruct>(this.Id)) if (!BlockEngine.GetBlockInfoExists<ServoReadOnlyStruct>(this.Id))
{ {

View file

@ -1,4 +1,5 @@
using Svelto.ECS; using Svelto.ECS;
using Svelto.DataStructures;
using Gamecraft.Wires; using Gamecraft.Wires;
using GamecraftModdingAPI.Engines; using GamecraftModdingAPI.Engines;
@ -166,21 +167,12 @@ namespace GamecraftModdingAPI.Blocks
} }
public EGID[] GetElectricBlocks() public EGID[] GetElectricBlocks()
{ {
uint count = entitiesDB.Count<BlockPortsStruct>(BlockIdentifiers.OWNED_BLOCKS) + entitiesDB.Count<BlockPortsStruct>(BlockIdentifiers.FUNCTIONAL_BLOCK_PARTS); var res = new FasterList<EGID>();
uint i = 0; foreach (var (coll, _) in entitiesDB.QueryEntities<BlockPortsStruct>())
EGID[] res = new EGID[count]; foreach (ref BlockPortsStruct s in coll)
foreach (ref BlockPortsStruct s in entitiesDB.QueryEntities<BlockPortsStruct>(BlockIdentifiers.OWNED_BLOCKS)) res.Add(s.ID);
{ return res.ToArray();
res[i] = s.ID;
i++;
}
foreach (ref BlockPortsStruct s in entitiesDB.QueryEntities<BlockPortsStruct>(BlockIdentifiers.FUNCTIONAL_BLOCK_PARTS))
{
res[i] = s.ID;
i++;
}
return res;
} }
private EntityCollection<ChannelDataStruct> GetSignalStruct(uint signalID, out uint index, bool input = true) private EntityCollection<ChannelDataStruct> GetSignalStruct(uint signalID, out uint index, bool input = true)

View file

@ -1,6 +1,7 @@
using System; using System;
using RobocraftX.Blocks; using RobocraftX.Blocks;
using RobocraftX.Common;
using Gamecraft.CharacterVulnerability; using Gamecraft.CharacterVulnerability;
using Svelto.ECS; using Svelto.ECS;
using Unity.Mathematics; 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<SpawnPointStatsEntityStruct>(this.Id)) if (!BlockEngine.GetBlockInfoExists<SpawnPointStatsEntityStruct>(this.Id))
{ {

View file

@ -1,6 +1,7 @@
using System; using System;
using Gamecraft.Blocks.GUI; using Gamecraft.Blocks.GUI;
using RobocraftX.Common;
using Svelto.ECS; using Svelto.ECS;
using Unity.Mathematics; 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<TextBlockDataStruct>(this.Id)) if (!BlockEngine.GetBlockInfoExists<TextBlockDataStruct>(this.Id))
{ {

View file

@ -1,6 +1,7 @@
using System; using System;
using RobocraftX.Blocks; using RobocraftX.Blocks;
using RobocraftX.Common;
using Gamecraft.Blocks.TimerBlock; using Gamecraft.Blocks.TimerBlock;
using Svelto.ECS; using Svelto.ECS;
using Unity.Mathematics; 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<TimerBlockDataStruct>(this.Id)) if (!BlockEngine.GetBlockInfoExists<TimerBlockDataStruct>(this.Id))
{ {

View file

@ -43,10 +43,10 @@ namespace GamecraftModdingAPI.Events
} }
} }
public JobHandle OnInitializeTimeStoppedMode() public JobHandle OnInitializeTimeStoppedMode(JobHandle inputDeps)
{ {
Emit(); Emit();
return default(JobHandle); return inputDeps;
} }
public void Ready() { } public void Ready() { }

View file

@ -42,10 +42,10 @@ namespace GamecraftModdingAPI.Events
} }
} }
public JobHandle OnInitializeTimeRunningMode() public JobHandle OnInitializeTimeRunningMode(JobHandle inputDeps)
{ {
Emit(); Emit();
return default(JobHandle); return inputDeps;
} }
public void Ready() { } public void Ready() { }

View file

@ -80,10 +80,6 @@
<HintPath>..\ref\Gamecraft_Data\Managed\Blocks.HUDFeedbackBlocks.dll</HintPath> <HintPath>..\ref\Gamecraft_Data\Managed\Blocks.HUDFeedbackBlocks.dll</HintPath>
<HintPath>..\..\ref\Gamecraft_Data\Managed\Blocks.HUDFeedbackBlocks.dll</HintPath> <HintPath>..\..\ref\Gamecraft_Data\Managed\Blocks.HUDFeedbackBlocks.dll</HintPath>
</Reference> </Reference>
<Reference Include="ClusterToWireConversion.Mock">
<HintPath>..\ref\Gamecraft_Data\Managed\ClusterToWireConversion.Mock.dll</HintPath>
<HintPath>..\..\ref\Gamecraft_Data\Managed\ClusterToWireConversion.Mock.dll</HintPath>
</Reference>
<Reference Include="CommandLine"> <Reference Include="CommandLine">
<HintPath>..\ref\Gamecraft_Data\Managed\CommandLine.dll</HintPath> <HintPath>..\ref\Gamecraft_Data\Managed\CommandLine.dll</HintPath>
<HintPath>..\..\ref\Gamecraft_Data\Managed\CommandLine.dll</HintPath> <HintPath>..\..\ref\Gamecraft_Data\Managed\CommandLine.dll</HintPath>

View file

@ -12,13 +12,7 @@ namespace GamecraftModdingAPI.Persistence
/// </summary> /// </summary>
public interface IEntitySerializer : IDeserializationFactory, IQueryingEntitiesEngine public interface IEntitySerializer : IDeserializationFactory, IQueryingEntitiesEngine
{ {
/// <summary> /// <summary>
/// The entity factory used for creating entities and entity components.
/// </summary>
/// <value>The entity factory.</value>
IEntityFactory EntityFactory { set; }
/// <summary>
/// Serialize the entities. /// Serialize the entities.
/// </summary> /// </summary>
/// <returns>Whether serialization was successful.</returns> /// <returns>Whether serialization was successful.</returns>

View file

@ -29,7 +29,6 @@ namespace GamecraftModdingAPI.Persistence
_registrations[name] = (IEntitySerialization ies) => { ies.RegisterSerializationFactory<T>(serializer); }; _registrations[name] = (IEntitySerialization ies) => { ies.RegisterSerializationFactory<T>(serializer); };
if (_lastEnginesRoot != null) if (_lastEnginesRoot != null)
{ {
serializer.EntityFactory = _lastEnginesRoot.GenerateEntityFactory();
_registrations[name].Invoke(_lastEnginesRoot.GenerateEntitySerializer()); _registrations[name].Invoke(_lastEnginesRoot.GenerateEntitySerializer());
_lastEnginesRoot.AddEngine(serializer); _lastEnginesRoot.AddEngine(serializer);
} }
@ -63,12 +62,10 @@ namespace GamecraftModdingAPI.Persistence
public static void RegisterSerializers(EnginesRoot enginesRoot) public static void RegisterSerializers(EnginesRoot enginesRoot)
{ {
_lastEnginesRoot = enginesRoot; _lastEnginesRoot = enginesRoot;
IEntityFactory factory = enginesRoot.GenerateEntityFactory();
IEntitySerialization ies = enginesRoot.GenerateEntitySerializer(); IEntitySerialization ies = enginesRoot.GenerateEntitySerializer();
foreach (string key in _serializers.Keys) foreach (string key in _serializers.Keys)
{ {
Logging.MetaDebugLog($"Registering IEntitySerializer for {key}"); Logging.MetaDebugLog($"Registering IEntitySerializer for {key}");
_serializers[key].EntityFactory = factory;
_registrations[key].Invoke(ies); _registrations[key].Invoke(ies);
enginesRoot.AddEngine(_serializers[key]); enginesRoot.AddEngine(_serializers[key]);
} }

View file

@ -21,13 +21,11 @@ namespace GamecraftModdingAPI.Persistence
protected int serializationType; protected int serializationType;
public IEntityFactory EntityFactory { set; protected get; }
public EntitiesDB entitiesDB { 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<Descriptor>(egid); EntityComponentInitializer esi = factory.BuildEntity<Descriptor>(egid);
entitySerialization.DeserializeEntityComponents(serializationData, entityDescriptor, ref esi, serializationType); entitySerialization.DeserializeEntityComponents(serializationData, entityDescriptor, ref esi, serializationType);
return esi; return esi;
} }

View file

@ -51,7 +51,7 @@ namespace GamecraftModdingAPI
/// <returns>The count.</returns> /// <returns>The count.</returns>
public static uint Count() public static uint Count()
{ {
return playerEngine.GetAllPlayerCount(); return (uint) playerEngine.GetAllPlayerCount();
} }
/// <summary> /// <summary>
@ -357,7 +357,7 @@ namespace GamecraftModdingAPI
public Block GetBlockLookedAt(float maxDistance = -1f) public Block GetBlockLookedAt(float maxDistance = -1f)
{ {
var egid = playerEngine.GetThingLookedAt(Id, maxDistance); 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) ? new Block(egid.Value)
: null; : null;
} }

View file

@ -65,10 +65,10 @@ namespace GamecraftModdingAPI.Players
return uint.MaxValue; return uint.MaxValue;
} }
public uint GetAllPlayerCount() public long GetAllPlayerCount()
{ {
if (entitiesDB == null) return 0; if (entitiesDB == null) return 0;
uint count = 0; long count = 0;
foreach (ExclusiveGroupStruct eg in PlayersExclusiveGroups.AllPlayers) foreach (ExclusiveGroupStruct eg in PlayersExclusiveGroups.AllPlayers)
{ {
count += entitiesDB.Count<PlayerIDStruct>(eg); count += entitiesDB.Count<PlayerIDStruct>(eg);
@ -76,13 +76,13 @@ namespace GamecraftModdingAPI.Players
return count; return count;
} }
public uint GetLocalPlayerCount() public long GetLocalPlayerCount()
{ {
if (entitiesDB == null) return 0; if (entitiesDB == null) return 0;
return entitiesDB.Count<PlayerIDStruct>(PlayersExclusiveGroups.LocalPlayers); return entitiesDB.Count<PlayerIDStruct>(PlayersExclusiveGroups.LocalPlayers);
} }
public uint GetRemotePlayerCount() public long GetRemotePlayerCount()
{ {
if (entitiesDB == null) return 0; if (entitiesDB == null) return 0;
return entitiesDB.Count<PlayerIDStruct>(PlayersExclusiveGroups.RemotePlayers); return entitiesDB.Count<PlayerIDStruct>(PlayersExclusiveGroups.RemotePlayers);