Exemplo n.º 1
0
        public T Load <T>(
            string[] filePaths,
            LoadOptions options        = null,
            bool fallbackToPlaceholder = true)
            where T : class
        {
            for (var i = 0; i < filePaths.Length; i++)
            {
                var actuallyFallbackToPlaceholder = fallbackToPlaceholder && i == filePaths.Length - 1;

                var result = Load <T>(filePaths[i], options, actuallyFallbackToPlaceholder);
                if (result != null)
                {
                    return(result);
                }
            }

            return(null);
        }
Exemplo n.º 2
0
        protected override Model LoadEntry(FileSystemEntry entry, ContentManager contentManager, Game game, LoadOptions loadOptions)
        {
            var w3dFile = W3dFile.FromFileSystemEntry(entry);

            var w3dHierarchy = w3dFile.Hierarchy;

            if (w3dFile.HLod != null && w3dHierarchy == null)
            {
                // Load referenced hierarchy.
                var hierarchyFileName  = w3dFile.HLod.Header.HierarchyName + ".W3D";
                var hierarchyFilePath  = Path.Combine(Path.GetDirectoryName(w3dFile.FilePath), hierarchyFileName);
                var hierarchyFileEntry = contentManager.FileSystem.GetFile(hierarchyFilePath);
                var hierarchyFile      = W3dFile.FromFileSystemEntry(hierarchyFileEntry);
                w3dHierarchy = hierarchyFile.Hierarchy;
            }

            return(CreateModel(
                       contentManager,
                       w3dFile,
                       w3dHierarchy));
        }
Exemplo n.º 3
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));
        }
Exemplo n.º 4
0
        protected override AptWindow LoadEntry(FileSystemEntry entry, ContentManager contentManager, Game game, LoadOptions loadOptions)
        {
            var aptFile = AptFile.FromFileSystemEntry(entry);

            return(AddDisposable(new AptWindow(game, contentManager, aptFile)));
        }
Exemplo n.º 5
0
 public sealed override object Load(FileSystemEntry entry, ContentManager contentManager, LoadOptions loadOptions)
 {
     return(LoadEntry(entry, contentManager, loadOptions));
 }
Exemplo n.º 6
0
 protected abstract T LoadEntry(FileSystemEntry entry, ContentManager contentManager, LoadOptions loadOptions);
Exemplo n.º 7
0
        protected override Texture LoadEntry(FileSystemEntry entry, ContentManager contentManager, Game game, LoadOptions loadOptions)
        {
            var generateMipMaps = (loadOptions as TextureLoadOptions)?.GenerateMipMaps ?? true;

            Texture applyDebugName(Texture texture)
            {
                texture.Name = entry.FilePath;
                return(texture);
            }

            switch (Path.GetExtension(entry.FilePath).ToLower())
            {
            case ".dds":
                if (!DdsFile.IsDdsFile(entry))
                {
                    goto case ".tga";
                }
                var ddsFile = DdsFile.FromFileSystemEntry(entry);
                return(applyDebugName(CreateTextureFromDds(
                                          contentManager.GraphicsDevice,
                                          ddsFile)));

            case ".tga":
                var tgaFile = TgaFile.FromFileSystemEntry(entry);
                return(applyDebugName(CreateTextureFromTga(
                                          contentManager.GraphicsDevice,
                                          tgaFile,
                                          generateMipMaps)));

            default:
                throw new InvalidOperationException();
            }
        }
Exemplo n.º 8
0
        protected override ShapeComponent LoadEntry(FileSystemEntry entry, ContentManager contentManager, LoadOptions loadOptions)
        {
            //load the corresponding .dat file
            var movieName = entry.FilePath.Split('/')[0].Split('_')[0];
            var datPath   = movieName + ".dat";
            var datEntry  = contentManager.FileSystem.GetFile(datPath);
            var imageMap  = ImageMap.FromFileSystemEntry(datEntry);

            var shape = Geometry.FromFileSystemEntry(entry);

            var component = new ShapeComponent()
            {
                Shape = shape, MovieName = movieName
            };

            component.Initialize(contentManager, imageMap);

            return(component);
        }
Exemplo n.º 9
0
        protected override Window LoadEntry(FileSystemEntry entry, ContentManager contentManager, Game game, LoadOptions loadOptions)
        {
            var wndFile = WndFile.FromFileSystemEntry(entry);

            var rootControl = CreateElementRecursive(
                wndFile.RootWindow,
                contentManager,
                _wndCallbackResolver,
                wndFile.RootWindow.ScreenRect.ToRectangle().Location);

            return(new Window(wndFile.RootWindow.ScreenRect.CreationResolution, rootControl, contentManager)
            {
                LayoutInit = _wndCallbackResolver.GetWindowCallback(wndFile.LayoutBlock.LayoutInit),
                LayoutUpdate = _wndCallbackResolver.GetWindowCallback(wndFile.LayoutBlock.LayoutUpdate),
                LayoutShutdown = _wndCallbackResolver.GetWindowCallback(wndFile.LayoutBlock.LayoutShutdown)
            });
        }
Exemplo n.º 10
0
 public abstract object Load(FileSystemEntry entry, ContentManager contentManager, LoadOptions loadOptions);
Exemplo n.º 11
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));
        }
Exemplo n.º 12
0
        protected override WavFile LoadEntry(FileSystemEntry entry, ContentManager contentManager, Game game, LoadOptions loadOptions)
        {
            var wavFile = WavFile.FromFileSystemEntry(entry);

            return(wavFile);
        }
Exemplo n.º 13
0
        protected override WndTopLevelWindow LoadEntry(FileSystemEntry entry, ContentManager contentManager, Game game, LoadOptions loadOptions)
        {
            var wndFile = WndFile.FromFileSystemEntry(entry);

            var result = CreateElementRecursive(
                wndFile.RootWindow,
                contentManager,
                _wndCallbackResolver);

            var window = new WndTopLevelWindow(wndFile, result, _wndCallbackResolver);

            void setWindowRecursive(WndWindow element)
            {
                element.Window = window;

                foreach (var child in element.Children)
                {
                    setWindowRecursive(child);
                }
            }

            setWindowRecursive(result);

            return(window);
        }
Exemplo n.º 14
0
        protected override Model LoadEntry(FileSystemEntry entry, ContentManager contentManager, Game game, LoadOptions loadOptions)
        {
            W3dFile w3dFile;

            using (var entryStream = entry.Open())
            {
                w3dFile = W3dFile.FromStream(entryStream, entry.FilePath);
            }

            var w3dHLod      = w3dFile.GetHLod();
            var w3dHierarchy = w3dFile.GetHierarchy();

            if (w3dHLod != null && w3dHierarchy == null)
            {
                // Load referenced hierarchy.
                var     hierarchyFileName  = w3dHLod.Header.HierarchyName + ".W3D";
                var     hierarchyFilePath  = Path.Combine(Path.GetDirectoryName(w3dFile.FilePath), hierarchyFileName);
                var     hierarchyFileEntry = contentManager.FileSystem.GetFile(hierarchyFilePath);
                W3dFile hierarchyFile;
                using (var entryStream = hierarchyFileEntry.Open())
                {
                    hierarchyFile = W3dFile.FromStream(entryStream, hierarchyFileEntry.FilePath);
                }
                w3dHierarchy = hierarchyFile.GetHierarchy();
            }

            return(CreateModel(
                       contentManager,
                       w3dFile,
                       w3dHierarchy));
        }
Exemplo n.º 15
0
        protected override Scene LoadEntry(FileSystemEntry entry, ContentManager contentManager, LoadOptions loadOptions)
        {
            contentManager.IniDataContext.LoadIniFile(@"Data\INI\Terrain.ini");

            var mapFile = MapFile.FromFileSystemEntry(entry);

            var result = new Scene();

            result.MapFile = mapFile;

            result.Settings.LightingConfigurations = mapFile.GlobalLighting.LightingConfigurations.ToLightSettingsDictionary();
            result.Settings.TimeOfDay = mapFile.GlobalLighting.Time;

            var heightMap = new HeightMap(mapFile.HeightMapData);

            result.HeightMap = heightMap;

            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(Buffer <TextureInfo> .CreateStatic(
                                                         contentManager.GraphicsDevice,
                                                         textureDetails,
                                                         BufferBindFlags.ShaderResource));

            var terrainMaterial = new TerrainMaterial(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 terrain = new Terrain.Terrain(heightMap, terrainPatches);

            var world = new World(terrain);

            result.Scene3D = new Scene3D(world);

            var objectsEntity = new Entity();

            result.Entities.Add(objectsEntity);
            LoadObjects(
                contentManager,
                objectsEntity,
                heightMap,
                mapFile.ObjectsList.Objects,
                result.Settings);

            foreach (var team in mapFile.SidesList.Teams ?? mapFile.Teams.Items)
            {
                var name        = (string)team.Properties["teamName"].Value;
                var owner       = (string)team.Properties["teamOwner"].Value;
                var isSingleton = (bool)team.Properties["teamIsSingleton"].Value;

                // TODO
            }

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

            result.Settings.WaypointPaths = new WaypointPathCollection(waypointPaths);

            var scriptsEntity = new Entity();

            result.Entities.Add(scriptsEntity);

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

            AddScripts(scriptsEntity, scriptList, result.Settings);

            return(result);
        }