/// <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); } }
/// <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"); }
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); }
protected WorkerContext GetContext() { return(WorkerContext.GetInstance()); }