Jump to content
  • Advertisement
Sign in to follow this  
johnnyBravo

Game class layout help

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

Hi, i'm trying to get my game's class layout setout so I won't have any problems in the future while coding it. What I have so far is these classes: Window: Just creates a window and returns the hwnd. Render: Initialises direct3d, and returns d3dDevice Scene: Right now it just creates a font object, and draws to the screen with the font. I've declared all these classes as global so say in render which needs the hwnd, i can just say window.getHwnd(); this is what my winmain would look like:
int WinMain(...............) {
   try {
      window.init(); //create window
      render.init(); //init direct3d
      scene.init(); //init font
   
      ShowWindow(window.gethwnd(), SW_SHOW);
      MSG msg;
      ZeroMemory(&msg, sizeof(msg));
      PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE);

      while(msg.message != WM_QUIT) {
         if(PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
            TranslateMessage(&msg);
	    DispatchMessage(&msg);
	  } else {
	     render.run(); //just checks if the d3ddevice has been lost
	     scene.run(); //beginscene, draw font, end scene
	  }
      }
   } catch(string e) {
     OutputDebugString(e.c_str());
   }

   return 0;
}


So so far I've tried to just give most classes a run function which is just called inside the winmain loop. But I've got a bit of a problem now. When the d3dDevice is lost I have to reset it like so: -See if device is lost, and can be regain -Release scene's font -Reset render's d3ddevice -Reset scene's font -Start drawing again And I don't want to have the render class calling anyone of scene's functions because that class like the window class are supposed to be reusable, so I want to keep out as much foreign code as possible. So any ideas on how I could change my class layout to incorporate resetting the device in that order I listed above? Thanks ...edit btw I would usually like to keep the winmain's while loop clear of any if's etc, as all that should be done inside the run classes, this i guess is causing a bit of trouble. And if anyone has any better ideas than what iam doing, i would really like to know. thx

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • 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!