Jump to content
  • Advertisement


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


Engine design issue

This topic is 5777 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

Lately I''ve been working on a game engine. Things are coming along nicely and everything seems to be fitting together the way I want it, but I''m starting to have some issues with the design im using. In the WinMain of the application I instantiate my CEngine class. In the CEngine::Initialize method I create instances of several sub systems for input, sound, rendering, and eventually a network subsystem. I also have a CStateManager class that is set up as a singleton and the CEngine class has a member variable that points to the instance of this class. I then have a base class called CGameState and have different state classes that derive off this base state. Examples of the derived states are CTitleScreenState, CLoginScreenState, CCharacterSelectState, and eventually a CPlayGameState. This setup follows the design pattern as described on this webpage: http://www.codeproject.com/tips/statepattern3.asp I also have a CRenderer class that also is instantiated in the CEngine::Initialize method and of course has a member variable in the CEngine class to point to this. Accessing the renderer isnt much of a problem because in the CEngine::Render method i just call statemanager->GetState()->Render(renderer); which will pass in a pointer to the renderer. Works nicely because the Render method of the states only handles rendering. Unfortunately this doenst seem to play nice with the other methods such as CEngine::Update (which in turn calls statemanager->GetState()->Update()) when access to other subsystems is required (sound, input, networking). I thought of passing the whole instance of CEngine in as a parameter of these methods, and then stemming off that using something like engine->ShowMouseCursor() or engine->soundmanager->Playsound(). I could make the subsystems singletons as well, but that seems rather clunky to have an app full of singletons and that really doesnt solve the issue of accessing other member variables of the CEngine class from within the derived states. Hopefully this all makes sense and you can see what im trying to do. Id like to keep with the whole idea of using singletons for the different gamestates as it seems to work out well. I''m open to suggestions on how to clean this up a bit and make things a little more elegant and accessable to these derived state classes. Any help is appreciated. -=[ Megahertz ]=-

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!