OK, so I have an ENGINE class, and in this class there will be a private vector array of SYSTEMs. When a SYSTEM object is created, it will be added to the ENGINE's vector array through the ENGINE's AddSystem() function. Then when the ENGINE's Update() function is called, it will loop through the vector of SYSTEM's and call each corresponding Update() function in the order the SYSTEMs were added to the ENGINE.
INPUT will update every game loop.
Need to detect if a key is being PUSHED, HELD, RELEASED, or NO_STATE.
Game continues to run when player interacts with the UI.
There will be a pause option in single player mode.
Posted more pseudo-code, hope it helps.
main.cpp
Code:
.
.
.
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE pInst, LPSTR cmd, int show)
{
ENGINE engine;
DEBUG debug; //redirects printf to console window
INPUT input;
WINDOW window; //creates window and handles window messages
GAME game; //game logic
PHYSICS physics; //gravity, collision, force application
GRAPHICS graphics; //directX
//add each SYSTEM to the vector array in ENGINE
engine.AddSystem(&debug);
engine.AddSystem(&input);
engine.AddSystem(&window);
engine.AddSystem(&game);
engine.AddSystem(&physics);
engine.AddSystem(&graphics);
engine.Load(); //calls Load() for each SYSTEM
engine.Initialize(); //calls Initialize() for each SYSTEM
while(engine.active())
{
engine.Update(); //calls Update() for each SYSTEM
}
engine.Unload(); //calls Unload() for each SYSTEM
return 0;
}
engine.h
Code:
.
.
.
class ENGINE
{
private: bool shutdown_
std::vector<SYSTEM*> system_;
public: ENGINE();
~ENGINE();
void Load();
void Initialize();
void Update();
void Unload();
void Shutdown() { shutdown_ = true; }
bool Active() { return shutdown_; }
};
engine.cpp
Code:
.
.
.
ENGINE::ENGINE()
{
shutdown_ = false;
}
ENGINE::~ENGINE()
{
//clean up vector array
}
ENGINE::Load()
{
for(int i = 0; i < system_.size(); i++) //loop through load functions
system_[i]->Load();
}
ENGINE::Initialize()
{
for(int i = 0; i < system_.size(); i++) //loop through initialize functions
system_[i]->Initialize();
}
ENGINE::Update()
{
for(int i = 0; i < system_.size(); i++) //loop through update functions
system_[i]->Update();
}
ENGINE::Unload()
{
for(int i = 0; i < system_.size(); i++) //loop through unload functions
system_[i]->Unload();
}
ENGINE::AddSystem(SYSTEM* system)
{
system_.push_back(system);
}
window.cpp
Code:
.
.
.
LRESULT CALLBACK WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
case WM_CLOSE: PostQuitMessage(0);
return 0;
case WM_KEYDOWN: //Update key presses
break;
case WM_KEYUP: //Update key releases
break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
WINDOW::WINDOW()
{
//create window
}
WINDOW::~WINDOW()
{
//unregister and close window
}
.
.
.
void WINDOW::Update()
{
while(PeekMessage(&msg_, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg_);
DispatchMessage(&msg_);
}
}
.
.
.
graphics.h
Code:
class Graphics : public System
{
private: LPDIRECT3D9 d3d_; //DirectX library access
LPDIRECT3DDEVICE9 d3ddev_; //DirectX device(graphics card)
D3DPRESENT_PARAMETERS d3dpp_;
public: Graphics();
~Graphics();
void Load();
void Initialize();
void Update(); //Rendering
void Unload();
};
graphics.cpp
Code:
.
.
.
GRAPHICS::GRAPHICS()
{
//initialize and gain access to DirectX
}
GRAPHICS::~GRAPHICS()
{
//clean up DirectX
}
.
.
.
void GRAPHICS::Update()
{
d3ddev_->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
if(d3ddev_->BeginScene())
{
//rendering occurs here
d3ddev_->EndScene();
}
d3ddev_->Present(NULL, NULL, NULL, NULL);
}
.
.
.
input.h
Code:
.
.
.
enum KEY_STATE { NO_STATE, RELEASED, HELD, PRESSED = 4};
class INPUT : public SYSTEM
{
private: char key_[256];
public: INPUT();
~INPUT();
void Load();
void Initialize();
void Update();
void Unload();
};
input.cpp
Code:
.
.
.
INPUT::Update()
{
///////////////////////////////////////
//Can't access this function in WinProc
//in the Window.cpp file. So how do I
//update my key array?
///////////////////////////////////////
}
.
.
.