MCPcopy Create free account
hub / github.com/JACoders/OpenJK / CMod_LoadPatches

Function CMod_LoadPatches

code/qcommon/cm_load.cpp:528–583  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

526*/
527#define MAX_PATCH_VERTS 1024
528void CMod_LoadPatches( lump_t *surfs, lump_t *verts, clipMap_t &cm ) {
529 mapVert_t *dv, *dv_p;
530 dsurface_t *in;
531 int count;
532 int i, j;
533 int c;
534 cPatch_t *patch;
535 vec3_t points[MAX_PATCH_VERTS];
536 int width, height;
537 int shaderNum;
538
539 in = (dsurface_t *)(cmod_base + surfs->fileofs);
540 if (surfs->filelen % sizeof(*in))
541 Com_Error (ERR_DROP, "MOD_LoadBmodel: funny lump size");
542 cm.numSurfaces = count = surfs->filelen / sizeof(*in);
543 cm.surfaces = (cPatch_t **) Z_Malloc( cm.numSurfaces * sizeof( cm.surfaces[0] ), TAG_BSP, qtrue );
544
545 dv = (mapVert_t *)(cmod_base + verts->fileofs);
546 if (verts->filelen % sizeof(*dv))
547 Com_Error (ERR_DROP, "MOD_LoadBmodel: funny lump size");
548
549 // scan through all the surfaces, but only load patches,
550 // not planar faces
551 for ( i = 0 ; i < count ; i++, in++ ) {
552 if ( LittleLong( in->surfaceType ) != MST_PATCH ) {
553 continue; // ignore other surfaces
554 }
555 // FIXME: check for non-colliding patches
556
557 cm.surfaces[ i ] = patch = (cPatch_t *) Z_Malloc( sizeof( *patch ), TAG_BSP, qtrue );
558
559 // load the full drawverts onto the stack
560 width = LittleLong( in->patchWidth );
561 height = LittleLong( in->patchHeight );
562 c = width * height;
563 if ( c > MAX_PATCH_VERTS ) {
564 Com_Error( ERR_DROP, "ParseMesh: MAX_PATCH_VERTS" );
565 }
566
567 dv_p = dv + LittleLong( in->firstVert );
568 for ( j = 0 ; j < c ; j++, dv_p++ ) {
569 points[j][0] = LittleFloat( dv_p->xyz[0] );
570 points[j][1] = LittleFloat( dv_p->xyz[1] );
571 points[j][2] = LittleFloat( dv_p->xyz[2] );
572 }
573
574 shaderNum = LittleLong( in->shaderNum );
575 patch->contents = cm.shaders[shaderNum].contentFlags;
576 CM_OrOfAllContentsFlagsInMap |= patch->contents;
577
578 patch->surfaceFlags = cm.shaders[shaderNum].surfaceFlags;
579
580 // create the internal facet structure
581 patch->pc = CM_GeneratePatchCollide( width, height, points );
582 }
583}
584
585//==================================================================

Callers 1

CM_LoadMap_ActualFunction · 0.70

Calls 3

Com_ErrorFunction · 0.70
Z_MallocFunction · 0.70
CM_GeneratePatchCollideFunction · 0.70

Tested by

no test coverage detected