protected override void SampleInputs() { var inputs = MatchConfig.CreateNativePlayerBuffer <PlayerInput>(Allocator.Temp); _reader.ReadInputs(new NativeSlice <PlayerInput>(inputs, 0, Config.PlayerCount)); InjectInputs(inputs); }
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."); }
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. }
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>(); } }
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); } }
/// <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; } }
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); }
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(); }
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)); }
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; }
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)); }
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); }
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); }
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)); }
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); }
public MatchController(MatchConfig config) { inputContext = new MatchInputContext(new MatchInput(config)); }
protected override IEnumerable <IMatchRule> CreateRules(MatchConfig config) { yield return(new TrainingMatchRule()); }
protected override void OnCreate() { _data = MatchConfig.CreateNativePlayerBuffer <PlayerUIData>(); }
// TODO(james71323): Refactor or move this to somewhere more sane protected virtual IMatchController CreateMatchController(MatchConfig config) { return(new MatchController(config)); }
protected abstract Task InitializeMatch(MatchManager manager, MatchConfig config);
/// <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; }
protected virtual IEnumerable <IMatchRule> CreateRules(MatchConfig config) { return(MatchRuleFactory.CreateRules(config)); }
public ReplayReader(MatchConfig config, BinaryReader reader) { _config = config; _reader = reader; }
public Task Initialize(MatchConfig config) { MatchConfig = config; BlastZone = Object.FindObjectOfType <BlastZone>(); return(Task.WhenAll(Rules.Select(rule => rule.Initialize(config)))); }
public Task Initialize(MatchConfig config) { return(Task.WhenAll(SimulationComponents.Select(comp => comp.Initialize(config)))); }