/* ** File : Prog.c ** Author: D Smethurst ** Description: Basic sprite list (library) use. ** Updates every frame and rotates the onscreen ** sprite. ** Version: v1.0 (v0.1 of library) */ /* ** System headers */ #include #include /* ** Include my headers */ #include "sprite.h" #include "pad.h" #include "tims.h" #include "screen.h" /* ** Local defines */ #define OTABLE_LENGTH (2) #define MAX_PACKETS (2048*24) /* ** Ordering tables */ static GsOT OTHeader[2]; static GsOT_TAG OTArray[2][1<spr.x = SCREEN_W/2; tmpSpr->spr.y = SCREEN_H/2; /* Add sprite to the list */ head = SprLstAdd( tmpSpr, head ); while( !(rpad & PADselect && rpad & PADstart) ) { /* Read joypad */ rpad = ReadJoyPad(); /* Update */ Update(); /* Get current buffer */ currBuff = GsGetActiveBuff(); /* Set the work base */ GsSetWorkBase( (PACKET *)pktMem[currBuff] ); /* Clear the OT */ GsClearOt( 0, 0, &OTHeader[currBuff] ); /* Draw the sprite list (see sprlst.c) */ SprLstDraw( head, OTHeader[currBuff] ); /* Sync to end of frame */ DrawSync( 0 ); drawTime = VSync( 0 ); /* Swap buffers */ GsSwapDispBuff(); /* Add a clear to the front of the OT */ GsSortClear( 0, 0, 0, &OTHeader[currBuff] ); /* Draw the OT */ GsDrawOt( &OTHeader[currBuff] ); /* Output some text */ FntPrint( FntOut, "Screen Draw Time: %d", drawTime ); FntFlush( FntOut ); } ResetGraph( 3 ); } /* ** InitScreen - Screen initialisation stuff */ void InitScreen() { /* VideMode - Can be changed in screen.h */ SetVideoMode( VID_MODE ); /* Setup graphics subsystem */ GsInitGraph( SCREEN_W, SCREEN_H, 0, 0, 0 ); /* Set the default display buffer */ GsDefDispBuff( 0, 0, 0, SCREEN_H ); /* Load font and set area to print out */ FntLoad( 960, 256 ); FntOut = FntOpen( 0, 0, SCREEN_W, 50, 0, 256 ); /* Setup the OT information */ OTHeader[0].length = OTABLE_LENGTH; OTHeader[1].length = OTABLE_LENGTH; OTHeader[0].org = OTArray[0]; OTHeader[1].org = OTArray[1]; /* Initialise the OT's */ GsClearOt( 0, 0, &OTHeader[0] ); GsClearOt( 0, 0, &OTHeader[1] ); } /* Global track of rotation */ long rot=0; /* ** Update function called once every loop. */ void Update() { /* Temporary sprite pointer */ lpspritelist tmp; /* Point to the head */ tmp = head; /* Update rotation */ rot += (ONE); if( rot > (ONE*359) ) rot = 0; /* Check the list and update */ /* If tmp is null it drops out */ while( tmp != NULL ) { /* Set the rotation of the sprite */ tmp->s->spr.rotate = rot; /* Move along the list - last in list points */ /* next to NULL */ tmp = tmp->next; } }