Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of <see cref="ComponentMap{T}"/>.
        /// </summary>
        /// <param name="dispatcher">
        /// Optional. Dispatcher for the ComponentMap to use. If left null, the map will attempt to use the dispatcher
        /// from the current <see cref="WorkerContext"/>.
        /// </param>
        /// <param name="disableEvents">
        /// Optional. Events to disable. Can pass in multiple flags using bitwise OR. For example,
        /// AddComponent | UpdateComponent.
        /// </param>
        public ComponentMap(IDispatcher dispatcher = null, ComponentMapEvent?disableEvents = null)
        {
            _authority             = new HashSet <EntityId>();
            _authorityLossImminent = new HashSet <EntityId>();
            _components            = new Dictionary <EntityId, IComponentData <T> >();

            dispatcher = dispatcher ?? WorkerContext.GetInstance().GetDispatcher();

            if (!HasFlag(disableEvents, ComponentMapEvent.AddComponent))
            {
                dispatcher.OnAddComponent <T>(AddComponent);
            }

            if (!HasFlag(disableEvents, ComponentMapEvent.RemoveEntity))
            {
                dispatcher.OnRemoveEntity(RemoveEntity);
            }

            if (!HasFlag(disableEvents, ComponentMapEvent.UpdateComponent))
            {
                dispatcher.OnComponentUpdate <T>(UpdateComponent);
            }

            if (!HasFlag(disableEvents, ComponentMapEvent.AuthorityChange))
            {
                dispatcher.OnAuthorityChange <T>(SetAuthority);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Constructs a GenericWorker. Initializes a <see cref="WorkerContext"/> given the parameters.
        /// </summary>
        /// <param name="workerType">Type of worker</param>
        /// <param name="workerId">Unique ID of worker</param>
        /// <param name="hostname">SpatialOS deployment hostname</param>
        /// <param name="port">SpatialOS deployment port</param>
        protected GenericWorker(string workerType, string workerId, string hostname, ushort port)
        {
            _workerId   = workerId;
            _workerType = workerType;

            WorkerContext.GetInstance().Init(workerType, workerId, hostname, port);

            _logger.Info("Initialized Deployment Context");
        }
Ejemplo n.º 3
0
        public void Setup()
        {
            _tickCount = 0;

            var mockConnection = new Mock <IConnection>();

            mockConnection.Setup(_ => _.IsConnected).Returns(true);
            mockConnection.Setup(_ => _.GetOpList(It.IsAny <uint>()));

            var mockDispatcher = new Mock <IDispatcher>();

            mockDispatcher.Setup(_ => _.Process(It.IsAny <OpList>()));

            WorkerContext.GetInstance().Init(mockConnection.Object, mockDispatcher.Object);
        }
Ejemplo n.º 4
0
 protected WorkerContext GetContext()
 {
     return(WorkerContext.GetInstance());
 }