Ketchup Engine
|
For our game to handle many objects with many Model, Texture, Shader, Image, and SpriteFont assets, we need to be able to load them from storage. Ketchup handles this by loading assets according to the behavior we define in EngineSettings::LoadResources. To make Ketchup load assets when the game starts, we use the Load methods provided in the ModelManager, TextureManager, ShaderManager, ImageManager, and FontManager.
Each of these managers can load assets, but also allow us to query them for a pointer to the asset throughout runtime. This allows us to re-use assets without duplicating them in memory, and handles cleanup automatically at the end of the game.
Each manager will associate a loaded or created asset with a MapKey, which is a std::string. In order to access a loaded asset, we call the manager's Get(), passing the MapKey as a parameter. We'll do this later when we create a GameObject.
We can load and create textures by either loading a .tga file, or by specifying a color, which the TextureManager will use to create a single-color Texture.
TextureManager::Load("grid", "Textures/grid.tga"); TextureManager::Load("red", 255, 0, 0);
We can load and create models by either loading a .azul file, or by specifying a Model::PreMadeModels, which the ModelManager will generate.
ModelManager::Load("plane", "Models/Plane.azul"); ModelManager::Load("unit_sphere", Model::PreMadeModels::UnitSphere);
We can load and create shaders by loading them from a path from /Assets/Shaders.
ShaderManager::Load("textureFlat", "textureFlatRender");
Images are defined by a Texture and a Rect defining the starting position in the Texture and the Image's width and height. We can also use the whole Texture.
ImageManager::Load(glyphName, p_tex, x, y, w, h); ImageManager::Load("reticle", TextureManager::Get("reticle"));
Fonts are loaded by the name of the .tga and .xml files associated with the font in /Assets/Fonts without file extensions.
FontManager::Load("Myanmar10", "Myanmar10");
Some assets are always loaded because they are used in engine tools.
Asset Type | MapKey | Asset |
---|---|---|
Model | ModelManager::spriteKey | Model::PreMadeModels::UnitSquareXY |
Model | ModelManager::unitBoxKey | Models/unit_box.azul |
Model | ModelManager::unitSphereKey | Model::PreMadeModels::UnitSphere |
Shader | ShaderManager::spriteKey | "spriteRender" |
Shader | ShaderManager::colorConstantKey | "colorConstantRender" |
For now, we can just load the five assets we'll need for the next tutorial.
#include "ShaderManager.h" #include "TextureManager.h" #include "ModelManager.h" void TutorialGameSettings::LoadResources() { ModelManager::Load("axis", "Models/Axis.azul"); ModelManager::Load("plane", "Models/Plane.azul"); ShaderManager::Load("textureFlat", "textureFlatRender"); ShaderManager::Load("colorNoTexture", "colorNoTextureRender"); TextureManager::Load("grid", "Textures/grid.tga"); }