protected override void OnUpdate()
        {
            if (!isBooted)
            {
                BootUp();
                isBooted = true;
            }

            var octetStream = new OctetWriter(MAX_EVENT_OCTETS);
            var bitStream   = new OutBitStream(octetStream);

            // TransferAction
            Entities.WithAll <Simulated>().ForEach((Entity entity, DynamicBuffer <TransferAction> buffer) =>
            {
                if (buffer.Length == 0)
                {
                    return;
                }

                var foundEntity = mapper.ToCoherenceEntityId(entity, out var coherenceEntityId);
                if (!foundEntity)
                {
                    Debug.LogError($"sending event, but can't find entity {entity} in coherence mapper");
                    return;
                }

                for (var i = 0; i < buffer.Length; i++)
                {
                    bitStream.Rewind(0);
                    EntityIdSerializer.Serialize(coherenceEntityId, bitStream);

                    var protocol = new Coherence.FieldStream.Serialize.Streams.OutBitStream(bitStream);

                    var eventComponent = buffer[i];

                    // --------- Type Specific Part ---------------
                    ComponentTypeIdSerializer.Serialize(TypeIds.InternalTransferAction, bitStream);
                    messageSerializers.TransferAction(protocol, eventComponent);
                    // --------------------------------------------

                    bitStream.Flush();
                    var payload = new BitSerializedMessage(octetStream.Octets, bitStream.Tell);
                    messageChannels.PushEntityEvent(payload);
                }

                buffer.Clear();
            }).WithoutBurst().Run();
        }
예제 #2
0
        protected override void OnUpdate()
        {
            if (!isBooted)
            {
                BootUp();
                isBooted = true;
            }


            // TransferAction
            Entities
            .WithAll <Simulated>()
            .ForEach((Entity entity, in TransferAction eventComponent) =>
            {
                var foundEntity = mapper.ToCoherenceEntityId(entity, out var coherenceEntityId);
                if (!foundEntity)
                {
                    Debug.LogError($"sending event, but can't find entity {entity} in coherence mapper");
                    return;
                }

                var octetStream = new OctetWriter(512);         // THIS MAGIC NUMBER IS TAKEN FROM COMMANDS CODE, HMM?!!
                var bitStream   = new OutBitStream(octetStream);

                EntityIdSerializer.Serialize(coherenceEntityId, bitStream);

                var protocol = new Coherence.FieldStream.Serialize.Streams.OutBitStream(bitStream);

                // --------- Type Specific Part ---------------
                ComponentTypeIdSerializer.Serialize(TypeIds.InternalTransferAction, bitStream);
                messageSerializers.TransferAction(protocol, eventComponent);
                // --------------------------------------------

                bitStream.Flush();
                var payload = new BitSerializedMessage(octetStream.Octets, bitStream.Tell);
                messageChannels.PushEntityEvent(payload);
            }).WithoutBurst().Run();
        }