Path: chuka.playstation.co.uk!news From: "Peter Armstrong" Newsgroups: scee.yaroze.freetalk.english Subject: Re: Main Game Loop Technique Date: Sun, 14 Jul 2002 20:13:43 +0100 Organization: PlayStation Net Yaroze (SCEE) Lines: 71 Message-ID: References: NNTP-Posting-Host: modem-284.bellsprout.dialup.pol.co.uk X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 I've used pointers to functions for that sort of thing. I'd have an array of function addresses and use the return value from the function call as the array index. As an example: // functions to call int (*functions[5])(void) = {NULL, TitleScrn, NewGame, PlayerSelect,GameOptions}; . . . . void CallFunction(void) { int index = 1; // init index int (*FuncCall)(void); while(index) { FuncCall = functions[index]; // get function address index = FuncCall(); // call function } } This method may well be less efficient than switch/case statements, I just prefer to keep the in-function code compact, plus since I started using function pointers I can't seem to stop. ;) Peter "Rikki Prince" wrote in message news:agrf9f$d9k24@www.netyaroze-europe.com... > Before I would do the following: > main loop { > Prepare screen drawing stuff > if(TITLE_SCREEN) { > GsSort Title Screen stuff > } > elseif(GAME_SCREEN) { > GsSort Game stuff > } > etc > > if(ONE_PLAYER) { > Proccess for 1 player > } > elseif(TWO_PLAYER) { > Process for 2 player > } > etc > > } end of loop > > However, I'm wondering whether it's better to get rid of these checks > every loop by checking what screen it is first, then going into a > special loop for that screen, and doing similar for the number of > players. Do those checks cause much of a performance hit - is it worth > worrying about? Or is it better to keep the amount of code down (due > to the 2MB limit), rather than duplicating it? I suppose I could use > pointers to functions, so the main loop would be the same code, but > somewhere else changes which function is pointed to, which does the > specific proccessing. Could this be a good method? > > Cheers, > Rikki > >