Working towards merging q2 model, sprite, and map support. Check back in a few

years, might be finished. ;)
This commit is contained in:
Ragnvald Maartmann-Moe IV 2004-02-08 02:49:38 +00:00
parent 6880b42182
commit c4402e07bd
12 changed files with 110 additions and 103 deletions

View file

@ -67,9 +67,12 @@
//=============================================================================
// little-endian PACK
#define IDPAKHEADER (('K'<<24)+('C'<<16)+('A'<<8)+'P')
#define BSPVERSION 29
#define TOOLVERSION 2
#define BSPVERSION 29
#define Q2BSPVERSION 38
#define TOOLVERSION 2
typedef struct lump_s {
int fileofs;
@ -91,7 +94,6 @@ typedef struct lump_s {
#define LUMP_EDGES 12
#define LUMP_SURFEDGES 13
#define LUMP_MODELS 14
#define HEADER_LUMPS 15
typedef struct dmodel_s {
@ -202,7 +204,6 @@ typedef struct dface_s {
} dface_t;
#define AMBIENT_WATER 0
#define AMBIENT_SKY 1
#define AMBIENT_SLIME 2

View file

@ -121,7 +121,7 @@ typedef struct glpoly_s
struct glpoly_s *chain;
struct glpoly_s *fb_chain;
int numverts;
int flags; // for SURF_UNDERWATER
int flags; // for SURF_UNDERWATER
float verts[4][VERTEXSIZE]; // variable sized (xyz s1t1 s2t2)
} glpoly_t;
@ -134,7 +134,7 @@ typedef struct msurface_s
int firstedge; // look up in model->surfedges[], negative numbers
int numedges; // are backwards edges
struct surfcache_s *cachespots[MIPLEVELS];
short texturemins[2];
@ -144,9 +144,10 @@ typedef struct msurface_s
glpoly_t *polys; // multiple if warped
struct msurface_s *texturechain;
// struct msurface_s *lightmapchain; // Quake 2 ???
mtexinfo_t *texinfo;
// lighting info
int dlightframe;
int dlightbits;
@ -163,14 +164,14 @@ typedef struct mnode_s
// common with leaf
int contents; // 0, to differentiate from leafs
int visframe; // node needs to be traversed if current
float minmaxs[6]; // for bounding box culling
struct mnode_s *parent;
// node specific
mplane_t *plane;
struct mnode_s *children[2];
struct mnode_s *children[2];
unsigned short firstsurface;
unsigned short numsurfaces;
@ -418,7 +419,6 @@ typedef struct model_s
// additional model data
cache_user_t cache; // only access through Mod_Extradata
} model_t;
// ============================================================================
@ -455,7 +455,10 @@ void Mod_SpriteLoadTexture (mspriteframe_t *pspriteframe, int framenum);
void Mod_LoadBrushModel (model_t *mod, void *buffer);
void Mod_LoadAliasModel (model_t *mod, void *buffer,
cache_allocator_t allocator);
void Mod_LoadAlias2Model (model_t *mod, void *buffer,
cache_allocator_t allocator);
void Mod_LoadSpriteModel (model_t *mod, void *buffer);
void Mod_LoadSprite2Model (model_t *mod, void *buffer);
void Mod_SubdivideSurface (msurface_t *fa);
void Mod_Print (void);

View file

@ -37,7 +37,8 @@
#include "QF/mathlib.h"
#define ALIAS_VERSION 6
#define ALIAS_VERSION_MDL 6 // .mdl
#define ALIAS_VERSION_MD2 8 // .md2
#define ALIAS_ONSEAM 0x0020
@ -133,10 +134,13 @@ typedef struct {
aliasskintype_t type;
} daliasskintype_t;
#define IDPOLYHEADER (('O'<<24)+('P'<<16)+('D'<<8)+'I')
// little-endian "IDPO"
// little-endian "IDPO"
#define IDHEADER_MDL (('O'<<24)+('P'<<16)+('D'<<8)+'I')
// little-endian "MD16" -- 16 bit vertices
#define HEADER_MDL16 (('6'<<24)+('1'<<16)+('D'<<8)+'M')
// special header indicating 16 bit vertices - little-endian "MD16"
#define POLYHEADER16 (('6'<<24)+('1'<<16)+('D'<<8)+'M')
// little-endian "IDP2"
#define IDHEADER_MD2 (('2'<<24)+('P'<<16)+('D'<<8)+'I')
#endif // _MODELGEN_H

View file

@ -65,10 +65,11 @@ typedef enum {false, true} qboolean;
// From mathlib...
typedef float vec_t;
typedef vec_t vec3_t[3];
typedef vec_t vec4_t[4];
typedef vec_t vec5_t[5];
typedef int fixed4_t;
typedef int fixed8_t;
typedef int fixed16_t;
typedef int fixed4_t;
typedef int fixed8_t;
typedef int fixed16_t;
#define SIDE_FRONT 0
#define SIDE_BACK 1

View file

@ -49,7 +49,8 @@
#ifndef _SPRITEGN_H
#define _SPRITEGN_H
#define SPRITE_VERSION 1
#define SPR_VERSION 1
#define SP2_VERSION 2
// must match definition in modelgen.h
#ifndef SYNCTYPE_T
@ -96,6 +97,10 @@ typedef struct {
spriteframetype_t type;
} dspriteframetype_t;
#define IDSPRITEHEADER (('P'<<24)+('S'<<16)+('D'<<8)+'I')
// little-endian "IDSP"
// little-endian "IDSP"
#define IDHEADER_SPR (('P'<<24)+('S'<<16)+('D'<<8)+'I')
// little-endian "IDS2"
#define IDHEADER_SP2 (('2'<<24)+('S'<<16)+('D'<<8)+'I')
#endif // _SPRITEGN_H

View file

@ -135,19 +135,18 @@ Mod_LoadAllSkins (int numskins, daliasskintype_t *pskintype, int *pskinindex)
void
Mod_LoadAliasModel (model_t *mod, void *buffer, cache_allocator_t allocator)
{
int i, j, size, version, numframes, start, end, total;
int size, version, numframes, start, end, total, i, j;
int extra = 0; // extra precision bytes
void *mem;
dtriangle_t *pintriangles;
daliasframetype_t *pframetype;
daliasskintype_t *pskintype;
mdl_t *pinmodel, *pmodel;
unsigned short crc;
stvert_t *pinstverts;
void *mem;
int extra = 0; // extra precision bytes
if (LittleLong (*(unsigned int *) buffer) == POLYHEADER16)
extra = 1; // extra precision bytes
if (LittleLong (* (unsigned int *) buffer) == HEADER_MDL16)
extra = 1; // extra precision bytes
CRC_Init (&crc);
CRC_ProcessBlock (buffer, &crc, qfs_filesize);
@ -157,9 +156,9 @@ Mod_LoadAliasModel (model_t *mod, void *buffer, cache_allocator_t allocator)
pinmodel = (mdl_t *) buffer;
version = LittleLong (pinmodel->version);
if (version != ALIAS_VERSION)
if (version != ALIAS_VERSION_MDL)
Sys_Error ("%s has wrong version number (%i should be %i)",
mod->name, version, ALIAS_VERSION);
mod->name, version, ALIAS_VERSION_MDL);
// allocate space for a working header, plus all the data except the
// frames, skin and group info
@ -182,7 +181,7 @@ Mod_LoadAliasModel (model_t *mod, void *buffer, cache_allocator_t allocator)
if (pmodel->skinheight > MAX_LBM_HEIGHT)
Sys_Error ("model %s has a skin taller than %d", mod->name,
MAX_LBM_HEIGHT);
MAX_LBM_HEIGHT);
pmodel->numverts = LittleLong (pinmodel->numverts);

View file

@ -126,7 +126,7 @@ Mod_ClearAll (void)
}
}
model_t *
model_t *
Mod_FindName (const char *name)
{
int i;
@ -173,43 +173,43 @@ Mod_RealLoadModel (model_t *mod, qboolean crash, cache_allocator_t allocator)
loadmodel = mod;
// fill it in
if (strequal (mod->name, "progs/grenade.mdl")) {
mod->shadow_alpha = 0;
} else {
mod->shadow_alpha = 255;
}
if (strnequal (mod->name, "progs/flame", 11)
|| strnequal (mod->name, "progs/bolt", 10)) {
mod->fullbright = 1;
mod->shadow_alpha = 0;
} else {
mod->fullbright = 0;
}
if (strequal (mod->name, "progs/player.mdl")) {
mod->min_light = 0.04;
} else if (strnequal (mod->name, "progs/v_", 8)) {
mod->min_light = 0.12;
} else {
mod->min_light = 0.0;
}
mod->fullbright = 0;
mod->shadow_alpha = 255;
mod->min_light = 0.0;
// call the apropriate loader
mod->needload = false;
mod->hasfullbrights = false;
switch (LittleLong (*(unsigned int *) buf)) {
case IDPOLYHEADER:
case POLYHEADER16:
case IDHEADER_MDL: // Type 6: Quake 1 .mdl
case HEADER_MDL16: // QF Type 6 extended for 16bit precision
if (strequal (mod->name, "progs/grenade.mdl")) {
mod->fullbright = 0;
mod->shadow_alpha = 0;
} else if (strnequal (mod->name, "progs/flame", 11)
|| strnequal (mod->name, "progs/bolt", 10)) {
mod->fullbright = 1;
mod->shadow_alpha = 0;
}
if (strnequal (mod->name, "progs/v_", 8)) {
mod->min_light = 0.12;
} else if (strequal (mod->name, "progs/player.mdl")) {
mod->min_light = 0.04;
}
Mod_LoadAliasModel (mod, buf, allocator);
break;
case IDSPRITEHEADER:
case IDHEADER_MD2: // Type 8: Quake 2 .md2
// Mod_LoadMD2 (mod, buf, allocator);
break;
case IDHEADER_SPR: // Type 1: Quake 1 .spr
Mod_LoadSpriteModel (mod, buf);
break;
default:
case IDHEADER_SP2: // Type 2: Quake 2 .sp2
// Mod_LoadSP2 (mod, buf);
break;
default: // Version 29: Quake 1 .bsp
// Version 38: Quake 2 .bsp
Mod_LoadBrushModel (mod, buf);
if (gl_textures_external->int_val)
@ -258,7 +258,7 @@ Mod_CallbackLoad (void *object, cache_allocator_t allocator)
Loads in a model for the given name
*/
model_t *
model_t *
Mod_ForName (const char *name, qboolean crash)
{
model_t *mod;

View file

@ -138,9 +138,9 @@ Mod_LoadSpriteModel (model_t *mod, void *buffer)
pin = (dsprite_t *) buffer;
version = LittleLong (pin->version);
if (version != SPRITE_VERSION)
if (version != SPR_VERSION)
Sys_Error ("%s has wrong version number "
"(%i should be %i)", mod->name, version, SPRITE_VERSION);
"(%i should be %i)", mod->name, version, SPR_VERSION);
numframes = LittleLong (pin->numframes);

View file

@ -1,7 +1,7 @@
/*
gl_mod_alias.c
(description)
Draw Alias Model
Copyright (C) 1996-1997 Id Software, Inc.
@ -95,9 +95,9 @@ static inline void
GL_DrawAliasFrameTri (vert_order_t *vo)
{
float color[4];
int count;
blended_vert_t *verts;
tex_coord_t *tex_coord;
int count;
blended_vert_t *verts;
tex_coord_t *tex_coord;
verts = vo->verts;
tex_coord = vo->tex_coord;
@ -119,10 +119,11 @@ GL_DrawAliasFrameTri (vert_order_t *vo)
static inline void
GL_DrawAliasFrameTri_fb (vert_order_t *vo)
{
float color[4] = { 1.0, 1.0, 1.0, 0.0};
int count;
float color[4] = { 1.0, 1.0, 1.0, 0.0};
blended_vert_t *verts;
tex_coord_t *tex_coord;
tex_coord_t *tex_coord;
verts = vo->verts;
color[3] = modelalpha * 1.0;
count = vo->count;
@ -145,7 +146,7 @@ GL_DrawAliasFrameTriMulti (vert_order_t *vo)
float color[4];
int count;
blended_vert_t *verts;
tex_coord_t *tex_coord;
tex_coord_t *tex_coord;
verts = vo->verts;
tex_coord = vo->tex_coord;
@ -688,7 +689,7 @@ R_DrawAliasModel (entity_t *e)
fb_texture = skindesc->fb_texnum;
}
if (paliashdr->mdl.ident == POLYHEADER16) {
if (paliashdr->mdl.ident == HEADER_MDL16) {
VectorScale (paliashdr->mdl.scale, e->scale / 256.0, scale);
vo = GL_GetAliasFrameVerts16 (e->frame, paliashdr, e);
} else {

View file

@ -39,7 +39,6 @@ static __attribute__ ((unused)) const char rcsid[] =
#include "d_ifacea.h"
#include "r_local.h"
#include "stdlib.h"
#define LIGHT_MIN 5 // lowest light value we'll allow, to
@ -89,6 +88,7 @@ float r_avertexnormals[NUMVERTEXNORMALS][3] = {
#include "anorms.h"
};
qboolean
R_AliasCheckBBox (void)
{
@ -236,7 +236,6 @@ R_AliasCheckBBox (void)
return true;
}
void
R_AliasTransformVector (vec3_t in, vec3_t out)
{
@ -245,7 +244,6 @@ R_AliasTransformVector (vec3_t in, vec3_t out)
out[2] = DotProduct (in, aliastransform[2]) + aliastransform[2][3];
}
static void
R_AliasClipAndProjectFinalVert (finalvert_t *fv, auxvert_t *av)
{
@ -267,7 +265,8 @@ R_AliasClipAndProjectFinalVert (finalvert_t *fv, auxvert_t *av)
}
static void
R_AliasTransformFinalVert16 (finalvert_t *fv, auxvert_t *av, trivertx_t *pverts)
R_AliasTransformFinalVert16 (finalvert_t *fv, auxvert_t *av,
trivertx_t *pverts)
{
trivertx_t * pextra;
float vextra[3];
@ -315,17 +314,16 @@ R_AliasPreparePoints (void)
fv = pfinalverts;
av = pauxverts;
if (pmdl->ident == POLYHEADER16) {
if (pmdl->ident == HEADER_MDL16) {
for (i = 0; i < r_anumverts; i++, fv++, av++, r_apverts++,
pstverts++) {
pstverts++) {
R_AliasTransformFinalVert16 (fv, av, r_apverts);
R_AliasTransformFinalVert (fv, av, r_apverts, pstverts);
R_AliasClipAndProjectFinalVert (fv, av);
}
}
else {
} else {
for (i = 0; i < r_anumverts; i++, fv++, av++, r_apverts++,
pstverts++) {
pstverts++) {
R_AliasTransformFinalVert8 (fv, av, r_apverts);
R_AliasTransformFinalVert (fv, av, r_apverts, pstverts);
R_AliasClipAndProjectFinalVert (fv, av);
@ -356,7 +354,6 @@ R_AliasPreparePoints (void)
}
}
void
R_AliasSetUpTransform (int trivial_accept)
{
@ -416,7 +413,7 @@ R_AliasSetUpTransform (int trivial_accept)
// correspondingly so the projected x and y come out right
// FIXME: make this work for clipped case too?
if (trivial_accept && pmdl->ident != POLYHEADER16) {
if (trivial_accept && pmdl->ident != HEADER_MDL16) {
for (i = 0; i < 4; i++) {
aliastransform[0][i] *= aliasxscale *
(1.0 / ((float) 0x8000 * 0x10000));
@ -552,15 +549,13 @@ R_AliasPrepareUnclippedPoints (void)
D_PolysetDraw ();
}
static void
R_AliasSetupSkin (void)
{
int skinnum;
int i, numskins;
maliasskingroup_t *paliasskingroup;
float *pskinintervals, fullskininterval;
int numskins, skinnum, i;
float skintargettime, skintime;
float *pskinintervals, fullskininterval;
maliasskingroup_t *paliasskingroup;
skinnum = currententity->skinnum;
if ((skinnum >= pmdl->numskins) || (skinnum < 0)) {
@ -642,7 +637,6 @@ R_AliasSetupLighting (alight_t *plighting)
r_plightvec[2] = DotProduct (plighting->plightvec, alias_up);
}
/*
R_AliasSetupFrame
@ -651,10 +645,10 @@ R_AliasSetupLighting (alight_t *plighting)
static void
R_AliasSetupFrame (void)
{
int frame;
int i, numframes;
int frame, numframes, i;
float fullinterval, targettime, time;
float *pintervals;
maliasgroup_t *paliasgroup;
float *pintervals, fullinterval, targettime, time;
frame = currententity->frame;
if ((frame >= pmdl->numframes) || (frame < 0)) {
@ -693,7 +687,7 @@ R_AliasSetupFrame (void)
void
R_AliasDrawModel (alight_t *plighting)
{
int size;
int size;
finalvert_t *finalverts;
r_amodels_drawn++;
@ -702,8 +696,8 @@ R_AliasDrawModel (alight_t *plighting)
pmdl = (mdl_t *) ((byte *) paliashdr + paliashdr->model);
size = (CACHE_SIZE - 1)
+ sizeof (finalvert_t) * (pmdl->numverts + 1)
+ sizeof (auxvert_t) * pmdl->numverts;
+ sizeof (finalvert_t) * (pmdl->numverts + 1)
+ sizeof (auxvert_t) * pmdl->numverts;
finalverts = (finalvert_t *) Hunk_TempAlloc (size);
if (!finalverts)
Sys_Error ("R_AliasDrawModel: out of memory");
@ -739,7 +733,7 @@ R_AliasDrawModel (alight_t *plighting)
else
ziscale = (float) 0x8000 *(float) 0x10000 *3.0;
if (currententity->trivial_accept && pmdl->ident != POLYHEADER16)
if (currententity->trivial_accept && pmdl->ident != HEADER_MDL16)
R_AliasPrepareUnclippedPoints ();
else
R_AliasPreparePoints ();

View file

@ -315,7 +315,7 @@ R_AliasPreparePoints (void)
fv = pfinalverts;
av = pauxverts;
if (pmdl->ident == POLYHEADER16) {
if (pmdl->ident == HEADER_MDL16) {
for (i = 0; i < r_anumverts; i++, fv++, av++, r_apverts++,
pstverts++) {
R_AliasTransformFinalVert16 (fv, av, r_apverts);
@ -727,7 +727,7 @@ R_AliasDrawModel (alight_t *plighting)
else
ziscale = (float) 0x8000 *(float) 0x10000 *3.0;
if (currententity->trivial_accept && pmdl->ident != POLYHEADER16)
if (currententity->trivial_accept && pmdl->ident != HEADER_MDL16)
R_AliasPrepareUnclippedPoints ();
else
R_AliasPreparePoints ();

View file

@ -138,9 +138,9 @@ static void
WriteFrame (QFile *modelouthandle, int framenum)
{
int j, k;
trivert_t *pframe;
daliasframe_t aframe;
float v;
daliasframe_t aframe;
trivert_t *pframe;
pframe = verts[framenum];
@ -152,7 +152,7 @@ WriteFrame (QFile *modelouthandle, int framenum)
}
for (j = 0; j < model.numverts; j++) {
// all of these are byte values, so no need to deal with endianness
// all of these are byte values, so no need to deal with endianness
tarray[j].lightnormalindex = pframe[j].lightnormalindex;
if (tarray[j].lightnormalindex > NUMVERTEXNORMALS)
@ -173,7 +173,6 @@ WriteFrame (QFile *modelouthandle, int framenum)
}
Qwrite (modelouthandle, &aframe, sizeof (aframe));
Qwrite (modelouthandle, &tarray[0], model.numverts * sizeof(tarray[0]));
}
@ -219,7 +218,7 @@ WriteModelFile (QFile *modelouthandle)
float dist[3];
mdl_t modeltemp;
// Calculate the bounding box for this model
// Calculate the bounding box for this model
for (i = 0; i < 3; i++) {
printf ("framesmins[%d]: %f, framesmaxs[%d]: %f\n",
i, framesmins[i], i, framesmaxs[i]);
@ -236,9 +235,9 @@ WriteModelFile (QFile *modelouthandle)
dist[1] * dist[1] +
dist[2] * dist[2]);
// write out the model header
modeltemp.ident = LittleLong (IDPOLYHEADER);
modeltemp.version = LittleLong (ALIAS_VERSION);
// write out the model header
modeltemp.ident = LittleLong (IDHEADER_MDL);
modeltemp.version = LittleLong (ALIAS_VERSION_MDL);
modeltemp.boundingradius = LittleFloat (model.boundingradius);
for (i = 0; i < 3; i++) {