2
0
mirror of https://github.com/FWGS/xash3d-fwgs synced 2024-11-23 02:15:55 +01:00
xash3d-fwgs/ref/gl/gl_rmisc.c

186 lines
4.5 KiB
C
Raw Normal View History

/*
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"
#include "screenfade.h"
#include "cdll_int.h"
2018-10-27 22:31:55 +02:00
static void R_ParseDetailTextures( const char *filename )
{
2019-07-13 22:25:03 +02:00
byte *afile;
char *pfile;
string token, texname;
string detail_texname;
string detail_path;
float xScale, yScale;
texture_t *tex;
int i;
afile = gEngfuncs.fsapi->LoadFile( filename, NULL, false );
if( !afile ) return;
2019-07-13 22:25:03 +02:00
pfile = (char *)afile;
// format: 'texturename' 'detailtexture' 'xScale' 'yScale'
2021-10-01 19:37:52 +02:00
while(( pfile = COM_ParseFile( pfile, token, sizeof( token ))) != NULL )
{
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 );
}
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 ));
// trying the scales or '{'
2021-10-01 19:37:52 +02:00
pfile = COM_ParseFile( pfile, token, sizeof( token ));
// 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
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
}
Q_snprintf( detail_path, sizeof( detail_path ), "gfx/%s", detail_texname );
// read scales
xScale = Q_atof( token );
2021-10-01 19:37:52 +02:00
pfile = COM_ParseFile( pfile, token, sizeof( token ));
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++ )
{
2019-02-23 19:49:46 +01:00
tex = WORLDMODEL->textures[i];
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 );
// texture is loaded
if( tex->dt_texturenum )
{
2018-10-04 08:08:48 +02:00
gl_texture_t *glt;
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();
// upload detailtextures
2018-10-04 08:08:48 +02:00
if( CVAR_TO_BOOL( r_detailtextures ))
{
string mapname, filepath;
2019-02-23 19:49:46 +01:00
Q_strncpy( mapname, WORLDMODEL->name, sizeof( mapname ));
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" ))
{
screenfade_t *sf = gEngfuncs.GetScreenFade();
2018-06-19 15:22:30 +02:00
float fadetime = 5.0f;
client_textmessage_t *title;
title = gEngfuncs.pfnTextMessageGet( "GAMETITLE" );
if( ENGINE_GET_PARM( PARM_QUAKE_COMPATIBLE ))
2018-06-19 15:22:30 +02:00
fadetime = 1.0f;
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;
sf->fadeFlags = FFADE_IN;
sf->fader = sf->fadeg = sf->fadeb = 0;
sf->fadealpha = 255;
sf->fadeSpeed = (float)sf->fadealpha / sf->fadeReset;
sf->fadeReset += gpGlobals->time;
sf->fadeEnd += sf->fadeReset;
gEngfuncs.Cvar_SetValue( "v_dark", 0.0f );
}
// 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;
2019-05-19 14:01:23 +02:00
glState.isFogEnabled = false;
tr.skytexturenum = -1;
pglDisable( GL_FOG );
// clearing texture chains
2019-02-23 19:49:46 +01:00
for( i = 0; i < WORLDMODEL->numtextures; i++ )
{
2019-02-23 19:49:46 +01:00
if( !WORLDMODEL->textures[i] )
continue;
2019-02-23 19:49:46 +01:00
tx = WORLDMODEL->textures[i];
2018-10-04 08:08:48 +02:00
if( !Q_strncmp( tx->name, "sky", 3 ) && tx->width == ( tx->height * 2 ))
tr.skytexturenum = i;
tx->texturechain = NULL;
}
2019-02-23 19:49:46 +01:00
R_SetupSky( MOVEVARS->skyName );
GL_BuildLightmaps ();
2019-02-06 18:40:38 +01:00
R_GenerateVBO();
if( gEngfuncs.drawFuncs->R_NewMap != NULL )
gEngfuncs.drawFuncs->R_NewMap();
2019-02-06 18:40:38 +01:00
}