Exemplo n.º 1
0
        public NetworkRunner(CvarcClient client)
        {
            this.client = client;

            factory = new SoloNetworkControllerFactory(client);

            var configProposal = client.Read<ConfigurationProposal>();
            var loadingData = configProposal.LoadingData;
            var competitions = Dispatcher.Loader.GetCompetitions(loadingData);
            var settings = competitions.Logic.CreateDefaultSettings();
            if (configProposal.SettingsProposal != null)
                configProposal.SettingsProposal.Push(settings, true);
            configuration = new Configuration
            {
                LoadingData = loadingData,
                Settings = settings
            };

            //configuration.Settings.EnableLog = true;
            //configuration.Settings.LogFile = UnityConstants.LogFolderRoot + "cvarclog1";

            var worldSettingsType = competitions.Logic.WorldStateType;
            worldState = (IWorldState)client.Read(worldSettingsType);

            Name = loadingData.AssemblyName + loadingData.Level;
            CanInterrupt = true;
            CanStart = true;
        }
Exemplo n.º 2
0
        public TournamentRunner(IWorldState worldState, Configuration configuration)
        {
            this.worldState = worldState;
            this.configuration = configuration;
            players = new List<TournamentPlayer>();

            //log section
            logFileName = Guid.NewGuid() + ".log";
            configuration.Settings.EnableLog = true;
            configuration.Settings.LogFile = UnityConstants.LogFolderRoot + logFileName;
            //log section end

            var competitions = Dispatcher.Loader.GetCompetitions(configuration.LoadingData);
            controllerIds = competitions.Logic.Actors.Keys.ToArray();

            foreach (var controller in controllerIds
                .Select(x => new ControllerSettings
                {
                    ControllerId = x,
                    Type = ControllerType.Client,
                    Name = configuration.Settings.Name
                }))
                configuration.Settings.Controllers.Add(controller);

            requiredCountOfPlayers = controllerIds.Length;

            Debugger.Log(DebuggerMessageType.Unity, "t.runner created. count: " + requiredCountOfPlayers);
            if (requiredCountOfPlayers == 0)
                throw new Exception("requiered count of players cant be 0");

            Name = configuration.LoadingData.AssemblyName + configuration.LoadingData.Level;//"Tournament";
            CanInterrupt = false;
            CanStart = false;
        }
Exemplo n.º 3
0
		/// <summary>
		/// Creates a world. 
		/// </summary>
		/// <param name="configuration">Contains the cometition/level name and the settings</param>
		/// <param name="controllerFactory">Is used to create controllers, i.e. entities that control the robots</param>
		/// <param name="state">The initial state of the world</param>
		/// <returns></returns>
		public IWorld CreateWorld(Configuration configuration, ControllerFactory controllerFactory, IWorldState state)
		{
			var competitions = GetCompetitions(configuration.LoadingData);
			var world = competitions.Logic.CreateWorld();
			world.Initialize(competitions, configuration, controllerFactory, state);
			world.Exit += ()=>
				controllerFactory.Exit();
			return world;
		}
Exemplo n.º 4
0
 public static void AddForceGame(IWorldState worldState, Configuration config)
 {
     if (forceRunner != null)
         while (!forceRunner.Disposed)
             Thread.Sleep(100);
     haveForceGame = true;
     lock (pool)
         pool.Clear();
     forceRunner = new TournamentRunner(worldState, config);
     Dispatcher.AddRunner(forceRunner);
 }
Exemplo n.º 5
0
        public LogRunner(string fileName)
        {
            var log = Log.Load(UnityConstants.LogFolderRoot + fileName);
            factory = new LogPlayerControllerFactory(log);
            configuration = log.Configuration;
            configuration.Settings.EnableLog = false; // чтоб файл логов не переписывать

            worldState = log.WorldState;

            Name = "log run: " + fileName;
            CanInterrupt = true;
            CanStart = true;
        }
Exemplo n.º 6
0
		/// <summary>
		/// Creates a controller for the network client and instantiate the world with this controller. This action is the last before the start.
		/// </summary>
		/// <param name="data"></param>
		public void InstantiateWorld(NetworkServerData data)
		{
			var factory = new SoloNetworkControllerFactory(data.ClientOnServerSide);
			var configuration = new Configuration
			{
				LoadingData = data.LoadingData,
				Settings = data.Settings
			};
			data.World = CreateWorld(configuration, factory, data.WorldState);
			data.World.Exit += () =>
			{
				if (data != null)
					data.Close();
			};
		}
Exemplo n.º 7
0
        protected override void HandleClient(CvarcClient client)
        {
            var configProposal = client.Read<ConfigurationProposal>();
            var loadingData = configProposal.LoadingData; //RoboMoviesLevel1
            var competitions = Dispatcher.Loader.GetCompetitions(loadingData);
            var worldSettingsType = competitions.Logic.WorldStateType;
            var worldState = (IWorldState)client.Read(worldSettingsType);
            var settings = competitions.Logic.CreateDefaultSettings(); // таким образом игнорируются все настйроки пользователя сейчас.

            var configuration = new Configuration
            {
                LoadingData = loadingData,
                Settings = settings
            };
            TournamentPool.AddPlayerToPool(client, configuration, worldState, configProposal);
        }
Exemplo n.º 8
0
        protected override void HandleClient(CvarcClient client)
        {
            var configProposal = client.Read<ConfigurationProposal>();
            var loadingData = configProposal.LoadingData; //RoboMoviesLevel1
            var competitions = Dispatcher.Loader.GetCompetitions(loadingData);
            var worldSettingsType = competitions.Logic.WorldStateType;
            var worldState = (IWorldState)client.Read(worldSettingsType);
            var settings = competitions.Logic.CreateDefaultSettings();
            if (configProposal.SettingsProposal != null)
                configProposal.SettingsProposal.Push(settings, true);
            var configuration = new Configuration
            {
                LoadingData = loadingData,
                Settings = settings
            };

            TournamentPool.AddForceGame(worldState, configuration);

            client.Close();
        }
Exemplo n.º 9
0
 public static void AddPlayerToPool(CvarcClient client, Configuration configuration, IWorldState worldState, ConfigurationProposal configProposal)
 {
     if (haveForceGame)
     {
         if (UnityConstants.OnlyGamesThroughServicePort)
             HttpWorker.SendInfoToLocal(configProposal.SettingsProposal.CvarcTag);
         if (forceRunner.AddPlayerAndCheck(new TournamentPlayer(client, configProposal, worldState)))
             haveForceGame = false;
         return;
     }
     lock (pool)
     {
         if (!pool.ContainsKey(configuration.LoadingData))
         {
             pool.Add(configuration.LoadingData, new TournamentRunner(worldState, configuration));
             Dispatcher.AddRunner(pool[configuration.LoadingData]);
         }
         if (pool[configuration.LoadingData].AddPlayerAndCheck(new TournamentPlayer(client, configProposal, worldState)))
             pool.Remove(configuration.LoadingData);
     }
 }
Exemplo n.º 10
0
        readonly IWorldState worldState; // откуда?

        #endregion Fields

        #region Constructors

        public TutorialRunner(LoadingData loadingData, Configuration configuration = null, IWorldState worldState = null)
        {
            factory = new TutorialControllerFactory();

            var competitions = Dispatcher.Loader.GetCompetitions(loadingData);
            if (configuration == null)
            {
                this.configuration = new Configuration
                {
                    LoadingData = loadingData,
                    Settings = competitions.Logic.CreateDefaultSettings()
                };
            }
            else
                this.configuration = configuration;

            this.worldState = worldState ?? competitions.Logic.CreateWorldState(competitions.Logic.PredefinedWorldStates[0]);
            //this.worldState = worldState ?? competitions.Logic.CreateWorldState("0"); // lol

            Name = "Tutorial";
            CanStart = true;
            CanInterrupt = true;
        }
Exemplo n.º 11
0
        public TournamentRunner(LoadingData loadingData, IWorldState worldState)
        {
            this.worldState = worldState;
            players = new List<TournamentPlayer>();

            var competitions = Dispatcher.Loader.GetCompetitions(loadingData);
            var settings = competitions.Logic.CreateDefaultSettings();
            configuration = new Configuration
            {
                LoadingData = loadingData,
                Settings = settings
            };

            //я игнорирую конфиги. надо хотя бы имя сохранять в метод "add player"

            controllerIds = competitions.Logic.Actors.Keys.ToArray();

            foreach (var controller in controllerIds
                .Select(x => new ControllerSettings
                {
                    ControllerId = x,
                    Type = ControllerType.Client,
                    Name = settings.Name
                }))
                settings.Controllers.Add(controller);

            requiredCountOfPlayers = controllerIds.Length;

            Debugger.Log(DebuggerMessageType.Unity, "t.runner created. count: " + requiredCountOfPlayers);
            if (requiredCountOfPlayers == 0)
                throw new Exception("requiered count of players cant be 0");

            Name = loadingData.AssemblyName + loadingData.Level;//"Tournament";
            CanInterrupt = false;
            CanStart = false;
        }
Exemplo n.º 12
0
		/// <summary>
		/// Creates the world for non-networking case: BotDemo or Tutorial modes.
		/// </summary>
		/// <param name="loadingData"></param>
		/// <param name="proposal"></param>
		/// <param name="factory"></param>
		/// <returns></returns>
		public IWorld CreateSimpleMode(LoadingData loadingData, SettingsProposal proposal, ControllerFactory factory)
		{
			var configuration = new Configuration();
			configuration.LoadingData = loadingData;
			var competitions = GetCompetitions(configuration.LoadingData);
			configuration.Settings = competitions.Logic.CreateDefaultSettings();


			proposal.Push(configuration.Settings, true);
			var stateName = configuration.Settings.WorldState;
			if (stateName == null)
			{
				if (competitions.Logic.PredefinedWorldStates.Count == 0)
					throw new Exception("The count of predefined stated in the " + competitions.Logic.GetType() + " is zero");
				stateName = competitions.Logic.PredefinedWorldStates[0];
			}
			var state = competitions.Logic.CreateWorldState(stateName);
			return CreateWorld(configuration, factory, state);

		}