Example #1
0
        internal Scene3D(
            Game game,
            InputMessageBuffer inputMessageBuffer,
            Func <Viewport> getViewport,
            ICameraController cameraController,
            GameObjectCollection gameObjects,
            WorldLighting lighting,
            bool isDiagnosticScene = false)
            : this(game, getViewport, inputMessageBuffer, isDiagnosticScene)
        {
            _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>();
            GameObjects   = gameObjects;
            Waypoints     = new WaypointCollection();
            WaypointPaths = new WaypointPathCollection();

            CameraController = cameraController;
        }
Example #2
0
        public Scene3D(
            Game game,
            ICameraController cameraController,
            MapFile mapFile,
            Terrain.Terrain terrain,
            MapScriptCollection scripts,
            GameObjectCollection gameObjects,
            WaypointCollection waypoints,
            WaypointPathCollection waypointPaths,
            WorldLighting lighting)
        {
            Camera           = new CameraComponent(game);
            CameraController = cameraController;

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

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

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

            _players = new List <Player>();
        }
Example #3
0
        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));
            Navigation = new Navigation.Navigation(mapFile.BlendTileData, Terrain.HeightMap);

            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();
        }
Example #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();
        }
Example #5
0
        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();
        }
Example #6
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();
        }
Example #7
0
        protected override Scene3D LoadEntry(FileSystemEntry entry, ContentManager contentManager, Game game, LoadOptions loadOptions)
        {
            switch (contentManager.SageGame)
            {
            case SageGame.Ra3:
            case SageGame.Ra3Uprising:
            case SageGame.Cnc4:
                // TODO
                break;

            default:
                contentManager.IniDataContext.LoadIniFile(@"Data\INI\Terrain.ini");
                break;
            }

            var mapFile = MapFile.FromFileSystemEntry(entry);

            var heightMap = new HeightMap(mapFile.HeightMapData);

            var indexBufferCache = AddDisposable(new TerrainPatchIndexBufferCache(contentManager.GraphicsDevice));

            var tileDataTexture = AddDisposable(CreateTileDataTexture(
                                                    contentManager.GraphicsDevice,
                                                    mapFile,
                                                    heightMap));

            var cliffDetailsBuffer = AddDisposable(CreateCliffDetails(
                                                       contentManager.GraphicsDevice,
                                                       mapFile));

            CreateTextures(
                contentManager,
                mapFile.BlendTileData,
                out var textureArray,
                out var textureDetails);

            var textureDetailsBuffer = AddDisposable(contentManager.GraphicsDevice.CreateStaticStructuredBuffer(textureDetails));

            var terrainMaterial = AddDisposable(new TerrainMaterial(contentManager, contentManager.EffectLibrary.Terrain));

            terrainMaterial.SetTileData(tileDataTexture);
            terrainMaterial.SetCliffDetails(cliffDetailsBuffer);
            terrainMaterial.SetTextureDetails(textureDetailsBuffer);
            terrainMaterial.SetTextureArray(textureArray);

            var terrainPatches = CreatePatches(
                contentManager.GraphicsDevice,
                heightMap,
                mapFile.BlendTileData,
                terrainMaterial,
                indexBufferCache);

            var cloudTextureName = mapFile.EnvironmentData?.CloudTexture ?? "tscloudmed.dds";
            var cloudTexture     = contentManager.Load <Texture>(Path.Combine("Art", "Textures", cloudTextureName));

            var macroTextureName = mapFile.EnvironmentData?.MacroTexture ?? "tsnoiseurb.dds";
            var macroTexture     = contentManager.Load <Texture>(Path.Combine("Art", "Textures", macroTextureName));

            var materialConstantsBuffer = AddDisposable(contentManager.GraphicsDevice.CreateStaticBuffer(
                                                            new TerrainMaterial.TerrainMaterialConstants
            {
                MapBorderWidth          = new Vector2(mapFile.HeightMapData.BorderWidth, mapFile.HeightMapData.BorderWidth) * HeightMap.HorizontalScale,
                MapSize                 = new Vector2(mapFile.HeightMapData.Width, mapFile.HeightMapData.Height) * HeightMap.HorizontalScale,
                IsMacroTextureStretched = false     // TODO: This must be one of the EnvironmentData unknown values.
            },
                                                            BufferUsage.UniformBuffer));

            terrainMaterial.SetMaterialConstants(materialConstantsBuffer);

            var terrain = new Terrain.Terrain(
                heightMap,
                terrainPatches,
                cloudTexture,
                macroTexture,
                contentManager.SolidWhiteTexture);

            var players = Player.FromMapData(mapFile.SidesList.Players, contentManager).ToArray();

            var teams = (mapFile.SidesList.Teams ?? mapFile.Teams.Items)
                        .Select(team => Team.FromMapData(team, players))
                        .ToArray();

            LoadObjects(
                contentManager,
                heightMap,
                mapFile.ObjectsList.Objects,
                teams,
                out var waypoints,
                out var gameObjects);

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

            var waypointPaths = new WaypointPathCollection(mapFile.WaypointsList.WaypointPaths
                                                           .Select(path =>
            {
                var start = waypoints[path.StartWaypointID];
                var end   = waypoints[path.EndWaypointID];
                return(new Settings.WaypointPath(start, end));
            }));

            // 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];
            var mapScripts = CreateScripts(scriptList);

            var cameraController = new RtsCameraController(contentManager)
            {
                TerrainPosition = terrain.HeightMap.GetPosition(
                    terrain.HeightMap.Width / 2,
                    terrain.HeightMap.Height / 2)
            };

            contentManager.GraphicsDevice.WaitForIdle();

            return(new Scene3D(
                       game,
                       cameraController,
                       mapFile,
                       terrain,
                       mapScripts,
                       gameObjects,
                       waypoints,
                       waypointPaths,
                       lighting,
                       players,
                       teams));
        }
Example #8
0
        protected override Scene3D LoadEntry(FileSystemEntry entry, ContentManager contentManager, Game game, LoadOptions loadOptions)
        {
            switch (contentManager.SageGame)
            {
            case SageGame.Ra3:
            case SageGame.Ra3Uprising:
            case SageGame.Cnc4:
                // TODO
                break;

            default:
                contentManager.IniDataContext.LoadIniFile(@"Data\INI\Terrain.ini");
                contentManager.IniDataContext.LoadIniFile(@"Data\INI\Roads.ini");
                break;
            }

            var mapFile = MapFile.FromFileSystemEntry(entry);

            var heightMap = new HeightMap(mapFile.HeightMapData);

            var indexBufferCache = AddDisposable(new TerrainPatchIndexBufferCache(contentManager.GraphicsDevice));

            var tileDataTexture = AddDisposable(CreateTileDataTexture(
                                                    contentManager.GraphicsDevice,
                                                    mapFile,
                                                    heightMap));

            var cliffDetailsBuffer = AddDisposable(CreateCliffDetails(
                                                       contentManager.GraphicsDevice,
                                                       mapFile));

            CreateTextures(
                contentManager,
                mapFile.BlendTileData,
                out var textureArray,
                out var textureDetails);

            var textureDetailsBuffer = AddDisposable(contentManager.GraphicsDevice.CreateStaticStructuredBuffer(textureDetails));

            var terrainPipeline = contentManager.ShaderResources.Terrain.Pipeline;

            Texture LoadTexture(string name)
            {
                var texture = contentManager.Load <Texture>(Path.Combine("Art", "Textures", name), fallbackToPlaceholder: false);

                if (texture == null)
                {
                    texture = contentManager.Load <Texture>(Path.Combine("Art", "CompiledTextures", name.Substring(0, 2), name));
                }
                return(texture);
            }

            var materialConstantsBuffer = AddDisposable(contentManager.GraphicsDevice.CreateStaticBuffer(
                                                            new TerrainShaderResources.TerrainMaterialConstants
            {
                MapBorderWidth          = new Vector2(mapFile.HeightMapData.BorderWidth, mapFile.HeightMapData.BorderWidth) * HeightMap.HorizontalScale,
                MapSize                 = new Vector2(mapFile.HeightMapData.Width, mapFile.HeightMapData.Height) * HeightMap.HorizontalScale,
                IsMacroTextureStretched = false     // TODO: This must be one of the EnvironmentData unknown values.
            },
                                                            BufferUsage.UniformBuffer));

            var macroTexture = LoadTexture(mapFile.EnvironmentData?.MacroTexture ?? "tsnoiseurb.dds");

            var materialResourceSet = AddDisposable(contentManager.ShaderResources.Terrain.CreateMaterialResourceSet(
                                                        materialConstantsBuffer,
                                                        tileDataTexture,
                                                        cliffDetailsBuffer ?? contentManager.GetNullStructuredBuffer(TerrainShaderResources.CliffInfo.Size),
                                                        textureDetailsBuffer,
                                                        textureArray,
                                                        macroTexture));

            var terrainPatches = CreatePatches(
                contentManager.GraphicsDevice,
                heightMap,
                mapFile.BlendTileData,
                indexBufferCache,
                materialResourceSet);

            var cloudTexture = LoadTexture(mapFile.EnvironmentData?.CloudTexture ?? "tscloudmed.dds");

            cloudTexture.Name = "Cloud texture";

            var cloudResourceLayout = AddDisposable(contentManager.GraphicsDevice.ResourceFactory.CreateResourceLayout(
                                                        new ResourceLayoutDescription(
                                                            new ResourceLayoutElementDescription("Global_CloudTexture", ResourceKind.TextureReadOnly, ShaderStages.Fragment))));

            var cloudResourceSet = AddDisposable(contentManager.GraphicsDevice.ResourceFactory.CreateResourceSet(
                                                     new ResourceSetDescription(
                                                         cloudResourceLayout,
                                                         cloudTexture)));

            cloudResourceSet.Name = "Cloud resource set";

            var terrain = new Terrain.Terrain(
                heightMap,
                terrainPatches,
                contentManager.ShaderResources.Terrain.ShaderSet,
                terrainPipeline,
                cloudResourceSet);

            var players = Player.FromMapData(mapFile.SidesList.Players, contentManager).ToArray();

            var teams = (mapFile.SidesList.Teams ?? mapFile.Teams.Items)
                        .Select(team => Team.FromMapData(team, players))
                        .ToArray();

            LoadObjects(
                contentManager,
                heightMap,
                mapFile.ObjectsList.Objects,
                teams,
                out var waypoints,
                out var gameObjects,
                out var roads,
                out var bridges);

            var waterAreas = new List <WaterArea>();

            if (mapFile.PolygonTriggers != null)
            {
                foreach (var polygonTrigger in mapFile.PolygonTriggers.Triggers)
                {
                    switch (polygonTrigger.TriggerType)
                    {
                    case PolygonTriggerType.Water:
                    case PolygonTriggerType.River:     // TODO: Handle this differently. Water texture should be animated "downstream".
                    case PolygonTriggerType.WaterAndRiver:
                        if (WaterArea.TryCreate(contentManager, polygonTrigger, out var waterArea))
                        {
                            waterAreas.Add(AddDisposable(waterArea));
                        }
                        break;
                    }
                }
            }

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

            var waypointPaths = new WaypointPathCollection(mapFile.WaypointsList.WaypointPaths
                                                           .Select(path =>
            {
                var start = waypoints[path.StartWaypointID];
                var end   = waypoints[path.EndWaypointID];
                return(new Settings.WaypointPath(start, end));
            }));

            // 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];
            var mapScripts = CreateScripts(scriptList);

            var cameraController = new RtsCameraController(contentManager)
            {
                TerrainPosition = terrain.HeightMap.GetPosition(
                    terrain.HeightMap.Width / 2,
                    terrain.HeightMap.Height / 2)
            };

            contentManager.GraphicsDevice.WaitForIdle();

            return(new Scene3D(
                       game,
                       game.InputMessageBuffer,
                       () => game.Viewport,
                       cameraController,
                       mapFile,
                       terrain,
                       waterAreas.ToArray(),
                       roads,
                       bridges,
                       mapScripts,
                       gameObjects,
                       waypoints,
                       waypointPaths,
                       lighting,
                       players,
                       teams));
        }