⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ivp_surbuild_q12.cxx

📁 hl2 source code. Do not use it illegal.
💻 CXX
📖 第 1 页 / 共 2 页
字号:
// Copyright (C) Ipion Software GmbH 1999-2000. All rights reserved.

// =====================================================================================

// This file contains software technology by Id Software, Inc. ("Id Technology").
// This data has been taken from the file 'bspfile.h' which is part of the
// archive 'qutils.zip'. The archive is freely available at ID's own ftp server
// 'ftp.id-software.com'.
//
// Ipion, June 8th 1999

#include <ivp_physics.hxx>
#ifdef LINUX
#	include <string.h>
#endif
#include <ivp_compact_ledge.hxx>

#include <ivp_halfspacesoup.hxx>
#include <ivp_surbuild_q12.hxx>
#include <ivp_surbuild_polygon_convex.hxx>
#include <ivp_surbuild_halfspacesoup.hxx>
#include <ivp_surbuild_ledge_soup.hxx>


// hack :)
class IVP_q12_int {
public:    
    int val;

    IVP_q12_int(int x) { this->val = x; }
    ~IVP_q12_int() { ; }
};
// hack :)


// ID software technology: start

//=============================================================================

typedef unsigned char byte;

#ifdef _SGI_SOURCE
#define	__BIG_ENDIAN__
#endif

#ifdef __BIG_ENDIAN__

short   LittleShort (short l)
{
    byte    b1,b2;

    b1 = l&255;
    b2 = (l>>8)&255;

    return (b1<<8) + b2;
}

short   BigShort (short l)
{
    return l;
}


int    LittleLong (int l)
{
    byte    b1,b2,b3,b4;

    b1 = l&255;
    b2 = (l>>8)&255;
    b3 = (l>>16)&255;
    b4 = (l>>24)&255;

    return ((int)b1<<24) + ((int)b2<<16) + ((int)b3<<8) + b4;
}

int    BigLong (int l)
{
    return l;
}


IVP_FLOAT	LittleFloat (IVP_FLOAT l)
{
    union {byte b[4]; IVP_FLOAT f;} in, out;
	
    in.f = l;
    out.b[0] = in.b[3];
    out.b[1] = in.b[2];
    out.b[2] = in.b[1];
    out.b[3] = in.b[0];
	
    return out.f;
}

IVP_FLOAT	BigFloat (IVP_FLOAT l)
{
    return l;
}


#else


short   BigShort (short l)
{
    byte    b1,b2;

    b1 = l&255;
    b2 = (l>>8)&255;

    return (b1<<8) + b2;
}

short   LittleShort (short l)
{
    return l;
}


int    BigLong (int l)
{
    byte    b1,b2,b3,b4;

    b1 = l&255;
    b2 = (l>>8)&255;
    b3 = (l>>16)&255;
    b4 = (l>>24)&255;

    return ((int)b1<<24) + ((int)b2<<16) + ((int)b3<<8) + b4;
}

int    LittleLong (int l)
{
    return l;
}

IVP_FLOAT	BigFloat (IVP_FLOAT l)
{
    union {byte b[4]; IVP_FLOAT f;} in, out;
	
    in.f = l;
    out.b[0] = in.b[3];
    out.b[1] = in.b[2];
    out.b[2] = in.b[1];
    out.b[3] = in.b[0];
	
    return out.f;
}

IVP_FLOAT	LittleFloat (IVP_FLOAT l)
{
    return l;
}


#endif

// upper design bounds

#define BSPVERSION	30

#define	LUMP_PLANES	1
#define	LUMP_NODES	5
#define	LUMP_CLIPNODES	9
#define	LUMP_MODELS	14


#if defined(SUN4) || defined(SUN) || (defined(__MWERKS__) && defined(__POWERPC__)) || defined(GEKKO)
void IVP_SurfaceBuilder_Q12::swap_bsp_data()
{
    int      i, j;
    dmodel_t *d;

	
    // models	
    for (i=0 ; i<this->n_models ; i++) {
	d = &this->dmodels[i];

	for (j=0 ; j<MAX_MAP_HULLS ; j++) {
	    d->headnode[j] = BigLong (d->headnode[j]);
	}

	d->visleafs = BigLong (d->visleafs);
	d->firstface = BigLong (d->firstface);
	d->numfaces = BigLong (d->numfaces);
		
	for (j=0 ; j<3 ; j++) {
	    d->mins[j] = BigFloat(d->mins[j]);
	    d->maxs[j] = BigFloat(d->maxs[j]);
	    d->origin[j] = BigFloat(d->origin[j]);
	}
    }

    // planes
    for (i=0 ; i<this->n_planes ; i++) {
	for (j=0 ; j<3 ; j++) {
	    this->dplanes[i].normal[j] = BigFloat (this->dplanes[i].normal[j]);
	}
	this->dplanes[i].dist = BigFloat (this->dplanes[i].dist);
	this->dplanes[i].type = BigLong (this->dplanes[i].type);
    }

    // nodes
    for (i=0 ; i<this->n_nodes ; i++) {
	this->dnodes[i].planenum = BigLong (this->dnodes[i].planenum);
	for (j=0 ; j<3 ; j++) {
	    this->dnodes[i].mins[j] = BigShort (this->dnodes[i].mins[j]);
	    this->dnodes[i].maxs[j] = BigShort (this->dnodes[i].maxs[j]);
	}
	this->dnodes[i].children[0] = BigShort (this->dnodes[i].children[0]);
	this->dnodes[i].children[1] = BigShort (this->dnodes[i].children[1]);
	this->dnodes[i].firstface = BigShort (this->dnodes[i].firstface);
	this->dnodes[i].numfaces = BigShort (this->dnodes[i].numfaces);
    }

    // clipnodes
    for (i=0 ; i<this->n_clipnodes ; i++) {
	this->dclipnodes[i].planenum = BigLong (this->dclipnodes[i].planenum);
	this->dclipnodes[i].children[0] = BigShort (this->dclipnodes[i].children[0]);
	this->dclipnodes[i].children[1] = BigShort (this->dclipnodes[i].children[1]);
    }

    return;
}
#else
void IVP_SurfaceBuilder_Q12::swap_bsp_data()
{
    int      i, j;
    dmodel_t *d;

	
    // models	
    for (i=0 ; i<this->n_models ; i++) {
	d = &this->dmodels[i];

	for (j=0 ; j<MAX_MAP_HULLS ; j++) {
	    d->headnode[j] = LittleLong (d->headnode[j]);
	}

	d->visleafs = LittleLong (d->visleafs);
	d->firstface = LittleLong (d->firstface);
	d->numfaces = LittleLong (d->numfaces);
		
	for (j=0 ; j<3 ; j++) {
	    d->mins[j] = LittleFloat(d->mins[j]);
	    d->maxs[j] = LittleFloat(d->maxs[j]);
	    d->origin[j] = LittleFloat(d->origin[j]);
	}
    }

    // planes
    for (i=0 ; i<this->n_planes ; i++) {
	for (j=0 ; j<3 ; j++) {
	    this->dplanes[i].normal[j] = LittleFloat (this->dplanes[i].normal[j]);
	}
	this->dplanes[i].dist = LittleFloat (this->dplanes[i].dist);
	this->dplanes[i].type = LittleLong (this->dplanes[i].type);
    }

    // nodes
    for (i=0 ; i<this->n_nodes ; i++) {
	this->dnodes[i].planenum = LittleLong (this->dnodes[i].planenum);
	for (j=0 ; j<3 ; j++) {
	    this->dnodes[i].mins[j] = LittleShort (this->dnodes[i].mins[j]);
	    this->dnodes[i].maxs[j] = LittleShort (this->dnodes[i].maxs[j]);
	}
	this->dnodes[i].children[0] = LittleShort (this->dnodes[i].children[0]);
	this->dnodes[i].children[1] = LittleShort (this->dnodes[i].children[1]);
	this->dnodes[i].firstface = LittleShort (this->dnodes[i].firstface);
	this->dnodes[i].numfaces = LittleShort (this->dnodes[i].numfaces);
    }

    // clipnodes
    for (i=0 ; i<this->n_clipnodes ; i++) {
	this->dclipnodes[i].planenum = LittleLong (this->dclipnodes[i].planenum);
	this->dclipnodes[i].children[0] = LittleShort (this->dclipnodes[i].children[0]);
	this->dclipnodes[i].children[1] = LittleShort (this->dclipnodes[i].children[1]);
    }

    return;
}
#endif


int IVP_SurfaceBuilder_Q12::init_bsp_data(int lump, void **dest, int size)
{
    int length, ofs;

    length = this->header->lumps[lump].filelen;
    ofs = this->header->lumps[lump].fileofs;

    *dest = (dmodel_t *)p_calloc(length, size);
	
    memcpy(*dest, (byte *)this->header + ofs, length);

    return(length / size);
}

// ID software technology: end



// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

int q12_get_length_of_file(FILE *fp)
{
    int pos = ftell(fp);
    fseek(fp, 0, SEEK_END);
    int end = ftell(fp);
    fseek(fp, pos, SEEK_SET);

    return(end);
}

int IVP_SurfaceBuilder_Q12::load_q12bsp_file(char *filename)
{

// ****
#ifndef GEKKO
// ****

    // load the bsp file
    FILE *fp = fopen(filename, "rb");
    if ( !fp ) return(0);
    int length = q12_get_length_of_file(fp);
    this->header = (dheader_t *)p_malloc(length+1);
    ((char *)this->header)[length] = 0;
    fread((char *)this->header, 1, length, fp);
    fclose(fp);

    // swap the header
    int i;
    for (i=0 ; i< (int)sizeof(dheader_t)/4 ; i++) {
#if defined(SUN4) || defined(SUN)
	((int *)header)[i] = BigLong( ((int *)header)[i]);
#else
	((int *)header)[i] = LittleLong( ((int *)header)[i]);
#endif
    }

    IVP_IF(1) {
	if ( header->version > BSPVERSION ) {
		printf("****** ERROR ******\n%s is version %i, not %i\n", filename, header->version, BSPVERSION);
	}
    }

    this->n_models       = this->init_bsp_data(LUMP_MODELS      , (void **)&this->dmodels      , sizeof(dmodel_t));
    //numvertexes     = init_bsp_data(LUMP_VERTEXES    , dvertexes    , sizeof(dvertex_t));
    this->n_planes       = this->init_bsp_data(LUMP_PLANES      , (void **)&this->dplanes      , sizeof(dplane_t));
    //numleafs        = init_bsp_data(LUMP_LEAFS       , dleafs       , sizeof(dleaf_t));
    this->n_nodes        = this->init_bsp_data(LUMP_NODES       , (void **)&this->dnodes       , sizeof(dnode_t));
    //numtexinfo      = init_bsp_data(LUMP_TEXINFO     , texinfo      , sizeof(texinfo_t));
    this->n_clipnodes    = this->init_bsp_data(LUMP_CLIPNODES   , (void **)&this->dclipnodes   , sizeof(dclipnode_t));
    //numfaces        = this->init_bsp_data(LUMP_FACES       , dfaces       , sizeof(dface_t));
    //nummarksurfaces = this->init_bsp_data(LUMP_MARKSURFACES, dmarksurfaces, sizeof(dmarksurfaces[0]));
    //numsurfedges    = this->init_bsp_data(LUMP_SURFEDGES   , dsurfedges   , sizeof(dsurfedges[0]));
    //numedges        = this->init_bsp_data(LUMP_EDGES       , dedges       , sizeof(dedge_t));

    //texdatasize     = this->init_bsp_data(LUMP_TEXTURES    , dtexdata     , 1);
    //visdatasize     = this->init_bsp_data(LUMP_VISIBILITY  , dvisdata     , 1);
    //lightdatasize   = this->init_bsp_data(LUMP_LIGHTING    , dlightdata   , 1);
    //entdatasize     = this->init_bsp_data(LUMP_ENTITIES    , dentdata     , 1);

    P_FREE(this->header);		// everything has been copied out

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -