Beispiel #1
0
        // ---
        // Process methods

        public void ProcessEcDict <Comp>(
            NetProtocol.EcDict <Comp> ecDict
            ) where Comp : INetComponent <Comp>, new()
        {
            foreach (KeyValuePair <Entity, Comp> pair in ecDict.data)
            {
                Entity entity = pair.Key;
                Comp   comp   = pair.Value;

                // We clone the component because we need the snapshot and
                // registry to have completely separate memory.
                // `Entity` is a struct so there is no need to explicitly clone.
                Comp compClone = (Comp)comp.Clone();
                AssignComponent(
                    entity,
                    compClone
                    );
            }
        }
Beispiel #2
0
        // ---
        // Snap methods

        private NetProtocol.EcDict <Comp> SnapEcDict <Comp>()
            where Comp : INetComponent <Comp>, new()
        {
            var result = new NetProtocol.EcDict <Comp>();
            HashSet <Entity> entities = GetEntities(
                typeof(Comp)
                );

            foreach (Entity entity in entities)
            {
                var comp = GetComponentUnsafe <Comp>(entity);

                // We clone the component because we need the snapshot and
                // registry to have completely separate memory.
                // `Entity` is a struct so there is no need to explicitly clone.
                var compClone = (Comp)comp.Clone();
                result.data.Add(entity, compClone);
            }

            return(result);
        }