I am trying my hand at my first entity-component system after a newfound love for the concept reading the recent GameDev article (because the other articles I've read on the subject didn't do a good enough job to make things clear as an intro to it). It's pretty clear to me right now how an aggregate of components can define an object's behavior. But as they are mostly data containers, I assume it should be a system's responsibility to load the data from the file system, correct? Should it be the same system that acts upon the component on every update?
For instance, if I have a Sprite component that holds a texture for the sprite, and I want to load this when I need the sprite, I picture having a GraphicsSystem with a Load function to prepare the appropriate Entities it needs to work on.
Some pseudocode would go as such:
// Main game code
GraphicsSystem graphics;
LoadGameContents()
{
GameObject objectWithSprite = new GameObject();
objectWithSprite.AddComponent("SpriteComponent");
objectWithSprite.Component("SpriteComponent").textureName = "texture.png";
graphics.LoadAndRegister(objectWithSprite);
}
// In SpriteComponent
String textureName;
Texture spriteTexture;
// In GraphicsSystem
List<GameObject> graphicsObjects;
LoadAndRegister(GameObject object)
{
if (object.HasComponent("SpriteComponent")
{
Texture spriteTexture = LoadTextureFromDisk(object.Component("SpriteComponent").textureName);
object.Component("SpriteComponent").SetTexture(spriteTexture);
graphicsObjects.Add(object);
}
}
So in this example the graphicsSystem takes care of the loading, which would be called only when the game or a game state is initialized. The same graphicsSystem would also draw the sprites from its list of GameObjects to the screen in a different function. The texture data is stored in the SpriteComponent.
Is this a common way to store and load assets in a game using Entity Components? I've just seen the Entity Systems being talked about as they are used in the update loop but I was wondering about their use during initialization.