Пример #1
0
        public void Dispose()
        {
            UnRegisterDispatcherCallbacks();
            UnregisterComponentFactories();

            var block = firstBlock;

            while (block != null)
            {
                var disposable = block as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }

                block = block.NextEntityBlock;
            }

            firstBlock = null;
            lastBlock  = null;
            started    = false;

            spatialCommunicator = null;
            connection          = null;
            dispatcher          = null;
        }
        /// <summary>
        ///     Registers the given <see cref="IEntityPipelineBlock" /> as <see cref="ComponentFactoryCallbacks" />
        ///     objects used in base SDK <see cref="IComponentFactory" /> instances in generated code.
        /// </summary>
        /// <param name="block"></param>
        /// <returns></returns>
        public static ComponentFactoryCallbacks ToComponentFactoryCallbacks(this IEntityPipelineBlock block)
        {
            var wrapper = new FactoryCallbackWrapper(block);

            return(new ComponentFactoryCallbacks
            {
                OnComponentAdded = wrapper.AddComponent,
                OnComponentRemoved = wrapper.RemoveComponent,
                OnAuthorityChanged = wrapper.ChangeAuthority,
                OnComponentUpdated = wrapper.UpdateComponent
            });
        }
Пример #3
0
        public IEntityPipeline AddBlock(IEntityPipelineBlock block)
        {
            if (started)
            {
                throw new InvalidOperationException("Cannot add blocks after the pipeline has been started.");
            }

            if (firstBlock == null)
            {
                firstBlock = block;
            }

            if (lastBlock != null)
            {
                lastBlock.NextEntityBlock = block;
            }

            lastBlock = block;
            return(this);
        }
        /// <summary>
        ///     Convenience method for dispatching the supplied op to the
        ///     appropriate method in the entity pipeline block.
        /// </summary>
        /// <exception cref="ArgumentException">
        ///     Thrown when op object is of an unrecognised type.
        /// </exception>
        public static void DispatchOp(this IEntityPipelineBlock block, IEntityPipelineOp pipelineOp)
        {
            switch (pipelineOp.PipelineOpType)
            {
            case PipelineOpType.AddEntity:
                block.AddEntity((AddEntityPipelineOp)pipelineOp);
                break;

            case PipelineOpType.RemoveEntity:
                block.RemoveEntity((RemoveEntityPipelineOp)pipelineOp);
                break;

            case PipelineOpType.CriticalSection:
                block.CriticalSection((CriticalSectionPipelineOp)pipelineOp);
                break;

            case PipelineOpType.AddComponent:
                block.AddComponent((AddComponentPipelineOp)pipelineOp);
                break;

            case PipelineOpType.RemoveComponent:
                block.RemoveComponent((RemoveComponentPipelineOp)pipelineOp);
                break;

            case PipelineOpType.ChangeAuthority:
                block.ChangeAuthority((ChangeAuthorityPipelineOp)pipelineOp);
                break;

            case PipelineOpType.UpdateComponent:
                block.UpdateComponent((UpdateComponentPipelineOp)pipelineOp);
                break;

            default:
                throw new ArgumentException(string.Format("Unknown op type {0}, cannot dispatch.", pipelineOp.GetType().Name), "op");
            }
        }
 internal FactoryCallbackWrapper(IEntityPipelineBlock block)
 {
     this.block = block;
 }