Sign in to follow this  
skwee

Hierarchy of game engine sub systems

Recommended Posts

Hello everyone. I'm working now on my game engine (using C++) and i decided to work with this shape: Every sub-system (graphics, sound, input, text, net etc) is a class. The game engine it self also a class that inherits from above sub-systems. Every thing was fine i did graphics ss, input and then started to do text. First of all I'm using SDL, and SDL_ttf for text. When I started to develop draw function for text i remembered that i need the screen SDL_Surface (that was initialized at Graphics class) to blit the text on, and text class have no relation or connection to graphics class. Some now I'm stuck. I cant do text class by inheriting it from graphics, the only thing I need is to access to one protected variable of graphics class from text class. Any ideas? I can add an illustration if needed. I'm appreciating every kind of help!

Share this post


Link to post
Share on other sites
I understand that the Text system will always need the Graphics system to work. In that case, you can inherit the Text system from the Graphics system and then inherit the root Game system from the Text system.

However, this way you may want to reconsider whether you want to make Graphics and Text system two different classes.

Share this post


Link to post
Share on other sites
Text system need only one variable that was initialized in graphics system.
I thought about inherit text system from graphic system but when i want to inherit class A from class B i always say to my self "Is A a kind of B?", in this case "Is text is a kind of graphics?" yes partly, text is graphic but text cant load images, draw them, and manage the main window setting like height, width and title of the window and etc. So in this case Text can't be inherited form graphic.

Another solution i thought is to make a basic graphic class that only initialize the screen and then create two other class that will inherit its methods, one is the advanced graphics that manage the images loading, drawing and etc and the second one is the text class.

This is the only solution i can afford to my self, but I want to know if there is a better solution?

Thanks a lot again.

[EDIT]
I got another solution, to pass this variable to text class like parameter.

[Edited by - Minios on June 1, 2007 5:30:11 AM]

Share this post


Link to post
Share on other sites
You shouldn't use inheritance here at all.

"Graphics" sounds like the class that should be responsible for drawing renderable entities on the screen. "Text" sounds like a renderable entity. Therefore, they should be passed to eachother -- you can pass the Text to the Graphics draw method, or the Graphics to the Text draw method (or expose one interface publicly but invert the responsibility internally, et cetera).

It may be overkill for your relatively simple 2D engine, but I wrote a basic overview of how the rendering system works in my current project here that you might want to glance over.

Share this post


Link to post
Share on other sites
Quote:
Original post by jpetrie
You shouldn't use inheritance here at all.

"Graphics" sounds like the class that should be responsible for drawing renderable entities on the screen. "Text" sounds like a renderable entity. Therefore, they should be passed to eachother -- you can pass the Text to the Graphics draw method, or the Graphics to the Text draw method (or expose one interface publicly but invert the responsibility internally, et cetera).

It may be overkill for your relatively simple 2D engine, but I wrote a basic overview of how the rendering system works in my current project here that you might want to glance over.


Thanks i think i got the idea i'll check u'r engine! Thanks a lot.

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