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) , 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), 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 (!hlbsp && mt->offsets[0]) // texture included
175 data = (byte *)((int) mt + mt->offsets[0]);
176 if (r_fullbrights.value && tx->name[0] != '*')
178 for (j = 0;j < tx->width*tx->height;j++)
179 if (data[j] >= 224) // fullbright
186 else // no texture, and no external replacement texture was found
188 tx->width = tx->height = 16;
189 data = (byte *)((int) r_notexture_mip + r_notexture_mip->offsets[0]);
194 tx->width = image_width;
195 tx->height = image_height;
197 if (!hlbsp && !strncmp(tx->name,"sky",3) && tx->width == 256 && tx->height == 128) // LordHavoc: HL sky textures are entirely unrelated
199 tx->transparent = FALSE;
200 R_InitSky (data, bytesperpixel);
204 tx->transparent = transparent;
209 data2 = malloc(tx->width*tx->height);
210 for (j = 0;j < tx->width*tx->height;j++)
211 data2[j] = data[j] >= 224 ? 0 : data[j]; // no fullbrights
212 tx->gl_texturenum = GL_LoadTexture (tx->name, tx->width, tx->height, data2, true, transparent, 1);
213 strcpy(name, tx->name);
214 strcat(name, "_glow");
215 for (j = 0;j < tx->width*tx->height;j++)
216 data2[j] = data[j] >= 224 ? data[j] : 0; // only fullbrights
217 tx->gl_glowtexturenum = GL_LoadTexture (name, tx->width, tx->height, data2, true, transparent, 1);
222 tx->gl_texturenum = GL_LoadTexture (tx->name, tx->width, tx->height, data, true, transparent, bytesperpixel);
223 tx->gl_glowtexturenum = 0;
231 // sequence the animations
233 for (i=0 ; i<m->nummiptex ; i++)
235 tx = loadmodel->textures[i];
236 if (!tx || tx->name[0] != '+')
239 continue; // allready sequenced
241 // find the number of frames in the animation
242 memset (anims, 0, sizeof(anims));
243 memset (altanims, 0, sizeof(altanims));
247 if (max >= 'a' && max <= 'z')
249 if (max >= '0' && max <= '9')
256 else if (max >= 'A' && max <= 'J')
260 altanims[altmax] = tx;
264 Host_Error ("Bad animating texture %s", tx->name);
266 for (j=i+1 ; j<m->nummiptex ; j++)
268 tx2 = loadmodel->textures[j];
269 if (!tx2 || tx2->name[0] != '+')
271 if (strcmp (tx2->name+2, tx->name+2))
275 if (num >= 'a' && num <= 'z')
277 if (num >= '0' && num <= '9')
284 else if (num >= 'A' && num <= 'J')
292 Host_Error ("Bad animating texture %s", tx->name);
296 // link them all together
297 for (j=0 ; j<max ; j++)
301 Host_Error ("Missing frame %i of %s",j, tx->name);
302 tx2->anim_total = max * ANIM_CYCLE;
303 tx2->anim_min = j * ANIM_CYCLE;
304 tx2->anim_max = (j+1) * ANIM_CYCLE;
305 tx2->anim_next = anims[ (j+1)%max ];
307 tx2->alternate_anims = altanims[0];
309 for (j=0 ; j<altmax ; j++)
313 Host_Error ("Missing frame %i of %s",j, tx->name);
314 tx2->anim_total = altmax * ANIM_CYCLE;
315 tx2->anim_min = j * ANIM_CYCLE;
316 tx2->anim_max = (j+1) * ANIM_CYCLE;
317 tx2->anim_next = altanims[ (j+1)%altmax ];
319 tx2->alternate_anims = anims[0];
329 void Mod_LoadLighting (lump_t *l)
332 byte *in, *out, *data;
334 char litfilename[1024];
335 loadmodel->lightdata = NULL;
336 if (hlbsp) // LordHavoc: load the colored lighting data straight
338 loadmodel->lightdata = Hunk_AllocName ( l->filelen, loadname);
339 memcpy (loadmodel->lightdata, mod_base + l->fileofs, l->filelen);
341 else // LordHavoc: bsp version 29 (normal white lighting)
343 // LordHavoc: hope is not lost yet, check for a .lit file to load
344 strcpy(litfilename, loadmodel->name);
345 COM_StripExtension(litfilename, litfilename);
346 strcat(litfilename, ".lit");
347 data = (byte*) COM_LoadHunkFile (litfilename, false);
350 if (data[0] == 'Q' && data[1] == 'L' && data[2] == 'I' && data[3] == 'T')
352 i = LittleLong(((int *)data)[1]);
355 Con_DPrintf("%s loaded", litfilename);
356 loadmodel->lightdata = data + 8;
360 Con_Printf("Unknown .lit file version (%d)\n", i);
363 Con_Printf("Corrupt .lit file (old version?), ignoring\n");
365 // LordHavoc: oh well, expand the white lighting data
368 loadmodel->lightdata = Hunk_AllocName ( l->filelen*3, litfilename);
369 in = loadmodel->lightdata + l->filelen*2; // place the file at the end, so it will not be overwritten until the very last write
370 out = loadmodel->lightdata;
371 memcpy (in, mod_base + l->fileofs, l->filelen);
372 for (i = 0;i < l->filelen;i++)
388 void Mod_LoadVisibility (lump_t *l)
392 loadmodel->visdata = NULL;
395 loadmodel->visdata = Hunk_AllocName ( l->filelen, loadname);
396 memcpy (loadmodel->visdata, mod_base + l->fileofs, l->filelen);
399 void CL_ParseEntityLump(char *entdata);
401 extern qboolean isworldmodel;
408 void Mod_LoadEntities (lump_t *l)
412 loadmodel->entities = NULL;
415 loadmodel->entities = Hunk_AllocName ( l->filelen, loadname);
416 memcpy (loadmodel->entities, mod_base + l->fileofs, l->filelen);
419 CL_ParseEntityLump(loadmodel->entities);
428 void Mod_LoadVertexes (lump_t *l)
434 in = (void *)(mod_base + l->fileofs);
435 if (l->filelen % sizeof(*in))
436 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
437 count = l->filelen / sizeof(*in);
438 out = Hunk_AllocName ( count*sizeof(*out), loadname);
440 loadmodel->vertexes = out;
441 loadmodel->numvertexes = count;
443 for ( i=0 ; i<count ; i++, in++, out++)
445 out->position[0] = LittleFloat (in->point[0]);
446 out->position[1] = LittleFloat (in->point[1]);
447 out->position[2] = LittleFloat (in->point[2]);
456 void Mod_LoadSubmodels (lump_t *l)
462 in = (void *)(mod_base + l->fileofs);
463 if (l->filelen % sizeof(*in))
464 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
465 count = l->filelen / sizeof(*in);
466 out = Hunk_AllocName ( count*sizeof(*out), loadname);
468 loadmodel->submodels = out;
469 loadmodel->numsubmodels = count;
471 for ( i=0 ; i<count ; i++, in++, out++)
473 for (j=0 ; j<3 ; j++)
474 { // spread the mins / maxs by a pixel
475 out->mins[j] = LittleFloat (in->mins[j]) - 1;
476 out->maxs[j] = LittleFloat (in->maxs[j]) + 1;
477 out->origin[j] = LittleFloat (in->origin[j]);
479 for (j=0 ; j<MAX_MAP_HULLS ; j++)
480 out->headnode[j] = LittleLong (in->headnode[j]);
481 out->visleafs = LittleLong (in->visleafs);
482 out->firstface = LittleLong (in->firstface);
483 out->numfaces = LittleLong (in->numfaces);
492 void Mod_LoadEdges (lump_t *l)
498 in = (void *)(mod_base + l->fileofs);
499 if (l->filelen % sizeof(*in))
500 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
501 count = l->filelen / sizeof(*in);
502 out = Hunk_AllocName ( (count + 1) * sizeof(*out), loadname);
504 loadmodel->edges = out;
505 loadmodel->numedges = count;
507 for ( i=0 ; i<count ; i++, in++, out++)
509 out->v[0] = (unsigned short)LittleShort(in->v[0]);
510 out->v[1] = (unsigned short)LittleShort(in->v[1]);
519 void Mod_LoadTexinfo (lump_t *l)
527 in = (void *)(mod_base + l->fileofs);
528 if (l->filelen % sizeof(*in))
529 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
530 count = l->filelen / sizeof(*in);
531 out = Hunk_AllocName ( count*sizeof(*out), loadname);
533 loadmodel->texinfo = out;
534 loadmodel->numtexinfo = count;
536 for ( i=0 ; i<count ; i++, in++, out++)
538 for (k=0 ; k<2 ; k++)
539 for (j=0 ; j<4 ; j++)
540 out->vecs[k][j] = LittleFloat (in->vecs[k][j]);
541 len1 = Length (out->vecs[0]);
542 len2 = Length (out->vecs[1]);
543 len1 = (len1 + len2)/2;
546 else if (len1 < 0.49)
548 else if (len1 < 0.99)
553 if (len1 + len2 < 0.001)
554 out->mipadjust = 1; // don't crash
556 out->mipadjust = 1 / floor( (len1+len2)/2 + 0.1 );
559 miptex = LittleLong (in->miptex);
560 out->flags = LittleLong (in->flags);
562 if (!loadmodel->textures)
564 out->texture = r_notexture_mip; // checkerboard texture
566 out->texture->transparent = FALSE;
570 if (miptex >= loadmodel->numtextures)
571 Host_Error ("miptex >= loadmodel->numtextures");
572 out->texture = loadmodel->textures[miptex];
575 out->texture = r_notexture_mip; // texture not found
577 out->texture->transparent = FALSE;
587 Fills in s->texturemins[] and s->extents[]
590 void CalcSurfaceExtents (msurface_t *s)
592 float mins[2], maxs[2], val;
596 int bmins[2], bmaxs[2];
598 mins[0] = mins[1] = 999999;
599 maxs[0] = maxs[1] = -99999;
603 for (i=0 ; i<s->numedges ; i++)
605 e = loadmodel->surfedges[s->firstedge+i];
607 v = &loadmodel->vertexes[loadmodel->edges[e].v[0]];
609 v = &loadmodel->vertexes[loadmodel->edges[-e].v[1]];
611 for (j=0 ; j<2 ; j++)
613 val = v->position[0] * tex->vecs[j][0] +
614 v->position[1] * tex->vecs[j][1] +
615 v->position[2] * tex->vecs[j][2] +
624 for (i=0 ; i<2 ; i++)
626 bmins[i] = floor(mins[i]/16);
627 bmaxs[i] = ceil(maxs[i]/16);
629 s->texturemins[i] = bmins[i] * 16;
630 s->extents[i] = (bmaxs[i] - bmins[i]) * 16;
631 if ( !(tex->flags & TEX_SPECIAL) && s->extents[i] > 512 /* 256 */ )
632 Host_Error ("Bad surface extents");
636 void GL_SubdivideSurface (msurface_t *fa);
638 extern char skyname[];
645 void Mod_LoadFaces (lump_t *l)
649 int i, count, surfnum;
652 in = (void *)(mod_base + l->fileofs);
653 if (l->filelen % sizeof(*in))
654 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
655 count = l->filelen / sizeof(*in);
656 out = Hunk_AllocName ( count*sizeof(*out), loadname);
658 loadmodel->surfaces = out;
659 loadmodel->numsurfaces = count;
661 for ( surfnum=0 ; surfnum<count ; surfnum++, in++, out++)
663 out->firstedge = LittleLong(in->firstedge);
664 out->numedges = LittleShort(in->numedges);
667 planenum = LittleShort(in->planenum);
668 side = LittleShort(in->side);
670 out->flags |= SURF_PLANEBACK;
672 out->plane = loadmodel->planes + planenum;
674 out->texinfo = loadmodel->texinfo + LittleShort (in->texinfo);
676 CalcSurfaceExtents (out);
680 for (i=0 ; i<MAXLIGHTMAPS ; i++)
681 out->styles[i] = in->styles[i];
682 i = LittleLong(in->lightofs);
685 else if (hlbsp) // LordHavoc: HalfLife map (bsp version 30)
686 out->samples = loadmodel->lightdata + i;
687 else // LordHavoc: white lighting (bsp version 29)
688 out->samples = loadmodel->lightdata + (i * 3);
690 // set the drawing flags flag
692 // if (!strncmp(out->texinfo->texture->name,"sky",3)) // sky
693 // LordHavoc: faster check
694 if ((out->texinfo->texture->name[0] == 's' || out->texinfo->texture->name[0] == 'S')
695 && (out->texinfo->texture->name[1] == 'k' || out->texinfo->texture->name[1] == 'K')
696 && (out->texinfo->texture->name[2] == 'y' || out->texinfo->texture->name[2] == 'Y'))
698 // LordHavoc: for consistency reasons, mark sky as fullbright and solid as well
699 out->flags |= (SURF_DRAWSKY | SURF_DRAWTILED | SURF_DRAWFULLBRIGHT | SURF_DRAWNOALPHA);
700 GL_SubdivideSurface (out); // cut up polygon for warps
704 // if (!strncmp(out->texinfo->texture->name,"*",1)) // turbulent
705 if (out->texinfo->texture->name[0] == '*') // LordHavoc: faster check
707 out->flags |= (SURF_DRAWTURB | SURF_DRAWTILED);
708 // LordHavoc: some turbulent textures should be fullbright and solid
709 if (!strncmp(out->texinfo->texture->name,"*lava",5)
710 || !strncmp(out->texinfo->texture->name,"*teleport",9)
711 || !strncmp(out->texinfo->texture->name,"*rift",5)) // Scourge of Armagon texture
712 out->flags |= (SURF_DRAWFULLBRIGHT | SURF_DRAWNOALPHA);
713 for (i=0 ; i<2 ; i++)
715 out->extents[i] = 16384;
716 out->texturemins[i] = -8192;
718 GL_SubdivideSurface (out); // cut up polygon for warps
731 void Mod_SetParent (mnode_t *node, mnode_t *parent)
733 node->parent = parent;
734 if (node->contents < 0)
736 Mod_SetParent (node->children[0], node);
737 Mod_SetParent (node->children[1], node);
745 void Mod_LoadNodes (lump_t *l)
751 in = (void *)(mod_base + l->fileofs);
752 if (l->filelen % sizeof(*in))
753 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
754 count = l->filelen / sizeof(*in);
755 out = Hunk_AllocName ( count*sizeof(*out), loadname);
757 loadmodel->nodes = out;
758 loadmodel->numnodes = count;
760 for ( i=0 ; i<count ; i++, in++, out++)
762 for (j=0 ; j<3 ; j++)
764 out->minmaxs[j] = LittleShort (in->mins[j]);
765 out->minmaxs[3+j] = LittleShort (in->maxs[j]);
768 p = LittleLong(in->planenum);
769 out->plane = loadmodel->planes + p;
771 out->firstsurface = LittleShort (in->firstface);
772 out->numsurfaces = LittleShort (in->numfaces);
774 for (j=0 ; j<2 ; j++)
776 p = LittleShort (in->children[j]);
778 out->children[j] = loadmodel->nodes + p;
780 out->children[j] = (mnode_t *)(loadmodel->leafs + (-1 - p));
784 Mod_SetParent (loadmodel->nodes, NULL); // sets nodes and leafs
792 void Mod_LoadLeafs (lump_t *l)
798 in = (void *)(mod_base + l->fileofs);
799 if (l->filelen % sizeof(*in))
800 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
801 count = l->filelen / sizeof(*in);
802 out = Hunk_AllocName ( count*sizeof(*out), loadname);
804 loadmodel->leafs = out;
805 loadmodel->numleafs = count;
807 for ( i=0 ; i<count ; i++, in++, out++)
809 for (j=0 ; j<3 ; j++)
811 out->minmaxs[j] = LittleShort (in->mins[j]);
812 out->minmaxs[3+j] = LittleShort (in->maxs[j]);
815 p = LittleLong(in->contents);
818 out->firstmarksurface = loadmodel->marksurfaces +
819 LittleShort(in->firstmarksurface);
820 out->nummarksurfaces = LittleShort(in->nummarksurfaces);
822 p = LittleLong(in->visofs);
824 out->compressed_vis = NULL;
826 out->compressed_vis = loadmodel->visdata + p;
829 for (j=0 ; j<4 ; j++)
830 out->ambient_sound_level[j] = in->ambient_level[j];
832 // gl underwater warp
833 // LordHavoc: disabled underwater warping
835 if (out->contents != CONTENTS_EMPTY)
837 for (j=0 ; j<out->nummarksurfaces ; j++)
838 out->firstmarksurface[j]->flags |= SURF_UNDERWATER;
849 void Mod_LoadClipnodes (lump_t *l)
851 dclipnode_t *in, *out;
855 in = (void *)(mod_base + l->fileofs);
856 if (l->filelen % sizeof(*in))
857 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
858 count = l->filelen / sizeof(*in);
859 out = Hunk_AllocName ( count*sizeof(*out), loadname);
861 loadmodel->clipnodes = out;
862 loadmodel->numclipnodes = count;
866 hull = &loadmodel->hulls[1];
867 hull->clipnodes = out;
868 hull->firstclipnode = 0;
869 hull->lastclipnode = count-1;
870 hull->planes = loadmodel->planes;
871 hull->clip_mins[0] = -16;
872 hull->clip_mins[1] = -16;
873 hull->clip_mins[2] = -36;
874 hull->clip_maxs[0] = 16;
875 hull->clip_maxs[1] = 16;
876 hull->clip_maxs[2] = 36;
878 hull = &loadmodel->hulls[2];
879 hull->clipnodes = out;
880 hull->firstclipnode = 0;
881 hull->lastclipnode = count-1;
882 hull->planes = loadmodel->planes;
883 hull->clip_mins[0] = -32;
884 hull->clip_mins[1] = -32;
885 hull->clip_mins[2] = -32;
886 hull->clip_maxs[0] = 32;
887 hull->clip_maxs[1] = 32;
888 hull->clip_maxs[2] = 32;
890 hull = &loadmodel->hulls[3];
891 hull->clipnodes = out;
892 hull->firstclipnode = 0;
893 hull->lastclipnode = count-1;
894 hull->planes = loadmodel->planes;
895 hull->clip_mins[0] = -16;
896 hull->clip_mins[1] = -16;
897 hull->clip_mins[2] = -18;
898 hull->clip_maxs[0] = 16;
899 hull->clip_maxs[1] = 16;
900 hull->clip_maxs[2] = 18;
904 hull = &loadmodel->hulls[1];
905 hull->clipnodes = out;
906 hull->firstclipnode = 0;
907 hull->lastclipnode = count-1;
908 hull->planes = loadmodel->planes;
909 hull->clip_mins[0] = -16;
910 hull->clip_mins[1] = -16;
911 hull->clip_mins[2] = -24;
912 hull->clip_maxs[0] = 16;
913 hull->clip_maxs[1] = 16;
914 hull->clip_maxs[2] = 32;
916 hull = &loadmodel->hulls[2];
917 hull->clipnodes = out;
918 hull->firstclipnode = 0;
919 hull->lastclipnode = count-1;
920 hull->planes = loadmodel->planes;
921 hull->clip_mins[0] = -32;
922 hull->clip_mins[1] = -32;
923 hull->clip_mins[2] = -24;
924 hull->clip_maxs[0] = 32;
925 hull->clip_maxs[1] = 32;
926 hull->clip_maxs[2] = 64;
929 for (i=0 ; i<count ; i++, out++, in++)
931 out->planenum = LittleLong(in->planenum);
932 out->children[0] = LittleShort(in->children[0]);
933 out->children[1] = LittleShort(in->children[1]);
934 if (out->children[0] >= count || out->children[1] >= count)
935 Host_Error("Corrupt clipping hull (out of range child)\n");
943 Duplicate the drawing hull structure as a clipping hull
946 void Mod_MakeHull0 (void)
953 hull = &loadmodel->hulls[0];
955 in = loadmodel->nodes;
956 count = loadmodel->numnodes;
957 out = Hunk_AllocName ( count*sizeof(*out), loadname);
959 hull->clipnodes = out;
960 hull->firstclipnode = 0;
961 hull->lastclipnode = count-1;
962 hull->planes = loadmodel->planes;
964 for (i=0 ; i<count ; i++, out++, in++)
966 out->planenum = in->plane - loadmodel->planes;
967 for (j=0 ; j<2 ; j++)
969 child = in->children[j];
970 if (child->contents < 0)
971 out->children[j] = child->contents;
973 out->children[j] = child - loadmodel->nodes;
983 void Mod_LoadMarksurfaces (lump_t *l)
989 in = (void *)(mod_base + l->fileofs);
990 if (l->filelen % sizeof(*in))
991 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
992 count = l->filelen / sizeof(*in);
993 out = Hunk_AllocName ( count*sizeof(*out), loadname);
995 loadmodel->marksurfaces = out;
996 loadmodel->nummarksurfaces = count;
998 for ( i=0 ; i<count ; i++)
1000 j = LittleShort(in[i]);
1001 if (j >= loadmodel->numsurfaces)
1002 Host_Error ("Mod_ParseMarksurfaces: bad surface number");
1003 out[i] = loadmodel->surfaces + j;
1012 void Mod_LoadSurfedges (lump_t *l)
1017 in = (void *)(mod_base + l->fileofs);
1018 if (l->filelen % sizeof(*in))
1019 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
1020 count = l->filelen / sizeof(*in);
1021 out = Hunk_AllocName ( count*sizeof(*out), loadname);
1023 loadmodel->surfedges = out;
1024 loadmodel->numsurfedges = count;
1026 for ( i=0 ; i<count ; i++)
1027 out[i] = LittleLong (in[i]);
1036 void Mod_LoadPlanes (lump_t *l)
1044 in = (void *)(mod_base + l->fileofs);
1045 if (l->filelen % sizeof(*in))
1046 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
1047 count = l->filelen / sizeof(*in);
1048 out = Hunk_AllocName ( count*2*sizeof(*out), loadname);
1050 loadmodel->planes = out;
1051 loadmodel->numplanes = count;
1053 for ( i=0 ; i<count ; i++, in++, out++)
1056 for (j=0 ; j<3 ; j++)
1058 out->normal[j] = LittleFloat (in->normal[j]);
1059 // if (out->normal[j] < 0)
1063 out->dist = LittleFloat (in->dist);
1064 out->type = LittleLong (in->type);
1065 // out->signbits = bits;
1066 BoxOnPlaneSideClassify(out);
1075 void Mod_LoadBrushModel (model_t *mod, void *buffer)
1081 loadmodel->type = mod_brush;
1083 header = (dheader_t *)buffer;
1085 i = LittleLong (header->version);
1086 if (i != BSPVERSION && i != 30)
1087 Host_Error ("Mod_LoadBrushModel: %s has wrong version number (%i should be %i or 30 (HalfLife))", mod->name, i, BSPVERSION);
1089 halflifebsp.value = hlbsp;
1091 // swap all the lumps
1092 mod_base = (byte *)header;
1094 for (i=0 ; i<sizeof(dheader_t)/4 ; i++)
1095 ((int *)header)[i] = LittleLong ( ((int *)header)[i]);
1099 // LordHavoc: had to move entity loading above everything to allow parsing various settings from worldspawn
1100 Mod_LoadEntities (&header->lumps[LUMP_ENTITIES]);
1102 Mod_LoadVertexes (&header->lumps[LUMP_VERTEXES]);
1103 Mod_LoadEdges (&header->lumps[LUMP_EDGES]);
1104 Mod_LoadSurfedges (&header->lumps[LUMP_SURFEDGES]);
1105 Mod_LoadTextures (&header->lumps[LUMP_TEXTURES]);
1106 Mod_LoadLighting (&header->lumps[LUMP_LIGHTING]);
1107 Mod_LoadPlanes (&header->lumps[LUMP_PLANES]);
1108 Mod_LoadTexinfo (&header->lumps[LUMP_TEXINFO]);
1109 Mod_LoadFaces (&header->lumps[LUMP_FACES]);
1110 Mod_LoadMarksurfaces (&header->lumps[LUMP_MARKSURFACES]);
1111 Mod_LoadVisibility (&header->lumps[LUMP_VISIBILITY]);
1112 Mod_LoadLeafs (&header->lumps[LUMP_LEAFS]);
1113 Mod_LoadNodes (&header->lumps[LUMP_NODES]);
1114 Mod_LoadClipnodes (&header->lumps[LUMP_CLIPNODES]);
1115 // Mod_LoadEntities (&header->lumps[LUMP_ENTITIES]);
1116 Mod_LoadSubmodels (&header->lumps[LUMP_MODELS]);
1120 mod->numframes = 2; // regular and alternate animation
1123 // set up the submodels (FIXME: this is confusing)
1125 for (i=0 ; i<mod->numsubmodels ; i++)
1127 bm = &mod->submodels[i];
1129 mod->hulls[0].firstclipnode = bm->headnode[0];
1130 for (j=1 ; j<MAX_MAP_HULLS ; j++)
1132 mod->hulls[j].firstclipnode = bm->headnode[j];
1133 mod->hulls[j].lastclipnode = mod->numclipnodes-1;
1136 mod->firstmodelsurface = bm->firstface;
1137 mod->nummodelsurfaces = bm->numfaces;
1139 VectorCopy (bm->maxs, mod->maxs);
1140 VectorCopy (bm->mins, mod->mins);
1142 mod->radius = RadiusFromBounds (mod->mins, mod->maxs);
1144 mod->numleafs = bm->visleafs;
1146 if (isworldmodel && i < (mod->numsubmodels-1)) // LordHavoc: only register submodels if it is the world (prevents bsp models from replacing world submodels)
1147 { // duplicate the basic information
1150 sprintf (name, "*%i", i+1);
1151 loadmodel = Mod_FindName (name);
1153 strcpy (loadmodel->name, name);