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];
117 loadmodel->textures = NULL;
121 m = (dmiptexlump_t *)(mod_base + l->fileofs);
123 m->nummiptex = LittleLong (m->nummiptex);
125 loadmodel->numtextures = m->nummiptex;
126 loadmodel->textures = Hunk_AllocName (m->nummiptex * sizeof(*loadmodel->textures) , loadname);
128 for (i=0 ; i<m->nummiptex ; i++)
130 m->dataofs[i] = LittleLong(m->dataofs[i]);
131 if (m->dataofs[i] == -1)
133 mt = (miptex_t *)((byte *)m + m->dataofs[i]);
134 mt->width = LittleLong (mt->width);
135 mt->height = LittleLong (mt->height);
136 for (j=0 ; j<MIPLEVELS ; j++)
137 mt->offsets[j] = LittleLong (mt->offsets[j]);
139 if ( (mt->width & 15) || (mt->height & 15) )
140 Host_Error ("Texture %s is not 16 aligned", mt->name);
141 // LordHavoc: rewriting the map texture loader for GLQuake
142 tx = Hunk_AllocName (sizeof(texture_t), loadname );
143 loadmodel->textures[i] = tx;
145 // LordHavoc: force all names to lowercase and make sure they are terminated while copying
146 for (j = 0;mt->name[j] && j < 15;j++)
148 if (mt->name[j] >= 'A' && mt->name[j] <= 'Z')
149 tx->name[j] = mt->name[j] + ('a' - 'A');
151 tx->name[j] = mt->name[j];
156 tx->width = mt->width;
157 tx->height = mt->height;
158 for (j=0 ; j<MIPLEVELS ; j++)
164 data = loadimagepixels(tx->name, FALSE, 0, 0); //tx->width, tx->height);
165 if (!data) // no external texture found
170 if (!hlbsp && mt->offsets[0]) // texture included
172 data = (byte *)((int) mt + mt->offsets[0]);
173 if (r_fullbrights.value && tx->name[0] != '*')
175 for (j = 0;j < tx->width*tx->height;j++)
176 if (data[j] >= 224) // fullbright
183 else // no texture, and no external replacement texture was found
185 tx->width = tx->height = 16;
186 data = (byte *)((int) r_notexture_mip + r_notexture_mip->offsets[0]);
191 tx->width = image_width;
192 tx->height = image_height;
194 if (!hlbsp && !strncmp(tx->name,"sky",3) && tx->width == 256 && tx->height == 128) // LordHavoc: HL sky textures are entirely unrelated
196 tx->transparent = FALSE;
197 R_InitSky (data, bytesperpixel);
201 tx->transparent = transparent;
206 data2 = malloc(tx->width*tx->height);
207 for (j = 0;j < tx->width*tx->height;j++)
208 data2[j] = data[j] >= 224 ? 0 : data[j]; // no fullbrights
209 tx->gl_texturenum = GL_LoadTexture (tx->name, tx->width, tx->height, data2, true, transparent, 1);
210 strcpy(name, tx->name);
211 strcat(name, "_glow");
212 for (j = 0;j < tx->width*tx->height;j++)
213 data2[j] = data[j] >= 224 ? data[j] : 0; // only fullbrights
214 tx->gl_glowtexturenum = GL_LoadTexture (name, tx->width, tx->height, data2, true, transparent, 1);
219 tx->gl_texturenum = GL_LoadTexture (tx->name, tx->width, tx->height, data, true, transparent, bytesperpixel);
220 tx->gl_glowtexturenum = 0;
228 // sequence the animations
230 for (i=0 ; i<m->nummiptex ; i++)
232 tx = loadmodel->textures[i];
233 if (!tx || tx->name[0] != '+')
236 continue; // allready sequenced
238 // find the number of frames in the animation
239 memset (anims, 0, sizeof(anims));
240 memset (altanims, 0, sizeof(altanims));
244 if (max >= 'a' && max <= 'z')
246 if (max >= '0' && max <= '9')
253 else if (max >= 'A' && max <= 'J')
257 altanims[altmax] = tx;
261 Host_Error ("Bad animating texture %s", tx->name);
263 for (j=i+1 ; j<m->nummiptex ; j++)
265 tx2 = loadmodel->textures[j];
266 if (!tx2 || tx2->name[0] != '+')
268 if (strcmp (tx2->name+2, tx->name+2))
272 if (num >= 'a' && num <= 'z')
274 if (num >= '0' && num <= '9')
281 else if (num >= 'A' && num <= 'J')
289 Host_Error ("Bad animating texture %s", tx->name);
293 // link them all together
294 for (j=0 ; j<max ; j++)
298 Host_Error ("Missing frame %i of %s",j, tx->name);
299 tx2->anim_total = max * ANIM_CYCLE;
300 tx2->anim_min = j * ANIM_CYCLE;
301 tx2->anim_max = (j+1) * ANIM_CYCLE;
302 tx2->anim_next = anims[ (j+1)%max ];
304 tx2->alternate_anims = altanims[0];
306 for (j=0 ; j<altmax ; j++)
310 Host_Error ("Missing frame %i of %s",j, tx->name);
311 tx2->anim_total = altmax * ANIM_CYCLE;
312 tx2->anim_min = j * ANIM_CYCLE;
313 tx2->anim_max = (j+1) * ANIM_CYCLE;
314 tx2->anim_next = altanims[ (j+1)%altmax ];
316 tx2->alternate_anims = anims[0];
326 void Mod_LoadLighting (lump_t *l)
329 byte *in, *out, *data;
331 char litfilename[1024];
332 loadmodel->lightdata = NULL;
333 if (hlbsp) // LordHavoc: load the colored lighting data straight
335 loadmodel->lightdata = Hunk_AllocName ( l->filelen, loadname);
336 memcpy (loadmodel->lightdata, mod_base + l->fileofs, l->filelen);
338 else // LordHavoc: bsp version 29 (normal white lighting)
340 // LordHavoc: hope is not lost yet, check for a .lit file to load
341 strcpy(litfilename, loadmodel->name);
342 COM_StripExtension(litfilename, litfilename);
343 strcat(litfilename, ".lit");
344 data = (byte*) COM_LoadHunkFile (litfilename, false);
347 if (data[0] == 'Q' && data[1] == 'L' && data[2] == 'I' && data[3] == 'T')
349 i = LittleLong(((int *)data)[1]);
352 Con_DPrintf("%s loaded", litfilename);
353 loadmodel->lightdata = data + 8;
357 Con_Printf("Unknown .lit file version (%d)\n", i);
360 Con_Printf("Corrupt .lit file (old version?), ignoring\n");
362 // LordHavoc: oh well, expand the white lighting data
365 loadmodel->lightdata = Hunk_AllocName ( l->filelen*3, litfilename);
366 in = loadmodel->lightdata + l->filelen*2; // place the file at the end, so it will not be overwritten until the very last write
367 out = loadmodel->lightdata;
368 memcpy (in, mod_base + l->fileofs, l->filelen);
369 for (i = 0;i < l->filelen;i++)
385 void Mod_LoadVisibility (lump_t *l)
389 loadmodel->visdata = NULL;
392 loadmodel->visdata = Hunk_AllocName ( l->filelen, loadname);
393 memcpy (loadmodel->visdata, mod_base + l->fileofs, l->filelen);
396 void CL_ParseEntityLump(char *entdata);
398 extern qboolean isworldmodel;
405 void Mod_LoadEntities (lump_t *l)
409 loadmodel->entities = NULL;
412 loadmodel->entities = Hunk_AllocName ( l->filelen, loadname);
413 memcpy (loadmodel->entities, mod_base + l->fileofs, l->filelen);
416 CL_ParseEntityLump(loadmodel->entities);
425 void Mod_LoadVertexes (lump_t *l)
431 in = (void *)(mod_base + l->fileofs);
432 if (l->filelen % sizeof(*in))
433 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
434 count = l->filelen / sizeof(*in);
435 out = Hunk_AllocName ( count*sizeof(*out), loadname);
437 loadmodel->vertexes = out;
438 loadmodel->numvertexes = count;
440 for ( i=0 ; i<count ; i++, in++, out++)
442 out->position[0] = LittleFloat (in->point[0]);
443 out->position[1] = LittleFloat (in->point[1]);
444 out->position[2] = LittleFloat (in->point[2]);
453 void Mod_LoadSubmodels (lump_t *l)
459 in = (void *)(mod_base + l->fileofs);
460 if (l->filelen % sizeof(*in))
461 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
462 count = l->filelen / sizeof(*in);
463 out = Hunk_AllocName ( count*sizeof(*out), loadname);
465 loadmodel->submodels = out;
466 loadmodel->numsubmodels = count;
468 for ( i=0 ; i<count ; i++, in++, out++)
470 for (j=0 ; j<3 ; j++)
471 { // spread the mins / maxs by a pixel
472 out->mins[j] = LittleFloat (in->mins[j]) - 1;
473 out->maxs[j] = LittleFloat (in->maxs[j]) + 1;
474 out->origin[j] = LittleFloat (in->origin[j]);
476 for (j=0 ; j<MAX_MAP_HULLS ; j++)
477 out->headnode[j] = LittleLong (in->headnode[j]);
478 out->visleafs = LittleLong (in->visleafs);
479 out->firstface = LittleLong (in->firstface);
480 out->numfaces = LittleLong (in->numfaces);
489 void Mod_LoadEdges (lump_t *l)
495 in = (void *)(mod_base + l->fileofs);
496 if (l->filelen % sizeof(*in))
497 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
498 count = l->filelen / sizeof(*in);
499 out = Hunk_AllocName ( (count + 1) * sizeof(*out), loadname);
501 loadmodel->edges = out;
502 loadmodel->numedges = count;
504 for ( i=0 ; i<count ; i++, in++, out++)
506 out->v[0] = (unsigned short)LittleShort(in->v[0]);
507 out->v[1] = (unsigned short)LittleShort(in->v[1]);
516 void Mod_LoadTexinfo (lump_t *l)
524 in = (void *)(mod_base + l->fileofs);
525 if (l->filelen % sizeof(*in))
526 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
527 count = l->filelen / sizeof(*in);
528 out = Hunk_AllocName ( count*sizeof(*out), loadname);
530 loadmodel->texinfo = out;
531 loadmodel->numtexinfo = count;
533 for ( i=0 ; i<count ; i++, in++, out++)
535 for (j=0 ; j<8 ; j++)
536 out->vecs[0][j] = LittleFloat (in->vecs[0][j]);
537 len1 = Length (out->vecs[0]);
538 len2 = Length (out->vecs[1]);
539 len1 = (len1 + len2)/2;
542 else if (len1 < 0.49)
544 else if (len1 < 0.99)
549 if (len1 + len2 < 0.001)
550 out->mipadjust = 1; // don't crash
552 out->mipadjust = 1 / floor( (len1+len2)/2 + 0.1 );
555 miptex = LittleLong (in->miptex);
556 out->flags = LittleLong (in->flags);
558 if (!loadmodel->textures)
560 out->texture = r_notexture_mip; // checkerboard texture
562 out->texture->transparent = FALSE;
566 if (miptex >= loadmodel->numtextures)
567 Host_Error ("miptex >= loadmodel->numtextures");
568 out->texture = loadmodel->textures[miptex];
571 out->texture = r_notexture_mip; // texture not found
573 out->texture->transparent = FALSE;
583 Fills in s->texturemins[] and s->extents[]
586 void CalcSurfaceExtents (msurface_t *s)
588 float mins[2], maxs[2], val;
592 int bmins[2], bmaxs[2];
594 mins[0] = mins[1] = 999999;
595 maxs[0] = maxs[1] = -99999;
599 for (i=0 ; i<s->numedges ; i++)
601 e = loadmodel->surfedges[s->firstedge+i];
603 v = &loadmodel->vertexes[loadmodel->edges[e].v[0]];
605 v = &loadmodel->vertexes[loadmodel->edges[-e].v[1]];
607 for (j=0 ; j<2 ; j++)
609 val = v->position[0] * tex->vecs[j][0] +
610 v->position[1] * tex->vecs[j][1] +
611 v->position[2] * tex->vecs[j][2] +
620 for (i=0 ; i<2 ; i++)
622 bmins[i] = floor(mins[i]/16);
623 bmaxs[i] = ceil(maxs[i]/16);
625 s->texturemins[i] = bmins[i] * 16;
626 s->extents[i] = (bmaxs[i] - bmins[i]) * 16;
627 if ( !(tex->flags & TEX_SPECIAL) && s->extents[i] > 512 /* 256 */ )
628 Host_Error ("Bad surface extents");
632 void GL_SubdivideSurface (msurface_t *fa);
634 extern char skyname[];
641 void Mod_LoadFaces (lump_t *l)
645 int i, count, surfnum;
648 in = (void *)(mod_base + l->fileofs);
649 if (l->filelen % sizeof(*in))
650 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
651 count = l->filelen / sizeof(*in);
652 out = Hunk_AllocName ( count*sizeof(*out), loadname);
654 loadmodel->surfaces = out;
655 loadmodel->numsurfaces = count;
657 for ( surfnum=0 ; surfnum<count ; surfnum++, in++, out++)
659 out->firstedge = LittleLong(in->firstedge);
660 out->numedges = LittleShort(in->numedges);
663 planenum = LittleShort(in->planenum);
664 side = LittleShort(in->side);
666 out->flags |= SURF_PLANEBACK;
668 out->plane = loadmodel->planes + planenum;
670 out->texinfo = loadmodel->texinfo + LittleShort (in->texinfo);
672 CalcSurfaceExtents (out);
676 for (i=0 ; i<MAXLIGHTMAPS ; i++)
677 out->styles[i] = in->styles[i];
678 i = LittleLong(in->lightofs);
681 else if (hlbsp) // LordHavoc: HalfLife map (bsp version 30)
682 out->samples = loadmodel->lightdata + i;
683 else // LordHavoc: white lighting (bsp version 29)
684 out->samples = loadmodel->lightdata + (i * 3);
686 // set the drawing flags flag
688 // if (!strncmp(out->texinfo->texture->name,"sky",3)) // sky
689 // LordHavoc: faster check
690 if ((out->texinfo->texture->name[0] == 's' || out->texinfo->texture->name[0] == 'S')
691 && (out->texinfo->texture->name[1] == 'k' || out->texinfo->texture->name[1] == 'K')
692 && (out->texinfo->texture->name[2] == 'y' || out->texinfo->texture->name[2] == 'Y'))
694 // LordHavoc: for consistency reasons, mark sky as fullbright and solid as well
695 out->flags |= (SURF_DRAWSKY | SURF_DRAWTILED | SURF_DRAWFULLBRIGHT | SURF_DRAWNOALPHA);
696 GL_SubdivideSurface (out); // cut up polygon for warps
700 // if (!strncmp(out->texinfo->texture->name,"*",1)) // turbulent
701 if (out->texinfo->texture->name[0] == '*') // LordHavoc: faster check
703 out->flags |= (SURF_DRAWTURB | SURF_DRAWTILED);
704 // LordHavoc: some turbulent textures should be fullbright and solid
705 if (!strncmp(out->texinfo->texture->name,"*lava",5)
706 || !strncmp(out->texinfo->texture->name,"*teleport",9)
707 || !strncmp(out->texinfo->texture->name,"*rift",5)) // Scourge of Armagon texture
708 out->flags |= (SURF_DRAWFULLBRIGHT | SURF_DRAWNOALPHA);
709 for (i=0 ; i<2 ; i++)
711 out->extents[i] = 16384;
712 out->texturemins[i] = -8192;
714 GL_SubdivideSurface (out); // cut up polygon for warps
727 void Mod_SetParent (mnode_t *node, mnode_t *parent)
729 node->parent = parent;
730 if (node->contents < 0)
732 Mod_SetParent (node->children[0], node);
733 Mod_SetParent (node->children[1], node);
741 void Mod_LoadNodes (lump_t *l)
747 in = (void *)(mod_base + l->fileofs);
748 if (l->filelen % sizeof(*in))
749 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
750 count = l->filelen / sizeof(*in);
751 out = Hunk_AllocName ( count*sizeof(*out), loadname);
753 loadmodel->nodes = out;
754 loadmodel->numnodes = count;
756 for ( i=0 ; i<count ; i++, in++, out++)
758 for (j=0 ; j<3 ; j++)
760 out->minmaxs[j] = LittleShort (in->mins[j]);
761 out->minmaxs[3+j] = LittleShort (in->maxs[j]);
764 p = LittleLong(in->planenum);
765 out->plane = loadmodel->planes + p;
767 out->firstsurface = LittleShort (in->firstface);
768 out->numsurfaces = LittleShort (in->numfaces);
770 for (j=0 ; j<2 ; j++)
772 p = LittleShort (in->children[j]);
774 out->children[j] = loadmodel->nodes + p;
776 out->children[j] = (mnode_t *)(loadmodel->leafs + (-1 - p));
780 Mod_SetParent (loadmodel->nodes, NULL); // sets nodes and leafs
788 void Mod_LoadLeafs (lump_t *l)
794 in = (void *)(mod_base + l->fileofs);
795 if (l->filelen % sizeof(*in))
796 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
797 count = l->filelen / sizeof(*in);
798 out = Hunk_AllocName ( count*sizeof(*out), loadname);
800 loadmodel->leafs = out;
801 loadmodel->numleafs = count;
803 for ( i=0 ; i<count ; i++, in++, out++)
805 for (j=0 ; j<3 ; j++)
807 out->minmaxs[j] = LittleShort (in->mins[j]);
808 out->minmaxs[3+j] = LittleShort (in->maxs[j]);
811 p = LittleLong(in->contents);
814 out->firstmarksurface = loadmodel->marksurfaces +
815 LittleShort(in->firstmarksurface);
816 out->nummarksurfaces = LittleShort(in->nummarksurfaces);
818 p = LittleLong(in->visofs);
820 out->compressed_vis = NULL;
822 out->compressed_vis = loadmodel->visdata + p;
825 for (j=0 ; j<4 ; j++)
826 out->ambient_sound_level[j] = in->ambient_level[j];
828 // gl underwater warp
829 // LordHavoc: disabled underwater warping
831 if (out->contents != CONTENTS_EMPTY)
833 for (j=0 ; j<out->nummarksurfaces ; j++)
834 out->firstmarksurface[j]->flags |= SURF_UNDERWATER;
845 void Mod_LoadClipnodes (lump_t *l)
847 dclipnode_t *in, *out;
851 in = (void *)(mod_base + l->fileofs);
852 if (l->filelen % sizeof(*in))
853 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
854 count = l->filelen / sizeof(*in);
855 out = Hunk_AllocName ( count*sizeof(*out), loadname);
857 loadmodel->clipnodes = out;
858 loadmodel->numclipnodes = count;
862 hull = &loadmodel->hulls[1];
863 hull->clipnodes = out;
864 hull->firstclipnode = 0;
865 hull->lastclipnode = count-1;
866 hull->planes = loadmodel->planes;
867 hull->clip_mins[0] = -16;
868 hull->clip_mins[1] = -16;
869 hull->clip_mins[2] = -36;
870 hull->clip_maxs[0] = 16;
871 hull->clip_maxs[1] = 16;
872 hull->clip_maxs[2] = 36;
874 hull = &loadmodel->hulls[2];
875 hull->clipnodes = out;
876 hull->firstclipnode = 0;
877 hull->lastclipnode = count-1;
878 hull->planes = loadmodel->planes;
879 hull->clip_mins[0] = -32;
880 hull->clip_mins[1] = -32;
881 hull->clip_mins[2] = -32;
882 hull->clip_maxs[0] = 32;
883 hull->clip_maxs[1] = 32;
884 hull->clip_maxs[2] = 32;
886 hull = &loadmodel->hulls[3];
887 hull->clipnodes = out;
888 hull->firstclipnode = 0;
889 hull->lastclipnode = count-1;
890 hull->planes = loadmodel->planes;
891 hull->clip_mins[0] = -16;
892 hull->clip_mins[1] = -16;
893 hull->clip_mins[2] = -18;
894 hull->clip_maxs[0] = 16;
895 hull->clip_maxs[1] = 16;
896 hull->clip_maxs[2] = 18;
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] = -24;
908 hull->clip_maxs[0] = 16;
909 hull->clip_maxs[1] = 16;
910 hull->clip_maxs[2] = 32;
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] = -24;
920 hull->clip_maxs[0] = 32;
921 hull->clip_maxs[1] = 32;
922 hull->clip_maxs[2] = 64;
925 for (i=0 ; i<count ; i++, out++, in++)
927 out->planenum = LittleLong(in->planenum);
928 out->children[0] = LittleShort(in->children[0]);
929 out->children[1] = LittleShort(in->children[1]);
930 if (out->children[0] >= count || out->children[1] >= count)
931 Host_Error("Corrupt clipping hull (out of range child)\n");
939 Duplicate the drawing hull structure as a clipping hull
942 void Mod_MakeHull0 (void)
949 hull = &loadmodel->hulls[0];
951 in = loadmodel->nodes;
952 count = loadmodel->numnodes;
953 out = Hunk_AllocName ( count*sizeof(*out), loadname);
955 hull->clipnodes = out;
956 hull->firstclipnode = 0;
957 hull->lastclipnode = count-1;
958 hull->planes = loadmodel->planes;
960 for (i=0 ; i<count ; i++, out++, in++)
962 out->planenum = in->plane - loadmodel->planes;
963 for (j=0 ; j<2 ; j++)
965 child = in->children[j];
966 if (child->contents < 0)
967 out->children[j] = child->contents;
969 out->children[j] = child - loadmodel->nodes;
979 void Mod_LoadMarksurfaces (lump_t *l)
985 in = (void *)(mod_base + l->fileofs);
986 if (l->filelen % sizeof(*in))
987 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
988 count = l->filelen / sizeof(*in);
989 out = Hunk_AllocName ( count*sizeof(*out), loadname);
991 loadmodel->marksurfaces = out;
992 loadmodel->nummarksurfaces = count;
994 for ( i=0 ; i<count ; i++)
996 j = LittleShort(in[i]);
997 if (j >= loadmodel->numsurfaces)
998 Host_Error ("Mod_ParseMarksurfaces: bad surface number");
999 out[i] = loadmodel->surfaces + j;
1008 void Mod_LoadSurfedges (lump_t *l)
1013 in = (void *)(mod_base + l->fileofs);
1014 if (l->filelen % sizeof(*in))
1015 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
1016 count = l->filelen / sizeof(*in);
1017 out = Hunk_AllocName ( count*sizeof(*out), loadname);
1019 loadmodel->surfedges = out;
1020 loadmodel->numsurfedges = count;
1022 for ( i=0 ; i<count ; i++)
1023 out[i] = LittleLong (in[i]);
1032 void Mod_LoadPlanes (lump_t *l)
1040 in = (void *)(mod_base + l->fileofs);
1041 if (l->filelen % sizeof(*in))
1042 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
1043 count = l->filelen / sizeof(*in);
1044 out = Hunk_AllocName ( count*2*sizeof(*out), loadname);
1046 loadmodel->planes = out;
1047 loadmodel->numplanes = count;
1049 for ( i=0 ; i<count ; i++, in++, out++)
1052 for (j=0 ; j<3 ; j++)
1054 out->normal[j] = LittleFloat (in->normal[j]);
1055 // if (out->normal[j] < 0)
1059 out->dist = LittleFloat (in->dist);
1060 out->type = LittleLong (in->type);
1061 // out->signbits = bits;
1062 BoxOnPlaneSideClassify(out);
1071 void Mod_LoadBrushModel (model_t *mod, void *buffer)
1077 loadmodel->type = mod_brush;
1079 header = (dheader_t *)buffer;
1081 i = LittleLong (header->version);
1082 if (i != BSPVERSION && i != 30)
1083 Host_Error ("Mod_LoadBrushModel: %s has wrong version number (%i should be %i or 30 (HalfLife))", mod->name, i, BSPVERSION);
1085 halflifebsp.value = hlbsp;
1087 // swap all the lumps
1088 mod_base = (byte *)header;
1090 for (i=0 ; i<sizeof(dheader_t)/4 ; i++)
1091 ((int *)header)[i] = LittleLong ( ((int *)header)[i]);
1095 // LordHavoc: had to move entity loading above everything to allow parsing various settings from worldspawn
1096 Mod_LoadEntities (&header->lumps[LUMP_ENTITIES]);
1098 Mod_LoadVertexes (&header->lumps[LUMP_VERTEXES]);
1099 Mod_LoadEdges (&header->lumps[LUMP_EDGES]);
1100 Mod_LoadSurfedges (&header->lumps[LUMP_SURFEDGES]);
1101 Mod_LoadTextures (&header->lumps[LUMP_TEXTURES]);
1102 Mod_LoadLighting (&header->lumps[LUMP_LIGHTING]);
1103 Mod_LoadPlanes (&header->lumps[LUMP_PLANES]);
1104 Mod_LoadTexinfo (&header->lumps[LUMP_TEXINFO]);
1105 Mod_LoadFaces (&header->lumps[LUMP_FACES]);
1106 Mod_LoadMarksurfaces (&header->lumps[LUMP_MARKSURFACES]);
1107 Mod_LoadVisibility (&header->lumps[LUMP_VISIBILITY]);
1108 Mod_LoadLeafs (&header->lumps[LUMP_LEAFS]);
1109 Mod_LoadNodes (&header->lumps[LUMP_NODES]);
1110 Mod_LoadClipnodes (&header->lumps[LUMP_CLIPNODES]);
1111 // Mod_LoadEntities (&header->lumps[LUMP_ENTITIES]);
1112 Mod_LoadSubmodels (&header->lumps[LUMP_MODELS]);
1116 mod->numframes = 2; // regular and alternate animation
1119 // set up the submodels (FIXME: this is confusing)
1121 for (i=0 ; i<mod->numsubmodels ; i++)
1123 bm = &mod->submodels[i];
1125 mod->hulls[0].firstclipnode = bm->headnode[0];
1126 for (j=1 ; j<MAX_MAP_HULLS ; j++)
1128 mod->hulls[j].firstclipnode = bm->headnode[j];
1129 mod->hulls[j].lastclipnode = mod->numclipnodes-1;
1132 mod->firstmodelsurface = bm->firstface;
1133 mod->nummodelsurfaces = bm->numfaces;
1135 VectorCopy (bm->maxs, mod->maxs);
1136 VectorCopy (bm->mins, mod->mins);
1138 mod->radius = RadiusFromBounds (mod->mins, mod->maxs);
1140 mod->numleafs = bm->visleafs;
1142 if (isworldmodel && i < (mod->numsubmodels-1)) // LordHavoc: only register submodels if it is the world (prevents bsp models from replacing world submodels)
1143 { // duplicate the basic information
1146 sprintf (name, "*%i", i+1);
1147 loadmodel = Mod_FindName (name);
1149 strcpy (loadmodel->name, name);