Skip to main content
GameDev.net gamedev.net
🔒 Locked

GameLoop

Started by Link May 16, 2003 at 12:46 PM 6 replies 600+ views
Original Post
Link
Link
Hi guy, i would ask u a thing really simple but for me really important that is where put the gameLoop (what draw the scene) function in the main .cpp file? tnx for answer.
nosajghoul
nosajghoul
#include files

WndProc()
{
.
.
.
}

WinMain
{
.
.
.
while(1)
{
this would be where to put it
}
}



Check out the books : "programming role playing games with directx" and "hortons beginning c++". Read both 1000+ page volumes 5 times. If you still have questions, Bill Gates lives in washington state somewhere.
normal_toes@hotmail.com
Link
Link
what do u mean to tell?
Pipo DeClown
Pipo DeClown
// Init game
StartDirectX();
LoadGraphics();
ResetGameStuff();

// Loop
while(1)
{
// GameLoop
GetInput();
ReactontheInput();
UpdateGameStuff();
RenderGame();

// If need to quit?
break; // Break''s out of the while() loop

}//end of loop

.lick
Saqr
Saqr
You can put the loop anywhere but it usually is in the main function as it''s been said but if you are a real class-fanatic
you could do something like this.

class Application
{
public:
Application ()
{
Init ();
Run ();
}

void Run ()
{
while (1)
{
...
}
}
};

Application app;

void main / WinMain (...) {}
Link
Link
i refer to:

WPARAM StartMessageLoop()
{
MSG msg;
while(1)
{
if(PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
{
if(msg.message == WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
//first determine how many seconds elapsed
g_Engine.timerdiff = timeGetTime() - g_Engine.timer;

//the function reads in milliseconds so convert to seconds by dividing by 1000
g_Engine.secsperframe=(float)(g_Engine.timerdiff/1000.0f);

//now compute the movement value
g_Engine.movementvalue = (float)(g_Engine.desireddistance*g_Engine.secsperframe);

//get the new time
g_Engine.timer = (float)timeGetTime();

g_Engine.ProcessGame();
}
}
return msg.wParam;
}


and


case WM_DESTROY:
PostQuitMessage( 0 );
return 0;

case WM_PAINT:

g_Engine.ProcessGame(); //disegna per il primo frame il gioco

ValidateRect(g_hWnd, NULL);
return 0;


It is correct to get the best intervalling of time?
Pipo DeClown
Pipo DeClown
LEAVE WM_PAINT EMPTY!!!
ONLY USE WM_ACTIVE, WM_QUIT, WM_DESTROY!

.lick


[edited by - Pipo DeClown on May 18, 2003 10:56:06 AM]
Link
Link
In this way?:


LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
return 0;

case WM_DESTROY:
PostQuitMessage( 0 );
return 0;

case WM_ACTIVE:
ValidateRect(g_hWnd, NULL);
return 0;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}

But i must delete WM_PAINT and use at the same place WM_ACTIVE??

Pipo do u use MSN Messanger? Can u contect me at warco_m@libero.it Tnx.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.