Virtual U.org
Get Personal Training on VU Today
    
Top shadow
 
 register/help
User Name:

Password:

OSPRITEA.CPP Source File
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

OSPRITEA.CPP

Go to the documentation of this file.
00001 //Filename    : OSPRITEA.CPP
00002 //Description : Object SpriteArray
00003 //Owner       : Fred
00004 
00005 //#include <ALL.H>
00006 //#include <OVGA.H>
00007 //#include <OSTR.H>
00008 //#include <OSYS.H>
00009 //#include <OSPRTRES.H>
00010 #include <OSPRITE.H>
00011 #include <OSPRITEA.H>
00012 //#include <OUNIT.H>
00013 
00014 /*#ifdef DEBUG
00015 #include <OBULLET.H>
00016 #include <OTORNADO.H>
00017 
00018 static int num_of_unit;
00019 #endif*/
00020 
00021 //--------- Begin of function SpriteArray::SpriteArray ---------//
00024 SpriteArray::SpriteArray(int initArraySize) : DynArrayB(sizeof(Sprite*),initArraySize, DEFAULT_REUSE_INTERVAL_DAYS) {
00025 }
00026 
00027 //----------- End of function SpriteArray::SpriteArray ---------//
00028 
00029 //--------- Begin of function SpriteArray::~SpriteArray ---------//
00030 SpriteArray::~SpriteArray() {
00031     deinit();
00032 }
00033 
00034 //----------- End of function SpriteArray::~SpriteArray ---------//
00035 
00036 //--------- Begin of function SpriteArray::init ---------//
00037 void SpriteArray::init() {
00038     restart_recno = 1;
00039 }
00040 
00041 //----------- End of function SpriteArray::init ---------//
00042 
00043 //--------- Begin of function SpriteArray::deinit ---------//
00051 void SpriteArray::deinit() {
00052     if( size()==0 )
00053         return;
00054 
00055     //----- delete sprite objects ------//
00056 
00057     Sprite* emptyPtr = NULL;
00058     Sprite* spritePtr;
00059 
00060     for( int i=1 ; i<=size() ; i++ ) {
00061         spritePtr = (Sprite*) get_ptr(i);
00062 
00063         if( spritePtr )
00064             delete spritePtr;
00065 
00066         update( &emptyPtr, i );                       // set the pointer in SpriteArray to NULL, so is_deleted() can return correct result, this is needed as Unit::deinit() will call is_deleted()
00067     }
00068 
00069     //-------- zap the array -----------//
00070 
00071     zap();
00072 }
00073 
00074 //----------- End of function SpriteArray::deinit ---------//
00075 
00076 //--------- Begin of function SpriteArray::add ---------//
00077 void SpriteArray::add(Sprite *newSprite) {
00078     linkin(&newSprite);
00079 
00080     newSprite->sprite_recno = recno();
00081 }
00082 
00083 //----------- End of function SpriteArray::add -----------//
00084 
00085 //--------- Begin of function SpriteArray::add_sorted ---------//
00095 void SpriteArray::add_sorted(Sprite *newSprite) {
00096     /*
00097       int l=0, r=size(), x=0;
00098       int addY  = newSprite->abs_y2;
00099       int testY = addY + 1;
00100 
00101       //---------------------------------------------------------------------//
00102       // Use a binary search to find the right location to add the new sprite.
00103       //---------------------------------------------------------------------//
00104 
00105       while (r > l)
00106       {
00107       x = (l + r) / 2;
00108 
00109       testY = operator[](x+1)->abs_y2;   // the one to be compared with the adding one.
00110 
00111       if (addY < testY)
00112       r = x;
00113       else
00114       l = x + 1;
00115 
00116       if (addY == testY)
00117       break;
00118       }
00119 
00120       if (addY >= testY)
00121       x++;
00122 
00123       insert_at(x+1, &newSprite);
00124     */
00125 }
00126 
00127 //----------- End of function SpriteArray::add_sorted -----------//
00128 
00129 //--------- Begin of function SpriteArray::del ---------//
00130 void SpriteArray::del(int recNo) {
00131     Sprite* spritePtr = (Sprite*) get_ptr(recNo);
00132 
00133     err_when( !spritePtr );
00134 
00135     delete spritePtr;
00136 
00137     linkout(recNo);
00138 }
00139 
00140 //----------- End of function SpriteArray::del -----------//
00141 
00142 //--------- Begin of function SpriteArray::process ---------//
00143 void SpriteArray::process() {
00144     Sprite* spritePtr;
00145     int i;
00146     int arraySize = size();
00147 
00148     for ( i=1; i<=arraySize; i++) {
00149         spritePtr = (Sprite *) get_ptr(i);
00150         spritePtr->process();
00151     }
00152 }
00153 
00154 //----------- End of function SpriteArray::process -----------//
00155 
00156 //------- Begin of function SpriteArray::operator[] -----//
00157 #ifdef DEBUG
00158 Sprite* SpriteArray::operator[](int recNo) {
00159     Sprite* spritePtr = (Sprite*) get_ptr(recNo);
00160 
00161     if( !spritePtr )
00162         err.run( "SpriteArray[] is deleted" );
00163 
00164     return spritePtr;
00165 }
00166 #endif
00167 //--------- End of function SpriteArray::operator[] ----//

Generated on Fri Aug 23 01:38:23 2002 for VirtualU by doxygen1.2.17