Example #1
0
static void UnLoad() {
  DeleteSprite(left[0]);
  DeleteSprite(left[1]);
  DeleteSprite(right[0]);
  DeleteSprite(right[1]);
  DeleteBitmap(twister);
  DeletePixmap(texture);
  DeletePalette(gradient);
}
Example #2
0
static void UnLoad() {
  DeleteSprite(sprite[0]);
  DeleteSprite(sprite[1]);
  DeleteSprite(sprite[2]);
  DeleteCopList(cp);
  DeletePalette(bitmap->palette);
  DeleteBitmap(bitmap);
  DeleteBitmap(screen);
}
Example #3
0
/**\brief SpriteManager update function.
 */
void SpriteManager::Update() {
	// Update the sprites inside each quadrant
	// TODO: Update only the sprites that are in nearby Quadrants
	list<Sprite *> all_oob;
	list<QuadTree*> nearby = GetQuadrantsNear( Camera::Instance()->GetFocusCoordinate(), QUADRANTSIZE*4 );
	list<QuadTree*>::iterator iter;
	for ( iter = nearby.begin(); iter != nearby.end(); ++iter ) {
		(*iter)->Update();
		list<Sprite *>* oob = (*iter)->FixOutOfBounds();
		all_oob.splice(all_oob.end(), *oob );
		delete oob;
	}

	// Move sprites to adjacent Quadrants as they cross boundaries
	list<Sprite *>::iterator i;
	for( i = all_oob.begin(); i != all_oob.end(); ++i ) {
		GetQuadrant( (*i)->GetWorldPosition() )->Insert( *i );
	}

	//Delete all sprites queued to be deleted
	if (!spritesToDelete.empty()) {
		spritesToDelete.unique();
		for( i = spritesToDelete.begin(); i != spritesToDelete.end(); ++i ) {
			DeleteSprite(*i);
		}
		spritesToDelete.clear();
	}

	for ( iter = nearby.begin(); iter != nearby.end(); ++iter ) {
		(*iter)->ReBallance();
	}

	DeleteEmptyQuadrants();
}
Example #4
0
// Remove every sprite (planet, AI ship, projectile, effect, etc.) except the player's sprite
void SpriteManager::DeleteAllExceptPlayer( void ) {
	list<Sprite *>::iterator i;

	for( i = spritelist->begin(); i != spritelist->end(); ++i ) {
		Sprite *s = (*i);
		if( s->GetDrawOrder() != DRAW_ORDER_PLAYER ) {
			DeleteSprite( s );
			i = spritelist->begin(); // TODO: spritelist->remove() is called which ... makes this necessary? Right?
		}
	}
}
Example #5
0
// Removes all sprites matching type 'type'
void SpriteManager::DeleteByType( int type ) {
	list<Sprite *>::iterator i;

	for( i = spritelist->begin(); i != spritelist->end(); ++i ) {
		Sprite *s = (*i);
		if( s->GetDrawOrder() == type ) {
			DeleteSprite( s );
			i = spritelist->begin(); // TODO: spritelist->remove() is called which ... makes this necessary? Right?
		}
	}
}
void ResourceManager::Destroy()
{
    DeleteSprite();
    CursorCleanUp();

    SkyBoxCleanUp();
    DeleteMap();

    for ( auto& toBeDelete : m_MeshArray )
    {
        if ( toBeDelete )
        {
            DeleteMesh( toBeDelete->m_MeshObject );
            SafeDelete( toBeDelete->m_MeshObject );
            delete toBeDelete;
        }
    }
    for ( auto& toBeDelete : m_HeightMapArray )
    {
        SafeDelete( toBeDelete );
    }
}
Example #7
0
/**\brief SpriteManager update function.
 * \details Update the sprites inside each quadrant
 * \param lowFps If true, forces the wave-update method to be used rather than the full-update
 */
void SpriteManager::Update( lua_State *L, bool lowFps) {
	//this will contain every quadrant that we will potentially want to update
	list<QuadTree*> quadList;
	
	//if update-all is given then we update every quadrant
	//we do the same if tickCount == 0 even if update-all is not given
	// (in wave update mode, tickCount == 0 is when we want to update all quadrants)
	if( ! lowFps || tickCount == 0) {
		//need to get all of the quadrants in our map
		GetAllQuadrants(&quadList);
	}
	else
	{
		//wave update mode with tickCount != 0 -- update some quadrants
		Camera* camera = Simulation_Lua::GetSimulation(L)->GetCamera();
		Coordinate currentPoint (camera->GetFocusCoordinate());	//always update centered on where we're at

		quadList.push_back (GetQuadrant (currentPoint)); //we ALWAYS update the current quadrant

		//we also ALWAYS update the 'regular' bands
		//	the first band is at index 1 - index 0 would be the single quadrant in the middle
		//	when we get the list of quadrants back we splice them onto the end of our overall list
		for (int i = 1; i <= numRegularBands; i ++) {
			list<QuadTree*> tempBandList = GetQuadrantsInBand (currentPoint, i);
			quadList.splice (quadList.end(), tempBandList);
		}

		//now - we SOMETIMES update the semi-regular bands
		//   the ticks that each band is updated in is stored in the map
		//   so we get our semiRegular update modulus of the ticks and then check the map
		//    - the map has the tick index as the key and the band to update as the value
		int semiRegularTick = tickCount % semiRegularPeriod;
		map<int,int>::iterator findBand = ticksToBandNum.find (semiRegularTick);
		if (findBand != ticksToBandNum.end()) {		//found the key
			//cout << "tick = " << tickCount << ", semiRegularTick = " << semiRegularTick << ", band = " << findBand->second << endl;
			list<QuadTree*> tempBandList = GetQuadrantsInBand (currentPoint, findBand->second);
			quadList.splice (quadList.end(), tempBandList);
		}
		else {
			//no semi-regular bands to update at this tick, do nothing
		}
	}

	// Find and Fix any Sprites that have moved out of bounds.
	list<Sprite *> all_oob;
	list<QuadTree*>::iterator iter;
	for ( iter = quadList.begin(); iter != quadList.end(); ++iter ) {
		(*iter)->Update(L);
		list<Sprite *>* oob = (*iter)->FixOutOfBounds();
		all_oob.splice(all_oob.end(), *oob );
		delete oob;
	}

	// Move sprites to adjacent Quadrants as they cross boundaries
	list<Sprite *>::iterator i;
	for( i = all_oob.begin(); i != all_oob.end(); ++i ) {
		GetQuadrant( (*i)->GetWorldPosition() )->Insert( *i );
	}

	// Delete all sprites queued to be deleted
	if (!spritesToDelete.empty()) {
		spritesToDelete.sort(); // The list has to be sorted or unique doesn't work correctly.
		spritesToDelete.unique();
	
		// Tell the AI that they've been killed
		for( i = spritesToDelete.begin(); i != spritesToDelete.end(); ++i ) {
			if( (*i)->GetDrawOrder() == DRAW_ORDER_SHIP ) {
				((AI*)(*i))->Killed(L);
			}
		}

		for( i = spritesToDelete.begin(); i != spritesToDelete.end(); ++i ) {
			DeleteSprite(*i);
		}
		spritesToDelete.clear();
	}

	for ( iter = quadList.begin(); iter != quadList.end(); ++iter ) {
		(*iter)->ReBallance();
	}

	DeleteEmptyQuadrants();

	// Update the tick count after all updates for this tick are done
	UpdateTickCount ();
}
Example #8
0
void Sprites::Draw()
{
	static int i,j,k;
	static float M[16];
	static XYZ point;
	static float distancemult;
	static int lasttype;
	static int lastspecial;
	static int whichpatchx,whichpatchz;
	static XYZ start,end,colpoint;
	static bool check;
	static bool blend;
	static float tempmult;
	static XYZ difference;
	static float lightcolor[3];
	static float viewdistsquared=viewdistance*viewdistance;
	static XYZ tempviewer;

	tempviewer=viewer+viewerfacing*6;
	check=0;

	lightcolor[0]=light.color[0]*.5+light.ambient[0];
	lightcolor[1]=light.color[1]*.5+light.ambient[1];
	lightcolor[2]=light.color[2]*.5+light.ambient[2];

	checkdelay-=multiplier*10;

	if(checkdelay<=0){
		check=1;
		checkdelay=1;
	}

	lasttype=-1;
	lastspecial=-1;
	glEnable(GL_BLEND);
	glDisable(GL_LIGHTING);
	glDisable(GL_CULL_FACE);
	glEnable(GL_TEXTURE_2D);
	blend = 1;
	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
	glDepthMask(0);
	glAlphaFunc(GL_GREATER, 0.0001);
	for(i=0;i<numsprites;i++){
		if(type[i]==cloudsprite&&lasttype!=type[i]){
			glBindTexture( GL_TEXTURE_2D, cloudtexture);
			if(!blend){
				blend=1;
				glAlphaFunc(GL_GREATER, 0.0001);
				glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
			}
		}
		if(type[i]==cloudimpactsprite&&lasttype!=type[i]){
			glBindTexture( GL_TEXTURE_2D, cloudimpacttexture);
			if(!blend){
				blend=1;
				glAlphaFunc(GL_GREATER, 0.0001);
				glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
			}
		}
		if(type[i]==breathsprite&&lasttype!=type[i]){
			glBindTexture( GL_TEXTURE_2D, cloudimpacttexture);
			if(!blend){
				blend=1;
				glAlphaFunc(GL_GREATER, 0.0001);
				glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
			}
		}
		if(type[i]==smoketype&&lasttype!=type[i]){
			glBindTexture( GL_TEXTURE_2D, smoketexture);
			if(!blend){
				blend=1;
				glAlphaFunc(GL_GREATER, 0.0001);
				glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
			}
		}
		if(type[i]==bloodsprite&&lasttype!=type[i]){
			glBindTexture( GL_TEXTURE_2D, bloodtexture);
			if(!blend){
				blend=1;
				glAlphaFunc(GL_GREATER, 0.0001);
				glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
			}
		}
		if(type[i]==splintersprite&&(lasttype!=type[i]||lastspecial!=special[i])){
			if(special[i]==0)glBindTexture( GL_TEXTURE_2D, splintertexture);
			if(special[i]==1)glBindTexture( GL_TEXTURE_2D, leaftexture);
			if(special[i]==2)glBindTexture( GL_TEXTURE_2D, snowflaketexture);
			if(special[i]==3)glBindTexture( GL_TEXTURE_2D, toothtexture);
			if(!blend){
				blend=1;
				glAlphaFunc(GL_GREATER, 0.0001);
				glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
			}
		}
		if(type[i]==snowsprite&&lasttype!=type[i]){
			glBindTexture( GL_TEXTURE_2D, snowflaketexture);
			if(!blend){
				blend=1;
				glAlphaFunc(GL_GREATER, 0.0001);
				glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
			}
		}
		if(type[i]==weaponshinesprite&&lasttype!=type[i]){
			glBindTexture( GL_TEXTURE_2D, shinetexture);
			if(blend){
				blend=0;
				glAlphaFunc(GL_GREATER, 0.001);
				glBlendFunc(GL_SRC_ALPHA,GL_ONE);
			}
		}
		if((type[i]==flamesprite||type[i]==weaponflamesprite)&&lasttype!=type[i]){
			glBindTexture( GL_TEXTURE_2D, flametexture);
			if(blend||lasttype==bloodflamesprite){
				blend=0;
				glAlphaFunc(GL_GREATER, 0.3);
				glBlendFunc(GL_SRC_ALPHA,GL_ONE);
			}
		}
		if((type[i]==bloodflamesprite)&&lasttype!=type[i]){
			glBindTexture( GL_TEXTURE_2D, bloodflametexture);
			if(blend){
				blend=0;
				glAlphaFunc(GL_GREATER, 0.3);
				glBlendFunc(GL_ONE,GL_ZERO);
				//glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
			}
		}
		if(type[i]!=snowsprite)distancemult=(viewdistsquared-(findDistancefast(&viewer,&position[i])-(viewdistsquared*fadestart))*(1/(1-fadestart)))/viewdistsquared;
		if(type[i]==snowsprite)distancemult=(144-(findDistancefast(&tempviewer,&position[i])-(144*fadestart))*(1/(1-fadestart)))/144;
		if(type[i]!=flamesprite){
			if(distancemult>=1)glColor4f(color[i][0]*lightcolor[0],color[i][1]*lightcolor[1],color[i][2]*lightcolor[2],opacity[i]);
			if(distancemult<1)glColor4f(color[i][0]*lightcolor[0],color[i][1]*lightcolor[1],color[i][2]*lightcolor[2],opacity[i]*distancemult);
		}
		if(type[i]==flamesprite){
			if(distancemult>=1)glColor4f(color[i][0],color[i][1],color[i][2],opacity[i]);
			if(distancemult<1)glColor4f(color[i][0],color[i][1],color[i][2],opacity[i]*distancemult);
		}
		lasttype=type[i];
		lastspecial=special[i];
		glMatrixMode(GL_MODELVIEW);							// Select The Modelview Matrix
		glPushMatrix();
			glTranslatef(position[i].x,position[i].y,position[i].z);
			if((type[i]==flamesprite||type[i]==weaponflamesprite||type[i]==weaponshinesprite)){
				difference=viewer-position[i];
				Normalise(&difference);
				glTranslatef(difference.x*size[i]/4, difference.y*size[i]/4, difference.z*size[i]/4);
			}
			if(type[i]==snowsprite){
				glRotatef(rotation[i]*.2,0,.3,1);
				glTranslatef(1,0,0);
			}
			glGetFloatv(GL_MODELVIEW_MATRIX,M);
			point.x=M[12];
			point.y=M[13];
			point.z=M[14];
			glLoadIdentity();
			glTranslatef(point.x, point.y, point.z);

			glRotatef(rotation[i],0,0,1);

			if((type[i]==flamesprite||type[i]==weaponflamesprite||type[i]==weaponshinesprite||type[i]==bloodflamesprite)){
				if(alivetime[i]<.14)glScalef(alivetime[i]/.14,alivetime[i]/.14,alivetime[i]/.14);
			}
			if(type[i]==smoketype||type[i]==snowsprite||type[i]==weaponshinesprite||type[i]==breathsprite){
				if(alivetime[i]<.3){
					if(distancemult>=1)glColor4f(color[i][0]*lightcolor[0],color[i][1]*lightcolor[1],color[i][2]*lightcolor[2],opacity[i]*alivetime[i]/.3);
					if(distancemult<1)glColor4f(color[i][0]*lightcolor[0],color[i][1]*lightcolor[1],color[i][2]*lightcolor[2],opacity[i]*distancemult*alivetime[i]/.3);
				}
			}
			if(type[i]==splintersprite&&special[i]>0&&special[i]!=3){
				if(alivetime[i]<.2){
					if(distancemult>=1)glColor4f(color[i][0]*lightcolor[0],color[i][1]*lightcolor[1],color[i][2]*lightcolor[2],alivetime[i]/.2);
					if(distancemult<1)glColor4f(color[i][0]*lightcolor[0],color[i][1]*lightcolor[1],color[i][2]*lightcolor[2],distancemult*alivetime[i]/.2);
				}
				else{
					if(distancemult>=1)glColor4f(color[i][0]*lightcolor[0],color[i][1]*lightcolor[1],color[i][2]*lightcolor[2],1);
					if(distancemult<1)glColor4f(color[i][0]*lightcolor[0],color[i][1]*lightcolor[1],color[i][2]*lightcolor[2],1);
				}
			}
			if(type[i]==splintersprite&&(special[i]==0||special[i]==3)){
				if(distancemult>=1)glColor4f(color[i][0]*lightcolor[0],color[i][1]*lightcolor[1],color[i][2]*lightcolor[2],1);
				if(distancemult<1)glColor4f(color[i][0]*lightcolor[0],color[i][1]*lightcolor[1],color[i][2]*lightcolor[2],1);
			}
			/*
			if(type[i]==snowsprite){
			glRotatef(rotation[i],0,0,1);
			glTranslatef(1,0,0);
			}*/

			glBegin(GL_TRIANGLES);
			glTexCoord2f(1.0f, 1.0f); glVertex3f( .5*size[i], .5*size[i], 0.0f);
			glTexCoord2f(0.0f, 1.0f); glVertex3f(-.5*size[i], .5*size[i], 0.0f);
			glTexCoord2f(1.0f, 0.0f); glVertex3f( .5*size[i],-.5*size[i], 0.0f);
			glTexCoord2f(0.0f, 0.0f); glVertex3f(-.5*size[i],-.5*size[i], 0.0f);
			glTexCoord2f(1.0f, 0.0f); glVertex3f( .5*size[i], -.5*size[i], 0.0f);
			glTexCoord2f(0.0f, 1.0f); glVertex3f(-.5*size[i], .5*size[i], 0.0f);
			glEnd();
		glPopMatrix();
	}
	tempmult=multiplier;
	for(i=numsprites-1;i>=0;i--){
		multiplier=tempmult;
		if(type[i]!=snowsprite)position[i]+=velocity[i]*multiplier;
		if(type[i]!=snowsprite)velocity[i]+=windvector*multiplier;
		if(type[i]==flamesprite||type[i]==smoketype)position[i]+=windvector*multiplier/2;
		if((type[i]==flamesprite||type[i]==weaponflamesprite||type[i]==weaponshinesprite||type[i]==bloodflamesprite))multiplier*=speed[i]*.7;
		alivetime[i]+=multiplier;

		if(type[i]==cloudsprite||type[i]==cloudimpactsprite){
			opacity[i]-=multiplier/2;
			size[i]+=multiplier/2;
			velocity[i].y+=gravity*multiplier*.25;
		}
		if(type[i]==breathsprite){
			opacity[i]-=multiplier/2;
			size[i]+=multiplier/2;
			if(findLength(&velocity[i])<=multiplier)velocity[i]=0;
			else{
				XYZ slowdown;
				slowdown=velocity[i]*-1;
				Normalise(&slowdown);
				slowdown*=multiplier;
				velocity[i]+=slowdown;
			}
		}
		if(type[i]==snowsprite){
			size[i]-=multiplier/120;
			rotation[i]+=multiplier*360;
			position[i].y-=multiplier;
			position[i]+=windvector*multiplier;
			if(position[i].y<tempviewer.y-6)position[i].y+=12;
			if(position[i].y>tempviewer.y+6)position[i].y-=12;
			if(position[i].z<tempviewer.z-6)position[i].z+=12;
			if(position[i].z>tempviewer.z+6)position[i].z-=12;
			if(position[i].x<tempviewer.x-6)position[i].x+=12;
			if(position[i].x>tempviewer.x+6)position[i].x-=12;
		}
		if(type[i]==bloodsprite){
			bool spritehit=0;
			rotation[i]+=multiplier*100;
			velocity[i].y+=gravity*multiplier;
			if(check){
				XYZ where,startpoint,endpoint,movepoint,footpoint;
				float rotationpoint;
				int whichtri;

				for(j=0;j<numplayers;j++){
					if(!spritehit&&player[j].dead&&alivetime[i]>.1){
						where=oldposition[i];
						where-=player[j].coords;
						if(!player[j].skeleton.free)where=DoRotation(where,0,-player[j].rotation,0);
						startpoint=where;
						where=position[i];
						where-=player[j].coords;
						if(!player[j].skeleton.free)where=DoRotation(where,0,-player[j].rotation,0);
						endpoint=where;

						movepoint=0;
						rotationpoint=0;
						whichtri=player[j].skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &footpoint, &movepoint, &rotationpoint);
						if(whichtri!=-1){
							spritehit=1;
							player[j].DoBloodBigWhere(0,160,oldposition[i]);
							DeleteSprite(i);
						}
					}
				}

				whichpatchx=position[i].x/(terrain.size/subdivision*terrain.scale*terraindetail);
				whichpatchz=position[i].z/(terrain.size/subdivision*terrain.scale*terraindetail);
				if(whichpatchx>0&&whichpatchz>0&&whichpatchx<subdivision&&whichpatchz<subdivision)
					if(terrain.patchobjectnum[whichpatchx][whichpatchz]){
						if(!spritehit)
							for(j=0;j<terrain.patchobjectnum[whichpatchx][whichpatchz];j++){
								k=terrain.patchobjects[whichpatchx][whichpatchz][j];
								start=oldposition[i];
								end=position[i];
								if(!spritehit)
									if(objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k])!=-1){
										if(detail==2||(detail==1&&abs(Random()%4)==0)||(detail==0&&abs(Random()%8)==0))objects.model[k].MakeDecal(blooddecalfast,DoRotation(colpoint-objects.position[k],0,-objects.rotation[k],0),size[i]*1.6/*+abs((float)(Random()%100))/2400*/,.5,Random()%360);
										DeleteSprite(i);
										spritehit=1;
									}	
							}
					}
					if(!spritehit)
						if(position[i].y<terrain.getHeight(position[i].x,position[i].z)){
							terrain.MakeDecal(blooddecalfast,position[i],size[i]*1.6/*+abs((float)(Random()%100))/2400*/,.6,Random()%360);
							DeleteSprite(i);
						}
			}
		}
		if(type[i]==splintersprite){
			rotation[i]+=rotatespeed[i]*multiplier;
			opacity[i]-=multiplier/2;
			if(special[i]==0||special[i]==2||special[i]==3)velocity[i].y+=gravity*multiplier;
			if(special[i]==1)velocity[i].y+=gravity*multiplier*.5;
		}
		if(type[i]==flamesprite||type[i]==weaponflamesprite||type[i]==weaponshinesprite||type[i]==bloodflamesprite){
			rotation[i]+=multiplier*rotatespeed[i];
			opacity[i]-=multiplier*5/4;
			if(type[i]!=weaponshinesprite&&type[i]!=bloodflamesprite)
				if(opacity[i]<.5&&opacity[i]+multiplier*5/4>=.5&&(abs(Random()%4)==0||(initialsize[i]>2&&Random()%2==0)))MakeSprite(smoketype, position[i],velocity[i], .9,.9,.6, size[i]*1.2, .4);
			if(alivetime[i]>.14&&(type[i]==flamesprite)){
				velocity[i]=0;
				velocity[i].y=1.5;
			}
		}
		/*if(type[i]==smoketype){
		opacity[i]-=multiplier/3/initialsize[i];
		size[i]+=multiplier;
		velocity[i]=0;
		velocity[i].y=1.5;
		rotation[i]+=multiplier*rotatespeed[i]/5;
		}*/
		if(type[i]==smoketype){
			opacity[i]-=multiplier/3/initialsize[i];
			color[i][0]-=multiplier;
			color[i][1]-=multiplier;
			color[i][2]-=multiplier;
			if(color[i][0]<.6)color[i][0]=.6;
			if(color[i][1]<.6)color[i][1]=.6;
			if(color[i][2]<.6)color[i][2]=.6;
			size[i]+=multiplier;
			velocity[i]=0;
			velocity[i].y=1.5;
			rotation[i]+=multiplier*rotatespeed[i]/5;
		}
		if(opacity[i]<=0||size[i]<=0)DeleteSprite(i);
	}
	if(check)
		for(i=numsprites-1;i>=0;i--){
			oldposition[i]=position[i];
		}
		glAlphaFunc(GL_GREATER, 0.0001);
		glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
}
Example #9
0
static void UnLoad() {
  DeleteSprite(pointer);
  DeleteSprite(nullspr);
  DeleteCopList(cp);
  DeleteBitmap(screen);
}