void SetSurfaceExtra( mapDrawSurface_t *ds, int num ) { surfaceExtra_t *se; /* dummy check */ if( ds == NULL || num < 0 ) return; /* get a new extra */ se = AllocSurfaceExtra(); /* copy out the relevant bits */ se->mds = ds; se->si = ds->shaderInfo; se->parentSurfaceNum = ds->parent != NULL ? ds->parent->outputNum : -1; se->entityNum = ds->entityNum; se->castShadows = ds->castShadows; se->recvShadows = ds->recvShadows; se->sampleSize = ds->sampleSize; se->longestCurve = ds->longestCurve; VectorCopy( ds->lightmapAxis, se->lightmapAxis ); /* debug code */ //% Sys_FPrintf( SYS_VRB, "SetSurfaceExtra(): entityNum = %d\n", ds->entityNum ); }
/* ================= SetSurfaceExtra stores extra (q3map2) data for the specific numbered drawsurface ================= */ void SetSurfaceExtra( mapDrawSurface_t *ds, int num ) { surfaceExtra_t *se; if( ds == NULL || num < 0 ) return; se = AllocSurfaceExtra(); se->mds = ds; se->si = ds->shaderInfo; se->parentSurfaceNum = ds->parent != NULL ? ds->parent->outputNum : -1; se->entityNum = ds->entityNum; se->castShadows = ds->castShadows; se->recvShadows = ds->recvShadows; se->sampleSize = ds->sampleSize; se->longestCurve = ds->longestCurve; VectorCopy( ds->lightmapAxis, se->lightmapAxis ); }
void LoadSurfaceExtraFile( const char *path ) { char srfPath[ 1024 ]; surfaceExtra_t *se; int surfaceNum, size; byte *buffer; /* dummy check */ if( path == NULL || path[ 0 ] == '\0' ) return; /* load the file */ strcpy( srfPath, path ); StripExtension( srfPath ); strcat( srfPath, ".srf" ); Sys_Printf( "Loading %s\n", srfPath ); size = LoadFile( srfPath, (void**) &buffer ); if( size <= 0 ) { Sys_Printf( "WARNING: Unable to find surface file %s, using defaults.\n", srfPath ); return; } /* parse the file */ ParseFromMemory( (char *) buffer, size ); /* tokenize it */ while( 1 ) { /* test for end of file */ if( !GetToken( qtrue ) ) break; /* default? */ if( !Q_stricmp( token, "default" ) ) se = &seDefault; /* surface number */ else { surfaceNum = atoi( token ); if( surfaceNum < 0 || surfaceNum > MAX_MAP_DRAW_SURFS ) Error( "ReadSurfaceExtraFile(): %s, line %d: bogus surface num %d", srfPath, scriptline, surfaceNum ); while( surfaceNum >= numSurfaceExtras ) se = AllocSurfaceExtra(); se = &surfaceExtras[ surfaceNum ]; } /* handle { } section */ if( !GetToken( qtrue ) || strcmp( token, "{" ) ) Error( "ReadSurfaceExtraFile(): %s, line %d: { not found", srfPath, scriptline ); while( 1 ) { if( !GetToken( qtrue ) ) break; if( !strcmp( token, "}" ) ) break; /* shader */ if( !Q_stricmp( token, "shader" ) ) { GetToken( qfalse ); se->si = ShaderInfoForShader( token ); } /* parent surface number */ else if( !Q_stricmp( token, "parent" ) ) { GetToken( qfalse ); se->parentSurfaceNum = atoi( token ); } /* entity number */ else if( !Q_stricmp( token, "entity" ) ) { GetToken( qfalse ); se->entityNum = atoi( token ); } /* cast shadows */ else if( !Q_stricmp( token, "castShadows" ) ) { GetToken( qfalse ); se->castShadows = atoi( token ); } /* recv shadows */ else if( !Q_stricmp( token, "receiveShadows" ) ) { GetToken( qfalse ); se->recvShadows = atoi( token ); } /* lightmap sample size */ else if( !Q_stricmp( token, "sampleSize" ) ) { GetToken( qfalse ); se->sampleSize = atoi( token ); } /* longest curve */ else if( !Q_stricmp( token, "longestCurve" ) ) { GetToken( qfalse ); se->longestCurve = atof( token ); } /* lightmap axis vector */ else if( !Q_stricmp( token, "lightmapAxis" ) ) Parse1DMatrix( 3, se->lightmapAxis ); /* ignore all other tokens on the line */ while( TokenAvailable() ) GetToken( qfalse ); } } /* free the buffer */ free( buffer ); }
/* ================= LoadSurfaceExtraFile reads a surface info file (<map>.srf) ================= */ void LoadSurfaceExtraFile( const char *path ) { char srfPath[MAX_SYSPATH]; surfaceExtra_t *se; int surfaceNum; script_t *script; token_t token; if( path == NULL || path[0] == '\0' ) return; com.strcpy( srfPath, path ); FS_StripExtension( srfPath ); FS_DefaultExtension( srfPath, ".srf" ); Msg( "Loading %s\n", srfPath ); script = (void *)Com_OpenScript( srfPath, NULL, 0 ); if( !script ) Sys_Break( "unable to load %s\n", srfPath ); // q3map is always crashed if this missed while( 1 ) { if( !Com_ReadToken( script, SC_ALLOW_NEWLINES|SC_PARSE_GENERIC, &token )) break; if( !com.stricmp( token.string, "default" )) se = &seDefault; else { surfaceNum = com.atoi( token.string ); if( surfaceNum < 0 || surfaceNum > MAX_MAP_DRAW_SURFS ) Sys_Error( "ReadSurfaceExtraFile(): %s, line %d: bogus surface num %d", srfPath, token.line, surfaceNum ); while( surfaceNum >= numSurfaceExtras ) se = AllocSurfaceExtra(); se = &surfaceExtras[surfaceNum]; } // handle { } section if( !Com_ReadToken( script, SC_ALLOW_NEWLINES|SC_PARSE_GENERIC, &token ) || com.strcmp( token.string, "{" )) Sys_Error( "ReadSurfaceExtraFile(): %s, line %d: { not found\n", srfPath, token.line ); while( 1 ) { if( !Com_ReadToken( script, SC_ALLOW_NEWLINES|SC_PARSE_GENERIC, &token )) break; if( !com.strcmp( token.string, "}" )) break; if( !com.stricmp( token.string, "shader" )) { Com_ReadToken( script, SC_ALLOW_PATHNAMES|SC_PARSE_GENERIC, &token ); se->si = ShaderInfoForShader( token.string ); } else if( !com.stricmp( token.string, "parent" )) { Com_ReadLong( script, false, &se->parentSurfaceNum ); } else if( !com.stricmp( token.string, "entity" )) { Com_ReadLong( script, false, &se->entityNum ); } else if( !com.stricmp( token.string, "castShadows" )) { Com_ReadLong( script, false, &se->castShadows ); } else if( !com.stricmp( token.string, "receiveShadows" )) { Com_ReadLong( script, false, &se->recvShadows ); } else if( !com.stricmp( token.string, "sampleSize" )) { Com_ReadLong( script, false, &se->sampleSize ); } else if( !com.stricmp( token.string, "longestCurve" )) { Com_ReadFloat( script, false, &se->longestCurve ); } else if( !com.stricmp( token.string, "lightmapAxis" )) Com_Parse1DMatrix( script, 3, se->lightmapAxis ); // ignore all other tokens on the line Com_SkipRestOfLine( script ); } } Com_CloseScript( script ); }