Esempio n. 1
0
        protected override void SampleInputs()
        {
            var inputs = MatchConfig.CreateNativePlayerBuffer <PlayerInput>(Allocator.Temp);

            _reader.ReadInputs(new NativeSlice <PlayerInput>(inputs, 0, Config.PlayerCount));
            InjectInputs(inputs);
        }
Esempio n. 2
0
        public async Task <MatchResult> RunMatch(MatchConfig config, bool loadScene = true)
        {
            Debug.Log($"Running Match. Config: {config}");
            await DataLoader.LoadTask.Task;
            Task sceneLoad = Task.CompletedTask;

            if (loadScene)
            {
                var stage = Registry.Get <SceneData>().Get(config.StageID);
                Assert.IsTrue(stage != null && stage.Type == SceneType.Stage);
                await stage.GameScene.LoadAsync();
            }
            var additionalScenes = Config.Get <SceneConfig>().AdditionalStageScenes;
            await Task.WhenAll(additionalScenes.Select(s => s.LoadAsync(LoadSceneMode.Additive)));

            var matchManager = MatchManager.Instance;

            matchManager.enabled = false;
            matchManager.Config  = config;
            try {
                await LoadingScreen.Await(InitializeMatch(matchManager, config));

                await LoadingScreen.AwaitAll();
            } catch (Exception e) {
                Debug.LogException(e);
            }
            matchManager.enabled = true;
            return(await matchManager.RunMatch());
        }
        protected override async Task InitializeMatch(MatchManager gameManager, MatchConfig config)
        {
            var gameView   = new MatchView();
            var gameSim    = CreateSimulation(config);
            var controller = CreateMatchController(config);

            Debug.Log($"Match Controller Type: {controller.GetType()}");

            controller.CurrentState = CreateInitialState(config);
            controller.InputSource  = Config.Get <GameplayConfig>().CreateInputSource(config);
            controller.Simulation   = gameSim;

            gameManager.MatchController = controller;
            gameManager.View            = gameView;

            var simTask = gameSim.Initialize(config).ContinueWith(task => {
                Debug.Log("Simulation initialized.");
            });
            var viewTask = gameView.Initialize(config).ContinueWith(task => {
                Debug.Log("View initialized.");
            });

            await Task.WhenAll(viewTask, simTask);

            controller.CurrentState = gameSim.ResetState(controller.CurrentState);
            Debug.Log("Match initialized.");
        }
Esempio n. 4
0
        protected RecordableMatch(MatchConfig config, World world = null) : base(config, world)
        {
            ReplayFilePath = GetReplayFilename();
            var binaryWriter = new StreamBinaryWriter(ReplayFilePath);

            _writer = new ReplayWriter(config, binaryWriter);
            // FIXME: This should write the MatchConfig here.
        }
Esempio n. 5
0
 protected IMatchSimulation CreateSimulation(MatchConfig config)
 {
     return(new MatchSimulation(new IMatchSimulation[] {
         new MatchPlayerSimulation(),
         new MatchHitboxSimulation(config),
         new MatchRuleSimulation(CreateRules(config))
     }));
 }
 public MatchHitboxSimulation(MatchConfig config)
 {
     Instance         = this;
     Config           = config;
     ActiveHitboxes   = new HashSet <Hitbox>();
     ActiveHurtboxes  = new HashSet <Hurtbox>();
     CollisionManager = new PlayerCollisionManager(config);
 }
 public PlayerCollisionManager(MatchConfig config)
 {
     PlayerCollisions = new List <HitboxCollision> [config.PlayerCount];
     for (var i = 0; i < PlayerCollisions.Length; i++)
     {
         PlayerCollisions[i] = new List <HitboxCollision>();
     }
 }
Esempio n. 8
0
 void SetDefaultDamages(MatchConfig config, MatchState initialState)
 {
     for (int i = 0; i < initialState.PlayerCount; i++)
     {
         var state = initialState.GetPlayerState(i);
         state.Damage = config.PlayerConfigs[i].DefaultDamage;
         initialState.SetPlayerState(i, state);
     }
 }
Esempio n. 9
0
 /// <summary>
 /// Constructs a new GameState based on a given GameConfig.
 /// </summary>
 /// <param name="config">the configuration for the game.</param>
 public MatchState(MatchConfig config) : this(config.PlayerCount)
 {
     Time = config.Time;
     for (var i = 0; i < PlayerCount; i++)
     {
         playerStates[i].Stocks     = (sbyte)config.Stocks;
         playerStates[i].MatchState = this;
     }
 }
Esempio n. 10
0
        public static PlayerMatchStats[] CreateMatchStatsFromConfig(MatchConfig config)
        {
            var players = new PlayerMatchStats[config.PlayerCount];

            for (uint i = 0; i < players.Length; i++)
            {
                players[i].Config = config.PlayerConfigs[i];
            }
            return(players);
        }
Esempio n. 11
0
        protected Match(MatchConfig config, World world = null)
        {
            Config = config;
            World  = world ?? Unity.Entities.World.DefaultGameObjectInjectionWorld;

            Simulation         = World.GetOrCreateSystem <SimulationSystemGroup>();
            Simulation.Enabled = false;
            Simulation.SortSystems();

            _blobAssetStore = new BlobAssetStore();
        }
Esempio n. 12
0
        protected MatchState CreateInitialState(MatchConfig config)
        {
            var tag            = Config.Get <SceneConfig>().SpawnTag;
            var startPositions = GameObject.FindGameObjectsWithTag(tag);

            if (startPositions.Length > 0)
            {
                return(CreateInitialStateByTransform(config, startPositions));
            }
            return(CreateInitialStateSimple(config));
        }
Esempio n. 13
0
        MatchState CreateInitialStateByTransform(MatchConfig config, GameObject[] startPositions)
        {
            var initialState = new MatchState(config);

            startPositions = startPositions.OrderBy(s => s.transform.GetSiblingIndex()).ToArray();
            for (int i = 0; i < initialState.PlayerCount; i++)
            {
                var             startPos = startPositions[i % startPositions.Length].transform;
                ref PlayerState state    = ref initialState[i];
                state.Position  = startPos.position;
                state.Direction = startPos.transform.forward.x >= 0;
            }
Esempio n. 14
0
        MatchState CreateInitialStateSimple(MatchConfig config)
        {
            var initialState = new MatchState(config);

            for (var i = 0; i < initialState.PlayerCount; i++)
            {
                var state = initialState.GetPlayerState(i);
                state.Position = new Vector3((int)i * 2 - 3, 1, 0);
                initialState.SetPlayerState(i, state);
            }
            return(initialState);
        }
        public Task Initialize(MatchConfig config)
        {
            Assert.IsTrue(config.IsValid);
            PlayerSimulations = new PlayerSimulation[config.PlayerCount];
            var tasks = new List <Task>();

            for (int i = 0; i < PlayerSimulations.Length; i++)
            {
                PlayerSimulations[i] = new PlayerSimulation();
                tasks.Add(PlayerSimulations[i].Initialize(config.PlayerConfigs[i]));
            }
            return(Task.WhenAll(tasks));
        }
Esempio n. 16
0
 public RollbackMatch(MatchConfig config, BackrollSessionConfig backrollConfig,
                      World world = null) : base(config, world)
 {
     _hasher     = World.GetOrCreateSystem <HashWorldSystem>();
     SavedStates = WorldPool.Instance;
     backrollConfig.Callbacks = new BackrollSessionCallbacks {
         SaveGameState = Serialize,
         LoadGameState = Deserialize,
         FreeBuffer    = ReleaseWorld,
         AdvanceFrame  = Step,
     };
     BackrollConfig = backrollConfig;
     Assert.IsTrue(BackrollConfig.IsValid);
 }
Esempio n. 17
0
        protected MatchState CreateInitialState(MatchConfig config)
        {
            var        tag            = Config.Get <SceneConfig>().SpawnTag;
            var        startPositions = GameObject.FindGameObjectsWithTag(tag);
            MatchState state;

            if (startPositions.Length > 0)
            {
                state = CreateInitialStateByTransform(config, startPositions);
            }
            else
            {
                state = CreateInitialStateSimple(config);
            }
            SetDefaultDamages(config, state);
            return(state);
        }
Esempio n. 18
0
        public Task Initialize(MatchConfig config)
        {
            Assert.IsTrue(config.IsValid);
            PlayerSimulations = new PlayerSimulation[config.PlayerCount];
            var tasks = new List <Task>();

            for (int i = 0; i < PlayerSimulations.Length; i++)
            {
                PlayerSimulations[i] = new PlayerSimulation();
                tasks.Add(PlayerSimulations[i].Initialize(config.PlayerConfigs[i]));
            }

            context = Mediator.Global.CreateContext();
            context.Subscribe <PlayerResetEvent>(ResetPlayer);

            return(Task.WhenAll(tasks));
        }
Esempio n. 19
0
        protected virtual void SampleInputs()
        {
            var manager = InputManager.Instance;

            if (manager == null)
            {
                return;
            }
            var inputs = MatchConfig.CreateNativePlayerBuffer <PlayerInput>(Allocator.Temp);

            for (var i = 0; i < Config.PlayerCount; i++)
            {
                if (!Config[i].IsLocal)
                {
                    continue;
                }
                inputs[Config[i].PlayerID] = manager.GetInputForPlayer(Config[i].LocalPlayerID);
            }
            InjectInputs(inputs);
        }
        IView <PlayerUIData>[] CreateViews(RectTransform prefab, RectTransform container)
        {
            var store = MatchConfig.CreatePlayerBuffer <IView <PlayerUIData> >();

            if (prefab == null)
            {
                return(store);
            }
            for (var i = 0; i < store.Length; i++)
            {
                RectTransform playerView = GameObject.Instantiate(prefab);
                if (container != null)
                {
                    playerView.SetParent(container, false);
                }
                playerView.gameObject.name = playerView.gameObject.name.Replace("(Clone)", "") + " " + (i + 1);
                store[i] = AggregateView <PlayerUIData> .FromGameObject(playerView.gameObject);
            }
            return(store);
        }
Esempio n. 21
0
 public MatchController(MatchConfig config)
 {
     inputContext = new MatchInputContext(new MatchInput(config));
 }
 protected override IEnumerable <IMatchRule> CreateRules(MatchConfig config)
 {
     yield return(new TrainingMatchRule());
 }
Esempio n. 23
0
 protected override void OnCreate()
 {
     _data = MatchConfig.CreateNativePlayerBuffer <PlayerUIData>();
 }
Esempio n. 24
0
 // TODO(james71323): Refactor or move this to somewhere more sane
 protected virtual IMatchController CreateMatchController(MatchConfig config)
 {
     return(new MatchController(config));
 }
Esempio n. 25
0
 protected abstract Task InitializeMatch(MatchManager manager, MatchConfig config);
Esempio n. 26
0
 /// <summary>
 /// Creatse a ReplayWriter.
 /// </summary>
 /// <param name="writer">A BinaryWriter implementation, takes ownership of it.</param>
 public ReplayWriter(MatchConfig config, BinaryWriter writer)
 {
     _config = config;
     _writer = writer;
 }
Esempio n. 27
0
 protected virtual IEnumerable <IMatchRule> CreateRules(MatchConfig config)
 {
     return(MatchRuleFactory.CreateRules(config));
 }
Esempio n. 28
0
 public ReplayReader(MatchConfig config, BinaryReader reader)
 {
     _config = config;
     _reader = reader;
 }
Esempio n. 29
0
 public Task Initialize(MatchConfig config)
 {
     MatchConfig = config;
     BlastZone   = Object.FindObjectOfType <BlastZone>();
     return(Task.WhenAll(Rules.Select(rule => rule.Initialize(config))));
 }
Esempio n. 30
0
 public Task Initialize(MatchConfig config)
 {
     return(Task.WhenAll(SimulationComponents.Select(comp => comp.Initialize(config))));
 }