mirror of
https://github.com/id-Software/GtkRadiant.git
synced 2026-03-20 08:59:32 +01:00
The GtkRadiant sources as originally released under the GPL license.
This commit is contained in:
49
tools/quake2/qdata_heretic2/adpcm.h
Normal file
49
tools/quake2/qdata_heretic2/adpcm.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/*
|
||||
** adpcm.h - include file for adpcm coder.
|
||||
**
|
||||
** Version 1.0, 7-Jul-92.
|
||||
**
|
||||
** Modded 10/3/98
|
||||
** John Scott
|
||||
*/
|
||||
|
||||
typedef struct adpcm_state_s
|
||||
{
|
||||
short in_valprev; // Previous output value
|
||||
short in_index; // Index into stepsize table
|
||||
short out_valprev; // Previous output value
|
||||
short out_index; // Index into stepsize table
|
||||
int count; // Number of sample counts
|
||||
} adpcm_state_t;
|
||||
|
||||
typedef struct adpcm_s
|
||||
{
|
||||
adpcm_state_t state;
|
||||
char adpcm[0x10000];
|
||||
} adpcm_t;
|
||||
|
||||
void adpcm_coder(short [], adpcm_t *);
|
||||
void adpcm_decoder(adpcm_t *, short []);
|
||||
|
||||
// end
|
||||
351
tools/quake2/qdata_heretic2/animcomp.c
Normal file
351
tools/quake2/qdata_heretic2/animcomp.c
Normal file
@@ -0,0 +1,351 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <memory.h>
|
||||
#include "animcomp.h"
|
||||
|
||||
|
||||
void *SafeMalloc(size_t n, char *desc);
|
||||
|
||||
|
||||
|
||||
float *matrix;
|
||||
float *delta;
|
||||
float *best;
|
||||
float *comp;
|
||||
float *tcomp;
|
||||
float *bestcomp;
|
||||
float *frames;
|
||||
float *base;
|
||||
|
||||
int MatWidth;
|
||||
int MatHeight;
|
||||
int CFrameSize;
|
||||
int nFrames;
|
||||
|
||||
|
||||
void AnimCompressInit(int nframes,int nVerts,int CompressedFrameSize)
|
||||
{
|
||||
nFrames=nframes;
|
||||
MatWidth=nVerts*3;
|
||||
MatHeight=CompressedFrameSize;
|
||||
CFrameSize=CompressedFrameSize;
|
||||
matrix=(float *)SafeMalloc(MatWidth*MatHeight*sizeof(float), "AnimCompressInit");
|
||||
best=(float *)SafeMalloc(MatWidth*MatHeight*sizeof(float), "AnimCompressInit");
|
||||
delta=(float *)SafeMalloc(MatWidth*MatHeight*sizeof(float), "AnimCompressInit");
|
||||
comp=(float *)SafeMalloc(CFrameSize*nFrames*sizeof(float), "AnimCompressInit");
|
||||
tcomp=(float *)SafeMalloc(CFrameSize*nFrames*sizeof(float), "AnimCompressInit");
|
||||
bestcomp=(float *)SafeMalloc(CFrameSize*nFrames*sizeof(float), "AnimCompressInit");
|
||||
base=(float *)SafeMalloc(MatWidth*sizeof(float), "AnimCompressInit");
|
||||
frames=(float *)SafeMalloc(MatWidth*nFrames*sizeof(float), "AnimCompressInit");
|
||||
}
|
||||
|
||||
void AnimSetFrame(int frame,int index,float x,float y,float z)
|
||||
{
|
||||
frames[frame*MatWidth+index*3]=x;
|
||||
frames[frame*MatWidth+index*3+1]=y;
|
||||
frames[frame*MatWidth+index*3+2]=z;
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int index;
|
||||
float val;
|
||||
} SORTP;
|
||||
|
||||
|
||||
#define F_RANDOM (((float)rand())/(float)RAND_MAX)
|
||||
|
||||
extern void DOsvd(float *a,float *res,float *comp,float *values,int nframes,int framesize,int compressedsize);
|
||||
|
||||
void AnimCompressDoit()
|
||||
{
|
||||
float compression;
|
||||
float *rescale;
|
||||
float *ans;
|
||||
float maxdev;
|
||||
float avedev;
|
||||
float tmp;
|
||||
int j,k,l,numave;
|
||||
|
||||
for (k=0;k<MatWidth;k++)
|
||||
base[k]=0.0f;
|
||||
for (j=0;j<nFrames;j++)
|
||||
for (k=0;k<MatWidth;k++)
|
||||
base[k]+=frames[j*MatWidth+k];
|
||||
tmp=1.0f/(float)nFrames;
|
||||
for (k=0;k<MatWidth;k++)
|
||||
base[k]*=tmp;
|
||||
for (j=0;j<nFrames;j++)
|
||||
for (k=0;k<MatWidth;k++)
|
||||
frames[j*MatWidth+k]-=base[k];
|
||||
|
||||
ans=(float *)SafeMalloc(sizeof(float)*MatWidth, "AnimCompressDoit");
|
||||
rescale=(float *)SafeMalloc(sizeof(float)*CFrameSize, "AnimCompressDoit");
|
||||
DOsvd(frames,best,bestcomp,rescale,nFrames,MatWidth,MatHeight);
|
||||
avedev=0.0;
|
||||
for (l=0;l<CFrameSize;l++)
|
||||
avedev+=rescale[l];
|
||||
for (l=0;l<CFrameSize;l++)
|
||||
printf("%3.1f ",100.0f*rescale[l]/avedev);
|
||||
printf("\n");
|
||||
for (j=0;j<nFrames;j++)
|
||||
{
|
||||
for (l=0;l<CFrameSize;l++)
|
||||
{
|
||||
bestcomp[j*CFrameSize+l]=0.0;
|
||||
for (k=0;k<MatWidth;k++)
|
||||
bestcomp[j*CFrameSize+l]+=best[l*MatWidth+k]*frames[j*MatWidth+k];
|
||||
}
|
||||
}
|
||||
numave=0;
|
||||
avedev=0.0;
|
||||
maxdev=0.0;
|
||||
for (j=0;j<nFrames;j++)
|
||||
{
|
||||
for (k=0;k<MatWidth;k++)
|
||||
{
|
||||
ans[k]=0.0;
|
||||
for (l=0;l<CFrameSize;l++)
|
||||
ans[k]+=best[l*MatWidth+k]*bestcomp[j*CFrameSize+l];
|
||||
ans[k]-=frames[j*MatWidth+k];
|
||||
tmp=(float)fabs(ans[k]);
|
||||
if (tmp>maxdev)
|
||||
maxdev=tmp;
|
||||
avedev+=tmp;
|
||||
numave++;
|
||||
}
|
||||
}
|
||||
avedev/=(float)numave;
|
||||
printf("%f Max Deviation (inches) %f Ave Dev. (inches)\n",maxdev,avedev);
|
||||
printf("%d bytes original size\n",MatWidth*nFrames);
|
||||
printf("%d bytes of overhead\n",MatWidth*MatHeight);
|
||||
printf("%d bytes/frame * %d frames = %d bytes\n",CFrameSize,nFrames,CFrameSize*nFrames);
|
||||
compression=(float)(MatWidth*MatHeight+CFrameSize*nFrames+MatWidth);
|
||||
compression/=(float)(MatWidth*nFrames);
|
||||
printf("Overall compression = %f %%\n",100.0f-100.0f*compression);
|
||||
compression=(float)(CFrameSize);
|
||||
compression/=(float)(MatWidth);
|
||||
printf("frame size compression = %f %%\n",100.0f-100.0f*compression);
|
||||
free(rescale);
|
||||
free(ans);
|
||||
}
|
||||
|
||||
void AnimCompressToBytes(float *trans,float *scale,char *mat,char *ccomp,unsigned char *cbase,float *cscale,float *coffset,float *bmin,float *bmax)
|
||||
{
|
||||
int k,l,nv,j;
|
||||
float maxdev;
|
||||
float avedev;
|
||||
float tmp;
|
||||
int numave;
|
||||
float t,mx;
|
||||
float *ans;
|
||||
|
||||
|
||||
nv=MatWidth/3;
|
||||
|
||||
trans[0]=1E30f;
|
||||
scale[0]=-1E30f;
|
||||
trans[1]=1E30f;
|
||||
scale[1]=-1E30f;
|
||||
trans[2]=1E30f;
|
||||
scale[2]=-1E30f;
|
||||
for (k=0;k<MatWidth;k+=3)
|
||||
{
|
||||
if (base[k]>scale[0])
|
||||
scale[0]=base[k];
|
||||
if (base[k]<trans[0])
|
||||
trans[0]=base[k];
|
||||
|
||||
if (base[k+1]>scale[1])
|
||||
scale[1]=base[k+1];
|
||||
if (base[k+1]<trans[1])
|
||||
trans[1]=base[k+1];
|
||||
|
||||
if (base[k+2]>scale[2])
|
||||
scale[2]=base[k+2];
|
||||
if (base[k+2]<trans[2])
|
||||
trans[2]=base[k+2];
|
||||
}
|
||||
|
||||
scale[0]-=trans[0];
|
||||
scale[1]-=trans[1];
|
||||
scale[2]-=trans[2];
|
||||
scale[0]/=255.0f;
|
||||
scale[1]/=255.0f;
|
||||
scale[2]/=255.0f;
|
||||
for (k=0;k<MatWidth;k+=3)
|
||||
{
|
||||
t=(base[k]-trans[0])/scale[0];
|
||||
if (t<0.0f)
|
||||
t=0.0f;
|
||||
if (t>255.0f)
|
||||
t=255.0f;
|
||||
cbase[k]=(unsigned char)t;
|
||||
|
||||
t=(base[k+1]-trans[1])/scale[1];
|
||||
if (t<0.0f)
|
||||
t=0.0f;
|
||||
if (t>255.0f)
|
||||
t=255.0f;
|
||||
cbase[k+1]=(unsigned char)t;
|
||||
|
||||
t=(base[k+2]-trans[2])/scale[2];
|
||||
if (t<0.0f)
|
||||
t=0.0f;
|
||||
if (t>255.0f)
|
||||
t=255.0f;
|
||||
cbase[k+2]=(unsigned char)t;
|
||||
}
|
||||
for (l=0;l<MatHeight;l++)
|
||||
{
|
||||
mx=0.0;
|
||||
for (k=0;k<MatWidth;k++)
|
||||
{
|
||||
if (fabs(best[l*MatWidth+k])>mx)
|
||||
mx=(float)fabs(best[l*MatWidth+k]);
|
||||
}
|
||||
if (mx>1E-8)
|
||||
{
|
||||
mx/=127.0f;
|
||||
coffset[l]=1E30f;
|
||||
cscale[l]=-1E30f;
|
||||
for (j=0;j<nFrames;j++)
|
||||
{
|
||||
bestcomp[j*MatHeight+l]*=mx;
|
||||
if (bestcomp[j*MatHeight+l]>cscale[l])
|
||||
cscale[l]=bestcomp[j*MatHeight+l];
|
||||
if (bestcomp[j*MatHeight+l]<coffset[l])
|
||||
coffset[l]=bestcomp[j*MatHeight+l];
|
||||
}
|
||||
cscale[l]-=coffset[l];
|
||||
if (cscale[l]>1E-10)
|
||||
{
|
||||
for (j=0;j<nFrames;j++)
|
||||
{
|
||||
tmp=254.0f*(bestcomp[j*MatHeight+l]-coffset[l])/cscale[l]-127.0f;
|
||||
if (tmp>127.0f)
|
||||
tmp=127.0f;
|
||||
if (tmp<-127.0f)
|
||||
tmp=-127.0f;
|
||||
ccomp[j*MatHeight+l]=(char)floor(tmp+0.5);
|
||||
}
|
||||
coffset[l]+=cscale[l]*127.0f/254.0f;
|
||||
cscale[l]/=254.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
cscale[l]=1.0f;
|
||||
coffset[l]=0.0f;
|
||||
for (j=0;j<nFrames;j++)
|
||||
ccomp[j*MatHeight+l]=0;
|
||||
}
|
||||
mx=1.0f/mx;
|
||||
for (k=0;k<MatWidth;k++)
|
||||
{
|
||||
tmp=best[l*MatWidth+k]*mx;
|
||||
if (tmp>127.0f)
|
||||
tmp=127.0f;
|
||||
if (tmp<-127.0f)
|
||||
tmp=-127.0f;
|
||||
mat[k*MatHeight+l]=(char)floor(tmp+0.5);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cscale[l]=1.0f;
|
||||
coffset[l]=0.0f;
|
||||
for (j=0;j<nFrames;j++)
|
||||
ccomp[j*MatHeight+l]=0;
|
||||
for (k=0;k<MatWidth;k++)
|
||||
mat[k*MatHeight+l]=0;
|
||||
}
|
||||
}
|
||||
bmin[0]=1E30f;
|
||||
bmin[1]=1E30f;
|
||||
bmin[2]=1E30f;
|
||||
bmax[0]=-1E30f;
|
||||
bmax[1]=-1E30f;
|
||||
bmax[2]=-1E30f;
|
||||
numave=0;
|
||||
avedev=0.0;
|
||||
maxdev=0.0;
|
||||
ans=(float *)SafeMalloc(sizeof(float)*MatWidth, "AnimCompressToBytes");
|
||||
for (j=0;j<nFrames;j++)
|
||||
{
|
||||
for (k=0;k<MatWidth;k++)
|
||||
{
|
||||
ans[k]=0.0;
|
||||
for (l=0;l<CFrameSize;l++)
|
||||
ans[k]+=(float)(mat[l+k*MatHeight])*((float)(ccomp[j*CFrameSize+l])*cscale[l]+coffset[l]);
|
||||
ans[k]+=(float)(cbase[k])*scale[k%3]+trans[k%3];
|
||||
tmp=(float)fabs(ans[k]-frames[j*MatWidth+k]-base[k]);
|
||||
if (tmp>maxdev)
|
||||
maxdev=tmp;
|
||||
avedev+=tmp;
|
||||
numave++;
|
||||
|
||||
if (bmin[k%3]>ans[k])
|
||||
bmin[k%3]=ans[k];
|
||||
if (bmax[k%3]<ans[k])
|
||||
bmax[k%3]=ans[k];
|
||||
}
|
||||
}
|
||||
avedev/=(float)numave;
|
||||
printf("%f Max Deviation (inches) %f Ave Dev. (inches)\n",maxdev,avedev);
|
||||
free(ans);
|
||||
}
|
||||
|
||||
void AnimCompressGetMatrix(float *mat)
|
||||
{
|
||||
int k,l;
|
||||
for (k=0;k<MatWidth;k++)
|
||||
for (l=0;l<MatHeight;l++)
|
||||
mat[k*MatHeight+l]=best[l*MatWidth+k];
|
||||
}
|
||||
|
||||
void AnimCompressGetFrames(float *mat)
|
||||
{
|
||||
memcpy(mat,bestcomp,CFrameSize*nFrames*sizeof(float));
|
||||
}
|
||||
|
||||
void AnimCompressGetBase(int i,float *x,float *y,float *z)
|
||||
{
|
||||
*x=base[i*3];
|
||||
*y=base[i*3+1];
|
||||
*z=base[i*3+2];
|
||||
}
|
||||
|
||||
void AnimCompressEnd()
|
||||
{
|
||||
free(matrix);
|
||||
free(best);
|
||||
free(delta);
|
||||
free(comp);
|
||||
free(tcomp);
|
||||
free(bestcomp);
|
||||
free(base);
|
||||
free(frames);
|
||||
}
|
||||
43
tools/quake2/qdata_heretic2/animcomp.h
Normal file
43
tools/quake2/qdata_heretic2/animcomp.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#if !defined(ANIMCOMP_INC)
|
||||
#define ANIMCOMP_INC
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
void AnimCompressInit(int nFrames,int nVerts,int CompressedFrameSize);
|
||||
void AnimSetFrame(int frame,int index,float x,float y,float z);
|
||||
void AnimCompressDoit();
|
||||
void AnimCompressToBytes(float *trans,float *scale,char *mat,char *ccomp,unsigned char *cbase,float *cscale,float *coffset,float *bmin,float *bmax);
|
||||
void AnimCompressGetMatrix(float *mat);
|
||||
void AnimCompressGetFrames(float *mat);
|
||||
void AnimCompressGetBase(int i,float *x,float *y,float *z);
|
||||
void AnimCompressEnd();
|
||||
void DOsvdPlane(float *pnts,int npnts,float *n,float *base);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
184
tools/quake2/qdata_heretic2/anorms.h
Normal file
184
tools/quake2/qdata_heretic2/anorms.h
Normal file
@@ -0,0 +1,184 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
{-0.525731f, 0.000000f, 0.850651f},
|
||||
{-0.442863f, 0.238856f, 0.864188f},
|
||||
{-0.295242f, 0.000000f, 0.955423f},
|
||||
{-0.309017f, 0.500000f, 0.809017f},
|
||||
{-0.162460f, 0.262866f, 0.951056f},
|
||||
{0.000000f, 0.000000f, 1.000000f},
|
||||
{0.000000f, 0.850651f, 0.525731f},
|
||||
{-0.147621f, 0.716567f, 0.681718f},
|
||||
{0.147621f, 0.716567f, 0.681718f},
|
||||
{0.000000f, 0.525731f, 0.850651f},
|
||||
{0.309017f, 0.500000f, 0.809017f},
|
||||
{0.525731f, 0.000000f, 0.850651f},
|
||||
{0.295242f, 0.000000f, 0.955423f},
|
||||
{0.442863f, 0.238856f, 0.864188f},
|
||||
{0.162460f, 0.262866f, 0.951056f},
|
||||
{-0.681718f, 0.147621f, 0.716567f},
|
||||
{-0.809017f, 0.309017f, 0.500000f},
|
||||
{-0.587785f, 0.425325f, 0.688191f},
|
||||
{-0.850651f, 0.525731f, 0.000000f},
|
||||
{-0.864188f, 0.442863f, 0.238856f},
|
||||
{-0.716567f, 0.681718f, 0.147621f},
|
||||
{-0.688191f, 0.587785f, 0.425325f},
|
||||
{-0.500000f, 0.809017f, 0.309017f},
|
||||
{-0.238856f, 0.864188f, 0.442863f},
|
||||
{-0.425325f, 0.688191f, 0.587785f},
|
||||
{-0.716567f, 0.681718f, -0.147621f},
|
||||
{-0.500000f, 0.809017f, -0.309017f},
|
||||
{-0.525731f, 0.850651f, 0.000000f},
|
||||
{0.000000f, 0.850651f, -0.525731f},
|
||||
{-0.238856f, 0.864188f, -0.442863f},
|
||||
{0.000000f, 0.955423f, -0.295242f},
|
||||
{-0.262866f, 0.951056f, -0.162460f},
|
||||
{0.000000f, 1.000000f, 0.000000f},
|
||||
{0.000000f, 0.955423f, 0.295242f},
|
||||
{-0.262866f, 0.951056f, 0.162460f},
|
||||
{0.238856f, 0.864188f, 0.442863f},
|
||||
{0.262866f, 0.951056f, 0.162460f},
|
||||
{0.500000f, 0.809017f, 0.309017f},
|
||||
{0.238856f, 0.864188f, -0.442863f},
|
||||
{0.262866f, 0.951056f, -0.162460f},
|
||||
{0.500000f, 0.809017f, -0.309017f},
|
||||
{0.850651f, 0.525731f, 0.000000f},
|
||||
{0.716567f, 0.681718f, 0.147621f},
|
||||
{0.716567f, 0.681718f, -0.147621f},
|
||||
{0.525731f, 0.850651f, 0.000000f},
|
||||
{0.425325f, 0.688191f, 0.587785f},
|
||||
{0.864188f, 0.442863f, 0.238856f},
|
||||
{0.688191f, 0.587785f, 0.425325f},
|
||||
{0.809017f, 0.309017f, 0.500000f},
|
||||
{0.681718f, 0.147621f, 0.716567f},
|
||||
{0.587785f, 0.425325f, 0.688191f},
|
||||
{0.955423f, 0.295242f, 0.000000f},
|
||||
{1.000000f, 0.000000f, 0.000000f},
|
||||
{0.951056f, 0.162460f, 0.262866f},
|
||||
{0.850651f, -0.525731f, 0.000000f},
|
||||
{0.955423f, -0.295242f, 0.000000f},
|
||||
{0.864188f, -0.442863f, 0.238856f},
|
||||
{0.951056f, -0.162460f, 0.262866f},
|
||||
{0.809017f, -0.309017f, 0.500000f},
|
||||
{0.681718f, -0.147621f, 0.716567f},
|
||||
{0.850651f, 0.000000f, 0.525731f},
|
||||
{0.864188f, 0.442863f, -0.238856f},
|
||||
{0.809017f, 0.309017f, -0.500000f},
|
||||
{0.951056f, 0.162460f, -0.262866f},
|
||||
{0.525731f, 0.000000f, -0.850651f},
|
||||
{0.681718f, 0.147621f, -0.716567f},
|
||||
{0.681718f, -0.147621f, -0.716567f},
|
||||
{0.850651f, 0.000000f, -0.525731f},
|
||||
{0.809017f, -0.309017f, -0.500000f},
|
||||
{0.864188f, -0.442863f, -0.238856f},
|
||||
{0.951056f, -0.162460f, -0.262866f},
|
||||
{0.147621f, 0.716567f, -0.681718f},
|
||||
{0.309017f, 0.500000f, -0.809017f},
|
||||
{0.425325f, 0.688191f, -0.587785f},
|
||||
{0.442863f, 0.238856f, -0.864188f},
|
||||
{0.587785f, 0.425325f, -0.688191f},
|
||||
{0.688191f, 0.587785f, -0.425325f},
|
||||
{-0.147621f, 0.716567f, -0.681718f},
|
||||
{-0.309017f, 0.500000f, -0.809017f},
|
||||
{0.000000f, 0.525731f, -0.850651f},
|
||||
{-0.525731f, 0.000000f, -0.850651f},
|
||||
{-0.442863f, 0.238856f, -0.864188f},
|
||||
{-0.295242f, 0.000000f, -0.955423f},
|
||||
{-0.162460f, 0.262866f, -0.951056f},
|
||||
{0.000000f, 0.000000f, -1.000000f},
|
||||
{0.295242f, 0.000000f, -0.955423f},
|
||||
{0.162460f, 0.262866f, -0.951056f},
|
||||
{-0.442863f, -0.238856f, -0.864188f},
|
||||
{-0.309017f, -0.500000f, -0.809017f},
|
||||
{-0.162460f, -0.262866f, -0.951056f},
|
||||
{0.000000f, -0.850651f, -0.525731f},
|
||||
{-0.147621f, -0.716567f, -0.681718f},
|
||||
{0.147621f, -0.716567f, -0.681718f},
|
||||
{0.000000f, -0.525731f, -0.850651f},
|
||||
{0.309017f, -0.500000f, -0.809017f},
|
||||
{0.442863f, -0.238856f, -0.864188f},
|
||||
{0.162460f, -0.262866f, -0.951056f},
|
||||
{0.238856f, -0.864188f, -0.442863f},
|
||||
{0.500000f, -0.809017f, -0.309017f},
|
||||
{0.425325f, -0.688191f, -0.587785f},
|
||||
{0.716567f, -0.681718f, -0.147621f},
|
||||
{0.688191f, -0.587785f, -0.425325f},
|
||||
{0.587785f, -0.425325f, -0.688191f},
|
||||
{0.000000f, -0.955423f, -0.295242f},
|
||||
{0.000000f, -1.000000f, 0.000000f},
|
||||
{0.262866f, -0.951056f, -0.162460f},
|
||||
{0.000000f, -0.850651f, 0.525731f},
|
||||
{0.000000f, -0.955423f, 0.295242f},
|
||||
{0.238856f, -0.864188f, 0.442863f},
|
||||
{0.262866f, -0.951056f, 0.162460f},
|
||||
{0.500000f, -0.809017f, 0.309017f},
|
||||
{0.716567f, -0.681718f, 0.147621f},
|
||||
{0.525731f, -0.850651f, 0.000000f},
|
||||
{-0.238856f, -0.864188f, -0.442863f},
|
||||
{-0.500000f, -0.809017f, -0.309017f},
|
||||
{-0.262866f, -0.951056f, -0.162460f},
|
||||
{-0.850651f, -0.525731f, 0.000000f},
|
||||
{-0.716567f, -0.681718f, -0.147621f},
|
||||
{-0.716567f, -0.681718f, 0.147621f},
|
||||
{-0.525731f, -0.850651f, 0.000000f},
|
||||
{-0.500000f, -0.809017f, 0.309017f},
|
||||
{-0.238856f, -0.864188f, 0.442863f},
|
||||
{-0.262866f, -0.951056f, 0.162460f},
|
||||
{-0.864188f, -0.442863f, 0.238856f},
|
||||
{-0.809017f, -0.309017f, 0.500000f},
|
||||
{-0.688191f, -0.587785f, 0.425325f},
|
||||
{-0.681718f, -0.147621f, 0.716567f},
|
||||
{-0.442863f, -0.238856f, 0.864188f},
|
||||
{-0.587785f, -0.425325f, 0.688191f},
|
||||
{-0.309017f, -0.500000f, 0.809017f},
|
||||
{-0.147621f, -0.716567f, 0.681718f},
|
||||
{-0.425325f, -0.688191f, 0.587785f},
|
||||
{-0.162460f, -0.262866f, 0.951056f},
|
||||
{0.442863f, -0.238856f, 0.864188f},
|
||||
{0.162460f, -0.262866f, 0.951056f},
|
||||
{0.309017f, -0.500000f, 0.809017f},
|
||||
{0.147621f, -0.716567f, 0.681718f},
|
||||
{0.000000f, -0.525731f, 0.850651f},
|
||||
{0.425325f, -0.688191f, 0.587785f},
|
||||
{0.587785f, -0.425325f, 0.688191f},
|
||||
{0.688191f, -0.587785f, 0.425325f},
|
||||
{-0.955423f, 0.295242f, 0.000000f},
|
||||
{-0.951056f, 0.162460f, 0.262866f},
|
||||
{-1.000000f, 0.000000f, 0.000000f},
|
||||
{-0.850651f, 0.000000f, 0.525731f},
|
||||
{-0.955423f, -0.295242f, 0.000000f},
|
||||
{-0.951056f, -0.162460f, 0.262866f},
|
||||
{-0.864188f, 0.442863f, -0.238856f},
|
||||
{-0.951056f, 0.162460f, -0.262866f},
|
||||
{-0.809017f, 0.309017f, -0.500000f},
|
||||
{-0.864188f, -0.442863f, -0.238856f},
|
||||
{-0.951056f, -0.162460f, -0.262866f},
|
||||
{-0.809017f, -0.309017f, -0.500000f},
|
||||
{-0.681718f, 0.147621f, -0.716567f},
|
||||
{-0.681718f, -0.147621f, -0.716567f},
|
||||
{-0.850651f, 0.000000f, -0.525731f},
|
||||
{-0.688191f, 0.587785f, -0.425325f},
|
||||
{-0.587785f, 0.425325f, -0.688191f},
|
||||
{-0.425325f, 0.688191f, -0.587785f},
|
||||
{-0.425325f, -0.688191f, -0.587785f},
|
||||
{-0.587785f, -0.425325f, -0.688191f},
|
||||
{-0.688191f, -0.587785f, -0.425325f},
|
||||
|
||||
372
tools/quake2/qdata_heretic2/book.c
Normal file
372
tools/quake2/qdata_heretic2/book.c
Normal file
@@ -0,0 +1,372 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
|
||||
#include "qdata.h"
|
||||
|
||||
byte *byteimage, *lbmpalette;
|
||||
int byteimagewidth, byteimageheight;
|
||||
|
||||
qboolean TrueColorImage;
|
||||
int longimagewidth, longimageheight;
|
||||
|
||||
char book_prefix[1024];
|
||||
byte buffer[640 * 480];
|
||||
unsigned long bufferl[640 * 480];
|
||||
|
||||
miptex_t *CreateBook8(byte *buffer, int w, int h, byte *palette, int *FinalSize)
|
||||
{
|
||||
miptex_t *mp;
|
||||
int i, j;
|
||||
byte *pos;
|
||||
int size;
|
||||
|
||||
size = sizeof(*mp) + (w * h);
|
||||
mp = (miptex_t *)SafeMalloc(size, "CreateBook8");
|
||||
memset(mp, 0, size);
|
||||
|
||||
mp->version = MIP_VERSION;
|
||||
|
||||
for(i=j=0;i<256;i++,j+=3)
|
||||
{
|
||||
mp->palette[i].r = palette[j];
|
||||
mp->palette[i].g = palette[j+1];
|
||||
mp->palette[i].b = palette[j+2];
|
||||
}
|
||||
pos = (byte *)(mp + 1);
|
||||
|
||||
mp->width[0] = w;
|
||||
mp->height[0] = h;
|
||||
mp->offsets[0] = sizeof(*mp);
|
||||
memcpy(pos, buffer, w * h);
|
||||
|
||||
*FinalSize = size;
|
||||
return(mp);
|
||||
}
|
||||
|
||||
miptex32_t *CreateBook32(long *buffer, int w, int h, int *FinalSize)
|
||||
{
|
||||
miptex32_t *mp;
|
||||
byte *pos;
|
||||
int size;
|
||||
|
||||
size = sizeof(*mp) + (w * h * 4);
|
||||
mp = (miptex32_t *)SafeMalloc(size, "CreateBook32");
|
||||
memset(mp, 0, size);
|
||||
|
||||
mp->version = MIP32_VERSION;
|
||||
|
||||
pos = (byte *)(mp + 1);
|
||||
|
||||
mp->width[0] = w;
|
||||
mp->height[0] = h;
|
||||
mp->offsets[0] = sizeof(*mp);
|
||||
memcpy(pos, buffer, w * h * 4);
|
||||
|
||||
*FinalSize = size;
|
||||
return(mp);
|
||||
}
|
||||
|
||||
|
||||
// Routines to chop a random sized image into gl texture friendly chunks
|
||||
|
||||
typedef struct rect_s
|
||||
{
|
||||
int x, y;
|
||||
int w, h;
|
||||
char name[4];
|
||||
} rect_t;
|
||||
|
||||
int GetCoords(int x, int store[MAX_MD2SKINS])
|
||||
{
|
||||
int index, start, delta;
|
||||
|
||||
index = 0;
|
||||
start = 0;
|
||||
delta = 256;
|
||||
|
||||
store[index++] = start;
|
||||
while(x)
|
||||
{
|
||||
if(x >= delta)
|
||||
{
|
||||
start += delta;
|
||||
store[index++] = start;
|
||||
x -= delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
delta >>= 1;
|
||||
}
|
||||
}
|
||||
return(index);
|
||||
}
|
||||
|
||||
int ChopImage(int w, int h, rect_t coords[MAX_MD2SKINS])
|
||||
{
|
||||
int xs[MAX_MD2SKINS], ys[MAX_MD2SKINS];
|
||||
int xcount, ycount, x, y, index;
|
||||
|
||||
index = 0;
|
||||
xcount = GetCoords(w, xs) - 1;
|
||||
ycount = GetCoords(h, ys) - 1;
|
||||
|
||||
for(y = 0; y < ycount; y++)
|
||||
{
|
||||
for(x = 0; x < xcount; x++, index++)
|
||||
{
|
||||
coords[index].x = xs[x];
|
||||
coords[index].y = ys[y];
|
||||
coords[index].w = xs[x + 1] - xs[x];
|
||||
coords[index].h = ys[y + 1] - ys[y];
|
||||
coords[index].name[0] = x + '0';
|
||||
coords[index].name[1] = y + '0';
|
||||
coords[index].name[2] = 0;
|
||||
}
|
||||
}
|
||||
return(index);
|
||||
}
|
||||
|
||||
/*
|
||||
===============
|
||||
Cmd_Pic
|
||||
===============
|
||||
*/
|
||||
|
||||
void Cmd_Book()
|
||||
{
|
||||
int xl,yl,xh,yh,w,h;
|
||||
byte *dest, *source;
|
||||
int flags, value, contents;
|
||||
char lumpname[64];
|
||||
char filename[1024];
|
||||
unsigned long *destl, *sourcel;
|
||||
int linedelta, x, y;
|
||||
int size;
|
||||
miptex_t *qtex;
|
||||
miptex32_t *qtex32;
|
||||
float scale_x, scale_y;
|
||||
int numrects, i;
|
||||
rect_t coords[MAX_MD2SKINS];
|
||||
bookframe_t bframes[MAX_MD2SKINS];
|
||||
bookframe_t *bf;
|
||||
book_t book;
|
||||
|
||||
GetScriptToken (false);
|
||||
strcpy (lumpname, token);
|
||||
|
||||
GetScriptToken (false);
|
||||
xl = atoi (token);
|
||||
GetScriptToken (false);
|
||||
yl = atoi (token);
|
||||
GetScriptToken (false);
|
||||
w = atoi (token);
|
||||
GetScriptToken (false);
|
||||
h = atoi (token);
|
||||
|
||||
total_x += w;
|
||||
total_y += h;
|
||||
total_textures++;
|
||||
|
||||
if ( (w & 7) || (h & 7) )
|
||||
Error ("line %i: miptex sizes must be multiples of 8", scriptline);
|
||||
|
||||
flags = 0;
|
||||
contents = 0;
|
||||
value = 0;
|
||||
|
||||
scale_x = scale_y = 0.5;
|
||||
|
||||
if (g_release)
|
||||
return;
|
||||
|
||||
if(TrueColorImage)
|
||||
{
|
||||
xh = xl + w;
|
||||
yh = yl + h;
|
||||
|
||||
if (xl >= longimagewidth || xh > longimagewidth ||
|
||||
yl >= longimageheight || yh > longimageheight)
|
||||
{
|
||||
Error ("line %i: bad clip dimmensions (%d,%d) (%d,%d) > image (%d,%d)", scriptline, xl,yl,w,h,longimagewidth,longimageheight);
|
||||
}
|
||||
|
||||
sourcel = (unsigned long *) longimage + (yl * longimagewidth) + xl;
|
||||
destl = (unsigned long *) longimage;
|
||||
linedelta = (longimagewidth - w);
|
||||
|
||||
for(y = yl; y < yh; y++)
|
||||
{
|
||||
for(x = xl; x < xh; x++)
|
||||
{
|
||||
*destl++ = *sourcel++; // RGBA
|
||||
}
|
||||
sourcel += linedelta;
|
||||
}
|
||||
|
||||
// Get rectangles to chop into
|
||||
numrects = ChopImage(w, h, coords);
|
||||
|
||||
bf = bframes;
|
||||
for(i = 0; i < numrects; i++, bf++)
|
||||
{
|
||||
// Copy section of image to buffer
|
||||
sourcel = (unsigned long *) longimage + (coords[i].y * w) + coords[i].x;
|
||||
destl = bufferl;
|
||||
linedelta = w - coords[i].w;
|
||||
|
||||
for(y = 0; y < coords[i].h; y++)
|
||||
{
|
||||
for(x = 0; x < coords[i].w; x++)
|
||||
{
|
||||
*destl++ = *sourcel++;
|
||||
}
|
||||
sourcel += linedelta;
|
||||
}
|
||||
|
||||
qtex32 = CreateBook32(bufferl, coords[i].w, coords[i].h, &size);
|
||||
|
||||
qtex32->flags = flags;
|
||||
qtex32->contents = contents;
|
||||
qtex32->value = value;
|
||||
qtex32->scale_x = scale_x;
|
||||
qtex32->scale_y = scale_y;
|
||||
|
||||
sprintf (filename, "%sbook/%s/%s_%s.m32", gamedir, book_prefix, lumpname, coords[i].name);
|
||||
sprintf (qtex32->name, "%s/%s_%s.m32", book_prefix, lumpname, coords[i].name);
|
||||
|
||||
strcpy(bf->name, qtex32->name);
|
||||
bf->x = coords[i].x;
|
||||
bf->y = coords[i].y;
|
||||
bf->w = coords[i].w;
|
||||
bf->h = coords[i].h;
|
||||
//
|
||||
// write it out
|
||||
//
|
||||
printf ("writing %s\n", filename);
|
||||
SaveFile (filename, (byte *)qtex32, size);
|
||||
|
||||
free (qtex32);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
xh = xl + w;
|
||||
yh = yl + h;
|
||||
|
||||
if (xl >= byteimagewidth || xh > byteimagewidth ||
|
||||
yl >= byteimageheight || yh > byteimageheight)
|
||||
{
|
||||
Error ("line %i: bad clip dimmensions (%d,%d) (%d,%d) > image (%d,%d)", scriptline, xl,yl,w,h,byteimagewidth,byteimageheight);
|
||||
}
|
||||
|
||||
// Copy image to top left
|
||||
source = byteimage + yl*byteimagewidth + xl;
|
||||
dest = byteimage;
|
||||
linedelta = byteimagewidth - w;
|
||||
|
||||
for(y = yl; y < yh; y++)
|
||||
{
|
||||
for(x = xl; x < xh; x++)
|
||||
{
|
||||
*dest++ = *source++;
|
||||
}
|
||||
source += linedelta;
|
||||
}
|
||||
|
||||
// Get rectangles to chop into
|
||||
numrects = ChopImage(w, h, coords);
|
||||
|
||||
bf = bframes;
|
||||
for(i = 0; i < numrects; i++, bf++)
|
||||
{
|
||||
// Copy section of image to buffer
|
||||
source = byteimage + (coords[i].y * w) + coords[i].x;
|
||||
dest = buffer;
|
||||
linedelta = w - coords[i].w;
|
||||
|
||||
for(y = 0; y < coords[i].h; y++)
|
||||
{
|
||||
for(x = 0; x < coords[i].w; x++)
|
||||
{
|
||||
*dest++ = *source++;
|
||||
}
|
||||
source += linedelta;
|
||||
}
|
||||
|
||||
qtex = CreateBook8(buffer, coords[i].w, coords[i].h, lbmpalette, &size);
|
||||
|
||||
qtex->flags = flags;
|
||||
qtex->contents = contents;
|
||||
qtex->value = value;
|
||||
|
||||
sprintf (filename, "%sbook/%s/%s_%s.m8", gamedir, book_prefix, lumpname, coords[i].name);
|
||||
sprintf (qtex->name, "%s/%s_%s.m8", book_prefix, lumpname, coords[i].name);
|
||||
|
||||
strcpy(bf->name, qtex->name);
|
||||
bf->x = coords[i].x;
|
||||
bf->y = coords[i].y;
|
||||
bf->w = coords[i].w;
|
||||
bf->h = coords[i].h;
|
||||
//
|
||||
// write it out
|
||||
//
|
||||
printf ("writing %s\n", filename);
|
||||
SaveFile (filename, (byte *)qtex, size);
|
||||
|
||||
free (qtex);
|
||||
}
|
||||
}
|
||||
// Set up descriptor
|
||||
size = sizeof(bookframe_t) * numrects;
|
||||
|
||||
book.bheader.ident = IDBOOKHEADER;
|
||||
book.bheader.version = BOOK_VERSION;
|
||||
book.bheader.num_segments = numrects;
|
||||
book.bheader.total_w = w;
|
||||
book.bheader.total_h = h;
|
||||
memcpy(book.bframes, bframes, size);
|
||||
|
||||
// Save out segment descriptor
|
||||
sprintf (filename, "%sBook/%s/%s.bk", gamedir, book_prefix, lumpname);
|
||||
printf ("writing %s\n", filename);
|
||||
SaveFile (filename, (byte *)&book, size + sizeof(bookheader_t));
|
||||
}
|
||||
|
||||
/*
|
||||
===============
|
||||
Cmd_picdir
|
||||
===============
|
||||
*/
|
||||
void Cmd_Bookdir (void)
|
||||
{
|
||||
char filename[1024];
|
||||
|
||||
GetScriptToken (false);
|
||||
strcpy (book_prefix, token);
|
||||
// create the directory if needed
|
||||
sprintf (filename, "%sBook", gamedir);
|
||||
Q_mkdir (filename);
|
||||
sprintf (filename, "%sBook/%s", gamedir, book_prefix);
|
||||
Q_mkdir (filename);
|
||||
}
|
||||
|
||||
// end
|
||||
793
tools/quake2/qdata_heretic2/common/bspfile.c
Normal file
793
tools/quake2/qdata_heretic2/common/bspfile.c
Normal file
@@ -0,0 +1,793 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
|
||||
#include "cmdlib.h"
|
||||
#include "inout.h"
|
||||
#include "mathlib.h"
|
||||
#include "bspfile.h"
|
||||
#include "scriplib.h"
|
||||
|
||||
void GetLeafNums (void);
|
||||
|
||||
//=============================================================================
|
||||
|
||||
int nummodels;
|
||||
dmodel_t dmodels[MAX_MAP_MODELS];
|
||||
|
||||
int visdatasize;
|
||||
byte dvisdata[MAX_MAP_VISIBILITY];
|
||||
dvis_t *dvis = (dvis_t *)dvisdata;
|
||||
|
||||
int lightdatasize;
|
||||
byte dlightdata[MAX_MAP_LIGHTING];
|
||||
|
||||
int entdatasize;
|
||||
char dentdata[MAX_MAP_ENTSTRING];
|
||||
|
||||
int numleafs;
|
||||
dleaf_t dleafs[MAX_MAP_LEAFS];
|
||||
|
||||
int numplanes;
|
||||
dplane_t dplanes[MAX_MAP_PLANES];
|
||||
|
||||
int numvertexes;
|
||||
dvertex_t dvertexes[MAX_MAP_VERTS];
|
||||
|
||||
int numnodes;
|
||||
dnode_t dnodes[MAX_MAP_NODES];
|
||||
|
||||
int numtexinfo;
|
||||
texinfo_t texinfo[MAX_MAP_TEXINFO];
|
||||
|
||||
int numfaces;
|
||||
dface_t dfaces[MAX_MAP_FACES];
|
||||
|
||||
int numedges;
|
||||
dedge_t dedges[MAX_MAP_EDGES];
|
||||
|
||||
int numleaffaces;
|
||||
unsigned short dleaffaces[MAX_MAP_LEAFFACES];
|
||||
|
||||
int numleafbrushes;
|
||||
unsigned short dleafbrushes[MAX_MAP_LEAFBRUSHES];
|
||||
|
||||
int numsurfedges;
|
||||
int dsurfedges[MAX_MAP_SURFEDGES];
|
||||
|
||||
int numbrushes;
|
||||
dbrush_t dbrushes[MAX_MAP_BRUSHES];
|
||||
|
||||
int numbrushsides;
|
||||
dbrushside_t dbrushsides[MAX_MAP_BRUSHSIDES];
|
||||
|
||||
int numareas;
|
||||
darea_t dareas[MAX_MAP_AREAS];
|
||||
|
||||
int numareaportals;
|
||||
dareaportal_t dareaportals[MAX_MAP_AREAPORTALS];
|
||||
|
||||
byte dpop[256];
|
||||
|
||||
/*
|
||||
===============
|
||||
CompressVis
|
||||
|
||||
===============
|
||||
*/
|
||||
int CompressVis (byte *vis, byte *dest)
|
||||
{
|
||||
int j;
|
||||
int rep;
|
||||
int visrow;
|
||||
byte *dest_p;
|
||||
|
||||
dest_p = dest;
|
||||
// visrow = (r_numvisleafs + 7)>>3;
|
||||
visrow = (dvis->numclusters + 7)>>3;
|
||||
|
||||
for (j=0 ; j<visrow ; j++)
|
||||
{
|
||||
*dest_p++ = vis[j];
|
||||
if (vis[j])
|
||||
continue;
|
||||
|
||||
rep = 1;
|
||||
for ( j++; j<visrow ; j++)
|
||||
if (vis[j] || rep == 255)
|
||||
break;
|
||||
else
|
||||
rep++;
|
||||
*dest_p++ = rep;
|
||||
j--;
|
||||
}
|
||||
|
||||
return dest_p - dest;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
===================
|
||||
DecompressVis
|
||||
===================
|
||||
*/
|
||||
void DecompressVis (byte *in, byte *decompressed)
|
||||
{
|
||||
int c;
|
||||
byte *out;
|
||||
int row;
|
||||
|
||||
// row = (r_numvisleafs+7)>>3;
|
||||
row = (dvis->numclusters+7)>>3;
|
||||
out = decompressed;
|
||||
|
||||
do
|
||||
{
|
||||
if (*in)
|
||||
{
|
||||
*out++ = *in++;
|
||||
continue;
|
||||
}
|
||||
|
||||
c = in[1];
|
||||
if (!c)
|
||||
Error ("DecompressVis: 0 repeat");
|
||||
in += 2;
|
||||
while (c)
|
||||
{
|
||||
*out++ = 0;
|
||||
c--;
|
||||
}
|
||||
} while (out - decompressed < row);
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
|
||||
/*
|
||||
=============
|
||||
SwapBSPFile
|
||||
|
||||
Byte swaps all data in a bsp file.
|
||||
=============
|
||||
*/
|
||||
void SwapBSPFile (qboolean todisk)
|
||||
{
|
||||
int i, j;
|
||||
dmodel_t *d;
|
||||
|
||||
|
||||
// models
|
||||
for (i=0 ; i<nummodels ; i++)
|
||||
{
|
||||
d = &dmodels[i];
|
||||
|
||||
d->firstface = LittleLong (d->firstface);
|
||||
d->numfaces = LittleLong (d->numfaces);
|
||||
d->headnode = LittleLong (d->headnode);
|
||||
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// vertexes
|
||||
//
|
||||
for (i=0 ; i<numvertexes ; i++)
|
||||
{
|
||||
for (j=0 ; j<3 ; j++)
|
||||
dvertexes[i].point[j] = LittleFloat (dvertexes[i].point[j]);
|
||||
}
|
||||
|
||||
//
|
||||
// planes
|
||||
//
|
||||
for (i=0 ; i<numplanes ; i++)
|
||||
{
|
||||
for (j=0 ; j<3 ; j++)
|
||||
dplanes[i].normal[j] = LittleFloat (dplanes[i].normal[j]);
|
||||
dplanes[i].dist = LittleFloat (dplanes[i].dist);
|
||||
dplanes[i].type = LittleLong (dplanes[i].type);
|
||||
}
|
||||
|
||||
//
|
||||
// texinfos
|
||||
//
|
||||
for (i=0 ; i<numtexinfo ; i++)
|
||||
{
|
||||
for (j=0 ; j<8 ; j++)
|
||||
texinfo[i].vecs[0][j] = LittleFloat (texinfo[i].vecs[0][j]);
|
||||
texinfo[i].flags = LittleLong (texinfo[i].flags);
|
||||
texinfo[i].value = LittleLong (texinfo[i].value);
|
||||
texinfo[i].nexttexinfo = LittleLong (texinfo[i].nexttexinfo);
|
||||
}
|
||||
|
||||
//
|
||||
// faces
|
||||
//
|
||||
for (i=0 ; i<numfaces ; i++)
|
||||
{
|
||||
dfaces[i].texinfo = LittleShort (dfaces[i].texinfo);
|
||||
dfaces[i].planenum = LittleShort (dfaces[i].planenum);
|
||||
dfaces[i].side = LittleShort (dfaces[i].side);
|
||||
dfaces[i].lighting.c = LittleLong (dfaces[i].lighting.c);
|
||||
dfaces[i].lightofs = LittleLong (dfaces[i].lightofs);
|
||||
dfaces[i].firstedge = LittleLong (dfaces[i].firstedge);
|
||||
dfaces[i].numedges = LittleShort (dfaces[i].numedges);
|
||||
}
|
||||
|
||||
//
|
||||
// nodes
|
||||
//
|
||||
for (i=0 ; i<numnodes ; i++)
|
||||
{
|
||||
dnodes[i].planenum = LittleLong (dnodes[i].planenum);
|
||||
for (j=0 ; j<3 ; j++)
|
||||
{
|
||||
dnodes[i].mins[j] = LittleShort (dnodes[i].mins[j]);
|
||||
dnodes[i].maxs[j] = LittleShort (dnodes[i].maxs[j]);
|
||||
}
|
||||
dnodes[i].children[0] = LittleLong (dnodes[i].children[0]);
|
||||
dnodes[i].children[1] = LittleLong (dnodes[i].children[1]);
|
||||
dnodes[i].firstface = LittleShort (dnodes[i].firstface);
|
||||
dnodes[i].numfaces = LittleShort (dnodes[i].numfaces);
|
||||
}
|
||||
|
||||
//
|
||||
// leafs
|
||||
//
|
||||
for (i=0 ; i<numleafs ; i++)
|
||||
{
|
||||
dleafs[i].contents = LittleLong (dleafs[i].contents);
|
||||
dleafs[i].cluster = LittleShort (dleafs[i].cluster);
|
||||
dleafs[i].area = LittleShort (dleafs[i].area);
|
||||
for (j=0 ; j<3 ; j++)
|
||||
{
|
||||
dleafs[i].mins[j] = LittleShort (dleafs[i].mins[j]);
|
||||
dleafs[i].maxs[j] = LittleShort (dleafs[i].maxs[j]);
|
||||
}
|
||||
|
||||
dleafs[i].firstleafface = LittleShort (dleafs[i].firstleafface);
|
||||
dleafs[i].numleaffaces = LittleShort (dleafs[i].numleaffaces);
|
||||
dleafs[i].firstleafbrush = LittleShort (dleafs[i].firstleafbrush);
|
||||
dleafs[i].numleafbrushes = LittleShort (dleafs[i].numleafbrushes);
|
||||
}
|
||||
|
||||
//
|
||||
// leaffaces
|
||||
//
|
||||
for (i=0 ; i<numleaffaces ; i++)
|
||||
dleaffaces[i] = LittleShort (dleaffaces[i]);
|
||||
|
||||
//
|
||||
// leafbrushes
|
||||
//
|
||||
for (i=0 ; i<numleafbrushes ; i++)
|
||||
dleafbrushes[i] = LittleShort (dleafbrushes[i]);
|
||||
|
||||
//
|
||||
// surfedges
|
||||
//
|
||||
for (i=0 ; i<numsurfedges ; i++)
|
||||
dsurfedges[i] = LittleLong (dsurfedges[i]);
|
||||
|
||||
//
|
||||
// edges
|
||||
//
|
||||
for (i=0 ; i<numedges ; i++)
|
||||
{
|
||||
dedges[i].v[0] = LittleShort (dedges[i].v[0]);
|
||||
dedges[i].v[1] = LittleShort (dedges[i].v[1]);
|
||||
}
|
||||
|
||||
//
|
||||
// brushes
|
||||
//
|
||||
for (i=0 ; i<numbrushes ; i++)
|
||||
{
|
||||
dbrushes[i].firstside = LittleLong (dbrushes[i].firstside);
|
||||
dbrushes[i].numsides = LittleLong (dbrushes[i].numsides);
|
||||
dbrushes[i].contents = LittleLong (dbrushes[i].contents);
|
||||
}
|
||||
|
||||
//
|
||||
// areas
|
||||
//
|
||||
for (i=0 ; i<numareas ; i++)
|
||||
{
|
||||
dareas[i].numareaportals = LittleLong (dareas[i].numareaportals);
|
||||
dareas[i].firstareaportal = LittleLong (dareas[i].firstareaportal);
|
||||
}
|
||||
|
||||
//
|
||||
// areasportals
|
||||
//
|
||||
for (i=0 ; i<numareaportals ; i++)
|
||||
{
|
||||
dareaportals[i].portalnum = LittleLong (dareaportals[i].portalnum);
|
||||
dareaportals[i].otherarea = LittleLong (dareaportals[i].otherarea);
|
||||
}
|
||||
|
||||
//
|
||||
// brushsides
|
||||
//
|
||||
for (i=0 ; i<numbrushsides ; i++)
|
||||
{
|
||||
dbrushsides[i].planenum = LittleShort (dbrushsides[i].planenum);
|
||||
dbrushsides[i].texinfo = LittleShort (dbrushsides[i].texinfo);
|
||||
}
|
||||
|
||||
//
|
||||
// visibility
|
||||
//
|
||||
if (todisk)
|
||||
j = dvis->numclusters;
|
||||
else
|
||||
j = LittleLong(dvis->numclusters);
|
||||
dvis->numclusters = LittleLong (dvis->numclusters);
|
||||
for (i=0 ; i<j ; i++)
|
||||
{
|
||||
dvis->bitofs[i][0] = LittleLong (dvis->bitofs[i][0]);
|
||||
dvis->bitofs[i][1] = LittleLong (dvis->bitofs[i][1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
dheader_t *header;
|
||||
|
||||
int CopyLump (int lump, void *dest, int size)
|
||||
{
|
||||
int length, ofs;
|
||||
|
||||
length = header->lumps[lump].filelen;
|
||||
ofs = header->lumps[lump].fileofs;
|
||||
|
||||
if (length % size)
|
||||
Error ("LoadBSPFile: odd lump size");
|
||||
|
||||
memcpy (dest, (byte *)header + ofs, length);
|
||||
|
||||
return length / size;
|
||||
}
|
||||
|
||||
/*
|
||||
=============
|
||||
LoadBSPFile
|
||||
=============
|
||||
*/
|
||||
void LoadBSPFile (char *filename)
|
||||
{
|
||||
int i;
|
||||
|
||||
//
|
||||
// load the file header
|
||||
//
|
||||
LoadFile (filename, (void **)&header);
|
||||
|
||||
// swap the header
|
||||
for (i=0 ; i< sizeof(dheader_t)/4 ; i++)
|
||||
((int *)header)[i] = LittleLong ( ((int *)header)[i]);
|
||||
|
||||
if (header->ident != IDBSPHEADER)
|
||||
Error ("%s is not a IBSP file", filename);
|
||||
if (header->version != BSPVERSION)
|
||||
Error ("%s is version %i, not %i", filename, header->version, BSPVERSION);
|
||||
|
||||
nummodels = CopyLump (LUMP_MODELS, dmodels, sizeof(dmodel_t));
|
||||
numvertexes = CopyLump (LUMP_VERTEXES, dvertexes, sizeof(dvertex_t));
|
||||
numplanes = CopyLump (LUMP_PLANES, dplanes, sizeof(dplane_t));
|
||||
numleafs = CopyLump (LUMP_LEAFS, dleafs, sizeof(dleaf_t));
|
||||
numnodes = CopyLump (LUMP_NODES, dnodes, sizeof(dnode_t));
|
||||
numtexinfo = CopyLump (LUMP_TEXINFO, texinfo, sizeof(texinfo_t));
|
||||
numfaces = CopyLump (LUMP_FACES, dfaces, sizeof(dface_t));
|
||||
numleaffaces = CopyLump (LUMP_LEAFFACES, dleaffaces, sizeof(dleaffaces[0]));
|
||||
numleafbrushes = CopyLump (LUMP_LEAFBRUSHES, dleafbrushes, sizeof(dleafbrushes[0]));
|
||||
numsurfedges = CopyLump (LUMP_SURFEDGES, dsurfedges, sizeof(dsurfedges[0]));
|
||||
numedges = CopyLump (LUMP_EDGES, dedges, sizeof(dedge_t));
|
||||
numbrushes = CopyLump (LUMP_BRUSHES, dbrushes, sizeof(dbrush_t));
|
||||
numbrushsides = CopyLump (LUMP_BRUSHSIDES, dbrushsides, sizeof(dbrushside_t));
|
||||
numareas = CopyLump (LUMP_AREAS, dareas, sizeof(darea_t));
|
||||
numareaportals = CopyLump (LUMP_AREAPORTALS, dareaportals, sizeof(dareaportal_t));
|
||||
|
||||
visdatasize = CopyLump (LUMP_VISIBILITY, dvisdata, 1);
|
||||
lightdatasize = CopyLump (LUMP_LIGHTING, dlightdata, 1);
|
||||
entdatasize = CopyLump (LUMP_ENTITIES, dentdata, 1);
|
||||
|
||||
CopyLump (LUMP_POP, dpop, 1);
|
||||
|
||||
free (header); // everything has been copied out
|
||||
|
||||
//
|
||||
// swap everything
|
||||
//
|
||||
SwapBSPFile (false);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
=============
|
||||
LoadBSPFileTexinfo
|
||||
|
||||
Only loads the texinfo lump, so qdata can scan for textures
|
||||
=============
|
||||
*/
|
||||
void LoadBSPFileTexinfo (char *filename)
|
||||
{
|
||||
int i;
|
||||
FILE *f;
|
||||
int length, ofs;
|
||||
|
||||
header = malloc(sizeof(dheader_t));
|
||||
|
||||
f = fopen (filename, "rb");
|
||||
fread (header, sizeof(dheader_t), 1, f);
|
||||
|
||||
// swap the header
|
||||
for (i=0 ; i< sizeof(dheader_t)/4 ; i++)
|
||||
((int *)header)[i] = LittleLong ( ((int *)header)[i]);
|
||||
|
||||
if (header->ident != IDBSPHEADER)
|
||||
Error ("%s is not a IBSP file", filename);
|
||||
if (header->version != BSPVERSION)
|
||||
Error ("%s is version %i, not %i", filename, header->version, BSPVERSION);
|
||||
|
||||
|
||||
length = header->lumps[LUMP_TEXINFO].filelen;
|
||||
ofs = header->lumps[LUMP_TEXINFO].fileofs;
|
||||
|
||||
fseek (f, ofs, SEEK_SET);
|
||||
fread (texinfo, length, 1, f);
|
||||
fclose (f);
|
||||
|
||||
numtexinfo = length / sizeof(texinfo_t);
|
||||
|
||||
free (header); // everything has been copied out
|
||||
|
||||
SwapBSPFile (false);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
|
||||
FILE *wadfile;
|
||||
dheader_t outheader;
|
||||
|
||||
void AddLump (int lumpnum, void *data, int len)
|
||||
{
|
||||
lump_t *lump;
|
||||
|
||||
lump = &header->lumps[lumpnum];
|
||||
|
||||
lump->fileofs = LittleLong( ftell(wadfile) );
|
||||
lump->filelen = LittleLong(len);
|
||||
SafeWrite (wadfile, data, (len+3)&~3);
|
||||
}
|
||||
|
||||
/*
|
||||
=============
|
||||
WriteBSPFile
|
||||
|
||||
Swaps the bsp file in place, so it should not be referenced again
|
||||
=============
|
||||
*/
|
||||
void WriteBSPFile (char *filename)
|
||||
{
|
||||
header = &outheader;
|
||||
memset (header, 0, sizeof(dheader_t));
|
||||
|
||||
SwapBSPFile (true);
|
||||
|
||||
header->ident = LittleLong (IDBSPHEADER);
|
||||
header->version = LittleLong (BSPVERSION);
|
||||
|
||||
wadfile = SafeOpenWrite (filename);
|
||||
SafeWrite (wadfile, header, sizeof(dheader_t)); // overwritten later
|
||||
|
||||
AddLump (LUMP_PLANES, dplanes, numplanes*sizeof(dplane_t));
|
||||
AddLump (LUMP_LEAFS, dleafs, numleafs*sizeof(dleaf_t));
|
||||
AddLump (LUMP_VERTEXES, dvertexes, numvertexes*sizeof(dvertex_t));
|
||||
AddLump (LUMP_NODES, dnodes, numnodes*sizeof(dnode_t));
|
||||
AddLump (LUMP_TEXINFO, texinfo, numtexinfo*sizeof(texinfo_t));
|
||||
AddLump (LUMP_FACES, dfaces, numfaces*sizeof(dface_t));
|
||||
AddLump (LUMP_BRUSHES, dbrushes, numbrushes*sizeof(dbrush_t));
|
||||
AddLump (LUMP_BRUSHSIDES, dbrushsides, numbrushsides*sizeof(dbrushside_t));
|
||||
AddLump (LUMP_LEAFFACES, dleaffaces, numleaffaces*sizeof(dleaffaces[0]));
|
||||
AddLump (LUMP_LEAFBRUSHES, dleafbrushes, numleafbrushes*sizeof(dleafbrushes[0]));
|
||||
AddLump (LUMP_SURFEDGES, dsurfedges, numsurfedges*sizeof(dsurfedges[0]));
|
||||
AddLump (LUMP_EDGES, dedges, numedges*sizeof(dedge_t));
|
||||
AddLump (LUMP_MODELS, dmodels, nummodels*sizeof(dmodel_t));
|
||||
AddLump (LUMP_AREAS, dareas, numareas*sizeof(darea_t));
|
||||
AddLump (LUMP_AREAPORTALS, dareaportals, numareaportals*sizeof(dareaportal_t));
|
||||
|
||||
AddLump (LUMP_LIGHTING, dlightdata, lightdatasize);
|
||||
AddLump (LUMP_VISIBILITY, dvisdata, visdatasize);
|
||||
AddLump (LUMP_ENTITIES, dentdata, entdatasize);
|
||||
AddLump (LUMP_POP, dpop, sizeof(dpop));
|
||||
|
||||
fseek (wadfile, 0, SEEK_SET);
|
||||
SafeWrite (wadfile, header, sizeof(dheader_t));
|
||||
fclose (wadfile);
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
|
||||
/*
|
||||
=============
|
||||
PrintBSPFileSizes
|
||||
|
||||
Dumps info about current file
|
||||
=============
|
||||
*/
|
||||
void PrintBSPFileSizes (void)
|
||||
{
|
||||
if (!num_entities)
|
||||
ParseEntities ();
|
||||
|
||||
printf ("%5i models %7i\n"
|
||||
,nummodels, (int)(nummodels*sizeof(dmodel_t)));
|
||||
printf ("%5i brushes %7i\n"
|
||||
,numbrushes, (int)(numbrushes*sizeof(dbrush_t)));
|
||||
printf ("%5i brushsides %7i\n"
|
||||
,numbrushsides, (int)(numbrushsides*sizeof(dbrushside_t)));
|
||||
printf ("%5i planes %7i\n"
|
||||
,numplanes, (int)(numplanes*sizeof(dplane_t)));
|
||||
printf ("%5i texinfo %7i\n"
|
||||
,numtexinfo, (int)(numtexinfo*sizeof(texinfo_t)));
|
||||
printf ("%5i entdata %7i\n", num_entities, entdatasize);
|
||||
|
||||
printf ("\n");
|
||||
|
||||
printf ("%5i vertexes %7i\n"
|
||||
,numvertexes, (int)(numvertexes*sizeof(dvertex_t)));
|
||||
printf ("%5i nodes %7i\n"
|
||||
,numnodes, (int)(numnodes*sizeof(dnode_t)));
|
||||
printf ("%5i faces %7i\n"
|
||||
,numfaces, (int)(numfaces*sizeof(dface_t)));
|
||||
printf ("%5i leafs %7i\n"
|
||||
,numleafs, (int)(numleafs*sizeof(dleaf_t)));
|
||||
printf ("%5i leaffaces %7i\n"
|
||||
,numleaffaces, (int)(numleaffaces*sizeof(dleaffaces[0])));
|
||||
printf ("%5i leafbrushes %7i\n"
|
||||
,numleafbrushes, (int)(numleafbrushes*sizeof(dleafbrushes[0])));
|
||||
printf ("%5i surfedges %7i\n"
|
||||
,numsurfedges, (int)(numsurfedges*sizeof(dsurfedges[0])));
|
||||
printf ("%5i edges %7i\n"
|
||||
,numedges, (int)(numedges*sizeof(dedge_t)));
|
||||
printf (" lightdata %7i\n", lightdatasize);
|
||||
printf (" visdata %7i\n", visdatasize);
|
||||
}
|
||||
|
||||
|
||||
//============================================
|
||||
|
||||
int num_entities;
|
||||
entity_t entities[MAX_MAP_ENTITIES];
|
||||
|
||||
void StripTrailing (char *e)
|
||||
{
|
||||
char *s;
|
||||
|
||||
s = e + strlen(e)-1;
|
||||
while (s >= e && *s <= 32)
|
||||
{
|
||||
*s = 0;
|
||||
s--;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
ParseEpair
|
||||
=================
|
||||
*/
|
||||
epair_t *ParseEpair (void)
|
||||
{
|
||||
epair_t *e;
|
||||
|
||||
e = malloc (sizeof(epair_t));
|
||||
memset (e, 0, sizeof(epair_t));
|
||||
|
||||
if (strlen(token) >= MAX_KEY-1)
|
||||
Error ("ParseEpar: token too long");
|
||||
e->key = copystring(token);
|
||||
GetScriptToken (false);
|
||||
if (strlen(token) >= MAX_VALUE-1)
|
||||
Error ("ParseEpar: token too long");
|
||||
e->value = copystring(token);
|
||||
|
||||
// strip trailing spaces
|
||||
StripTrailing (e->key);
|
||||
StripTrailing (e->value);
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
================
|
||||
ParseEntity
|
||||
================
|
||||
*/
|
||||
qboolean ParseEntity (void)
|
||||
{
|
||||
epair_t *e;
|
||||
entity_t *mapent;
|
||||
|
||||
if (!GetScriptToken (true))
|
||||
return false;
|
||||
|
||||
if (strcmp (token, "{") )
|
||||
Error ("ParseEntity: { not found");
|
||||
|
||||
if (num_entities == MAX_MAP_ENTITIES)
|
||||
Error ("num_entities == MAX_MAP_ENTITIES");
|
||||
|
||||
mapent = &entities[num_entities];
|
||||
num_entities++;
|
||||
|
||||
do
|
||||
{
|
||||
if (!GetScriptToken (true))
|
||||
Error ("ParseEntity: EOF without closing brace");
|
||||
if (!strcmp (token, "}") )
|
||||
break;
|
||||
e = ParseEpair ();
|
||||
e->next = mapent->epairs;
|
||||
mapent->epairs = e;
|
||||
} while (1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
ParseEntities
|
||||
|
||||
Parses the dentdata string into entities
|
||||
================
|
||||
*/
|
||||
void ParseEntities (void)
|
||||
{
|
||||
num_entities = 0;
|
||||
ParseFromMemory (dentdata, entdatasize);
|
||||
|
||||
while (ParseEntity ())
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
================
|
||||
UnparseEntities
|
||||
|
||||
Generates the dentdata string from all the entities
|
||||
================
|
||||
*/
|
||||
void UnparseEntities (void)
|
||||
{
|
||||
char *buf, *end;
|
||||
epair_t *ep;
|
||||
char line[2048];
|
||||
int i;
|
||||
char key[1024], value[1024];
|
||||
|
||||
buf = dentdata;
|
||||
end = buf;
|
||||
*end = 0;
|
||||
|
||||
for (i=0 ; i<num_entities ; i++)
|
||||
{
|
||||
ep = entities[i].epairs;
|
||||
if (!ep)
|
||||
continue; // ent got removed
|
||||
|
||||
strcat (end,"{\n");
|
||||
end += 2;
|
||||
|
||||
for (ep = entities[i].epairs ; ep ; ep=ep->next)
|
||||
{
|
||||
strcpy (key, ep->key);
|
||||
StripTrailing (key);
|
||||
strcpy (value, ep->value);
|
||||
StripTrailing (value);
|
||||
|
||||
sprintf (line, "\"%s\" \"%s\"\n", key, value);
|
||||
strcat (end, line);
|
||||
end += strlen(line);
|
||||
}
|
||||
strcat (end,"}\n");
|
||||
end += 2;
|
||||
|
||||
if (end > buf + MAX_MAP_ENTSTRING)
|
||||
Error ("Entity text too long");
|
||||
}
|
||||
entdatasize = end - buf + 1;
|
||||
}
|
||||
|
||||
void PrintEntity (entity_t *ent)
|
||||
{
|
||||
epair_t *ep;
|
||||
|
||||
printf ("------- entity %p -------\n", ent);
|
||||
for (ep=ent->epairs ; ep ; ep=ep->next)
|
||||
{
|
||||
printf ("%s = %s\n", ep->key, ep->value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SetKeyValue (entity_t *ent, char *key, char *value)
|
||||
{
|
||||
epair_t *ep;
|
||||
|
||||
for (ep=ent->epairs ; ep ; ep=ep->next)
|
||||
if (!strcmp (ep->key, key) )
|
||||
{
|
||||
free (ep->value);
|
||||
ep->value = copystring(value);
|
||||
return;
|
||||
}
|
||||
ep = malloc (sizeof(*ep));
|
||||
if (!ep)
|
||||
Error("SetKeyValue MALLOC failed! Could not allocate %s bytes.", sizeof(*ep));
|
||||
ep->next = ent->epairs;
|
||||
ent->epairs = ep;
|
||||
ep->key = copystring(key);
|
||||
ep->value = copystring(value);
|
||||
}
|
||||
|
||||
char *ValueForKey (entity_t *ent, char *key)
|
||||
{
|
||||
epair_t *ep;
|
||||
|
||||
for (ep=ent->epairs ; ep ; ep=ep->next)
|
||||
if (!strcmp (ep->key, key) )
|
||||
return ep->value;
|
||||
return "";
|
||||
}
|
||||
|
||||
vec_t FloatForKey (entity_t *ent, char *key)
|
||||
{
|
||||
char *k;
|
||||
|
||||
k = ValueForKey (ent, key);
|
||||
return atof(k);
|
||||
}
|
||||
|
||||
void GetVectorForKey (entity_t *ent, char *key, vec3_t vec)
|
||||
{
|
||||
char *k;
|
||||
double v1, v2, v3;
|
||||
|
||||
k = ValueForKey (ent, key);
|
||||
// scanf into doubles, then assign, so it is vec_t size independent
|
||||
v1 = v2 = v3 = 0;
|
||||
sscanf (k, "%lf %lf %lf", &v1, &v2, &v3);
|
||||
vec[0] = v1;
|
||||
vec[1] = v2;
|
||||
vec[2] = v3;
|
||||
}
|
||||
|
||||
|
||||
133
tools/quake2/qdata_heretic2/common/bspfile.h
Normal file
133
tools/quake2/qdata_heretic2/common/bspfile.h
Normal file
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef _QBSP3_H
|
||||
#define _QBSP3_H
|
||||
|
||||
|
||||
#include "qfiles.h"
|
||||
|
||||
|
||||
extern int nummodels;
|
||||
extern dmodel_t dmodels[MAX_MAP_MODELS];
|
||||
|
||||
extern int visdatasize;
|
||||
extern byte dvisdata[MAX_MAP_VISIBILITY];
|
||||
extern dvis_t *dvis;
|
||||
|
||||
extern int lightdatasize;
|
||||
extern byte dlightdata[MAX_MAP_LIGHTING];
|
||||
|
||||
extern int entdatasize;
|
||||
extern char dentdata[MAX_MAP_ENTSTRING];
|
||||
|
||||
extern int numleafs;
|
||||
extern dleaf_t dleafs[MAX_MAP_LEAFS];
|
||||
|
||||
extern int numplanes;
|
||||
extern dplane_t dplanes[MAX_MAP_PLANES];
|
||||
|
||||
extern int numvertexes;
|
||||
extern dvertex_t dvertexes[MAX_MAP_VERTS];
|
||||
|
||||
extern int numnodes;
|
||||
extern dnode_t dnodes[MAX_MAP_NODES];
|
||||
|
||||
extern int numtexinfo;
|
||||
extern texinfo_t texinfo[MAX_MAP_TEXINFO];
|
||||
|
||||
extern int numfaces;
|
||||
extern dface_t dfaces[MAX_MAP_FACES];
|
||||
|
||||
extern int numedges;
|
||||
extern dedge_t dedges[MAX_MAP_EDGES];
|
||||
|
||||
extern int numleaffaces;
|
||||
extern unsigned short dleaffaces[MAX_MAP_LEAFFACES];
|
||||
|
||||
extern int numleafbrushes;
|
||||
extern unsigned short dleafbrushes[MAX_MAP_LEAFBRUSHES];
|
||||
|
||||
extern int numsurfedges;
|
||||
extern int dsurfedges[MAX_MAP_SURFEDGES];
|
||||
|
||||
extern int numareas;
|
||||
extern darea_t dareas[MAX_MAP_AREAS];
|
||||
|
||||
extern int numareaportals;
|
||||
extern dareaportal_t dareaportals[MAX_MAP_AREAPORTALS];
|
||||
|
||||
extern int numbrushes;
|
||||
extern dbrush_t dbrushes[MAX_MAP_BRUSHES];
|
||||
|
||||
extern int numbrushsides;
|
||||
extern dbrushside_t dbrushsides[MAX_MAP_BRUSHSIDES];
|
||||
|
||||
extern byte dpop[256];
|
||||
|
||||
void DecompressVis (byte *in, byte *decompressed);
|
||||
int CompressVis (byte *vis, byte *dest);
|
||||
|
||||
void LoadBSPFile (char *filename);
|
||||
void LoadBSPFileTexinfo (char *filename); // just for qdata
|
||||
void WriteBSPFile (char *filename);
|
||||
void PrintBSPFileSizes (void);
|
||||
|
||||
//===============
|
||||
|
||||
|
||||
typedef struct epair_s
|
||||
{
|
||||
struct epair_s *next;
|
||||
char *key;
|
||||
char *value;
|
||||
} epair_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
vec3_t origin;
|
||||
int firstbrush;
|
||||
int numbrushes;
|
||||
epair_t *epairs;
|
||||
|
||||
// only valid for func_areaportals
|
||||
int areaportalnum;
|
||||
int portalareas[2];
|
||||
} entity_t;
|
||||
|
||||
extern int num_entities;
|
||||
extern entity_t entities[MAX_MAP_ENTITIES];
|
||||
|
||||
void ParseEntities (void);
|
||||
void UnparseEntities (void);
|
||||
|
||||
void SetKeyValue (entity_t *ent, char *key, char *value);
|
||||
char *ValueForKey (entity_t *ent, char *key);
|
||||
// will return "" if not present
|
||||
|
||||
vec_t FloatForKey (entity_t *ent, char *key);
|
||||
void GetVectorForKey (entity_t *ent, char *key, vec3_t vec);
|
||||
|
||||
epair_t *ParseEpair (void);
|
||||
|
||||
void PrintEntity (entity_t *ent);
|
||||
|
||||
#endif //_QBSP3_H
|
||||
1238
tools/quake2/qdata_heretic2/common/cmdlib.c
Normal file
1238
tools/quake2/qdata_heretic2/common/cmdlib.c
Normal file
File diff suppressed because it is too large
Load Diff
177
tools/quake2/qdata_heretic2/common/cmdlib.h
Normal file
177
tools/quake2/qdata_heretic2/common/cmdlib.h
Normal file
@@ -0,0 +1,177 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
// cmdlib.h
|
||||
|
||||
#ifndef __CMDLIB__
|
||||
#define __CMDLIB__
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma warning(disable : 4244) // MIPS
|
||||
#pragma warning(disable : 4136) // X86
|
||||
#pragma warning(disable : 4051) // ALPHA
|
||||
|
||||
#pragma warning(disable : 4018) // signed/unsigned mismatch
|
||||
#pragma warning(disable : 4305) // truncate from double to float
|
||||
|
||||
#pragma check_stack(off)
|
||||
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include <time.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#pragma intrinsic( memset, memcpy )
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef __BYTEBOOL__
|
||||
#define __BYTEBOOL__
|
||||
//typedef enum {false, true} qboolean;
|
||||
//typedef unsigned char byte;
|
||||
#include "q_typedef.h"
|
||||
#endif
|
||||
|
||||
#define MAX_OS_PATH 1024
|
||||
#define MEM_BLOCKSIZE 4096
|
||||
/*
|
||||
extern qboolean verbose;
|
||||
#define SYS_VRB 0 // verbose support (on/off)
|
||||
#define SYS_STD 1 // standard print level
|
||||
#define SYS_WRN 2 // warnings
|
||||
#define SYS_ERR 3 // error
|
||||
*/
|
||||
// the dec offsetof macro doesnt work very well...
|
||||
#define myoffsetof(type,identifier) ((size_t)&((type *)0)->identifier)
|
||||
|
||||
#define SAFE_MALLOC
|
||||
#ifdef SAFE_MALLOC
|
||||
void *safe_malloc( size_t size );
|
||||
void *safe_malloc_info( size_t size, char* info );
|
||||
#else
|
||||
#define safe_malloc(a) malloc(a)
|
||||
#endif /* SAFE_MALLOC */
|
||||
|
||||
// set these before calling CheckParm
|
||||
extern int myargc;
|
||||
extern char **myargv;
|
||||
|
||||
char *strlower (char *in);
|
||||
int Q_strncasecmp( const char *s1, const char *s2, int n );
|
||||
int Q_stricmp( const char *s1, const char *s2 );
|
||||
int Q_strcasecmp( const char *s1, const char *s2 );
|
||||
void Q_getwd( char *out );
|
||||
|
||||
int Q_filelength (FILE *f);
|
||||
int FileTime( const char *path );
|
||||
|
||||
void Q_mkdir( const char *path );
|
||||
|
||||
extern char qdir[1024];
|
||||
extern char gamedir[1024];
|
||||
extern char writedir[1024];
|
||||
extern char *moddirparam;
|
||||
void SetQdirFromPath( const char *path);
|
||||
char *ExpandArg( const char *path ); // from cmd line
|
||||
char *ExpandPath( const char *path ); // from scripts
|
||||
char *ExpandGamePath (const char *path);
|
||||
char *ExpandPathAndArchive( const char *path );
|
||||
void ExpandWildcards( int *argc, char ***argv );
|
||||
|
||||
|
||||
double I_FloatTime( void );
|
||||
|
||||
int CheckParm( const char *check );
|
||||
|
||||
void *SafeMalloc(size_t n, char *desc);
|
||||
FILE *SafeOpenWrite( const char *filename );
|
||||
FILE *SafeOpenRead( const char *filename );
|
||||
void SafeRead (FILE *f, void *buffer, int count);
|
||||
void SafeWrite (FILE *f, const void *buffer, int count);
|
||||
|
||||
int LoadFile( const char *filename, void **bufferptr );
|
||||
int LoadFileBlock( const char *filename, void **bufferptr );
|
||||
int TryLoadFile( const char *filename, void **bufferptr );
|
||||
void SaveFile( const char *filename, const void *buffer, int count );
|
||||
qboolean FileExists( const char *filename );
|
||||
|
||||
void DefaultExtension( char *path, const char *extension );
|
||||
void DefaultPath( char *path, const char *basepath );
|
||||
void StripFilename( char *path );
|
||||
void StripExtension( char *path );
|
||||
|
||||
void ExtractFilePath( const char *path, char *dest );
|
||||
void ExtractFileBase( const char *path, char *dest );
|
||||
void ExtractFileExtension( const char *path, char *dest );
|
||||
|
||||
int ParseNum (const char *str);
|
||||
/*
|
||||
void Sys_Printf (const char *text, ...);
|
||||
void Sys_FPrintf (int flag, const char *text, ...);
|
||||
void Error( const char *error, ... );
|
||||
*/
|
||||
short BigShort (short l);
|
||||
short LittleShort (short l);
|
||||
int BigLong (int l);
|
||||
int LittleLong (int l);
|
||||
float BigFloat (float l);
|
||||
float LittleFloat (float l);
|
||||
|
||||
|
||||
char *COM_Parse (char *data);
|
||||
|
||||
extern char com_token[1024];
|
||||
extern qboolean com_eof;
|
||||
|
||||
char *copystring(const char *s);
|
||||
|
||||
|
||||
void CRC_Init(unsigned short *crcvalue);
|
||||
void CRC_ProcessByte(unsigned short *crcvalue, byte data);
|
||||
unsigned short CRC_Value(unsigned short crcvalue);
|
||||
|
||||
void CreatePath( const char *path );
|
||||
void QCopyFile( const char *from, const char *to );
|
||||
|
||||
extern qboolean archive;
|
||||
extern char archivedir[1024];
|
||||
|
||||
extern qboolean g_dokeypress;
|
||||
|
||||
// sleep for the given amount of milliseconds
|
||||
void Sys_Sleep(int n);
|
||||
|
||||
// for compression routines
|
||||
typedef struct
|
||||
{
|
||||
byte *data;
|
||||
int count;
|
||||
} cblock_t;
|
||||
|
||||
|
||||
#endif
|
||||
35
tools/quake2/qdata_heretic2/common/her2_threads.h
Normal file
35
tools/quake2/qdata_heretic2/common/her2_threads.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#ifndef _THREADS_H
|
||||
|
||||
#define _THREADS_H
|
||||
|
||||
|
||||
extern int numthreads;
|
||||
|
||||
void ThreadSetDefault (void);
|
||||
int GetThreadWork (void);
|
||||
void RunThreadsOnIndividual (int workcnt, qboolean showpacifier, void(*func)(int));
|
||||
void RunThreadsOn (int workcnt, qboolean showpacifier, void(*func)(int));
|
||||
void ThreadLock (void);
|
||||
void ThreadUnlock (void);
|
||||
|
||||
#endif //_THREADS_H
|
||||
367
tools/quake2/qdata_heretic2/common/inout.c
Normal file
367
tools/quake2/qdata_heretic2/common/inout.c
Normal file
@@ -0,0 +1,367 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
// DESCRIPTION:
|
||||
// deal with in/out tasks, for either stdin/stdout or network/XML stream
|
||||
//
|
||||
|
||||
#include "cmdlib.h"
|
||||
#include "mathlib.h"
|
||||
#include "polylib.h"
|
||||
#include "inout.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <direct.h>
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
// network broadcasting
|
||||
#include "l_net/l_net.h"
|
||||
#include "libxml/tree.h"
|
||||
|
||||
#ifdef WIN32
|
||||
HWND hwndOut = NULL;
|
||||
qboolean lookedForServer = false;
|
||||
UINT wm_BroadcastCommand = -1;
|
||||
#endif
|
||||
|
||||
socket_t *brdcst_socket;
|
||||
netmessage_t msg;
|
||||
|
||||
qboolean verbose = false;
|
||||
|
||||
// our main document
|
||||
// is streamed through the network to Radiant
|
||||
// possibly written to disk at the end of the run
|
||||
//++timo FIXME: need to be global, required when creating nodes?
|
||||
xmlDocPtr doc;
|
||||
xmlNodePtr tree;
|
||||
|
||||
// some useful stuff
|
||||
xmlNodePtr xml_NodeForVec( vec3_t v )
|
||||
{
|
||||
xmlNodePtr ret;
|
||||
char buf[1024];
|
||||
|
||||
sprintf (buf, "%f %f %f", v[0], v[1], v[2]);
|
||||
ret = xmlNewNode (NULL, "point");
|
||||
xmlNodeSetContent (ret, buf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// send a node down the stream, add it to the document
|
||||
void xml_SendNode (xmlNodePtr node)
|
||||
{
|
||||
xmlBufferPtr xml_buf;
|
||||
char xmlbuf[MAX_NETMESSAGE]; // we have to copy content from the xmlBufferPtr into an aux buffer .. that sucks ..
|
||||
// this index loops through the node buffer
|
||||
int pos = 0;
|
||||
int size;
|
||||
|
||||
xmlAddChild( doc->children, node );
|
||||
|
||||
if (brdcst_socket)
|
||||
{
|
||||
xml_buf = xmlBufferCreate();
|
||||
xmlNodeDump( xml_buf, doc, node, 0, 0 );
|
||||
|
||||
// the XML node might be too big to fit in a single network message
|
||||
// l_net library defines an upper limit of MAX_NETMESSAGE
|
||||
// there are some size check errors, so we use MAX_NETMESSAGE-10 to be safe
|
||||
// if the size of the buffer exceeds MAX_NETMESSAGE-10 we'll send in several network messages
|
||||
while (pos < xml_buf->use)
|
||||
{
|
||||
// what size are we gonna send now?
|
||||
(xml_buf->use - pos < MAX_NETMESSAGE - 10) ? (size = xml_buf->use - pos) : (size = MAX_NETMESSAGE - 10);
|
||||
//++timo just a debug thing
|
||||
if (size == MAX_NETMESSAGE - 10)
|
||||
Sys_FPrintf (SYS_NOXML, "Got to split the buffer\n");
|
||||
memcpy( xmlbuf, xml_buf->content+pos, size);
|
||||
xmlbuf[size] = '\0';
|
||||
NMSG_Clear( &msg );
|
||||
NMSG_WriteString (&msg, xmlbuf );
|
||||
Net_Send(brdcst_socket, &msg );
|
||||
// now that the thing is sent prepare to loop again
|
||||
pos += size;
|
||||
}
|
||||
|
||||
#if 0
|
||||
// NOTE: the NMSG_WriteString is limited to MAX_NETMESSAGE
|
||||
// we will need to split into chunks
|
||||
// (we could also go lower level, in the end it's using send and receiv which are not size limited)
|
||||
//++timo FIXME: MAX_NETMESSAGE is not exactly the max size we can stick in the message
|
||||
// there's some tweaking to do in l_net for that .. so let's give us a margin for now
|
||||
|
||||
//++timo we need to handle the case of a buffer too big to fit in a single message
|
||||
// try without checks for now
|
||||
if (xml_buf->use > MAX_NETMESSAGE-10 )
|
||||
{
|
||||
// if we send that we are probably gonna break the stream at the other end..
|
||||
// and Error will call right there
|
||||
//Error( "MAX_NETMESSAGE exceeded for XML feedback stream in FPrintf (%d)\n", xml_buf->use);
|
||||
Sys_FPrintf (SYS_NOXML, "MAX_NETMESSAGE exceeded for XML feedback stream in FPrintf (%d)\n", xml_buf->use);
|
||||
xml_buf->content[xml_buf->use]='\0'; //++timo this corrupts the buffer but we don't care it's for printing
|
||||
Sys_FPrintf (SYS_NOXML, xml_buf->content);
|
||||
|
||||
}
|
||||
|
||||
size = xml_buf->use;
|
||||
memcpy( xmlbuf, xml_buf->content, size );
|
||||
xmlbuf[size] = '\0';
|
||||
NMSG_Clear( &msg );
|
||||
NMSG_WriteString (&msg, xmlbuf );
|
||||
Net_Send(brdcst_socket, &msg );
|
||||
#endif
|
||||
|
||||
xmlBufferFree( xml_buf );
|
||||
}
|
||||
}
|
||||
|
||||
void xml_Select (char *msg, int entitynum, int brushnum, qboolean bError)
|
||||
{
|
||||
xmlNodePtr node, select;
|
||||
char buf[1024];
|
||||
char level[2];
|
||||
|
||||
// now build a proper "select" XML node
|
||||
sprintf (buf, "Entity %i, Brush %i: %s", entitynum, brushnum, msg);
|
||||
node = xmlNewNode (NULL, "select");
|
||||
xmlNodeSetContent (node, buf);
|
||||
level[0] = (int)'0' + (bError ? SYS_ERR : SYS_WRN) ;
|
||||
level[1] = 0;
|
||||
xmlSetProp (node, "level", (char *)&level);
|
||||
// a 'select' information
|
||||
sprintf (buf, "%i %i", entitynum, brushnum);
|
||||
select = xmlNewNode (NULL, "brush");
|
||||
xmlNodeSetContent (select, buf);
|
||||
xmlAddChild (node, select);
|
||||
xml_SendNode (node);
|
||||
|
||||
sprintf (buf, "Entity %i, Brush %i: %s", entitynum, brushnum, msg);
|
||||
if (bError)
|
||||
Error(buf);
|
||||
else
|
||||
Sys_FPrintf (SYS_NOXML, "%s\n", buf);
|
||||
|
||||
}
|
||||
|
||||
void xml_Point (char *msg, vec3_t pt)
|
||||
{
|
||||
xmlNodePtr node, point;
|
||||
char buf[1024];
|
||||
char level[2];
|
||||
|
||||
node = xmlNewNode (NULL, "pointmsg");
|
||||
xmlNodeSetContent (node, msg);
|
||||
level[0] = (int)'0' + SYS_ERR;
|
||||
level[1] = 0;
|
||||
xmlSetProp (node, "level", (char *)&level);
|
||||
// a 'point' node
|
||||
sprintf (buf, "%g %g %g", pt[0], pt[1], pt[2]);
|
||||
point = xmlNewNode (NULL, "point");
|
||||
xmlNodeSetContent (point, buf);
|
||||
xmlAddChild (node, point);
|
||||
xml_SendNode (node);
|
||||
|
||||
sprintf (buf, "%s (%g %g %g)", msg, pt[0], pt[1], pt[2]);
|
||||
Error (buf);
|
||||
}
|
||||
|
||||
#define WINDING_BUFSIZE 2048
|
||||
void xml_Winding (char *msg, vec3_t p[], int numpoints, qboolean die)
|
||||
{
|
||||
xmlNodePtr node, winding;
|
||||
char buf[WINDING_BUFSIZE];
|
||||
char smlbuf[128];
|
||||
char level[2];
|
||||
int i;
|
||||
|
||||
node = xmlNewNode (NULL, "windingmsg");
|
||||
xmlNodeSetContent (node, msg);
|
||||
level[0] = (int)'0' + SYS_ERR;
|
||||
level[1] = 0;
|
||||
xmlSetProp (node, "level", (char *)&level);
|
||||
// a 'winding' node
|
||||
sprintf( buf, "%i ", numpoints);
|
||||
for(i = 0; i < numpoints; i++)
|
||||
{
|
||||
sprintf (smlbuf, "(%g %g %g)", p[i][0], p[i][1], p[i][2]);
|
||||
// don't overflow
|
||||
if (strlen(buf)+strlen(smlbuf)>WINDING_BUFSIZE)
|
||||
break;
|
||||
strcat( buf, smlbuf);
|
||||
}
|
||||
|
||||
winding = xmlNewNode (NULL, "winding");
|
||||
xmlNodeSetContent (winding, buf);
|
||||
xmlAddChild (node, winding);
|
||||
xml_SendNode (node);
|
||||
|
||||
if(die)
|
||||
Error (msg);
|
||||
else
|
||||
{
|
||||
Sys_Printf(msg);
|
||||
Sys_Printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
// in include
|
||||
#include "stream_version.h"
|
||||
|
||||
void Broadcast_Setup( const char *dest )
|
||||
{
|
||||
address_t address;
|
||||
char sMsg[1024];
|
||||
|
||||
Net_Setup();
|
||||
Net_StringToAddress((char *)dest, &address);
|
||||
brdcst_socket = Net_Connect(&address, 0);
|
||||
if (brdcst_socket)
|
||||
{
|
||||
// send in a header
|
||||
sprintf (sMsg, "<?xml version=\"1.0\"?><q3map_feedback version=\"" Q3MAP_STREAM_VERSION "\">");
|
||||
NMSG_Clear( &msg );
|
||||
NMSG_WriteString(&msg, sMsg );
|
||||
Net_Send(brdcst_socket, &msg );
|
||||
}
|
||||
}
|
||||
|
||||
void Broadcast_Shutdown()
|
||||
{
|
||||
if (brdcst_socket)
|
||||
{
|
||||
Sys_Printf("Disconnecting\n");
|
||||
Net_Disconnect(brdcst_socket);
|
||||
brdcst_socket = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// all output ends up through here
|
||||
void FPrintf (int flag, char *buf)
|
||||
{
|
||||
xmlNodePtr node;
|
||||
static qboolean bGotXML = false;
|
||||
char level[2];
|
||||
|
||||
printf(buf);
|
||||
|
||||
// the following part is XML stuff only.. but maybe we don't want that message to go down the XML pipe?
|
||||
if (flag == SYS_NOXML)
|
||||
return;
|
||||
|
||||
// ouput an XML file of the run
|
||||
// use the DOM interface to build a tree
|
||||
/*
|
||||
<message level='flag'>
|
||||
message string
|
||||
.. various nodes to describe corresponding geometry ..
|
||||
</message>
|
||||
*/
|
||||
if (!bGotXML)
|
||||
{
|
||||
// initialize
|
||||
doc = xmlNewDoc("1.0");
|
||||
doc->children = xmlNewDocRawNode(doc, NULL, "q3map_feedback", NULL);
|
||||
bGotXML = true;
|
||||
}
|
||||
node = xmlNewNode (NULL, "message");
|
||||
xmlNodeSetContent (node, buf);
|
||||
level[0] = (int)'0' + flag;
|
||||
level[1] = 0;
|
||||
xmlSetProp (node, "level", (char *)&level );
|
||||
|
||||
xml_SendNode (node);
|
||||
}
|
||||
|
||||
#ifdef DBG_XML
|
||||
void DumpXML()
|
||||
{
|
||||
xmlSaveFile( "XMLDump.xml", doc );
|
||||
}
|
||||
#endif
|
||||
|
||||
void Sys_FPrintf (int flag, const char *format, ...)
|
||||
{
|
||||
char out_buffer[4096];
|
||||
va_list argptr;
|
||||
|
||||
if ((flag == SYS_VRB) && (verbose == false))
|
||||
return;
|
||||
|
||||
va_start (argptr, format);
|
||||
vsprintf (out_buffer, format, argptr);
|
||||
va_end (argptr);
|
||||
|
||||
FPrintf (flag, out_buffer);
|
||||
}
|
||||
|
||||
void Sys_Printf (const char *format, ...)
|
||||
{
|
||||
char out_buffer[4096];
|
||||
va_list argptr;
|
||||
|
||||
va_start (argptr, format);
|
||||
vsprintf (out_buffer, format, argptr);
|
||||
va_end (argptr);
|
||||
|
||||
FPrintf (SYS_STD, out_buffer);
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
Error
|
||||
|
||||
For abnormal program terminations
|
||||
=================
|
||||
*/
|
||||
void Error( const char *error, ...)
|
||||
{
|
||||
char out_buffer[4096];
|
||||
char tmp[4096];
|
||||
va_list argptr;
|
||||
|
||||
va_start (argptr,error);
|
||||
vsprintf (tmp, error, argptr);
|
||||
va_end (argptr);
|
||||
|
||||
sprintf( out_buffer, "************ ERROR ************\n%s\n", tmp );
|
||||
|
||||
FPrintf( SYS_ERR, out_buffer );
|
||||
|
||||
#ifdef DBG_XML
|
||||
DumpXML();
|
||||
#endif
|
||||
|
||||
//++timo HACK ALERT .. if we shut down too fast the xml stream won't reach the listener.
|
||||
// a clean solution is to send a sync request node in the stream and wait for an answer before exiting
|
||||
Sys_Sleep( 1000 );
|
||||
|
||||
Broadcast_Shutdown();
|
||||
|
||||
exit (1);
|
||||
}
|
||||
|
||||
63
tools/quake2/qdata_heretic2/common/inout.h
Normal file
63
tools/quake2/qdata_heretic2/common/inout.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef __INOUT__
|
||||
#define __INOUT__
|
||||
|
||||
// inout is the only stuff relying on xml, include the headers there
|
||||
#include "libxml/tree.h"
|
||||
#include "mathlib.h"
|
||||
|
||||
// some useful xml routines
|
||||
xmlNodePtr xml_NodeForVec( vec3_t v );
|
||||
void xml_SendNode (xmlNodePtr node);
|
||||
// print a message in q3map output and send the corresponding select information down the xml stream
|
||||
// bError: do we end with an error on this one or do we go ahead?
|
||||
void xml_Select (char *msg, int entitynum, int brushnum, qboolean bError);
|
||||
// end q3map with an error message and send a point information in the xml stream
|
||||
// note: we might want to add a boolean to use this as a warning or an error thing..
|
||||
void xml_Winding (char *msg, vec3_t p[], int numpoints, qboolean die);
|
||||
void xml_Point (char *msg, vec3_t pt);
|
||||
|
||||
extern qboolean bNetworkBroadcast;
|
||||
void Broadcast_Setup( const char *dest );
|
||||
void Broadcast_Shutdown();
|
||||
|
||||
#define SYS_VRB 0 // verbose support (on/off)
|
||||
#define SYS_STD 1 // standard print level
|
||||
#define SYS_WRN 2 // warnings
|
||||
#define SYS_ERR 3 // error
|
||||
#define SYS_NOXML 4 // don't send that down the XML stream
|
||||
|
||||
extern qboolean verbose;
|
||||
void Sys_Printf (const char *text, ...);
|
||||
void Sys_FPrintf (int flag, const char *text, ...);
|
||||
void Error( const char *error, ...);
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define DBG_XML 1
|
||||
#endif
|
||||
|
||||
#ifdef DBG_XML
|
||||
void DumpXML();
|
||||
#endif
|
||||
|
||||
#endif
|
||||
476
tools/quake2/qdata_heretic2/common/l3dslib.c
Normal file
476
tools/quake2/qdata_heretic2/common/l3dslib.c
Normal file
@@ -0,0 +1,476 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
//
|
||||
// l3dslib.c: library for loading triangles from an Alias triangle file
|
||||
//
|
||||
|
||||
#include <stdio.h>
|
||||
#include "cmdlib.h"
|
||||
#include "inout.h"
|
||||
#include "mathlib.h"
|
||||
#include "trilib.h"
|
||||
#include "l3dslib.h"
|
||||
#include "token.h"
|
||||
#include "fmodel.h"
|
||||
#include "bspfile.h"
|
||||
|
||||
#define MAIN3DS 0x4D4D
|
||||
#define EDIT3DS 0x3D3D // this is the start of the editor config
|
||||
#define EDIT_OBJECT 0x4000
|
||||
#define OBJ_TRIMESH 0x4100
|
||||
#define TRI_VERTEXL 0x4110
|
||||
#define TRI_FACEL1 0x4120
|
||||
|
||||
#define MAXVERTS 2000
|
||||
|
||||
typedef struct {
|
||||
int v[4];
|
||||
} tri;
|
||||
|
||||
float fverts[MAXVERTS][3];
|
||||
tri tris[MAXTRIANGLES];
|
||||
|
||||
int bytesread, level, numtris, totaltris;
|
||||
int vertsfound, trisfound;
|
||||
|
||||
triangle_t *ptri;
|
||||
|
||||
|
||||
|
||||
void DefaultNodesList(mesh_node_t **nodesList, int *num_mesh_nodes, int *numtriangles)
|
||||
{
|
||||
int pos, bit, i;
|
||||
|
||||
if (nodesList)
|
||||
{
|
||||
*num_mesh_nodes = 1;
|
||||
memset(&(*nodesList)[0], 0, sizeof(mesh_node_t));
|
||||
strcpy((*nodesList)[0].name, "default");
|
||||
|
||||
// set all of the tris to be used for the top node
|
||||
for(i = 0; i < (*numtriangles); i++)
|
||||
{
|
||||
pos = (i) >> 3;
|
||||
bit = 1 << ((i) & 7 );
|
||||
|
||||
(*nodesList)[0].tris[pos] |= bit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Alias stores triangles as 3 explicit vertices in .tri files, so even though we
|
||||
// start out with a vertex pool and vertex indices for triangles, we have to convert
|
||||
// to raw, explicit triangles
|
||||
void StoreAliasTriangles (void)
|
||||
{
|
||||
int i, j, k;
|
||||
|
||||
if ((totaltris + numtris) > MAXTRIANGLES)
|
||||
Error ("Error: Too many triangles");
|
||||
|
||||
for (i=0; i<numtris ; i++)
|
||||
{
|
||||
for (j=0 ; j<3 ; j++)
|
||||
{
|
||||
for (k=0 ; k<3 ; k++)
|
||||
{
|
||||
ptri[i+totaltris].verts[j][k] = fverts[tris[i].v[j]][k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
totaltris += numtris;
|
||||
numtris = 0;
|
||||
vertsfound = 0;
|
||||
trisfound = 0;
|
||||
}
|
||||
|
||||
|
||||
int ParseVertexL (FILE *input)
|
||||
{
|
||||
int i, j, startbytesread, numverts;
|
||||
unsigned short tshort;
|
||||
|
||||
if (vertsfound)
|
||||
Error ("Error: Multiple vertex chunks");
|
||||
|
||||
vertsfound = 1;
|
||||
startbytesread = bytesread;
|
||||
|
||||
if (feof(input))
|
||||
Error ("Error: unexpected end of file");
|
||||
|
||||
fread(&tshort, sizeof(tshort), 1, input);
|
||||
bytesread += sizeof(tshort);
|
||||
numverts = (int)tshort;
|
||||
|
||||
if (numverts > MAXVERTS)
|
||||
Error ("Error: Too many vertices");
|
||||
|
||||
for (i=0 ; i<numverts ; i++)
|
||||
{
|
||||
for (j=0 ; j<3 ; j++)
|
||||
{
|
||||
if (feof(input))
|
||||
Error ("Error: unexpected end of file");
|
||||
|
||||
fread(&fverts[i][j], sizeof(float), 1, input);
|
||||
bytesread += sizeof(float);
|
||||
}
|
||||
}
|
||||
|
||||
if (vertsfound && trisfound)
|
||||
StoreAliasTriangles ();
|
||||
|
||||
return bytesread - startbytesread;
|
||||
}
|
||||
|
||||
|
||||
int ParseFaceL1 (FILE *input)
|
||||
{
|
||||
|
||||
int i, j, startbytesread;
|
||||
unsigned short tshort;
|
||||
|
||||
if (trisfound)
|
||||
Error ("Error: Multiple face chunks");
|
||||
|
||||
trisfound = 1;
|
||||
startbytesread = bytesread;
|
||||
|
||||
if (feof(input))
|
||||
Error ("Error: unexpected end of file");
|
||||
|
||||
fread(&tshort, sizeof(tshort), 1, input);
|
||||
bytesread += sizeof(tshort);
|
||||
numtris = (int)tshort;
|
||||
|
||||
if (numtris > MAXTRIANGLES)
|
||||
Error ("Error: Too many triangles");
|
||||
|
||||
for (i=0 ; i<numtris ; i++)
|
||||
{
|
||||
for (j=0 ; j<4 ; j++)
|
||||
{
|
||||
if (feof(input))
|
||||
Error ("Error: unexpected end of file");
|
||||
|
||||
fread(&tshort, sizeof(tshort), 1, input);
|
||||
bytesread += sizeof(tshort);
|
||||
tris[i].v[j] = (int)tshort;
|
||||
}
|
||||
}
|
||||
|
||||
if (vertsfound && trisfound)
|
||||
StoreAliasTriangles ();
|
||||
|
||||
return bytesread - startbytesread;
|
||||
}
|
||||
|
||||
|
||||
int ParseChunk (FILE *input)
|
||||
{
|
||||
#define BLOCK_SIZE 4096
|
||||
char temp[BLOCK_SIZE];
|
||||
unsigned short type;
|
||||
int i, length, w, t, retval;
|
||||
|
||||
level++;
|
||||
retval = 0;
|
||||
|
||||
// chunk type
|
||||
if (feof(input))
|
||||
Error ("Error: unexpected end of file");
|
||||
|
||||
fread(&type, sizeof(type), 1, input);
|
||||
bytesread += sizeof(type);
|
||||
|
||||
// chunk length
|
||||
if (feof(input))
|
||||
Error ("Error: unexpected end of file");
|
||||
|
||||
fread (&length, sizeof(length), 1, input);
|
||||
bytesread += sizeof(length);
|
||||
w = length - 6;
|
||||
|
||||
// process chunk if we care about it, otherwise skip it
|
||||
switch (type)
|
||||
{
|
||||
case TRI_VERTEXL:
|
||||
w -= ParseVertexL (input);
|
||||
goto ParseSubchunk;
|
||||
|
||||
case TRI_FACEL1:
|
||||
w -= ParseFaceL1 (input);
|
||||
goto ParseSubchunk;
|
||||
|
||||
case EDIT_OBJECT:
|
||||
// read the name
|
||||
i = 0;
|
||||
|
||||
do
|
||||
{
|
||||
if (feof(input))
|
||||
Error ("Error: unexpected end of file");
|
||||
|
||||
fread (&temp[i], 1, 1, input);
|
||||
i++;
|
||||
w--;
|
||||
bytesread++;
|
||||
} while (temp[i-1]);
|
||||
|
||||
case MAIN3DS:
|
||||
case OBJ_TRIMESH:
|
||||
case EDIT3DS:
|
||||
// parse through subchunks
|
||||
ParseSubchunk:
|
||||
while (w > 0)
|
||||
{
|
||||
w -= ParseChunk (input);
|
||||
}
|
||||
|
||||
retval = length;
|
||||
goto Done;
|
||||
|
||||
default:
|
||||
// skip other chunks
|
||||
while (w > 0)
|
||||
{
|
||||
t = w;
|
||||
|
||||
if (t > BLOCK_SIZE)
|
||||
t = BLOCK_SIZE;
|
||||
|
||||
if (feof(input))
|
||||
Error ("Error: unexpected end of file");
|
||||
|
||||
fread (&temp, t, 1, input);
|
||||
bytesread += t;
|
||||
|
||||
w -= t;
|
||||
}
|
||||
|
||||
retval = length;
|
||||
goto Done;
|
||||
}
|
||||
|
||||
Done:
|
||||
level--;
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
void Load3DSTriangleList (char *filename, triangle_t **pptri, int *numtriangles, mesh_node_t **nodesList, int *num_mesh_nodes)
|
||||
{
|
||||
FILE *input;
|
||||
short int tshort;
|
||||
|
||||
if (nodesList)
|
||||
{
|
||||
*num_mesh_nodes = 0;
|
||||
*nodesList = (mesh_node_t *) SafeMalloc(MAX_FM_MESH_NODES * sizeof(mesh_node_t), "Mesh Node List");
|
||||
}
|
||||
|
||||
bytesread = 0;
|
||||
level = 0;
|
||||
numtris = 0;
|
||||
totaltris = 0;
|
||||
vertsfound = 0;
|
||||
trisfound = 0;
|
||||
|
||||
if ((input = fopen(filename, "rb")) == 0) {
|
||||
fprintf(stderr,"reader: could not open file '%s'\n", filename);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
fread(&tshort, sizeof(tshort), 1, input);
|
||||
|
||||
// should only be MAIN3DS, but some files seem to start with EDIT3DS, with
|
||||
// no MAIN3DS
|
||||
if ((tshort != MAIN3DS) && (tshort != EDIT3DS)) {
|
||||
fprintf(stderr,"File is not a 3DS file.\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// back to top of file so we can parse the first chunk descriptor
|
||||
fseek(input, 0, SEEK_SET);
|
||||
|
||||
ptri = malloc (MAXTRIANGLES * sizeof(triangle_t));
|
||||
|
||||
*pptri = ptri;
|
||||
|
||||
// parse through looking for the relevant chunk tree (MAIN3DS | EDIT3DS | EDIT_OBJECT |
|
||||
// OBJ_TRIMESH | {TRI_VERTEXL, TRI_FACEL1}) and skipping other chunks
|
||||
ParseChunk (input);
|
||||
|
||||
if (vertsfound || trisfound)
|
||||
Error ("Incomplete triangle set");
|
||||
|
||||
*numtriangles = totaltris;
|
||||
|
||||
fclose (input);
|
||||
|
||||
DefaultNodesList(nodesList,num_mesh_nodes,numtriangles);
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// LoadASC
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void LoadASC(char *fileName, triangle_t **triList, int *triangleCount, mesh_node_t **nodesList, int *num_mesh_nodes)
|
||||
{
|
||||
int i, j;
|
||||
int vertexCount;
|
||||
struct
|
||||
{
|
||||
float v[3];
|
||||
} *vList;
|
||||
int triCount;
|
||||
triangle_t *tList;
|
||||
float x, y, z;
|
||||
// float x2, y2, z2;
|
||||
// float rx, ry, rz;
|
||||
qboolean goodObject;
|
||||
|
||||
if (nodesList)
|
||||
{
|
||||
*num_mesh_nodes = 0;
|
||||
*nodesList = (mesh_node_t *) SafeMalloc(MAX_FM_MESH_NODES * sizeof(mesh_node_t), "Mesh Node List");
|
||||
}
|
||||
|
||||
TK_OpenSource(fileName);
|
||||
|
||||
goodObject = false;
|
||||
while(goodObject == false)
|
||||
{
|
||||
TK_Beyond(TK_C_NAMED);
|
||||
TK_Beyond(TK_OBJECT);
|
||||
TK_Beyond(TK_C_TRI);
|
||||
TK_Beyond(TK_MESH);
|
||||
TK_BeyondRequire(TK_C_VERTICES, TK_COLON);
|
||||
TK_FetchRequire(TK_INTNUMBER);
|
||||
vertexCount = tk_IntNumber;
|
||||
if(vertexCount > 0)
|
||||
{
|
||||
goodObject = true;
|
||||
}
|
||||
}
|
||||
TK_BeyondRequire(TK_C_FACES, TK_COLON);
|
||||
TK_FetchRequire(TK_INTNUMBER);
|
||||
triCount = tk_IntNumber;
|
||||
if(triCount >= MAXTRIANGLES)
|
||||
{
|
||||
Error("Too many triangles in file %s\n", fileName);
|
||||
}
|
||||
*triangleCount = triCount;
|
||||
tList = (triangle_t *) SafeMalloc(MAXTRIANGLES*sizeof(triangle_t), "Triangle list");
|
||||
*triList = tList;
|
||||
|
||||
memset(*triList,0,MAXTRIANGLES*sizeof(triangle_t));
|
||||
TK_BeyondRequire(TK_C_VERTEX, TK_LIST);
|
||||
|
||||
/* rx = ((rotation[0]+90.0)/360.0)*2.0*M_PI;
|
||||
//rx = (rotation[0]/360.0)*2.0*M_PI;
|
||||
ry = (rotation[1]/360.0)*2.0*M_PI;
|
||||
rz = (rotation[2]/360.0)*2.0*M_PI;
|
||||
*/
|
||||
vList = (void *) SafeMalloc(vertexCount*sizeof vList[0], "Vertex list");
|
||||
for(i = 0; i < vertexCount; i++)
|
||||
{
|
||||
TK_BeyondRequire(TK_C_VERTEX, TK_INTNUMBER);
|
||||
if(tk_IntNumber != i)
|
||||
{
|
||||
Error("File '%s', line %d:\nVertex index mismatch.\n",
|
||||
tk_SourceName, tk_Line);
|
||||
}
|
||||
TK_FetchRequireFetch(TK_COLON);
|
||||
|
||||
TK_BeyondRequire(TK_COLON, TK_FLOATNUMBER);
|
||||
x = tk_FloatNumber;
|
||||
TK_BeyondRequire(TK_COLON, TK_FLOATNUMBER);
|
||||
y = tk_FloatNumber;
|
||||
TK_BeyondRequire(TK_COLON, TK_FLOATNUMBER);
|
||||
z = tk_FloatNumber;
|
||||
|
||||
/* x2 = x*cos(rz)+y*sin(rz);
|
||||
y2 = -x*sin(rz)+y*cos(rz);
|
||||
x = x2;
|
||||
y = y2;
|
||||
y2 = y*cos(rx)+z*sin(rx);
|
||||
z2 = -y*sin(rx)+z*cos(rx);
|
||||
y = y2;
|
||||
z = z2;
|
||||
x2 = x*cos(ry)-z*sin(ry);
|
||||
z2 = x*sin(ry)+z*cos(ry);
|
||||
x = x2;
|
||||
z = z2;
|
||||
*/
|
||||
vList[i].v[0] = x;
|
||||
vList[i].v[1] = y;
|
||||
vList[i].v[2] = z;
|
||||
}
|
||||
TK_BeyondRequire(TK_C_FACE, TK_LIST);
|
||||
for(i = 0; i < triCount; i++)
|
||||
{
|
||||
TK_BeyondRequire(TK_C_FACE, TK_INTNUMBER);
|
||||
if(tk_IntNumber != i)
|
||||
{
|
||||
Error("File '%s', line %d:\nTriangle index mismatch.\n",
|
||||
tk_SourceName, tk_Line);
|
||||
}
|
||||
for(j = 0; j < 3; j++)
|
||||
{
|
||||
TK_BeyondRequire(TK_IDENTIFIER, TK_COLON);
|
||||
TK_FetchRequire(TK_INTNUMBER);
|
||||
if(tk_IntNumber >= vertexCount)
|
||||
{
|
||||
Error("File '%s', line %d:\nVertex number"
|
||||
" > vertexCount: %d\n", tk_SourceName, tk_Line,
|
||||
tk_IntNumber);
|
||||
}
|
||||
tList[i].verts[2-j][0] = vList[tk_IntNumber].v[0];
|
||||
tList[i].verts[2-j][1] = vList[tk_IntNumber].v[1];
|
||||
tList[i].verts[2-j][2] = vList[tk_IntNumber].v[2];
|
||||
#ifdef _QDATA
|
||||
tList[i].indicies[2-j] = tk_IntNumber;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* printf("Face %i:\n v0: %f, %f, %f\n v1: %f, %f, %f\n"
|
||||
" v2: %f, %f, %f\n", i,
|
||||
tList[i].verts[0][0],
|
||||
tList[i].verts[0][1],
|
||||
tList[i].verts[0][2],
|
||||
tList[i].verts[1][0],
|
||||
tList[i].verts[1][1],
|
||||
tList[i].verts[1][2],
|
||||
tList[i].verts[2][0],
|
||||
tList[i].verts[2][1],
|
||||
tList[i].verts[2][2]);
|
||||
*/
|
||||
}
|
||||
|
||||
DefaultNodesList(nodesList,num_mesh_nodes,triangleCount);
|
||||
}
|
||||
28
tools/quake2/qdata_heretic2/common/l3dslib.h
Normal file
28
tools/quake2/qdata_heretic2/common/l3dslib.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
//
|
||||
// l3dslib.h: header file for loading triangles from a 3DS triangle file
|
||||
//
|
||||
void DefaultNodesList(mesh_node_t **nodesList, int *num_mesh_nodes, int *numtriangles);
|
||||
|
||||
void Load3DSTriangleList (char *filename, triangle_t **pptri, int *numtriangles, mesh_node_t **ppmnodes, int *num_mesh_nodes);
|
||||
void LoadASC(char *fileName, triangle_t **triList, int *triangleCount, mesh_node_t **ppmnodes, int *num_mesh_nodes);
|
||||
1052
tools/quake2/qdata_heretic2/common/lbmlib.c
Normal file
1052
tools/quake2/qdata_heretic2/common/lbmlib.c
Normal file
File diff suppressed because it is too large
Load Diff
41
tools/quake2/qdata_heretic2/common/lbmlib.h
Normal file
41
tools/quake2/qdata_heretic2/common/lbmlib.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
// piclib.h
|
||||
|
||||
|
||||
void LoadLBM (char *filename, byte **picture, byte **palette);
|
||||
void WriteLBMfile (char *filename, byte *data, int width, int height
|
||||
, byte *palette);
|
||||
void LoadPCX (char *filename, byte **picture, byte **palette, int *width, int *height);
|
||||
void WritePCXfile (char *filename, byte *data, int width, int height
|
||||
, byte *palette);
|
||||
|
||||
// loads / saves either lbm or pcx, depending on extension
|
||||
void Load256Image (char *name, byte **pixels, byte **palette,
|
||||
int *width, int *height);
|
||||
void Save256Image (char *name, byte *pixels, byte *palette,
|
||||
int width, int height);
|
||||
|
||||
|
||||
void LoadTGA (char *filename, byte **pixels, int *width, int *height);
|
||||
|
||||
qboolean LoadAnyImage (char *name, byte **pixels, byte **palette, int *width, int *height);
|
||||
176
tools/quake2/qdata_heretic2/common/mathlib.c
Normal file
176
tools/quake2/qdata_heretic2/common/mathlib.c
Normal file
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
// mathlib.c -- math primitives
|
||||
|
||||
#include "cmdlib.h"
|
||||
#include "mathlib.h"
|
||||
|
||||
vec3_t vec3_origin = {0,0,0};
|
||||
|
||||
|
||||
double VectorLength(vec3_t v)
|
||||
{
|
||||
int i;
|
||||
double length;
|
||||
|
||||
length = 0;
|
||||
for (i=0 ; i< 3 ; i++)
|
||||
length += v[i]*v[i];
|
||||
length = sqrt (length); // FIXME
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
qboolean VectorCompare (vec3_t v1, vec3_t v2)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0 ; i<3 ; i++)
|
||||
if (fabs(v1[i]-v2[i]) > EQUAL_EPSILON)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
vec_t Q_rint (vec_t in)
|
||||
{
|
||||
return floor (in + 0.5);
|
||||
}
|
||||
|
||||
void VectorMA (vec3_t va, double scale, vec3_t vb, vec3_t vc)
|
||||
{
|
||||
vc[0] = va[0] + scale*vb[0];
|
||||
vc[1] = va[1] + scale*vb[1];
|
||||
vc[2] = va[2] + scale*vb[2];
|
||||
}
|
||||
|
||||
void CrossProduct (vec3_t v1, vec3_t v2, vec3_t cross)
|
||||
{
|
||||
cross[0] = v1[1]*v2[2] - v1[2]*v2[1];
|
||||
cross[1] = v1[2]*v2[0] - v1[0]*v2[2];
|
||||
cross[2] = v1[0]*v2[1] - v1[1]*v2[0];
|
||||
}
|
||||
|
||||
vec_t _DotProduct (vec3_t v1, vec3_t v2)
|
||||
{
|
||||
return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];
|
||||
}
|
||||
|
||||
void _VectorSubtract (vec3_t va, vec3_t vb, vec3_t out)
|
||||
{
|
||||
out[0] = va[0]-vb[0];
|
||||
out[1] = va[1]-vb[1];
|
||||
out[2] = va[2]-vb[2];
|
||||
}
|
||||
|
||||
void _VectorAdd (vec3_t va, vec3_t vb, vec3_t out)
|
||||
{
|
||||
out[0] = va[0]+vb[0];
|
||||
out[1] = va[1]+vb[1];
|
||||
out[2] = va[2]+vb[2];
|
||||
}
|
||||
|
||||
void _VectorCopy (vec3_t in, vec3_t out)
|
||||
{
|
||||
out[0] = in[0];
|
||||
out[1] = in[1];
|
||||
out[2] = in[2];
|
||||
}
|
||||
|
||||
void _VectorScale (vec3_t v, vec_t scale, vec3_t out)
|
||||
{
|
||||
out[0] = v[0] * scale;
|
||||
out[1] = v[1] * scale;
|
||||
out[2] = v[2] * scale;
|
||||
}
|
||||
|
||||
#pragma optimize("g", off) // went back to turning optimization off,
|
||||
// the bug_fix thing stopped working
|
||||
|
||||
vec_t VectorNormalize (vec3_t in, vec3_t out)
|
||||
{
|
||||
vec_t length, ilength;
|
||||
|
||||
length = sqrt (in[0]*in[0] + in[1]*in[1] + in[2]*in[2]);
|
||||
if (length == 0)
|
||||
{
|
||||
VectorClear (out);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ilength = 1.0/length;
|
||||
out[0] = in[0]*ilength;
|
||||
out[1] = in[1]*ilength;
|
||||
out[2] = in[2]*ilength;
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
vec_t ColorNormalize (vec3_t in, vec3_t out)
|
||||
{
|
||||
float max, scale;
|
||||
|
||||
max = in[0];
|
||||
if (in[1] > max)
|
||||
max = in[1];
|
||||
if (in[2] > max)
|
||||
max = in[2];
|
||||
|
||||
if (max == 0)
|
||||
return 0;
|
||||
|
||||
scale = 1.0 / max;
|
||||
|
||||
VectorScale (in, scale, out);
|
||||
|
||||
return max;
|
||||
}
|
||||
|
||||
#pragma optimize("", on)
|
||||
|
||||
void VectorInverse (vec3_t v)
|
||||
{
|
||||
v[0] = -v[0];
|
||||
v[1] = -v[1];
|
||||
v[2] = -v[2];
|
||||
}
|
||||
|
||||
void ClearBounds (vec3_t mins, vec3_t maxs)
|
||||
{
|
||||
mins[0] = mins[1] = mins[2] = 99999;
|
||||
maxs[0] = maxs[1] = maxs[2] = -99999;
|
||||
}
|
||||
|
||||
void AddPointToBounds (vec3_t v, vec3_t mins, vec3_t maxs)
|
||||
{
|
||||
int i;
|
||||
vec_t val;
|
||||
|
||||
for (i=0 ; i<3 ; i++)
|
||||
{
|
||||
val = v[i];
|
||||
if (val < mins[i])
|
||||
mins[i] = val;
|
||||
if (val > maxs[i])
|
||||
maxs[i] = val;
|
||||
}
|
||||
}
|
||||
76
tools/quake2/qdata_heretic2/common/mathlib.h
Normal file
76
tools/quake2/qdata_heretic2/common/mathlib.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef __MATHLIB__
|
||||
#define __MATHLIB__
|
||||
|
||||
// mathlib.h
|
||||
|
||||
#include <math.h>
|
||||
/*
|
||||
#ifdef DOUBLEVEC_T
|
||||
typedef double vec_t;
|
||||
#else
|
||||
typedef float vec_t;
|
||||
#endif
|
||||
typedef vec_t vec3_t[3];
|
||||
*/
|
||||
#define SIDE_FRONT 0
|
||||
#define SIDE_ON 2
|
||||
#define SIDE_BACK 1
|
||||
#define SIDE_CROSS -2
|
||||
|
||||
#define Q_PI 3.14159265358979323846
|
||||
|
||||
extern vec3_t vec3_origin;
|
||||
|
||||
#define EQUAL_EPSILON 0.001
|
||||
|
||||
qboolean VectorCompare (vec3_t v1, vec3_t v2);
|
||||
|
||||
#define DotProduct(x,y) (x[0]*y[0]+x[1]*y[1]+x[2]*y[2])
|
||||
#define VectorSubtract(a,b,c) {c[0]=a[0]-b[0];c[1]=a[1]-b[1];c[2]=a[2]-b[2];}
|
||||
#define VectorAdd(a,b,c) {c[0]=a[0]+b[0];c[1]=a[1]+b[1];c[2]=a[2]+b[2];}
|
||||
#define VectorCopy(a,b) {b[0]=a[0];b[1]=a[1];b[2]=a[2];}
|
||||
#define VectorScale(a,b,c) {c[0]=b*a[0];c[1]=b*a[1];c[2]=b*a[2];}
|
||||
#define VectorClear(x) {x[0] = x[1] = x[2] = 0;}
|
||||
#define VectorNegate(x) {x[0]=-x[0];x[1]=-x[1];x[2]=-x[2];}
|
||||
|
||||
vec_t Q_rint (vec_t in);
|
||||
vec_t _DotProduct (vec3_t v1, vec3_t v2);
|
||||
void _VectorSubtract (vec3_t va, vec3_t vb, vec3_t out);
|
||||
void _VectorAdd (vec3_t va, vec3_t vb, vec3_t out);
|
||||
void _VectorCopy (vec3_t in, vec3_t out);
|
||||
void _VectorScale (vec3_t v, vec_t scale, vec3_t out);
|
||||
|
||||
double VectorLength(vec3_t v);
|
||||
|
||||
void VectorMA (vec3_t va, double scale, vec3_t vb, vec3_t vc);
|
||||
|
||||
void CrossProduct (vec3_t v1, vec3_t v2, vec3_t cross);
|
||||
vec_t VectorNormalize (vec3_t in, vec3_t out);
|
||||
vec_t ColorNormalize (vec3_t in, vec3_t out);
|
||||
void VectorInverse (vec3_t v);
|
||||
|
||||
void ClearBounds (vec3_t mins, vec3_t maxs);
|
||||
void AddPointToBounds (vec3_t v, vec3_t mins, vec3_t maxs);
|
||||
|
||||
#endif
|
||||
298
tools/quake2/qdata_heretic2/common/md4.c
Normal file
298
tools/quake2/qdata_heretic2/common/md4.c
Normal file
@@ -0,0 +1,298 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/* GLOBAL.H - RSAREF types and constants */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/* POINTER defines a generic pointer type */
|
||||
typedef unsigned char *POINTER;
|
||||
|
||||
/* UINT2 defines a two byte word */
|
||||
typedef unsigned short int UINT2;
|
||||
|
||||
/* UINT4 defines a four byte word */
|
||||
typedef unsigned long int UINT4;
|
||||
|
||||
|
||||
/* MD4.H - header file for MD4C.C */
|
||||
|
||||
/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
License to copy and use this software is granted provided that it is identified as the “RSA Data Security, Inc. MD4 Message-Digest Algorithm” in all material mentioning or referencing this software or this function.
|
||||
License is also granted to make and use derivative works provided that such works are identified as “derived from the RSA Data Security, Inc. MD4 Message-Digest Algorithm” in all material mentioning or referencing the derived work.
|
||||
RSA Data Security, Inc. makes no representations concerning either the merchantability of this software or the suitability of this software for any particular purpose. It is provided “as is” without express or implied warranty of any kind.
|
||||
|
||||
These notices must be retained in any copies of any part of this documentation and/or software. */
|
||||
|
||||
/* MD4 context. */
|
||||
typedef struct {
|
||||
UINT4 state[4]; /* state (ABCD) */
|
||||
UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */
|
||||
unsigned char buffer[64]; /* input buffer */
|
||||
} MD4_CTX;
|
||||
|
||||
void MD4Init (MD4_CTX *);
|
||||
void MD4Update (MD4_CTX *, unsigned char *, unsigned int);
|
||||
void MD4Final (unsigned char [16], MD4_CTX *);
|
||||
|
||||
|
||||
|
||||
/* MD4C.C - RSA Data Security, Inc., MD4 message-digest algorithm */
|
||||
/* Copyright (C) 1990-2, RSA Data Security, Inc. All rights reserved.
|
||||
|
||||
License to copy and use this software is granted provided that it is identified as the
|
||||
RSA Data Security, Inc. MD4 Message-Digest Algorithm
|
||||
in all material mentioning or referencing this software or this function.
|
||||
License is also granted to make and use derivative works provided that such works are identified as
|
||||
derived from the RSA Data Security, Inc. MD4 Message-Digest Algorithm
|
||||
in all material mentioning or referencing the derived work.
|
||||
RSA Data Security, Inc. makes no representations concerning either the merchantability of this software or the suitability of this software for any particular purpose. It is provided
|
||||
as is without express or implied warranty of any kind.
|
||||
|
||||
These notices must be retained in any copies of any part of this documentation and/or software. */
|
||||
|
||||
/* Constants for MD4Transform routine. */
|
||||
#define S11 3
|
||||
#define S12 7
|
||||
#define S13 11
|
||||
#define S14 19
|
||||
#define S21 3
|
||||
#define S22 5
|
||||
#define S23 9
|
||||
#define S24 13
|
||||
#define S31 3
|
||||
#define S32 9
|
||||
#define S33 11
|
||||
#define S34 15
|
||||
|
||||
static void MD4Transform (UINT4 [4], unsigned char [64]);
|
||||
static void Encode (unsigned char *, UINT4 *, unsigned int);
|
||||
static void Decode (UINT4 *, unsigned char *, unsigned int);
|
||||
static void MD4_memcpy (POINTER, POINTER, unsigned int);
|
||||
static void MD4_memset (POINTER, int, unsigned int);
|
||||
|
||||
static unsigned char PADDING[64] = {
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
/* F, G and H are basic MD4 functions. */
|
||||
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
|
||||
#define G(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
|
||||
#define H(x, y, z) ((x) ^ (y) ^ (z))
|
||||
|
||||
/* ROTATE_LEFT rotates x left n bits. */
|
||||
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
|
||||
|
||||
/* FF, GG and HH are transformations for rounds 1, 2 and 3 */
|
||||
/* Rotation is separate from addition to prevent recomputation */
|
||||
#define FF(a, b, c, d, x, s) {(a) += F ((b), (c), (d)) + (x); (a) = ROTATE_LEFT ((a), (s));}
|
||||
|
||||
#define GG(a, b, c, d, x, s) {(a) += G ((b), (c), (d)) + (x) + (UINT4)0x5a827999; (a) = ROTATE_LEFT ((a), (s));}
|
||||
|
||||
#define HH(a, b, c, d, x, s) {(a) += H ((b), (c), (d)) + (x) + (UINT4)0x6ed9eba1; (a) = \
|
||||
ROTATE_LEFT ((a), (s)); }
|
||||
|
||||
|
||||
/* MD4 initialization. Begins an MD4 operation, writing a new context. */
|
||||
void MD4Init (MD4_CTX *context)
|
||||
{
|
||||
context->count[0] = context->count[1] = 0;
|
||||
|
||||
/* Load magic initialization constants.*/
|
||||
context->state[0] = 0x67452301;
|
||||
context->state[1] = 0xefcdab89;
|
||||
context->state[2] = 0x98badcfe;
|
||||
context->state[3] = 0x10325476;
|
||||
}
|
||||
|
||||
/* MD4 block update operation. Continues an MD4 message-digest operation, processing another message block, and updating the context. */
|
||||
void MD4Update (MD4_CTX *context, unsigned char *input, unsigned int inputLen)
|
||||
{
|
||||
unsigned int i, index, partLen;
|
||||
|
||||
/* Compute number of bytes mod 64 */
|
||||
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
|
||||
|
||||
/* Update number of bits */
|
||||
if ((context->count[0] += ((UINT4)inputLen << 3))< ((UINT4)inputLen << 3))
|
||||
context->count[1]++;
|
||||
|
||||
context->count[1] += ((UINT4)inputLen >> 29);
|
||||
|
||||
partLen = 64 - index;
|
||||
|
||||
/* Transform as many times as possible.*/
|
||||
if (inputLen >= partLen)
|
||||
{
|
||||
memcpy((POINTER)&context->buffer[index], (POINTER)input, partLen);
|
||||
MD4Transform (context->state, context->buffer);
|
||||
|
||||
for (i = partLen; i + 63 < inputLen; i += 64)
|
||||
MD4Transform (context->state, &input[i]);
|
||||
|
||||
index = 0;
|
||||
}
|
||||
else
|
||||
i = 0;
|
||||
|
||||
/* Buffer remaining input */
|
||||
memcpy ((POINTER)&context->buffer[index], (POINTER)&input[i], inputLen-i);
|
||||
}
|
||||
|
||||
|
||||
/* MD4 finalization. Ends an MD4 message-digest operation, writing the the message digest and zeroizing the context. */
|
||||
void MD4Final (unsigned char digest[16], MD4_CTX *context)
|
||||
{
|
||||
unsigned char bits[8];
|
||||
unsigned int index, padLen;
|
||||
|
||||
/* Save number of bits */
|
||||
Encode (bits, context->count, 8);
|
||||
|
||||
/* Pad out to 56 mod 64.*/
|
||||
index = (unsigned int)((context->count[0] >> 3) & 0x3f);
|
||||
padLen = (index < 56) ? (56 - index) : (120 - index);
|
||||
MD4Update (context, PADDING, padLen);
|
||||
|
||||
/* Append length (before padding) */
|
||||
MD4Update (context, bits, 8);
|
||||
|
||||
/* Store state in digest */
|
||||
Encode (digest, context->state, 16);
|
||||
|
||||
/* Zeroize sensitive information.*/
|
||||
memset ((POINTER)context, 0, sizeof (*context));
|
||||
}
|
||||
|
||||
|
||||
/* MD4 basic transformation. Transforms state based on block. */
|
||||
static void MD4Transform (UINT4 state[4], unsigned char block[64])
|
||||
{
|
||||
UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
|
||||
|
||||
Decode (x, block, 64);
|
||||
|
||||
/* Round 1 */
|
||||
FF (a, b, c, d, x[ 0], S11); /* 1 */
|
||||
FF (d, a, b, c, x[ 1], S12); /* 2 */
|
||||
FF (c, d, a, b, x[ 2], S13); /* 3 */
|
||||
FF (b, c, d, a, x[ 3], S14); /* 4 */
|
||||
FF (a, b, c, d, x[ 4], S11); /* 5 */
|
||||
FF (d, a, b, c, x[ 5], S12); /* 6 */
|
||||
FF (c, d, a, b, x[ 6], S13); /* 7 */
|
||||
FF (b, c, d, a, x[ 7], S14); /* 8 */
|
||||
FF (a, b, c, d, x[ 8], S11); /* 9 */
|
||||
FF (d, a, b, c, x[ 9], S12); /* 10 */
|
||||
FF (c, d, a, b, x[10], S13); /* 11 */
|
||||
FF (b, c, d, a, x[11], S14); /* 12 */
|
||||
FF (a, b, c, d, x[12], S11); /* 13 */
|
||||
FF (d, a, b, c, x[13], S12); /* 14 */
|
||||
FF (c, d, a, b, x[14], S13); /* 15 */
|
||||
FF (b, c, d, a, x[15], S14); /* 16 */
|
||||
|
||||
/* Round 2 */
|
||||
GG (a, b, c, d, x[ 0], S21); /* 17 */
|
||||
GG (d, a, b, c, x[ 4], S22); /* 18 */
|
||||
GG (c, d, a, b, x[ 8], S23); /* 19 */
|
||||
GG (b, c, d, a, x[12], S24); /* 20 */
|
||||
GG (a, b, c, d, x[ 1], S21); /* 21 */
|
||||
GG (d, a, b, c, x[ 5], S22); /* 22 */
|
||||
GG (c, d, a, b, x[ 9], S23); /* 23 */
|
||||
GG (b, c, d, a, x[13], S24); /* 24 */
|
||||
GG (a, b, c, d, x[ 2], S21); /* 25 */
|
||||
GG (d, a, b, c, x[ 6], S22); /* 26 */
|
||||
GG (c, d, a, b, x[10], S23); /* 27 */
|
||||
GG (b, c, d, a, x[14], S24); /* 28 */
|
||||
GG (a, b, c, d, x[ 3], S21); /* 29 */
|
||||
GG (d, a, b, c, x[ 7], S22); /* 30 */
|
||||
GG (c, d, a, b, x[11], S23); /* 31 */
|
||||
GG (b, c, d, a, x[15], S24); /* 32 */
|
||||
|
||||
/* Round 3 */
|
||||
HH (a, b, c, d, x[ 0], S31); /* 33 */
|
||||
HH (d, a, b, c, x[ 8], S32); /* 34 */
|
||||
HH (c, d, a, b, x[ 4], S33); /* 35 */
|
||||
HH (b, c, d, a, x[12], S34); /* 36 */
|
||||
HH (a, b, c, d, x[ 2], S31); /* 37 */
|
||||
HH (d, a, b, c, x[10], S32); /* 38 */
|
||||
HH (c, d, a, b, x[ 6], S33); /* 39 */
|
||||
HH (b, c, d, a, x[14], S34); /* 40 */
|
||||
HH (a, b, c, d, x[ 1], S31); /* 41 */
|
||||
HH (d, a, b, c, x[ 9], S32); /* 42 */
|
||||
HH (c, d, a, b, x[ 5], S33); /* 43 */
|
||||
HH (b, c, d, a, x[13], S34); /* 44 */
|
||||
HH (a, b, c, d, x[ 3], S31); /* 45 */
|
||||
HH (d, a, b, c, x[11], S32); /* 46 */
|
||||
HH (c, d, a, b, x[ 7], S33); /* 47 */
|
||||
HH (b, c, d, a, x[15], S34); /* 48 */
|
||||
|
||||
state[0] += a;
|
||||
state[1] += b;
|
||||
state[2] += c;
|
||||
state[3] += d;
|
||||
|
||||
/* Zeroize sensitive information.*/
|
||||
memset ((POINTER)x, 0, sizeof (x));
|
||||
}
|
||||
|
||||
|
||||
/* Encodes input (UINT4) into output (unsigned char). Assumes len is a multiple of 4. */
|
||||
static void Encode (unsigned char *output, UINT4 *input, unsigned int len)
|
||||
{
|
||||
unsigned int i, j;
|
||||
|
||||
for (i = 0, j = 0; j < len; i++, j += 4) {
|
||||
output[j] = (unsigned char)(input[i] & 0xff);
|
||||
output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
|
||||
output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
|
||||
output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Decodes input (unsigned char) into output (UINT4). Assumes len is a multiple of 4. */
|
||||
static void Decode (UINT4 *output, unsigned char *input, unsigned int len)
|
||||
{
|
||||
unsigned int i, j;
|
||||
|
||||
for (i = 0, j = 0; j < len; i++, j += 4)
|
||||
output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) | (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
|
||||
}
|
||||
|
||||
//===================================================================
|
||||
|
||||
unsigned Com_BlockChecksum (void *buffer, int length)
|
||||
{
|
||||
int digest[4];
|
||||
unsigned val;
|
||||
MD4_CTX ctx;
|
||||
|
||||
MD4Init (&ctx);
|
||||
MD4Update (&ctx, (unsigned char *)buffer, length);
|
||||
MD4Final ( (unsigned char *)digest, &ctx);
|
||||
|
||||
val = digest[0] ^ digest[1] ^ digest[2] ^ digest[3];
|
||||
|
||||
return val;
|
||||
}
|
||||
405
tools/quake2/qdata_heretic2/common/path_init.c
Normal file
405
tools/quake2/qdata_heretic2/common/path_init.c
Normal file
@@ -0,0 +1,405 @@
|
||||
/* -------------------------------------------------------------------------------
|
||||
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/*
|
||||
Nurail: Swiped from Q3Map2
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* marker */
|
||||
#define PATH_INIT_C
|
||||
|
||||
#if defined( __linux__ ) || defined( __APPLE__ )
|
||||
#define Q_UNIX
|
||||
#endif
|
||||
|
||||
#ifdef Q_UNIX
|
||||
#include <unistd.h>
|
||||
#include <pwd.h>
|
||||
#include <limits.h>
|
||||
#endif
|
||||
|
||||
|
||||
/* dependencies */
|
||||
#include "cmdlib.h"
|
||||
#include "inout.h"
|
||||
|
||||
|
||||
|
||||
/* path support */
|
||||
#define MAX_BASE_PATHS 10
|
||||
#define MAX_GAME_PATHS 10
|
||||
|
||||
char *homePath;
|
||||
char installPath[ MAX_OS_PATH ];
|
||||
|
||||
int numBasePaths;
|
||||
char *basePaths[ MAX_BASE_PATHS ];
|
||||
int numGamePaths;
|
||||
char *gamePaths[ MAX_GAME_PATHS ];
|
||||
|
||||
/*
|
||||
some of this code is based off the original q3map port from loki
|
||||
and finds various paths. moved here from bsp.c for clarity.
|
||||
*/
|
||||
|
||||
/*
|
||||
PathLokiGetHomeDir()
|
||||
gets the user's home dir (for ~/.q3a)
|
||||
*/
|
||||
|
||||
char *LokiGetHomeDir( void )
|
||||
{
|
||||
#ifndef Q_UNIX
|
||||
return NULL;
|
||||
#else
|
||||
char *home;
|
||||
uid_t id;
|
||||
struct passwd *pwd;
|
||||
|
||||
|
||||
/* get the home environment variable */
|
||||
home = getenv( "HOME" );
|
||||
if( home == NULL )
|
||||
{
|
||||
/* do some more digging */
|
||||
id = getuid();
|
||||
setpwent();
|
||||
while( (pwd = getpwent()) != NULL )
|
||||
{
|
||||
if( pwd->pw_uid == id )
|
||||
{
|
||||
home = pwd->pw_dir;
|
||||
break;
|
||||
}
|
||||
}
|
||||
endpwent();
|
||||
}
|
||||
|
||||
/* return it */
|
||||
return home;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
PathLokiInitPaths()
|
||||
initializes some paths on linux/os x
|
||||
*/
|
||||
|
||||
void LokiInitPaths( char *argv0 )
|
||||
{
|
||||
#ifndef Q_UNIX
|
||||
/* this is kinda crap, but hey */
|
||||
strcpy( installPath, "../" );
|
||||
#else
|
||||
char temp[ MAX_OS_PATH ];
|
||||
char *home;
|
||||
char *path;
|
||||
char *last;
|
||||
qboolean found;
|
||||
|
||||
|
||||
/* get home dir */
|
||||
home = LokiGetHomeDir();
|
||||
if( home == NULL )
|
||||
home = ".";
|
||||
|
||||
/* do some path divining */
|
||||
strcpy( temp, argv0 );
|
||||
if( strrchr( temp, '/' ) )
|
||||
argv0 = strrchr( argv0, '/' ) + 1;
|
||||
else
|
||||
{
|
||||
/* get path environment variable */
|
||||
path = getenv( "PATH" );
|
||||
|
||||
/* minor setup */
|
||||
last[ 0 ] = path[ 0 ];
|
||||
last[ 1 ] = '\0';
|
||||
found = false;
|
||||
|
||||
/* go through each : segment of path */
|
||||
while( last[ 0 ] != '\0' && found == false )
|
||||
{
|
||||
/* null out temp */
|
||||
temp[ 0 ] = '\0';
|
||||
|
||||
/* find next chunk */
|
||||
last = strchr( path, ':' );
|
||||
if( last == NULL )
|
||||
last = path + strlen( path );
|
||||
|
||||
/* found home dir candidate */
|
||||
if( *path == '~' )
|
||||
{
|
||||
strcpy( temp, home );
|
||||
path++;
|
||||
}
|
||||
|
||||
/* concatenate */
|
||||
if( last > (path + 1) )
|
||||
{
|
||||
strncat( temp, path, (last - path) );
|
||||
strcat( temp, "/" );
|
||||
}
|
||||
strcat( temp, "./" );
|
||||
strcat( temp, argv0 );
|
||||
|
||||
/* verify the path */
|
||||
if( access( temp, X_OK ) == 0 )
|
||||
found++;
|
||||
path = last + 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* flake */
|
||||
if( realpath( temp, installPath ) )
|
||||
{
|
||||
/* q3map is in "tools/" */
|
||||
*(strrchr( installPath, '/' )) = '\0';
|
||||
*(strrchr( installPath, '/' ) + 1) = '\0';
|
||||
}
|
||||
|
||||
/* set home path */
|
||||
homePath = home;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
CleanPath() - ydnar
|
||||
cleans a dos path \ -> /
|
||||
*/
|
||||
|
||||
void CleanPath( char *path )
|
||||
{
|
||||
while( *path )
|
||||
{
|
||||
if( *path == '\\' )
|
||||
*path = '/';
|
||||
path++;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
AddBasePath() - ydnar
|
||||
adds a base path to the list
|
||||
*/
|
||||
|
||||
void AddBasePath( char *path )
|
||||
{
|
||||
/* dummy check */
|
||||
if( path == NULL || path[ 0 ] == '\0' || numBasePaths >= MAX_BASE_PATHS )
|
||||
return;
|
||||
|
||||
/* add it to the list */
|
||||
basePaths[ numBasePaths ] = safe_malloc( strlen( path ) + 1 );
|
||||
strcpy( basePaths[ numBasePaths ], path );
|
||||
CleanPath( basePaths[ numBasePaths ] );
|
||||
numBasePaths++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
AddHomeBasePath() - ydnar
|
||||
adds a base path to the beginning of the list, prefixed by ~/
|
||||
*/
|
||||
|
||||
void AddHomeBasePath( char *path )
|
||||
{
|
||||
#ifdef Q_UNIX
|
||||
int i;
|
||||
char temp[ MAX_OS_PATH ];
|
||||
|
||||
|
||||
/* dummy check */
|
||||
if( path == NULL || path[ 0 ] == '\0' )
|
||||
return;
|
||||
|
||||
/* make a hole */
|
||||
for( i = 0; i < (MAX_BASE_PATHS - 1); i++ )
|
||||
basePaths[ i + 1 ] = basePaths[ i ];
|
||||
|
||||
/* concatenate home dir and path */
|
||||
sprintf( temp, "%s/%s", homePath, path );
|
||||
|
||||
/* add it to the list */
|
||||
basePaths[ 0 ] = safe_malloc( strlen( temp ) + 1 );
|
||||
strcpy( basePaths[ 0 ], temp );
|
||||
CleanPath( basePaths[ 0 ] );
|
||||
numBasePaths++;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
AddGamePath() - ydnar
|
||||
adds a game path to the list
|
||||
*/
|
||||
|
||||
void AddGamePath( char *path )
|
||||
{
|
||||
/* dummy check */
|
||||
if( path == NULL || path[ 0 ] == '\0' || numGamePaths >= MAX_GAME_PATHS )
|
||||
return;
|
||||
|
||||
/* add it to the list */
|
||||
gamePaths[ numGamePaths ] = safe_malloc( strlen( path ) + 1 );
|
||||
strcpy( gamePaths[ numGamePaths ], path );
|
||||
CleanPath( gamePaths[ numGamePaths ] );
|
||||
numGamePaths++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
InitPaths() - ydnar
|
||||
cleaned up some of the path initialization code from bsp.c
|
||||
will remove any arguments it uses
|
||||
*/
|
||||
|
||||
void InitPaths( int *argc, char **argv )
|
||||
{
|
||||
int i, j, k, len, len2;
|
||||
char temp[ MAX_OS_PATH ];
|
||||
char gamePath[MAX_OS_PATH], homeBasePath[MAX_OS_PATH], game_magic[10];
|
||||
|
||||
strcpy(gamePath, "base");
|
||||
strcpy(game_magic, "h");
|
||||
strcpy(homeBasePath, ".heretic2");
|
||||
|
||||
/* note it */
|
||||
Sys_FPrintf( SYS_VRB, "--- InitPaths ---\n" );
|
||||
|
||||
/* get the install path for backup */
|
||||
LokiInitPaths( argv[ 0 ] );
|
||||
|
||||
/* set game to default (q3a) */
|
||||
numBasePaths = 0;
|
||||
numGamePaths = 0;
|
||||
|
||||
/* parse through the arguments and extract those relevant to paths */
|
||||
for( i = 0; i < *argc; i++ )
|
||||
{
|
||||
/* check for null */
|
||||
if( argv[ i ] == NULL )
|
||||
continue;
|
||||
|
||||
/* -fs_basepath */
|
||||
if( strcmp( argv[ i ], "-fs_basepath" ) == 0 )
|
||||
{
|
||||
if( ++i >= *argc )
|
||||
Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
|
||||
argv[ i - 1 ] = NULL;
|
||||
AddBasePath( argv[ i ] );
|
||||
argv[ i ] = NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* remove processed arguments */
|
||||
for( i = 0, j = 0, k = 0; i < *argc && j < *argc; i++, j++ )
|
||||
{
|
||||
for( j; j < *argc && argv[ j ] == NULL; j++ );
|
||||
argv[ i ] = argv[ j ];
|
||||
if( argv[ i ] != NULL )
|
||||
k++;
|
||||
}
|
||||
*argc = k;
|
||||
|
||||
/* add standard game path */
|
||||
AddGamePath( gamePath );
|
||||
|
||||
/* if there is no base path set, figure it out */
|
||||
if( numBasePaths == 0 )
|
||||
{
|
||||
/* this is another crappy replacement for SetQdirFromPath() */
|
||||
len2 = strlen( game_magic );
|
||||
for( i = 0; i < *argc && numBasePaths == 0; i++ )
|
||||
{
|
||||
/* extract the arg */
|
||||
strcpy( temp, argv[ i ] );
|
||||
CleanPath( temp );
|
||||
len = strlen( temp );
|
||||
Sys_FPrintf( SYS_VRB, "Searching for \"%s\" in \"%s\" (%d)...\n", game_magic, temp, i );
|
||||
|
||||
/* this is slow, but only done once */
|
||||
for( j = 0; j < (len - len2); j++ )
|
||||
{
|
||||
/* check for the game's magic word */
|
||||
if( Q_strncasecmp( &temp[ j ], game_magic, len2 ) == 0 )
|
||||
{
|
||||
/* now find the next slash and nuke everything after it */
|
||||
while( temp[ ++j ] != '/' && temp[ j ] != '\0' );
|
||||
temp[ j ] = '\0';
|
||||
|
||||
/* add this as a base path */
|
||||
AddBasePath( temp );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* add install path */
|
||||
if( numBasePaths == 0 )
|
||||
AddBasePath( installPath );
|
||||
|
||||
/* check again */
|
||||
if( numBasePaths == 0 )
|
||||
Error( "Failed to find a valid base path." );
|
||||
}
|
||||
|
||||
/* this only affects unix */
|
||||
AddHomeBasePath( homeBasePath );
|
||||
|
||||
/* initialize vfs paths */
|
||||
if( numBasePaths > MAX_BASE_PATHS )
|
||||
numBasePaths = MAX_BASE_PATHS;
|
||||
if( numGamePaths > MAX_GAME_PATHS )
|
||||
numGamePaths = MAX_GAME_PATHS;
|
||||
|
||||
/* walk the list of game paths */
|
||||
//for( j = 0; j < numGamePaths; j++ )
|
||||
//{
|
||||
/* walk the list of base paths */
|
||||
// for( i = 0; i < numBasePaths; i++ )
|
||||
// {
|
||||
/* create a full path and initialize it */
|
||||
// sprintf( temp, "%s/%s/", basePaths[ i ], gamePaths[ j ] );
|
||||
// vfsInitDirectory( temp );
|
||||
// }
|
||||
//}
|
||||
|
||||
/* done */
|
||||
Sys_Printf( "\n" );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
656
tools/quake2/qdata_heretic2/common/polylib.c
Normal file
656
tools/quake2/qdata_heretic2/common/polylib.c
Normal file
@@ -0,0 +1,656 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
|
||||
#include "cmdlib.h"
|
||||
#include "inout.h"
|
||||
#include "mathlib.h"
|
||||
#include "polylib.h"
|
||||
|
||||
|
||||
extern int numthreads;
|
||||
|
||||
// counters are only bumped when running single threaded,
|
||||
// because they are an awefull coherence problem
|
||||
int c_active_windings;
|
||||
int c_peak_windings;
|
||||
int c_winding_allocs;
|
||||
int c_winding_points;
|
||||
|
||||
#define BOGUS_RANGE 8192
|
||||
|
||||
void pw(winding_t *w)
|
||||
{
|
||||
int i;
|
||||
for (i=0 ; i<w->numpoints ; i++)
|
||||
printf ("(%5.1f, %5.1f, %5.1f)\n",w->p[i][0], w->p[i][1],w->p[i][2]);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
=============
|
||||
AllocWinding
|
||||
=============
|
||||
*/
|
||||
winding_t *AllocWinding (int points)
|
||||
{
|
||||
winding_t *w;
|
||||
int s;
|
||||
|
||||
if (numthreads == 1)
|
||||
{
|
||||
c_winding_allocs++;
|
||||
c_winding_points += points;
|
||||
c_active_windings++;
|
||||
if (c_active_windings > c_peak_windings)
|
||||
c_peak_windings = c_active_windings;
|
||||
}
|
||||
s = sizeof(vec_t)*3*points + sizeof(int);
|
||||
w = malloc (s);
|
||||
if (!w)
|
||||
Error("AllocWinding MALLOC failed! Could not allocate %s bytes.", s);
|
||||
memset (w, 0, s);
|
||||
return w;
|
||||
}
|
||||
|
||||
void FreeWinding (winding_t *w)
|
||||
{
|
||||
if (*(unsigned *)w == 0xdeaddead)
|
||||
Error ("FreeWinding: freed a freed winding");
|
||||
*(unsigned *)w = 0xdeaddead;
|
||||
|
||||
if (numthreads == 1)
|
||||
c_active_windings--;
|
||||
free (w);
|
||||
}
|
||||
|
||||
/*
|
||||
============
|
||||
RemoveColinearPoints
|
||||
============
|
||||
*/
|
||||
int c_removed;
|
||||
|
||||
void RemoveColinearPoints (winding_t *w)
|
||||
{
|
||||
int i, j, k;
|
||||
vec3_t v1, v2;
|
||||
int nump;
|
||||
vec3_t p[MAX_POINTS_ON_WINDING];
|
||||
|
||||
nump = 0;
|
||||
for (i=0 ; i<w->numpoints ; i++)
|
||||
{
|
||||
j = (i+1)%w->numpoints;
|
||||
k = (i+w->numpoints-1)%w->numpoints;
|
||||
VectorSubtract (w->p[j], w->p[i], v1);
|
||||
VectorSubtract (w->p[i], w->p[k], v2);
|
||||
VectorNormalize(v1,v1);
|
||||
VectorNormalize(v2,v2);
|
||||
if (DotProduct(v1, v2) < 0.999)
|
||||
{
|
||||
VectorCopy (w->p[i], p[nump]);
|
||||
nump++;
|
||||
}
|
||||
}
|
||||
|
||||
if (nump == w->numpoints)
|
||||
return;
|
||||
|
||||
if (numthreads == 1)
|
||||
c_removed += w->numpoints - nump;
|
||||
w->numpoints = nump;
|
||||
memcpy (w->p, p, nump*sizeof(p[0]));
|
||||
}
|
||||
|
||||
/*
|
||||
============
|
||||
WindingPlane
|
||||
============
|
||||
*/
|
||||
void WindingPlane (winding_t *w, vec3_t normal, vec_t *dist)
|
||||
{
|
||||
vec3_t v1, v2;
|
||||
|
||||
VectorSubtract (w->p[1], w->p[0], v1);
|
||||
VectorSubtract (w->p[2], w->p[0], v2);
|
||||
CrossProduct (v2, v1, normal);
|
||||
VectorNormalize (normal, normal);
|
||||
*dist = DotProduct (w->p[0], normal);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
=============
|
||||
WindingArea
|
||||
=============
|
||||
*/
|
||||
vec_t WindingArea (winding_t *w)
|
||||
{
|
||||
int i;
|
||||
vec3_t d1, d2, cross;
|
||||
vec_t total;
|
||||
|
||||
total = 0;
|
||||
for (i=2 ; i<w->numpoints ; i++)
|
||||
{
|
||||
VectorSubtract (w->p[i-1], w->p[0], d1);
|
||||
VectorSubtract (w->p[i], w->p[0], d2);
|
||||
CrossProduct (d1, d2, cross);
|
||||
total += 0.5 * VectorLength ( cross );
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
void WindingBounds (winding_t *w, vec3_t mins, vec3_t maxs)
|
||||
{
|
||||
vec_t v;
|
||||
int i,j;
|
||||
|
||||
mins[0] = mins[1] = mins[2] = 99999;
|
||||
maxs[0] = maxs[1] = maxs[2] = -99999;
|
||||
|
||||
for (i=0 ; i<w->numpoints ; i++)
|
||||
{
|
||||
for (j=0 ; j<3 ; j++)
|
||||
{
|
||||
v = w->p[i][j];
|
||||
if (v < mins[j])
|
||||
mins[j] = v;
|
||||
if (v > maxs[j])
|
||||
maxs[j] = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
=============
|
||||
WindingCenter
|
||||
=============
|
||||
*/
|
||||
void WindingCenter (winding_t *w, vec3_t center)
|
||||
{
|
||||
int i;
|
||||
float scale;
|
||||
|
||||
VectorCopy (vec3_origin, center);
|
||||
for (i=0 ; i<w->numpoints ; i++)
|
||||
VectorAdd (w->p[i], center, center);
|
||||
|
||||
scale = 1.0/w->numpoints;
|
||||
VectorScale (center, scale, center);
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
BaseWindingForPlane
|
||||
=================
|
||||
*/
|
||||
winding_t *BaseWindingForPlane (vec3_t normal, vec_t dist)
|
||||
{
|
||||
int i, x;
|
||||
vec_t max, v;
|
||||
vec3_t org, vright, vup;
|
||||
winding_t *w;
|
||||
|
||||
// find the major axis
|
||||
|
||||
max = -BOGUS_RANGE;
|
||||
x = -1;
|
||||
for (i=0 ; i<3; i++)
|
||||
{
|
||||
v = fabs(normal[i]);
|
||||
if (v > max)
|
||||
{
|
||||
x = i;
|
||||
max = v;
|
||||
}
|
||||
}
|
||||
if (x==-1)
|
||||
Error ("BaseWindingForPlane: no axis found");
|
||||
|
||||
VectorCopy (vec3_origin, vup);
|
||||
switch (x)
|
||||
{
|
||||
case 0:
|
||||
case 1:
|
||||
vup[2] = 1;
|
||||
break;
|
||||
case 2:
|
||||
vup[0] = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
v = DotProduct (vup, normal);
|
||||
VectorMA (vup, -v, normal, vup);
|
||||
VectorNormalize (vup, vup);
|
||||
|
||||
VectorScale (normal, dist, org);
|
||||
|
||||
CrossProduct (vup, normal, vright);
|
||||
|
||||
VectorScale (vup, 8192, vup);
|
||||
VectorScale (vright, 8192, vright);
|
||||
|
||||
// project a really big axis aligned box onto the plane
|
||||
w = AllocWinding (4);
|
||||
|
||||
VectorSubtract (org, vright, w->p[0]);
|
||||
VectorAdd (w->p[0], vup, w->p[0]);
|
||||
|
||||
VectorAdd (org, vright, w->p[1]);
|
||||
VectorAdd (w->p[1], vup, w->p[1]);
|
||||
|
||||
VectorAdd (org, vright, w->p[2]);
|
||||
VectorSubtract (w->p[2], vup, w->p[2]);
|
||||
|
||||
VectorSubtract (org, vright, w->p[3]);
|
||||
VectorSubtract (w->p[3], vup, w->p[3]);
|
||||
|
||||
w->numpoints = 4;
|
||||
|
||||
return w;
|
||||
}
|
||||
|
||||
/*
|
||||
==================
|
||||
CopyWinding
|
||||
==================
|
||||
*/
|
||||
winding_t *CopyWinding (winding_t *w)
|
||||
{
|
||||
int size;
|
||||
winding_t *c;
|
||||
|
||||
c = AllocWinding (w->numpoints);
|
||||
size = (int)((winding_t *)0)->p[w->numpoints];
|
||||
memcpy (c, w, size);
|
||||
return c;
|
||||
}
|
||||
|
||||
/*
|
||||
==================
|
||||
ReverseWinding
|
||||
==================
|
||||
*/
|
||||
winding_t *ReverseWinding (winding_t *w)
|
||||
{
|
||||
int i;
|
||||
winding_t *c;
|
||||
|
||||
c = AllocWinding (w->numpoints);
|
||||
for (i=0 ; i<w->numpoints ; i++)
|
||||
{
|
||||
VectorCopy (w->p[w->numpoints-1-i], c->p[i]);
|
||||
}
|
||||
c->numpoints = w->numpoints;
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
=============
|
||||
ClipWindingEpsilon
|
||||
=============
|
||||
*/
|
||||
void ClipWindingEpsilon (winding_t *in, vec3_t normal, vec_t dist,
|
||||
vec_t epsilon, winding_t **front, winding_t **back)
|
||||
{
|
||||
vec_t dists[MAX_POINTS_ON_WINDING+4];
|
||||
int sides[MAX_POINTS_ON_WINDING+4];
|
||||
int counts[3];
|
||||
vec_t dot; // VC 4.2 optimizer bug if not static
|
||||
int i, j;
|
||||
vec_t *p1, *p2;
|
||||
vec3_t mid;
|
||||
winding_t *f, *b;
|
||||
int maxpts;
|
||||
|
||||
if (in->numpoints >= MAX_POINTS_ON_WINDING-4)
|
||||
Error ("ClipWinding: MAX_POINTS_ON_WINDING");
|
||||
|
||||
counts[0] = counts[1] = counts[2] = 0;
|
||||
|
||||
// determine sides for each point
|
||||
for (i=0 ; i<in->numpoints ; i++)
|
||||
{
|
||||
dot = DotProduct (in->p[i], normal);
|
||||
dot -= dist;
|
||||
dists[i] = dot;
|
||||
if (dot > epsilon)
|
||||
sides[i] = SIDE_FRONT;
|
||||
else if (dot < -epsilon)
|
||||
sides[i] = SIDE_BACK;
|
||||
else
|
||||
{
|
||||
sides[i] = SIDE_ON;
|
||||
}
|
||||
counts[sides[i]]++;
|
||||
}
|
||||
sides[i] = sides[0];
|
||||
dists[i] = dists[0];
|
||||
|
||||
*front = *back = NULL;
|
||||
|
||||
if (!counts[0])
|
||||
{
|
||||
*back = CopyWinding (in);
|
||||
return;
|
||||
}
|
||||
if (!counts[1])
|
||||
{
|
||||
*front = CopyWinding (in);
|
||||
return;
|
||||
}
|
||||
|
||||
maxpts = in->numpoints+4; // cant use counts[0]+2 because
|
||||
// of fp grouping errors
|
||||
|
||||
*front = f = AllocWinding (maxpts);
|
||||
*back = b = AllocWinding (maxpts);
|
||||
|
||||
for (i=0 ; i<in->numpoints ; i++)
|
||||
{
|
||||
p1 = in->p[i];
|
||||
|
||||
if (sides[i] == SIDE_ON)
|
||||
{
|
||||
VectorCopy (p1, f->p[f->numpoints]);
|
||||
f->numpoints++;
|
||||
VectorCopy (p1, b->p[b->numpoints]);
|
||||
b->numpoints++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (sides[i] == SIDE_FRONT)
|
||||
{
|
||||
VectorCopy (p1, f->p[f->numpoints]);
|
||||
f->numpoints++;
|
||||
}
|
||||
if (sides[i] == SIDE_BACK)
|
||||
{
|
||||
VectorCopy (p1, b->p[b->numpoints]);
|
||||
b->numpoints++;
|
||||
}
|
||||
|
||||
if (sides[i+1] == SIDE_ON || sides[i+1] == sides[i])
|
||||
continue;
|
||||
|
||||
// generate a split point
|
||||
p2 = in->p[(i+1)%in->numpoints];
|
||||
|
||||
dot = dists[i] / (dists[i]-dists[i+1]);
|
||||
for (j=0 ; j<3 ; j++)
|
||||
{ // avoid round off error when possible
|
||||
if (normal[j] == 1)
|
||||
mid[j] = dist;
|
||||
else if (normal[j] == -1)
|
||||
mid[j] = -dist;
|
||||
else
|
||||
mid[j] = p1[j] + dot*(p2[j]-p1[j]);
|
||||
}
|
||||
|
||||
VectorCopy (mid, f->p[f->numpoints]);
|
||||
f->numpoints++;
|
||||
VectorCopy (mid, b->p[b->numpoints]);
|
||||
b->numpoints++;
|
||||
}
|
||||
|
||||
if (f->numpoints > maxpts || b->numpoints > maxpts)
|
||||
Error ("ClipWinding: points exceeded estimate");
|
||||
if (f->numpoints > MAX_POINTS_ON_WINDING || b->numpoints > MAX_POINTS_ON_WINDING)
|
||||
Error ("ClipWinding: MAX_POINTS_ON_WINDING");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
=============
|
||||
ChopWindingInPlace
|
||||
=============
|
||||
*/
|
||||
void ChopWindingInPlace (winding_t **inout, vec3_t normal, vec_t dist, vec_t epsilon)
|
||||
{
|
||||
winding_t *in;
|
||||
vec_t dists[MAX_POINTS_ON_WINDING+4];
|
||||
int sides[MAX_POINTS_ON_WINDING+4];
|
||||
int counts[3];
|
||||
vec_t dot; // VC 4.2 optimizer bug if not static
|
||||
int i, j;
|
||||
vec_t *p1, *p2;
|
||||
vec3_t mid;
|
||||
winding_t *f;
|
||||
int maxpts;
|
||||
|
||||
in = *inout;
|
||||
counts[0] = counts[1] = counts[2] = 0;
|
||||
|
||||
if (!in)
|
||||
{
|
||||
printf ("Warning: NULL passed to ChopWindingInPlace\n");
|
||||
return;
|
||||
}
|
||||
if (in->numpoints >= MAX_POINTS_ON_WINDING-4)
|
||||
Error ("ChopWinding: MAX_POINTS_ON_WINDING");
|
||||
|
||||
// determine sides for each point
|
||||
for (i=0 ; i<in->numpoints ; i++)
|
||||
{
|
||||
dot = DotProduct (in->p[i], normal);
|
||||
dot -= dist;
|
||||
dists[i] = dot;
|
||||
if (dot > epsilon)
|
||||
sides[i] = SIDE_FRONT;
|
||||
else if (dot < -epsilon)
|
||||
sides[i] = SIDE_BACK;
|
||||
else
|
||||
{
|
||||
sides[i] = SIDE_ON;
|
||||
}
|
||||
counts[sides[i]]++;
|
||||
}
|
||||
sides[i] = sides[0];
|
||||
dists[i] = dists[0];
|
||||
|
||||
if (!counts[0])
|
||||
{
|
||||
FreeWinding (in);
|
||||
*inout = NULL;
|
||||
return;
|
||||
}
|
||||
if (!counts[1])
|
||||
return; // inout stays the same
|
||||
|
||||
maxpts = in->numpoints+4; // cant use counts[0]+2 because
|
||||
// of fp grouping errors
|
||||
|
||||
f = AllocWinding (maxpts);
|
||||
|
||||
for (i=0 ; i<in->numpoints ; i++)
|
||||
{
|
||||
p1 = in->p[i];
|
||||
|
||||
if (sides[i] == SIDE_ON)
|
||||
{
|
||||
VectorCopy (p1, f->p[f->numpoints]);
|
||||
f->numpoints++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (sides[i] == SIDE_FRONT)
|
||||
{
|
||||
VectorCopy (p1, f->p[f->numpoints]);
|
||||
f->numpoints++;
|
||||
}
|
||||
|
||||
if (sides[i+1] == SIDE_ON || sides[i+1] == sides[i])
|
||||
continue;
|
||||
|
||||
// generate a split point
|
||||
p2 = in->p[(i+1)%in->numpoints];
|
||||
|
||||
dot = dists[i] / (dists[i]-dists[i+1]);
|
||||
for (j=0 ; j<3 ; j++)
|
||||
{ // avoid round off error when possible
|
||||
if (normal[j] == 1)
|
||||
mid[j] = dist;
|
||||
else if (normal[j] == -1)
|
||||
mid[j] = -dist;
|
||||
else
|
||||
mid[j] = p1[j] + dot*(p2[j]-p1[j]);
|
||||
}
|
||||
|
||||
VectorCopy (mid, f->p[f->numpoints]);
|
||||
f->numpoints++;
|
||||
}
|
||||
|
||||
if (f->numpoints > maxpts)
|
||||
Error ("ClipWinding: points exceeded estimate");
|
||||
if (f->numpoints > MAX_POINTS_ON_WINDING)
|
||||
Error ("ClipWinding: MAX_POINTS_ON_WINDING");
|
||||
|
||||
FreeWinding (in);
|
||||
*inout = f;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
=================
|
||||
ChopWinding
|
||||
|
||||
Returns the fragment of in that is on the front side
|
||||
of the cliping plane. The original is freed.
|
||||
=================
|
||||
*/
|
||||
winding_t *ChopWinding (winding_t *in, vec3_t normal, vec_t dist)
|
||||
{
|
||||
winding_t *f, *b;
|
||||
|
||||
ClipWindingEpsilon (in, normal, dist, ON_EPSILON, &f, &b);
|
||||
FreeWinding (in);
|
||||
if (b)
|
||||
FreeWinding (b);
|
||||
return f;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
=================
|
||||
CheckWinding
|
||||
|
||||
=================
|
||||
*/
|
||||
void CheckWinding (winding_t *w)
|
||||
{
|
||||
int i, j;
|
||||
vec_t *p1, *p2;
|
||||
vec_t d, edgedist;
|
||||
vec3_t dir, edgenormal, facenormal;
|
||||
vec_t area;
|
||||
vec_t facedist;
|
||||
|
||||
if (w->numpoints < 3)
|
||||
Error ("CheckWinding: %i points",w->numpoints);
|
||||
|
||||
area = WindingArea(w);
|
||||
if (area < 1)
|
||||
Error ("CheckWinding: %f area", area);
|
||||
|
||||
WindingPlane (w, facenormal, &facedist);
|
||||
|
||||
for (i=0 ; i<w->numpoints ; i++)
|
||||
{
|
||||
p1 = w->p[i];
|
||||
|
||||
for (j=0 ; j<3 ; j++)
|
||||
if (p1[j] > BOGUS_RANGE || p1[j] < -BOGUS_RANGE)
|
||||
Error ("CheckFace: BUGUS_RANGE: %f",p1[j]);
|
||||
|
||||
j = i+1 == w->numpoints ? 0 : i+1;
|
||||
|
||||
// check the point is on the face plane
|
||||
d = DotProduct (p1, facenormal) - facedist;
|
||||
if (d < -ON_EPSILON || d > ON_EPSILON)
|
||||
Error ("CheckWinding: point off plane");
|
||||
|
||||
// check the edge isnt degenerate
|
||||
p2 = w->p[j];
|
||||
VectorSubtract (p2, p1, dir);
|
||||
|
||||
if (VectorLength (dir) < ON_EPSILON)
|
||||
Error ("CheckWinding: degenerate edge");
|
||||
|
||||
CrossProduct (facenormal, dir, edgenormal);
|
||||
VectorNormalize (edgenormal, edgenormal);
|
||||
edgedist = DotProduct (p1, edgenormal);
|
||||
edgedist += ON_EPSILON;
|
||||
|
||||
// all other points must be on front side
|
||||
for (j=0 ; j<w->numpoints ; j++)
|
||||
{
|
||||
if (j == i)
|
||||
continue;
|
||||
d = DotProduct (w->p[j], edgenormal);
|
||||
if (d > edgedist)
|
||||
Error ("CheckWinding: non-convex");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
============
|
||||
WindingOnPlaneSide
|
||||
============
|
||||
*/
|
||||
int WindingOnPlaneSide (winding_t *w, vec3_t normal, vec_t dist)
|
||||
{
|
||||
qboolean front, back;
|
||||
int i;
|
||||
vec_t d;
|
||||
|
||||
front = false;
|
||||
back = false;
|
||||
for (i=0 ; i<w->numpoints ; i++)
|
||||
{
|
||||
d = DotProduct (w->p[i], normal) - dist;
|
||||
if (d < -ON_EPSILON)
|
||||
{
|
||||
if (front)
|
||||
return SIDE_CROSS;
|
||||
back = true;
|
||||
continue;
|
||||
}
|
||||
if (d > ON_EPSILON)
|
||||
{
|
||||
if (back)
|
||||
return SIDE_CROSS;
|
||||
front = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (back)
|
||||
return SIDE_BACK;
|
||||
if (front)
|
||||
return SIDE_FRONT;
|
||||
return SIDE_ON;
|
||||
}
|
||||
|
||||
55
tools/quake2/qdata_heretic2/common/polylib.h
Normal file
55
tools/quake2/qdata_heretic2/common/polylib.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int numpoints;
|
||||
vec3_t p[4]; // variable sized
|
||||
} winding_t;
|
||||
|
||||
#define MAX_POINTS_ON_WINDING 64
|
||||
|
||||
// you can define on_epsilon in the makefile as tighter
|
||||
#ifndef ON_EPSILON
|
||||
#define ON_EPSILON 0.1
|
||||
#endif
|
||||
|
||||
winding_t *AllocWinding (int points);
|
||||
vec_t WindingArea (winding_t *w);
|
||||
void WindingCenter (winding_t *w, vec3_t center);
|
||||
void ClipWindingEpsilon (winding_t *in, vec3_t normal, vec_t dist,
|
||||
vec_t epsilon, winding_t **front, winding_t **back);
|
||||
winding_t *ChopWinding (winding_t *in, vec3_t normal, vec_t dist);
|
||||
winding_t *CopyWinding (winding_t *w);
|
||||
winding_t *ReverseWinding (winding_t *w);
|
||||
winding_t *BaseWindingForPlane (vec3_t normal, vec_t dist);
|
||||
void CheckWinding (winding_t *w);
|
||||
void WindingPlane (winding_t *w, vec3_t normal, vec_t *dist);
|
||||
void RemoveColinearPoints (winding_t *w);
|
||||
int WindingOnPlaneSide (winding_t *w, vec3_t normal, vec_t dist);
|
||||
void FreeWinding (winding_t *w);
|
||||
void WindingBounds (winding_t *w, vec3_t mins, vec3_t maxs);
|
||||
|
||||
void ChopWindingInPlace (winding_t **w, vec3_t normal, vec_t dist, vec_t epsilon);
|
||||
// frees the original if clipped
|
||||
|
||||
void pw(winding_t *w);
|
||||
82
tools/quake2/qdata_heretic2/common/qfiles.c
Normal file
82
tools/quake2/qdata_heretic2/common/qfiles.c
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "qfiles.h"
|
||||
#include "scriplib.h"
|
||||
//#include <windows.h>
|
||||
|
||||
materialtype_t defaultmaterialtypes[] =
|
||||
{
|
||||
{"gravel", MATERIAL_GRAVEL},
|
||||
{"metal", MATERIAL_METAL},
|
||||
{"stone", MATERIAL_STONE},
|
||||
{"wood", MATERIAL_WOOD},
|
||||
{NULL, 0}
|
||||
};
|
||||
|
||||
materialtype_t *materialtypes;
|
||||
|
||||
void QFile_ReadMaterialTypes(char* filename)
|
||||
{
|
||||
int i;
|
||||
FILE *f;
|
||||
|
||||
f = fopen (filename, "rb");
|
||||
if (!f)
|
||||
{
|
||||
materialtypes = defaultmaterialtypes;
|
||||
return;
|
||||
}
|
||||
fclose (f);
|
||||
|
||||
free(materialtypes);
|
||||
materialtypes = (materialtype_t*)malloc(256 * sizeof(materialtype_t));
|
||||
|
||||
LoadScriptFile(filename);
|
||||
i = 0;
|
||||
|
||||
while (i < 255)
|
||||
{
|
||||
GetScriptToken (true);
|
||||
if (endofscript)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (strcmp(token, "material") != 0)
|
||||
{
|
||||
while (ScriptTokenAvailable())
|
||||
{
|
||||
GetScriptToken(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GetScriptToken(false);
|
||||
materialtypes[i].name = (char*)malloc(strlen(token) + 1);
|
||||
strcpy(materialtypes[i].name, token);
|
||||
GetScriptToken (false);
|
||||
materialtypes[i].value = atoi(token);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
materialtypes[i].name = NULL;
|
||||
materialtypes[i].value = 0;
|
||||
}
|
||||
619
tools/quake2/qdata_heretic2/common/qfiles.h
Normal file
619
tools/quake2/qdata_heretic2/common/qfiles.h
Normal file
@@ -0,0 +1,619 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef _QFILES_H
|
||||
#define _QFILES_H
|
||||
|
||||
#include "q_typedef.h"
|
||||
|
||||
//
|
||||
// qfiles.h: quake file formats
|
||||
// This file must be identical in the quake and utils directories
|
||||
//
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
The .pak files are just a linear collapse of a directory tree
|
||||
|
||||
========================================================================
|
||||
*/
|
||||
|
||||
#define IDPAKHEADER (('K'<<24)+('C'<<16)+('A'<<8)+'P')
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char name[56];
|
||||
int filepos, filelen;
|
||||
} dpackfile_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int ident; // == IDPAKHEADER
|
||||
int dirofs;
|
||||
int dirlen;
|
||||
} dpackheader_t;
|
||||
|
||||
#define MAX_FILES_IN_PACK 4096
|
||||
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
PCX files are used for as many images as possible
|
||||
|
||||
========================================================================
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char manufacturer;
|
||||
char version;
|
||||
char encoding;
|
||||
char bits_per_pixel;
|
||||
unsigned short xmin,ymin,xmax,ymax;
|
||||
unsigned short hres,vres;
|
||||
unsigned char palette[48];
|
||||
char reserved;
|
||||
char color_planes;
|
||||
unsigned short bytes_per_line;
|
||||
unsigned short palette_type;
|
||||
char filler[58];
|
||||
unsigned char data; // unbounded
|
||||
} pcx_t;
|
||||
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
.MD2 compressed triangle model file format
|
||||
|
||||
========================================================================
|
||||
*/
|
||||
#define IDJOINTEDALIASHEADER (('2'<<24)+('J'<<16)+('D'<<8)+'I')
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
.MD2 triangle model file format
|
||||
|
||||
========================================================================
|
||||
*/
|
||||
|
||||
#define IDALIASHEADER (('2'<<24)+('P'<<16)+('D'<<8)+'I')
|
||||
#define ALIAS_VERSION 8
|
||||
|
||||
#define MAX_TRIANGLES 2048
|
||||
#define MAX_VERTS 2048
|
||||
#define MAX_FRAMES 512
|
||||
#define MAX_MD2SKINS 64
|
||||
#define MAX_SKINNAME 64
|
||||
|
||||
typedef struct
|
||||
{
|
||||
short s;
|
||||
short t;
|
||||
} dstvert_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
short index_xyz[3];
|
||||
short index_st[3];
|
||||
} dtriangle_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
byte v[3]; // scaled byte to fit in frame mins/maxs
|
||||
byte lightnormalindex;
|
||||
} dtrivertx_t;
|
||||
|
||||
#define DTRIVERTX_V0 0
|
||||
#define DTRIVERTX_V1 1
|
||||
#define DTRIVERTX_V2 2
|
||||
#define DTRIVERTX_LNI 3
|
||||
#define DTRIVERTX_SIZE 4
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float scale[3]; // multiply byte verts by this
|
||||
float translate[3]; // then add this
|
||||
char name[16]; // frame name from grabbing
|
||||
dtrivertx_t verts[1]; // variable sized
|
||||
} daliasframe_t;
|
||||
|
||||
|
||||
// the glcmd format:
|
||||
// a positive integer starts a tristrip command, followed by that many
|
||||
// vertex structures.
|
||||
// a negative integer starts a trifan command, followed by -x vertexes
|
||||
// a zero indicates the end of the command list.
|
||||
// a vertex consists of a floating point s, a floating point t,
|
||||
// and an integer vertex index.
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int ident;
|
||||
int version;
|
||||
|
||||
int skinwidth;
|
||||
int skinheight;
|
||||
int framesize; // byte size of each frame
|
||||
|
||||
int num_skins;
|
||||
int num_xyz;
|
||||
int num_st; // greater than num_xyz for seams
|
||||
int num_tris;
|
||||
int num_glcmds; // dwords in strip/fan command list
|
||||
int num_frames;
|
||||
|
||||
int ofs_skins; // each skin is a MAX_SKINNAME string
|
||||
int ofs_st; // byte offset from start for stverts
|
||||
int ofs_tris; // offset for dtriangles
|
||||
int ofs_frames; // offset for first frame
|
||||
int ofs_glcmds;
|
||||
int ofs_end; // end of file
|
||||
|
||||
} dmdl_t;
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
.BK file format
|
||||
|
||||
========================================================================
|
||||
*/
|
||||
|
||||
#define IDBOOKHEADER (('K'<<24)+('O'<<16)+('O'<<8)+'B')
|
||||
#define BOOK_VERSION 2
|
||||
|
||||
typedef struct bookframe_s
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
int w;
|
||||
int h;
|
||||
char name[MAX_SKINNAME]; // name of gfx file
|
||||
} bookframe_t;
|
||||
|
||||
typedef struct bookheader_s
|
||||
{
|
||||
unsigned int ident;
|
||||
unsigned int version;
|
||||
int num_segments;
|
||||
int total_w;
|
||||
int total_h;
|
||||
} bookheader_t;
|
||||
|
||||
typedef struct book_s
|
||||
{
|
||||
bookheader_t bheader;
|
||||
bookframe_t bframes[MAX_MD2SKINS];
|
||||
} book_t;
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
.SP2 sprite file format
|
||||
|
||||
========================================================================
|
||||
*/
|
||||
|
||||
#define IDSPRITEHEADER (('2'<<24)+('S'<<16)+('D'<<8)+'I')
|
||||
// little-endian "IDS2"
|
||||
#define SPRITE_VERSION 2
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int width, height;
|
||||
int origin_x, origin_y; // raster coordinates inside pic
|
||||
char name[MAX_SKINNAME]; // name of pcx file
|
||||
} dsprframe_t;
|
||||
|
||||
typedef struct {
|
||||
int ident;
|
||||
int version;
|
||||
int numframes;
|
||||
dsprframe_t frames[1]; // variable sized
|
||||
} dsprite_t;
|
||||
|
||||
/*
|
||||
==============================================================================
|
||||
|
||||
.M8 texture file format
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
typedef struct palette_s
|
||||
{
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
byte r,g,b;
|
||||
};
|
||||
};
|
||||
} palette_t;
|
||||
|
||||
#define MIP_VERSION 2
|
||||
#define PAL_SIZE 256
|
||||
#define MIPLEVELS 16
|
||||
|
||||
typedef struct miptex_s
|
||||
{
|
||||
int version;
|
||||
char name[32];
|
||||
unsigned width[MIPLEVELS], height[MIPLEVELS];
|
||||
unsigned offsets[MIPLEVELS]; // four mip maps stored
|
||||
char animname[32]; // next frame in animation chain
|
||||
palette_t palette[PAL_SIZE];
|
||||
int flags;
|
||||
int contents;
|
||||
int value;
|
||||
} miptex_t;
|
||||
|
||||
|
||||
#define MIP32_VERSION 4
|
||||
|
||||
#define MIP32_NOMIP_FLAG2 0x00000001
|
||||
#define MIP32_DETAILER_FLAG2 0x00000002
|
||||
|
||||
typedef struct miptex32_s
|
||||
{
|
||||
int version;
|
||||
char name[128];
|
||||
char altname[128]; // texture substitution
|
||||
char animname[128]; // next frame in animation chain
|
||||
char damagename[128]; // image that should be shown when damaged
|
||||
unsigned width[MIPLEVELS], height[MIPLEVELS];
|
||||
unsigned offsets[MIPLEVELS];
|
||||
int flags;
|
||||
int contents;
|
||||
int value;
|
||||
float scale_x, scale_y;
|
||||
int mip_scale;
|
||||
|
||||
// detail texturing info
|
||||
char dt_name[128]; // detailed texture name
|
||||
float dt_scale_x, dt_scale_y;
|
||||
float dt_u, dt_v;
|
||||
float dt_alpha;
|
||||
int dt_src_blend_mode, dt_dst_blend_mode;
|
||||
|
||||
int flags2;
|
||||
int unused[19]; // future expansion to maintain compatibility with h2
|
||||
} miptex32_t;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
==============================================================================
|
||||
|
||||
.BSP file format
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
#define IDBSPHEADER (('P'<<24)+('S'<<16)+('B'<<8)+'I')
|
||||
// little-endian "IBSP"
|
||||
|
||||
#define BSPVERSION 38
|
||||
|
||||
|
||||
// upper design bounds
|
||||
// leaffaces, leafbrushes, planes, and verts are still bounded by
|
||||
// 16 bit short limits
|
||||
#define MAX_MAP_MODELS 1024
|
||||
#define MAX_MAP_BRUSHES 8192
|
||||
#define MAX_MAP_ENTITIES 2048
|
||||
#define MAX_MAP_ENTSTRING 0x40000
|
||||
#define MAX_MAP_TEXINFO 8192
|
||||
|
||||
#define MAX_MAP_AREAS 256
|
||||
#define MAX_MAP_AREAPORTALS 1024
|
||||
#define MAX_MAP_PLANES 65536
|
||||
#define MAX_MAP_NODES 65536
|
||||
#define MAX_MAP_BRUSHSIDES 65536
|
||||
#define MAX_MAP_LEAFS 65536
|
||||
#define MAX_MAP_VERTS 65536
|
||||
#define MAX_MAP_FACES 65536
|
||||
#define MAX_MAP_LEAFFACES 65536
|
||||
#define MAX_MAP_LEAFBRUSHES 65536
|
||||
#define MAX_MAP_PORTALS 65536
|
||||
#define MAX_MAP_EDGES 128000
|
||||
#define MAX_MAP_SURFEDGES 256000
|
||||
#define MAX_MAP_LIGHTING 0x200000
|
||||
#define MAX_MAP_VISIBILITY 0x180000
|
||||
|
||||
// key / value pair sizes
|
||||
|
||||
#define MAX_KEY 32
|
||||
#define MAX_VALUE 1024
|
||||
|
||||
//=============================================================================
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int fileofs, filelen;
|
||||
} lump_t;
|
||||
|
||||
#define LUMP_ENTITIES 0
|
||||
#define LUMP_PLANES 1
|
||||
#define LUMP_VERTEXES 2
|
||||
#define LUMP_VISIBILITY 3
|
||||
#define LUMP_NODES 4
|
||||
#define LUMP_TEXINFO 5
|
||||
#define LUMP_FACES 6
|
||||
#define LUMP_LIGHTING 7
|
||||
#define LUMP_LEAFS 8
|
||||
#define LUMP_LEAFFACES 9
|
||||
#define LUMP_LEAFBRUSHES 10
|
||||
#define LUMP_EDGES 11
|
||||
#define LUMP_SURFEDGES 12
|
||||
#define LUMP_MODELS 13
|
||||
#define LUMP_BRUSHES 14
|
||||
#define LUMP_BRUSHSIDES 15
|
||||
#define LUMP_POP 16
|
||||
#define LUMP_AREAS 17
|
||||
#define LUMP_AREAPORTALS 18
|
||||
#define HEADER_LUMPS 19
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int ident;
|
||||
int version;
|
||||
lump_t lumps[HEADER_LUMPS];
|
||||
} dheader_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float mins[3], maxs[3];
|
||||
float origin[3]; // for sounds or lights
|
||||
int headnode;
|
||||
int firstface, numfaces; // submodels just draw faces
|
||||
// without walking the bsp tree
|
||||
} dmodel_t;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float point[3];
|
||||
} dvertex_t;
|
||||
|
||||
|
||||
// 0-2 are axial planes
|
||||
#define PLANE_X 0
|
||||
#define PLANE_Y 1
|
||||
#define PLANE_Z 2
|
||||
|
||||
// 3-5 are non-axial planes snapped to the nearest
|
||||
#define PLANE_ANYX 3
|
||||
#define PLANE_ANYY 4
|
||||
#define PLANE_ANYZ 5
|
||||
|
||||
// planes (x&~1) and (x&~1)+1 are allways opposites
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float normal[3];
|
||||
float dist;
|
||||
int type; // PLANE_X - PLANE_ANYZ ?remove? trivial to regenerate
|
||||
} dplane_t;
|
||||
|
||||
|
||||
// contents flags are seperate bits
|
||||
// a given brush can contribute multiple content bits
|
||||
// multiple brushes can be in a single leaf
|
||||
|
||||
// these definitions also need to be in q_shared.h!
|
||||
|
||||
// lower bits are stronger, and will eat weaker brushes completely
|
||||
#define CONTENTS_SOLID 0x00000001 // an eye is never valid in a solid
|
||||
#define CONTENTS_WINDOW 0x00000002 // translucent, but not watery
|
||||
#define CONTENTS_PUSHPULL 0x00000004
|
||||
#define CONTENTS_LAVA 0x00000008
|
||||
#define CONTENTS_SLIME 0x00000010
|
||||
#define CONTENTS_WATER 0x00000020
|
||||
#define CONTENTS_MIST 0x00000040 // 64
|
||||
#define LAST_VISIBLE_CONTENTS 64 // this one worries me a bit JKH
|
||||
|
||||
// remaining contents are non-visible, and don't eat brushes
|
||||
|
||||
#define CONTENTS_AREAPORTAL 0x00008000
|
||||
|
||||
#define CONTENTS_PLAYERCLIP 0x00010000
|
||||
#define CONTENTS_MONSTERCLIP 0x00020000
|
||||
|
||||
// currents can be added to any other contents, and may be mixed
|
||||
#define CONTENTS_CURRENT_0 0x00040000
|
||||
#define CONTENTS_CURRENT_90 0x00080000
|
||||
#define CONTENTS_CURRENT_180 0x00100000
|
||||
#define CONTENTS_CURRENT_270 0x00200000
|
||||
#define CONTENTS_CURRENT_UP 0x00400000
|
||||
#define CONTENTS_CURRENT_DOWN 0x00800000
|
||||
|
||||
#define CONTENTS_ORIGIN 0x01000000 // removed before bsping an entity
|
||||
|
||||
#define CONTENTS_MONSTER 0x02000000 // should never be on a brush, only in game
|
||||
#define CONTENTS_DEADMONSTER 0x04000000
|
||||
#define CONTENTS_DETAIL 0x08000000 // brushes to be added after vis leafs
|
||||
#define CONTENTS_TRANSLUCENT 0x10000000 // auto set if any surface has trans
|
||||
#define CONTENTS_LADDER 0x20000000
|
||||
|
||||
|
||||
|
||||
#define SURF_LIGHT 0x00000001 // value will hold the light strength
|
||||
|
||||
#define SURF_SLICK 0x00000002 // effects game physics
|
||||
|
||||
#define SURF_SKY 0x00000004 // don't draw, but add to skybox
|
||||
#define SURF_WARP 0x00000008 // turbulent water warp
|
||||
#define SURF_TRANS33 0x00000010
|
||||
#define SURF_TRANS66 0x00000020
|
||||
#define SURF_FLOWING 0x00000040 // scroll towards angle
|
||||
#define SURF_NODRAW 0x00000080 // don't bother referencing the texture
|
||||
|
||||
#define SURF_HINT 0x00000100 // make a primary bsp splitter
|
||||
#define SURF_SKIP 0x00000200 // completely ignore, allowing non-closed brushes
|
||||
#define SURF_TALL_WALL 0x00000400 // face doesn't get broken up as normal
|
||||
|
||||
#define SURF_ALPHA_TEXTURE 0x00000800 // texture has alpha in it, and should show through in bsp process
|
||||
#define SURF_ANIMSPEED 0x00001000 // value will hold the anim speed in fps
|
||||
|
||||
#define SURF_UNDULATE 0x00002000 // rock surface up and down...
|
||||
#define SURF_SKYREFLECT 0x00004000 // liquid will somewhat reflect the sky - not quite finished....
|
||||
|
||||
#define SURF_TYPE_GRAVEL 0x00000000
|
||||
#define SURF_TYPE_METAL 0x01000000
|
||||
#define SURF_TYPE_STONE 0x02000000
|
||||
#define SURF_TYPE_WOOD 0x03000000
|
||||
#define SURF_MATERIAL 0xFF000000
|
||||
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int planenum;
|
||||
int children[2]; // negative numbers are -(leafs+1), not nodes
|
||||
short mins[3]; // for frustom culling
|
||||
short maxs[3];
|
||||
unsigned short firstface;
|
||||
unsigned short numfaces; // counting both sides
|
||||
} dnode_t;
|
||||
|
||||
|
||||
typedef struct texinfo_s
|
||||
{
|
||||
float vecs[2][4]; // [s/t][xyz offset]
|
||||
int flags; // miptex flags + overrides
|
||||
int value; // light emission, etc
|
||||
char texture[32]; // texture name (textures/*.wal)
|
||||
int nexttexinfo; // for animations, -1 = end of chain
|
||||
} texinfo_t;
|
||||
|
||||
|
||||
// note that edge 0 is never used, because negative edge nums are used for
|
||||
// counterclockwise use of the edge in a face
|
||||
typedef struct
|
||||
{
|
||||
unsigned short v[2]; // vertex numbers
|
||||
} dedge_t;
|
||||
|
||||
#define MAXLIGHTMAPS 4
|
||||
typedef struct
|
||||
{
|
||||
unsigned short planenum;
|
||||
short side;
|
||||
|
||||
int firstedge; // we must support > 64k edges
|
||||
short numedges;
|
||||
short texinfo;
|
||||
|
||||
// lighting info
|
||||
union {
|
||||
byte styles[MAXLIGHTMAPS];
|
||||
paletteRGBA_t lighting;
|
||||
};
|
||||
int lightofs; // start of [numstyles*surfsize] samples
|
||||
} dface_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int contents; // OR of all brushes (not needed?)
|
||||
|
||||
short cluster;
|
||||
short area;
|
||||
|
||||
short mins[3]; // for frustum culling
|
||||
short maxs[3];
|
||||
|
||||
unsigned short firstleafface;
|
||||
unsigned short numleaffaces;
|
||||
|
||||
unsigned short firstleafbrush;
|
||||
unsigned short numleafbrushes;
|
||||
} dleaf_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned short planenum; // facing out of the leaf
|
||||
short texinfo;
|
||||
} dbrushside_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int firstside;
|
||||
int numsides;
|
||||
int contents;
|
||||
} dbrush_t;
|
||||
|
||||
#define ANGLE_UP -1
|
||||
#define ANGLE_DOWN -2
|
||||
|
||||
|
||||
// the visibility lump consists of a header with a count, then
|
||||
// byte offsets for the PVS and PHS of each cluster, then the raw
|
||||
// compressed bit vectors
|
||||
#define DVIS_PVS 0
|
||||
#define DVIS_PHS 1
|
||||
typedef struct
|
||||
{
|
||||
int numclusters;
|
||||
int bitofs[8][2]; // bitofs[numclusters][2]
|
||||
} dvis_t;
|
||||
|
||||
// each area has a list of portals that lead into other areas
|
||||
// when portals are closed, other areas may not be visible or
|
||||
// hearable even if the vis info says that it should be
|
||||
typedef struct
|
||||
{
|
||||
int portalnum;
|
||||
int otherarea;
|
||||
} dareaportal_t;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int numareaportals;
|
||||
int firstareaportal;
|
||||
} darea_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char *name;
|
||||
int value;
|
||||
} materialtype_t;
|
||||
|
||||
enum
|
||||
{
|
||||
MATERIAL_GRAVEL,
|
||||
MATERIAL_METAL,
|
||||
MATERIAL_STONE,
|
||||
MATERIAL_WOOD,
|
||||
};
|
||||
|
||||
materialtype_t *materialtypes;
|
||||
|
||||
void QFile_ReadMaterialTypes(char* filename);
|
||||
|
||||
|
||||
#endif //_QFILES_H
|
||||
297
tools/quake2/qdata_heretic2/common/scriplib.c
Normal file
297
tools/quake2/qdata_heretic2/common/scriplib.c
Normal file
@@ -0,0 +1,297 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
// scriplib.c
|
||||
|
||||
#include "cmdlib.h"
|
||||
#include "inout.h"
|
||||
#include "scriplib.h"
|
||||
|
||||
/*
|
||||
=============================================================================
|
||||
|
||||
PARSING STUFF
|
||||
|
||||
=============================================================================
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char filename[1024];
|
||||
char *buffer,*script_p,*end_p;
|
||||
int line;
|
||||
} script_t;
|
||||
|
||||
#define MAX_INCLUDES 8
|
||||
script_t scriptstack[MAX_INCLUDES];
|
||||
script_t *script;
|
||||
int scriptline;
|
||||
|
||||
char token[MAXTOKEN];
|
||||
qboolean endofscript;
|
||||
qboolean tokenready; // only true if UnGetScriptToken was just called
|
||||
|
||||
/*
|
||||
==============
|
||||
AddScriptToStack
|
||||
==============
|
||||
*/
|
||||
void AddScriptToStack (char *filename)
|
||||
{
|
||||
int size;
|
||||
|
||||
script++;
|
||||
if (script == &scriptstack[MAX_INCLUDES])
|
||||
Error ("script file exceeded MAX_INCLUDES");
|
||||
strcpy (script->filename, ExpandPath (filename) );
|
||||
|
||||
size = LoadFile (script->filename, (void **)&script->buffer);
|
||||
|
||||
printf ("entering %s\n", script->filename);
|
||||
|
||||
script->line = 1;
|
||||
|
||||
script->script_p = script->buffer;
|
||||
script->end_p = script->buffer + size;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
==============
|
||||
LoadScriptFile
|
||||
==============
|
||||
*/
|
||||
void LoadScriptFile (char *filename)
|
||||
{
|
||||
script = scriptstack;
|
||||
AddScriptToStack (filename);
|
||||
|
||||
endofscript = false;
|
||||
tokenready = false;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
==============
|
||||
ParseFromMemory
|
||||
==============
|
||||
*/
|
||||
void ParseFromMemory (char *buffer, int size)
|
||||
{
|
||||
script = scriptstack;
|
||||
script++;
|
||||
if (script == &scriptstack[MAX_INCLUDES])
|
||||
Error ("script file exceeded MAX_INCLUDES");
|
||||
strcpy (script->filename, "memory buffer" );
|
||||
|
||||
script->buffer = buffer;
|
||||
script->line = 1;
|
||||
script->script_p = script->buffer;
|
||||
script->end_p = script->buffer + size;
|
||||
|
||||
endofscript = false;
|
||||
tokenready = false;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
==============
|
||||
UnGetScriptToken
|
||||
|
||||
Signals that the current token was not used, and should be reported
|
||||
for the next GetScriptToken. Note that
|
||||
|
||||
GetScriptToken (true);
|
||||
UnGetScriptToken ();
|
||||
GetScriptToken (false);
|
||||
|
||||
could cross a line boundary.
|
||||
==============
|
||||
*/
|
||||
void UnGetScriptToken (void)
|
||||
{
|
||||
tokenready = true;
|
||||
}
|
||||
|
||||
|
||||
qboolean EndOfScript (qboolean crossline)
|
||||
{
|
||||
if (!crossline)
|
||||
Error ("Line %i is incomplete\n",scriptline);
|
||||
|
||||
if (!strcmp (script->filename, "memory buffer"))
|
||||
{
|
||||
endofscript = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
free (script->buffer);
|
||||
if (script == scriptstack+1)
|
||||
{
|
||||
endofscript = true;
|
||||
return false;
|
||||
}
|
||||
script--;
|
||||
scriptline = script->line;
|
||||
printf ("returning to %s\n", script->filename);
|
||||
return GetScriptToken (crossline);
|
||||
}
|
||||
|
||||
/*
|
||||
==============
|
||||
GetScriptToken
|
||||
==============
|
||||
*/
|
||||
qboolean GetScriptToken (qboolean crossline)
|
||||
{
|
||||
char *token_p;
|
||||
|
||||
if (tokenready) // is a token allready waiting?
|
||||
{
|
||||
tokenready = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (script->script_p >= script->end_p)
|
||||
return EndOfScript (crossline);
|
||||
|
||||
//
|
||||
// skip space
|
||||
//
|
||||
skipspace:
|
||||
while (*script->script_p <= 32)
|
||||
{
|
||||
if (script->script_p >= script->end_p)
|
||||
return EndOfScript (crossline);
|
||||
if (*script->script_p++ == '\n')
|
||||
{
|
||||
if (!crossline)
|
||||
Error ("Line %i is incomplete\n",scriptline);
|
||||
scriptline = script->line++;
|
||||
}
|
||||
}
|
||||
|
||||
if (script->script_p >= script->end_p)
|
||||
return EndOfScript (crossline);
|
||||
|
||||
// ; # // comments
|
||||
if (*script->script_p == ';' || *script->script_p == '#'
|
||||
|| ( script->script_p[0] == '/' && script->script_p[1] == '/') )
|
||||
{
|
||||
if (!crossline)
|
||||
Error ("Line %i is incomplete\n",scriptline);
|
||||
while (*script->script_p++ != '\n')
|
||||
if (script->script_p >= script->end_p)
|
||||
return EndOfScript (crossline);
|
||||
goto skipspace;
|
||||
}
|
||||
|
||||
// /* */ comments
|
||||
if (script->script_p[0] == '/' && script->script_p[1] == '*')
|
||||
{
|
||||
if (!crossline)
|
||||
Error ("Line %i is incomplete\n",scriptline);
|
||||
script->script_p+=2;
|
||||
while (script->script_p[0] != '*' && script->script_p[1] != '/')
|
||||
{
|
||||
script->script_p++;
|
||||
if (script->script_p >= script->end_p)
|
||||
return EndOfScript (crossline);
|
||||
}
|
||||
script->script_p += 2;
|
||||
goto skipspace;
|
||||
}
|
||||
|
||||
//
|
||||
// copy token
|
||||
//
|
||||
token_p = token;
|
||||
|
||||
if (*script->script_p == '"')
|
||||
{
|
||||
// quoted token
|
||||
script->script_p++;
|
||||
while (*script->script_p != '"')
|
||||
{
|
||||
*token_p++ = *script->script_p++;
|
||||
if (script->script_p == script->end_p)
|
||||
break;
|
||||
if (token_p == &token[MAXTOKEN])
|
||||
Error ("Token too large on line %i\n",scriptline);
|
||||
}
|
||||
script->script_p++;
|
||||
}
|
||||
else // regular token
|
||||
while ( *script->script_p > 32 && *script->script_p != ';')
|
||||
{
|
||||
*token_p++ = *script->script_p++;
|
||||
if (script->script_p == script->end_p)
|
||||
break;
|
||||
if (token_p == &token[MAXTOKEN])
|
||||
Error ("Token too large on line %i\n",scriptline);
|
||||
}
|
||||
|
||||
*token_p = 0;
|
||||
|
||||
if (!strcmp (token, "$include"))
|
||||
{
|
||||
GetScriptToken (false);
|
||||
AddScriptToStack (token);
|
||||
return GetScriptToken (crossline);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
==============
|
||||
ScriptTokenAvailable
|
||||
|
||||
Returns true if there is another token on the line
|
||||
==============
|
||||
*/
|
||||
qboolean ScriptTokenAvailable (void)
|
||||
{
|
||||
char *search_p;
|
||||
|
||||
search_p = script->script_p;
|
||||
|
||||
if (search_p >= script->end_p)
|
||||
return false;
|
||||
|
||||
while ( *search_p <= 32)
|
||||
{
|
||||
if (*search_p == '\n')
|
||||
return false;
|
||||
search_p++;
|
||||
if (search_p == script->end_p)
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
if (*search_p == ';')
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
44
tools/quake2/qdata_heretic2/common/scriplib.h
Normal file
44
tools/quake2/qdata_heretic2/common/scriplib.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
// scriplib.h
|
||||
|
||||
#ifndef __CMDLIB__
|
||||
#include "cmdlib.h"
|
||||
#endif
|
||||
|
||||
#define MAXTOKEN 1024
|
||||
|
||||
extern char token[MAXTOKEN];
|
||||
extern char *scriptbuffer,*script_p,*scriptend_p;
|
||||
extern int grabbed;
|
||||
extern int scriptline;
|
||||
extern qboolean endofscript;
|
||||
|
||||
|
||||
void LoadScriptFile (char *filename);
|
||||
void ParseFromMemory (char *buffer, int size);
|
||||
|
||||
qboolean GetScriptToken (qboolean crossline);
|
||||
void UnGetScriptToken (void);
|
||||
qboolean ScriptTokenAvailable (void);
|
||||
|
||||
|
||||
620
tools/quake2/qdata_heretic2/common/threads.c
Normal file
620
tools/quake2/qdata_heretic2/common/threads.c
Normal file
@@ -0,0 +1,620 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef WIN32
|
||||
// The below define is necessary to use
|
||||
// pthreads extensions like pthread_mutexattr_settype
|
||||
#define _GNU_SOURCE
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
#include "cmdlib.h"
|
||||
#include "mathlib.h"
|
||||
#include "inout.h"
|
||||
#include "her2_threads.h"
|
||||
|
||||
#define MAX_THREADS 64
|
||||
|
||||
int dispatch;
|
||||
int workcount;
|
||||
int oldf;
|
||||
qboolean pacifier;
|
||||
|
||||
qboolean threaded;
|
||||
|
||||
/*
|
||||
=============
|
||||
GetThreadWork
|
||||
|
||||
=============
|
||||
*/
|
||||
int GetThreadWork (void)
|
||||
{
|
||||
int r;
|
||||
int f;
|
||||
|
||||
ThreadLock ();
|
||||
|
||||
if (dispatch == workcount)
|
||||
{
|
||||
ThreadUnlock ();
|
||||
return -1;
|
||||
}
|
||||
|
||||
f = 10*dispatch / workcount;
|
||||
if (f != oldf)
|
||||
{
|
||||
oldf = f;
|
||||
if (pacifier)
|
||||
{
|
||||
Sys_Printf ("%i...", f);
|
||||
fflush( stdout ); /* ydnar */
|
||||
}
|
||||
}
|
||||
|
||||
r = dispatch;
|
||||
dispatch++;
|
||||
ThreadUnlock ();
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
void (*workfunction) (int);
|
||||
|
||||
void ThreadWorkerFunction (int threadnum)
|
||||
{
|
||||
int work;
|
||||
|
||||
while (1)
|
||||
{
|
||||
work = GetThreadWork ();
|
||||
if (work == -1)
|
||||
break;
|
||||
//Sys_Printf ("thread %i, work %i\n", threadnum, work);
|
||||
workfunction(work);
|
||||
}
|
||||
}
|
||||
|
||||
void RunThreadsOnIndividual (int workcnt, qboolean showpacifier, void(*func)(int))
|
||||
{
|
||||
if (numthreads == -1)
|
||||
ThreadSetDefault ();
|
||||
workfunction = func;
|
||||
RunThreadsOn (workcnt, showpacifier, ThreadWorkerFunction);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
===================================================================
|
||||
|
||||
WIN32
|
||||
|
||||
===================================================================
|
||||
*/
|
||||
#ifdef WIN32
|
||||
|
||||
#define USED
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
int numthreads = -1;
|
||||
CRITICAL_SECTION crit;
|
||||
static int enter;
|
||||
|
||||
void ThreadSetDefault (void)
|
||||
{
|
||||
SYSTEM_INFO info;
|
||||
|
||||
if (numthreads == -1) // not set manually
|
||||
{
|
||||
GetSystemInfo (&info);
|
||||
numthreads = info.dwNumberOfProcessors;
|
||||
if (numthreads < 1 || numthreads > 32)
|
||||
numthreads = 1;
|
||||
}
|
||||
|
||||
Sys_Printf ("%i threads\n", numthreads);
|
||||
}
|
||||
|
||||
|
||||
void ThreadLock (void)
|
||||
{
|
||||
if (!threaded)
|
||||
return;
|
||||
EnterCriticalSection (&crit);
|
||||
if (enter)
|
||||
Error ("Recursive ThreadLock\n");
|
||||
enter = 1;
|
||||
}
|
||||
|
||||
void ThreadUnlock (void)
|
||||
{
|
||||
if (!threaded)
|
||||
return;
|
||||
if (!enter)
|
||||
Error ("ThreadUnlock without lock\n");
|
||||
enter = 0;
|
||||
LeaveCriticalSection (&crit);
|
||||
}
|
||||
|
||||
/*
|
||||
=============
|
||||
RunThreadsOn
|
||||
=============
|
||||
*/
|
||||
void RunThreadsOn (int workcnt, qboolean showpacifier, void(*func)(int))
|
||||
{
|
||||
int threadid[MAX_THREADS];
|
||||
HANDLE threadhandle[MAX_THREADS];
|
||||
int i;
|
||||
int start, end;
|
||||
|
||||
start = I_FloatTime ();
|
||||
dispatch = 0;
|
||||
workcount = workcnt;
|
||||
oldf = -1;
|
||||
pacifier = showpacifier;
|
||||
threaded = true;
|
||||
|
||||
//
|
||||
// run threads in parallel
|
||||
//
|
||||
InitializeCriticalSection (&crit);
|
||||
|
||||
if (numthreads == 1)
|
||||
{ // use same thread
|
||||
func (0);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i=0 ; i<numthreads ; i++)
|
||||
{
|
||||
threadhandle[i] = CreateThread(
|
||||
NULL, // LPSECURITY_ATTRIBUTES lpsa,
|
||||
//0, // DWORD cbStack,
|
||||
|
||||
/* ydnar: cranking stack size to eliminate radiosity crash with 1MB stack on win32 */
|
||||
(4096 * 1024),
|
||||
|
||||
(LPTHREAD_START_ROUTINE)func, // LPTHREAD_START_ROUTINE lpStartAddr,
|
||||
(LPVOID)i, // LPVOID lpvThreadParm,
|
||||
0, // DWORD fdwCreate,
|
||||
&threadid[i]);
|
||||
}
|
||||
|
||||
for (i=0 ; i<numthreads ; i++)
|
||||
WaitForSingleObject (threadhandle[i], INFINITE);
|
||||
}
|
||||
DeleteCriticalSection (&crit);
|
||||
|
||||
threaded = false;
|
||||
end = I_FloatTime ();
|
||||
if (pacifier)
|
||||
Sys_Printf (" (%i)\n", end-start);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
===================================================================
|
||||
|
||||
OSF1
|
||||
|
||||
===================================================================
|
||||
*/
|
||||
|
||||
#ifdef __osf__
|
||||
#define USED
|
||||
|
||||
int numthreads = 4;
|
||||
|
||||
void ThreadSetDefault (void)
|
||||
{
|
||||
if (numthreads == -1) // not set manually
|
||||
{
|
||||
numthreads = 4;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
pthread_mutex_t *my_mutex;
|
||||
|
||||
void ThreadLock (void)
|
||||
{
|
||||
if (my_mutex)
|
||||
pthread_mutex_lock (my_mutex);
|
||||
}
|
||||
|
||||
void ThreadUnlock (void)
|
||||
{
|
||||
if (my_mutex)
|
||||
pthread_mutex_unlock (my_mutex);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
=============
|
||||
RunThreadsOn
|
||||
=============
|
||||
*/
|
||||
void RunThreadsOn (int workcnt, qboolean showpacifier, void(*func)(int))
|
||||
{
|
||||
int i;
|
||||
pthread_t work_threads[MAX_THREADS];
|
||||
pthread_addr_t status;
|
||||
pthread_attr_t attrib;
|
||||
pthread_mutexattr_t mattrib;
|
||||
int start, end;
|
||||
|
||||
start = I_FloatTime ();
|
||||
dispatch = 0;
|
||||
workcount = workcnt;
|
||||
oldf = -1;
|
||||
pacifier = showpacifier;
|
||||
threaded = true;
|
||||
|
||||
if (pacifier)
|
||||
setbuf (stdout, NULL);
|
||||
|
||||
if (!my_mutex)
|
||||
{
|
||||
my_mutex = safe_malloc (sizeof(*my_mutex));
|
||||
if (pthread_mutexattr_create (&mattrib) == -1)
|
||||
Error ("pthread_mutex_attr_create failed");
|
||||
if (pthread_mutexattr_setkind_np (&mattrib, MUTEX_FAST_NP) == -1)
|
||||
Error ("pthread_mutexattr_setkind_np failed");
|
||||
if (pthread_mutex_init (my_mutex, mattrib) == -1)
|
||||
Error ("pthread_mutex_init failed");
|
||||
}
|
||||
|
||||
if (pthread_attr_create (&attrib) == -1)
|
||||
Error ("pthread_attr_create failed");
|
||||
if (pthread_attr_setstacksize (&attrib, 0x100000) == -1)
|
||||
Error ("pthread_attr_setstacksize failed");
|
||||
|
||||
for (i=0 ; i<numthreads ; i++)
|
||||
{
|
||||
if (pthread_create(&work_threads[i], attrib
|
||||
, (pthread_startroutine_t)func, (pthread_addr_t)i) == -1)
|
||||
Error ("pthread_create failed");
|
||||
}
|
||||
|
||||
for (i=0 ; i<numthreads ; i++)
|
||||
{
|
||||
if (pthread_join (work_threads[i], &status) == -1)
|
||||
Error ("pthread_join failed");
|
||||
}
|
||||
|
||||
threaded = false;
|
||||
|
||||
end = I_FloatTime ();
|
||||
if (pacifier)
|
||||
Sys_Printf (" (%i)\n", end-start);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
===================================================================
|
||||
|
||||
IRIX
|
||||
|
||||
===================================================================
|
||||
*/
|
||||
|
||||
#ifdef _MIPS_ISA
|
||||
#define USED
|
||||
|
||||
#include <task.h>
|
||||
#include <abi_mutex.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/prctl.h>
|
||||
|
||||
|
||||
int numthreads = -1;
|
||||
abilock_t lck;
|
||||
|
||||
void ThreadSetDefault (void)
|
||||
{
|
||||
if (numthreads == -1)
|
||||
numthreads = prctl(PR_MAXPPROCS);
|
||||
Sys_Printf ("%i threads\n", numthreads);
|
||||
usconfig (CONF_INITUSERS, numthreads);
|
||||
}
|
||||
|
||||
|
||||
void ThreadLock (void)
|
||||
{
|
||||
spin_lock (&lck);
|
||||
}
|
||||
|
||||
void ThreadUnlock (void)
|
||||
{
|
||||
release_lock (&lck);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
=============
|
||||
RunThreadsOn
|
||||
=============
|
||||
*/
|
||||
void RunThreadsOn (int workcnt, qboolean showpacifier, void(*func)(int))
|
||||
{
|
||||
int i;
|
||||
int pid[MAX_THREADS];
|
||||
int start, end;
|
||||
|
||||
start = I_FloatTime ();
|
||||
dispatch = 0;
|
||||
workcount = workcnt;
|
||||
oldf = -1;
|
||||
pacifier = showpacifier;
|
||||
threaded = true;
|
||||
|
||||
if (pacifier)
|
||||
setbuf (stdout, NULL);
|
||||
|
||||
init_lock (&lck);
|
||||
|
||||
for (i=0 ; i<numthreads-1 ; i++)
|
||||
{
|
||||
pid[i] = sprocsp ( (void (*)(void *, size_t))func, PR_SALL, (void *)i
|
||||
, NULL, 0x200000); // 2 meg stacks
|
||||
if (pid[i] == -1)
|
||||
{
|
||||
perror ("sproc");
|
||||
Error ("sproc failed");
|
||||
}
|
||||
}
|
||||
|
||||
func(i);
|
||||
|
||||
for (i=0 ; i<numthreads-1 ; i++)
|
||||
wait (NULL);
|
||||
|
||||
threaded = false;
|
||||
|
||||
end = I_FloatTime ();
|
||||
if (pacifier)
|
||||
Sys_Printf (" (%i)\n", end-start);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
=======================================================================
|
||||
|
||||
Linux pthreads
|
||||
|
||||
=======================================================================
|
||||
*/
|
||||
|
||||
#ifdef __linux__
|
||||
#define USED
|
||||
|
||||
int numthreads = 4;
|
||||
|
||||
void ThreadSetDefault (void)
|
||||
{
|
||||
if (numthreads == -1) // not set manually
|
||||
{
|
||||
/* default to one thread, only multi-thread when specifically told to */
|
||||
numthreads = 1;
|
||||
}
|
||||
if(numthreads > 1)
|
||||
Sys_Printf("threads: %d\n", numthreads);
|
||||
}
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
typedef struct pt_mutex_s
|
||||
{
|
||||
pthread_t *owner;
|
||||
pthread_mutex_t a_mutex;
|
||||
pthread_cond_t cond;
|
||||
unsigned int lock;
|
||||
} pt_mutex_t;
|
||||
|
||||
pt_mutex_t global_lock;
|
||||
|
||||
void ThreadLock(void)
|
||||
{
|
||||
pt_mutex_t *pt_mutex = &global_lock;
|
||||
|
||||
if(!threaded)
|
||||
return;
|
||||
|
||||
pthread_mutex_lock(&pt_mutex->a_mutex);
|
||||
if(pthread_equal(pthread_self(), (pthread_t)&pt_mutex->owner))
|
||||
pt_mutex->lock++;
|
||||
else
|
||||
{
|
||||
if((!pt_mutex->owner) && (pt_mutex->lock == 0))
|
||||
{
|
||||
pt_mutex->owner = (pthread_t *)pthread_self();
|
||||
pt_mutex->lock = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
pthread_cond_wait(&pt_mutex->cond, &pt_mutex->a_mutex);
|
||||
if((!pt_mutex->owner) && (pt_mutex->lock == 0))
|
||||
{
|
||||
pt_mutex->owner = (pthread_t *)pthread_self();
|
||||
pt_mutex->lock = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&pt_mutex->a_mutex);
|
||||
}
|
||||
|
||||
void ThreadUnlock(void)
|
||||
{
|
||||
pt_mutex_t *pt_mutex = &global_lock;
|
||||
|
||||
if(!threaded)
|
||||
return;
|
||||
|
||||
pthread_mutex_lock(&pt_mutex->a_mutex);
|
||||
pt_mutex->lock--;
|
||||
|
||||
if(pt_mutex->lock == 0)
|
||||
{
|
||||
pt_mutex->owner = NULL;
|
||||
pthread_cond_signal(&pt_mutex->cond);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&pt_mutex->a_mutex);
|
||||
}
|
||||
|
||||
void recursive_mutex_init(pthread_mutexattr_t attribs)
|
||||
{
|
||||
pt_mutex_t *pt_mutex = &global_lock;
|
||||
|
||||
pt_mutex->owner = NULL;
|
||||
if(pthread_mutex_init(&pt_mutex->a_mutex, &attribs) != 0)
|
||||
Error("pthread_mutex_init failed\n");
|
||||
if(pthread_cond_init(&pt_mutex->cond, NULL) != 0)
|
||||
Error("pthread_cond_init failed\n");
|
||||
|
||||
pt_mutex->lock = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
=============
|
||||
RunThreadsOn
|
||||
=============
|
||||
*/
|
||||
void RunThreadsOn (int workcnt, qboolean showpacifier, void(*func)(int))
|
||||
{
|
||||
pthread_mutexattr_t mattrib;
|
||||
pthread_t work_threads[MAX_THREADS];
|
||||
|
||||
int start, end;
|
||||
int i=0, status=0;
|
||||
|
||||
start = I_FloatTime ();
|
||||
pacifier = showpacifier;
|
||||
|
||||
dispatch = 0;
|
||||
oldf = -1;
|
||||
workcount = workcnt;
|
||||
|
||||
if(numthreads == 1)
|
||||
func(0);
|
||||
else
|
||||
{
|
||||
threaded = true;
|
||||
|
||||
if(pacifier)
|
||||
setbuf(stdout, NULL);
|
||||
|
||||
if(pthread_mutexattr_init(&mattrib) != 0)
|
||||
Error("pthread_mutexattr_init failed");
|
||||
#if __GLIBC_MINOR__ == 1
|
||||
if (pthread_mutexattr_settype(&mattrib, PTHREAD_MUTEX_FAST_NP) != 0)
|
||||
#else
|
||||
if (pthread_mutexattr_settype(&mattrib, PTHREAD_MUTEX_ADAPTIVE_NP) != 0)
|
||||
#endif
|
||||
Error ("pthread_mutexattr_settype failed");
|
||||
recursive_mutex_init(mattrib);
|
||||
|
||||
for (i=0 ; i<numthreads ; i++)
|
||||
{
|
||||
/* Default pthread attributes: joinable & non-realtime scheduling */
|
||||
if(pthread_create(&work_threads[i], NULL, (void*)func, (void*)i) != 0)
|
||||
Error("pthread_create failed");
|
||||
}
|
||||
for (i=0 ; i<numthreads ; i++)
|
||||
{
|
||||
if(pthread_join(work_threads[i], (void **)&status) != 0)
|
||||
Error("pthread_join failed");
|
||||
}
|
||||
pthread_mutexattr_destroy(&mattrib);
|
||||
threaded = false;
|
||||
}
|
||||
|
||||
end = I_FloatTime ();
|
||||
if (pacifier)
|
||||
Sys_Printf (" (%i)\n", end-start);
|
||||
}
|
||||
#endif // ifdef __linux__
|
||||
|
||||
|
||||
/*
|
||||
=======================================================================
|
||||
|
||||
SINGLE THREAD
|
||||
|
||||
=======================================================================
|
||||
*/
|
||||
|
||||
#ifndef USED
|
||||
|
||||
int numthreads = 1;
|
||||
|
||||
void ThreadSetDefault (void)
|
||||
{
|
||||
numthreads = 1;
|
||||
}
|
||||
|
||||
void ThreadLock (void)
|
||||
{
|
||||
}
|
||||
|
||||
void ThreadUnlock (void)
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
=============
|
||||
RunThreadsOn
|
||||
=============
|
||||
*/
|
||||
void RunThreadsOn (int workcnt, qboolean showpacifier, void(*func)(int))
|
||||
{
|
||||
int i;
|
||||
int start, end;
|
||||
|
||||
dispatch = 0;
|
||||
workcount = workcnt;
|
||||
oldf = -1;
|
||||
pacifier = showpacifier;
|
||||
start = I_FloatTime ();
|
||||
func(0);
|
||||
|
||||
end = I_FloatTime ();
|
||||
if (pacifier)
|
||||
Sys_Printf (" (%i)\n", end-start);
|
||||
}
|
||||
|
||||
#endif
|
||||
550
tools/quake2/qdata_heretic2/common/token.c
Normal file
550
tools/quake2/qdata_heretic2/common/token.c
Normal file
@@ -0,0 +1,550 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
|
||||
//**************************************************************************
|
||||
//**
|
||||
//** token.c
|
||||
//**
|
||||
//**************************************************************************
|
||||
|
||||
// HEADER FILES ------------------------------------------------------------
|
||||
|
||||
#include "token.h"
|
||||
#include "inout.h"
|
||||
|
||||
// MACROS ------------------------------------------------------------------
|
||||
|
||||
// TYPES -------------------------------------------------------------------
|
||||
|
||||
typedef enum
|
||||
{
|
||||
CHR_EOF,
|
||||
CHR_LETTER,
|
||||
CHR_NUMBER,
|
||||
CHR_QUOTE,
|
||||
CHR_SPECIAL
|
||||
} chr_t;
|
||||
|
||||
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
|
||||
|
||||
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
|
||||
|
||||
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
|
||||
|
||||
static void ProcessLetterToken(void);
|
||||
static void ProcessNumberToken(void);
|
||||
static void ProcessQuoteToken(void);
|
||||
static void ProcessSpecialToken(void);
|
||||
static qboolean CheckForKeyword(void);
|
||||
static void NextChr(void);
|
||||
|
||||
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
|
||||
|
||||
// PUBLIC DATA DEFINITIONS -------------------------------------------------
|
||||
|
||||
tokenType_t tk_Token;
|
||||
int tk_Line;
|
||||
int tk_IntNumber;
|
||||
float tk_FloatNumber;
|
||||
char *tk_String;
|
||||
char tk_SourceName[MAX_FILE_NAME_LENGTH];
|
||||
|
||||
// PRIVATE DATA DEFINITIONS ------------------------------------------------
|
||||
|
||||
static char Chr;
|
||||
static char *FileStart;
|
||||
static char *FilePtr;
|
||||
static char *FileEnd;
|
||||
static qboolean SourceOpen;
|
||||
static char ASCIIToChrCode[256];
|
||||
static char TokenStringBuffer[MAX_QUOTED_LENGTH];
|
||||
static qboolean IncLineNumber;
|
||||
static char TempBuffer[2048];
|
||||
|
||||
static struct
|
||||
{
|
||||
char *name;
|
||||
tokenType_t token;
|
||||
} Keywords[] =
|
||||
{
|
||||
"model", TK_MODEL,
|
||||
"mesh", TK_MESH,
|
||||
"vertices", TK_VERTICES,
|
||||
"edges", TK_EDGES,
|
||||
"position", TK_POSITION,
|
||||
"polygons", TK_POLYGONS,
|
||||
"nodes", TK_NODES,
|
||||
"rotation", TK_ROTATION,
|
||||
"scaling", TK_SCALING,
|
||||
"translation", TK_TRANSLATION,
|
||||
"vertex", TK_VERTEX,
|
||||
"HRCH", TK_HRCH,
|
||||
"Softimage", TK_SOFTIMAGE,
|
||||
"material", TK_MATERIAL,
|
||||
"spline", TK_SPLINE,
|
||||
|
||||
"Named", TK_C_NAMED,
|
||||
"object", TK_OBJECT,
|
||||
"Tri", TK_C_TRI,
|
||||
"Vertices", TK_C_VERTICES,
|
||||
"Faces", TK_C_FACES,
|
||||
"Vertex", TK_C_VERTEX,
|
||||
"list", TK_LIST,
|
||||
"Face", TK_C_FACE,
|
||||
|
||||
"Hexen", TK_C_HEXEN,
|
||||
"Triangles", TK_C_TRIANGLES,
|
||||
"Version", TK_C_VERSION,
|
||||
"faces", TK_FACES,
|
||||
"face", TK_FACE,
|
||||
"origin", TK_ORIGIN,
|
||||
|
||||
"DK_clusters", TK_CLUSTERS,
|
||||
"DK_cluster_ncvs", TK_NUM_CLUSTER_VERTICES,
|
||||
"name", TK_NAME,
|
||||
"DK_cluster_name", TK_CLUSTER_NAME,
|
||||
"DK_cluster_state", TK_CLUSTER_STATE,
|
||||
|
||||
"actor_data", TK_ACTOR_DATA,
|
||||
"uvTexture", TK_UVTEXTURE,
|
||||
|
||||
NULL, -1
|
||||
};
|
||||
|
||||
static char *TokenNames[] =
|
||||
{
|
||||
"<nothing>",
|
||||
"<unknown_char>",
|
||||
"<EOF>",
|
||||
"<identifier>",
|
||||
"<string>",
|
||||
"<int_number>",
|
||||
"<float_number>",
|
||||
"(",
|
||||
")",
|
||||
"{",
|
||||
"}",
|
||||
"[",
|
||||
"]",
|
||||
":",
|
||||
"mesh",
|
||||
"model",
|
||||
"nodes",
|
||||
"rotation",
|
||||
"scaling",
|
||||
"translation",
|
||||
"polygons",
|
||||
"position",
|
||||
"vertex",
|
||||
"vertices",
|
||||
"HRCH",
|
||||
"Softimage"
|
||||
};
|
||||
|
||||
// CODE --------------------------------------------------------------------
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// TK_Init
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void TK_Init(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for(i = 0; i < 256; i++)
|
||||
{
|
||||
ASCIIToChrCode[i] = CHR_SPECIAL;
|
||||
}
|
||||
for(i = '0'; i <= '9'; i++)
|
||||
{
|
||||
ASCIIToChrCode[i] = CHR_NUMBER;
|
||||
}
|
||||
for(i = 'A'; i <= 'Z'; i++)
|
||||
{
|
||||
ASCIIToChrCode[i] = CHR_LETTER;
|
||||
}
|
||||
for(i = 'a'; i <= 'z'; i++)
|
||||
{
|
||||
ASCIIToChrCode[i] = CHR_LETTER;
|
||||
}
|
||||
ASCIIToChrCode[ASCII_QUOTE] = CHR_QUOTE;
|
||||
ASCIIToChrCode[ASCII_UNDERSCORE] = CHR_LETTER;
|
||||
ASCIIToChrCode[EOF_CHARACTER] = CHR_EOF;
|
||||
tk_String = TokenStringBuffer;
|
||||
IncLineNumber = FALSE;
|
||||
SourceOpen = FALSE;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// TK_OpenSource
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void TK_OpenSource(char *fileName)
|
||||
{
|
||||
int size;
|
||||
|
||||
TK_CloseSource();
|
||||
size = LoadFile(fileName, (void **)&FileStart);
|
||||
strcpy(tk_SourceName, fileName);
|
||||
SourceOpen = TRUE;
|
||||
FileEnd = FileStart+size;
|
||||
FilePtr = FileStart;
|
||||
tk_Line = 1;
|
||||
tk_Token = TK_NONE;
|
||||
NextChr();
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// TK_CloseSource
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void TK_CloseSource(void)
|
||||
{
|
||||
if(SourceOpen)
|
||||
{
|
||||
free(FileStart);
|
||||
SourceOpen = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// TK_Fetch
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
tokenType_t TK_Fetch(void)
|
||||
{
|
||||
while(Chr == ASCII_SPACE)
|
||||
{
|
||||
NextChr();
|
||||
}
|
||||
if(Chr == '-')
|
||||
{
|
||||
ProcessNumberToken();
|
||||
}
|
||||
else switch(ASCIIToChrCode[(byte)Chr])
|
||||
{
|
||||
case CHR_EOF:
|
||||
tk_Token = TK_EOF;
|
||||
break;
|
||||
case CHR_LETTER:
|
||||
ProcessLetterToken();
|
||||
break;
|
||||
case CHR_NUMBER:
|
||||
ProcessNumberToken();
|
||||
break;
|
||||
case CHR_QUOTE:
|
||||
ProcessQuoteToken();
|
||||
break;
|
||||
default:
|
||||
ProcessSpecialToken();
|
||||
break;
|
||||
}
|
||||
return tk_Token;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// TK_Require
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void TK_Require(tokenType_t tokType)
|
||||
{
|
||||
if(tokType == TK_FLOATNUMBER && tk_Token == TK_INTNUMBER)
|
||||
{
|
||||
tk_FloatNumber = (float)tk_IntNumber;
|
||||
tk_Token = TK_FLOATNUMBER;
|
||||
return;
|
||||
}
|
||||
if(tk_Token != tokType)
|
||||
{
|
||||
Error("File '%s', line %d:\nExpected '%s', found '%s'.\n",
|
||||
tk_SourceName, tk_Line, TokenNames[tokType],
|
||||
TokenNames[tk_Token]);
|
||||
}
|
||||
}
|
||||
|
||||
void TK_FetchRequire(tokenType_t tokType)
|
||||
{
|
||||
TK_Fetch();
|
||||
TK_Require(tokType);
|
||||
}
|
||||
|
||||
tokenType_t TK_RequireFetch(tokenType_t tokType)
|
||||
{
|
||||
TK_Require(tokType);
|
||||
return TK_Fetch();
|
||||
}
|
||||
|
||||
tokenType_t TK_FetchRequireFetch(tokenType_t tokType)
|
||||
{
|
||||
TK_Fetch();
|
||||
TK_Require(tokType);
|
||||
return TK_Fetch();
|
||||
}
|
||||
|
||||
tokenType_t TK_Beyond(tokenType_t tokType)
|
||||
{
|
||||
while(tk_Token != tokType)
|
||||
{
|
||||
if(TK_Fetch() == TK_EOF)
|
||||
{
|
||||
Error("File '%s':\nCould not find token '%s'.\n", // FIXME: TokenNames table not big enuff
|
||||
tk_SourceName, TokenNames[tokType]);
|
||||
}
|
||||
}
|
||||
return TK_Fetch();
|
||||
}
|
||||
|
||||
void TK_BeyondRequire(tokenType_t bTok, tokenType_t rTok)
|
||||
{
|
||||
TK_Beyond(bTok);
|
||||
TK_Require(rTok);
|
||||
}
|
||||
|
||||
tokenType_t TK_Search(tokenType_t tokType)
|
||||
{
|
||||
while(tk_Token != tokType)
|
||||
{
|
||||
if(TK_Fetch() == TK_EOF)
|
||||
{
|
||||
return TK_EOF;
|
||||
}
|
||||
}
|
||||
return TK_Fetch();
|
||||
}
|
||||
|
||||
tokenType_t TK_Get(tokenType_t tokType)
|
||||
{
|
||||
while(tk_Token != tokType)
|
||||
{
|
||||
if(TK_Fetch() == TK_EOF)
|
||||
{
|
||||
Error("File '%s':\nCould not find token '%s'.\n",
|
||||
tk_SourceName, TokenNames[tokType]);
|
||||
}
|
||||
}
|
||||
return tk_Token;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// ProcessLetterToken
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
static void ProcessLetterToken(void)
|
||||
{
|
||||
int i;
|
||||
char *text;
|
||||
|
||||
i = 0;
|
||||
text = TokenStringBuffer;
|
||||
while(ASCIIToChrCode[(byte)Chr] == CHR_LETTER
|
||||
|| ASCIIToChrCode[(byte)Chr] == CHR_NUMBER)
|
||||
{
|
||||
if(++i == MAX_IDENTIFIER_LENGTH)
|
||||
{
|
||||
Error("File '%s', line %d:\nIdentifier too long.\n",
|
||||
tk_SourceName, tk_Line);
|
||||
}
|
||||
*text++ = Chr;
|
||||
NextChr();
|
||||
}
|
||||
*text = 0;
|
||||
if(CheckForKeyword() == FALSE)
|
||||
{
|
||||
tk_Token = TK_IDENTIFIER;
|
||||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// CheckForKeyword
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
static qboolean CheckForKeyword(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for(i = 0; Keywords[i].name != NULL; i++)
|
||||
{
|
||||
if(strcmp(tk_String, Keywords[i].name) == 0)
|
||||
{
|
||||
tk_Token = Keywords[i].token;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// ProcessNumberToken
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
static void ProcessNumberToken(void)
|
||||
{
|
||||
char *buffer;
|
||||
|
||||
buffer = TempBuffer;
|
||||
*buffer++ = Chr;
|
||||
NextChr();
|
||||
while(ASCIIToChrCode[(byte)Chr] == CHR_NUMBER)
|
||||
{
|
||||
*buffer++ = Chr;
|
||||
NextChr();
|
||||
}
|
||||
if(Chr == '.')
|
||||
{ // Float
|
||||
*buffer++ = Chr;
|
||||
NextChr(); // Skip period
|
||||
while(ASCIIToChrCode[(byte)Chr] == CHR_NUMBER)
|
||||
{
|
||||
*buffer++ = Chr;
|
||||
NextChr();
|
||||
}
|
||||
*buffer = 0;
|
||||
tk_FloatNumber = (float)atof(TempBuffer);
|
||||
tk_Token = TK_FLOATNUMBER;
|
||||
return;
|
||||
}
|
||||
|
||||
// Integer
|
||||
*buffer = 0;
|
||||
tk_IntNumber = atoi(TempBuffer);
|
||||
tk_Token = TK_INTNUMBER;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// ProcessQuoteToken
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
static void ProcessQuoteToken(void)
|
||||
{
|
||||
int i;
|
||||
char *text;
|
||||
|
||||
i = 0;
|
||||
text = TokenStringBuffer;
|
||||
NextChr();
|
||||
while(Chr != ASCII_QUOTE)
|
||||
{
|
||||
if(Chr == EOF_CHARACTER)
|
||||
{
|
||||
Error("File '%s', line %d:\n<EOF> inside string.\n",
|
||||
tk_SourceName, tk_Line);
|
||||
}
|
||||
if(++i > MAX_QUOTED_LENGTH-1)
|
||||
{
|
||||
Error("File '%s', line %d:\nString literal too long.\n",
|
||||
tk_SourceName, tk_Line);
|
||||
}
|
||||
*text++ = Chr;
|
||||
NextChr();
|
||||
}
|
||||
*text = 0;
|
||||
NextChr();
|
||||
tk_Token = TK_STRING;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// ProcessSpecialToken
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
static void ProcessSpecialToken(void)
|
||||
{
|
||||
char c;
|
||||
|
||||
c = Chr;
|
||||
NextChr();
|
||||
switch(c)
|
||||
{
|
||||
case '(':
|
||||
tk_Token = TK_LPAREN;
|
||||
break;
|
||||
case ')':
|
||||
tk_Token = TK_RPAREN;
|
||||
break;
|
||||
case '{':
|
||||
tk_Token = TK_LBRACE;
|
||||
break;
|
||||
case '}':
|
||||
tk_Token = TK_RBRACE;
|
||||
break;
|
||||
case '[':
|
||||
tk_Token = TK_LBRACKET;
|
||||
break;
|
||||
case ']':
|
||||
tk_Token = TK_RBRACKET;
|
||||
break;
|
||||
case ':':
|
||||
tk_Token = TK_COLON;
|
||||
break;
|
||||
default:
|
||||
tk_Token = TK_UNKNOWNCHAR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// NextChr
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
static void NextChr(void)
|
||||
{
|
||||
if(FilePtr >= FileEnd)
|
||||
{
|
||||
Chr = EOF_CHARACTER;
|
||||
return;
|
||||
}
|
||||
if(IncLineNumber == TRUE)
|
||||
{
|
||||
tk_Line++;
|
||||
IncLineNumber = FALSE;
|
||||
}
|
||||
Chr = *FilePtr++;
|
||||
if(Chr < ASCII_SPACE)
|
||||
{
|
||||
if(Chr == '\n')
|
||||
{
|
||||
IncLineNumber = TRUE;
|
||||
}
|
||||
Chr = ASCII_SPACE;
|
||||
}
|
||||
}
|
||||
132
tools/quake2/qdata_heretic2/common/token.h
Normal file
132
tools/quake2/qdata_heretic2/common/token.h
Normal file
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
|
||||
//**************************************************************************
|
||||
//**
|
||||
//** token.h
|
||||
//**
|
||||
//**************************************************************************
|
||||
|
||||
#ifndef __TOKEN_H__
|
||||
#define __TOKEN_H__
|
||||
|
||||
#include "cmdlib.h"
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
#ifndef YES
|
||||
#define YES 1
|
||||
#endif
|
||||
#ifndef NO
|
||||
#define NO 0
|
||||
#endif
|
||||
#define ASCII_SPACE 32
|
||||
#define ASCII_QUOTE 34
|
||||
#define ASCII_UNDERSCORE 95
|
||||
#define EOF_CHARACTER 127
|
||||
#define MAX_IDENTIFIER_LENGTH 64
|
||||
#define MAX_QUOTED_LENGTH 1024
|
||||
#define MAX_FILE_NAME_LENGTH 1024
|
||||
|
||||
typedef enum
|
||||
{
|
||||
TK_NONE,
|
||||
TK_UNKNOWNCHAR,
|
||||
TK_EOF,
|
||||
TK_IDENTIFIER, // VALUE: (char *) tk_String
|
||||
TK_STRING, // VALUE: (char *) tk_String
|
||||
TK_INTNUMBER, // VALUE: (int) tk_IntNumber
|
||||
TK_FLOATNUMBER, // VALUE: (float) tk_FloatNumber
|
||||
TK_LPAREN,
|
||||
TK_RPAREN,
|
||||
TK_LBRACE,
|
||||
TK_RBRACE, // 10
|
||||
TK_LBRACKET,
|
||||
TK_RBRACKET,
|
||||
TK_COLON,
|
||||
TK_MESH,
|
||||
TK_MODEL, // 15
|
||||
TK_NODES,
|
||||
TK_ROTATION,
|
||||
TK_SCALING,
|
||||
TK_TRANSLATION,
|
||||
TK_POLYGONS, // 20
|
||||
TK_POSITION,
|
||||
TK_VERTEX,
|
||||
TK_VERTICES,
|
||||
TK_EDGES,
|
||||
TK_HRCH, // 25
|
||||
TK_SOFTIMAGE,
|
||||
TK_MATERIAL,
|
||||
TK_SPLINE, // 28
|
||||
|
||||
TK_C_NAMED,
|
||||
TK_OBJECT, // 30
|
||||
TK_C_TRI,
|
||||
TK_C_VERTICES,
|
||||
TK_C_FACES,
|
||||
TK_C_VERTEX,
|
||||
TK_LIST, // 35
|
||||
TK_C_FACE,
|
||||
|
||||
TK_C_HEXEN,
|
||||
TK_C_TRIANGLES,
|
||||
TK_C_VERSION,
|
||||
TK_FACES, // 40
|
||||
TK_FACE,
|
||||
TK_ORIGIN,
|
||||
|
||||
TK_CLUSTERS,
|
||||
TK_NUM_CLUSTER_VERTICES,
|
||||
TK_NAME, // 45
|
||||
TK_CLUSTER_NAME,
|
||||
TK_CLUSTER_STATE,
|
||||
|
||||
TK_ACTOR_DATA,
|
||||
TK_UVTEXTURE,
|
||||
} tokenType_t;
|
||||
|
||||
void TK_Init(void);
|
||||
void TK_OpenSource(char *fileName);
|
||||
void TK_CloseSource(void);
|
||||
tokenType_t TK_Fetch(void);
|
||||
void TK_Require(tokenType_t tokType);
|
||||
void TK_FetchRequire(tokenType_t tokType);
|
||||
tokenType_t TK_RequireFetch(tokenType_t tokType);
|
||||
tokenType_t TK_FetchRequireFetch(tokenType_t tokType);
|
||||
tokenType_t TK_Beyond(tokenType_t tokType);
|
||||
void TK_BeyondRequire(tokenType_t bTok, tokenType_t rTok);
|
||||
tokenType_t TK_Search(tokenType_t tokType);
|
||||
tokenType_t TK_Get(tokenType_t tokType);
|
||||
|
||||
extern tokenType_t tk_Token;
|
||||
extern int tk_Line;
|
||||
extern int tk_IntNumber;
|
||||
extern float tk_FloatNumber;
|
||||
extern char *tk_String;
|
||||
extern char tk_SourceName[MAX_FILE_NAME_LENGTH];
|
||||
|
||||
#endif
|
||||
1077
tools/quake2/qdata_heretic2/common/trilib.c
Normal file
1077
tools/quake2/qdata_heretic2/common/trilib.c
Normal file
File diff suppressed because it is too large
Load Diff
56
tools/quake2/qdata_heretic2/common/trilib.h
Normal file
56
tools/quake2/qdata_heretic2/common/trilib.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
//
|
||||
// trilib.h: header file for loading triangles from an Alias triangle file
|
||||
//
|
||||
|
||||
#include "fmodel.h"
|
||||
|
||||
#define MAXTRIANGLES MAX_FM_TRIANGLES
|
||||
|
||||
typedef struct
|
||||
{
|
||||
vec3_t verts[3];
|
||||
#if 1
|
||||
int indicies[3];
|
||||
float uv[3][2];
|
||||
qboolean HasUV;
|
||||
#endif
|
||||
} triangle_t;
|
||||
|
||||
#define NUM_CLUSTERS 8
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char name[64];
|
||||
byte tris[MAXTRIANGLES>>3];
|
||||
byte verts[MAX_FM_VERTS>>3];
|
||||
int start_glcmds, num_glcmds;
|
||||
|
||||
int *clusters[NUM_CLUSTERS];
|
||||
struct IntListNode_s *vertLists[NUM_CLUSTERS];
|
||||
int num_verts[NUM_CLUSTERS + 1];
|
||||
int new_num_verts[NUM_CLUSTERS + 1];
|
||||
qboolean clustered;
|
||||
} mesh_node_t;
|
||||
|
||||
void LoadTriangleList (char *filename, triangle_t **pptri, int *numtriangles, mesh_node_t **ppmnodes, int *num_mesh_nodes);
|
||||
3404
tools/quake2/qdata_heretic2/fmodels.c
Normal file
3404
tools/quake2/qdata_heretic2/fmodels.c
Normal file
File diff suppressed because it is too large
Load Diff
BIN
tools/quake2/qdata_heretic2/icon1.ico
Normal file
BIN
tools/quake2/qdata_heretic2/icon1.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 766 B |
1397
tools/quake2/qdata_heretic2/images.c
Normal file
1397
tools/quake2/qdata_heretic2/images.c
Normal file
File diff suppressed because it is too large
Load Diff
572
tools/quake2/qdata_heretic2/jointed.c
Normal file
572
tools/quake2/qdata_heretic2/jointed.c
Normal file
@@ -0,0 +1,572 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include "token.h"
|
||||
#include "joints.h"
|
||||
#include "angles.h"
|
||||
#include "inout.h"
|
||||
|
||||
char *SKEL_ROOT_NAMES[] =
|
||||
{
|
||||
"RAVEN_SPINE"
|
||||
};
|
||||
|
||||
char *SKEL_NAMES[] =
|
||||
{
|
||||
"RAVEN_WAIST1",
|
||||
"RAVEN_WAIST2",
|
||||
"RAVEN_NECK"
|
||||
};
|
||||
|
||||
int NAME_OFFSETS[] =
|
||||
{
|
||||
0
|
||||
};
|
||||
|
||||
int numJointsForSkeleton[] =
|
||||
{
|
||||
NUM_JOINTS_RAVEN,
|
||||
NUM_JOINTS_BOX
|
||||
};
|
||||
|
||||
float g_scaling[3];
|
||||
float g_rotation[3];
|
||||
float g_translation[3];
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// LoadHRCClustered
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
static void LoadHRCClustered(char *fileName, int **clusterList, int *num_verts, int skelType)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
TK_OpenSource(fileName);
|
||||
TK_FetchRequire(TK_HRCH);
|
||||
TK_FetchRequire(TK_COLON);
|
||||
TK_FetchRequire(TK_SOFTIMAGE);
|
||||
|
||||
TK_Beyond(TK_CLUSTERS);
|
||||
|
||||
while(TK_Search(TK_CLUSTER_NAME) != TK_EOF)
|
||||
{
|
||||
TK_Require(TK_STRING);
|
||||
|
||||
for( i = 0; i < numJointsForSkeleton[skelType]; ++i)
|
||||
{
|
||||
if(stricmp(tk_String, SKEL_NAMES[NAME_OFFSETS[skelType]+i]) == 0)
|
||||
{
|
||||
i = -i + numJointsForSkeleton[skelType] - 1;
|
||||
|
||||
TK_BeyondRequire(TK_NUM_CLUSTER_VERTICES, TK_INTNUMBER);
|
||||
|
||||
num_verts[i+1] = tk_IntNumber;
|
||||
|
||||
clusterList[i] = (int *) SafeMalloc(num_verts[i+1]*sizeof(int), "LoadHRCClustered");
|
||||
assert(clusterList[i]);
|
||||
// currently this function is only called by LoadTriangleListClustered, which in turn is only
|
||||
// called by Cmd_Base in qdata. This is where the only call to free for this memory is being made.
|
||||
|
||||
TK_Beyond(TK_LBRACE);
|
||||
|
||||
for(j = 0; j < num_verts[i+1]; ++j)
|
||||
{
|
||||
TK_Require(TK_INTNUMBER);
|
||||
clusterList[i][j] = tk_IntNumber;
|
||||
TK_Fetch();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
num_verts[0] = numJointsForSkeleton[skelType];
|
||||
}
|
||||
|
||||
static void LoadHRCGlobals(char *fileName)
|
||||
{
|
||||
int i;
|
||||
|
||||
TK_OpenSource(fileName);
|
||||
TK_FetchRequire(TK_HRCH);
|
||||
TK_FetchRequire(TK_COLON);
|
||||
TK_FetchRequire(TK_SOFTIMAGE);
|
||||
TK_Beyond(TK_MODEL);
|
||||
|
||||
TK_Beyond(TK_SCALING);
|
||||
for(i = 0; i < 3; i++)
|
||||
{
|
||||
TK_Require(TK_FLOATNUMBER);
|
||||
g_scaling[i] = tk_FloatNumber;
|
||||
TK_Fetch();
|
||||
}
|
||||
|
||||
TK_Beyond(TK_ROTATION);
|
||||
for(i = 0; i < 3; i++)
|
||||
{
|
||||
TK_Require(TK_FLOATNUMBER);
|
||||
g_rotation[i] = tk_FloatNumber;
|
||||
TK_Fetch();
|
||||
}
|
||||
|
||||
TK_Beyond(TK_TRANSLATION);
|
||||
for(i = 0; i < 3; i++)
|
||||
{
|
||||
TK_Require(TK_FLOATNUMBER);
|
||||
g_translation[i] = tk_FloatNumber;
|
||||
TK_Fetch();
|
||||
}
|
||||
}
|
||||
|
||||
static void ParseVec3(vec3_t in)
|
||||
{
|
||||
TK_Require(TK_FLOATNUMBER);
|
||||
in[1] = tk_FloatNumber;
|
||||
TK_FetchRequire(TK_FLOATNUMBER);
|
||||
in[2] = tk_FloatNumber;
|
||||
TK_FetchRequire(TK_FLOATNUMBER);
|
||||
in[0] = tk_FloatNumber;
|
||||
}
|
||||
|
||||
static void ParseRotation3(vec3_t in)
|
||||
{
|
||||
TK_Require(TK_FLOATNUMBER);
|
||||
in[1] = -tk_FloatNumber;
|
||||
TK_FetchRequire(TK_FLOATNUMBER);
|
||||
in[2] = tk_FloatNumber;
|
||||
TK_FetchRequire(TK_FLOATNUMBER);
|
||||
in[0] = tk_FloatNumber;
|
||||
}
|
||||
|
||||
static void ParseTranslation3(vec3_t in)
|
||||
{
|
||||
TK_Require(TK_FLOATNUMBER);
|
||||
in[1] = tk_FloatNumber;
|
||||
TK_FetchRequire(TK_FLOATNUMBER);
|
||||
in[2] = tk_FloatNumber;
|
||||
TK_FetchRequire(TK_FLOATNUMBER);
|
||||
in[0] = tk_FloatNumber;
|
||||
}
|
||||
|
||||
static void LoadHRCJointList(char *fileName, QDataJoint_t *jointList, int skelType)
|
||||
{
|
||||
#define MAX_STACK 64
|
||||
int i, j;
|
||||
vec3_t curTranslation[MAX_STACK], curRotation[MAX_STACK], curScale[MAX_STACK];
|
||||
int curCorrespondingJoint[MAX_STACK];
|
||||
int currentStack = 0, stackSize;
|
||||
int baseJoint;
|
||||
float cx, sx, cy, sy, cz, sz;
|
||||
float rx, ry, rz;
|
||||
float x2, y2, z2;
|
||||
|
||||
|
||||
TK_OpenSource(fileName);
|
||||
TK_FetchRequire(TK_HRCH);
|
||||
TK_FetchRequire(TK_COLON);
|
||||
TK_FetchRequire(TK_SOFTIMAGE);
|
||||
|
||||
TK_Beyond(TK_MODEL);
|
||||
TK_Beyond(TK_MODEL);
|
||||
|
||||
/* while(1)
|
||||
{
|
||||
TK_Beyond(TK_MODEL);
|
||||
TK_BeyondRequire(TK_NAME, TK_STRING);
|
||||
|
||||
if(_stricmp(tk_String, SKEL_ROOT_NAMES[skelType]) == 0)
|
||||
break;
|
||||
}*/
|
||||
|
||||
TK_Beyond(TK_SCALING);
|
||||
|
||||
ParseVec3(curScale[currentStack]);
|
||||
|
||||
TK_Beyond(TK_ROTATION);
|
||||
|
||||
ParseRotation3(curRotation[currentStack]);
|
||||
|
||||
TK_Beyond(TK_TRANSLATION);
|
||||
|
||||
ParseVec3(curTranslation[currentStack]);
|
||||
|
||||
// account for global model translation
|
||||
curTranslation[currentStack][1] += g_translation[0];
|
||||
curTranslation[currentStack][2] += g_translation[1];
|
||||
curTranslation[currentStack][0] += g_translation[2];
|
||||
|
||||
++currentStack;
|
||||
|
||||
for(i = 0; i < NUM_JOINTS_RAVEN; ++i)
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
TK_Beyond(TK_MODEL);
|
||||
|
||||
// TK_BeyondRequire(TK_NAME, TK_STRING);
|
||||
|
||||
// if(_stricmp(tk_String, SKEL_NAMES[NAME_OFFSETS[skelType]+i]) == 0)
|
||||
break;
|
||||
|
||||
TK_Beyond(TK_SCALING);
|
||||
|
||||
ParseVec3(curScale[currentStack]);
|
||||
|
||||
TK_Beyond(TK_ROTATION);
|
||||
|
||||
ParseRotation3(curRotation[currentStack]);
|
||||
|
||||
TK_Beyond(TK_TRANSLATION);
|
||||
|
||||
ParseVec3(curTranslation[currentStack]);
|
||||
|
||||
curCorrespondingJoint[currentStack] = -1;
|
||||
|
||||
++currentStack;
|
||||
}
|
||||
|
||||
TK_Beyond(TK_SCALING);
|
||||
|
||||
ParseVec3(curScale[currentStack]);
|
||||
|
||||
TK_Beyond(TK_ROTATION);
|
||||
|
||||
ParseRotation3(curRotation[currentStack]);
|
||||
|
||||
jointList[i].rotation[1] = curRotation[currentStack][1];
|
||||
jointList[i].rotation[2] = curRotation[currentStack][2];
|
||||
jointList[i].rotation[0] = curRotation[currentStack][0];
|
||||
|
||||
TK_Beyond(TK_TRANSLATION);
|
||||
|
||||
ParseVec3(curTranslation[currentStack]);
|
||||
|
||||
jointList[i].placement.origin[1] = curTranslation[currentStack][1];
|
||||
jointList[i].placement.origin[2] = curTranslation[currentStack][2];
|
||||
jointList[i].placement.origin[0] = curTranslation[currentStack][0];
|
||||
|
||||
jointList[i].placement.direction[1] = 7.5;
|
||||
jointList[i].placement.direction[2] = 0.0;
|
||||
jointList[i].placement.direction[0] = 0.0;
|
||||
|
||||
jointList[i].placement.up[1] = 0.0;
|
||||
jointList[i].placement.up[2] = 7.5;
|
||||
jointList[i].placement.up[0] = 0.0;
|
||||
|
||||
curCorrespondingJoint[currentStack] = i;
|
||||
|
||||
++currentStack;
|
||||
}
|
||||
|
||||
stackSize = currentStack;
|
||||
|
||||
for(i = 0; i < NUM_JOINTS_RAVEN; ++i)
|
||||
{
|
||||
rx = jointList[i].rotation[0]*ANGLE_TO_RAD;
|
||||
ry = jointList[i].rotation[1]*ANGLE_TO_RAD;
|
||||
rz = jointList[i].rotation[2]*ANGLE_TO_RAD;
|
||||
|
||||
cx = cos(rx);
|
||||
sx = sin(rx);
|
||||
|
||||
cy = cos(ry);
|
||||
sy = sin(ry);
|
||||
|
||||
cz = cos(rz);
|
||||
sz = sin(rz);
|
||||
|
||||
// y-axis rotation for direction
|
||||
x2 = jointList[i].placement.direction[0]*cy+jointList[i].placement.direction[2]*sy;
|
||||
z2 = -jointList[i].placement.direction[0]*sy+jointList[i].placement.direction[2]*cy;
|
||||
jointList[i].placement.direction[0] = x2;
|
||||
jointList[i].placement.direction[2] = z2;
|
||||
|
||||
// y-axis rotation for up
|
||||
x2 = jointList[i].placement.up[0]*cy+jointList[i].placement.up[2]*sy;
|
||||
z2 = -jointList[i].placement.up[0]*sy+jointList[i].placement.up[2]*cy;
|
||||
jointList[i].placement.up[0] = x2;
|
||||
jointList[i].placement.up[2] = z2;
|
||||
|
||||
// z-axis rotation for direction
|
||||
x2 = jointList[i].placement.direction[0]*cz-jointList[i].placement.direction[1]*sz;
|
||||
y2 = jointList[i].placement.direction[0]*sz+jointList[i].placement.direction[1]*cz;
|
||||
jointList[i].placement.direction[0] = x2;
|
||||
jointList[i].placement.direction[1] = y2;
|
||||
|
||||
// z-axis rotation for up
|
||||
x2 = jointList[i].placement.up[0]*cz-jointList[i].placement.up[1]*sz;
|
||||
y2 = jointList[i].placement.up[0]*sz+jointList[i].placement.up[1]*cz;
|
||||
jointList[i].placement.up[0] = x2;
|
||||
jointList[i].placement.up[1] = y2;
|
||||
|
||||
// x-axis rotation for direction vector
|
||||
y2 = jointList[i].placement.direction[1]*cx-jointList[i].placement.direction[2]*sx;
|
||||
z2 = jointList[i].placement.direction[1]*sx+jointList[i].placement.direction[2]*cx;
|
||||
jointList[i].placement.direction[1] = y2;
|
||||
jointList[i].placement.direction[2] = z2;
|
||||
|
||||
// x-axis rotation for up vector
|
||||
y2 = jointList[i].placement.up[1]*cx-jointList[i].placement.up[2]*sx;
|
||||
z2 = jointList[i].placement.up[1]*sx+jointList[i].placement.up[2]*cx;
|
||||
jointList[i].placement.up[1] = y2;
|
||||
jointList[i].placement.up[2] = z2;
|
||||
|
||||
// translate to position in model
|
||||
jointList[i].placement.direction[0] += jointList[i].placement.origin[0];
|
||||
jointList[i].placement.direction[1] += jointList[i].placement.origin[1];
|
||||
jointList[i].placement.direction[2] += jointList[i].placement.origin[2];
|
||||
|
||||
// translate to position in model
|
||||
jointList[i].placement.up[0] += jointList[i].placement.origin[0];
|
||||
jointList[i].placement.up[1] += jointList[i].placement.origin[1];
|
||||
jointList[i].placement.up[2] += jointList[i].placement.origin[2];
|
||||
}
|
||||
|
||||
baseJoint = NUM_JOINTS_RAVEN;
|
||||
|
||||
for(i = stackSize/*NUM_JOINTS_RAVEN*/ - 1; i > 0; --i)
|
||||
{
|
||||
|
||||
rx = curRotation[i-1][0]*ANGLE_TO_RAD;
|
||||
ry = curRotation[i-1][1]*ANGLE_TO_RAD;
|
||||
rz = curRotation[i-1][2]*ANGLE_TO_RAD;
|
||||
|
||||
cx = cos(rx);
|
||||
sx = sin(rx);
|
||||
|
||||
cy = cos(ry);
|
||||
sy = sin(ry);
|
||||
|
||||
cz = cos(rz);
|
||||
sz = sin(rz);
|
||||
|
||||
for(j = i-1; j < stackSize-1; ++j)
|
||||
{
|
||||
// y-axis rotation for origin
|
||||
x2 = jointList[j].placement.origin[0]*cy+jointList[j].placement.origin[2]*sy;
|
||||
z2 = -jointList[j].placement.origin[0]*sy+jointList[j].placement.origin[2]*cy;
|
||||
jointList[j].placement.origin[0] = x2;
|
||||
jointList[j].placement.origin[2] = z2;
|
||||
|
||||
// y-axis rotation for direction
|
||||
x2 = jointList[j].placement.direction[0]*cy+jointList[j].placement.direction[2]*sy;
|
||||
z2 = -jointList[j].placement.direction[0]*sy+jointList[j].placement.direction[2]*cy;
|
||||
jointList[j].placement.direction[0] = x2;
|
||||
jointList[j].placement.direction[2] = z2;
|
||||
|
||||
// y-axis rotation for up
|
||||
x2 = jointList[j].placement.up[0]*cy+jointList[j].placement.up[2]*sy;
|
||||
z2 = -jointList[j].placement.up[0]*sy+jointList[j].placement.up[2]*cy;
|
||||
jointList[j].placement.up[0] = x2;
|
||||
jointList[j].placement.up[2] = z2;
|
||||
|
||||
// z-axis rotation for origin
|
||||
x2 = jointList[j].placement.origin[0]*cz-jointList[j].placement.origin[1]*sz;
|
||||
y2 = jointList[j].placement.origin[0]*sz+jointList[j].placement.origin[1]*cz;
|
||||
jointList[j].placement.origin[0] = x2;
|
||||
jointList[j].placement.origin[1] = y2;
|
||||
|
||||
// z-axis rotation for direction
|
||||
x2 = jointList[j].placement.direction[0]*cz-jointList[j].placement.direction[1]*sz;
|
||||
y2 = jointList[j].placement.direction[0]*sz+jointList[j].placement.direction[1]*cz;
|
||||
jointList[j].placement.direction[0] = x2;
|
||||
jointList[j].placement.direction[1] = y2;
|
||||
|
||||
// z-axis rotation for up
|
||||
x2 = jointList[j].placement.up[0]*cz-jointList[j].placement.up[1]*sz;
|
||||
y2 = jointList[j].placement.up[0]*sz+jointList[j].placement.up[1]*cz;
|
||||
jointList[j].placement.up[0] = x2;
|
||||
jointList[j].placement.up[1] = y2;
|
||||
|
||||
// x-axis rotation for origin
|
||||
y2 = jointList[j].placement.origin[1]*cx-jointList[j].placement.origin[2]*sx;
|
||||
z2 = jointList[j].placement.origin[1]*sx+jointList[j].placement.origin[2]*cx;
|
||||
jointList[j].placement.origin[1] = y2;
|
||||
jointList[j].placement.origin[2] = z2;
|
||||
|
||||
// x-axis rotation for direction vector
|
||||
y2 = jointList[j].placement.direction[1]*cx-jointList[j].placement.direction[2]*sx;
|
||||
z2 = jointList[j].placement.direction[1]*sx+jointList[j].placement.direction[2]*cx;
|
||||
jointList[j].placement.direction[1] = y2;
|
||||
jointList[j].placement.direction[2] = z2;
|
||||
|
||||
// x-axis rotation for up vector
|
||||
y2 = jointList[j].placement.up[1]*cx-jointList[j].placement.up[2]*sx;
|
||||
z2 = jointList[j].placement.up[1]*sx+jointList[j].placement.up[2]*cx;
|
||||
jointList[j].placement.up[1] = y2;
|
||||
jointList[j].placement.up[2] = z2;
|
||||
|
||||
if(curCorrespondingJoint[j+1] != -1)
|
||||
{
|
||||
// translate origin
|
||||
jointList[j].placement.origin[0] += curTranslation[i-1][0];
|
||||
jointList[j].placement.origin[1] += curTranslation[i-1][1];
|
||||
jointList[j].placement.origin[2] += curTranslation[i-1][2];
|
||||
|
||||
// translate back to local coord
|
||||
jointList[j].placement.direction[0] += curTranslation[i-1][0];
|
||||
jointList[j].placement.direction[1] += curTranslation[i-1][1];
|
||||
jointList[j].placement.direction[2] += curTranslation[i-1][2];
|
||||
|
||||
// translate back to local coord
|
||||
jointList[j].placement.up[0] += curTranslation[i-1][0];
|
||||
jointList[j].placement.up[1] += curTranslation[i-1][1];
|
||||
jointList[j].placement.up[2] += curTranslation[i-1][2];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LoadGlobals(char *fileName)
|
||||
{
|
||||
FILE *file1;
|
||||
int dot = '.';
|
||||
char *dotstart;
|
||||
char InputFileName[256];
|
||||
|
||||
dotstart = strrchr(fileName,dot); // Does it already have an extension on the file name?
|
||||
|
||||
if (!dotstart)
|
||||
{
|
||||
strcpy(InputFileName, fileName);
|
||||
strcat(InputFileName, ".hrc");
|
||||
if((file1 = fopen(InputFileName, "rb")) != NULL)
|
||||
{
|
||||
fclose(file1);
|
||||
|
||||
LoadHRCGlobals(InputFileName);
|
||||
|
||||
printf(" - assuming .HRC\n");
|
||||
return;
|
||||
}
|
||||
|
||||
Error("\n Could not open file '%s':\n"
|
||||
"No HRC match.\n", fileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
if((file1 = fopen(fileName, "rb")) != NULL)
|
||||
{
|
||||
printf("\n");
|
||||
fclose(file1);
|
||||
if (strcmp(dotstart,".hrc") == 0 || strcmp(dotstart,".HRC") == 0)
|
||||
{
|
||||
LoadHRCGlobals(fileName);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Error("Could not open file '%s':\n",fileName);
|
||||
}
|
||||
}
|
||||
|
||||
void LoadClusters(char *fileName, int **clusterList, int *num_verts, int skelType)
|
||||
{
|
||||
FILE *file1;
|
||||
int dot = '.';
|
||||
char *dotstart;
|
||||
char InputFileName[256];
|
||||
|
||||
dotstart = strrchr(fileName,dot); // Does it already have an extension on the file name?
|
||||
|
||||
if (!dotstart)
|
||||
{
|
||||
strcpy(InputFileName, fileName);
|
||||
strcat(InputFileName, ".hrc");
|
||||
if((file1 = fopen(InputFileName, "rb")) != NULL)
|
||||
{
|
||||
fclose(file1);
|
||||
|
||||
LoadHRCClustered(InputFileName, clusterList, num_verts, skelType);
|
||||
|
||||
printf(" - assuming .HRC\n");
|
||||
return;
|
||||
}
|
||||
|
||||
Error("\n Could not open file '%s':\n"
|
||||
"No HRC match.\n", fileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
if((file1 = fopen(fileName, "rb")) != NULL)
|
||||
{
|
||||
printf("\n");
|
||||
fclose(file1);
|
||||
if (strcmp(dotstart,".hrc") == 0 || strcmp(dotstart,".HRC") == 0)
|
||||
{
|
||||
LoadHRCClustered(fileName, clusterList, num_verts, skelType);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Error("Could not open file '%s':\n",fileName);
|
||||
}
|
||||
}
|
||||
|
||||
void LoadJointList(char *fileName, QDataJoint_t *jointList, int skelType)
|
||||
{
|
||||
FILE *file1;
|
||||
int dot = '.';
|
||||
char *dotstart;
|
||||
char InputFileName[256];
|
||||
|
||||
dotstart = strrchr(fileName,dot); // Does it already have an extension on the file name?
|
||||
|
||||
if (!dotstart)
|
||||
{
|
||||
strcpy(InputFileName, fileName);
|
||||
strcat(InputFileName, ".hrc");
|
||||
if((file1 = fopen(InputFileName, "rb")) != NULL)
|
||||
{
|
||||
fclose(file1);
|
||||
|
||||
LoadHRCJointList(InputFileName, jointList, skelType);
|
||||
|
||||
printf(" - assuming .HRC\n");
|
||||
return;
|
||||
}
|
||||
|
||||
Error("\n Could not open file '%s':\n"
|
||||
"No HRC.\n", fileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
if((file1 = fopen(fileName, "rb")) != NULL)
|
||||
{
|
||||
printf("\n");
|
||||
fclose(file1);
|
||||
if (strcmp(dotstart,".hrc") == 0 || strcmp(dotstart,".HRC") == 0)
|
||||
{
|
||||
LoadHRCJointList(fileName, jointList, skelType);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Error("Could not open file '%s':\n",fileName);
|
||||
}
|
||||
}
|
||||
|
||||
35
tools/quake2/qdata_heretic2/jointed.h
Normal file
35
tools/quake2/qdata_heretic2/jointed.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef _JOINTED_H
|
||||
#define _JOINTED_H
|
||||
|
||||
#include "joints.h"
|
||||
|
||||
void LoadGlobals(char *fileName);
|
||||
void LoadClusters(char *fileName, int **clusterList, int *num_verts, int skel_type);
|
||||
void LoadJointList(char *fileName, struct QDataJoint_s *jointList, int num_verts);
|
||||
|
||||
#define NUM_CLUSTERS 8
|
||||
|
||||
#define NOT_JOINTED -1
|
||||
|
||||
#endif //_JOINTED_H
|
||||
144
tools/quake2/qdata_heretic2/joints.h
Normal file
144
tools/quake2/qdata_heretic2/joints.h
Normal file
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef JOINTS_H
|
||||
#define JOINTS_H
|
||||
|
||||
#ifdef _HERETIC2_
|
||||
#include "angles.h"
|
||||
#endif
|
||||
|
||||
//typedef float vec3_t[3];
|
||||
//typedef unsigned char byte;
|
||||
|
||||
#ifndef _WIN32
|
||||
#define stricmp strcasecmp
|
||||
#define strcmpi strcasecmp
|
||||
#endif
|
||||
|
||||
typedef struct Placement_s
|
||||
{
|
||||
vec3_t origin;
|
||||
vec3_t direction;
|
||||
vec3_t up;
|
||||
} Placement_t;
|
||||
|
||||
#if 1
|
||||
typedef struct QDataJoint_s
|
||||
{
|
||||
Placement_t placement;
|
||||
vec3_t rotation;
|
||||
} QDataJoint_t;
|
||||
#endif
|
||||
|
||||
typedef struct ArrayedListNode_s
|
||||
{
|
||||
int data;
|
||||
int next;
|
||||
int inUse;
|
||||
} ArrayedListNode_t;
|
||||
|
||||
#define ARRAYEDLISTNODE_NULL -1
|
||||
|
||||
typedef struct JointAngles_s
|
||||
{
|
||||
float angles[3];
|
||||
int children;
|
||||
int created;
|
||||
} JointAngles_t;
|
||||
|
||||
typedef struct JointAngles2_s
|
||||
{
|
||||
float angles[3];
|
||||
int children;
|
||||
int changed[3];
|
||||
int inUse;
|
||||
} JointAngles2_t;
|
||||
|
||||
#define MAX_MODELJOINTS 256
|
||||
#define MAX_MODELJOINTNODES 255
|
||||
|
||||
extern JointAngles_t jointAngles[MAX_MODELJOINTS];
|
||||
extern JointAngles2_t jointAngles2[MAX_MODELJOINTS];
|
||||
|
||||
extern ArrayedListNode_t jointAngleNodes[MAX_MODELJOINTNODES];
|
||||
|
||||
// Skeletal structures enums
|
||||
enum {
|
||||
SKEL_RAVEN = 0,
|
||||
SKEL_BOX,
|
||||
NUM_SKELETONS
|
||||
};
|
||||
|
||||
// Raven Skeletal structures enums
|
||||
enum {
|
||||
RAVEN_WAIST1 = 0,
|
||||
RAVEN_WAIST2 = 1,
|
||||
RAVEN_HEAD = 2,
|
||||
NUM_JOINTS_RAVEN
|
||||
};
|
||||
|
||||
// Box Skeletal structures enums
|
||||
enum {
|
||||
BOX_CENTER = 0,
|
||||
NUM_JOINTS_BOX
|
||||
};
|
||||
|
||||
extern int numJointsForSkeleton[];
|
||||
extern char *RAVEN_SKEL_NAMES[];
|
||||
|
||||
#define J_NEW_SKELETON 0x00001000
|
||||
#define J_YAW_CHANGED 0x00002000
|
||||
#define J_PITCH_CHANGED 0x00004000
|
||||
#define J_ROLL_CHANGED 0x00008000
|
||||
#define MAX_JOINTS 0x00000fff
|
||||
/*
|
||||
inline int GetFreeNode(ArrayedListNode_t *nodeArray, int max)
|
||||
{ // yeah, I know this is a sucky, inefficient way to do this, but I didn't feel like taking the time to write a real resource manager in C
|
||||
int i;
|
||||
|
||||
for(i = 0; i < max; ++i)
|
||||
{
|
||||
if(!nodeArray[i].inUse)
|
||||
{
|
||||
nodeArray[i].inUse = 1;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
assert(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
inline void FreeNode(ArrayedListNode_t *nodeArray, int index)
|
||||
{
|
||||
nodeArray[index].inUse = 0;
|
||||
}
|
||||
*/
|
||||
int CreateSkeleton(int structure);
|
||||
void CreateSkeletonAtIndex(int structure, int index);
|
||||
void FreeSkeleton(int structure, int index);
|
||||
void SetJointAngle(int jointIndex, int angleIndex, float angle);
|
||||
float ModifyJointAngle(int jointIndex, int angleIndex, float deltaAngle);
|
||||
int ZeroJointAngle(int jointIndex, int angleIndex, float angVel);
|
||||
int ApplyAngVelToJoint(int jointIndex, int angleIndex, float angVel, float destAng);
|
||||
|
||||
#endif
|
||||
2050
tools/quake2/qdata_heretic2/models.c
Normal file
2050
tools/quake2/qdata_heretic2/models.c
Normal file
File diff suppressed because it is too large
Load Diff
198
tools/quake2/qdata_heretic2/pics.c
Normal file
198
tools/quake2/qdata_heretic2/pics.c
Normal file
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
|
||||
#include "qdata.h"
|
||||
|
||||
byte *byteimage, *lbmpalette;
|
||||
int byteimagewidth, byteimageheight;
|
||||
|
||||
qboolean TrueColorImage;
|
||||
unsigned *longimage;
|
||||
int longimagewidth, longimageheight;
|
||||
|
||||
char pic_prefix[1024];
|
||||
extern char *g_outputDir;
|
||||
|
||||
/*
|
||||
===============
|
||||
Cmd_Pic
|
||||
===============
|
||||
*/
|
||||
|
||||
void Cmd_Pic (void)
|
||||
{
|
||||
int xl,yl,xh,yh,w,h;
|
||||
byte *dest, *source;
|
||||
int flags, value, contents;
|
||||
char lumpname[128];
|
||||
char animname[128];
|
||||
byte buffer[256*256];
|
||||
unsigned bufferl[256*256];
|
||||
char filename[1024];
|
||||
unsigned *destl, *sourcel;
|
||||
int linedelta, x, y;
|
||||
int size;
|
||||
miptex_t *qtex;
|
||||
miptex32_t *qtex32;
|
||||
float scale_x, scale_y;
|
||||
|
||||
GetScriptToken (false);
|
||||
strcpy (lumpname, token);
|
||||
|
||||
GetScriptToken (false);
|
||||
xl = atoi (token);
|
||||
GetScriptToken (false);
|
||||
yl = atoi (token);
|
||||
GetScriptToken (false);
|
||||
w = atoi (token);
|
||||
GetScriptToken (false);
|
||||
h = atoi (token);
|
||||
|
||||
total_x += w;
|
||||
total_y += h;
|
||||
total_textures++;
|
||||
|
||||
if ( (w & 7) || (h & 7) )
|
||||
Error ("line %i: miptex sizes must be multiples of 8", scriptline);
|
||||
|
||||
flags = 0;
|
||||
contents = 0;
|
||||
value = 0;
|
||||
|
||||
animname[0] = 0;
|
||||
|
||||
scale_x = scale_y = 0.5;
|
||||
|
||||
if (TrueColorImage)
|
||||
{
|
||||
sprintf (filename, "%spics/%s/%s.m32", g_outputDir, pic_prefix, lumpname);
|
||||
if (g_release)
|
||||
return; // textures are only released by $maps
|
||||
|
||||
xh = xl+w;
|
||||
yh = yl+h;
|
||||
|
||||
if (xl >= longimagewidth || xh > longimagewidth ||
|
||||
yl >= longimageheight || yh > longimageheight)
|
||||
{
|
||||
Error ("line %i: bad clip dimmensions (%d,%d) (%d,%d) > image (%d,%d)", scriptline, xl,yl,w,h,longimagewidth,longimageheight);
|
||||
}
|
||||
|
||||
sourcel = longimage + (yl*longimagewidth) + xl;
|
||||
destl = bufferl;
|
||||
linedelta = (longimagewidth - w);
|
||||
|
||||
for (y=yl ; y<yh ; y++)
|
||||
{
|
||||
for (x=xl ; x<xh ; x++)
|
||||
{
|
||||
*destl++ = *sourcel++; // RGBA
|
||||
}
|
||||
sourcel += linedelta;
|
||||
}
|
||||
|
||||
qtex32 = CreateMip32(bufferl, w, h, &size, false);
|
||||
|
||||
qtex32->flags |= LittleLong(flags);
|
||||
qtex32->contents = contents;
|
||||
qtex32->value = value;
|
||||
qtex32->scale_x = scale_x;
|
||||
qtex32->scale_y = scale_y;
|
||||
sprintf (qtex32->name, "%s/%s", pic_prefix, lumpname);
|
||||
if (animname[0])
|
||||
sprintf (qtex32->animname, "%s/%s", pic_prefix, animname);
|
||||
|
||||
//
|
||||
// write it out
|
||||
//
|
||||
printf ("writing %s\n", filename);
|
||||
SaveFile (filename, (byte *)qtex32, size);
|
||||
|
||||
free (qtex32);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf (filename, "%spics/%s/%s.m8", g_outputDir, pic_prefix, lumpname);
|
||||
if (g_release)
|
||||
return; // textures are only released by $maps
|
||||
|
||||
xh = xl+w;
|
||||
yh = yl+h;
|
||||
|
||||
if (xl >= byteimagewidth || xh > byteimagewidth ||
|
||||
yl >= byteimageheight || yh > byteimageheight)
|
||||
{
|
||||
Error ("line %i: bad clip dimmensions (%d,%d) (%d,%d) > image (%d,%d)", scriptline, xl,yl,w,h,byteimagewidth,byteimageheight);
|
||||
}
|
||||
|
||||
source = byteimage + yl*byteimagewidth + xl;
|
||||
dest = buffer;
|
||||
linedelta = byteimagewidth - w;
|
||||
|
||||
for (y=yl ; y<yh ; y++)
|
||||
{
|
||||
for (x=xl ; x<xh ; x++)
|
||||
{
|
||||
*dest++ = *source++;
|
||||
}
|
||||
source += linedelta;
|
||||
}
|
||||
|
||||
qtex = CreateMip(buffer, w, h, lbmpalette, &size, false);
|
||||
|
||||
qtex->flags = flags;
|
||||
qtex->contents = contents;
|
||||
qtex->value = value;
|
||||
sprintf (qtex->name, "%s/%s", pic_prefix, lumpname);
|
||||
if (animname[0])
|
||||
sprintf (qtex->animname, "%s/%s", pic_prefix, animname);
|
||||
|
||||
//
|
||||
// write it out
|
||||
//
|
||||
printf ("writing %s\n", filename);
|
||||
SaveFile (filename, (byte *)qtex, size);
|
||||
|
||||
free (qtex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
===============
|
||||
Cmd_picdir
|
||||
===============
|
||||
*/
|
||||
void Cmd_Picdir (void)
|
||||
{
|
||||
char filename[1024];
|
||||
|
||||
GetScriptToken (false);
|
||||
strcpy (pic_prefix, token);
|
||||
// create the directory if needed
|
||||
sprintf (filename, "%sPics", g_outputDir);
|
||||
Q_mkdir (filename);
|
||||
sprintf (filename, "%sPics/%s", g_outputDir, pic_prefix);
|
||||
Q_mkdir (filename);
|
||||
}
|
||||
|
||||
|
||||
76
tools/quake2/qdata_heretic2/qcommon/angles.h
Normal file
76
tools/quake2/qdata_heretic2/qcommon/angles.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
// Angles in radians
|
||||
|
||||
#define ANGLE_0 0.0F
|
||||
#define ANGLE_1 0.017453292F
|
||||
#define ANGLE_5 0.087266462F
|
||||
#define ANGLE_10 0.174532925F
|
||||
#define ANGLE_15 0.261799387F
|
||||
#define ANGLE_20 0.392699081F
|
||||
#define ANGLE_30 0.523598775F
|
||||
#define ANGLE_45 0.785398163F
|
||||
#define ANGLE_60 1.047197551F
|
||||
#define ANGLE_72 1.256637061F
|
||||
#define ANGLE_90 1.570796327F
|
||||
#define ANGLE_120 2.094395102F
|
||||
#define ANGLE_135 2.35619449F
|
||||
#define ANGLE_144 2.513274123F
|
||||
#define ANGLE_180 3.141592653F
|
||||
#define ANGLE_225 3.926990817F
|
||||
#define ANGLE_270 4.71238898F
|
||||
#define ANGLE_315 5.497787144F
|
||||
#define ANGLE_360 6.283185307F
|
||||
|
||||
// Angles in degrees
|
||||
|
||||
#define DEGREE_0 0.0F
|
||||
#define DEGREE_180 180.0F
|
||||
#define DEGREE_45 (DEGREE_180 / 4.0F)
|
||||
#define DEGREE_90 (DEGREE_180 / 2.0F)
|
||||
#define DEGREE_135 (DEGREE_90 + DEGREE_45)
|
||||
#define DEGREE_270 (DEGREE_180 + DEGREE_90)
|
||||
#define DEGREE_360 (DEGREE_180 * 2.0F)
|
||||
|
||||
#define DEGREE_225 (DEGREE_180 + DEGREE_45)
|
||||
#define DEGREE_315 (DEGREE_270 + DEGREE_45)
|
||||
|
||||
#define DEGREE_30 (DEGREE_180 / 6.0F)
|
||||
#define DEGREE_60 (DEGREE_180 / 3.0F)
|
||||
#define DEGREE_120 (DEGREE_360 / 3.0F)
|
||||
|
||||
#define DEGREE_1 (DEGREE_180 / 180.0F)
|
||||
#define DEGREE_5 (DEGREE_180 / 36.0F)
|
||||
#define DEGREE_10 (DEGREE_180 / 18.0F)
|
||||
#define DEGREE_15 (DEGREE_180 / 12.0F)
|
||||
#define DEGREE_20 (DEGREE_180 / 8.0F)
|
||||
|
||||
// Conversion routines
|
||||
|
||||
#define ANGLE_TO_RAD ANGLE_1
|
||||
#define RAD_TO_ANGLE (180.0F / ANGLE_180)
|
||||
|
||||
#define SHORT_TO_ANGLE (360.0/65536)
|
||||
|
||||
|
||||
#pragma warning(disable : 4305) // 'initializing' : truncation from 'const double ' to 'float '
|
||||
|
||||
71
tools/quake2/qdata_heretic2/qcommon/arrayedlist.h
Normal file
71
tools/quake2/qdata_heretic2/qcommon/arrayedlist.h
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef _ARRAYEDLIST_H
|
||||
#define _ARRAYEDLIST_H
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
typedef struct ArrayedListNode_s
|
||||
{
|
||||
int data;
|
||||
int next;
|
||||
int inUse;
|
||||
} ArrayedListNode_t;
|
||||
|
||||
#define ARRAYEDLISTNODE_NULL -1
|
||||
|
||||
static
|
||||
#ifdef _WIN32
|
||||
_inline
|
||||
#else
|
||||
inline
|
||||
#endif
|
||||
int GetFreeNode(ArrayedListNode_t *nodeArray, int max)
|
||||
{
|
||||
int i;
|
||||
|
||||
for(i = 0; i < max; ++i)
|
||||
{
|
||||
if(!nodeArray[i].inUse)
|
||||
{
|
||||
nodeArray[i].inUse = 1;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
assert(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static
|
||||
#ifdef _WIN32
|
||||
_inline
|
||||
#else
|
||||
inline
|
||||
#endif
|
||||
void FreeNode(ArrayedListNode_t *nodeArray, int index)
|
||||
{
|
||||
nodeArray[index].inUse = 0;
|
||||
}
|
||||
|
||||
#endif //_ARRAYEDLIST_H
|
||||
|
||||
33
tools/quake2/qdata_heretic2/qcommon/flex.h
Normal file
33
tools/quake2/qdata_heretic2/qcommon/flex.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
// Generic flexible format
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char ident[32];
|
||||
int version;
|
||||
int size;
|
||||
} header_t;
|
||||
|
||||
void WriteHeader(FILE *, char *, int, int, void *);
|
||||
|
||||
// end
|
||||
202
tools/quake2/qdata_heretic2/qcommon/fmodel.h
Normal file
202
tools/quake2/qdata_heretic2/qcommon/fmodel.h
Normal file
@@ -0,0 +1,202 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
.FM triangle flexible model file format
|
||||
|
||||
========================================================================
|
||||
*/
|
||||
|
||||
#ifndef __FMODEL_HEADER
|
||||
#define __FMODEL_HEADER
|
||||
|
||||
#include "bspfile.h"
|
||||
|
||||
//typedef unsigned char byte;
|
||||
//typedef int qboolean;
|
||||
//typedef float vec3_t[3];
|
||||
|
||||
#define MAX_FM_TRIANGLES 2048
|
||||
#define MAX_FM_VERTS 2048
|
||||
#define MAX_FM_FRAMES 2048
|
||||
#define MAX_FM_SKINS 64
|
||||
#define MAX_FM_SKINNAME 64
|
||||
#define MAX_FM_MESH_NODES 16 // also defined in game/qshared.h
|
||||
|
||||
|
||||
#define DTRIVERTX_V0 0
|
||||
#define DTRIVERTX_V1 1
|
||||
#define DTRIVERTX_V2 2
|
||||
#define DTRIVERTX_LNI 3
|
||||
#define DTRIVERTX_SIZE 4
|
||||
|
||||
#define SKINPAGE_WIDTH 640
|
||||
#define SKINPAGE_HEIGHT 480
|
||||
|
||||
#define ENCODED_WIDTH_X 92
|
||||
#define ENCODED_WIDTH_Y 475
|
||||
#define ENCODED_HEIGHT_X 128
|
||||
#define ENCODED_HEIGHT_Y 475
|
||||
|
||||
#define SCALE_ADJUST_FACTOR 0.96
|
||||
|
||||
#define INFO_HEIGHT 5
|
||||
#define INFO_Y (SKINPAGE_HEIGHT-INFO_HEIGHT)
|
||||
|
||||
extern byte *BasePalette;
|
||||
extern byte *BasePixels,*TransPixels;
|
||||
extern int BaseWidth, BaseHeight, TransWidth, TransHeight;
|
||||
extern int ScaleWidth, ScaleHeight;
|
||||
|
||||
int ExtractNumber(byte *pic, int x, int y);
|
||||
void DrawTextChar(int x, int y, char *text);
|
||||
void DrawLine(int x1, int y1, int x2, int y2);
|
||||
|
||||
// the glcmd format:
|
||||
// a positive integer starts a tristrip command, followed by that many
|
||||
// vertex structures.
|
||||
// a negative integer starts a trifan command, followed by -x vertexes
|
||||
// a zero indicates the end of the command list.
|
||||
// a vertex consists of a floating point s, a floating point t,
|
||||
// and an integer vertex index.
|
||||
|
||||
|
||||
// Initial Header
|
||||
#define FM_HEADER_NAME "header"
|
||||
#define FM_HEADER_VER 2
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int skinwidth;
|
||||
int skinheight;
|
||||
int framesize; // byte size of each frame
|
||||
|
||||
int num_skins;
|
||||
int num_xyz;
|
||||
int num_st; // greater than num_xyz for seams
|
||||
int num_tris;
|
||||
int num_glcmds; // dwords in strip/fan command list
|
||||
int num_frames;
|
||||
int num_mesh_nodes;
|
||||
} fmheader_t;
|
||||
|
||||
|
||||
// Skin Header
|
||||
#define FM_SKIN_NAME "skin"
|
||||
#define FM_SKIN_VER 1
|
||||
|
||||
|
||||
// ST Coord Header
|
||||
#define FM_ST_NAME "st coord"
|
||||
#define FM_ST_VER 1
|
||||
|
||||
typedef struct
|
||||
{
|
||||
short s;
|
||||
short t;
|
||||
} fmstvert_t;
|
||||
|
||||
|
||||
// Tri Header
|
||||
#define FM_TRI_NAME "tris"
|
||||
#define FM_TRI_VER 1
|
||||
|
||||
typedef struct
|
||||
{
|
||||
short index_xyz[3];
|
||||
short index_st[3];
|
||||
} fmtriangle_t;
|
||||
|
||||
|
||||
// Frame Header
|
||||
#define FM_FRAME_NAME "frames"
|
||||
#define FM_FRAME_VER 1
|
||||
|
||||
// Frame for compression, just the names
|
||||
#define FM_SHORT_FRAME_NAME "short frames"
|
||||
#define FM_SHORT_FRAME_VER 1
|
||||
|
||||
// Normals for compressed frames
|
||||
#define FM_NORMAL_NAME "normals"
|
||||
#define FM_NORMAL_VER 1
|
||||
|
||||
// Compressed Frame Data
|
||||
#define FM_COMP_NAME "comp data"
|
||||
#define FM_COMP_VER 1
|
||||
|
||||
// GL Cmds Header
|
||||
#define FM_GLCMDS_NAME "glcmds"
|
||||
#define FM_GLCMDS_VER 1
|
||||
|
||||
|
||||
// Mesh Nodes Header
|
||||
#define FM_MESH_NAME "mesh nodes"
|
||||
#define FM_MESH_VER 3
|
||||
|
||||
// Skeleton Header
|
||||
#define FM_SKELETON_NAME "skeleton"
|
||||
#define FM_SKELETON_VER 1
|
||||
|
||||
// References Header
|
||||
#define FM_REFERENCES_NAME "references"
|
||||
#define FM_REFERENCES_VER 1
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
||||
union
|
||||
{
|
||||
|
||||
byte tris[MAX_FM_TRIANGLES>>3];
|
||||
|
||||
struct {
|
||||
short *triIndicies;
|
||||
int num_tris;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
byte verts[MAX_FM_VERTS>>3];
|
||||
short start_glcmds, num_glcmds;
|
||||
} fmmeshnode_t;
|
||||
|
||||
//=================================================================
|
||||
|
||||
// Frame info
|
||||
typedef struct
|
||||
{
|
||||
byte v[3]; // scaled byte to fit in frame mins/maxs
|
||||
byte lightnormalindex;
|
||||
} fmtrivertx_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float scale[3]; // multiply byte verts by this
|
||||
float translate[3]; // then add this
|
||||
char name[16]; // frame name from grabbing
|
||||
fmtrivertx_t verts[1]; // variable sized
|
||||
} fmaliasframe_t;
|
||||
|
||||
|
||||
#endif // #define __FMODEL_HEADER
|
||||
26
tools/quake2/qdata_heretic2/qcommon/h2common.h
Normal file
26
tools/quake2/qdata_heretic2/qcommon/h2common.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef H2COMMON_H
|
||||
#define H2COMMON_H
|
||||
#define H2COMMON_API
|
||||
#endif
|
||||
|
||||
38
tools/quake2/qdata_heretic2/qcommon/placement.h
Normal file
38
tools/quake2/qdata_heretic2/qcommon/placement.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef PLACEMENT_H
|
||||
#define PLACEMENT_H
|
||||
|
||||
#include "q_typedef.h"
|
||||
|
||||
//typedef float vec3_t[3];
|
||||
|
||||
typedef struct Placement_s
|
||||
{
|
||||
vec3_t origin;
|
||||
vec3_t direction;
|
||||
vec3_t up;
|
||||
} Placement_t;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
63
tools/quake2/qdata_heretic2/qcommon/q_typedef.h
Normal file
63
tools/quake2/qdata_heretic2/qcommon/q_typedef.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef Q_TYPEDEF_H
|
||||
#define Q_TYPEDEF_H
|
||||
|
||||
typedef float vec_t;
|
||||
typedef vec_t vec2_t[2];
|
||||
typedef vec_t vec3_t[3];
|
||||
typedef double vec3d_t[3];
|
||||
typedef vec_t vec5_t[5];
|
||||
|
||||
typedef float matrix3_t[3][3];
|
||||
typedef float matrix3d_t[3][3];
|
||||
|
||||
typedef int fixed4_t;
|
||||
typedef int fixed8_t;
|
||||
typedef int fixed16_t;
|
||||
|
||||
typedef unsigned char byte;
|
||||
|
||||
#ifndef __cplusplus
|
||||
typedef enum {false, true} qboolean;
|
||||
#else
|
||||
typedef int qboolean;
|
||||
#endif
|
||||
|
||||
typedef struct edict_s edict_t;
|
||||
|
||||
typedef struct paletteRGBA_s
|
||||
{
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
byte r,g,b,a;
|
||||
};
|
||||
unsigned c;
|
||||
byte c_array[4];
|
||||
};
|
||||
} paletteRGBA_t;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
604
tools/quake2/qdata_heretic2/qcommon/qfiles.h
Normal file
604
tools/quake2/qdata_heretic2/qcommon/qfiles.h
Normal file
@@ -0,0 +1,604 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
|
||||
//
|
||||
// qfiles.h: quake file formats
|
||||
// This file must be identical in the quake and utils directories
|
||||
//
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
The .pak files are just a linear collapse of a directory tree
|
||||
|
||||
========================================================================
|
||||
*/
|
||||
|
||||
#define IDPAKHEADER (('K'<<24)+('C'<<16)+('A'<<8)+'P')
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char name[56];
|
||||
int filepos, filelen;
|
||||
} dpackfile_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int ident; // == IDPAKHEADER
|
||||
int dirofs;
|
||||
int dirlen;
|
||||
} dpackheader_t;
|
||||
|
||||
#define MAX_FILES_IN_PACK 6144
|
||||
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
PCX files are used for as many images as possible
|
||||
|
||||
========================================================================
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char manufacturer;
|
||||
char version;
|
||||
char encoding;
|
||||
char bits_per_pixel;
|
||||
unsigned short xmin,ymin,xmax,ymax;
|
||||
unsigned short hres,vres;
|
||||
unsigned char palette[48];
|
||||
char reserved;
|
||||
char color_planes;
|
||||
unsigned short bytes_per_line;
|
||||
unsigned short palette_type;
|
||||
char filler[58];
|
||||
unsigned char data; // unbounded
|
||||
} pcx_t;
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
.MD2 compressed triangle model file format
|
||||
|
||||
========================================================================
|
||||
*/
|
||||
#define IDCOMPRESSEDALIASHEADER (('2'<<24)+('C'<<16)+('D'<<8)+'I')
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
.MD2 compressed triangle model file format
|
||||
|
||||
========================================================================
|
||||
*/
|
||||
#define IDJOINTEDALIASHEADER (('2'<<24)+('J'<<16)+('D'<<8)+'I')
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
.MD2 triangle model file format
|
||||
|
||||
========================================================================
|
||||
*/
|
||||
|
||||
#define IDALIASHEADER (('2'<<24)+('P'<<16)+('D'<<8)+'I')
|
||||
#define ALIAS_VERSION 8
|
||||
|
||||
#define MAX_TRIANGLES 4096
|
||||
#define MAX_VERTS 2048
|
||||
#define MAX_FRAMES 512
|
||||
#define MAX_MD2SKINS 64
|
||||
#define MAX_SKINNAME 64
|
||||
|
||||
typedef struct
|
||||
{
|
||||
short s;
|
||||
short t;
|
||||
} dstvert_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
short index_xyz[3];
|
||||
short index_st[3];
|
||||
} dtriangle_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
byte v[3]; // scaled byte to fit in frame mins/maxs
|
||||
byte lightnormalindex;
|
||||
};
|
||||
|
||||
int vert;
|
||||
};
|
||||
} dtrivertx_t;
|
||||
|
||||
#define DTRIVERTX_V0 0
|
||||
#define DTRIVERTX_V1 1
|
||||
#define DTRIVERTX_V2 2
|
||||
#define DTRIVERTX_LNI 3
|
||||
#define DTRIVERTX_SIZE 4
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float scale[3]; // multiply byte verts by this
|
||||
float translate[3]; // then add this
|
||||
char name[16]; // frame name from grabbing
|
||||
dtrivertx_t verts[1]; // variable sized
|
||||
} daliasframe_t;
|
||||
|
||||
|
||||
// the glcmd format:
|
||||
// a positive integer starts a tristrip command, followed by that many
|
||||
// vertex structures.
|
||||
// a negative integer starts a trifan command, followed by -x vertexes
|
||||
// a zero indicates the end of the command list.
|
||||
// a vertex consists of a floating point s, a floating point t,
|
||||
// and an integer vertex index.
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int ident;
|
||||
int version;
|
||||
|
||||
int skinwidth;
|
||||
int skinheight;
|
||||
int framesize; // byte size of each frame
|
||||
|
||||
int num_skins;
|
||||
int num_xyz;
|
||||
int num_st; // greater than num_xyz for seams
|
||||
int num_tris;
|
||||
int num_glcmds; // dwords in strip/fan command list
|
||||
int num_frames;
|
||||
|
||||
int ofs_skins; // each skin is a MAX_SKINNAME string
|
||||
int ofs_st; // byte offset from start for stverts
|
||||
int ofs_tris; // offset for dtriangles
|
||||
int ofs_frames; // offset for first frame
|
||||
int ofs_glcmds;
|
||||
int ofs_end; // end of file
|
||||
|
||||
} dmdl_t;
|
||||
|
||||
// compressed model
|
||||
typedef struct dcompmdl_s
|
||||
{
|
||||
dmdl_t header;
|
||||
short CompressedFrameSize;
|
||||
short UniqueVerts;
|
||||
short *remap;
|
||||
float *translate; // then add this
|
||||
float *scale; // multiply byte verts by this
|
||||
char *mat;
|
||||
char *frames;
|
||||
char *base;
|
||||
float *ctranslate;
|
||||
float *cscale;
|
||||
char data[1];
|
||||
} dcompmdl_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
dcompmdl_t compModInfo;
|
||||
int rootCluster;
|
||||
int skeletalType;
|
||||
struct ModelSkeleton_s *skeletons;
|
||||
} JointedModel_t;
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
.BK file format
|
||||
|
||||
========================================================================
|
||||
*/
|
||||
|
||||
#define IDBOOKHEADER (('K'<<24)+('O'<<16)+('O'<<8)+'B')
|
||||
#define BOOK_VERSION 2
|
||||
|
||||
typedef struct bookframe_s
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
int w;
|
||||
int h;
|
||||
char name[MAX_SKINNAME]; // name of gfx file
|
||||
} bookframe_t;
|
||||
|
||||
typedef struct bookheader_s
|
||||
{
|
||||
unsigned int ident;
|
||||
unsigned int version;
|
||||
int num_segments;
|
||||
int total_w;
|
||||
int total_h;
|
||||
} bookheader_t;
|
||||
|
||||
typedef struct book_s
|
||||
{
|
||||
bookheader_t bheader;
|
||||
bookframe_t bframes[MAX_MD2SKINS];
|
||||
} book_t;
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
.SP2 sprite file format
|
||||
|
||||
========================================================================
|
||||
*/
|
||||
|
||||
#define IDSPRITEHEADER (('2'<<24)+('S'<<16)+('D'<<8)+'I')
|
||||
// little-endian "IDS2"
|
||||
#define SPRITE_VERSION 2
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int width, height;
|
||||
int origin_x, origin_y; // raster coordinates inside pic
|
||||
char name[MAX_SKINNAME]; // name of pcx file
|
||||
} dsprframe_t;
|
||||
|
||||
typedef struct {
|
||||
int ident;
|
||||
int version;
|
||||
int numframes;
|
||||
dsprframe_t frames[1]; // variable sized
|
||||
} dsprite_t;
|
||||
|
||||
/*
|
||||
==============================================================================
|
||||
|
||||
.M8 texture file format
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
typedef struct palette_s
|
||||
{
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
byte r,g,b;
|
||||
};
|
||||
};
|
||||
} palette_t;
|
||||
|
||||
#define MIP_VERSION 2
|
||||
#define PAL_SIZE 256
|
||||
#define MIPLEVELS 16
|
||||
|
||||
typedef struct miptex_s
|
||||
{
|
||||
int version;
|
||||
char name[32];
|
||||
unsigned width[MIPLEVELS], height[MIPLEVELS];
|
||||
unsigned offsets[MIPLEVELS]; // four mip maps stored
|
||||
char animname[32]; // next frame in animation chain
|
||||
palette_t palette[PAL_SIZE];
|
||||
int flags;
|
||||
int contents;
|
||||
int value;
|
||||
} miptex_t;
|
||||
|
||||
|
||||
|
||||
#define MIP32_VERSION 4
|
||||
|
||||
typedef struct miptex32_s
|
||||
{
|
||||
int version;
|
||||
char name[128];
|
||||
char altname[128]; // texture substitution
|
||||
char animname[128]; // next frame in animation chain
|
||||
char damagename[128]; // image that should be shown when damaged
|
||||
unsigned width[MIPLEVELS], height[MIPLEVELS];
|
||||
unsigned offsets[MIPLEVELS];
|
||||
int flags;
|
||||
int contents;
|
||||
int value;
|
||||
float scale_x, scale_y;
|
||||
int mip_scale;
|
||||
|
||||
// detail texturing info
|
||||
char dt_name[128]; // detailed texture name
|
||||
float dt_scale_x, dt_scale_y;
|
||||
float dt_u, dt_v;
|
||||
float dt_alpha;
|
||||
int dt_src_blend_mode, dt_dst_blend_mode;
|
||||
|
||||
int unused[20]; // future expansion to maintain compatibility with h2
|
||||
} miptex32_t;
|
||||
|
||||
|
||||
/*
|
||||
==============================================================================
|
||||
|
||||
.BSP file format
|
||||
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
#define IDBSPHEADER (('P'<<24)+('S'<<16)+('B'<<8)+'I')
|
||||
// little-endian "IBSP"
|
||||
|
||||
#define BSPVERSION 38
|
||||
|
||||
|
||||
// upper design bounds
|
||||
// leaffaces, leafbrushes, planes, and verts are still bounded by
|
||||
// 16 bit short limits
|
||||
#define MAX_MAP_MODELS 1024
|
||||
//#define MAX_MAP_BRUSHES 8192 // Quake 2 original
|
||||
#define MAX_MAP_BRUSHES 10240
|
||||
#define MAX_MAP_ENTITIES 2048
|
||||
#define MAX_MAP_ENTSTRING 0x40000
|
||||
#define MAX_MAP_TEXINFO 8192
|
||||
|
||||
#define MAX_MAP_AREAS 256
|
||||
#define MAX_MAP_AREAPORTALS 1024
|
||||
#define MAX_MAP_PLANES 65536
|
||||
#define MAX_MAP_NODES 65536
|
||||
#define MAX_MAP_BRUSHSIDES 65536
|
||||
#define MAX_MAP_LEAFS 65536
|
||||
#define MAX_MAP_VERTS 65536
|
||||
#define MAX_MAP_FACES 65536
|
||||
#define MAX_MAP_LEAFFACES 65536
|
||||
#define MAX_MAP_LEAFBRUSHES 65536
|
||||
#define MAX_MAP_PORTALS 65536
|
||||
#define MAX_MAP_EDGES 128000
|
||||
#define MAX_MAP_SURFEDGES 256000
|
||||
#define MAX_MAP_LIGHTING 0x200000
|
||||
#define MAX_MAP_VISIBILITY 0x180000
|
||||
|
||||
// key / value pair sizes
|
||||
|
||||
#define MAX_KEY 32
|
||||
#define MAX_VALUE 1024
|
||||
|
||||
//=============================================================================
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int fileofs, filelen;
|
||||
} lump_t;
|
||||
|
||||
#define LUMP_ENTITIES 0
|
||||
#define LUMP_PLANES 1
|
||||
#define LUMP_VERTEXES 2
|
||||
#define LUMP_VISIBILITY 3
|
||||
#define LUMP_NODES 4
|
||||
#define LUMP_TEXINFO 5
|
||||
#define LUMP_FACES 6
|
||||
#define LUMP_LIGHTING 7
|
||||
#define LUMP_LEAFS 8
|
||||
#define LUMP_LEAFFACES 9
|
||||
#define LUMP_LEAFBRUSHES 10
|
||||
#define LUMP_EDGES 11
|
||||
#define LUMP_SURFEDGES 12
|
||||
#define LUMP_MODELS 13
|
||||
#define LUMP_BRUSHES 14
|
||||
#define LUMP_BRUSHSIDES 15
|
||||
#define LUMP_POP 16
|
||||
#define LUMP_AREAS 17
|
||||
#define LUMP_AREAPORTALS 18
|
||||
#define HEADER_LUMPS 19
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int ident;
|
||||
int version;
|
||||
lump_t lumps[HEADER_LUMPS];
|
||||
} dheader_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float mins[3], maxs[3];
|
||||
float origin[3]; // for sounds or lights
|
||||
int headnode;
|
||||
int firstface, numfaces; // submodels just draw faces
|
||||
// without walking the bsp tree
|
||||
} dmodel_t;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float point[3];
|
||||
} dvertex_t;
|
||||
|
||||
|
||||
// 0-2 are axial planes
|
||||
#define PLANE_X 0
|
||||
#define PLANE_Y 1
|
||||
#define PLANE_Z 2
|
||||
|
||||
// 3-5 are non-axial planes snapped to the nearest
|
||||
#define PLANE_ANYX 3
|
||||
#define PLANE_ANYY 4
|
||||
#define PLANE_ANYZ 5
|
||||
|
||||
// planes (x&~1) and (x&~1)+1 are allways opposites
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float normal[3];
|
||||
float dist;
|
||||
int type; // PLANE_X - PLANE_ANYZ ?remove? trivial to regenerate
|
||||
} dplane_t;
|
||||
|
||||
|
||||
// contents flags are seperate bits
|
||||
// a given brush can contribute multiple content bits
|
||||
// multiple brushes can be in a single leaf
|
||||
|
||||
// These definitions also need to be in q_shared.h!
|
||||
|
||||
// ************************************************************************************************
|
||||
// CONTENTS_XXX
|
||||
// ------------
|
||||
// Contents flags.
|
||||
// ************************************************************************************************
|
||||
|
||||
// Lower bits are stronger, and will eat weaker brushes completely.
|
||||
|
||||
#define CONTENTS_SOLID 0x00000001 // An eye is never valid in a solid.
|
||||
#define CONTENTS_WINDOW 0x00000002 // Translucent, but not watery.
|
||||
#define CONTENTS_AUX 0x00000004
|
||||
#define CONTENTS_LAVA 0x00000008
|
||||
#define CONTENTS_SLIME 0x00000010
|
||||
#define CONTENTS_WATER 0x00000020
|
||||
#define CONTENTS_MIST 0x00000040
|
||||
#define LAST_VISIBLE_CONTENTS CONTENTS_MIST
|
||||
|
||||
// Remaining contents are non-visible, and don't eat brushes.
|
||||
|
||||
#define CONTENTS_AREAPORTAL 0x00008000
|
||||
#define CONTENTS_PLAYERCLIP 0x00010000
|
||||
#define CONTENTS_MONSTERCLIP 0x00020000
|
||||
|
||||
// Currents can be added to any other contents, and may be mixed.
|
||||
|
||||
#define CONTENTS_CURRENT_0 0x00040000
|
||||
#define CONTENTS_CURRENT_90 0x00080000
|
||||
#define CONTENTS_CURRENT_180 0x00100000
|
||||
#define CONTENTS_CURRENT_270 0x00200000
|
||||
#define CONTENTS_CURRENT_UP 0x00400000
|
||||
#define CONTENTS_CURRENT_DOWN 0x00800000
|
||||
#define CONTENTS_ORIGIN 0x01000000 // Removed before bsping an entity.
|
||||
#define CONTENTS_MONSTER 0x02000000 // Should never be on a brush, only in game.
|
||||
#define CONTENTS_DEADMONSTER 0x04000000
|
||||
#define CONTENTS_DETAIL 0x08000000 // Brushes to be added after vis leaves.
|
||||
#define CONTENTS_TRANSLUCENT 0x10000000 // Auto set if any surface has transparency.
|
||||
#define CONTENTS_LADDER 0x20000000
|
||||
#define CONTENTS_CAMERANOBLOCK 0x40000000 // Camera LOS ignores any brushes with this flag.
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int planenum;
|
||||
int children[2]; // negative numbers are -(leafs+1), not nodes
|
||||
short mins[3]; // for frustom culling
|
||||
short maxs[3];
|
||||
unsigned short firstface;
|
||||
unsigned short numfaces; // counting both sides
|
||||
} dnode_t;
|
||||
|
||||
|
||||
typedef struct texinfo_s
|
||||
{
|
||||
float vecs[2][4]; // [s/t][xyz offset]
|
||||
int flags; // miptex flags + overrides
|
||||
int value; // light emission, etc
|
||||
char texture[32]; // texture name (textures/*.wal)
|
||||
int nexttexinfo; // for animations, -1 = end of chain
|
||||
} texinfo_t;
|
||||
|
||||
|
||||
// note that edge 0 is never used, because negative edge nums are used for
|
||||
// counterclockwise use of the edge in a face
|
||||
typedef struct
|
||||
{
|
||||
unsigned short v[2]; // vertex numbers
|
||||
} dedge_t;
|
||||
|
||||
#define MAXLIGHTMAPS 4
|
||||
typedef struct
|
||||
{
|
||||
unsigned short planenum;
|
||||
short side;
|
||||
|
||||
int firstedge; // we must support > 64k edges
|
||||
short numedges;
|
||||
short texinfo;
|
||||
|
||||
// lighting info
|
||||
byte styles[MAXLIGHTMAPS];
|
||||
int lightofs; // start of [numstyles*surfsize] samples
|
||||
} dface_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int contents; // OR of all brushes (not needed?)
|
||||
|
||||
short cluster;
|
||||
short area;
|
||||
|
||||
short mins[3]; // for frustum culling
|
||||
short maxs[3];
|
||||
|
||||
unsigned short firstleafface;
|
||||
unsigned short numleaffaces;
|
||||
|
||||
unsigned short firstleafbrush;
|
||||
unsigned short numleafbrushes;
|
||||
} dleaf_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned short planenum; // facing out of the leaf
|
||||
short texinfo;
|
||||
} dbrushside_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int firstside;
|
||||
int numsides;
|
||||
int contents;
|
||||
} dbrush_t;
|
||||
|
||||
#define ANGLE_UP -1
|
||||
#define ANGLE_DOWN -2
|
||||
|
||||
|
||||
// the visibility lump consists of a header with a count, then
|
||||
// byte offsets for the PVS and PHS of each cluster, then the raw
|
||||
// compressed bit vectors
|
||||
#define DVIS_PVS 0
|
||||
#define DVIS_PHS 1
|
||||
typedef struct
|
||||
{
|
||||
int numclusters;
|
||||
int bitofs[8][2]; // bitofs[numclusters][2]
|
||||
} dvis_t;
|
||||
|
||||
// each area has a list of portals that lead into other areas
|
||||
// when portals are closed, other areas may not be visible or
|
||||
// hearable even if the vis info says that it should be
|
||||
typedef struct
|
||||
{
|
||||
int portalnum;
|
||||
int otherarea;
|
||||
} dareaportal_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int numareaportals;
|
||||
int firstareaportal;
|
||||
} darea_t;
|
||||
|
||||
124
tools/quake2/qdata_heretic2/qcommon/reference.c
Normal file
124
tools/quake2/qdata_heretic2/qcommon/reference.c
Normal file
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "reference.h"
|
||||
#include "arrayedlist.h"
|
||||
#include "resourcemanager.h"
|
||||
#include "skeletons.h"
|
||||
|
||||
char *referenceRootNames[] =
|
||||
{
|
||||
"elf_Lhandroot",//0
|
||||
"elf_Rhandroot",
|
||||
"elf_Rfootroot",
|
||||
"elf_Lfootroot",
|
||||
"elf_Bstaffroot",
|
||||
"elf_bladeroot",
|
||||
"elf_hellroot",
|
||||
"StaffBone",//7
|
||||
"SwordBone",
|
||||
"SpearBone",
|
||||
"RFootBone",
|
||||
"LFootBone",
|
||||
"hp_backroot",//12
|
||||
"hp_staffroot",
|
||||
"hp_lhandroot",
|
||||
"hp_rhandroot",
|
||||
"hp_rfootroot",
|
||||
"hp_lfootroot",
|
||||
"staffroot",//18
|
||||
"rfootroot",
|
||||
"lfootroot",
|
||||
"rhandroot",
|
||||
"lhandroot",
|
||||
"leyeroot",
|
||||
"reyeroot"
|
||||
};
|
||||
|
||||
int referenceRootNameOffsets[NUM_REFERENCED] =
|
||||
{
|
||||
0, // CORVUS
|
||||
7, // INSECT
|
||||
12, // HIGH PRIESTESS
|
||||
18, // MORCALAVIN
|
||||
};
|
||||
|
||||
int numReferences[NUM_REFERENCED] =
|
||||
{
|
||||
NUM_REFERENCES_CORVUS,
|
||||
NUM_REFERENCES_INSECT,
|
||||
NUM_REFERENCES_PRIESTESS,
|
||||
NUM_REFERENCES_MORK,
|
||||
};
|
||||
|
||||
int corvusJointIDs[NUM_REFERENCES_CORVUS] =
|
||||
{
|
||||
CORVUS_UPPERBACK,
|
||||
CORVUS_UPPERBACK,
|
||||
-1,
|
||||
-1,
|
||||
CORVUS_UPPERBACK,
|
||||
CORVUS_UPPERBACK,
|
||||
CORVUS_UPPERBACK,
|
||||
};
|
||||
|
||||
int *jointIDs[NUM_REFERENCED] =
|
||||
{
|
||||
corvusJointIDs,
|
||||
};
|
||||
|
||||
static ResourceManager_t ReferenceMngr;
|
||||
|
||||
void InitReferenceMngr()
|
||||
{
|
||||
#define REFERENCE_BLOCK_SIZE 8
|
||||
char *dummystr = NULL;
|
||||
|
||||
ResMngr_Con(&ReferenceMngr, sizeof(LERPedReferences_t), REFERENCE_BLOCK_SIZE, dummystr);
|
||||
}
|
||||
|
||||
void ReleaseReferenceMngr()
|
||||
{
|
||||
ResMngr_Des(&ReferenceMngr);
|
||||
}
|
||||
|
||||
LERPedReferences_t *LERPedReferences_new(int init_refType)
|
||||
{
|
||||
LERPedReferences_t *newRefs;
|
||||
|
||||
newRefs = ResMngr_AllocateResource(&ReferenceMngr, sizeof(*newRefs));
|
||||
newRefs->refType = init_refType;
|
||||
newRefs->jointIDs = jointIDs[init_refType];
|
||||
newRefs->lastUpdate = -(REF_MINCULLTIME*2.0);
|
||||
|
||||
memset(newRefs->references, 0, MAX_REFPOINTS*sizeof(Reference_t));
|
||||
memset(newRefs->oldReferences, 0, MAX_REFPOINTS*sizeof(Reference_t));
|
||||
|
||||
return newRefs;
|
||||
}
|
||||
|
||||
void LERPedReferences_delete(LERPedReferences_t *toDelete)
|
||||
{
|
||||
ResMngr_DeallocateResource(&ReferenceMngr, toDelete, sizeof(*toDelete));
|
||||
}
|
||||
|
||||
// end
|
||||
126
tools/quake2/qdata_heretic2/qcommon/reference.h
Normal file
126
tools/quake2/qdata_heretic2/qcommon/reference.h
Normal file
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef REFERENCE_H
|
||||
#define REFERENCE_H
|
||||
|
||||
#include "placement.h"
|
||||
|
||||
#define MAX_REFPOINTS 16
|
||||
#define REF_MINCULLTIME 1.0
|
||||
|
||||
typedef struct Reference_s
|
||||
{
|
||||
int activecount;
|
||||
Placement_t placement;
|
||||
} Reference_t;
|
||||
|
||||
typedef struct LERPedReferences_s
|
||||
{
|
||||
int refType;
|
||||
int *jointIDs;
|
||||
float lastUpdate;
|
||||
Reference_t references[MAX_REFPOINTS];
|
||||
Reference_t oldReferences[MAX_REFPOINTS];
|
||||
} LERPedReferences_t;
|
||||
|
||||
// Reference Types
|
||||
enum {
|
||||
REF_NULL = -1,
|
||||
REF_CORVUS,//0
|
||||
REF_INSECT,//1
|
||||
REF_PRIESTESS,//2
|
||||
REF_MORK,//3
|
||||
NUM_REFERENCED//4
|
||||
};
|
||||
|
||||
// Corvus Reference Points
|
||||
enum {
|
||||
CORVUS_LEFTHAND,//0
|
||||
CORVUS_RIGHTHAND,
|
||||
CORVUS_LEFTFOOT,
|
||||
CORVUS_RIGHTFOOT,
|
||||
CORVUS_STAFF,
|
||||
CORVUS_BLADE,
|
||||
CORVUS_HELL_HEAD,
|
||||
NUM_REFERENCES_CORVUS//7
|
||||
};
|
||||
|
||||
// Tchekrik Reference Points
|
||||
enum {
|
||||
INSECT_STAFF,//0
|
||||
INSECT_SWORD,
|
||||
INSECT_SPEAR,
|
||||
INSECT_RIGHTFOOT,
|
||||
INSECT_LEFTFOOT,
|
||||
NUM_REFERENCES_INSECT//5
|
||||
};
|
||||
|
||||
// High Priestess Reference Points
|
||||
enum {
|
||||
PRIESTESS_BACK,//0
|
||||
PRIESTESS_STAFF,
|
||||
PRIESTESS_LHAND,
|
||||
PRIESTESS_RHAND,
|
||||
PRIESTESS_RFOOT,
|
||||
PRIESTESS_LFOOT,
|
||||
NUM_REFERENCES_PRIESTESS//6
|
||||
};
|
||||
|
||||
// Morcalavin Reference Points
|
||||
enum
|
||||
{
|
||||
MORK_STAFFREF,//0
|
||||
MORK_RFOOTREF,//1
|
||||
MORK_LFOOTREF,//2
|
||||
MORK_RHANDREF,//3
|
||||
MORK_LHANDREF,//4
|
||||
MORK_LEYEREF,//5
|
||||
MORK_REYEREF,//6
|
||||
NUM_REFERENCES_MORK//7
|
||||
};
|
||||
|
||||
#define CORVUS_LIMBS_MASK ((1 << CORVUS_LEFTHAND) | (1 << CORVUS_RIGHTHAND) | (1 << CORVUS_LEFTFOOT) | (1 << CORVUS_RIGHTFOOT))
|
||||
#define CORVUS_WEAPON_MASK ((1 << CORVUS_STAFF) | (1 << CORVUS_BLADE) | (1 << CORVUS_HELL_HEAD))
|
||||
#define CORVUS_MASK (CORVUS_LIMBS_MASK | CORVUS_WEAPON_MASK)
|
||||
|
||||
#define INSECT_MASK ((1 << INSECT_STAFF) | (1 << INSECT_SWORD) | (1 << INSECT_SPEAR) | (1 << INSECT_RIGHTFOOT) | (1 << INSECT_LEFTFOOT))
|
||||
|
||||
#define PRIESTESS_MASK ((1 << PRIESTESS_BACK) | (1 << PRIESTESS_STAFF) | (1 << PRIESTESS_LHAND) | (1 << PRIESTESS_RHAND) | (1 << PRIESTESS_RFOOT) | (1 << PRIESTESS_LFOOT))
|
||||
|
||||
#define MORK_MASK ((1 << MORK_STAFFREF) | (1 << MORK_RFOOTREF) | (1 << MORK_LFOOTREF) | (1 << MORK_RHANDREF) | (1 << MORK_LHANDREF) | (1 << MORK_LEYEREF) | (1 << MORK_REYEREF))
|
||||
|
||||
extern char *referenceRootNames[];
|
||||
extern int referenceRootNameOffsets[];
|
||||
extern int numReferences[];
|
||||
|
||||
void EnableRefPoints(LERPedReferences_t *refInfo, int mask);
|
||||
void DisableRefPoints(LERPedReferences_t *refInfo, int mask);
|
||||
|
||||
void InitReferenceMngr();
|
||||
void ReleaseReferenceMngr();
|
||||
|
||||
LERPedReferences_t *LERPedReferences_new(int init_refType);
|
||||
void LERPedReferences_delete(LERPedReferences_t *toDelete);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
159
tools/quake2/qdata_heretic2/qcommon/resourcemanager.c
Normal file
159
tools/quake2/qdata_heretic2/qcommon/resourcemanager.c
Normal file
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
|
||||
//
|
||||
// ResourceManager.c
|
||||
//
|
||||
|
||||
#include <stdio.h>
|
||||
#include "resourcemanager.h"
|
||||
#include <assert.h>
|
||||
|
||||
typedef struct ResMngr_Block_s
|
||||
{
|
||||
char *start;
|
||||
unsigned int size;
|
||||
struct ResMngr_Block_s *next;
|
||||
} ResMngr_Block_t;
|
||||
|
||||
static void ResMngr_CreateBlock(ResourceManager_t *resource)
|
||||
{
|
||||
unsigned int _blockSize;
|
||||
char *block;
|
||||
char **current;
|
||||
ResMngr_Block_t *temp;
|
||||
unsigned int i;
|
||||
|
||||
_blockSize = resource->nodeSize * resource->resPerBlock;
|
||||
|
||||
block = malloc(_blockSize);
|
||||
|
||||
assert(block);
|
||||
|
||||
temp = malloc(sizeof(*temp));
|
||||
|
||||
temp->start = block;
|
||||
temp->size = _blockSize;
|
||||
temp->next = resource->blockList;
|
||||
|
||||
resource->blockList = temp;
|
||||
|
||||
resource->free = (char **)(block);
|
||||
|
||||
current = resource->free;
|
||||
|
||||
for(i = 1; i < resource->resPerBlock; ++i)
|
||||
{
|
||||
// set current->next to point to next node
|
||||
*current = (char *)(current) + resource->nodeSize;
|
||||
|
||||
// set current node to current->next
|
||||
current = (char **)(*current);
|
||||
}
|
||||
|
||||
*current = NULL;
|
||||
}
|
||||
|
||||
H2COMMON_API void ResMngr_Con(ResourceManager_t *resource, size_t init_resSize, unsigned int init_resPerBlock, char *resman_name)
|
||||
{
|
||||
resource->resSize = init_resSize;
|
||||
|
||||
resource->resPerBlock = init_resPerBlock;
|
||||
|
||||
resource->nodeSize = resource->resSize + sizeof(*resource->free);
|
||||
|
||||
resource->blockList = NULL;
|
||||
|
||||
resource->numResourcesAllocated = 0;
|
||||
|
||||
ResMngr_CreateBlock(resource);
|
||||
}
|
||||
|
||||
H2COMMON_API void ResMngr_Des(ResourceManager_t *resource)
|
||||
{
|
||||
ResMngr_Block_t *toDelete;
|
||||
|
||||
#if 0
|
||||
if (resource->numResourcesAllocated)
|
||||
{
|
||||
char mess[100];
|
||||
sprintf(mess,"Potential memory leak %d bytes unfreed\n",resource->resSize*resource->numResourcesAllocated);
|
||||
OutputDebugString(mess);
|
||||
}
|
||||
#endif
|
||||
|
||||
while(resource->blockList)
|
||||
{
|
||||
toDelete = resource->blockList;
|
||||
resource->blockList = resource->blockList->next;
|
||||
free(toDelete->start);
|
||||
free(toDelete);
|
||||
}
|
||||
}
|
||||
|
||||
H2COMMON_API void *ResMngr_AllocateResource(ResourceManager_t *resource, size_t size)
|
||||
{
|
||||
char **toPop;
|
||||
|
||||
assert(size == resource->resSize);
|
||||
|
||||
++resource->numResourcesAllocated;
|
||||
|
||||
assert(resource->free); // constructor not called; possibly due to a static object
|
||||
// containing a static ResourceManagerFastLarge member being
|
||||
// constructed before its own static members
|
||||
|
||||
toPop = resource->free;
|
||||
|
||||
// set unallocated to the next node and check for NULL (end of list)
|
||||
if(!(resource->free = (char **)(*resource->free)))
|
||||
{ // if at end create new block
|
||||
ResMngr_CreateBlock(resource);
|
||||
}
|
||||
|
||||
// set next to NULL
|
||||
*toPop = NULL;
|
||||
|
||||
// return the resource for the node
|
||||
return (void *)(toPop + 1);
|
||||
}
|
||||
|
||||
H2COMMON_API void ResMngr_DeallocateResource(ResourceManager_t *resource, void *toDeallocate, size_t size)
|
||||
{
|
||||
char **toPush;
|
||||
|
||||
assert(size == resource->resSize);
|
||||
|
||||
--resource->numResourcesAllocated;
|
||||
|
||||
toPush = (char **)(toDeallocate) - 1;
|
||||
|
||||
assert(resource->free); // see same assert at top of AllocateResource
|
||||
|
||||
// set toPop->next to current unallocated front
|
||||
*toPush = (char *)(resource->free);
|
||||
|
||||
// set unallocated to the node removed from allocated
|
||||
resource->free = toPush;
|
||||
}
|
||||
|
||||
// end
|
||||
47
tools/quake2/qdata_heretic2/qcommon/resourcemanager.h
Normal file
47
tools/quake2/qdata_heretic2/qcommon/resourcemanager.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
//
|
||||
// ResourceManager.h
|
||||
//
|
||||
|
||||
#include "h2common.h"
|
||||
#include <stdlib.h> // needed here for size_t
|
||||
|
||||
typedef struct ResourceManager_s
|
||||
{
|
||||
size_t resSize;
|
||||
unsigned int resPerBlock;
|
||||
unsigned int nodeSize;
|
||||
struct ResMngr_Block_s *blockList;
|
||||
char **free;
|
||||
char *ResMan_Name;
|
||||
|
||||
unsigned numResourcesAllocated;
|
||||
|
||||
} ResourceManager_t;
|
||||
|
||||
extern H2COMMON_API void ResMngr_Con(ResourceManager_t *resource, size_t init_resSize, unsigned int init_resPerBlock, char *resman_name);
|
||||
extern H2COMMON_API void ResMngr_Des(ResourceManager_t *resource);
|
||||
extern H2COMMON_API void *ResMngr_AllocateResource(ResourceManager_t *resource, size_t size);
|
||||
extern H2COMMON_API void ResMngr_DeallocateResource(ResourceManager_t *resource, void *toDeallocate, size_t size);
|
||||
|
||||
|
||||
232
tools/quake2/qdata_heretic2/qcommon/skeletons.c
Normal file
232
tools/quake2/qdata_heretic2/qcommon/skeletons.c
Normal file
@@ -0,0 +1,232 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
//
|
||||
// Skeletons.c
|
||||
//
|
||||
|
||||
#include "skeletons.h"
|
||||
|
||||
char *skeletonRootNames[] =
|
||||
{
|
||||
"RAVEN_ROOT",
|
||||
"BOX_ROOT",
|
||||
"BEETLE_ROOT",
|
||||
"ELFLORD_ROOT",
|
||||
"PLAGUELF_ROOT",
|
||||
"ELF_BACKROOT",
|
||||
};
|
||||
|
||||
int skeletonRNameOffsets[] =
|
||||
{
|
||||
0, // RAVEN
|
||||
1, // BOX
|
||||
2, // BEETLE
|
||||
3, // ELFLORD
|
||||
4, // PLAGUE ELF
|
||||
5, // CORVUS
|
||||
};
|
||||
|
||||
char *skeletonJointNames[] =
|
||||
{
|
||||
"RAVEN_LOWERBACK", // 0
|
||||
"RAVEN_UPPERBACK",
|
||||
"RAVEN_NECK",
|
||||
"BOX_CENTER", // 3
|
||||
"BEETLE_NECK", // 4
|
||||
"BEETLE_HEAD",
|
||||
"PLAGUELF_BACKB", // 6
|
||||
"PLAGUELF_BACKC",
|
||||
"PLAGUELF_NECK",
|
||||
"ELF_BACKB", // 9
|
||||
"ELF_BACKC",
|
||||
"ELF_NECKB",
|
||||
};
|
||||
|
||||
int skeletonNameOffsets[] =
|
||||
{
|
||||
0, // RAVEN
|
||||
3, // BOX
|
||||
4, // BEETLE
|
||||
-1, // ELFLORD
|
||||
6, // PLAGUE ELF
|
||||
9, // CORVUS
|
||||
};
|
||||
|
||||
char *skeletonEffectorNames[] =
|
||||
{
|
||||
"BEETLE_EYES", // 0
|
||||
"CORVUS_EYES", // 1
|
||||
};
|
||||
|
||||
int skeletonENameOffsets[] =
|
||||
{
|
||||
-1, // RAVEN
|
||||
-1, // BOX
|
||||
0, // BEETLE
|
||||
-1, // ELFLORD
|
||||
1, // PLAGUE ELF
|
||||
};
|
||||
|
||||
int numJointsInSkeleton[] =
|
||||
{
|
||||
NUM_JOINTS_RAVEN,
|
||||
NUM_JOINTS_BOX,
|
||||
NUM_JOINTS_BEETLE,
|
||||
NUM_JOINTS_ELFLORD,
|
||||
NUM_JOINTS_PLAGUE_ELF,
|
||||
NUM_JOINTS_CORVUS,
|
||||
};
|
||||
|
||||
int numNodesInSkeleton[] =
|
||||
{
|
||||
2, // RAVEN
|
||||
0, // BOX
|
||||
1, // BEETLE
|
||||
-1, // ELFLORD
|
||||
2, // PLAGUE ELF
|
||||
2, // CORVUS
|
||||
};
|
||||
|
||||
void CreateRavenSkel(void *g_skeletalJoints, size_t jointSize, struct ArrayedListNode_s *g_jointNodes, int root);
|
||||
void CreateBoxSkel(void *g_skeletalJoints, size_t jointSize, struct ArrayedListNode_s *g_jointNodes, int root);
|
||||
void CreateBeetleSkel(void *g_skeletalJoints, size_t jointSize, ArrayedListNode_t *g_jointNodes, int rootIndex);
|
||||
void CreateElfLordSkel(void *g_skeletalJoints, size_t jointSize, ArrayedListNode_t *g_jointNodes, int rootIndex);
|
||||
void CreatePlagueElfSkel(void *g_skeletalJoints, size_t jointSize, ArrayedListNode_t *g_jointNodes, int rootIndex);
|
||||
|
||||
CreateSkeleton_t SkeletonCreators[NUM_SKELETONS] =
|
||||
{
|
||||
CreateRavenSkel,
|
||||
CreateBoxSkel,
|
||||
CreateBeetleSkel,
|
||||
CreateElfLordSkel,
|
||||
CreatePlagueElfSkel,
|
||||
CreatePlagueElfSkel, // Corvus has the same structure as the Plague Elf
|
||||
};
|
||||
|
||||
void CreateRavenSkel(void *g_skeletalJoints, size_t jointSize, ArrayedListNode_t *g_jointNodes, int rootIndex)
|
||||
{
|
||||
char *root;
|
||||
int *children;
|
||||
int nodeIndex;
|
||||
|
||||
root = (char *)g_skeletalJoints + rootIndex * jointSize;
|
||||
|
||||
children = (int *)(root + RAVEN_HEAD * jointSize);
|
||||
*children = ARRAYEDLISTNODE_NULL;
|
||||
|
||||
nodeIndex = GetFreeNode(g_jointNodes, MAX_ARRAYED_JOINT_NODES);
|
||||
|
||||
children = (int *)(root + RAVEN_UPPERBACK * jointSize);
|
||||
*children = nodeIndex;
|
||||
|
||||
g_jointNodes[nodeIndex].data = rootIndex + RAVEN_HEAD;
|
||||
g_jointNodes[nodeIndex].next = ARRAYEDLISTNODE_NULL;
|
||||
|
||||
nodeIndex = GetFreeNode(g_jointNodes, MAX_ARRAYED_JOINT_NODES);
|
||||
|
||||
children = (int *)(root + RAVEN_LOWERBACK * jointSize);
|
||||
*children = nodeIndex;
|
||||
|
||||
g_jointNodes[nodeIndex].data = rootIndex + RAVEN_UPPERBACK;
|
||||
g_jointNodes[nodeIndex].next = ARRAYEDLISTNODE_NULL;
|
||||
}
|
||||
|
||||
void CreateBoxSkel(void *g_skeletalJoints, size_t jointSize, ArrayedListNode_t *g_jointNodes, int rootIndex)
|
||||
{
|
||||
char *root;
|
||||
int *children;
|
||||
|
||||
root = (char *)g_skeletalJoints + rootIndex * jointSize;
|
||||
|
||||
children = (int *)(root + RAVEN_HEAD * jointSize);
|
||||
*children = ARRAYEDLISTNODE_NULL;
|
||||
}
|
||||
|
||||
void CreateBeetleSkel(void *g_skeletalJoints, size_t jointSize, ArrayedListNode_t *g_jointNodes, int rootIndex)
|
||||
{
|
||||
char *root;
|
||||
int *children;
|
||||
int nodeIndex;
|
||||
|
||||
root = (char *)g_skeletalJoints + rootIndex * jointSize;
|
||||
|
||||
children = (int *)(root + BEETLE_HEAD * jointSize);
|
||||
*children = ARRAYEDLISTNODE_NULL;
|
||||
|
||||
nodeIndex = GetFreeNode(g_jointNodes, MAX_ARRAYED_JOINT_NODES);
|
||||
|
||||
children = (int *)(root + BEETLE_NECK * jointSize);
|
||||
*children = nodeIndex;
|
||||
|
||||
g_jointNodes[nodeIndex].data = rootIndex + BEETLE_HEAD;
|
||||
g_jointNodes[nodeIndex].next = ARRAYEDLISTNODE_NULL;
|
||||
}
|
||||
|
||||
void CreateElfLordSkel(void *g_skeletalJoints, size_t jointSize, ArrayedListNode_t *g_jointNodes, int rootIndex)
|
||||
{
|
||||
char *root;
|
||||
int *children;
|
||||
int nodeIndex;
|
||||
|
||||
root = (char *)g_skeletalJoints + rootIndex * jointSize;
|
||||
|
||||
children = (int *)(root + BEETLE_HEAD * jointSize);
|
||||
*children = ARRAYEDLISTNODE_NULL;
|
||||
|
||||
nodeIndex = GetFreeNode(g_jointNodes, MAX_ARRAYED_JOINT_NODES);
|
||||
|
||||
children = (int *)(root + BEETLE_NECK * jointSize);
|
||||
*children = nodeIndex;
|
||||
|
||||
g_jointNodes[nodeIndex].data = rootIndex + BEETLE_HEAD;
|
||||
g_jointNodes[nodeIndex].next = ARRAYEDLISTNODE_NULL;
|
||||
}
|
||||
|
||||
void CreatePlagueElfSkel(void *g_skeletalJoints, size_t jointSize, ArrayedListNode_t *g_jointNodes, int rootIndex)
|
||||
{
|
||||
char *root;
|
||||
int *children;
|
||||
int nodeIndex;
|
||||
|
||||
root = (char *)g_skeletalJoints + rootIndex * jointSize;
|
||||
|
||||
children = (int *)(root + PLAGUE_ELF_HEAD * jointSize);
|
||||
*children = ARRAYEDLISTNODE_NULL;
|
||||
|
||||
nodeIndex = GetFreeNode(g_jointNodes, MAX_ARRAYED_JOINT_NODES);
|
||||
|
||||
children = (int *)(root + PLAGUE_ELF_UPPERBACK * jointSize);
|
||||
*children = nodeIndex;
|
||||
|
||||
g_jointNodes[nodeIndex].data = rootIndex + PLAGUE_ELF_HEAD;
|
||||
g_jointNodes[nodeIndex].next = ARRAYEDLISTNODE_NULL;
|
||||
|
||||
nodeIndex = GetFreeNode(g_jointNodes, MAX_ARRAYED_JOINT_NODES);
|
||||
|
||||
children = (int *)(root + PLAGUE_ELF_LOWERBACK * jointSize);
|
||||
*children = nodeIndex;
|
||||
|
||||
g_jointNodes[nodeIndex].data = rootIndex + PLAGUE_ELF_UPPERBACK;
|
||||
g_jointNodes[nodeIndex].next = ARRAYEDLISTNODE_NULL;
|
||||
}
|
||||
|
||||
|
||||
107
tools/quake2/qdata_heretic2/qcommon/skeletons.h
Normal file
107
tools/quake2/qdata_heretic2/qcommon/skeletons.h
Normal file
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdlib.h> // for size_t
|
||||
#include "arrayedlist.h"
|
||||
|
||||
#define JN_YAW_CHANGED 0x00000001
|
||||
#define JN_PITCH_CHANGED 0x00000002
|
||||
#define JN_ROLL_CHANGED 0x00000004
|
||||
|
||||
// Skeleton types
|
||||
enum {
|
||||
SKEL_NULL = -1,
|
||||
SKEL_RAVEN = 0,
|
||||
SKEL_BOX,
|
||||
SKEL_BEETLE,
|
||||
SKEL_ELFLORD,
|
||||
SKEL_PLAGUE_ELF,
|
||||
SKEL_CORVUS,
|
||||
NUM_SKELETONS
|
||||
};
|
||||
|
||||
// Raven Skeletal joints
|
||||
enum {
|
||||
RAVEN_LOWERBACK = 0,
|
||||
RAVEN_UPPERBACK,
|
||||
RAVEN_HEAD,
|
||||
NUM_JOINTS_RAVEN
|
||||
};
|
||||
|
||||
// Box Skeletal joints
|
||||
enum {
|
||||
BOX_CENTER = 0,
|
||||
NUM_JOINTS_BOX
|
||||
};
|
||||
|
||||
// Beetle Skeletal joints
|
||||
enum {
|
||||
BEETLE_NECK = 0,
|
||||
BEETLE_HEAD,
|
||||
NUM_JOINTS_BEETLE
|
||||
};
|
||||
|
||||
// Elflord Skeletal joints
|
||||
enum {
|
||||
ELFLORD_,
|
||||
ELFLORD__,
|
||||
NUM_JOINTS_ELFLORD
|
||||
};
|
||||
|
||||
// Plague Elf Skeletal joints
|
||||
enum {
|
||||
PLAGUE_ELF_LOWERBACK,
|
||||
PLAGUE_ELF_UPPERBACK,
|
||||
PLAGUE_ELF_HEAD,
|
||||
NUM_JOINTS_PLAGUE_ELF
|
||||
};
|
||||
|
||||
// Corvus Skeletal joints
|
||||
enum {
|
||||
CORVUS_LOWERBACK,
|
||||
CORVUS_UPPERBACK,
|
||||
CORVUS_HEAD,
|
||||
NUM_JOINTS_CORVUS
|
||||
};
|
||||
|
||||
#define NO_SWAP_FRAME -1
|
||||
#define NULL_ROOT_JOINT -1
|
||||
|
||||
#define MAX_ARRAYED_SKELETAL_JOINTS 255 // has max of 65,535 (if this remains at 255, net code can be changed to reflect)
|
||||
#define MAX_ARRAYED_JOINT_NODES (MAX_ARRAYED_SKELETAL_JOINTS - 1)
|
||||
|
||||
#define MAX_JOINTS_PER_SKELETON 8 // arbitrary small number
|
||||
#define MAX_JOINT_NODES_PER_SKELETON (MAX_JOINTS_PER_SKELETON - 1)
|
||||
|
||||
extern char *skeletonRootNames[];
|
||||
extern int skeletonRNameOffsets[];
|
||||
extern char *skeletonJointNames[];
|
||||
extern int skeletonNameOffsets[];
|
||||
extern int numJointsInSkeleton[];
|
||||
extern char *skeletonEffectorNames[];
|
||||
extern int skeletonENameOffsets[];
|
||||
extern int numNodesInSkeleton[];
|
||||
|
||||
typedef void (*CreateSkeleton_t)(void *skeletalJoints, size_t jointSize, struct ArrayedListNode_s *jointNodes, int rootIndex);
|
||||
|
||||
extern CreateSkeleton_t SkeletonCreators[NUM_SKELETONS];
|
||||
|
||||
|
||||
61
tools/quake2/qdata_heretic2/qd_fmodel.h
Normal file
61
tools/quake2/qdata_heretic2/qd_fmodel.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef FMODEL_H
|
||||
#define FMODEL_H
|
||||
#include "fmodel.h"
|
||||
#endif
|
||||
#include "qd_skeletons.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int numnormals;
|
||||
vec3_t normalsum;
|
||||
} fmvertexnormals_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
vec3_t v;
|
||||
int lightnormalindex;
|
||||
fmvertexnormals_t vnorm;
|
||||
} fmtrivert_t;
|
||||
|
||||
#define FRAME_NAME_LEN (16)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
vec3_t mins, maxs;
|
||||
char name[FRAME_NAME_LEN];
|
||||
fmtrivert_t v[MAX_FM_VERTS];
|
||||
struct QD_SkeletalJoint_s joints[NUM_CLUSTERS];
|
||||
struct QD_SkeletalJoint_s references[NUM_REFERENCES];
|
||||
} fmframe_t;
|
||||
|
||||
extern fmframe_t g_frames[MAX_FM_FRAMES];
|
||||
|
||||
extern fmheader_t fmheader;
|
||||
extern char cdarchive[1024]; // set by $fmcd
|
||||
extern char cdpartial[1024]; // set by $fmcd
|
||||
extern char cddir[1024]; // set by $fmcd
|
||||
|
||||
void GrabFrame (char *frame);
|
||||
void H_printf(char *fmt, ...);
|
||||
char *FindFrameFile (char *frame);
|
||||
1291
tools/quake2/qdata_heretic2/qd_skeletons.c
Normal file
1291
tools/quake2/qdata_heretic2/qd_skeletons.c
Normal file
File diff suppressed because it is too large
Load Diff
84
tools/quake2/qdata_heretic2/qd_skeletons.h
Normal file
84
tools/quake2/qdata_heretic2/qd_skeletons.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef QD_SKELETONS_H
|
||||
#define QD_SKELETONS_H
|
||||
|
||||
#include "placement.h"
|
||||
|
||||
|
||||
typedef struct Placement_d_s
|
||||
{
|
||||
vec3d_t origin;
|
||||
vec3d_t direction;
|
||||
vec3d_t up;
|
||||
} Placement_d_t;
|
||||
|
||||
typedef struct QD_SkeletalJoint_s
|
||||
{
|
||||
Placement_d_t placement;
|
||||
vec3d_t rotation;
|
||||
} QD_SkeletalJoint_t;
|
||||
|
||||
#define NUM_CLUSTERS 8
|
||||
|
||||
typedef struct IntListNode_s
|
||||
{
|
||||
int data;
|
||||
struct IntListNode_s *next;
|
||||
} IntListNode_t; // gaak
|
||||
|
||||
typedef struct Skeletalfmheader_s
|
||||
{
|
||||
int type;
|
||||
int clustered;
|
||||
int references;
|
||||
|
||||
int *clusters[NUM_CLUSTERS];
|
||||
IntListNode_t *vertLists[NUM_CLUSTERS];
|
||||
int num_verts[NUM_CLUSTERS + 1];
|
||||
int new_num_verts[NUM_CLUSTERS + 1];
|
||||
|
||||
float scaling[3];
|
||||
float rotation[3];
|
||||
float translation[3];
|
||||
} Skeletalfmheader_t;
|
||||
|
||||
#define SKELETAL_NAME_MAX 32
|
||||
|
||||
extern Skeletalfmheader_t g_skelModel;
|
||||
|
||||
void ClearSkeletalModel();
|
||||
void GrabModelTransform(char *frame);
|
||||
void GrabSkeletalFrame(char *frame);
|
||||
void GrabReferencedFrame(char *frame);
|
||||
|
||||
// Reference Stuff
|
||||
#define NUM_REFERENCES 8
|
||||
|
||||
#define REF_MAX_POINTS 16
|
||||
#define REF_MAX_STRLEN 32
|
||||
|
||||
// We're assuming no more than 16 reference points, with no more than 32 characters in the name
|
||||
extern char RefPointNameList[REF_MAX_POINTS][REF_MAX_STRLEN];
|
||||
extern int RefPointNum;
|
||||
|
||||
#endif
|
||||
736
tools/quake2/qdata_heretic2/qdata.c
Normal file
736
tools/quake2/qdata_heretic2/qdata.c
Normal file
@@ -0,0 +1,736 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "qdata.h"
|
||||
|
||||
void TK_Init();
|
||||
|
||||
qboolean g_compress_pak;
|
||||
qboolean g_release; // don't grab, copy output data to new tree
|
||||
qboolean g_pak; // if true, copy to pak instead of release
|
||||
char g_releasedir[1024]; // c:\quake2\baseq2, etc
|
||||
qboolean g_archive; // don't grab, copy source data to new tree
|
||||
qboolean do3ds;
|
||||
char g_only[256]; // if set, only grab this cd
|
||||
qboolean g_skipmodel; // set true when a cd is not g_only
|
||||
int g_forcemodel = MODEL_AUTO;
|
||||
qboolean g_verbose = false;
|
||||
qboolean g_allow_newskin = true;
|
||||
qboolean g_ignoreTriUV = false;
|
||||
qboolean g_publishOutput = false;
|
||||
|
||||
char *ext_3ds = "3ds";
|
||||
char *ext_tri= "tri";
|
||||
char *trifileext;
|
||||
|
||||
char g_materialFile[256] = "none"; // default for Heretic2
|
||||
char *g_outputDir;
|
||||
extern char *g_publishDir;
|
||||
|
||||
extern qboolean g_nomkdir;
|
||||
|
||||
/*
|
||||
=======================================================
|
||||
|
||||
PAK FILES
|
||||
|
||||
=======================================================
|
||||
*/
|
||||
|
||||
unsigned Com_BlockChecksum (void *buffer, int length);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char name[56];
|
||||
int filepos, filelen;
|
||||
} packfile_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char id[4];
|
||||
int dirofs;
|
||||
int dirlen;
|
||||
} packheader_t;
|
||||
|
||||
packfile_t pfiles[16384];
|
||||
FILE *pakfile;
|
||||
packfile_t *pf;
|
||||
packheader_t pakheader;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
==============
|
||||
BeginPak
|
||||
==============
|
||||
*/
|
||||
void BeginPak (char *outname)
|
||||
{
|
||||
if (!g_pak)
|
||||
return;
|
||||
|
||||
pakfile = SafeOpenWrite (outname);
|
||||
|
||||
// leave space for header
|
||||
SafeWrite (pakfile, &pakheader, sizeof(pakheader));
|
||||
|
||||
pf = pfiles;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
==============
|
||||
ReleaseFile
|
||||
|
||||
Filename should be gamedir reletive.
|
||||
Either copies the file to the release dir, or adds it to
|
||||
the pak file.
|
||||
==============
|
||||
*/
|
||||
void ReleaseFile (char *filename)
|
||||
{
|
||||
int len;
|
||||
byte *buf;
|
||||
char source[1024];
|
||||
char dest[1024];
|
||||
|
||||
if (!g_release)
|
||||
return;
|
||||
|
||||
sprintf (source, "%s%s", gamedir, filename);
|
||||
|
||||
if (!g_pak)
|
||||
{ // copy it
|
||||
sprintf (dest, "%s/%s", g_releasedir, filename);
|
||||
printf ("copying to %s\n", dest);
|
||||
QCopyFile (source, dest);
|
||||
return;
|
||||
}
|
||||
|
||||
// pak it
|
||||
printf ("paking %s\n", filename);
|
||||
if (strlen(filename) >= sizeof(pf->name))
|
||||
Error ("Filename too long for pak: %s", filename);
|
||||
|
||||
len = LoadFile (source, (void **)&buf);
|
||||
|
||||
// segment moved to old.c
|
||||
|
||||
strcpy (pf->name, filename);
|
||||
pf->filepos = LittleLong(ftell(pakfile));
|
||||
pf->filelen = LittleLong(len);
|
||||
pf++;
|
||||
|
||||
SafeWrite (pakfile, buf, len);
|
||||
|
||||
free (buf);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
==============
|
||||
FinishPak
|
||||
==============
|
||||
*/
|
||||
void FinishPak (void)
|
||||
{
|
||||
int dirlen;
|
||||
int d;
|
||||
int i;
|
||||
unsigned checksum;
|
||||
|
||||
if (!g_pak)
|
||||
return;
|
||||
|
||||
pakheader.id[0] = 'P';
|
||||
pakheader.id[1] = 'A';
|
||||
pakheader.id[2] = 'C';
|
||||
pakheader.id[3] = 'K';
|
||||
dirlen = (byte *)pf - (byte *)pfiles;
|
||||
pakheader.dirofs = LittleLong(ftell(pakfile));
|
||||
pakheader.dirlen = LittleLong(dirlen);
|
||||
|
||||
checksum = Com_BlockChecksum ( (void *)pfiles, dirlen );
|
||||
|
||||
SafeWrite (pakfile, pfiles, dirlen);
|
||||
|
||||
i = ftell (pakfile);
|
||||
|
||||
fseek (pakfile, 0, SEEK_SET);
|
||||
SafeWrite (pakfile, &pakheader, sizeof(pakheader));
|
||||
fclose (pakfile);
|
||||
|
||||
d = pf - pfiles;
|
||||
printf ("%i files packed in %i bytes\n",d, i);
|
||||
printf ("checksum: 0x%x\n", checksum);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
===============
|
||||
Cmd_File
|
||||
|
||||
This is only used to cause a file to be copied during a release
|
||||
build (default.cfg, maps, etc)
|
||||
===============
|
||||
*/
|
||||
void Cmd_File (void)
|
||||
{
|
||||
GetScriptToken (false);
|
||||
ReleaseFile (token);
|
||||
}
|
||||
|
||||
/*
|
||||
===============
|
||||
PackDirectory_r
|
||||
|
||||
===============
|
||||
*/
|
||||
#ifdef _WIN32
|
||||
#include "io.h"
|
||||
void PackDirectory_r (char *dir)
|
||||
{
|
||||
struct _finddata_t fileinfo;
|
||||
int handle;
|
||||
char dirstring[1024];
|
||||
char filename[1024];
|
||||
|
||||
sprintf (dirstring, "%s%s/*.*", gamedir, dir);
|
||||
|
||||
handle = _findfirst (dirstring, &fileinfo);
|
||||
if (handle == -1)
|
||||
return;
|
||||
|
||||
do
|
||||
{
|
||||
sprintf (filename, "%s/%s", dir, fileinfo.name);
|
||||
if (fileinfo.attrib & _A_SUBDIR)
|
||||
{ // directory
|
||||
if (fileinfo.name[0] != '.') // don't pak . and ..
|
||||
PackDirectory_r (filename);
|
||||
continue;
|
||||
}
|
||||
// copy or pack the file
|
||||
ReleaseFile (filename);
|
||||
} while (_findnext( handle, &fileinfo ) != -1);
|
||||
|
||||
_findclose (handle);
|
||||
}
|
||||
#else
|
||||
|
||||
#include <sys/types.h>
|
||||
#ifdef NeXT
|
||||
#include <sys/dir.h>
|
||||
#else
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
|
||||
void PackDirectory_r (char *dir)
|
||||
{
|
||||
#ifdef NeXT
|
||||
struct direct **namelist, *ent;
|
||||
#else
|
||||
struct dirent **namelist, *ent;
|
||||
#endif
|
||||
int count;
|
||||
struct stat st;
|
||||
int i;
|
||||
int len;
|
||||
char fullname[1024];
|
||||
char dirstring[1024];
|
||||
char *name;
|
||||
|
||||
sprintf (dirstring, "%s%s", gamedir, dir);
|
||||
count = scandir(dirstring, &namelist, NULL, NULL);
|
||||
|
||||
for (i=0 ; i<count ; i++)
|
||||
{
|
||||
ent = namelist[i];
|
||||
name = ent->d_name;
|
||||
|
||||
if (name[0] == '.')
|
||||
continue;
|
||||
|
||||
sprintf (fullname, "%s/%s", dir, name);
|
||||
sprintf (dirstring, "%s%s/%s", gamedir, dir, name);
|
||||
|
||||
if (stat (dirstring, &st) == -1)
|
||||
Error ("fstating %s", pf->name);
|
||||
if (st.st_mode & S_IFDIR)
|
||||
{ // directory
|
||||
PackDirectory_r (fullname);
|
||||
continue;
|
||||
}
|
||||
|
||||
// copy or pack the file
|
||||
ReleaseFile (fullname);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
===============
|
||||
Cmd_Dir
|
||||
|
||||
This is only used to cause a directory to be copied during a
|
||||
release build (sounds, etc)
|
||||
===============
|
||||
*/
|
||||
void Cmd_Dir (void)
|
||||
{
|
||||
GetScriptToken (false);
|
||||
PackDirectory_r (token);
|
||||
}
|
||||
|
||||
//========================================================================
|
||||
|
||||
#define MAX_RTEX 16384
|
||||
int numrtex;
|
||||
char rtex[MAX_RTEX][64];
|
||||
|
||||
void ReleaseTexture (char *name)
|
||||
{
|
||||
int i;
|
||||
char path[1024];
|
||||
|
||||
for (i=0 ; i<numrtex ; i++)
|
||||
if (!Q_strcasecmp(name, rtex[i]))
|
||||
return;
|
||||
|
||||
if (numrtex == MAX_RTEX)
|
||||
Error ("numrtex == MAX_RTEX");
|
||||
|
||||
strcpy (rtex[i], name);
|
||||
numrtex++;
|
||||
|
||||
sprintf (path, "textures/%s.wal", name);
|
||||
ReleaseFile (path);
|
||||
}
|
||||
|
||||
/*
|
||||
===============
|
||||
Cmd_Maps
|
||||
|
||||
Only relevent for release and pak files.
|
||||
Releases the .bsp files for the maps, and scans all of the files to
|
||||
build a list of all textures used, which are then released.
|
||||
===============
|
||||
*/
|
||||
void Cmd_Maps (void)
|
||||
{
|
||||
char map[1024];
|
||||
int i;
|
||||
|
||||
while (ScriptTokenAvailable ())
|
||||
{
|
||||
GetScriptToken (false);
|
||||
sprintf (map, "maps/%s.bsp", token);
|
||||
ReleaseFile (map);
|
||||
|
||||
if (!g_release)
|
||||
continue;
|
||||
|
||||
// get all the texture references
|
||||
sprintf (map, "%smaps/%s.bsp", gamedir, token);
|
||||
LoadBSPFileTexinfo (map);
|
||||
for (i=0 ; i<numtexinfo ; i++)
|
||||
ReleaseTexture (texinfo[i].texture);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//==============================================================
|
||||
|
||||
/*
|
||||
===============
|
||||
ParseScript
|
||||
===============
|
||||
*/
|
||||
void ParseScript (void)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
do
|
||||
{ // look for a line starting with a $ command
|
||||
GetScriptToken (true);
|
||||
if (endofscript)
|
||||
return;
|
||||
if (token[0] == '$')
|
||||
break;
|
||||
while (ScriptTokenAvailable())
|
||||
GetScriptToken (false);
|
||||
} while (1);
|
||||
|
||||
//
|
||||
// model commands
|
||||
//
|
||||
if (!strcmp (token, "$modelname"))
|
||||
MODELCMD_Modelname (MODEL_MD2);
|
||||
else if (!strcmp (token, "$cd"))
|
||||
MODELCMD_Cd (MODEL_MD2);
|
||||
else if (!strcmp (token, "$origin"))
|
||||
MODELCMD_Origin (MODEL_MD2);
|
||||
else if (!strcmp (token, "$cluster"))
|
||||
MODELCMD_Cluster (MODEL_MD2);
|
||||
else if (!strcmp (token, "$base"))
|
||||
MODELCMD_Base (MODEL_MD2);
|
||||
else if (!strcmp (token, "$scale"))
|
||||
MODELCMD_ScaleUp (MODEL_MD2);
|
||||
else if (!strcmp (token, "$frame"))
|
||||
MODELCMD_Frame (MODEL_MD2);
|
||||
else if (!strcmp (token, "$skin"))
|
||||
MODELCMD_Skin (MODEL_MD2);
|
||||
else if (!strcmp (token, "$skinsize"))
|
||||
MODELCMD_Skinsize (MODEL_MD2);
|
||||
//
|
||||
// flexible model commands
|
||||
//
|
||||
else if (!strcmp (token, "$fm_modelname"))
|
||||
MODELCMD_Modelname (MODEL_FM);
|
||||
else if (!strcmp (token, "$fm_base"))
|
||||
MODELCMD_Base (MODEL_FM);
|
||||
else if (!strcmp (token, "$fm_basest"))
|
||||
MODELCMD_BaseST (MODEL_FM);
|
||||
else if (!strcmp (token, "$fm_cd"))
|
||||
MODELCMD_Cd (MODEL_FM);
|
||||
else if (!strcmp (token, "$fm_origin"))
|
||||
MODELCMD_Origin (MODEL_FM);
|
||||
else if (!strcmp (token, "$fm_cluster"))
|
||||
MODELCMD_Cluster (MODEL_FM);
|
||||
else if (!strcmp (token, "$fm_skeleton"))
|
||||
MODELCMD_Skeleton (MODEL_FM);
|
||||
else if (!strcmp (token, "$fm_scale"))
|
||||
MODELCMD_ScaleUp (MODEL_FM);
|
||||
else if (!strcmp (token, "$fm_frame"))
|
||||
MODELCMD_Frame (MODEL_FM);
|
||||
else if (!strcmp (token, "$fm_skeletal_frame")) // left in for compadibility with qdt already using fm_skeletal_frame
|
||||
MODELCMD_Frame (MODEL_FM);
|
||||
else if (!strcmp (token, "$fm_skin"))
|
||||
MODELCMD_Skin (MODEL_FM);
|
||||
else if (!strcmp (token, "$fm_skinsize"))
|
||||
MODELCMD_Skinsize (MODEL_FM);
|
||||
else if (!strcmp (token, "$fm_begin_group"))
|
||||
MODELCMD_BeginGroup(MODEL_FM);
|
||||
else if (!strcmp (token, "$fm_end_group"))
|
||||
MODELCMD_EndGroup(MODEL_FM);
|
||||
else if (!strcmp (token, "$fm_referenced"))
|
||||
MODELCMD_Referenced(MODEL_FM);
|
||||
else if (!strcmp (token, "$fm_node_order"))
|
||||
MODELCMD_NodeOrder(MODEL_FM);
|
||||
|
||||
//
|
||||
// sprite commands
|
||||
//
|
||||
else if (!strcmp (token, "$spritename"))
|
||||
Cmd_SpriteName ();
|
||||
else if (!strcmp (token, "$sprdir"))
|
||||
Cmd_Sprdir ();
|
||||
else if (!strcmp (token, "$load"))
|
||||
Cmd_Load ();
|
||||
else if (!strcmp (token, "$spriteframe"))
|
||||
Cmd_SpriteFrame ();
|
||||
//
|
||||
// image commands
|
||||
//
|
||||
else if (!strcmpi (token, "$grab"))
|
||||
Cmd_Grab ();
|
||||
else if (!strcmpi (token, "$raw"))
|
||||
Cmd_Raw ();
|
||||
else if (!strcmpi (token, "$colormap"))
|
||||
Cmd_Colormap ();
|
||||
else if (!strcmpi (token, "$mippal"))
|
||||
Cmd_Mippal ();
|
||||
else if (!strcmpi (token, "$mipdir"))
|
||||
Cmd_Mipdir ();
|
||||
else if (!strcmpi (token, "$mip"))
|
||||
Cmd_Mip ();
|
||||
else if (!strcmp (token, "$environment"))
|
||||
Cmd_Environment ();
|
||||
//
|
||||
// pics
|
||||
//
|
||||
else if (!strcmp (token, "$picdir"))
|
||||
Cmd_Picdir ();
|
||||
else if (!strcmp (token, "$pic"))
|
||||
Cmd_Pic ();
|
||||
//
|
||||
// book
|
||||
//
|
||||
else if (!strcmp (token, "$bookdir"))
|
||||
Cmd_Bookdir ();
|
||||
else if (!strcmp (token, "$book"))
|
||||
Cmd_Book ();
|
||||
//
|
||||
// tmix
|
||||
//
|
||||
else if (!strcmp (token, "$texturemix"))
|
||||
Cmd_TextureMix ();
|
||||
//
|
||||
// video
|
||||
//
|
||||
else if (!strcmp (token, "$video"))
|
||||
Cmd_Video ();
|
||||
//
|
||||
// misc
|
||||
//
|
||||
else if (!strcmp (token, "$file"))
|
||||
Cmd_File ();
|
||||
else if (!strcmp (token, "$dir"))
|
||||
Cmd_Dir ();
|
||||
else if (!strcmp (token, "$maps"))
|
||||
Cmd_Maps ();
|
||||
else if (!strcmp (token, "$alphalight"))
|
||||
Cmd_Alphalight ();
|
||||
else if (!strcmp (token, "$inverse16table" ))
|
||||
Cmd_Inverse16Table();
|
||||
else
|
||||
Error ("bad command %s\n", token);
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================
|
||||
|
||||
/*
|
||||
==============
|
||||
main
|
||||
==============
|
||||
*/
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
char path[1024];
|
||||
char *basedir;
|
||||
double starttime, endtime;
|
||||
|
||||
printf ("Qdata Plus : "__TIME__" "__DATE__"\n");
|
||||
|
||||
starttime = I_FloatTime();
|
||||
basedir = NULL;
|
||||
|
||||
TK_Init();
|
||||
ExpandWildcards (&argc, &argv);
|
||||
|
||||
for (i=1 ; i<argc ; i++)
|
||||
{
|
||||
if (!strcmp(argv[i], "-archive"))
|
||||
{
|
||||
// -archive f:/quake2/release/dump_11_30
|
||||
archive = true;
|
||||
strcpy (archivedir, argv[i+1]);
|
||||
printf ("Archiving source to: %s\n", archivedir);
|
||||
i++;
|
||||
}
|
||||
else if (!strcmp(argv[i], "-release"))
|
||||
{
|
||||
g_release = true;
|
||||
strcpy (g_releasedir, argv[i+1]);
|
||||
printf ("Copy output to: %s\n", g_releasedir);
|
||||
i++;
|
||||
}
|
||||
else if (!strcmp(argv[i], "-base"))
|
||||
{
|
||||
i++;
|
||||
basedir = argv[i];
|
||||
}
|
||||
else if (!strcmp(argv[i], "-compress"))
|
||||
{
|
||||
g_compress_pak = true;
|
||||
printf ("Compressing pakfile\n");
|
||||
}
|
||||
else if (!strcmp(argv[i], "-pak"))
|
||||
{
|
||||
g_release = true;
|
||||
g_pak = true;
|
||||
printf ("Building pakfile: %s\n", argv[i+1]);
|
||||
BeginPak (argv[i+1]);
|
||||
i++;
|
||||
}
|
||||
else if (!strcmp(argv[i], "-only"))
|
||||
{
|
||||
strcpy (g_only, argv[i+1]);
|
||||
printf ("Only grabbing %s\n", g_only);
|
||||
i++;
|
||||
}
|
||||
else if (!strcmpi(argv[i], "-keypress"))
|
||||
{
|
||||
g_dokeypress = true;
|
||||
}
|
||||
else if (!strcmp(argv[i], "-3ds"))
|
||||
{
|
||||
do3ds = true;
|
||||
printf ("loading .3ds files\n");
|
||||
}
|
||||
else if (!strcmp(argv[i], "-materialfile"))
|
||||
{
|
||||
strcpy(g_materialFile, argv[i+1]);
|
||||
printf("Setting material file to %s\n", g_materialFile);
|
||||
i++;
|
||||
}
|
||||
/* else if (!strcmpi(argv[i], "-newgen"))
|
||||
{
|
||||
if (i < argc-4)
|
||||
{
|
||||
printf("run new triangle grouping routine here\n");
|
||||
NewGen(argv[i+1],argv[i+2],atoi(argv[i+3]),atoi(argv[i+4]));
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("qdata -newskin <base.hrc> <skin.pcx> width height\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
*/ else if (!strcmpi(argv[i], "-genskin"))
|
||||
{
|
||||
i++;
|
||||
if (i < argc-3)
|
||||
{
|
||||
GenSkin(argv[i],argv[i+1],atol(argv[i+2]),atol(argv[i+3]));
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("qdata -genskin <base.hrc> <skin.pcx> <desired width> <desired height>\n");
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
else if (!strcmpi(argv[i], "-noopts"))
|
||||
{
|
||||
g_no_opimizations = true;
|
||||
printf("not performing optimizations\n");
|
||||
}
|
||||
else if (!strcmpi(argv[i], "-md2"))
|
||||
{
|
||||
g_forcemodel = MODEL_MD2;
|
||||
}
|
||||
else if (!strcmpi(argv[i], "-fm"))
|
||||
{
|
||||
g_forcemodel = MODEL_FM;
|
||||
}
|
||||
else if (!strcmpi(argv[i], "-verbose"))
|
||||
{
|
||||
g_verbose = true;
|
||||
}
|
||||
else if (!strcmpi(argv[i], "-oldskin"))
|
||||
{
|
||||
g_allow_newskin = false;
|
||||
}
|
||||
else if (!strcmpi(argv[i], "-ignoreUV"))
|
||||
{
|
||||
g_ignoreTriUV = true;
|
||||
}
|
||||
else if (!strcmpi(argv[i], "-publish"))
|
||||
{
|
||||
g_publishOutput = true;
|
||||
}
|
||||
else if (!strcmpi(argv[i], "-nomkdir"))
|
||||
{
|
||||
g_nomkdir = true;
|
||||
}
|
||||
else if (argv[i][0] == '-')
|
||||
Error ("Unknown option \"%s\"", argv[i]);
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (i >= argc)
|
||||
{
|
||||
Error ("usage: qdata [-archive <directory>]\n"
|
||||
" [-release <directory>]\n"
|
||||
" [-base <directory>]\n"
|
||||
" [-compress]\n"
|
||||
" [-pak <file>]\n"
|
||||
" [-only <model>]\n"
|
||||
" [-keypress]\n"
|
||||
" [-3ds]\n"
|
||||
" [-materialfile <file>]\n"
|
||||
" [-noopts]\n"
|
||||
" [-md2]\n"
|
||||
" [-fm]\n"
|
||||
" [-verbose]\n"
|
||||
" [-ignoreUV]\n"
|
||||
" [-oldskin]\n"
|
||||
" [-publish]\n"
|
||||
" [-nomkdir]\n"
|
||||
" file.qdt\n"
|
||||
"or\n"
|
||||
" qdata -genskin <base.hrc> <skin.pcx> <desired width> <desired height>");
|
||||
}
|
||||
|
||||
if (do3ds)
|
||||
trifileext = ext_3ds;
|
||||
else
|
||||
trifileext = ext_tri;
|
||||
|
||||
for ( ; i<argc ; i++)
|
||||
{
|
||||
printf ("--------------- %s ---------------\n", argv[i]);
|
||||
// load the script
|
||||
strcpy (path, argv[i]);
|
||||
DefaultExtension (path, ".qdt");
|
||||
DefaultExtension(g_materialFile, ".mat");
|
||||
SetQdirFromPath (path);
|
||||
|
||||
printf("workingdir='%s'\n", gamedir);
|
||||
if (basedir)
|
||||
{
|
||||
qdir[0] = 0;
|
||||
g_outputDir = basedir;
|
||||
}
|
||||
|
||||
printf("outputdir='%s'\n", g_outputDir);
|
||||
|
||||
QFile_ReadMaterialTypes(g_materialFile);
|
||||
LoadScriptFile (ExpandArg(path));
|
||||
|
||||
//
|
||||
// parse it
|
||||
//
|
||||
ParseScript ();
|
||||
|
||||
// write out the last model
|
||||
FinishModel ();
|
||||
FMFinishModel ();
|
||||
FinishSprite ();
|
||||
}
|
||||
|
||||
if (total_textures)
|
||||
{
|
||||
printf("\n");
|
||||
printf("Total textures processed: %d\n",total_textures);
|
||||
printf("Average size: %d x %d\n",total_x / total_textures, total_y / total_textures);
|
||||
}
|
||||
|
||||
if (g_pak)
|
||||
FinishPak ();
|
||||
|
||||
endtime = I_FloatTime();
|
||||
printf("Time elapsed: %f\n", endtime-starttime);
|
||||
|
||||
if (g_dokeypress)
|
||||
{
|
||||
printf("Success! ... Hit a key: ");
|
||||
getchar();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
166
tools/quake2/qdata_heretic2/qdata.h
Normal file
166
tools/quake2/qdata_heretic2/qdata.h
Normal file
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
// qdata.h
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "cmdlib.h"
|
||||
#include "inout.h"
|
||||
#include "scriplib.h"
|
||||
#include "mathlib.h"
|
||||
#include "trilib.h"
|
||||
#include "lbmlib.h"
|
||||
#include "her2_threads.h"
|
||||
#include "l3dslib.h"
|
||||
#include "bspfile.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
#define stricmp strcasecmp
|
||||
#define strcmpi strcasecmp
|
||||
#endif
|
||||
|
||||
|
||||
#define MODEL_AUTO 0
|
||||
#define MODEL_MD2 1
|
||||
#define MODEL_FM 2
|
||||
|
||||
// Model cover functions (to allow the forcing of a model type)
|
||||
void MODELCMD_Modelname (int modeltype);
|
||||
void MODELCMD_Cd (int modeltype);
|
||||
void MODELCMD_Origin (int modeltype);
|
||||
void MODELCMD_Jointed (int modeltype);
|
||||
void MODELCMD_Cluster (int modeltype);
|
||||
void MODELCMD_Base (int modeltype);
|
||||
void MODELCMD_BaseST (int modeltype);
|
||||
void MODELCMD_ScaleUp (int modeltype);
|
||||
void MODELCMD_Frame (int modeltype);
|
||||
void MODELCMD_Skin (int modeltype);
|
||||
void MODELCMD_Skinsize (int modeltype);
|
||||
void MODELCMD_Skeleton (int modeltype);
|
||||
void MODELCMD_SkeletalFrame (int modeltype);
|
||||
void MODELCMD_BeginGroup(int modeltype);
|
||||
void MODELCMD_EndGroup(int modeltype);
|
||||
void MODELCMD_Referenced(int modeltype);
|
||||
void MODELCMD_NodeOrder(int modeltype);
|
||||
|
||||
void Cmd_Modelname (void);
|
||||
void Cmd_Base (void);
|
||||
void Cmd_Cd (void);
|
||||
void Cmd_Origin (void);
|
||||
void Cmd_ScaleUp (void);
|
||||
void Cmd_Frame (void);
|
||||
void Cmd_Skin (void);
|
||||
void Cmd_Skinsize (void);
|
||||
void FinishModel (void);
|
||||
void Cmd_Cluster (void);
|
||||
|
||||
// Flexible Models
|
||||
//void Cmd_FMModelname (void);
|
||||
void Cmd_FMBase (qboolean GetST);
|
||||
void Cmd_FMCd (void);
|
||||
//void Cmd_FMOrigin (void);
|
||||
void Cmd_FMCluster();
|
||||
void Cmd_FMSkeleton();
|
||||
//void Cmd_FMScaleUp (void);
|
||||
void Cmd_FMFrame (void);
|
||||
void Cmd_FMSkeletalFrame();
|
||||
void Cmd_FMSkin (void);
|
||||
//void Cmd_FMSkinsize (void);
|
||||
void Cmd_FMBeginGroup(void);
|
||||
void Cmd_FMEndGroup(void);
|
||||
void Cmd_FMReferenced();
|
||||
void Cmd_FMNodeOrder(void);
|
||||
void FMFinishModel (void);
|
||||
void GenSkin(char *ModelFile, char *OutputName, int Width, int Height);
|
||||
void NewGen (char *ModelFile, char *OutputName, int width, int height);
|
||||
|
||||
|
||||
void Cmd_Inverse16Table( void );
|
||||
|
||||
void Cmd_SpriteName (void);
|
||||
void Cmd_Load (void);
|
||||
void Cmd_SpriteFrame (void);
|
||||
void Cmd_Sprdir (void);
|
||||
void FinishSprite (void);
|
||||
|
||||
void Cmd_Grab (void);
|
||||
void Cmd_Raw (void);
|
||||
void Cmd_Mip (void);
|
||||
void Cmd_Environment (void);
|
||||
void Cmd_Colormap (void);
|
||||
|
||||
void Cmd_File (void);
|
||||
void Cmd_Dir (void);
|
||||
void Cmd_StartWad (void);
|
||||
void Cmd_EndWad (void);
|
||||
void Cmd_Mippal (void);
|
||||
void Cmd_Mipdir (void);
|
||||
void Cmd_Alphalight (void);
|
||||
|
||||
void Cmd_Picdir (void);
|
||||
void Cmd_Pic (void);
|
||||
|
||||
void Cmd_Bookdir (void);
|
||||
void Cmd_Book (void);
|
||||
|
||||
void Cmd_TextureMix (void);
|
||||
|
||||
void Cmd_Video (void);
|
||||
|
||||
//void RemapZero (byte *pixels, byte *palette, int width, int height);
|
||||
|
||||
void ReleaseFile (char *filename);
|
||||
|
||||
extern byte *byteimage, *lbmpalette;
|
||||
extern int byteimagewidth, byteimageheight;
|
||||
extern qboolean TrueColorImage;
|
||||
extern unsigned *longimage;
|
||||
extern int longimagewidth, longimageheight;
|
||||
|
||||
extern qboolean g_release; // don't grab, copy output data to new tree
|
||||
extern char g_releasedir[1024]; // c:\quake2\baseq2, etc
|
||||
extern qboolean g_archive; // don't grab, copy source data to new tree
|
||||
extern qboolean do3ds;
|
||||
extern char g_only[256]; // if set, only grab this cd
|
||||
extern qboolean g_skipmodel; // set true when a cd is not g_only
|
||||
extern qboolean g_no_opimizations;
|
||||
extern int g_forcemodel;
|
||||
extern qboolean g_verbose;
|
||||
extern qboolean g_allow_newskin;
|
||||
extern qboolean g_ignoreTriUV; //from qdata.c
|
||||
extern qboolean g_dokeypress;
|
||||
|
||||
extern char *trifileext;
|
||||
|
||||
extern char g_materialFile[256];
|
||||
|
||||
extern unsigned total_x;
|
||||
extern unsigned total_y;
|
||||
extern unsigned total_textures;
|
||||
|
||||
miptex_t *CreateMip(byte *data, unsigned width, unsigned height, byte *palette, int *FinalSize, qboolean mip);
|
||||
miptex32_t *CreateMip32(unsigned *data, unsigned width, unsigned height, int *FinalSize, qboolean mip);
|
||||
314
tools/quake2/qdata_heretic2/qdata3_heretic2.dsp
Normal file
314
tools/quake2/qdata_heretic2/qdata3_heretic2.dsp
Normal file
@@ -0,0 +1,314 @@
|
||||
# Microsoft Developer Studio Project File - Name="qdata3_heretic2" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||
|
||||
CFG=qdata3_heretic2 - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "qdata3_heretic2.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "qdata3_heretic2.mak" CFG="qdata3_heretic2 - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "qdata3_heretic2 - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "qdata3_heretic2 - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "qdata3_heretic2 - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
F90=df.exe
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /MD /W3 /GX- /Zi /O2 /I "./common" /I "./qcommon" /I "." /I "..\..\..\..\libxml2\include" /I "..\..\..\libs" /I "..\..\..\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FR /FD /c
|
||||
# SUBTRACT CPP /YX
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||
# ADD LINK32 wsock32.lib l_net.lib mathlib.lib /nologo /subsystem:console /map /machine:I386 /out:"Release/qdata3.exe" /libpath:"..\..\..\libs\l_net\release" /libpath:"..\..\..\..\libxml2\win32\libxml2\release_so" /libpath:"..\..\..\libs\mathlib\release"
|
||||
|
||||
!ELSEIF "$(CFG)" == "qdata3_heretic2 - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
F90=df.exe
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MDd /W3 /Gm /GX- /ZI /Od /I "./common" /I "./qcommon" /I "." /I "..\..\..\..\libxml2\include" /I "..\..\..\libs" /I "..\..\..\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /FD /GZ /c
|
||||
# SUBTRACT CPP /YX
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 wsock32.lib l_net.lib mathlib.lib /nologo /subsystem:console /profile /map /debug /machine:I386 /out:"Debug/qdata3.exe" /libpath:"..\..\..\libs\l_net\debug" /libpath:"..\..\..\..\libxml2\win32\libxml2\debug_so" /libpath:"..\..\..\libs\mathlib\debug"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "qdata3_heretic2 - Win32 Release"
|
||||
# Name "qdata3_heretic2 - Win32 Debug"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\animcomp.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\book.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\common\bspfile.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\common\cmdlib.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\fmodels.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\images.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\common\inout.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jointed.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\common\l3dslib.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\common\lbmlib.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\common\mathlib.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\common\md4.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\models.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\common\path_init.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\pics.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\qd_skeletons.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\qdata.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\common\qfiles.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\qcommon\reference.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\qcommon\resourcemanager.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\common\scriplib.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\qcommon\skeletons.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sprites.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\svdcmp.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\tables.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\common\threads.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\tmix.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\common\token.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\common\trilib.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\video.c
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\adpcm.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\animcomp.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\anorms.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\common\bspfile.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\common\cmdlib.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\common\her2_threads.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\common\inout.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jointed.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\joints.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\common\l3dslib.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\common\lbmlib.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\common\mathlib.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\qd_fmodel.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\qd_skeletons.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\qdata.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\common\qfiles.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\qcommon\reference.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\resource.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\qcommon\resourcemanager.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\common\scriplib.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\qcommon\skeletons.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\common\token.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\common\trilib.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Resource Files"
|
||||
|
||||
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
||||
329
tools/quake2/qdata_heretic2/qdata3_heretic2.vcproj
Normal file
329
tools/quake2/qdata_heretic2/qdata3_heretic2.vcproj
Normal file
@@ -0,0 +1,329 @@
|
||||
<?xml version="1.0" encoding = "Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="7.00"
|
||||
Name="qdata3_heretic2"
|
||||
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"/>
|
||||
</Platforms>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory=".\Release"
|
||||
IntermediateDirectory=".\Release"
|
||||
ConfigurationType="1"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="FALSE"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
InlineFunctionExpansion="1"
|
||||
AdditionalIncludeDirectories="./common,./qcommon,.,..\..\..\..\libxml2\include,..\..\..\libs,..\..\..\include"
|
||||
PreprocessorDefinitions="WIN32,NDEBUG,_CONSOLE"
|
||||
StringPooling="TRUE"
|
||||
RuntimeLibrary="2"
|
||||
EnableFunctionLevelLinking="TRUE"
|
||||
PrecompiledHeaderFile=".\Release/qdata3_heretic2.pch"
|
||||
AssemblerListingLocation=".\Release/"
|
||||
ObjectFile=".\Release/"
|
||||
ProgramDataBaseFileName=".\Release/"
|
||||
BrowseInformation="1"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="TRUE"
|
||||
DebugInformationFormat="3"
|
||||
CompileAs="0"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalOptions="/MACHINE:I386"
|
||||
AdditionalDependencies="wsock32.lib"
|
||||
OutputFile="Release/qdata3.exe"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="TRUE"
|
||||
AdditionalLibraryDirectories="..\..\..\libs\l_net\release,..\..\..\..\libxml2\win32\libxml2\release_so,..\..\..\libs\mathlib\release"
|
||||
ProgramDatabaseFile=".\Release/qdata3.pdb"
|
||||
GenerateMapFile="TRUE"
|
||||
MapFileName=".\Release/qdata3.map"
|
||||
SubSystem="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
TypeLibraryName=".\Release/qdata3_heretic2.tlb"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="NDEBUG"
|
||||
Culture="1033"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory=".\Debug"
|
||||
IntermediateDirectory=".\Debug"
|
||||
ConfigurationType="1"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="FALSE"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="./common,./qcommon,.,..\..\..\..\libxml2\include,..\..\..\libs,..\..\..\include"
|
||||
PreprocessorDefinitions="WIN32,_DEBUG,_CONSOLE"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
PrecompiledHeaderFile=".\Debug/qdata3_heretic2.pch"
|
||||
AssemblerListingLocation=".\Debug/"
|
||||
ObjectFile=".\Debug/"
|
||||
ProgramDataBaseFileName=".\Debug/"
|
||||
BrowseInformation="1"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="TRUE"
|
||||
DebugInformationFormat="4"
|
||||
CompileAs="0"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalOptions="/MACHINE:I386"
|
||||
AdditionalDependencies="wsock32.lib"
|
||||
OutputFile="Debug/qdata3.exe"
|
||||
LinkIncremental="2"
|
||||
SuppressStartupBanner="TRUE"
|
||||
AdditionalLibraryDirectories="..\..\..\libs\l_net\debug,..\..\..\..\libxml2\win32\libxml2\debug_so,..\..\..\libs\mathlib\debug"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile=".\Debug/qdata3.pdb"
|
||||
GenerateMapFile="TRUE"
|
||||
MapFileName=".\Debug/qdata3.map"
|
||||
SubSystem="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
TypeLibraryName=".\Debug/qdata3_heretic2.tlb"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
Culture="1033"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
|
||||
<File
|
||||
RelativePath=".\animcomp.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\book.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\common\bspfile.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\common\cmdlib.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\fmodels.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\images.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\common\inout.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\jointed.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\common\l3dslib.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\common\lbmlib.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\common\mathlib.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\common\md4.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\models.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\common\path_init.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\pics.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\qd_skeletons.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\qdata.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\common\qfiles.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\qcommon\reference.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\qcommon\resourcemanager.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\common\scriplib.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\qcommon\skeletons.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\sprites.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\svdcmp.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\tables.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\common\threads.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\tmix.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\common\token.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\common\trilib.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\video.c">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl">
|
||||
<File
|
||||
RelativePath=".\adpcm.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\animcomp.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\anorms.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\common\bspfile.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\common\cmdlib.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\common\her2_threads.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\common\inout.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\jointed.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\joints.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\common\l3dslib.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\common\lbmlib.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\common\mathlib.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\qd_fmodel.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\qd_skeletons.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\qdata.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\common\qfiles.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\qcommon\reference.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\resource.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\qcommon\resourcemanager.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\common\scriplib.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\qcommon\skeletons.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\common\token.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\common\trilib.h">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="debug"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath="..\..\..\..\libxml2\win32\binaries-debug\libxml2.lib">
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
ExcludedFromBuild="TRUE">
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="release"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath="..\..\..\..\libxml2\win32\binaries-release\libxml2.lib">
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
ExcludedFromBuild="TRUE">
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
18
tools/quake2/qdata_heretic2/resource.h
Normal file
18
tools/quake2/qdata_heretic2/resource.h
Normal file
@@ -0,0 +1,18 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Developer Studio generated include file.
|
||||
// Used by Script1.rc
|
||||
//
|
||||
#define IDI_ICON1 101
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NO_MFC 1
|
||||
#define _APS_3D_CONTROLS 1
|
||||
#define _APS_NEXT_RESOURCE_VALUE 102
|
||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||
#define _APS_NEXT_CONTROL_VALUE 1000
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
||||
BIN
tools/quake2/qdata_heretic2/script1.aps
Normal file
BIN
tools/quake2/qdata_heretic2/script1.aps
Normal file
Binary file not shown.
115
tools/quake2/qdata_heretic2/script1.rc
Normal file
115
tools/quake2/qdata_heretic2/script1.rc
Normal file
@@ -0,0 +1,115 @@
|
||||
//Microsoft Developer Studio generated resource script.
|
||||
//
|
||||
#include "resource.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "afxres.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// English (U.S.) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
#pragma code_page(1252)
|
||||
#endif //_WIN32
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Icon
|
||||
//
|
||||
|
||||
// Icon with lowest ID value placed first to ensure application icon
|
||||
// remains consistent on all systems.
|
||||
IDI_ICON1 ICON DISCARDABLE "icon1.ico"
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"resource.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"#include ""afxres.h""\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
3 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
|
||||
#ifndef _MAC
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Version
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,0,0,1
|
||||
PRODUCTVERSION 1,0,0,1
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS 0x40004L
|
||||
FILETYPE 0x1L
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904b0"
|
||||
BEGIN
|
||||
VALUE "Comments", "Heavily modified from original ID tool\0"
|
||||
VALUE "CompanyName", "Raven Software\0"
|
||||
VALUE "FileDescription", "qdata\0"
|
||||
VALUE "FileVersion", "2.0\0"
|
||||
VALUE "InternalName", "qdata\0"
|
||||
VALUE "LegalCopyright", "Copyright © 1998\0"
|
||||
VALUE "OriginalFilename", "qdata.exe\0"
|
||||
VALUE "ProductName", "Raven Software qdata\0"
|
||||
VALUE "ProductVersion", "2.0\0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x409, 1200
|
||||
END
|
||||
END
|
||||
|
||||
#endif // !_MAC
|
||||
|
||||
#endif // English (U.S.) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#ifndef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 3 resource.
|
||||
//
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // not APSTUDIO_INVOKED
|
||||
|
||||
349
tools/quake2/qdata_heretic2/sprites.c
Normal file
349
tools/quake2/qdata_heretic2/sprites.c
Normal file
@@ -0,0 +1,349 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
|
||||
#include "qdata.h"
|
||||
|
||||
#define MAX_SPRFRAMES MAX_MD2SKINS
|
||||
|
||||
dsprite_t sprite;
|
||||
dsprframe_t frames[MAX_SPRFRAMES];
|
||||
|
||||
byte *byteimage, *lbmpalette;
|
||||
int byteimagewidth, byteimageheight;
|
||||
|
||||
qboolean TrueColorImage;
|
||||
unsigned *longimage;
|
||||
int longimagewidth, longimageheight;
|
||||
|
||||
char spritename[1024];
|
||||
|
||||
|
||||
void FinishSprite (void);
|
||||
void Cmd_Spritename (void);
|
||||
|
||||
char spr_prefix[1024];
|
||||
char pic_prefix[1024];
|
||||
|
||||
extern char *g_outputDir;
|
||||
|
||||
|
||||
/*
|
||||
==============
|
||||
FinishSprite
|
||||
==============
|
||||
*/
|
||||
void FinishSprite (void)
|
||||
{
|
||||
FILE *spriteouthandle;
|
||||
int i, curframe;
|
||||
dsprite_t spritetemp;
|
||||
char savename[1024];
|
||||
|
||||
if (sprite.numframes == 0)
|
||||
return;
|
||||
|
||||
if (!strlen(spritename))
|
||||
Error ("Didn't name sprite file");
|
||||
|
||||
sprintf (savename, "%sSprites/%s/%s.sp2", g_outputDir, spr_prefix, spritename);
|
||||
|
||||
if (g_release)
|
||||
{
|
||||
char name[1024];
|
||||
|
||||
sprintf (name, "%s.sp2", spritename);
|
||||
ReleaseFile (name);
|
||||
spritename[0] = 0; // clear for a new sprite
|
||||
sprite.numframes = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
printf ("saving in %s\n", savename);
|
||||
CreatePath (savename);
|
||||
spriteouthandle = SafeOpenWrite (savename);
|
||||
|
||||
|
||||
//
|
||||
// write out the sprite header
|
||||
//
|
||||
spritetemp.ident = LittleLong (IDSPRITEHEADER);
|
||||
spritetemp.version = LittleLong (SPRITE_VERSION);
|
||||
spritetemp.numframes = LittleLong (sprite.numframes);
|
||||
|
||||
SafeWrite (spriteouthandle, &spritetemp, 12);
|
||||
|
||||
//
|
||||
// write out the frames
|
||||
//
|
||||
curframe = 0;
|
||||
|
||||
for (i=0 ; i<sprite.numframes ; i++)
|
||||
{
|
||||
frames[i].width = LittleLong(frames[i].width);
|
||||
frames[i].height = LittleLong(frames[i].height);
|
||||
frames[i].origin_x = LittleLong(frames[i].origin_x);
|
||||
frames[i].origin_y = LittleLong(frames[i].origin_y);
|
||||
}
|
||||
SafeWrite (spriteouthandle, frames, sizeof(frames[0])*sprite.numframes);
|
||||
|
||||
fclose (spriteouthandle);
|
||||
|
||||
spritename[0] = 0; // clear for a new sprite
|
||||
sprite.numframes = 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
===============
|
||||
Cmd_Load
|
||||
===============
|
||||
*/
|
||||
void Cmd_Load (void)
|
||||
{
|
||||
char *name;
|
||||
|
||||
GetScriptToken (false);
|
||||
|
||||
if (g_release)
|
||||
return;
|
||||
|
||||
name = ExpandPathAndArchive(token);
|
||||
|
||||
// load the image
|
||||
printf ("loading %s\n", name);
|
||||
TrueColorImage = LoadAnyImage (name, &byteimage, &lbmpalette, &byteimagewidth, &byteimageheight);
|
||||
|
||||
if (!TrueColorImage)
|
||||
{
|
||||
// RemapZero (byteimage, lbmpalette, byteimagewidth, byteimageheight);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (longimage)
|
||||
free(longimage);
|
||||
longimage = (unsigned *)byteimage;
|
||||
longimagewidth = byteimagewidth;
|
||||
longimageheight = byteimageheight;
|
||||
|
||||
byteimage = NULL;
|
||||
byteimagewidth = 0;
|
||||
byteimageheight = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
===============
|
||||
Cmd_SpriteFrame
|
||||
===============
|
||||
*/
|
||||
|
||||
void Cmd_SpriteFrame (void)
|
||||
{
|
||||
int x,y,xl,yl,xh,yh,w,h;
|
||||
dsprframe_t *pframe;
|
||||
int ox, oy, linedelta, size;
|
||||
// byte *cropped;
|
||||
char filename[1024];
|
||||
miptex_t *qtex;
|
||||
miptex32_t *qtex32;
|
||||
unsigned *destl, *sourcel;
|
||||
unsigned bufferl[256*256];
|
||||
byte *dest, *source;
|
||||
byte buffer[256*256];
|
||||
|
||||
GetScriptToken (false);
|
||||
xl = atoi (token);
|
||||
GetScriptToken (false);
|
||||
yl = atoi (token);
|
||||
GetScriptToken (false);
|
||||
w = atoi (token);
|
||||
GetScriptToken (false);
|
||||
h = atoi (token);
|
||||
|
||||
// origin offset is optional
|
||||
if (ScriptTokenAvailable ())
|
||||
{
|
||||
GetScriptToken (false);
|
||||
ox = atoi (token);
|
||||
GetScriptToken (false);
|
||||
oy = atoi (token);
|
||||
}
|
||||
else
|
||||
{
|
||||
ox = w/2;
|
||||
oy = h/2;
|
||||
}
|
||||
|
||||
if ((xl & 0x0f) || (yl & 0x0f) || (w & 0x0f) || (h & 0x0f))
|
||||
Error ("Sprite dimensions not multiples of 16\n");
|
||||
|
||||
if ((w > 256) || (h > 256))
|
||||
Error ("Sprite has a dimension longer than 256");
|
||||
|
||||
xh = xl+w;
|
||||
yh = yl+h;
|
||||
|
||||
if (sprite.numframes >= MAX_SPRFRAMES)
|
||||
Error ("Too many frames; increase MAX_SPRFRAMES\n");
|
||||
|
||||
pframe = &frames[sprite.numframes];
|
||||
pframe->width = w;
|
||||
pframe->height = h;
|
||||
pframe->origin_x = ox;
|
||||
pframe->origin_y = oy;
|
||||
|
||||
if (g_release)
|
||||
{
|
||||
ReleaseFile (pframe->name);
|
||||
return;
|
||||
}
|
||||
|
||||
if (TrueColorImage)
|
||||
{
|
||||
sprintf (filename, "%ssprites/%s/%s_%i.m32", g_outputDir, spr_prefix, spritename, sprite.numframes);
|
||||
sprintf (pframe->name, "%s/%s_%i.m32", spr_prefix, spritename, sprite.numframes);
|
||||
|
||||
if (g_release)
|
||||
return; // textures are only released by $maps
|
||||
|
||||
xh = xl+w;
|
||||
yh = yl+h;
|
||||
|
||||
if (xl >= longimagewidth || xh > longimagewidth ||
|
||||
yl >= longimageheight || yh > longimageheight)
|
||||
{
|
||||
Error ("line %i: bad clip dimmensions (%d,%d) (%d,%d) > image (%d,%d)", scriptline, xl,yl,w,h,longimagewidth,longimageheight);
|
||||
}
|
||||
|
||||
sourcel = longimage + (yl*longimagewidth) + xl;
|
||||
destl = bufferl;
|
||||
linedelta = (longimagewidth - w);
|
||||
|
||||
for (y=yl ; y<yh ; y++)
|
||||
{
|
||||
for (x=xl ; x<xh ; x++)
|
||||
{
|
||||
*destl++ = *sourcel++; // RGBA
|
||||
}
|
||||
sourcel += linedelta;
|
||||
}
|
||||
|
||||
qtex32 = CreateMip32(bufferl, w, h, &size, true);
|
||||
|
||||
qtex32->contents = 0;
|
||||
qtex32->value = 0;
|
||||
strcpy(qtex32->name, pframe->name);
|
||||
//
|
||||
// write it out
|
||||
//
|
||||
printf ("writing %s\n", filename);
|
||||
SaveFile (filename, (byte *)qtex32, size);
|
||||
|
||||
free (qtex32);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf (filename, "%ssprites/%s/%s_%i.m8", g_outputDir, spr_prefix, spritename, sprite.numframes);
|
||||
sprintf (pframe->name, "%s/%s_%i.m8", spr_prefix, spritename, sprite.numframes);
|
||||
|
||||
if (g_release)
|
||||
return; // textures are only released by $maps
|
||||
|
||||
xh = xl+w;
|
||||
yh = yl+h;
|
||||
|
||||
if (xl >= byteimagewidth || xh > byteimagewidth ||
|
||||
yl >= byteimageheight || yh > byteimageheight)
|
||||
{
|
||||
Error ("line %i: bad clip dimmensions (%d,%d) (%d,%d) > image (%d,%d)", scriptline, xl,yl,w,h,byteimagewidth,byteimageheight);
|
||||
}
|
||||
|
||||
source = byteimage + yl*byteimagewidth + xl;
|
||||
dest = buffer;
|
||||
linedelta = byteimagewidth - w;
|
||||
|
||||
for (y=yl ; y<yh ; y++)
|
||||
{
|
||||
for (x=xl ; x<xh ; x++)
|
||||
{
|
||||
*dest++ = *source++;
|
||||
}
|
||||
source += linedelta;
|
||||
}
|
||||
|
||||
qtex = CreateMip(buffer, w, h, lbmpalette, &size, true);
|
||||
|
||||
qtex->flags = 0;
|
||||
qtex->contents = 0;
|
||||
qtex->value = 0;
|
||||
strcpy(qtex->name, pframe->name);
|
||||
//
|
||||
// write it out
|
||||
//
|
||||
printf ("writing %s\n", filename);
|
||||
SaveFile (filename, (byte *)qtex, size);
|
||||
|
||||
free (qtex);
|
||||
}
|
||||
|
||||
sprite.numframes++;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
==============
|
||||
Cmd_SpriteName
|
||||
==============
|
||||
*/
|
||||
void Cmd_SpriteName (void)
|
||||
{
|
||||
if (sprite.numframes)
|
||||
FinishSprite ();
|
||||
|
||||
GetScriptToken (false);
|
||||
strcpy (spritename, token);
|
||||
memset (&sprite, 0, sizeof(sprite));
|
||||
memset (&frames, 0, sizeof(frames));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
===============
|
||||
Cmd_Sprdir
|
||||
===============
|
||||
*/
|
||||
void Cmd_Sprdir (void)
|
||||
{
|
||||
char filename[1024];
|
||||
|
||||
GetScriptToken (false);
|
||||
strcpy (spr_prefix, token);
|
||||
// create the directory if needed
|
||||
sprintf (filename, "%sSprites", g_outputDir);
|
||||
Q_mkdir (filename);
|
||||
sprintf (filename, "%sSprites/%s", g_outputDir, spr_prefix);
|
||||
Q_mkdir (filename);
|
||||
}
|
||||
|
||||
|
||||
490
tools/quake2/qdata_heretic2/svdcmp.c
Normal file
490
tools/quake2/qdata_heretic2/svdcmp.c
Normal file
@@ -0,0 +1,490 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
static double at,bt,ct;
|
||||
#define PYTHAG(a,b) ((at=fabs(a)) > (bt=fabs(b)) ? \
|
||||
(ct=bt/at,at*sqrt(1.0+ct*ct)) : (bt ? (ct=at/bt,bt*sqrt(1.0+ct*ct)): 0.0))
|
||||
|
||||
static double maxarg1,maxarg2;
|
||||
#define MAX(a,b) (maxarg1=(a),maxarg2=(b),(maxarg1) > (maxarg2) ?\
|
||||
(maxarg1) : (maxarg2))
|
||||
#define SIGN(a,b) ((b) >= 0.0 ? fabs(a) : -fabs(a))
|
||||
|
||||
void ntrerror(char *s)
|
||||
{
|
||||
printf("%s\n",s);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
double *allocVect(int sz)
|
||||
{
|
||||
double *ret;
|
||||
|
||||
ret = calloc(sizeof(double), (size_t)sz);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void freeVect(double *ret)
|
||||
{
|
||||
free(ret);
|
||||
}
|
||||
|
||||
double **allocMatrix(int r,int c)
|
||||
{
|
||||
double **ret;
|
||||
|
||||
ret = calloc(sizeof(double), (size_t)(r*c));
|
||||
return ret;
|
||||
}
|
||||
|
||||
void freeMatrix(double **ret,int r)
|
||||
{
|
||||
free(ret);
|
||||
}
|
||||
|
||||
void svdcmp(double** a, int m, int n, double* w, double** v)
|
||||
{
|
||||
int flag,i,its,j,jj,k,l,nm;
|
||||
double c,f,h,s,x,y,z;
|
||||
double anorm=0.0,g=0.0,scale=0.0;
|
||||
double *rv1;
|
||||
void nrerror();
|
||||
|
||||
if (m < n) ntrerror("SVDCMP: You must augment A with extra zero rows");
|
||||
rv1=allocVect(n);
|
||||
for (i=1;i<=n;i++) {
|
||||
l=i+1;
|
||||
rv1[i]=scale*g;
|
||||
g=s=scale=0.0;
|
||||
if (i <= m) {
|
||||
for (k=i;k<=m;k++) scale += fabs(a[k][i]);
|
||||
if (scale) {
|
||||
for (k=i;k<=m;k++) {
|
||||
a[k][i] /= scale;
|
||||
s += a[k][i]*a[k][i];
|
||||
}
|
||||
f=a[i][i];
|
||||
g = -SIGN(sqrt(s),f);
|
||||
h=f*g-s;
|
||||
a[i][i]=f-g;
|
||||
if (i != n) {
|
||||
for (j=l;j<=n;j++) {
|
||||
for (s=0.0,k=i;k<=m;k++) s += a[k][i]*a[k][j];
|
||||
f=s/h;
|
||||
for (k=i;k<=m;k++) a[k][j] += f*a[k][i];
|
||||
}
|
||||
}
|
||||
for (k=i;k<=m;k++) a[k][i] *= scale;
|
||||
}
|
||||
}
|
||||
w[i]=scale*g;
|
||||
g=s=scale=0.0;
|
||||
if (i <= m && i != n) {
|
||||
for (k=l;k<=n;k++) scale += fabs(a[i][k]);
|
||||
if (scale) {
|
||||
for (k=l;k<=n;k++) {
|
||||
a[i][k] /= scale;
|
||||
s += a[i][k]*a[i][k];
|
||||
}
|
||||
f=a[i][l];
|
||||
g = -SIGN(sqrt(s),f);
|
||||
h=f*g-s;
|
||||
a[i][l]=f-g;
|
||||
for (k=l;k<=n;k++) rv1[k]=a[i][k]/h;
|
||||
if (i != m) {
|
||||
for (j=l;j<=m;j++) {
|
||||
for (s=0.0,k=l;k<=n;k++) s += a[j][k]*a[i][k];
|
||||
for (k=l;k<=n;k++) a[j][k] += s*rv1[k];
|
||||
}
|
||||
}
|
||||
for (k=l;k<=n;k++) a[i][k] *= scale;
|
||||
}
|
||||
}
|
||||
anorm=MAX(anorm,(fabs(w[i])+fabs(rv1[i])));
|
||||
}
|
||||
for (i=n;i>=1;i--) {
|
||||
if (i < n) {
|
||||
if (g) {
|
||||
for (j=l;j<=n;j++)
|
||||
v[j][i]=(a[i][j]/a[i][l])/g;
|
||||
for (j=l;j<=n;j++) {
|
||||
for (s=0.0,k=l;k<=n;k++) s += a[i][k]*v[k][j];
|
||||
for (k=l;k<=n;k++) v[k][j] += s*v[k][i];
|
||||
}
|
||||
}
|
||||
for (j=l;j<=n;j++) v[i][j]=v[j][i]=0.0;
|
||||
}
|
||||
v[i][i]=1.0;
|
||||
g=rv1[i];
|
||||
l=i;
|
||||
}
|
||||
for (i=n;i>=1;i--) {
|
||||
l=i+1;
|
||||
g=w[i];
|
||||
if (i < n)
|
||||
for (j=l;j<=n;j++) a[i][j]=0.0;
|
||||
if (g) {
|
||||
g=1.0/g;
|
||||
if (i != n) {
|
||||
for (j=l;j<=n;j++) {
|
||||
for (s=0.0,k=l;k<=m;k++) s += a[k][i]*a[k][j];
|
||||
f=(s/a[i][i])*g;
|
||||
for (k=i;k<=m;k++) a[k][j] += f*a[k][i];
|
||||
}
|
||||
}
|
||||
for (j=i;j<=m;j++) a[j][i] *= g;
|
||||
} else {
|
||||
for (j=i;j<=m;j++) a[j][i]=0.0;
|
||||
}
|
||||
++a[i][i];
|
||||
}
|
||||
for (k=n;k>=1;k--) {
|
||||
for (its=1;its<=30;its++) {
|
||||
flag=1;
|
||||
for (l=k;l>=1;l--) {
|
||||
nm=l-1;
|
||||
if (fabs(rv1[l])+anorm == anorm) {
|
||||
flag=0;
|
||||
break;
|
||||
}
|
||||
if (fabs(w[nm])+anorm == anorm) break;
|
||||
}
|
||||
if (flag) {
|
||||
c=0.0;
|
||||
s=1.0;
|
||||
for (i=l;i<=k;i++) {
|
||||
f=s*rv1[i];
|
||||
if (fabs(f)+anorm != anorm) {
|
||||
g=w[i];
|
||||
h=PYTHAG(f,g);
|
||||
w[i]=h;
|
||||
h=1.0/h;
|
||||
c=g*h;
|
||||
s=(-f*h);
|
||||
for (j=1;j<=m;j++) {
|
||||
y=a[j][nm];
|
||||
z=a[j][i];
|
||||
a[j][nm]=y*c+z*s;
|
||||
a[j][i]=z*c-y*s;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
z=w[k];
|
||||
if (l == k) {
|
||||
if (z < 0.0) {
|
||||
w[k] = -z;
|
||||
for (j=1;j<=n;j++) v[j][k]=(-v[j][k]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (its == 30) ntrerror("No convergence in 30 SVDCMP iterations");
|
||||
x=w[l];
|
||||
nm=k-1;
|
||||
y=w[nm];
|
||||
g=rv1[nm];
|
||||
h=rv1[k];
|
||||
f=((y-z)*(y+z)+(g-h)*(g+h))/(2.0*h*y);
|
||||
g=PYTHAG(f,1.0);
|
||||
f=((x-z)*(x+z)+h*((y/(f+SIGN(g,f)))-h))/x;
|
||||
c=s=1.0;
|
||||
for (j=l;j<=nm;j++) {
|
||||
i=j+1;
|
||||
g=rv1[i];
|
||||
y=w[i];
|
||||
h=s*g;
|
||||
g=c*g;
|
||||
z=PYTHAG(f,h);
|
||||
rv1[j]=z;
|
||||
c=f/z;
|
||||
s=h/z;
|
||||
f=x*c+g*s;
|
||||
g=g*c-x*s;
|
||||
h=y*s;
|
||||
y=y*c;
|
||||
for (jj=1;jj<=n;jj++) {
|
||||
x=v[jj][j];
|
||||
z=v[jj][i];
|
||||
v[jj][j]=x*c+z*s;
|
||||
v[jj][i]=z*c-x*s;
|
||||
}
|
||||
z=PYTHAG(f,h);
|
||||
w[j]=z;
|
||||
if (z) {
|
||||
z=1.0/z;
|
||||
c=f*z;
|
||||
s=h*z;
|
||||
}
|
||||
f=(c*g)+(s*y);
|
||||
x=(c*y)-(s*g);
|
||||
for (jj=1;jj<=m;jj++) {
|
||||
y=a[jj][j];
|
||||
z=a[jj][i];
|
||||
a[jj][j]=y*c+z*s;
|
||||
a[jj][i]=z*c-y*s;
|
||||
}
|
||||
}
|
||||
rv1[l]=0.0;
|
||||
rv1[k]=f;
|
||||
w[k]=x;
|
||||
}
|
||||
}
|
||||
freeVect(rv1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void svbksb(double** u, double* w, double** v,int m, int n, double* b, double* x)
|
||||
{
|
||||
int jj,j,i;
|
||||
double s,*tmp;
|
||||
tmp=allocVect(n);
|
||||
for (j=1;j<=n;j++)
|
||||
{
|
||||
s=0.0;
|
||||
if (w[j])
|
||||
{
|
||||
for (i=1;i<=m;i++)
|
||||
s += u[i][j]*b[i];
|
||||
s /= w[j];
|
||||
}
|
||||
tmp[j]=s;
|
||||
}
|
||||
for (j=1;j<=n;j++)
|
||||
{
|
||||
s=0.0;
|
||||
for (jj=1;jj<=n;jj++)
|
||||
s += v[j][jj]*tmp[jj];
|
||||
x[j]=s;
|
||||
}
|
||||
freeVect(tmp);
|
||||
}
|
||||
|
||||
#undef SIGN
|
||||
#undef MAX
|
||||
#undef PYTHAG
|
||||
|
||||
|
||||
#if 1
|
||||
void DOsvd(float *a,float *res,float *comp,float *values,int nframes,int framesize,int compressedsize)
|
||||
{
|
||||
int usedfs;
|
||||
int *remap;
|
||||
int i,j;
|
||||
double **da;
|
||||
double **v;
|
||||
double *w;
|
||||
int DOFerr;
|
||||
float mx;
|
||||
int bestat;
|
||||
|
||||
if (nframes>framesize)
|
||||
usedfs=nframes;
|
||||
else
|
||||
usedfs=framesize;
|
||||
|
||||
da=allocMatrix(usedfs,nframes);
|
||||
v=allocMatrix(nframes,nframes);
|
||||
w=allocVect(nframes);
|
||||
|
||||
DOFerr = 0; //false
|
||||
for (i=0;i<nframes;i++)
|
||||
{
|
||||
for (j=0;j<framesize;j++)
|
||||
da[j+1][i+1]=a[i*framesize+j];
|
||||
for (;j<usedfs;j++)
|
||||
da[j+1][i+1]=0.0;
|
||||
}
|
||||
|
||||
svdcmp(da,usedfs,nframes,w,v);
|
||||
|
||||
remap = calloc(sizeof(int), (size_t)nframes);
|
||||
|
||||
|
||||
for (i=0;i<nframes;i++)
|
||||
remap[i]=-1;
|
||||
for (j=0;j<compressedsize;j++)
|
||||
{
|
||||
mx=-1.0f;
|
||||
for (i=0;i<nframes;i++)
|
||||
{
|
||||
if (remap[i]<0&&fabs(w[i+1])>mx)
|
||||
{
|
||||
mx=(float) fabs(w[i+1]);
|
||||
bestat=i;
|
||||
}
|
||||
}
|
||||
|
||||
if(mx>0)
|
||||
{
|
||||
remap[bestat]=j;
|
||||
}
|
||||
else
|
||||
{
|
||||
DOFerr = 1; //true
|
||||
}
|
||||
}
|
||||
|
||||
if(DOFerr)
|
||||
{
|
||||
printf("Warning: To many degrees of freedom! File size may increase\n");
|
||||
|
||||
for (i=0;i<compressedsize;i++)
|
||||
{
|
||||
values[i]=0;
|
||||
for (j=0;j<framesize;j++)
|
||||
res[i*framesize+j]=0;
|
||||
}
|
||||
}
|
||||
|
||||
for (i=0;i<nframes;i++)
|
||||
{
|
||||
if (remap[i]<0)
|
||||
w[i+1]=0.0;
|
||||
else
|
||||
{
|
||||
values[remap[i]]=(float) w[i+1];
|
||||
for (j=0;j<framesize;j++)
|
||||
res[remap[i]*framesize+j]=(float) da[j+1][i+1];
|
||||
}
|
||||
}
|
||||
freeVect(w);
|
||||
freeMatrix(v,nframes);
|
||||
freeMatrix(da,framesize);
|
||||
free(remap);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void DOsvd(float *a,float *res,float *comp,float *values,int nframes,int framesize,int compressedsize)
|
||||
{
|
||||
int *remap;
|
||||
int i,j;
|
||||
int nrows;
|
||||
nrows=nframes;
|
||||
if (nrows<framesize)
|
||||
nrows=framesize;
|
||||
double **da=allocMatrix(nrows,framesize);
|
||||
double **v=allocMatrix(framesize,framesize);
|
||||
double *w=allocVect(framesize);
|
||||
float mx;
|
||||
int bestat;
|
||||
|
||||
for (j=0;j<framesize;j++)
|
||||
{
|
||||
for (i=0;i<nframes;i++)
|
||||
da[j+1][i+1]=a[i*framesize+j];
|
||||
for (;i<nrows;i++)
|
||||
da[j+1][i+1]=0.0;
|
||||
}
|
||||
|
||||
svdcmp(da,nrows,framesize,w,v);
|
||||
|
||||
remap=new int[framesize];
|
||||
|
||||
|
||||
for (i=0;i<framesize;i++)
|
||||
remap[i]=-1;
|
||||
for (j=0;j<compressedsize;j++)
|
||||
{
|
||||
mx=-1.0f;
|
||||
for (i=0;i<framesize;i++)
|
||||
{
|
||||
if (remap[i]<0&&fabs(w[i+1])>mx)
|
||||
{
|
||||
mx=fabs(w[i+1]);
|
||||
bestat=i;
|
||||
}
|
||||
}
|
||||
assert(mx>-.5f);
|
||||
remap[bestat]=j;
|
||||
}
|
||||
// josh **DO NOT** put your dof>nframes mod here
|
||||
for (i=0;i<framesize;i++)
|
||||
{
|
||||
if (remap[i]<0)
|
||||
w[i+1]=0.0;
|
||||
else
|
||||
{
|
||||
values[remap[i]]=w[i+1];
|
||||
for (j=0;j<framesize;j++)
|
||||
res[remap[i]*framesize+j]=v[j+1][i+1];
|
||||
}
|
||||
}
|
||||
freeVect(w);
|
||||
freeMatrix(v,framesize);
|
||||
freeMatrix(da,nrows);
|
||||
delete[] remap;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void DOsvdPlane(float *pnts,int npnts,float *n,float *base)
|
||||
{
|
||||
int i,j;
|
||||
double **da=allocMatrix(npnts,3);
|
||||
double **v=allocMatrix(3,3);
|
||||
double *w=allocVect(3);
|
||||
float mn=1E30f;
|
||||
int bestat;
|
||||
|
||||
|
||||
assert(npnts>=3);
|
||||
base[0]=pnts[0];
|
||||
base[1]=pnts[1];
|
||||
base[2]=pnts[2];
|
||||
for (i=1;i<npnts;i++)
|
||||
{
|
||||
for (j=0;j<3;j++)
|
||||
base[j]+=pnts[i*3+j];
|
||||
}
|
||||
base[0]/=(float)(npnts);
|
||||
base[1]/=(float)(npnts);
|
||||
base[2]/=(float)(npnts);
|
||||
|
||||
for (i=0;i<3;i++)
|
||||
{
|
||||
for (j=0;j<npnts;j++)
|
||||
da[j+1][i+1]=pnts[j*3+i]-base[i];
|
||||
}
|
||||
|
||||
svdcmp(da,npnts,3,w,v);
|
||||
for (i=0;i<3;i++)
|
||||
{
|
||||
if (fabs(w[i+1])<mn)
|
||||
{
|
||||
mn=(float) fabs(w[i+1]);
|
||||
bestat=i;
|
||||
}
|
||||
}
|
||||
n[0]=(float) v[1][bestat+1];
|
||||
n[1]=(float) v[2][bestat+1];
|
||||
n[2]=(float) v[3][bestat+1];
|
||||
freeVect(w);
|
||||
freeMatrix(v,3);
|
||||
freeMatrix(da,npnts);
|
||||
}
|
||||
171
tools/quake2/qdata_heretic2/tables.c
Normal file
171
tools/quake2/qdata_heretic2/tables.c
Normal file
@@ -0,0 +1,171 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "qdata.h"
|
||||
|
||||
/*
|
||||
=============================================================================
|
||||
|
||||
ALPHALIGHT GENERATION
|
||||
|
||||
Find alphamap values that best match modulated lightmap values
|
||||
|
||||
This isn't used anymore, but I'm keeping it around...
|
||||
=============================================================================
|
||||
*/
|
||||
|
||||
unsigned short alphamap[32*32*32];
|
||||
unsigned char inverse16to8table[65536];
|
||||
|
||||
/*
|
||||
static int FindNearestColor( unsigned int color )
|
||||
{
|
||||
int i;
|
||||
int closest_so_far = 0;
|
||||
float closest_distance_so_far = 100000000;
|
||||
float d;
|
||||
float r[2], g[2], b[2];
|
||||
|
||||
// incoming color is assumed to be in 0xRRGGBB format
|
||||
r[0] = ( color & 31 ) << 3;
|
||||
g[0] = ( ( color >> 5 ) & 63 ) << 2;
|
||||
b[0] = ( ( color >> 11 ) & 31 ) << 3;
|
||||
|
||||
for ( i = 0; i < 256; i++ )
|
||||
{
|
||||
r[1] = ( d_8to24table[i] >> 0 ) & 0xFF;
|
||||
g[1] = ( d_8to24table[i] >> 8 ) & 0xFF;
|
||||
b[1] = ( d_8to24table[i] >> 16 ) & 0xFF;
|
||||
|
||||
d = ( r[1] - r[0] ) * ( r[1] - r[0] ) +
|
||||
( g[1] - g[0] ) * ( g[1] - g[0] ) +
|
||||
( b[1] - b[0] ) * ( b[1] - b[0] );
|
||||
|
||||
if ( d < closest_distance_so_far )
|
||||
{
|
||||
closest_distance_so_far = d;
|
||||
closest_so_far = i;
|
||||
}
|
||||
}
|
||||
|
||||
return closest_so_far;
|
||||
}
|
||||
*/
|
||||
|
||||
extern byte BestColor( int, int, int, int, int );
|
||||
|
||||
void Inverse16_BuildTable( void )
|
||||
{
|
||||
int i;
|
||||
|
||||
/*
|
||||
** create the 16-to-8 table
|
||||
*/
|
||||
for ( i = 0; i < 65536; i++ )
|
||||
{
|
||||
int r = i & 31;
|
||||
int g = ( i >> 5 ) & 63;
|
||||
int b = ( i >> 11 ) & 31;
|
||||
|
||||
r <<= 3;
|
||||
g <<= 2;
|
||||
b <<= 3;
|
||||
|
||||
inverse16to8table[i] = BestColor( r, g, b, 0, 255 );
|
||||
}
|
||||
}
|
||||
|
||||
void Alphalight_Thread (int i)
|
||||
{
|
||||
int j;
|
||||
float r, g, b;
|
||||
float mr, mg, mb, ma;
|
||||
float distortion, bestdistortion;
|
||||
float v;
|
||||
|
||||
r = (i>>10) * (1.0/16);
|
||||
g = ((i>>5)&31) * (1.0/16);
|
||||
b = (i&31) * (1.0/16);
|
||||
|
||||
bestdistortion = 999999;
|
||||
for (j=0 ; j<16*16*16*16 ; j++)
|
||||
{
|
||||
mr = (j>>12) * (1.0/16);
|
||||
mg = ((j>>8)&15) * (1.0/16);
|
||||
mb = ((j>>4)&15) * (1.0/16);
|
||||
ma = (j&15) * (1.0/16);
|
||||
|
||||
v = r * 0.5 - (mr*ma + 0.5*(1.0-ma));
|
||||
distortion = v*v;
|
||||
v = g * 0.5 - (mg*ma + 0.5*(1.0-ma));
|
||||
distortion += v*v;
|
||||
v = b * 0.5 - (mb*ma + 0.5*(1.0-ma));
|
||||
distortion += v*v;
|
||||
|
||||
distortion *= 1.0 + ma*4;
|
||||
|
||||
if (distortion < bestdistortion)
|
||||
{
|
||||
bestdistortion = distortion;
|
||||
alphamap[i] = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Cmd_Alphalight (void)
|
||||
{
|
||||
char savename[1024];
|
||||
|
||||
GetScriptToken (false);
|
||||
|
||||
if (g_release)
|
||||
{
|
||||
ReleaseFile (token);
|
||||
return;
|
||||
}
|
||||
|
||||
sprintf (savename, "%s%s", gamedir, token);
|
||||
printf ("Building alphalight table...\n");
|
||||
|
||||
RunThreadsOnIndividual (32*32*32, true, Alphalight_Thread);
|
||||
|
||||
SaveFile (savename, (byte *)alphamap, sizeof(alphamap));
|
||||
}
|
||||
|
||||
|
||||
void Cmd_Inverse16Table( void )
|
||||
{
|
||||
char savename[1024];
|
||||
|
||||
if ( g_release )
|
||||
{
|
||||
sprintf (savename, "pics/16to8.dat");
|
||||
ReleaseFile( savename );
|
||||
return;
|
||||
}
|
||||
|
||||
sprintf (savename, "%spics/16to8.dat", gamedir);
|
||||
printf ("Building inverse 16-to-8 table...\n");
|
||||
|
||||
Inverse16_BuildTable();
|
||||
|
||||
SaveFile( savename, (byte *) inverse16to8table, sizeof( inverse16to8table ) );
|
||||
}
|
||||
698
tools/quake2/qdata_heretic2/tmix.c
Normal file
698
tools/quake2/qdata_heretic2/tmix.c
Normal file
@@ -0,0 +1,698 @@
|
||||
/*
|
||||
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
|
||||
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
||||
|
||||
This file is part of GtkRadiant.
|
||||
|
||||
GtkRadiant is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GtkRadiant is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GtkRadiant; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "qdata.h"
|
||||
#include "flex.h"
|
||||
|
||||
#define MAXFILES 2048
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
int w;
|
||||
int h;
|
||||
int cw;
|
||||
int ch;
|
||||
int rw;
|
||||
int index;
|
||||
int depth;
|
||||
int col;
|
||||
int baseline;
|
||||
char name[128];
|
||||
} Coords;
|
||||
|
||||
int filenum;
|
||||
int valid;
|
||||
Coords in[MAXFILES];
|
||||
Coords out;
|
||||
char outscript[256];
|
||||
char sourcedir[256];
|
||||
char outusage[256];
|
||||
char root[32];
|
||||
|
||||
int destsize = 0;
|
||||
byte *pixels = NULL; // Buffer to load image
|
||||
long *outpixels = NULL; // Buffer to store combined textures
|
||||
long *usagemap = NULL; // Buffer of usage map
|
||||
void *bmptemp = NULL; // Buffer of usage map
|
||||
byte *map = NULL;
|
||||
|
||||
int xcharsize;
|
||||
int ycharsize;
|
||||
int dosort = 0;
|
||||
int missed = 0;
|
||||
int overlap = 0;
|
||||
int nobaseline = 0;
|
||||
int percent;
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
// Setting the char based usage map //
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
byte TryPlace(Coords *coord)
|
||||
{
|
||||
int x, y;
|
||||
byte entry = 0;
|
||||
byte *mapitem;
|
||||
|
||||
mapitem = map + (coord->x / xcharsize) + ((coord->y / ycharsize) * out.cw);
|
||||
|
||||
for (y = 0; y < coord->ch; y++, mapitem += out.cw - coord->cw)
|
||||
{
|
||||
for (x = 0; x < coord->cw; x++)
|
||||
{
|
||||
if (entry |= *mapitem++ & 8)
|
||||
{
|
||||
return(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
return(entry);
|
||||
}
|
||||
|
||||
void SetMap(Coords *coord)
|
||||
{
|
||||
int x, y;
|
||||
byte *mapitem;
|
||||
|
||||
mapitem = map + (coord->x / xcharsize) + ((coord->y / ycharsize) * out.cw);
|
||||
|
||||
for (y = 0; y < coord->ch; y++, mapitem += out.cw - coord->cw)
|
||||
for (x = 0; x < coord->cw; x++)
|
||||
*mapitem++ |= 8;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
// Setting the pixel based usage map //
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
void CheckOverlap(Coords *coord)
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
long *dest;
|
||||
|
||||
x = coord->x;
|
||||
y = coord->y;
|
||||
|
||||
dest = (long *)(usagemap + x + (y * out.w));
|
||||
|
||||
for (y = 0; y < coord->h; y++, dest += out.w - coord->w)
|
||||
{
|
||||
for (x = 0; x < coord->w; x++)
|
||||
{
|
||||
if (*dest++)
|
||||
{
|
||||
overlap++;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SetUsageMap(Coords *coord)
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
long *dest;
|
||||
|
||||
x = coord->x;
|
||||
y = coord->y;
|
||||
|
||||
dest = (long *)(usagemap + x + (y * out.w));
|
||||
|
||||
for (y = 0; y < coord->h; y++, dest += out.w - coord->w)
|
||||
{
|
||||
for (x = 0; x < coord->w; x++)
|
||||
{
|
||||
*dest++ = coord->col;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
// Flips the BMP image to the correct way up //
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
void CopyLine(byte *dest, byte *src, int size)
|
||||
{
|
||||
int x;
|
||||
|
||||
for (x = 0; x < size; x++)
|
||||
*dest++ = *src++;
|
||||
}
|
||||
|
||||
/****************************************************/
|
||||
/* Printing headers etc */
|
||||
/****************************************************/
|
||||
|
||||
void RemoveLeading(char *name)
|
||||
{
|
||||
int i;
|
||||
char temp[128];
|
||||
|
||||
for(i = strlen(name) - 1; i > 0; i--)
|
||||
{
|
||||
if((name[i] == '\\') || (name[i] == '/'))
|
||||
{
|
||||
strcpy(temp, name + i + 1);
|
||||
strcpy(name, temp);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RemoveExt(char *name)
|
||||
{
|
||||
while ((*name != '.') && *name)
|
||||
name++;
|
||||
*name = 0;
|
||||
}
|
||||
|
||||
/****************************************************/
|
||||
/* Misc calcualtions */
|
||||
/****************************************************/
|
||||
|
||||
int TotalArea()
|
||||
{
|
||||
int i;
|
||||
int total = 0;
|
||||
|
||||
for (i = 0; i < (filenum + 2); i++)
|
||||
total += in[i].w * in[i].h;
|
||||
|
||||
return(total);
|
||||
}
|
||||
|
||||
/****************************************************/
|
||||
/* Setup and checking of all info */
|
||||
/****************************************************/
|
||||
|
||||
void InitVars()
|
||||
{
|
||||
filenum = 0;
|
||||
valid = 0;
|
||||
dosort = 0;
|
||||
missed = 0;
|
||||
overlap = 0;
|
||||
nobaseline = 0;
|
||||
|
||||
memset(outscript, 0, sizeof(outscript));
|
||||
memset(outscript, 0, sizeof(sourcedir));
|
||||
memset(outscript, 0, sizeof(outusage));
|
||||
memset(outscript, 0, sizeof(root));
|
||||
|
||||
memset(in, 0, sizeof(in));
|
||||
memset(&out, 0, sizeof(out));
|
||||
}
|
||||
void Cleanup()
|
||||
{
|
||||
if (pixels)
|
||||
free(pixels);
|
||||
if (usagemap)
|
||||
free(usagemap);
|
||||
if (outpixels)
|
||||
free(outpixels);
|
||||
if (bmptemp)
|
||||
free(bmptemp);
|
||||
if (map)
|
||||
free(map);
|
||||
}
|
||||
|
||||
typedef struct glxy_s
|
||||
{
|
||||
float xl, yt, xr, yb;
|
||||
int w, h, baseline;
|
||||
} glxy_t;
|
||||
|
||||
int SaveScript(char *name)
|
||||
{
|
||||
FILE *fp;
|
||||
int i, j;
|
||||
glxy_t buff;
|
||||
|
||||
if(fp = fopen(name, "wb"))
|
||||
{
|
||||
for (j = 0; j < filenum; j++)
|
||||
{
|
||||
for (i = 0; i < filenum; i++)
|
||||
{
|
||||
if (in[i].index == j)
|
||||
{
|
||||
if (in[i].depth)
|
||||
{
|
||||
buff.xl = (float)in[i].x / (float)out.w;
|
||||
buff.yt = (float)in[i].y / (float)out.h;
|
||||
buff.xr = ((float)in[i].w + (float)in[i].x) / (float)out.w;
|
||||
buff.yb = ((float)in[i].h + (float)in[i].y) / (float)out.h;
|
||||
buff.w = in[i].w;
|
||||
buff.h = in[i].h;
|
||||
buff.baseline = in[i].baseline;
|
||||
}
|
||||
else
|
||||
{
|
||||
memset(&buff, 0, sizeof(glxy_t));
|
||||
}
|
||||
fwrite(&buff, 1, sizeof(glxy_t), fp);
|
||||
i = filenum;
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
return(true);
|
||||
}
|
||||
else
|
||||
return(false);
|
||||
}
|
||||
|
||||
int GetScriptInfo(char *name)
|
||||
{
|
||||
FILE *fp;
|
||||
char buffer[256];
|
||||
char tempbuff[256];
|
||||
char delims[] = {" \t,\n"};
|
||||
|
||||
printf("Opening script file %s.\n", name);
|
||||
|
||||
if (fp = fopen(name, "r"))
|
||||
{
|
||||
while(fgets(buffer, 256, fp))
|
||||
{
|
||||
if (strncmp(buffer, "//", 2) && strncmp(buffer, "\n", 1))
|
||||
{
|
||||
strupr(buffer);
|
||||
strcpy(tempbuff, buffer);
|
||||
if (strcmp(strtok(tempbuff, delims), "OUTPUT") == 0)
|
||||
{
|
||||
strcpy(out.name, strtok(NULL, delims));
|
||||
strlwr(out.name);
|
||||
}
|
||||
|
||||
strcpy(tempbuff, buffer);
|
||||
if (strcmp(strtok(tempbuff, delims), "SOURCEDIR") == 0)
|
||||
{
|
||||
strcpy(tempbuff, strtok(NULL, delims));
|
||||
strcpy(sourcedir, ExpandPathAndArchive(tempbuff));
|
||||
}
|
||||
|
||||
strcpy(tempbuff, buffer);
|
||||
if (strcmp(strtok(tempbuff, delims), "DOSORT") == 0)
|
||||
dosort = 1;
|
||||
|
||||
strcpy(tempbuff, buffer);
|
||||
if (strcmp(strtok(tempbuff, delims), "XCHARSIZE") == 0)
|
||||
xcharsize = strtol(strtok(NULL, delims), NULL, 0);
|
||||
|
||||
strcpy(tempbuff, buffer);
|
||||
if (strcmp(strtok(tempbuff, delims), "YCHARSIZE") == 0)
|
||||
ycharsize = strtol(strtok(NULL, delims), NULL, 0);
|
||||
|
||||
strcpy(tempbuff, buffer);
|
||||
if (strcmp(strtok(tempbuff, delims), "OUTSCRIPT") == 0)
|
||||
{
|
||||
strcpy(outscript, strtok(NULL, delims));
|
||||
strlwr(outscript);
|
||||
}
|
||||
|
||||
strcpy(tempbuff, buffer);
|
||||
if (strcmp(strtok(tempbuff, delims), "OUTUSAGE") == 0)
|
||||
strcpy(outusage, strtok(NULL, delims));
|
||||
|
||||
strcpy(tempbuff, buffer);
|
||||
if (strcmp(strtok(tempbuff, delims), "POS") == 0)
|
||||
{
|
||||
out.w = strtol(strtok(NULL, delims), NULL, 0);
|
||||
out.h = strtol(strtok(NULL, delims), NULL, 0);
|
||||
}
|
||||
|
||||
strcpy(tempbuff, buffer);
|
||||
if (strcmp(strtok(tempbuff, delims), "FILE") == 0)
|
||||
{
|
||||
strcpy(in[filenum].name, strtok(NULL, delims));
|
||||
in[filenum].x = strtol(strtok(NULL, delims), NULL, 0);
|
||||
in[filenum].y = strtol(strtok(NULL, delims), NULL, 0);
|
||||
in[filenum].col = strtol(strtok(NULL, delims), NULL, 0);
|
||||
filenum++;
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
return(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("ERROR : Could not open script file.\n");
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
|
||||
int CheckVars()
|
||||
{
|
||||
int i;
|
||||
|
||||
if (out.name[0] == 0)
|
||||
{
|
||||
printf("ERROR : No output name specified.\n");
|
||||
return(false);
|
||||
}
|
||||
if ((out.w <= 0) || (out.h <= 0))
|
||||
{
|
||||
printf("ERROR : Invalid VRAM coordinates.\n");
|
||||
return(false);
|
||||
}
|
||||
if (filenum == 0)
|
||||
{
|
||||
printf("ERROR : No input files specified.\n");
|
||||
return(false);
|
||||
}
|
||||
for (i = 0; i < filenum; i++)
|
||||
if (in[i].name[0] == 0)
|
||||
{
|
||||
printf("ERROR : Input filename invalid.\n");
|
||||
return(false);
|
||||
}
|
||||
return(true);
|
||||
}
|
||||
|
||||
// Makes sure texture is totally within the output area
|
||||
|
||||
int CheckCoords(Coords *coord)
|
||||
{
|
||||
if ((coord->x + coord->w) > out.w)
|
||||
return(false);
|
||||
if ((coord->y + coord->h) > out.h)
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
// Gets the width, height, palette width and palette height of each BMP file
|
||||
|
||||
int GetFileDimensions()
|
||||
{
|
||||
int i;
|
||||
int width, height;
|
||||
char name[128];
|
||||
|
||||
for (i = 0; i < filenum; i++)
|
||||
{
|
||||
in[i].index = i;
|
||||
|
||||
strcpy(name, sourcedir);
|
||||
strcat(name, in[i].name);
|
||||
printf("Getting file dimensions, file : %s \r", in[i].name);
|
||||
if(FileExists(name))
|
||||
{
|
||||
LoadAnyImage(name, NULL, NULL, &width, &height);
|
||||
in[i].depth = 32;
|
||||
in[i].rw = width;
|
||||
in[i].w = width; // makes it width in
|
||||
in[i].h = height;
|
||||
in[i].cw = (in[i].w + (xcharsize - 1)) / xcharsize;
|
||||
in[i].ch = (in[i].h + (ycharsize - 1)) / ycharsize;
|
||||
|
||||
if (!CheckCoords(&in[i]) && (in[i].x >= 0))
|
||||
{
|
||||
printf("Error : texture %s out of bounds.\n", in[i].name);
|
||||
return(false);
|
||||
}
|
||||
valid++;
|
||||
}
|
||||
else
|
||||
{
|
||||
in[i].depth = 0;
|
||||
in[i].x = -1;
|
||||
in[i].y = -1;
|
||||
in[i].w = 0;
|
||||
in[i].h = 0;
|
||||
}
|
||||
}
|
||||
printf("\n\n");
|
||||
return(true);
|
||||
}
|
||||
|
||||
// Sorts files into order for optimal space finding
|
||||
// Fixed position ones first, followed by the others in descending size
|
||||
// The theory being that it is easier to find space for smaller textures.
|
||||
// size = (width + height)
|
||||
// For space finding it is easier to place a 32x32 than a 128x2
|
||||
|
||||
#define WEIGHT 0x8000
|
||||
|
||||
void Swap(Coords *a, Coords *b)
|
||||
{
|
||||
Coords c;
|
||||
|
||||
c = *a;
|
||||
*a = *b;
|
||||
*b = c;
|
||||
}
|
||||
|
||||
void SortInNames()
|
||||
{
|
||||
int i, j;
|
||||
int largest, largcount;
|
||||
int size;
|
||||
|
||||
printf("Sorting filenames by size.\n\n");
|
||||
|
||||
for (j = 0; j < filenum; j++)
|
||||
{
|
||||
largest = -1;
|
||||
largcount = -1;
|
||||
|
||||
for (i = j; i < filenum; i++)
|
||||
{
|
||||
if (in[i].depth)
|
||||
{
|
||||
size = in[i].w + in[i].h;
|
||||
|
||||
if ((in[i].x < 0) && (size > largest))
|
||||
{
|
||||
largcount = i;
|
||||
largest = size;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((largcount >= 0) && (largcount != j))
|
||||
Swap(&in[j], &in[largcount]);
|
||||
}
|
||||
}
|
||||
|
||||
int SetVars(char *name)
|
||||
{
|
||||
if (!GetScriptInfo(name))
|
||||
return(false);
|
||||
|
||||
if (!CheckVars())
|
||||
return(false);
|
||||
|
||||
destsize = out.w * out.h;
|
||||
|
||||
out.cw = out.w / xcharsize;
|
||||
out.ch = out.h / ycharsize;
|
||||
|
||||
if ((usagemap = (long *)SafeMalloc(destsize * 4, "")) == NULL)
|
||||
return(false);
|
||||
if ((outpixels = (long *)SafeMalloc(destsize * 4, "")) == NULL)
|
||||
return(false);
|
||||
if ((bmptemp = (void *)SafeMalloc(destsize * 4, "")) == NULL)
|
||||
return(false);
|
||||
if ((map = (byte *)SafeMalloc(destsize / (xcharsize * ycharsize), "")) == NULL)
|
||||
return(false);
|
||||
|
||||
if (GetFileDimensions() == false)
|
||||
return(false);
|
||||
|
||||
if (dosort)
|
||||
SortInNames();
|
||||
|
||||
return(true);
|
||||
}
|
||||
/****************************************************/
|
||||
/* Actual copying routines */
|
||||
/****************************************************/
|
||||
|
||||
int FindCoords(Coords *coord)
|
||||
{
|
||||
int tx, ty;
|
||||
|
||||
if (coord->x >= 0)
|
||||
{
|
||||
SetMap(coord);
|
||||
return(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (ty = 0; ty < out.ch; ty++)
|
||||
{
|
||||
for (tx = 0; tx < out.cw; tx++)
|
||||
{
|
||||
coord->x = (tx * xcharsize);
|
||||
coord->y = (ty * ycharsize);
|
||||
|
||||
if (CheckCoords(coord) && !TryPlace(coord))
|
||||
{
|
||||
SetMap(coord);
|
||||
return(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
coord->x = -1;
|
||||
coord->y = -1;
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
void CheckBaseline(int i)
|
||||
{
|
||||
int y;
|
||||
long *pix;
|
||||
|
||||
in[i].baseline = -1;
|
||||
pix = (long *)pixels;
|
||||
|
||||
for(y = 0; y < in[i].h; y++, pix += in[i].w)
|
||||
{
|
||||
if((*pix & 0x00ffffff) == 0x00ff00ff)
|
||||
{
|
||||
in[i].baseline = y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
pix = (long *)pixels;
|
||||
for(y = 0; y < in[i].w * in[i].h; y++, pix++)
|
||||
{
|
||||
if((*pix & 0x00ffffff) == 0x00ff00ff)
|
||||
{
|
||||
*pix = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(in[i].baseline == -1)
|
||||
{
|
||||
printf("\nERROR : %s has no baseline\n", in[i].name);
|
||||
nobaseline++;
|
||||
}
|
||||
}
|
||||
|
||||
void CopyToMain32(Coords *coord)
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
long *source;
|
||||
long *dest;
|
||||
|
||||
x = coord->x;
|
||||
y = coord->y;
|
||||
|
||||
source = (long *)pixels;
|
||||
dest = (long *)(outpixels + x + (y * out.w));
|
||||
|
||||
for (y = 0; y < coord->h; y++, dest += out.w - coord->w)
|
||||
{
|
||||
for (x = 0; x < coord->w; x++)
|
||||
{
|
||||
*dest++ = *source++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CreateMain()
|
||||
{
|
||||
int i, count;
|
||||
int width, height;
|
||||
char name[128];
|
||||
|
||||
for (i = 0, count = 0; i < filenum; i++)
|
||||
{
|
||||
if (in[i].depth)
|
||||
{
|
||||
printf("\rProcessing %d of %d (%d missed, %d overlapping, %d nobase)\r", count + 1, valid, missed, overlap, nobaseline);
|
||||
count++;
|
||||
if (!FindCoords(&in[i]))
|
||||
missed++;
|
||||
else
|
||||
{
|
||||
strcpy(name, sourcedir);
|
||||
strcat(name, in[i].name);
|
||||
LoadAnyImage(name, &pixels, NULL, &width, &height);
|
||||
CheckBaseline(i);
|
||||
CheckOverlap(&in[i]);
|
||||
CopyToMain32(&in[i]);
|
||||
SetUsageMap(&in[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Cmd_TextureMix()
|
||||
{
|
||||
miptex32_t *qtex32;
|
||||
char filename[1024];
|
||||
int size;
|
||||
|
||||
InitVars();
|
||||
|
||||
GetScriptToken (false);
|
||||
|
||||
strcpy(root, token);
|
||||
RemoveExt(root);
|
||||
RemoveLeading(root);
|
||||
|
||||
strcpy(filename, ExpandPathAndArchive(token));
|
||||
if (SetVars(filename))
|
||||
{
|
||||
// Create combined texture
|
||||
percent = ((TotalArea() * 100) / (out.w * out.h));
|
||||
printf("Total area consumed : %d%%\n", percent);
|
||||
printf("Texture resolution : %dx%d pixels.\n", xcharsize, ycharsize);
|
||||
CreateMain();
|
||||
|
||||
// Save image as m32
|
||||
sprintf (filename, "%spics/misc/%s.m32", gamedir, out.name);
|
||||
qtex32 = CreateMip32((unsigned *)outpixels, out.w, out.h, &size, false);
|
||||
|
||||
qtex32->contents = 0;
|
||||
qtex32->value = 0;
|
||||
qtex32->scale_x = 1.0;
|
||||
qtex32->scale_y = 1.0;
|
||||
sprintf (qtex32->name, "misc/%s", out.name);
|
||||
|
||||
printf ("\n\nwriting %s\n", filename);
|
||||
SaveFile (filename, (byte *)qtex32, size);
|
||||
free (qtex32);
|
||||
|
||||
// Save out script file
|
||||
sprintf (filename, "%spics/misc/%s.fnt", gamedir, outscript);
|
||||
printf("Writing %s as script file\n", filename);
|
||||
if (!SaveScript(filename))
|
||||
{
|
||||
printf("Unable to save output script.\n");
|
||||
}
|
||||
}
|
||||
printf("Everythings groovy.\n");
|
||||
Cleanup();
|
||||
}
|
||||
|
||||
// end
|
||||
|
||||
1149
tools/quake2/qdata_heretic2/video.c
Normal file
1149
tools/quake2/qdata_heretic2/video.c
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user