To modularize the project so that everyone is working on a specific area of the game with their own files, I wanted to create a master game class that would hold all of our modules. The only problem with this approach was that other modules couldn’t call each other unless they were passed a ptr to it. I then thought that a namespace would make it easier for the other modules to reach. The structure was like this: (contents of BTC_main.h)
#ifndef __BTC_MAIN_H
#define __BTC_MAIN_H
#include "BTC_display.h"
#include "BTC_input.h"
#include "BTC_time.h"
#include "BTC_menu.h"
#include "BTC_gamedata.h"
#include "BTC_network.h"
#include "BTC_flow.h"
#include "BTC_lobby.h"
#include "BTC_setup.h"
#include "BTC_sound.h"
#include "BTC_hud.h"
namespace game
{
int (*control)(); // Function Pointer that pts to what 'loop' is in control
Display display; // Display Module
Input input; // Input Module
Time time; // Time Module
Menu menu; // Menu Module
Gamedata gamedata; // In-Game Data Object
Network network; // Networking Module
Lobby lobby; // Lobby Module
Setup setup; // Startup Code
Sound sound; // Sound Module
Hud hud; // Heads Up Display Module
int SetupGame(HWND hwnd, HINSTANCE hinstance)
{
setup.Display(hwnd, hinstance, &display);
display.Init();
sound.Init();
time.Init();
return 0;
}
int ShutdownGame()
{
display.Release();
sound.Release();
return 0;
}
}
#endif
|