コード例 #1
0
ファイル: Scene3D.cs プロジェクト: nashmit/OpenSAGE
        internal Scene3D(Game game, MapFile mapFile, int randomSeed)
            : this(game, () => game.Viewport, game.InputMessageBuffer, randomSeed, false)
        {
            var contentManager = game.ContentManager;

            _players = Player.FromMapData(mapFile.SidesList.Players, game.AssetStore).ToList();

            // TODO: This is completely wrong.
            LocalPlayer = _players.FirstOrDefault();

            _teams = (mapFile.SidesList.Teams ?? mapFile.Teams.Items)
                     .Select(team => Team.FromMapData(team, _players))
                     .ToList();

            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);

            Audio            = game.Audio;
            AssetLoadContext = game.AssetStore.LoadContext;

            Lighting = new WorldLighting(
                mapFile.GlobalLighting.LightingConfigurations.ToLightSettingsDictionary(),
                mapFile.GlobalLighting.Time);

            LoadObjects(
                game.AssetStore.LoadContext,
                game.CivilianPlayer,
                Terrain.HeightMap,
                mapFile.ObjectsList.Objects,
                MapFile.NamedCameras,
                _teams,
                out var waypoints,
                out var gameObjects,
                out var roads,
                out var bridges,
                out var cameras);

            Roads       = roads;
            Bridges     = bridges;
            GameObjects = gameObjects;
            Waypoints   = waypoints;
            Cameras     = cameras;

            PlayerScripts = mapFile
                            .GetPlayerScriptsList()
                            .ScriptLists
                            .Select(s => new MapScriptCollection(s))
                            .ToArray();

            CameraController = new RtsCameraController(game.AssetStore.GameData.Current)
            {
                TerrainPosition = Terrain.HeightMap.GetPosition(
                    Terrain.HeightMap.Width / 2,
                    Terrain.HeightMap.Height / 2)
            };

            contentManager.GraphicsDevice.WaitForIdle();
        }
コード例 #2
0
ファイル: Scene3D.cs プロジェクト: MetaIdea/OpenSAGE
        internal Scene3D(
            Game game,
            InputMessageBuffer inputMessageBuffer,
            Func <Viewport> getViewport,
            ICameraController cameraController,
            WorldLighting lighting,
            int randomSeed,
            bool isDiagnosticScene = false)
            : this(game, getViewport, inputMessageBuffer, randomSeed, isDiagnosticScene, null, null)
        {
            _players = new List <Player>();
            _teams   = new List <Team>();

            // TODO: This is completely wrong.
            LocalPlayer = _players.FirstOrDefault();

            WaterAreas = AddDisposable(new WaterAreaCollection());
            Lighting   = lighting;

            Roads     = AddDisposable(new RoadCollection());
            Bridges   = Array.Empty <Bridge>();
            Waypoints = new WaypointCollection();
            Cameras   = new CameraCollection();

            CameraController = cameraController;
        }
コード例 #3
0
ファイル: Scene3D.cs プロジェクト: VectorIV/OpenSAGE
        internal Scene3D(Game game, MapFile mapFile)
            : this(game, () => game.Viewport, game.InputMessageBuffer, false)
        {
            var contentManager = game.ContentManager;

            _players = Player.FromMapData(mapFile.SidesList.Players, game.AssetStore).ToList();

            // TODO: This is completely wrong.
            LocalPlayer = _players.FirstOrDefault();

            _teams = (mapFile.SidesList.Teams ?? mapFile.Teams.Items)
                     .Select(team => Team.FromMapData(team, _players))
                     .ToList();

            MapFile    = mapFile;
            Terrain    = AddDisposable(new Terrain.Terrain(mapFile, game.AssetStore.LoadContext));
            WaterAreas = AddDisposable(new WaterAreaCollection(mapFile.PolygonTriggers, mapFile.StandingWaterAreas, mapFile.StandingWaveAreas, game.AssetStore.LoadContext));

            Lighting = new WorldLighting(
                mapFile.GlobalLighting.LightingConfigurations.ToLightSettingsDictionary(),
                mapFile.GlobalLighting.Time);

            LoadObjects(
                game.AssetStore.LoadContext,
                game.CivilianPlayer,
                Terrain.HeightMap,
                mapFile.ObjectsList.Objects,
                MapFile.NamedCameras,
                _teams,
                out var waypoints,
                out var gameObjects,
                out var roads,
                out var bridges,
                out var cameras);

            Roads         = roads;
            Bridges       = bridges;
            GameObjects   = gameObjects;
            Waypoints     = waypoints;
            WaypointPaths = new WaypointPathCollection(waypoints, mapFile.WaypointsList.WaypointPaths);
            Cameras       = cameras;

            // TODO: Don't hardcode this.
            // Perhaps add one ScriptComponent for the neutral player,
            // and one for the active player.
            var scriptList = mapFile.GetPlayerScriptsList().ScriptLists[0];

            Scripts = new MapScriptCollection(scriptList);

            CameraController = new RtsCameraController(game.AssetStore.GameData.Current)
            {
                TerrainPosition = Terrain.HeightMap.GetPosition(
                    Terrain.HeightMap.Width / 2,
                    Terrain.HeightMap.Height / 2)
            };

            contentManager.GraphicsDevice.WaitForIdle();
        }
コード例 #4
0
        public Scene3D(
            Game game,
            InputMessageBuffer inputMessageBuffer,
            Func <Viewport> getViewport,
            ICameraController cameraController,
            MapFile mapFile,
            Terrain.Terrain terrain,
            Terrain.WaterArea[] waterAreas,
            Terrain.Road[] roads,
            Terrain.Bridge[] bridges,
            MapScriptCollection scripts,
            GameObjectCollection gameObjects,
            WaypointCollection waypoints,
            WaypointPathCollection waypointPaths,
            WorldLighting lighting,
            Player[] players,
            Team[] teams,
            bool isDiagnosticScene = false)
        {
            Camera           = new Camera(getViewport);
            CameraController = cameraController;

            MapFile       = mapFile;
            Terrain       = terrain;
            WaterAreas    = waterAreas;
            Roads         = roads;
            Bridges       = bridges;
            Scripts       = scripts;
            GameObjects   = AddDisposable(gameObjects);
            Waypoints     = waypoints;
            WaypointPaths = waypointPaths;
            Lighting      = lighting;

            SelectionGui = new SelectionGui();

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

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

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

            _particleSystemManager = AddDisposable(new ParticleSystemManager(this));

            _players = players.ToList();
            _teams   = teams.ToList();
            // TODO: This is completely wrong.
            LocalPlayer = _players.FirstOrDefault();
        }
コード例 #5
0
ファイル: Scene3D.cs プロジェクト: josh-fisher/OpenSAGE
        public Scene3D(
            Game game,
            ICameraController cameraController,
            MapFile mapFile,
            Terrain.Terrain terrain,
            Terrain.WaterArea[] waterAreas,
            Terrain.Road[] roads,
            Terrain.Bridge[] bridges,
            MapScriptCollection scripts,
            GameObjectCollection gameObjects,
            WaypointCollection waypoints,
            WaypointPathCollection waypointPaths,
            WorldLighting lighting,
            Player[] players,
            Team[] teams)
        {
            Camera           = new Camera(() => game.Viewport);
            CameraController = cameraController;

            MapFile       = mapFile;
            Terrain       = terrain;
            WaterAreas    = waterAreas;
            Roads         = roads;
            Bridges       = bridges;
            Scripts       = scripts;
            GameObjects   = AddDisposable(gameObjects);
            Waypoints     = waypoints;
            WaypointPaths = waypointPaths;
            Lighting      = lighting;

            SelectionGui             = new SelectionGui();
            _selectionMessageHandler = new SelectionMessageHandler(game.Selection);
            game.InputMessageBuffer.Handlers.Add(_selectionMessageHandler);
            AddDisposeAction(() => game.InputMessageBuffer.Handlers.Remove(_selectionMessageHandler));

            _cameraInputMessageHandler = new CameraInputMessageHandler();
            game.InputMessageBuffer.Handlers.Add(_cameraInputMessageHandler);
            AddDisposeAction(() => game.InputMessageBuffer.Handlers.Remove(_cameraInputMessageHandler));

            DebugOverlay         = new DebugOverlay(this, game.ContentManager);
            _debugMessageHandler = new DebugMessageHandler(DebugOverlay);
            game.InputMessageBuffer.Handlers.Add(_debugMessageHandler);
            AddDisposeAction(() => game.InputMessageBuffer.Handlers.Remove(_debugMessageHandler));

            _particleSystemManager = AddDisposable(new ParticleSystemManager(game, this));

            _players = players.ToList();
            _teams   = teams.ToList();
            // TODO: This is completely wrong.
            LocalPlayer = _players.FirstOrDefault();
        }
コード例 #6
0
        internal Scene3D(Game game, MapFile mapFile, string mapPath, int randomSeed)
            : this(game, () => game.Viewport, game.InputMessageBuffer, randomSeed, false, mapFile, mapPath)
        {
            var contentManager = game.ContentManager;

            _players = Player.FromMapData(mapFile.SidesList.Players, game.AssetStore).ToList();

            LocalPlayer = _players.First();

            _teams = (mapFile.SidesList.Teams ?? mapFile.Teams.Items)
                     .Select(team => Team.FromMapData(team, _players))
                     .ToList();

            Audio            = game.Audio;
            AssetLoadContext = game.AssetStore.LoadContext;

            Lighting = new WorldLighting(
                mapFile.GlobalLighting.LightingConfigurations.ToLightSettingsDictionary(),
                mapFile.GlobalLighting.Time);

            LoadObjects(
                game.AssetStore.LoadContext,
                Terrain.HeightMap,
                mapFile.ObjectsList.Objects,
                MapFile.NamedCameras,
                _teams,
                out var waypoints,
                out var roads,
                out var bridges,
                out var cameras);

            Roads     = roads;
            Bridges   = bridges;
            Waypoints = waypoints;
            Cameras   = cameras;

            PlayerScripts = mapFile
                            .GetPlayerScriptsList()
                            .ScriptLists;

            CameraController = new RtsCameraController(game.AssetStore.GameData.Current, Camera, Terrain.HeightMap)
            {
                TerrainPosition = Terrain.HeightMap.GetPosition(
                    Terrain.HeightMap.Width / 2,
                    Terrain.HeightMap.Height / 2)
            };

            contentManager.GraphicsDevice.WaitForIdle();
        }
コード例 #7
0
        public void SetPlayers(IEnumerable <Player> players, Player localPlayer)
        {
            _players = players.ToList();

            if (!_players.Contains(localPlayer))
            {
                throw new ArgumentException(
                          $"Argument {nameof(localPlayer)} should be included in {nameof(players)}",
                          nameof(localPlayer));
            }

            LocalPlayer = localPlayer;

            // TODO: What to do with teams?
            // Teams refer to old Players and therefore they will not be collected by GC
            // (+ objects will have invalid owners)
        }
コード例 #8
0
        public Scene3D(
            Game game,
            ICameraController cameraController,
            MapFile mapFile,
            Terrain.Terrain terrain,
            MapScriptCollection scripts,
            GameObjectCollection gameObjects,
            WaypointCollection waypoints,
            WaypointPathCollection waypointPaths,
            WorldLighting lighting,
            Player[] players,
            Team[] teams)
        {
            Camera           = new CameraComponent(game);
            CameraController = cameraController;

            MapFile       = mapFile;
            Terrain       = terrain;
            Scripts       = scripts;
            GameObjects   = AddDisposable(gameObjects);
            Waypoints     = waypoints;
            WaypointPaths = waypointPaths;
            Lighting      = lighting;

            SelectionGui             = new SelectionGui();
            _selectionMessageHandler = new SelectionMessageHandler(game.Selection);
            game.InputMessageBuffer.Handlers.Add(_selectionMessageHandler);
            AddDisposeAction(() => game.InputMessageBuffer.Handlers.Remove(_selectionMessageHandler));

            _cameraInputMessageHandler = new CameraInputMessageHandler();
            game.InputMessageBuffer.Handlers.Add(_cameraInputMessageHandler);
            AddDisposeAction(() => game.InputMessageBuffer.Handlers.Remove(_cameraInputMessageHandler));

            _particleSystemManager = AddDisposable(new ParticleSystemManager(game, this));

            _players = players.ToList();
            _teams   = teams.ToList();
            // TODO: This is completely wrong.
            LocalPlayer = _players.FirstOrDefault();
        }
コード例 #9
0
ファイル: Scene3D.cs プロジェクト: SobolevWladimir/OpenSAGE
        public void SetSkirmishPlayers(IEnumerable <Player> players, Player localPlayer)
        {
            _players = players.ToList();

            if (!_players.Contains(localPlayer))
            {
                throw new ArgumentException(
                          $"Argument {nameof(localPlayer)} should be included in {nameof(players)}",
                          nameof(localPlayer));
            }

            LocalPlayer = localPlayer;

            if (LocalPlayer.SelectedUnits.Count > 0)
            {
                var mainUnit = LocalPlayer.SelectedUnits.First();
                CameraController.GoToObject(mainUnit);
            }

            // TODO: What to do with teams?
            // Teams refer to old Players and therefore they will not be collected by GC
            // (+ objects will have invalid owners)
        }
コード例 #10
0
ファイル: Scene3D.cs プロジェクト: MetaIdea/OpenSAGE
 // TODO: Move this over to a player collection?
 public int GetPlayerIndex(Player player)
 {
     return(_players.IndexOf(player));
 }
コード例 #11
0
 // TODO: Move this over to a player collection?
 public int GetPlayerIndex(Player player) => PlayerManager.GetPlayerIndex(player);
コード例 #12
0
ファイル: Scene3D.cs プロジェクト: hcll123456/OpenSAGE
        private void LoadObjects(
            AssetLoadContext loadContext,
            Player civilianPlayer,
            HeightMap heightMap,
            MapObject[] mapObjects,
            List <Team> teams,
            out WaypointCollection waypointCollection,
            out GameObjectCollection gameObjects,
            out RoadCollection roads,
            out Bridge[] bridges)
        {
            var waypoints = new List <Waypoint>();

            gameObjects = AddDisposable(new GameObjectCollection(loadContext, civilianPlayer));
            var roadsList   = new List <Road>();
            var bridgesList = new List <Bridge>();

            var roadTopology = new RoadTopology();

            for (var i = 0; i < mapObjects.Length; i++)
            {
                var mapObject = mapObjects[i];

                var position = mapObject.Position;

                switch (mapObject.RoadType & RoadType.PrimaryType)
                {
                case RoadType.None:
                    switch (mapObject.TypeName)
                    {
                    case "*Waypoints/Waypoint":
                        waypoints.Add(new Waypoint(mapObject));
                        break;

                    default:
                        position.Z += heightMap.GetHeight(position.X, position.Y);

                        var gameObject = GameObject.FromMapObject(mapObject, teams, loadContext.AssetStore, gameObjects, position);
                        if (gameObject != null)
                        {
                            gameObjects.Add(gameObject);
                        }

                        break;
                    }
                    break;

                case RoadType.BridgeStart:
                case RoadType.BridgeEnd:
                    // Multiple invalid bridges can be found in e.g GLA01.
                    if ((i + 1) >= mapObjects.Length || !mapObjects[i + 1].RoadType.HasFlag(RoadType.BridgeEnd))
                    {
                        Logger.Warn($"Invalid bridge: {mapObject.ToString()}, skipping...");
                        continue;
                    }

                    var bridgeEnd = mapObjects[++i];

                    bridgesList.Add(AddDisposable(new Bridge(
                                                      loadContext,
                                                      heightMap,
                                                      mapObject,
                                                      mapObject.Position,
                                                      bridgeEnd.Position,
                                                      gameObjects)));

                    break;

                case RoadType.Start:
                case RoadType.End:
                    var roadEnd = mapObjects[++i];

                    // Some maps have roads with invalid start- or endpoints.
                    // We'll skip processing them altogether.
                    if (mapObject.TypeName == "" || roadEnd.TypeName == "")
                    {
                        Logger.Warn($"Road {mapObject.ToString()} has invalid start- or endpoint, skipping...");
                        continue;
                    }

                    if (!mapObject.RoadType.HasFlag(RoadType.Start) || !roadEnd.RoadType.HasFlag(RoadType.End))
                    {
                        throw new InvalidDataException();
                    }

                    // Note that we're searching with the type of either end.
                    // This is because of weirdly corrupted roads with unmatched ends in USA04, which work fine in WB and SAGE.
                    var roadTemplate =
                        loadContext.AssetStore.RoadTemplates.GetByName(mapObject.TypeName)
                        ?? loadContext.AssetStore.RoadTemplates.GetByName(roadEnd.TypeName);

                    if (roadTemplate == null)
                    {
                        throw new InvalidDataException($"Missing road template: {mapObject.TypeName}");
                    }

                    roadTopology.AddSegment(roadTemplate, mapObject, roadEnd);
                    break;
                }

                loadContext.GraphicsDevice.WaitForIdle();
            }

            roads = AddDisposable(new RoadCollection(roadTopology, loadContext, heightMap));
            waypointCollection = new WaypointCollection(waypoints);
            bridges            = bridgesList.ToArray();
        }