#include "3DObject.h" #define MAX_OBJECTS (40) #define ORDERING_TABLE_LENGTH ( 12 ) #define MAX_NO_PACKETS ( 248000 ) long objectTable[ MAX_OBJECTS ] ; // We need two Ordering Table Headers, one for each buffer COrderTableHeader othWorld[2] ; // And we need Two Ordering Tables, one for each buffer GsOT_TAG otWorld[ 2 ] [ 1 << ORDERING_TABLE_LENGTH ] ; //We also allocate memory used for depth sorting, a block for each buffer PACKET outPacket[ 2 ] [ MAX_NO_PACKETS ] ; CWorld::CWorld( ) { } void CWorld::init( ) { m_lIndex = 0 ; for ( u_long l = 0 ; l < MAX_OBJECTS ; l++ ) objectTable[ l ] = 0 ; // Before we can use the ordering table headers, // we need to... // 1. Set them to the right length othWorld[0].length = ORDERING_TABLE_LENGTH; othWorld[1].length = ORDERING_TABLE_LENGTH; // 2. Associate them with an actual ordering table othWorld[0].org = otWorld[0]; othWorld[1].org = otWorld[1]; // 3. initialise the World Ordering Table Headers and Arrays GsClearOt(0,0,&othWorld[0]); GsClearOt(0,0,&othWorld[1]); } CWorld& CWorld::operator+=( LPDRAWABLEOBJECT p ) { objectTable[m_lIndex++] = (long)p ; return *this ; } LPDRAWABLEOBJECT CWorld::operator[]( u_long l ) const { return (LPDRAWABLEOBJECT)objectTable[ l ] ; } void CWorld::draw( ) { // This variable keeps track of the current buffer for double buffering //get the current buffer int currentBuffer = GsGetActiveBuff(); // set address for GPU scratchpad area GsSetWorkBase( ( PACKET* ) outPacket[ currentBuffer ] ) ; // clear the ordering table GsClearOt( 0, 0, &othWorld[ currentBuffer ] ) ; //draw the objects in the object table for( u_long l = 0; l < m_lIndex ; l++ ) { LPDRAWABLEOBJECT p = (LPDRAWABLEOBJECT)objectTable[ l ] ; if ( p ) p->draw( othWorld[currentBuffer] ) ; } // wait for end of drawing DrawSync(0); // wait for V_BLANK interrupt u_long v = VSync(0); FntPrint( "Keys...\n" "Left arrows move cube.\n" "Right arrows move projection.\n" "Start restarts\n", "Start & Select quits\n\n" ) ; FntPrint("VSync=%d\n", v ) ; // force text output to the PSX screen FntFlush(-1); // swap double buffers GsSwapDispBuff(); // register clear-command: clear ordering table to black GsSortClear( 0, 0, 0, &othWorld[ currentBuffer ] ) ; // register request to draw ordering table GsDrawOt( &othWorld[ currentBuffer ] ) ; } u_long CWorld::objectCount( ) const { return m_lIndex ; }