Browse Source

Update to Techblox 2022.03.17.17.24

tags/v2.3.0
NorbiPeti 2 years ago
parent
commit
c4a9125ed3
7 changed files with 33 additions and 28 deletions
  1. +6
    -0
      TechbloxModdingAPI/Blocks/BlockIDs.cs
  2. +21
    -22
      TechbloxModdingAPI/Blocks/Engines/BlockEngine.cs
  3. +1
    -1
      TechbloxModdingAPI/Blocks/Engines/BlueprintEngine.cs
  4. +1
    -1
      TechbloxModdingAPI/Blocks/Engines/PlacementEngine.cs
  5. +1
    -1
      TechbloxModdingAPI/Utility/ManagedApiExtensions.cs
  6. +2
    -2
      TechbloxModdingAPI/Utility/NativeApiExtensions.cs
  7. +1
    -1
      TechbloxModdingAPI/Utility/OptionalRef.cs

+ 6
- 0
TechbloxModdingAPI/Blocks/BlockIDs.cs View File

@@ -313,5 +313,11 @@ namespace TechbloxModdingAPI.Blocks
LargeJet,
DistanceSensor,
Stabilizer,
ObjectID,
TeamScore = 428,
ScorePickupBlock,
StreetLamp = 435,
ConstantBlock = 452,
CounterBlock,
}
}

+ 21
- 22
TechbloxModdingAPI/Blocks/Engines/BlockEngine.cs View File

@@ -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<GFXPrefabEntityStructGPUI>(block).prefabID = prefabId;
if (block.Exists)
{
@@ -168,28 +169,25 @@ namespace TechbloxModdingAPI.Blocks.Engines
public SimBody[] GetSimBodiesFromID(byte id)
{
var ret = new FasterList<SimBody>(4);
var oide = entitiesDB.QueryEntities<ObjectIdEntityStruct>();
var (oids, tags, count) = entitiesDB.QueryEntities<ObjectIdEntityStruct, BlockTagEntityStruct>(CommonExclusiveGroups.OBJID_BLOCK_GROUP);
EGIDMapper<GridConnectionsEntityStruct>? 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<GridConnectionsEntityStruct>(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<GridConnectionsEntityStruct>(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<GridConnectionsEntityStruct>();
var groups = entitiesDB.FindGroups<GridConnectionsEntityStruct>();
groups = new QueryGroups(groups).Except(CommonExclusiveGroups.DISABLED_JOINTS_IN_SIM_GROUP).Evaluate().result;
var set = new HashSet<Block>();
foreach (var ((coll, count), _) in groups)
foreach (var ((coll, tags, count), _) in entitiesDB.QueryEntities<GridConnectionsEntityStruct, BlockTagEntityStruct>(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));
}
}



+ 1
- 1
TechbloxModdingAPI/Blocks/Engines/BlueprintEngine.cs View File

@@ -277,7 +277,7 @@ namespace TechbloxModdingAPI.Blocks.Engines
FullGameFields._managers.blockLabelResourceManager);
entityInitializer.Init(dbStruct);
entityInitializer.Init(new GFXPrefabEntityStructGPUI(
PrefabsID.GetOrCreatePrefabID((ushort)entityInitializer.Get<PrefabAssetIDComponent>().prefabAssetID,
PrefabsID.GetOrAddPrefabID((ushort)entityInitializer.Get<PrefabAssetIDComponent>().prefabAssetID,
entitiesDB.QueryEntity<CubeMaterialStruct>(sourceId).materialId, 7,
FlippedBlockUtils.IsFlipped(in scalingEntityStruct.scale)), true));
entityInitializer.Init(entitiesDB.QueryEntity<CubeMaterialStruct>(sourceId));


+ 1
- 1
TechbloxModdingAPI/Blocks/Engines/PlacementEngine.cs View File

@@ -58,7 +58,7 @@ namespace TechbloxModdingAPI.Blocks.Engines
uint prefabAssetID = structInitializer.Has<PrefabAssetIDComponent>()
? structInitializer.Get<PrefabAssetIDComponent>().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});


+ 1
- 1
TechbloxModdingAPI/Utility/ManagedApiExtensions.cs View File

@@ -51,7 +51,7 @@ namespace TechbloxModdingAPI.Utility
EGID id = group == ExclusiveGroupStruct.Invalid ? obj.Id : new EGID(obj.Id.entityID, group);
var opt = QueryEntityOptional<T>(entitiesDB, id);
if (opt) return ref opt.Get();
if (obj.InitData.Valid) return ref obj.InitData.Initializer(id).GetOrCreate<T>();
if (obj.InitData.Valid) return ref obj.InitData.Initializer(id).GetOrAdd<T>();
return ref opt.Get(); //Default value
}
}

+ 2
- 2
TechbloxModdingAPI/Utility/NativeApiExtensions.cs View File

@@ -55,7 +55,7 @@ namespace TechbloxModdingAPI.Utility
EGID id = group == ExclusiveGroupStruct.Invalid ? obj.Id : new EGID(obj.Id.entityID, group);
var opt = QueryEntityOptional<T>(entitiesDB, id);
if (opt) return ref opt.Get();
if (obj.InitData.Valid) return ref obj.InitData.Initializer(id).GetOrCreate<T>();
if (obj.InitData.Valid) return ref obj.InitData.Initializer(id).GetOrAdd<T>();
/*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.
/// </summary>
/// <param name="entitiesDB">The entities DB to publish to</param>
/// <param name="obj">The ECS object that got changed</param>
/// <param name="id">The ECS object that got changed</param>
/// <param name="limit">Limits how many changes to publish - should be no more than the consumers' capacity that process this component</param>
/// <typeparam name="T">The component that changed</typeparam>
public static void PublishEntityChangeDelayed<T>(this EntitiesDB entitiesDB, EGID id, int limit = 80)


+ 1
- 1
TechbloxModdingAPI/Utility/OptionalRef.cs View File

@@ -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<T>();
if ((state & State.Initializer) != State.Empty) return ref initializer.GetOrAdd<T>();
if ((state & State.Native) != State.Empty) return ref array[index];
return ref managedArray[index];
}


Loading…
Cancel
Save