Fix build errors from beta hotfix 1

This commit is contained in:
NGnius (Graham) 2020-11-09 16:18:25 -05:00 committed by NorbiPeti
parent 987fbe673a
commit 08138e3589
23 changed files with 119 additions and 86 deletions

View file

@ -46,11 +46,12 @@ namespace GamecraftModdingAPI.App
public Game[] GetMyGames() public Game[] GetMyGames()
{ {
EntityCollection<MyGameDataEntityStruct> mgsevs = entitiesDB.QueryEntities<MyGameDataEntityStruct>(MyGamesScreenExclusiveGroups.MyGames); EntityCollection<MyGameDataEntityStruct> mgsevs = entitiesDB.QueryEntities<MyGameDataEntityStruct>(MyGamesScreenExclusiveGroups.MyGames);
var mgsevsB = mgsevs.ToBuffer().buffer;
Game[] games = new Game[mgsevs.count]; Game[] games = new Game[mgsevs.count];
for (int i = 0; i < mgsevs.count; i++) for (int i = 0; i < mgsevs.count; i++)
{ {
Utility.Logging.MetaDebugLog($"Found game named {mgsevs[i].GameName}"); Utility.Logging.MetaDebugLog($"Found game named {mgsevsB[i].GameName}");
games[i] = new Game(mgsevs[i].ID); games[i] = new Game(mgsevsB[i].ID);
} }
return games; return games;
} }

View file

@ -52,7 +52,7 @@ namespace GamecraftModdingAPI.App
{ {
if (async) if (async)
{ {
ExitCurrentGameAsync().RunOn(Lean.EveryFrameStepRunner_RUNS_IN_TIME_STOPPED_AND_RUNNING); ExitCurrentGameAsync().RunOn(Lean.EveryFrameStepRunner_TimeRunningAndStopped);
} }
else else
{ {
@ -102,14 +102,14 @@ namespace GamecraftModdingAPI.App
if (filter == BlockIDs.Invalid) if (filter == BlockIDs.Invalid)
{ {
foreach (var (blocks, _) in allBlocks) foreach (var (blocks, _) in allBlocks)
foreach (var block in blocks) foreach (var block in blocks.ToBuffer().buffer.ToManagedArray())
blockEGIDs.Add(block.ID); blockEGIDs.Add(block.ID);
return blockEGIDs.ToArray(); return blockEGIDs.ToArray();
} }
else else
{ {
foreach (var (blocks, _) in allBlocks) foreach (var (blocks, _) in allBlocks)
foreach (var block in blocks) foreach (var block in blocks.ToBuffer().buffer.ToManagedArray())
if (block.DBID == (ulong) filter) if (block.DBID == (ulong) filter)
blockEGIDs.Add(block.ID); blockEGIDs.Add(block.ID);
return blockEGIDs.ToArray(); return blockEGIDs.ToArray();

View file

@ -61,12 +61,13 @@ namespace GamecraftModdingAPI.App
public uint HighestID() public uint HighestID()
{ {
EntityCollection<MyGameDataEntityStruct> games = entitiesDB.QueryEntities<MyGameDataEntityStruct>(MyGamesScreenExclusiveGroups.MyGames); EntityCollection<MyGameDataEntityStruct> games = entitiesDB.QueryEntities<MyGameDataEntityStruct>(MyGamesScreenExclusiveGroups.MyGames);
var gamesB = games.ToBuffer().buffer;
uint max = 0; uint max = 0;
for (int i = 0; i < games.count; i++) 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; return max;
@ -118,11 +119,12 @@ namespace GamecraftModdingAPI.App
{ {
EntityCollection<MyGamesSlotEntityViewStruct> entities = EntityCollection<MyGamesSlotEntityViewStruct> entities =
entitiesDB.QueryEntities<MyGamesSlotEntityViewStruct>(MyGamesScreenExclusiveGroups.GameSlotGuiEntities); entitiesDB.QueryEntities<MyGamesSlotEntityViewStruct>(MyGamesScreenExclusiveGroups.GameSlotGuiEntities);
var entitiesB = entities.ToBuffer().buffer;
for (int i = 0; i < entities.count; i++) 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]; MyGamesSlotEntityViewStruct[] defRef = new MyGamesSlotEntityViewStruct[1];

View file

@ -116,32 +116,32 @@ namespace GamecraftModdingAPI
private static Dictionary<Type, ExclusiveGroupStruct[]> typeToGroup = private static Dictionary<Type, ExclusiveGroupStruct[]> typeToGroup =
new Dictionary<Type, ExclusiveGroupStruct[]> new Dictionary<Type, ExclusiveGroupStruct[]>
{ {
{typeof(ConsoleBlock), new[] {CommonExclusiveGroups.BUILD_CONSOLE_BLOCK_GROUP}}, {typeof(ConsoleBlock), new[] {CommonExclusiveGroups.CONSOLE_BLOCK_GROUP}},
{typeof(LogicGate), new [] {CommonExclusiveGroups.BUILD_LOGIC_BLOCK_GROUP}}, {typeof(LogicGate), new [] {CommonExclusiveGroups.LOGIC_BLOCK_GROUP}},
{typeof(Motor), new[] {CommonExclusiveGroups.BUILD_MOTOR_BLOCK_GROUP}}, {typeof(Motor), new[] {CommonExclusiveGroups.MOTOR_BLOCK_GROUP}},
{typeof(MusicBlock), new[] {CommonExclusiveGroups.BUILD_MUSIC_BLOCK_GROUP}}, {typeof(MusicBlock), new[] {CommonExclusiveGroups.MUSIC_BLOCK_GROUP}},
{typeof(ObjectIdentifier), new[]{CommonExclusiveGroups.BUILD_OBJID_BLOCK_GROUP}}, {typeof(ObjectIdentifier), new[]{CommonExclusiveGroups.OBJID_BLOCK_GROUP}},
{typeof(Piston), new[] {CommonExclusiveGroups.BUILD_PISTON_BLOCK_GROUP}}, {typeof(Piston), new[] {CommonExclusiveGroups.PISTON_BLOCK_GROUP}},
{typeof(Servo), new[] {CommonExclusiveGroups.BUILD_SERVO_BLOCK_GROUP}}, {typeof(Servo), new[] {CommonExclusiveGroups.SERVO_BLOCK_GROUP}},
{ {
typeof(SpawnPoint), typeof(SpawnPoint),
new[] new[]
{ {
CommonExclusiveGroups.BUILD_SPAWNPOINT_BLOCK_GROUP, CommonExclusiveGroups.SPAWNPOINT_BLOCK_GROUP,
CommonExclusiveGroups.BUILD_BUILDINGSPAWN_BLOCK_GROUP CommonExclusiveGroups.BUILDINGSPAWN_BLOCK_GROUP
} }
}, },
{ {
typeof(SfxBlock), typeof(SfxBlock),
new[] new[]
{ {
CommonExclusiveGroups.BUILD_SIMPLESFX_BLOCK_GROUP, CommonExclusiveGroups.SIMPLESFX_BLOCK_GROUP,
CommonExclusiveGroups.BUILD_LOOPEDSFX_BLOCK_GROUP CommonExclusiveGroups.LOOPEDSFX_BLOCK_GROUP
} }
}, },
{typeof(DampedSpring), new [] {CommonExclusiveGroups.BUILD_DAMPEDSPRING_BLOCK_GROUP}}, {typeof(DampedSpring), new [] {CommonExclusiveGroups.DAMPEDSPRING_BLOCK_GROUP}},
{typeof(TextBlock), new[] {CommonExclusiveGroups.BUILD_TEXT_BLOCK_GROUP}}, {typeof(TextBlock), new[] {CommonExclusiveGroups.TEXT_BLOCK_GROUP}},
{typeof(Timer), new[] {CommonExclusiveGroups.BUILD_TIMER_BLOCK_GROUP}} {typeof(Timer), new[] {CommonExclusiveGroups.TIMER_BLOCK_GROUP}}
}; };
/// <summary> /// <summary>
@ -312,8 +312,9 @@ namespace GamecraftModdingAPI
BlockEngine.SetBlockInfo(this, (ref ColourParameterEntityStruct color, BlockColor val) => BlockEngine.SetBlockInfo(this, (ref ColourParameterEntityStruct color, BlockColor val) =>
{ {
color.indexInPalette = (byte) (val.Color + val.Darkness * 10); color.indexInPalette = (byte) (val.Color + val.Darkness * 10);
color.overridePaletteColour = false; //color.overridePaletteColour = false;
color.needsUpdate = true; //color.needsUpdate = true;
color.hasNetworkChange = true;
color.paletteColour = BlockEngine.ConvertBlockColor(color.indexInPalette); color.paletteColour = BlockEngine.ConvertBlockColor(color.indexInPalette);
}, value); }, value);
} }
@ -324,14 +325,15 @@ namespace GamecraftModdingAPI
/// </summary> /// </summary>
public float4 CustomColor public float4 CustomColor
{ {
get => BlockEngine.GetBlockInfo(this, (ColourParameterEntityStruct st) => st.overriddenColour); get => BlockEngine.GetBlockInfo(this, (ColourParameterEntityStruct st) => st.paletteColour);
set set
{ {
BlockEngine.SetBlockInfo(this, (ref ColourParameterEntityStruct color, float4 val) => BlockEngine.SetBlockInfo(this, (ref ColourParameterEntityStruct color, float4 val) =>
{ {
color.overriddenColour = val; color.paletteColour = val;
color.overridePaletteColour = true; //color.overridePaletteColour = true;
color.needsUpdate = true; //color.needsUpdate = true;
color.hasNetworkChange = true;
}, value); }, value);
} }
} }

View file

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using Gamecraft.ColourPalette; using Gamecraft.ColourPalette;
using Gamecraft.TimeRunning;
using Gamecraft.Wires; using Gamecraft.Wires;
using RobocraftX.Blocks; using RobocraftX.Blocks;
using RobocraftX.Common; using RobocraftX.Common;
@ -43,8 +44,14 @@ namespace GamecraftModdingAPI.Blocks
FasterList<EGID> cubes = new FasterList<EGID>(10); FasterList<EGID> cubes = new FasterList<EGID>(10);
var coll = entitiesDB.QueryEntities<GridConnectionsEntityStruct>(); var coll = entitiesDB.QueryEntities<GridConnectionsEntityStruct>();
foreach (var (ecoll, _) in coll) foreach (var (ecoll, _) in coll)
foreach (ref var conn in ecoll) {
var ecollB = ecoll.ToBuffer();
for(int i = 0; i < ecoll.count; i++)
{
ref var conn = ref ecollB.buffer[i];
conn.isProcessed = false; conn.isProcessed = false;
}
}
ConnectedCubesUtility.TreeTraversal.GetConnectedCubes(entitiesDB, blockID, cubeStack, cubes, ConnectedCubesUtility.TreeTraversal.GetConnectedCubes(entitiesDB, blockID, cubeStack, cubes,
(in GridConnectionsEntityStruct g) => { return false; }); (in GridConnectionsEntityStruct g) => { return false; });
@ -68,17 +75,17 @@ namespace GamecraftModdingAPI.Blocks
return ref structHolder[0]; //Gets a default value automatically return ref structHolder[0]; //Gets a default value automatically
} }
public ref T GetBlockInfoViewStruct<T>(EGID blockID) where T : struct, INeedEGID, IEntityComponent public ref T GetBlockInfoViewStruct<T>(EGID blockID) where T : struct, INeedEGID, IEntityViewComponent
{ {
if (entitiesDB.Exists<T>(blockID)) if (entitiesDB.Exists<T>(blockID))
{ {
// TODO: optimize by using EntitiesDB internal calls instead of iterating over everything // TODO: optimize by using EntitiesDB internal calls instead of iterating over everything
EntityCollection<T> entities = entitiesDB.QueryEntities<T>(blockID.groupID); BT<MB<T>> entities = entitiesDB.QueryEntities<T>(blockID.groupID).ToBuffer();
for (int i = 0; i < entities.count; i++) 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) public SimBody[] GetSimBodiesFromID(byte id)
{ {
var ret = new FasterList<SimBody>(4); var ret = new FasterList<SimBody>(4);
if (!entitiesDB.HasAny<ObjectIdEntityStruct>(CommonExclusiveGroups.BUILD_OBJID_BLOCK_GROUP)) if (!entitiesDB.HasAny<ObjectIdEntityStruct>(CommonExclusiveGroups.OBJID_BLOCK_GROUP))
return new SimBody[0]; return new SimBody[0];
var oids = entitiesDB.QueryEntities<ObjectIdEntityStruct>(CommonExclusiveGroups.BUILD_OBJID_BLOCK_GROUP); var oids = entitiesDB.QueryEntities<ObjectIdEntityStruct>(CommonExclusiveGroups.OBJID_BLOCK_GROUP).ToBuffer();
var connections = entitiesDB.QueryMappedEntities<GridConnectionsEntityStruct>(CommonExclusiveGroups.BUILD_OBJID_BLOCK_GROUP); var connections = entitiesDB.QueryMappedEntities<GridConnectionsEntityStruct>(CommonExclusiveGroups.OBJID_BLOCK_GROUP);
foreach (ref ObjectIdEntityStruct oid in oids) for (int i = 0; i < oids.count; i++)
{ {
ref ObjectIdEntityStruct oid = ref oids.buffer[i];
if (oid.objectId != id) continue; if (oid.objectId != id) continue;
var rid = connections.Entity(oid.ID.entityID).machineRigidBodyId; var rid = connections.Entity(oid.ID.entityID).machineRigidBodyId;
foreach (var rb in ret) foreach (var rb in ret)
@ -182,21 +190,26 @@ 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.BUILD_OBJID_BLOCK_GROUP)) if (!entitiesDB.HasAny<ObjectIdEntityStruct>(CommonExclusiveGroups.OBJID_BLOCK_GROUP))
return new ObjectIdentifier[0]; return new ObjectIdentifier[0];
var oids = entitiesDB.QueryEntities<ObjectIdEntityStruct>(CommonExclusiveGroups.BUILD_OBJID_BLOCK_GROUP); var oids = entitiesDB.QueryEntities<ObjectIdEntityStruct>(CommonExclusiveGroups.OBJID_BLOCK_GROUP).ToBuffer();
foreach (ref ObjectIdEntityStruct oid in oids) for (int i = 0; i < oids.count; i++)
{
ref ObjectIdEntityStruct oid = ref oids.buffer[i];
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));
}
return ret.ToArray(); return ret.ToArray();
} }
public SimBody[] GetConnectedSimBodies(uint id) public SimBody[] GetConnectedSimBodies(uint id)
{ {
var joints = entitiesDB.QueryEntities<JointEntityStruct>(MachineSimulationGroups.JOINTS_GROUP); var joints = entitiesDB.QueryEntities<JointEntityStruct>(MachineSimulationGroups.JOINTS_GROUP).ToBuffer();
var list = new FasterList<SimBody>(4); var list = new FasterList<SimBody>(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.jointState == JointState.Broken) continue;
if (joint.connectedEntityA == id) list.Add(new SimBody(joint.connectedEntityB)); if (joint.connectedEntityA == id) list.Add(new SimBody(joint.connectedEntityB));
else if (joint.connectedEntityB == id) list.Add(new SimBody(joint.connectedEntityA)); else if (joint.connectedEntityB == id) list.Add(new SimBody(joint.connectedEntityA));
@ -211,7 +224,7 @@ namespace GamecraftModdingAPI.Blocks
var bodies = new HashSet<uint>(); var bodies = new HashSet<uint>();
foreach (var (coll, _) in groups) foreach (var (coll, _) in groups)
{ {
foreach (var conn in coll) foreach (var conn in coll.ToBuffer().buffer.ToManagedArray())
{ {
if (conn.clusterId == cid) if (conn.clusterId == cid)
bodies.Add(conn.machineRigidBodyId); bodies.Add(conn.machineRigidBodyId);
@ -238,7 +251,7 @@ namespace GamecraftModdingAPI.Blocks
var groups = entitiesDB.QueryEntities<GridConnectionsEntityStruct>(); var groups = entitiesDB.QueryEntities<GridConnectionsEntityStruct>();
foreach (var (coll, _) in groups) 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 { //Static blocks don't have a cluster ID but the cluster destruction manager should have one
if (conn.machineRigidBodyId == sbid && conn.clusterId != uint.MaxValue) if (conn.machineRigidBodyId == sbid && conn.clusterId != uint.MaxValue)
return new Cluster(conn.clusterId); return new Cluster(conn.clusterId);
@ -254,7 +267,7 @@ namespace GamecraftModdingAPI.Blocks
var set = new HashSet<Block>(); var set = new HashSet<Block>();
foreach (var (coll, _) in groups) foreach (var (coll, _) in groups)
{ {
foreach (var conn in coll) foreach (var conn in coll.ToBuffer().buffer.ToManagedArray())
{ {
if (conn.machineRigidBodyId == sbid) if (conn.machineRigidBodyId == sbid)
set.Add(new Block(conn.ID)); set.Add(new Block(conn.ID));

View file

@ -14,10 +14,10 @@ namespace GamecraftModdingAPI.Blocks
/// </summary> /// </summary>
internal struct BlockInitData internal struct BlockInitData
{ {
public FasterDictionary<RefWrapper<Type>, ITypeSafeDictionary> Group; public FasterDictionary<RefWrapperType, ITypeSafeDictionary> Group;
} }
internal delegate FasterDictionary<RefWrapper<Type>, ITypeSafeDictionary> GetInitGroup( internal delegate FasterDictionary<RefWrapperType, ITypeSafeDictionary> GetInitGroup(
EntityComponentInitializer initializer); EntityComponentInitializer initializer);
/// <summary> /// <summary>

View file

@ -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))
{ {
} }

View file

@ -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))
{ {
} }

View file

@ -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))
{ {
} }
} }

View file

@ -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))
{ {
} }

View file

@ -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))
{ {
} }

View file

@ -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))
{ {
} }

View file

@ -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))
{ {
} }

View file

@ -16,6 +16,7 @@ using UnityEngine;
using GamecraftModdingAPI.Utility; using GamecraftModdingAPI.Utility;
using GamecraftModdingAPI.Engines; using GamecraftModdingAPI.Engines;
using GamecraftModdingAPI.Players; using GamecraftModdingAPI.Players;
using RobocraftX.Rendering.GPUI;
namespace GamecraftModdingAPI.Blocks namespace GamecraftModdingAPI.Blocks
{ {
@ -81,7 +82,7 @@ namespace GamecraftModdingAPI.Blocks
structInitializer.Init(new ColourParameterEntityStruct structInitializer.Init(new ColourParameterEntityStruct
{ {
indexInPalette = colour.indexInPalette, indexInPalette = colour.indexInPalette,
needsUpdate = true hasNetworkChange = true
}); });
uint prefabId = PrefabsID.GetPrefabId(dbid, 0); uint prefabId = PrefabsID.GetPrefabId(dbid, 0);
structInitializer.Init(new GFXPrefabEntityStructGPUI(prefabId)); structInitializer.Init(new GFXPrefabEntityStructGPUI(prefabId));

View file

@ -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))
{ {
} }

View file

@ -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 */))
{ {
} }

View file

@ -115,7 +115,8 @@ namespace GamecraftModdingAPI.Blocks
public bool SetSignal(uint signalID, float signal, bool input = true) public bool SetSignal(uint signalID, float signal, bool input = true)
{ {
var array = GetSignalStruct(signalID, out uint index, input); 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; return false;
} }
@ -128,9 +129,10 @@ namespace GamecraftModdingAPI.Blocks
public float AddSignal(uint signalID, float signal, bool clamp = true, bool input = true) public float AddSignal(uint signalID, float signal, bool clamp = true, bool input = true)
{ {
var array = GetSignalStruct(signalID, out uint index, input); var array = GetSignalStruct(signalID, out uint index, input);
var arrayB = array.ToBuffer();
if (array.count > 0) if (array.count > 0)
{ {
ref var channelData = ref array[index]; ref var channelData = ref arrayB.buffer[index];
channelData.valueAsFloat += signal; channelData.valueAsFloat += signal;
if (clamp) if (clamp)
{ {
@ -159,7 +161,8 @@ namespace GamecraftModdingAPI.Blocks
public float GetSignal(uint signalID, bool input = true) public float GetSignal(uint signalID, bool input = true)
{ {
var array = GetSignalStruct(signalID, out uint index, input); 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) public uint[] GetSignalIDs(EGID blockID, bool input = true)
@ -244,13 +247,14 @@ namespace GamecraftModdingAPI.Blocks
{ {
ref PortEntityStruct port = ref entitiesDB.QueryEntity<PortEntityStruct>(portID); ref PortEntityStruct port = ref entitiesDB.QueryEntity<PortEntityStruct>(portID);
var wires = entitiesDB.QueryEntities<WireEntityStruct>(NamedExclusiveGroup<WiresGroup>.Group); var wires = entitiesDB.QueryEntities<WireEntityStruct>(NamedExclusiveGroup<WiresGroup>.Group);
var wiresB = wires.ToBuffer().buffer;
for (uint i = 0; i < wires.count; i++) for (uint i = 0; i < wires.count; i++)
{ {
if ((wires[i].destinationPortUsage == port.usage && wires[i].destinationBlockEGID == blockID) if ((wiresB[i].destinationPortUsage == port.usage && wiresB[i].destinationBlockEGID == blockID)
|| (wires[i].sourcePortUsage == port.usage && wires[i].sourceBlockEGID == blockID)) || (wiresB[i].sourcePortUsage == port.usage && wiresB[i].sourceBlockEGID == blockID))
{ {
exists = true; exists = true;
return ref wires[i]; return ref wiresB[i];
} }
} }
exists = false; exists = false;
@ -286,6 +290,7 @@ namespace GamecraftModdingAPI.Blocks
} }
EntityCollection<WireEntityStruct> wires = entitiesDB.QueryEntities<WireEntityStruct>(NamedExclusiveGroup<WiresGroup>.Group); EntityCollection<WireEntityStruct> wires = entitiesDB.QueryEntities<WireEntityStruct>(NamedExclusiveGroup<WiresGroup>.Group);
var wiresB = wires.ToBuffer().buffer;
for (int endIndex = 0; endIndex < endPorts.Length; endIndex++) for (int endIndex = 0; endIndex < endPorts.Length; endIndex++)
{ {
PortEntityStruct endPES = entitiesDB.QueryEntity<PortEntityStruct>(endPorts[endIndex]); PortEntityStruct endPES = entitiesDB.QueryEntity<PortEntityStruct>(endPorts[endIndex]);
@ -294,11 +299,11 @@ namespace GamecraftModdingAPI.Blocks
PortEntityStruct startPES = entitiesDB.QueryEntity<PortEntityStruct>(startPorts[startIndex]); PortEntityStruct startPES = entitiesDB.QueryEntity<PortEntityStruct>(startPorts[startIndex]);
for (int w = 0; w < wires.count; w++) for (int w = 0; w < wires.count; w++)
{ {
if ((wires[w].destinationPortUsage == endPES.usage && wires[w].destinationBlockEGID == endBlock) if ((wiresB[w].destinationPortUsage == endPES.usage && wiresB[w].destinationBlockEGID == endBlock)
&& (wires[w].sourcePortUsage == startPES.usage && wires[w].sourceBlockEGID == startBlock)) && (wiresB[w].sourcePortUsage == startPES.usage && wiresB[w].sourceBlockEGID == startBlock))
{ {
exists = true; exists = true;
return ref wires[w]; return ref wiresB[w];
} }
} }
} }
@ -313,10 +318,11 @@ namespace GamecraftModdingAPI.Blocks
{ {
ref PortEntityStruct port = ref entitiesDB.QueryEntity<PortEntityStruct>(portID); ref PortEntityStruct port = ref entitiesDB.QueryEntity<PortEntityStruct>(portID);
var channels = entitiesDB.QueryEntities<ChannelDataStruct>(NamedExclusiveGroup<ChannelDataGroup>.Group); var channels = entitiesDB.QueryEntities<ChannelDataStruct>(NamedExclusiveGroup<ChannelDataGroup>.Group);
var channelsB = channels.ToBuffer();
if (port.firstChannelIndexCachedInSim < channels.count) if (port.firstChannelIndexCachedInSim < channels.count)
{ {
exists = true; exists = true;
return ref channels[port.firstChannelIndexCachedInSim]; return ref channelsB.buffer[port.firstChannelIndexCachedInSim];
} }
exists = false; exists = false;
ChannelDataStruct[] defRef = new ChannelDataStruct[1]; ChannelDataStruct[] defRef = new ChannelDataStruct[1];
@ -327,8 +333,15 @@ namespace GamecraftModdingAPI.Blocks
{ {
var res = new FasterList<EGID>(); var res = new FasterList<EGID>();
foreach (var (coll, _) in entitiesDB.QueryEntities<BlockPortsStruct>()) foreach (var (coll, _) in entitiesDB.QueryEntities<BlockPortsStruct>())
foreach (ref BlockPortsStruct s in coll) {
var collB = coll.ToBuffer();
for (int i = 0; i < coll.count; i++)
{
ref BlockPortsStruct s = ref collB.buffer[i];
res.Add(s.ID); res.Add(s.ID);
}
}
return res.ToArray(); return res.ToArray();
} }
@ -358,15 +371,16 @@ namespace GamecraftModdingAPI.Blocks
return result; return result;
} }
private T[] Search<T>(ExclusiveGroup group, Func<T, bool> isMatch) where T : struct, IEntityComponent private T[] Search<T>(ExclusiveGroup group, Func<T, bool> isMatch) where T : unmanaged, IEntityComponent
{ {
FasterList<T> results = new FasterList<T>(); FasterList<T> results = new FasterList<T>();
EntityCollection<T> components = entitiesDB.QueryEntities<T>(group); EntityCollection<T> components = entitiesDB.QueryEntities<T>(group);
var componentsB = components.ToBuffer();
for (uint i = 0; i < components.count; i++) 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(); return results.ToArray();

View file

@ -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))
{ {
} }

View file

@ -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))
{ {
} }

View file

@ -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))
{ {
} }

View file

@ -36,13 +36,13 @@ namespace GamecraftModdingAPI.Inventory
public bool SelectBlock(int block, uint playerID, bool cubeSelectedByPick = false) public bool SelectBlock(int block, uint playerID, bool cubeSelectedByPick = false)
{ {
var inputs = entitiesDB.QueryEntities<LocalInputEntityStruct>(InputExclusiveGroups.LocalPlayers); var inputs = entitiesDB.QueryEntities<LocalInputEntityStruct>(InputExclusiveGroups.LocalPlayers).ToBuffer();
if (inputs.count == 0) return false; if (inputs.count == 0) return false;
for (int i = 0; i < inputs.count; i++) for (int i = 0; i < inputs.count; i++)
{ {
if (inputs[i].ID.entityID == playerID) { if (inputs.buffer[i].ID.entityID == playerID) {
inputs[i].cubeSelectedByPick = cubeSelectedByPick; inputs.buffer[i].cubeSelectedByPick = cubeSelectedByPick;
inputs[i].selectedCube = block; inputs.buffer[i].selectedCube = block;
return true; return true;
} }
} }

View file

@ -50,10 +50,10 @@ namespace GamecraftModdingAPI.Players
public uint GetLocalPlayer() public uint GetLocalPlayer()
{ {
if (!isReady) return uint.MaxValue; if (!isReady) return uint.MaxValue;
var localPlayers = entitiesDB.QueryEntities<PlayerIDStruct>(PlayersExclusiveGroups.LocalPlayers); var localPlayers = entitiesDB.QueryEntities<PlayerIDStruct>(PlayersExclusiveGroups.LocalPlayers).ToBuffer();
if (localPlayers.count > 0) if (localPlayers.count > 0)
{ {
return localPlayers[0].ID.entityID; return localPlayers.buffer[0].ID.entityID;
} }
return uint.MaxValue; return uint.MaxValue;
} }
@ -61,10 +61,10 @@ namespace GamecraftModdingAPI.Players
public uint GetRemotePlayer() public uint GetRemotePlayer()
{ {
if (!isReady) return uint.MaxValue; if (!isReady) return uint.MaxValue;
var localPlayers = entitiesDB.QueryEntities<PlayerIDStruct>(PlayersExclusiveGroups.RemotePlayers); var localPlayers = entitiesDB.QueryEntities<PlayerIDStruct>(PlayersExclusiveGroups.RemotePlayers).ToBuffer();
if (localPlayers.count > 0) if (localPlayers.count > 0)
{ {
return localPlayers[0].ID.entityID; return localPlayers.buffer[0].ID.entityID;
} }
return uint.MaxValue; return uint.MaxValue;
} }

View file

@ -65,7 +65,7 @@ namespace GamecraftModdingAPI.Tests
_testsCountPassed = 0; _testsCountPassed = 0;
_testsCountFailed = 0; _testsCountFailed = 0;
// flow control // 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"; Game.Exit += (s, a) => state = "ReturningFromGame";
Client.EnterMenu += (sender, args) => Client.EnterMenu += (sender, args) =>
{ {