2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 byte mod_novis[MAX_MAP_LEAFS/8];
25 qboolean hlbsp; // LordHavoc: true if it is a HalfLife BSP file (version 30)
27 cvar_t gl_subdivide_size = {"gl_subdivide_size", "128", true};
28 cvar_t halflifebsp = {"halflifebsp", "0"};
35 void Mod_BrushInit (void)
37 Cvar_RegisterVariable (&gl_subdivide_size);
38 Cvar_RegisterVariable (&halflifebsp);
39 memset (mod_novis, 0xff, sizeof(mod_novis));
42 // Mod_PointInLeaf moved to cpu_noasm.c
49 byte *Mod_DecompressVis (byte *in, model_t *model)
51 static byte decompressed[MAX_MAP_LEAFS/8];
56 row = (model->numleafs+7)>>3;
60 { // no vis info, so make all visible
84 } while (out - decompressed < row);
89 byte *Mod_LeafPVS (mleaf_t *leaf, model_t *model)
91 if (leaf == model->leafs)
93 return Mod_DecompressVis (leaf->compressed_vis, model);
96 extern byte *mod_base;
98 extern cvar_t r_fullbrights;
105 void Mod_LoadTextures (lump_t *l)
107 int i, j, num, max, altmax, bytesperpixel, freeimage, transparent, fullbrights;
110 texture_t *anims[10];
111 texture_t *altanims[10];
118 loadmodel->textures = NULL;
122 m = (dmiptexlump_t *)(mod_base + l->fileofs);
124 m->nummiptex = LittleLong (m->nummiptex);
126 loadmodel->numtextures = m->nummiptex;
127 loadmodel->textures = Hunk_AllocName (m->nummiptex * sizeof(*loadmodel->textures), va("%s texture headers", loadname));
129 // just to work around bounds checking when debugging with it (array index out of bounds error thing)
131 for (i=0 ; i<m->nummiptex ; i++)
133 dofs[i] = LittleLong(dofs[i]);
136 mt = (miptex_t *)((byte *)m + dofs[i]);
137 mt->width = LittleLong (mt->width);
138 mt->height = LittleLong (mt->height);
139 for (j=0 ; j<MIPLEVELS ; j++)
140 mt->offsets[j] = LittleLong (mt->offsets[j]);
142 if ( (mt->width & 15) || (mt->height & 15) )
143 Host_Error ("Texture %s is not 16 aligned", mt->name);
144 // LordHavoc: rewriting the map texture loader for GLQuake
145 tx = Hunk_AllocName (sizeof(texture_t), va("%s textures", loadname));
146 loadmodel->textures[i] = tx;
148 // LordHavoc: force all names to lowercase and make sure they are terminated while copying
149 for (j = 0;mt->name[j] && j < 15;j++)
151 if (mt->name[j] >= 'A' && mt->name[j] <= 'Z')
152 tx->name[j] = mt->name[j] + ('a' - 'A');
154 tx->name[j] = mt->name[j];
159 tx->width = mt->width;
160 tx->height = mt->height;
161 for (j=0 ; j<MIPLEVELS ; j++)
167 data = loadimagepixels(tx->name, FALSE, 0, 0); //tx->width, tx->height);
168 if (!data) // no external texture found
173 if (mt->offsets[0]) // texture included
175 data = (byte *)((int) mt + mt->offsets[0]);
178 byte *in, *out, *pal;
184 data = out = qmalloc(mt->width * mt->height * 4);
185 pal = in + (((mt->width * mt->height) * 85) >> 6);
186 // palsize = pal[1] * 0x100 + pal[0];
187 // if (palsize >= 256)
190 for (d = 0;d < mt->width * mt->height;d++)
193 if (mt->name[0] == '{' && p == 255)
195 out[0] = out[1] = out[2] = out[3] = 0;
211 if (r_fullbrights.value && tx->name[0] != '*')
213 for (j = 0;j < tx->width*tx->height;j++)
215 if (data[j] >= 224) // fullbright
224 else // no texture, and no external replacement texture was found
226 tx->width = tx->height = 16;
227 data = (byte *)((int) r_notexture_mip + r_notexture_mip->offsets[0]);
230 if (!hlbsp && !strncmp(tx->name,"sky",3) && tx->width == 256 && tx->height == 128) // LordHavoc: HL sky textures are entirely unrelated
232 tx->transparent = FALSE;
233 R_InitSky (data, bytesperpixel);
241 tx->transparent = false;
242 data2 = qmalloc(tx->width*tx->height);
243 for (j = 0;j < tx->width*tx->height;j++)
244 data2[j] = data[j] >= 224 ? 0 : data[j]; // no fullbrights
245 tx->gl_texturenum = GL_LoadTexture (tx->name, tx->width, tx->height, data2, true, false, 1);
246 strcpy(name, tx->name);
247 strcat(name, "_glow");
248 for (j = 0;j < tx->width*tx->height;j++)
249 data2[j] = data[j] >= 224 ? data[j] : 0; // only fullbrights
250 tx->gl_glowtexturenum = GL_LoadTexture (name, tx->width, tx->height, data2, true, false, 1);
255 tx->transparent = transparent;
256 tx->gl_texturenum = GL_LoadTexture (tx->name, tx->width, tx->height, data, true, transparent, bytesperpixel);
257 tx->gl_glowtexturenum = 0;
265 // sequence the animations
267 for (i=0 ; i<m->nummiptex ; i++)
269 tx = loadmodel->textures[i];
270 if (!tx || tx->name[0] != '+')
273 continue; // allready sequenced
275 // find the number of frames in the animation
276 memset (anims, 0, sizeof(anims));
277 memset (altanims, 0, sizeof(altanims));
281 if (max >= 'a' && max <= 'z')
283 if (max >= '0' && max <= '9')
290 else if (max >= 'A' && max <= 'J')
294 altanims[altmax] = tx;
298 Host_Error ("Bad animating texture %s", tx->name);
300 for (j=i+1 ; j<m->nummiptex ; j++)
302 tx2 = loadmodel->textures[j];
303 if (!tx2 || tx2->name[0] != '+')
305 if (strcmp (tx2->name+2, tx->name+2))
309 if (num >= 'a' && num <= 'z')
311 if (num >= '0' && num <= '9')
318 else if (num >= 'A' && num <= 'J')
326 Host_Error ("Bad animating texture %s", tx->name);
330 // link them all together
331 for (j=0 ; j<max ; j++)
335 Host_Error ("Missing frame %i of %s",j, tx->name);
336 tx2->anim_total = max * ANIM_CYCLE;
337 tx2->anim_min = j * ANIM_CYCLE;
338 tx2->anim_max = (j+1) * ANIM_CYCLE;
339 tx2->anim_next = anims[ (j+1)%max ];
341 tx2->alternate_anims = altanims[0];
343 for (j=0 ; j<altmax ; j++)
347 Host_Error ("Missing frame %i of %s",j, tx->name);
348 tx2->anim_total = altmax * ANIM_CYCLE;
349 tx2->anim_min = j * ANIM_CYCLE;
350 tx2->anim_max = (j+1) * ANIM_CYCLE;
351 tx2->anim_next = altanims[ (j+1)%altmax ];
353 tx2->alternate_anims = anims[0];
363 void Mod_LoadLighting (lump_t *l)
366 byte *in, *out, *data;
368 char litfilename[1024];
369 loadmodel->lightdata = NULL;
370 if (hlbsp) // LordHavoc: load the colored lighting data straight
372 loadmodel->lightdata = Hunk_AllocName ( l->filelen, va("%s lightmaps", loadname));
373 memcpy (loadmodel->lightdata, mod_base + l->fileofs, l->filelen);
375 else // LordHavoc: bsp version 29 (normal white lighting)
377 // LordHavoc: hope is not lost yet, check for a .lit file to load
378 strcpy(litfilename, loadmodel->name);
379 COM_StripExtension(litfilename, litfilename);
380 strcat(litfilename, ".lit");
381 data = (byte*) COM_LoadHunkFile (litfilename, false);
384 if (data[0] == 'Q' && data[1] == 'L' && data[2] == 'I' && data[3] == 'T')
386 i = LittleLong(((int *)data)[1]);
389 Con_DPrintf("%s loaded", litfilename);
390 loadmodel->lightdata = data + 8;
394 Con_Printf("Unknown .lit file version (%d)\n", i);
397 Con_Printf("Corrupt .lit file (old version?), ignoring\n");
399 // LordHavoc: oh well, expand the white lighting data
402 loadmodel->lightdata = Hunk_AllocName ( l->filelen*3, va("%s lightmaps", loadname));
403 in = loadmodel->lightdata + l->filelen*2; // place the file at the end, so it will not be overwritten until the very last write
404 out = loadmodel->lightdata;
405 memcpy (in, mod_base + l->fileofs, l->filelen);
406 for (i = 0;i < l->filelen;i++)
422 void Mod_LoadVisibility (lump_t *l)
426 loadmodel->visdata = NULL;
429 loadmodel->visdata = Hunk_AllocName ( l->filelen, va("%s visdata", loadname));
430 memcpy (loadmodel->visdata, mod_base + l->fileofs, l->filelen);
433 void CL_ParseEntityLump(char *entdata);
435 extern qboolean isworldmodel;
442 void Mod_LoadEntities (lump_t *l)
446 loadmodel->entities = NULL;
449 loadmodel->entities = Hunk_AllocName ( l->filelen, va("%s entities", loadname));
450 memcpy (loadmodel->entities, mod_base + l->fileofs, l->filelen);
453 CL_ParseEntityLump(loadmodel->entities);
462 void Mod_LoadVertexes (lump_t *l)
468 in = (void *)(mod_base + l->fileofs);
469 if (l->filelen % sizeof(*in))
470 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
471 count = l->filelen / sizeof(*in);
472 out = Hunk_AllocName ( count*sizeof(*out), va("%s vertices", loadname));
474 loadmodel->vertexes = out;
475 loadmodel->numvertexes = count;
477 for ( i=0 ; i<count ; i++, in++, out++)
479 out->position[0] = LittleFloat (in->point[0]);
480 out->position[1] = LittleFloat (in->point[1]);
481 out->position[2] = LittleFloat (in->point[2]);
490 void Mod_LoadSubmodels (lump_t *l)
496 in = (void *)(mod_base + l->fileofs);
497 if (l->filelen % sizeof(*in))
498 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
499 count = l->filelen / sizeof(*in);
500 out = Hunk_AllocName ( count*sizeof(*out), va("%s submodels", loadname));
502 loadmodel->submodels = out;
503 loadmodel->numsubmodels = count;
505 for ( i=0 ; i<count ; i++, in++, out++)
507 for (j=0 ; j<3 ; j++)
508 { // spread the mins / maxs by a pixel
509 out->mins[j] = LittleFloat (in->mins[j]) - 1;
510 out->maxs[j] = LittleFloat (in->maxs[j]) + 1;
511 out->origin[j] = LittleFloat (in->origin[j]);
513 for (j=0 ; j<MAX_MAP_HULLS ; j++)
514 out->headnode[j] = LittleLong (in->headnode[j]);
515 out->visleafs = LittleLong (in->visleafs);
516 out->firstface = LittleLong (in->firstface);
517 out->numfaces = LittleLong (in->numfaces);
526 void Mod_LoadEdges (lump_t *l)
532 in = (void *)(mod_base + l->fileofs);
533 if (l->filelen % sizeof(*in))
534 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
535 count = l->filelen / sizeof(*in);
536 out = Hunk_AllocName ( (count + 1) * sizeof(*out), va("%s edges", loadname));
538 loadmodel->edges = out;
539 loadmodel->numedges = count;
541 for ( i=0 ; i<count ; i++, in++, out++)
543 out->v[0] = (unsigned short)LittleShort(in->v[0]);
544 out->v[1] = (unsigned short)LittleShort(in->v[1]);
553 void Mod_LoadTexinfo (lump_t *l)
561 in = (void *)(mod_base + l->fileofs);
562 if (l->filelen % sizeof(*in))
563 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
564 count = l->filelen / sizeof(*in);
565 out = Hunk_AllocName ( count*sizeof(*out), va("%s texinfo", loadname));
567 loadmodel->texinfo = out;
568 loadmodel->numtexinfo = count;
570 for ( i=0 ; i<count ; i++, in++, out++)
572 for (k=0 ; k<2 ; k++)
573 for (j=0 ; j<4 ; j++)
574 out->vecs[k][j] = LittleFloat (in->vecs[k][j]);
575 len1 = Length (out->vecs[0]);
576 len2 = Length (out->vecs[1]);
577 len1 = (len1 + len2)/2;
580 else if (len1 < 0.49)
582 else if (len1 < 0.99)
587 if (len1 + len2 < 0.001)
588 out->mipadjust = 1; // don't crash
590 out->mipadjust = 1 / floor( (len1+len2)/2 + 0.1 );
593 miptex = LittleLong (in->miptex);
594 out->flags = LittleLong (in->flags);
596 if (!loadmodel->textures)
598 out->texture = r_notexture_mip; // checkerboard texture
600 out->texture->transparent = FALSE;
604 if (miptex >= loadmodel->numtextures)
605 Host_Error ("miptex >= loadmodel->numtextures");
606 out->texture = loadmodel->textures[miptex];
609 out->texture = r_notexture_mip; // texture not found
611 out->texture->transparent = FALSE;
621 Fills in s->texturemins[] and s->extents[]
624 void CalcSurfaceExtents (msurface_t *s)
626 float mins[2], maxs[2], val;
630 int bmins[2], bmaxs[2];
632 mins[0] = mins[1] = 999999;
633 maxs[0] = maxs[1] = -99999;
637 for (i=0 ; i<s->numedges ; i++)
639 e = loadmodel->surfedges[s->firstedge+i];
641 v = &loadmodel->vertexes[loadmodel->edges[e].v[0]];
643 v = &loadmodel->vertexes[loadmodel->edges[-e].v[1]];
645 for (j=0 ; j<2 ; j++)
647 val = v->position[0] * tex->vecs[j][0] +
648 v->position[1] * tex->vecs[j][1] +
649 v->position[2] * tex->vecs[j][2] +
658 for (i=0 ; i<2 ; i++)
660 bmins[i] = floor(mins[i]/16);
661 bmaxs[i] = ceil(maxs[i]/16);
663 s->texturemins[i] = bmins[i] * 16;
664 s->extents[i] = (bmaxs[i] - bmins[i]) * 16;
665 if ( !(tex->flags & TEX_SPECIAL) && s->extents[i] > 512 /* 256 */ )
666 Host_Error ("Bad surface extents");
670 void GL_SubdivideSurface (msurface_t *fa);
672 extern char skyname[];
679 void Mod_LoadFaces (lump_t *l)
683 int i, count, surfnum;
686 in = (void *)(mod_base + l->fileofs);
687 if (l->filelen % sizeof(*in))
688 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
689 count = l->filelen / sizeof(*in);
690 out = Hunk_AllocName ( count*sizeof(*out), va("%s faces", loadname));
692 loadmodel->surfaces = out;
693 loadmodel->numsurfaces = count;
695 for ( surfnum=0 ; surfnum<count ; surfnum++, in++, out++)
697 out->firstedge = LittleLong(in->firstedge);
698 out->numedges = LittleShort(in->numedges);
701 planenum = LittleShort(in->planenum);
702 side = LittleShort(in->side);
704 out->flags |= SURF_PLANEBACK;
706 out->plane = loadmodel->planes + planenum;
708 out->texinfo = loadmodel->texinfo + LittleShort (in->texinfo);
710 CalcSurfaceExtents (out);
714 for (i=0 ; i<MAXLIGHTMAPS ; i++)
715 out->styles[i] = in->styles[i];
716 i = LittleLong(in->lightofs);
719 else if (hlbsp) // LordHavoc: HalfLife map (bsp version 30)
720 out->samples = loadmodel->lightdata + i;
721 else // LordHavoc: white lighting (bsp version 29)
722 out->samples = loadmodel->lightdata + (i * 3);
724 // set the drawing flags flag
726 // if (!strncmp(out->texinfo->texture->name,"sky",3)) // sky
727 // LordHavoc: faster check
728 if ((out->texinfo->texture->name[0] == 's' || out->texinfo->texture->name[0] == 'S')
729 && (out->texinfo->texture->name[1] == 'k' || out->texinfo->texture->name[1] == 'K')
730 && (out->texinfo->texture->name[2] == 'y' || out->texinfo->texture->name[2] == 'Y'))
732 // LordHavoc: for consistency reasons, mark sky as fullbright and solid as well
733 out->flags |= (SURF_DRAWSKY | SURF_DRAWTILED | SURF_DRAWFULLBRIGHT | SURF_DRAWNOALPHA);
734 GL_SubdivideSurface (out); // cut up polygon for warps
738 // if (!strncmp(out->texinfo->texture->name,"*",1)) // turbulent
739 if (out->texinfo->texture->name[0] == '*') // LordHavoc: faster check
741 out->flags |= (SURF_DRAWTURB | SURF_DRAWTILED);
742 // LordHavoc: some turbulent textures should be fullbright and solid
743 if (!strncmp(out->texinfo->texture->name,"*lava",5)
744 || !strncmp(out->texinfo->texture->name,"*teleport",9)
745 || !strncmp(out->texinfo->texture->name,"*rift",5)) // Scourge of Armagon texture
746 out->flags |= (SURF_DRAWFULLBRIGHT | SURF_DRAWNOALPHA);
747 for (i=0 ; i<2 ; i++)
749 out->extents[i] = 16384;
750 out->texturemins[i] = -8192;
752 GL_SubdivideSurface (out); // cut up polygon for warps
765 void Mod_SetParent (mnode_t *node, mnode_t *parent)
767 node->parent = parent;
768 if (node->contents < 0)
770 Mod_SetParent (node->children[0], node);
771 Mod_SetParent (node->children[1], node);
779 void Mod_LoadNodes (lump_t *l)
785 in = (void *)(mod_base + l->fileofs);
786 if (l->filelen % sizeof(*in))
787 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
788 count = l->filelen / sizeof(*in);
789 out = Hunk_AllocName ( count*sizeof(*out), va("%s nodes", loadname));
791 loadmodel->nodes = out;
792 loadmodel->numnodes = count;
794 for ( i=0 ; i<count ; i++, in++, out++)
796 for (j=0 ; j<3 ; j++)
798 out->minmaxs[j] = LittleShort (in->mins[j]);
799 out->minmaxs[3+j] = LittleShort (in->maxs[j]);
802 p = LittleLong(in->planenum);
803 out->plane = loadmodel->planes + p;
805 out->firstsurface = LittleShort (in->firstface);
806 out->numsurfaces = LittleShort (in->numfaces);
808 for (j=0 ; j<2 ; j++)
810 p = LittleShort (in->children[j]);
812 out->children[j] = loadmodel->nodes + p;
814 out->children[j] = (mnode_t *)(loadmodel->leafs + (-1 - p));
818 Mod_SetParent (loadmodel->nodes, NULL); // sets nodes and leafs
826 void Mod_LoadLeafs (lump_t *l)
832 in = (void *)(mod_base + l->fileofs);
833 if (l->filelen % sizeof(*in))
834 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
835 count = l->filelen / sizeof(*in);
836 out = Hunk_AllocName ( count*sizeof(*out), va("%s leafs", loadname));
838 loadmodel->leafs = out;
839 loadmodel->numleafs = count;
841 for ( i=0 ; i<count ; i++, in++, out++)
843 for (j=0 ; j<3 ; j++)
845 out->minmaxs[j] = LittleShort (in->mins[j]);
846 out->minmaxs[3+j] = LittleShort (in->maxs[j]);
849 p = LittleLong(in->contents);
852 out->firstmarksurface = loadmodel->marksurfaces +
853 LittleShort(in->firstmarksurface);
854 out->nummarksurfaces = LittleShort(in->nummarksurfaces);
856 p = LittleLong(in->visofs);
858 out->compressed_vis = NULL;
860 out->compressed_vis = loadmodel->visdata + p;
863 for (j=0 ; j<4 ; j++)
864 out->ambient_sound_level[j] = in->ambient_level[j];
866 // gl underwater warp
867 // LordHavoc: disabled underwater warping
869 if (out->contents != CONTENTS_EMPTY)
871 for (j=0 ; j<out->nummarksurfaces ; j++)
872 out->firstmarksurface[j]->flags |= SURF_UNDERWATER;
883 void Mod_LoadClipnodes (lump_t *l)
885 dclipnode_t *in, *out;
889 in = (void *)(mod_base + l->fileofs);
890 if (l->filelen % sizeof(*in))
891 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
892 count = l->filelen / sizeof(*in);
893 out = Hunk_AllocName ( count*sizeof(*out), va("%s clipnodes", loadname));
895 loadmodel->clipnodes = out;
896 loadmodel->numclipnodes = count;
900 hull = &loadmodel->hulls[1];
901 hull->clipnodes = out;
902 hull->firstclipnode = 0;
903 hull->lastclipnode = count-1;
904 hull->planes = loadmodel->planes;
905 hull->clip_mins[0] = -16;
906 hull->clip_mins[1] = -16;
907 hull->clip_mins[2] = -36;
908 hull->clip_maxs[0] = 16;
909 hull->clip_maxs[1] = 16;
910 hull->clip_maxs[2] = 36;
912 hull = &loadmodel->hulls[2];
913 hull->clipnodes = out;
914 hull->firstclipnode = 0;
915 hull->lastclipnode = count-1;
916 hull->planes = loadmodel->planes;
917 hull->clip_mins[0] = -32;
918 hull->clip_mins[1] = -32;
919 hull->clip_mins[2] = -32;
920 hull->clip_maxs[0] = 32;
921 hull->clip_maxs[1] = 32;
922 hull->clip_maxs[2] = 32;
924 hull = &loadmodel->hulls[3];
925 hull->clipnodes = out;
926 hull->firstclipnode = 0;
927 hull->lastclipnode = count-1;
928 hull->planes = loadmodel->planes;
929 hull->clip_mins[0] = -16;
930 hull->clip_mins[1] = -16;
931 hull->clip_mins[2] = -18;
932 hull->clip_maxs[0] = 16;
933 hull->clip_maxs[1] = 16;
934 hull->clip_maxs[2] = 18;
938 hull = &loadmodel->hulls[1];
939 hull->clipnodes = out;
940 hull->firstclipnode = 0;
941 hull->lastclipnode = count-1;
942 hull->planes = loadmodel->planes;
943 hull->clip_mins[0] = -16;
944 hull->clip_mins[1] = -16;
945 hull->clip_mins[2] = -24;
946 hull->clip_maxs[0] = 16;
947 hull->clip_maxs[1] = 16;
948 hull->clip_maxs[2] = 32;
950 hull = &loadmodel->hulls[2];
951 hull->clipnodes = out;
952 hull->firstclipnode = 0;
953 hull->lastclipnode = count-1;
954 hull->planes = loadmodel->planes;
955 hull->clip_mins[0] = -32;
956 hull->clip_mins[1] = -32;
957 hull->clip_mins[2] = -24;
958 hull->clip_maxs[0] = 32;
959 hull->clip_maxs[1] = 32;
960 hull->clip_maxs[2] = 64;
963 for (i=0 ; i<count ; i++, out++, in++)
965 out->planenum = LittleLong(in->planenum);
966 out->children[0] = LittleShort(in->children[0]);
967 out->children[1] = LittleShort(in->children[1]);
968 if (out->children[0] >= count || out->children[1] >= count)
969 Host_Error("Corrupt clipping hull (out of range child)\n");
977 Duplicate the drawing hull structure as a clipping hull
980 void Mod_MakeHull0 (void)
987 hull = &loadmodel->hulls[0];
989 in = loadmodel->nodes;
990 count = loadmodel->numnodes;
991 out = Hunk_AllocName ( count*sizeof(*out), va("%s hull0", loadname));
993 hull->clipnodes = out;
994 hull->firstclipnode = 0;
995 hull->lastclipnode = count-1;
996 hull->planes = loadmodel->planes;
998 for (i=0 ; i<count ; i++, out++, in++)
1000 out->planenum = in->plane - loadmodel->planes;
1001 for (j=0 ; j<2 ; j++)
1003 child = in->children[j];
1004 if (child->contents < 0)
1005 out->children[j] = child->contents;
1007 out->children[j] = child - loadmodel->nodes;
1014 Mod_LoadMarksurfaces
1017 void Mod_LoadMarksurfaces (lump_t *l)
1023 in = (void *)(mod_base + l->fileofs);
1024 if (l->filelen % sizeof(*in))
1025 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
1026 count = l->filelen / sizeof(*in);
1027 out = Hunk_AllocName ( count*sizeof(*out), va("%s marksurfaces", loadname));
1029 loadmodel->marksurfaces = out;
1030 loadmodel->nummarksurfaces = count;
1032 for ( i=0 ; i<count ; i++)
1034 j = LittleShort(in[i]);
1035 if (j >= loadmodel->numsurfaces)
1036 Host_Error ("Mod_ParseMarksurfaces: bad surface number");
1037 out[i] = loadmodel->surfaces + j;
1046 void Mod_LoadSurfedges (lump_t *l)
1051 in = (void *)(mod_base + l->fileofs);
1052 if (l->filelen % sizeof(*in))
1053 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
1054 count = l->filelen / sizeof(*in);
1055 out = Hunk_AllocName ( count*sizeof(*out), va("%s surfedges", loadname));
1057 loadmodel->surfedges = out;
1058 loadmodel->numsurfedges = count;
1060 for ( i=0 ; i<count ; i++)
1061 out[i] = LittleLong (in[i]);
1070 void Mod_LoadPlanes (lump_t *l)
1078 in = (void *)(mod_base + l->fileofs);
1079 if (l->filelen % sizeof(*in))
1080 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
1081 count = l->filelen / sizeof(*in);
1082 out = Hunk_AllocName ( count*2*sizeof(*out), va("%s planes", loadname));
1084 loadmodel->planes = out;
1085 loadmodel->numplanes = count;
1087 for ( i=0 ; i<count ; i++, in++, out++)
1090 for (j=0 ; j<3 ; j++)
1092 out->normal[j] = LittleFloat (in->normal[j]);
1093 // if (out->normal[j] < 0)
1097 out->dist = LittleFloat (in->dist);
1098 out->type = LittleLong (in->type);
1099 // out->signbits = bits;
1100 BoxOnPlaneSideClassify(out);
1109 void Mod_LoadBrushModel (model_t *mod, void *buffer)
1115 loadmodel->type = mod_brush;
1117 header = (dheader_t *)buffer;
1119 i = LittleLong (header->version);
1120 if (i != BSPVERSION && i != 30)
1121 Host_Error ("Mod_LoadBrushModel: %s has wrong version number (%i should be %i or 30 (HalfLife))", mod->name, i, BSPVERSION);
1123 halflifebsp.value = hlbsp;
1125 // swap all the lumps
1126 mod_base = (byte *)header;
1128 for (i=0 ; i<sizeof(dheader_t)/4 ; i++)
1129 ((int *)header)[i] = LittleLong ( ((int *)header)[i]);
1133 // LordHavoc: had to move entity loading above everything to allow parsing various settings from worldspawn
1134 Mod_LoadEntities (&header->lumps[LUMP_ENTITIES]);
1136 Mod_LoadVertexes (&header->lumps[LUMP_VERTEXES]);
1137 Mod_LoadEdges (&header->lumps[LUMP_EDGES]);
1138 Mod_LoadSurfedges (&header->lumps[LUMP_SURFEDGES]);
1139 Mod_LoadTextures (&header->lumps[LUMP_TEXTURES]);
1140 Mod_LoadLighting (&header->lumps[LUMP_LIGHTING]);
1141 Mod_LoadPlanes (&header->lumps[LUMP_PLANES]);
1142 Mod_LoadTexinfo (&header->lumps[LUMP_TEXINFO]);
1143 Mod_LoadFaces (&header->lumps[LUMP_FACES]);
1144 Mod_LoadMarksurfaces (&header->lumps[LUMP_MARKSURFACES]);
1145 Mod_LoadVisibility (&header->lumps[LUMP_VISIBILITY]);
1146 Mod_LoadLeafs (&header->lumps[LUMP_LEAFS]);
1147 Mod_LoadNodes (&header->lumps[LUMP_NODES]);
1148 Mod_LoadClipnodes (&header->lumps[LUMP_CLIPNODES]);
1149 // Mod_LoadEntities (&header->lumps[LUMP_ENTITIES]);
1150 Mod_LoadSubmodels (&header->lumps[LUMP_MODELS]);
1154 mod->numframes = 2; // regular and alternate animation
1157 // set up the submodels (FIXME: this is confusing)
1159 for (i=0 ; i<mod->numsubmodels ; i++)
1161 bm = &mod->submodels[i];
1163 mod->hulls[0].firstclipnode = bm->headnode[0];
1164 for (j=1 ; j<MAX_MAP_HULLS ; j++)
1166 mod->hulls[j].firstclipnode = bm->headnode[j];
1167 mod->hulls[j].lastclipnode = mod->numclipnodes-1;
1170 mod->firstmodelsurface = bm->firstface;
1171 mod->nummodelsurfaces = bm->numfaces;
1173 VectorCopy (bm->maxs, mod->maxs);
1174 VectorCopy (bm->mins, mod->mins);
1176 mod->radius = RadiusFromBounds (mod->mins, mod->maxs);
1178 mod->numleafs = bm->visleafs;
1180 if (isworldmodel && i < (mod->numsubmodels-1)) // LordHavoc: only register submodels if it is the world (prevents bsp models from replacing world submodels)
1181 { // duplicate the basic information
1184 sprintf (name, "*%i", i+1);
1185 loadmodel = Mod_FindName (name);
1187 strcpy (loadmodel->name, name);