Sign in to follow this  

Component communication and placement

Recommended Posts

I'm in the process of designing my own little engine (like everyone else lol) and this time I'm getting a design document done first so I can clearly see what I'm doing. My current plan is to have a component based engine with a kernel, tasks etc. I currently have main classes such as:
Window ~ Create a window and contains the winproc.
Renderer ~ Initializes and shutsdown OpenGL, draws blocks of objects from the Geometry class.
ResourceManager ~ Loads, unloads, returns/stores resources.
Kernel ~ Manages tasks etc.
Task ~ Task class for Kernel
Now I'm wondering where I actually declare this classes. Currently my plan is to have the major components (Window, Renderer, Kernel etc.) all as members of an overall 'System' class. Is this how its commonly done? How else is it done? Now I obviously need a way for the components to communicate so I thought about adding a messageing system. So Window::WinProc could send a message on WM_SIZE to Renderer:OnResize when the window gets resized. But I'm not sure how I would give each component access to the PostMessage() function. One thought was to pass a pointer to the 'System' class mentioned above to every component and the component calls PostMessage() from system which calls the corect function from the message handling class. Are there any potential pitfalls of using this method? I could just pass a pointer to the message system to the component but I want to keep them as seperate as possible and not have all different classes knowing about random other ones. Thanks for your time!

Share this post

Link to post
Share on other sites
I think you're overengineering. You probably don't need a message system. If an object x needs to talk to an object y, just have x hold a pointer to y, or pass the pointer to a method of x. Decoupling isn't about objects not knowing other objects, but classes not knowing other (concrete) classes, so use interfaces (abstract base classes in C++ terminology) gratuitously to isolate concrete classes from each other.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this