Beispiel #1
0
        private Scene3D(Game game, Func <Viewport> getViewport, InputMessageBuffer inputMessageBuffer, int randomSeed, bool isDiagnosticScene, MapFile mapFile, string mapPath)
        {
            Game = game;

            Camera = new Camera(getViewport);

            SelectionGui = new SelectionGui();

            DebugOverlay = new DebugOverlay(this, game.ContentManager);

            Random = new Random(randomSeed);

            if (mapFile != null)
            {
                MapFile    = mapFile;
                Terrain    = AddDisposable(new Terrain.Terrain(mapFile, game.AssetStore.LoadContext));
                WaterAreas = AddDisposable(new WaterAreaCollection(mapFile.PolygonTriggers, mapFile.StandingWaterAreas, mapFile.StandingWaveAreas, game.AssetStore.LoadContext));
                Navigation = new Navigation.Navigation(mapFile.BlendTileData, Terrain.HeightMap);
            }

            if (mapPath != null)
            {
                var mapCache = game.AssetStore.MapCaches.GetByName(mapPath.ToLower());
                if (mapCache == null)
                {
                    mapCache = game.AssetStore.MapCaches.GetByName(Path.Combine(game.UserDataFolder, mapPath).ToLower());
                }
                if (mapCache == null)
                {
                    throw new Exception($"Failed to load MapCache \"{mapPath}\"");
                }
                MapCache = mapCache;
            }

            RegisterInputHandler(_cameraInputMessageHandler = new CameraInputMessageHandler(), inputMessageBuffer);

            if (!isDiagnosticScene)
            {
                RegisterInputHandler(new SelectionMessageHandler(game.Selection), inputMessageBuffer);
                RegisterInputHandler(_orderGeneratorInputHandler = new OrderGeneratorInputHandler(game.OrderGenerator), inputMessageBuffer);
                RegisterInputHandler(_debugMessageHandler        = new DebugMessageHandler(DebugOverlay), inputMessageBuffer);
            }

            _particleSystemManager = AddDisposable(new ParticleSystemManager(game.AssetStore.LoadContext));

            Radar = new Radar(this, game.AssetStore, MapCache);

            GameContext = new GameContext(
                game.AssetStore.LoadContext,
                game.Audio,
                _particleSystemManager,
                new ObjectCreationListManager(),
                Terrain,
                Navigation,
                Radar,
                this);

            GameObjects = AddDisposable(
                new GameObjectCollection(
                    GameContext,
                    game.CivilianPlayer,
                    Navigation));

            GameContext.GameObjects = GameObjects;

            _orderGeneratorSystem = game.OrderGenerator;
        }
Beispiel #2
0
        private Scene3D(Game game, Func <Viewport> getViewport, InputMessageBuffer inputMessageBuffer, int randomSeed, bool isDiagnosticScene, MapFile mapFile, string mapPath)
        {
            Game = game;

            Camera = new Camera(getViewport);

            SelectionGui = new SelectionGui();

            DebugOverlay = new DebugOverlay(this, game.ContentManager);

            Random = new Random(randomSeed);

            if (mapFile != null)
            {
                MapFile    = mapFile;
                Terrain    = AddDisposable(new Terrain.Terrain(mapFile, game.AssetStore.LoadContext));
                WaterAreas = AddDisposable(new WaterAreaCollection(mapFile.PolygonTriggers, mapFile.StandingWaterAreas, mapFile.StandingWaveAreas, game.AssetStore.LoadContext));
                Navigation = new Navigation.Navigation(mapFile.BlendTileData, Terrain.HeightMap);
            }

            RegisterInputHandler(_cameraInputMessageHandler = new CameraInputMessageHandler(), inputMessageBuffer);

            if (!isDiagnosticScene)
            {
                RegisterInputHandler(new SelectionMessageHandler(game.Selection), inputMessageBuffer);
                RegisterInputHandler(_orderGeneratorInputHandler = new OrderGeneratorInputHandler(game.OrderGenerator), inputMessageBuffer);
                RegisterInputHandler(_debugMessageHandler        = new DebugMessageHandler(DebugOverlay), inputMessageBuffer);
            }

            ParticleSystemManager = AddDisposable(new ParticleSystemManager(game.AssetStore.LoadContext));

            Radar = new Radar(this, game.AssetStore, mapPath);

            if (mapFile != null)
            {
                var borderWidth = mapFile.HeightMapData.BorderWidth * HeightMap.HorizontalScale;
                var width       = mapFile.HeightMapData.Width * HeightMap.HorizontalScale;
                var height      = mapFile.HeightMapData.Height * HeightMap.HorizontalScale;
                Quadtree = new Quadtree <GameObject>(new RectangleF(-borderWidth, -borderWidth, width, height));
            }

            GameContext = new GameContext(
                game.AssetStore.LoadContext,
                game.Audio,
                ParticleSystemManager,
                new ObjectCreationListManager(),
                Terrain,
                Navigation,
                Radar,
                Quadtree,
                this);

            Game.GameLogic.Reset();
            Game.GameClient.Reset();

            GameObjects = AddDisposable(new GameObjectCollection(GameContext));

            GameContext.GameObjects = GameObjects;

            _orderGeneratorSystem = game.OrderGenerator;
        }