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;
345 if (hlbsp) // LordHavoc: load the colored lighting data straight
347 loadmodel->lightdata = Hunk_AllocName ( l->filelen, loadname);
348 memcpy (loadmodel->lightdata, mod_base + l->fileofs, l->filelen);
350 else // LordHavoc: bsp version 29 (normal white lighting)
352 // LordHavoc: hope is not lost yet, check for a .lit file to load
353 strcpy(litfilename, loadmodel->name);
354 COM_StripExtension(litfilename, litfilename);
355 strcat(litfilename, ".lit");
356 data = (byte*) COM_LoadHunkFile (litfilename, false);
359 if (data[0] == 'Q' && data[1] == 'L' && data[2] == 'I' && data[3] == 'T')
361 i = LittleLong(((int *)data)[1]);
364 loadmodel->lightdata = data + 8;
368 Con_Printf("Unknown .lit file version (%d)\n", i);
371 Con_Printf("Corrupt .lit file (old version?), ignoring\n");
373 // LordHavoc: oh well, expand the white lighting data
374 loadmodel->lightdata = Hunk_AllocName ( l->filelen*3, litfilename);
375 in = loadmodel->lightdata + l->filelen*2; // place the file at the end, so it will not be overwritten until the very last write
376 out = loadmodel->lightdata;
377 memcpy (in, mod_base + l->fileofs, l->filelen);
378 for (i = 0;i < l->filelen;i++)
394 void Mod_LoadVisibility (lump_t *l)
398 loadmodel->visdata = NULL;
401 loadmodel->visdata = Hunk_AllocName ( l->filelen, loadname);
402 memcpy (loadmodel->visdata, mod_base + l->fileofs, l->filelen);
405 void CL_ParseEntityLump(char *entdata);
407 extern qboolean isworldmodel;
414 void Mod_LoadEntities (lump_t *l)
418 loadmodel->entities = NULL;
421 loadmodel->entities = Hunk_AllocName ( l->filelen, loadname);
422 memcpy (loadmodel->entities, mod_base + l->fileofs, l->filelen);
425 CL_ParseEntityLump(loadmodel->entities);
434 void Mod_LoadVertexes (lump_t *l)
440 in = (void *)(mod_base + l->fileofs);
441 if (l->filelen % sizeof(*in))
442 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
443 count = l->filelen / sizeof(*in);
444 out = Hunk_AllocName ( count*sizeof(*out), loadname);
446 loadmodel->vertexes = out;
447 loadmodel->numvertexes = count;
449 for ( i=0 ; i<count ; i++, in++, out++)
451 out->position[0] = LittleFloat (in->point[0]);
452 out->position[1] = LittleFloat (in->point[1]);
453 out->position[2] = LittleFloat (in->point[2]);
462 void Mod_LoadSubmodels (lump_t *l)
468 in = (void *)(mod_base + l->fileofs);
469 if (l->filelen % sizeof(*in))
470 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
471 count = l->filelen / sizeof(*in);
472 out = Hunk_AllocName ( count*sizeof(*out), loadname);
474 loadmodel->submodels = out;
475 loadmodel->numsubmodels = count;
477 for ( i=0 ; i<count ; i++, in++, out++)
479 for (j=0 ; j<3 ; j++)
480 { // spread the mins / maxs by a pixel
481 out->mins[j] = LittleFloat (in->mins[j]) - 1;
482 out->maxs[j] = LittleFloat (in->maxs[j]) + 1;
483 out->origin[j] = LittleFloat (in->origin[j]);
485 for (j=0 ; j<MAX_MAP_HULLS ; j++)
486 out->headnode[j] = LittleLong (in->headnode[j]);
487 out->visleafs = LittleLong (in->visleafs);
488 out->firstface = LittleLong (in->firstface);
489 out->numfaces = LittleLong (in->numfaces);
498 void Mod_LoadEdges (lump_t *l)
504 in = (void *)(mod_base + l->fileofs);
505 if (l->filelen % sizeof(*in))
506 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
507 count = l->filelen / sizeof(*in);
508 out = Hunk_AllocName ( (count + 1) * sizeof(*out), loadname);
510 loadmodel->edges = out;
511 loadmodel->numedges = count;
513 for ( i=0 ; i<count ; i++, in++, out++)
515 out->v[0] = (unsigned short)LittleShort(in->v[0]);
516 out->v[1] = (unsigned short)LittleShort(in->v[1]);
525 void Mod_LoadTexinfo (lump_t *l)
533 in = (void *)(mod_base + l->fileofs);
534 if (l->filelen % sizeof(*in))
535 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
536 count = l->filelen / sizeof(*in);
537 out = Hunk_AllocName ( count*sizeof(*out), loadname);
539 loadmodel->texinfo = out;
540 loadmodel->numtexinfo = count;
542 for ( i=0 ; i<count ; i++, in++, out++)
544 for (j=0 ; j<8 ; j++)
545 out->vecs[0][j] = LittleFloat (in->vecs[0][j]);
546 len1 = Length (out->vecs[0]);
547 len2 = Length (out->vecs[1]);
548 len1 = (len1 + len2)/2;
551 else if (len1 < 0.49)
553 else if (len1 < 0.99)
558 if (len1 + len2 < 0.001)
559 out->mipadjust = 1; // don't crash
561 out->mipadjust = 1 / floor( (len1+len2)/2 + 0.1 );
564 miptex = LittleLong (in->miptex);
565 out->flags = LittleLong (in->flags);
567 if (!loadmodel->textures)
569 out->texture = r_notexture_mip; // checkerboard texture
571 out->texture->transparent = FALSE;
575 if (miptex >= loadmodel->numtextures)
576 Host_Error ("miptex >= loadmodel->numtextures");
577 out->texture = loadmodel->textures[miptex];
580 out->texture = r_notexture_mip; // texture not found
582 out->texture->transparent = FALSE;
592 Fills in s->texturemins[] and s->extents[]
595 void CalcSurfaceExtents (msurface_t *s)
597 float mins[2], maxs[2], val;
601 int bmins[2], bmaxs[2];
603 mins[0] = mins[1] = 999999;
604 maxs[0] = maxs[1] = -99999;
608 for (i=0 ; i<s->numedges ; i++)
610 e = loadmodel->surfedges[s->firstedge+i];
612 v = &loadmodel->vertexes[loadmodel->edges[e].v[0]];
614 v = &loadmodel->vertexes[loadmodel->edges[-e].v[1]];
616 for (j=0 ; j<2 ; j++)
618 val = v->position[0] * tex->vecs[j][0] +
619 v->position[1] * tex->vecs[j][1] +
620 v->position[2] * tex->vecs[j][2] +
629 for (i=0 ; i<2 ; i++)
631 bmins[i] = floor(mins[i]/16);
632 bmaxs[i] = ceil(maxs[i]/16);
634 s->texturemins[i] = bmins[i] * 16;
635 s->extents[i] = (bmaxs[i] - bmins[i]) * 16;
636 if ( !(tex->flags & TEX_SPECIAL) && s->extents[i] > 512 /* 256 */ )
637 Host_Error ("Bad surface extents");
641 void GL_SubdivideSurface (msurface_t *fa);
643 extern char skyname[];
650 void Mod_LoadFaces (lump_t *l)
654 int i, count, surfnum;
657 in = (void *)(mod_base + l->fileofs);
658 if (l->filelen % sizeof(*in))
659 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
660 count = l->filelen / sizeof(*in);
661 out = Hunk_AllocName ( count*sizeof(*out), loadname);
663 loadmodel->surfaces = out;
664 loadmodel->numsurfaces = count;
666 for ( surfnum=0 ; surfnum<count ; surfnum++, in++, out++)
668 out->firstedge = LittleLong(in->firstedge);
669 out->numedges = LittleShort(in->numedges);
672 planenum = LittleShort(in->planenum);
673 side = LittleShort(in->side);
675 out->flags |= SURF_PLANEBACK;
677 out->plane = loadmodel->planes + planenum;
679 out->texinfo = loadmodel->texinfo + LittleShort (in->texinfo);
681 CalcSurfaceExtents (out);
685 for (i=0 ; i<MAXLIGHTMAPS ; i++)
686 out->styles[i] = in->styles[i];
687 i = LittleLong(in->lightofs);
690 else if (hlbsp) // LordHavoc: HalfLife map (bsp version 30)
691 out->samples = loadmodel->lightdata + i;
692 else // LordHavoc: white lighting (bsp version 29)
693 out->samples = loadmodel->lightdata + (i * 3);
695 // set the drawing flags flag
697 // if (!strncmp(out->texinfo->texture->name,"sky",3)) // sky
698 // LordHavoc: faster check
699 if ((out->texinfo->texture->name[0] == 's' || out->texinfo->texture->name[0] == 'S')
700 && (out->texinfo->texture->name[1] == 'k' || out->texinfo->texture->name[1] == 'K')
701 && (out->texinfo->texture->name[2] == 'y' || out->texinfo->texture->name[2] == 'Y'))
703 // LordHavoc: for consistency reasons, mark sky as fullbright and solid as well
704 out->flags |= (SURF_DRAWSKY | SURF_DRAWTILED | SURF_DRAWFULLBRIGHT | SURF_DRAWNOALPHA);
705 GL_SubdivideSurface (out); // cut up polygon for warps
709 // if (!strncmp(out->texinfo->texture->name,"*",1)) // turbulent
710 if (out->texinfo->texture->name[0] == '*') // LordHavoc: faster check
712 out->flags |= (SURF_DRAWTURB | SURF_DRAWTILED);
713 // LordHavoc: some turbulent textures should be fullbright and solid
714 if (!strncmp(out->texinfo->texture->name,"*lava",5)
715 || !strncmp(out->texinfo->texture->name,"*teleport",9)
716 || !strncmp(out->texinfo->texture->name,"*rift",5)) // Scourge of Armagon texture
717 out->flags |= (SURF_DRAWFULLBRIGHT | SURF_DRAWNOALPHA);
718 for (i=0 ; i<2 ; i++)
720 out->extents[i] = 16384;
721 out->texturemins[i] = -8192;
723 GL_SubdivideSurface (out); // cut up polygon for warps
736 void Mod_SetParent (mnode_t *node, mnode_t *parent)
738 node->parent = parent;
739 if (node->contents < 0)
741 Mod_SetParent (node->children[0], node);
742 Mod_SetParent (node->children[1], node);
750 void Mod_LoadNodes (lump_t *l)
756 in = (void *)(mod_base + l->fileofs);
757 if (l->filelen % sizeof(*in))
758 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
759 count = l->filelen / sizeof(*in);
760 out = Hunk_AllocName ( count*sizeof(*out), loadname);
762 loadmodel->nodes = out;
763 loadmodel->numnodes = count;
765 for ( i=0 ; i<count ; i++, in++, out++)
767 for (j=0 ; j<3 ; j++)
769 out->minmaxs[j] = LittleShort (in->mins[j]);
770 out->minmaxs[3+j] = LittleShort (in->maxs[j]);
773 p = LittleLong(in->planenum);
774 out->plane = loadmodel->planes + p;
776 out->firstsurface = LittleShort (in->firstface);
777 out->numsurfaces = LittleShort (in->numfaces);
779 for (j=0 ; j<2 ; j++)
781 p = LittleShort (in->children[j]);
783 out->children[j] = loadmodel->nodes + p;
785 out->children[j] = (mnode_t *)(loadmodel->leafs + (-1 - p));
789 Mod_SetParent (loadmodel->nodes, NULL); // sets nodes and leafs
797 void Mod_LoadLeafs (lump_t *l)
803 in = (void *)(mod_base + l->fileofs);
804 if (l->filelen % sizeof(*in))
805 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
806 count = l->filelen / sizeof(*in);
807 out = Hunk_AllocName ( count*sizeof(*out), loadname);
809 loadmodel->leafs = out;
810 loadmodel->numleafs = count;
812 for ( i=0 ; i<count ; i++, in++, out++)
814 for (j=0 ; j<3 ; j++)
816 out->minmaxs[j] = LittleShort (in->mins[j]);
817 out->minmaxs[3+j] = LittleShort (in->maxs[j]);
820 p = LittleLong(in->contents);
823 out->firstmarksurface = loadmodel->marksurfaces +
824 LittleShort(in->firstmarksurface);
825 out->nummarksurfaces = LittleShort(in->nummarksurfaces);
827 p = LittleLong(in->visofs);
829 out->compressed_vis = NULL;
831 out->compressed_vis = loadmodel->visdata + p;
834 for (j=0 ; j<4 ; j++)
835 out->ambient_sound_level[j] = in->ambient_level[j];
837 // gl underwater warp
838 // LordHavoc: disabled underwater warping
840 if (out->contents != CONTENTS_EMPTY)
842 for (j=0 ; j<out->nummarksurfaces ; j++)
843 out->firstmarksurface[j]->flags |= SURF_UNDERWATER;
854 void Mod_LoadClipnodes (lump_t *l)
856 dclipnode_t *in, *out;
860 in = (void *)(mod_base + l->fileofs);
861 if (l->filelen % sizeof(*in))
862 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
863 count = l->filelen / sizeof(*in);
864 out = Hunk_AllocName ( count*sizeof(*out), loadname);
866 loadmodel->clipnodes = out;
867 loadmodel->numclipnodes = count;
869 hull = &loadmodel->hulls[1];
870 hull->clipnodes = out;
871 hull->firstclipnode = 0;
872 hull->lastclipnode = count-1;
873 hull->planes = loadmodel->planes;
874 hull->clip_mins[0] = -16;
875 hull->clip_mins[1] = -16;
876 hull->clip_mins[2] = -24;
877 hull->clip_maxs[0] = 16;
878 hull->clip_maxs[1] = 16;
879 hull->clip_maxs[2] = 32;
881 hull = &loadmodel->hulls[2];
882 hull->clipnodes = out;
883 hull->firstclipnode = 0;
884 hull->lastclipnode = count-1;
885 hull->planes = loadmodel->planes;
886 hull->clip_mins[0] = -32;
887 hull->clip_mins[1] = -32;
888 hull->clip_mins[2] = -24;
889 hull->clip_maxs[0] = 32;
890 hull->clip_maxs[1] = 32;
891 hull->clip_maxs[2] = 64;
893 for (i=0 ; i<count ; i++, out++, in++)
895 out->planenum = LittleLong(in->planenum);
896 out->children[0] = LittleShort(in->children[0]);
897 out->children[1] = LittleShort(in->children[1]);
898 if (out->children[0] >= count || out->children[1] >= count)
899 Host_Error("Corrupt clipping hull (out of range child)\n");
907 Duplicate the drawing hull structure as a clipping hull
910 void Mod_MakeHull0 (void)
917 hull = &loadmodel->hulls[0];
919 in = loadmodel->nodes;
920 count = loadmodel->numnodes;
921 out = Hunk_AllocName ( count*sizeof(*out), loadname);
923 hull->clipnodes = out;
924 hull->firstclipnode = 0;
925 hull->lastclipnode = count-1;
926 hull->planes = loadmodel->planes;
928 for (i=0 ; i<count ; i++, out++, in++)
930 out->planenum = in->plane - loadmodel->planes;
931 for (j=0 ; j<2 ; j++)
933 child = in->children[j];
934 if (child->contents < 0)
935 out->children[j] = child->contents;
937 out->children[j] = child - loadmodel->nodes;
947 void Mod_LoadMarksurfaces (lump_t *l)
953 in = (void *)(mod_base + l->fileofs);
954 if (l->filelen % sizeof(*in))
955 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
956 count = l->filelen / sizeof(*in);
957 out = Hunk_AllocName ( count*sizeof(*out), loadname);
959 loadmodel->marksurfaces = out;
960 loadmodel->nummarksurfaces = count;
962 for ( i=0 ; i<count ; i++)
964 j = LittleShort(in[i]);
965 if (j >= loadmodel->numsurfaces)
966 Host_Error ("Mod_ParseMarksurfaces: bad surface number");
967 out[i] = loadmodel->surfaces + j;
976 void Mod_LoadSurfedges (lump_t *l)
981 in = (void *)(mod_base + l->fileofs);
982 if (l->filelen % sizeof(*in))
983 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
984 count = l->filelen / sizeof(*in);
985 out = Hunk_AllocName ( count*sizeof(*out), loadname);
987 loadmodel->surfedges = out;
988 loadmodel->numsurfedges = count;
990 for ( i=0 ; i<count ; i++)
991 out[i] = LittleLong (in[i]);
1000 void Mod_LoadPlanes (lump_t *l)
1008 in = (void *)(mod_base + l->fileofs);
1009 if (l->filelen % sizeof(*in))
1010 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
1011 count = l->filelen / sizeof(*in);
1012 out = Hunk_AllocName ( count*2*sizeof(*out), loadname);
1014 loadmodel->planes = out;
1015 loadmodel->numplanes = count;
1017 for ( i=0 ; i<count ; i++, in++, out++)
1020 for (j=0 ; j<3 ; j++)
1022 out->normal[j] = LittleFloat (in->normal[j]);
1023 // if (out->normal[j] < 0)
1027 out->dist = LittleFloat (in->dist);
1028 out->type = LittleLong (in->type);
1029 // out->signbits = bits;
1030 BoxOnPlaneSideClassify(out);
1039 void Mod_LoadBrushModel (model_t *mod, void *buffer)
1045 loadmodel->type = mod_brush;
1047 header = (dheader_t *)buffer;
1049 i = LittleLong (header->version);
1050 if (i != BSPVERSION && i != 30)
1051 Host_Error ("Mod_LoadBrushModel: %s has wrong version number (%i should be %i or 30 (HalfLife))", mod->name, i, BSPVERSION);
1053 halflifebsp.value = hlbsp;
1055 // swap all the lumps
1056 mod_base = (byte *)header;
1058 for (i=0 ; i<sizeof(dheader_t)/4 ; i++)
1059 ((int *)header)[i] = LittleLong ( ((int *)header)[i]);
1063 // LordHavoc: had to move entity loading above everything to allow parsing various settings from worldspawn
1064 Mod_LoadEntities (&header->lumps[LUMP_ENTITIES]);
1066 Mod_LoadVertexes (&header->lumps[LUMP_VERTEXES]);
1067 Mod_LoadEdges (&header->lumps[LUMP_EDGES]);
1068 Mod_LoadSurfedges (&header->lumps[LUMP_SURFEDGES]);
1069 Mod_LoadTextures (&header->lumps[LUMP_TEXTURES]);
1070 Mod_LoadLighting (&header->lumps[LUMP_LIGHTING]);
1071 Mod_LoadPlanes (&header->lumps[LUMP_PLANES]);
1072 Mod_LoadTexinfo (&header->lumps[LUMP_TEXINFO]);
1073 Mod_LoadFaces (&header->lumps[LUMP_FACES]);
1074 Mod_LoadMarksurfaces (&header->lumps[LUMP_MARKSURFACES]);
1075 Mod_LoadVisibility (&header->lumps[LUMP_VISIBILITY]);
1076 Mod_LoadLeafs (&header->lumps[LUMP_LEAFS]);
1077 Mod_LoadNodes (&header->lumps[LUMP_NODES]);
1078 Mod_LoadClipnodes (&header->lumps[LUMP_CLIPNODES]);
1079 // Mod_LoadEntities (&header->lumps[LUMP_ENTITIES]);
1080 Mod_LoadSubmodels (&header->lumps[LUMP_MODELS]);
1084 mod->numframes = 2; // regular and alternate animation
1087 // set up the submodels (FIXME: this is confusing)
1089 for (i=0 ; i<mod->numsubmodels ; i++)
1091 bm = &mod->submodels[i];
1093 mod->hulls[0].firstclipnode = bm->headnode[0];
1094 for (j=1 ; j<MAX_MAP_HULLS ; j++)
1096 mod->hulls[j].firstclipnode = bm->headnode[j];
1097 mod->hulls[j].lastclipnode = mod->numclipnodes-1;
1100 mod->firstmodelsurface = bm->firstface;
1101 mod->nummodelsurfaces = bm->numfaces;
1103 VectorCopy (bm->maxs, mod->maxs);
1104 VectorCopy (bm->mins, mod->mins);
1106 mod->radius = RadiusFromBounds (mod->mins, mod->maxs);
1108 mod->numleafs = bm->visleafs;
1110 if (isworldmodel && i < (mod->numsubmodels-1)) // LordHavoc: only register submodels if it is the world (prevents bsp models from replacing world submodels)
1111 { // duplicate the basic information
1114 sprintf (name, "*%i", i+1);
1115 loadmodel = Mod_FindName (name);
1117 strcpy (loadmodel->name, name);