2000-05-10 20:33:16 +00:00
|
|
|
/*
|
2000-09-20 22:11:17 +00:00
|
|
|
model_bursh.c
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-22 06:58:14 +00:00
|
|
|
model loading and caching
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
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.
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
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.
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
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$
|
2000-05-10 20:33:16 +00:00
|
|
|
*/
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
// models are the only shared resource between a client and server running
|
|
|
|
// on the same machine.
|
2000-05-22 06:58:14 +00:00
|
|
|
|
2000-05-17 10:03:19 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2000-12-08 06:51:37 +00:00
|
|
|
# include "config.h"
|
2000-05-17 10:03:19 +00:00
|
|
|
#endif
|
2000-12-30 02:16:36 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
2001-02-07 05:45:59 +00:00
|
|
|
# include <string.h>
|
2000-12-30 02:16:36 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
2001-02-07 05:45:59 +00:00
|
|
|
# include <strings.h>
|
2000-12-30 02:16:36 +00:00
|
|
|
#endif
|
2000-05-12 19:17:02 +00:00
|
|
|
|
2001-02-07 05:45:59 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
|
2000-12-30 02:16:36 +00:00
|
|
|
#include "checksum.h"
|
2000-12-17 22:07:06 +00:00
|
|
|
#include "cvar.h"
|
2000-09-20 22:11:17 +00:00
|
|
|
#include "model.h"
|
2000-05-21 08:24:45 +00:00
|
|
|
#include "qendian.h"
|
2000-09-20 22:11:17 +00:00
|
|
|
#include "server.h"
|
2000-06-03 12:15:49 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
extern model_t *loadmodel;
|
|
|
|
extern char loadname[];
|
2000-06-03 12:15:49 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
extern const int mod_lightmap_bytes;
|
2000-06-03 12:15:49 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
byte mod_novis[MAX_MAP_LEAFS / 8];
|
2000-06-03 12:15:49 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
void GL_SubdivideSurface (msurface_t *fa);
|
2000-12-17 22:07:06 +00:00
|
|
|
extern cvar_t *gl_sky_divide;
|
2000-09-29 20:02:16 +00:00
|
|
|
|
2000-06-03 12:15:49 +00:00
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
Mod_PointInLeaf
|
2000-06-03 12:15:49 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
mleaf_t *
|
|
|
|
Mod_PointInLeaf (vec3_t p, model_t *model)
|
2000-06-03 12:15:49 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
mnode_t *node;
|
|
|
|
float d;
|
|
|
|
mplane_t *plane;
|
|
|
|
|
2000-06-03 12:15:49 +00:00
|
|
|
if (!model || !model->nodes)
|
|
|
|
SV_Error ("Mod_PointInLeaf: bad model");
|
|
|
|
|
|
|
|
node = model->nodes;
|
2000-12-08 06:51:37 +00:00
|
|
|
while (1) {
|
2000-06-03 12:15:49 +00:00
|
|
|
if (node->contents < 0)
|
2000-12-08 06:51:37 +00:00
|
|
|
return (mleaf_t *) node;
|
2000-06-03 12:15:49 +00:00
|
|
|
plane = node->plane;
|
2000-12-08 06:51:37 +00:00
|
|
|
d = DotProduct (p, plane->normal) - plane->dist;
|
2000-06-03 12:15:49 +00:00
|
|
|
if (d > 0)
|
|
|
|
node = node->children[0];
|
|
|
|
else
|
|
|
|
node = node->children[1];
|
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
|
|
|
|
return NULL; // never reached
|
2000-06-03 12:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
Mod_DecompressVis
|
2000-06-03 12:15:49 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
byte *
|
|
|
|
Mod_DecompressVis (byte * in, model_t *model)
|
2000-06-03 12:15:49 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
static byte decompressed[MAX_MAP_LEAFS / 8];
|
|
|
|
int c;
|
|
|
|
byte *out;
|
|
|
|
int row;
|
2000-06-03 12:15:49 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
row = (model->numleafs + 7) >> 3;
|
2000-06-03 12:15:49 +00:00
|
|
|
out = decompressed;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
memcpy (out, in, row);
|
|
|
|
#else
|
2000-12-08 06:51:37 +00:00
|
|
|
if (!in) { // no vis info, so make all visible
|
|
|
|
while (row) {
|
2000-06-03 12:15:49 +00:00
|
|
|
*out++ = 0xff;
|
|
|
|
row--;
|
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
return decompressed;
|
2000-06-03 12:15:49 +00:00
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
do {
|
|
|
|
if (*in) {
|
2000-06-03 12:15:49 +00:00
|
|
|
*out++ = *in++;
|
|
|
|
continue;
|
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
|
2000-06-03 12:15:49 +00:00
|
|
|
c = in[1];
|
|
|
|
in += 2;
|
2000-12-08 06:51:37 +00:00
|
|
|
while (c) {
|
2000-06-03 12:15:49 +00:00
|
|
|
*out++ = 0;
|
|
|
|
c--;
|
|
|
|
}
|
|
|
|
} while (out - decompressed < row);
|
|
|
|
#endif
|
2000-12-08 06:51:37 +00:00
|
|
|
|
2000-06-03 12:15:49 +00:00
|
|
|
return decompressed;
|
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
byte *
|
|
|
|
Mod_LeafPVS (mleaf_t *leaf, model_t *model)
|
2000-06-03 12:15:49 +00:00
|
|
|
{
|
|
|
|
if (leaf == model->leafs)
|
|
|
|
return mod_novis;
|
|
|
|
return Mod_DecompressVis (leaf->compressed_vis, model);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
BRUSHMODEL LOADING
|
|
|
|
*/
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
byte *mod_base;
|
2000-06-03 12:15:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
Mod_LoadTextures
|
2000-06-03 12:15:49 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Mod_LoadTextures (lump_t *l)
|
2000-06-03 12:15:49 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
int i, j, pixels, num, max, altmax;
|
|
|
|
miptex_t *mt;
|
|
|
|
texture_t *tx, *tx2;
|
|
|
|
texture_t *anims[10];
|
|
|
|
texture_t *altanims[10];
|
2000-06-03 12:15:49 +00:00
|
|
|
dmiptexlump_t *m;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (!l->filelen) {
|
2000-06-03 12:15:49 +00:00
|
|
|
loadmodel->textures = NULL;
|
|
|
|
return;
|
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
m = (dmiptexlump_t *) (mod_base + l->fileofs);
|
|
|
|
|
2000-06-03 12:15:49 +00:00
|
|
|
m->nummiptex = LittleLong (m->nummiptex);
|
2000-12-08 06:51:37 +00:00
|
|
|
|
2000-06-03 12:15:49 +00:00
|
|
|
loadmodel->numtextures = m->nummiptex;
|
2000-12-08 06:51:37 +00:00
|
|
|
loadmodel->textures =
|
|
|
|
Hunk_AllocName (m->nummiptex * sizeof (*loadmodel->textures), loadname);
|
2000-06-03 12:15:49 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (i = 0; i < m->nummiptex; i++) {
|
|
|
|
m->dataofs[i] = LittleLong (m->dataofs[i]);
|
2000-06-03 12:15:49 +00:00
|
|
|
if (m->dataofs[i] == -1)
|
|
|
|
continue;
|
2000-12-08 06:51:37 +00:00
|
|
|
mt = (miptex_t *) ((byte *) m + m->dataofs[i]);
|
2000-06-03 12:15:49 +00:00
|
|
|
mt->width = LittleLong (mt->width);
|
|
|
|
mt->height = LittleLong (mt->height);
|
2000-12-08 06:51:37 +00:00
|
|
|
for (j = 0; j < MIPLEVELS; j++)
|
2000-06-03 12:15:49 +00:00
|
|
|
mt->offsets[j] = LittleLong (mt->offsets[j]);
|
2000-12-08 06:51:37 +00:00
|
|
|
|
|
|
|
if ((mt->width & 15) || (mt->height & 15))
|
2000-06-03 12:15:49 +00:00
|
|
|
SV_Error ("Texture %s is not 16 aligned", mt->name);
|
2000-12-08 06:51:37 +00:00
|
|
|
pixels = mt->width * mt->height / 64 * 85;
|
|
|
|
tx = Hunk_AllocName (sizeof (texture_t) + pixels, loadname);
|
|
|
|
|
2000-06-03 12:15:49 +00:00
|
|
|
loadmodel->textures[i] = tx;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
memcpy (tx->name, mt->name, sizeof (tx->name));
|
2000-06-03 12:15:49 +00:00
|
|
|
tx->width = mt->width;
|
|
|
|
tx->height = mt->height;
|
2000-12-08 06:51:37 +00:00
|
|
|
for (j = 0; j < MIPLEVELS; j++)
|
|
|
|
tx->offsets[j] =
|
|
|
|
|
|
|
|
mt->offsets[j] + sizeof (texture_t) - sizeof (miptex_t);
|
2000-06-03 12:15:49 +00:00
|
|
|
// the pixels immediately follow the structures
|
2000-12-08 06:51:37 +00:00
|
|
|
memcpy (tx + 1, mt + 1, pixels);
|
2000-06-03 12:15:49 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (!strncmp (mt->name, "sky", 3))
|
2000-06-03 12:15:49 +00:00
|
|
|
R_InitSky (tx);
|
2000-12-08 06:51:37 +00:00
|
|
|
else {
|
|
|
|
Mod_ProcessTexture (mt, tx);
|
2000-06-03 12:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// sequence the animations
|
|
|
|
//
|
2000-12-08 06:51:37 +00:00
|
|
|
for (i = 0; i < m->nummiptex; i++) {
|
2000-06-03 12:15:49 +00:00
|
|
|
tx = loadmodel->textures[i];
|
|
|
|
if (!tx || tx->name[0] != '+')
|
|
|
|
continue;
|
|
|
|
if (tx->anim_next)
|
2000-12-08 06:51:37 +00:00
|
|
|
continue; // allready sequenced
|
2000-06-03 12:15:49 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
// find the number of frames in the animation
|
|
|
|
memset (anims, 0, sizeof (anims));
|
|
|
|
memset (altanims, 0, sizeof (altanims));
|
2000-06-03 12:15:49 +00:00
|
|
|
|
|
|
|
max = tx->name[1];
|
|
|
|
altmax = 0;
|
|
|
|
if (max >= 'a' && max <= 'z')
|
|
|
|
max -= 'a' - 'A';
|
2000-12-08 06:51:37 +00:00
|
|
|
if (max >= '0' && max <= '9') {
|
2000-06-03 12:15:49 +00:00
|
|
|
max -= '0';
|
|
|
|
altmax = 0;
|
|
|
|
anims[max] = tx;
|
|
|
|
max++;
|
2000-12-08 06:51:37 +00:00
|
|
|
} else if (max >= 'A' && max <= 'J') {
|
2000-06-03 12:15:49 +00:00
|
|
|
altmax = max - 'A';
|
|
|
|
max = 0;
|
|
|
|
altanims[altmax] = tx;
|
|
|
|
altmax++;
|
2000-12-08 06:51:37 +00:00
|
|
|
} else
|
2000-06-03 12:15:49 +00:00
|
|
|
SV_Error ("Bad animating texture %s", tx->name);
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (j = i + 1; j < m->nummiptex; j++) {
|
2000-06-03 12:15:49 +00:00
|
|
|
tx2 = loadmodel->textures[j];
|
|
|
|
if (!tx2 || tx2->name[0] != '+')
|
|
|
|
continue;
|
2000-12-08 06:51:37 +00:00
|
|
|
if (strcmp (tx2->name + 2, tx->name + 2))
|
2000-06-03 12:15:49 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
num = tx2->name[1];
|
|
|
|
if (num >= 'a' && num <= 'z')
|
|
|
|
num -= 'a' - 'A';
|
2000-12-08 06:51:37 +00:00
|
|
|
if (num >= '0' && num <= '9') {
|
2000-06-03 12:15:49 +00:00
|
|
|
num -= '0';
|
|
|
|
anims[num] = tx2;
|
2000-12-08 06:51:37 +00:00
|
|
|
if (num + 1 > max)
|
2000-06-03 12:15:49 +00:00
|
|
|
max = num + 1;
|
2000-12-08 06:51:37 +00:00
|
|
|
} else if (num >= 'A' && num <= 'J') {
|
2000-06-03 12:15:49 +00:00
|
|
|
num = num - 'A';
|
|
|
|
altanims[num] = tx2;
|
2000-12-08 06:51:37 +00:00
|
|
|
if (num + 1 > altmax)
|
|
|
|
altmax = num + 1;
|
|
|
|
} else
|
2000-06-03 12:15:49 +00:00
|
|
|
SV_Error ("Bad animating texture %s", tx->name);
|
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
|
2000-06-03 12:15:49 +00:00
|
|
|
#define ANIM_CYCLE 2
|
2000-12-08 06:51:37 +00:00
|
|
|
// link them all together
|
|
|
|
for (j = 0; j < max; j++) {
|
2000-06-03 12:15:49 +00:00
|
|
|
tx2 = anims[j];
|
|
|
|
if (!tx2)
|
2000-12-08 06:51:37 +00:00
|
|
|
SV_Error ("Missing frame %i of %s", j, tx->name);
|
2000-06-03 12:15:49 +00:00
|
|
|
tx2->anim_total = max * ANIM_CYCLE;
|
|
|
|
tx2->anim_min = j * ANIM_CYCLE;
|
2000-12-08 06:51:37 +00:00
|
|
|
tx2->anim_max = (j + 1) * ANIM_CYCLE;
|
|
|
|
tx2->anim_next = anims[(j + 1) % max];
|
2000-06-03 12:15:49 +00:00
|
|
|
if (altmax)
|
|
|
|
tx2->alternate_anims = altanims[0];
|
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
for (j = 0; j < altmax; j++) {
|
2000-06-03 12:15:49 +00:00
|
|
|
tx2 = altanims[j];
|
|
|
|
if (!tx2)
|
2000-12-08 06:51:37 +00:00
|
|
|
SV_Error ("Missing frame %i of %s", j, tx->name);
|
2000-06-03 12:15:49 +00:00
|
|
|
tx2->anim_total = altmax * ANIM_CYCLE;
|
|
|
|
tx2->anim_min = j * ANIM_CYCLE;
|
2000-12-08 06:51:37 +00:00
|
|
|
tx2->anim_max = (j + 1) * ANIM_CYCLE;
|
|
|
|
tx2->anim_next = altanims[(j + 1) % altmax];
|
2000-06-03 12:15:49 +00:00
|
|
|
if (max)
|
|
|
|
tx2->alternate_anims = anims[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
Mod_LoadVisibility
|
2000-06-03 12:15:49 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Mod_LoadVisibility (lump_t *l)
|
2000-06-03 12:15:49 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
if (!l->filelen) {
|
2000-06-03 12:15:49 +00:00
|
|
|
loadmodel->visdata = NULL;
|
|
|
|
return;
|
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
loadmodel->visdata = Hunk_AllocName (l->filelen, loadname);
|
2000-06-03 12:15:49 +00:00
|
|
|
memcpy (loadmodel->visdata, mod_base + l->fileofs, l->filelen);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
Mod_LoadEntities
|
2000-06-03 12:15:49 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Mod_LoadEntities (lump_t *l)
|
2000-06-03 12:15:49 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
if (!l->filelen) {
|
2000-06-03 12:15:49 +00:00
|
|
|
loadmodel->entities = NULL;
|
|
|
|
return;
|
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
loadmodel->entities = Hunk_AllocName (l->filelen, loadname);
|
2000-06-03 12:15:49 +00:00
|
|
|
memcpy (loadmodel->entities, mod_base + l->fileofs, l->filelen);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
Mod_LoadVertexes
|
2000-06-03 12:15:49 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Mod_LoadVertexes (lump_t *l)
|
2000-06-03 12:15:49 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
dvertex_t *in;
|
|
|
|
mvertex_t *out;
|
|
|
|
int i, count;
|
2000-06-03 12:15:49 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
in = (void *) (mod_base + l->fileofs);
|
|
|
|
if (l->filelen % sizeof (*in))
|
|
|
|
SV_Error ("MOD_LoadBmodel: funny lump size in %s", loadmodel->name);
|
|
|
|
count = l->filelen / sizeof (*in);
|
|
|
|
out = Hunk_AllocName (count * sizeof (*out), loadname);
|
2000-06-03 12:15:49 +00:00
|
|
|
|
|
|
|
loadmodel->vertexes = out;
|
|
|
|
loadmodel->numvertexes = count;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (i = 0; i < count; i++, in++, out++) {
|
2000-06-03 12:15:49 +00:00
|
|
|
out->position[0] = LittleFloat (in->point[0]);
|
|
|
|
out->position[1] = LittleFloat (in->point[1]);
|
|
|
|
out->position[2] = LittleFloat (in->point[2]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
Mod_LoadSubmodels
|
2000-06-03 12:15:49 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Mod_LoadSubmodels (lump_t *l)
|
2000-06-03 12:15:49 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
dmodel_t *in;
|
|
|
|
dmodel_t *out;
|
|
|
|
int i, j, count;
|
2000-06-03 12:15:49 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
in = (void *) (mod_base + l->fileofs);
|
|
|
|
if (l->filelen % sizeof (*in))
|
|
|
|
SV_Error ("MOD_LoadBmodel: funny lump size in %s", loadmodel->name);
|
|
|
|
count = l->filelen / sizeof (*in);
|
|
|
|
out = Hunk_AllocName (count * sizeof (*out), loadname);
|
2000-06-03 12:15:49 +00:00
|
|
|
|
|
|
|
loadmodel->submodels = out;
|
|
|
|
loadmodel->numsubmodels = count;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (i = 0; i < count; i++, in++, out++) {
|
|
|
|
for (j = 0; j < 3; j++) { // spread the mins / maxs by a pixel
|
2000-06-03 12:15:49 +00:00
|
|
|
out->mins[j] = LittleFloat (in->mins[j]) - 1;
|
|
|
|
out->maxs[j] = LittleFloat (in->maxs[j]) + 1;
|
|
|
|
out->origin[j] = LittleFloat (in->origin[j]);
|
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
for (j = 0; j < MAX_MAP_HULLS; j++)
|
2000-06-03 12:15:49 +00:00
|
|
|
out->headnode[j] = LittleLong (in->headnode[j]);
|
|
|
|
out->visleafs = LittleLong (in->visleafs);
|
|
|
|
out->firstface = LittleLong (in->firstface);
|
|
|
|
out->numfaces = LittleLong (in->numfaces);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
Mod_LoadEdges
|
2000-06-03 12:15:49 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Mod_LoadEdges (lump_t *l)
|
2000-06-03 12:15:49 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
dedge_t *in;
|
|
|
|
medge_t *out;
|
|
|
|
int i, count;
|
2000-06-03 12:15:49 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
in = (void *) (mod_base + l->fileofs);
|
|
|
|
if (l->filelen % sizeof (*in))
|
|
|
|
SV_Error ("MOD_LoadBmodel: funny lump size in %s", loadmodel->name);
|
|
|
|
count = l->filelen / sizeof (*in);
|
|
|
|
out = Hunk_AllocName ((count + 1) * sizeof (*out), loadname);
|
2000-06-03 12:15:49 +00:00
|
|
|
|
|
|
|
loadmodel->edges = out;
|
|
|
|
loadmodel->numedges = count;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (i = 0; i < count; i++, in++, out++) {
|
|
|
|
out->v[0] = (unsigned short) LittleShort (in->v[0]);
|
|
|
|
out->v[1] = (unsigned short) LittleShort (in->v[1]);
|
2000-06-03 12:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
Mod_LoadTexinfo
|
2000-06-03 12:15:49 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Mod_LoadTexinfo (lump_t *l)
|
2000-06-03 12:15:49 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
texinfo_t *in;
|
2000-06-03 12:15:49 +00:00
|
|
|
mtexinfo_t *out;
|
2000-12-08 06:51:37 +00:00
|
|
|
int i, j, count;
|
|
|
|
int miptex;
|
|
|
|
float len1, len2;
|
2000-06-03 12:15:49 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
in = (void *) (mod_base + l->fileofs);
|
|
|
|
if (l->filelen % sizeof (*in))
|
|
|
|
SV_Error ("MOD_LoadBmodel: funny lump size in %s", loadmodel->name);
|
|
|
|
count = l->filelen / sizeof (*in);
|
|
|
|
out = Hunk_AllocName (count * sizeof (*out), loadname);
|
2000-06-03 12:15:49 +00:00
|
|
|
|
|
|
|
loadmodel->texinfo = out;
|
|
|
|
loadmodel->numtexinfo = count;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (i = 0; i < count; i++, in++, out++) {
|
|
|
|
for (j = 0; j < 4; j++) {
|
2000-06-03 12:15:49 +00:00
|
|
|
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]);
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
len1 = (len1 + len2) / 2;
|
2000-06-03 12:15:49 +00:00
|
|
|
if (len1 < 0.32)
|
|
|
|
out->mipadjust = 4;
|
|
|
|
else if (len1 < 0.49)
|
|
|
|
out->mipadjust = 3;
|
|
|
|
else if (len1 < 0.99)
|
|
|
|
out->mipadjust = 2;
|
|
|
|
else
|
|
|
|
out->mipadjust = 1;
|
|
|
|
|
|
|
|
miptex = LittleLong (in->miptex);
|
|
|
|
out->flags = LittleLong (in->flags);
|
2000-12-08 06:51:37 +00:00
|
|
|
|
|
|
|
if (!loadmodel->textures) {
|
2000-06-03 12:15:49 +00:00
|
|
|
out->texture = r_notexture_mip; // checkerboard texture
|
|
|
|
out->flags = 0;
|
2000-12-08 06:51:37 +00:00
|
|
|
} else {
|
2000-06-03 12:15:49 +00:00
|
|
|
if (miptex >= loadmodel->numtextures)
|
|
|
|
SV_Error ("miptex >= loadmodel->numtextures");
|
|
|
|
out->texture = loadmodel->textures[miptex];
|
2000-12-08 06:51:37 +00:00
|
|
|
if (!out->texture) {
|
|
|
|
out->texture = r_notexture_mip; // texture not found
|
2000-06-03 12:15:49 +00:00
|
|
|
out->flags = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
CalcSurfaceExtents
|
2000-06-03 12:15:49 +00:00
|
|
|
|
2001-02-09 02:53:09 +00:00
|
|
|
Fills in s->texturemins[] and s->extents[]
|
2000-06-03 12:15:49 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
CalcSurfaceExtents (msurface_t *s)
|
2000-06-03 12:15:49 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
float mins[2], maxs[2], val;
|
|
|
|
int i, j, e;
|
|
|
|
mvertex_t *v;
|
|
|
|
mtexinfo_t *tex;
|
|
|
|
int bmins[2], bmaxs[2];
|
2000-06-03 12:15:49 +00:00
|
|
|
|
|
|
|
mins[0] = mins[1] = 999999;
|
|
|
|
maxs[0] = maxs[1] = -99999;
|
|
|
|
|
|
|
|
tex = s->texinfo;
|
2000-12-08 06:51:37 +00:00
|
|
|
|
|
|
|
for (i = 0; i < s->numedges; i++) {
|
|
|
|
e = loadmodel->surfedges[s->firstedge + i];
|
2000-06-03 12:15:49 +00:00
|
|
|
if (e >= 0)
|
|
|
|
v = &loadmodel->vertexes[loadmodel->edges[e].v[0]];
|
|
|
|
else
|
|
|
|
v = &loadmodel->vertexes[loadmodel->edges[-e].v[1]];
|
2000-12-08 06:51:37 +00:00
|
|
|
|
|
|
|
for (j = 0; j < 2; j++) {
|
|
|
|
val = v->position[0] * tex->vecs[j][0] +
|
2000-06-03 12:15:49 +00:00
|
|
|
v->position[1] * tex->vecs[j][1] +
|
2000-12-08 06:51:37 +00:00
|
|
|
v->position[2] * tex->vecs[j][2] + tex->vecs[j][3];
|
2000-06-03 12:15:49 +00:00
|
|
|
if (val < mins[j])
|
|
|
|
mins[j] = val;
|
|
|
|
if (val > maxs[j])
|
|
|
|
maxs[j] = val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
bmins[i] = floor (mins[i] / 16);
|
|
|
|
bmaxs[i] = ceil (maxs[i] / 16);
|
2000-06-03 12:15:49 +00:00
|
|
|
|
|
|
|
s->texturemins[i] = bmins[i] * 16;
|
|
|
|
s->extents[i] = (bmaxs[i] - bmins[i]) * 16;
|
2000-12-08 06:51:37 +00:00
|
|
|
if (!(tex->flags & TEX_SPECIAL) && s->extents[i] > 512 /* 256 */ )
|
2000-06-03 12:15:49 +00:00
|
|
|
SV_Error ("Bad surface extents");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
Mod_LoadFaces
|
2000-06-03 12:15:49 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Mod_LoadFaces (lump_t *l)
|
2000-06-03 12:15:49 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
dface_t *in;
|
|
|
|
msurface_t *out;
|
|
|
|
int i, count, surfnum;
|
|
|
|
int planenum, side;
|
2000-06-03 12:15:49 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
in = (void *) (mod_base + l->fileofs);
|
|
|
|
if (l->filelen % sizeof (*in))
|
|
|
|
SV_Error ("MOD_LoadBmodel: funny lump size in %s", loadmodel->name);
|
|
|
|
count = l->filelen / sizeof (*in);
|
|
|
|
out = Hunk_AllocName (count * sizeof (*out), loadname);
|
2000-06-03 12:15:49 +00:00
|
|
|
|
|
|
|
loadmodel->surfaces = out;
|
|
|
|
loadmodel->numsurfaces = count;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (surfnum = 0; surfnum < count; surfnum++, in++, out++) {
|
|
|
|
out->firstedge = LittleLong (in->firstedge);
|
|
|
|
out->numedges = LittleShort (in->numedges);
|
2000-06-03 12:15:49 +00:00
|
|
|
out->flags = 0;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
planenum = LittleShort (in->planenum);
|
|
|
|
side = LittleShort (in->side);
|
2000-06-03 12:15:49 +00:00
|
|
|
if (side)
|
2000-12-08 06:51:37 +00:00
|
|
|
out->flags |= SURF_PLANEBACK;
|
2000-06-03 12:15:49 +00:00
|
|
|
|
|
|
|
out->plane = loadmodel->planes + planenum;
|
|
|
|
|
|
|
|
out->texinfo = loadmodel->texinfo + LittleShort (in->texinfo);
|
|
|
|
|
|
|
|
CalcSurfaceExtents (out);
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
// lighting info
|
|
|
|
|
|
|
|
for (i = 0; i < MAXLIGHTMAPS; i++)
|
2000-06-03 12:15:49 +00:00
|
|
|
out->styles[i] = in->styles[i];
|
2000-12-08 06:51:37 +00:00
|
|
|
i = LittleLong (in->lightofs);
|
2000-06-16 09:41:42 +00:00
|
|
|
if (i == -1)
|
|
|
|
out->samples = NULL;
|
|
|
|
else
|
2000-09-20 22:11:17 +00:00
|
|
|
out->samples = loadmodel->lightdata + (i * mod_lightmap_bytes);
|
2000-12-08 06:51:37 +00:00
|
|
|
|
2000-09-20 22:11:17 +00:00
|
|
|
// set the drawing flags flag
|
|
|
|
// fixme: do this right?-)
|
2000-12-08 06:51:37 +00:00
|
|
|
if (!out->texinfo->texture)
|
|
|
|
continue;
|
|
|
|
if (!out->texinfo->texture->name)
|
|
|
|
continue;
|
2000-09-20 22:11:17 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (!strncmp (out->texinfo->texture->name, "sky", 3)) // sky
|
2000-06-03 12:15:49 +00:00
|
|
|
{
|
|
|
|
out->flags |= (SURF_DRAWSKY | SURF_DRAWTILED);
|
2000-12-17 22:07:06 +00:00
|
|
|
if (gl_sky_divide && gl_sky_divide->int_val)
|
|
|
|
GL_SubdivideSurface (out);
|
2000-06-03 12:15:49 +00:00
|
|
|
continue;
|
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
|
|
|
|
if (out->texinfo->texture->name[0] == '*') // turbulent
|
2000-06-03 12:15:49 +00:00
|
|
|
{
|
|
|
|
out->flags |= (SURF_DRAWTURB | SURF_DRAWTILED);
|
2000-12-08 06:51:37 +00:00
|
|
|
for (i = 0; i < 2; i++) {
|
2000-06-03 12:15:49 +00:00
|
|
|
out->extents[i] = 16384;
|
|
|
|
out->texturemins[i] = -8192;
|
|
|
|
}
|
|
|
|
GL_SubdivideSurface (out); // cut up polygon for warps
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
Mod_SetParent
|
2000-06-03 12:15:49 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Mod_SetParent (mnode_t *node, mnode_t *parent)
|
2000-06-03 12:15:49 +00:00
|
|
|
{
|
|
|
|
node->parent = parent;
|
|
|
|
if (node->contents < 0)
|
|
|
|
return;
|
|
|
|
Mod_SetParent (node->children[0], node);
|
|
|
|
Mod_SetParent (node->children[1], node);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
Mod_LoadNodes
|
2000-06-03 12:15:49 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Mod_LoadNodes (lump_t *l)
|
2000-06-03 12:15:49 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
int i, j, count, p;
|
|
|
|
dnode_t *in;
|
|
|
|
mnode_t *out;
|
2000-06-03 12:15:49 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
in = (void *) (mod_base + l->fileofs);
|
|
|
|
if (l->filelen % sizeof (*in))
|
|
|
|
SV_Error ("MOD_LoadBmodel: funny lump size in %s", loadmodel->name);
|
|
|
|
count = l->filelen / sizeof (*in);
|
|
|
|
out = Hunk_AllocName (count * sizeof (*out), loadname);
|
2000-06-03 12:15:49 +00:00
|
|
|
|
|
|
|
loadmodel->nodes = out;
|
|
|
|
loadmodel->numnodes = count;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (i = 0; i < count; i++, in++, out++) {
|
|
|
|
for (j = 0; j < 3; j++) {
|
2000-06-03 12:15:49 +00:00
|
|
|
out->minmaxs[j] = LittleShort (in->mins[j]);
|
2000-12-08 06:51:37 +00:00
|
|
|
out->minmaxs[3 + j] = LittleShort (in->maxs[j]);
|
2000-06-03 12:15:49 +00:00
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
|
|
|
|
p = LittleLong (in->planenum);
|
2000-06-03 12:15:49 +00:00
|
|
|
out->plane = loadmodel->planes + p;
|
|
|
|
|
|
|
|
out->firstsurface = LittleShort (in->firstface);
|
|
|
|
out->numsurfaces = LittleShort (in->numfaces);
|
2000-12-08 06:51:37 +00:00
|
|
|
|
|
|
|
for (j = 0; j < 2; j++) {
|
2000-06-03 12:15:49 +00:00
|
|
|
p = LittleShort (in->children[j]);
|
|
|
|
if (p >= 0)
|
|
|
|
out->children[j] = loadmodel->nodes + p;
|
|
|
|
else
|
2000-12-08 06:51:37 +00:00
|
|
|
out->children[j] = (mnode_t *) (loadmodel->leafs + (-1 - p));
|
2000-06-03 12:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
|
2000-06-03 12:15:49 +00:00
|
|
|
Mod_SetParent (loadmodel->nodes, NULL); // sets nodes and leafs
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
Mod_LoadLeafs
|
2000-06-03 12:15:49 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Mod_LoadLeafs (lump_t *l)
|
2000-06-03 12:15:49 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
dleaf_t *in;
|
|
|
|
mleaf_t *out;
|
|
|
|
int i, j, count, p;
|
|
|
|
|
|
|
|
// char s[80];
|
|
|
|
qboolean isnotmap = true;
|
|
|
|
|
|
|
|
in = (void *) (mod_base + l->fileofs);
|
|
|
|
if (l->filelen % sizeof (*in))
|
|
|
|
SV_Error ("MOD_LoadBmodel: funny lump size in %s", loadmodel->name);
|
|
|
|
count = l->filelen / sizeof (*in);
|
|
|
|
out = Hunk_AllocName (count * sizeof (*out), loadname);
|
2000-06-03 12:15:49 +00:00
|
|
|
|
|
|
|
loadmodel->leafs = out;
|
|
|
|
loadmodel->numleafs = count;
|
2000-12-08 06:51:37 +00:00
|
|
|
// snprintf(s, sizeof (s), "maps/%s.bsp",
|
|
|
|
// Info_ValueForKey(cl.serverinfo,"map"));
|
|
|
|
if (!strncmp ("maps/", loadmodel->name, 5))
|
2000-06-03 12:15:49 +00:00
|
|
|
isnotmap = false;
|
2000-12-08 06:51:37 +00:00
|
|
|
for (i = 0; i < count; i++, in++, out++) {
|
|
|
|
for (j = 0; j < 3; j++) {
|
2000-06-03 12:15:49 +00:00
|
|
|
out->minmaxs[j] = LittleShort (in->mins[j]);
|
2000-12-08 06:51:37 +00:00
|
|
|
out->minmaxs[3 + j] = LittleShort (in->maxs[j]);
|
2000-06-03 12:15:49 +00:00
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
p = LittleLong (in->contents);
|
2000-06-03 12:15:49 +00:00
|
|
|
out->contents = p;
|
|
|
|
|
|
|
|
out->firstmarksurface = loadmodel->marksurfaces +
|
2000-12-08 06:51:37 +00:00
|
|
|
LittleShort (in->firstmarksurface);
|
|
|
|
out->nummarksurfaces = LittleShort (in->nummarksurfaces);
|
|
|
|
|
|
|
|
p = LittleLong (in->visofs);
|
2000-06-03 12:15:49 +00:00
|
|
|
if (p == -1)
|
|
|
|
out->compressed_vis = NULL;
|
|
|
|
else
|
|
|
|
out->compressed_vis = loadmodel->visdata + p;
|
|
|
|
out->efrags = NULL;
|
2000-12-08 06:51:37 +00:00
|
|
|
|
|
|
|
for (j = 0; j < 4; j++)
|
2000-06-03 12:15:49 +00:00
|
|
|
out->ambient_sound_level[j] = in->ambient_level[j];
|
|
|
|
|
|
|
|
// gl underwater warp
|
2000-12-08 06:51:37 +00:00
|
|
|
if (out->contents != CONTENTS_EMPTY) {
|
|
|
|
for (j = 0; j < out->nummarksurfaces; j++)
|
2000-06-03 12:15:49 +00:00
|
|
|
out->firstmarksurface[j]->flags |= SURF_UNDERWATER;
|
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
if (isnotmap) {
|
|
|
|
for (j = 0; j < out->nummarksurfaces; j++)
|
2000-06-03 12:15:49 +00:00
|
|
|
out->firstmarksurface[j]->flags |= SURF_DONTWARP;
|
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
}
|
2000-06-03 12:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
Mod_LoadClipnodes
|
2000-06-03 12:15:49 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Mod_LoadClipnodes (lump_t *l)
|
2000-06-03 12:15:49 +00:00
|
|
|
{
|
|
|
|
dclipnode_t *in, *out;
|
2000-12-08 06:51:37 +00:00
|
|
|
int i, count;
|
|
|
|
hull_t *hull;
|
2000-06-03 12:15:49 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
in = (void *) (mod_base + l->fileofs);
|
|
|
|
if (l->filelen % sizeof (*in))
|
|
|
|
SV_Error ("MOD_LoadBmodel: funny lump size in %s", loadmodel->name);
|
|
|
|
count = l->filelen / sizeof (*in);
|
|
|
|
out = Hunk_AllocName (count * sizeof (*out), loadname);
|
2000-06-03 12:15:49 +00:00
|
|
|
|
|
|
|
loadmodel->clipnodes = out;
|
|
|
|
loadmodel->numclipnodes = count;
|
|
|
|
|
|
|
|
hull = &loadmodel->hulls[1];
|
|
|
|
hull->clipnodes = out;
|
|
|
|
hull->firstclipnode = 0;
|
2000-12-08 06:51:37 +00:00
|
|
|
hull->lastclipnode = count - 1;
|
2000-06-03 12:15:49 +00:00
|
|
|
hull->planes = loadmodel->planes;
|
|
|
|
hull->clip_mins[0] = -16;
|
|
|
|
hull->clip_mins[1] = -16;
|
|
|
|
hull->clip_mins[2] = -24;
|
|
|
|
hull->clip_maxs[0] = 16;
|
|
|
|
hull->clip_maxs[1] = 16;
|
|
|
|
hull->clip_maxs[2] = 32;
|
|
|
|
|
|
|
|
hull = &loadmodel->hulls[2];
|
|
|
|
hull->clipnodes = out;
|
|
|
|
hull->firstclipnode = 0;
|
2000-12-08 06:51:37 +00:00
|
|
|
hull->lastclipnode = count - 1;
|
2000-06-03 12:15:49 +00:00
|
|
|
hull->planes = loadmodel->planes;
|
|
|
|
hull->clip_mins[0] = -32;
|
|
|
|
hull->clip_mins[1] = -32;
|
|
|
|
hull->clip_mins[2] = -24;
|
|
|
|
hull->clip_maxs[0] = 32;
|
|
|
|
hull->clip_maxs[1] = 32;
|
|
|
|
hull->clip_maxs[2] = 64;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (i = 0; i < count; i++, out++, in++) {
|
|
|
|
out->planenum = LittleLong (in->planenum);
|
|
|
|
out->children[0] = LittleShort (in->children[0]);
|
|
|
|
out->children[1] = LittleShort (in->children[1]);
|
2000-06-03 12:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
Mod_MakeHull0
|
2000-06-03 12:15:49 +00:00
|
|
|
|
2001-02-09 02:53:09 +00:00
|
|
|
Deplicate the drawing hull structure as a clipping hull
|
2000-06-03 12:15:49 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Mod_MakeHull0 (void)
|
2000-06-03 12:15:49 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
mnode_t *in, *child;
|
2000-06-03 12:15:49 +00:00
|
|
|
dclipnode_t *out;
|
2000-12-08 06:51:37 +00:00
|
|
|
int i, j, count;
|
|
|
|
hull_t *hull;
|
|
|
|
|
|
|
|
hull = &loadmodel->hulls[0];
|
|
|
|
|
2000-06-03 12:15:49 +00:00
|
|
|
in = loadmodel->nodes;
|
|
|
|
count = loadmodel->numnodes;
|
2000-12-08 06:51:37 +00:00
|
|
|
out = Hunk_AllocName (count * sizeof (*out), loadname);
|
2000-06-03 12:15:49 +00:00
|
|
|
|
|
|
|
hull->clipnodes = out;
|
|
|
|
hull->firstclipnode = 0;
|
2000-12-08 06:51:37 +00:00
|
|
|
hull->lastclipnode = count - 1;
|
2000-06-03 12:15:49 +00:00
|
|
|
hull->planes = loadmodel->planes;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (i = 0; i < count; i++, out++, in++) {
|
2000-06-03 12:15:49 +00:00
|
|
|
out->planenum = in->plane - loadmodel->planes;
|
2000-12-08 06:51:37 +00:00
|
|
|
for (j = 0; j < 2; j++) {
|
2000-06-03 12:15:49 +00:00
|
|
|
child = in->children[j];
|
|
|
|
if (child->contents < 0)
|
|
|
|
out->children[j] = child->contents;
|
|
|
|
else
|
|
|
|
out->children[j] = child - loadmodel->nodes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
Mod_LoadMarksurfaces
|
2000-06-03 12:15:49 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Mod_LoadMarksurfaces (lump_t *l)
|
|
|
|
{
|
|
|
|
int i, j, count;
|
|
|
|
short *in;
|
2000-06-03 12:15:49 +00:00
|
|
|
msurface_t **out;
|
2000-12-08 06:51:37 +00:00
|
|
|
|
|
|
|
in = (void *) (mod_base + l->fileofs);
|
|
|
|
if (l->filelen % sizeof (*in))
|
|
|
|
SV_Error ("MOD_LoadBmodel: funny lump size in %s", loadmodel->name);
|
|
|
|
count = l->filelen / sizeof (*in);
|
|
|
|
out = Hunk_AllocName (count * sizeof (*out), loadname);
|
2000-06-03 12:15:49 +00:00
|
|
|
|
|
|
|
loadmodel->marksurfaces = out;
|
|
|
|
loadmodel->nummarksurfaces = count;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
j = LittleShort (in[i]);
|
2000-06-03 12:15:49 +00:00
|
|
|
if (j >= loadmodel->numsurfaces)
|
|
|
|
SV_Error ("Mod_ParseMarksurfaces: bad surface number");
|
|
|
|
out[i] = loadmodel->surfaces + j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
Mod_LoadSurfedges
|
2000-06-03 12:15:49 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Mod_LoadSurfedges (lump_t *l)
|
|
|
|
{
|
|
|
|
int i, count;
|
|
|
|
int *in, *out;
|
|
|
|
|
|
|
|
in = (void *) (mod_base + l->fileofs);
|
|
|
|
if (l->filelen % sizeof (*in))
|
|
|
|
SV_Error ("MOD_LoadBmodel: funny lump size in %s", loadmodel->name);
|
|
|
|
count = l->filelen / sizeof (*in);
|
|
|
|
out = Hunk_AllocName (count * sizeof (*out), loadname);
|
2000-06-03 12:15:49 +00:00
|
|
|
|
|
|
|
loadmodel->surfedges = out;
|
|
|
|
loadmodel->numsurfedges = count;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (i = 0; i < count; i++)
|
2000-06-03 12:15:49 +00:00
|
|
|
out[i] = LittleLong (in[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
Mod_LoadPlanes
|
2000-06-03 12:15:49 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Mod_LoadPlanes (lump_t *l)
|
2000-06-03 12:15:49 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
int i, j;
|
|
|
|
mplane_t *out;
|
|
|
|
dplane_t *in;
|
|
|
|
int count;
|
|
|
|
int bits;
|
|
|
|
|
|
|
|
in = (void *) (mod_base + l->fileofs);
|
|
|
|
if (l->filelen % sizeof (*in))
|
|
|
|
SV_Error ("MOD_LoadBmodel: funny lump size in %s", loadmodel->name);
|
|
|
|
count = l->filelen / sizeof (*in);
|
|
|
|
out = Hunk_AllocName (count * 2 * sizeof (*out), loadname);
|
|
|
|
|
2000-06-03 12:15:49 +00:00
|
|
|
loadmodel->planes = out;
|
|
|
|
loadmodel->numplanes = count;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (i = 0; i < count; i++, in++, out++) {
|
2000-06-03 12:15:49 +00:00
|
|
|
bits = 0;
|
2000-12-08 06:51:37 +00:00
|
|
|
for (j = 0; j < 3; j++) {
|
2000-06-03 12:15:49 +00:00
|
|
|
out->normal[j] = LittleFloat (in->normal[j]);
|
|
|
|
if (out->normal[j] < 0)
|
2000-12-08 06:51:37 +00:00
|
|
|
bits |= 1 << j;
|
2000-06-03 12:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
out->dist = LittleFloat (in->dist);
|
|
|
|
out->type = LittleLong (in->type);
|
|
|
|
out->signbits = bits;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
RadiusFromBounds
|
2000-06-03 12:15:49 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
float
|
|
|
|
RadiusFromBounds (vec3_t mins, vec3_t maxs)
|
2000-06-03 12:15:49 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
int i;
|
|
|
|
vec3_t corner;
|
2000-06-03 12:15:49 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
corner[i] =
|
|
|
|
fabs (mins[i]) > fabs (maxs[i]) ? fabs (mins[i]) : fabs (maxs[i]);
|
2000-06-03 12:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Length (corner);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
Mod_LoadBrushModel
|
2000-06-03 12:15:49 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Mod_LoadBrushModel (model_t *mod, void *buffer)
|
2000-06-03 12:15:49 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
int i, j;
|
|
|
|
dheader_t *header;
|
|
|
|
dmodel_t *bm;
|
|
|
|
|
2000-06-03 12:15:49 +00:00
|
|
|
loadmodel->type = mod_brush;
|
2000-12-08 06:51:37 +00:00
|
|
|
|
|
|
|
header = (dheader_t *) buffer;
|
2000-06-03 12:15:49 +00:00
|
|
|
|
|
|
|
i = LittleLong (header->version);
|
2000-06-16 09:41:42 +00:00
|
|
|
if (i != BSPVERSION)
|
2000-12-08 06:51:37 +00:00
|
|
|
SV_Error
|
|
|
|
("Mod_LoadBrushModel: %s has wrong version number (%i should be %i)",
|
|
|
|
mod->name, i, BSPVERSION);
|
2000-06-03 12:15:49 +00:00
|
|
|
|
|
|
|
// swap all the lumps
|
2000-12-08 06:51:37 +00:00
|
|
|
mod_base = (byte *) header;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof (dheader_t) / 4; i++)
|
2000-06-03 12:15:49 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
((int *) header)[i] = LittleLong (((int *) header)[i]);
|
2000-06-03 12:15:49 +00:00
|
|
|
|
|
|
|
// 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;
|
2000-12-08 06:51:37 +00:00
|
|
|
mod->checksum ^=
|
|
|
|
LittleLong (Com_BlockChecksum
|
|
|
|
(mod_base + header->lumps[i].fileofs,
|
|
|
|
header->lumps[i].filelen));
|
2000-06-03 12:15:49 +00:00
|
|
|
|
|
|
|
if (i == LUMP_VISIBILITY || i == LUMP_LEAFS || i == LUMP_NODES)
|
|
|
|
continue;
|
2000-12-08 06:51:37 +00:00
|
|
|
mod->checksum2 ^=
|
|
|
|
LittleLong (Com_BlockChecksum
|
|
|
|
(mod_base + header->lumps[i].fileofs,
|
|
|
|
header->lumps[i].filelen));
|
2000-06-03 12:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// load into heap
|
|
|
|
|
|
|
|
Mod_LoadVertexes (&header->lumps[LUMP_VERTEXES]);
|
|
|
|
Mod_LoadEdges (&header->lumps[LUMP_EDGES]);
|
|
|
|
Mod_LoadSurfedges (&header->lumps[LUMP_SURFEDGES]);
|
2000-06-16 09:41:42 +00:00
|
|
|
Mod_LoadTextures (&header->lumps[LUMP_TEXTURES]);
|
|
|
|
Mod_LoadLighting (&header->lumps[LUMP_LIGHTING]);
|
2000-06-03 12:15:49 +00:00
|
|
|
Mod_LoadPlanes (&header->lumps[LUMP_PLANES]);
|
|
|
|
Mod_LoadTexinfo (&header->lumps[LUMP_TEXINFO]);
|
|
|
|
Mod_LoadFaces (&header->lumps[LUMP_FACES]);
|
|
|
|
Mod_LoadMarksurfaces (&header->lumps[LUMP_MARKSURFACES]);
|
|
|
|
Mod_LoadVisibility (&header->lumps[LUMP_VISIBILITY]);
|
|
|
|
Mod_LoadLeafs (&header->lumps[LUMP_LEAFS]);
|
|
|
|
Mod_LoadNodes (&header->lumps[LUMP_NODES]);
|
|
|
|
Mod_LoadClipnodes (&header->lumps[LUMP_CLIPNODES]);
|
2000-06-16 09:41:42 +00:00
|
|
|
Mod_LoadEntities (&header->lumps[LUMP_ENTITIES]);
|
2000-06-03 12:15:49 +00:00
|
|
|
Mod_LoadSubmodels (&header->lumps[LUMP_MODELS]);
|
|
|
|
|
|
|
|
Mod_MakeHull0 ();
|
2000-12-08 06:51:37 +00:00
|
|
|
|
|
|
|
mod->numframes = 2; // regular and alternate animation
|
|
|
|
|
2000-06-03 12:15:49 +00:00
|
|
|
//
|
|
|
|
// set up the submodels (FIXME: this is confusing)
|
|
|
|
//
|
2000-12-08 06:51:37 +00:00
|
|
|
for (i = 0; i < mod->numsubmodels; i++) {
|
2000-06-03 12:15:49 +00:00
|
|
|
bm = &mod->submodels[i];
|
|
|
|
|
|
|
|
mod->hulls[0].firstclipnode = bm->headnode[0];
|
2000-12-08 06:51:37 +00:00
|
|
|
for (j = 1; j < MAX_MAP_HULLS; j++) {
|
2000-06-03 12:15:49 +00:00
|
|
|
mod->hulls[j].firstclipnode = bm->headnode[j];
|
2000-12-08 06:51:37 +00:00
|
|
|
mod->hulls[j].lastclipnode = mod->numclipnodes - 1;
|
2000-06-03 12:15:49 +00:00
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
|
2000-06-03 12:15:49 +00:00
|
|
|
mod->firstmodelsurface = bm->firstface;
|
|
|
|
mod->nummodelsurfaces = bm->numfaces;
|
|
|
|
|
|
|
|
VectorCopy (bm->maxs, mod->maxs);
|
|
|
|
VectorCopy (bm->mins, mod->mins);
|
|
|
|
|
|
|
|
mod->radius = RadiusFromBounds (mod->mins, mod->maxs);
|
|
|
|
|
|
|
|
mod->numleafs = bm->visleafs;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
if (i < mod->numsubmodels - 1) { // duplicate the basic
|
|
|
|
// information
|
|
|
|
char name[10];
|
2000-06-03 12:15:49 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
snprintf (name, sizeof (name), "*%i", i + 1);
|
2000-06-03 12:15:49 +00:00
|
|
|
loadmodel = Mod_FindName (name);
|
|
|
|
*loadmodel = *mod;
|
|
|
|
strcpy (loadmodel->name, name);
|
|
|
|
mod = loadmodel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|