I'm sort of wondering what most people consider a decent way of interfacing different parts of the engine. Say the user of the engine (normally myself, but sometimes a fellow developer) wants to be able to load an image, and use it for a character. What's the best way to do something like this? The way I currently do it for the loading "sf::Image"s, is that I loaded them in the render system, and then an integer index is returned, which is then used to access the image. Using the actual image requires the use of another class, the DrawObj. This is where I kind of think I'm doing it weird. Here's a quick example of how I do it from outside of the engine:
Code: Select all
class TestModule : public Module{
public:
TestModule (int screenW, int screenH);
void OnRender();
private:
DrawObj obj;
};
TestModule::TestModule() : Module (screenW, screenH) {
// Set the draw objects properties
obj.SetX(0);
obj.SetY(0);
// Load an image, and use it as the image for the DrawObj
obj.SetImage(Render().LoadImg("image.png"));
}
void TestModule::OnRender(){
// Display the draw object
obj.Display();
}
int main(){
TestModule module (640, 480);
// Module's run loop
while (module.isRunning()){
module.Update();
}
return 0;
}
I kind of learned about the Component Based Design, but can't decide if this is even remotely correct. I like this way, but I have a pretty good feeling it'd be weird for someone else to use :/
If there's a better way or another design suggestion, that would be appreciated .