/****************************************************************************
 *
 *  			Copyright 1995 Division Limited.
 *			      All Rights Reserved
 *
 *
 *  System        : 
 *  Module        : 
 *  Object Name   : $RCSfile: pfile.h,v $
 *  Revision      : $Revision: 1.15 $
 *  Date          : $Date: 95/05/16 13:46:35 $
 *  Author        : $Author: bill $
 *  Last Modified : <110595.1427>
 *
 *  Description	
 *
 *  Notes
 *
 *  History
 *	
 *  $Log:	pfile.h,v $
 * Revision 1.15  95/05/16  13:46:35  bill
 * Added 1) dos. 2) STRIP_LIST. 3) POINTLIST. 4) biz->bgf
 * 
 * Revision 1.14  95/04/27  23:01:16  bill
 * Major ci for 3.0 Alpha (new: pgeneral, dm)
 * 
 *
 ****************************************************************************
 *
 *  Copyright (c) 1995 Division Ltd.
 * 
 *  All Rights Reserved.
 * 
 *  This Document may not, in whole or in part, be copied,
 *  photocopied, reproduced, translated, or reduced to any
 *  electronic medium or machine readable form without prior
 *  written consent from Division Ltd.
 ****************************************************************************/

#ifndef __PFILE_H__
#define __PFILE_H__

#ifdef _PF_LOCAL
#include "pgeneral.h"
#else
#include <dsys/pgeneral.h>
#endif

#include <float.h>

/*****************************************************************************/
/* pfile error numbers */
#define dpfENO_ROPEN     0x8001
#define dpfENO_READ      0x8002
#define dpfENO_WOPEN     0x8003
#define dpfENO_WRITE     0x8004
#define dpfENO_CLOSE     0x8005
#define dpfENO_FORM      0x8006
#define dpfENO_VALUE     0x8007
#define dpfENO_USAGE     0x8008
#define dpfENO_NULL      0x8009
#define dpfENO_CONV      0x800A

/*****************************************************************************/
/* pfile warning levels */
#define dpfWARN_BADFILE  2
#define dpfWARN_PROBLEM  3
/*****************************************************************************/
/* pfile monitor flags */
#define dpfMON_READ      0x00100000
#define dpfMON_WRITE     0x00200000

/*****************************************************************************/
/* Useful constants */
#define dpf_ALLOW_B2Z     1
#define dpf_ALLOW_BMF     2
#define dpf_ALLOW_ALL     3

/* max min ranges for types */
#define dpfRGB_MAX     (float32)   1.0
#define dpfRGB_MIN     (float32)   0.0
#define dpfALPHA_MAX   (float32)   1.0
#define dpfALPHA_MIN   (float32)   0.0
#define dpfV1POWER_MAX (float32)  32.0
#define dpfV1POWER_MIN (float32)   1.0
#define dpfV2POWER_MAX (float32) 128.0
#define dpfV2POWER_MIN (float32)   1.0
#define dpfOPACITY_MAX (float32)   1.0
#define dpfOPACITY_MIN (float32)   0.0
#define dpfDICE_MAX    65565
#define dpfDICE_MIN        3
#define dpfDICE_DETER      0
#define dpfTHICK_MAX     255
#define dpfTHICK_MIN       1

/*****************************************************************************/
/* Different vertex types */
#define dpf_VERT_NONE           (uint8) 0x0000
#define dpf_VERT_NORMALS        (uint8) 0x0001
#define dpf_VERT_RGBA           (uint8) 0x0002
#define dpf_VERT_LUMINANCE      (uint8) 0x0004
#define dpf_VERT_TEXTURE        (uint8) 0x0008
#define dpf_VERT_THREED_TEXTURE (uint8) 0x0010

/*****************************************************************************/
/* Different Geometry Types */
#define dpf_GEOM_UNDEFINED  (int32) 0x0000
#define dpf_GEOM_POLYGON    (int32) 0x0043
#define dpf_GEOM_TRISTRIP   (int32) 0x0044
#define dpf_GEOM_POLYSTRIP  (int32) 0x0045
#define dpf_GEOM_PMESH      (int32) 0x0046
#define dpf_GEOM_SPHERE     (int32) 0x0048
#define dpf_GEOM_LINE       (int32) 0x004A
#define dpf_GEOM_TEXT       (int32) 0x004B
#define dpf_GEOM_POINT      (int32) 0x0050

/*****************************************************************************/
/* Unit conversion scaling factors */
#define dpfINCHtoMM 25.4
#define dpfMMtoINCH (1.0/dpfINCHtoMM)
#define dpfINCHtoM  0.0254
#define dpfMtoINCH  (1.0/dpfINCHtoM)

/*****************************************************************************/
/* types. */
/* must never have double precision without global changes */
/*
#define dpf_DOUBLE_PRECISION
*/

typedef enum 
{ /* used for indexing arrays, identifying axies etc etc */
    dpf_PITCH = 0, dpf_YAW = 1, dpf_ROLL = 2,
    dpfERGBA =  4, dpf_R = 0, dpf_G = 1, dpf_B = 2, 
    dpf_A = 3, dpf_POWER=3, dpf_LUM = 0,
    dpfETEXT   =  2, dpf_U = 0, dpf_V = 1,
    dpfETHREEDTEXT =  3
} coord;

typedef int32   dpfIVECTOR[3] ;            /* Generic 4 elem vector. */
typedef float32 dpfRGBA[dpfERGBA];
typedef float32 dpfTEXT[dpfETEXT] ;
typedef float32 dpfTHREEDTEXT[dpfETHREEDTEXT] ;

typedef enum {dpf_B2Z_FILE,   dpf_V2Z_FILE,
              dpf_VIZ_FILE,   dpf_BIZ_FILE, 
              dpf_UNKNOWN_FILE } dpfFILETYPE;

typedef enum {dpf_FILE_GEOMETRY=0, dpf_FILE_MATERIAL=1 } dpfFILEFORMAT;

typedef enum {dpfREAD, dpfWRITE} dpfFILEMODE;

/* New enumerated types */
typedef enum { dpf_MIN_DEFAULT=0, dpf_MIN_POINT_SAMPLED=1, 
               dpf_MIN_BILINEAR=2, dpf_MIN_TRILINEAR=3,
               dpf_MIN_MIP_MAP_LINEAR=4, dpf_MIN_MIP_MAP_BILINEAR=5, 
               dpf_MIN_MIP_MAP_TRILINEAR=6, dpf_MIN_MIP_MAP_QUADLINEAR=7, 
               dpf_MIN_MIP_MAP_POINT_SAMPLED=8 } dpfMINIFY;
typedef enum { dpf_MAG_DEFAULT=0, dpf_MAG_POINT_SAMPLED=1, 
               dpf_MAG_BILINEAR=2, dpf_MAG_TRILINEAR=3, 
               dpf_MAG_BICUBIC=4, dpf_MAG_SHARPEN=5 } dpfMAGNIFY;
typedef enum { dpf_ALPHA_BLEND=0, dpf_ALPHA_CUT=1, 
               dpf_ALPHA_BLEND_CUT=2 } dpfALPHA ;
typedef enum { dpf_WRAP_REPEAT=0, dpf_WRAP_CLAMP=1, dpf_WRAP_SELECT=2 } dpfWRAP ;
typedef enum { dpf_DETAIL_NONE=0, dpf_DETAIL_ADD=1, 
               dpf_DETAIL_MODULATE=2 } dpfDETAIL ;
typedef enum { dpf_TRANS_SNAP=0, dpf_TRANS_BLEND=1 } dpfTRANSITION ;
typedef enum { dpf_MAT_NONE=0, dpf_MAT_NAMED=1, 
               dpf_MAT_DEFAULT=2, dpf_MAT_F_MATERIAL=3 } dpfMATTYPE ;
typedef enum { dpf_MATTXT_NONE=0, dpf_MATTXT_DEFAULT=1,
               dpf_MATTXT_NAMED=2 } dpfMATTXTTYPE ;
typedef enum { dpf_PLANE_NORMAL=0, dpf_PLANE_UNDERLAY=1, 
               dpf_PLANE_OVERLAY=2 } dpfPLANE ;
typedef enum { dpf_FACET_NONE=0, dpf_FACET_BACKFACE=1, 
               dpf_FACET_FRONTFACE=2, dpf_FACET_TWOFACED=3 } dpfFACET ;
typedef enum { dpf_DM_FILLED=0, dpf_DM_WIREFRAME=1, dpf_DM_DOTTED=2 } dpfDRAWMODE ;
typedef enum { dpf_PREC_SINGLE=0, dpf_PREC_DOUBLE=1 } dpfPRECISION ;
typedef enum { dpf_UNIT_INCH=0, dpf_UNIT_METRE=1 } dpfUNIT ;
typedef enum { dpf_FONT_QUICK=0, dpf_FONT_BITMAP=1, dpf_FONT_VECTOR=2,
               dpf_FONT_POLY_2D=3, dpf_FONT_POLY_3D=4, dpf_FONT_TEXTURE=5 } dpfFONT ;
typedef enum { dpf_AUTO_OFF=0, dpf_AUTO_ON=1 } dpfAUTO ;
typedef enum { dpf_LOCK_OFF=0, dpf_LOCK_ON=1 } dpfLOCK ;

struct dpfSTRINGTYPE ;
typedef struct dpfSTRINGTYPE *dpfSTRINGPTR ;

struct dpfSURFACETYPE ;
typedef struct dpfSURFACETYPE *dpfSURFACEPTR;

struct dpfBOUNDTYPE ;
typedef struct dpfBOUNDTYPE *dpfBOUNDPTR ; 

struct dpfTEXTURETYPE ;
typedef struct dpfTEXTURETYPE *dpfTEXTUREPTR ; 

struct dpfRAMPTYPE ;
typedef struct dpfRAMPTYPE *dpfRAMPPTR ;

struct dpfMATERIALTYPE ;
typedef struct dpfMATERIALTYPE *dpfMATERIALPTR ;

struct dpfVERTEXTYPE ;
typedef struct dpfVERTEXTYPE *dpfVERTEXPTR ;

struct dpfSLISTTYPE;
typedef struct dpfSLISTTYPE *dpfSLISTPTR ;

struct dpfCLISTTYPE;
typedef struct dpfCLISTTYPE *dpfCLISTPTR ;

struct dpfSPHERENODETYPE ;
typedef struct dpfSPHERENODETYPE *dpfSPHERENODEPTR ;

struct dpfTEXTNODETYPE ;
typedef struct dpfTEXTNODETYPE *dpfTEXTNODEPTR ;

struct dpfPOLYGONTYPE ;
typedef struct dpfPOLYGONTYPE *dpfPOLYGONPTR ;

struct dpfGEOMETRYTYPE ;
typedef struct dpfGEOMETRYTYPE *dpfGEOMETRYPTR ;

struct dpfPATCHTYPE ;
typedef struct dpfPATCHTYPE *dpfPATCHPTR ;

struct dpfLODTYPE ;
typedef struct dpfLODTYPE *dpfLODPTR ;

struct dpfOBJECTTYPE ;
typedef struct dpfOBJECTTYPE *dpfOBJECTPTR ;

struct dpfHEADERTYPE ;
typedef struct dpfHEADERTYPE *dpfHEADERPTR ;

struct dpfFILE_TYPE ;
typedef struct dpfFILE_TYPE *dpfFILEPTR ;

/* ptools declaration */

struct dptTRIANGLETYPE ;
typedef struct dptTRIANGLETYPE *dptTRIANGLEPTR ;
struct dptMESHTYPE ;
typedef struct dptMESHTYPE *dptMESHPTR ;

/*****************************************************************************/
/* Externally callable Functions. */
/*****************************************************************************/
/* Useful macros */

#define dpfRGBCmp(a,b)     memcmp(a, b, sizeof(float32)*3)
#define dpfRGBACmp(a,b)    memcmp(a, b, sizeof(dpfRGBA))
#define dpfTextCmp(a,b)    memcmp(a, b, sizeof(float32)*2)
#define dpfRGBACpy(a,b)    memcpy(a, b, sizeof(dpfRGBA))
#define dpfTextCpy(a,b)    memcpy(a, b, sizeof(dpfTEXT))

#define dpfBadFloat(f) (((*(long *)&(f) & 0x7f800000L)==0x7f800000L))

/*****************************************************************************/
/* pfsurfac Surfaces */
void
dpfInitSurface(dpfSURFACEPTR);       /* Set to dpfINITSURFACE */
void 
dpfReinitSurface(dpfSURFACEPTR surf);
void
dpfCpySurface(dpfSURFACEPTR surf1, dpfSURFACEPTR surf2) ;
int32
dpfCmpSurface(dpfSURFACEPTR s1, dpfSURFACEPTR s2) ;  
/* if s1 == s2 then return 0, else return non-zero */


/* Set surface characturistics */
void 
dpfSetSurface(dpfSURFACEPTR surf, dpfSURFACEPTR source) ;
/* Set material name literally sets the name to the given pointer, 
** so make sure it dynamically allocated and not used by anything else!
** If in doubt use copy name which creates a new dynamically allocated name.
*/
void
dpfSetSurfaceName(dpfSURFACEPTR surf, char *name) ;
void 
dpfSetSurfaceF_Material(dpfSURFACEPTR surf, dpfMATTYPE Material, char *MatName) ;
void 
dpfSetSurfaceB_Material(dpfSURFACEPTR surf, dpfMATTYPE Material, char *MatName) ;
void 
dpfSetSurfaceVertex(dpfSURFACEPTR surf, uint8 Characturistic, uint8 State) ;
void 
dpfSetSurfacePlane(dpfSURFACEPTR surf, dpfPLANE Plane) ;
void 
dpfSetSurfaceFacet(dpfSURFACEPTR surf, dpfFACET Facet) ;
void 
dpfSetSurfaceDecal(dpfSURFACEPTR surf, int32 decal) ;
void 
dpfSetSurfaceDrawMode(dpfSURFACEPTR surf, dpfDRAWMODE DrawMode, uint8 Width) ;
void 
dpfSetSurfaceLock(dpfSURFACEPTR surf, dpfLOCK lock) ;
void 
dpfSetSurfaceSpecial(dpfSURFACEPTR surf, dpfSTRINGPTR Special) ;

/* Get surface characturistics */
/* Returns a pointer to THE name. so don't destroy */
char *
dpfGetSurfaceName(dpfSURFACEPTR surf) ;
dpfMATTYPE
dpfGetSurfaceF_Material(dpfSURFACEPTR surf, char **MatName) ;
dpfMATTYPE
dpfGetSurfaceB_Material(dpfSURFACEPTR surf, char **MatName) ;
uint8 
dpfGetSurfaceVertex(dpfSURFACEPTR surf) ;
dpfPLANE
dpfGetSurfacePlane(dpfSURFACEPTR surf) ;
dpfFACET
dpfGetSurfaceFacet(dpfSURFACEPTR surf) ;
int32
dpfGetSurfaceDecal(dpfSURFACEPTR surf) ;
dpfDRAWMODE
dpfGetSurfaceDrawMode(dpfSURFACEPTR surf, uint8 *Width) ;
dpfLOCK
dpfGetSurfaceLock(dpfSURFACEPTR surf) ;
dpfSTRINGPTR
dpfGetSurfaceSpecial(dpfSURFACEPTR surf) ;


/* pfvertex Vertices & VertLists */
/* Vertices */
void
dpfSetVertexFlag(uint8 vflag, uint8 textCook, uint8 overRide) ;
uint8
dpfCheckVertexFlag(uint8 vflag, uint8 useOverRide) ;
dpfVERTEXPTR
dpfCreateVertex(void);
dpfVERTEXPTR
dpfCreateVertexBlock(int32 numVerts);
int32
dpfCreateVertexTable(dpfGEOMETRYPTR geom, dpfVERTEXPTR **table) ;
int32
dpfAddVertex(dpfGEOMETRYPTR geom, dpfVERTEXPTR vertex) ;
int32
dpfUnlinkVertex(dpfVERTEXPTR);
int32
dpfFreeVertex(dpfVERTEXPTR);
int32
dpfFreeVertexList(dpfVERTEXPTR vert) ;
void
dpfKillVertices() ;

/* The following calls are used to loop through all the vertices in a 
** geometry. Get Previous has to search a list to find the previous so it
** can be slow.
*/
int32
dpfGetVertexCount(dpfGEOMETRYPTR geom) ;
dpfVERTEXPTR
dpfGetFrstVertex(dpfGEOMETRYPTR geom) ;
dpfVERTEXPTR
dpfGetNextVertex(dpfVERTEXPTR vertex) ;
dpfVERTEXPTR
dpfGetPrevVertex(dpfVERTEXPTR vertex) ;
dpfVERTEXPTR
dpfGetNthVertex(dpfGEOMETRYPTR geom, int32 Nth) ;


/* Vertex info */
void
dpfGetVertexPoint(dpfVERTEXPTR, dmVector) ;
void
dpfGetVertexNormal(dpfVERTEXPTR, dmVector) ;
void
dpfGetVertexColour(dpfVERTEXPTR, dpfRGBA) ;
void
dpfGetVertexTexture(dpfVERTEXPTR, dpfTEXT) ;

void
dpfSetVertexPoint(dpfVERTEXPTR, dmVector) ;
void
dpfSetVertexNormal(dpfVERTEXPTR, dmVector) ;
void
dpfSetVertexColour(dpfVERTEXPTR, dpfRGBA) ;
void
dpfSetVertexTexture(dpfVERTEXPTR, dpfTEXT) ;

/* Pmesh functions */
/* Connection List's */
dpfCLISTPTR
dpfCreateCList(int32 pcount, int32 fcount);
int32
dpfAddCList(dpfGEOMETRYPTR geom, dpfCLISTPTR cList) ;
int32
dpfUnlinkCList(dpfCLISTPTR);
int32
dpfFreeCList(dpfCLISTPTR);
int32
dpfFreeCListList(dpfCLISTPTR cList) ;

/* The following calls are used to loop through all the vertLists in a 
** geometry. Get Previous has to search a list to find the previous so it
** can be slow.
*/
int32
dpfGetCListCount(dpfGEOMETRYPTR geom) ;
dpfCLISTPTR
dpfGetFrstCList(dpfGEOMETRYPTR geom) ;
dpfCLISTPTR
dpfGetNextCList(dpfCLISTPTR cList) ;
dpfCLISTPTR
dpfGetPrevCList(dpfCLISTPTR cList) ;

/* VertList Info */
int32
dpfGetCListPCount(dpfCLISTPTR cList) ;
int32
dpfGetCListFCount(dpfCLISTPTR cList) ;
int32 *
dpfCreateCListFace(dpfCLISTPTR cList) ;
int32 *
dpfGetCListFace(dpfCLISTPTR cList, int32 fno) ;
void
dpfSetCListFace(dpfCLISTPTR cList, int32 fno, int32 *verts) ;
int32
dpfFreeCListFace(dpfCLISTPTR cList, int32 fno) ;

/* Strip List's */
dpfSLISTPTR
dpfCreateSList(int32 pcount, int32 vcount);
int32
dpfAddSList(dpfGEOMETRYPTR geom, dpfSLISTPTR sList) ;
int32
dpfUnlinkSList(dpfSLISTPTR);
int32
dpfFreeSList(dpfSLISTPTR);
int32
dpfFreeSListList(dpfSLISTPTR sList) ;

/* The following calls are used to loop through all the Strip Lists in a 
** geometry. Get Previous has to search a list to find the previous so it
** can be slow.
*/
int32
dpfGetSListCount(dpfGEOMETRYPTR geom) ;
dpfSLISTPTR
dpfGetFrstSList(dpfGEOMETRYPTR geom) ;
dpfSLISTPTR
dpfGetNextSList(dpfSLISTPTR sList) ;
dpfSLISTPTR
dpfGetPrevSList(dpfSLISTPTR sList) ;

/* Strip List Info */
int32
dpfGetSListPCount(dpfSLISTPTR sList) ;
int32
dpfGetSListVCount(dpfSLISTPTR sList) ;
int32
dpfAddSListVertex(dpfSLISTPTR sList, int32 vertNo) ;
int32 *
dpfGetSListVertex(dpfSLISTPTR sList, int32 vno) ;
void
dpfSetSListVertex(dpfSLISTPTR sList, int32 vno, int32 vertNo) ;


/* Sphere's */
dpfSPHERENODEPTR
dpfCreateSphereNode(void);
dpfSPHERENODEPTR
dpfCreateSphereNodeBlock(int32 numVLists) ;
int32
dpfAddSphereNode(dpfGEOMETRYPTR geom, dpfSPHERENODEPTR vertex) ;
int32
dpfUnlinkSphereNode(dpfSPHERENODEPTR);
int32
dpfFreeSphereNode(dpfSPHERENODEPTR);
int32
dpfFreeSphereNodeList(dpfSPHERENODEPTR vertList) ;


/* The following calls are used to loop through all the spheres in a 
** geometry. Get Previous has to search a list to find the previous so it
** can be slow.
*/
int32
dpfGetSphereNodeCount(dpfGEOMETRYPTR geom) ;
dpfSPHERENODEPTR
dpfGetFrstSphereNode(dpfGEOMETRYPTR geom) ;
dpfSPHERENODEPTR
dpfGetNextSphereNode(dpfSPHERENODEPTR vertList) ;
dpfSPHERENODEPTR
dpfGetPrevSphereNode(dpfSPHERENODEPTR vertList) ;

/* Sphere Info */
void
dpfGetSphereDice(dpfGEOMETRYPTR geom, uint8 *u_dice, uint8 *v_dice) ;
void
dpfSetSphereDice(dpfGEOMETRYPTR geom, uint8 u_dice, uint8 v_dice) ;

float32
dpfGetSphereNodeData(dpfSPHERENODEPTR vertList, dmVector point) ;
void
dpfSetSphereNodeData(dpfSPHERENODEPTR vertList, float32 radius,
                     dmVector point) ;

/* Text */
dpfTEXTNODEPTR
dpfCreateTextNode(void) ;
dpfTEXTNODEPTR
dpfCreateTextNodeBlock(int32 numTexts) ;
int32
dpfUnlinkTextNode(dpfTEXTNODEPTR text) ;
int32 
dpfAddTextNode(dpfGEOMETRYPTR geom, dpfTEXTNODEPTR text) ;
int32
dpfFreeTextNode(dpfTEXTNODEPTR text) ;
int32
dpfFreeTextNodeList(dpfTEXTNODEPTR text) ;

/* move through text list */
int32
dpfGetTextNodeCount(dpfGEOMETRYPTR geom) ;
dpfTEXTNODEPTR
dpfGetFrstTextNode(dpfGEOMETRYPTR geom) ;
dpfTEXTNODEPTR
dpfGetNextTextNode(dpfTEXTNODEPTR text) ;
dpfTEXTNODEPTR
dpfGetPrevTextNode(dpfTEXTNODEPTR text) ;

/* Get and set text global info */
dpfFONT
dpfGetTextFont(dpfGEOMETRYPTR geom) ;
void
dpfGetTextOrientation(dpfGEOMETRYPTR geom, dmVector orn) ;
void
dpfGetTextScale(dpfGEOMETRYPTR geom, dmVector scale) ;
void
dpfSetTextFont(dpfGEOMETRYPTR geom, dpfFONT font) ;
void
dpfSetTextOrientation(dpfGEOMETRYPTR geom, dmVector orn) ;
void
dpfSetTextScale(dpfGEOMETRYPTR geom, dmVector scale) ;

/* get and set text node info */
void
dpfGetTextNodePoint(dpfTEXTNODEPTR text, dmVector point) ;
char *
dpfGetTextNodeString(dpfTEXTNODEPTR text) ;
void
dpfSetTextNodePoint(dpfTEXTNODEPTR text, dmVector point) ;
void
dpfSetTextNodeString(dpfTEXTNODEPTR text, char *str1) ;

/* Get and set line global info */
uint8
dpfGetLineThickness(dpfGEOMETRYPTR geom) ;
void
dpfSetLineThickness(dpfGEOMETRYPTR geom, uint8 thickness) ;

/* pfgeomet Geometry & strips & pmeshes etc */
dpfGEOMETRYPTR
dpfCreatePoint(void) ;
dpfGEOMETRYPTR
dpfCreatePolygon(void) ;
dpfGEOMETRYPTR
dpfCreateTristrip(void);
dpfGEOMETRYPTR
dpfCreatePolystrip(void);
dpfGEOMETRYPTR
dpfCreatePmesh(void);
dpfGEOMETRYPTR
dpfCreateSphere(void);
dpfGEOMETRYPTR
dpfCreateLine(void) ;
dpfGEOMETRYPTR
dpfCreateText(void) ;
int32
dpfAddGeometry(dpfPATCHPTR patch, dpfGEOMETRYPTR geom) ;
int32 
dpfUnlinkGeometry(dpfGEOMETRYPTR geometry) ;
int32
dpfFreeGeometry(dpfGEOMETRYPTR);
int32
dpfFreeFileGeometries(dpfFILEPTR file) ;
int32
dpfTurnGeometry2Pmesh(dpfGEOMETRYPTR geom) ;

/* The following calls are used to loop through all the geometries in a
** file. Get Previous has to search a list to find the previous so it
** can be slow.
*/
dpfPATCHPTR
dpfGetGeometryParent(dpfGEOMETRYPTR geom) ;
dpfGEOMETRYPTR
dpfGetFrstGeometry(dpfPATCHPTR patch) ;
dpfGEOMETRYPTR
dpfGetNextGeometry(dpfGEOMETRYPTR geom) ;
dpfGEOMETRYPTR
dpfGetPrevGeometry(dpfGEOMETRYPTR geom) ;

/* Geometry info */
int32
dpfGetGeometryType(dpfGEOMETRYPTR geom) ;

/* pfpatch patches */
dpfPATCHPTR
dpfCreatePatch(void) ;
int32
dpfAddPatch(dpfLODPTR lod, dpfPATCHPTR patch) ;
int32
dpfJoinPatch(dpfPATCHPTR patch1, dpfPATCHPTR patch2) ;
int32
dpfUnlinkPatch(dpfPATCHPTR) ;
int32
dpfFreePatch(dpfPATCHPTR) ;

/* The following calls are used to loop through all the patches in an
** LOD. Get Previous has to search a list to find the previous so it
** can be slow.
*/
dpfLODPTR
dpfGetPatchParent(dpfPATCHPTR patch) ;
dpfPATCHPTR
dpfGetFrstPatch(dpfLODPTR object) ;
dpfPATCHPTR
dpfGetNextPatch(dpfPATCHPTR patch) ;
dpfPATCHPTR
dpfGetPrevPatch(dpfPATCHPTR patch) ;

/* Get surface pointer for the surface setting and getting calls */
dpfSURFACEPTR
dpfGetPatchSurface(dpfPATCHPTR patch) ;

/* pflod LODs */
dpfLODPTR
dpfCreateLOD(void) ;
int32
dpfAddLOD(dpfOBJECTPTR object, dpfLODPTR lod) ;
int32
dpfJoinLOD(dpfLODPTR lod1, dpfLODPTR lod2) ;
int32
dpfUnlinkLOD(dpfLODPTR) ;
int32
dpfFreeLOD(dpfLODPTR) ;
int32
dpfCmpLOD(dpfLODPTR lod1, dpfLODPTR lod2) ;

/* The following calls are used to loop through all the lods in a
** file. Get Previous has to search a list to find the previous so it
** can be slow.
*/
dpfOBJECTPTR
dpfGetLODParent(dpfLODPTR) ;
dpfLODPTR
dpfGetFrstLOD(dpfOBJECTPTR) ;
dpfLODPTR
dpfGetNextLOD(dpfLODPTR) ;
dpfLODPTR
dpfGetPrevLOD(dpfLODPTR) ;

/* LOD info */
char *
dpfGetLODName(dpfLODPTR lod) ;
void
dpfGetLODDistance(dpfLODPTR lod, float32 *InDist, float32 *OutDist) ;
dpfTRANSITION
dpfGetLODTransition(dpfLODPTR lod) ;
int32
dpfGetLODReference(dpfLODPTR lod, dmVector reference) ;

void
dpfSetLODName(dpfLODPTR lod, char *name) ;
void
dpfSetLODDistance(dpfLODPTR lod, float32 InDist, float32 OutDist) ;
void
dpfSetLODTransition(dpfLODPTR lod, dpfTRANSITION Transition) ;
void
dpfSetLODReference(dpfLODPTR lod, int32 referenceFlag, dmVector reference) ;


/* pfobject objects */
dpfOBJECTPTR
dpfCreateObject(void) ;
int32
dpfAddObject(dpfFILEPTR file, dpfOBJECTPTR object) ;
int32
dpfJoinObject(dpfOBJECTPTR object1, dpfOBJECTPTR object2) ;
int32
dpfUnlinkObject(dpfOBJECTPTR) ;
int32
dpfFreeObject(dpfOBJECTPTR) ;

/* The following calls are used to loop through all the objects in a
** file. Get Previous has to search a list to find the previous so it
** can be slow.
*/
dpfFILEPTR
dpfGetObjectParent(dpfOBJECTPTR) ;
dpfOBJECTPTR
dpfGetFrstObject(dpfFILEPTR) ;
dpfOBJECTPTR
dpfGetNextObject(dpfOBJECTPTR) ;
dpfOBJECTPTR
dpfGetPrevObject(dpfOBJECTPTR) ;

/* Get surface pointer for the surface setting and getting calls */
dpfSURFACEPTR
dpfGetObjectSurface(dpfOBJECTPTR object) ;

/* pffile file structure */
int32
dpfGetAllFile(char *name, dpfFILEPTR *file, uint8 verMajor, uint8 verMinor) ;
dpfFILEPTR
dpfOpenAllFile(char *name, uint8 verMajor, uint8 verMinor) ;
int32
dpfGetAllFileBody(dpfFILEPTR file) ;
int32
dpfGetFile(char *name, dpfFILEPTR *file) ;
dpfFILEPTR
dpfOpenFile(char *name) ;
int32
dpfGetFileBody(dpfFILEPTR file) ;

int32
dpfPutAllFile(char *name, dpfFILEPTR Sfile, dpfFILEPTR matFile) ;
int32
dpfPutAllFileBody(dpfFILEPTR Dfile,dpfFILEPTR Sfile, dpfFILEPTR matFile) ;
int32
dpfPutFile(char *name, dpfFILEPTR Sfile) ;
int32
dpfPutFileBody(dpfFILEPTR Dfile,dpfFILEPTR Sfile) ;
dpfFILEPTR
dpfOpenNewFile(char *name, dpfFILEFORMAT form, dpfFILETYPE fileType) ;

dpfFILEPTR
dpfCreateFile(char *name) ;
int32
dpfJoinFile(dpfFILEPTR file1, dpfFILEPTR file2) ;
int32
dpfCloseFile(dpfFILEPTR file) ;
int32
dpfFreeFile(dpfFILEPTR) ;
int32
dpfKillFile(dpfFILEPTR file) ;

/* File info */
dpfFILETYPE
dpfGetFileType(dpfFILEPTR file) ;
dpfFILEFORMAT
dpfGetFileFormat(dpfFILEPTR file) ;
char *
dpfGetFileName(dpfFILEPTR file) ;

/* File info */
void
dpfSetFileType(dpfFILEPTR file, dpfFILETYPE type) ;
void
dpfSetFileFormat(dpfFILEPTR file,dpfFILEFORMAT format) ;

/* pfinfo information on struction, read and written */
int32
dpfCountFileContent(dpfFILEPTR file) ;
int32
dpfGetFileNoMaterials(dpfFILEPTR file) ;
int32
dpfGetFileNoTextures(dpfFILEPTR file) ;
int32
dpfGetFileNoRamps(dpfFILEPTR file) ;
int32
dpfGetFileNoObjects(dpfFILEPTR file) ;
int32
dpfGetFileNoLODs(dpfFILEPTR file) ;
int32
dpfGetFileNoPatches(dpfFILEPTR file) ;
int32
dpfGetFileNoGeometries(dpfFILEPTR file) ;
int32
dpfGetFileNoPolystrips(dpfFILEPTR file) ;
int32
dpfGetFileNoTristrips(dpfFILEPTR file) ;
int32
dpfGetFileNoPmeshes(dpfFILEPTR file) ;
int32
dpfGetFileNoSLists(dpfFILEPTR file) ;
int32
dpfGetFileNoSFaces(dpfFILEPTR file) ;
int32
dpfGetFileSFtimesP(dpfFILEPTR file) ;
int32
dpfGetFileNoCLists(dpfFILEPTR file) ;
int32
dpfGetFileNoCFaces(dpfFILEPTR file) ;
int32
dpfGetFileCFtimesP(dpfFILEPTR file) ;
int32
dpfGetFileNoVertices(dpfFILEPTR file) ;
int32
dpfGetFileNoTriangles(dpfFILEPTR file) ;
int32
dpfGetFileTotNoTriangles(dpfFILEPTR file) ;
int32
dpfGetFileNoSphereLists(dpfFILEPTR file) ;
int32
dpfGetFileNoSpheres(dpfFILEPTR file) ;
int32
dpfGetFileNoPointLists(dpfFILEPTR file) ;
int32
dpfGetFileNoPoints(dpfFILEPTR file) ;
int32
dpfGetFileNoLines(dpfFILEPTR file) ;
int32
dpfGetFileNoLineNodes(dpfFILEPTR file) ;
int32
dpfGetFileNoTexts(dpfFILEPTR file) ;
int32
dpfGetFileNoTextStrings(dpfFILEPTR file) ;
int32
dpfGetFileNoPolygons(dpfFILEPTR file) ;
int32
dpfGetFileNoPolygonVertices(dpfFILEPTR file) ;


/* pfmaterl materials */
dpfMATERIALPTR
dpfCreateMaterial(void) ;
char *
dpfCreateMaterialName(char *extPath, char *library, char *mname) ;
void
dpfCpyMaterial(dpfMATERIALPTR mat1, dpfMATERIALPTR mat2) ;
int32
dpfCmpMaterial(dpfMATERIALPTR mat1, dpfMATERIALPTR mat2) ;
dpfMATERIALPTR
dpfAddMaterial(dpfFILEPTR file, dpfMATERIALPTR mat) ;
dpfMATERIALPTR
dpfAddV1Material(dpfFILEPTR file, dpfMATERIALPTR mat) ;
int32
dpfFreeMaterial(dpfMATERIALPTR mat) ;

dpfFILEPTR
dpfGetMaterialParent(dpfMATERIALPTR mat) ;
dpfMATERIALPTR
dpfGetFrstMaterial(dpfFILEPTR file) ;
dpfMATERIALPTR
dpfGetNextMaterial(dpfMATERIALPTR mat) ;
dpfMATERIALPTR
dpfGetPrevMaterial(dpfMATERIALPTR mat) ;
dpfMATERIALPTR
dpfFindMaterial(dpfFILEPTR fp, char *matName) ;

/* Set material name literally sets the name to the given pointer, 
** so make sure it dynamically allocated and not used by anything else!
** If in doubt use copy name which creates a new dynamically allocated name.
*/
void 
dpfSetMaterialName(dpfMATERIALPTR mat, char *name) ;
void
dpfSetMaterialTexture(dpfMATERIALPTR mat, dpfMATTXTTYPE TxtType, char *name) ;
void 
dpfSetMaterialRamp(dpfMATERIALPTR mat, char *name) ;
void 
dpfSetMaterialAmbient(dpfMATERIALPTR mat,dpfRGBA colour) ;
void 
dpfSetMaterialDiffuse(dpfMATERIALPTR mat,dpfRGBA colour) ;
void 
dpfSetMaterialSpecular(dpfMATERIALPTR mat,dpfRGBA colour) ;
void 
dpfSetMaterialEmissive(dpfMATERIALPTR mat,dpfRGBA colour) ;
void 
dpfSetMaterialOpacity(dpfMATERIALPTR mat,dpfRGBA colour) ;

/* Returns a pointer to THE name. so don't destroy */
char *
dpfGetMaterialName(dpfMATERIALPTR mat) ;
dpfMATTXTTYPE
dpfGetMaterialTexture(dpfMATERIALPTR mat, char **name) ;
char *
dpfGetMaterialRamp(dpfMATERIALPTR mat) ;
void 
dpfGetMaterialAmbient(dpfMATERIALPTR mat,dpfRGBA colour) ;
void 
dpfGetMaterialDiffuse(dpfMATERIALPTR mat,dpfRGBA colour) ;
void 
dpfGetMaterialSpecular(dpfMATERIALPTR mat,dpfRGBA colour) ;
void 
dpfGetMaterialEmissive(dpfMATERIALPTR mat,dpfRGBA colour) ;
void 
dpfGetMaterialOpacity(dpfMATERIALPTR mat,dpfRGBA colour) ;


/* pfile General file loading calls */
void
dpfErrorOn(void) ;
void
dpfErrorOff(void) ;
void
dpfDebugOn(void) ;
void
dpfDebugOff(void) ;

/* Names and Strings and things */
char *
dpfCreateName(char *name) ;
char *
dpfDuplicateName(char *name) ;
void
dpfFreeName(char *name) ;
/* the return from cmp is similar to strcmp, ie 0 if the same, else non-zero */
int32
dpfCmpName(char *name1, char *name2) ;

/* Strings can have '\0' in them, so the first byte is the string length */
/* Create uses the str as its string, copy mallocs more space and copies
** in the string str 
*/
dpfSTRINGPTR
dpfCreateString(void) ;
dpfSTRINGPTR
dpfDuplicateString(dpfSTRINGPTR str) ;
int32
dpfSetString(dpfSTRINGPTR str, int32 Length, uint8 *theStr) ;
void
dpfFreeString(dpfSTRINGPTR str) ;
/* the return from cmp is similar to strcmp, ie 0 if the same, else non-zero */
int32
dpfCmpString(dpfSTRINGPTR str1, dpfSTRINGPTR str2) ;
int32
dpfGetStringLength(dpfSTRINGPTR str) ;
uint8 *
dpfGetStringString(dpfSTRINGPTR str) ;

/* pfcheck checks input values */
float32
dpfCheckRGB(float32 colour) ;
float32
dpfCheckAlpha(float32 alpha) ;
float32 
dpfCheckV1Power(float32 power) ;
float32
dpfCheckPower(float32 power) ;
float32
dpfCheckOpacity(float32 opacity) ;
uint16
dpfCheckDice(uint16 dice) ;

/* ramp stuff */
dpfRAMPPTR 
dpfCreateRamp(void);
int32
dpfCmpRamp(dpfRAMPPTR r1, dpfRAMPPTR r2) ;
dpfRAMPPTR
dpfAddRamp(dpfFILEPTR file, dpfRAMPPTR r) ;
int32
dpfFreeRamp(dpfRAMPPTR r) ;

dpfFILEPTR
dpfGetRampParent(dpfRAMPPTR mat) ;
dpfRAMPPTR
dpfGetFrstRamp(dpfFILEPTR file) ;
dpfRAMPPTR
dpfGetNextRamp(dpfRAMPPTR mat) ;
dpfRAMPPTR
dpfGetPrevRamp(dpfRAMPPTR mat) ;
dpfRAMPPTR
dpfFindRamp(dpfFILEPTR fp, char *rampName) ;

void
dpfSetRampName(dpfRAMPPTR r, char *a);
void
dpfSetRampData(dpfRAMPPTR r, dpfRGBA a, dpfRGBA b);
char *
dpfGetRampName(dpfRAMPPTR r);
void
dpfGetRampData(dpfRAMPPTR r, dpfRGBA data0, dpfRGBA data1) ;

/* new boundary stuff */
dpfBOUNDPTR
dpfCreateBound(void) ;
int32
dpfUnlinkBound(dpfBOUNDPTR bound) ;
int32
dpfAddFileBound(dpfFILEPTR file, dpfBOUNDPTR bound) ;
int32
dpfAddBoundBound(dpfBOUNDPTR prnt, dpfBOUNDPTR bound) ;
int32
dpfFreeBound(dpfBOUNDPTR bound) ;
dpfFILEPTR
dpfGetBoundFile(dpfBOUNDPTR bound) ;
dpfBOUNDPTR
dpfGetBoundParent(dpfBOUNDPTR bound) ;
dpfBOUNDPTR
dpfGetFileBound(dpfFILEPTR file) ;
dpfBOUNDPTR
dpfGetFrstBound(dpfBOUNDPTR bound) ;
dpfBOUNDPTR
dpfGetNextBound(dpfBOUNDPTR bound) ;
dpfBOUNDPTR
dpfGetPrevBound(dpfBOUNDPTR bound) ;
void
dpfSetBoundSphere(dpfBOUNDPTR bound, int32 present, float32 radius,
                  dmVector point) ;
void
dpfSetBoundBox(dpfBOUNDPTR bound,int32 present,dmVector bMin,dmVector bMax, dmVector orien) ;
void
dpfSetBoundPmesh(dpfBOUNDPTR bound, dpfGEOMETRYPTR pmesh) ;
void
dpfSetBoundAuto(dpfBOUNDPTR bound, uint8 Auto) ;
void
dpfSetBoundLODName(dpfBOUNDPTR bound, char *name) ;
void
dpfSetBoundObjectName(dpfBOUNDPTR bound, char *name) ;
int32
dpfGetBoundSphere(dpfBOUNDPTR bound, float32 *radius, dmVector point) ;
int32
dpfGetBoundBox(dpfBOUNDPTR bound, dmVector bMin, dmVector bMax, dmVector orien) ;
dpfGEOMETRYPTR
dpfGetBoundPmesh(dpfBOUNDPTR bound) ;
uint8
dpfGetBoundAuto(dpfBOUNDPTR bound) ;
void
dpfCalcBBoxInitialize(dpfBOUNDPTR bound) ;
void
dpfCalcPointBBox(dmVector vec, dmVector MinVec, dmVector MaxVec) ;
int32
dpfCalcGeometryBBox(dpfGEOMETRYPTR geom, dpfBOUNDPTR bound) ;
int32
dpfCalcPatchBBox(dpfPATCHPTR patch, dpfBOUNDPTR bound) ;
int32
dpfCalcLODBBox(dpfLODPTR lod, dpfBOUNDPTR bound) ;
int32
dpfCalcBBox(dpfFILEPTR file, dpfBOUNDPTR bound) ;
int32
dpfCalcGeometryBSphere(dpfGEOMETRYPTR geom, dpfBOUNDPTR bound) ;
int32
dpfCalcPatchBSphere(dpfPATCHPTR patch, dpfBOUNDPTR bound) ;
int32
dpfCalcBSphere(dpfFILEPTR file, dpfBOUNDPTR bound) ;
int32
dpfCheckBound(dpfFILEPTR file) ;

/*** texture stuff ***/
dpfTEXTUREPTR
dpfCreateTexture(void);
int32
dpfCpyTexture(dpfTEXTUREPTR txt1, dpfTEXTUREPTR txt2) ;
int32
dpfCmpTexture(dpfTEXTUREPTR txt1, dpfTEXTUREPTR txt2) ;
dpfTEXTUREPTR
dpfAddTexture(dpfFILEPTR file, dpfTEXTUREPTR txt) ;
int32
dpfUnlinkTexture(dpfTEXTUREPTR txt) ;
int32
dpfFreeTexture(dpfTEXTUREPTR txt) ;

dpfFILEPTR
dpfGetTextureParent(dpfTEXTUREPTR txt) ;
dpfTEXTUREPTR
dpfGetFrstTexture(dpfFILEPTR file) ;
dpfTEXTUREPTR
dpfGetNextTexture(dpfTEXTUREPTR txt) ;
dpfTEXTUREPTR
dpfGetPrevTexture(dpfTEXTUREPTR txt) ;
dpfTEXTUREPTR
dpfFindTexture(dpfFILEPTR fp, char *txtName) ;

void
dpfSetTextureName(dpfTEXTUREPTR t, char *a);
void
dpfSetTextureMap(dpfTEXTUREPTR t, char *a);
void
dpfSetTextureWrap(dpfTEXTUREPTR t, int32 a);
void
dpfSetTextureUWrap(dpfTEXTUREPTR t, int32 a);
void
dpfSetTextureVWrap(dpfTEXTUREPTR t, int32 a);
void
dpfSetTextureDetail(dpfTEXTUREPTR t, dpfDETAIL detail, char *name) ;
void
dpfSetTextureMinify(dpfTEXTUREPTR t, int32 a);
void
dpfSetTextureMagnify(dpfTEXTUREPTR t, int32 a);
void
dpfSetTextureAlpha(dpfTEXTUREPTR t, int32 a);
void
dpfSetTextureBitslice(dpfTEXTUREPTR t, uint8 a);

char *
dpfGetTextureName(dpfTEXTUREPTR t) ;
char *
dpfGetTextureMap(dpfTEXTUREPTR t) ;
void
dpfGetTextureWrap(dpfTEXTUREPTR t, int32 a) ;
dpfWRAP
dpfGetTextureUWrap(dpfTEXTUREPTR t) ;
dpfWRAP
dpfGetTextureVWrap(dpfTEXTUREPTR t) ;
dpfDETAIL
dpfGetTextureDetail(dpfTEXTUREPTR t, char **name) ;
dpfMINIFY
dpfGetTextureMinify(dpfTEXTUREPTR t) ;
dpfMAGNIFY
dpfGetTextureMagnify(dpfTEXTUREPTR t) ;
dpfALPHA
dpfGetTextureAlpha(dpfTEXTUREPTR t) ;
uint8
dpfGetTextureBitslice(dpfTEXTUREPTR t) ;


/*** header stuff ***/
void
dpfSetFileVersion(dpfFILEPTR f, uint8 i, uint8 j);
void
dpfSetFileDate(dpfFILEPTR f, uint8 i, uint8 j, uint8 k);
void
dpfSetFileTime(dpfFILEPTR f, uint8 i, uint8 j);
void
dpfSetFileUnit(dpfFILEPTR f, dpfUNIT i);
void
dpfSetFileScale(dpfFILEPTR f, float32 i);
void
dpfSetFilePrecision(dpfFILEPTR f, dpfPRECISION i);
void
dpfSetHeaderComment(dpfFILEPTR f, dpfSTRINGPTR i);

void
dpfGetLibraryVersion(uint8 *i, uint8 *j) ;
int32
dpfGetFileVersion(dpfFILEPTR f, uint8 *verMajor, uint8 *verMinor) ;
int32
dpfGetFileDate(dpfFILEPTR f, uint8 *dpfday, uint8 *dpfmonth, uint8 *dpfyear) ;
int32
dpfGetFileTime(dpfFILEPTR f, uint8 *dpfhours, uint8 *dpfminutes) ;
dpfUNIT
dpfGetFileUnit(dpfFILEPTR f) ;
float32
dpfGetFileScale(dpfFILEPTR f) ;
dpfPRECISION
dpfGetFilePrecision(dpfFILEPTR f) ; 
dpfSTRINGPTR
dpfGetFileComment(dpfFILEPTR f) ;

/**************** callbacks *******************/
/* The following functions are used to set callbacks 
 * for each of several structures.  They are called when
 * a structure has been completed and would normally be
 * linked into the file structure.  The procedure is passed
 * a pointer to the structure to do with as it wishes and
 * returns an integer value.  If the return value is 1 the
 * structure is freed, otherwise it is linked into the
 * file structure as usual.
 */


/* new whizzy v1.0 -> v2.0 texture name converter stuff */
struct dpfVISTEXTURETYPE ;
typedef struct dpfVISTEXTURETYPE *dpfVISTEXTUREPTR;

dpfVISTEXTUREPTR
dpfCreateV1TextureList(char *mazName) ;
void
dpfSetFileVisList(dpfFILEPTR file, dpfVISTEXTUREPTR visList) ;
void
dpfConvertV1Texture(dpfFILEPTR Sfp, dpfMATERIALPTR Fmat, dpfMATERIALPTR Bmat) ;
void
dpfFreeV1TextureList(dpfVISTEXTUREPTR visList) ;


int32
dpfCheckFile(dpfFILEPTR file) ;


#endif /* __PFILE_H__ */

