/* =============== CG_ParseColor =============== */ bool CG_ParseColor( byte *c, const char **text_p ) { char *token; int i; for ( i = 0; i <= 2; i++ ) { token = COM_Parse( text_p ); if ( !*token ) { return false; } c[ i ] = ( int )( ( float ) 0xFF * atof_neg( token, false ) ); } token = COM_Parse( text_p ); if ( strcmp( token, "}" ) ) { CG_Printf( S_ERROR "missing '}'\n" ); return false; } return true; }
/* =============== CG_ParseTrailBeamColor =============== */ static bool CG_ParseTrailBeamColor( byte *c, char **text_p ) { char *token; int i; for( i = 0; i <= 2; i++ ) { token = COM_Parse( text_p ); if( !Q_stricmp( token, "" ) ) return false; c[ i ] = (int)( (float)0xFF * atof_neg( token, false ) ); } return true; }
/* =============== CG_ParseTrailBeam Parse a trail beam =============== */ static bool CG_ParseTrailBeam( baseTrailBeam_t *btb, const char **text_p ) { char *token; // read optional parameters while ( 1 ) { token = COM_Parse( text_p ); if ( !*token ) { return false; } if ( !Q_stricmp( token, "segments" ) ) { token = COM_Parse( text_p ); if ( !*token ) { break; } btb->numSegments = atoi_neg( token, false ); if ( btb->numSegments >= MAX_TRAIL_BEAM_NODES ) { btb->numSegments = MAX_TRAIL_BEAM_NODES - 1; Log::Warn( "too many segments in trail beam" ); } continue; } else if ( !Q_stricmp( token, "width" ) ) { token = COM_Parse( text_p ); if ( !*token ) { break; } btb->frontWidth = atof_neg( token, false ); token = COM_Parse( text_p ); if ( !*token ) { break; } if ( !Q_stricmp( token, "-" ) ) { btb->backWidth = btb->frontWidth; } else { btb->backWidth = atof_neg( token, false ); } continue; } else if ( !Q_stricmp( token, "alpha" ) ) { token = COM_Parse( text_p ); if ( !*token ) { break; } btb->frontAlpha = atof_neg( token, false ); token = COM_Parse( text_p ); if ( !*token ) { break; } if ( !Q_stricmp( token, "-" ) ) { btb->backAlpha = btb->frontAlpha; } else { btb->backAlpha = atof_neg( token, false ); } continue; } else if ( !Q_stricmp( token, "color" ) ) { token = COM_Parse( text_p ); if ( !*token ) { break; } if ( !Q_stricmp( token, "{" ) ) { if ( !CG_ParseColor( btb->frontColor, text_p ) ) { break; } token = COM_Parse( text_p ); if ( !*token ) { break; } if ( !Q_stricmp( token, "-" ) ) { btb->backColor[ 0 ] = btb->frontColor[ 0 ]; btb->backColor[ 1 ] = btb->frontColor[ 1 ]; btb->backColor[ 2 ] = btb->frontColor[ 2 ]; } else if ( !Q_stricmp( token, "{" ) ) { if ( !CG_ParseColor( btb->backColor, text_p ) ) { break; } } else { Log::Warn( "missing '{'" ); break; } } else { Log::Warn( "missing '{'" ); break; } continue; } else if ( !Q_stricmp( token, "segmentTime" ) ) { token = COM_Parse( text_p ); if ( !*token ) { break; } btb->segmentTime = atoi_neg( token, false ); continue; } else if ( !Q_stricmp( token, "fadeOutTime" ) ) { token = COM_Parse( text_p ); if ( !*token ) { break; } btb->fadeOutTime = atoi_neg( token, false ); continue; } else if ( !Q_stricmp( token, "shader" ) ) { token = COM_Parse( text_p ); if ( !*token ) { break; } Q_strncpyz( btb->shaderName, token, MAX_QPATH ); continue; } else if ( !Q_stricmp( token, "textureType" ) ) { token = COM_Parse( text_p ); if ( !*token ) { break; } if ( !Q_stricmp( token, "stretch" ) ) { btb->textureType = TBTT_STRETCH; token = COM_Parse( text_p ); if ( !*token ) { break; } btb->frontTextureCoord = atof_neg( token, false ); token = COM_Parse( text_p ); if ( !*token ) { break; } btb->backTextureCoord = atof_neg( token, false ); } else if ( !Q_stricmp( token, "repeat" ) ) { btb->textureType = TBTT_REPEAT; token = COM_Parse( text_p ); if ( !*token ) { break; } if ( !Q_stricmp( token, "front" ) ) { btb->clampToBack = false; } else if ( !Q_stricmp( token, "back" ) ) { btb->clampToBack = true; } else { Log::Warn( "unknown textureType clamp \"%s\"", token ); break; } token = COM_Parse( text_p ); if ( !*token ) { break; } btb->repeatLength = atof_neg( token, false ); } else { Log::Warn( "unknown textureType \"%s\"", token ); break; } continue; } else if ( !Q_stricmp( token, "realLight" ) ) { btb->realLight = true; continue; } else if ( !Q_stricmp( token, "jitter" ) ) { if ( btb->numJitters == MAX_TRAIL_BEAM_JITTERS ) { Log::Warn( "too many jitters" ); break; } token = COM_Parse( text_p ); if ( !*token ) { break; } btb->jitters[ btb->numJitters ].magnitude = atof_neg( token, false ); token = COM_Parse( text_p ); if ( !*token ) { break; } btb->jitters[ btb->numJitters ].period = atoi_neg( token, false ); btb->numJitters++; continue; } else if ( !Q_stricmp( token, "jitterAttachments" ) ) { btb->jitterAttachments = true; continue; } else if ( !Q_stricmp( token, "dynamicLight" ) ) { btb->dynamicLight = true; token = COM_Parse( text_p ); if ( !*token ) { break; } btb->dLightRadius = atof( token ); token = COM_Parse( text_p ); if ( !*token ) { break; } if ( !Q_stricmp( token, "{" ) ) { if ( !CG_ParseColor( btb->dLightColor, text_p ) ) { break; } } } else if ( !Q_stricmp( token, "}" ) ) { return true; //reached the end of this trail beam } else { Log::Warn( "unknown token '%s' in trail beam", token ); return false; } } return false; }
/* =============== CG_ParseTrailBeam Parse a trail beam =============== */ static bool CG_ParseTrailBeam( baseTrailBeam_t *btb, char **text_p ) { char *token; // read optional parameters while( 1 ) { token = COM_Parse( text_p ); if( !Q_stricmp( token, "" ) ) return false; if( !Q_stricmp( token, "segments" ) ) { token = COM_Parse( text_p ); if( !Q_stricmp( token, "" ) ) break; btb->numSegments = atoi_neg( token, false ); if( btb->numSegments >= MAX_TRAIL_BEAM_NODES ) { btb->numSegments = MAX_TRAIL_BEAM_NODES - 1; CG_Printf( S_COLOR_YELLOW "WARNING: too many segments in trail beam\n" ); } continue; } else if( !Q_stricmp( token, "width" ) ) { token = COM_Parse( text_p ); if( !Q_stricmp( token, "" ) ) break; btb->frontWidth = atof_neg( token, false ); token = COM_Parse( text_p ); if( !Q_stricmp( token, "" ) ) break; if( !Q_stricmp( token, "-" ) ) btb->backWidth = btb->frontWidth; else btb->backWidth = atof_neg( token, false ); continue; } else if( !Q_stricmp( token, "alpha" ) ) { token = COM_Parse( text_p ); if( !Q_stricmp( token, "" ) ) break; btb->frontAlpha = atof_neg( token, false ); token = COM_Parse( text_p ); if( !Q_stricmp( token, "" ) ) break; if( !Q_stricmp( token, "-" ) ) btb->backAlpha = btb->frontAlpha; else btb->backAlpha = atof_neg( token, false ); continue; } else if( !Q_stricmp( token, "color" ) ) { token = COM_Parse( text_p ); if( !Q_stricmp( token, "" ) ) break; if( !Q_stricmp( token, "{" ) ) { if( !CG_ParseTrailBeamColor( btb->frontColor, text_p ) ) break; token = COM_Parse( text_p ); if( Q_stricmp( token, "}" ) ) { CG_Printf( S_COLOR_RED "ERROR: missing '}'\n" ); break; } token = COM_Parse( text_p ); if( !Q_stricmp( token, "" ) ) break; if( !Q_stricmp( token, "-" ) ) { btb->backColor[ 0 ] = btb->frontColor[ 0 ]; btb->backColor[ 1 ] = btb->frontColor[ 1 ]; btb->backColor[ 2 ] = btb->frontColor[ 2 ]; } else if( !Q_stricmp( token, "{" ) ) { if( !CG_ParseTrailBeamColor( btb->backColor, text_p ) ) break; token = COM_Parse( text_p ); if( Q_stricmp( token, "}" ) ) { CG_Printf( S_COLOR_RED "ERROR: missing '}'\n" ); break; } } else { CG_Printf( S_COLOR_RED "ERROR: missing '{'\n" ); break; } } else { CG_Printf( S_COLOR_RED "ERROR: missing '{'\n" ); break; } continue; } else if( !Q_stricmp( token, "segmentTime" ) ) { token = COM_Parse( text_p ); if( !Q_stricmp( token, "" ) ) break; btb->segmentTime = atoi_neg( token, false ); continue; } else if( !Q_stricmp( token, "fadeOutTime" ) ) { token = COM_Parse( text_p ); if( !Q_stricmp( token, "" ) ) break; btb->fadeOutTime = atoi_neg( token, false ); continue; } else if( !Q_stricmp( token, "shader" ) ) { token = COM_Parse( text_p ); if( !Q_stricmp( token, "" ) ) break; Q_strncpyz( btb->shaderName, token, MAX_QPATH ); continue; } else if( !Q_stricmp( token, "textureType" ) ) { token = COM_Parse( text_p ); if( !Q_stricmp( token, "" ) ) break; if( !Q_stricmp( token, "stretch" ) ) { btb->textureType = TBTT_STRETCH; token = COM_Parse( text_p ); if( !Q_stricmp( token, "" ) ) break; btb->frontTextureCoord = atof_neg( token, false ); token = COM_Parse( text_p ); if( !Q_stricmp( token, "" ) ) break; btb->backTextureCoord = atof_neg( token, false ); } else if( !Q_stricmp( token, "repeat" ) ) { btb->textureType = TBTT_REPEAT; token = COM_Parse( text_p ); if( !Q_stricmp( token, "" ) ) break; if( !Q_stricmp( token, "front" ) ) btb->clampToBack = false; else if( !Q_stricmp( token, "back" ) ) btb->clampToBack = true; else { CG_Printf( S_COLOR_RED "ERROR: unknown textureType clamp \"%s\"\n", token ); break; } token = COM_Parse( text_p ); if( !Q_stricmp( token, "" ) ) break; btb->repeatLength = atof_neg( token, false ); } else { CG_Printf( S_COLOR_RED "ERROR: unknown textureType \"%s\"\n", token ); break; } continue; } else if( !Q_stricmp( token, "realLight" ) ) { btb->realLight = true; continue; } else if( !Q_stricmp( token, "jitter" ) ) { if( btb->numJitters == MAX_TRAIL_BEAM_JITTERS ) { CG_Printf( S_COLOR_RED "ERROR: too many jitters\n" ); break; } token = COM_Parse( text_p ); if( !Q_stricmp( token, "" ) ) break; btb->jitters[ btb->numJitters ].magnitude = atof_neg( token, false ); token = COM_Parse( text_p ); if( !Q_stricmp( token, "" ) ) break; btb->jitters[ btb->numJitters ].period = atoi_neg( token, false ); btb->numJitters++; continue; } else if( !Q_stricmp( token, "jitterAttachments" ) ) { btb->jitterAttachments = true; continue; } else if( !Q_stricmp( token, "}" ) ) return true; //reached the end of this trail beam else { CG_Printf( S_COLOR_RED "ERROR: unknown token '%s' in trail beam\n", token ); return false; } } return false; }