Hi,
Don't know if you are still watching this thread. But I looked today into
my
game loop and realized it is sort of broke after I switched from
multithreaded to singlethreaded (I switched because I read in the directx
docs that directx expects to run on the same thread that created the main
window)..
When it was MT I actually checked several things like the runlist, when
the
next animation should occur etc. Then I waited on a mutex object until
that
becomes signalled or whenever the minimum time expired (i.e. it had to
either draw something on the screen or the sleeplist changed or audio
etc. ).
The mutex object could become signalled when events (like mouse or
keyboard)
came in from the main windows thread. Those would post the message to the
game engine and set the mutex object state to signalled.
Allthough my app is now single threaded it didn't cause any problems
(probably because the time to redraw graphics is pretty short anyway I
usually aim at 25 fps) but I sure have to look into it.
Regards, Ron AF Greve
---------------------------------Current game loop
Collision->Dump();
Display->Dump();
ProcState->CurrentTime = Clock->GetGameTicks();
if( ProcState->CurrentTime < ProcState->TicksToWait )
{
unsigned long WaitTime = Clock->GameTick2MilliSeconds(
ProcState->TicksToWait - ProcState->CurrentTime );
if( WaitForSingleObject( HTrigger, WaitTime ) == WAIT_OBJECT_0 )
{
//Run Game so it consumes the mouse and keyboard messages
Game->HeartBeat();
ProcState->NextGame = Game->GetNextTick();
ProcState->TicksToWait = min( ProcState->TicksToWait,
ProcState->NextGame );
}
ProcState->CurrentTime = Clock->GetGameTicks();
}
ProcState->TicksToWait = static_cast<unsigned long>( -1 );
//Channel << Level4 << " CurrentTime = " << ProcState->CurrentTime << "
NextDisplay = " << ProcState->NextDisplay << End;
unsigned long Cur = ProcState->CurrentTime;
unsigned long Dis = ProcState->NextDisplay;
if( ProcState->CurrentTime >= ProcState->NextDisplay )
{
Display->HeartBeat();
ProcState->NextDisplay = Display->GetNextTick();
ProcState->TicksToWait = min( ProcState->TicksToWait,
ProcState->NextDisplay );
}
ProcState->CurrentTime = Clock->GetGameTicks();
if( ProcState->CurrentTime >= ProcState->NextAudio )
{
Audio->HeartBeat();
ProcState->NextAudio = Audio->GetNextTick();
ProcState->TicksToWait = min( ProcState->TicksToWait,
ProcState->NextAudio );
}
ProcState->CurrentTime = Clock->GetGameTicks();
if( ProcState->CurrentTime >= ProcState->NextRunList )
{
switch( RunList->HeartBeat() )
{
case MRunList::eJustReturning:
// Nothing to do
// Check if a SceneSwitch has occurred (this is due to an ELoadScene
event)
Game->ExecuteSwitch();
break;
case MRunList::eAutoSaveGame:
AutoSaveGame();
// Save game
break;
case MRunList::eEscapeGame:
// Go to Control 'Game'
EscapeGame();
ControlSetup();
break;
case MRunList::eResumeGame:
// Go to Control 'Game'
ResumeGame();
break;
case MRunList::eSaveGame:
// save game
//#error " SaveGame( with info from Global::Info? );"
CtrlSaveGame();
break;
case MRunList::eLoadGame:
// load game
CtrlLoadGame();
break;
case MRunList::eQuickSaveGame:
QuickSaveGame();
// Save game
break;
case MRunList::eQuickLoadGame:
QuickLoadGame();
// Save game
break;
case MRunList::eQuitGame:
// Quit the game
//this->Stop();
PostQuitMessage( 0 );
Channel << Level4 << "Exiting Game" << End;
break;
case MRunList::eSwitchScene:
{
// Switch scene due to a Switch statement in the scripting language
Game->ExecuteSwitch();
}
break;
}
ProcState->NextRunList = RunList->GetNextTick();
ProcState->TicksToWait = min( ProcState->TicksToWait,
ProcState->NextRunList );
}
ProcState->CurrentTime = Clock->GetGameTicks();
if( ProcState->CurrentTime >= ProcState->NextGame )
{
Game->HeartBeat();
ProcState->NextGame = Game->GetNextTick();
ProcState->TicksToWait = min( ProcState->TicksToWait,
ProcState->NextGame );
}
http://www.InformationSuperHighway.eu
"Anton" <anton.txt@[EMAIL PROTECTED]
> wrote in message
news:Xns99DEDAD89B6F9antontxtgmailcom@[EMAIL PROTECTED]
> Hello all.
>
> I have a somewhat general question about game architecture. I'm gonna
> make a squad-level isometric game. I have tiles, unit animations,..
> e.t.c. And the question is, how I should design the graphical subsystem.
>
> Options:
>
> I. The game screen is updated tile-by-tile, only changed tiles
> (including characters moving thereon) at a specified rate (anomation
> speed).
>
> GUIis treated separately. Once animation has stoppped, I poll input
> events and handle them until a unit has received an order. Then I call
> the animation loop.
>
> Such things as burning things, smoke e.t.c. should be animated only
> during this "interface" loop. Same go to scrolling.
>
> BTW: Remember, in XCOM all smoke and fire tiles freezed when units were
> acting, and came back alive after they had accomplished thier orders. I
> suppose they used this approach.
>
> II. Doing everithing synchronously.
> There's one main loop, which never stops polling, handling events (Game
> screen then GUI), and immediately updating the whole screen without any
> delay. The game mechnics is synchronised by virtue of some game-event
> queue wherein events are bound to their times, so that GFX (frames per
> second) are independant of the game speed.
>
> This latter method seems easier and more versatile, but is't too
> CPU-heavy (like using an oscilloscope to drive nails in, or to shoot at
> birds from a mortar)?
>
> Thanks in advance for feedback,
> Anton


|