From 425decdf7e9284d15aa726e3ae96b9942fb0e3ea Mon Sep 17 00:00:00 2001 From: IronClawTrem Date: Sun, 16 Feb 2020 03:40:06 +0000 Subject: create tremded branch --- src/cgame/cg_trails.c | 61 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 15 deletions(-) (limited to 'src/cgame/cg_trails.c') diff --git a/src/cgame/cg_trails.c b/src/cgame/cg_trails.c index c8943ed..c7d2662 100644 --- a/src/cgame/cg_trails.c +++ b/src/cgame/cg_trails.c @@ -1,12 +1,13 @@ /* =========================================================================== -Copyright (C) 2000-2006 Tim Angus +Copyright (C) 2000-2013 Darklegion Development +Copyright (C) 2015-2019 GrangerHub This file is part of Tremulous. Tremulous is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as -published by the Free Software Foundation; either version 2 of the License, +published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. Tremulous is distributed in the hope that it will be @@ -15,14 +16,13 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with Tremulous; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +along with Tremulous; if not, see + =========================================================================== */ // cg_trails.c -- the trail system - #include "cg_local.h" static baseTrailSystem_t baseTrailSystems[ MAX_BASETRAIL_SYSTEMS ]; @@ -60,7 +60,7 @@ static void CG_CalculateBeamNodeProperties( trailBeam_t *tb ) if( ts->destroyTime > 0 && btb->fadeOutTime ) { - fadeAlpha -= ( cg.time - ts->destroyTime ) / btb->fadeOutTime; + fadeAlpha -= (float)( cg.time - ts->destroyTime ) / btb->fadeOutTime; if( fadeAlpha < 0.0f ) fadeAlpha = 0.0f; @@ -559,7 +559,7 @@ static void CG_UpdateBeam( trailBeam_t *tb ) tb->lastEvalTime = cg.time; // first make sure this beam has enough nodes - if( ts->destroyTime <= 0 ) + if( ts->destroyTime <= 0 || btb->fadeOutTime > 0 ) { nodesToAdd = btb->numSegments - CG_CountBeamNodes( tb ) + 1; @@ -898,7 +898,7 @@ static qboolean CG_ParseTrailBeam( baseTrailBeam_t *btb, char **text_p ) { if( btb->numJitters == MAX_TRAIL_BEAM_JITTERS ) { - CG_Printf( S_COLOR_RED "ERROR: too many jitters\n", token ); + CG_Printf( S_COLOR_RED "ERROR: too many jitters\n" ); break; } @@ -1009,6 +1009,15 @@ static qboolean CG_ParseTrailSystem( baseTrailSystem_t *bts, char **text_p, cons } else if( !Q_stricmp( token, "thirdPersonOnly" ) ) bts->thirdPersonOnly = qtrue; + else if( !Q_stricmp( token, "lifeTime" ) ) + { + token = COM_Parse( text_p ); + if( !Q_stricmp( token, "" ) ) + break; + + bts->lifeTime = atoi_neg( token, qfalse ); + continue; + } else if( !Q_stricmp( token, "beam" ) ) //acceptable text continue; else if( !Q_stricmp( token, "}" ) ) @@ -1051,9 +1060,11 @@ static qboolean CG_ParseTrailFile( const char *fileName ) if( len <= 0 ) return qfalse; - if( len >= sizeof( text ) - 1 ) + if( len == 0 || len >= sizeof( text ) - 1 ) { - CG_Printf( S_COLOR_RED "ERROR: trail file %s too long\n", fileName ); + trap_FS_FCloseFile( f ); + CG_Printf( S_COLOR_RED "ERROR: trail file %s is %s\n", fileName, + len == 0 ? "empty" : "too long" ); return qfalse; } @@ -1251,11 +1262,14 @@ static trailBeam_t *CG_SpawnNewTrailBeam( baseTrailBeam_t *btb, if( cg_debugTrails.integer >= 1 ) CG_Printf( "TB %s created\n", ts->class->name ); - break; + return tb; } } - return tb; + if( cg_debugTrails.integer >= 1 ) + CG_Printf( "MAX_TRAIL_BEAMS\n" ); + + return NULL; } @@ -1291,18 +1305,22 @@ trailSystem_t *CG_SpawnNewTrailSystem( qhandle_t psHandle ) ts->valid = qtrue; ts->destroyTime = -1; - + ts->birthTime = cg.time; + for( j = 0; j < bts->numBeams; j++ ) CG_SpawnNewTrailBeam( bts->beams[ j ], ts ); if( cg_debugTrails.integer >= 1 ) CG_Printf( "TS %s created\n", bts->name ); - break; + return ts; } } - return ts; + if( cg_debugTrails.integer >= 1 ) + CG_Printf( "MAX_TRAIL_SYSTEMS\n" ); + + return NULL; } /* @@ -1406,6 +1424,19 @@ static void CG_GarbageCollectTrailSystems( void ) CG_DestroyTrailSystem( &tempTS ); } + // lifetime expired + if( ts->destroyTime <= 0 && ts->class->lifeTime && + ts->birthTime + ts->class->lifeTime < cg.time ) + { + trailSystem_t *tempTS = ts; + + CG_DestroyTrailSystem( &tempTS ); + if( cg_debugTrails.integer >= 1 ) + CG_Printf( "TS %s expired (born %d, lives %d, now %d)\n", + ts->class->name, ts->birthTime, ts->class->lifeTime, + cg.time ); + } + if( cg_debugTrails.integer >= 1 && !ts->valid ) CG_Printf( "TS %s garbage collected\n", ts->class->name ); } -- cgit