From: molivier Date: Sun, 3 Apr 2005 08:26:14 +0000 (+0000) Subject: Added Quake 2 sprite support (.sp2 files). Added the corresponding QC extension ... X-Git-Tag: xonotic-v0.1.0preview~5030 X-Git-Url: https://git.xonotic.org/?a=commitdiff_plain;h=d4c8d7d1f126232f3ed69a97da905d9425a291c2;p=xonotic%2Fdarkplaces.git Added Quake 2 sprite support (.sp2 files). Added the corresponding QC extension (DP_QUAKE2_SPRITE) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@5143 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/model_shared.c b/model_shared.c index 9553daf6..5064ac4b 100644 --- a/model_shared.c +++ b/model_shared.c @@ -306,6 +306,7 @@ static model_t *Mod_LoadModel(model_t *mod, qboolean crash, qboolean checkdisk, else if (!memcmp(buf, "IDP2", 4)) Mod_IDP2_Load(mod, buf); else if (!memcmp(buf, "IDP3", 4)) Mod_IDP3_Load(mod, buf); else if (!memcmp(buf, "IDSP", 4)) Mod_IDSP_Load(mod, buf); + else if (!memcmp(buf, "IDS2", 4)) Mod_IDS2_Load(mod, buf); else if (!memcmp(buf, "IBSP", 4)) Mod_IBSP_Load(mod, buf); else if (!memcmp(buf, "ZYMOTICMODEL", 12)) Mod_ZYMOTICMODEL_Load(mod, buf); else if (strlen(mod->name) >= 4 && !strcmp(mod->name - 4, ".map")) Mod_MAP_Load(mod, buf); diff --git a/model_sprite.c b/model_sprite.c index 8aa39070..7d2960f5 100644 --- a/model_sprite.c +++ b/model_sprite.c @@ -38,7 +38,7 @@ void Mod_SpriteInit (void) } static int alphaonlytable[4] = {255 | 0x80000000, 255 | 0x80000000, 255 | 0x80000000, 3}; -static void Mod_Sprite_SharedSetup(qbyte *datapointer, int version, int *palette, int *alphapalette) +static void Mod_Sprite_SharedSetup(const qbyte *datapointer, int version, const int *palette, const int *alphapalette) { int i, j, groupframes, realframes, x, y, origin[2], width, height; dspriteframetype_t *pinframetype; @@ -48,14 +48,12 @@ static void Mod_Sprite_SharedSetup(qbyte *datapointer, int version, int *palette float modelradius, interval; char name[MAX_QPATH], fogname[MAX_QPATH]; qbyte *pixbuf; - void *startframes; + const void *startframes; modelradius = 0; if (loadmodel->numframes < 1) Host_Error ("Mod_Sprite_SharedSetup: Invalid # of frames: %d\n", loadmodel->numframes); - loadmodel->type = mod_sprite; - // LordHavoc: hack to allow sprites to be non-fullbright for (i = 0;i < MAX_QPATH && loadmodel->name[i];i++) { @@ -66,10 +64,6 @@ static void Mod_Sprite_SharedSetup(qbyte *datapointer, int version, int *palette } } - // LordHavoc: 32bit textures - if (version != SPRITE_VERSION && version != SPRITE32_VERSION && version != SPRITEHL_VERSION) - Host_Error("Mod_Sprite_SharedSetup: unsupported version %i, only %i (quake), %i (HalfLife), and %i (sprite32) supported", version, SPRITE_VERSION, SPRITEHL_VERSION, SPRITE32_VERSION); - // // load the frames // @@ -210,16 +204,14 @@ static void Mod_Sprite_SharedSetup(qbyte *datapointer, int version, int *palette } extern void R_Model_Sprite_Draw(entity_render_t *ent); -void Mod_IDSP_Load(model_t *mod, void *buffer) +void Mod_IDSP_Load(model_t *mod, const void *buffer) { - int version, i, rendermode; - qbyte palette[256][4], alphapalette[256][4], *in; - dsprite_t *pinqsprite; - dspritehl_t *pinhlsprite; - qbyte *datapointer; + int version; + const qbyte *datapointer; datapointer = buffer; + loadmodel->type = mod_sprite; loadmodel->flags2 = EF_FULLBRIGHT; loadmodel->DrawSky = NULL; @@ -230,6 +222,8 @@ void Mod_IDSP_Load(model_t *mod, void *buffer) version = LittleLong(((dsprite_t *)buffer)->version); if (version == SPRITE_VERSION || version == SPRITE32_VERSION) { + dsprite_t *pinqsprite; + pinqsprite = (dsprite_t *)datapointer; datapointer += sizeof(dsprite_t); @@ -241,6 +235,11 @@ void Mod_IDSP_Load(model_t *mod, void *buffer) } else if (version == SPRITEHL_VERSION) { + int i, rendermode; + qbyte palette[256][4], alphapalette[256][4]; + const qbyte *in; + dspritehl_t *pinhlsprite; + pinhlsprite = (dspritehl_t *)datapointer; datapointer += sizeof(dspritehl_t); @@ -313,6 +312,99 @@ void Mod_IDSP_Load(model_t *mod, void *buffer) Mod_Sprite_SharedSetup(datapointer, LittleLong (pinhlsprite->version), (int *)(&palette[0][0]), (int *)(&alphapalette[0][0])); } else - Host_Error("Mod_IDSP_Load: %s has wrong version number (%i should be 1 (quake) or 32 (sprite32) or 2 (halflife)", loadmodel->name, version); + Host_Error("Mod_IDSP_Load: %s has wrong version number (%i). Only %i (quake), %i (HalfLife), and %i (sprite32) supported", + loadmodel->name, version, SPRITE_VERSION, SPRITEHL_VERSION, SPRITE32_VERSION); } + +void Mod_IDS2_Load(model_t *mod, const void *buffer) +{ + int i, version; + const dsprite2_t *pinqsprite; + float modelradius; + + loadmodel->type = mod_sprite; + loadmodel->flags2 = EF_FULLBRIGHT; + + loadmodel->DrawSky = NULL; + loadmodel->Draw = R_Model_Sprite_Draw; + loadmodel->DrawShadowVolume = NULL; + loadmodel->DrawLight = NULL; + + pinqsprite = (dsprite2_t *)buffer; + + version = LittleLong(pinqsprite->version); + if (version != SPRITE2_VERSION) + Host_Error("Mod_IDS2_Load: %s has wrong version number (%i should be 2 (quake 2)", loadmodel->name, version); + + loadmodel->numframes = LittleLong (pinqsprite->numframes); + if (loadmodel->numframes < 1) + Host_Error ("Mod_IDS2_Load: Invalid # of frames: %d\n", loadmodel->numframes); + loadmodel->sprite.sprnum_type = SPR_VP_PARALLEL; + loadmodel->synctype = ST_SYNC; + + // Hack to allow sprites to be non-fullbright + for (i = 0;i < MAX_QPATH && loadmodel->name[i];i++) + { + if (loadmodel->name[i] == '!') + { + loadmodel->flags2 &= ~EF_FULLBRIGHT; + break; + } + } + + loadmodel->animscenes = Mem_Alloc(loadmodel->mempool, sizeof(animscene_t) * loadmodel->numframes); + loadmodel->sprite.sprdata_frames = Mem_Alloc(loadmodel->mempool, sizeof(mspriteframe_t) * loadmodel->numframes); + + modelradius = 0; + for (i = 0;i < loadmodel->numframes;i++) + { + int origin[2], x, y, width, height; + const dsprite2frame_t *pinframe; + mspriteframe_t *sprframe; + + dpsnprintf(loadmodel->animscenes[i].name, sizeof(loadmodel->animscenes[i].name), "frame %i", i); + loadmodel->animscenes[i].firstframe = i; + loadmodel->animscenes[i].framecount = 1; + loadmodel->animscenes[i].framerate = 10; + loadmodel->animscenes[i].loop = true; + + pinframe = &pinqsprite->frames[i]; + + origin[0] = LittleLong (pinframe->origin_x); + origin[1] = LittleLong (pinframe->origin_y); + width = LittleLong (pinframe->width); + height = LittleLong (pinframe->height); + + sprframe = &loadmodel->sprite.sprdata_frames[i]; + + sprframe->left = origin[0]; + sprframe->right = origin[0] + width; + sprframe->up = origin[1]; + sprframe->down = origin[1] - height; + + x = max(sprframe->left * sprframe->left, sprframe->right * sprframe->right); + y = max(sprframe->up * sprframe->up, sprframe->down * sprframe->down); + if (modelradius < x + y) + modelradius = x + y; + + if (width > 0 && height > 0) + { + sprframe->texture = loadtextureimagewithmask(loadmodel->texturepool, pinframe->name, 0, 0, false, (r_mipsprites.integer ? TEXF_MIPMAP : 0) | TEXF_ALPHA | TEXF_CLAMP | TEXF_PRECACHE | TEXF_PICMIP); + sprframe->fogtexture = image_masktex; + + // TODO: use a default texture if we can't load it? + if (sprframe->texture == NULL) + Host_Error("Mod_IDS2_Load: failed to load %s", pinframe->name); + } + } + + modelradius = sqrt(modelradius); + for (i = 0;i < 3;i++) + { + loadmodel->normalmins[i] = loadmodel->yawmins[i] = loadmodel->rotatedmins[i] = -modelradius; + loadmodel->normalmaxs[i] = loadmodel->yawmaxs[i] = loadmodel->rotatedmaxs[i] = modelradius; + } + loadmodel->radius = modelradius; + loadmodel->radius2 = modelradius * modelradius; +} diff --git a/model_sprite.h b/model_sprite.h index 97e152ea..12ef2414 100644 --- a/model_sprite.h +++ b/model_sprite.h @@ -38,7 +38,8 @@ typedef struct mspriteframe_s rtexture_t *texture, *fogtexture; } mspriteframe_t; -extern void Mod_IDSP_Load(struct model_s *mod, void *buffer); +extern void Mod_IDSP_Load(struct model_s *mod, const void *buffer); +extern void Mod_IDS2_Load(struct model_s *mod, const void *buffer); extern void Mod_SpriteInit(void); #endif diff --git a/pr_cmds.c b/pr_cmds.c index 82737bfb..316bc2ee 100644 --- a/pr_cmds.c +++ b/pr_cmds.c @@ -128,6 +128,7 @@ char *ENGINE_EXTENSIONS = "DP_QC_TRACE_MOVETYPE_WORLDONLY " "DP_QC_VECTORVECTORS " "DP_QUAKE2_MODEL " +"DP_QUAKE2_SPRITE " "DP_QUAKE3_MODEL " "DP_REGISTERCVAR " "DP_SND_DIRECTIONLESSATTNNONE " diff --git a/spritegn.h b/spritegn.h index 4b47cb0f..96473110 100644 --- a/spritegn.h +++ b/spritegn.h @@ -45,10 +45,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // //------------------------------------------------------- -#define SPRITE_VERSION 1 +#define SPRITE_VERSION 1 #define SPRITEHL_VERSION 2 #define SPRITE32_VERSION 32 +#define SPRITE2_VERSION 2 + typedef struct { int ident; @@ -76,6 +78,21 @@ typedef struct synctype_t synctype; } dspritehl_t; +typedef struct +{ + int width, height; + int origin_x, origin_y; // raster coordinates inside pic + char name[64]; // name of pcx file +} dsprite2frame_t; + +typedef struct +{ + int ident; + int version; + int numframes; + dsprite2frame_t frames[1]; // variable sized +} dsprite2_t; + #define SPR_VP_PARALLEL_UPRIGHT 0 #define SPR_FACING_UPRIGHT 1 #define SPR_VP_PARALLEL 2 diff --git a/todo b/todo index 07c4fdfc..a4f4d885 100644 --- a/todo +++ b/todo @@ -216,7 +216,6 @@ 2 darkplaces console: figure out how to prevent "alias a a" - infinite loop when executed, this should be detected when executing it (Vicious) 2 darkplaces console: review the whole set of console commands and cvars carefully and identify interactions, known interactions include sequences such as +sv_cheats 1 +map e1m1, or +maxplayers 8 +deathmatch 7 +map dpdm2, but for some reason this works with the cvar after the map command, and also if you do -window it does not affect the value saved to config, because the configs are executed again after the -window, perhaps it is not executing the commandline a second time? apparently also -dedicated without +map does not load a map automatically in transfusion (Wazat, Willis) 2 darkplaces image: add scaling capabilities to Image_CopyMux -2 darkplaces loader: add q2 sprite support sometime 2 darkplaces loader: add support for fuhquake naming of map textures (textures/start/quake.tga style) 2 darkplaces loader: implement r_shadow_bumpscale_basetexture support in hl maps (CheapAlert) 2 darkplaces menu: add lan searching to the server browser and related code (Vermeulen) @@ -418,6 +417,7 @@ d darkplaces input: add more joystick buttons, 3 isn't enough (Static_Fiend) d darkplaces input: allow typing characters > 128 into console to allow Latin1 fonts to be used properly, already works in text messages (Urre) d darkplaces input: key repeat should work in menus, for example scrolling quickly through options (Up2nOgOoD) d darkplaces loader q3bsp: remove snapping to integer on patch vertices (HReaper) +d darkplaces loader: add q2 sprite support sometime d darkplaces loading: clear stainmaps on map restart/change based on cl_stainmapsclearonload cvar (John Truex) d darkplaces loading: fix bumpmapping, there's something quite mixed up about the svectors and tvectors (Randi) d darkplaces loading: make files override pak and pk3 archives, as it's really what people expect, hopefully this won't break any broken mods (Stribbs)