diff --git a/GamecraftModdingAPI/App/AppEngine.cs b/GamecraftModdingAPI/App/AppEngine.cs index 4f20b7e..9cc454d 100644 --- a/GamecraftModdingAPI/App/AppEngine.cs +++ b/GamecraftModdingAPI/App/AppEngine.cs @@ -46,11 +46,12 @@ namespace GamecraftModdingAPI.App public Game[] GetMyGames() { EntityCollection mgsevs = entitiesDB.QueryEntities(MyGamesScreenExclusiveGroups.MyGames); + var mgsevsB = mgsevs.ToBuffer().buffer; Game[] games = new Game[mgsevs.count]; for (int i = 0; i < mgsevs.count; i++) { - Utility.Logging.MetaDebugLog($"Found game named {mgsevs[i].GameName}"); - games[i] = new Game(mgsevs[i].ID); + Utility.Logging.MetaDebugLog($"Found game named {mgsevsB[i].GameName}"); + games[i] = new Game(mgsevsB[i].ID); } return games; } diff --git a/GamecraftModdingAPI/App/GameGameEngine.cs b/GamecraftModdingAPI/App/GameGameEngine.cs index a616df5..dea3821 100644 --- a/GamecraftModdingAPI/App/GameGameEngine.cs +++ b/GamecraftModdingAPI/App/GameGameEngine.cs @@ -52,7 +52,7 @@ namespace GamecraftModdingAPI.App { if (async) { - ExitCurrentGameAsync().RunOn(Lean.EveryFrameStepRunner_RUNS_IN_TIME_STOPPED_AND_RUNNING); + ExitCurrentGameAsync().RunOn(Lean.EveryFrameStepRunner_TimeRunningAndStopped); } else { @@ -102,14 +102,14 @@ namespace GamecraftModdingAPI.App if (filter == BlockIDs.Invalid) { foreach (var (blocks, _) in allBlocks) - foreach (var block in blocks) + foreach (var block in blocks.ToBuffer().buffer.ToManagedArray()) blockEGIDs.Add(block.ID); return blockEGIDs.ToArray(); } else { foreach (var (blocks, _) in allBlocks) - foreach (var block in blocks) + foreach (var block in blocks.ToBuffer().buffer.ToManagedArray()) if (block.DBID == (ulong) filter) blockEGIDs.Add(block.ID); return blockEGIDs.ToArray(); diff --git a/GamecraftModdingAPI/App/GameMenuEngine.cs b/GamecraftModdingAPI/App/GameMenuEngine.cs index 74bc42a..efcb73e 100644 --- a/GamecraftModdingAPI/App/GameMenuEngine.cs +++ b/GamecraftModdingAPI/App/GameMenuEngine.cs @@ -61,12 +61,13 @@ namespace GamecraftModdingAPI.App public uint HighestID() { EntityCollection games = entitiesDB.QueryEntities(MyGamesScreenExclusiveGroups.MyGames); + var gamesB = games.ToBuffer().buffer; uint max = 0; for (int i = 0; i < games.count; i++) { - if (games[i].ID.entityID > max) + if (gamesB[i].ID.entityID > max) { - max = games[i].ID.entityID; + max = gamesB[i].ID.entityID; } } return max; @@ -118,11 +119,12 @@ namespace GamecraftModdingAPI.App { EntityCollection entities = entitiesDB.QueryEntities(MyGamesScreenExclusiveGroups.GameSlotGuiEntities); + var entitiesB = entities.ToBuffer().buffer; for (int i = 0; i < entities.count; i++) { - if (entities[i].ID.entityID == id.entityID) + if (entitiesB[i].ID.entityID == id.entityID) { - return ref entities[i]; + return ref entitiesB[i]; } } MyGamesSlotEntityViewStruct[] defRef = new MyGamesSlotEntityViewStruct[1]; diff --git a/GamecraftModdingAPI/Block.cs b/GamecraftModdingAPI/Block.cs index 408304d..81d6439 100644 --- a/GamecraftModdingAPI/Block.cs +++ b/GamecraftModdingAPI/Block.cs @@ -116,32 +116,32 @@ namespace GamecraftModdingAPI private static Dictionary typeToGroup = new Dictionary { - {typeof(ConsoleBlock), new[] {CommonExclusiveGroups.BUILD_CONSOLE_BLOCK_GROUP}}, - {typeof(LogicGate), new [] {CommonExclusiveGroups.BUILD_LOGIC_BLOCK_GROUP}}, - {typeof(Motor), new[] {CommonExclusiveGroups.BUILD_MOTOR_BLOCK_GROUP}}, - {typeof(MusicBlock), new[] {CommonExclusiveGroups.BUILD_MUSIC_BLOCK_GROUP}}, - {typeof(ObjectIdentifier), new[]{CommonExclusiveGroups.BUILD_OBJID_BLOCK_GROUP}}, - {typeof(Piston), new[] {CommonExclusiveGroups.BUILD_PISTON_BLOCK_GROUP}}, - {typeof(Servo), new[] {CommonExclusiveGroups.BUILD_SERVO_BLOCK_GROUP}}, + {typeof(ConsoleBlock), new[] {CommonExclusiveGroups.CONSOLE_BLOCK_GROUP}}, + {typeof(LogicGate), new [] {CommonExclusiveGroups.LOGIC_BLOCK_GROUP}}, + {typeof(Motor), new[] {CommonExclusiveGroups.MOTOR_BLOCK_GROUP}}, + {typeof(MusicBlock), new[] {CommonExclusiveGroups.MUSIC_BLOCK_GROUP}}, + {typeof(ObjectIdentifier), new[]{CommonExclusiveGroups.OBJID_BLOCK_GROUP}}, + {typeof(Piston), new[] {CommonExclusiveGroups.PISTON_BLOCK_GROUP}}, + {typeof(Servo), new[] {CommonExclusiveGroups.SERVO_BLOCK_GROUP}}, { typeof(SpawnPoint), new[] { - CommonExclusiveGroups.BUILD_SPAWNPOINT_BLOCK_GROUP, - CommonExclusiveGroups.BUILD_BUILDINGSPAWN_BLOCK_GROUP + CommonExclusiveGroups.SPAWNPOINT_BLOCK_GROUP, + CommonExclusiveGroups.BUILDINGSPAWN_BLOCK_GROUP } }, { typeof(SfxBlock), new[] { - CommonExclusiveGroups.BUILD_SIMPLESFX_BLOCK_GROUP, - CommonExclusiveGroups.BUILD_LOOPEDSFX_BLOCK_GROUP + CommonExclusiveGroups.SIMPLESFX_BLOCK_GROUP, + CommonExclusiveGroups.LOOPEDSFX_BLOCK_GROUP } }, - {typeof(DampedSpring), new [] {CommonExclusiveGroups.BUILD_DAMPEDSPRING_BLOCK_GROUP}}, - {typeof(TextBlock), new[] {CommonExclusiveGroups.BUILD_TEXT_BLOCK_GROUP}}, - {typeof(Timer), new[] {CommonExclusiveGroups.BUILD_TIMER_BLOCK_GROUP}} + {typeof(DampedSpring), new [] {CommonExclusiveGroups.DAMPEDSPRING_BLOCK_GROUP}}, + {typeof(TextBlock), new[] {CommonExclusiveGroups.TEXT_BLOCK_GROUP}}, + {typeof(Timer), new[] {CommonExclusiveGroups.TIMER_BLOCK_GROUP}} }; /// @@ -312,8 +312,9 @@ namespace GamecraftModdingAPI BlockEngine.SetBlockInfo(this, (ref ColourParameterEntityStruct color, BlockColor val) => { color.indexInPalette = (byte) (val.Color + val.Darkness * 10); - color.overridePaletteColour = false; - color.needsUpdate = true; + //color.overridePaletteColour = false; + //color.needsUpdate = true; + color.hasNetworkChange = true; color.paletteColour = BlockEngine.ConvertBlockColor(color.indexInPalette); }, value); } @@ -324,14 +325,15 @@ namespace GamecraftModdingAPI /// public float4 CustomColor { - get => BlockEngine.GetBlockInfo(this, (ColourParameterEntityStruct st) => st.overriddenColour); + get => BlockEngine.GetBlockInfo(this, (ColourParameterEntityStruct st) => st.paletteColour); set { BlockEngine.SetBlockInfo(this, (ref ColourParameterEntityStruct color, float4 val) => { - color.overriddenColour = val; - color.overridePaletteColour = true; - color.needsUpdate = true; + color.paletteColour = val; + //color.overridePaletteColour = true; + //color.needsUpdate = true; + color.hasNetworkChange = true; }, value); } } diff --git a/GamecraftModdingAPI/Blocks/BlockEngine.cs b/GamecraftModdingAPI/Blocks/BlockEngine.cs index e39a3e8..5566525 100644 --- a/GamecraftModdingAPI/Blocks/BlockEngine.cs +++ b/GamecraftModdingAPI/Blocks/BlockEngine.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using Gamecraft.ColourPalette; +using Gamecraft.TimeRunning; using Gamecraft.Wires; using RobocraftX.Blocks; using RobocraftX.Common; @@ -43,8 +44,14 @@ namespace GamecraftModdingAPI.Blocks FasterList cubes = new FasterList(10); var coll = entitiesDB.QueryEntities(); foreach (var (ecoll, _) in coll) - foreach (ref var conn in ecoll) - conn.isProcessed = false; + { + var ecollB = ecoll.ToBuffer(); + for(int i = 0; i < ecoll.count; i++) + { + ref var conn = ref ecollB.buffer[i]; + conn.isProcessed = false; + } + } ConnectedCubesUtility.TreeTraversal.GetConnectedCubes(entitiesDB, blockID, cubeStack, cubes, (in GridConnectionsEntityStruct g) => { return false; }); @@ -68,17 +75,17 @@ namespace GamecraftModdingAPI.Blocks return ref structHolder[0]; //Gets a default value automatically } - public ref T GetBlockInfoViewStruct(EGID blockID) where T : struct, INeedEGID, IEntityComponent + public ref T GetBlockInfoViewStruct(EGID blockID) where T : struct, INeedEGID, IEntityViewComponent { if (entitiesDB.Exists(blockID)) { // TODO: optimize by using EntitiesDB internal calls instead of iterating over everything - EntityCollection entities = entitiesDB.QueryEntities(blockID.groupID); + BT> entities = entitiesDB.QueryEntities(blockID.groupID).ToBuffer(); for (int i = 0; i < entities.count; i++) { - if (entities[i].ID == blockID) + if (entities.buffer[i].ID == blockID) { - return ref entities[i]; + return ref entities.buffer[i]; } } } @@ -160,12 +167,13 @@ namespace GamecraftModdingAPI.Blocks public SimBody[] GetSimBodiesFromID(byte id) { var ret = new FasterList(4); - if (!entitiesDB.HasAny(CommonExclusiveGroups.BUILD_OBJID_BLOCK_GROUP)) + if (!entitiesDB.HasAny(CommonExclusiveGroups.OBJID_BLOCK_GROUP)) return new SimBody[0]; - var oids = entitiesDB.QueryEntities(CommonExclusiveGroups.BUILD_OBJID_BLOCK_GROUP); - var connections = entitiesDB.QueryMappedEntities(CommonExclusiveGroups.BUILD_OBJID_BLOCK_GROUP); - foreach (ref ObjectIdEntityStruct oid in oids) + var oids = entitiesDB.QueryEntities(CommonExclusiveGroups.OBJID_BLOCK_GROUP).ToBuffer(); + var connections = entitiesDB.QueryMappedEntities(CommonExclusiveGroups.OBJID_BLOCK_GROUP); + for (int i = 0; i < oids.count; i++) { + ref ObjectIdEntityStruct oid = ref oids.buffer[i]; if (oid.objectId != id) continue; var rid = connections.Entity(oid.ID.entityID).machineRigidBodyId; foreach (var rb in ret) @@ -182,21 +190,26 @@ namespace GamecraftModdingAPI.Blocks public ObjectIdentifier[] GetObjectIDsFromID(byte id, bool sim) { var ret = new FasterList(4); - if (!entitiesDB.HasAny(CommonExclusiveGroups.BUILD_OBJID_BLOCK_GROUP)) + if (!entitiesDB.HasAny(CommonExclusiveGroups.OBJID_BLOCK_GROUP)) return new ObjectIdentifier[0]; - var oids = entitiesDB.QueryEntities(CommonExclusiveGroups.BUILD_OBJID_BLOCK_GROUP); - foreach (ref ObjectIdEntityStruct oid in oids) + var oids = entitiesDB.QueryEntities(CommonExclusiveGroups.OBJID_BLOCK_GROUP).ToBuffer(); + for (int i = 0; i < oids.count; i++) + { + ref ObjectIdEntityStruct oid = ref oids.buffer[i]; if (sim ? oid.simObjectId == id : oid.objectId == id) ret.Add(new ObjectIdentifier(oid.ID)); + } + return ret.ToArray(); } public SimBody[] GetConnectedSimBodies(uint id) { - var joints = entitiesDB.QueryEntities(MachineSimulationGroups.JOINTS_GROUP); + var joints = entitiesDB.QueryEntities(MachineSimulationGroups.JOINTS_GROUP).ToBuffer(); var list = new FasterList(4); - foreach (var joint in joints) + for (int i = 0; i < joints.count; i++) { + ref var joint = ref joints.buffer[i]; if (joint.jointState == JointState.Broken) continue; if (joint.connectedEntityA == id) list.Add(new SimBody(joint.connectedEntityB)); else if (joint.connectedEntityB == id) list.Add(new SimBody(joint.connectedEntityA)); @@ -211,7 +224,7 @@ namespace GamecraftModdingAPI.Blocks var bodies = new HashSet(); foreach (var (coll, _) in groups) { - foreach (var conn in coll) + foreach (var conn in coll.ToBuffer().buffer.ToManagedArray()) { if (conn.clusterId == cid) bodies.Add(conn.machineRigidBodyId); @@ -238,7 +251,7 @@ namespace GamecraftModdingAPI.Blocks var groups = entitiesDB.QueryEntities(); foreach (var (coll, _) in groups) { - foreach (var conn in coll) + foreach (var conn in coll.ToBuffer().buffer.ToManagedArray()) { //Static blocks don't have a cluster ID but the cluster destruction manager should have one if (conn.machineRigidBodyId == sbid && conn.clusterId != uint.MaxValue) return new Cluster(conn.clusterId); @@ -254,7 +267,7 @@ namespace GamecraftModdingAPI.Blocks var set = new HashSet(); foreach (var (coll, _) in groups) { - foreach (var conn in coll) + foreach (var conn in coll.ToBuffer().buffer.ToManagedArray()) { if (conn.machineRigidBodyId == sbid) set.Add(new Block(conn.ID)); diff --git a/GamecraftModdingAPI/Blocks/BlockEngineInit.cs b/GamecraftModdingAPI/Blocks/BlockEngineInit.cs index 70f713a..1bf6c15 100644 --- a/GamecraftModdingAPI/Blocks/BlockEngineInit.cs +++ b/GamecraftModdingAPI/Blocks/BlockEngineInit.cs @@ -14,10 +14,10 @@ namespace GamecraftModdingAPI.Blocks /// internal struct BlockInitData { - public FasterDictionary, ITypeSafeDictionary> Group; + public FasterDictionary Group; } - internal delegate FasterDictionary, ITypeSafeDictionary> GetInitGroup( + internal delegate FasterDictionary GetInitGroup( EntityComponentInitializer initializer); /// diff --git a/GamecraftModdingAPI/Blocks/ConsoleBlock.cs b/GamecraftModdingAPI/Blocks/ConsoleBlock.cs index c8982e4..e696fca 100644 --- a/GamecraftModdingAPI/Blocks/ConsoleBlock.cs +++ b/GamecraftModdingAPI/Blocks/ConsoleBlock.cs @@ -16,7 +16,7 @@ namespace GamecraftModdingAPI.Blocks { } - public ConsoleBlock(uint id): base(new EGID(id, CommonExclusiveGroups.BUILD_CONSOLE_BLOCK_GROUP)) + public ConsoleBlock(uint id): base(new EGID(id, CommonExclusiveGroups.CONSOLE_BLOCK_GROUP)) { } diff --git a/GamecraftModdingAPI/Blocks/DampedSpring.cs b/GamecraftModdingAPI/Blocks/DampedSpring.cs index 96e628d..5a5a936 100644 --- a/GamecraftModdingAPI/Blocks/DampedSpring.cs +++ b/GamecraftModdingAPI/Blocks/DampedSpring.cs @@ -10,7 +10,7 @@ namespace GamecraftModdingAPI.Blocks { } - public DampedSpring(uint id) : base(new EGID(id, CommonExclusiveGroups.BUILD_DAMPEDSPRING_BLOCK_GROUP)) + public DampedSpring(uint id) : base(new EGID(id, CommonExclusiveGroups.DAMPEDSPRING_BLOCK_GROUP)) { } diff --git a/GamecraftModdingAPI/Blocks/LogicGate.cs b/GamecraftModdingAPI/Blocks/LogicGate.cs index 124bc10..2ec4cef 100644 --- a/GamecraftModdingAPI/Blocks/LogicGate.cs +++ b/GamecraftModdingAPI/Blocks/LogicGate.cs @@ -9,7 +9,7 @@ namespace GamecraftModdingAPI.Blocks { } - public LogicGate(uint id) : base(new EGID(id, CommonExclusiveGroups.BUILD_LOGIC_BLOCK_GROUP)) + public LogicGate(uint id) : base(new EGID(id, CommonExclusiveGroups.LOGIC_BLOCK_GROUP)) { } } diff --git a/GamecraftModdingAPI/Blocks/Motor.cs b/GamecraftModdingAPI/Blocks/Motor.cs index 3c38a52..0a69d27 100644 --- a/GamecraftModdingAPI/Blocks/Motor.cs +++ b/GamecraftModdingAPI/Blocks/Motor.cs @@ -15,7 +15,7 @@ namespace GamecraftModdingAPI.Blocks { } - public Motor(uint id): base(new EGID(id, CommonExclusiveGroups.BUILD_MOTOR_BLOCK_GROUP)) + public Motor(uint id): base(new EGID(id, CommonExclusiveGroups.MOTOR_BLOCK_GROUP)) { } diff --git a/GamecraftModdingAPI/Blocks/MusicBlock.cs b/GamecraftModdingAPI/Blocks/MusicBlock.cs index fc3c880..6b99b6f 100644 --- a/GamecraftModdingAPI/Blocks/MusicBlock.cs +++ b/GamecraftModdingAPI/Blocks/MusicBlock.cs @@ -20,7 +20,7 @@ namespace GamecraftModdingAPI.Blocks { } - public MusicBlock(uint id) : base(new EGID(id, CommonExclusiveGroups.BUILD_MUSIC_BLOCK_GROUP)) + public MusicBlock(uint id) : base(new EGID(id, CommonExclusiveGroups.MUSIC_BLOCK_GROUP)) { } diff --git a/GamecraftModdingAPI/Blocks/ObjectIdentifier.cs b/GamecraftModdingAPI/Blocks/ObjectIdentifier.cs index 0dc835a..1233343 100644 --- a/GamecraftModdingAPI/Blocks/ObjectIdentifier.cs +++ b/GamecraftModdingAPI/Blocks/ObjectIdentifier.cs @@ -10,7 +10,7 @@ namespace GamecraftModdingAPI.Blocks { } - public ObjectIdentifier(uint id) : base(new EGID(id, CommonExclusiveGroups.BUILD_OBJID_BLOCK_GROUP)) + public ObjectIdentifier(uint id) : base(new EGID(id, CommonExclusiveGroups.OBJID_BLOCK_GROUP)) { } diff --git a/GamecraftModdingAPI/Blocks/Piston.cs b/GamecraftModdingAPI/Blocks/Piston.cs index c3f2497..04b3aeb 100644 --- a/GamecraftModdingAPI/Blocks/Piston.cs +++ b/GamecraftModdingAPI/Blocks/Piston.cs @@ -15,7 +15,7 @@ namespace GamecraftModdingAPI.Blocks { } - public Piston(uint id) : base(new EGID(id, CommonExclusiveGroups.BUILD_PISTON_BLOCK_GROUP)) + public Piston(uint id) : base(new EGID(id, CommonExclusiveGroups.PISTON_BLOCK_GROUP)) { } diff --git a/GamecraftModdingAPI/Blocks/PlacementEngine.cs b/GamecraftModdingAPI/Blocks/PlacementEngine.cs index cb1cdee..cf9a80f 100644 --- a/GamecraftModdingAPI/Blocks/PlacementEngine.cs +++ b/GamecraftModdingAPI/Blocks/PlacementEngine.cs @@ -16,6 +16,7 @@ using UnityEngine; using GamecraftModdingAPI.Utility; using GamecraftModdingAPI.Engines; using GamecraftModdingAPI.Players; +using RobocraftX.Rendering.GPUI; namespace GamecraftModdingAPI.Blocks { @@ -81,7 +82,7 @@ namespace GamecraftModdingAPI.Blocks structInitializer.Init(new ColourParameterEntityStruct { indexInPalette = colour.indexInPalette, - needsUpdate = true + hasNetworkChange = true }); uint prefabId = PrefabsID.GetPrefabId(dbid, 0); structInitializer.Init(new GFXPrefabEntityStructGPUI(prefabId)); diff --git a/GamecraftModdingAPI/Blocks/Servo.cs b/GamecraftModdingAPI/Blocks/Servo.cs index 1177fb6..606a48a 100644 --- a/GamecraftModdingAPI/Blocks/Servo.cs +++ b/GamecraftModdingAPI/Blocks/Servo.cs @@ -15,7 +15,7 @@ namespace GamecraftModdingAPI.Blocks { } - public Servo(uint id) : base(new EGID(id, CommonExclusiveGroups.BUILD_SERVO_BLOCK_GROUP)) + public Servo(uint id) : base(new EGID(id, CommonExclusiveGroups.SERVO_BLOCK_GROUP)) { } diff --git a/GamecraftModdingAPI/Blocks/SfxBlock.cs b/GamecraftModdingAPI/Blocks/SfxBlock.cs index f7efe6d..88d69d2 100644 --- a/GamecraftModdingAPI/Blocks/SfxBlock.cs +++ b/GamecraftModdingAPI/Blocks/SfxBlock.cs @@ -14,7 +14,7 @@ namespace GamecraftModdingAPI.Blocks { } - public SfxBlock(uint id) : base(new EGID(id, CommonExclusiveGroups.BUILD_SIMPLESFX_BLOCK_GROUP /* This could also be BUILD_LOOPEDSFX_BLOCK_GROUP */)) + public SfxBlock(uint id) : base(new EGID(id, CommonExclusiveGroups.SIMPLESFX_BLOCK_GROUP /* This could also be BUILD_LOOPEDSFX_BLOCK_GROUP */)) { } diff --git a/GamecraftModdingAPI/Blocks/SignalEngine.cs b/GamecraftModdingAPI/Blocks/SignalEngine.cs index 763a1a1..0980d79 100644 --- a/GamecraftModdingAPI/Blocks/SignalEngine.cs +++ b/GamecraftModdingAPI/Blocks/SignalEngine.cs @@ -115,7 +115,8 @@ namespace GamecraftModdingAPI.Blocks public bool SetSignal(uint signalID, float signal, bool input = true) { var array = GetSignalStruct(signalID, out uint index, input); - if (array.count > 0) array[index].valueAsFloat = signal; + var arrayB = array.ToBuffer(); + if (array.count > 0) arrayB.buffer[index].valueAsFloat = signal; return false; } @@ -128,9 +129,10 @@ namespace GamecraftModdingAPI.Blocks public float AddSignal(uint signalID, float signal, bool clamp = true, bool input = true) { var array = GetSignalStruct(signalID, out uint index, input); + var arrayB = array.ToBuffer(); if (array.count > 0) { - ref var channelData = ref array[index]; + ref var channelData = ref arrayB.buffer[index]; channelData.valueAsFloat += signal; if (clamp) { @@ -159,7 +161,8 @@ namespace GamecraftModdingAPI.Blocks public float GetSignal(uint signalID, bool input = true) { var array = GetSignalStruct(signalID, out uint index, input); - return array.count > 0 ? array[index].valueAsFloat : 0f; + var arrayB = array.ToBuffer(); + return array.count > 0 ? arrayB.buffer[index].valueAsFloat : 0f; } public uint[] GetSignalIDs(EGID blockID, bool input = true) @@ -244,13 +247,14 @@ namespace GamecraftModdingAPI.Blocks { ref PortEntityStruct port = ref entitiesDB.QueryEntity(portID); var wires = entitiesDB.QueryEntities(NamedExclusiveGroup.Group); + var wiresB = wires.ToBuffer().buffer; for (uint i = 0; i < wires.count; i++) { - if ((wires[i].destinationPortUsage == port.usage && wires[i].destinationBlockEGID == blockID) - || (wires[i].sourcePortUsage == port.usage && wires[i].sourceBlockEGID == blockID)) + if ((wiresB[i].destinationPortUsage == port.usage && wiresB[i].destinationBlockEGID == blockID) + || (wiresB[i].sourcePortUsage == port.usage && wiresB[i].sourceBlockEGID == blockID)) { exists = true; - return ref wires[i]; + return ref wiresB[i]; } } exists = false; @@ -286,6 +290,7 @@ namespace GamecraftModdingAPI.Blocks } EntityCollection wires = entitiesDB.QueryEntities(NamedExclusiveGroup.Group); + var wiresB = wires.ToBuffer().buffer; for (int endIndex = 0; endIndex < endPorts.Length; endIndex++) { PortEntityStruct endPES = entitiesDB.QueryEntity(endPorts[endIndex]); @@ -294,11 +299,11 @@ namespace GamecraftModdingAPI.Blocks PortEntityStruct startPES = entitiesDB.QueryEntity(startPorts[startIndex]); for (int w = 0; w < wires.count; w++) { - if ((wires[w].destinationPortUsage == endPES.usage && wires[w].destinationBlockEGID == endBlock) - && (wires[w].sourcePortUsage == startPES.usage && wires[w].sourceBlockEGID == startBlock)) + if ((wiresB[w].destinationPortUsage == endPES.usage && wiresB[w].destinationBlockEGID == endBlock) + && (wiresB[w].sourcePortUsage == startPES.usage && wiresB[w].sourceBlockEGID == startBlock)) { exists = true; - return ref wires[w]; + return ref wiresB[w]; } } } @@ -313,10 +318,11 @@ namespace GamecraftModdingAPI.Blocks { ref PortEntityStruct port = ref entitiesDB.QueryEntity(portID); var channels = entitiesDB.QueryEntities(NamedExclusiveGroup.Group); + var channelsB = channels.ToBuffer(); if (port.firstChannelIndexCachedInSim < channels.count) { exists = true; - return ref channels[port.firstChannelIndexCachedInSim]; + return ref channelsB.buffer[port.firstChannelIndexCachedInSim]; } exists = false; ChannelDataStruct[] defRef = new ChannelDataStruct[1]; @@ -327,8 +333,15 @@ namespace GamecraftModdingAPI.Blocks { var res = new FasterList(); foreach (var (coll, _) in entitiesDB.QueryEntities()) - foreach (ref BlockPortsStruct s in coll) - res.Add(s.ID); + { + var collB = coll.ToBuffer(); + for (int i = 0; i < coll.count; i++) + { + ref BlockPortsStruct s = ref collB.buffer[i]; + res.Add(s.ID); + } + } + return res.ToArray(); } @@ -358,15 +371,16 @@ namespace GamecraftModdingAPI.Blocks return result; } - private T[] Search(ExclusiveGroup group, Func isMatch) where T : struct, IEntityComponent + private T[] Search(ExclusiveGroup group, Func isMatch) where T : unmanaged, IEntityComponent { FasterList results = new FasterList(); EntityCollection components = entitiesDB.QueryEntities(group); + var componentsB = components.ToBuffer(); for (uint i = 0; i < components.count; i++) { - if (isMatch(components[i])) + if (isMatch(componentsB.buffer[i])) { - results.Add(components[i]); + results.Add(componentsB.buffer[i]); } } return results.ToArray(); diff --git a/GamecraftModdingAPI/Blocks/SpawnPoint.cs b/GamecraftModdingAPI/Blocks/SpawnPoint.cs index 7616acb..17bffd9 100644 --- a/GamecraftModdingAPI/Blocks/SpawnPoint.cs +++ b/GamecraftModdingAPI/Blocks/SpawnPoint.cs @@ -17,7 +17,7 @@ namespace GamecraftModdingAPI.Blocks { } - public SpawnPoint(uint id) : base(new EGID(id, CommonExclusiveGroups.BUILD_SPAWNPOINT_BLOCK_GROUP)) + public SpawnPoint(uint id) : base(new EGID(id, CommonExclusiveGroups.SPAWNPOINT_BLOCK_GROUP)) { } diff --git a/GamecraftModdingAPI/Blocks/TextBlock.cs b/GamecraftModdingAPI/Blocks/TextBlock.cs index 895494d..d7d620a 100644 --- a/GamecraftModdingAPI/Blocks/TextBlock.cs +++ b/GamecraftModdingAPI/Blocks/TextBlock.cs @@ -16,7 +16,7 @@ namespace GamecraftModdingAPI.Blocks { } - public TextBlock(uint id) : base(new EGID(id, CommonExclusiveGroups.BUILD_TEXT_BLOCK_GROUP)) + public TextBlock(uint id) : base(new EGID(id, CommonExclusiveGroups.TEXT_BLOCK_GROUP)) { } diff --git a/GamecraftModdingAPI/Blocks/Timer.cs b/GamecraftModdingAPI/Blocks/Timer.cs index 1aeecd9..0bbd302 100644 --- a/GamecraftModdingAPI/Blocks/Timer.cs +++ b/GamecraftModdingAPI/Blocks/Timer.cs @@ -17,7 +17,7 @@ namespace GamecraftModdingAPI.Blocks { } - public Timer(uint id) : base(new EGID(id, CommonExclusiveGroups.BUILD_TIMER_BLOCK_GROUP)) + public Timer(uint id) : base(new EGID(id, CommonExclusiveGroups.TIMER_BLOCK_GROUP)) { } diff --git a/GamecraftModdingAPI/Inventory/HotbarEngine.cs b/GamecraftModdingAPI/Inventory/HotbarEngine.cs index d5eb2d8..34cdf12 100644 --- a/GamecraftModdingAPI/Inventory/HotbarEngine.cs +++ b/GamecraftModdingAPI/Inventory/HotbarEngine.cs @@ -36,13 +36,13 @@ namespace GamecraftModdingAPI.Inventory public bool SelectBlock(int block, uint playerID, bool cubeSelectedByPick = false) { - var inputs = entitiesDB.QueryEntities(InputExclusiveGroups.LocalPlayers); + var inputs = entitiesDB.QueryEntities(InputExclusiveGroups.LocalPlayers).ToBuffer(); if (inputs.count == 0) return false; for (int i = 0; i < inputs.count; i++) { - if (inputs[i].ID.entityID == playerID) { - inputs[i].cubeSelectedByPick = cubeSelectedByPick; - inputs[i].selectedCube = block; + if (inputs.buffer[i].ID.entityID == playerID) { + inputs.buffer[i].cubeSelectedByPick = cubeSelectedByPick; + inputs.buffer[i].selectedCube = block; return true; } } diff --git a/GamecraftModdingAPI/Players/PlayerEngine.cs b/GamecraftModdingAPI/Players/PlayerEngine.cs index 6d461f2..e253eac 100644 --- a/GamecraftModdingAPI/Players/PlayerEngine.cs +++ b/GamecraftModdingAPI/Players/PlayerEngine.cs @@ -50,10 +50,10 @@ namespace GamecraftModdingAPI.Players public uint GetLocalPlayer() { if (!isReady) return uint.MaxValue; - var localPlayers = entitiesDB.QueryEntities(PlayersExclusiveGroups.LocalPlayers); + var localPlayers = entitiesDB.QueryEntities(PlayersExclusiveGroups.LocalPlayers).ToBuffer(); if (localPlayers.count > 0) { - return localPlayers[0].ID.entityID; + return localPlayers.buffer[0].ID.entityID; } return uint.MaxValue; } @@ -61,10 +61,10 @@ namespace GamecraftModdingAPI.Players public uint GetRemotePlayer() { if (!isReady) return uint.MaxValue; - var localPlayers = entitiesDB.QueryEntities(PlayersExclusiveGroups.RemotePlayers); + var localPlayers = entitiesDB.QueryEntities(PlayersExclusiveGroups.RemotePlayers).ToBuffer(); if (localPlayers.count > 0) { - return localPlayers[0].ID.entityID; + return localPlayers.buffer[0].ID.entityID; } return uint.MaxValue; } diff --git a/GamecraftModdingAPI/Tests/TestRoot.cs b/GamecraftModdingAPI/Tests/TestRoot.cs index 6acb51c..22f3035 100644 --- a/GamecraftModdingAPI/Tests/TestRoot.cs +++ b/GamecraftModdingAPI/Tests/TestRoot.cs @@ -65,7 +65,7 @@ namespace GamecraftModdingAPI.Tests _testsCountPassed = 0; _testsCountFailed = 0; // flow control - Game.Enter += (sender, args) => { GameTests().RunOn(RobocraftX.Schedulers.Lean.EveryFrameStepRunner_RUNS_IN_TIME_STOPPED_AND_RUNNING); }; + Game.Enter += (sender, args) => { GameTests().RunOn(RobocraftX.Schedulers.Lean.EveryFrameStepRunner_TimeRunningAndStopped); }; Game.Exit += (s, a) => state = "ReturningFromGame"; Client.EnterMenu += (sender, args) => {