public void OnEnable()
 {
     logDispatcher = GetComponent <SpatialOSComponent>().Worker.LogDispatcher;
     cubeSpawnerCommandRequestHandler.OnDeleteSpawnedCubeRequest += OnDeleteSpawnedCubeRequest;
     worldCommandResponseHandler.OnDeleteEntityResponse          += OnDeleteEntityResponse;
 }
Ejemplo n.º 2
0
 public IInjectable CreateInjectable(Entity entity, EntityManager entityManager, ILogDispatcher logDispatcher)
 {
     return(new CommandRequestHandler(entity, entityManager, logDispatcher));
 }
 public ReaderWriterImpl(Entity entity, EntityManager entityManager, ILogDispatcher logDispatcher)
     : base(entity, entityManager, logDispatcher)
 {
 }
Ejemplo n.º 4
0
 public CommandResponseHandler(Entity entity, EntityManager entityManager, ILogDispatcher logger) : base(logger)
 {
     this.entity        = entity;
     this.entityManager = entityManager;
     this.logger        = logger;
 }
Ejemplo n.º 5
0
 public CommandRequestSender(Entity entity, EntityManager entityManager, ILogDispatcher logger) : base(logger)
 {
     this.entity        = entity;
     this.entityManager = entityManager;
     this.logger        = logger;
 }
Ejemplo n.º 6
0
 protected ReaderWriterBase(Entity entity, EntityManager entityManager, ILogDispatcher logDispatcher)
 {
     Entity             = entity;
     EntityManager      = entityManager;
     this.logDispatcher = logDispatcher;
 }
 public RequiredFieldInjector(EntityManager entityManager, ILogDispatcher logger)
 {
     this.logger            = logger;
     this.injectableFactory = new InjectableFactory(entityManager, logger);
 }
Ejemplo n.º 8
0
 private WorldCommandRequestSender(Entity entity, EntityManager entityManager,
                                   ILogDispatcher logDispatcher) : base(logDispatcher)
 {
     this.entity        = entity;
     this.entityManager = entityManager;
 }
Ejemplo n.º 9
0
        /// <summary>
        ///     Asynchronously connects a worker to the SpatialOS runtime.
        /// </summary>
        /// <remarks>
        ///     Uses the global position of this GameObject as the worker origin.
        ///     Uses <see cref="ShouldUseLocator"/> to determine whether to connect via the Locator.
        /// </remarks>
        /// <param name="workerType">The type of the worker to connect as</param>
        /// <param name="logger">The logger for the worker to use.</param>
        /// <returns></returns>
        public async Task Connect(string workerType, ILogDispatcher logger)
        {
            // Check that other workers have finished trying to connect before this one starts.
            // This prevents races on the workers starting and races on when we start ticking systems.
            await WorkerConnectionSemaphore.WaitAsync();

            try
            {
                // A check is needed for the case that play mode is exited before the semaphore was released.
                if (!Application.isPlaying)
                {
                    return;
                }

                var origin = transform.position;
                ConnectionDelegate connectionDelegate;
                var chosenService        = GetConnectionService();
                var connectionParameters = GetConnectionParameters(workerType, chosenService);
                switch (chosenService)
                {
                case ConnectionService.Receptionist:
                    connectionDelegate = async() =>
                                         await Worker.CreateWorkerAsync(GetReceptionistConfig(workerType), connectionParameters, logger, origin)
                                         .ConfigureAwait(false);

                    break;

                case ConnectionService.Locator:
                    connectionDelegate = async() =>
                                         await Worker
                                         .CreateWorkerAsync(GetLocatorConfig(), connectionParameters, logger, origin)
                                         .ConfigureAwait(false);

                    break;

                case ConnectionService.AlphaLocator:
                    connectionDelegate = async() =>
                                         await Worker.CreateWorkerAsync(GetAlphaLocatorConfig(workerType), connectionParameters, logger, origin)
                                         .ConfigureAwait(false);

                    break;

                default:
                    throw new Exception("No valid connection flow type selected");
                }

                Worker = await ConnectWithRetries(connectionDelegate, MaxConnectionAttempts, logger, workerType);

                Worker.OnDisconnect += OnDisconnected;

                HandleWorkerConnectionEstablished();

                World.Active = World.Active ?? Worker.World;
                ScriptBehaviourUpdateOrder.UpdatePlayerLoop(World.AllWorlds.ToArray());
            }
            catch (Exception e)
            {
                logger.HandleLog(LogType.Error, new LogEvent("Failed to create worker")
                                 .WithException(e)
                                 .WithField("WorkerType", workerType)
                                 .WithField("Message", e.Message));
#if UNITY_EDITOR
                // Temporary warning to be replaced when we can reliably detect if a local runtime is running, or not.
                logger.HandleLog(LogType.Warning,
                                 new LogEvent(
                                     "Is a local runtime running? If not, you can start one from 'SpatialOS -> Local launch' or by pressing Cmd/Ctrl-L")
                                 .WithField("Reason", "A worker running in the Editor failed to connect"));
#endif
                // A check is needed for the case that play mode is exited before the connection can complete.
                if (Application.isPlaying)
                {
                    HandleWorkerConnectionFailure(e.Message);
                    Dispose();
                }
            }
            finally
            {
                WorkerConnectionSemaphore.Release();
            }

            foreach (var callback in workerConnectedCallbacks)
            {
                callback(Worker);
            }
        }
Ejemplo n.º 10
0
 public RequirableBase(ILogDispatcher logDispatcher)
 {
     this.logDispatcher = logDispatcher;
 }
Ejemplo n.º 11
0
 public EntityGameObjectLinker(World world, ILogDispatcher logDispatcher)
 {
     this.world         = world;
     this.logDispatcher = logDispatcher;
 }
Ejemplo n.º 12
0
 public GameObjectCreatorFromMetadata(string workerType, Vector3 workerOrigin, ILogDispatcher logger)
 {
     this.workerType   = workerType;
     this.workerOrigin = workerOrigin;
     this.logger       = logger;
 }
Ejemplo n.º 13
0
        public WorkerSystem(IConnectionHandler connectionHandler, Connection connection, ILogDispatcher logDispatcher, string workerType, Vector3 origin)
        {
            Connection        = connection;
            LogDispatcher     = logDispatcher;
            WorkerType        = workerType;
            Origin            = origin;
            ConnectionHandler = connectionHandler;

            MessagesToSend = connectionHandler.GetMessagesToSendContainer();
        }
Ejemplo n.º 14
0
 /// <summary>
 ///     Creates a <see cref="Worker"/> object asynchronously.
 /// </summary>
 /// <param name="connectionHandlerBuilder">
 ///     A builder which describes how to create the <see cref="IConnectionHandler"/> for this worker.
 /// </param>
 /// <param name="workerType">The type of worker to connect as.</param>
 /// <param name="logDispatcher">The logger to use for this worker.</param>
 /// <param name="token">A cancellation token which will cancel this asynchronous operation</param>
 /// <returns>A task which represents the asynchronous creation of a worker.</returns>
 public static async Task<Worker> CreateWorkerAsync(IConnectionHandlerBuilder connectionHandlerBuilder, string workerType,
     ILogDispatcher logDispatcher, CancellationToken? token = null)
 {
     var handler = await connectionHandlerBuilder.CreateAsync(token);
     return new Worker(handler, workerType, logDispatcher);
 }
 public IInjectable CreateInjectable(Entity entity, EntityManager entityManager, ILogDispatcher logDispatcher)
 {
     return(new ReaderWriterImpl(entity, entityManager, logDispatcher));
 }
        protected override void OnCreateManager(int capacity)
        {
            base.OnCreateManager(capacity);

            logDispatcher = World.GetExistingManager <WorkerSystem>().LogDispatcher;
        }
Ejemplo n.º 17
0
		public void SetDispatcher(ILogDispatcher dispatcher)
		{

		}
Ejemplo n.º 18
0
 public IInjectable CreateInjectable(Entity entity, EntityManager entityManager,
                                     ILogDispatcher logDispatcher)
 {
     return(new WorldCommandResponseHandler(logDispatcher));
 }