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));
47 mleaf_t *Mod_PointInLeaf (vec3_t p, model_t *model)
53 if (!model || !model->nodes)
54 Sys_Error ("Mod_PointInLeaf: bad model");
59 if (node->contents < 0)
60 return (mleaf_t *)node;
62 d = DotProduct (p,plane->normal) - plane->dist;
64 node = node->children[0];
66 node = node->children[1];
69 return NULL; // never reached
78 byte *Mod_DecompressVis (byte *in, model_t *model)
80 static byte decompressed[MAX_MAP_LEAFS/8];
85 row = (model->numleafs+7)>>3;
89 { // no vis info, so make all visible
113 } while (out - decompressed < row);
118 byte *Mod_LeafPVS (mleaf_t *leaf, model_t *model)
120 if (leaf == model->leafs)
122 return Mod_DecompressVis (leaf->compressed_vis, model);
127 extern cvar_t r_fullbrights;
134 void Mod_LoadTextures (lump_t *l)
136 int i, j, num, max, altmax, bytesperpixel, freeimage, transparent, fullbrights;
139 texture_t *anims[10];
140 texture_t *altanims[10];
146 loadmodel->textures = NULL;
150 m = (dmiptexlump_t *)(mod_base + l->fileofs);
152 m->nummiptex = LittleLong (m->nummiptex);
154 loadmodel->numtextures = m->nummiptex;
155 loadmodel->textures = Hunk_AllocName (m->nummiptex * sizeof(*loadmodel->textures) , loadname);
157 for (i=0 ; i<m->nummiptex ; i++)
159 m->dataofs[i] = LittleLong(m->dataofs[i]);
160 if (m->dataofs[i] == -1)
162 mt = (miptex_t *)((byte *)m + m->dataofs[i]);
163 mt->width = LittleLong (mt->width);
164 mt->height = LittleLong (mt->height);
165 for (j=0 ; j<MIPLEVELS ; j++)
166 mt->offsets[j] = LittleLong (mt->offsets[j]);
168 if ( (mt->width & 15) || (mt->height & 15) )
169 Host_Error ("Texture %s is not 16 aligned", mt->name);
170 // LordHavoc: rewriting the map texture loader for GLQuake
171 tx = Hunk_AllocName (sizeof(texture_t), loadname );
172 loadmodel->textures[i] = tx;
174 memcpy (tx->name, mt->name, sizeof(tx->name));
175 tx->width = mt->width;
176 tx->height = mt->height;
177 for (j=0 ; j<MIPLEVELS ; j++)
183 data = loadimagepixels(mt->name, FALSE, 0, 0); //tx->width, tx->height);
184 if (!data) // no external texture found
189 if (!hlbsp && mt->offsets[0]) // texture included
191 data = (byte *)((int) mt + mt->offsets[0]);
192 if (r_fullbrights.value && mt->name[0] != '*')
194 for (j = 0;j < tx->width*tx->height;j++)
195 if (data[j] >= 224) // fullbright
202 else // no texture, and no external replacement texture was found
204 tx->width = tx->height = 16;
205 data = (byte *)((int) r_notexture_mip + r_notexture_mip->offsets[0]);
210 tx->width = image_width;
211 tx->height = image_height;
213 if (!hlbsp && !strncmp(mt->name,"sky",3) && tx->width == 256 && tx->height == 128) // LordHavoc: HL sky textures are entirely unrelated
215 tx->transparent = FALSE;
216 R_InitSky (data, bytesperpixel);
220 tx->transparent = transparent;
225 data2 = malloc(tx->width*tx->height);
226 for (j = 0;j < tx->width*tx->height;j++)
227 data2[j] = data[j] >= 224 ? 0 : data[j]; // no fullbrights
228 tx->gl_texturenum = GL_LoadTexture (tx->name, tx->width, tx->height, data2, true, transparent, 1);
229 strcpy(name, tx->name);
230 strcat(name, "_glow");
231 for (j = 0;j < tx->width*tx->height;j++)
232 data2[j] = data[j] >= 224 ? data[j] : 0; // only fullbrights
233 tx->gl_glowtexturenum = GL_LoadTexture (name, tx->width, tx->height, data2, true, transparent, 1);
238 tx->gl_texturenum = GL_LoadTexture (tx->name, tx->width, tx->height, data, true, transparent, bytesperpixel);
239 tx->gl_glowtexturenum = 0;
246 pixels = mt->width*mt->height/64*85;
247 tx = Hunk_AllocName (sizeof(texture_t) +pixels, loadname );
248 loadmodel->textures[i] = tx;
250 memcpy (tx->name, mt->name, sizeof(tx->name));
251 tx->width = mt->width;
252 tx->height = mt->height;
253 for (j=0 ; j<MIPLEVELS ; j++)
254 tx->offsets[j] = mt->offsets[j] + sizeof(texture_t) - sizeof(miptex_t);
255 // the pixels immediately follow the structures
256 memcpy ( tx+1, mt+1, pixels);
259 if (!strncmp(mt->name,"sky",3))
262 tx->gl_texturenum = GL_LoadTexture (mt->name, tx->width, tx->height, (byte *)(tx+1), true, false, 1);
267 // sequence the animations
269 for (i=0 ; i<m->nummiptex ; i++)
271 tx = loadmodel->textures[i];
272 if (!tx || tx->name[0] != '+')
275 continue; // allready sequenced
277 // find the number of frames in the animation
278 memset (anims, 0, sizeof(anims));
279 memset (altanims, 0, sizeof(altanims));
283 if (max >= 'a' && max <= 'z')
285 if (max >= '0' && max <= '9')
292 else if (max >= 'A' && max <= 'J')
296 altanims[altmax] = tx;
300 Host_Error ("Bad animating texture %s", tx->name);
302 for (j=i+1 ; j<m->nummiptex ; j++)
304 tx2 = loadmodel->textures[j];
305 if (!tx2 || tx2->name[0] != '+')
307 if (strcmp (tx2->name+2, tx->name+2))
311 if (num >= 'a' && num <= 'z')
313 if (num >= '0' && num <= '9')
320 else if (num >= 'A' && num <= 'J')
328 Host_Error ("Bad animating texture %s", tx->name);
332 // link them all together
333 for (j=0 ; j<max ; j++)
337 Host_Error ("Missing frame %i of %s",j, tx->name);
338 tx2->anim_total = max * ANIM_CYCLE;
339 tx2->anim_min = j * ANIM_CYCLE;
340 tx2->anim_max = (j+1) * ANIM_CYCLE;
341 tx2->anim_next = anims[ (j+1)%max ];
343 tx2->alternate_anims = altanims[0];
345 for (j=0 ; j<altmax ; j++)
349 Host_Error ("Missing frame %i of %s",j, tx->name);
350 tx2->anim_total = altmax * ANIM_CYCLE;
351 tx2->anim_min = j * ANIM_CYCLE;
352 tx2->anim_max = (j+1) * ANIM_CYCLE;
353 tx2->anim_next = altanims[ (j+1)%altmax ];
355 tx2->alternate_anims = anims[0];
365 void Mod_LoadLighting (lump_t *l)
368 byte *in, *out, *data;
370 char litfilename[1024];
371 loadmodel->lightdata = NULL;
374 if (hlbsp) // LordHavoc: load the colored lighting data straight
376 loadmodel->lightdata = Hunk_AllocName ( l->filelen, loadname);
377 memcpy (loadmodel->lightdata, mod_base + l->fileofs, l->filelen);
379 else // LordHavoc: bsp version 29 (normal white lighting)
381 // LordHavoc: hope is not lost yet, check for a .lit file to load
382 strcpy(litfilename, loadmodel->name);
383 COM_StripExtension(litfilename, litfilename);
384 strcat(litfilename, ".lit");
385 data = (byte*) COM_LoadHunkFile (litfilename, false);
388 if (data[0] == 'Q' && data[1] == 'L' && data[2] == 'I' && data[3] == 'T')
390 i = LittleLong(((int *)data)[1]);
393 loadmodel->lightdata = data + 8;
397 Con_Printf("Unknown .lit file version (%d)\n", i);
400 Con_Printf("Corrupt .lit file (old version?), ignoring\n");
402 // LordHavoc: oh well, expand the white lighting data
403 loadmodel->lightdata = Hunk_AllocName ( l->filelen*3, litfilename);
404 in = loadmodel->lightdata + l->filelen*2; // place the file at the end, so it will not be overwritten until the very last write
405 out = loadmodel->lightdata;
406 memcpy (in, mod_base + l->fileofs, l->filelen);
407 for (i = 0;i < l->filelen;i++)
423 void Mod_LoadVisibility (lump_t *l)
427 loadmodel->visdata = NULL;
430 loadmodel->visdata = Hunk_AllocName ( l->filelen, loadname);
431 memcpy (loadmodel->visdata, mod_base + l->fileofs, l->filelen);
434 void CL_ParseEntityLump(char *entdata);
436 extern qboolean isworldmodel;
443 void Mod_LoadEntities (lump_t *l)
447 loadmodel->entities = NULL;
450 loadmodel->entities = Hunk_AllocName ( l->filelen, loadname);
451 memcpy (loadmodel->entities, mod_base + l->fileofs, l->filelen);
454 CL_ParseEntityLump(loadmodel->entities);
463 void Mod_LoadVertexes (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->vertexes = out;
476 loadmodel->numvertexes = count;
478 for ( i=0 ; i<count ; i++, in++, out++)
480 out->position[0] = LittleFloat (in->point[0]);
481 out->position[1] = LittleFloat (in->point[1]);
482 out->position[2] = LittleFloat (in->point[2]);
491 void Mod_LoadSubmodels (lump_t *l)
497 in = (void *)(mod_base + l->fileofs);
498 if (l->filelen % sizeof(*in))
499 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
500 count = l->filelen / sizeof(*in);
501 out = Hunk_AllocName ( count*sizeof(*out), loadname);
503 loadmodel->submodels = out;
504 loadmodel->numsubmodels = count;
506 for ( i=0 ; i<count ; i++, in++, out++)
508 for (j=0 ; j<3 ; j++)
509 { // spread the mins / maxs by a pixel
510 out->mins[j] = LittleFloat (in->mins[j]) - 1;
511 out->maxs[j] = LittleFloat (in->maxs[j]) + 1;
512 out->origin[j] = LittleFloat (in->origin[j]);
514 for (j=0 ; j<MAX_MAP_HULLS ; j++)
515 out->headnode[j] = LittleLong (in->headnode[j]);
516 out->visleafs = LittleLong (in->visleafs);
517 out->firstface = LittleLong (in->firstface);
518 out->numfaces = LittleLong (in->numfaces);
527 void Mod_LoadEdges (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 + 1) * sizeof(*out), loadname);
539 loadmodel->edges = out;
540 loadmodel->numedges = count;
542 for ( i=0 ; i<count ; i++, in++, out++)
544 out->v[0] = (unsigned short)LittleShort(in->v[0]);
545 out->v[1] = (unsigned short)LittleShort(in->v[1]);
554 void Mod_LoadTexinfo (lump_t *l)
562 in = (void *)(mod_base + l->fileofs);
563 if (l->filelen % sizeof(*in))
564 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
565 count = l->filelen / sizeof(*in);
566 out = Hunk_AllocName ( count*sizeof(*out), loadname);
568 loadmodel->texinfo = out;
569 loadmodel->numtexinfo = count;
571 for ( i=0 ; i<count ; i++, in++, out++)
573 for (j=0 ; j<8 ; j++)
574 out->vecs[0][j] = LittleFloat (in->vecs[0][j]);
575 len1 = Length (out->vecs[0]);
576 len2 = Length (out->vecs[1]);
577 len1 = (len1 + len2)/2;
580 else if (len1 < 0.49)
582 else if (len1 < 0.99)
587 if (len1 + len2 < 0.001)
588 out->mipadjust = 1; // don't crash
590 out->mipadjust = 1 / floor( (len1+len2)/2 + 0.1 );
593 miptex = LittleLong (in->miptex);
594 out->flags = LittleLong (in->flags);
596 if (!loadmodel->textures)
598 out->texture = r_notexture_mip; // checkerboard texture
600 out->texture->transparent = FALSE;
604 if (miptex >= loadmodel->numtextures)
605 Host_Error ("miptex >= loadmodel->numtextures");
606 out->texture = loadmodel->textures[miptex];
609 out->texture = r_notexture_mip; // texture not found
611 out->texture->transparent = FALSE;
621 Fills in s->texturemins[] and s->extents[]
624 void CalcSurfaceExtents (msurface_t *s)
626 float mins[2], maxs[2], val;
630 int bmins[2], bmaxs[2];
632 mins[0] = mins[1] = 999999;
633 maxs[0] = maxs[1] = -99999;
637 for (i=0 ; i<s->numedges ; i++)
639 e = loadmodel->surfedges[s->firstedge+i];
641 v = &loadmodel->vertexes[loadmodel->edges[e].v[0]];
643 v = &loadmodel->vertexes[loadmodel->edges[-e].v[1]];
645 for (j=0 ; j<2 ; j++)
647 val = v->position[0] * tex->vecs[j][0] +
648 v->position[1] * tex->vecs[j][1] +
649 v->position[2] * tex->vecs[j][2] +
658 for (i=0 ; i<2 ; i++)
660 bmins[i] = floor(mins[i]/16);
661 bmaxs[i] = ceil(maxs[i]/16);
663 s->texturemins[i] = bmins[i] * 16;
664 s->extents[i] = (bmaxs[i] - bmins[i]) * 16;
665 if ( !(tex->flags & TEX_SPECIAL) && s->extents[i] > 512 /* 256 */ )
666 Host_Error ("Bad surface extents");
670 void GL_SubdivideSurface (msurface_t *fa);
672 extern char skyname[];
679 void Mod_LoadFaces (lump_t *l)
683 int i, count, surfnum;
686 in = (void *)(mod_base + l->fileofs);
687 if (l->filelen % sizeof(*in))
688 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
689 count = l->filelen / sizeof(*in);
690 out = Hunk_AllocName ( count*sizeof(*out), loadname);
692 loadmodel->surfaces = out;
693 loadmodel->numsurfaces = count;
695 for ( surfnum=0 ; surfnum<count ; surfnum++, in++, out++)
697 out->firstedge = LittleLong(in->firstedge);
698 out->numedges = LittleShort(in->numedges);
701 planenum = LittleShort(in->planenum);
702 side = LittleShort(in->side);
704 out->flags |= SURF_PLANEBACK;
706 out->plane = loadmodel->planes + planenum;
708 out->texinfo = loadmodel->texinfo + LittleShort (in->texinfo);
710 CalcSurfaceExtents (out);
714 for (i=0 ; i<MAXLIGHTMAPS ; i++)
715 out->styles[i] = in->styles[i];
716 i = LittleLong(in->lightofs);
719 else if (hlbsp) // LordHavoc: HalfLife map (bsp version 30)
720 out->samples = loadmodel->lightdata + i;
721 else // LordHavoc: white lighting (bsp version 29)
722 out->samples = loadmodel->lightdata + (i * 3);
724 // set the drawing flags flag
726 // if (!strncmp(out->texinfo->texture->name,"sky",3)) // sky
727 // LordHavoc: faster check
728 if ((out->texinfo->texture->name[0] == 's' || out->texinfo->texture->name[0] == 'S')
729 && (out->texinfo->texture->name[1] == 'k' || out->texinfo->texture->name[1] == 'K')
730 && (out->texinfo->texture->name[2] == 'y' || out->texinfo->texture->name[2] == 'Y'))
732 // LordHavoc: for consistency reasons, mark sky as fullbright and solid as well
733 out->flags |= (SURF_DRAWSKY | SURF_DRAWTILED | SURF_DRAWFULLBRIGHT | SURF_DRAWNOALPHA);
734 GL_SubdivideSurface (out); // cut up polygon for warps
738 // if (!strncmp(out->texinfo->texture->name,"*",1)) // turbulent
739 if (out->texinfo->texture->name[0] == '*') // LordHavoc: faster check
741 out->flags |= (SURF_DRAWTURB | SURF_DRAWTILED);
742 // LordHavoc: some turbulent textures should be fullbright and solid
743 if (!strncmp(out->texinfo->texture->name,"*lava",5)
744 || !strncmp(out->texinfo->texture->name,"*teleport",9)
745 || !strncmp(out->texinfo->texture->name,"*rift",5)) // Scourge of Armagon texture
746 out->flags |= (SURF_DRAWFULLBRIGHT | SURF_DRAWNOALPHA);
747 for (i=0 ; i<2 ; i++)
749 out->extents[i] = 16384;
750 out->texturemins[i] = -8192;
752 GL_SubdivideSurface (out); // cut up polygon for warps
765 void Mod_SetParent (mnode_t *node, mnode_t *parent)
767 node->parent = parent;
768 if (node->contents < 0)
770 Mod_SetParent (node->children[0], node);
771 Mod_SetParent (node->children[1], node);
779 void Mod_LoadNodes (lump_t *l)
785 in = (void *)(mod_base + l->fileofs);
786 if (l->filelen % sizeof(*in))
787 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
788 count = l->filelen / sizeof(*in);
789 out = Hunk_AllocName ( count*sizeof(*out), loadname);
791 loadmodel->nodes = out;
792 loadmodel->numnodes = count;
794 for ( i=0 ; i<count ; i++, in++, out++)
796 for (j=0 ; j<3 ; j++)
798 out->minmaxs[j] = LittleShort (in->mins[j]);
799 out->minmaxs[3+j] = LittleShort (in->maxs[j]);
802 p = LittleLong(in->planenum);
803 out->plane = loadmodel->planes + p;
805 out->firstsurface = LittleShort (in->firstface);
806 out->numsurfaces = LittleShort (in->numfaces);
808 for (j=0 ; j<2 ; j++)
810 p = LittleShort (in->children[j]);
812 out->children[j] = loadmodel->nodes + p;
814 out->children[j] = (mnode_t *)(loadmodel->leafs + (-1 - p));
818 Mod_SetParent (loadmodel->nodes, NULL); // sets nodes and leafs
826 void Mod_LoadLeafs (lump_t *l)
832 in = (void *)(mod_base + l->fileofs);
833 if (l->filelen % sizeof(*in))
834 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
835 count = l->filelen / sizeof(*in);
836 out = Hunk_AllocName ( count*sizeof(*out), loadname);
838 loadmodel->leafs = out;
839 loadmodel->numleafs = count;
841 for ( i=0 ; i<count ; i++, in++, out++)
843 for (j=0 ; j<3 ; j++)
845 out->minmaxs[j] = LittleShort (in->mins[j]);
846 out->minmaxs[3+j] = LittleShort (in->maxs[j]);
849 p = LittleLong(in->contents);
852 out->firstmarksurface = loadmodel->marksurfaces +
853 LittleShort(in->firstmarksurface);
854 out->nummarksurfaces = LittleShort(in->nummarksurfaces);
856 p = LittleLong(in->visofs);
858 out->compressed_vis = NULL;
860 out->compressed_vis = loadmodel->visdata + p;
863 for (j=0 ; j<4 ; j++)
864 out->ambient_sound_level[j] = in->ambient_level[j];
866 // gl underwater warp
867 // LordHavoc: disabled underwater warping
869 if (out->contents != CONTENTS_EMPTY)
871 for (j=0 ; j<out->nummarksurfaces ; j++)
872 out->firstmarksurface[j]->flags |= SURF_UNDERWATER;
883 void Mod_LoadClipnodes (lump_t *l)
885 dclipnode_t *in, *out;
889 in = (void *)(mod_base + l->fileofs);
890 if (l->filelen % sizeof(*in))
891 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
892 count = l->filelen / sizeof(*in);
893 out = Hunk_AllocName ( count*sizeof(*out), loadname);
895 loadmodel->clipnodes = out;
896 loadmodel->numclipnodes = count;
898 hull = &loadmodel->hulls[1];
899 hull->clipnodes = out;
900 hull->firstclipnode = 0;
901 hull->lastclipnode = count-1;
902 hull->planes = loadmodel->planes;
903 hull->clip_mins[0] = -16;
904 hull->clip_mins[1] = -16;
905 hull->clip_mins[2] = -24;
906 hull->clip_maxs[0] = 16;
907 hull->clip_maxs[1] = 16;
908 hull->clip_maxs[2] = 32;
910 hull = &loadmodel->hulls[2];
911 hull->clipnodes = out;
912 hull->firstclipnode = 0;
913 hull->lastclipnode = count-1;
914 hull->planes = loadmodel->planes;
915 hull->clip_mins[0] = -32;
916 hull->clip_mins[1] = -32;
917 hull->clip_mins[2] = -24;
918 hull->clip_maxs[0] = 32;
919 hull->clip_maxs[1] = 32;
920 hull->clip_maxs[2] = 64;
922 for (i=0 ; i<count ; i++, out++, in++)
924 out->planenum = LittleLong(in->planenum);
925 out->children[0] = LittleShort(in->children[0]);
926 out->children[1] = LittleShort(in->children[1]);
934 Duplicate the drawing hull structure as a clipping hull
937 void Mod_MakeHull0 (void)
944 hull = &loadmodel->hulls[0];
946 in = loadmodel->nodes;
947 count = loadmodel->numnodes;
948 out = Hunk_AllocName ( count*sizeof(*out), loadname);
950 hull->clipnodes = out;
951 hull->firstclipnode = 0;
952 hull->lastclipnode = count-1;
953 hull->planes = loadmodel->planes;
955 for (i=0 ; i<count ; i++, out++, in++)
957 out->planenum = in->plane - loadmodel->planes;
958 for (j=0 ; j<2 ; j++)
960 child = in->children[j];
961 if (child->contents < 0)
962 out->children[j] = child->contents;
964 out->children[j] = child - loadmodel->nodes;
974 void Mod_LoadMarksurfaces (lump_t *l)
980 in = (void *)(mod_base + l->fileofs);
981 if (l->filelen % sizeof(*in))
982 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
983 count = l->filelen / sizeof(*in);
984 out = Hunk_AllocName ( count*sizeof(*out), loadname);
986 loadmodel->marksurfaces = out;
987 loadmodel->nummarksurfaces = count;
989 for ( i=0 ; i<count ; i++)
991 j = LittleShort(in[i]);
992 if (j >= loadmodel->numsurfaces)
993 Host_Error ("Mod_ParseMarksurfaces: bad surface number");
994 out[i] = loadmodel->surfaces + j;
1003 void Mod_LoadSurfedges (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*sizeof(*out), loadname);
1014 loadmodel->surfedges = out;
1015 loadmodel->numsurfedges = count;
1017 for ( i=0 ; i<count ; i++)
1018 out[i] = LittleLong (in[i]);
1027 void Mod_LoadPlanes (lump_t *l)
1035 in = (void *)(mod_base + l->fileofs);
1036 if (l->filelen % sizeof(*in))
1037 Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
1038 count = l->filelen / sizeof(*in);
1039 out = Hunk_AllocName ( count*2*sizeof(*out), loadname);
1041 loadmodel->planes = out;
1042 loadmodel->numplanes = count;
1044 for ( i=0 ; i<count ; i++, in++, out++)
1047 for (j=0 ; j<3 ; j++)
1049 out->normal[j] = LittleFloat (in->normal[j]);
1050 // if (out->normal[j] < 0)
1054 out->dist = LittleFloat (in->dist);
1055 out->type = LittleLong (in->type);
1056 // out->signbits = bits;
1057 BoxOnPlaneSideClassify(out);
1066 void Mod_LoadBrushModel (model_t *mod, void *buffer)
1072 loadmodel->type = mod_brush;
1074 header = (dheader_t *)buffer;
1076 i = LittleLong (header->version);
1077 if (i != BSPVERSION & i != 30)
1078 Host_Error ("Mod_LoadBrushModel: %s has wrong version number (%i should be %i or 30 (HalfLife))", mod->name, i, BSPVERSION);
1080 halflifebsp.value = hlbsp;
1082 // swap all the lumps
1083 mod_base = (byte *)header;
1085 for (i=0 ; i<sizeof(dheader_t)/4 ; i++)
1086 ((int *)header)[i] = LittleLong ( ((int *)header)[i]);
1090 // LordHavoc: had to move entity loading above everything to allow parsing various settings from worldspawn
1091 Mod_LoadEntities (&header->lumps[LUMP_ENTITIES]);
1093 Mod_LoadVertexes (&header->lumps[LUMP_VERTEXES]);
1094 Mod_LoadEdges (&header->lumps[LUMP_EDGES]);
1095 Mod_LoadSurfedges (&header->lumps[LUMP_SURFEDGES]);
1096 Mod_LoadTextures (&header->lumps[LUMP_TEXTURES]);
1097 Mod_LoadLighting (&header->lumps[LUMP_LIGHTING]);
1098 Mod_LoadPlanes (&header->lumps[LUMP_PLANES]);
1099 Mod_LoadTexinfo (&header->lumps[LUMP_TEXINFO]);
1100 Mod_LoadFaces (&header->lumps[LUMP_FACES]);
1101 Mod_LoadMarksurfaces (&header->lumps[LUMP_MARKSURFACES]);
1102 Mod_LoadVisibility (&header->lumps[LUMP_VISIBILITY]);
1103 Mod_LoadLeafs (&header->lumps[LUMP_LEAFS]);
1104 Mod_LoadNodes (&header->lumps[LUMP_NODES]);
1105 Mod_LoadClipnodes (&header->lumps[LUMP_CLIPNODES]);
1106 // Mod_LoadEntities (&header->lumps[LUMP_ENTITIES]);
1107 Mod_LoadSubmodels (&header->lumps[LUMP_MODELS]);
1111 mod->numframes = 2; // regular and alternate animation
1114 // set up the submodels (FIXME: this is confusing)
1116 for (i=0 ; i<mod->numsubmodels ; i++)
1118 bm = &mod->submodels[i];
1120 mod->hulls[0].firstclipnode = bm->headnode[0];
1121 for (j=1 ; j<MAX_MAP_HULLS ; j++)
1123 mod->hulls[j].firstclipnode = bm->headnode[j];
1124 mod->hulls[j].lastclipnode = mod->numclipnodes-1;
1127 mod->firstmodelsurface = bm->firstface;
1128 mod->nummodelsurfaces = bm->numfaces;
1130 VectorCopy (bm->maxs, mod->maxs);
1131 VectorCopy (bm->mins, mod->mins);
1133 mod->radius = RadiusFromBounds (mod->mins, mod->maxs);
1135 mod->numleafs = bm->visleafs;
1137 if (isworldmodel && i < (mod->numsubmodels-1)) // LordHavoc: only register submodels if it is the world (prevents bsp models from replacing world submodels)
1138 { // duplicate the basic information
1141 sprintf (name, "*%i", i+1);
1142 loadmodel = Mod_FindName (name);
1144 strcpy (loadmodel->name, name);