//*************************************************************************
//              3D-Ware 32-bit Header File
//*************************************************************************

#ifndef DDDWARE_INC

#ifdef __cplusplus
extern "C" {
#define WinFuncCreateDC  ::CreateDC
#define WinFuncCreatePalette  ::CreatePalette
#define WinFuncDeleteDC  ::DeleteDC
#define WinFuncDeleteObject  ::DeleteObject
#define WinFuncDispatchMessage  ::DispatchMessage
#define WinFuncGetDC  ::GetDC
#define WinFuncGetSystemPaletteEntries  ::GetSystemPaletteEntries
#define WinFuncPeekMessage  ::PeekMessage
#define WinFuncPostMessage  ::PostMessage
#define WinFuncRealizePalette  ::RealizePalette
#define WinFuncReleaseDC  ::ReleaseDC
#define WinFuncSelectPalette  ::SelectPalette
#define WinFuncSetDIBitsToDevice  ::SetDIBitsToDevice
#define WinFuncStretchDIBits  ::StretchDIBits
#define WinFuncUnrealizeObject  ::UnrealizeObject
#endif
#ifndef __cplusplus
#define WinFuncCreateDC  CreateDC
#define WinFuncCreatePalette  CreatePalette
#define WinFuncDeleteDC  DeleteDC
#define WinFuncDeleteObject  DeleteObject
#define WinFuncDispatchMessage  DispatchMessage
#define WinFuncGetDC  GetDC
#define WinFuncGetSystemPaletteEntries  GetSystemPaletteEntries
#define WinFuncPeekMessage  PeekMessage
#define WinFuncPostMessage  PostMessage
#define WinFuncRealizePalette  RealizePalette
#define WinFuncReleaseDC  ReleaseDC
#define WinFuncSelectPalette  SelectPalette
#define WinFuncSetDIBitsToDevice  SetDIBitsToDevice
#define WinFuncStretchDIBits  StretchDIBits
#define WinFuncUnrealizeObject  UnrealizeObject
#endif


//*************************************************************************
//System Extensions
//*************************************************************************

extern void __cdecl dddSetSystemFunctions(long,void *,...);

#ifdef WIN32_PASCAL_CALLING
#define dddcall __pascal
#define DDDWINDOWS
#define dddInit(a,b,c) \
dddSetSystemFunctions(21, \
WinFuncCreateDC, \
WinFuncCreatePalette, \
WinFuncDeleteDC, \
WinFuncDeleteObject, \
WinFuncDispatchMessage, \
WinFuncGetDC, \
WinFuncGetSystemPaletteEntries, \
WinFuncPeekMessage, \
WinFuncPostMessage, \
WinFuncRealizePalette, \
WinFuncReleaseDC, \
WinFuncSelectPalette, \
WinFuncSetDIBitsToDevice, \
WinFuncStretchDIBits, \
WinFuncUnrealizeObject, \
_lopen, \
_lclose, \
_lcreat, \
_lread, \
_lwrite, \
_llseek); \
dddInitWin32(a,b,c); 
#endif

#ifdef WIN32S_PASCAL_CALLING
#define dddcall __pascal
#define DDDWINDOWS
#define dddInit(a,b,c) \
dddSetSystemFunctions(21, \
WinFuncCreateDC, \
WinFuncCreatePalette, \
WinFuncDeleteDC, \
WinFuncDeleteObject, \
WinFuncDispatchMessage, \
WinFuncGetDC, \
WinFuncGetSystemPaletteEntries, \
WinFuncPeekMessage, \
WinFuncPostMessage, \
WinFuncRealizePalette, \
WinFuncReleaseDC, \
WinFuncSelectPalette, \
WinFuncSetDIBitsToDevice, \
WinFuncStretchDIBits, \
WinFuncUnrealizeObject, \
_lopen, \
_lclose, \
_lcreat, \
_lread, \
_lwrite, \
_llseek); \
dddInitWin32S(a,b,c); 
#endif

#ifdef WIN32_C_CALLING
#define dddcall __cdecl
#define DDDWINDOWS
#define dddInit(a,b,c) \
dddSetSystemFunctions(21, \
WinFuncCreateDC, \
WinFuncCreatePalette, \
WinFuncDeleteDC, \
WinFuncDeleteObject, \
WinFuncDispatchMessage, \
WinFuncGetDC, \
WinFuncGetSystemPaletteEntries, \
WinFuncPeekMessage, \
WinFuncPostMessage, \
WinFuncRealizePalette, \
WinFuncReleaseDC, \
WinFuncSelectPalette, \
WinFuncSetDIBitsToDevice, \
WinFuncStretchDIBits, \
WinFuncUnrealizeObject, \
_lopen, \
_lclose, \
_lcreat, \
_lread, \
_lwrite, \
_llseek); \
dddInitWin32(a,b,c); 
#endif

#ifdef WIN32S_C_CALLING
#define dddcall __cdecl
#define DDDWINDOWS
#define dddInit(a,b,c) \
dddSetSystemFunctions(21, \
WinFuncCreateDC, \
WinFuncCreatePalette, \
WinFuncDeleteDC, \
WinFuncDeleteObject, \
WinFuncDispatchMessage, \
WinFuncGetDC, \
WinFuncGetSystemPaletteEntries, \
WinFuncPeekMessage, \
WinFuncPostMessage, \
WinFuncRealizePalette, \
WinFuncReleaseDC, \
WinFuncSelectPalette, \
WinFuncSetDIBitsToDevice, \
WinFuncStretchDIBits, \
WinFuncUnrealizeObject, \
_lopen, \
_lclose, \
_lcreat, \
_lread, \
_lwrite, \
_llseek); \
dddInitWin32S(a,b,c); 
#endif

#ifdef DOS_PASCAL_CALLING
#define dddcall __pascal
#define DDDDOS
#define dddInit(a,b,c) dddInitDos(a,b,c)
#endif

#ifdef DOS_C_CALLING
#define dddcall __cdecl
#define DDDDOS
#define dddInit(a,b,c) dddInitDos(a,b,c)
#endif

#ifdef NEWOS_PASCAL_CALLING
#define dddcall __pascal
#endif

#ifdef NEWOS_C_CALLING
#define dddcall __cdecl
#endif



//*************************************************************************

//Defined strings

#define DDDWARE_INC             0

//predefined dddware Windows message
#define WM_DDDREDRAW            0x9000
#define WM_DDDSTOP              0x9001
#define WM_DDDSTART             0x9002

//Graphics Modes
#define VGA8BIT320X200          0x00013
#define VGA8BIT320X400          0x10013

//Mouse defines
#define BUTTON_L                1
#define BUTTON_R                2
#define BUTTON_B                3
#define LEFT_BUTTON             (dddGetMouseValue(MOUSEBUTTONS)==BUTTON_L)
#define RIGHT_BUTTON            (dddGetMouseValue(MOUSEBUTTONS)==BUTTON_R)
#define BOTH_BUTTON             (dddGetMouseValue(MOUSEBUTTONS)==BUTTON_B)
#define EITHER_BUTTON           ((dddGetMouseValue(MOUSEBUTTONS)==BUTTON_L) | (dddGetMouseValue(MOUSEBUTTONS)==BUTTON_R))

//Mouse Values
#define MOUSEPOSX               0
#define MOUSEPOSY               1
#define MOUSERELX               2
#define MOUSERELY               3
#define MOUSEBUTTONS            4

//Object Types
#define DUMMY                   0x0000
#define SHAPE                   0x0001
#define CAMERA                  0x0002
#define SOUND                   0x0003
#define AMBIENT_LIGHT           0x0004
#define VECTOR_LIGHT            0x0005
#define OMNI_LIGHT              0x0006
#define SPOT_LIGHT              0x0007
#define INT_SHAPE               0x0008

//Render Methods
#define RENDERED                0x8000
#define LINEON                  0x0010
#define ZBUFFERED               0x0020
#define FLAT_SHADE              0x0040
#define GOURAUD_SHADE           0x0080
#define RM_TRANSPARENT          0x0100
#define RM_ALPHABLEND           0x0200

//Polygon Types
#define NORMAL                  0x0000
#define PATTERN                 0x0400
#define GOURAUD                 0x0800
#define QTEXTURE                0x0C00
#define TEXTURE                 0x1000

//Vertex Types
#define SCREEN                  0x0000
#define POSREL                  0x2000
#define POSABS                  0x4000

//*************************************************************************

//Global Structures

typedef struct screen_struct
{
        short   size_x,size_y;
        short   max_size_x,max_size_y;
        char *  screenptr;
        short * zbufferptr;
        long    reserved;
} screen_struct;

typedef struct position_struct
{
        long    x,y,z;
} position_struct;

typedef struct angle_struct
{
        short   x,y,z;
} angle_struct;

typedef struct collision_data
{
        position_struct center;
        position_struct extents;
} collision_data;

typedef struct point_struct
{
        position_struct       Pos;
        position_struct       ScrPos;
        long                  Inter1;
        long                  Inter2;
        long                  Inter3;
        long                  Inter4;
        long                  Inter5;
        long                  Inter6;
        long                  Inter7;
        struct point_struct * ForwardPtr;
        struct point_struct * BackwardPtr;
        unsigned long         reserved;
} point_struct;

typedef struct object_struct
{
        position_struct Pos;
        angle_struct    Ang;    
        unsigned short  Type;   
        long            Flags;  
        void *          DataPtr; 
        long            reserved[9];
} object_struct;

typedef struct color_struct
{
        unsigned char   r;
        unsigned char   g;
        unsigned char   b;
        unsigned char   reserved;
} color_struct;

typedef struct pal_struct
{
        long             reserved;
        color_struct    Color[256];
} pal_struct;

typedef screen_struct *         VtkScr;
typedef object_struct *         VtkObj;
typedef void *                  VtkFont;
typedef unsigned char           VtkTransTab[256][256];
typedef unsigned long           color_val;
typedef long                    VtkMat[9];
typedef unsigned long           VtkDWord;
typedef pal_struct *            VtkPal;
typedef void(__cdecl *VtkCFunc)(void);

//*************************************************************************

//Global Variables
extern screen_struct __cdecl    Default320x200;
extern screen_struct __cdecl    Default320x400;

//Single Height Fonts
extern long     __cdecl         dddFont3x5[];
extern long     __cdecl         dddFont7x7[];
extern long     __cdecl         dddFont8x9[];

//Double Height Fonts (for stereo)
extern long     __cdecl         dddFont8x16[];
extern long     __cdecl         dddFont12x24[];

//*************************************************************************

//*** UNIVERSAL **

//Defined Functions

//Debug Functions
extern void              dddcall  dddDebugOn(void);
extern void              dddcall  dddDebugOff(void);
extern void              __cdecl  dddDebugText(const char *);

//File Functions
extern void *            dddcall  dddLoadFile(const char *);
extern unsigned long     dddcall  dddSaveFile(const char *,void *,unsigned long);

//Maths
extern angle_struct *    dddcall  dddAlign(angle_struct *,position_struct *,position_struct *);
extern short             dddcall  dddAtan(long,long);
extern void              dddcall  dddInitRnd(long);
extern void              dddcall  dddGenerate3dMatrix(VtkMat *out_matrix,angle_struct *input_angles);
extern long              dddcall  dddGetSine(short);
extern long              dddcall  dddGetCosine(short);
extern void              dddcall  dddProjectPoint(position_struct *,angle_struct *,short);
extern void              dddcall  dddRotate3dPoint(position_struct *,VtkMat *matrix);
extern VtkDWord          dddcall  dddRnd(void);
extern unsigned short    dddcall  dddSquareRoot(unsigned long);
extern long              dddcall  dddGetClock(void);

//File
extern VtkFont           dddcall  dddFontLoad(const char *);
extern void *            dddcall  dddTextureLoad(const char *);
extern VtkPal            dddcall  dddPaletteLoad(const char *);
extern VtkDWord          dddcall  dddFOpen(const char *);
extern void              dddcall  dddFClose(VtkDWord);
extern VtkDWord          dddcall  dddFCreate(const char *);
extern unsigned long     dddcall  dddFRead(VtkDWord,void *,unsigned long);
extern unsigned long     dddcall  dddFWrite(VtkDWord,void *,unsigned long);
extern unsigned long     dddcall  dddFLSeek(VtkDWord,long,long);
extern unsigned long     dddcall  dddFLength(VtkDWord);

//Memory
extern void              dddcall  dddRestoreAll(void);
extern void              dddcall  dddSetBeforeCloseCall(void(*func)(void));
extern void              dddcall  dddSetAfterCloseCall(void(*func)(void));
extern VtkCFunc          dddcall  dddGetBeforeCloseCall(void);
extern VtkCFunc          dddcall  dddGetAfterCloseCall(void);
extern void *            dddcall  dddMemAlloc(unsigned long);
extern void              dddcall  dddMemFree(void *);
extern void *            dddcall  dddMemRealloc(void *,unsigned long);
extern unsigned long     dddcall  dddMemSize(void *);


//Screen 
extern short             dddcall  dddCreateScreenX(long x,long z);
extern short             dddcall  dddCreateScreenY(long y,long z);
extern VtkDWord          dddcall  dddCreateScreenZ(long z);

extern void              dddcall  dddCls(void);
extern void              __cdecl  dddDrawPoly(VtkDWord Type,VtkDWord Data,unsigned long NumberOfPoints,point_struct *p1,...);
extern void              dddcall  dddDefinePolyFunctions(VtkDWord PolyType,int InterType,
                                                         void *BeforeZ_Shape,void *BeforeZ_Poly,
                                                         void *AfterZ,void *EgdeCalc,void *ScanCalc,
                                                         void *ScanFill,void *Extra);
extern void              dddcall  dddFillScreen(color_val);
extern color_val         dddcall  dddGetPixel(long x,long y);
extern void              dddcall  dddPrint(VtkFont,color_val,short,short,const char *);
extern void              dddcall  dddSelectMemoryScreen(screen_struct *);
extern void              dddcall  dddSetCenter(long center_x,long center_y);
extern void              dddcall  dddSetClipArea(long minx,long miny,long maxx,long maxy);
extern void              dddcall  dddSetPixel(color_val,long x,long y);
extern void              dddcall  dddSetScreenPtr(void *);
extern void              dddcall  dddVsync(void);
extern void              dddcall  dddZBCls(void);

//Setting enviroment
extern VtkTransTab *     dddcall  dddCreateTransparencyTable(VtkPal pal);
extern void              dddcall  dddLookAt(object_struct *,position_struct *,angle_struct *,long);
extern void              dddcall  dddSetZBValue(long);
extern void              dddcall  dddSetLineOnColor(color_val);
extern void              dddcall  dddSetReturnObjectPos(VtkObj *,long *,long,long);
extern VtkPal            dddcall  dddSetPalette(VtkPal); 
extern VtkTransTab *     dddcall  dddSetTransparencyTable(VtkTransTab *);

//Object Functions
//RENDERING
extern void              dddcall  dddClearObjects(void);
extern void              dddcall  dddInsertObject(VtkObj Obj);
extern long              dddcall  dddSelectCamera(VtkObj CameraObj);
extern long              dddcall  dddDrawObjects(void);

//CREATION
extern VtkObj            dddcall  dddCreateDummyObject(void);
extern VtkObj            dddcall  dddCreateCamera(unsigned long cutoff,short persective_x,short persective_y);
extern VtkObj            dddcall  dddCreateLight(VtkDWord type,color_val intensity,short cone_angle);
extern VtkObj            dddcall  dddLoad(const char *FileName);
extern void              dddcall  dddDestroy(VtkObj object);
extern void              dddcall  dddSetObjectUserDataSize(unsigned long);

//LINKS
extern long              dddcall  dddAttach(VtkObj obj,VtkObj parent,const char *name,long x,long y,long z,short ax,short ay,short az);
extern long              dddcall  dddAttachToDeclaredName(VtkObj obj,VtkObj parent,const char *name);
extern void              dddcall  dddDetach(VtkObj obj);
extern void              dddcall  dddDetachChildren(VtkObj obj);
extern angle_struct *    dddcall  dddGetDeclaredNameAng(VtkObj obj,const char *name,angle_struct *return_ang);
extern position_struct * dddcall  dddGetDeclaredNamePos(VtkObj obj,const char *name,position_struct *return_pos);
extern VtkObj            dddcall  dddPart(VtkObj obj,char *part_name);

//DEPENDENT
extern long              dddcall  dddSetShapeFlags(VtkObj obj, VtkDWord new_flags);
extern VtkDWord          dddcall  dddGetShapeFlags(VtkObj obj);
extern long              dddcall  dddSetCameraCutoff(VtkObj obj,unsigned long cutoff);
extern unsigned long     dddcall  dddGetCameraCutoff(VtkObj obj);
extern long              dddcall  dddSetCameraPerspectiveX(VtkObj obj,long perspective);
extern long              dddcall  dddGetCameraPerspectiveX(VtkObj obj);
extern long              dddcall  dddSetCameraPerspectiveY(VtkObj obj,long perspective);
extern long              dddcall  dddGetCameraPerspectiveY(VtkObj obj);
extern VtkDWord          dddcall  dddGetLightType(VtkObj obj);
extern long              dddcall  dddSetLightIntensity(VtkObj obj,color_val intensity);
extern color_val         dddcall  dddGetLightIntensity(VtkObj obj);
extern long              dddcall  dddSetLightConeAngle(VtkObj obj,short cone_angle);
extern short             dddcall  dddGetLightConeAngle(VtkObj obj);
extern long              dddcall  dddGetMaxExtent(VtkObj obj);
extern collision_data *  dddcall  dddGetCollisionBoxes(VtkObj obj);

//GENERIC
extern void              dddcall  dddSetRenderMethod(VtkObj obj, VtkDWord new_method);
extern VtkDWord          dddcall  dddGetRenderMethod(VtkObj obj);
extern angle_struct *    dddcall  dddGetAbsAng(VtkObj obj,angle_struct *angs_out);
extern position_struct * dddcall  dddGetAbsPos(VtkObj obj,position_struct *pos_out);
extern angle_struct *    dddcall  dddGetAngles(VtkObj obj,angle_struct *angs_out);
extern position_struct * dddcall  dddGetPosition(VtkObj obj,position_struct *pos_out);
extern angle_struct *    dddcall  dddAlignObj(angle_struct *,VtkObj obj,position_struct *);
extern VtkMat *          dddcall  dddGetObjectMatrix(VtkObj obj);
extern void              dddcall  dddProjectObj(VtkObj obj,short);
extern void              dddcall  dddMoveTo(VtkObj obj,long x,long y,long z);
extern void              dddcall  dddRotateTo(VtkObj obj,short x,short y,short z);
extern void              dddcall  dddMoveBy(VtkObj obj,long x,long y,long z);
extern void              dddcall  dddRotateBy(VtkObj obj,short x,short y,short z);

//*** WINDOWS MODE **
#ifdef DDDWINDOWS
extern  void             __cdecl  dddContinuousMessageLoop(HWND AppHwnd,MSG *AppMsg,void(*UserFunction)(MSG *));
extern  void             dddcall  dddInitWin32(void *(*mem_alloc)(unsigned),
                                               void(*mem_free)(void *),
                                               void *file_read_function);
extern  void             dddcall  dddInitWin32S( void *(*mem_alloc)(unsigned),
                                                void(*mem_free)(void *),
                                                void *file_read_function);
extern  void             __cdecl  dddScreenCopy(HWND dest_hwnd,long x_pos,long y_pos);
extern  void             __cdecl  dddStretchScreenCopy(HWND dest_hwnd,long x_pos,long y_pos,long x_size,long y_size);
#endif

#ifdef DDDDOS
//*** DOS MODE **
extern void              dddcall  dddInitDos(void *(*mem_alloc)(unsigned),
															void(*mem_free)(void *),
															void *file_read_function);
extern void              __cdecl  dddScreenCopy(void);
extern long              dddcall  dddSetVideo(long);

//Mouse
extern void              dddcall  dddDrawMouse(void *);
extern void              dddcall  dddInitMouse(void);
extern void              dddcall  dddReadMouse(void);
extern void              dddcall  dddReadMouseRel(void);
extern long              dddcall  dddGetMouseValue(long);
extern void              dddcall  dddSetMouseValue(long,long);
#endif

//*************************************************************************

#ifdef __cplusplus
};
#endif

#endif
        
