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 (j=0 ; j<8 ; j++)
539 out->vecs[0][j] = LittleFloat (in->vecs[0][j]);
540 len1 = Length (out->vecs[0]);
541 len2 = Length (out->vecs[1]);
542 len1 = (len1 + len2)/2;
545 else if (len1 < 0.49)
547 else if (len1 < 0.99)
552 if (len1 + len2 < 0.001)
553 out->mipadjust = 1; // don't crash
555 out->mipadjust = 1 / floor( (len1+len2)/2 + 0.1 );
558 miptex = LittleLong (in->miptex);
559 out->flags = LittleLong (in->flags);
561 if (!loadmodel->textures)
563 out->texture = r_notexture_mip; // checkerboard texture
565 out->texture->transparent = FALSE;
569 if (miptex >= loadmodel->numtextures)
570 Host_Error ("miptex >= loadmodel->numtextures");
571 out->texture = loadmodel->textures[miptex];
574 out->texture = r_notexture_mip; // texture not found
576 out->texture->transparent = FALSE;
586 Fills in s->texturemins[] and s->extents[]
589 void CalcSurfaceExtents (msurface_t *s)
591 float mins[2], maxs[2], val;
595 int bmins[2], bmaxs[2];
597 mins[0] = mins[1] = 999999;
598 maxs[0] = maxs[1] = -99999;
602 for (i=0 ; i<s->numedges ; i++)
604 e = loadmodel->surfedges[s->firstedge+i];
606 v = &loadmodel->vertexes[loadmodel->edges[e].v[0]];
608 v = &loadmodel->vertexes[loadmodel->edges[-e].v[1]];
610 for (j=0 ; j<2 ; j++)
612 val = v->position[0] * tex->vecs[j][0] +
613 v->position[1] * tex->vecs[j][1] +
614 v->position[2] * tex->vecs[j][2] +
623 for (i=0 ; i<2 ; i++)
625 bmins[i] = floor(mins[i]/16);
626 bmaxs[i] = ceil(maxs[i]/16);
628 s->texturemins[i] = bmins[i] * 16;
629 s->extents[i] = (bmaxs[i] - bmins[i]) * 16;
630 if ( !(tex->flags & TEX_SPECIAL) && s->extents[i] > 512 /* 256 */ )
631 Host_Error ("Bad surface extents");
635 void GL_SubdivideSurface (msurface_t *fa);
637 extern char skyname[];
644 void Mod_LoadFaces (lump_t *l)
648 int i, count, surfnum;
651 in = (void *)(mod_base + l->fileofs);
652 if (l->filelen % sizeof(*in))
653 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
654 count = l->filelen / sizeof(*in);
655 out = Hunk_AllocName ( count*sizeof(*out), loadname);
657 loadmodel->surfaces = out;
658 loadmodel->numsurfaces = count;
660 for ( surfnum=0 ; surfnum<count ; surfnum++, in++, out++)
662 out->firstedge = LittleLong(in->firstedge);
663 out->numedges = LittleShort(in->numedges);
666 planenum = LittleShort(in->planenum);
667 side = LittleShort(in->side);
669 out->flags |= SURF_PLANEBACK;
671 out->plane = loadmodel->planes + planenum;
673 out->texinfo = loadmodel->texinfo + LittleShort (in->texinfo);
675 CalcSurfaceExtents (out);
679 for (i=0 ; i<MAXLIGHTMAPS ; i++)
680 out->styles[i] = in->styles[i];
681 i = LittleLong(in->lightofs);
684 else if (hlbsp) // LordHavoc: HalfLife map (bsp version 30)
685 out->samples = loadmodel->lightdata + i;
686 else // LordHavoc: white lighting (bsp version 29)
687 out->samples = loadmodel->lightdata + (i * 3);
689 // set the drawing flags flag
691 // if (!strncmp(out->texinfo->texture->name,"sky",3)) // sky
692 // LordHavoc: faster check
693 if ((out->texinfo->texture->name[0] == 's' || out->texinfo->texture->name[0] == 'S')
694 && (out->texinfo->texture->name[1] == 'k' || out->texinfo->texture->name[1] == 'K')
695 && (out->texinfo->texture->name[2] == 'y' || out->texinfo->texture->name[2] == 'Y'))
697 // LordHavoc: for consistency reasons, mark sky as fullbright and solid as well
698 out->flags |= (SURF_DRAWSKY | SURF_DRAWTILED | SURF_DRAWFULLBRIGHT | SURF_DRAWNOALPHA);
699 GL_SubdivideSurface (out); // cut up polygon for warps
703 // if (!strncmp(out->texinfo->texture->name,"*",1)) // turbulent
704 if (out->texinfo->texture->name[0] == '*') // LordHavoc: faster check
706 out->flags |= (SURF_DRAWTURB | SURF_DRAWTILED);
707 // LordHavoc: some turbulent textures should be fullbright and solid
708 if (!strncmp(out->texinfo->texture->name,"*lava",5)
709 || !strncmp(out->texinfo->texture->name,"*teleport",9)
710 || !strncmp(out->texinfo->texture->name,"*rift",5)) // Scourge of Armagon texture
711 out->flags |= (SURF_DRAWFULLBRIGHT | SURF_DRAWNOALPHA);
712 for (i=0 ; i<2 ; i++)
714 out->extents[i] = 16384;
715 out->texturemins[i] = -8192;
717 GL_SubdivideSurface (out); // cut up polygon for warps
730 void Mod_SetParent (mnode_t *node, mnode_t *parent)
732 node->parent = parent;
733 if (node->contents < 0)
735 Mod_SetParent (node->children[0], node);
736 Mod_SetParent (node->children[1], node);
744 void Mod_LoadNodes (lump_t *l)
750 in = (void *)(mod_base + l->fileofs);
751 if (l->filelen % sizeof(*in))
752 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
753 count = l->filelen / sizeof(*in);
754 out = Hunk_AllocName ( count*sizeof(*out), loadname);
756 loadmodel->nodes = out;
757 loadmodel->numnodes = count;
759 for ( i=0 ; i<count ; i++, in++, out++)
761 for (j=0 ; j<3 ; j++)
763 out->minmaxs[j] = LittleShort (in->mins[j]);
764 out->minmaxs[3+j] = LittleShort (in->maxs[j]);
767 p = LittleLong(in->planenum);
768 out->plane = loadmodel->planes + p;
770 out->firstsurface = LittleShort (in->firstface);
771 out->numsurfaces = LittleShort (in->numfaces);
773 for (j=0 ; j<2 ; j++)
775 p = LittleShort (in->children[j]);
777 out->children[j] = loadmodel->nodes + p;
779 out->children[j] = (mnode_t *)(loadmodel->leafs + (-1 - p));
783 Mod_SetParent (loadmodel->nodes, NULL); // sets nodes and leafs
791 void Mod_LoadLeafs (lump_t *l)
797 in = (void *)(mod_base + l->fileofs);
798 if (l->filelen % sizeof(*in))
799 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
800 count = l->filelen / sizeof(*in);
801 out = Hunk_AllocName ( count*sizeof(*out), loadname);
803 loadmodel->leafs = out;
804 loadmodel->numleafs = count;
806 for ( i=0 ; i<count ; i++, in++, out++)
808 for (j=0 ; j<3 ; j++)
810 out->minmaxs[j] = LittleShort (in->mins[j]);
811 out->minmaxs[3+j] = LittleShort (in->maxs[j]);
814 p = LittleLong(in->contents);
817 out->firstmarksurface = loadmodel->marksurfaces +
818 LittleShort(in->firstmarksurface);
819 out->nummarksurfaces = LittleShort(in->nummarksurfaces);
821 p = LittleLong(in->visofs);
823 out->compressed_vis = NULL;
825 out->compressed_vis = loadmodel->visdata + p;
828 for (j=0 ; j<4 ; j++)
829 out->ambient_sound_level[j] = in->ambient_level[j];
831 // gl underwater warp
832 // LordHavoc: disabled underwater warping
834 if (out->contents != CONTENTS_EMPTY)
836 for (j=0 ; j<out->nummarksurfaces ; j++)
837 out->firstmarksurface[j]->flags |= SURF_UNDERWATER;
848 void Mod_LoadClipnodes (lump_t *l)
850 dclipnode_t *in, *out;
854 in = (void *)(mod_base + l->fileofs);
855 if (l->filelen % sizeof(*in))
856 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
857 count = l->filelen / sizeof(*in);
858 out = Hunk_AllocName ( count*sizeof(*out), loadname);
860 loadmodel->clipnodes = out;
861 loadmodel->numclipnodes = count;
865 hull = &loadmodel->hulls[1];
866 hull->clipnodes = out;
867 hull->firstclipnode = 0;
868 hull->lastclipnode = count-1;
869 hull->planes = loadmodel->planes;
870 hull->clip_mins[0] = -16;
871 hull->clip_mins[1] = -16;
872 hull->clip_mins[2] = -36;
873 hull->clip_maxs[0] = 16;
874 hull->clip_maxs[1] = 16;
875 hull->clip_maxs[2] = 36;
877 hull = &loadmodel->hulls[2];
878 hull->clipnodes = out;
879 hull->firstclipnode = 0;
880 hull->lastclipnode = count-1;
881 hull->planes = loadmodel->planes;
882 hull->clip_mins[0] = -32;
883 hull->clip_mins[1] = -32;
884 hull->clip_mins[2] = -32;
885 hull->clip_maxs[0] = 32;
886 hull->clip_maxs[1] = 32;
887 hull->clip_maxs[2] = 32;
889 hull = &loadmodel->hulls[3];
890 hull->clipnodes = out;
891 hull->firstclipnode = 0;
892 hull->lastclipnode = count-1;
893 hull->planes = loadmodel->planes;
894 hull->clip_mins[0] = -16;
895 hull->clip_mins[1] = -16;
896 hull->clip_mins[2] = -18;
897 hull->clip_maxs[0] = 16;
898 hull->clip_maxs[1] = 16;
899 hull->clip_maxs[2] = 18;
903 hull = &loadmodel->hulls[1];
904 hull->clipnodes = out;
905 hull->firstclipnode = 0;
906 hull->lastclipnode = count-1;
907 hull->planes = loadmodel->planes;
908 hull->clip_mins[0] = -16;
909 hull->clip_mins[1] = -16;
910 hull->clip_mins[2] = -24;
911 hull->clip_maxs[0] = 16;
912 hull->clip_maxs[1] = 16;
913 hull->clip_maxs[2] = 32;
915 hull = &loadmodel->hulls[2];
916 hull->clipnodes = out;
917 hull->firstclipnode = 0;
918 hull->lastclipnode = count-1;
919 hull->planes = loadmodel->planes;
920 hull->clip_mins[0] = -32;
921 hull->clip_mins[1] = -32;
922 hull->clip_mins[2] = -24;
923 hull->clip_maxs[0] = 32;
924 hull->clip_maxs[1] = 32;
925 hull->clip_maxs[2] = 64;
928 for (i=0 ; i<count ; i++, out++, in++)
930 out->planenum = LittleLong(in->planenum);
931 out->children[0] = LittleShort(in->children[0]);
932 out->children[1] = LittleShort(in->children[1]);
933 if (out->children[0] >= count || out->children[1] >= count)
934 Host_Error("Corrupt clipping hull (out of range child)\n");
942 Duplicate the drawing hull structure as a clipping hull
945 void Mod_MakeHull0 (void)
952 hull = &loadmodel->hulls[0];
954 in = loadmodel->nodes;
955 count = loadmodel->numnodes;
956 out = Hunk_AllocName ( count*sizeof(*out), loadname);
958 hull->clipnodes = out;
959 hull->firstclipnode = 0;
960 hull->lastclipnode = count-1;
961 hull->planes = loadmodel->planes;
963 for (i=0 ; i<count ; i++, out++, in++)
965 out->planenum = in->plane - loadmodel->planes;
966 for (j=0 ; j<2 ; j++)
968 child = in->children[j];
969 if (child->contents < 0)
970 out->children[j] = child->contents;
972 out->children[j] = child - loadmodel->nodes;
982 void Mod_LoadMarksurfaces (lump_t *l)
988 in = (void *)(mod_base + l->fileofs);
989 if (l->filelen % sizeof(*in))
990 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
991 count = l->filelen / sizeof(*in);
992 out = Hunk_AllocName ( count*sizeof(*out), loadname);
994 loadmodel->marksurfaces = out;
995 loadmodel->nummarksurfaces = count;
997 for ( i=0 ; i<count ; i++)
999 j = LittleShort(in[i]);
1000 if (j >= loadmodel->numsurfaces)
1001 Host_Error ("Mod_ParseMarksurfaces: bad surface number");
1002 out[i] = loadmodel->surfaces + j;
1011 void Mod_LoadSurfedges (lump_t *l)
1016 in = (void *)(mod_base + l->fileofs);
1017 if (l->filelen % sizeof(*in))
1018 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
1019 count = l->filelen / sizeof(*in);
1020 out = Hunk_AllocName ( count*sizeof(*out), loadname);
1022 loadmodel->surfedges = out;
1023 loadmodel->numsurfedges = count;
1025 for ( i=0 ; i<count ; i++)
1026 out[i] = LittleLong (in[i]);
1035 void Mod_LoadPlanes (lump_t *l)
1043 in = (void *)(mod_base + l->fileofs);
1044 if (l->filelen % sizeof(*in))
1045 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
1046 count = l->filelen / sizeof(*in);
1047 out = Hunk_AllocName ( count*2*sizeof(*out), loadname);
1049 loadmodel->planes = out;
1050 loadmodel->numplanes = count;
1052 for ( i=0 ; i<count ; i++, in++, out++)
1055 for (j=0 ; j<3 ; j++)
1057 out->normal[j] = LittleFloat (in->normal[j]);
1058 // if (out->normal[j] < 0)
1062 out->dist = LittleFloat (in->dist);
1063 out->type = LittleLong (in->type);
1064 // out->signbits = bits;
1065 BoxOnPlaneSideClassify(out);
1074 void Mod_LoadBrushModel (model_t *mod, void *buffer)
1080 loadmodel->type = mod_brush;
1082 header = (dheader_t *)buffer;
1084 i = LittleLong (header->version);
1085 if (i != BSPVERSION && i != 30)
1086 Host_Error ("Mod_LoadBrushModel: %s has wrong version number (%i should be %i or 30 (HalfLife))", mod->name, i, BSPVERSION);
1088 halflifebsp.value = hlbsp;
1090 // swap all the lumps
1091 mod_base = (byte *)header;
1093 for (i=0 ; i<sizeof(dheader_t)/4 ; i++)
1094 ((int *)header)[i] = LittleLong ( ((int *)header)[i]);
1098 // LordHavoc: had to move entity loading above everything to allow parsing various settings from worldspawn
1099 Mod_LoadEntities (&header->lumps[LUMP_ENTITIES]);
1101 Mod_LoadVertexes (&header->lumps[LUMP_VERTEXES]);
1102 Mod_LoadEdges (&header->lumps[LUMP_EDGES]);
1103 Mod_LoadSurfedges (&header->lumps[LUMP_SURFEDGES]);
1104 Mod_LoadTextures (&header->lumps[LUMP_TEXTURES]);
1105 Mod_LoadLighting (&header->lumps[LUMP_LIGHTING]);
1106 Mod_LoadPlanes (&header->lumps[LUMP_PLANES]);
1107 Mod_LoadTexinfo (&header->lumps[LUMP_TEXINFO]);
1108 Mod_LoadFaces (&header->lumps[LUMP_FACES]);
1109 Mod_LoadMarksurfaces (&header->lumps[LUMP_MARKSURFACES]);
1110 Mod_LoadVisibility (&header->lumps[LUMP_VISIBILITY]);
1111 Mod_LoadLeafs (&header->lumps[LUMP_LEAFS]);
1112 Mod_LoadNodes (&header->lumps[LUMP_NODES]);
1113 Mod_LoadClipnodes (&header->lumps[LUMP_CLIPNODES]);
1114 // Mod_LoadEntities (&header->lumps[LUMP_ENTITIES]);
1115 Mod_LoadSubmodels (&header->lumps[LUMP_MODELS]);
1119 mod->numframes = 2; // regular and alternate animation
1122 // set up the submodels (FIXME: this is confusing)
1124 for (i=0 ; i<mod->numsubmodels ; i++)
1126 bm = &mod->submodels[i];
1128 mod->hulls[0].firstclipnode = bm->headnode[0];
1129 for (j=1 ; j<MAX_MAP_HULLS ; j++)
1131 mod->hulls[j].firstclipnode = bm->headnode[j];
1132 mod->hulls[j].lastclipnode = mod->numclipnodes-1;
1135 mod->firstmodelsurface = bm->firstface;
1136 mod->nummodelsurfaces = bm->numfaces;
1138 VectorCopy (bm->maxs, mod->maxs);
1139 VectorCopy (bm->mins, mod->mins);
1141 mod->radius = RadiusFromBounds (mod->mins, mod->maxs);
1143 mod->numleafs = bm->visleafs;
1145 if (isworldmodel && i < (mod->numsubmodels-1)) // LordHavoc: only register submodels if it is the world (prevents bsp models from replacing world submodels)
1146 { // duplicate the basic information
1149 sprintf (name, "*%i", i+1);
1150 loadmodel = Mod_FindName (name);
1152 strcpy (loadmodel->name, name);