< Summary

Information
Class: Lattice.ECS.Core.ComponentCallbacks
Assembly: Lattice
File(s): /home/runner/work/Sideline/Sideline/godot/scripts/lattice/ECS/Core/ComponentCallbacks.cs
Line coverage
91%
Covered lines: 11
Uncovered lines: 1
Coverable lines: 12
Total lines: 84
Line coverage: 91.6%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
.ctor(...)50%2285.71%
get_Serialize()100%11100%
get_OnAdded()100%11100%
get_OnRemoved()100%11100%
get_SerializationVersion()100%11100%

File(s)

/home/runner/work/Sideline/Sideline/godot/scripts/lattice/ECS/Core/ComponentCallbacks.cs

#LineLine coverage
 1// Copyright (c) 2026 Sideline Authors. All rights reserved.
 2// Licensed under GPL-3.0.
 3
 4using System;
 5using Lattice.Core;
 6using Lattice.ECS.Serialization;
 7
 8namespace Lattice.ECS.Core
 9{
 10    /// <summary>
 11    /// 组件序列化委托,对齐 FrameSync 的组件序列化回调设计。
 12    /// </summary>
 13    public unsafe delegate void ComponentSerializeDelegate(void* component, IFrameSerializer serializer);
 14
 15    /// <summary>
 16    /// 组件生命周期回调,在组件添加或移除时触发。
 17    /// </summary>
 18    public unsafe delegate void ComponentChangedDelegate(EntityRef entity, void* component, Frame frame);
 19
 20    /// <summary>
 21    /// 组件回调集合。
 22    /// </summary>
 23    public readonly struct ComponentCallbacks
 24    {
 125        public static readonly ComponentCallbacks Empty = new(null, null, null);
 26
 27        public ComponentCallbacks(
 28            ComponentSerializeDelegate? serialize,
 29            ComponentChangedDelegate? onAdded,
 30            ComponentChangedDelegate? onRemoved,
 31            int serializationVersion = 1)
 32        {
 733            if (serializationVersion <= 0)
 34            {
 035                throw new ArgumentOutOfRangeException(nameof(serializationVersion), "Component serialization version mus
 36            }
 37
 738            Serialize = serialize;
 739            OnAdded = onAdded;
 740            OnRemoved = onRemoved;
 741            SerializationVersion = serializationVersion;
 742        }
 43
 44        /// <summary>组件序列化回调。</summary>
 255545        public ComponentSerializeDelegate? Serialize { get; }
 46
 47        /// <summary>组件添加回调。</summary>
 134948        public ComponentChangedDelegate? OnAdded { get; }
 49
 50        /// <summary>组件移除回调。</summary>
 87251        public ComponentChangedDelegate? OnRemoved { get; }
 52
 53        /// <summary>
 54        /// 组件序列化协议版本。
 55        /// 当组件的稳定序列化布局发生兼容性变更时,应显式递增此版本,
 56        /// 而不是继续依赖“调用方知道改过什么”的隐式约定。
 57        /// </summary>
 138858        public int SerializationVersion { get; }
 59    }
 60
 61    internal delegate void ComponentFrameRemoveDelegate(Frame frame, EntityRef entity);
 62
 63    internal unsafe delegate void ComponentCommandApplyDelegate(Frame frame, EntityRef entity, void* componentData);
 64
 65    internal unsafe delegate void ComponentDeferredCommitDelegate(void* storage, EntityRef entity);
 66
 67    internal unsafe delegate ComponentStorageSnapshot? ComponentSnapshotCaptureDelegate(void* storage, ComponentSerializ
 68
 69    internal delegate void ComponentSnapshotRestoreDelegate(Frame frame, ComponentStorageSnapshot snapshot, ComponentSer
 70
 71    internal unsafe delegate void ComponentPendingRemovalDelegate(void* storage, EntityRef entity);
 72
 73    internal unsafe delegate void ComponentPendingQueueIndexSetterDelegate(void* storage, EntityRef entity, int queueInd
 74
 75    internal unsafe delegate void ComponentStorageCopyDelegate(Frame destinationFrame, void* sourceStorage);
 76
 77    internal unsafe delegate void ComponentStorageResetDelegate(void* storage);
 78
 79    internal unsafe delegate bool ComponentPackedStatePresenceDelegate(void* storage, ComponentSerializationMode mode);
 80
 81    internal unsafe delegate bool ComponentPackedStateWriteDelegate(void* storage, FrameStateWriter writer, ComponentSer
 82
 83    internal delegate void ComponentPackedStateRestoreDelegate(Frame frame, FrameStateReader reader, ComponentSerializat
 84}