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
173 if (mt->offsets[0]) // texture included
175 data = (byte *)((int) mt + mt->offsets[0]);
178 byte *in, *out, *pal;
183 data = out = qmalloc(mt->width * mt->height * 4);
184 pal = in + (((mt->width * mt->height) * 85) >> 6);
185 palsize = pal[1] * 0x100 + pal[0];
189 for (d = 0;d < mt->width * mt->height;d++)
196 if (out[0] == 255 && out[1] == 0 && out[2] == 0) // HL transparent color (pure blue)
197 out[0] = out[1] = out[2] = out[3] = 0;
201 else if (r_fullbrights.value && tx->name[0] != '*')
203 for (j = 0;j < tx->width*tx->height;j++)
205 if (data[j] >= 224) // fullbright
213 else // no texture, and no external replacement texture was found
215 tx->width = tx->height = 16;
216 data = (byte *)((int) r_notexture_mip + r_notexture_mip->offsets[0]);
221 tx->width = image_width;
222 tx->height = image_height;
224 if (!hlbsp && !strncmp(tx->name,"sky",3) && tx->width == 256 && tx->height == 128) // LordHavoc: HL sky textures are entirely unrelated
226 tx->transparent = FALSE;
227 R_InitSky (data, bytesperpixel);
235 tx->transparent = false;
236 data2 = qmalloc(tx->width*tx->height);
237 for (j = 0;j < tx->width*tx->height;j++)
238 data2[j] = data[j] >= 224 ? 0 : data[j]; // no fullbrights
239 tx->gl_texturenum = GL_LoadTexture (tx->name, tx->width, tx->height, data2, true, false, 1);
240 strcpy(name, tx->name);
241 strcat(name, "_glow");
242 for (j = 0;j < tx->width*tx->height;j++)
243 data2[j] = data[j] >= 224 ? data[j] : 0; // only fullbrights
244 tx->gl_glowtexturenum = GL_LoadTexture (name, tx->width, tx->height, data2, true, false, 1);
249 tx->transparent = transparent;
250 tx->gl_texturenum = GL_LoadTexture (tx->name, tx->width, tx->height, data, true, transparent, bytesperpixel);
251 tx->gl_glowtexturenum = 0;
259 // sequence the animations
261 for (i=0 ; i<m->nummiptex ; i++)
263 tx = loadmodel->textures[i];
264 if (!tx || tx->name[0] != '+')
267 continue; // allready sequenced
269 // find the number of frames in the animation
270 memset (anims, 0, sizeof(anims));
271 memset (altanims, 0, sizeof(altanims));
275 if (max >= 'a' && max <= 'z')
277 if (max >= '0' && max <= '9')
284 else if (max >= 'A' && max <= 'J')
288 altanims[altmax] = tx;
292 Host_Error ("Bad animating texture %s", tx->name);
294 for (j=i+1 ; j<m->nummiptex ; j++)
296 tx2 = loadmodel->textures[j];
297 if (!tx2 || tx2->name[0] != '+')
299 if (strcmp (tx2->name+2, tx->name+2))
303 if (num >= 'a' && num <= 'z')
305 if (num >= '0' && num <= '9')
312 else if (num >= 'A' && num <= 'J')
320 Host_Error ("Bad animating texture %s", tx->name);
324 // link them all together
325 for (j=0 ; j<max ; j++)
329 Host_Error ("Missing frame %i of %s",j, tx->name);
330 tx2->anim_total = max * ANIM_CYCLE;
331 tx2->anim_min = j * ANIM_CYCLE;
332 tx2->anim_max = (j+1) * ANIM_CYCLE;
333 tx2->anim_next = anims[ (j+1)%max ];
335 tx2->alternate_anims = altanims[0];
337 for (j=0 ; j<altmax ; j++)
341 Host_Error ("Missing frame %i of %s",j, tx->name);
342 tx2->anim_total = altmax * ANIM_CYCLE;
343 tx2->anim_min = j * ANIM_CYCLE;
344 tx2->anim_max = (j+1) * ANIM_CYCLE;
345 tx2->anim_next = altanims[ (j+1)%altmax ];
347 tx2->alternate_anims = anims[0];
357 void Mod_LoadLighting (lump_t *l)
360 byte *in, *out, *data;
362 char litfilename[1024];
363 loadmodel->lightdata = NULL;
364 if (hlbsp) // LordHavoc: load the colored lighting data straight
366 loadmodel->lightdata = Hunk_AllocName ( l->filelen, va("%s lightmaps", loadname));
367 memcpy (loadmodel->lightdata, mod_base + l->fileofs, l->filelen);
369 else // LordHavoc: bsp version 29 (normal white lighting)
371 // LordHavoc: hope is not lost yet, check for a .lit file to load
372 strcpy(litfilename, loadmodel->name);
373 COM_StripExtension(litfilename, litfilename);
374 strcat(litfilename, ".lit");
375 data = (byte*) COM_LoadHunkFile (litfilename, false);
378 if (data[0] == 'Q' && data[1] == 'L' && data[2] == 'I' && data[3] == 'T')
380 i = LittleLong(((int *)data)[1]);
383 Con_DPrintf("%s loaded", litfilename);
384 loadmodel->lightdata = data + 8;
388 Con_Printf("Unknown .lit file version (%d)\n", i);
391 Con_Printf("Corrupt .lit file (old version?), ignoring\n");
393 // LordHavoc: oh well, expand the white lighting data
396 loadmodel->lightdata = Hunk_AllocName ( l->filelen*3, va("%s lightmaps", loadname));
397 in = loadmodel->lightdata + l->filelen*2; // place the file at the end, so it will not be overwritten until the very last write
398 out = loadmodel->lightdata;
399 memcpy (in, mod_base + l->fileofs, l->filelen);
400 for (i = 0;i < l->filelen;i++)
416 void Mod_LoadVisibility (lump_t *l)
420 loadmodel->visdata = NULL;
423 loadmodel->visdata = Hunk_AllocName ( l->filelen, va("%s visdata", loadname));
424 memcpy (loadmodel->visdata, mod_base + l->fileofs, l->filelen);
427 void CL_ParseEntityLump(char *entdata);
429 extern qboolean isworldmodel;
436 void Mod_LoadEntities (lump_t *l)
440 loadmodel->entities = NULL;
443 loadmodel->entities = Hunk_AllocName ( l->filelen, va("%s entities", loadname));
444 memcpy (loadmodel->entities, mod_base + l->fileofs, l->filelen);
447 CL_ParseEntityLump(loadmodel->entities);
456 void Mod_LoadVertexes (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), va("%s vertices", loadname));
468 loadmodel->vertexes = out;
469 loadmodel->numvertexes = count;
471 for ( i=0 ; i<count ; i++, in++, out++)
473 out->position[0] = LittleFloat (in->point[0]);
474 out->position[1] = LittleFloat (in->point[1]);
475 out->position[2] = LittleFloat (in->point[2]);
484 void Mod_LoadSubmodels (lump_t *l)
490 in = (void *)(mod_base + l->fileofs);
491 if (l->filelen % sizeof(*in))
492 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
493 count = l->filelen / sizeof(*in);
494 out = Hunk_AllocName ( count*sizeof(*out), va("%s submodels", loadname));
496 loadmodel->submodels = out;
497 loadmodel->numsubmodels = count;
499 for ( i=0 ; i<count ; i++, in++, out++)
501 for (j=0 ; j<3 ; j++)
502 { // spread the mins / maxs by a pixel
503 out->mins[j] = LittleFloat (in->mins[j]) - 1;
504 out->maxs[j] = LittleFloat (in->maxs[j]) + 1;
505 out->origin[j] = LittleFloat (in->origin[j]);
507 for (j=0 ; j<MAX_MAP_HULLS ; j++)
508 out->headnode[j] = LittleLong (in->headnode[j]);
509 out->visleafs = LittleLong (in->visleafs);
510 out->firstface = LittleLong (in->firstface);
511 out->numfaces = LittleLong (in->numfaces);
520 void Mod_LoadEdges (lump_t *l)
526 in = (void *)(mod_base + l->fileofs);
527 if (l->filelen % sizeof(*in))
528 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
529 count = l->filelen / sizeof(*in);
530 out = Hunk_AllocName ( (count + 1) * sizeof(*out), va("%s edges", loadname));
532 loadmodel->edges = out;
533 loadmodel->numedges = count;
535 for ( i=0 ; i<count ; i++, in++, out++)
537 out->v[0] = (unsigned short)LittleShort(in->v[0]);
538 out->v[1] = (unsigned short)LittleShort(in->v[1]);
547 void Mod_LoadTexinfo (lump_t *l)
555 in = (void *)(mod_base + l->fileofs);
556 if (l->filelen % sizeof(*in))
557 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
558 count = l->filelen / sizeof(*in);
559 out = Hunk_AllocName ( count*sizeof(*out), va("%s texinfo", loadname));
561 loadmodel->texinfo = out;
562 loadmodel->numtexinfo = count;
564 for ( i=0 ; i<count ; i++, in++, out++)
566 for (k=0 ; k<2 ; k++)
567 for (j=0 ; j<4 ; j++)
568 out->vecs[k][j] = LittleFloat (in->vecs[k][j]);
569 len1 = Length (out->vecs[0]);
570 len2 = Length (out->vecs[1]);
571 len1 = (len1 + len2)/2;
574 else if (len1 < 0.49)
576 else if (len1 < 0.99)
581 if (len1 + len2 < 0.001)
582 out->mipadjust = 1; // don't crash
584 out->mipadjust = 1 / floor( (len1+len2)/2 + 0.1 );
587 miptex = LittleLong (in->miptex);
588 out->flags = LittleLong (in->flags);
590 if (!loadmodel->textures)
592 out->texture = r_notexture_mip; // checkerboard texture
594 out->texture->transparent = FALSE;
598 if (miptex >= loadmodel->numtextures)
599 Host_Error ("miptex >= loadmodel->numtextures");
600 out->texture = loadmodel->textures[miptex];
603 out->texture = r_notexture_mip; // texture not found
605 out->texture->transparent = FALSE;
615 Fills in s->texturemins[] and s->extents[]
618 void CalcSurfaceExtents (msurface_t *s)
620 float mins[2], maxs[2], val;
624 int bmins[2], bmaxs[2];
626 mins[0] = mins[1] = 999999;
627 maxs[0] = maxs[1] = -99999;
631 for (i=0 ; i<s->numedges ; i++)
633 e = loadmodel->surfedges[s->firstedge+i];
635 v = &loadmodel->vertexes[loadmodel->edges[e].v[0]];
637 v = &loadmodel->vertexes[loadmodel->edges[-e].v[1]];
639 for (j=0 ; j<2 ; j++)
641 val = v->position[0] * tex->vecs[j][0] +
642 v->position[1] * tex->vecs[j][1] +
643 v->position[2] * tex->vecs[j][2] +
652 for (i=0 ; i<2 ; i++)
654 bmins[i] = floor(mins[i]/16);
655 bmaxs[i] = ceil(maxs[i]/16);
657 s->texturemins[i] = bmins[i] * 16;
658 s->extents[i] = (bmaxs[i] - bmins[i]) * 16;
659 if ( !(tex->flags & TEX_SPECIAL) && s->extents[i] > 512 /* 256 */ )
660 Host_Error ("Bad surface extents");
664 void GL_SubdivideSurface (msurface_t *fa);
666 extern char skyname[];
673 void Mod_LoadFaces (lump_t *l)
677 int i, count, surfnum;
680 in = (void *)(mod_base + l->fileofs);
681 if (l->filelen % sizeof(*in))
682 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
683 count = l->filelen / sizeof(*in);
684 out = Hunk_AllocName ( count*sizeof(*out), va("%s faces", loadname));
686 loadmodel->surfaces = out;
687 loadmodel->numsurfaces = count;
689 for ( surfnum=0 ; surfnum<count ; surfnum++, in++, out++)
691 out->firstedge = LittleLong(in->firstedge);
692 out->numedges = LittleShort(in->numedges);
695 planenum = LittleShort(in->planenum);
696 side = LittleShort(in->side);
698 out->flags |= SURF_PLANEBACK;
700 out->plane = loadmodel->planes + planenum;
702 out->texinfo = loadmodel->texinfo + LittleShort (in->texinfo);
704 CalcSurfaceExtents (out);
708 for (i=0 ; i<MAXLIGHTMAPS ; i++)
709 out->styles[i] = in->styles[i];
710 i = LittleLong(in->lightofs);
713 else if (hlbsp) // LordHavoc: HalfLife map (bsp version 30)
714 out->samples = loadmodel->lightdata + i;
715 else // LordHavoc: white lighting (bsp version 29)
716 out->samples = loadmodel->lightdata + (i * 3);
718 // set the drawing flags flag
720 // if (!strncmp(out->texinfo->texture->name,"sky",3)) // sky
721 // LordHavoc: faster check
722 if ((out->texinfo->texture->name[0] == 's' || out->texinfo->texture->name[0] == 'S')
723 && (out->texinfo->texture->name[1] == 'k' || out->texinfo->texture->name[1] == 'K')
724 && (out->texinfo->texture->name[2] == 'y' || out->texinfo->texture->name[2] == 'Y'))
726 // LordHavoc: for consistency reasons, mark sky as fullbright and solid as well
727 out->flags |= (SURF_DRAWSKY | SURF_DRAWTILED | SURF_DRAWFULLBRIGHT | SURF_DRAWNOALPHA);
728 GL_SubdivideSurface (out); // cut up polygon for warps
732 // if (!strncmp(out->texinfo->texture->name,"*",1)) // turbulent
733 if (out->texinfo->texture->name[0] == '*') // LordHavoc: faster check
735 out->flags |= (SURF_DRAWTURB | SURF_DRAWTILED);
736 // LordHavoc: some turbulent textures should be fullbright and solid
737 if (!strncmp(out->texinfo->texture->name,"*lava",5)
738 || !strncmp(out->texinfo->texture->name,"*teleport",9)
739 || !strncmp(out->texinfo->texture->name,"*rift",5)) // Scourge of Armagon texture
740 out->flags |= (SURF_DRAWFULLBRIGHT | SURF_DRAWNOALPHA);
741 for (i=0 ; i<2 ; i++)
743 out->extents[i] = 16384;
744 out->texturemins[i] = -8192;
746 GL_SubdivideSurface (out); // cut up polygon for warps
759 void Mod_SetParent (mnode_t *node, mnode_t *parent)
761 node->parent = parent;
762 if (node->contents < 0)
764 Mod_SetParent (node->children[0], node);
765 Mod_SetParent (node->children[1], node);
773 void Mod_LoadNodes (lump_t *l)
779 in = (void *)(mod_base + l->fileofs);
780 if (l->filelen % sizeof(*in))
781 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
782 count = l->filelen / sizeof(*in);
783 out = Hunk_AllocName ( count*sizeof(*out), va("%s nodes", loadname));
785 loadmodel->nodes = out;
786 loadmodel->numnodes = count;
788 for ( i=0 ; i<count ; i++, in++, out++)
790 for (j=0 ; j<3 ; j++)
792 out->minmaxs[j] = LittleShort (in->mins[j]);
793 out->minmaxs[3+j] = LittleShort (in->maxs[j]);
796 p = LittleLong(in->planenum);
797 out->plane = loadmodel->planes + p;
799 out->firstsurface = LittleShort (in->firstface);
800 out->numsurfaces = LittleShort (in->numfaces);
802 for (j=0 ; j<2 ; j++)
804 p = LittleShort (in->children[j]);
806 out->children[j] = loadmodel->nodes + p;
808 out->children[j] = (mnode_t *)(loadmodel->leafs + (-1 - p));
812 Mod_SetParent (loadmodel->nodes, NULL); // sets nodes and leafs
820 void Mod_LoadLeafs (lump_t *l)
826 in = (void *)(mod_base + l->fileofs);
827 if (l->filelen % sizeof(*in))
828 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
829 count = l->filelen / sizeof(*in);
830 out = Hunk_AllocName ( count*sizeof(*out), va("%s leafs", loadname));
832 loadmodel->leafs = out;
833 loadmodel->numleafs = count;
835 for ( i=0 ; i<count ; i++, in++, out++)
837 for (j=0 ; j<3 ; j++)
839 out->minmaxs[j] = LittleShort (in->mins[j]);
840 out->minmaxs[3+j] = LittleShort (in->maxs[j]);
843 p = LittleLong(in->contents);
846 out->firstmarksurface = loadmodel->marksurfaces +
847 LittleShort(in->firstmarksurface);
848 out->nummarksurfaces = LittleShort(in->nummarksurfaces);
850 p = LittleLong(in->visofs);
852 out->compressed_vis = NULL;
854 out->compressed_vis = loadmodel->visdata + p;
857 for (j=0 ; j<4 ; j++)
858 out->ambient_sound_level[j] = in->ambient_level[j];
860 // gl underwater warp
861 // LordHavoc: disabled underwater warping
863 if (out->contents != CONTENTS_EMPTY)
865 for (j=0 ; j<out->nummarksurfaces ; j++)
866 out->firstmarksurface[j]->flags |= SURF_UNDERWATER;
877 void Mod_LoadClipnodes (lump_t *l)
879 dclipnode_t *in, *out;
883 in = (void *)(mod_base + l->fileofs);
884 if (l->filelen % sizeof(*in))
885 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
886 count = l->filelen / sizeof(*in);
887 out = Hunk_AllocName ( count*sizeof(*out), va("%s clipnodes", loadname));
889 loadmodel->clipnodes = out;
890 loadmodel->numclipnodes = count;
894 hull = &loadmodel->hulls[1];
895 hull->clipnodes = out;
896 hull->firstclipnode = 0;
897 hull->lastclipnode = count-1;
898 hull->planes = loadmodel->planes;
899 hull->clip_mins[0] = -16;
900 hull->clip_mins[1] = -16;
901 hull->clip_mins[2] = -36;
902 hull->clip_maxs[0] = 16;
903 hull->clip_maxs[1] = 16;
904 hull->clip_maxs[2] = 36;
906 hull = &loadmodel->hulls[2];
907 hull->clipnodes = out;
908 hull->firstclipnode = 0;
909 hull->lastclipnode = count-1;
910 hull->planes = loadmodel->planes;
911 hull->clip_mins[0] = -32;
912 hull->clip_mins[1] = -32;
913 hull->clip_mins[2] = -32;
914 hull->clip_maxs[0] = 32;
915 hull->clip_maxs[1] = 32;
916 hull->clip_maxs[2] = 32;
918 hull = &loadmodel->hulls[3];
919 hull->clipnodes = out;
920 hull->firstclipnode = 0;
921 hull->lastclipnode = count-1;
922 hull->planes = loadmodel->planes;
923 hull->clip_mins[0] = -16;
924 hull->clip_mins[1] = -16;
925 hull->clip_mins[2] = -18;
926 hull->clip_maxs[0] = 16;
927 hull->clip_maxs[1] = 16;
928 hull->clip_maxs[2] = 18;
932 hull = &loadmodel->hulls[1];
933 hull->clipnodes = out;
934 hull->firstclipnode = 0;
935 hull->lastclipnode = count-1;
936 hull->planes = loadmodel->planes;
937 hull->clip_mins[0] = -16;
938 hull->clip_mins[1] = -16;
939 hull->clip_mins[2] = -24;
940 hull->clip_maxs[0] = 16;
941 hull->clip_maxs[1] = 16;
942 hull->clip_maxs[2] = 32;
944 hull = &loadmodel->hulls[2];
945 hull->clipnodes = out;
946 hull->firstclipnode = 0;
947 hull->lastclipnode = count-1;
948 hull->planes = loadmodel->planes;
949 hull->clip_mins[0] = -32;
950 hull->clip_mins[1] = -32;
951 hull->clip_mins[2] = -24;
952 hull->clip_maxs[0] = 32;
953 hull->clip_maxs[1] = 32;
954 hull->clip_maxs[2] = 64;
957 for (i=0 ; i<count ; i++, out++, in++)
959 out->planenum = LittleLong(in->planenum);
960 out->children[0] = LittleShort(in->children[0]);
961 out->children[1] = LittleShort(in->children[1]);
962 if (out->children[0] >= count || out->children[1] >= count)
963 Host_Error("Corrupt clipping hull (out of range child)\n");
971 Duplicate the drawing hull structure as a clipping hull
974 void Mod_MakeHull0 (void)
981 hull = &loadmodel->hulls[0];
983 in = loadmodel->nodes;
984 count = loadmodel->numnodes;
985 out = Hunk_AllocName ( count*sizeof(*out), va("%s hull0", loadname));
987 hull->clipnodes = out;
988 hull->firstclipnode = 0;
989 hull->lastclipnode = count-1;
990 hull->planes = loadmodel->planes;
992 for (i=0 ; i<count ; i++, out++, in++)
994 out->planenum = in->plane - loadmodel->planes;
995 for (j=0 ; j<2 ; j++)
997 child = in->children[j];
998 if (child->contents < 0)
999 out->children[j] = child->contents;
1001 out->children[j] = child - loadmodel->nodes;
1008 Mod_LoadMarksurfaces
1011 void Mod_LoadMarksurfaces (lump_t *l)
1017 in = (void *)(mod_base + l->fileofs);
1018 if (l->filelen % sizeof(*in))
1019 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
1020 count = l->filelen / sizeof(*in);
1021 out = Hunk_AllocName ( count*sizeof(*out), va("%s marksurfaces", loadname));
1023 loadmodel->marksurfaces = out;
1024 loadmodel->nummarksurfaces = count;
1026 for ( i=0 ; i<count ; i++)
1028 j = LittleShort(in[i]);
1029 if (j >= loadmodel->numsurfaces)
1030 Host_Error ("Mod_ParseMarksurfaces: bad surface number");
1031 out[i] = loadmodel->surfaces + j;
1040 void Mod_LoadSurfedges (lump_t *l)
1045 in = (void *)(mod_base + l->fileofs);
1046 if (l->filelen % sizeof(*in))
1047 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
1048 count = l->filelen / sizeof(*in);
1049 out = Hunk_AllocName ( count*sizeof(*out), va("%s surfedges", loadname));
1051 loadmodel->surfedges = out;
1052 loadmodel->numsurfedges = count;
1054 for ( i=0 ; i<count ; i++)
1055 out[i] = LittleLong (in[i]);
1064 void Mod_LoadPlanes (lump_t *l)
1072 in = (void *)(mod_base + l->fileofs);
1073 if (l->filelen % sizeof(*in))
1074 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
1075 count = l->filelen / sizeof(*in);
1076 out = Hunk_AllocName ( count*2*sizeof(*out), va("%s planes", loadname));
1078 loadmodel->planes = out;
1079 loadmodel->numplanes = count;
1081 for ( i=0 ; i<count ; i++, in++, out++)
1084 for (j=0 ; j<3 ; j++)
1086 out->normal[j] = LittleFloat (in->normal[j]);
1087 // if (out->normal[j] < 0)
1091 out->dist = LittleFloat (in->dist);
1092 out->type = LittleLong (in->type);
1093 // out->signbits = bits;
1094 BoxOnPlaneSideClassify(out);
1103 void Mod_LoadBrushModel (model_t *mod, void *buffer)
1109 loadmodel->type = mod_brush;
1111 header = (dheader_t *)buffer;
1113 i = LittleLong (header->version);
1114 if (i != BSPVERSION && i != 30)
1115 Host_Error ("Mod_LoadBrushModel: %s has wrong version number (%i should be %i or 30 (HalfLife))", mod->name, i, BSPVERSION);
1117 halflifebsp.value = hlbsp;
1119 // swap all the lumps
1120 mod_base = (byte *)header;
1122 for (i=0 ; i<sizeof(dheader_t)/4 ; i++)
1123 ((int *)header)[i] = LittleLong ( ((int *)header)[i]);
1127 // LordHavoc: had to move entity loading above everything to allow parsing various settings from worldspawn
1128 Mod_LoadEntities (&header->lumps[LUMP_ENTITIES]);
1130 Mod_LoadVertexes (&header->lumps[LUMP_VERTEXES]);
1131 Mod_LoadEdges (&header->lumps[LUMP_EDGES]);
1132 Mod_LoadSurfedges (&header->lumps[LUMP_SURFEDGES]);
1133 Mod_LoadTextures (&header->lumps[LUMP_TEXTURES]);
1134 Mod_LoadLighting (&header->lumps[LUMP_LIGHTING]);
1135 Mod_LoadPlanes (&header->lumps[LUMP_PLANES]);
1136 Mod_LoadTexinfo (&header->lumps[LUMP_TEXINFO]);
1137 Mod_LoadFaces (&header->lumps[LUMP_FACES]);
1138 Mod_LoadMarksurfaces (&header->lumps[LUMP_MARKSURFACES]);
1139 Mod_LoadVisibility (&header->lumps[LUMP_VISIBILITY]);
1140 Mod_LoadLeafs (&header->lumps[LUMP_LEAFS]);
1141 Mod_LoadNodes (&header->lumps[LUMP_NODES]);
1142 Mod_LoadClipnodes (&header->lumps[LUMP_CLIPNODES]);
1143 // Mod_LoadEntities (&header->lumps[LUMP_ENTITIES]);
1144 Mod_LoadSubmodels (&header->lumps[LUMP_MODELS]);
1148 mod->numframes = 2; // regular and alternate animation
1151 // set up the submodels (FIXME: this is confusing)
1153 for (i=0 ; i<mod->numsubmodels ; i++)
1155 bm = &mod->submodels[i];
1157 mod->hulls[0].firstclipnode = bm->headnode[0];
1158 for (j=1 ; j<MAX_MAP_HULLS ; j++)
1160 mod->hulls[j].firstclipnode = bm->headnode[j];
1161 mod->hulls[j].lastclipnode = mod->numclipnodes-1;
1164 mod->firstmodelsurface = bm->firstface;
1165 mod->nummodelsurfaces = bm->numfaces;
1167 VectorCopy (bm->maxs, mod->maxs);
1168 VectorCopy (bm->mins, mod->mins);
1170 mod->radius = RadiusFromBounds (mod->mins, mod->maxs);
1172 mod->numleafs = bm->visleafs;
1174 if (isworldmodel && i < (mod->numsubmodels-1)) // LordHavoc: only register submodels if it is the world (prevents bsp models from replacing world submodels)
1175 { // duplicate the basic information
1178 sprintf (name, "*%i", i+1);
1179 loadmodel = Mod_FindName (name);
1181 strcpy (loadmodel->name, name);