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] == 0 && out[1] == 0 && out[2] == 255) // HL transparent color (pure blue)
198 out[0] = out[1] = out[2] = out[3] = 0;
204 else if (r_fullbrights.value && tx->name[0] != '*')
206 for (j = 0;j < tx->width*tx->height;j++)
208 if (data[j] >= 224) // fullbright
216 else // no texture, and no external replacement texture was found
218 tx->width = tx->height = 16;
219 data = (byte *)((int) r_notexture_mip + r_notexture_mip->offsets[0]);
224 tx->width = image_width;
225 tx->height = image_height;
227 if (!hlbsp && !strncmp(tx->name,"sky",3) && tx->width == 256 && tx->height == 128) // LordHavoc: HL sky textures are entirely unrelated
229 tx->transparent = FALSE;
230 R_InitSky (data, bytesperpixel);
238 tx->transparent = false;
239 data2 = qmalloc(tx->width*tx->height);
240 for (j = 0;j < tx->width*tx->height;j++)
241 data2[j] = data[j] >= 224 ? 0 : data[j]; // no fullbrights
242 tx->gl_texturenum = GL_LoadTexture (tx->name, tx->width, tx->height, data2, true, false, 1);
243 strcpy(name, tx->name);
244 strcat(name, "_glow");
245 for (j = 0;j < tx->width*tx->height;j++)
246 data2[j] = data[j] >= 224 ? data[j] : 0; // only fullbrights
247 tx->gl_glowtexturenum = GL_LoadTexture (name, tx->width, tx->height, data2, true, false, 1);
252 tx->transparent = transparent;
253 tx->gl_texturenum = GL_LoadTexture (tx->name, tx->width, tx->height, data, true, transparent, bytesperpixel);
254 tx->gl_glowtexturenum = 0;
262 // sequence the animations
264 for (i=0 ; i<m->nummiptex ; i++)
266 tx = loadmodel->textures[i];
267 if (!tx || tx->name[0] != '+')
270 continue; // allready sequenced
272 // find the number of frames in the animation
273 memset (anims, 0, sizeof(anims));
274 memset (altanims, 0, sizeof(altanims));
278 if (max >= 'a' && max <= 'z')
280 if (max >= '0' && max <= '9')
287 else if (max >= 'A' && max <= 'J')
291 altanims[altmax] = tx;
295 Host_Error ("Bad animating texture %s", tx->name);
297 for (j=i+1 ; j<m->nummiptex ; j++)
299 tx2 = loadmodel->textures[j];
300 if (!tx2 || tx2->name[0] != '+')
302 if (strcmp (tx2->name+2, tx->name+2))
306 if (num >= 'a' && num <= 'z')
308 if (num >= '0' && num <= '9')
315 else if (num >= 'A' && num <= 'J')
323 Host_Error ("Bad animating texture %s", tx->name);
327 // link them all together
328 for (j=0 ; j<max ; j++)
332 Host_Error ("Missing frame %i of %s",j, tx->name);
333 tx2->anim_total = max * ANIM_CYCLE;
334 tx2->anim_min = j * ANIM_CYCLE;
335 tx2->anim_max = (j+1) * ANIM_CYCLE;
336 tx2->anim_next = anims[ (j+1)%max ];
338 tx2->alternate_anims = altanims[0];
340 for (j=0 ; j<altmax ; j++)
344 Host_Error ("Missing frame %i of %s",j, tx->name);
345 tx2->anim_total = altmax * ANIM_CYCLE;
346 tx2->anim_min = j * ANIM_CYCLE;
347 tx2->anim_max = (j+1) * ANIM_CYCLE;
348 tx2->anim_next = altanims[ (j+1)%altmax ];
350 tx2->alternate_anims = anims[0];
360 void Mod_LoadLighting (lump_t *l)
363 byte *in, *out, *data;
365 char litfilename[1024];
366 loadmodel->lightdata = NULL;
367 if (hlbsp) // LordHavoc: load the colored lighting data straight
369 loadmodel->lightdata = Hunk_AllocName ( l->filelen, va("%s lightmaps", loadname));
370 memcpy (loadmodel->lightdata, mod_base + l->fileofs, l->filelen);
372 else // LordHavoc: bsp version 29 (normal white lighting)
374 // LordHavoc: hope is not lost yet, check for a .lit file to load
375 strcpy(litfilename, loadmodel->name);
376 COM_StripExtension(litfilename, litfilename);
377 strcat(litfilename, ".lit");
378 data = (byte*) COM_LoadHunkFile (litfilename, false);
381 if (data[0] == 'Q' && data[1] == 'L' && data[2] == 'I' && data[3] == 'T')
383 i = LittleLong(((int *)data)[1]);
386 Con_DPrintf("%s loaded", litfilename);
387 loadmodel->lightdata = data + 8;
391 Con_Printf("Unknown .lit file version (%d)\n", i);
394 Con_Printf("Corrupt .lit file (old version?), ignoring\n");
396 // LordHavoc: oh well, expand the white lighting data
399 loadmodel->lightdata = Hunk_AllocName ( l->filelen*3, va("%s lightmaps", loadname));
400 in = loadmodel->lightdata + l->filelen*2; // place the file at the end, so it will not be overwritten until the very last write
401 out = loadmodel->lightdata;
402 memcpy (in, mod_base + l->fileofs, l->filelen);
403 for (i = 0;i < l->filelen;i++)
419 void Mod_LoadVisibility (lump_t *l)
423 loadmodel->visdata = NULL;
426 loadmodel->visdata = Hunk_AllocName ( l->filelen, va("%s visdata", loadname));
427 memcpy (loadmodel->visdata, mod_base + l->fileofs, l->filelen);
430 void CL_ParseEntityLump(char *entdata);
432 extern qboolean isworldmodel;
439 void Mod_LoadEntities (lump_t *l)
443 loadmodel->entities = NULL;
446 loadmodel->entities = Hunk_AllocName ( l->filelen, va("%s entities", loadname));
447 memcpy (loadmodel->entities, mod_base + l->fileofs, l->filelen);
450 CL_ParseEntityLump(loadmodel->entities);
459 void Mod_LoadVertexes (lump_t *l)
465 in = (void *)(mod_base + l->fileofs);
466 if (l->filelen % sizeof(*in))
467 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
468 count = l->filelen / sizeof(*in);
469 out = Hunk_AllocName ( count*sizeof(*out), va("%s vertices", loadname));
471 loadmodel->vertexes = out;
472 loadmodel->numvertexes = count;
474 for ( i=0 ; i<count ; i++, in++, out++)
476 out->position[0] = LittleFloat (in->point[0]);
477 out->position[1] = LittleFloat (in->point[1]);
478 out->position[2] = LittleFloat (in->point[2]);
487 void Mod_LoadSubmodels (lump_t *l)
493 in = (void *)(mod_base + l->fileofs);
494 if (l->filelen % sizeof(*in))
495 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
496 count = l->filelen / sizeof(*in);
497 out = Hunk_AllocName ( count*sizeof(*out), va("%s submodels", loadname));
499 loadmodel->submodels = out;
500 loadmodel->numsubmodels = count;
502 for ( i=0 ; i<count ; i++, in++, out++)
504 for (j=0 ; j<3 ; j++)
505 { // spread the mins / maxs by a pixel
506 out->mins[j] = LittleFloat (in->mins[j]) - 1;
507 out->maxs[j] = LittleFloat (in->maxs[j]) + 1;
508 out->origin[j] = LittleFloat (in->origin[j]);
510 for (j=0 ; j<MAX_MAP_HULLS ; j++)
511 out->headnode[j] = LittleLong (in->headnode[j]);
512 out->visleafs = LittleLong (in->visleafs);
513 out->firstface = LittleLong (in->firstface);
514 out->numfaces = LittleLong (in->numfaces);
523 void Mod_LoadEdges (lump_t *l)
529 in = (void *)(mod_base + l->fileofs);
530 if (l->filelen % sizeof(*in))
531 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
532 count = l->filelen / sizeof(*in);
533 out = Hunk_AllocName ( (count + 1) * sizeof(*out), va("%s edges", loadname));
535 loadmodel->edges = out;
536 loadmodel->numedges = count;
538 for ( i=0 ; i<count ; i++, in++, out++)
540 out->v[0] = (unsigned short)LittleShort(in->v[0]);
541 out->v[1] = (unsigned short)LittleShort(in->v[1]);
550 void Mod_LoadTexinfo (lump_t *l)
558 in = (void *)(mod_base + l->fileofs);
559 if (l->filelen % sizeof(*in))
560 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
561 count = l->filelen / sizeof(*in);
562 out = Hunk_AllocName ( count*sizeof(*out), va("%s texinfo", loadname));
564 loadmodel->texinfo = out;
565 loadmodel->numtexinfo = count;
567 for ( i=0 ; i<count ; i++, in++, out++)
569 for (k=0 ; k<2 ; k++)
570 for (j=0 ; j<4 ; j++)
571 out->vecs[k][j] = LittleFloat (in->vecs[k][j]);
572 len1 = Length (out->vecs[0]);
573 len2 = Length (out->vecs[1]);
574 len1 = (len1 + len2)/2;
577 else if (len1 < 0.49)
579 else if (len1 < 0.99)
584 if (len1 + len2 < 0.001)
585 out->mipadjust = 1; // don't crash
587 out->mipadjust = 1 / floor( (len1+len2)/2 + 0.1 );
590 miptex = LittleLong (in->miptex);
591 out->flags = LittleLong (in->flags);
593 if (!loadmodel->textures)
595 out->texture = r_notexture_mip; // checkerboard texture
597 out->texture->transparent = FALSE;
601 if (miptex >= loadmodel->numtextures)
602 Host_Error ("miptex >= loadmodel->numtextures");
603 out->texture = loadmodel->textures[miptex];
606 out->texture = r_notexture_mip; // texture not found
608 out->texture->transparent = FALSE;
618 Fills in s->texturemins[] and s->extents[]
621 void CalcSurfaceExtents (msurface_t *s)
623 float mins[2], maxs[2], val;
627 int bmins[2], bmaxs[2];
629 mins[0] = mins[1] = 999999;
630 maxs[0] = maxs[1] = -99999;
634 for (i=0 ; i<s->numedges ; i++)
636 e = loadmodel->surfedges[s->firstedge+i];
638 v = &loadmodel->vertexes[loadmodel->edges[e].v[0]];
640 v = &loadmodel->vertexes[loadmodel->edges[-e].v[1]];
642 for (j=0 ; j<2 ; j++)
644 val = v->position[0] * tex->vecs[j][0] +
645 v->position[1] * tex->vecs[j][1] +
646 v->position[2] * tex->vecs[j][2] +
655 for (i=0 ; i<2 ; i++)
657 bmins[i] = floor(mins[i]/16);
658 bmaxs[i] = ceil(maxs[i]/16);
660 s->texturemins[i] = bmins[i] * 16;
661 s->extents[i] = (bmaxs[i] - bmins[i]) * 16;
662 if ( !(tex->flags & TEX_SPECIAL) && s->extents[i] > 512 /* 256 */ )
663 Host_Error ("Bad surface extents");
667 void GL_SubdivideSurface (msurface_t *fa);
669 extern char skyname[];
676 void Mod_LoadFaces (lump_t *l)
680 int i, count, surfnum;
683 in = (void *)(mod_base + l->fileofs);
684 if (l->filelen % sizeof(*in))
685 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
686 count = l->filelen / sizeof(*in);
687 out = Hunk_AllocName ( count*sizeof(*out), va("%s faces", loadname));
689 loadmodel->surfaces = out;
690 loadmodel->numsurfaces = count;
692 for ( surfnum=0 ; surfnum<count ; surfnum++, in++, out++)
694 out->firstedge = LittleLong(in->firstedge);
695 out->numedges = LittleShort(in->numedges);
698 planenum = LittleShort(in->planenum);
699 side = LittleShort(in->side);
701 out->flags |= SURF_PLANEBACK;
703 out->plane = loadmodel->planes + planenum;
705 out->texinfo = loadmodel->texinfo + LittleShort (in->texinfo);
707 CalcSurfaceExtents (out);
711 for (i=0 ; i<MAXLIGHTMAPS ; i++)
712 out->styles[i] = in->styles[i];
713 i = LittleLong(in->lightofs);
716 else if (hlbsp) // LordHavoc: HalfLife map (bsp version 30)
717 out->samples = loadmodel->lightdata + i;
718 else // LordHavoc: white lighting (bsp version 29)
719 out->samples = loadmodel->lightdata + (i * 3);
721 // set the drawing flags flag
723 // if (!strncmp(out->texinfo->texture->name,"sky",3)) // sky
724 // LordHavoc: faster check
725 if ((out->texinfo->texture->name[0] == 's' || out->texinfo->texture->name[0] == 'S')
726 && (out->texinfo->texture->name[1] == 'k' || out->texinfo->texture->name[1] == 'K')
727 && (out->texinfo->texture->name[2] == 'y' || out->texinfo->texture->name[2] == 'Y'))
729 // LordHavoc: for consistency reasons, mark sky as fullbright and solid as well
730 out->flags |= (SURF_DRAWSKY | SURF_DRAWTILED | SURF_DRAWFULLBRIGHT | SURF_DRAWNOALPHA);
731 GL_SubdivideSurface (out); // cut up polygon for warps
735 // if (!strncmp(out->texinfo->texture->name,"*",1)) // turbulent
736 if (out->texinfo->texture->name[0] == '*') // LordHavoc: faster check
738 out->flags |= (SURF_DRAWTURB | SURF_DRAWTILED);
739 // LordHavoc: some turbulent textures should be fullbright and solid
740 if (!strncmp(out->texinfo->texture->name,"*lava",5)
741 || !strncmp(out->texinfo->texture->name,"*teleport",9)
742 || !strncmp(out->texinfo->texture->name,"*rift",5)) // Scourge of Armagon texture
743 out->flags |= (SURF_DRAWFULLBRIGHT | SURF_DRAWNOALPHA);
744 for (i=0 ; i<2 ; i++)
746 out->extents[i] = 16384;
747 out->texturemins[i] = -8192;
749 GL_SubdivideSurface (out); // cut up polygon for warps
762 void Mod_SetParent (mnode_t *node, mnode_t *parent)
764 node->parent = parent;
765 if (node->contents < 0)
767 Mod_SetParent (node->children[0], node);
768 Mod_SetParent (node->children[1], node);
776 void Mod_LoadNodes (lump_t *l)
782 in = (void *)(mod_base + l->fileofs);
783 if (l->filelen % sizeof(*in))
784 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
785 count = l->filelen / sizeof(*in);
786 out = Hunk_AllocName ( count*sizeof(*out), va("%s nodes", loadname));
788 loadmodel->nodes = out;
789 loadmodel->numnodes = count;
791 for ( i=0 ; i<count ; i++, in++, out++)
793 for (j=0 ; j<3 ; j++)
795 out->minmaxs[j] = LittleShort (in->mins[j]);
796 out->minmaxs[3+j] = LittleShort (in->maxs[j]);
799 p = LittleLong(in->planenum);
800 out->plane = loadmodel->planes + p;
802 out->firstsurface = LittleShort (in->firstface);
803 out->numsurfaces = LittleShort (in->numfaces);
805 for (j=0 ; j<2 ; j++)
807 p = LittleShort (in->children[j]);
809 out->children[j] = loadmodel->nodes + p;
811 out->children[j] = (mnode_t *)(loadmodel->leafs + (-1 - p));
815 Mod_SetParent (loadmodel->nodes, NULL); // sets nodes and leafs
823 void Mod_LoadLeafs (lump_t *l)
829 in = (void *)(mod_base + l->fileofs);
830 if (l->filelen % sizeof(*in))
831 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
832 count = l->filelen / sizeof(*in);
833 out = Hunk_AllocName ( count*sizeof(*out), va("%s leafs", loadname));
835 loadmodel->leafs = out;
836 loadmodel->numleafs = count;
838 for ( i=0 ; i<count ; i++, in++, out++)
840 for (j=0 ; j<3 ; j++)
842 out->minmaxs[j] = LittleShort (in->mins[j]);
843 out->minmaxs[3+j] = LittleShort (in->maxs[j]);
846 p = LittleLong(in->contents);
849 out->firstmarksurface = loadmodel->marksurfaces +
850 LittleShort(in->firstmarksurface);
851 out->nummarksurfaces = LittleShort(in->nummarksurfaces);
853 p = LittleLong(in->visofs);
855 out->compressed_vis = NULL;
857 out->compressed_vis = loadmodel->visdata + p;
860 for (j=0 ; j<4 ; j++)
861 out->ambient_sound_level[j] = in->ambient_level[j];
863 // gl underwater warp
864 // LordHavoc: disabled underwater warping
866 if (out->contents != CONTENTS_EMPTY)
868 for (j=0 ; j<out->nummarksurfaces ; j++)
869 out->firstmarksurface[j]->flags |= SURF_UNDERWATER;
880 void Mod_LoadClipnodes (lump_t *l)
882 dclipnode_t *in, *out;
886 in = (void *)(mod_base + l->fileofs);
887 if (l->filelen % sizeof(*in))
888 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
889 count = l->filelen / sizeof(*in);
890 out = Hunk_AllocName ( count*sizeof(*out), va("%s clipnodes", loadname));
892 loadmodel->clipnodes = out;
893 loadmodel->numclipnodes = count;
897 hull = &loadmodel->hulls[1];
898 hull->clipnodes = out;
899 hull->firstclipnode = 0;
900 hull->lastclipnode = count-1;
901 hull->planes = loadmodel->planes;
902 hull->clip_mins[0] = -16;
903 hull->clip_mins[1] = -16;
904 hull->clip_mins[2] = -36;
905 hull->clip_maxs[0] = 16;
906 hull->clip_maxs[1] = 16;
907 hull->clip_maxs[2] = 36;
909 hull = &loadmodel->hulls[2];
910 hull->clipnodes = out;
911 hull->firstclipnode = 0;
912 hull->lastclipnode = count-1;
913 hull->planes = loadmodel->planes;
914 hull->clip_mins[0] = -32;
915 hull->clip_mins[1] = -32;
916 hull->clip_mins[2] = -32;
917 hull->clip_maxs[0] = 32;
918 hull->clip_maxs[1] = 32;
919 hull->clip_maxs[2] = 32;
921 hull = &loadmodel->hulls[3];
922 hull->clipnodes = out;
923 hull->firstclipnode = 0;
924 hull->lastclipnode = count-1;
925 hull->planes = loadmodel->planes;
926 hull->clip_mins[0] = -16;
927 hull->clip_mins[1] = -16;
928 hull->clip_mins[2] = -18;
929 hull->clip_maxs[0] = 16;
930 hull->clip_maxs[1] = 16;
931 hull->clip_maxs[2] = 18;
935 hull = &loadmodel->hulls[1];
936 hull->clipnodes = out;
937 hull->firstclipnode = 0;
938 hull->lastclipnode = count-1;
939 hull->planes = loadmodel->planes;
940 hull->clip_mins[0] = -16;
941 hull->clip_mins[1] = -16;
942 hull->clip_mins[2] = -24;
943 hull->clip_maxs[0] = 16;
944 hull->clip_maxs[1] = 16;
945 hull->clip_maxs[2] = 32;
947 hull = &loadmodel->hulls[2];
948 hull->clipnodes = out;
949 hull->firstclipnode = 0;
950 hull->lastclipnode = count-1;
951 hull->planes = loadmodel->planes;
952 hull->clip_mins[0] = -32;
953 hull->clip_mins[1] = -32;
954 hull->clip_mins[2] = -24;
955 hull->clip_maxs[0] = 32;
956 hull->clip_maxs[1] = 32;
957 hull->clip_maxs[2] = 64;
960 for (i=0 ; i<count ; i++, out++, in++)
962 out->planenum = LittleLong(in->planenum);
963 out->children[0] = LittleShort(in->children[0]);
964 out->children[1] = LittleShort(in->children[1]);
965 if (out->children[0] >= count || out->children[1] >= count)
966 Host_Error("Corrupt clipping hull (out of range child)\n");
974 Duplicate the drawing hull structure as a clipping hull
977 void Mod_MakeHull0 (void)
984 hull = &loadmodel->hulls[0];
986 in = loadmodel->nodes;
987 count = loadmodel->numnodes;
988 out = Hunk_AllocName ( count*sizeof(*out), va("%s hull0", loadname));
990 hull->clipnodes = out;
991 hull->firstclipnode = 0;
992 hull->lastclipnode = count-1;
993 hull->planes = loadmodel->planes;
995 for (i=0 ; i<count ; i++, out++, in++)
997 out->planenum = in->plane - loadmodel->planes;
998 for (j=0 ; j<2 ; j++)
1000 child = in->children[j];
1001 if (child->contents < 0)
1002 out->children[j] = child->contents;
1004 out->children[j] = child - loadmodel->nodes;
1011 Mod_LoadMarksurfaces
1014 void Mod_LoadMarksurfaces (lump_t *l)
1020 in = (void *)(mod_base + l->fileofs);
1021 if (l->filelen % sizeof(*in))
1022 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
1023 count = l->filelen / sizeof(*in);
1024 out = Hunk_AllocName ( count*sizeof(*out), va("%s marksurfaces", loadname));
1026 loadmodel->marksurfaces = out;
1027 loadmodel->nummarksurfaces = count;
1029 for ( i=0 ; i<count ; i++)
1031 j = LittleShort(in[i]);
1032 if (j >= loadmodel->numsurfaces)
1033 Host_Error ("Mod_ParseMarksurfaces: bad surface number");
1034 out[i] = loadmodel->surfaces + j;
1043 void Mod_LoadSurfedges (lump_t *l)
1048 in = (void *)(mod_base + l->fileofs);
1049 if (l->filelen % sizeof(*in))
1050 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
1051 count = l->filelen / sizeof(*in);
1052 out = Hunk_AllocName ( count*sizeof(*out), va("%s surfedges", loadname));
1054 loadmodel->surfedges = out;
1055 loadmodel->numsurfedges = count;
1057 for ( i=0 ; i<count ; i++)
1058 out[i] = LittleLong (in[i]);
1067 void Mod_LoadPlanes (lump_t *l)
1075 in = (void *)(mod_base + l->fileofs);
1076 if (l->filelen % sizeof(*in))
1077 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
1078 count = l->filelen / sizeof(*in);
1079 out = Hunk_AllocName ( count*2*sizeof(*out), va("%s planes", loadname));
1081 loadmodel->planes = out;
1082 loadmodel->numplanes = count;
1084 for ( i=0 ; i<count ; i++, in++, out++)
1087 for (j=0 ; j<3 ; j++)
1089 out->normal[j] = LittleFloat (in->normal[j]);
1090 // if (out->normal[j] < 0)
1094 out->dist = LittleFloat (in->dist);
1095 out->type = LittleLong (in->type);
1096 // out->signbits = bits;
1097 BoxOnPlaneSideClassify(out);
1106 void Mod_LoadBrushModel (model_t *mod, void *buffer)
1112 loadmodel->type = mod_brush;
1114 header = (dheader_t *)buffer;
1116 i = LittleLong (header->version);
1117 if (i != BSPVERSION && i != 30)
1118 Host_Error ("Mod_LoadBrushModel: %s has wrong version number (%i should be %i or 30 (HalfLife))", mod->name, i, BSPVERSION);
1120 halflifebsp.value = hlbsp;
1122 // swap all the lumps
1123 mod_base = (byte *)header;
1125 for (i=0 ; i<sizeof(dheader_t)/4 ; i++)
1126 ((int *)header)[i] = LittleLong ( ((int *)header)[i]);
1130 // LordHavoc: had to move entity loading above everything to allow parsing various settings from worldspawn
1131 Mod_LoadEntities (&header->lumps[LUMP_ENTITIES]);
1133 Mod_LoadVertexes (&header->lumps[LUMP_VERTEXES]);
1134 Mod_LoadEdges (&header->lumps[LUMP_EDGES]);
1135 Mod_LoadSurfedges (&header->lumps[LUMP_SURFEDGES]);
1136 Mod_LoadTextures (&header->lumps[LUMP_TEXTURES]);
1137 Mod_LoadLighting (&header->lumps[LUMP_LIGHTING]);
1138 Mod_LoadPlanes (&header->lumps[LUMP_PLANES]);
1139 Mod_LoadTexinfo (&header->lumps[LUMP_TEXINFO]);
1140 Mod_LoadFaces (&header->lumps[LUMP_FACES]);
1141 Mod_LoadMarksurfaces (&header->lumps[LUMP_MARKSURFACES]);
1142 Mod_LoadVisibility (&header->lumps[LUMP_VISIBILITY]);
1143 Mod_LoadLeafs (&header->lumps[LUMP_LEAFS]);
1144 Mod_LoadNodes (&header->lumps[LUMP_NODES]);
1145 Mod_LoadClipnodes (&header->lumps[LUMP_CLIPNODES]);
1146 // Mod_LoadEntities (&header->lumps[LUMP_ENTITIES]);
1147 Mod_LoadSubmodels (&header->lumps[LUMP_MODELS]);
1151 mod->numframes = 2; // regular and alternate animation
1154 // set up the submodels (FIXME: this is confusing)
1156 for (i=0 ; i<mod->numsubmodels ; i++)
1158 bm = &mod->submodels[i];
1160 mod->hulls[0].firstclipnode = bm->headnode[0];
1161 for (j=1 ; j<MAX_MAP_HULLS ; j++)
1163 mod->hulls[j].firstclipnode = bm->headnode[j];
1164 mod->hulls[j].lastclipnode = mod->numclipnodes-1;
1167 mod->firstmodelsurface = bm->firstface;
1168 mod->nummodelsurfaces = bm->numfaces;
1170 VectorCopy (bm->maxs, mod->maxs);
1171 VectorCopy (bm->mins, mod->mins);
1173 mod->radius = RadiusFromBounds (mod->mins, mod->maxs);
1175 mod->numleafs = bm->visleafs;
1177 if (isworldmodel && i < (mod->numsubmodels-1)) // LordHavoc: only register submodels if it is the world (prevents bsp models from replacing world submodels)
1178 { // duplicate the basic information
1181 sprintf (name, "*%i", i+1);
1182 loadmodel = Mod_FindName (name);
1184 strcpy (loadmodel->name, name);