2016-01-26 12:53:08 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
|
2015-01-25 21:27:03 +00:00
|
|
|
namespace rw {
|
2014-12-23 14:59:14 +00:00
|
|
|
|
2016-01-11 10:23:26 +00:00
|
|
|
struct LLLink
|
|
|
|
{
|
|
|
|
LLLink *next;
|
|
|
|
LLLink *prev;
|
|
|
|
void init(void){
|
2016-06-21 22:16:09 +01:00
|
|
|
this->next = nil;
|
|
|
|
this->prev = nil;
|
2016-01-11 10:23:26 +00:00
|
|
|
}
|
|
|
|
void remove(void){
|
|
|
|
this->prev->next = this->next;
|
|
|
|
this->next->prev = this->prev;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-07-12 09:10:57 +01:00
|
|
|
#define LLLinkGetData(linkvar,type,entry) \
|
2016-01-11 10:23:26 +00:00
|
|
|
((type*)(((uint8*)(linkvar))-offsetof(type,entry)))
|
|
|
|
|
2016-01-14 22:49:00 +00:00
|
|
|
// Have to be careful since the link might be deleted.
|
|
|
|
#define FORLIST(_link, _list) \
|
2016-06-21 22:16:09 +01:00
|
|
|
for(rw::LLLink *_next = nil, *_link = (_list).link.next; \
|
2016-01-14 22:49:00 +00:00
|
|
|
_next = (_link)->next, (_link) != (_list).end(); \
|
|
|
|
(_link) = _next)
|
|
|
|
|
2016-01-11 10:23:26 +00:00
|
|
|
struct LinkList
|
|
|
|
{
|
|
|
|
LLLink link;
|
|
|
|
void init(void){
|
|
|
|
this->link.next = &this->link;
|
|
|
|
this->link.prev = &this->link;
|
|
|
|
}
|
|
|
|
bool32 isEmpty(void){
|
|
|
|
return this->link.next == &this->link;
|
|
|
|
}
|
|
|
|
void add(LLLink *link){
|
|
|
|
link->next = this->link.next;
|
|
|
|
link->prev = &this->link;
|
|
|
|
this->link.next->prev = link;
|
|
|
|
this->link.next = link;
|
|
|
|
}
|
2016-01-11 17:22:59 +00:00
|
|
|
void append(LLLink *link){
|
|
|
|
link->next = &this->link;
|
|
|
|
link->prev = this->link.prev;
|
|
|
|
this->link.prev->next = link;
|
|
|
|
this->link.prev = link;
|
|
|
|
}
|
2016-01-11 10:23:26 +00:00
|
|
|
LLLink *end(void){
|
|
|
|
return &this->link;
|
|
|
|
}
|
2016-01-14 22:49:00 +00:00
|
|
|
int32 count(void){
|
|
|
|
int32 n = 0;
|
|
|
|
FORLIST(lnk, (*this))
|
|
|
|
n++;
|
|
|
|
return n;
|
|
|
|
}
|
2016-01-11 10:23:26 +00:00
|
|
|
};
|
|
|
|
|
2014-12-23 14:59:14 +00:00
|
|
|
struct Object
|
|
|
|
{
|
|
|
|
uint8 type;
|
|
|
|
uint8 subType;
|
|
|
|
uint8 flags;
|
2016-01-11 10:23:26 +00:00
|
|
|
uint8 privateFlags;
|
2014-12-23 14:59:14 +00:00
|
|
|
void *parent;
|
2016-01-11 10:23:26 +00:00
|
|
|
|
|
|
|
void init(uint8 type, uint8 subType){
|
|
|
|
this->type = type;
|
|
|
|
this->subType = subType;
|
|
|
|
this->flags = 0;
|
|
|
|
this->privateFlags = 0;
|
2016-06-21 22:16:09 +01:00
|
|
|
this->parent = nil;
|
2016-01-11 10:23:26 +00:00
|
|
|
}
|
2016-01-11 23:38:36 +00:00
|
|
|
void copy(Object *o){
|
|
|
|
this->type = o->type;
|
|
|
|
this->subType = o->subType;
|
|
|
|
this->flags = o->flags;
|
|
|
|
this->privateFlags = o->privateFlags;
|
2016-06-21 22:16:09 +01:00
|
|
|
this->parent = nil;
|
2016-01-11 23:38:36 +00:00
|
|
|
}
|
2014-12-23 14:59:14 +00:00
|
|
|
};
|
|
|
|
|
2017-08-10 13:43:52 +01:00
|
|
|
struct Frame
|
2015-01-09 19:17:32 +00:00
|
|
|
{
|
2017-08-10 13:43:52 +01:00
|
|
|
PLUGINBASE
|
2015-01-09 19:17:32 +00:00
|
|
|
typedef Frame *(*Callback)(Frame *f, void *data);
|
2016-01-13 07:58:15 +00:00
|
|
|
enum { ID = 0 };
|
2016-06-21 22:16:09 +01:00
|
|
|
enum { // private flags
|
|
|
|
// The hierarchy has unsynched frames
|
|
|
|
HIERARCHYSYNCLTM = 0x01, // LTM not synched
|
|
|
|
HIERARCHYSYNCOBJ = 0x02, // attached objects not synched
|
2016-02-12 23:52:32 +00:00
|
|
|
HIERARCHYSYNC = HIERARCHYSYNCLTM | HIERARCHYSYNCOBJ,
|
2016-06-21 22:16:09 +01:00
|
|
|
// This frame is not synched
|
2016-02-12 23:52:32 +00:00
|
|
|
SUBTREESYNCLTM = 0x04,
|
|
|
|
SUBTREESYNCOBJ = 0x08,
|
|
|
|
SUBTREESYNC = SUBTREESYNCLTM | SUBTREESYNCOBJ,
|
|
|
|
SYNCLTM = HIERARCHYSYNCLTM | SUBTREESYNCLTM,
|
|
|
|
SYNCOBJ = HIERARCHYSYNCOBJ | SUBTREESYNCOBJ,
|
2016-08-03 19:32:43 +01:00
|
|
|
// STATIC = 0x10
|
2016-02-12 23:52:32 +00:00
|
|
|
};
|
|
|
|
|
2016-01-11 10:23:26 +00:00
|
|
|
Object object;
|
2016-02-12 23:52:32 +00:00
|
|
|
LLLink inDirtyList;
|
2016-01-11 10:23:26 +00:00
|
|
|
LinkList objectList;
|
2016-02-14 19:56:05 +00:00
|
|
|
Matrix matrix;
|
|
|
|
Matrix ltm;
|
2015-01-09 19:17:32 +00:00
|
|
|
|
|
|
|
Frame *child;
|
|
|
|
Frame *next;
|
|
|
|
Frame *root;
|
|
|
|
|
2016-01-11 17:22:59 +00:00
|
|
|
static Frame *create(void);
|
2016-01-11 23:38:36 +00:00
|
|
|
Frame *cloneHierarchy(void);
|
2016-01-11 17:22:59 +00:00
|
|
|
void destroy(void);
|
2016-01-11 23:38:36 +00:00
|
|
|
void destroyHierarchy(void);
|
2016-01-24 00:42:51 +00:00
|
|
|
Frame *addChild(Frame *f, bool32 append = 0);
|
2015-01-09 19:17:32 +00:00
|
|
|
Frame *removeChild(void);
|
|
|
|
Frame *forAllChildren(Callback cb, void *data);
|
2016-01-11 23:38:36 +00:00
|
|
|
Frame *getParent(void){
|
2016-01-13 07:58:15 +00:00
|
|
|
return (Frame*)this->object.parent; }
|
2015-01-09 19:17:32 +00:00
|
|
|
int32 count(void);
|
2016-02-18 13:56:10 +00:00
|
|
|
bool32 dirty(void) {
|
|
|
|
return !!(this->root->object.privateFlags & HIERARCHYSYNC); }
|
2016-02-14 19:56:05 +00:00
|
|
|
Matrix *getLTM(void);
|
2017-03-16 00:10:01 +00:00
|
|
|
void rotate(V3d *axis, float32 angle, CombineOp op);
|
|
|
|
void translate(V3d *trans, CombineOp op);
|
2017-08-09 23:42:33 +01:00
|
|
|
void scale(V3d *scale, CombineOp op);
|
|
|
|
void transform(Matrix *mat, CombineOp op);
|
2016-02-12 23:52:32 +00:00
|
|
|
void updateObjects(void);
|
2016-01-11 23:38:36 +00:00
|
|
|
|
2016-06-21 22:16:09 +01:00
|
|
|
|
2016-02-12 23:52:32 +00:00
|
|
|
void syncHierarchyLTM(void);
|
2016-01-11 23:38:36 +00:00
|
|
|
void setHierarchyRoot(Frame *root);
|
|
|
|
Frame *cloneAndLink(Frame *clonedroot);
|
|
|
|
void purgeClone(void);
|
2016-06-21 22:16:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
static LinkList dirtyList;
|
|
|
|
static void syncDirty(void);
|
2015-01-09 19:17:32 +00:00
|
|
|
};
|
|
|
|
|
2016-06-17 12:29:49 +01:00
|
|
|
struct FrameList_
|
|
|
|
{
|
|
|
|
int32 numFrames;
|
|
|
|
Frame **frames;
|
|
|
|
|
|
|
|
FrameList_ *streamRead(Stream *stream);
|
|
|
|
void streamWrite(Stream *stream);
|
|
|
|
static uint32 streamGetSize(Frame *f);
|
|
|
|
};
|
2015-12-18 00:10:42 +00:00
|
|
|
Frame **makeFrameList(Frame *frame, Frame **flist);
|
|
|
|
|
2016-06-16 13:08:09 +01:00
|
|
|
struct ObjectWithFrame
|
2016-01-11 10:23:26 +00:00
|
|
|
{
|
2016-06-23 15:39:34 +01:00
|
|
|
typedef void (*Sync)(ObjectWithFrame*);
|
|
|
|
|
2016-06-16 13:08:09 +01:00
|
|
|
Object object;
|
2016-01-11 10:23:26 +00:00
|
|
|
LLLink inFrame;
|
2016-06-23 15:39:34 +01:00
|
|
|
Sync syncCB;
|
2016-06-21 22:16:09 +01:00
|
|
|
|
2016-01-11 10:23:26 +00:00
|
|
|
void setFrame(Frame *f){
|
2016-06-16 13:08:09 +01:00
|
|
|
if(this->object.parent)
|
2016-01-11 10:23:26 +00:00
|
|
|
this->inFrame.remove();
|
2016-06-16 13:08:09 +01:00
|
|
|
this->object.parent = f;
|
2016-08-05 00:13:41 +01:00
|
|
|
if(f){
|
2016-01-11 10:23:26 +00:00
|
|
|
f->objectList.add(&this->inFrame);
|
2016-08-05 00:13:41 +01:00
|
|
|
f->updateObjects();
|
|
|
|
}
|
2016-01-11 10:23:26 +00:00
|
|
|
}
|
2016-06-21 22:16:09 +01:00
|
|
|
void sync(void){ this->syncCB(this); }
|
2016-01-13 07:58:15 +00:00
|
|
|
static ObjectWithFrame *fromFrame(LLLink *lnk){
|
|
|
|
return LLLinkGetData(lnk, ObjectWithFrame, inFrame);
|
|
|
|
}
|
2016-01-11 10:23:26 +00:00
|
|
|
};
|
|
|
|
|
2014-12-25 15:02:57 +00:00
|
|
|
struct Image
|
|
|
|
{
|
|
|
|
int32 flags;
|
|
|
|
int32 width, height;
|
|
|
|
int32 depth;
|
|
|
|
int32 stride;
|
|
|
|
uint8 *pixels;
|
|
|
|
uint8 *palette;
|
|
|
|
|
2016-01-11 17:22:59 +00:00
|
|
|
static Image *create(int32 width, int32 height, int32 depth);
|
|
|
|
void destroy(void);
|
2014-12-25 15:02:57 +00:00
|
|
|
void allocate(void);
|
|
|
|
void free(void);
|
|
|
|
void setPixels(uint8 *pixels);
|
2016-07-19 22:37:37 +01:00
|
|
|
void setPixelsDXT(int32 type, uint8 *pixels);
|
2014-12-25 15:02:57 +00:00
|
|
|
void setPalette(uint8 *palette);
|
2016-02-23 09:07:04 +00:00
|
|
|
bool32 hasAlpha(void);
|
2016-07-19 17:40:10 +01:00
|
|
|
void unindex(void);
|
|
|
|
void removeMask(void);
|
|
|
|
Image *extractMask(void);
|
2015-01-20 13:48:18 +00:00
|
|
|
|
|
|
|
static void setSearchPath(const char*);
|
|
|
|
static void printSearchPath(void);
|
|
|
|
static char *getFilename(const char*);
|
2014-12-25 15:02:57 +00:00
|
|
|
};
|
2016-07-19 17:40:10 +01:00
|
|
|
|
2014-12-25 18:37:36 +00:00
|
|
|
Image *readTGA(const char *filename);
|
|
|
|
void writeTGA(Image *image, const char *filename);
|
2016-07-19 17:40:10 +01:00
|
|
|
void writeBMP(Image *image, const char *filename);
|
2014-12-25 15:02:57 +00:00
|
|
|
|
2015-09-15 07:29:57 +01:00
|
|
|
// used to emulate d3d and xbox textures
|
|
|
|
struct RasterLevels
|
|
|
|
{
|
|
|
|
int32 numlevels;
|
|
|
|
uint32 format;
|
|
|
|
struct Level {
|
|
|
|
int32 width, height, size;
|
|
|
|
uint8 *data;
|
|
|
|
} levels[1]; // 0 is illegal :/
|
|
|
|
};
|
|
|
|
|
2017-08-10 13:43:52 +01:00
|
|
|
struct Raster
|
2015-01-20 13:48:18 +00:00
|
|
|
{
|
2017-08-10 13:43:52 +01:00
|
|
|
PLUGINBASE
|
2015-09-13 19:23:22 +01:00
|
|
|
int32 platform;
|
|
|
|
|
2015-01-20 13:48:18 +00:00
|
|
|
int32 type; // hardly used
|
2015-09-13 19:23:22 +01:00
|
|
|
int32 flags;
|
|
|
|
int32 format;
|
2015-01-20 13:48:18 +00:00
|
|
|
int32 width, height, depth;
|
|
|
|
int32 stride;
|
|
|
|
uint8 *texels;
|
|
|
|
uint8 *palette;
|
|
|
|
|
2016-07-15 10:55:52 +01:00
|
|
|
static Raster *create(int32 width, int32 height, int32 depth,
|
|
|
|
int32 format, int32 platform = 0);
|
2016-01-11 17:22:59 +00:00
|
|
|
void destroy(void);
|
2016-07-15 10:55:52 +01:00
|
|
|
static Raster *createFromImage(Image *image, int32 platform = 0);
|
|
|
|
Image *toImage(void);
|
2015-09-13 19:23:22 +01:00
|
|
|
uint8 *lock(int32 level);
|
|
|
|
void unlock(int32 level);
|
|
|
|
int32 getNumLevels(void);
|
2015-09-15 07:29:57 +01:00
|
|
|
static int32 calculateNumLevels(int32 width, int32 height);
|
2015-01-20 13:48:18 +00:00
|
|
|
|
|
|
|
enum Format {
|
2015-09-13 19:23:22 +01:00
|
|
|
DEFAULT = 0,
|
|
|
|
C1555 = 0x0100,
|
|
|
|
C565 = 0x0200,
|
|
|
|
C4444 = 0x0300,
|
|
|
|
LUM8 = 0x0400,
|
|
|
|
C8888 = 0x0500,
|
|
|
|
C888 = 0x0600,
|
|
|
|
D16 = 0x0700,
|
|
|
|
D24 = 0x0800,
|
|
|
|
D32 = 0x0900,
|
|
|
|
C555 = 0x0A00,
|
2015-01-20 13:48:18 +00:00
|
|
|
AUTOMIPMAP = 0x1000,
|
|
|
|
PAL8 = 0x2000,
|
|
|
|
PAL4 = 0x4000,
|
|
|
|
MIPMAP = 0x8000
|
|
|
|
};
|
2016-06-23 15:39:34 +01:00
|
|
|
enum Type {
|
|
|
|
NORMAL = 0x00,
|
|
|
|
ZBUFFER = 0x01,
|
|
|
|
CAMERA = 0x02,
|
|
|
|
TEXTURE = 0x04,
|
|
|
|
CAMERATEXTURE = 0x05,
|
|
|
|
DONTALLOCATE = 0x80,
|
|
|
|
};
|
2015-01-20 13:48:18 +00:00
|
|
|
};
|
|
|
|
|
2016-02-06 17:11:31 +00:00
|
|
|
#define IGNORERASTERIMP 0
|
2015-12-14 17:52:50 +00:00
|
|
|
|
2016-01-11 17:22:59 +00:00
|
|
|
struct TexDictionary;
|
|
|
|
|
2017-08-10 13:43:52 +01:00
|
|
|
struct Texture
|
2014-12-23 14:59:14 +00:00
|
|
|
{
|
2017-08-10 13:43:52 +01:00
|
|
|
PLUGINBASE
|
2016-01-11 10:23:26 +00:00
|
|
|
Raster *raster;
|
2016-01-11 17:22:59 +00:00
|
|
|
TexDictionary *dict;
|
|
|
|
LLLink inDict;
|
2014-12-23 14:59:14 +00:00
|
|
|
char name[32];
|
|
|
|
char mask[32];
|
2015-09-11 11:32:06 +01:00
|
|
|
uint32 filterAddressing; // VVVVUUUU FFFFFFFF
|
2014-12-23 14:59:14 +00:00
|
|
|
int32 refCount;
|
|
|
|
|
2016-01-11 17:22:59 +00:00
|
|
|
static Texture *create(Raster *raster);
|
|
|
|
void destroy(void);
|
|
|
|
static Texture *fromDict(LLLink *lnk){
|
2016-01-13 07:58:15 +00:00
|
|
|
return LLLinkGetData(lnk, Texture, inDict); }
|
2014-12-27 22:18:10 +00:00
|
|
|
static Texture *streamRead(Stream *stream);
|
|
|
|
bool streamWrite(Stream *stream);
|
2014-12-23 14:59:14 +00:00
|
|
|
uint32 streamGetSize(void);
|
2015-01-20 18:22:57 +00:00
|
|
|
static Texture *read(const char *name, const char *mask);
|
2015-09-13 19:23:22 +01:00
|
|
|
static Texture *streamReadNative(Stream *stream);
|
|
|
|
void streamWriteNative(Stream *stream);
|
|
|
|
uint32 streamGetSizeNative(void);
|
2014-12-23 14:59:14 +00:00
|
|
|
|
2016-02-18 13:29:04 +00:00
|
|
|
static Texture *(*findCB)(const char *name);
|
|
|
|
static Texture *(*readCB)(const char *name, const char *mask);
|
|
|
|
|
2014-12-23 14:59:14 +00:00
|
|
|
enum FilterMode {
|
|
|
|
NEAREST = 1,
|
|
|
|
LINEAR,
|
|
|
|
MIPNEAREST,
|
|
|
|
MIPLINEAR,
|
|
|
|
LINEARMIPNEAREST,
|
|
|
|
LINEARMIPLINEAR
|
|
|
|
};
|
|
|
|
enum Addressing {
|
|
|
|
WRAP = 1,
|
|
|
|
MIRROR,
|
|
|
|
CLAMP,
|
|
|
|
BORDER
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2016-06-16 13:08:09 +01:00
|
|
|
|
2016-01-09 21:01:21 +00:00
|
|
|
struct SurfaceProperties
|
|
|
|
{
|
|
|
|
float32 ambient;
|
|
|
|
float32 specular;
|
|
|
|
float32 diffuse;
|
|
|
|
};
|
|
|
|
|
2017-08-10 13:43:52 +01:00
|
|
|
struct Material
|
2014-12-23 14:59:14 +00:00
|
|
|
{
|
2017-08-10 13:43:52 +01:00
|
|
|
PLUGINBASE
|
2014-12-23 14:59:14 +00:00
|
|
|
Texture *texture;
|
2016-01-13 07:58:15 +00:00
|
|
|
RGBA color;
|
2016-01-09 21:01:21 +00:00
|
|
|
SurfaceProperties surfaceProps;
|
2015-01-10 21:13:27 +00:00
|
|
|
Pipeline *pipeline;
|
2014-12-23 14:59:14 +00:00
|
|
|
int32 refCount;
|
|
|
|
|
2016-01-11 17:22:59 +00:00
|
|
|
static Material *create(void);
|
|
|
|
Material *clone(void);
|
|
|
|
void destroy(void);
|
2016-06-17 12:29:49 +01:00
|
|
|
void setTexture(Texture *tex);
|
2014-12-27 22:18:10 +00:00
|
|
|
static Material *streamRead(Stream *stream);
|
|
|
|
bool streamWrite(Stream *stream);
|
2014-12-23 14:59:14 +00:00
|
|
|
uint32 streamGetSize(void);
|
|
|
|
};
|
|
|
|
|
2015-01-25 21:27:03 +00:00
|
|
|
void registerMaterialRightsPlugin(void);
|
2015-01-10 21:13:27 +00:00
|
|
|
|
2014-12-23 14:59:14 +00:00
|
|
|
struct Mesh
|
|
|
|
{
|
|
|
|
uint16 *indices;
|
|
|
|
uint32 numIndices;
|
|
|
|
Material *material;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MeshHeader
|
|
|
|
{
|
2016-01-24 00:42:51 +00:00
|
|
|
enum {
|
|
|
|
TRISTRIP = 1
|
|
|
|
};
|
2014-12-23 14:59:14 +00:00
|
|
|
uint32 flags;
|
|
|
|
uint16 numMeshes;
|
|
|
|
// RW has uint16 serialNum here
|
|
|
|
uint32 totalIndices;
|
|
|
|
Mesh *mesh; // RW has a byte offset here
|
2015-09-07 22:00:28 +01:00
|
|
|
|
|
|
|
void allocateIndices(void);
|
2015-12-20 12:05:32 +00:00
|
|
|
~MeshHeader(void);
|
2014-12-23 14:59:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct MorphTarget
|
|
|
|
{
|
2016-02-18 13:29:04 +00:00
|
|
|
Sphere boundingSphere;
|
2017-08-05 00:44:37 +01:00
|
|
|
V3d *vertices;
|
|
|
|
V3d *normals;
|
2014-12-23 14:59:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct InstanceDataHeader
|
|
|
|
{
|
|
|
|
uint32 platform;
|
|
|
|
};
|
|
|
|
|
2016-01-24 00:42:51 +00:00
|
|
|
struct Triangle
|
|
|
|
{
|
|
|
|
uint16 v[3];
|
|
|
|
uint16 matId;
|
|
|
|
};
|
|
|
|
|
2017-03-16 10:42:59 +00:00
|
|
|
struct MaterialList
|
|
|
|
{
|
|
|
|
Material **materials;
|
|
|
|
int32 numMaterials;
|
|
|
|
int32 space;
|
|
|
|
|
|
|
|
void init(void);
|
|
|
|
void deinit(void);
|
|
|
|
int32 appendMaterial(Material *mat);
|
|
|
|
int32 findIndex(Material *mat);
|
|
|
|
static MaterialList *streamRead(Stream *stream, MaterialList *matlist);
|
|
|
|
bool streamWrite(Stream *stream);
|
|
|
|
uint32 streamGetSize(void);
|
|
|
|
};
|
|
|
|
|
2017-08-10 13:43:52 +01:00
|
|
|
struct Geometry
|
2014-12-23 14:59:14 +00:00
|
|
|
{
|
2017-08-10 13:43:52 +01:00
|
|
|
PLUGINBASE
|
2016-01-13 07:58:15 +00:00
|
|
|
enum { ID = 8 };
|
2016-01-11 10:23:26 +00:00
|
|
|
Object object;
|
2017-03-16 10:42:59 +00:00
|
|
|
uint32 flags;
|
2014-12-23 14:59:14 +00:00
|
|
|
int32 numTriangles;
|
|
|
|
int32 numVertices;
|
|
|
|
int32 numMorphTargets;
|
|
|
|
int32 numTexCoordSets;
|
|
|
|
|
2016-01-24 00:42:51 +00:00
|
|
|
Triangle *triangles;
|
2017-08-05 00:44:37 +01:00
|
|
|
RGBA *colors;
|
|
|
|
TexCoords *texCoords[8];
|
2014-12-23 14:59:14 +00:00
|
|
|
|
|
|
|
MorphTarget *morphTargets;
|
2017-03-16 10:42:59 +00:00
|
|
|
MaterialList matList;
|
2014-12-23 14:59:14 +00:00
|
|
|
|
|
|
|
MeshHeader *meshHeader;
|
|
|
|
InstanceDataHeader *instData;
|
|
|
|
|
|
|
|
int32 refCount;
|
|
|
|
|
2016-01-11 17:22:59 +00:00
|
|
|
static Geometry *create(int32 numVerts, int32 numTris, uint32 flags);
|
|
|
|
void destroy(void);
|
2014-12-23 14:59:14 +00:00
|
|
|
void addMorphTargets(int32 n);
|
2015-12-19 16:05:39 +00:00
|
|
|
void calculateBoundingSphere(void);
|
|
|
|
bool32 hasColoredMaterial(void);
|
2015-08-11 19:57:43 +01:00
|
|
|
void allocateData(void);
|
2016-06-21 22:16:09 +01:00
|
|
|
void generateTriangles(int8 *adc = nil);
|
2016-01-24 00:42:51 +00:00
|
|
|
void buildMeshes(void);
|
2017-03-16 00:10:01 +00:00
|
|
|
void buildTristrips(void);
|
2017-03-09 10:45:26 +00:00
|
|
|
void correctTristripWinding(void);
|
2016-02-23 09:07:04 +00:00
|
|
|
void removeUnusedMaterials(void);
|
2017-03-16 10:42:59 +00:00
|
|
|
static Geometry *streamRead(Stream *stream);
|
|
|
|
bool streamWrite(Stream *stream);
|
|
|
|
uint32 streamGetSize(void);
|
2014-12-23 14:59:14 +00:00
|
|
|
|
|
|
|
enum Flags
|
|
|
|
{
|
|
|
|
TRISTRIP = 0x01,
|
|
|
|
POSITIONS = 0x02,
|
|
|
|
TEXTURED = 0x04,
|
|
|
|
PRELIT = 0x08,
|
|
|
|
NORMALS = 0x10,
|
|
|
|
LIGHT = 0x20,
|
|
|
|
MODULATE = 0x40,
|
|
|
|
TEXTURED2 = 0x80,
|
|
|
|
NATIVE = 0x01000000,
|
2016-06-23 15:39:34 +01:00
|
|
|
// Just for documentation: RW sets this flag
|
|
|
|
// to prevent rendering when executing a pipeline,
|
|
|
|
// so only instancing will occur.
|
|
|
|
// librw's pipelines are different so it's unused here.
|
2014-12-23 14:59:14 +00:00
|
|
|
NATIVEINSTANCE = 0x02000000
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2015-01-25 21:27:03 +00:00
|
|
|
void registerMeshPlugin(void);
|
|
|
|
void registerNativeDataPlugin(void);
|
2015-01-10 21:13:27 +00:00
|
|
|
|
2014-12-23 14:59:14 +00:00
|
|
|
struct Clump;
|
2016-06-23 15:39:34 +01:00
|
|
|
struct World;
|
2014-12-23 14:59:14 +00:00
|
|
|
|
2017-08-10 13:43:52 +01:00
|
|
|
struct Atomic
|
2016-01-13 07:58:15 +00:00
|
|
|
{
|
2017-08-10 13:43:52 +01:00
|
|
|
PLUGINBASE
|
2016-02-12 23:52:32 +00:00
|
|
|
typedef void (*RenderCB)(Atomic *atomic);
|
2016-01-13 07:58:15 +00:00
|
|
|
enum { ID = 1 };
|
2016-02-14 19:56:05 +00:00
|
|
|
enum {
|
2017-03-16 10:42:59 +00:00
|
|
|
// flags
|
2016-02-14 19:56:05 +00:00
|
|
|
COLLISIONTEST = 0x01, // unused here
|
2016-02-18 13:56:10 +00:00
|
|
|
RENDER = 0x04,
|
2017-03-16 10:42:59 +00:00
|
|
|
// private flags
|
|
|
|
WORLDBOUNDDIRTY = 0x01,
|
|
|
|
// for setGeometry
|
|
|
|
SAMEBOUNDINGSPHERE = 0x01,
|
2017-03-16 00:10:01 +00:00
|
|
|
};
|
2016-02-12 23:52:32 +00:00
|
|
|
|
2016-01-13 07:58:15 +00:00
|
|
|
ObjectWithFrame object;
|
|
|
|
Geometry *geometry;
|
2017-03-16 00:10:01 +00:00
|
|
|
Sphere boundingSphere;
|
2016-02-18 13:56:10 +00:00
|
|
|
Sphere worldBoundingSphere;
|
2016-01-13 07:58:15 +00:00
|
|
|
Clump *clump;
|
|
|
|
LLLink inClump;
|
|
|
|
ObjPipeline *pipeline;
|
2016-02-12 23:52:32 +00:00
|
|
|
RenderCB renderCB;
|
2016-01-13 07:58:15 +00:00
|
|
|
|
2016-06-23 15:39:34 +01:00
|
|
|
World *world;
|
|
|
|
ObjectWithFrame::Sync originalSync;
|
|
|
|
|
2016-01-13 07:58:15 +00:00
|
|
|
static Atomic *create(void);
|
|
|
|
Atomic *clone(void);
|
|
|
|
void destroy(void);
|
2016-02-18 13:56:10 +00:00
|
|
|
void setFrame(Frame *f) {
|
|
|
|
this->object.setFrame(f);
|
2016-06-16 13:08:09 +01:00
|
|
|
this->object.object.privateFlags |= WORLDBOUNDDIRTY;
|
2016-02-18 13:56:10 +00:00
|
|
|
}
|
2016-06-16 13:08:09 +01:00
|
|
|
Frame *getFrame(void) { return (Frame*)this->object.object.parent; }
|
2016-01-13 07:58:15 +00:00
|
|
|
static Atomic *fromClump(LLLink *lnk){
|
|
|
|
return LLLinkGetData(lnk, Atomic, inClump); }
|
2016-06-14 22:07:16 +01:00
|
|
|
void removeFromClump(void);
|
2017-03-16 00:10:01 +00:00
|
|
|
void setGeometry(Geometry *geo, uint32 flags);
|
2016-02-18 13:56:10 +00:00
|
|
|
Sphere *getWorldBoundingSphere(void);
|
2016-06-14 22:07:16 +01:00
|
|
|
ObjPipeline *getPipeline(void);
|
|
|
|
void render(void) { this->renderCB(this); }
|
2016-07-21 16:06:56 +01:00
|
|
|
void setRenderCB(RenderCB renderCB){
|
|
|
|
this->renderCB = renderCB;
|
|
|
|
if(this->renderCB == nil)
|
|
|
|
this->renderCB = defaultRenderCB;
|
|
|
|
};
|
2016-01-13 07:58:15 +00:00
|
|
|
static Atomic *streamReadClump(Stream *stream,
|
2016-06-17 12:29:49 +01:00
|
|
|
FrameList_ *frameList, Geometry **geometryList);
|
|
|
|
bool streamWriteClump(Stream *stream, FrameList_ *frmlst);
|
2016-01-13 07:58:15 +00:00
|
|
|
uint32 streamGetSize(void);
|
|
|
|
|
2016-02-12 23:52:32 +00:00
|
|
|
static void defaultRenderCB(Atomic *atomic);
|
2016-01-13 07:58:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void registerAtomicRightsPlugin(void);
|
|
|
|
|
2017-08-10 13:43:52 +01:00
|
|
|
struct Light
|
2014-12-23 14:59:14 +00:00
|
|
|
{
|
2017-08-10 13:43:52 +01:00
|
|
|
PLUGINBASE
|
2016-01-13 07:58:15 +00:00
|
|
|
enum { ID = 3 };
|
2016-01-11 10:23:26 +00:00
|
|
|
ObjectWithFrame object;
|
2014-12-23 14:59:14 +00:00
|
|
|
float32 radius;
|
2016-01-14 22:49:00 +00:00
|
|
|
RGBAf color;
|
2014-12-23 14:59:14 +00:00
|
|
|
float32 minusCosAngle;
|
2016-06-23 15:39:34 +01:00
|
|
|
LLLink inWorld;
|
2016-01-11 10:23:26 +00:00
|
|
|
|
2016-06-23 15:39:34 +01:00
|
|
|
// clump extension
|
2014-12-23 14:59:14 +00:00
|
|
|
Clump *clump;
|
2016-01-11 17:22:59 +00:00
|
|
|
LLLink inClump;
|
2014-12-23 14:59:14 +00:00
|
|
|
|
2016-06-23 15:39:34 +01:00
|
|
|
// world extension
|
|
|
|
World *world;
|
|
|
|
ObjectWithFrame::Sync originalSync;
|
|
|
|
|
2016-01-11 17:22:59 +00:00
|
|
|
static Light *create(int32 type);
|
|
|
|
void destroy(void);
|
2016-01-11 10:23:26 +00:00
|
|
|
void setFrame(Frame *f) { this->object.setFrame(f); }
|
2016-06-16 13:08:09 +01:00
|
|
|
Frame *getFrame(void){ return (Frame*)this->object.object.parent; }
|
2016-01-11 17:22:59 +00:00
|
|
|
static Light *fromClump(LLLink *lnk){
|
2016-01-13 07:58:15 +00:00
|
|
|
return LLLinkGetData(lnk, Light, inClump); }
|
2016-06-23 15:39:34 +01:00
|
|
|
static Light *fromWorld(LLLink *lnk){
|
|
|
|
return LLLinkGetData(lnk, Light, inWorld); }
|
2016-01-13 07:58:15 +00:00
|
|
|
void setAngle(float32 angle);
|
|
|
|
float32 getAngle(void);
|
|
|
|
void setColor(float32 r, float32 g, float32 b);
|
2016-06-16 13:08:09 +01:00
|
|
|
int32 getType(void){ return this->object.object.subType; }
|
2017-03-16 00:10:01 +00:00
|
|
|
void setFlags(uint32 flags) { this->object.object.flags = flags; }
|
|
|
|
uint32 getFlags(void) { return this->object.object.flags; }
|
2014-12-27 22:18:10 +00:00
|
|
|
static Light *streamRead(Stream *stream);
|
|
|
|
bool streamWrite(Stream *stream);
|
2014-12-23 14:59:14 +00:00
|
|
|
uint32 streamGetSize(void);
|
2016-01-13 07:58:15 +00:00
|
|
|
|
|
|
|
enum Type {
|
|
|
|
DIRECTIONAL = 1,
|
|
|
|
AMBIENT,
|
|
|
|
POINT = 0x80, // positioned
|
|
|
|
SPOT,
|
|
|
|
SOFTSPOT,
|
|
|
|
};
|
|
|
|
enum Flags {
|
|
|
|
LIGHTATOMICS = 1,
|
|
|
|
LIGHTWORLD = 2
|
|
|
|
};
|
2014-12-23 14:59:14 +00:00
|
|
|
};
|
|
|
|
|
2017-03-16 00:10:01 +00:00
|
|
|
struct FrustumPlane
|
|
|
|
{
|
|
|
|
Plane plane;
|
|
|
|
/* Used for BBox tests:
|
|
|
|
* 0 = inf is closer to normal direction
|
|
|
|
* 1 = sup is closer to normal direction */
|
|
|
|
uint8 closestX;
|
|
|
|
uint8 closestY;
|
|
|
|
uint8 closestZ;
|
|
|
|
};
|
|
|
|
|
2017-08-10 13:43:52 +01:00
|
|
|
struct Camera
|
2014-12-23 14:59:14 +00:00
|
|
|
{
|
2017-08-10 13:43:52 +01:00
|
|
|
PLUGINBASE
|
2016-01-13 07:58:15 +00:00
|
|
|
enum { ID = 4 };
|
2016-02-14 19:56:05 +00:00
|
|
|
enum { PERSPECTIVE = 1, PARALLEL };
|
2016-07-05 17:22:22 +01:00
|
|
|
enum { CLEARIMAGE = 0x1, CLEARZ = 0x2};
|
2017-07-11 07:18:15 +01:00
|
|
|
// return value of frustumTestSphere
|
|
|
|
enum { SPHEREOUTSIDE, SPHEREBOUNDARY, SPHEREINSIDE };
|
2016-02-14 19:56:05 +00:00
|
|
|
|
2016-01-11 10:23:26 +00:00
|
|
|
ObjectWithFrame object;
|
2016-06-23 15:39:34 +01:00
|
|
|
void (*beginUpdateCB)(Camera*);
|
|
|
|
void (*endUpdateCB)(Camera*);
|
2016-01-13 07:58:15 +00:00
|
|
|
V2d viewWindow;
|
|
|
|
V2d viewOffset;
|
2016-01-14 22:49:00 +00:00
|
|
|
float32 nearPlane, farPlane;
|
2016-01-13 07:58:15 +00:00
|
|
|
float32 fogPlane;
|
|
|
|
int32 projection;
|
|
|
|
|
2016-07-06 10:44:59 +01:00
|
|
|
Matrix viewMatrix;
|
|
|
|
float32 zScale, zShift;
|
|
|
|
|
2017-03-16 00:10:01 +00:00
|
|
|
FrustumPlane frustumPlanes[6];
|
|
|
|
V3d frustumCorners[8];
|
|
|
|
BBox frustumBoundBox;
|
|
|
|
|
2016-06-23 15:39:34 +01:00
|
|
|
// clump link handled by plugin in RW
|
2014-12-23 14:59:14 +00:00
|
|
|
Clump *clump;
|
2016-01-11 17:22:59 +00:00
|
|
|
LLLink inClump;
|
2014-12-23 14:59:14 +00:00
|
|
|
|
2016-06-23 15:39:34 +01:00
|
|
|
// world extension
|
|
|
|
/* 3 unknowns */
|
|
|
|
World *world;
|
|
|
|
ObjectWithFrame::Sync originalSync;
|
|
|
|
void (*originalBeginUpdate)(Camera*);
|
|
|
|
void (*originalEndUpdate)(Camera*);
|
2016-06-21 22:16:09 +01:00
|
|
|
|
2016-01-13 07:58:15 +00:00
|
|
|
static Camera *create(void);
|
|
|
|
Camera *clone(void);
|
2016-01-11 17:22:59 +00:00
|
|
|
void destroy(void);
|
2016-01-11 10:23:26 +00:00
|
|
|
void setFrame(Frame *f) { this->object.setFrame(f); }
|
2016-06-16 13:08:09 +01:00
|
|
|
Frame *getFrame(void){ return (Frame*)this->object.object.parent; }
|
2016-01-13 07:58:15 +00:00
|
|
|
static Camera *fromClump(LLLink *lnk){
|
|
|
|
return LLLinkGetData(lnk, Camera, inClump); }
|
2016-06-21 22:16:09 +01:00
|
|
|
void beginUpdate(void) { this->beginUpdateCB(this); }
|
|
|
|
void endUpdate(void) { this->endUpdateCB(this); }
|
2016-07-05 17:22:22 +01:00
|
|
|
void clear(RGBA *col, uint32 mode);
|
2017-08-09 09:57:32 +01:00
|
|
|
void showRaster(void);
|
2016-07-06 10:44:59 +01:00
|
|
|
void setNearPlane(float32);
|
|
|
|
void setFarPlane(float32);
|
2017-07-11 07:18:15 +01:00
|
|
|
int32 frustumTestSphere(Sphere *s);
|
2016-01-13 07:58:15 +00:00
|
|
|
static Camera *streamRead(Stream *stream);
|
|
|
|
bool streamWrite(Stream *stream);
|
2014-12-23 14:59:14 +00:00
|
|
|
uint32 streamGetSize(void);
|
2016-02-14 19:56:05 +00:00
|
|
|
|
|
|
|
// fov in degrees
|
|
|
|
void setFOV(float32 fov, float32 ratio);
|
2014-12-23 14:59:14 +00:00
|
|
|
};
|
|
|
|
|
2017-08-10 13:43:52 +01:00
|
|
|
struct Clump
|
2014-12-23 14:59:14 +00:00
|
|
|
{
|
2017-08-10 13:43:52 +01:00
|
|
|
PLUGINBASE
|
2016-01-13 07:58:15 +00:00
|
|
|
enum { ID = 2 };
|
2016-01-14 22:49:00 +00:00
|
|
|
Object object;
|
2016-01-11 17:22:59 +00:00
|
|
|
LinkList atomics;
|
|
|
|
LinkList lights;
|
2016-01-13 07:58:15 +00:00
|
|
|
LinkList cameras;
|
2014-12-23 14:59:14 +00:00
|
|
|
|
2016-06-23 15:39:34 +01:00
|
|
|
World *world;
|
|
|
|
|
2016-01-11 17:22:59 +00:00
|
|
|
static Clump *create(void);
|
|
|
|
Clump *clone(void);
|
|
|
|
void destroy(void);
|
2016-01-14 22:49:00 +00:00
|
|
|
int32 countAtomics(void) { return this->atomics.count(); }
|
2016-01-11 17:22:59 +00:00
|
|
|
void addAtomic(Atomic *a){
|
|
|
|
a->clump = this;
|
|
|
|
this->atomics.append(&a->inClump);
|
|
|
|
}
|
2016-01-14 22:49:00 +00:00
|
|
|
int32 countLights(void) { return this->lights.count(); }
|
2016-01-11 17:22:59 +00:00
|
|
|
void addLight(Light *l){
|
|
|
|
l->clump = this;
|
|
|
|
this->lights.append(&l->inClump);
|
|
|
|
}
|
2016-01-14 22:49:00 +00:00
|
|
|
int32 countCameras(void) { return this->cameras.count(); }
|
2016-01-13 07:58:15 +00:00
|
|
|
void addCamera(Camera *c){
|
|
|
|
c->clump = this;
|
|
|
|
this->cameras.append(&c->inClump);
|
2016-01-11 23:38:36 +00:00
|
|
|
}
|
2016-01-13 07:58:15 +00:00
|
|
|
void setFrame(Frame *f){
|
|
|
|
this->object.parent = f; }
|
2016-01-11 23:38:36 +00:00
|
|
|
Frame *getFrame(void){
|
2016-01-13 07:58:15 +00:00
|
|
|
return (Frame*)this->object.parent; }
|
2014-12-27 22:18:10 +00:00
|
|
|
static Clump *streamRead(Stream *stream);
|
|
|
|
bool streamWrite(Stream *stream);
|
2014-12-23 14:59:14 +00:00
|
|
|
uint32 streamGetSize(void);
|
2016-02-14 19:56:05 +00:00
|
|
|
void render(void);
|
2014-12-23 14:59:14 +00:00
|
|
|
};
|
|
|
|
|
2016-06-23 15:39:34 +01:00
|
|
|
// A bit of a stub right now
|
2017-08-10 13:43:52 +01:00
|
|
|
struct World
|
2016-06-23 15:39:34 +01:00
|
|
|
{
|
2017-08-10 13:43:52 +01:00
|
|
|
PLUGINBASE
|
2016-06-23 15:39:34 +01:00
|
|
|
enum { ID = 7 };
|
|
|
|
Object object;
|
|
|
|
LinkList lights; // these have positions (type >= 0x80)
|
|
|
|
LinkList directionalLights; // these do not (type < 0x80)
|
|
|
|
|
|
|
|
static World *create(void);
|
|
|
|
void addLight(Light *light);
|
|
|
|
void addCamera(Camera *cam);
|
|
|
|
};
|
|
|
|
|
2017-08-10 13:43:52 +01:00
|
|
|
struct TexDictionary
|
2015-01-20 18:22:57 +00:00
|
|
|
{
|
2017-08-10 13:43:52 +01:00
|
|
|
PLUGINBASE
|
2016-01-13 07:58:15 +00:00
|
|
|
enum { ID = 6 };
|
2016-01-11 10:23:26 +00:00
|
|
|
Object object;
|
2016-01-11 17:22:59 +00:00
|
|
|
LinkList textures;
|
2015-01-20 18:22:57 +00:00
|
|
|
|
2016-01-11 17:22:59 +00:00
|
|
|
static TexDictionary *create(void);
|
|
|
|
void destroy(void);
|
2016-01-14 22:49:00 +00:00
|
|
|
int32 count(void) { return this->textures.count(); }
|
2016-07-21 07:59:06 +01:00
|
|
|
void add(Texture *t);
|
2015-01-20 18:22:57 +00:00
|
|
|
Texture *find(const char *name);
|
2015-09-13 19:23:22 +01:00
|
|
|
static TexDictionary *streamRead(Stream *stream);
|
|
|
|
void streamWrite(Stream *stream);
|
|
|
|
uint32 streamGetSize(void);
|
2015-01-20 18:22:57 +00:00
|
|
|
|
2016-07-21 07:59:06 +01:00
|
|
|
static void setCurrent(TexDictionary *txd);
|
|
|
|
static TexDictionary *getCurrent(void);
|
|
|
|
};
|
2016-01-13 07:58:15 +00:00
|
|
|
|
2015-01-06 22:17:05 +00:00
|
|
|
}
|