rename net_com.c to checksum.c and create checksum.h.

Also, preliminary steps to merging model.c and gl_model.c as much as possible
before splitting them into functional chunks.
This commit is contained in:
Bill Currie 2000-08-30 06:56:25 +00:00
parent c1ac5ca92a
commit 514fb7069e
5 changed files with 237 additions and 250 deletions

34
include/checksum.h Normal file
View file

@ -0,0 +1,34 @@
/*
checksum.h
@description@
Copyright (C) 1996-1997 Id Software, Inc.
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 2
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
$Id$
*/
#ifndef __checksum_h
#define __checksum_h
unsigned Com_BlockChecksum (void *buffer, int length);
#endif // __checksum_h

View file

@ -104,7 +104,7 @@ EXTRA_libqfcd_a_SOURCES= cd_audio.c cd_win.c cd_linux.c cd_null.c
#
# ... Networking
#
libqfnet_a_SOURCES= mdfour.c net_bsd.c net_com.c net_dgrm.c net_loop.c \
libqfnet_a_SOURCES= mdfour.c net_bsd.c checksum.c net_dgrm.c net_loop.c \
net_main.c net_udp.c net_vcr.c
EXTRA_libqfcd_a_SOURCES=net_dos.c net_bw.c net_ipx.c net_mp.c net_ser.c \

View file

@ -30,37 +30,15 @@
// on the same machine.
#ifdef HAVE_CONFIG_H
# include <config.h>
# include "config.h"
#endif
#include <math.h>
#include <string.h>
#include <stdio.h>
#include "qendian.h"
#include "msg.h"
#include "bspfile.h" // needed by: glquake.h
#include "vid.h"
#include "r_local.h"
#include "sys.h"
#include "mathlib.h" // needed by: protocol.h, render.h, client.h,
// modelgen.h, glmodel.h
#include "wad.h"
#include "draw.h"
#include "cvar.h"
#include "crc.h"
#include "net.h" // needed by: client.h
#include "protocol.h" // needed by: client.h
#include "cmd.h"
#include "sbar.h"
#include "render.h" // needed by: client.h, gl_model.h, glquake.h
#include "client.h" // need cls in this file
#include "model.h" // needed by: glquake.h
#include "console.h"
#include "qendian.h"
#include "checksum.h"
#include "glquake.h"
#include "quakefs.h"
void Sys_Error (char *error, ...);
extern int texture_mode;
model_t *loadmodel;
char loadname[32]; // for hunk tags
@ -69,8 +47,6 @@ void Mod_LoadSpriteModel (model_t *mod, void *buffer);
void Mod_LoadBrushModel (model_t *mod, void *buffer);
void Mod_LoadAliasModel (model_t *mod, void *buffer);
model_t *Mod_LoadModel (model_t *mod, qboolean crash);
void R_InitSky(struct texture_s *mt);
void GL_SubdivideSurface (msurface_t *fa);
void Mod_LoadMMNearest(miptex_t *mx, texture_t *tx);
byte mod_novis[MAX_MAP_LEAFS/8];
@ -140,9 +116,6 @@ byte *Mod_DecompressVis (byte *in, model_t *model)
row = (model->numleafs+7)>>3;
out = decompressed;
#if 0
memcpy (out, in, row);
#else
if (!in)
{ // no vis info, so make all visible
while (row)
@ -169,7 +142,6 @@ byte *Mod_DecompressVis (byte *in, model_t *model)
c--;
}
} while (out - decompressed < row);
#endif
return decompressed;
}
@ -479,8 +451,6 @@ void Mod_LoadTextures (lump_t *l)
}
}
extern byte *COM_LoadFile (char *path, int usehunk);
/*
=================
Mod_LoadLighting
@ -908,7 +878,6 @@ void Mod_LoadLeafs (lump_t *l)
dleaf_t *in;
mleaf_t *out;
int i, j, count, p;
//char s[80];
qboolean isnotmap = true;
in = (void *)(mod_base + l->fileofs);
@ -919,7 +888,6 @@ void Mod_LoadLeafs (lump_t *l)
loadmodel->leafs = out;
loadmodel->numleafs = count;
//snprintf (s, sizeof(s), "maps/%s.bsp", Info_ValueForKey(cl.serverinfo,"map"));
if (!strncmp("maps/", loadmodel->name,5))
isnotmap = false;
for ( i=0 ; i<count ; i++, in++, out++)
@ -1160,8 +1128,6 @@ float RadiusFromBounds (vec3_t mins, vec3_t maxs)
return Length (corner);
}
unsigned Com_BlockChecksum (void *buffer, int length);
/*
=================
Mod_LoadBrushModel
@ -1224,6 +1190,7 @@ void Mod_LoadBrushModel (model_t *mod, void *buffer)
Mod_MakeHull0 ();
mod->numframes = 2; // regular and alternate animation
mod->flags = 0;
//
// set up the submodels (FIXME: this is confusing)
@ -1262,8 +1229,6 @@ void Mod_LoadBrushModel (model_t *mod, void *buffer)
}
}
void Sys_Error (char *error, ...);
extern char loadname[]; // for hunk tags
extern model_t *loadmodel;
extern model_t mod_known[];
@ -1276,7 +1241,7 @@ model_t *Mod_FindName (char *name);
/*
===============
Mod_Init
Mod_Extradata
Caches the data if needed
===============

View file

@ -1,7 +1,7 @@
/*
model.c
@description@
model loading and caching
Copyright (C) 1996-1997 Id Software, Inc.
@ -34,6 +34,7 @@
#include "sys.h"
#include "console.h"
#include "qendian.h"
#include "checksum.h"
model_t *loadmodel;
char loadname[32]; // for hunk tags
@ -45,14 +46,13 @@ model_t *Mod_LoadModel (model_t *mod, qboolean crash);
byte mod_novis[MAX_MAP_LEAFS/8];
#define MAX_MOD_KNOWN 256
#define MAX_MOD_KNOWN 512
model_t mod_known[MAX_MOD_KNOWN];
int mod_numknown;
// values for model_t's needload
#define NL_PRESENT 0
#define NL_NEEDS_LOADED 1
#define NL_UNREFERENCED 2
unsigned *model_checksum;
texture_t *r_notexture_mip;
cvar_t *gl_subdivide_size;
/*
===============
@ -61,31 +61,10 @@ Mod_Init
*/
void Mod_Init (void)
{
gl_subdivide_size = Cvar_Get("gl_subdivide_size", "128", CVAR_ARCHIVE, "None");
memset (mod_novis, 0xff, sizeof(mod_novis));
}
/*
===============
Mod_Extradata
Caches the data if needed
===============
*/
void *Mod_Extradata (model_t *mod)
{
void *r;
r = Cache_Check (&mod->cache);
if (r)
return r;
Mod_LoadModel (mod, true);
if (!mod->cache.data)
Sys_Error ("Mod_Extradata: caching failed");
return mod->cache.data;
}
/*
===============
Mod_PointInLeaf
@ -179,12 +158,9 @@ void Mod_ClearAll (void)
int i;
model_t *mod;
for (i=0 , mod=mod_known ; i<mod_numknown ; i++, mod++) {
mod->needload = NL_UNREFERENCED;
//FIX FOR CACHE_ALLOC ERRORS:
if (mod->type == mod_sprite) mod->cache.data = NULL;
}
for (i=0 , mod=mod_known ; i<mod_numknown ; i++, mod++)
if (mod->type != mod_alias)
mod->needload = true;
}
/*
@ -197,7 +173,6 @@ model_t *Mod_FindName (char *name)
{
int i;
model_t *mod;
model_t *avail = NULL;
if (!name[0])
Sys_Error ("Mod_ForName: NULL name");
@ -206,56 +181,21 @@ model_t *Mod_FindName (char *name)
// search the currently loaded models
//
for (i=0 , mod=mod_known ; i<mod_numknown ; i++, mod++)
{
if (!strcmp (mod->name, name) )
break;
if (mod->needload == NL_UNREFERENCED)
if (!avail || mod->type != mod_alias)
avail = mod;
}
if (i == mod_numknown)
{
if (mod_numknown == MAX_MOD_KNOWN)
{
if (avail)
{
mod = avail;
if (mod->type == mod_alias)
if (Cache_Check (&mod->cache))
Cache_Free (&mod->cache);
}
else
Sys_Error ("mod_numknown == MAX_MOD_KNOWN");
}
else
mod_numknown++;
Sys_Error ("mod_numknown == MAX_MOD_KNOWN");
strcpy (mod->name, name);
mod->needload = NL_NEEDS_LOADED;
mod->needload = true;
mod_numknown++;
}
return mod;
}
/*
==================
Mod_TouchModel
==================
*/
void Mod_TouchModel (char *name)
{
model_t *mod;
mod = Mod_FindName (name);
if (mod->needload == NL_PRESENT)
{
if (mod->type == mod_alias)
Cache_Check (&mod->cache);
}
}
/*
==================
Mod_LoadModel
@ -265,26 +205,21 @@ Loads a model into the cache
*/
model_t *Mod_LoadModel (model_t *mod, qboolean crash)
{
void *d;
unsigned *buf;
byte stackbuf[1024]; // avoid dirtying the cache heap
if (mod->type == mod_alias)
if (!mod->needload)
{
if (Cache_Check (&mod->cache))
if (mod->type == mod_alias)
{
mod->needload = NL_PRESENT;
return mod;
d = Cache_Check (&mod->cache);
if (d)
return mod;
}
else
return mod; // not cached at all
}
else
{
if (mod->needload == NL_PRESENT)
return mod;
}
//
// because the world is so huge, load it one piece at a time
//
//
// load the file
@ -309,7 +244,8 @@ model_t *Mod_LoadModel (model_t *mod, qboolean crash)
//
// call the apropriate loader
mod->needload = NL_PRESENT;
mod->needload = false;
mod->hasfullbrights = false;
switch (LittleLong(*(unsigned *)buf))
{
@ -672,10 +608,13 @@ void Mod_LoadTexinfo (lump_t *l)
for ( i=0 ; i<count ; i++, in++, out++)
{
for (j=0 ; j<8 ; j++)
for (j=0 ; j<4 ; j++) {
out->vecs[0][j] = LittleFloat (in->vecs[0][j]);
out->vecs[1][j] = LittleFloat (in->vecs[1][j]);
}
len1 = Length (out->vecs[0]);
len2 = Length (out->vecs[1]);
len1 = (len1 + len2)/2;
if (len1 < 0.32)
out->mipadjust = 4;
@ -685,12 +624,6 @@ void Mod_LoadTexinfo (lump_t *l)
out->mipadjust = 2;
else
out->mipadjust = 1;
#if 0
if (len1 + len2 < 0.001)
out->mipadjust = 1; // don't crash
else
out->mipadjust = 1 / floor( (len1+len2)/2 + 0.1 );
#endif
miptex = LittleLong (in->miptex);
out->flags = LittleLong (in->flags);
@ -762,7 +695,7 @@ void CalcSurfaceExtents (msurface_t *s)
s->texturemins[i] = bmins[i] * 16;
s->extents[i] = (bmaxs[i] - bmins[i]) * 16;
if ( !(tex->flags & TEX_SPECIAL) && s->extents[i] > 256)
if ( !(tex->flags & TEX_SPECIAL) && s->extents[i] > 512 /* 256 */ )
Sys_Error ("Bad surface extents");
}
}
@ -909,6 +842,7 @@ void Mod_LoadLeafs (lump_t *l)
dleaf_t *in;
mleaf_t *out;
int i, j, count, p;
qboolean isnotmap = true;
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
@ -918,7 +852,8 @@ void Mod_LoadLeafs (lump_t *l)
loadmodel->leafs = out;
loadmodel->numleafs = count;
if (!strncmp("maps/", loadmodel->name,5))
isnotmap = false;
for ( i=0 ; i<count ; i++, in++, out++)
{
for (j=0 ; j<3 ; j++)
@ -1170,6 +1105,22 @@ void Mod_LoadBrushModel (model_t *mod, void *buffer)
for (i=0 ; i<sizeof(dheader_t)/4 ; i++)
((int *)header)[i] = LittleLong ( ((int *)header)[i]);
// checksum all of the map, except for entities
mod->checksum = 0;
mod->checksum2 = 0;
for (i = 0; i < HEADER_LUMPS; i++) {
if (i == LUMP_ENTITIES)
continue;
mod->checksum ^= LittleLong(Com_BlockChecksum(mod_base + header->lumps[i].fileofs,
header->lumps[i].filelen));
if (i == LUMP_VISIBILITY || i == LUMP_LEAFS || i == LUMP_NODES)
continue;
mod->checksum2 ^= LittleLong(Com_BlockChecksum(mod_base + header->lumps[i].fileofs,
header->lumps[i].filelen));
}
// load into heap
Mod_LoadVertexes (&header->lumps[LUMP_VERTEXES]);
@ -1212,6 +1163,7 @@ void Mod_LoadBrushModel (model_t *mod, void *buffer)
VectorCopy (bm->maxs, mod->maxs);
VectorCopy (bm->mins, mod->mins);
mod->radius = RadiusFromBounds (mod->mins, mod->maxs);
mod->numleafs = bm->visleafs;
@ -1229,6 +1181,47 @@ void Mod_LoadBrushModel (model_t *mod, void *buffer)
}
}
/*
===============
Mod_Extradata
Caches the data if needed
===============
*/
void *Mod_Extradata (model_t *mod)
{
void *r;
r = Cache_Check (&mod->cache);
if (r)
return r;
Mod_LoadModel (mod, true);
if (!mod->cache.data)
Sys_Error ("Mod_Extradata: caching failed");
return mod->cache.data;
}
/*
==================
Mod_TouchModel
==================
*/
void Mod_TouchModel (char *name)
{
model_t *mod;
mod = Mod_FindName (name);
if (~mod->needload)
{
if (mod->type == mod_alias)
Cache_Check (&mod->cache);
}
}
/*
==============================================================================
@ -1872,12 +1865,7 @@ void Mod_Print (void)
Con_Printf ("Cached models:\n");
for (i=0, mod=mod_known ; i < mod_numknown ; i++, mod++)
{
Con_Printf ("%8p : %s",mod->cache.data, mod->name);
if (mod->needload & NL_UNREFERENCED)
Con_Printf (" (!R)");
if (mod->needload & NL_NEEDS_LOADED)
Con_Printf (" (!P)");
Con_Printf ("\n");
Con_Printf ("%8p : %s\n",mod->cache.data, mod->name);
}
}