コード例 #1
0
ファイル: Match.cs プロジェクト: JoshHux/FantasyCrescendoECS
        protected override void SampleInputs()
        {
            var inputs = MatchConfig.CreateNativePlayerBuffer <PlayerInput>(Allocator.Temp);

            _reader.ReadInputs(new NativeSlice <PlayerInput>(inputs, 0, Config.PlayerCount));
            InjectInputs(inputs);
        }
コード例 #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());
        }
コード例 #3
0
        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.");
        }
コード例 #4
0
ファイル: Match.cs プロジェクト: JoshHux/FantasyCrescendoECS
        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.
        }
コード例 #5
0
 protected IMatchSimulation CreateSimulation(MatchConfig config)
 {
     return(new MatchSimulation(new IMatchSimulation[] {
         new MatchPlayerSimulation(),
         new MatchHitboxSimulation(config),
         new MatchRuleSimulation(CreateRules(config))
     }));
 }
コード例 #6
0
 public MatchHitboxSimulation(MatchConfig config)
 {
     Instance         = this;
     Config           = config;
     ActiveHitboxes   = new HashSet <Hitbox>();
     ActiveHurtboxes  = new HashSet <Hurtbox>();
     CollisionManager = new PlayerCollisionManager(config);
 }
コード例 #7
0
 public PlayerCollisionManager(MatchConfig config)
 {
     PlayerCollisions = new List <HitboxCollision> [config.PlayerCount];
     for (var i = 0; i < PlayerCollisions.Length; i++)
     {
         PlayerCollisions[i] = new List <HitboxCollision>();
     }
 }
コード例 #8
0
ファイル: Match.cs プロジェクト: samuribe/FantasyCrescendo
 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);
     }
 }
コード例 #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;
     }
 }
コード例 #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);
        }
コード例 #11
0
ファイル: Match.cs プロジェクト: JoshHux/FantasyCrescendoECS
        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();
        }
コード例 #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));
        }
コード例 #13
0
ファイル: Match.cs プロジェクト: Etrius01/FantasyCrescendo
        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;
            }
コード例 #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);
        }
コード例 #15
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]));
            }
            return(Task.WhenAll(tasks));
        }
コード例 #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);
 }
コード例 #17
0
ファイル: Match.cs プロジェクト: samuribe/FantasyCrescendo
        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);
        }
コード例 #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));
        }
コード例 #19
0
ファイル: Match.cs プロジェクト: JoshHux/FantasyCrescendoECS
        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);
        }
コード例 #20
0
        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);
        }
コード例 #21
0
 public MatchController(MatchConfig config)
 {
     inputContext = new MatchInputContext(new MatchInput(config));
 }
コード例 #22
0
 protected override IEnumerable <IMatchRule> CreateRules(MatchConfig config)
 {
     yield return(new TrainingMatchRule());
 }
コード例 #23
0
 protected override void OnCreate()
 {
     _data = MatchConfig.CreateNativePlayerBuffer <PlayerUIData>();
 }
コード例 #24
0
 // TODO(james71323): Refactor or move this to somewhere more sane
 protected virtual IMatchController CreateMatchController(MatchConfig config)
 {
     return(new MatchController(config));
 }
コード例 #25
0
 protected abstract Task InitializeMatch(MatchManager manager, MatchConfig config);
コード例 #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;
 }
コード例 #27
0
 protected virtual IEnumerable <IMatchRule> CreateRules(MatchConfig config)
 {
     return(MatchRuleFactory.CreateRules(config));
 }
コード例 #28
0
 public ReplayReader(MatchConfig config, BinaryReader reader)
 {
     _config = config;
     _reader = reader;
 }
コード例 #29
0
 public Task Initialize(MatchConfig config)
 {
     MatchConfig = config;
     BlastZone   = Object.FindObjectOfType <BlastZone>();
     return(Task.WhenAll(Rules.Select(rule => rule.Initialize(config))));
 }
コード例 #30
0
 public Task Initialize(MatchConfig config)
 {
     return(Task.WhenAll(SimulationComponents.Select(comp => comp.Initialize(config))));
 }