Netcode Bootstrap

This commit is contained in:
Luis Gonzalez
2026-05-31 14:27:52 -07:00
parent 99d8d2d2a9
commit 7fa77ce821
1813 changed files with 2921554 additions and 84 deletions
@@ -0,0 +1,46 @@
using System;
using Unity.Collections;
using Unity.Entities;
using Hash128 = Unity.Entities.Hash128;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
[assembly: RegisterGenericComponentType(typeof(Rukhanka.NewBlobAssetDatabaseRecord<Rukhanka.AnimationClipBlob>))]
[assembly: RegisterGenericComponentType(typeof(Rukhanka.NewBlobAssetDatabaseRecord<Rukhanka.AvatarMaskBlob>))]
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
namespace Rukhanka
{
public struct BlobDatabaseSingleton: IComponentData
{
public NativeHashMap<Hash128, BlobAssetReference<AnimationClipBlob>> animations;
public NativeHashMap<Hash128, BlobAssetReference<AvatarMaskBlob>> avatarMasks;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public static BlobAssetReference<T> GetBlobAsset<T>(Hash128 blobHash, NativeHashMap<Hash128, BlobAssetReference<T>> blobDatabase) where T: unmanaged
{
if (!blobDatabase.TryGetValue(blobHash, out var bar))
return default;
return bar;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public BlobAssetReference<AvatarMaskBlob> GetAvatarMaskBlob(Hash128 blobHash) => GetBlobAsset(blobHash, avatarMasks);
public BlobAssetReference<AnimationClipBlob> GetAnimationClipBlob(Hash128 blobHash) => GetBlobAsset(blobHash, animations);
}
//=================================================================================================================//
public struct NewBlobAssetDatabaseRecord<T>: IBufferElementData where T: unmanaged
{
public Hash128 hash;
public BlobAssetReference<T> value;
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 3af0196747a230b45a6e72e1dbec5523
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 298480
packageName: Rukhanka Animation System 2
packageVersion: 2.9.0
assetPath: Packages/com.rukhanka.animation/Rukhanka.Runtime/BlobDatabase/BlobDatabase.cs
uploadId: 897522
@@ -0,0 +1,88 @@
using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using Hash128 = Unity.Entities.Hash128;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
namespace Rukhanka
{
[UpdateInGroup(typeof(InitializationSystemGroup), OrderLast = true)]
public partial struct BlobDatabaseUpdateSystem: ISystem
{
EntityQuery newBlobAssetsQuery;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
[BurstCompile]
public void OnCreate(ref SystemState ss)
{
CreateDBSingleton(ref ss);
newBlobAssetsQuery = SystemAPI.QueryBuilder()
.WithAny
<
NewBlobAssetDatabaseRecord<AnimationClipBlob>,
NewBlobAssetDatabaseRecord<AvatarMaskBlob>
>()
.WithOptions(EntityQueryOptions.IncludePrefab)
.Build();
ss.RequireForUpdate(newBlobAssetsQuery);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CreateDBSingleton(ref SystemState ss)
{
var blobDB = new BlobDatabaseSingleton()
{
animations = new (128, Allocator.Persistent),
avatarMasks = new (128, Allocator.Persistent),
};
ss.EntityManager.CreateSingleton(blobDB, "Rukhanka.BlobDatabaseSingleton");
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
[BurstCompile]
public void OnUpdate(ref SystemState ss)
{
if (!SystemAPI.TryGetSingletonRW<BlobDatabaseSingleton>(out var db))
return;
var ecbs = SystemAPI.GetSingleton<BeginSimulationEntityCommandBufferSystem.Singleton>();
var ecb = ecbs.CreateCommandBuffer(ss.WorldUnmanaged);
ProcessNewBlobs(ref ss, ref db.ValueRW.avatarMasks, ecb);
ProcessNewBlobs(ref ss, ref db.ValueRW.animations, ecb);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void ProcessNewBlobs<T>(ref SystemState ss, ref NativeHashMap<Hash128, BlobAssetReference<T>> db, EntityCommandBuffer ecb) where T: unmanaged
{
var componentTypeHandle = ss.EntityManager.GetBufferTypeHandle<NewBlobAssetDatabaseRecord<T>>(true);
var processNewBlobsJob = new ProcessNewBlobsJob<T>()
{
db = db,
componentTypeHandle = componentTypeHandle
};
ss.Dependency = processNewBlobsJob.Schedule(newBlobAssetsQuery, ss.Dependency);
ecb.RemoveComponent<NewBlobAssetDatabaseRecord<T>>(newBlobAssetsQuery, EntityQueryCaptureMode.AtPlayback);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
[BurstCompile]
public void OnDestroy(ref SystemState ss)
{
if (SystemAPI.TryGetSingletonRW<BlobDatabaseSingleton>(out var animDB))
{
animDB.ValueRW.animations.Dispose();
animDB.ValueRW.avatarMasks.Dispose();
}
}
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 1b5bab6a76d92554cba1f6cafa248b48
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 298480
packageName: Rukhanka Animation System 2
packageVersion: 2.9.0
assetPath: Packages/com.rukhanka.animation/Rukhanka.Runtime/BlobDatabase/BlobDatabaseUpdateSystem.cs
uploadId: 897522
@@ -0,0 +1,44 @@
using Unity.Burst.Intrinsics;
using Unity.Collections;
using Unity.Entities;
using Unity.Jobs;
using Hash128 = Unity.Entities.Hash128;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
[assembly: RegisterGenericJobType(typeof(Rukhanka.BlobDatabaseUpdateSystem.ProcessNewBlobsJob<Rukhanka.AvatarMaskBlob>))]
[assembly: RegisterGenericJobType(typeof(Rukhanka.BlobDatabaseUpdateSystem.ProcessNewBlobsJob<Rukhanka.AnimationClipBlob>))]
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
namespace Rukhanka
{
public partial struct BlobDatabaseUpdateSystem
{
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
internal struct ProcessNewBlobsJob<T>: IJobChunk where T: unmanaged
{
public BufferTypeHandle<NewBlobAssetDatabaseRecord<T>> componentTypeHandle;
public NativeHashMap<Hash128, BlobAssetReference<T>> db;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public void Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
{
var ba = chunk.GetBufferAccessor(ref componentTypeHandle);
for (var i = 0; i < chunk.Count && ba.Length > 0; ++i)
{
var newBlobsArr = ba[i];
for (int j = 0; j < newBlobsArr.Length; ++j)
{
var a = newBlobsArr[j];
db[a.hash] = a.value;
}
}
}
}
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: b900a60865904dc429164cdcb5c6f9dc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 298480
packageName: Rukhanka Animation System 2
packageVersion: 2.9.0
assetPath: Packages/com.rukhanka.animation/Rukhanka.Runtime/BlobDatabase/BlobDatabaseUpdateSystem_Jobs.cs
uploadId: 897522