2018-04-13 18:23:45 +02:00
|
|
|
/*
|
|
|
|
gl_rmisc.c - renderer misceallaneous
|
|
|
|
Copyright (C) 2010 Uncle Mike
|
|
|
|
|
|
|
|
This program 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 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gl_local.h"
|
|
|
|
#include "shake.h"
|
2019-02-24 16:45:27 +01:00
|
|
|
#include "screenfade.h"
|
|
|
|
#include "cdll_int.h"
|
2018-04-13 18:23:45 +02:00
|
|
|
|
2018-10-27 22:31:55 +02:00
|
|
|
static void R_ParseDetailTextures( const char *filename )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
2019-07-13 22:25:03 +02:00
|
|
|
byte *afile;
|
|
|
|
char *pfile;
|
2018-04-13 18:23:45 +02:00
|
|
|
string token, texname;
|
|
|
|
string detail_texname;
|
|
|
|
string detail_path;
|
|
|
|
float xScale, yScale;
|
|
|
|
texture_t *tex;
|
|
|
|
int i;
|
|
|
|
|
2022-07-01 18:37:21 +02:00
|
|
|
afile = gEngfuncs.fsapi->LoadFile( filename, NULL, false );
|
2018-04-13 18:23:45 +02:00
|
|
|
if( !afile ) return;
|
|
|
|
|
2019-07-13 22:25:03 +02:00
|
|
|
pfile = (char *)afile;
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
// format: 'texturename' 'detailtexture' 'xScale' 'yScale'
|
2021-10-01 19:37:52 +02:00
|
|
|
while(( pfile = COM_ParseFile( pfile, token, sizeof( token ))) != NULL )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
texname[0] = '\0';
|
|
|
|
detail_texname[0] = '\0';
|
|
|
|
|
|
|
|
// read texname
|
|
|
|
if( token[0] == '{' )
|
|
|
|
{
|
|
|
|
// NOTE: COM_ParseFile handled some symbols seperately
|
|
|
|
// this code will be fix it
|
2021-10-01 19:37:52 +02:00
|
|
|
pfile = COM_ParseFile( pfile, token, sizeof( token ));
|
2022-12-19 20:24:22 +01:00
|
|
|
Q_snprintf( texname, sizeof( texname ), "{%s", token );
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
else Q_strncpy( texname, token, sizeof( texname ));
|
|
|
|
|
|
|
|
// read detailtexture name
|
2021-10-01 19:37:52 +02:00
|
|
|
pfile = COM_ParseFile( pfile, token, sizeof( token ));
|
2022-12-19 20:24:22 +01:00
|
|
|
Q_strncpy( detail_texname, token, sizeof( detail_texname ));
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
// trying the scales or '{'
|
2021-10-01 19:37:52 +02:00
|
|
|
pfile = COM_ParseFile( pfile, token, sizeof( token ));
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
// read second part of detailtexture name
|
|
|
|
if( token[0] == '{' )
|
|
|
|
{
|
|
|
|
Q_strncat( detail_texname, token, sizeof( detail_texname ));
|
2021-10-01 19:37:52 +02:00
|
|
|
pfile = COM_ParseFile( pfile, token, sizeof( token )); // read scales
|
2018-04-13 18:23:45 +02:00
|
|
|
Q_strncat( detail_texname, token, sizeof( detail_texname ));
|
2021-10-01 19:37:52 +02:00
|
|
|
pfile = COM_ParseFile( pfile, token, sizeof( token )); // parse scales
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Q_snprintf( detail_path, sizeof( detail_path ), "gfx/%s", detail_texname );
|
|
|
|
|
|
|
|
// read scales
|
2021-01-03 02:28:45 +01:00
|
|
|
xScale = Q_atof( token );
|
2018-04-13 18:23:45 +02:00
|
|
|
|
2021-10-01 19:37:52 +02:00
|
|
|
pfile = COM_ParseFile( pfile, token, sizeof( token ));
|
2018-04-13 18:23:45 +02:00
|
|
|
yScale = Q_atof( token );
|
|
|
|
|
|
|
|
if( xScale <= 0.0f || yScale <= 0.0f )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// search for existing texture and uploading detail texture
|
2019-02-23 19:49:46 +01:00
|
|
|
for( i = 0; i < WORLDMODEL->numtextures; i++ )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
2019-02-23 19:49:46 +01:00
|
|
|
tex = WORLDMODEL->textures[i];
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
if( Q_stricmp( tex->name, texname ))
|
|
|
|
continue;
|
|
|
|
|
2018-10-27 22:31:55 +02:00
|
|
|
tex->dt_texturenum = GL_LoadTexture( detail_path, NULL, 0, TF_FORCE_COLOR );
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
// texture is loaded
|
|
|
|
if( tex->dt_texturenum )
|
|
|
|
{
|
2018-10-04 08:08:48 +02:00
|
|
|
gl_texture_t *glt;
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
glt = R_GetTexture( tex->gl_texturenum );
|
|
|
|
glt->xscale = xScale;
|
|
|
|
glt->yscale = yScale;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Mem_Free( afile );
|
|
|
|
}
|
|
|
|
|
|
|
|
void R_NewMap( void )
|
|
|
|
{
|
|
|
|
texture_t *tx;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
R_ClearDecals(); // clear all level decals
|
|
|
|
|
2019-03-16 02:17:56 +01:00
|
|
|
R_StudioResetPlayerModels();
|
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
// upload detailtextures
|
2018-10-04 08:08:48 +02:00
|
|
|
if( CVAR_TO_BOOL( r_detailtextures ))
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
string mapname, filepath;
|
|
|
|
|
2019-02-23 19:49:46 +01:00
|
|
|
Q_strncpy( mapname, WORLDMODEL->name, sizeof( mapname ));
|
2018-04-13 18:23:45 +02:00
|
|
|
COM_StripExtension( mapname );
|
|
|
|
Q_sprintf( filepath, "%s_detail.txt", mapname );
|
|
|
|
|
|
|
|
R_ParseDetailTextures( filepath );
|
|
|
|
}
|
|
|
|
|
2019-03-11 15:37:58 +01:00
|
|
|
if( gEngfuncs.pfnGetCvarFloat( "v_dark" ))
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
2019-02-24 16:45:27 +01:00
|
|
|
screenfade_t *sf = gEngfuncs.GetScreenFade();
|
2018-06-19 15:22:30 +02:00
|
|
|
float fadetime = 5.0f;
|
2018-04-13 18:23:45 +02:00
|
|
|
client_textmessage_t *title;
|
|
|
|
|
2019-02-24 16:45:27 +01:00
|
|
|
title = gEngfuncs.pfnTextMessageGet( "GAMETITLE" );
|
2019-03-22 14:36:46 +01:00
|
|
|
if( ENGINE_GET_PARM( PARM_QUAKE_COMPATIBLE ))
|
2018-06-19 15:22:30 +02:00
|
|
|
fadetime = 1.0f;
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
if( title )
|
|
|
|
{
|
|
|
|
// get settings from titles.txt
|
|
|
|
sf->fadeEnd = title->holdtime + title->fadeout;
|
|
|
|
sf->fadeReset = title->fadeout;
|
|
|
|
}
|
2018-06-19 15:22:30 +02:00
|
|
|
else sf->fadeEnd = sf->fadeReset = fadetime;
|
2021-01-03 02:28:45 +01:00
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
sf->fadeFlags = FFADE_IN;
|
|
|
|
sf->fader = sf->fadeg = sf->fadeb = 0;
|
|
|
|
sf->fadealpha = 255;
|
|
|
|
sf->fadeSpeed = (float)sf->fadealpha / sf->fadeReset;
|
2019-02-24 16:45:27 +01:00
|
|
|
sf->fadeReset += gpGlobals->time;
|
2018-04-13 18:23:45 +02:00
|
|
|
sf->fadeEnd += sf->fadeReset;
|
|
|
|
|
2019-03-06 15:14:25 +01:00
|
|
|
gEngfuncs.Cvar_SetValue( "v_dark", 0.0f );
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// clear out efrags in case the level hasn't been reloaded
|
2019-02-23 19:49:46 +01:00
|
|
|
for( i = 0; i < WORLDMODEL->numleafs; i++ )
|
|
|
|
WORLDMODEL->leafs[i+1].efrags = NULL;
|
2018-04-13 18:23:45 +02:00
|
|
|
|
2019-05-19 14:01:23 +02:00
|
|
|
glState.isFogEnabled = false;
|
2018-04-13 18:23:45 +02:00
|
|
|
tr.skytexturenum = -1;
|
|
|
|
pglDisable( GL_FOG );
|
|
|
|
|
|
|
|
// clearing texture chains
|
2019-02-23 19:49:46 +01:00
|
|
|
for( i = 0; i < WORLDMODEL->numtextures; i++ )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
2019-02-23 19:49:46 +01:00
|
|
|
if( !WORLDMODEL->textures[i] )
|
2018-04-13 18:23:45 +02:00
|
|
|
continue;
|
|
|
|
|
2019-02-23 19:49:46 +01:00
|
|
|
tx = WORLDMODEL->textures[i];
|
2018-04-13 18:23:45 +02:00
|
|
|
|
2018-10-04 08:08:48 +02:00
|
|
|
if( !Q_strncmp( tx->name, "sky", 3 ) && tx->width == ( tx->height * 2 ))
|
2018-04-13 18:23:45 +02:00
|
|
|
tr.skytexturenum = i;
|
|
|
|
|
|
|
|
tx->texturechain = NULL;
|
|
|
|
}
|
|
|
|
|
2019-02-23 19:49:46 +01:00
|
|
|
R_SetupSky( MOVEVARS->skyName );
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
GL_BuildLightmaps ();
|
2019-02-06 18:40:38 +01:00
|
|
|
R_GenerateVBO();
|
2019-03-17 15:19:24 +01:00
|
|
|
|
|
|
|
if( gEngfuncs.drawFuncs->R_NewMap != NULL )
|
|
|
|
gEngfuncs.drawFuncs->R_NewMap();
|
|
|
|
|
2019-02-06 18:40:38 +01:00
|
|
|
}
|