mirror of
https://github.com/aap/librw.git
synced 2025-02-16 17:26:18 +00:00
added very basic World
This commit is contained in:
parent
3271713d16
commit
b7d0b04380
@ -31,6 +31,26 @@ cameraSync(ObjectWithFrame*)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
worldBeginUpdateCB(Camera *cam)
|
||||||
|
{
|
||||||
|
engine.currentWorld = cam->world;
|
||||||
|
cam->originalBeginUpdate(cam);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
worldEndUpdateCB(Camera *cam)
|
||||||
|
{
|
||||||
|
cam->originalEndUpdate(cam);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
worldCameraSync(ObjectWithFrame *obj)
|
||||||
|
{
|
||||||
|
Camera *camera = (Camera*)obj;
|
||||||
|
camera->originalSync(obj);
|
||||||
|
}
|
||||||
|
|
||||||
Camera*
|
Camera*
|
||||||
Camera::create(void)
|
Camera::create(void)
|
||||||
{
|
{
|
||||||
@ -41,17 +61,27 @@ Camera::create(void)
|
|||||||
}
|
}
|
||||||
cam->object.object.init(Camera::ID, 0);
|
cam->object.object.init(Camera::ID, 0);
|
||||||
cam->object.syncCB = cameraSync;
|
cam->object.syncCB = cameraSync;
|
||||||
|
cam->beginUpdateCB = defaultBeginUpdateCB;
|
||||||
|
cam->endUpdateCB = defaultEndUpdateCB;
|
||||||
cam->viewWindow.set(1.0f, 1.0f);
|
cam->viewWindow.set(1.0f, 1.0f);
|
||||||
cam->viewOffset.set(0.0f, 0.0f);
|
cam->viewOffset.set(0.0f, 0.0f);
|
||||||
cam->nearPlane = 0.05f;
|
cam->nearPlane = 0.05f;
|
||||||
cam->farPlane = 10.0f;
|
cam->farPlane = 10.0f;
|
||||||
cam->fogPlane = 5.0f;
|
cam->fogPlane = 5.0f;
|
||||||
cam->projection = Camera::PERSPECTIVE;
|
cam->projection = Camera::PERSPECTIVE;
|
||||||
|
|
||||||
|
// clump extension
|
||||||
cam->clump = nil;
|
cam->clump = nil;
|
||||||
cam->inClump.init();
|
cam->inClump.init();
|
||||||
|
|
||||||
cam->beginUpdateCB = defaultBeginUpdateCB;
|
// world extension
|
||||||
cam->endUpdateCB = defaultEndUpdateCB;
|
cam->world = nil;
|
||||||
|
cam->originalSync = cam->object.syncCB;
|
||||||
|
cam->originalBeginUpdate = cam->beginUpdateCB;
|
||||||
|
cam->originalEndUpdate = cam->endUpdateCB;
|
||||||
|
cam->object.syncCB = worldCameraSync;
|
||||||
|
cam->beginUpdateCB = worldBeginUpdateCB;
|
||||||
|
cam->endUpdateCB = worldEndUpdateCB;
|
||||||
|
|
||||||
cam->constructPlugins();
|
cam->constructPlugins();
|
||||||
return cam;
|
return cam;
|
||||||
@ -138,6 +168,7 @@ Camera::streamGetSize(void)
|
|||||||
return 12 + sizeof(CameraChunkData) + 12 + this->streamGetPluginSize();
|
return 12 + sizeof(CameraChunkData) + 12 + this->streamGetPluginSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: remove
|
||||||
void
|
void
|
||||||
Camera::updateProjectionMatrix(void)
|
Camera::updateProjectionMatrix(void)
|
||||||
{
|
{
|
||||||
|
@ -320,6 +320,14 @@ atomicSync(ObjectWithFrame*)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
worldAtomicSync(ObjectWithFrame *obj)
|
||||||
|
{
|
||||||
|
Atomic *atomic = (Atomic*)obj;
|
||||||
|
atomic->originalSync(obj);
|
||||||
|
}
|
||||||
|
|
||||||
Atomic*
|
Atomic*
|
||||||
Atomic::create(void)
|
Atomic::create(void)
|
||||||
{
|
{
|
||||||
@ -338,6 +346,12 @@ Atomic::create(void)
|
|||||||
atomic->pipeline = nil;
|
atomic->pipeline = nil;
|
||||||
atomic->renderCB = Atomic::defaultRenderCB;
|
atomic->renderCB = Atomic::defaultRenderCB;
|
||||||
atomic->object.object.flags = Atomic::COLLISIONTEST | Atomic::RENDER;
|
atomic->object.object.flags = Atomic::COLLISIONTEST | Atomic::RENDER;
|
||||||
|
|
||||||
|
// World extension
|
||||||
|
atomic->world = nil;
|
||||||
|
atomic->originalSync = atomic->object.syncCB;
|
||||||
|
atomic->object.syncCB = worldAtomicSync;
|
||||||
|
|
||||||
atomic->constructPlugins();
|
atomic->constructPlugins();
|
||||||
return atomic;
|
return atomic;
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,13 @@ lightSync(ObjectWithFrame*)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
worldLightSync(ObjectWithFrame *obj)
|
||||||
|
{
|
||||||
|
Light *light = (Light*)obj;
|
||||||
|
light->originalSync(obj);
|
||||||
|
}
|
||||||
|
|
||||||
Light*
|
Light*
|
||||||
Light::create(int32 type)
|
Light::create(int32 type)
|
||||||
{
|
{
|
||||||
@ -34,8 +41,17 @@ Light::create(int32 type)
|
|||||||
light->minusCosAngle = 1.0f;
|
light->minusCosAngle = 1.0f;
|
||||||
light->object.object.privateFlags = 1;
|
light->object.object.privateFlags = 1;
|
||||||
light->object.object.flags = LIGHTATOMICS | LIGHTWORLD;
|
light->object.object.flags = LIGHTATOMICS | LIGHTWORLD;
|
||||||
|
light->inWorld.init();
|
||||||
|
|
||||||
|
// clump extension
|
||||||
light->clump = nil;
|
light->clump = nil;
|
||||||
light->inClump.init();
|
light->inClump.init();
|
||||||
|
|
||||||
|
// world extension
|
||||||
|
light->world = nil;
|
||||||
|
light->originalSync = light->object.syncCB;
|
||||||
|
light->object.syncCB = worldLightSync;
|
||||||
|
|
||||||
light->constructPlugins();
|
light->constructPlugins();
|
||||||
return light;
|
return light;
|
||||||
}
|
}
|
||||||
@ -46,6 +62,7 @@ Light::destroy(void)
|
|||||||
this->destructPlugins();
|
this->destructPlugins();
|
||||||
if(this->clump)
|
if(this->clump)
|
||||||
this->inClump.remove();
|
this->inClump.remove();
|
||||||
|
// we do not remove from world, be careful
|
||||||
free(this);
|
free(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,6 +137,15 @@ Matrix::setIdentity(void)
|
|||||||
*this = identMat;
|
*this = identMat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Matrix::pointInDirection(const V3d &d, const V3d &up)
|
||||||
|
{
|
||||||
|
// this->right is really pointing left
|
||||||
|
this->at = normalize(d);
|
||||||
|
this->right = normalize(cross(up, this->at));
|
||||||
|
this->up = cross(this->at, this->right);
|
||||||
|
}
|
||||||
|
|
||||||
V3d
|
V3d
|
||||||
Matrix::transPoint(const V3d &p)
|
Matrix::transPoint(const V3d &p)
|
||||||
{
|
{
|
||||||
|
20
src/rwbase.h
20
src/rwbase.h
@ -53,6 +53,25 @@ struct RGBAf
|
|||||||
float32 alpha;
|
float32 alpha;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline void convColor(RGBA *i, RGBAf *f){
|
||||||
|
int32 c;
|
||||||
|
c = (int32)(f->red*255.0f + 0.5f);
|
||||||
|
i->red = (uint8)c;
|
||||||
|
c = (int32)(f->green*255.0f + 0.5f);
|
||||||
|
i->green = (uint8)c;
|
||||||
|
c = (int32)(f->blue*255.0f + 0.5f);
|
||||||
|
i->blue = (uint8)c;
|
||||||
|
c = (int32)(f->alpha*255.0f + 0.5f);
|
||||||
|
i->alpha = (uint8)c;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void convColor(RGBAf *f, RGBA *i){
|
||||||
|
f->red = i->red/255.0f;
|
||||||
|
f->green = i->green/255.0f;
|
||||||
|
f->blue = i->blue/255.0f;
|
||||||
|
f->alpha = i->alpha/255.0f;
|
||||||
|
}
|
||||||
|
|
||||||
struct V2d
|
struct V2d
|
||||||
{
|
{
|
||||||
float32 x, y;
|
float32 x, y;
|
||||||
@ -122,6 +141,7 @@ struct Matrix
|
|||||||
|
|
||||||
static Matrix makeRotation(const Quat &q);
|
static Matrix makeRotation(const Quat &q);
|
||||||
void setIdentity(void);
|
void setIdentity(void);
|
||||||
|
void pointInDirection(const V3d &d, const V3d &up);
|
||||||
V3d transPoint(const V3d &p);
|
V3d transPoint(const V3d &p);
|
||||||
V3d transVec(const V3d &v);
|
V3d transVec(const V3d &v);
|
||||||
bool32 isIdentity(void);
|
bool32 isIdentity(void);
|
||||||
|
@ -4,7 +4,8 @@ namespace rw {
|
|||||||
|
|
||||||
struct Engine
|
struct Engine
|
||||||
{
|
{
|
||||||
Camera *currentCamera;
|
void *currentCamera;
|
||||||
|
void *currentWorld;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Engine engine;
|
extern Engine engine;
|
||||||
|
@ -148,9 +148,11 @@ Frame **makeFrameList(Frame *frame, Frame **flist);
|
|||||||
|
|
||||||
struct ObjectWithFrame
|
struct ObjectWithFrame
|
||||||
{
|
{
|
||||||
|
typedef void (*Sync)(ObjectWithFrame*);
|
||||||
|
|
||||||
Object object;
|
Object object;
|
||||||
LLLink inFrame;
|
LLLink inFrame;
|
||||||
void (*syncCB)(ObjectWithFrame*);
|
Sync syncCB;
|
||||||
|
|
||||||
void setFrame(Frame *f){
|
void setFrame(Frame *f){
|
||||||
if(this->object.parent)
|
if(this->object.parent)
|
||||||
@ -237,6 +239,14 @@ struct Raster : PluginBase<Raster>
|
|||||||
PAL4 = 0x4000,
|
PAL4 = 0x4000,
|
||||||
MIPMAP = 0x8000
|
MIPMAP = 0x8000
|
||||||
};
|
};
|
||||||
|
enum Type {
|
||||||
|
NORMAL = 0x00,
|
||||||
|
ZBUFFER = 0x01,
|
||||||
|
CAMERA = 0x02,
|
||||||
|
TEXTURE = 0x04,
|
||||||
|
CAMERATEXTURE = 0x05,
|
||||||
|
DONTALLOCATE = 0x80,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
extern bool32 loadTextures;
|
extern bool32 loadTextures;
|
||||||
@ -403,6 +413,10 @@ struct Geometry : PluginBase<Geometry>
|
|||||||
MODULATE = 0x40,
|
MODULATE = 0x40,
|
||||||
TEXTURED2 = 0x80,
|
TEXTURED2 = 0x80,
|
||||||
NATIVE = 0x01000000,
|
NATIVE = 0x01000000,
|
||||||
|
// 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.
|
||||||
NATIVEINSTANCE = 0x02000000
|
NATIVEINSTANCE = 0x02000000
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -411,6 +425,7 @@ void registerMeshPlugin(void);
|
|||||||
void registerNativeDataPlugin(void);
|
void registerNativeDataPlugin(void);
|
||||||
|
|
||||||
struct Clump;
|
struct Clump;
|
||||||
|
struct World;
|
||||||
|
|
||||||
struct Atomic : PluginBase<Atomic>
|
struct Atomic : PluginBase<Atomic>
|
||||||
{
|
{
|
||||||
@ -431,6 +446,9 @@ struct Atomic : PluginBase<Atomic>
|
|||||||
ObjPipeline *pipeline;
|
ObjPipeline *pipeline;
|
||||||
RenderCB renderCB;
|
RenderCB renderCB;
|
||||||
|
|
||||||
|
World *world;
|
||||||
|
ObjectWithFrame::Sync originalSync;
|
||||||
|
|
||||||
static Atomic *create(void);
|
static Atomic *create(void);
|
||||||
Atomic *clone(void);
|
Atomic *clone(void);
|
||||||
void destroy(void);
|
void destroy(void);
|
||||||
@ -463,17 +481,24 @@ struct Light : PluginBase<Light>
|
|||||||
float32 radius;
|
float32 radius;
|
||||||
RGBAf color;
|
RGBAf color;
|
||||||
float32 minusCosAngle;
|
float32 minusCosAngle;
|
||||||
|
LLLink inWorld;
|
||||||
|
|
||||||
// clump link handled by plugin in RW
|
// clump extension
|
||||||
Clump *clump;
|
Clump *clump;
|
||||||
LLLink inClump;
|
LLLink inClump;
|
||||||
|
|
||||||
|
// world extension
|
||||||
|
World *world;
|
||||||
|
ObjectWithFrame::Sync originalSync;
|
||||||
|
|
||||||
static Light *create(int32 type);
|
static Light *create(int32 type);
|
||||||
void destroy(void);
|
void destroy(void);
|
||||||
void setFrame(Frame *f) { this->object.setFrame(f); }
|
void setFrame(Frame *f) { this->object.setFrame(f); }
|
||||||
Frame *getFrame(void){ return (Frame*)this->object.object.parent; }
|
Frame *getFrame(void){ return (Frame*)this->object.object.parent; }
|
||||||
static Light *fromClump(LLLink *lnk){
|
static Light *fromClump(LLLink *lnk){
|
||||||
return LLLinkGetData(lnk, Light, inClump); }
|
return LLLinkGetData(lnk, Light, inClump); }
|
||||||
|
static Light *fromWorld(LLLink *lnk){
|
||||||
|
return LLLinkGetData(lnk, Light, inWorld); }
|
||||||
void setAngle(float32 angle);
|
void setAngle(float32 angle);
|
||||||
float32 getAngle(void);
|
float32 getAngle(void);
|
||||||
void setColor(float32 r, float32 g, float32 b);
|
void setColor(float32 r, float32 g, float32 b);
|
||||||
@ -501,18 +526,26 @@ struct Camera : PluginBase<Camera>
|
|||||||
enum { PERSPECTIVE = 1, PARALLEL };
|
enum { PERSPECTIVE = 1, PARALLEL };
|
||||||
|
|
||||||
ObjectWithFrame object;
|
ObjectWithFrame object;
|
||||||
|
void (*beginUpdateCB)(Camera*);
|
||||||
|
void (*endUpdateCB)(Camera*);
|
||||||
V2d viewWindow;
|
V2d viewWindow;
|
||||||
V2d viewOffset;
|
V2d viewOffset;
|
||||||
float32 nearPlane, farPlane;
|
float32 nearPlane, farPlane;
|
||||||
float32 fogPlane;
|
float32 fogPlane;
|
||||||
int32 projection;
|
int32 projection;
|
||||||
|
// TODO: remove this?
|
||||||
float32 projMat[16];
|
float32 projMat[16];
|
||||||
|
|
||||||
|
// clump link handled by plugin in RW
|
||||||
Clump *clump;
|
Clump *clump;
|
||||||
LLLink inClump;
|
LLLink inClump;
|
||||||
|
|
||||||
void (*beginUpdateCB)(Camera*);
|
// world extension
|
||||||
void (*endUpdateCB)(Camera*);
|
/* 3 unknowns */
|
||||||
|
World *world;
|
||||||
|
ObjectWithFrame::Sync originalSync;
|
||||||
|
void (*originalBeginUpdate)(Camera*);
|
||||||
|
void (*originalEndUpdate)(Camera*);
|
||||||
|
|
||||||
static Camera *create(void);
|
static Camera *create(void);
|
||||||
Camera *clone(void);
|
Camera *clone(void);
|
||||||
@ -540,6 +573,8 @@ struct Clump : PluginBase<Clump>
|
|||||||
LinkList lights;
|
LinkList lights;
|
||||||
LinkList cameras;
|
LinkList cameras;
|
||||||
|
|
||||||
|
World *world;
|
||||||
|
|
||||||
static Clump *create(void);
|
static Clump *create(void);
|
||||||
Clump *clone(void);
|
Clump *clone(void);
|
||||||
void destroy(void);
|
void destroy(void);
|
||||||
@ -568,6 +603,19 @@ struct Clump : PluginBase<Clump>
|
|||||||
void render(void);
|
void render(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// A bit of a stub right now
|
||||||
|
struct World : PluginBase<World>
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
};
|
||||||
|
|
||||||
struct TexDictionary : PluginBase<TexDictionary>
|
struct TexDictionary : PluginBase<TexDictionary>
|
||||||
{
|
{
|
||||||
enum { ID = 6 };
|
enum { ID = 6 };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user