/*
===================
CG_AddLocalEntities

===================
*/
void CG_AddLocalEntities( void ) 
{
	localEntity_t	*le, *next;

	// walk the list backwards, so any new local entities generated
	// (trails, marks, etc) will be present this frame
	le = cg_activeLocalEntities.prev;
	for ( ; le != &cg_activeLocalEntities ; le = next ) {
		// grab next now, so if the local entity is freed we
		// still have it
		next = le->prev;

		if ( cg.time >= le->endTime ) {
			CG_FreeLocalEntity( le );
			continue;
		}
		switch ( le->leType ) {
		default:
			CG_Error( "Bad leType: %i", le->leType );
			break;

		case LE_MARK:
			break;

		case LE_FADE_MODEL:
			CG_AddFadeModel( le );
			break;

		case LE_FADE_SCALE_MODEL:
			CG_AddFadeScaleModel( le );
			break;

		case LE_FRAGMENT:
			CG_AddFragment( le );
			break;

		case LE_PUFF:
			CG_AddPuff( le );
			break;

		case LE_FADE_RGB:		// teleporters, railtrails
			CG_AddFadeRGB( le );
			break;

		case LE_LIGHT:
			CG_AddLocalLight( le );
			break;

		case LE_LINE:					// oriented lines for FX
			CG_AddLine( le );
			break;

		// Use for debug only
		case LE_QUAD:
			CG_AddQuad( le );
			break;

		case LE_SPRITE:
			CG_AddSprite( le );
		}
	}
}
/*
===================
CG_AddLocalEntities

===================
*/
void CG_AddLocalEntities( void ) {
	localEntity_t	*le, *next;

	// walk the list backwards, so any new local entities generated
	// (trails, marks, etc) will be present this frame
	le = cg_activeLocalEntities.prev;
	for ( ; le != &cg_activeLocalEntities ; le = next ) {
		// grab next now, so if the local entity is freed we
		// still have it
		next = le->prev;

		if ( cg.time >= le->endTime ) {
			CG_FreeLocalEntity( le );
			continue;
		}

		if (le->leFlags & LEF_ONE_FRAME)
		{	// If this flag is set, only render one single frame, no more.
			if (le->leFlags & LEF_ONE_FRAME_DONE) 
			{
				CG_FreeLocalEntity( le );
				continue;
			}
			else
			{
				le->leFlags |= LEF_ONE_FRAME_DONE;
			}
		}

		switch ( le->leType ) {
		default:
			CG_Error( "Bad leType: %i", le->leType );
			break;

		case LE_MARK:
			break;

		case LE_SPRITE_EXPLOSION:
			CG_AddSpriteExplosion( le );
			break;

		case LE_EXPLOSION:
			CG_AddExplosion( le );
			break;

		case LE_MOVE_SCALE_FADE:		// water bubbles
			CG_AddMoveScaleFade( le );
			break;

		case LE_FADE_RGB:				// teleporters, railtrails
			CG_AddFadeRGB( le );
			break;

		case LE_FALL_SCALE_FADE: // gib blood trails
			CG_AddFallScaleFade( le );
			break;

		case LE_SCALE_FADE:		// rocket trails
			CG_AddScaleFade( le );
			break;

		case LE_SCALE_FADE_SPRITE:		// Trek type for oriented poly sprites.
			CG_AddScaleFadeSprite( le );
			break;

		case LE_LINE:					// Trek type for beams.
			CG_AddLine( le );
			break;

		case LE_LINE2:					// Trek type for beams, with taper support.
			CG_AddLine2( le );
			break;

		case LE_OLINE:					// Trek type for rectangles
			CG_AddOLine( le );
			break;

		case LE_TRAIL:					// Trek type for sparks.
			CG_AddTrail( le );
			break;

		case LE_VIEWSPRITE:				// Trek primitive for camera-facing sprites.
			CG_AddViewSprite( le );
			break;

		case LE_BEZIER:
			CG_AddBezier( le );
			break;

		case LE_QUAD:
			CG_AddQuad( le );
			break;

		case LE_CYLINDER:
			CG_AddCylinder(le);
			break;

		case LE_ELECTRICITY:
			CG_AddElectricity(le);
			break;

		case LE_PARTICLE:
			CG_AddParticle(le);
			break;

		case LE_SPAWNER:
			CG_AddSpawner(le);
			break;

		case LE_FRAGMENT:
			CG_AddFragment(le);
			break;

		case LE_STASISDOOR:
			if(le->refEntity.data.cylinder.wrap) {
				le->refEntity.shaderRGBA[3] = (1 - (le->endTime - cg.time)/1000) * 255;
			} else {
				le->refEntity.shaderRGBA[3] = ((le->endTime - cg.time)/1000) * 255;
			}
			trap_R_AddRefEntityToScene(&le->refEntity);
			break;
		}
	}
}