Click here to Skip to main content
15,915,019 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Large Menu Items Pin
Code-o-mat19-May-10 11:28
Code-o-mat19-May-10 11:28 
GeneralRe: Large Menu Items Pin
cryptoknight1719-May-10 12:22
cryptoknight1719-May-10 12:22 
QuestionSave/Restore "state" of document in CHtmlView Pin
nobaq18-May-10 5:52
nobaq18-May-10 5:52 
QuestionClass Custom Control Pin
AbhiHcl18-May-10 2:33
AbhiHcl18-May-10 2:33 
AnswerRe: Class Custom Control Pin
Iain Clarke, Warrior Programmer18-May-10 2:42
Iain Clarke, Warrior Programmer18-May-10 2:42 
GeneralRe: Class Custom Control Pin
AbhiHcl18-May-10 23:57
AbhiHcl18-May-10 23:57 
GeneralRe: Class Custom Control Pin
Iain Clarke, Warrior Programmer19-May-10 1:58
Iain Clarke, Warrior Programmer19-May-10 1:58 
QuestionVisual Studio Addin for source code editor tooltip [modified] Pin
lclarsen18-May-10 1:58
lclarsen18-May-10 1:58 
QuestionMemory leak In Excel range pointer Pin
trioum18-May-10 0:53
trioum18-May-10 0:53 
AnswerRe: Memory leak In Excel range pointer Pin
Stephen Hewitt18-May-10 14:06
Stephen Hewitt18-May-10 14:06 
GeneralRe: Memory leak In Excel range pointer Pin
trioum18-May-10 22:30
trioum18-May-10 22:30 
QuestionService access file on network folder Pin
baerten18-May-10 0:39
baerten18-May-10 0:39 
AnswerRe: Service access file on network folder Pin
Garth J Lancaster18-May-10 0:52
professionalGarth J Lancaster18-May-10 0:52 
AnswerRe: Service access file on network folder Pin
Covean18-May-10 0:52
Covean18-May-10 0:52 
AnswerRe: Service access file on network folder Pin
baerten18-May-10 2:39
baerten18-May-10 2:39 
GeneralRe: Service access file on network folder Pin
sashoalm18-May-10 7:45
sashoalm18-May-10 7:45 
Questionmake a timer Pin
hasani200717-May-10 23:05
hasani200717-May-10 23:05 
AnswerRe: make a timer Pin
Rajesh R Subramanian17-May-10 23:26
professionalRajesh R Subramanian17-May-10 23:26 
JokeRe: make a timer Pin
CPallini17-May-10 23:45
mveCPallini17-May-10 23:45 
AnswerRe: make a timer Pin
Maximilien18-May-10 0:30
Maximilien18-May-10 0:30 
GeneralRe: make a timer Pin
Stephen Hewitt18-May-10 0:35
Stephen Hewitt18-May-10 0:35 
AnswerRe: make a timer Pin
KarstenK18-May-10 1:26
mveKarstenK18-May-10 1:26 
AnswerRe: Here is your count down timer hasani2007 Pin
Software_Developer18-May-10 7:31
Software_Developer18-May-10 7:31 
GeneralRe: Here is your count down timer hasani2007 Pin
Stephen Hewitt18-May-10 14:04
Stephen Hewitt18-May-10 14:04 
AnswerRe: make a timer Pin
Aescleal19-May-10 5:49
Aescleal19-May-10 5:49 
Hi Folks,

nothing like coming late to the party but as no one has mentioned the way most games are written I thought I'd stick me oar in...

In any game the timing is worked into the main dispatch loop. Every cycle around your dispatch loop you grab input, you update the timer, evolve the rest of the system based on how much time has elapsed and then render the game world according to what's happens. It looks something like this:

unsigned last_time = get_current_time_in_ms();

while( true )
{
    /*
       Record who's got keys pressed, where the mouse is, network stuff
     */

    update_IO_state();

    /*
        Sort out how much time has elapsed and how much time we have to evolve the game state over
     */

    unsigned time_now = get_current_time_in_ms();
    unsigned ms_this_loop = time_now - last_time;
    last_time = time_now;

    /*
        Change the state of all the game objects
     */

    evolve( ms_this_loop );

    /*
        Display the changes
     */

    render();
}


All the functions take some additional parameters depending on how you store your game state.

The key point of this lot is that the game hammers along flat out - the thread this is on will eat a CPU. It churns out frames as often as it can and slows down when there's something system intensive happening. Oh, and if you do your IO on another thread make sure everything is synchronised properly or something weird WILL happen, possibly not on your computer but on your first customer's computer.

Hope that helps,

Cheers,

Ash

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.