Archived

This topic is now archived and is closed to further replies.

Organising Program Structure

This topic is 5240 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

The 582nd re-write of my engine is way overdue, and I''ve had the sense to pick up pen and paper before open MSVC. Problem is, I''m having some trouble abstracting all the functions I need into a sensible organised manner, without too much complicated stuff holding them together (I''m trying to avoid stuff like multiple inheritance, singletons, templates etc, for the time being). At this point, the main classes I need are: Application Renderer Logging System Mesh Object (and derived sub-objects) Camera (subclass of Object) All the above classes are sub-classes of Application, which would give me a nice entry point. However, in previous attempts, I''ve tripped over my own code by being unable to access the Renderer class (which houses all the OGL calls) from the Mesh class. This would only work by passing the pointer to the Renderer instance into the Mesh object. Messy. Can anybody point me in the right direction for a better way to do things? Could I use an intermediate class in some way?

Share this post


Link to post
Share on other sites
quote:
Original post by BlackSheep
All the above classes are sub-classes of Application, which would give me a nice entry point.


I hope you meant that the Render, Logging System, etc. are members of the Application class, not that they inherit from the Application class. Inheritance implies a "is-a" relationship, I think you want a "has-a" relationship (composition).

quote:
Original post by BlackSheep
... in previous attempts, I''ve tripped over my own code by being unable to access the Renderer class (which houses all the OGL calls) from the Mesh class. This would only work by passing the pointer to the Renderer instance into the Mesh object. Messy.


Could you change this around. Rather than having your Mesh objects in charge of rendering themselves, you could have Mesh member functions to return what ever is necessary for the Renderer to display them. This is all off the top of my head, but couldn''t you have a Renderer::Render function that took a Mesh object. It would call the Mesh::GetVertexBuffer() function (or whatever else it needs for your rendering method) and make the appropriate OGL calls.

In your main rendering routine, you''d loop through all the visible objects, and call Renderer::Render on each of the Mesh objects. Since you have a class called "Renderer", it seems like that''s where rendering should happen.

Share this post


Link to post
Share on other sites