Exemplo n.º 1
0
        public IGameEntity GetNonSelfEntityCopy(int snapShotSeq)
        {
            if (_nonSelfSnapShotSeq != snapShotSeq)
            {
                try
                {
                    Core.Utils.SpinWait spin = new Core.Utils.SpinWait();
                    while (Interlocked.Increment(ref _nonSelfEntityCopyLock) != 1)
                    {
                        Interlocked.Decrement(ref _nonSelfEntityCopyLock);
                        spin.SpinOnce();
                    }

                    if (_nonSelfSnapShotSeq != snapShotSeq)
                    {
                        if (_nonSelfEntityCopy != null)
                        {
                            RefCounterRecycler.Instance.ReleaseReference(_nonSelfEntityCopy);

                            _nonSelfEntityCopy = null;
                        }

                        _nonSelfEntityCopy = GameEntity.Allocate(EntityKey);
                        var idxById = _lookup.NoSelfIndexs;
                        for (int i = 0; i < idxById.Length; i++)
                        {
                            int index = idxById[i];
                            if (index >= 0)
                            {
                                var component = _entity.HasComponent(index) ? _entity.GetComponent(index) : null;
                                if (component != null && component is IGameComponent)
                                {
                                    var c = component as IGameComponent;
                                    _nonSelfEntityCopy.AddComponent(c.GetComponentId(), c);
                                }
                            }
                        }
                    }

                    _nonSelfSnapShotSeq = snapShotSeq;
                }
                finally
                {
                    Interlocked.Decrement(ref _nonSelfEntityCopyLock);
                }


                return(_nonSelfEntityCopy);
            }

            {
                return(_nonSelfEntityCopy);
            }
        }
Exemplo n.º 2
0
        public void OnLeftEntityMissing(IGameEntity rightEntity)
        {
            var         entityKey   = rightEntity.EntityKey;
            IGameEntity localEntity = _handler.CreateAndGetLocalEntity(entityKey);

            _logger.DebugFormat("create entity {0}", entityKey);
            foreach (var rightComponent in rightEntity.ComponentList)
            {
                if (!IsExcludeComponent(rightComponent) && localEntity.GetComponent(rightComponent.GetComponentId()) == null)
                {
                    _logger.DebugFormat("{2}add component {0}:{1}", entityKey, rightComponent.GetType(), rightComponent);
                    var leftComponent = (ILatestComponent)localEntity.AddComponent(rightComponent.GetComponentId(), rightComponent);
                }
            }
        }
        public void SyncToEntity(IPlayerUserCmdGetter getter, UpdateLatestPacakge package)
        {
            PlayerEntity playerEntity = getter.OwnerEntity as PlayerEntity;
            IGameEntity  gameEntity   = playerEntity.entityAdapter.SelfAdapter;
            int          count        = package.UpdateComponents.Count;

            for (var i = 0; i < count; i++)
            {
                IUpdateComponent component = package.UpdateComponents[i];
                var id     = component.GetComponentId();
                var target = gameEntity.GetComponent(id);
                if (target == null)
                {
                    target = gameEntity.AddComponent(id);
                }

                var p = GetProfile(component.GetComponentId());
                try
                {
                    p.BeginProfileOnlyEnableProfile();
                    ((INetworkObject)target).CopyFrom(component);
                    if (id == (int)EComponentIds.SendUserCmd)
                    {
                        UserCmd cmd = UserCmd.Allocate();
                        CopyForm(cmd, component as SendUserCmdComponent);
                        playerEntity.userCmd.AddLatest(cmd);
                        cmd.Seq        = package.Head.LastUserCmdSeq;
                        cmd.SnapshotId = package.Head.LastSnapshotId;
                        cmd.ReleaseReference();
                    }
                }
                finally
                {
                    p.EndProfileOnlyEnableProfile();
                }
            }
        }
Exemplo n.º 4
0
        public void SyncToEntity(IUserCmdOwner owner, UpdateLatestPacakge package)
        {
            PlayerEntity playerEntity = owner.OwnerEntity as PlayerEntity;
            IGameEntity  gameEntity   = playerEntity.entityAdapter.SelfAdapter;

            foreach (var component in package.UpdateComponents)
            {
                var target = gameEntity.GetComponent(component.GetComponentId());
                if (target == null)
                {
                    target = gameEntity.AddComponent(component.GetComponentId());
                }
                ((INetworkObject)target).CopyFrom(component);
                if (component is SendUserCmdComponent)
                {
                    UserCmd cmd = UserCmd.Allocate();
                    CopyForm(cmd, component as SendUserCmdComponent);
                    playerEntity.userCmd.AddLatest(cmd);
                    cmd.Seq        = package.Head.UserCmdSeq;
                    cmd.SnapshotId = package.Head.LastSnapshotId;
                    cmd.ReleaseReference();
                }
            }
        }
Exemplo n.º 5
0
 public void OnLeftComponentMissing(IGameEntity leftEntity, IGameEntity rightEntity, IGameComponent rightComponent)
 {
     _logger.DebugFormat("add component {0}:{1}", leftEntity.EntityKey, rightComponent.GetType());
     var leftComponent = (ILatestComponent)leftEntity.AddComponent(rightComponent.GetComponentId(), rightComponent);
 }
Exemplo n.º 6
0
 public override void ApplyPatchTo(IGameEntity entity, INetworkObjectSerializerManager serializerManager)
 {
     var copyCopy = entity.AddComponent(Component.GetComponentId(), Component);
 }
 public override void OnLeftComponentMissing(IGameEntity leftEntity, IGameEntity rightEntity, IGameComponent rightComponent)
 {
     _logger.DebugFormat("add component {0}:{1}", leftEntity.EntityKey, rightComponent.GetType());
     leftEntity.AddComponent(rightComponent.GetComponentId());
 }