System_Start
Start the main game loop.
Synopsis
bool HGE::System_Start();
Returns
Always returns false after the loop exits.
Description
System_Start begins the main game loop. It repeatedly calls your frame function and render function until the frame function returns true.
The typical loop flow:
- Process Windows messages
- Calculate delta time
- Call your frame function (HGE_FRAMEFUNC)
- If frame function returned false, call render function (HGE_RENDERFUNC)
- If frame function returned true, exit the loop
Prerequisites
Before calling System_Start:
System_Initiate()must have succeeded- Frame function must be set via
System_SetState(HGE_FRAMEFUNC, ...)
Example
bool FrameFunc()
{
float dt = hge->Timer_GetDelta();
// Update game logic
UpdateGame(dt);
// Return true to exit
return hge->Input_GetKeyState(HGEK_ESCAPE);
}
bool RenderFunc()
{
hge->Gfx_BeginScene();
hge->Gfx_Clear(0);
// Draw game
RenderGame();
hge->Gfx_EndScene();
return false;
}
int main()
{
HGE *hge = hgeCreate(HGE_VERSION);
hge->System_SetState(HGE_FRAMEFUNC, FrameFunc);
hge->System_SetState(HGE_RENDERFUNC, RenderFunc);
// ... other setup ...
if (hge->System_Initiate())
{
hge->System_Start(); // Runs until FrameFunc returns true
}
hge->System_Shutdown();
hge->Release();
return 0;
}
Frame Rate Control
The loop timing is controlled by HGE_FPS:
hge->System_SetState(HGE_FPS, 60); // Target 60 FPS
hge->System_SetState(HGE_FPS, 0); // Unlimited
hge->System_SetState(HGE_FPS, HGEFPS_VSYNC); // Sync to monitor