summaryrefslogtreecommitdiffstats
path: root/src/fakerw/rwplcore.h
blob: 79c745b6e2be7a3e0842bb7af1f5010b2c20f49c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
#pragma once

typedef rw::int8 RwInt8;
typedef rw::int16 RwInt16;
typedef rw::int32 RwInt32;
typedef rw::uint8 RwUInt8;
typedef rw::uint16 RwUInt16;
typedef rw::uint32 RwUInt32;
typedef rw::float32 RwReal;

typedef char RwChar;
typedef RwInt32 RwBool;

#define __RWUNUSED__

#ifndef FALSE
#define FALSE 0
#endif

#ifndef TRUE
#define TRUE !FALSE
#endif

// used for unicode
#define RWSTRING(x) x

typedef rw::V2d RwV2d;

typedef rw::V3d RwV3d;

typedef rw::Rect RwRect;

typedef rw::Sphere RwSphere;

enum RwTextureCoordinateIndex
{
	rwNARWTEXTURECOORDINATEINDEX = 0,
	rwTEXTURECOORDINATEINDEX0,
	rwTEXTURECOORDINATEINDEX1,
	rwTEXTURECOORDINATEINDEX2,
	rwTEXTURECOORDINATEINDEX3,
	rwTEXTURECOORDINATEINDEX4,
	rwTEXTURECOORDINATEINDEX5,
	rwTEXTURECOORDINATEINDEX6,
	rwTEXTURECOORDINATEINDEX7,
};

typedef rw::TexCoords RwTexCoords;

typedef rw::SurfaceProperties RwSurfaceProperties;

#define RWRGBALONG(r,g,b,a)                                             \
    ((RwUInt32) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b)))


#define MAKECHUNKID(vendorID, chunkID) (((vendorID & 0xFFFFFF) << 8) | (chunkID & 0xFF))

enum RwCorePluginID
{
	rwID_NAOBJECT               = 0x00,
	rwID_STRUCT                 = 0x01,
	rwID_STRING                 = 0x02,
	rwID_EXTENSION              = 0x03,
	rwID_CAMERA                 = 0x05,
	rwID_TEXTURE                = 0x06,
	rwID_MATERIAL               = 0x07,
	rwID_MATLIST                = 0x08,
	rwID_ATOMICSECT             = 0x09,
	rwID_PLANESECT              = 0x0A,
	rwID_WORLD                  = 0x0B,
	rwID_SPLINE                 = 0x0C,
	rwID_MATRIX                 = 0x0D,
	rwID_FRAMELIST              = 0x0E,
	rwID_GEOMETRY               = 0x0F,
	rwID_CLUMP                  = 0x10,
	rwID_LIGHT                  = 0x12,
	rwID_UNICODESTRING          = 0x13,
	rwID_ATOMIC                 = 0x14,
	rwID_TEXTURENATIVE          = 0x15,
	rwID_TEXDICTIONARY          = 0x16,
	rwID_ANIMDATABASE           = 0x17,
	rwID_IMAGE                  = 0x18,
	rwID_SKINANIMATION          = 0x19,
	rwID_GEOMETRYLIST           = 0x1A,
	rwID_HANIMANIMATION         = 0x1B,
	rwID_TEAM                   = 0x1C,
	rwID_CROWD                  = 0x1D,
	rwID_DMORPHANIMATION        = 0x1E,
	rwID_RIGHTTORENDER          = 0x1f,
	rwID_MTEFFECTNATIVE         = 0x20,
	rwID_MTEFFECTDICT           = 0x21,
	rwID_TEAMDICTIONARY         = 0x22,
	rwID_PITEXDICTIONARY        = 0x23,
	rwID_TOC                    = 0x24,
	rwID_PRTSTDGLOBALDATA       = 0x25,
	/* Insert before MAX and increment MAX */
	rwID_COREPLUGINIDMAX        = 0x26,
};


/*
 ***********************************************
 *
 * RwObject
 *
 ***********************************************
 */

//struct RwObject;
typedef rw::Object RwObject;

typedef RwObject *(*RwObjectCallBack)(RwObject *object, void *data);

RwUInt8 RwObjectGetType(const RwObject *obj);



#define rwsprintf   sprintf
#define rwvsprintf  vsprintf
#define rwstrcpy    strcpy
#define rwstrncpy   strncpy
#define rwstrcat    strcat
#define rwstrncat   strncat
#define rwstrrchr   strrchr
#define rwstrchr    strchr
#define rwstrstr    strstr
#define rwstrcmp    strcmp
#define rwstricmp   stricmp
#define rwstrlen    strlen
#define rwstrupr    strupr
#define rwstrlwr    strlwr
#define rwstrtok    strtok
#define rwsscanf    sscanf


/*
 ***********************************************
 *
 * Memory
 *
 ***********************************************
 */

struct RwMemoryFunctions;
/*
{
	void *(*rwmalloc)(size_t size);
	void  (*rwfree)(void *mem);
	void *(*rwrealloc)(void *mem, size_t newSize);
	void *(*rwcalloc)(size_t numObj, size_t sizeObj);
};
*/

void *RwMalloc(size_t size);
void  RwFree(void *mem);
void *RwRealloc(void *mem, size_t newSize);
void *RwCalloc(size_t numObj, size_t sizeObj);

/*
 ***********************************************
 *
 * RwStream
 *
 ***********************************************
 */

//struct RwStream;
typedef rw::Stream RwStream;

struct RwMemory
{
	RwUInt8     *start;
	RwUInt32    length;
};

enum RwStreamType
{
	rwNASTREAM = 0,
	rwSTREAMFILE,
	rwSTREAMFILENAME,
	rwSTREAMMEMORY,
	rwSTREAMCUSTOM
};

enum RwStreamAccessType
{
	rwNASTREAMACCESS = 0,
	rwSTREAMREAD,
	rwSTREAMWRITE,
	rwSTREAMAPPEND
};

RwStream *RwStreamOpen(RwStreamType type, RwStreamAccessType accessType, const void *pData);
RwBool RwStreamClose(RwStream * stream, void *pData);
RwUInt32 RwStreamRead(RwStream * stream, void *buffer, RwUInt32 length);
RwStream *RwStreamWrite(RwStream * stream, const void *buffer, RwUInt32 length);
RwStream *RwStreamSkip(RwStream * stream, RwUInt32 offset);


/*
 ***********************************************
 *
 * Plugin Registry 
 *
 ***********************************************
 */

#define RWPLUGINOFFSET(_type, _base, _offset)                   \
   ((_type *)((RwUInt8 *)(_base) + (_offset)))

typedef RwStream *(*RwPluginDataChunkWriteCallBack)(RwStream *stream, RwInt32 binaryLength, const void *object, RwInt32 offsetInObject, RwInt32 sizeInObject);
typedef RwStream *(*RwPluginDataChunkReadCallBack)(RwStream *stream, RwInt32 binaryLength, void *object, RwInt32 offsetInObject, RwInt32 sizeInObject);
typedef RwInt32(*RwPluginDataChunkGetSizeCallBack)(const void *object, RwInt32 offsetInObject, RwInt32 sizeInObject);
typedef RwBool(*RwPluginDataChunkAlwaysCallBack)(void *object, RwInt32 offsetInObject, RwInt32 sizeInObject);
typedef RwBool(*RwPluginDataChunkRightsCallBack)(void *object, RwInt32 offsetInObject, RwInt32 sizeInObject, RwUInt32 extraData);
typedef void *(*RwPluginObjectConstructor)(void *object, RwInt32 offsetInObject, RwInt32 sizeInObject);
typedef void *(*RwPluginObjectCopy)(void *dstObject, const void *srcObject, RwInt32 offsetInObject, RwInt32 sizeInObject);
typedef void *(*RwPluginObjectDestructor)(void *object, RwInt32 offsetInObject, RwInt32 sizeInObject);

/*
 ***********************************************
 *
 * RwMatrix
 *
 ***********************************************
 */

typedef rw::Matrix RwMatrix;

enum RwOpCombineType
{
	rwCOMBINEREPLACE = rw::COMBINEREPLACE,
	rwCOMBINEPRECONCAT = rw::COMBINEPRECONCAT,
	rwCOMBINEPOSTCONCAT = rw::COMBINEPOSTCONCAT
};

enum RwMatrixType
{
	rwMATRIXTYPENORMAL = rw::Matrix::TYPENORMAL,
	rwMATRIXTYPEORTHOGANAL = rw::Matrix::TYPEORTHOGONAL,
	rwMATRIXTYPEORTHONORMAL = rw::Matrix::TYPEORTHONORMAL,
	rwMATRIXTYPEMASK = 0x00000003,
};

typedef rw::Matrix::Tolerance RwMatrixTolerance;

RwBool RwMatrixDestroy(RwMatrix *mpMat);
RwMatrix *RwMatrixCreate(void);
void RwMatrixCopy(RwMatrix * dstMatrix, const RwMatrix * srcMatrix);
void RwMatrixSetIdentity(RwMatrix * matrix);
RwMatrix *RwMatrixMultiply(RwMatrix * matrixOut, const RwMatrix * MatrixIn1, const RwMatrix * matrixIn2);
RwMatrix *RwMatrixTransform(RwMatrix * matrix, const RwMatrix * transform, RwOpCombineType combineOp);
RwMatrix *RwMatrixOrthoNormalize(RwMatrix * matrixOut, const RwMatrix * matrixIn);
RwMatrix *RwMatrixInvert(RwMatrix * matrixOut, const RwMatrix * matrixIn);
RwMatrix *RwMatrixScale(RwMatrix * matrix, const RwV3d * scale, RwOpCombineType combineOp);
RwMatrix *RwMatrixTranslate(RwMatrix * matrix, const RwV3d * translation, RwOpCombineType combineOp);
RwMatrix *RwMatrixRotate(RwMatrix * matrix, const RwV3d * axis, RwReal angle, RwOpCombineType combineOp);
RwMatrix *RwMatrixRotateOneMinusCosineSine(RwMatrix * matrix, const RwV3d * unitAxis, RwReal oneMinusCosine, RwReal sine, RwOpCombineType combineOp);
const RwMatrix *RwMatrixQueryRotate(const RwMatrix * matrix, RwV3d * unitAxis, RwReal * angle, RwV3d * center);
RwV3d *RwMatrixGetRight(RwMatrix * matrix);
RwV3d *RwMatrixGetUp(RwMatrix * matrix);
RwV3d *RwMatrixGetAt(RwMatrix * matrix);
RwV3d *RwMatrixGetPos(RwMatrix * matrix);
RwMatrix *RwMatrixUpdate(RwMatrix * matrix);
RwMatrix *RwMatrixOptimize(RwMatrix * matrix, const RwMatrixTolerance *tolerance);

/*
 ***********************************************
 *
 * RwRGBA
 *
 ***********************************************
 */

typedef rw::RGBA RwRGBA;
typedef rw::RGBAf RwRGBAReal;


inline void RwRGBAAssign(RwRGBA *target, const RwRGBA *source) { *target = *source; }


RwReal RwV3dNormalize(RwV3d * out, const RwV3d * in);
RwReal RwV3dLength(const RwV3d * in);
RwReal RwV2dLength(const RwV2d * in);
RwReal RwV2dNormalize(RwV2d * out, const RwV2d * in);
void RwV2dAssign(RwV2d * out, const RwV2d * ina);
void RwV2dAdd(RwV2d * out, const RwV2d * ina, const RwV2d * inb);
void RwV2dLineNormal(RwV2d * out, const RwV2d * ina, const RwV2d * inb);
void RwV2dSub(RwV2d * out, const RwV2d * ina, const RwV2d * inb);
void RwV2dPerp(RwV2d * out, const RwV2d * in);
void RwV2dScale(RwV2d * out, const RwV2d * in, RwReal scalar);
RwReal RwV2dDotProduct(const RwV2d * ina, const RwV2d * inb);
void RwV3dAssign(RwV3d * out, const RwV3d * ina);
void RwV3dAdd(RwV3d * out, const RwV3d * ina, const RwV3d * inb);
void RwV3dSub(RwV3d * out, const RwV3d * ina, const RwV3d * inb);
void RwV3dScale(RwV3d * out, const RwV3d * in, RwReal scalar);
void RwV3dIncrementScaled(RwV3d * out,  const RwV3d * in, RwReal scalar);
void RwV3dNegate(RwV3d * out, const RwV3d * in);
RwReal RwV3dDotProduct(const RwV3d * ina, const RwV3d * inb);
void RwV3dCrossProduct(RwV3d * out, const RwV3d * ina, const RwV3d * inb);
RwV3d *RwV3dTransformPoints(RwV3d * pointsOut, const RwV3d * pointsIn, RwInt32 numPoints, const RwMatrix * matrix);
RwV3d *RwV3dTransformVectors(RwV3d * vectorsOut, const RwV3d * vectorsIn, RwInt32 numPoints, const RwMatrix * matrix);


/*
 ***********************************************
 *
 * Render States
 *
 ***********************************************
 */

// not librw because we don't support all of them (yet?) - mapping in wrapper functions
enum RwRenderState
{
	rwRENDERSTATENARENDERSTATE = 0,
	rwRENDERSTATETEXTURERASTER,
	rwRENDERSTATETEXTUREADDRESS,
	rwRENDERSTATETEXTUREADDRESSU,
	rwRENDERSTATETEXTUREADDRESSV,
	rwRENDERSTATETEXTUREPERSPECTIVE,
	rwRENDERSTATEZTESTENABLE,
	rwRENDERSTATESHADEMODE,
	rwRENDERSTATEZWRITEENABLE,
	rwRENDERSTATETEXTUREFILTER,
	rwRENDERSTATESRCBLEND,
	rwRENDERSTATEDESTBLEND,
	rwRENDERSTATEVERTEXALPHAENABLE,
	rwRENDERSTATEBORDERCOLOR,
	rwRENDERSTATEFOGENABLE,
	rwRENDERSTATEFOGCOLOR,
	rwRENDERSTATEFOGTYPE,
	rwRENDERSTATEFOGDENSITY,
	rwRENDERSTATEFOGTABLE,
	rwRENDERSTATEALPHAPRIMITIVEBUFFER,
	rwRENDERSTATECULLMODE,
	rwRENDERSTATESTENCILENABLE,
	rwRENDERSTATESTENCILFAIL,
	rwRENDERSTATESTENCILZFAIL,
	rwRENDERSTATESTENCILPASS,
	rwRENDERSTATESTENCILFUNCTION,
	rwRENDERSTATESTENCILFUNCTIONREF,
	rwRENDERSTATESTENCILFUNCTIONMASK,
	rwRENDERSTATESTENCILFUNCTIONWRITEMASK
};

// not supported - we only do gouraud
enum RwShadeMode
{
	rwSHADEMODENASHADEMODE = 0,
	rwSHADEMODEFLAT,
	rwSHADEMODEGOURAUD
};

enum RwBlendFunction
{
	rwBLENDNABLEND = 0,
	rwBLENDZERO = rw::BLENDZERO,
	rwBLENDONE = rw::BLENDONE,
	rwBLENDSRCCOLOR = rw::BLENDSRCCOLOR,
	rwBLENDINVSRCCOLOR = rw::BLENDINVSRCCOLOR,
	rwBLENDSRCALPHA = rw::BLENDSRCALPHA,
	rwBLENDINVSRCALPHA = rw::BLENDINVSRCALPHA,
	rwBLENDDESTALPHA = rw::BLENDDESTALPHA,
	rwBLENDINVDESTALPHA = rw::BLENDINVDESTALPHA,
	rwBLENDDESTCOLOR = rw::BLENDDESTCOLOR,
	rwBLENDINVDESTCOLOR = rw::BLENDINVDESTCOLOR,
	rwBLENDSRCALPHASAT = rw::BLENDSRCALPHASAT
};

// unsupported - we only need linear
enum RwFogType
{
	rwFOGTYPENAFOGTYPE = 0,
	rwFOGTYPELINEAR,
	rwFOGTYPEEXPONENTIAL,
	rwFOGTYPEEXPONENTIAL2
};

enum RwTextureFilterMode
{
	rwFILTERNAFILTERMODE = 0,
	rwFILTERNEAREST = rw::Texture::NEAREST,
	rwFILTERLINEAR = rw::Texture::LINEAR,
	rwFILTERMIPNEAREST = rw::Texture::MIPNEAREST,
	rwFILTERMIPLINEAR = rw::Texture::MIPLINEAR,
	rwFILTERLINEARMIPNEAREST = rw::Texture::LINEARMIPNEAREST,
	rwFILTERLINEARMIPLINEAR = rw::Texture::LINEARMIPLINEAR
};

enum RwTextureAddressMode
{
	rwTEXTUREADDRESSNATEXTUREADDRESS = 0,
	rwTEXTUREADDRESSWRAP = rw::Texture::WRAP,
	rwTEXTUREADDRESSMIRROR = rw::Texture::MIRROR,
	rwTEXTUREADDRESSCLAMP = rw::Texture::CLAMP,
	rwTEXTUREADDRESSBORDER = rw::Texture::BORDER
};

enum RwCullMode
{
	rwCULLMODENACULLMODE = 0,
	rwCULLMODECULLNONE = rw::CULLNONE,
	rwCULLMODECULLBACK = rw::CULLBACK,
	rwCULLMODECULLFRONT = rw::CULLFRONT
};

enum RwPrimitiveType
{
	rwPRIMTYPENAPRIMTYPE = rw::PRIMTYPENONE,
	rwPRIMTYPELINELIST = rw::PRIMTYPELINELIST,
	rwPRIMTYPEPOLYLINE = rw::PRIMTYPEPOLYLINE,
	rwPRIMTYPETRILIST = rw::PRIMTYPETRILIST,
	rwPRIMTYPETRISTRIP = rw::PRIMTYPETRISTRIP,
	rwPRIMTYPETRIFAN = rw::PRIMTYPETRIFAN,
	rwPRIMTYPEPOINTLIST = rw::PRIMTYPEPOINTLIST
};


RwBool RwRenderStateGet(RwRenderState state, void *value);
RwBool RwRenderStateSet(RwRenderState state, void *value);


/*
 ***********************************************
 *
 * Engine
 *
 ***********************************************
 */

struct RwEngineOpenParams
{
	void    *displayID;
};

typedef rw::SubSystemInfo RwSubSystemInfo;

enum RwVideoModeFlag
{
	rwVIDEOMODEEXCLUSIVE  = rw::VIDEOMODEEXCLUSIVE,
/*
	rwVIDEOMODEINTERLACE  = 0x2,
	rwVIDEOMODEFFINTERLACE  = 0x4,
	rwVIDEOMODEFSAA0 = 0x8,
	rwVIDEOMODEFSAA1 = 0x10
*/
};

typedef rw::VideoMode RwVideoMode;

#if 0
struct RwFileFunctions
{
	rwFnFexist  rwfexist; /**< Pointer to fexist function */
	rwFnFopen   rwfopen;  /**< Pointer to fopen function */
	rwFnFclose  rwfclose; /**< Pointer to fclose function */
	rwFnFread   rwfread;  /**< Pointer to fread function */
	rwFnFwrite  rwfwrite; /**< Pointer to fwrite function */
	rwFnFgets   rwfgets;  /**< Pointer to fgets function */
	rwFnFputs   rwfputs;  /**< Pointer to puts function */
	rwFnFeof    rwfeof;   /**< Pointer to feof function */
	rwFnFseek   rwfseek;  /**< Pointer to fseek function */
	rwFnFflush  rwfflush; /**< Pointer to fflush function */
	rwFnFtell   rwftell;  /**< Pointer to ftell function */  
};
RwFileFunctions *RwOsGetFileInterface(void);
#endif

RwBool RwEngineInit(RwMemoryFunctions *memFuncs, RwUInt32 initFlags, RwUInt32 resArenaSize);
RwInt32 RwEngineRegisterPlugin(RwInt32 size, RwUInt32 pluginID, RwPluginObjectConstructor initCB, RwPluginObjectDestructor termCB);
RwInt32 RwEngineGetPluginOffset(RwUInt32 pluginID);
RwBool RwEngineOpen(RwEngineOpenParams *initParams);
RwBool RwEngineStart(void);
RwBool RwEngineStop(void);
RwBool RwEngineClose(void);
RwBool RwEngineTerm(void);
RwInt32 RwEngineGetNumSubSystems(void);
RwSubSystemInfo *RwEngineGetSubSystemInfo(RwSubSystemInfo *subSystemInfo, RwInt32 subSystemIndex);
RwInt32 RwEngineGetCurrentSubSystem(void);
RwBool RwEngineSetSubSystem(RwInt32 subSystemIndex);
RwInt32 RwEngineGetNumVideoModes(void);
RwVideoMode *RwEngineGetVideoModeInfo(RwVideoMode *modeinfo, RwInt32 modeIndex);
RwInt32 RwEngineGetCurrentVideoMode(void);
RwBool RwEngineSetVideoMode(RwInt32 modeIndex);
RwInt32 RwEngineGetTextureMemorySize(void);
RwInt32 RwEngineGetMaxTextureSize(void);


/*
 ***********************************************
 *
 * Binary stream
 *
 ***********************************************
 */

RwBool RwStreamFindChunk(RwStream *stream, RwUInt32 type, RwUInt32 *lengthOut, RwUInt32 *versionOut);