Path: chuka.playstation.co.uk!news From: sosman@terratron.com (Steven Osman) Newsgroups: scee.yaroze.freetalk.english Subject: Re: Packet Explanation Date: Sat, 24 Nov 2001 19:46:15 GMT Organization: PlayStation Net Yaroze (SCEE) Lines: 376 Message-ID: <3c00f3e4.761094546@www.netyaroze-europe.com> References: <9tkp3s$dq91@www.netyaroze-europe.com> <9tlh4b$dq95@www.netyaroze-europe.com> <9tne1e$dq916@www.netyaroze-europe.com> NNTP-Posting-Host: dsl092-099-074.nyc2.dsl.speakeasy.net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Newsreader: Forte Agent 1.5/32.452 Greg, You should try and think about things in terms of a "state machine" to help you with your "thanks for checking me out" display. Try something like this. It is by no means the only way to do this, but one possible way: #define STATE_NORMAL 0 #define STATE_PAUSED 1 #define STATE_EXITING 2 #define STATE_END 3 int iState=STATE_NORMAL; int iExitTimer; u_long ulInput; int iContinuePlaying=1; while (iContinuePlaying) { ulInput=readPad(); switch(iState) { case STATE_NORMAL: if (ulInput & (PADstart | PADselect)) { setState(STATE_EXITING); } if (ulInput & PADstart) { setState(STATE_PAUSED); } if (ulInput & PADLleft) { x=x-1; } (etc, etc) draw your screen with your game stuff break; case STATE_END: iContinuePlaying=0; break; case STATE_EXITING: if (--iExitTimer==0) { setState(STATE_END); } else { draw your screen that says goodbye. } break; case STATE_PAUSED: draw your screen that says game is paused if (ulInput & (PADstart | PADselect)) { setState(STATE_EXITING); } if (ulInput & PADstart) { setState(STATE_NORMAL); } break; } DrawSync(0); (switch buffers here) } and your setState function would be something like: void setState(int iNewState) { iState=iNewState; if (iState==STATE_EXITING) { iExitTimer=150; // 5 second timer at 30fps } } Basically, your state answers the following question for your program: "What should I be doing right now?" If the state is "paused" (STATE_PAUSED), your program should display "game is paused" until the person hits start. If the state is "normal," the game should proceed as usual. If the state is "exiting," the game should be displaying a goodbye message for a short period of time, then exit. If your state is "end," then the game should end. Things like that... Of course the stuff for each state probably grows quite a bit so you may want to separate them into functions. Also, as your game gets more complex, you may want to use several state machines instead of just one. For example, a state machine for the main menu, a state machine during game play, etc. Now don't look at the above code as a definitive way to do this... It's just a simple example to show you how a state machine could work. Steven On Sat, 24 Nov 2001 19:17:32 +1300, "Greg Cook" wrote: >Thanks alot for the explanantion Alex. > >Heres some code i've written today, as you can see im just starting out... > >Ive got a few questions scattered in that code as comments, maybe you can >answer some > >like i said this is the first code i wrote and got working today, though i >understand a good portion of it, theres alot im not sure of, > >also just say i press select and start to quit the program.. > >how would i clear the screen, put the words " thanks for checking me oout" >and then quit the program? > >thanks alot for your help and patience. > >Greg > > >****************************************** > >#include >#include "pad.c" > > >/*=========================== Defines ==================================*/ >#define SCREEN_WIDTH 320 >#define SCREEN_HEIGHT 256 >#define SPRITE_COUNT (1+1) >#define OT_LENGTH 1 > >GsOT WorldOT[2]; > >// the ordering tables units thought i really still dont get what they are. > >GsOT_TAG WorldTags[2][1< >static PACKET packetArea[2][SPRITE_COUNT*sizeof(GsSPRITE)]; // GPU PACKETS >AREA > >int ContinuePlaying = 1; >int x = 0; >int y = 0; >/*=========================== Protypes =================================*/ > >void main (void); >void InitialiseScreen(void); >void GetPadInput(void); > >/*=========================== Code Starts =========================*/ > >void main (void) >{ > int buffNumber; > > InitialiseScreen(); > buffNumber = GsGetActiveBuff(); > > while(ContinuePlaying) > { > > GetPadInput(); > > // not sure about the (PACKET*) part, but as i understand it > // it is type casting (PACKET*) but whats the *? pointer? > > GsSetWorkBase((PACKET*)packetArea[buffNumber]); > > GsClearOt(0,0,&WorldOT[buffNumber]); > > DrawSync(0); > > VSync(0); > > ResetGraph(1); > > GsSwapDispBuff(); > > GsSortClear(0,0,0,&WorldOT[buffNumber]); > > GsDrawOt(&WorldOT[buffNumber]); > > buffNumber = buffNumber^1; > > FntFlush(-1); > > } > > ResetGraph(0); >} > >void InitialiseScreen(void) >{ > int x; > int something; > > PadInit(); > SetVideoMode(MODE_PAL); > > // why is this set at 4? hmmm good question... how did you work that value >out? > // i know what the 4 means, non interlaced etc,but how did you get 4? > > GsInitGraph(SCREEN_WIDTH,SCREEN_HEIGHT,4,0,0); > > GsDefDispBuff(0,0,0,SCREEN_HEIGHT); > > for(x=0;x<2;x++) > { > WorldOT[x].length = OT_LENGTH; // set OT length > > // still unsure about this.. whats exactly is WorldTags[x] > > WorldOT[x].org = WorldTags[x]; // link in the OT units > > GsClearOt(0,0,&WorldOT[x]); > } > > // where do some of these magic numbers come from... > > FntLoad(960,256); > FntOpen(10,80,256,200,0,512); > } > >void GetPadInput(void) >{ > u_long padStatus; > > > // PadRead() gets the status from the controller. > padStatus = PadRead(); > > if (padStatus & PADstart && padStatus & PADselect) // Quit Program > { > ContinuePlaying = 0; > } > > if (padStatus & PADLleft) > { > x = x - 1 ; > } > > if (padStatus & PADLright) > { > x = x + 1; > } > > if (padStatus & PADLdown) > { > y = y - 1 ; > } > > if (padStatus & PADLup) > { > y = y + 1; > } > > FntPrint("X : %d\n", x); > > FntPrint("Y : %d\n", y); >} >----- Original Message ----- >From: "Alex Herbert" >Newsgroups: scee.yaroze.freetalk.english >Sent: Saturday, November 24, 2001 2:00 AM >Subject: Re: Packet Explanation > > >> Hi Greg, >> >> The packet area is just a chuck of memory, so as long as it's big enough >to >> hold all the packets you create then fine. It doesn't really matter how >you >> define it but declaring an array seems to be the most common way. >> >> The NO_SPRITES*sizeof(GsSPRITE) method seems logical at first as this >would >> suggest that the packet area is the correct size to hold the number of >> sprite packets as defined by NO_SPRITES. However this is wrong as the >size >> of the GsSPRITE structure has nothing to do with the size of the packets >> created. For this reason I wouldn't advise doing it this way. >> >> The PACKETMAX*24 method makes a little more sense to me as 24 is an >average >> size for a GPU packet. Some are bigger, some are smaller but 24 is good >as >> a rough guide. As for how a value for PACKETMAX is chosen, well that's up >> to the programmer to decide. Picking a value of 2048 for example is >saying >> that you definitely won't be sorting more than 2048 items (roughly) into >the >> OT. >> >> Or you could just declare it like this: >> >> #define PACKETAREA_SIZE 32768 // 32Kbytes >> PACKET packetarea[2][PACKETAREA_SIZE]; >> >> and just specify the number of bytes required. Choosing a big(ish) number >> like 32K is a good starting place. This number can then be refined >> throughout development as you get a better idea of how much space is >> actually required. Calling GsGetWorkBase() after sorting all your objects >> (i.e. just before you call GsDrawOt) will return the address of the next >> free byte in the packet area (one byte beyond the used area). So, simply >> subtracting the start address of the packet area will tell you how much >> memory is being used. Sorted! >> >> Alternatively, instead of declaring an array for the packet workspace, you >> could assign memory from the heap at run-time using malloc(). Or if >> memory's getting tight, you could set the address of the packet workspaces >> to the area of memory where you loaded your TIMs. Once the TIMs have been >> loaded into VRAM the chances are that you don't need the copies in main >RAM >> any more, so overwriting them with GPU packets isn't a problem. At the >end >> of the day it's up to you to use the method which you feel is the most >> appropriate. >> >> Alex >> >> >> "Greg Cook" wrote in message >> news:9tkp3s$dq91@www.netyaroze-europe.com... >> > Ok well ive been working through various beginner tutes, and have been >> > reading the beginners forum to get some help and explain some things. >> > >> > But i have a question about Packets. In most tutes there are two >distinct >> > ways to define the Packet Area and im unsure which is the correct way to >> do >> > it.. >> > >> > 1. >> > >> > #define NO_SPRITES 1 >> > >> > static PACKET packetarea[2] [NO_SPRITES*sizeof(GSPRITE)]; >> > >> > 2. >> > >> > #define PACKETMAX 2048 >> > #define PACKETMAX2 (PACKETMAX*24) >> > >> > static PACKET packetarea[2][PACKETMAX2]; >> > >> > so which one is correct? and in the second version where does the magic >> > number 2048 come from? i assume the 24 is something to do with the size >of >> > the items in the structure... but is 2048 just a magic number as i have >> seen >> > it defined as 1024 and various other sizes........... >> > >> > ok well yet another question from me.. >> > >> > thanks guys >> > >> > Greg >> > >> > >> > >> > >> >> > >