From c4a9125ed342bebefb486dd401da7a28cd197712 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sun, 20 Mar 2022 18:01:14 +0100 Subject: [PATCH] Update to Techblox 2022.03.17.17.24 --- TechbloxModdingAPI/Blocks/BlockIDs.cs | 6 +++ .../Blocks/Engines/BlockEngine.cs | 43 +++++++++---------- .../Blocks/Engines/BlueprintEngine.cs | 2 +- .../Blocks/Engines/PlacementEngine.cs | 2 +- .../Utility/ManagedApiExtensions.cs | 2 +- .../Utility/NativeApiExtensions.cs | 4 +- TechbloxModdingAPI/Utility/OptionalRef.cs | 2 +- 7 files changed, 33 insertions(+), 28 deletions(-) diff --git a/TechbloxModdingAPI/Blocks/BlockIDs.cs b/TechbloxModdingAPI/Blocks/BlockIDs.cs index 3bf837a..49993a3 100644 --- a/TechbloxModdingAPI/Blocks/BlockIDs.cs +++ b/TechbloxModdingAPI/Blocks/BlockIDs.cs @@ -313,5 +313,11 @@ namespace TechbloxModdingAPI.Blocks LargeJet, DistanceSensor, Stabilizer, + ObjectID, + TeamScore = 428, + ScorePickupBlock, + StreetLamp = 435, + ConstantBlock = 452, + CounterBlock, } } \ No newline at end of file diff --git a/TechbloxModdingAPI/Blocks/Engines/BlockEngine.cs b/TechbloxModdingAPI/Blocks/Engines/BlockEngine.cs index 5d6162c..0b63e2c 100644 --- a/TechbloxModdingAPI/Blocks/Engines/BlockEngine.cs +++ b/TechbloxModdingAPI/Blocks/Engines/BlockEngine.cs @@ -15,6 +15,7 @@ using RobocraftX.Rendering.GPUI; using Svelto.DataStructures; using Svelto.ECS; using Svelto.ECS.EntityStructs; +using Svelto.ECS.Experimental; using Svelto.ECS.Hybrid; using Techblox.BuildingDrone; using Unity.Mathematics; @@ -138,7 +139,7 @@ namespace TechbloxModdingAPI.Blocks.Engines } uint prefabId = - PrefabsID.GetOrCreatePrefabID((ushort) prefabAssetID, material, 1, flipped); + PrefabsID.GetOrAddPrefabID((ushort) prefabAssetID, material, 1, flipped); entitiesDB.QueryEntityOrDefault(block).prefabID = prefabId; if (block.Exists) { @@ -168,28 +169,25 @@ namespace TechbloxModdingAPI.Blocks.Engines public SimBody[] GetSimBodiesFromID(byte id) { var ret = new FasterList(4); - var oide = entitiesDB.QueryEntities(); + var (oids, tags, count) = entitiesDB.QueryEntities(CommonExclusiveGroups.OBJID_BLOCK_GROUP); EGIDMapper? connections = null; - foreach (var ((oids, count), _) in oide) + for (int i = 0; i < count; i++) { - for (int i = 0; i < count; i++) - { - ref ObjectIdEntityStruct oid = ref oids[i]; - if (oid.objectId != id) continue; - if (!connections.HasValue) //Would need reflection to get the group from the build group otherwise - connections = entitiesDB.QueryMappedEntities(oid.ID.groupID); - var rid = connections.Value.Entity(oid.ID.entityID).machineRigidBodyId; - foreach (var rb in ret) - { - if (rb.Id.entityID == rid) - goto DUPLICATE; //Multiple Object Identifiers on one rigid body - } - - ret.Add(new SimBody(rid)); - DUPLICATE: ; + if (oids[i].objectId != id) continue; + var tag = tags[i]; + if (!connections.HasValue) //Would need reflection to get the group from the build group otherwise + connections = entitiesDB.QueryMappedEntities(tag.ID.groupID); + var rid = connections.Value.Entity(tag.ID.entityID).machineRigidBodyId; + foreach (var rb in ret) + { + if (rb.Id.entityID == rid) + goto DUPLICATE; //Multiple Object Identifiers on one rigid body } - } + ret.Add(new SimBody(rid)); + DUPLICATE: ; + } + return ret.ToArray(); } @@ -256,15 +254,16 @@ namespace TechbloxModdingAPI.Blocks.Engines public Block[] GetBodyBlocks(uint sbid) { - var groups = entitiesDB.QueryEntities(); + var groups = entitiesDB.FindGroups(); + groups = new QueryGroups(groups).Except(CommonExclusiveGroups.DISABLED_JOINTS_IN_SIM_GROUP).Evaluate().result; var set = new HashSet(); - foreach (var ((coll, count), _) in groups) + foreach (var ((coll, tags, count), _) in entitiesDB.QueryEntities(groups)) { for (var index = 0; index < count; index++) { var conn = coll[index]; if (conn.machineRigidBodyId == sbid) - set.Add(Block.New(conn.ID)); + set.Add(Block.New(tags[index].ID)); } } diff --git a/TechbloxModdingAPI/Blocks/Engines/BlueprintEngine.cs b/TechbloxModdingAPI/Blocks/Engines/BlueprintEngine.cs index 789076e..6bd48c8 100644 --- a/TechbloxModdingAPI/Blocks/Engines/BlueprintEngine.cs +++ b/TechbloxModdingAPI/Blocks/Engines/BlueprintEngine.cs @@ -277,7 +277,7 @@ namespace TechbloxModdingAPI.Blocks.Engines FullGameFields._managers.blockLabelResourceManager); entityInitializer.Init(dbStruct); entityInitializer.Init(new GFXPrefabEntityStructGPUI( - PrefabsID.GetOrCreatePrefabID((ushort)entityInitializer.Get().prefabAssetID, + PrefabsID.GetOrAddPrefabID((ushort)entityInitializer.Get().prefabAssetID, entitiesDB.QueryEntity(sourceId).materialId, 7, FlippedBlockUtils.IsFlipped(in scalingEntityStruct.scale)), true)); entityInitializer.Init(entitiesDB.QueryEntity(sourceId)); diff --git a/TechbloxModdingAPI/Blocks/Engines/PlacementEngine.cs b/TechbloxModdingAPI/Blocks/Engines/PlacementEngine.cs index 8f06ecc..4d363a4 100644 --- a/TechbloxModdingAPI/Blocks/Engines/PlacementEngine.cs +++ b/TechbloxModdingAPI/Blocks/Engines/PlacementEngine.cs @@ -58,7 +58,7 @@ namespace TechbloxModdingAPI.Blocks.Engines uint prefabAssetID = structInitializer.Has() ? structInitializer.Get().prefabAssetID : throw new BlockException("Prefab asset ID not found!"); //Set by the game - uint prefabId = PrefabsID.GetOrCreatePrefabID((ushort) prefabAssetID, (byte) BlockMaterial.SteelBodywork, 1, false); + uint prefabId = PrefabsID.GetOrAddPrefabID((ushort) prefabAssetID, (byte) BlockMaterial.SteelBodywork, 1, false); structInitializer.Init(new GFXPrefabEntityStructGPUI(prefabId)); structInitializer.Init(dbEntity); structInitializer.Init(new PositionEntityStruct {position = position}); diff --git a/TechbloxModdingAPI/Utility/ManagedApiExtensions.cs b/TechbloxModdingAPI/Utility/ManagedApiExtensions.cs index 6829b2d..b67705f 100644 --- a/TechbloxModdingAPI/Utility/ManagedApiExtensions.cs +++ b/TechbloxModdingAPI/Utility/ManagedApiExtensions.cs @@ -51,7 +51,7 @@ namespace TechbloxModdingAPI.Utility EGID id = group == ExclusiveGroupStruct.Invalid ? obj.Id : new EGID(obj.Id.entityID, group); var opt = QueryEntityOptional(entitiesDB, id); if (opt) return ref opt.Get(); - if (obj.InitData.Valid) return ref obj.InitData.Initializer(id).GetOrCreate(); + if (obj.InitData.Valid) return ref obj.InitData.Initializer(id).GetOrAdd(); return ref opt.Get(); //Default value } } diff --git a/TechbloxModdingAPI/Utility/NativeApiExtensions.cs b/TechbloxModdingAPI/Utility/NativeApiExtensions.cs index 90b0262..dec1eb0 100644 --- a/TechbloxModdingAPI/Utility/NativeApiExtensions.cs +++ b/TechbloxModdingAPI/Utility/NativeApiExtensions.cs @@ -55,7 +55,7 @@ namespace TechbloxModdingAPI.Utility EGID id = group == ExclusiveGroupStruct.Invalid ? obj.Id : new EGID(obj.Id.entityID, group); var opt = QueryEntityOptional(entitiesDB, id); if (opt) return ref opt.Get(); - if (obj.InitData.Valid) return ref obj.InitData.Initializer(id).GetOrCreate(); + if (obj.InitData.Valid) return ref obj.InitData.Initializer(id).GetOrAdd(); /*if (!obj.InitData.Valid) return ref opt.Get(); //Default value var init = obj.InitData.Initializer(id); // Do not create the component if missing, as that can trigger Add() listeners that, in some cases, may be @@ -71,7 +71,7 @@ namespace TechbloxModdingAPI.Utility /// It will only publish in the next frame. /// /// The entities DB to publish to - /// The ECS object that got changed + /// The ECS object that got changed /// Limits how many changes to publish - should be no more than the consumers' capacity that process this component /// The component that changed public static void PublishEntityChangeDelayed(this EntitiesDB entitiesDB, EGID id, int limit = 80) diff --git a/TechbloxModdingAPI/Utility/OptionalRef.cs b/TechbloxModdingAPI/Utility/OptionalRef.cs index c83e0da..9b3ec3d 100644 --- a/TechbloxModdingAPI/Utility/OptionalRef.cs +++ b/TechbloxModdingAPI/Utility/OptionalRef.cs @@ -59,7 +59,7 @@ namespace TechbloxModdingAPI.Utility { CompRefCache.Default = default; //The default value can be changed by mods if (state == State.Empty) return ref CompRefCache.Default; - if ((state & State.Initializer) != State.Empty) return ref initializer.GetOrCreate(); + if ((state & State.Initializer) != State.Empty) return ref initializer.GetOrAdd(); if ((state & State.Native) != State.Empty) return ref array[index]; return ref managedArray[index]; }