public void InvokeCallbacks()
        {
            var updates = componentUpdateSystem.GetEventsReceived <T>();

            for (var i = 0; i < updates.Count; ++i)
            {
                ref readonly var update = ref updates[i];
        protected override void OnUpdate()
        {
            var events           = componentUpdateSystem.GetEventsReceived <ShootingComponent.Shots.Event>();
            var gunDataForEntity = GetComponentDataFromEntity <GunComponent.Component>();

            for (var i = 0; i < events.Count; ++i)
            {
                ref readonly var shotEvent = ref events[i];
        public void Events_are_available_immediately()
        {
            CreateEntity();
            Update();

            SendDependentDataEvent();
            Update();

            var events = componentUpdateSystem.GetEventsReceived <DependentDataComponent.FooEvent.Event>();

            Assert.AreEqual(1, events.Count);

            var entitySpecificEvents =
                componentUpdateSystem.GetEventsReceived <DependentDataComponent.FooEvent.Event>(new EntityId(EntityId));

            Assert.AreEqual(1, entitySpecificEvents.Count);
        }
Exemple #4
0
        protected override void OnUpdate()
        {
            Entities.ForEach((Entity entity, ref SpatialEntityId entityId, ref ClientUpdate.Component clientUpdate, in ClientUpdate.HasAuthority authority) =>
            {
                var timeResponses =
                    _componentUpdateSystem.GetEventsReceived <ServerUpdate.TimeResponse.Event>(entityId.EntityId);

                for (int i = 0; i < timeResponses.Count; i++)
                {
                    var timeResponse = timeResponses[i];
                    var payload      = timeResponse.Event.Payload;

                    if (!_timeRequests.ContainsKey(payload.RequestId))
                    {
                        Debug.LogWarning("Received a time response with an invalid request id. Id was " + payload.RequestId);
                        continue;
                    }

                    long timeInMs = TimeUtils.CurrentTimeInMs();
                    long rtt      = timeInMs - _timeRequests[payload.RequestId];
                    long rttHalf  = rtt / 2;
                    long newTime  = payload.Time + rttHalf + TimeConfig.CommandBufferLengthMs;
                    _ticker.SetTime(newTime);

                    var timeData = new TimeRequestData()
                    {
                        ServerDateTimeTicks = newTime, UpdatedTime = timeInMs, RttMs = rtt
                    };

                    SetSingleton(timeData);
                    _timeRequests.Remove(payload.RequestId);
                }

                var timeDilations =
                    _componentUpdateSystem.GetEventsReceived <ServerUpdate.TimeDilation.Event>(entityId.EntityId);

                for (int i = 0; i < timeDilations.Count; i++)
                {
                    _ticker.Dilate();
                }
            }).WithoutBurst().Run();
        private void ProcessDamageEvents()
        {
            var healthModifiedEvents = componentUpdateSystem.GetEventsReceived <HealthComponent.HealthModified.Event>();

            if (healthModifiedEvents.Count == 0)
            {
                return;
            }

            for (var i = 0; i < healthModifiedEvents.Count; ++i)
            {
                ref readonly var healthEvent = ref healthModifiedEvents[i];
Exemple #6
0
        protected override void OnUpdate()
        {
            Entities.ForEach((Entity entity, ref SpatialEntityId entityId, ref ServerUpdate.Component serverUpdate) =>
            {
                var timeRequests = _componentUpdateSystem.GetEventsReceived <ClientUpdate.TimeRequest.Event>(entityId.EntityId);

                for (int i = 0; i < timeRequests.Count; i++)
                {
                    var payload = timeRequests[i].Event.Payload;

                    var timeInMs = TimeUtils.CurrentTimeInMs();

                    var timeResponse = new ServerUpdate.TimeResponse.Event(new TimeResponse(payload.RequestId, timeInMs));
                    _componentUpdateSystem.SendEvent(timeResponse, entityId.EntityId);
                }
            }).WithoutBurst().Run();
        }
Exemple #7
0
        protected override void OnUpdate()
        {
            var changeColorEvents = updateSystem.GetEventsReceived <CubeColor.ChangeColor.Event>();

            for (var i = 0; i < changeColorEvents.Count; i++)
            {
                var colorEvent = changeColorEvents[i];
                if (!workerSystem.TryGetEntity(colorEvent.EntityId, out var entity))
                {
                    continue;
                }

                if (EntityManager.HasComponent <MeshRenderer>(entity))
                {
                    var renderer   = EntityManager.GetComponentObject <MeshRenderer>(entity);
                    var eventColor = colorEvent.Event.Payload.Color;
                    renderer.SetPropertyBlock(materialPropertyBlocks[eventColor]);
                }
            }
        }