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

View file

@ -144,6 +144,7 @@ typedef struct msurface_s
glpoly_t *polys; // multiple if warped glpoly_t *polys; // multiple if warped
struct msurface_s *texturechain; struct msurface_s *texturechain;
// struct msurface_s *lightmapchain; // Quake 2 ???
mtexinfo_t *texinfo; mtexinfo_t *texinfo;
@ -418,7 +419,6 @@ typedef struct model_s
// additional model data // additional model data
cache_user_t cache; // only access through Mod_Extradata cache_user_t cache; // only access through Mod_Extradata
} model_t; } model_t;
// ============================================================================ // ============================================================================
@ -455,7 +455,10 @@ void Mod_SpriteLoadTexture (mspriteframe_t *pspriteframe, int framenum);
void Mod_LoadBrushModel (model_t *mod, void *buffer); void Mod_LoadBrushModel (model_t *mod, void *buffer);
void Mod_LoadAliasModel (model_t *mod, void *buffer, void Mod_LoadAliasModel (model_t *mod, void *buffer,
cache_allocator_t allocator); 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_LoadSpriteModel (model_t *mod, void *buffer);
void Mod_LoadSprite2Model (model_t *mod, void *buffer);
void Mod_SubdivideSurface (msurface_t *fa); void Mod_SubdivideSurface (msurface_t *fa);
void Mod_Print (void); void Mod_Print (void);

View file

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

View file

@ -65,6 +65,7 @@ typedef enum {false, true} qboolean;
// From mathlib... // From mathlib...
typedef float vec_t; typedef float vec_t;
typedef vec_t vec3_t[3]; typedef vec_t vec3_t[3];
typedef vec_t vec4_t[4];
typedef vec_t vec5_t[5]; typedef vec_t vec5_t[5];
typedef int fixed4_t; typedef int fixed4_t;
typedef int fixed8_t; typedef int fixed8_t;

View file

@ -49,7 +49,8 @@
#ifndef _SPRITEGN_H #ifndef _SPRITEGN_H
#define _SPRITEGN_H #define _SPRITEGN_H
#define SPRITE_VERSION 1 #define SPR_VERSION 1
#define SP2_VERSION 2
// must match definition in modelgen.h // must match definition in modelgen.h
#ifndef SYNCTYPE_T #ifndef SYNCTYPE_T
@ -96,6 +97,10 @@ typedef struct {
spriteframetype_t type; spriteframetype_t type;
} dspriteframetype_t; } 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 #endif // _SPRITEGN_H

View file

@ -135,18 +135,17 @@ Mod_LoadAllSkins (int numskins, daliasskintype_t *pskintype, int *pskinindex)
void void
Mod_LoadAliasModel (model_t *mod, void *buffer, cache_allocator_t allocator) 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; dtriangle_t *pintriangles;
daliasframetype_t *pframetype; daliasframetype_t *pframetype;
daliasskintype_t *pskintype; daliasskintype_t *pskintype;
mdl_t *pinmodel, *pmodel; mdl_t *pinmodel, *pmodel;
unsigned short crc; unsigned short crc;
stvert_t *pinstverts; stvert_t *pinstverts;
void *mem;
int extra = 0; // extra precision bytes if (LittleLong (* (unsigned int *) buffer) == HEADER_MDL16)
if (LittleLong (*(unsigned int *) buffer) == POLYHEADER16)
extra = 1; // extra precision bytes extra = 1; // extra precision bytes
CRC_Init (&crc); CRC_Init (&crc);
@ -157,9 +156,9 @@ Mod_LoadAliasModel (model_t *mod, void *buffer, cache_allocator_t allocator)
pinmodel = (mdl_t *) buffer; pinmodel = (mdl_t *) buffer;
version = LittleLong (pinmodel->version); version = LittleLong (pinmodel->version);
if (version != ALIAS_VERSION) if (version != ALIAS_VERSION_MDL)
Sys_Error ("%s has wrong version number (%i should be %i)", 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 // allocate space for a working header, plus all the data except the
// frames, skin and group info // frames, skin and group info

View file

@ -173,43 +173,43 @@ Mod_RealLoadModel (model_t *mod, qboolean crash, cache_allocator_t allocator)
loadmodel = mod; loadmodel = mod;
// fill it in // 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; mod->fullbright = 0;
} mod->shadow_alpha = 255;
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->min_light = 0.0;
}
// call the apropriate loader // call the apropriate loader
mod->needload = false; mod->needload = false;
mod->hasfullbrights = false; mod->hasfullbrights = false;
switch (LittleLong (*(unsigned int *) buf)) { switch (LittleLong (*(unsigned int *) buf)) {
case IDPOLYHEADER: case IDHEADER_MDL: // Type 6: Quake 1 .mdl
case POLYHEADER16: 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); Mod_LoadAliasModel (mod, buf, allocator);
break; break;
case IDHEADER_MD2: // Type 8: Quake 2 .md2
case IDSPRITEHEADER: // Mod_LoadMD2 (mod, buf, allocator);
break;
case IDHEADER_SPR: // Type 1: Quake 1 .spr
Mod_LoadSpriteModel (mod, buf); Mod_LoadSpriteModel (mod, buf);
break; break;
case IDHEADER_SP2: // Type 2: Quake 2 .sp2
default: // Mod_LoadSP2 (mod, buf);
break;
default: // Version 29: Quake 1 .bsp
// Version 38: Quake 2 .bsp
Mod_LoadBrushModel (mod, buf); Mod_LoadBrushModel (mod, buf);
if (gl_textures_external->int_val) if (gl_textures_external->int_val)

View file

@ -138,9 +138,9 @@ Mod_LoadSpriteModel (model_t *mod, void *buffer)
pin = (dsprite_t *) buffer; pin = (dsprite_t *) buffer;
version = LittleLong (pin->version); version = LittleLong (pin->version);
if (version != SPRITE_VERSION) if (version != SPR_VERSION)
Sys_Error ("%s has wrong version number " 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); numframes = LittleLong (pin->numframes);

View file

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

View file

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

View file

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

View file

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