# Game class layout help

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

## 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

• 40
• 15
• 10
• 23
• 10