12 Nov 2008

This commit is contained in:
g-cont 2008-11-12 00:00:00 +03:00 committed by Alibek Omarov
parent 217aee35c0
commit 08b2fdfb51
26 changed files with 307 additions and 149 deletions

View File

@ -1004,13 +1004,13 @@ BuildFacelights
float sampleofs[5][2] =
{ {0,0}, {-0.25, -0.25}, {0.25, -0.25}, {0.25, 0.25}, {-0.25, 0.25} };
static lightinfo_t light_info[5];
void BuildFacelights (int facenum)
{
dsurface_t *f;
lightinfo_t l[5];
float *styletable[MAX_LSTYLES];
int i, j;
float *styletable[MAX_LSTYLES];
float *spot;
patch_t *patch;
int numsamples;
@ -1030,43 +1030,43 @@ void BuildFacelights (int facenum)
numsamples = 1;
for (i=0 ; i<numsamples ; i++)
{
memset (&l[i], 0, sizeof(l[i]));
l[i].surfnum = facenum;
l[i].face = f;
VectorCopy (dplanes[f->planenum].normal, l[i].facenormal);
l[i].facedist = dplanes[f->planenum].dist;
memset (&light_info[i], 0, sizeof(light_info[i]));
light_info[i].surfnum = facenum;
light_info[i].face = f;
VectorCopy (dplanes[f->planenum].normal, light_info[i].facenormal);
light_info[i].facedist = dplanes[f->planenum].dist;
if (f->side)
{
VectorSubtract (vec3_origin, l[i].facenormal, l[i].facenormal);
l[i].facedist = -l[i].facedist;
VectorSubtract (vec3_origin, light_info[i].facenormal, light_info[i].facenormal);
light_info[i].facedist = -light_info[i].facedist;
}
// get the origin offset for rotating bmodels
VectorCopy (face_offset[facenum], l[i].modelorg);
VectorCopy (face_offset[facenum], light_info[i].modelorg);
CalcFaceVectors (&l[i]);
CalcFaceExtents (&l[i]);
CalcPoints (&l[i], sampleofs[i][0], sampleofs[i][1]);
CalcFaceVectors (&light_info[i]);
CalcFaceExtents (&light_info[i]);
CalcPoints (&light_info[i], sampleofs[i][0], sampleofs[i][1]);
}
tablesize = l[0].numsurfpt * sizeof(vec3_t);
tablesize = light_info[0].numsurfpt * sizeof(vec3_t);
styletable[0] = Malloc(tablesize);
fl = &facelight[facenum];
fl->numsamples = l[0].numsurfpt;
fl->numsamples = light_info[0].numsurfpt;
fl->origins = Malloc (tablesize);
memcpy (fl->origins, l[0].surfpt, tablesize);
memcpy (fl->origins, light_info[0].surfpt, tablesize);
for (i=0 ; i<l[0].numsurfpt ; i++)
for (i=0 ; i<light_info[0].numsurfpt ; i++)
{
for (j=0 ; j<numsamples ; j++)
{
GatherSampleLight (l[j].surfpt[i], l[0].facenormal, styletable,
GatherSampleLight (light_info[j].surfpt[i], light_info[0].facenormal, styletable,
i*3, tablesize, 1.0/numsamples);
}
// contribute the sample to one or more patches
AddSampleToPatch (l[0].surfpt[i], styletable[0]+i*3, facenum);
AddSampleToPatch (light_info[0].surfpt[i], styletable[0]+i*3, facenum);
}
// average up the direct light on each patch for radiosity
@ -1098,7 +1098,7 @@ void BuildFacelights (int facenum)
)
{
spot = fl->samples[0];
for (i=0 ; i<l[0].numsurfpt ; i++, spot+=3)
for (i=0 ; i<light_info[0].numsurfpt ; i++, spot+=3)
{
VectorAdd (spot, face_patches[facenum]->baselight, spot);
}

View File

@ -80,7 +80,7 @@ void CalcTextureReflectivity( void )
// scale the reflectivity up, because the textures are so dim
scale = ColorNormalize( color, texture_reflectivity[i] );
texinfo[i].value = texels * 255.0 / scale; // basic intensity value
texinfo[i].value = (texels * 255.0) / scale; // basic intensity value
FS_FreeImage( pic ); // don't forget free image
}
else VectorSet( texture_reflectivity[i], 0.5, 0.5, 0.5 ); // no texture, no shader...

View File

@ -237,7 +237,7 @@ void WritePortalFile (tree_t *tree)
NumberLeafs_r (headnode);
// write the file
sprintf (path, "maps/%s.prt", gs_filename );
com.sprintf (path, "maps/%s.prt", gs_filename );
pf = FS_Open(path, "w" );
if (!pf) Sys_Error ("Error opening %s", path);

View File

@ -287,7 +287,7 @@ void Init_PhysicsLibrary( void )
pi.api_size = sizeof(physic_imp_t);
Sys_LoadLibrary( &physic_dll );
if(physic_dll.link)
if( physic_dll.link )
{
CreatePhysic = (void *)physic_dll.main;
pe = CreatePhysic( &com, &pi ); // sys_error not overrided
@ -298,7 +298,7 @@ void Init_PhysicsLibrary( void )
void Free_PhysicLibrary( void )
{
if(physic_dll.link)
if( physic_dll.link )
{
pe->Shutdown();
memset( &pe, 0, sizeof(pe));

View File

@ -97,8 +97,6 @@ void EmitLeaf( node_t *node )
leaf_p->cluster = node->cluster;
leaf_p->area = node->area;
Msg( "leaf %i cluster %i, area %i\n", numleafs - 1, leaf_p->cluster, leaf_p->area );
//
// write bounding box info
//
@ -270,7 +268,7 @@ void WriteBSP( node_t *headnode )
oldsurfaces = numsurfaces;
dmodels[nummodels].headnode = EmitDrawNode_r( headnode );
// EmitAreaPortals( headnode );
EmitAreaPortals( headnode );
}
//===========================================================

View File

@ -67,5 +67,5 @@ if exist vsound\vsound.plg del /f /q vsound\vsound.plg
echo Build succeeded!
echo Please wait. Xash is now loading
cd D:\Xash3D\
quake.exe -game tmpQuArK -log -debug -dev 4 +map skytest
quake.exe -game tmpQuArK -log -debug -dev 3 +map start
:done

View File

@ -95,6 +95,7 @@ struct sv_entvars_s
float sequence;
float animtime;
float framerate;
float style;
float gaitsequence;
float effects;
float renderfx;
@ -142,6 +143,6 @@ struct sv_entvars_s
float team;
};
#define PROG_CRC_SERVER 9289
#define PROG_CRC_SERVER 9691
#endif//SV_EDICT_H

View File

@ -13,6 +13,10 @@ typedef struct
int entities[MAX_VISIBLE_PACKET];
} sv_ents_t;
static byte *clientpvs;
static byte *clientphs;
static byte *bitvector;
int c_fullsend;
/*
@ -192,12 +196,14 @@ static void SV_AddEntitiesToPacket( vec3_t origin, client_frame_t *frame, sv_ent
// specfically check for it
if( !sv.state ) return;
bitvector = pe->FatPVS( origin, portal );
leafnum = pe->PointLeafnum( origin );
clientarea = pe->LeafArea( leafnum );
clientcluster = pe->LeafCluster( leafnum );
// calculate the visible areas
frame->areabits_size = pe->WriteAreaBits( frame->areabits, clientarea );
frame->areabits_size = pe->WriteAreaBits( frame->areabits, clientarea, portal );
clientpvs = pe->ClusterPVS( clientcluster );
for( e = 0; e < prog->num_edicts; e++ )
@ -237,7 +243,7 @@ static void SV_AddEntitiesToPacket( vec3_t origin, client_frame_t *frame, sv_ent
if( !pe->AreasConnected( clientarea, ent->priv.sv->areanum2 ))
continue; // blocked by a door
}
bitvector = clientpvs;
// bitvector = clientpvs;
// check individual leafs
if( !svent->num_clusters && !force ) continue;
@ -425,11 +431,6 @@ void SV_BuildClientFrame( sv_client_t *cl )
// of an entity being included twice.
qsort( frame_ents.entities, frame_ents.num_entities, sizeof( frame_ents.entities[0] ), SV_EntityNumbers );
// now that all viewpoint's areabits have been OR'd together, invert
// all of them to make it a mask vector, which is what the renderer wants
for( i = 0; i < MAX_MAP_AREA_BYTES / 4; i++ )
((int *)frame->areabits)[i] = ((int *)frame->areabits)[i] ^ -1;
// copy the entity states out
frame->num_entities = 0;
frame->first_entity = svs.next_client_entities;

View File

@ -2117,11 +2117,12 @@ void PF_AreaPortalState( void )
edict_t *ent;
bool open;
if(!VM_ValidateArgs( "areaportal", 2 )) return;
if( !VM_ValidateArgs( "areaportal", 2 ))
return;
ent = PRVM_G_EDICT( OFS_PARM0 );
if( ent->priv.sv->areanum2 == -1 ) return;
open = (bool)PRVM_G_FLOAT( OFS_PARM1 );
pe->SetAreaPortalState( ent->priv.sv->areanum, ent->priv.sv->areanum2, open );
pe->SetAreaPortalState( ent->progs.sv->style, open );
}
/*

View File

@ -3145,7 +3145,7 @@ file_t *VFS_Close( vfile_t *file )
}
handle = file->handle; // keep real handle
Mem_Free( file->buff );
if( file->buff )Mem_Free( file->buff );
Mem_Free( file ); // himself
return handle;

View File

@ -2169,18 +2169,18 @@ bool Image_DecompressRGBA( uint target, int level, int intformat, uint width, ui
case PF_RGB_24:
for (i = 0; i < width * height; i++ )
{
fout[(i<<2)+0] = fin[i+0];
fout[(i<<2)+1] = fin[i+1];
fout[(i<<2)+2] = fin[i+2];
fout[(i<<2)+0] = fin[i*3+0];
fout[(i<<2)+1] = fin[i*3+1];
fout[(i<<2)+2] = fin[i*3+2];
fout[(i<<2)+3] = 255;
}
break;
case PF_BGR_24:
for (i = 0; i < width * height; i++ )
{
fout[(i<<2)+0] = fin[i+2];
fout[(i<<2)+1] = fin[i+1];
fout[(i<<2)+2] = fin[i+0];
fout[(i<<2)+0] = fin[i*3+2];
fout[(i<<2)+1] = fin[i*3+1];
fout[(i<<2)+2] = fin[i*3+0];
fout[(i<<2)+3] = 255;
}
break;

View File

@ -1208,7 +1208,8 @@ void Image_Process( rgbdata_t **pix, int width, int height, uint flags )
return;
}
if( flags & IMAGE_FORCE_RGBA ) Sys_Error( "Image_Process: Image_ForceRGBA not implemented\n" );
// FIXME:
// if( flags & IMAGE_FORCE_RGBA ) Sys_Error( "Image_Process: Image_ForceRGBA not implemented\n" );
// NOTE: flip and resample algorythms can't different palette size
if( flags & IMAGE_PALTO24 ) Image_ConvertPalTo24bit( pic );

View File

@ -1442,7 +1442,7 @@ void CM_CollisionDrawForEachBrush( void )
if( !draw ) continue;
if( i == 0 ) color = PackRGBA( 1, 0.7f, 0, 1 ); // world
else color = PackRGBA( 1, 0.1f, 0.1f, 1 );
ph.debug_line( color, draw->numpoints, (float *)&draw->points->v[0] );
ph.debug_line( color, draw->numpoints, (float *)&draw->points->v[0], (int *)&draw->elements );
}
}
}

View File

@ -12,7 +12,7 @@ void DebugShowGeometryCollision( const NewtonBody* body, int vertexCount, const
if( body == cm.body ) color = PackRGBA( 1, 0.7f, 0, 1 ); // world
else color = PackRGBA( 1, 0.1f, 0.1f, 1 );
ph.debug_line( color, vertexCount, faceVertec );
ph.debug_line( color, vertexCount, faceVertec, NULL );
}
void DebugShowBodyCollision( const NewtonBody* body )

View File

@ -106,17 +106,12 @@ typedef struct
typedef struct
{
int numareaportals;
int firstareaportal;
int floodnum; // if two areas have equal floodnums, they are connected
int floodvalid;
} carea_t;
typedef struct
{
int numClusters;
int clusterBytes;
byte *data; // vis data
} cvis_t;
typedef struct material_info_s
{
string name;
@ -139,9 +134,11 @@ typedef struct collide_info_s
typedef struct clipmap_s
{
string name;
uint checksum; // map checksum
byte pvsrow[MAX_MAP_LEAFS/8];
byte phsrow[MAX_MAP_LEAFS/8];
byte portalopen[MAX_MAP_AREAPORTALS];
// brush, studio and sprite models
cmodel_t cmodels[MAX_MODELS];
@ -158,18 +155,18 @@ typedef struct clipmap_s
dleafface_t *leafsurfaces;
cnode_t *nodes; // 6 extra planes for box hull
dvertex_t *vertices;
dsurface_t *surfaces; // source collision data
dedge_t *edges;
dsurface_t *surfaces; // source collision data
dsurfedge_t *surfedges;
dtexinfo_t *texinfo;
csurface_t *shaders;
cbrush_t *brushes;
cbrushside_t *brushsides;
byte *visbase; // vis offset
dvis_t *vis;
NewtonCollision *collision;
csurface_t *shaders;
carea_t *areas;
int *areaportals; // [ cm.numareas * cm.numareas ] reference counts
dareaportal_t *areaportals;
int numbrushsides;
int numtexinfo;
@ -179,11 +176,11 @@ typedef struct clipmap_s
int numleafs; // allow leaf funcs to be called without a map
int numleafbrushes;
int numleafsurfaces;
size_t numareaportals;
int numshaders;
int numsurfaces;
int numbrushes;
int numsurfaces;
int numareas;
int numareaportals;
int numclusters;
int floodvalid;

View File

@ -383,7 +383,7 @@ void BSP_LoadLeafBrushes( lump_t *l )
count = l->filelen / sizeof(*in);
if( count < 1 ) Host_Error( "Map %s with no leaf brushes\n", cm.name );
out = cm.leafbrushes = (dword *)Mem_Alloc( cmappool, count * sizeof(*out));
out = cm.leafbrushes = (dleafbrush_t *)Mem_Alloc( cmappool, count * sizeof(*out));
cm.numleafbrushes = count;
for( i = 0; i < count; i++, in++, out++) *out = LittleLong( *in );
}
@ -407,8 +407,8 @@ void BSP_LoadLeafs( lump_t *l )
count = l->filelen / sizeof(*in);
if( count < 1 ) Host_Error( "Map %s with no leafs\n", cm.name );
out = cm.leafs = (cleaf_t *)Mem_Alloc( cmappool, count * sizeof(*out));
cm.numclusters = cm.numareas = 0;
cm.numleafs = count;
cm.numclusters = 0;
for( i = 0; i < count; i++, in++, out++)
{
@ -419,8 +419,6 @@ void BSP_LoadLeafs( lump_t *l )
out->area = LittleLong( in->area );
if( out->cluster >= cm.numclusters )
cm.numclusters = out->cluster + 1;
if( out->area >= cm.numareas )
cm.numareas = out->area + 1;
for( j = 0; j < 3; j++ )
{
// yes the mins/maxs are ints
@ -441,9 +439,13 @@ void BSP_LoadLeafs( lump_t *l )
out->numleafbrushes = c;
}
// probably any wall it's liquid ?
if( cm.leafs[0].contents != CONTENTS_SOLID )
Host_Error("Map %s with leaf 0 is not CONTENTS_SOLID\n", cm.name );
for( i = 1; i < count; i++ )
{
if(!cm.leafs[i].contents)
if( !cm.leafs[i].contents )
{
emptyleaf = i;
break;
@ -452,10 +454,6 @@ void BSP_LoadLeafs( lump_t *l )
// stuck into brushes
if( emptyleaf == -1 ) Host_Error( "Map %s does not have an empty leaf\n", cm.name );
cm.numareaportals = cm.numareas * cm.numareas * sizeof( *cm.areaportals );
cm.areas = Mem_Alloc( cmappool, cm.numareas * sizeof( *cm.areas ));
cm.areaportals = Mem_Alloc( cmappool, cm.numareaportals );
}
/*
@ -500,7 +498,7 @@ void BSP_LoadBrushSides( lump_t *l )
in = (void *)(cm.mod_base + l->fileofs);
if( l->filelen % sizeof( *in ))
Host_Error( "BSP_LoadBrushSides: funny lump size\n" );
count = l->filelen / sizeof(*in);
count = l->filelen / sizeof( *in );
out = cm.brushsides = (cbrushside_t *)Mem_Alloc( cmappool, count * sizeof(*out));
cm.numbrushsides = count;
@ -514,6 +512,57 @@ void BSP_LoadBrushSides( lump_t *l )
}
}
/*
=================
BSP_LoadAreas
=================
*/
void BSP_LoadAreas( lump_t *l )
{
darea_t *in;
carea_t *out;
int i, count;
in = (void *)(cm.mod_base + l->fileofs);
if( l->filelen % sizeof( *in ))
Host_Error( "BSP_LoadAreas: funny lump size\n" );
count = l->filelen / sizeof( *in );
out = cm.areas = (carea_t *)Mem_Alloc( cmappool, count * sizeof( *out ));
cm.numareas = count;
for( i = 0; i < count; i++, in++, out++ )
{
out->numareaportals = LittleLong( in->numareaportals );
out->firstareaportal = LittleLong( in->firstareaportal );
out->floodvalid = 0;
out->floodnum = 0;
}
}
/*
=================
BSP_LoadAreaPortals
=================
*/
void BSP_LoadAreaPortals( lump_t *l )
{
dareaportal_t *in, *out;
int i, count;
in = (void *)(cm.mod_base + l->fileofs);
if( l->filelen % sizeof( *in ))
Host_Error( "BSP_LoadAreaPortals: funny lump size\n" );
count = l->filelen / sizeof( *in );
out = cm.areaportals = (dareaportal_t *)Mem_Alloc( cmappool, count * sizeof( *out ));
cm.numareaportals = count;
for( i = 0; i < count; i++, in++, out++ )
{
out->portalnum = LittleLong( in->portalnum );
out->otherarea = LittleLong( in->otherarea );
}
}
/*
=================
BSP_LoadVisibility
@ -524,18 +573,19 @@ void BSP_LoadVisibility( lump_t *l )
int i;
if( !l->filelen ) return;
cm.visbase = (byte *)Mem_Alloc( cmappool, l->filelen );
Mem_Copy( cm.visbase, cm.mod_base + l->fileofs, l->filelen );
cm.vis = (dvis_t *)cm.visbase; // conversion
cm.vis->numclusters = LittleLong( cm.vis->numclusters );
for( i = 0; i < cm.vis->numclusters; i++ )
{
cm.vis->bitofs[i][0] = LittleLong(cm.vis->bitofs[i][0]);
cm.vis->bitofs[i][1] = LittleLong(cm.vis->bitofs[i][1]);
cm.vis->bitofs[i][0] = LittleLong( cm.vis->bitofs[i][0] );
cm.vis->bitofs[i][1] = LittleLong( cm.vis->bitofs[i][1] );
}
if( cm.numclusters != cm.vis->numclusters )
Sys_Break( "invalid vis->numclusters (%i, should be %i)\n", cm.vis->numclusters, cm.numclusters );
Host_Error( "BSP_LoadVisibility: mismatch vis and leaf clusters (%i should be %i)\n", cm.vis->numclusters, cm.numclusters );
}
/*
@ -603,8 +653,7 @@ void BSP_LoadSurfedges( lump_t *l )
if( l->filelen % sizeof( *in ))
Host_Error( "BSP_LoadSurfedges: funny lump size\n" );
count = l->filelen / sizeof(*in);
if( count < 1 || count >= MAX_MAP_SURFEDGES )
Host_Error( "BSP_LoadSurfedges: invalid surfedges count %i\n", count );
if( count < 1 ) Host_Error( "BSP_LoadSurfedges: map without surfedges\n" );
cm.surfedges = Mem_Alloc( cmappool, count * sizeof( *in ));
Mem_Copy( cm.edges, in, count * sizeof( *in ));
@ -643,23 +692,10 @@ BSP_LoadCollision
*/
void BSP_LoadCollision( lump_t *l )
{
if( !l->filelen ) return;
cm.world_tree = VFS_Create( cm.mod_base + l->fileofs, l->filelen );
}
/*
=================
BSP_LoadBuiltinProgs
=================
*/
void BSP_LoadBuiltinProgs( lump_t *l )
{
// not implemented
if( !l->filelen )
{
return;
}
}
static void BSP_RecursiveFindNumLeafs( cnode_t *node )
{
int numleafs;
@ -838,9 +874,9 @@ void CM_SaveCollisionTree( file_t *f, cmsave_t callback )
void CM_LoadCollisionTree( void )
{
if( !cm.world_tree ) return;
cm.collision = NewtonCreateTreeCollisionFromSerialization( gWorld, NULL, BSP_LoadTree, cm.world_tree );
VFS_Close( cm.world_tree );
cm.world_tree = NULL;
}
void CM_LoadWorld( const void *buffer )
@ -872,10 +908,11 @@ void CM_FreeWorld( void )
// free old stuff
if( cm.loaded ) Mem_EmptyPool( cmappool );
cm.numplanes = cm.numnodes = cm.numleafs = 0;
cm.numleafbrushes = cm.numsurfaces = cm.numbmodels = 0;
cm.floodvalid = cm.numbrushsides = cm.numtexinfo = 0;
cm.numbrushes = cm.numleafsurfaces = cm.numareas = 0;
cm.numleafbrushes = cm.numsurfaces = cm.numbmodels = 0;
cm.numclusters = cm.numareaportals = cm.numshaders = 0;
cm.numareaportals = cm.numclusters = cm.numshaders = 0;
cm.world_tree = NULL;
cm.vis = NULL;
cm.name[0] = 0;
@ -928,7 +965,7 @@ cmodel_t *CM_BeginRegistration( const char *name, bool clientload, uint *checksu
if( !clientload )
{
// rebuild portals for server
Mem_Set( cm.areaportals, 0, cm.numareaportals );
Mem_Set( cm.portalopen, 0, sizeof( cm.portalopen ));
CM_FloodAreaConnections();
}
// still have the right version
@ -940,7 +977,7 @@ cmodel_t *CM_BeginRegistration( const char *name, bool clientload, uint *checksu
// load the newmap
buf = (uint *)FS_LoadFile( name, &length );
if(!buf) Host_Error("Couldn't load %s\n", name );
if(!buf) Host_Error( "Couldn't load %s\n", name );
*checksum = cm.checksum = LittleLong(Com_BlockChecksum (buf, length));
hdr = (dheader_t *)buf;
@ -964,9 +1001,12 @@ cmodel_t *CM_BeginRegistration( const char *name, bool clientload, uint *checksu
BSP_LoadLeafSurfaces(&hdr->lumps[LUMP_LEAFFACES]);
BSP_LoadLeafs(&hdr->lumps[LUMP_LEAFS]);
BSP_LoadNodes(&hdr->lumps[LUMP_NODES]);
BSP_LoadAreas(&hdr->lumps[LUMP_AREAS]);
BSP_LoadAreaPortals(&hdr->lumps[LUMP_AREAPORTALS]);
BSP_LoadVisibility(&hdr->lumps[LUMP_VISIBILITY]);
BSP_LoadModels(&hdr->lumps[LUMP_MODELS]);
BSP_LoadCollision(&hdr->lumps[LUMP_COLLISION]);
cm.loaded = true;
BSP_RecursiveFindNumLeafs( cm.nodes );
BSP_RecursiveSetParent( cm.nodes, NULL );
@ -975,8 +1015,8 @@ cmodel_t *CM_BeginRegistration( const char *name, bool clientload, uint *checksu
Mem_Free( buf ); // release map buffer
com.strncpy( cm.name, name, MAX_STRING );
Mem_Set( cm.portalopen, 0, sizeof( cm.portalopen ));
CM_FloodAreaConnections();
cm.loaded = true;
return &cm.bmodels[0];
}
@ -997,14 +1037,14 @@ void CM_EndRegistration( void )
int CM_LeafContents( int leafnum )
{
if( leafnum < 0 || leafnum >= cm.numleafs )
Host_Error("CM_LeafContents: bad number %d\n", leafnum );
Host_Error("CM_LeafContents: bad number %i >= %i\n", leafnum, cm.numleafs );
return cm.leafs[leafnum].contents;
}
int CM_LeafCluster( int leafnum )
{
if( leafnum < 0 || leafnum >= cm.numleafs )
Host_Error("CM_LeafCluster: bad number %d\n", leafnum );
Host_Error("CM_LeafCluster: bad number %i >= %i\n", leafnum, cm.numleafs );
return cm.leafs[leafnum].cluster;
}

View File

@ -5,6 +5,8 @@
#include "cm_local.h"
static byte fatpvs[MAX_MAP_LEAFS/8];
/*
===============================================================================
@ -74,6 +76,55 @@ byte *CM_ClusterPHS( int cluster )
return cm.phsrow;
}
/*
============
CM_FatPVS
The client will interpolate the view position,
so we can't use a single PVS point
===========
*/
byte *CM_FatPVS( const vec3_t org, bool portal )
{
int leafs[128];
int i, j, count;
int longs;
byte *src;
vec3_t mins, maxs;
int snap = portal ? 1 : 8;
for( i = 0; i < 3; i++ )
{
mins[i] = org[i] - snap;
maxs[i] = org[i] + snap;
}
count = CM_BoxLeafnums( mins, maxs, leafs, 128, NULL );
if( count < 1 ) Host_Error( "CM_FatPVS: invalid leafnum count\n" );
longs = (CM_NumClusters() + 31)>>5;
// convert leafs to clusters
for( i = 0; i < count; i++ ) leafs[i] = CM_LeafCluster( leafs[i] );
if( !portal ) Mem_Copy( fatpvs, CM_ClusterPVS( leafs[0] ), longs<<2 );
// or in all the other leaf bits
for( i = portal ? 0 : 1; i < count; i++ )
{
for( j = 0; j < i; j++ )
{
if( leafs[i] == leafs[j] )
break;
}
if( j != i ) continue; // already have the cluster we want
src = CM_ClusterPVS( leafs[i] );
for( j = 0; j < longs; j++ ) ((long *)fatpvs)[j] |= ((long *)src)[j];
}
return fatpvs;
}
/*
===============================================================================
@ -81,25 +132,26 @@ AREAPORTALS
===============================================================================
*/
void CM_FloodArea_r( int areanum, int floodnum )
void CM_FloodArea_r( carea_t *area, int floodnum )
{
carea_t *area;
int i, *con;
area = &cm.areas[areanum];
int i;
dareaportal_t *p;
if( area->floodvalid == cm.floodvalid )
{
if( area->floodnum == floodnum ) return;
Host_Error("FloodArea_r: reflooded\n");
Host_Error( "CM_FloodArea_r: reflooded\n" );
}
area->floodnum = floodnum;
area->floodvalid = cm.floodvalid;
con = cm.areaportals + areanum * cm.numareas;
p = &cm.areaportals[area->firstareaportal];
for( i = 0; i < cm.numareas; i++ )
if( con[i] > 0 ) CM_FloodArea_r( i, floodnum );
for( i = 0; i < area->numareaportals; i++, p++ )
{
if( cm.portalopen[p->portalnum] )
CM_FloodArea_r( &cm.areas[p->otherarea], floodnum );
}
}
/*
@ -116,20 +168,21 @@ void CM_FloodAreaConnections( void )
cm.floodvalid++;
// area 0 is not used
for( i = 0, area = cm.areas; i < cm.numareas; i++, area++ )
for( i = 1; i < cm.numareas; i++ )
{
area = &cm.areas[i];
if( area->floodvalid == cm.floodvalid )
continue; // already flooded into
floodnum++;
CM_FloodArea_r( i, floodnum );
CM_FloodArea_r( area, floodnum );
}
}
void CM_SetAreaPortals ( byte *portals, size_t size )
{
if( size == cm.numareaportals )
if( size == sizeof( cm.portalopen ))
{
Mem_Copy( cm.areaportals, portals, cm.numareaportals );
Mem_Copy( cm.portalopen, portals, size );
CM_FloodAreaConnections();
return;
}
@ -140,28 +193,16 @@ void CM_GetAreaPortals ( byte **portals, size_t *size )
{
byte *prt = *portals;
if( prt ) Mem_Copy( prt, cm.areaportals, cm.numareaportals );
if( size) *size = cm.numareaportals;
if( prt ) Mem_Copy( prt, cm.portalopen, sizeof( cm.portalopen ));
if( size) *size = sizeof( cm.portalopen );
}
void CM_SetAreaPortalState( int area1, int area2, bool open )
void CM_SetAreaPortalState( int portalnum, bool open )
{
if( area1 < 0 || area2 < 0 ) return;
if( area1 >= cm.numareas || area2 >= cm.numareas )
Host_Error( "CM_SetAreaPortalState: bad area numbers %i or %i\n", area1, area2 );
if( portalnum > cm.numareaportals )
Host_Error( "CM_SetAreaPortalState: areaportal > numareaportals\n" );
if( open )
{
cm.areaportals[area1*cm.numareas+area2]++;
cm.areaportals[area2*cm.numareas+area1]++;
}
else
{
cm.areaportals[area1*cm.numareas+area2]--;
cm.areaportals[area2*cm.numareas+area1]--;
if(cm.areaportals[area2*cm.numareas+area1] < 0 )
Host_Error( "CM_SetAreaPortalState: negative reference count\n" );
}
cm.portalopen[portalnum] = open;
CM_FloodAreaConnections();
}
@ -188,24 +229,56 @@ that area in the same flood as the area parameter
This is used by the client refreshes to cull visibility
=================
*/
int CM_WriteAreaBits( byte *buffer, int area )
int CM_WriteAreaBits( byte *buffer, int area, bool portal )
{
int i, size, floodnum;
int i, size;
size = (cm.numareas + 7)>>3;
if( cm_noareas->integer || area == -1 )
if( cm_noareas->integer )
{
Mem_Set( buffer, 0xFF, size );
if( !portal ) Mem_Set( buffer, 0xFF, size );
}
else
{
floodnum = cm.areas[area].floodnum;
if( !portal ) Mem_Set( buffer, 0x00, size );
for( i = 0; i < cm.numareas; i++ )
{
if( cm.areas[i].floodnum == floodnum || area == -1 )
buffer[i>>3] |= 1 << (i & 7);
if(CM_AreasConnected( i, area ) || !area )
{
if( !portal ) buffer[i>>3] |= 1 << (i & 7);
else buffer[i>>3] |= 1 << (i & 7) ^ ~0;
}
}
}
return size;
}
/*
=============
CM_HeadnodeVisible
Returns true if any leaf under headnode has a cluster that
is potentially visible
=============
*/
bool CM_HeadnodeVisible( int nodenum, byte *visbits )
{
int leafnum, cluster;
cnode_t *node;
if( nodenum < 0 )
{
leafnum = -1-nodenum;
cluster = cm.leafs[leafnum].cluster;
if( cluster == -1 ) return false;
if( visbits[cluster>>3] & (1<<(cluster&7)))
return true;
return false;
}
node = &cm.nodes[nodenum];
if( CM_HeadnodeVisible( node->children[0] - cm.nodes, visbits ))
return true;
return CM_HeadnodeVisible( node->children[1] - cm.nodes, visbits );
}

View File

@ -46,7 +46,10 @@ void CM_EndRegistration ( void );
void CM_SetAreaPortals( byte *portals, size_t size );
void CM_GetAreaPortals( byte **portals, size_t *size );
void CM_SetAreaPortalState( int area1, int area2, bool open );
void CM_SetAreaPortalState( int portalnum, bool open );
bool CM_HeadnodeVisible( int nodenum, byte *visbits );
byte *CM_FatPVS( const vec3_t org, bool portal );
int CM_NumClusters( void );
int CM_NumTextures( void );
@ -66,7 +69,7 @@ int CM_BoxLeafnums( const vec3_t mins, const vec3_t maxs, int *list, int listsiz
int CM_LeafCluster( int leafnum );
int CM_LeafArea( int leafnum );
bool CM_AreasConnected( int area, int otherarea );
int CM_WriteAreaBits( byte *buffer, int area );
int CM_WriteAreaBits( byte *buffer, int area, bool portal );
void CM_ModelBounds( cmodel_t *model, vec3_t mins, vec3_t maxs );
float CM_FindFloor( vec3_t p0, float maxDist );
void CM_SetOrigin( physbody_t *body, vec3_t origin );

View File

@ -89,6 +89,9 @@ physic_exp_t DLLEXPORT *CreateAPI ( stdlib_api_t *input, physic_imp_t *engfuncs
Phys.GetAreaPortals = CM_GetAreaPortals;
Phys.SetAreaPortalState = CM_SetAreaPortalState;
Phys.HeadnodeVisible = CM_HeadnodeVisible;
Phys.FatPVS = CM_FatPVS;
Phys.NumClusters = CM_NumClusters;
Phys.NumTextures = CM_NumTextures;
Phys.NumBmodels = CM_NumInlineModels;

View File

@ -100,7 +100,7 @@ typedef struct { const char *name; void **func; } dllfunc_t; // Sys_LoadLibrary
typedef struct { int numfilenames; char **filenames; char *filenamesbuffer; } search_t;
typedef struct { int ofs; int type; const char *name; } fields_t; // prvm custom fields
typedef void (*cmsave_t) (void* handle, const void* buffer, size_t size);
typedef void (*cmdraw_t)( int color, int numpoints, const float *points );
typedef void (*cmdraw_t)( int color, int numpoints, const float *points, const int *elements );
typedef void ( *setpair_t )( const char *key, const char *value, void *buffer, void *numpairs );
typedef enum { NA_BAD, NA_LOOPBACK, NA_BROADCAST, NA_IP, NA_IPX, NA_BROADCAST_IPX } netadrtype_t;
typedef enum { mod_bad, mod_world, mod_brush, mod_studio, mod_sprite } modtype_t;

View File

@ -57,7 +57,7 @@ typedef struct physic_exp_s
void (*SetAreaPortals)( byte *portals, size_t size );
void (*GetAreaPortals)( byte **portals, size_t *size );
void (*SetAreaPortalState)( int area1, int area2, bool open );
void (*SetAreaPortalState)( int portalnum, bool open );
int (*NumClusters)( void );
int (*NumTextures)( void );
@ -67,11 +67,13 @@ typedef struct physic_exp_s
byte *(*ClusterPVS)( int cluster );
byte *(*ClusterPHS)( int cluster );
int (*PointLeafnum)( vec3_t p );
byte *(*FatPVS)( const vec3_t org, bool portal );
int (*BoxLeafnums)( vec3_t mins, vec3_t maxs, int *list, int listsize, int *lastleaf );
int (*WriteAreaBits)( byte *buffer, int area, bool portal );
bool (*HeadnodeVisible)( int nodenum, byte *visbits );
int (*LeafCluster)( int leafnum );
int (*LeafArea)( int leafnum );
bool (*AreasConnected)( int area1, int area2 );
int (*WriteAreaBits)( byte *buffer, int area );
void (*ClipToGenericEntity)( trace_t *trace, cmodel_t *model, const vec3_t bodymins, const vec3_t bodymaxs, int bodysupercontents, matrix4x4 matrix, matrix4x4 inversematrix, const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int contentsmask );
void (*ClipToWorld)( trace_t *trace, cmodel_t *model, const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int contentsmask );

View File

@ -1342,7 +1342,7 @@ static void RB_DrawModelBounds( void )
pglEnd();
}
static void RB_DrawLine( int color, int numpoints, const float *points )
static void RB_DrawLine( int color, int numpoints, const float *points, const int *elements )
{
int i = numpoints - 1;
vec3_t p0, p1;

View File

@ -2048,6 +2048,7 @@ static void R_UploadTexture( rgbdata_t *pic, texture_t *tex )
texture_t *R_CreateImage( const char *name, byte *buf, int width, int height, texFlags_t texFlags, texFilter_t filter, texWrap_t wrap )
{
rgbdata_t r_generic;
int i;
Mem_Set( &r_generic, 0, sizeof( r_generic ));
r_generic.width = width;
@ -2058,8 +2059,16 @@ texture_t *R_CreateImage( const char *name, byte *buf, int width, int height, te
r_generic.buffer = buf;
// setup image flags
if( texFlags & TF_CUBEMAP ) r_generic.flags |= TF_CUBEMAP;
if( texFlags & TF_CUBEMAP ) r_generic.flags |= IMAGE_CUBEMAP;
for( i = 0; i < width * height; i++ )
{
if( buf[i*4+2] != buf[i*4+1] || buf[i*4+1] != buf[i*4+0] )
{
r_generic.flags |= IMAGE_HAS_COLOR;
break;
}
}
return R_LoadTexture( name, &r_generic, 0, texFlags, filter, wrap );
}
@ -2483,6 +2492,8 @@ void RB_ShowTextures( void )
continue;
if( r_showtextures->integer == 2 && !(texture->flags & TF_STATIC ))
continue;
if( r_showtextures->integer == 3 && !(texture->flags & TF_LIGHTMAP ))
continue;
w = r_width->integer / 10;
h = r_height->integer / 8;

View File

@ -618,7 +618,7 @@ static void R_BuildLightmap( surface_t *surf, byte *dest, int stride )
{
int i, map, size, s, t;
vec3_t scale;
float *bl;
float *bl, max;
byte *lm;
lm = surf->lmSamples;
@ -673,8 +673,34 @@ static void R_BuildLightmap( surface_t *surf, byte *dest, int stride )
{
for( s = 0; s < surf->lmWidth; s++ )
{
ColorNormalize( bl, bl );
Vector4Set( dest, bl[0], bl[1], bl[2], 255 );
// catch negative lights
if( bl[0] < 0 ) bl[0] = 0;
if( bl[1] < 0 ) bl[1] = 0;
if( bl[2] < 0 ) bl[2] = 0;
// determine the brightest of the three color components
max = bl[0];
if( max < bl[1] ) max = bl[1];
if( max < bl[2] ) max = bl[2];
// rescale all the color components if the intensity of the
// greatest channel exceeds 255
if( max > 255.0 )
{
max = 255.0 / max;
dest[0] = bl[0] * max;
dest[1] = bl[1] * max;
dest[2] = bl[2] * max;
dest[3] = 255;
}
else
{
dest[0] = bl[0];
dest[1] = bl[1];
dest[2] = bl[2];
dest[3] = 255;
}
bl += 3;
dest += 4;
}
@ -714,7 +740,7 @@ static void R_UploadLightmap( void )
Host_Error( "R_UploadLightmap: MAX_LIGHTMAPS limit exceeded\n" );
com.snprintf( name, sizeof(name), "*lightmap%i", r_lmState.currentNum );
lightmap = R_CreateImage( va("*lightmap%d", r_lmState.currentNum ), (byte *)r_lmState.buffer, LM_SIZE, LM_SIZE, 0, 0, TW_CLAMP );
lightmap = R_CreateImage( va("*lightmap%d", r_lmState.currentNum ), (byte *)r_lmState.buffer, LM_SIZE, LM_SIZE, TF_LIGHTMAP, 0, TW_CLAMP );
r_lightmapTextures[r_lmState.currentNum++] = lightmap;
// reset

View File

@ -49,6 +49,7 @@ typedef enum
TF_NORMALMAP = BIT(5),
TF_GEN_MIPS = BIT(6),
TF_CUBEMAP = BIT(7),
TF_LIGHTMAP = BIT(8),
} texFlags_t;
typedef enum

View File

@ -1764,7 +1764,7 @@ static bool R_ParseStageMap( ref_shader_t *shader, shaderStage_t *stage, script_
return false;
}
if( !Com_ReadToken( script, SC_ALLOW_PATHNAMES, &tok ))
if( !Com_ReadToken( script, SC_PARSE_GENERIC, &tok ))
{
MsgDev( D_WARN, "missing parameters for 'map' in shader '%s'\n", shader->name );
return false;
@ -3694,7 +3694,7 @@ static void R_ParseShaderFile( script_t *script, const char *name )
while( 1 )
{
// parse the name
if( !Com_ReadToken( script, SC_ALLOW_NEWLINES|SC_ALLOW_PATHNAMES, &tok ))
if( !Com_ReadToken( script, SC_ALLOW_NEWLINES|SC_PARSE_GENERIC, &tok ))
break; // end of data