2019-03-06 14:23:33 +01:00
|
|
|
/*
|
|
|
|
mod_sprite.c - sprite loading
|
|
|
|
Copyright (C) 2010 Uncle Mike
|
|
|
|
Copyright (C) 2019 a1batross
|
|
|
|
|
|
|
|
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 3 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "sprite.h"
|
|
|
|
#include "studio.h"
|
2019-11-24 01:52:08 +01:00
|
|
|
#if !XASH_DEDICATED
|
2019-03-06 14:23:33 +01:00
|
|
|
#include "ref_common.h"
|
|
|
|
#endif // XASH_DEDICATED
|
2024-01-27 17:48:17 +01:00
|
|
|
#include "mod_local.h"
|
2019-03-06 14:23:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
Mod_LoadSpriteModel
|
|
|
|
|
|
|
|
load sprite model
|
|
|
|
====================
|
|
|
|
*/
|
2024-07-21 01:59:51 +02:00
|
|
|
void Mod_LoadSpriteModel( model_t *mod, const void *buffer, qboolean *loaded )
|
2019-03-06 14:23:33 +01:00
|
|
|
{
|
|
|
|
dsprite_q1_t *pinq1;
|
|
|
|
dsprite_hl_t *pinhl;
|
|
|
|
dsprite_t *pin;
|
|
|
|
msprite_t *psprite;
|
2023-03-13 04:08:36 +01:00
|
|
|
char poolname[MAX_VA_STRING];
|
2019-03-06 14:23:33 +01:00
|
|
|
int i, size;
|
|
|
|
|
|
|
|
if( loaded ) *loaded = false;
|
|
|
|
pin = (dsprite_t *)buffer;
|
|
|
|
mod->type = mod_sprite;
|
|
|
|
i = pin->version;
|
|
|
|
|
|
|
|
if( pin->ident != IDSPRITEHEADER )
|
|
|
|
{
|
|
|
|
Con_DPrintf( S_ERROR "%s has wrong id (%x should be %x)\n", mod->name, pin->ident, IDSPRITEHEADER );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( i != SPRITE_VERSION_Q1 && i != SPRITE_VERSION_HL && i != SPRITE_VERSION_32 )
|
|
|
|
{
|
|
|
|
Con_DPrintf( S_ERROR "%s has wrong version number (%i should be %i or %i)\n", mod->name, i, SPRITE_VERSION_Q1, SPRITE_VERSION_HL );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-03-13 04:08:36 +01:00
|
|
|
Q_snprintf( poolname, sizeof( poolname ), "^2%s^7", mod->name );
|
|
|
|
mod->mempool = Mem_AllocPool( poolname );
|
2019-03-06 14:23:33 +01:00
|
|
|
|
|
|
|
if( i == SPRITE_VERSION_Q1 || i == SPRITE_VERSION_32 )
|
|
|
|
{
|
|
|
|
pinq1 = (dsprite_q1_t *)buffer;
|
|
|
|
size = sizeof( msprite_t ) + ( pinq1->numframes - 1 ) * sizeof( psprite->frames );
|
|
|
|
psprite = Mem_Calloc( mod->mempool, size );
|
|
|
|
mod->cache.data = psprite; // make link to extradata
|
|
|
|
|
|
|
|
psprite->type = pinq1->type;
|
|
|
|
psprite->texFormat = SPR_ADDITIVE; //SPR_ALPHTEST;
|
|
|
|
psprite->numframes = mod->numframes = pinq1->numframes;
|
|
|
|
psprite->facecull = SPR_CULL_FRONT;
|
|
|
|
psprite->radius = pinq1->boundingradius;
|
|
|
|
psprite->synctype = pinq1->synctype;
|
|
|
|
|
|
|
|
// LordHavoc: hack to allow sprites to be non-fullbright
|
|
|
|
for( i = 0; i < MAX_QPATH && mod->name[i]; i++ )
|
|
|
|
if( mod->name[i] == '!' )
|
|
|
|
psprite->texFormat = SPR_ALPHTEST;
|
|
|
|
|
|
|
|
mod->mins[0] = mod->mins[1] = -pinq1->bounds[0] * 0.5f;
|
|
|
|
mod->maxs[0] = mod->maxs[1] = pinq1->bounds[0] * 0.5f;
|
|
|
|
mod->mins[2] = -pinq1->bounds[1] * 0.5f;
|
|
|
|
mod->maxs[2] = pinq1->bounds[1] * 0.5f;
|
|
|
|
}
|
2019-12-24 00:47:51 +01:00
|
|
|
else // if( i == SPRITE_VERSION_HL )
|
2019-03-06 14:23:33 +01:00
|
|
|
{
|
|
|
|
pinhl = (dsprite_hl_t *)buffer;
|
|
|
|
size = sizeof( msprite_t ) + ( pinhl->numframes - 1 ) * sizeof( psprite->frames );
|
|
|
|
psprite = Mem_Calloc( mod->mempool, size );
|
|
|
|
mod->cache.data = psprite; // make link to extradata
|
|
|
|
|
|
|
|
psprite->type = pinhl->type;
|
|
|
|
psprite->texFormat = pinhl->texFormat;
|
|
|
|
psprite->numframes = mod->numframes = pinhl->numframes;
|
|
|
|
psprite->facecull = pinhl->facetype;
|
|
|
|
psprite->radius = pinhl->boundingradius;
|
|
|
|
psprite->synctype = pinhl->synctype;
|
|
|
|
|
|
|
|
mod->mins[0] = mod->mins[1] = -pinhl->bounds[0] * 0.5f;
|
|
|
|
mod->maxs[0] = mod->maxs[1] = pinhl->bounds[0] * 0.5f;
|
|
|
|
mod->mins[2] = -pinhl->bounds[1] * 0.5f;
|
|
|
|
mod->maxs[2] = pinhl->bounds[1] * 0.5f;
|
|
|
|
}
|
2019-03-17 15:19:24 +01:00
|
|
|
if( loaded ) *loaded = true; // done
|
2019-03-06 14:23:33 +01:00
|
|
|
|
|
|
|
if( Host_IsDedicated() )
|
|
|
|
{
|
|
|
|
// skip frames loading
|
|
|
|
psprite->numframes = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|