Update to Techblox 2022.03.17.17.24

This commit is contained in:
Norbi Peti 2022-03-20 18:01:14 +01:00
parent 3eecdf2cf5
commit c4a9125ed3
7 changed files with 33 additions and 28 deletions

View file

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

View file

@ -15,6 +15,7 @@ using RobocraftX.Rendering.GPUI;
using Svelto.DataStructures; using Svelto.DataStructures;
using Svelto.ECS; using Svelto.ECS;
using Svelto.ECS.EntityStructs; using Svelto.ECS.EntityStructs;
using Svelto.ECS.Experimental;
using Svelto.ECS.Hybrid; using Svelto.ECS.Hybrid;
using Techblox.BuildingDrone; using Techblox.BuildingDrone;
using Unity.Mathematics; using Unity.Mathematics;
@ -138,7 +139,7 @@ namespace TechbloxModdingAPI.Blocks.Engines
} }
uint prefabId = uint prefabId =
PrefabsID.GetOrCreatePrefabID((ushort) prefabAssetID, material, 1, flipped); PrefabsID.GetOrAddPrefabID((ushort) prefabAssetID, material, 1, flipped);
entitiesDB.QueryEntityOrDefault<GFXPrefabEntityStructGPUI>(block).prefabID = prefabId; entitiesDB.QueryEntityOrDefault<GFXPrefabEntityStructGPUI>(block).prefabID = prefabId;
if (block.Exists) if (block.Exists)
{ {
@ -168,26 +169,23 @@ namespace TechbloxModdingAPI.Blocks.Engines
public SimBody[] GetSimBodiesFromID(byte id) public SimBody[] GetSimBodiesFromID(byte id)
{ {
var ret = new FasterList<SimBody>(4); 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; EGIDMapper<GridConnectionsEntityStruct>? connections = null;
foreach (var ((oids, count), _) in oide) for (int i = 0; i < count; i++)
{ {
for (int i = 0; i < count; i++) 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)
{ {
ref ObjectIdEntityStruct oid = ref oids[i]; if (rb.Id.entityID == rid)
if (oid.objectId != id) continue; goto DUPLICATE; //Multiple Object Identifiers on one rigid body
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: ;
} }
ret.Add(new SimBody(rid));
DUPLICATE: ;
} }
return ret.ToArray(); return ret.ToArray();
@ -256,15 +254,16 @@ namespace TechbloxModdingAPI.Blocks.Engines
public Block[] GetBodyBlocks(uint sbid) 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>(); 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++) for (var index = 0; index < count; index++)
{ {
var conn = coll[index]; var conn = coll[index];
if (conn.machineRigidBodyId == sbid) if (conn.machineRigidBodyId == sbid)
set.Add(Block.New(conn.ID)); set.Add(Block.New(tags[index].ID));
} }
} }

View file

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

View file

@ -58,7 +58,7 @@ namespace TechbloxModdingAPI.Blocks.Engines
uint prefabAssetID = structInitializer.Has<PrefabAssetIDComponent>() uint prefabAssetID = structInitializer.Has<PrefabAssetIDComponent>()
? structInitializer.Get<PrefabAssetIDComponent>().prefabAssetID ? structInitializer.Get<PrefabAssetIDComponent>().prefabAssetID
: throw new BlockException("Prefab asset ID not found!"); //Set by the game : 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(new GFXPrefabEntityStructGPUI(prefabId));
structInitializer.Init(dbEntity); structInitializer.Init(dbEntity);
structInitializer.Init(new PositionEntityStruct {position = position}); structInitializer.Init(new PositionEntityStruct {position = position});

View file

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

View file

@ -55,7 +55,7 @@ namespace TechbloxModdingAPI.Utility
EGID id = group == ExclusiveGroupStruct.Invalid ? obj.Id : new EGID(obj.Id.entityID, group); EGID id = group == ExclusiveGroupStruct.Invalid ? obj.Id : new EGID(obj.Id.entityID, group);
var opt = QueryEntityOptional<T>(entitiesDB, id); var opt = QueryEntityOptional<T>(entitiesDB, id);
if (opt) return ref opt.Get(); 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 /*if (!obj.InitData.Valid) return ref opt.Get(); //Default value
var init = obj.InitData.Initializer(id); 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 // 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. /// It will only publish in the next frame.
/// </summary> /// </summary>
/// <param name="entitiesDB">The entities DB to publish to</param> /// <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> /// <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> /// <typeparam name="T">The component that changed</typeparam>
public static void PublishEntityChangeDelayed<T>(this EntitiesDB entitiesDB, EGID id, int limit = 80) public static void PublishEntityChangeDelayed<T>(this EntitiesDB entitiesDB, EGID id, int limit = 80)

View file

@ -59,7 +59,7 @@ namespace TechbloxModdingAPI.Utility
{ {
CompRefCache.Default = default; //The default value can be changed by mods CompRefCache.Default = default; //The default value can be changed by mods
if (state == State.Empty) return ref CompRefCache.Default; 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]; if ((state & State.Native) != State.Empty) return ref array[index];
return ref managedArray[index]; return ref managedArray[index];
} }