Resources management and new WaveContent class in Wave Engine 2.0

Resources management is an important part during the game development and it becomes tedious when a large amount of it is required in a project. In this article, we show the progress done with Wave Engine and how it will ease task management.

How it works in previous versions

In Wave Engine 1.4.2 and previous versions, game assets can be included to throw the Asset Exporter tool and can be accessed programmatically using the asset path.

This method has some known issues as the project grows and asset replacements are required.

  • UNIX systems are case-sensitive. You should pay attention to how you write the path.
  • When assets are moved or renamed, the asset path must be replaced in all code files manually.
  • If the asset path is invalid, an exception will be raised at runtime.
  • Every time you need an asset. You must remember the asset path or copy the relative path from Asset Exporter.

     What is new in Wave Engine 2.0

    With the inclusion of the new Wave Visual Editor and the new assets workflow, we also want to improve this method and remove the previously mentioned issues.

    The solution proposed is to auto-generate a file called WaveContent.cs that contains all asset paths as constants following directory hierarchy. This allows to directly reference assets from the IDE without switching between Wave Visual Editor and the IDE.

This also works for the scenes (*.wscene files), Materials (*.wmat files) and texture names inside sprite sheets.

How it works?

To auto-generate the WaveContent class, Wave Engine includes a command-line tool that is executed in the pre-build phase during the compilation of your project. This allows to compile the project without opening Wave Visual Editor. Also, any asset path error will be raised in compile-time.

  
<Target Name="BeforeBuild">
    …
	<Exec Command='"$(WaveEngine)v2.0ToolsVisualEditorWaveConstantsCMD.exe" -i "$(SolutionDir)$(ProjectName).weproj" -o "$(SolutionDir)SharedSourceMain"'/>
</Target>

During this generation, any invalid character inside the asset path will be replaced by another valid set of characters in order to create valid variable names.

  
public sealed class WaveContent
{
    public sealed class Assets
    {
        /// <summary> Path to Content/Assets/MyMaterial.wmat </summary>
        public const string MyMaterial = "Content/Assets/MyMaterial.wmat";
            
        public sealed class Textures
        {
            /// <summary> Path to Content/Assets/Textures/Dinosaur.png </summary>
            public const string Dinosaur_png = "Content/Assets/Textures/Dinosaur.png";
        }
    }
    
    public sealed class Scenes
    {
        /// <summary> Path to Content/Scenes/MyScene.wscene </summary>
        public const string MyScene = "Content/Scenes/MyScene.wscene";
    }
}

This command-line tool can be found at: $(WaveEngine)v2.0ToolsVisualEditorWaveConstantsCMD.exe

It only receives two arguments:

-i: path to the wave project (*.weproj)

-o: output path, where the WaveContent.cs file will be generated.

Note: If a file with the same name exists in the output path, it will be overwritten preserving only the class namespace.

We will continue revealing more WaveEngine 2.0 features in the upcomming days.

Stay tuned at @waveengineteam and waveengine.net.

Leave a Reply

Your email address will not be published. Required fields are marked *