void CProjectileHandler::Update()
{
    SCOPED_TIMER("Projectile handler");

    Projectile_List::iterator psi=ps.begin();
    while(psi!= ps.end()) {
        CProjectile *p = *psi;
        if(p->deleteMe) {
            Projectile_List::iterator prev=psi++;
            ps.erase(prev);
            delete p;
        } else {
            (*psi)->Update();
            ++psi;
        }
    }

    for(unsigned int i = 0; i < groundFlashes.size();)
    {
        CGroundFlash *gf = groundFlashes[i];
        if (!gf->Update ())
        {
            // swap gf with the groundflash at the end of the list, so pop_back() can be used to erase it
            if ( i < groundFlashes.size()-1 )
                std::swap (groundFlashes.back(), groundFlashes[i]);
            groundFlashes.pop_back();
            delete gf;
        } else i++;
    }

    for(std::list<FlyingPiece_List*>::iterator pti=flyingPieces.begin(); pti!=flyingPieces.end(); ++pti) {
        FlyingPiece_List * fpl = *pti;
        /* Note: nothing in the third clause of this loop. TODO Rewrite it as a while */
        for(std::list<FlyingPiece*>::iterator pi=fpl->begin(); pi!=fpl->end();) {
            (*pi)->pos+=(*pi)->speed;
            (*pi)->speed*=0.996f;
            (*pi)->speed.y+=gs->gravity;
            (*pi)->rot+=(*pi)->rotSpeed;
            if((*pi)->pos.y<ground->GetApproximateHeight((*pi)->pos.x,(*pi)->pos.z)-10) {
                delete *pi;
                pi=fpl->erase(pi);
            } else {
                ++pi;
            }
        }
    }
}
Exemplo n.º 2
0
void CProjectileDrawer::DrawGroundFlashes()
{
	static const GLfloat black[] = {0.0f, 0.0f, 0.0f, 0.0f};

	glDepthMask(GL_FALSE);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE);
	glActiveTexture(GL_TEXTURE0);
	groundFXAtlas->BindTexture();
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_ALPHA_TEST);
	glAlphaFunc(GL_GREATER, 0.01f);
	glPolygonOffset(-20, -1000);
	glEnable(GL_POLYGON_OFFSET_FILL);
	glFogfv(GL_FOG_COLOR, black);

	{
		GML_STDMUTEX_LOCK(rflash); // DrawGroundFlashes

		ph->groundFlashes.delete_delayed();
		ph->groundFlashes.add_delayed();
	}

	CGroundFlash::va = GetVertexArray();
	CGroundFlash::va->Initialize();
	CGroundFlash::va->EnlargeArrays(8, 0, VA_SIZE_TC);

	GroundFlashContainer& gfc = ph->groundFlashes;
	GroundFlashContainer::render_iterator gfi;

	bool depthTest = true;
	bool depthMask = false;

	for (gfi = gfc.render_begin(); gfi != gfc.render_end(); ++gfi) {
		CGroundFlash* gf = *gfi;

		const bool los = gu->spectatingFullView || loshandler->InAirLos(gf->pos, gu->myAllyTeam);
		const bool vis = camera->InView(gf->pos, gf->size);

		if (depthTest != gf->depthTest) {
			depthTest = gf->depthTest;

			if (depthTest) {
				glEnable(GL_DEPTH_TEST);
			} else {
				glDisable(GL_DEPTH_TEST);
			}
		}
		if (depthMask != gf->depthMask) {
			depthMask = gf->depthMask;

			if (depthMask) {
				glDepthMask(GL_TRUE);
			} else {
				glDepthMask(GL_FALSE);
			}
		}

		if ((gf->alwaysVisible || los) && vis) {
			gf->Draw();
		}

		CGroundFlash::va->DrawArrayTC(GL_QUADS);
		CGroundFlash::va->Initialize();
	}


	glFogfv(GL_FOG_COLOR, mapInfo->atmosphere.fogColor);
	glDisable(GL_POLYGON_OFFSET_FILL);
	glDisable(GL_ALPHA_TEST);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glDisable(GL_BLEND);
	glEnable(GL_DEPTH_TEST);
	glDepthMask(GL_TRUE);
}
Exemplo n.º 3
0
void CProjectileHandler::Update()
{
	CheckCollisions();

	{
		SCOPED_TIMER("ProjectileHandler::Update");
		GML_UPDATE_TICKS();

		UpdateProjectileContainer(syncedProjectiles, true);
		UpdateProjectileContainer(unsyncedProjectiles, false);


		{
			GML_STDMUTEX_LOCK(rproj); // Update

			if (syncedProjectiles.can_delete_synced()) {
#if !DETACH_SYNCED
				GML_RECMUTEX_LOCK(proj); // Update
#endif

				eventHandler.DeleteSyncedProjectiles();
				//! delete all projectiles that were
				//! queued (push_back'ed) for deletion
#if DETACH_SYNCED
				syncedProjectiles.detach_erased_synced();
#else
				syncedProjectiles.delete_erased_synced();
#endif
			}

			eventHandler.UpdateProjectiles();
		}


		GroundFlashContainer::iterator gfi = groundFlashes.begin();
		while (gfi != groundFlashes.end()) {
			CGroundFlash* gf = *gfi;

			if (!gf->Update()) {
				gfi = groundFlashes.erase_delete(gfi);
			} else {
				++gfi;
			}
		}

		{
			GML_STDMUTEX_LOCK(rflash); // Update

			groundFlashes.delay_delete();
			groundFlashes.delay_add();
		}

		#define UPDATE_FLYING_PIECES(fpContainer)                                        \
			FlyingPieceContainer::iterator pti = fpContainer.begin();                    \
                                                                                         \
			while (pti != fpContainer.end()) {                                           \
				FlyingPiece* p = *pti;                                                   \
				p->pos     += p->speed;                                                  \
				p->speed   *= 0.996f;                                                    \
				p->speed.y += mapInfo->map.gravity; /* fp's are not projectiles */       \
				p->rot     += p->rotSpeed;                                               \
                                                                                         \
				if (p->pos.y < ground->GetApproximateHeight(p->pos.x, p->pos.z - 10)) {  \
					pti = fpContainer.erase_delete_set(pti);                             \
				} else {                                                                 \
					++pti;                                                               \
				}                                                                        \
			}

		{ UPDATE_FLYING_PIECES(flyingPieces3DO); }
		{ UPDATE_FLYING_PIECES(flyingPiecesS3O); }
		#undef UPDATE_FLYING_PIECES

		{
			GML_STDMUTEX_LOCK(rpiece); // Update

			flyingPieces3DO.delay_delete();
			flyingPieces3DO.delay_add();
			flyingPiecesS3O.delay_delete();
			flyingPiecesS3O.delay_add();
		}
	}
}
Exemplo n.º 4
0
void CProjectileHandler::Update()
{
	SCOPED_TIMER("Projectile Update");

	GML_UPDATE_TICKS();

	UpdateProjectileContainer(syncedProjectiles, true);
	UpdateProjectileContainer(unsyncedProjectiles, false);


	{
		GML_STDMUTEX_LOCK(rproj); // Update

		if (syncedProjectiles.can_delete_synced()) {
			GML_STDMUTEX_LOCK(proj); // Update

			//! delete all projectiles that were
			//! queued (push_back'ed) for deletion
			syncedProjectiles.delete_erased_synced();
		}

		//! prepare projectile batches for
		//! addition into the render queue
		syncedProjectiles.delay_add();

		unsyncedProjectiles.delay_delete();
		unsyncedProjectiles.delay_add();
	}


	GroundFlashContainer::iterator gfi = groundFlashes.begin();
	while (gfi != groundFlashes.end()) {
		CGroundFlash* gf = *gfi;

		if (!gf->Update())
			gfi = groundFlashes.erase_delete(gfi);
		else
			++gfi;
	}

	{
		GML_STDMUTEX_LOCK(rflash); // Update

		groundFlashes.delay_delete();
		groundFlashes.delay_add();
	}

	FlyingPieceContainer::iterator pti = flyingPieces.begin();
	while (pti != flyingPieces.end()) {
		FlyingPiece* p = *pti;
		p->pos     += p->speed;
		p->speed   *= 0.996f;
		p->speed.y += mapInfo->map.gravity; //! fp's are not projectiles
		p->rot     += p->rotSpeed;

		if (p->pos.y < ground->GetApproximateHeight(p->pos.x, p->pos.z - 10))
			pti = flyingPieces.erase_delete_set(pti);
		else
			++pti;
	}

	{
		GML_STDMUTEX_LOCK(rpiece); // Update

		flyingPieces.delay_delete();
		flyingPieces.delay_add();
	}
}
Exemplo n.º 5
0
void CProjectileHandler::Update()
{
	GML_RECMUTEX_LOCK(lua); // Update
	GML_RECMUTEX_LOCK(proj); // Update

	SCOPED_TIMER("Projectile handler");

	GML_UPDATE_TICKS();

	Projectile_List::iterator psi = ps.begin();
	while (psi != ps.end()) {
		CProjectile* p = *psi;

		if (p->deleteMe) {
			Projectile_List::iterator prev = psi++;
			ps.erase(prev);

			if (p->synced && p->weapon) {
				// iterator is always valid
				ProjectileMap::iterator it = weaponProjectileIDs.find(p->id);
				const ProjectileMapPair& pp = it->second;

				eventHandler.ProjectileDestroyed(pp.first, pp.second);
				weaponProjectileIDs.erase(it);
				if (p->id != 0) {
					freeIDs.push_back(p->id);
				}
			}

			delete p;
		} else {
			p->Update();
			GML_GET_TICKS(p->lastProjUpdate);
			++psi;
		}
	}

	for (unsigned int i = 0; i < groundFlashes.size(); /* do nothing */) {
		CGroundFlash *gf = groundFlashes[i];
		if (!gf->Update ()) {
			// swap gf with the groundflash at the end of the list, so pop_back() can be used to erase it
			if (i < groundFlashes.size() - 1) {
				std::swap(groundFlashes.back(), groundFlashes[i]);
			}
			groundFlashes.pop_back();
			delete gf;
		} else {
			i++;
		}
	}

	for (list<FlyingPiece_List*>::iterator pti = flyingPieces.begin(); pti != flyingPieces.end(); ++pti) {
		FlyingPiece_List* fpl = *pti;
		FlyingPiece_List::iterator pi = fpl->begin();
		while ( pi != fpl->end() ) {
			FlyingPiece* p = *pi;
			p->pos     += p->speed;
			p->speed   *= 0.996f;
			p->speed.y += mapInfo->map.gravity;
			p->rot     += p->rotSpeed;

			if (p->pos.y < ground->GetApproximateHeight(p->pos.x, p->pos.z - 10)) {
				if (p->verts != NULL){
					delete[] p->verts;
				}
				delete p;
				pi = fpl->erase(pi);
			} else {
				++pi;
			}
		}
	}
}