]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - model_shared.c
changed brush model API - now uses function pointers for some of the brush model...
[xonotic/darkplaces.git] / model_shared.c
index 9c3ecaf6bc8f753ad698ac772c3c0631cc17fa74..bb0804031b40bb4bd28210d9b9c0247c0ac2f077 100644 (file)
@@ -141,6 +141,7 @@ Mod_Init
 ===============
 */
 static void Mod_Print (void);
+static void Mod_Precache (void);
 void Mod_Init (void)
 {
        Mod_BrushInit();
@@ -148,6 +149,7 @@ void Mod_Init (void)
        Mod_SpriteInit();
 
        Cmd_AddCommand ("modellist", Mod_Print);
+       Cmd_AddCommand ("modelprecache", Mod_Precache);
 }
 
 void Mod_RenderInit(void)
@@ -183,8 +185,9 @@ Mod_LoadModel
 Loads a model
 ==================
 */
-static model_t *Mod_LoadModel (model_t *mod, qboolean crash, qboolean checkdisk, qboolean isworldmodel)
+static model_t *Mod_LoadModel(model_t *mod, qboolean crash, qboolean checkdisk, qboolean isworldmodel)
 {
+       int num;
        unsigned int crc;
        void *buf;
 
@@ -240,11 +243,10 @@ static model_t *Mod_LoadModel (model_t *mod, qboolean crash, qboolean checkdisk,
        // LordHavoc: unload the existing model in this slot (if there is one)
        Mod_UnloadModel(mod);
        mod->isworldmodel = isworldmodel;
-       mod->needload = false;
        mod->used = true;
        mod->crc = crc;
-       // errors can prevent the corresponding mod->error = false;
-       mod->error = true;
+       // errors can prevent the corresponding mod->needload = false;
+       mod->needload = true;
 
        // all models use memory, so allocate a memory pool
        mod->mempool = Mem_AllocPool(mod->name);
@@ -253,21 +255,25 @@ static model_t *Mod_LoadModel (model_t *mod, qboolean crash, qboolean checkdisk,
                mod->texturepool = R_AllocTexturePool();
 
        // call the apropriate loader
-            if (!memcmp(buf, "IDPO"    , 4)) Mod_LoadQ1AliasModel(mod, buf);
-       else if (!memcmp(buf, "IDP2"    , 4)) Mod_LoadQ2AliasModel(mod, buf);
-       else if (!memcmp(buf, "IDP3"    , 4)) Mod_LoadQ3AliasModel(mod, buf);
-       else if (!memcmp(buf, "ZYMOTIC" , 7)) Mod_LoadZymoticModel(mod, buf);
-       else if (!memcmp(buf, "IDSP"    , 4)) Mod_LoadSpriteModel (mod, buf);
-       else                                  Mod_LoadBrushModel  (mod, buf);
+       num = LittleLong(*((int *)buf));
+            if (!memcmp(buf, "IDPO", 4)) Mod_IDP0_Load(mod, buf);
+       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, "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);
+       else if (num == BSPVERSION || num == 30) Mod_Q1BSP_Load(mod, buf);
+       else Host_Error("Mod_LoadModel: model \"%s\" is of unknown/unsupported type\n", mod->name);
 
        Mem_Free(buf);
 
        // no errors occurred
-       mod->error = false;
+       mod->needload = false;
        return mod;
 }
 
-void Mod_CheckLoaded (model_t *mod)
+void Mod_CheckLoaded(model_t *mod)
 {
        if (mod)
        {
@@ -288,20 +294,10 @@ void Mod_CheckLoaded (model_t *mod)
 Mod_ClearAll
 ===================
 */
-void Mod_ClearAll (void)
+void Mod_ClearAll(void)
 {
 }
 
-void Mod_ClearErrorModels (void)
-{
-       int i;
-       model_t *mod;
-
-       for (i = 0, mod = mod_known;i < MAX_MOD_KNOWN;i++, mod++)
-               if (mod->error)
-                       Mod_FreeModel(mod);
-}
-
 void Mod_ClearUsed(void)
 {
        int i;
@@ -340,7 +336,7 @@ Mod_FindName
 
 ==================
 */
-model_t *Mod_FindName (const char *name)
+model_t *Mod_FindName(const char *name)
 {
        int i;
        model_t *mod, *freemod;
@@ -383,11 +379,11 @@ Mod_TouchModel
 
 ==================
 */
-void Mod_TouchModel (const char *name)
+void Mod_TouchModel(const char *name)
 {
        model_t *mod;
 
-       mod = Mod_FindName (name);
+       mod = Mod_FindName(name);
        mod->used = true;
 }
 
@@ -398,9 +394,9 @@ Mod_ForName
 Loads in a model for the given name
 ==================
 */
-model_t *Mod_ForName (const char *name, qboolean crash, qboolean checkdisk, qboolean isworldmodel)
+model_t *Mod_ForName(const char *name, qboolean crash, qboolean checkdisk, qboolean isworldmodel)
 {
-       return Mod_LoadModel (Mod_FindName (name), crash, checkdisk, isworldmodel);
+       return Mod_LoadModel(Mod_FindName(name), crash, checkdisk, isworldmodel);
 }
 
 qbyte *mod_base;
@@ -413,7 +409,7 @@ qbyte *mod_base;
 Mod_Print
 ================
 */
-static void Mod_Print (void)
+static void Mod_Print(void)
 {
        int             i;
        model_t *mod;
@@ -424,6 +420,19 @@ static void Mod_Print (void)
                        Con_Printf ("%4iK %s\n", mod->mempool ? (mod->mempool->totalsize + 1023) / 1024 : 0, mod->name);
 }
 
+/*
+================
+Mod_Precache
+================
+*/
+static void Mod_Precache(void)
+{
+       if (Cmd_Argc() == 2)
+               Mod_ForName(Cmd_Argv(1), false, true, cl.worldmodel && !strcasecmp(Cmd_Argv(1), cl.worldmodel->name));
+       else
+               Con_Printf("usage: modelprecache <filename>\n");
+}
+
 int Mod_FindTriangleWithEdge(const int *elements, int numtriangles, int start, int end, int ignore)
 {
        int i, match, count;
@@ -671,7 +680,7 @@ void Mod_ShadowMesh_AddPolygon(mempool_t *mempool, shadowmesh_t *mesh, int numve
        */
 }
 
-void Mod_ShadowMesh_AddMesh(mempool_t *mempool, shadowmesh_t *mesh, int numverts, float *verts, int numtris, int *elements)
+void Mod_ShadowMesh_AddMesh(mempool_t *mempool, shadowmesh_t *mesh, float *verts, int numtris, int *elements)
 {
        int i;
        for (i = 0;i < numtris;i++, elements += 3)
@@ -783,7 +792,7 @@ static rtexture_t *GL_TextureForSkinLayer(const qbyte *in, int width, int height
 }
 
 static int detailtexturecycle = 0;
-int Mod_LoadSkinFrame (skinframe_t *skinframe, char *basename, int textureflags, int loadpantsandshirt, int usedetailtexture, int loadglowtexture)
+int Mod_LoadSkinFrame(skinframe_t *skinframe, char *basename, int textureflags, int loadpantsandshirt, int usedetailtexture, int loadglowtexture)
 {
        imageskin_t s;
        memset(skinframe, 0, sizeof(*skinframe));
@@ -811,7 +820,7 @@ int Mod_LoadSkinFrame (skinframe_t *skinframe, char *basename, int textureflags,
        return true;
 }
 
-int Mod_LoadSkinFrame_Internal (skinframe_t *skinframe, char *basename, int textureflags, int loadpantsandshirt, int usedetailtexture, int loadglowtexture, qbyte *skindata, int width, int height)
+int Mod_LoadSkinFrame_Internal(skinframe_t *skinframe, char *basename, int textureflags, int loadpantsandshirt, int usedetailtexture, int loadglowtexture, qbyte *skindata, int width, int height)
 {
        qbyte *temp1, *temp2;
        memset(skinframe, 0, sizeof(*skinframe));