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



            #region AuthorityTransferRequest
            // ------------  AuthorityTransferRequest --------------
            Entities
            .ForEach((Entity entity, DynamicBuffer <AuthorityTransferRequest> buffer) =>
            {
                if (buffer.Length == 0)
                {
                    return;
                }

                var foundEntity = mapper.ToCoherenceEntityId(entity, out var coherenceEntityId);
                if (!foundEntity)
                {
                    Debug.LogError($"send command request. Can not find entity {entity}");
                    return;
                }

                var rawArray = buffer.Reinterpret <AuthorityTransferRequest>();

                for (var i = 0; i < rawArray.Length; i++)
                {
                    var item        = rawArray[i];
                    var octetStream = new OctetWriter(512);
                    var bitStream   = new OutBitStream(octetStream);
                    EntityIdSerializer.Serialize(coherenceEntityId, bitStream);
                    var protocol = new Coherence.FieldStream.Serialize.Streams.OutBitStream(bitStream);

                    // --------- Type Specific Part ---------------
                    ComponentTypeIdSerializer.Serialize(TypeIds.InternalAuthorityTransfer, bitStream);
                    messageSerializers.AuthorityTransferRequest(protocol, item);
                    // --------------------------------------------

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

                buffer.Clear();
            }).WithoutBurst().Run();
            #endregion
        }
        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();
        }
Пример #3
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();
        }