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
172 if (mt->offsets[0]) // texture included
177 data = W_ConvertWAD3Texture(mt);
178 tx->width = image_width;
179 tx->height = image_height;
181 byte *in, *out, *pal;
187 in = (byte *)((int) mt + mt->offsets[0]);
188 data = out = qmalloc(mt->width * mt->height * 4);
189 pal = in + (((mt->width * mt->height) * 85) >> 6);
190 // palsize = pal[1] * 0x100 + pal[0];
191 // if (palsize >= 256)
194 for (d = 0;d < mt->width * mt->height;d++)
197 if (mt->name[0] == '{' && p == 255)
199 out[0] = out[1] = out[2] = out[3] = 0;
219 data = W_GetTexture(mt->name);
220 tx->width = image_width;
221 tx->height = image_height;
228 data = (byte *)((int) r_notexture_mip + r_notexture_mip->offsets[0]);
229 tx->width = tx->height = 16;
234 if (mt->offsets[0]) // texture included
239 data = (byte *)((int) mt + mt->offsets[0]);
240 tx->width = mt->width;
241 tx->height = mt->height;
242 if (r_fullbrights.value && tx->name[0] != '*')
244 for (j = 0;j < tx->width*tx->height;j++)
246 if (data[j] >= 224) // fullbright
254 else // no texture, and no external replacement texture was found
259 data = (byte *)((int) r_notexture_mip + r_notexture_mip->offsets[0]);
260 tx->width = tx->height = 16;
264 if (!hlbsp && !strncmp(tx->name,"sky",3) && tx->width == 256 && tx->height == 128) // LordHavoc: HL sky textures are entirely unrelated
266 tx->transparent = false;
267 R_InitSky (data, bytesperpixel);
275 tx->transparent = false;
276 data2 = qmalloc(tx->width*tx->height);
277 for (j = 0;j < tx->width*tx->height;j++)
278 data2[j] = data[j] >= 224 ? 0 : data[j]; // no fullbrights
279 tx->gl_texturenum = GL_LoadTexture (tx->name, tx->width, tx->height, data2, true, false, 1);
280 strcpy(name, tx->name);
281 strcat(name, "_glow");
282 for (j = 0;j < tx->width*tx->height;j++)
283 data2[j] = data[j] >= 224 ? data[j] : 0; // only fullbrights
284 tx->gl_glowtexturenum = GL_LoadTexture (name, tx->width, tx->height, data2, true, false, 1);
289 tx->transparent = transparent;
290 tx->gl_texturenum = GL_LoadTexture (tx->name, tx->width, tx->height, data, true, transparent, bytesperpixel);
291 tx->gl_glowtexturenum = 0;
299 // sequence the animations
301 for (i=0 ; i<m->nummiptex ; i++)
303 tx = loadmodel->textures[i];
304 if (!tx || tx->name[0] != '+')
307 continue; // allready sequenced
309 // find the number of frames in the animation
310 memset (anims, 0, sizeof(anims));
311 memset (altanims, 0, sizeof(altanims));
315 if (max >= 'a' && max <= 'z')
317 if (max >= '0' && max <= '9')
324 else if (max >= 'A' && max <= 'J')
328 altanims[altmax] = tx;
332 Host_Error ("Bad animating texture %s", tx->name);
334 for (j=i+1 ; j<m->nummiptex ; j++)
336 tx2 = loadmodel->textures[j];
337 if (!tx2 || tx2->name[0] != '+')
339 if (strcmp (tx2->name+2, tx->name+2))
343 if (num >= 'a' && num <= 'z')
345 if (num >= '0' && num <= '9')
352 else if (num >= 'A' && num <= 'J')
360 Host_Error ("Bad animating texture %s", tx->name);
364 // link them all together
365 for (j=0 ; j<max ; j++)
369 Host_Error ("Missing frame %i of %s",j, tx->name);
370 tx2->anim_total = max * ANIM_CYCLE;
371 tx2->anim_min = j * ANIM_CYCLE;
372 tx2->anim_max = (j+1) * ANIM_CYCLE;
373 tx2->anim_next = anims[ (j+1)%max ];
375 tx2->alternate_anims = altanims[0];
377 for (j=0 ; j<altmax ; j++)
381 Host_Error ("Missing frame %i of %s",j, tx->name);
382 tx2->anim_total = altmax * ANIM_CYCLE;
383 tx2->anim_min = j * ANIM_CYCLE;
384 tx2->anim_max = (j+1) * ANIM_CYCLE;
385 tx2->anim_next = altanims[ (j+1)%altmax ];
387 tx2->alternate_anims = anims[0];
397 void Mod_LoadLighting (lump_t *l)
400 byte *in, *out, *data;
402 char litfilename[1024];
403 loadmodel->lightdata = NULL;
404 if (hlbsp) // LordHavoc: load the colored lighting data straight
406 loadmodel->lightdata = Hunk_AllocName ( l->filelen, va("%s lightmaps", loadname));
407 memcpy (loadmodel->lightdata, mod_base + l->fileofs, l->filelen);
409 else // LordHavoc: bsp version 29 (normal white lighting)
411 // LordHavoc: hope is not lost yet, check for a .lit file to load
412 strcpy(litfilename, loadmodel->name);
413 COM_StripExtension(litfilename, litfilename);
414 strcat(litfilename, ".lit");
415 data = (byte*) COM_LoadHunkFile (litfilename, false);
418 if (data[0] == 'Q' && data[1] == 'L' && data[2] == 'I' && data[3] == 'T')
420 i = LittleLong(((int *)data)[1]);
423 Con_DPrintf("%s loaded", litfilename);
424 loadmodel->lightdata = data + 8;
428 Con_Printf("Unknown .lit file version (%d)\n", i);
431 Con_Printf("Corrupt .lit file (old version?), ignoring\n");
433 // LordHavoc: oh well, expand the white lighting data
436 loadmodel->lightdata = Hunk_AllocName ( l->filelen*3, va("%s lightmaps", loadname));
437 in = loadmodel->lightdata + l->filelen*2; // place the file at the end, so it will not be overwritten until the very last write
438 out = loadmodel->lightdata;
439 memcpy (in, mod_base + l->fileofs, l->filelen);
440 for (i = 0;i < l->filelen;i++)
456 void Mod_LoadVisibility (lump_t *l)
460 loadmodel->visdata = NULL;
463 loadmodel->visdata = Hunk_AllocName ( l->filelen, va("%s visdata", loadname));
464 memcpy (loadmodel->visdata, mod_base + l->fileofs, l->filelen);
467 void CL_ParseEntityLump(char *entdata);
469 extern qboolean isworldmodel;
476 void Mod_LoadEntities (lump_t *l)
480 loadmodel->entities = NULL;
483 loadmodel->entities = Hunk_AllocName ( l->filelen, va("%s entities", loadname));
484 memcpy (loadmodel->entities, mod_base + l->fileofs, l->filelen);
487 CL_ParseEntityLump(loadmodel->entities);
496 void Mod_LoadVertexes (lump_t *l)
502 in = (void *)(mod_base + l->fileofs);
503 if (l->filelen % sizeof(*in))
504 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
505 count = l->filelen / sizeof(*in);
506 out = Hunk_AllocName ( count*sizeof(*out), va("%s vertices", loadname));
508 loadmodel->vertexes = out;
509 loadmodel->numvertexes = count;
511 for ( i=0 ; i<count ; i++, in++, out++)
513 out->position[0] = LittleFloat (in->point[0]);
514 out->position[1] = LittleFloat (in->point[1]);
515 out->position[2] = LittleFloat (in->point[2]);
524 void Mod_LoadSubmodels (lump_t *l)
530 in = (void *)(mod_base + l->fileofs);
531 if (l->filelen % sizeof(*in))
532 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
533 count = l->filelen / sizeof(*in);
534 out = Hunk_AllocName ( count*sizeof(*out), va("%s submodels", loadname));
536 loadmodel->submodels = out;
537 loadmodel->numsubmodels = count;
539 for ( i=0 ; i<count ; i++, in++, out++)
541 for (j=0 ; j<3 ; j++)
542 { // spread the mins / maxs by a pixel
543 out->mins[j] = LittleFloat (in->mins[j]) - 1;
544 out->maxs[j] = LittleFloat (in->maxs[j]) + 1;
545 out->origin[j] = LittleFloat (in->origin[j]);
547 for (j=0 ; j<MAX_MAP_HULLS ; j++)
548 out->headnode[j] = LittleLong (in->headnode[j]);
549 out->visleafs = LittleLong (in->visleafs);
550 out->firstface = LittleLong (in->firstface);
551 out->numfaces = LittleLong (in->numfaces);
560 void Mod_LoadEdges (lump_t *l)
566 in = (void *)(mod_base + l->fileofs);
567 if (l->filelen % sizeof(*in))
568 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
569 count = l->filelen / sizeof(*in);
570 out = Hunk_AllocName ( (count + 1) * sizeof(*out), va("%s edges", loadname));
572 loadmodel->edges = out;
573 loadmodel->numedges = count;
575 for ( i=0 ; i<count ; i++, in++, out++)
577 out->v[0] = (unsigned short)LittleShort(in->v[0]);
578 out->v[1] = (unsigned short)LittleShort(in->v[1]);
587 void Mod_LoadTexinfo (lump_t *l)
595 in = (void *)(mod_base + l->fileofs);
596 if (l->filelen % sizeof(*in))
597 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
598 count = l->filelen / sizeof(*in);
599 out = Hunk_AllocName ( count*sizeof(*out), va("%s texinfo", loadname));
601 loadmodel->texinfo = out;
602 loadmodel->numtexinfo = count;
604 for ( i=0 ; i<count ; i++, in++, out++)
606 for (k=0 ; k<2 ; k++)
607 for (j=0 ; j<4 ; j++)
608 out->vecs[k][j] = LittleFloat (in->vecs[k][j]);
609 len1 = Length (out->vecs[0]);
610 len2 = Length (out->vecs[1]);
611 len1 = (len1 + len2)/2;
614 else if (len1 < 0.49)
616 else if (len1 < 0.99)
621 if (len1 + len2 < 0.001)
622 out->mipadjust = 1; // don't crash
624 out->mipadjust = 1 / floor( (len1+len2)/2 + 0.1 );
627 miptex = LittleLong (in->miptex);
628 out->flags = LittleLong (in->flags);
630 if (!loadmodel->textures)
632 out->texture = r_notexture_mip; // checkerboard texture
634 out->texture->transparent = false;
638 if (miptex >= loadmodel->numtextures)
639 Host_Error ("miptex >= loadmodel->numtextures");
640 out->texture = loadmodel->textures[miptex];
643 out->texture = r_notexture_mip; // texture not found
645 out->texture->transparent = false;
655 Fills in s->texturemins[] and s->extents[]
658 void CalcSurfaceExtents (msurface_t *s)
660 float mins[2], maxs[2], val;
664 int bmins[2], bmaxs[2];
666 mins[0] = mins[1] = 999999;
667 maxs[0] = maxs[1] = -99999;
671 for (i=0 ; i<s->numedges ; i++)
673 e = loadmodel->surfedges[s->firstedge+i];
675 v = &loadmodel->vertexes[loadmodel->edges[e].v[0]];
677 v = &loadmodel->vertexes[loadmodel->edges[-e].v[1]];
679 for (j=0 ; j<2 ; j++)
681 val = v->position[0] * tex->vecs[j][0] +
682 v->position[1] * tex->vecs[j][1] +
683 v->position[2] * tex->vecs[j][2] +
692 for (i=0 ; i<2 ; i++)
694 bmins[i] = floor(mins[i]/16);
695 bmaxs[i] = ceil(maxs[i]/16);
697 s->texturemins[i] = bmins[i] * 16;
698 s->extents[i] = (bmaxs[i] - bmins[i]) * 16;
699 if ( !(tex->flags & TEX_SPECIAL) && s->extents[i] > 512 /* 256 */ )
700 Host_Error ("Bad surface extents");
704 void GL_SubdivideSurface (msurface_t *fa);
706 extern char skyname[];
713 void Mod_LoadFaces (lump_t *l)
717 int i, count, surfnum;
720 in = (void *)(mod_base + l->fileofs);
721 if (l->filelen % sizeof(*in))
722 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
723 count = l->filelen / sizeof(*in);
724 out = Hunk_AllocName ( count*sizeof(*out), va("%s faces", loadname));
726 loadmodel->surfaces = out;
727 loadmodel->numsurfaces = count;
729 for ( surfnum=0 ; surfnum<count ; surfnum++, in++, out++)
731 out->firstedge = LittleLong(in->firstedge);
732 out->numedges = LittleShort(in->numedges);
735 planenum = LittleShort(in->planenum);
736 side = LittleShort(in->side);
738 out->flags |= SURF_PLANEBACK;
740 out->plane = loadmodel->planes + planenum;
742 out->texinfo = loadmodel->texinfo + LittleShort (in->texinfo);
744 CalcSurfaceExtents (out);
748 for (i=0 ; i<MAXLIGHTMAPS ; i++)
749 out->styles[i] = in->styles[i];
750 i = LittleLong(in->lightofs);
753 else if (hlbsp) // LordHavoc: HalfLife map (bsp version 30)
754 out->samples = loadmodel->lightdata + i;
755 else // LordHavoc: white lighting (bsp version 29)
756 out->samples = loadmodel->lightdata + (i * 3);
758 // set the drawing flags flag
760 // if (!strncmp(out->texinfo->texture->name,"sky",3)) // sky
761 // LordHavoc: faster check
762 if ((out->texinfo->texture->name[0] == 's' || out->texinfo->texture->name[0] == 'S')
763 && (out->texinfo->texture->name[1] == 'k' || out->texinfo->texture->name[1] == 'K')
764 && (out->texinfo->texture->name[2] == 'y' || out->texinfo->texture->name[2] == 'Y'))
766 // LordHavoc: for consistency reasons, mark sky as fullbright and solid as well
767 out->flags |= (SURF_DRAWSKY | SURF_DRAWTILED | SURF_DRAWFULLBRIGHT | SURF_DRAWNOALPHA);
768 GL_SubdivideSurface (out); // cut up polygon for warps
772 // if (!strncmp(out->texinfo->texture->name,"*",1)) // turbulent
773 if (out->texinfo->texture->name[0] == '*') // LordHavoc: faster check
775 out->flags |= (SURF_DRAWTURB | SURF_DRAWTILED);
776 // LordHavoc: some turbulent textures should be fullbright and solid
777 if (!strncmp(out->texinfo->texture->name,"*lava",5)
778 || !strncmp(out->texinfo->texture->name,"*teleport",9)
779 || !strncmp(out->texinfo->texture->name,"*rift",5)) // Scourge of Armagon texture
780 out->flags |= (SURF_DRAWFULLBRIGHT | SURF_DRAWNOALPHA);
781 for (i=0 ; i<2 ; i++)
783 out->extents[i] = 16384;
784 out->texturemins[i] = -8192;
786 GL_SubdivideSurface (out); // cut up polygon for warps
799 void Mod_SetParent (mnode_t *node, mnode_t *parent)
801 node->parent = parent;
802 if (node->contents < 0)
804 Mod_SetParent (node->children[0], node);
805 Mod_SetParent (node->children[1], node);
813 void Mod_LoadNodes (lump_t *l)
819 in = (void *)(mod_base + l->fileofs);
820 if (l->filelen % sizeof(*in))
821 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
822 count = l->filelen / sizeof(*in);
823 out = Hunk_AllocName ( count*sizeof(*out), va("%s nodes", loadname));
825 loadmodel->nodes = out;
826 loadmodel->numnodes = count;
828 for ( i=0 ; i<count ; i++, in++, out++)
830 for (j=0 ; j<3 ; j++)
832 out->minmaxs[j] = LittleShort (in->mins[j]);
833 out->minmaxs[3+j] = LittleShort (in->maxs[j]);
836 p = LittleLong(in->planenum);
837 out->plane = loadmodel->planes + p;
839 out->firstsurface = LittleShort (in->firstface);
840 out->numsurfaces = LittleShort (in->numfaces);
842 for (j=0 ; j<2 ; j++)
844 p = LittleShort (in->children[j]);
846 out->children[j] = loadmodel->nodes + p;
848 out->children[j] = (mnode_t *)(loadmodel->leafs + (-1 - p));
852 Mod_SetParent (loadmodel->nodes, NULL); // sets nodes and leafs
860 void Mod_LoadLeafs (lump_t *l)
866 in = (void *)(mod_base + l->fileofs);
867 if (l->filelen % sizeof(*in))
868 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
869 count = l->filelen / sizeof(*in);
870 out = Hunk_AllocName ( count*sizeof(*out), va("%s leafs", loadname));
872 loadmodel->leafs = out;
873 loadmodel->numleafs = count;
875 for ( i=0 ; i<count ; i++, in++, out++)
877 for (j=0 ; j<3 ; j++)
879 out->minmaxs[j] = LittleShort (in->mins[j]);
880 out->minmaxs[3+j] = LittleShort (in->maxs[j]);
883 p = LittleLong(in->contents);
886 out->firstmarksurface = loadmodel->marksurfaces +
887 LittleShort(in->firstmarksurface);
888 out->nummarksurfaces = LittleShort(in->nummarksurfaces);
890 p = LittleLong(in->visofs);
892 out->compressed_vis = NULL;
894 out->compressed_vis = loadmodel->visdata + p;
897 for (j=0 ; j<4 ; j++)
898 out->ambient_sound_level[j] = in->ambient_level[j];
900 // gl underwater warp
901 // LordHavoc: disabled underwater warping
903 if (out->contents != CONTENTS_EMPTY)
905 for (j=0 ; j<out->nummarksurfaces ; j++)
906 out->firstmarksurface[j]->flags |= SURF_UNDERWATER;
917 void Mod_LoadClipnodes (lump_t *l)
919 dclipnode_t *in, *out;
923 in = (void *)(mod_base + l->fileofs);
924 if (l->filelen % sizeof(*in))
925 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
926 count = l->filelen / sizeof(*in);
927 out = Hunk_AllocName ( count*sizeof(*out), va("%s clipnodes", loadname));
929 loadmodel->clipnodes = out;
930 loadmodel->numclipnodes = count;
934 hull = &loadmodel->hulls[1];
935 hull->clipnodes = out;
936 hull->firstclipnode = 0;
937 hull->lastclipnode = count-1;
938 hull->planes = loadmodel->planes;
939 hull->clip_mins[0] = -16;
940 hull->clip_mins[1] = -16;
941 hull->clip_mins[2] = -36;
942 hull->clip_maxs[0] = 16;
943 hull->clip_maxs[1] = 16;
944 hull->clip_maxs[2] = 36;
946 hull = &loadmodel->hulls[2];
947 hull->clipnodes = out;
948 hull->firstclipnode = 0;
949 hull->lastclipnode = count-1;
950 hull->planes = loadmodel->planes;
951 hull->clip_mins[0] = -32;
952 hull->clip_mins[1] = -32;
953 hull->clip_mins[2] = -32;
954 hull->clip_maxs[0] = 32;
955 hull->clip_maxs[1] = 32;
956 hull->clip_maxs[2] = 32;
958 hull = &loadmodel->hulls[3];
959 hull->clipnodes = out;
960 hull->firstclipnode = 0;
961 hull->lastclipnode = count-1;
962 hull->planes = loadmodel->planes;
963 hull->clip_mins[0] = -16;
964 hull->clip_mins[1] = -16;
965 hull->clip_mins[2] = -18;
966 hull->clip_maxs[0] = 16;
967 hull->clip_maxs[1] = 16;
968 hull->clip_maxs[2] = 18;
972 hull = &loadmodel->hulls[1];
973 hull->clipnodes = out;
974 hull->firstclipnode = 0;
975 hull->lastclipnode = count-1;
976 hull->planes = loadmodel->planes;
977 hull->clip_mins[0] = -16;
978 hull->clip_mins[1] = -16;
979 hull->clip_mins[2] = -24;
980 hull->clip_maxs[0] = 16;
981 hull->clip_maxs[1] = 16;
982 hull->clip_maxs[2] = 32;
984 hull = &loadmodel->hulls[2];
985 hull->clipnodes = out;
986 hull->firstclipnode = 0;
987 hull->lastclipnode = count-1;
988 hull->planes = loadmodel->planes;
989 hull->clip_mins[0] = -32;
990 hull->clip_mins[1] = -32;
991 hull->clip_mins[2] = -24;
992 hull->clip_maxs[0] = 32;
993 hull->clip_maxs[1] = 32;
994 hull->clip_maxs[2] = 64;
997 for (i=0 ; i<count ; i++, out++, in++)
999 out->planenum = LittleLong(in->planenum);
1000 out->children[0] = LittleShort(in->children[0]);
1001 out->children[1] = LittleShort(in->children[1]);
1002 if (out->children[0] >= count || out->children[1] >= count)
1003 Host_Error("Corrupt clipping hull (out of range child)\n");
1011 Duplicate the drawing hull structure as a clipping hull
1014 void Mod_MakeHull0 (void)
1016 mnode_t *in, *child;
1021 hull = &loadmodel->hulls[0];
1023 in = loadmodel->nodes;
1024 count = loadmodel->numnodes;
1025 out = Hunk_AllocName ( count*sizeof(*out), va("%s hull0", loadname));
1027 hull->clipnodes = out;
1028 hull->firstclipnode = 0;
1029 hull->lastclipnode = count-1;
1030 hull->planes = loadmodel->planes;
1032 for (i=0 ; i<count ; i++, out++, in++)
1034 out->planenum = in->plane - loadmodel->planes;
1035 for (j=0 ; j<2 ; j++)
1037 child = in->children[j];
1038 if (child->contents < 0)
1039 out->children[j] = child->contents;
1041 out->children[j] = child - loadmodel->nodes;
1048 Mod_LoadMarksurfaces
1051 void Mod_LoadMarksurfaces (lump_t *l)
1057 in = (void *)(mod_base + l->fileofs);
1058 if (l->filelen % sizeof(*in))
1059 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
1060 count = l->filelen / sizeof(*in);
1061 out = Hunk_AllocName ( count*sizeof(*out), va("%s marksurfaces", loadname));
1063 loadmodel->marksurfaces = out;
1064 loadmodel->nummarksurfaces = count;
1066 for ( i=0 ; i<count ; i++)
1068 j = LittleShort(in[i]);
1069 if (j >= loadmodel->numsurfaces)
1070 Host_Error ("Mod_ParseMarksurfaces: bad surface number");
1071 out[i] = loadmodel->surfaces + j;
1080 void Mod_LoadSurfedges (lump_t *l)
1085 in = (void *)(mod_base + l->fileofs);
1086 if (l->filelen % sizeof(*in))
1087 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
1088 count = l->filelen / sizeof(*in);
1089 out = Hunk_AllocName ( count*sizeof(*out), va("%s surfedges", loadname));
1091 loadmodel->surfedges = out;
1092 loadmodel->numsurfedges = count;
1094 for ( i=0 ; i<count ; i++)
1095 out[i] = LittleLong (in[i]);
1104 void Mod_LoadPlanes (lump_t *l)
1112 in = (void *)(mod_base + l->fileofs);
1113 if (l->filelen % sizeof(*in))
1114 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
1115 count = l->filelen / sizeof(*in);
1116 out = Hunk_AllocName ( count*2*sizeof(*out), va("%s planes", loadname));
1118 loadmodel->planes = out;
1119 loadmodel->numplanes = count;
1121 for ( i=0 ; i<count ; i++, in++, out++)
1124 for (j=0 ; j<3 ; j++)
1126 out->normal[j] = LittleFloat (in->normal[j]);
1127 // if (out->normal[j] < 0)
1131 out->dist = LittleFloat (in->dist);
1132 out->type = LittleLong (in->type);
1133 // out->signbits = bits;
1134 BoxOnPlaneSideClassify(out);
1143 void Mod_LoadBrushModel (model_t *mod, void *buffer)
1149 loadmodel->type = mod_brush;
1151 header = (dheader_t *)buffer;
1153 i = LittleLong (header->version);
1154 if (i != BSPVERSION && i != 30)
1155 Host_Error ("Mod_LoadBrushModel: %s has wrong version number (%i should be %i or 30 (HalfLife))", mod->name, i, BSPVERSION);
1157 halflifebsp.value = hlbsp;
1159 // swap all the lumps
1160 mod_base = (byte *)header;
1162 for (i=0 ; i<sizeof(dheader_t)/4 ; i++)
1163 ((int *)header)[i] = LittleLong ( ((int *)header)[i]);
1167 // LordHavoc: had to move entity loading above everything to allow parsing various settings from worldspawn
1168 Mod_LoadEntities (&header->lumps[LUMP_ENTITIES]);
1170 Mod_LoadVertexes (&header->lumps[LUMP_VERTEXES]);
1171 Mod_LoadEdges (&header->lumps[LUMP_EDGES]);
1172 Mod_LoadSurfedges (&header->lumps[LUMP_SURFEDGES]);
1173 Mod_LoadTextures (&header->lumps[LUMP_TEXTURES]);
1174 Mod_LoadLighting (&header->lumps[LUMP_LIGHTING]);
1175 Mod_LoadPlanes (&header->lumps[LUMP_PLANES]);
1176 Mod_LoadTexinfo (&header->lumps[LUMP_TEXINFO]);
1177 Mod_LoadFaces (&header->lumps[LUMP_FACES]);
1178 Mod_LoadMarksurfaces (&header->lumps[LUMP_MARKSURFACES]);
1179 Mod_LoadVisibility (&header->lumps[LUMP_VISIBILITY]);
1180 Mod_LoadLeafs (&header->lumps[LUMP_LEAFS]);
1181 Mod_LoadNodes (&header->lumps[LUMP_NODES]);
1182 Mod_LoadClipnodes (&header->lumps[LUMP_CLIPNODES]);
1183 // Mod_LoadEntities (&header->lumps[LUMP_ENTITIES]);
1184 Mod_LoadSubmodels (&header->lumps[LUMP_MODELS]);
1188 mod->numframes = 2; // regular and alternate animation
1191 // set up the submodels (FIXME: this is confusing)
1193 for (i=0 ; i<mod->numsubmodels ; i++)
1195 bm = &mod->submodels[i];
1197 mod->hulls[0].firstclipnode = bm->headnode[0];
1198 for (j=1 ; j<MAX_MAP_HULLS ; j++)
1200 mod->hulls[j].firstclipnode = bm->headnode[j];
1201 mod->hulls[j].lastclipnode = mod->numclipnodes-1;
1204 mod->firstmodelsurface = bm->firstface;
1205 mod->nummodelsurfaces = bm->numfaces;
1207 VectorCopy (bm->maxs, mod->maxs);
1208 VectorCopy (bm->mins, mod->mins);
1210 mod->radius = RadiusFromBounds (mod->mins, mod->maxs);
1212 mod->numleafs = bm->visleafs;
1214 if (isworldmodel && i < (mod->numsubmodels-1)) // LordHavoc: only register submodels if it is the world (prevents bsp models from replacing world submodels)
1215 { // duplicate the basic information
1218 sprintf (name, "*%i", i+1);
1219 loadmodel = Mod_FindName (name);
1221 strcpy (loadmodel->name, name);