X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=model_shared.c;h=01e1e46b79964e58a68bf5d3258d8f69eb9acdd1;hb=69a003b5def5ea2ece7310d3b35b62bf023c29b1;hp=d892a36d3b5aeac9dc9640e41a196677e99af3bc;hpb=d57be67cb00229acb8564b92c8b7c58eeed8a0cb;p=xonotic%2Fdarkplaces.git diff --git a/model_shared.c b/model_shared.c index d892a36d..01e1e46b 100644 --- a/model_shared.c +++ b/model_shared.c @@ -24,29 +24,69 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" -model_t *loadmodel; +model_t *loadmodel; // LordHavoc: increased from 512 to 2048 #define MAX_MOD_KNOWN 2048 -model_t mod_known[MAX_MOD_KNOWN]; +static model_t mod_known[MAX_MOD_KNOWN]; -void mod_start() +rtexture_t *r_notexture; +rtexturepool_t *r_notexturepool; + +texture_t r_surf_notexture; + +void Mod_SetupNoTexture(void) +{ + int x, y; + qbyte pix[16][16][4]; + + // this makes a light grey/dark grey checkerboard texture + for (y = 0;y < 16;y++) + { + for (x = 0;x < 16;x++) + { + if ((y < 8) ^ (x < 8)) + { + pix[y][x][0] = 128; + pix[y][x][1] = 128; + pix[y][x][2] = 128; + pix[y][x][3] = 255; + } + else + { + pix[y][x][0] = 64; + pix[y][x][1] = 64; + pix[y][x][2] = 64; + pix[y][x][3] = 255; + } + } + } + + r_notexturepool = R_AllocTexturePool(); + r_notexture = R_LoadTexture(r_notexturepool, "notexture", 16, 16, &pix[0][0][0], TEXTYPE_RGBA, TEXF_MIPMAP); +} + +static void mod_start(void) { int i; for (i = 0;i < MAX_MOD_KNOWN;i++) if (mod_known[i].name[0]) Mod_UnloadModel(&mod_known[i]); + + Mod_SetupNoTexture(); } -void mod_shutdown() +static void mod_shutdown(void) { int i; for (i = 0;i < MAX_MOD_KNOWN;i++) if (mod_known[i].name[0]) Mod_UnloadModel(&mod_known[i]); + + R_FreeTexturePool(&r_notexturepool); } -void mod_newmap() +static void mod_newmap(void) { } @@ -104,62 +144,58 @@ static model_t *Mod_LoadModel (model_t *mod, qboolean crash, qboolean checkdisk, { int crc; void *buf; - char tempname[MAX_QPATH]; mod->used = true; if (mod->name[0] == '*') // submodel return mod; - if (checkdisk) + crc = 0; + buf = NULL; + if (!mod->needload) { - // load the file - buf = COM_LoadFile (mod->name, false); - if (!buf) + if (checkdisk) { - if (crash) - Host_Error ("Mod_LoadModel: %s not found", mod->name); // LordHavoc: Sys_Error was *ANNOYING* - return NULL; - } + buf = COM_LoadFile (mod->name, false); + if (!buf) + { + if (crash) + Host_Error ("Mod_LoadModel: %s not found", mod->name); // LordHavoc: Sys_Error was *ANNOYING* + return NULL; + } - crc = CRC_Block(buf, com_filesize); + crc = CRC_Block(buf, com_filesize); + } + else + crc = mod->crc; - if (!mod->needload && mod->crc == crc && mod->isworldmodel == isworldmodel) + if (mod->crc == crc && mod->isworldmodel == isworldmodel) { - Mem_Free(buf); + if (buf) + Mem_Free(buf); return mod; // already loaded } - - Con_DPrintf("loading model %s\n", mod->name); } - else - { - if (!mod->needload && mod->isworldmodel == isworldmodel) - return mod; // already loaded - Con_DPrintf("loading model %s\n", mod->name); + Con_DPrintf("loading model %s\n", mod->name); + if (!buf) + { buf = COM_LoadFile (mod->name, false); if (!buf) { if (crash) - Host_Error ("Mod_LoadModel: %s not found", mod->name); // LordHavoc: Sys_Error was *ANNOYING* + Host_Error ("Mod_LoadModel: %s not found", mod->name); return NULL; } crc = CRC_Block(buf, com_filesize); } - // make sure nothing got trashed - Mem_CheckSentinelsGlobal(); - // allocate a new model loadmodel = mod; - // LordHavoc: clear the model struct - strcpy(tempname, mod->name); - Mod_FreeModel(mod); - - strcpy(mod->name, tempname); + // LordHavoc: unload the existing model in this slot (if there is one) + Mod_UnloadModel(mod); mod->isworldmodel = isworldmodel; mod->needload = false; mod->used = true; @@ -168,7 +204,8 @@ static model_t *Mod_LoadModel (model_t *mod, qboolean crash, qboolean checkdisk, // all models use memory, so allocate a memory pool mod->mempool = Mem_AllocPool(mod->name); // all models load textures, so allocate a texture pool - mod->texturepool = R_AllocTexturePool(); + if (cls.state != ca_dedicated) + mod->texturepool = R_AllocTexturePool(); // call the apropriate loader if (!memcmp(buf, "IDPO" , 4)) Mod_LoadAliasModel (mod, buf); @@ -179,9 +216,6 @@ static model_t *Mod_LoadModel (model_t *mod, qboolean crash, qboolean checkdisk, Mem_Free(buf); - // make sure nothing got trashed - Mem_CheckSentinelsGlobal(); - return mod; } @@ -189,15 +223,15 @@ void Mod_CheckLoaded (model_t *mod) { if (mod) { - if (!mod->needload) + if (mod->needload) + Mod_LoadModel(mod, true, true, mod->isworldmodel); + else { if (mod->type == mod_invalid) Host_Error("Mod_CheckLoaded: invalid model\n"); mod->used = true; return; } - - Mod_LoadModel(mod, true, true, mod->isworldmodel); } } @@ -208,15 +242,6 @@ Mod_ClearAll */ void Mod_ClearAll (void) { - /* - int i; - model_t *mod; - - for (i = 0, mod = mod_known;i < MAX_MOD_KNOWN;i++, mod++) - if (mod->name[0]) - if (mod->usesheap) - Mod_FreeModel(mod); - */ } void Mod_ClearUsed(void) @@ -306,33 +331,11 @@ Loads in a model for the given name */ model_t *Mod_ForName (char *name, qboolean crash, qboolean checkdisk, qboolean isworldmodel) { - model_t *mod; - - mod = Mod_FindName (name); - mod->used = true; - - return Mod_LoadModel (mod, crash, checkdisk, isworldmodel); + return Mod_LoadModel (Mod_FindName (name), crash, checkdisk, isworldmodel); } -byte *mod_base; +qbyte *mod_base; -/* -================= -RadiusFromBounds -================= -*/ -/* -float RadiusFromBounds (vec3_t mins, vec3_t maxs) -{ - int i; - vec3_t corner; - - for (i=0 ; i<3 ; i++) - corner[i] = fabs(mins[i]) > fabs(maxs[i]) ? fabs(mins[i]) : fabs(maxs[i]); - - return Length (corner); -} -*/ //=============================================================================