Component Based Design (C++)
Posted: Tue Feb 08, 2011 6:39 pm
So I've been racking my brain around figuring out a decent way to design a base game engine. The thing has to be able to deal with images, sounds, physics, and map loading/rendering. I'm using SFML, if that interests anyone.
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:
Basically, a module deals with all of the update events that could happen in SFML. A DrawObj is used to display sprites, which use sf::Images. Passing an integer value - the value returned when the Render System loads an image - attaches that image from the Render System to the DrawObj's sprite. I'm just wondering if this would be a good way to do things for the user of the engine. I kind of like it, because it's the way another language, Turing, did things.
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 .
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 .