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 memcpy (tx->name, mt->name, sizeof(tx->name));
146 tx->width = mt->width;
147 tx->height = mt->height;
148 for (j=0 ; j<MIPLEVELS ; j++)
154 data = loadimagepixels(mt->name, FALSE, 0, 0); //tx->width, tx->height);
155 if (!data) // no external texture found
160 if (!hlbsp && mt->offsets[0]) // texture included
162 data = (byte *)((int) mt + mt->offsets[0]);
163 if (r_fullbrights.value && mt->name[0] != '*')
165 for (j = 0;j < tx->width*tx->height;j++)
166 if (data[j] >= 224) // fullbright
173 else // no texture, and no external replacement texture was found
175 tx->width = tx->height = 16;
176 data = (byte *)((int) r_notexture_mip + r_notexture_mip->offsets[0]);
181 tx->width = image_width;
182 tx->height = image_height;
184 if (!hlbsp && !strncmp(mt->name,"sky",3) && tx->width == 256 && tx->height == 128) // LordHavoc: HL sky textures are entirely unrelated
186 tx->transparent = FALSE;
187 R_InitSky (data, bytesperpixel);
191 tx->transparent = transparent;
196 data2 = malloc(tx->width*tx->height);
197 for (j = 0;j < tx->width*tx->height;j++)
198 data2[j] = data[j] >= 224 ? 0 : data[j]; // no fullbrights
199 tx->gl_texturenum = GL_LoadTexture (tx->name, tx->width, tx->height, data2, true, transparent, 1);
200 strcpy(name, tx->name);
201 strcat(name, "_glow");
202 for (j = 0;j < tx->width*tx->height;j++)
203 data2[j] = data[j] >= 224 ? data[j] : 0; // only fullbrights
204 tx->gl_glowtexturenum = GL_LoadTexture (name, tx->width, tx->height, data2, true, transparent, 1);
209 tx->gl_texturenum = GL_LoadTexture (tx->name, tx->width, tx->height, data, true, transparent, bytesperpixel);
210 tx->gl_glowtexturenum = 0;
217 pixels = mt->width*mt->height/64*85;
218 tx = Hunk_AllocName (sizeof(texture_t) +pixels, loadname );
219 loadmodel->textures[i] = tx;
221 memcpy (tx->name, mt->name, sizeof(tx->name));
222 tx->width = mt->width;
223 tx->height = mt->height;
224 for (j=0 ; j<MIPLEVELS ; j++)
225 tx->offsets[j] = mt->offsets[j] + sizeof(texture_t) - sizeof(miptex_t);
226 // the pixels immediately follow the structures
227 memcpy ( tx+1, mt+1, pixels);
230 if (!strncmp(mt->name,"sky",3))
233 tx->gl_texturenum = GL_LoadTexture (mt->name, tx->width, tx->height, (byte *)(tx+1), true, false, 1);
238 // sequence the animations
240 for (i=0 ; i<m->nummiptex ; i++)
242 tx = loadmodel->textures[i];
243 if (!tx || tx->name[0] != '+')
246 continue; // allready sequenced
248 // find the number of frames in the animation
249 memset (anims, 0, sizeof(anims));
250 memset (altanims, 0, sizeof(altanims));
254 if (max >= 'a' && max <= 'z')
256 if (max >= '0' && max <= '9')
263 else if (max >= 'A' && max <= 'J')
267 altanims[altmax] = tx;
271 Host_Error ("Bad animating texture %s", tx->name);
273 for (j=i+1 ; j<m->nummiptex ; j++)
275 tx2 = loadmodel->textures[j];
276 if (!tx2 || tx2->name[0] != '+')
278 if (strcmp (tx2->name+2, tx->name+2))
282 if (num >= 'a' && num <= 'z')
284 if (num >= '0' && num <= '9')
291 else if (num >= 'A' && num <= 'J')
299 Host_Error ("Bad animating texture %s", tx->name);
303 // link them all together
304 for (j=0 ; j<max ; j++)
308 Host_Error ("Missing frame %i of %s",j, tx->name);
309 tx2->anim_total = max * ANIM_CYCLE;
310 tx2->anim_min = j * ANIM_CYCLE;
311 tx2->anim_max = (j+1) * ANIM_CYCLE;
312 tx2->anim_next = anims[ (j+1)%max ];
314 tx2->alternate_anims = altanims[0];
316 for (j=0 ; j<altmax ; j++)
320 Host_Error ("Missing frame %i of %s",j, tx->name);
321 tx2->anim_total = altmax * ANIM_CYCLE;
322 tx2->anim_min = j * ANIM_CYCLE;
323 tx2->anim_max = (j+1) * ANIM_CYCLE;
324 tx2->anim_next = altanims[ (j+1)%altmax ];
326 tx2->alternate_anims = anims[0];
336 void Mod_LoadLighting (lump_t *l)
339 byte *in, *out, *data;
341 char litfilename[1024];
342 loadmodel->lightdata = NULL;
343 if (hlbsp) // LordHavoc: load the colored lighting data straight
345 loadmodel->lightdata = Hunk_AllocName ( l->filelen, loadname);
346 memcpy (loadmodel->lightdata, mod_base + l->fileofs, l->filelen);
348 else // LordHavoc: bsp version 29 (normal white lighting)
350 // LordHavoc: hope is not lost yet, check for a .lit file to load
351 strcpy(litfilename, loadmodel->name);
352 COM_StripExtension(litfilename, litfilename);
353 strcat(litfilename, ".lit");
354 data = (byte*) COM_LoadHunkFile (litfilename, false);
357 if (data[0] == 'Q' && data[1] == 'L' && data[2] == 'I' && data[3] == 'T')
359 i = LittleLong(((int *)data)[1]);
362 Con_DPrintf("%s loaded", litfilename);
363 loadmodel->lightdata = data + 8;
367 Con_Printf("Unknown .lit file version (%d)\n", i);
370 Con_Printf("Corrupt .lit file (old version?), ignoring\n");
372 // LordHavoc: oh well, expand the white lighting data
375 loadmodel->lightdata = Hunk_AllocName ( l->filelen*3, litfilename);
376 in = loadmodel->lightdata + l->filelen*2; // place the file at the end, so it will not be overwritten until the very last write
377 out = loadmodel->lightdata;
378 memcpy (in, mod_base + l->fileofs, l->filelen);
379 for (i = 0;i < l->filelen;i++)
395 void Mod_LoadVisibility (lump_t *l)
399 loadmodel->visdata = NULL;
402 loadmodel->visdata = Hunk_AllocName ( l->filelen, loadname);
403 memcpy (loadmodel->visdata, mod_base + l->fileofs, l->filelen);
406 void CL_ParseEntityLump(char *entdata);
408 extern qboolean isworldmodel;
415 void Mod_LoadEntities (lump_t *l)
419 loadmodel->entities = NULL;
422 loadmodel->entities = Hunk_AllocName ( l->filelen, loadname);
423 memcpy (loadmodel->entities, mod_base + l->fileofs, l->filelen);
426 CL_ParseEntityLump(loadmodel->entities);
435 void Mod_LoadVertexes (lump_t *l)
441 in = (void *)(mod_base + l->fileofs);
442 if (l->filelen % sizeof(*in))
443 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
444 count = l->filelen / sizeof(*in);
445 out = Hunk_AllocName ( count*sizeof(*out), loadname);
447 loadmodel->vertexes = out;
448 loadmodel->numvertexes = count;
450 for ( i=0 ; i<count ; i++, in++, out++)
452 out->position[0] = LittleFloat (in->point[0]);
453 out->position[1] = LittleFloat (in->point[1]);
454 out->position[2] = LittleFloat (in->point[2]);
463 void Mod_LoadSubmodels (lump_t *l)
469 in = (void *)(mod_base + l->fileofs);
470 if (l->filelen % sizeof(*in))
471 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
472 count = l->filelen / sizeof(*in);
473 out = Hunk_AllocName ( count*sizeof(*out), loadname);
475 loadmodel->submodels = out;
476 loadmodel->numsubmodels = count;
478 for ( i=0 ; i<count ; i++, in++, out++)
480 for (j=0 ; j<3 ; j++)
481 { // spread the mins / maxs by a pixel
482 out->mins[j] = LittleFloat (in->mins[j]) - 1;
483 out->maxs[j] = LittleFloat (in->maxs[j]) + 1;
484 out->origin[j] = LittleFloat (in->origin[j]);
486 for (j=0 ; j<MAX_MAP_HULLS ; j++)
487 out->headnode[j] = LittleLong (in->headnode[j]);
488 out->visleafs = LittleLong (in->visleafs);
489 out->firstface = LittleLong (in->firstface);
490 out->numfaces = LittleLong (in->numfaces);
499 void Mod_LoadEdges (lump_t *l)
505 in = (void *)(mod_base + l->fileofs);
506 if (l->filelen % sizeof(*in))
507 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
508 count = l->filelen / sizeof(*in);
509 out = Hunk_AllocName ( (count + 1) * sizeof(*out), loadname);
511 loadmodel->edges = out;
512 loadmodel->numedges = count;
514 for ( i=0 ; i<count ; i++, in++, out++)
516 out->v[0] = (unsigned short)LittleShort(in->v[0]);
517 out->v[1] = (unsigned short)LittleShort(in->v[1]);
526 void Mod_LoadTexinfo (lump_t *l)
534 in = (void *)(mod_base + l->fileofs);
535 if (l->filelen % sizeof(*in))
536 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
537 count = l->filelen / sizeof(*in);
538 out = Hunk_AllocName ( count*sizeof(*out), loadname);
540 loadmodel->texinfo = out;
541 loadmodel->numtexinfo = count;
543 for ( i=0 ; i<count ; i++, in++, out++)
545 for (j=0 ; j<8 ; j++)
546 out->vecs[0][j] = LittleFloat (in->vecs[0][j]);
547 len1 = Length (out->vecs[0]);
548 len2 = Length (out->vecs[1]);
549 len1 = (len1 + len2)/2;
552 else if (len1 < 0.49)
554 else if (len1 < 0.99)
559 if (len1 + len2 < 0.001)
560 out->mipadjust = 1; // don't crash
562 out->mipadjust = 1 / floor( (len1+len2)/2 + 0.1 );
565 miptex = LittleLong (in->miptex);
566 out->flags = LittleLong (in->flags);
568 if (!loadmodel->textures)
570 out->texture = r_notexture_mip; // checkerboard texture
572 out->texture->transparent = FALSE;
576 if (miptex >= loadmodel->numtextures)
577 Host_Error ("miptex >= loadmodel->numtextures");
578 out->texture = loadmodel->textures[miptex];
581 out->texture = r_notexture_mip; // texture not found
583 out->texture->transparent = FALSE;
593 Fills in s->texturemins[] and s->extents[]
596 void CalcSurfaceExtents (msurface_t *s)
598 float mins[2], maxs[2], val;
602 int bmins[2], bmaxs[2];
604 mins[0] = mins[1] = 999999;
605 maxs[0] = maxs[1] = -99999;
609 for (i=0 ; i<s->numedges ; i++)
611 e = loadmodel->surfedges[s->firstedge+i];
613 v = &loadmodel->vertexes[loadmodel->edges[e].v[0]];
615 v = &loadmodel->vertexes[loadmodel->edges[-e].v[1]];
617 for (j=0 ; j<2 ; j++)
619 val = v->position[0] * tex->vecs[j][0] +
620 v->position[1] * tex->vecs[j][1] +
621 v->position[2] * tex->vecs[j][2] +
630 for (i=0 ; i<2 ; i++)
632 bmins[i] = floor(mins[i]/16);
633 bmaxs[i] = ceil(maxs[i]/16);
635 s->texturemins[i] = bmins[i] * 16;
636 s->extents[i] = (bmaxs[i] - bmins[i]) * 16;
637 if ( !(tex->flags & TEX_SPECIAL) && s->extents[i] > 512 /* 256 */ )
638 Host_Error ("Bad surface extents");
642 void GL_SubdivideSurface (msurface_t *fa);
644 extern char skyname[];
651 void Mod_LoadFaces (lump_t *l)
655 int i, count, surfnum;
658 in = (void *)(mod_base + l->fileofs);
659 if (l->filelen % sizeof(*in))
660 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
661 count = l->filelen / sizeof(*in);
662 out = Hunk_AllocName ( count*sizeof(*out), loadname);
664 loadmodel->surfaces = out;
665 loadmodel->numsurfaces = count;
667 for ( surfnum=0 ; surfnum<count ; surfnum++, in++, out++)
669 out->firstedge = LittleLong(in->firstedge);
670 out->numedges = LittleShort(in->numedges);
673 planenum = LittleShort(in->planenum);
674 side = LittleShort(in->side);
676 out->flags |= SURF_PLANEBACK;
678 out->plane = loadmodel->planes + planenum;
680 out->texinfo = loadmodel->texinfo + LittleShort (in->texinfo);
682 CalcSurfaceExtents (out);
686 for (i=0 ; i<MAXLIGHTMAPS ; i++)
687 out->styles[i] = in->styles[i];
688 i = LittleLong(in->lightofs);
691 else if (hlbsp) // LordHavoc: HalfLife map (bsp version 30)
692 out->samples = loadmodel->lightdata + i;
693 else // LordHavoc: white lighting (bsp version 29)
694 out->samples = loadmodel->lightdata + (i * 3);
696 // set the drawing flags flag
698 // if (!strncmp(out->texinfo->texture->name,"sky",3)) // sky
699 // LordHavoc: faster check
700 if ((out->texinfo->texture->name[0] == 's' || out->texinfo->texture->name[0] == 'S')
701 && (out->texinfo->texture->name[1] == 'k' || out->texinfo->texture->name[1] == 'K')
702 && (out->texinfo->texture->name[2] == 'y' || out->texinfo->texture->name[2] == 'Y'))
704 // LordHavoc: for consistency reasons, mark sky as fullbright and solid as well
705 out->flags |= (SURF_DRAWSKY | SURF_DRAWTILED | SURF_DRAWFULLBRIGHT | SURF_DRAWNOALPHA);
706 GL_SubdivideSurface (out); // cut up polygon for warps
710 // if (!strncmp(out->texinfo->texture->name,"*",1)) // turbulent
711 if (out->texinfo->texture->name[0] == '*') // LordHavoc: faster check
713 out->flags |= (SURF_DRAWTURB | SURF_DRAWTILED);
714 // LordHavoc: some turbulent textures should be fullbright and solid
715 if (!strncmp(out->texinfo->texture->name,"*lava",5)
716 || !strncmp(out->texinfo->texture->name,"*teleport",9)
717 || !strncmp(out->texinfo->texture->name,"*rift",5)) // Scourge of Armagon texture
718 out->flags |= (SURF_DRAWFULLBRIGHT | SURF_DRAWNOALPHA);
719 for (i=0 ; i<2 ; i++)
721 out->extents[i] = 16384;
722 out->texturemins[i] = -8192;
724 GL_SubdivideSurface (out); // cut up polygon for warps
737 void Mod_SetParent (mnode_t *node, mnode_t *parent)
739 node->parent = parent;
740 if (node->contents < 0)
742 Mod_SetParent (node->children[0], node);
743 Mod_SetParent (node->children[1], node);
751 void Mod_LoadNodes (lump_t *l)
757 in = (void *)(mod_base + l->fileofs);
758 if (l->filelen % sizeof(*in))
759 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
760 count = l->filelen / sizeof(*in);
761 out = Hunk_AllocName ( count*sizeof(*out), loadname);
763 loadmodel->nodes = out;
764 loadmodel->numnodes = count;
766 for ( i=0 ; i<count ; i++, in++, out++)
768 for (j=0 ; j<3 ; j++)
770 out->minmaxs[j] = LittleShort (in->mins[j]);
771 out->minmaxs[3+j] = LittleShort (in->maxs[j]);
774 p = LittleLong(in->planenum);
775 out->plane = loadmodel->planes + p;
777 out->firstsurface = LittleShort (in->firstface);
778 out->numsurfaces = LittleShort (in->numfaces);
780 for (j=0 ; j<2 ; j++)
782 p = LittleShort (in->children[j]);
784 out->children[j] = loadmodel->nodes + p;
786 out->children[j] = (mnode_t *)(loadmodel->leafs + (-1 - p));
790 Mod_SetParent (loadmodel->nodes, NULL); // sets nodes and leafs
798 void Mod_LoadLeafs (lump_t *l)
804 in = (void *)(mod_base + l->fileofs);
805 if (l->filelen % sizeof(*in))
806 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
807 count = l->filelen / sizeof(*in);
808 out = Hunk_AllocName ( count*sizeof(*out), loadname);
810 loadmodel->leafs = out;
811 loadmodel->numleafs = count;
813 for ( i=0 ; i<count ; i++, in++, out++)
815 for (j=0 ; j<3 ; j++)
817 out->minmaxs[j] = LittleShort (in->mins[j]);
818 out->minmaxs[3+j] = LittleShort (in->maxs[j]);
821 p = LittleLong(in->contents);
824 out->firstmarksurface = loadmodel->marksurfaces +
825 LittleShort(in->firstmarksurface);
826 out->nummarksurfaces = LittleShort(in->nummarksurfaces);
828 p = LittleLong(in->visofs);
830 out->compressed_vis = NULL;
832 out->compressed_vis = loadmodel->visdata + p;
835 for (j=0 ; j<4 ; j++)
836 out->ambient_sound_level[j] = in->ambient_level[j];
838 // gl underwater warp
839 // LordHavoc: disabled underwater warping
841 if (out->contents != CONTENTS_EMPTY)
843 for (j=0 ; j<out->nummarksurfaces ; j++)
844 out->firstmarksurface[j]->flags |= SURF_UNDERWATER;
855 void Mod_LoadClipnodes (lump_t *l)
857 dclipnode_t *in, *out;
861 in = (void *)(mod_base + l->fileofs);
862 if (l->filelen % sizeof(*in))
863 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
864 count = l->filelen / sizeof(*in);
865 out = Hunk_AllocName ( count*sizeof(*out), loadname);
867 loadmodel->clipnodes = out;
868 loadmodel->numclipnodes = count;
872 hull = &loadmodel->hulls[1];
873 hull->clipnodes = out;
874 hull->firstclipnode = 0;
875 hull->lastclipnode = count-1;
876 hull->planes = loadmodel->planes;
877 hull->clip_mins[0] = -16;
878 hull->clip_mins[1] = -16;
879 hull->clip_mins[2] = -36;
880 hull->clip_maxs[0] = 16;
881 hull->clip_maxs[1] = 16;
882 hull->clip_maxs[2] = 36;
884 hull = &loadmodel->hulls[2];
885 hull->clipnodes = out;
886 hull->firstclipnode = 0;
887 hull->lastclipnode = count-1;
888 hull->planes = loadmodel->planes;
889 hull->clip_mins[0] = -32;
890 hull->clip_mins[1] = -32;
891 hull->clip_mins[2] = -32;
892 hull->clip_maxs[0] = 32;
893 hull->clip_maxs[1] = 32;
894 hull->clip_maxs[2] = 32;
896 hull = &loadmodel->hulls[3];
897 hull->clipnodes = out;
898 hull->firstclipnode = 0;
899 hull->lastclipnode = count-1;
900 hull->planes = loadmodel->planes;
901 hull->clip_mins[0] = -16;
902 hull->clip_mins[1] = -16;
903 hull->clip_mins[2] = -18;
904 hull->clip_maxs[0] = 16;
905 hull->clip_maxs[1] = 16;
906 hull->clip_maxs[2] = 18;
910 hull = &loadmodel->hulls[1];
911 hull->clipnodes = out;
912 hull->firstclipnode = 0;
913 hull->lastclipnode = count-1;
914 hull->planes = loadmodel->planes;
915 hull->clip_mins[0] = -16;
916 hull->clip_mins[1] = -16;
917 hull->clip_mins[2] = -24;
918 hull->clip_maxs[0] = 16;
919 hull->clip_maxs[1] = 16;
920 hull->clip_maxs[2] = 32;
922 hull = &loadmodel->hulls[2];
923 hull->clipnodes = out;
924 hull->firstclipnode = 0;
925 hull->lastclipnode = count-1;
926 hull->planes = loadmodel->planes;
927 hull->clip_mins[0] = -32;
928 hull->clip_mins[1] = -32;
929 hull->clip_mins[2] = -24;
930 hull->clip_maxs[0] = 32;
931 hull->clip_maxs[1] = 32;
932 hull->clip_maxs[2] = 64;
935 for (i=0 ; i<count ; i++, out++, in++)
937 out->planenum = LittleLong(in->planenum);
938 out->children[0] = LittleShort(in->children[0]);
939 out->children[1] = LittleShort(in->children[1]);
940 if (out->children[0] >= count || out->children[1] >= count)
941 Host_Error("Corrupt clipping hull (out of range child)\n");
949 Duplicate the drawing hull structure as a clipping hull
952 void Mod_MakeHull0 (void)
959 hull = &loadmodel->hulls[0];
961 in = loadmodel->nodes;
962 count = loadmodel->numnodes;
963 out = Hunk_AllocName ( count*sizeof(*out), loadname);
965 hull->clipnodes = out;
966 hull->firstclipnode = 0;
967 hull->lastclipnode = count-1;
968 hull->planes = loadmodel->planes;
970 for (i=0 ; i<count ; i++, out++, in++)
972 out->planenum = in->plane - loadmodel->planes;
973 for (j=0 ; j<2 ; j++)
975 child = in->children[j];
976 if (child->contents < 0)
977 out->children[j] = child->contents;
979 out->children[j] = child - loadmodel->nodes;
989 void Mod_LoadMarksurfaces (lump_t *l)
995 in = (void *)(mod_base + l->fileofs);
996 if (l->filelen % sizeof(*in))
997 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
998 count = l->filelen / sizeof(*in);
999 out = Hunk_AllocName ( count*sizeof(*out), loadname);
1001 loadmodel->marksurfaces = out;
1002 loadmodel->nummarksurfaces = count;
1004 for ( i=0 ; i<count ; i++)
1006 j = LittleShort(in[i]);
1007 if (j >= loadmodel->numsurfaces)
1008 Host_Error ("Mod_ParseMarksurfaces: bad surface number");
1009 out[i] = loadmodel->surfaces + j;
1018 void Mod_LoadSurfedges (lump_t *l)
1023 in = (void *)(mod_base + l->fileofs);
1024 if (l->filelen % sizeof(*in))
1025 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
1026 count = l->filelen / sizeof(*in);
1027 out = Hunk_AllocName ( count*sizeof(*out), loadname);
1029 loadmodel->surfedges = out;
1030 loadmodel->numsurfedges = count;
1032 for ( i=0 ; i<count ; i++)
1033 out[i] = LittleLong (in[i]);
1042 void Mod_LoadPlanes (lump_t *l)
1050 in = (void *)(mod_base + l->fileofs);
1051 if (l->filelen % sizeof(*in))
1052 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
1053 count = l->filelen / sizeof(*in);
1054 out = Hunk_AllocName ( count*2*sizeof(*out), loadname);
1056 loadmodel->planes = out;
1057 loadmodel->numplanes = count;
1059 for ( i=0 ; i<count ; i++, in++, out++)
1062 for (j=0 ; j<3 ; j++)
1064 out->normal[j] = LittleFloat (in->normal[j]);
1065 // if (out->normal[j] < 0)
1069 out->dist = LittleFloat (in->dist);
1070 out->type = LittleLong (in->type);
1071 // out->signbits = bits;
1072 BoxOnPlaneSideClassify(out);
1081 void Mod_LoadBrushModel (model_t *mod, void *buffer)
1087 loadmodel->type = mod_brush;
1089 header = (dheader_t *)buffer;
1091 i = LittleLong (header->version);
1092 if (i != BSPVERSION && i != 30)
1093 Host_Error ("Mod_LoadBrushModel: %s has wrong version number (%i should be %i or 30 (HalfLife))", mod->name, i, BSPVERSION);
1095 halflifebsp.value = hlbsp;
1097 // swap all the lumps
1098 mod_base = (byte *)header;
1100 for (i=0 ; i<sizeof(dheader_t)/4 ; i++)
1101 ((int *)header)[i] = LittleLong ( ((int *)header)[i]);
1105 // LordHavoc: had to move entity loading above everything to allow parsing various settings from worldspawn
1106 Mod_LoadEntities (&header->lumps[LUMP_ENTITIES]);
1108 Mod_LoadVertexes (&header->lumps[LUMP_VERTEXES]);
1109 Mod_LoadEdges (&header->lumps[LUMP_EDGES]);
1110 Mod_LoadSurfedges (&header->lumps[LUMP_SURFEDGES]);
1111 Mod_LoadTextures (&header->lumps[LUMP_TEXTURES]);
1112 Mod_LoadLighting (&header->lumps[LUMP_LIGHTING]);
1113 Mod_LoadPlanes (&header->lumps[LUMP_PLANES]);
1114 Mod_LoadTexinfo (&header->lumps[LUMP_TEXINFO]);
1115 Mod_LoadFaces (&header->lumps[LUMP_FACES]);
1116 Mod_LoadMarksurfaces (&header->lumps[LUMP_MARKSURFACES]);
1117 Mod_LoadVisibility (&header->lumps[LUMP_VISIBILITY]);
1118 Mod_LoadLeafs (&header->lumps[LUMP_LEAFS]);
1119 Mod_LoadNodes (&header->lumps[LUMP_NODES]);
1120 Mod_LoadClipnodes (&header->lumps[LUMP_CLIPNODES]);
1121 // Mod_LoadEntities (&header->lumps[LUMP_ENTITIES]);
1122 Mod_LoadSubmodels (&header->lumps[LUMP_MODELS]);
1126 mod->numframes = 2; // regular and alternate animation
1129 // set up the submodels (FIXME: this is confusing)
1131 for (i=0 ; i<mod->numsubmodels ; i++)
1133 bm = &mod->submodels[i];
1135 mod->hulls[0].firstclipnode = bm->headnode[0];
1136 for (j=1 ; j<MAX_MAP_HULLS ; j++)
1138 mod->hulls[j].firstclipnode = bm->headnode[j];
1139 mod->hulls[j].lastclipnode = mod->numclipnodes-1;
1142 mod->firstmodelsurface = bm->firstface;
1143 mod->nummodelsurfaces = bm->numfaces;
1145 VectorCopy (bm->maxs, mod->maxs);
1146 VectorCopy (bm->mins, mod->mins);
1148 mod->radius = RadiusFromBounds (mod->mins, mod->maxs);
1150 mod->numleafs = bm->visleafs;
1152 if (isworldmodel && i < (mod->numsubmodels-1)) // LordHavoc: only register submodels if it is the world (prevents bsp models from replacing world submodels)
1153 { // duplicate the basic information
1156 sprintf (name, "*%i", i+1);
1157 loadmodel = Mod_FindName (name);
1159 strcpy (loadmodel->name, name);