Compare commits

...

7 Commits

14 changed files with 296 additions and 267 deletions

View File

@@ -57,6 +57,7 @@ typedef uint64_t longtime_t;
#define MAX_USERMSG_LENGTH 2048 // don't modify it's relies on a client-side definitions #define MAX_USERMSG_LENGTH 2048 // don't modify it's relies on a client-side definitions
#define BIT( n ) ( 1U << ( n )) #define BIT( n ) ( 1U << ( n ))
#define BIT64( n ) ( 1ULL << ( n ))
#define GAMMA ( 2.2f ) // Valve Software gamma #define GAMMA ( 2.2f ) // Valve Software gamma
#define INVGAMMA ( 1.0f / 2.2f ) // back to 1.0 #define INVGAMMA ( 1.0f / 2.2f ) // back to 1.0
#define TEXGAMMA ( 0.9f ) // compensate dim textures #define TEXGAMMA ( 0.9f ) // compensate dim textures

View File

@@ -659,7 +659,7 @@ static void make_hull_windings( hull_t *hull, hull_model_t *model )
Con_Reportf( "%i hull polys\n", model->num_polys ); Con_Reportf( "%i hull polys\n", model->num_polys );
} }
void Mod_InitDebugHulls( void ) void Mod_InitDebugHulls( model_t *loadmodel )
{ {
int i; int i;

File diff suppressed because it is too large Load Diff

View File

@@ -118,7 +118,6 @@ typedef struct world_static_s
#ifndef REF_DLL #ifndef REF_DLL
extern world_static_t world; extern world_static_t world;
extern poolhandle_t com_studiocache; extern poolhandle_t com_studiocache;
extern model_t *loadmodel;
extern convar_t mod_studiocache; extern convar_t mod_studiocache;
extern convar_t r_wadtextures; extern convar_t r_wadtextures;
extern convar_t r_showhull; extern convar_t r_showhull;
@@ -164,7 +163,7 @@ void Mod_PrintWorldStats_f( void );
// //
// mod_dbghulls.c // mod_dbghulls.c
// //
void Mod_InitDebugHulls( void ); void Mod_InitDebugHulls( model_t *mod );
void Mod_CreatePolygonsForHull( int hullnum ); void Mod_CreatePolygonsForHull( int hullnum );
void Mod_ReleaseHullPolygons( void ); void Mod_ReleaseHullPolygons( void );

View File

@@ -851,11 +851,11 @@ void Mod_LoadStudioModel( model_t *mod, const void *buffer, qboolean *loaded )
char poolname[MAX_VA_STRING]; char poolname[MAX_VA_STRING];
studiohdr_t *phdr; studiohdr_t *phdr;
Q_snprintf( poolname, sizeof( poolname ), "^2%s^7", loadmodel->name ); Q_snprintf( poolname, sizeof( poolname ), "^2%s^7", mod->name );
if( loaded ) *loaded = false; if( loaded ) *loaded = false;
loadmodel->mempool = Mem_AllocPool( poolname ); mod->mempool = Mem_AllocPool( poolname );
loadmodel->type = mod_studio; mod->type = mod_studio;
phdr = R_StudioLoadHeader( mod, buffer ); phdr = R_StudioLoadHeader( mod, buffer );
if( !phdr ) return; // bad model if( !phdr ) return; // bad model
@@ -886,9 +886,9 @@ void Mod_LoadStudioModel( model_t *mod, const void *buffer, qboolean *loaded )
// give space for textures and skinrefs // give space for textures and skinrefs
size1 = thdr->numtextures * sizeof( mstudiotexture_t ); size1 = thdr->numtextures * sizeof( mstudiotexture_t );
size2 = thdr->numskinfamilies * thdr->numskinref * sizeof( short ); size2 = thdr->numskinfamilies * thdr->numskinref * sizeof( short );
mod->cache.data = Mem_Calloc( loadmodel->mempool, phdr->length + size1 + size2 ); mod->cache.data = Mem_Calloc( mod->mempool, phdr->length + size1 + size2 );
memcpy( loadmodel->cache.data, buffer, phdr->length ); // copy main mdl buffer memcpy( mod->cache.data, buffer, phdr->length ); // copy main mdl buffer
phdr = (studiohdr_t *)loadmodel->cache.data; // get the new pointer on studiohdr phdr = (studiohdr_t *)mod->cache.data; // get the new pointer on studiohdr
phdr->numskinfamilies = thdr->numskinfamilies; phdr->numskinfamilies = thdr->numskinfamilies;
phdr->numtextures = thdr->numtextures; phdr->numtextures = thdr->numtextures;
phdr->numskinref = thdr->numskinref; phdr->numskinref = thdr->numskinref;
@@ -905,52 +905,52 @@ void Mod_LoadStudioModel( model_t *mod, const void *buffer, qboolean *loaded )
else else
{ {
// NOTE: don't modify source buffer because it's used for CRC computing // NOTE: don't modify source buffer because it's used for CRC computing
loadmodel->cache.data = Mem_Calloc( loadmodel->mempool, phdr->length ); mod->cache.data = Mem_Calloc( mod->mempool, phdr->length );
memcpy( loadmodel->cache.data, buffer, phdr->length ); memcpy( mod->cache.data, buffer, phdr->length );
phdr = (studiohdr_t *)loadmodel->cache.data; // get the new pointer on studiohdr phdr = (studiohdr_t *)mod->cache.data; // get the new pointer on studiohdr
#if !XASH_DEDICATED #if !XASH_DEDICATED
ref.dllFuncs.Mod_StudioLoadTextures( mod, phdr ); ref.dllFuncs.Mod_StudioLoadTextures( mod, phdr );
#endif #endif
// NOTE: we wan't keep raw textures in memory. just cutoff model pointer above texture base // NOTE: we wan't keep raw textures in memory. just cutoff model pointer above texture base
loadmodel->cache.data = Mem_Realloc( loadmodel->mempool, loadmodel->cache.data, phdr->texturedataindex ); mod->cache.data = Mem_Realloc( mod->mempool, mod->cache.data, phdr->texturedataindex );
phdr = (studiohdr_t *)loadmodel->cache.data; // get the new pointer on studiohdr phdr = (studiohdr_t *)mod->cache.data; // get the new pointer on studiohdr
phdr->length = phdr->texturedataindex; // update model size phdr->length = phdr->texturedataindex; // update model size
} }
} }
else else
{ {
// just copy model into memory // just copy model into memory
loadmodel->cache.data = Mem_Calloc( loadmodel->mempool, phdr->length ); mod->cache.data = Mem_Calloc( mod->mempool, phdr->length );
memcpy( loadmodel->cache.data, buffer, phdr->length ); memcpy( mod->cache.data, buffer, phdr->length );
phdr = loadmodel->cache.data; phdr = mod->cache.data;
} }
// setup bounding box // setup bounding box
if( !VectorCompare( vec3_origin, phdr->bbmin )) if( !VectorCompare( vec3_origin, phdr->bbmin ))
{ {
// clipping bounding box // clipping bounding box
VectorCopy( phdr->bbmin, loadmodel->mins ); VectorCopy( phdr->bbmin, mod->mins );
VectorCopy( phdr->bbmax, loadmodel->maxs ); VectorCopy( phdr->bbmax, mod->maxs );
} }
else if( !VectorCompare( vec3_origin, phdr->min )) else if( !VectorCompare( vec3_origin, phdr->min ))
{ {
// movement bounding box // movement bounding box
VectorCopy( phdr->min, loadmodel->mins ); VectorCopy( phdr->min, mod->mins );
VectorCopy( phdr->max, loadmodel->maxs ); VectorCopy( phdr->max, mod->maxs );
} }
else else
{ {
// well compute bounds from vertices and round to nearest even values // well compute bounds from vertices and round to nearest even values
Mod_StudioComputeBounds( phdr, loadmodel->mins, loadmodel->maxs, true ); Mod_StudioComputeBounds( phdr, mod->mins, mod->maxs, true );
RoundUpHullSize( loadmodel->mins ); RoundUpHullSize( mod->mins );
RoundUpHullSize( loadmodel->maxs ); RoundUpHullSize( mod->maxs );
} }
loadmodel->numframes = Mod_StudioBodyVariations( loadmodel ); mod->numframes = Mod_StudioBodyVariations( mod );
loadmodel->radius = RadiusFromBounds( loadmodel->mins, loadmodel->maxs ); mod->radius = RadiusFromBounds( mod->mins, mod->maxs );
loadmodel->flags = phdr->flags; // copy header flags mod->flags = phdr->flags; // copy header flags
if( loaded ) *loaded = true; if( loaded ) *loaded = true;
} }

View File

@@ -31,7 +31,6 @@ poolhandle_t com_studiocache; // cache for submodels
CVAR_DEFINE( mod_studiocache, "r_studiocache", "1", FCVAR_ARCHIVE, "enables studio cache for speedup tracing hitboxes" ); CVAR_DEFINE( mod_studiocache, "r_studiocache", "1", FCVAR_ARCHIVE, "enables studio cache for speedup tracing hitboxes" );
CVAR_DEFINE_AUTO( r_wadtextures, "0", 0, "completely ignore textures in the bsp-file if enabled" ); CVAR_DEFINE_AUTO( r_wadtextures, "0", 0, "completely ignore textures in the bsp-file if enabled" );
CVAR_DEFINE_AUTO( r_showhull, "0", 0, "draw collision hulls 1-3" ); CVAR_DEFINE_AUTO( r_showhull, "0", 0, "draw collision hulls 1-3" );
model_t *loadmodel;
/* /*
=============================================================================== ===============================================================================
@@ -287,7 +286,6 @@ model_t *Mod_LoadModel( model_t *mod, qboolean crash )
Con_Reportf( "loading %s\n", mod->name ); Con_Reportf( "loading %s\n", mod->name );
mod->needload = NL_PRESENT; mod->needload = NL_PRESENT;
mod->type = mod_bad; mod->type = mod_bad;
loadmodel = mod;
// call the apropriate loader // call the apropriate loader
switch( *(uint *)buf ) switch( *(uint *)buf )

View File

@@ -1041,8 +1041,9 @@ qboolean SV_SpawnServer( const char *mapname, const char *startspot, qboolean ba
// force normal player collisions for single player // force normal player collisions for single player
if( svs.maxclients == 1 ) Cvar_SetValue( "sv_clienttrace", 1 ); if( svs.maxclients == 1 ) Cvar_SetValue( "sv_clienttrace", 1 );
// make sure what server name doesn't contain path and extension // allow loading maps from subdirectories, strip extension anyway
COM_FileBase( mapname, sv.name, sizeof( sv.name )); Q_strncpy( sv.name, mapname, sizeof( sv.name ));
COM_StripExtension( sv.name );
// precache and static commands can be issued during map initialization // precache and static commands can be issued during map initialization
Host_SetServerState( ss_loading ); Host_SetServerState( ss_loading );

View File

@@ -642,20 +642,13 @@ COM_ExtractFilePath
*/ */
void COM_ExtractFilePath( const char *path, char *dest ) void COM_ExtractFilePath( const char *path, char *dest )
{ {
size_t len = Q_strlen( path ); const char *src = path + Q_strlen( path ) - 1;
const char *src = path + len - 1;
if( len == 0 )
{
dest[0] = 0;
return;
}
// back up until a \ or the start // back up until a \ or the start
while( src != path && !(*(src - 1) == '\\' || *(src - 1) == '/' )) while( src > path && !(*(src - 1) == '\\' || *(src - 1) == '/' ))
src--; src--;
if( src != path ) if( src > path )
{ {
memcpy( dest, path, src - path ); memcpy( dest, path, src - path );
dest[src - path - 1] = 0; // cutoff backslash dest[src - path - 1] = 0; // cutoff backslash

40
public/tests/test_efp.c Normal file
View File

@@ -0,0 +1,40 @@
#include <stdlib.h>
#include "crtlib.h"
#include <stdio.h>
int Test_ExtractFilePath( void )
{
char dst[64];
const char *strings[] =
{
"dir/file", "dir",
"bark\\meow", "bark",
"nopath", "",
"knee/deep/in/paths", "knee/deep/in",
// yes, it removes the behavior/ even if it might be technically a directory
"keep/the/original/func/behavior/", "keep/the/original/func",
"backslashes\\are\\annoying\\af", "backslashes\\are\\annoying",
"", ""
};
size_t i;
for( i = 0; i < sizeof( strings ) / sizeof( strings[0] ); i += 2 )
{
COM_ExtractFilePath( strings[i], dst );
if( Q_strcmp( dst, strings[i+1] ))
{
printf( "%s %s %s\n", strings[i], strings[i+1], dst );
return (i >> 1) + 1;
}
}
return 0;
}
int main( void )
{
if( Test_ExtractFilePath( ))
return EXIT_FAILURE;
return EXIT_SUCCESS;
}

View File

@@ -28,6 +28,7 @@ def build(bld):
'strings': 'tests/test_strings.c', 'strings': 'tests/test_strings.c',
'build': 'tests/test_build.c', 'build': 'tests/test_build.c',
'filebase': 'tests/test_filebase.c', 'filebase': 'tests/test_filebase.c',
'efp': 'tests/test_efp.c',
} }
for i in tests: for i in tests:

View File

@@ -1309,9 +1309,9 @@ static void GL2_Mul4x4( const GLfloat *in0, const GLfloat *in1, GLfloat *out )
static void GL2_UpdateMVP( gl2wrap_prog_t *prog ) static void GL2_UpdateMVP( gl2wrap_prog_t *prog )
{ {
// use bitset to determine if need update matrix for this prog // use bitset to determine if need update matrix for this prog
if( FBitSet( gl2wrap_matrix.update, BIT( prog->flags ))) if( FBitSet( gl2wrap_matrix.update, BIT64( prog->flags )))
{ {
ClearBits( gl2wrap_matrix.update, BIT( prog->flags )); ClearBits( gl2wrap_matrix.update, BIT64( prog->flags ));
GL2_Mul4x4( gl2wrap_matrix.mv, gl2wrap_matrix.pr, gl2wrap_matrix.mvp ); GL2_Mul4x4( gl2wrap_matrix.mv, gl2wrap_matrix.pr, gl2wrap_matrix.mvp );
pglUniformMatrix4fvARB( prog->uMVP, 1, false, (void *)gl2wrap_matrix.mvp ); pglUniformMatrix4fvARB( prog->uMVP, 1, false, (void *)gl2wrap_matrix.mvp );
} }

View File

@@ -875,7 +875,7 @@ void DrawGLPolyChain( glpoly_t *p, float soffset, float toffset )
} }
} }
_inline qboolean R_HasLightmap( void ) static qboolean R_HasLightmap( void )
{ {
if( r_fullbright->value || !WORLDMODEL->lightdata ) if( r_fullbright->value || !WORLDMODEL->lightdata )
return false; return false;

View File

@@ -1726,7 +1726,7 @@ static void R_LightLambert( vec4_t light[MAX_LOCALLIGHTS], const vec3_t normal,
out[2] = Q_min( (int)( finalLight[2] ), 255 ); out[2] = Q_min( (int)( finalLight[2] ), 255 );
} }
static void R_StudioSetColorArray(short *ptricmds, vec3_t *pstudionorms, byte *color ) static void R_StudioSetColorArray( short *ptricmds, vec3_t *pstudionorms, byte *color )
{ {
float *lv = (float *)g_studio.lightvalues[ptricmds[1]]; float *lv = (float *)g_studio.lightvalues[ptricmds[1]];
@@ -1896,9 +1896,8 @@ R_StudioDrawNormalMesh
generic path generic path
=============== ===============
*/ */
_inline void R_StudioDrawNormalMesh( short *ptricmds, vec3_t *pstudionorms, float s, float t ) static void R_StudioDrawNormalMesh( short *ptricmds, vec3_t *pstudionorms, float s, float t )
{ {
float *lv;
int i; int i;
while(( i = *( ptricmds++ ))) while(( i = *( ptricmds++ )))
@@ -1929,9 +1928,8 @@ R_StudioDrawNormalMesh
generic path generic path
=============== ===============
*/ */
_inline void R_StudioDrawFloatMesh( short *ptricmds, vec3_t *pstudionorms ) static void R_StudioDrawFloatMesh( short *ptricmds, vec3_t *pstudionorms )
{ {
float *lv;
int i; int i;
while(( i = *( ptricmds++ ))) while(( i = *( ptricmds++ )))
@@ -1961,7 +1959,7 @@ R_StudioDrawNormalMesh
generic path generic path
=============== ===============
*/ */
_inline void R_StudioDrawChromeMesh( short *ptricmds, vec3_t *pstudionorms, float s, float t, float scale ) static void R_StudioDrawChromeMesh( short *ptricmds, vec3_t *pstudionorms, float s, float t, float scale )
{ {
float *lv, *av; float *lv, *av;
int i, idx; int i, idx;
@@ -2006,7 +2004,7 @@ _inline void R_StudioDrawChromeMesh( short *ptricmds, vec3_t *pstudionorms, floa
} }
_inline int R_StudioBuildIndices( qboolean tri_strip, int vertexState ) static int R_StudioBuildIndices( qboolean tri_strip, int vertexState )
{ {
// build in indices // build in indices
if( vertexState++ < 3 ) if( vertexState++ < 3 )
@@ -2049,7 +2047,7 @@ R_StudioDrawNormalMesh
generic path generic path
=============== ===============
*/ */
_inline void R_StudioBuildArrayNormalMesh( short *ptricmds, vec3_t *pstudionorms, float s, float t ) static void R_StudioBuildArrayNormalMesh( short *ptricmds, vec3_t *pstudionorms, float s, float t )
{ {
float *lv; float *lv;
int i; int i;
@@ -2092,7 +2090,7 @@ R_StudioDrawNormalMesh
generic path generic path
=============== ===============
*/ */
_inline void R_StudioBuildArrayFloatMesh( short *ptricmds, vec3_t *pstudionorms ) static void R_StudioBuildArrayFloatMesh( short *ptricmds, vec3_t *pstudionorms )
{ {
float *lv; float *lv;
int i; int i;
@@ -2135,7 +2133,7 @@ R_StudioDrawNormalMesh
generic path generic path
=============== ===============
*/ */
_inline void R_StudioBuildArrayChromeMesh( short *ptricmds, vec3_t *pstudionorms, float s, float t, float scale ) static void R_StudioBuildArrayChromeMesh( short *ptricmds, vec3_t *pstudionorms, float s, float t, float scale )
{ {
float *lv, *av; float *lv, *av;
int i, idx; int i, idx;
@@ -2192,7 +2190,7 @@ _inline void R_StudioBuildArrayChromeMesh( short *ptricmds, vec3_t *pstudionorms
} }
} }
_inline void R_StudioDrawArrays( uint startverts, uint startelems ) static void R_StudioDrawArrays( uint startverts, uint startelems )
{ {
pglEnableClientState( GL_VERTEX_ARRAY ); pglEnableClientState( GL_VERTEX_ARRAY );
pglVertexPointer( 3, GL_FLOAT, 12, g_studio.arrayverts ); pglVertexPointer( 3, GL_FLOAT, 12, g_studio.arrayverts );

View File

@@ -1891,7 +1891,7 @@ R_StudioDrawNormalMesh
generic path generic path
=============== ===============
*/ */
_inline void R_StudioDrawNormalMesh( short *ptricmds, vec3_t *pstudionorms, float s, float t ) static void R_StudioDrawNormalMesh( short *ptricmds, vec3_t *pstudionorms, float s, float t )
{ {
float *lv; float *lv;
int i; int i;
@@ -1924,7 +1924,7 @@ R_StudioDrawNormalMesh
generic path generic path
=============== ===============
*/ */
_inline void R_StudioDrawFloatMesh( short *ptricmds, vec3_t *pstudionorms ) static void R_StudioDrawFloatMesh( short *ptricmds, vec3_t *pstudionorms )
{ {
float *lv; float *lv;
int i; int i;
@@ -1956,7 +1956,7 @@ R_StudioDrawNormalMesh
generic path generic path
=============== ===============
*/ */
_inline void R_StudioDrawChromeMesh( short *ptricmds, vec3_t *pstudionorms, float s, float t, float scale ) static void R_StudioDrawChromeMesh( short *ptricmds, vec3_t *pstudionorms, float s, float t, float scale )
{ {
float *lv, *av; float *lv, *av;
int i, idx; int i, idx;