예제 #1
0
        private void LoadMap(MapFactory factory, string mapPath, IMaterialFactory materialFactory)
        {
            var watch = new Stopwatch();

            watch.Start();

            var imap = factory.Load(mapPath);

            if (imap is not H2vMap map)
            {
                throw new Exception("Engine only supports Halo 2 Vista maps currently");
            }

            map.UseMaterialFactory(materialFactory);

            var scene = new Scene(map, new EntityCreator(map));

            scene.Load();

            watch.Stop();
            Console.WriteLine($"Loading map took {watch.ElapsedMilliseconds / 1000f} seconds");

            var player = new Player(true);

            player.FriendlyName          = "player_0";
            player.Transform.Position    = map.Scenario.PlayerSpawnMarkers[0].Position + new Vector3(0, 0, 0.3f);
            player.Transform.Orientation = Quaternion.CreateFromAxisAngle(EngineGlobals.Up, map.Scenario.PlayerSpawnMarkers[0].Heading);
            player.Transform.UpdateDerivedData();
            scene.AddEntity(player);


            foreach (var squad in map.Scenario.AiSquadDefinitions)
            {
                foreach (var start in squad.StartingLocations)
                {
                    var entity = ActorFactory.SpawnPointFromStartingLocation(map, start);

                    if (entity != null)
                    {
                        scene.AddEntity(entity);
                    }
                }
            }

            world.LoadScene(scene);

            var timestamp = DateTime.Now.ToString("yy-MM-ddTHH-mm");
            var sinkPath  = Path.Combine(Environment.CurrentDirectory, "diagnostics", $"{timestamp}-metrics.csv");

            Directory.CreateDirectory(Path.GetDirectoryName(sinkPath));
            var sink = new FlatFileMetricSink(sinkPath);

            scene.UseMetricSink(sink);
            sink.Start();
        }