mirror of https://github.com/aap/librw.git
improved uv animation code
This commit is contained in:
parent
da0417571d
commit
56e48f4d76
|
@ -78,6 +78,7 @@ Global
|
||||||
{2592ED29-F258-4949-AB45-7B873BF697F7}.Debug - null|Win32.ActiveCfg = Debug - null|Win32
|
{2592ED29-F258-4949-AB45-7B873BF697F7}.Debug - null|Win32.ActiveCfg = Debug - null|Win32
|
||||||
{2592ED29-F258-4949-AB45-7B873BF697F7}.Debug - null|Win32.Build.0 = Debug - null|Win32
|
{2592ED29-F258-4949-AB45-7B873BF697F7}.Debug - null|Win32.Build.0 = Debug - null|Win32
|
||||||
{2592ED29-F258-4949-AB45-7B873BF697F7}.Debug - null|x64.ActiveCfg = Debug - null|x64
|
{2592ED29-F258-4949-AB45-7B873BF697F7}.Debug - null|x64.ActiveCfg = Debug - null|x64
|
||||||
|
{2592ED29-F258-4949-AB45-7B873BF697F7}.Debug - null|x64.Build.0 = Debug - null|x64
|
||||||
{2592ED29-F258-4949-AB45-7B873BF697F7}.Debug|Win32.ActiveCfg = Debug|Win32
|
{2592ED29-F258-4949-AB45-7B873BF697F7}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||||
{2592ED29-F258-4949-AB45-7B873BF697F7}.Debug|x64.ActiveCfg = Debug|x64
|
{2592ED29-F258-4949-AB45-7B873BF697F7}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
{2592ED29-F258-4949-AB45-7B873BF697F7}.Debug|x64.Build.0 = Debug|x64
|
{2592ED29-F258-4949-AB45-7B873BF697F7}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
|
138
src/anim.cpp
138
src/anim.cpp
|
@ -39,16 +39,27 @@ findAnimInterpolatorInfo(int32 id)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Animation::Animation(AnimInterpolatorInfo *interpInfo, int32 numFrames, int32 flags, float duration)
|
Animation*
|
||||||
|
Animation::create(AnimInterpolatorInfo *interpInfo, int32 numFrames, int32 flags, float duration)
|
||||||
{
|
{
|
||||||
this->interpInfo = interpInfo;
|
Animation *anim = (Animation*)malloc(sizeof(*anim));
|
||||||
this->numFrames = numFrames;
|
anim->interpInfo = interpInfo;
|
||||||
this->flags = flags;
|
anim->numFrames = numFrames;
|
||||||
this->duration = duration;
|
anim->flags = flags;
|
||||||
uint8 *data = new uint8[this->numFrames*interpInfo->keyFrameSize + interpInfo->customDataSize];
|
anim->duration = duration;
|
||||||
this->keyframes = data;
|
uint8 *data = new uint8[anim->numFrames*interpInfo->keyFrameSize + interpInfo->customDataSize];
|
||||||
data += this->numFrames*interpInfo->keyFrameSize;
|
anim->keyframes = data;
|
||||||
this->customData = data;
|
data += anim->numFrames*interpInfo->keyFrameSize;
|
||||||
|
anim->customData = data;
|
||||||
|
return anim;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Animation::destroy(void)
|
||||||
|
{
|
||||||
|
uint8 *c = (uint8*)this->keyframes;
|
||||||
|
delete[] c;
|
||||||
|
free(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Animation*
|
Animation*
|
||||||
|
@ -61,7 +72,7 @@ Animation::streamRead(Stream *stream)
|
||||||
int32 numFrames = stream->readI32();
|
int32 numFrames = stream->readI32();
|
||||||
int32 flags = stream->readI32();
|
int32 flags = stream->readI32();
|
||||||
float duration = stream->readF32();
|
float duration = stream->readF32();
|
||||||
anim = new Animation(interpInfo, numFrames, flags, duration);
|
anim = Animation::create(interpInfo, numFrames, flags, duration);
|
||||||
interpInfo->streamRead(stream, anim);
|
interpInfo->streamRead(stream, anim);
|
||||||
return anim;
|
return anim;
|
||||||
}
|
}
|
||||||
|
@ -74,7 +85,7 @@ Animation::streamReadLegacy(Stream *stream)
|
||||||
int32 numFrames = stream->readI32();
|
int32 numFrames = stream->readI32();
|
||||||
int32 flags = stream->readI32();
|
int32 flags = stream->readI32();
|
||||||
float duration = stream->readF32();
|
float duration = stream->readF32();
|
||||||
anim = new Animation(interpInfo, numFrames, flags, duration);
|
anim = Animation::create(interpInfo, numFrames, flags, duration);
|
||||||
HAnimKeyFrame *frames = (HAnimKeyFrame*)anim->keyframes;
|
HAnimKeyFrame *frames = (HAnimKeyFrame*)anim->keyframes;
|
||||||
for(int32 i = 0; i < anim->numFrames; i++){
|
for(int32 i = 0; i < anim->numFrames; i++){
|
||||||
stream->read(frames[i].q, 4*4);
|
stream->read(frames[i].q, 4*4);
|
||||||
|
@ -129,18 +140,58 @@ AnimInterpolator::AnimInterpolator(Animation *anim)
|
||||||
this->anim = anim;
|
this->anim = anim;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// UVAnim
|
||||||
|
//
|
||||||
|
|
||||||
|
void
|
||||||
|
UVAnimCustomData::destroy(Animation *anim)
|
||||||
|
{
|
||||||
|
this->refCount--;
|
||||||
|
if(this->refCount <= 0)
|
||||||
|
anim->destroy();
|
||||||
|
}
|
||||||
|
|
||||||
UVAnimDictionary *currentUVAnimDictionary;
|
UVAnimDictionary *currentUVAnimDictionary;
|
||||||
|
|
||||||
|
UVAnimDictionary*
|
||||||
|
UVAnimDictionary::create(void)
|
||||||
|
{
|
||||||
|
UVAnimDictionary *dict = (UVAnimDictionary*)malloc(sizeof(*dict));
|
||||||
|
dict->animations.init();
|
||||||
|
return dict;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
UVAnimDictionary::destroy(void)
|
||||||
|
{
|
||||||
|
FORLIST(lnk, this->animations){
|
||||||
|
UVAnimDictEntry *de = UVAnimDictEntry::fromDict(lnk);
|
||||||
|
UVAnimCustomData *cust = (UVAnimCustomData*)de->anim->customData;
|
||||||
|
cust->destroy(de->anim);
|
||||||
|
delete de;
|
||||||
|
}
|
||||||
|
free(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
UVAnimDictionary::add(Animation *anim)
|
||||||
|
{
|
||||||
|
UVAnimDictEntry *de = new UVAnimDictEntry;
|
||||||
|
UVAnimCustomData *custom = (UVAnimCustomData*)anim->customData;
|
||||||
|
de->anim = anim;
|
||||||
|
this->animations.append(&de->inDict);
|
||||||
|
}
|
||||||
|
|
||||||
UVAnimDictionary*
|
UVAnimDictionary*
|
||||||
UVAnimDictionary::streamRead(Stream *stream)
|
UVAnimDictionary::streamRead(Stream *stream)
|
||||||
{
|
{
|
||||||
assert(findChunk(stream, ID_STRUCT, NULL, NULL));
|
assert(findChunk(stream, ID_STRUCT, NULL, NULL));
|
||||||
UVAnimDictionary *dict = new UVAnimDictionary;
|
UVAnimDictionary *dict = UVAnimDictionary::create();
|
||||||
dict->numAnims = stream->readI32();
|
int32 numAnims = stream->readI32();
|
||||||
dict->anims = new Animation*[dict->numAnims];
|
for(int32 i = 0; i < numAnims; i++){
|
||||||
for(int32 i = 0; i < dict->numAnims; i++){
|
|
||||||
assert(findChunk(stream, ID_ANIMANIMATION, NULL, NULL));
|
assert(findChunk(stream, ID_ANIMANIMATION, NULL, NULL));
|
||||||
dict->anims[i] = Animation::streamRead(stream);
|
dict->add(Animation::streamRead(stream));
|
||||||
}
|
}
|
||||||
return dict;
|
return dict;
|
||||||
}
|
}
|
||||||
|
@ -151,9 +202,12 @@ UVAnimDictionary::streamWrite(Stream *stream)
|
||||||
uint32 size = this->streamGetSize();
|
uint32 size = this->streamGetSize();
|
||||||
writeChunkHeader(stream, ID_UVANIMDICT, size);
|
writeChunkHeader(stream, ID_UVANIMDICT, size);
|
||||||
writeChunkHeader(stream, ID_STRUCT, 4);
|
writeChunkHeader(stream, ID_STRUCT, 4);
|
||||||
stream->writeI32(this->numAnims);
|
int32 numAnims = this->count();
|
||||||
for(int32 i = 0; i < this->numAnims; i++)
|
stream->writeI32(numAnims);
|
||||||
this->anims[i]->streamWrite(stream);
|
FORLIST(lnk, this->animations){
|
||||||
|
UVAnimDictEntry *de = UVAnimDictEntry::fromDict(lnk);
|
||||||
|
de->anim->streamWrite(stream);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,16 +215,19 @@ uint32
|
||||||
UVAnimDictionary::streamGetSize(void)
|
UVAnimDictionary::streamGetSize(void)
|
||||||
{
|
{
|
||||||
uint32 size = 12 + 4;
|
uint32 size = 12 + 4;
|
||||||
for(int32 i = 0; i < this->numAnims; i++)
|
int32 numAnims = this->count();
|
||||||
size += 12 + this->anims[i]->streamGetSize();
|
FORLIST(lnk, this->animations){
|
||||||
|
UVAnimDictEntry *de = UVAnimDictEntry::fromDict(lnk);
|
||||||
|
size += 12 + de->anim->streamGetSize();
|
||||||
|
}
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
Animation*
|
Animation*
|
||||||
UVAnimDictionary::find(const char *name)
|
UVAnimDictionary::find(const char *name)
|
||||||
{
|
{
|
||||||
for(int32 i = 0; i < this->numAnims; i++){
|
FORLIST(lnk, this->animations){
|
||||||
Animation *anim = this->anims[i];
|
Animation *anim = UVAnimDictEntry::fromDict(lnk)->anim;
|
||||||
UVAnimCustomData *custom = (UVAnimCustomData*)anim->customData;
|
UVAnimCustomData *custom = (UVAnimCustomData*)anim->customData;
|
||||||
if(strncmp(custom->name, name, 32) == 0) // strncmp correct?
|
if(strncmp(custom->name, name, 32) == 0) // strncmp correct?
|
||||||
return anim;
|
return anim;
|
||||||
|
@ -186,6 +243,7 @@ uvAnimStreamRead(Stream *stream, Animation *anim)
|
||||||
stream->readI32();
|
stream->readI32();
|
||||||
stream->read(custom->name, 32);
|
stream->read(custom->name, 32);
|
||||||
stream->read(custom->nodeToUVChannel, 8*4);
|
stream->read(custom->nodeToUVChannel, 8*4);
|
||||||
|
custom->refCount = 1;
|
||||||
|
|
||||||
for(int32 i = 0; i < anim->numFrames; i++){
|
for(int32 i = 0; i < anim->numFrames; i++){
|
||||||
frames[i].time = stream->readF32();
|
frames[i].time = stream->readF32();
|
||||||
|
@ -262,8 +320,14 @@ destroyUVAnim(void *object, int32 offset, int32)
|
||||||
{
|
{
|
||||||
UVAnim *uvanim;
|
UVAnim *uvanim;
|
||||||
uvanim = PLUGINOFFSET(UVAnim, object, offset);
|
uvanim = PLUGINOFFSET(UVAnim, object, offset);
|
||||||
// TODO: ref counts &c.
|
for(int32 i = 0; i < 8; i++){
|
||||||
(void)uvanim;
|
AnimInterpolator *ip = uvanim->interp[i];
|
||||||
|
if(ip){
|
||||||
|
UVAnimCustomData *custom = (UVAnimCustomData*)ip->anim->customData;
|
||||||
|
custom->destroy(ip->anim);
|
||||||
|
delete ip;
|
||||||
|
}
|
||||||
|
}
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,8 +337,16 @@ copyUVAnim(void *dst, void *src, int32 offset, int32)
|
||||||
UVAnim *srcuvanim, *dstuvanim;
|
UVAnim *srcuvanim, *dstuvanim;
|
||||||
dstuvanim = PLUGINOFFSET(UVAnim, dst, offset);
|
dstuvanim = PLUGINOFFSET(UVAnim, dst, offset);
|
||||||
srcuvanim = PLUGINOFFSET(UVAnim, src, offset);
|
srcuvanim = PLUGINOFFSET(UVAnim, src, offset);
|
||||||
memcpy(dstuvanim, srcuvanim, sizeof(*srcuvanim));
|
for(int32 i = 0; i < 8; i++){
|
||||||
// TODO: ref counts &c.
|
AnimInterpolator *srcip = srcuvanim->interp[i];
|
||||||
|
AnimInterpolator *dstip;
|
||||||
|
if(srcip){
|
||||||
|
UVAnimCustomData *custom = (UVAnimCustomData*)srcip->anim->customData;
|
||||||
|
dstip = new AnimInterpolator(srcip->anim);
|
||||||
|
custom->refCount++;
|
||||||
|
dstuvanim->interp[i] = dstip;
|
||||||
|
}
|
||||||
|
}
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,12 +354,13 @@ Animation*
|
||||||
makeDummyAnimation(const char *name)
|
makeDummyAnimation(const char *name)
|
||||||
{
|
{
|
||||||
AnimInterpolatorInfo *interpInfo = findAnimInterpolatorInfo(0x1C0);
|
AnimInterpolatorInfo *interpInfo = findAnimInterpolatorInfo(0x1C0);
|
||||||
Animation *anim = new Animation(interpInfo, 2, 0, 1.0f);
|
Animation *anim = Animation::create(interpInfo, 2, 0, 1.0f);
|
||||||
UVAnimCustomData *custom = (UVAnimCustomData*)anim->customData;
|
UVAnimCustomData *custom = (UVAnimCustomData*)anim->customData;
|
||||||
// UVAnimKeyFrame *frames = (UVAnimKeyFrame*)anim->keyframes;
|
|
||||||
strncpy(custom->name, name, 32);
|
strncpy(custom->name, name, 32);
|
||||||
memset(custom->nodeToUVChannel, 0, sizeof(custom->nodeToUVChannel));
|
memset(custom->nodeToUVChannel, 0, sizeof(custom->nodeToUVChannel));
|
||||||
|
custom->refCount = 1;
|
||||||
// TODO: init the frames
|
// TODO: init the frames
|
||||||
|
// UVAnimKeyFrame *frames = (UVAnimKeyFrame*)anim->keyframes;
|
||||||
return anim;
|
return anim;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -305,9 +378,14 @@ readUVAnim(Stream *stream, int32, void *object, int32 offset, int32)
|
||||||
Animation *anim = NULL;
|
Animation *anim = NULL;
|
||||||
if(currentUVAnimDictionary)
|
if(currentUVAnimDictionary)
|
||||||
anim = currentUVAnimDictionary->find(name);
|
anim = currentUVAnimDictionary->find(name);
|
||||||
if(anim == NULL)
|
if(anim == NULL){
|
||||||
anim = makeDummyAnimation(name);
|
anim = makeDummyAnimation(name);
|
||||||
|
if(currentUVAnimDictionary)
|
||||||
|
currentUVAnimDictionary->add(anim);
|
||||||
|
}
|
||||||
|
UVAnimCustomData *custom = (UVAnimCustomData*)anim->customData;
|
||||||
AnimInterpolator *interp = new AnimInterpolator(anim);
|
AnimInterpolator *interp = new AnimInterpolator(anim);
|
||||||
|
custom->refCount++;
|
||||||
uvanim->interp[i] = interp;
|
uvanim->interp[i] = interp;
|
||||||
}
|
}
|
||||||
bit <<= 1;
|
bit <<= 1;
|
||||||
|
|
|
@ -284,33 +284,6 @@ Clump::destroy(void)
|
||||||
free(this);
|
free(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32
|
|
||||||
Clump::countAtomics(void)
|
|
||||||
{
|
|
||||||
int32 n = 0;
|
|
||||||
FORLIST(l, this->atomics)
|
|
||||||
n++;
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32
|
|
||||||
Clump::countLights(void)
|
|
||||||
{
|
|
||||||
int32 n = 0;
|
|
||||||
FORLIST(l, this->lights)
|
|
||||||
n++;
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32
|
|
||||||
Clump::countCameras(void)
|
|
||||||
{
|
|
||||||
int32 n = 0;
|
|
||||||
FORLIST(l, this->cameras)
|
|
||||||
n++;
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
Clump*
|
Clump*
|
||||||
Clump::streamRead(Stream *stream)
|
Clump::streamRead(Stream *stream)
|
||||||
{
|
{
|
||||||
|
@ -748,9 +721,10 @@ Light::create(int32 type)
|
||||||
assert(light != NULL);
|
assert(light != NULL);
|
||||||
light->object.init(Light::ID, type);
|
light->object.init(Light::ID, type);
|
||||||
light->radius = 0.0f;
|
light->radius = 0.0f;
|
||||||
light->red = 1.0f;
|
light->color.red = 1.0f;
|
||||||
light->green = 1.0f;
|
light->color.green = 1.0f;
|
||||||
light->blue = 1.0f;
|
light->color.blue = 1.0f;
|
||||||
|
light->color.alpha = 1.0f;
|
||||||
light->minusCosAngle = 1.0f;
|
light->minusCosAngle = 1.0f;
|
||||||
light->object.privateFlags = 1;
|
light->object.privateFlags = 1;
|
||||||
light->object.flags = LIGHTATOMICS | LIGHTWORLD;
|
light->object.flags = LIGHTATOMICS | LIGHTWORLD;
|
||||||
|
@ -781,9 +755,9 @@ Light::getAngle(void)
|
||||||
void
|
void
|
||||||
Light::setColor(float32 r, float32 g, float32 b)
|
Light::setColor(float32 r, float32 g, float32 b)
|
||||||
{
|
{
|
||||||
this->red = r;
|
this->color.red = r;
|
||||||
this->green = g;
|
this->color.green = g;
|
||||||
this->blue = b;
|
this->color.blue = b;
|
||||||
this->object.privateFlags = r == g && r == b;
|
this->object.privateFlags = r == g && r == b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -824,9 +798,9 @@ Light::streamWrite(Stream *stream)
|
||||||
writeChunkHeader(stream, ID_LIGHT, this->streamGetSize());
|
writeChunkHeader(stream, ID_LIGHT, this->streamGetSize());
|
||||||
writeChunkHeader(stream, ID_STRUCT, sizeof(LightChunkData));
|
writeChunkHeader(stream, ID_STRUCT, sizeof(LightChunkData));
|
||||||
buf.radius = this->radius;
|
buf.radius = this->radius;
|
||||||
buf.red = this->red;
|
buf.red = this->color.red;
|
||||||
buf.green = this->green;
|
buf.green = this->color.green;
|
||||||
buf.blue = this->blue;
|
buf.blue = this->color.blue;
|
||||||
if(version >= 0x30300)
|
if(version >= 0x30300)
|
||||||
buf.minusCosAngle = this->minusCosAngle;
|
buf.minusCosAngle = this->minusCosAngle;
|
||||||
else
|
else
|
||||||
|
@ -854,6 +828,12 @@ Camera::create(void)
|
||||||
{
|
{
|
||||||
Camera *cam = (Camera*)malloc(PluginBase::s_size);
|
Camera *cam = (Camera*)malloc(PluginBase::s_size);
|
||||||
cam->object.init(Camera::ID, 0);
|
cam->object.init(Camera::ID, 0);
|
||||||
|
cam->viewWindow.set(1.0f, 1.0f);
|
||||||
|
cam->viewOffset.set(0.0f, 0.0f);
|
||||||
|
cam->nearPlane = 0.05f;
|
||||||
|
cam->farPlane = 10.0f;
|
||||||
|
cam->fogPlane = 5.0f;
|
||||||
|
cam->projection = 1;
|
||||||
cam->constructPlugins();
|
cam->constructPlugins();
|
||||||
return cam;
|
return cam;
|
||||||
}
|
}
|
||||||
|
@ -863,6 +843,13 @@ Camera::clone(void)
|
||||||
{
|
{
|
||||||
Camera *cam = Camera::create();
|
Camera *cam = Camera::create();
|
||||||
cam->object.copy(&this->object);
|
cam->object.copy(&this->object);
|
||||||
|
cam->setFrame(this->getFrame());
|
||||||
|
cam->viewWindow = this->viewWindow;
|
||||||
|
cam->viewOffset = this->viewOffset;
|
||||||
|
cam->nearPlane = this->nearPlane;
|
||||||
|
cam->farPlane = this->farPlane;
|
||||||
|
cam->fogPlane = this->fogPlane;
|
||||||
|
cam->projection = this->projection;
|
||||||
cam->copyPlugins(this);
|
cam->copyPlugins(this);
|
||||||
return cam;
|
return cam;
|
||||||
}
|
}
|
||||||
|
@ -878,7 +865,7 @@ struct CameraChunkData
|
||||||
{
|
{
|
||||||
V2d viewWindow;
|
V2d viewWindow;
|
||||||
V2d viewOffset;
|
V2d viewOffset;
|
||||||
float32 nearClip, farClip;
|
float32 nearPlane, farPlane;
|
||||||
float32 fogPlane;
|
float32 fogPlane;
|
||||||
int32 projection;
|
int32 projection;
|
||||||
};
|
};
|
||||||
|
@ -892,8 +879,8 @@ Camera::streamRead(Stream *stream)
|
||||||
Camera *cam = Camera::create();
|
Camera *cam = Camera::create();
|
||||||
cam->viewWindow = buf.viewWindow;
|
cam->viewWindow = buf.viewWindow;
|
||||||
cam->viewOffset = buf.viewOffset;
|
cam->viewOffset = buf.viewOffset;
|
||||||
cam->nearClip = buf.nearClip;
|
cam->nearPlane = buf.nearPlane;
|
||||||
cam->farClip = buf.farClip;
|
cam->farPlane = buf.farPlane;
|
||||||
cam->fogPlane = buf.fogPlane;
|
cam->fogPlane = buf.fogPlane;
|
||||||
cam->projection = buf.projection;
|
cam->projection = buf.projection;
|
||||||
cam->streamReadPlugins(stream);
|
cam->streamReadPlugins(stream);
|
||||||
|
@ -909,8 +896,8 @@ Camera::streamWrite(Stream *stream)
|
||||||
writeChunkHeader(stream, ID_STRUCT, sizeof(CameraChunkData));
|
writeChunkHeader(stream, ID_STRUCT, sizeof(CameraChunkData));
|
||||||
buf.viewWindow = this->viewWindow;
|
buf.viewWindow = this->viewWindow;
|
||||||
buf.viewOffset = this->viewOffset;
|
buf.viewOffset = this->viewOffset;
|
||||||
buf.nearClip = this->nearClip;
|
buf.nearPlane = this->nearPlane;
|
||||||
buf.farClip = this->farClip;
|
buf.farPlane = this->farPlane;
|
||||||
buf.fogPlane = this->fogPlane;
|
buf.fogPlane = this->fogPlane;
|
||||||
buf.projection = this->projection;
|
buf.projection = this->projection;
|
||||||
stream->write(&buf, sizeof(CameraChunkData));
|
stream->write(&buf, sizeof(CameraChunkData));
|
||||||
|
|
|
@ -49,15 +49,6 @@ TexDictionary::destroy(void)
|
||||||
free(this);
|
free(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32
|
|
||||||
TexDictionary::count(void)
|
|
||||||
{
|
|
||||||
int32 n = 0;
|
|
||||||
FORLIST(lnk, this->textures)
|
|
||||||
n++;
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
Texture*
|
Texture*
|
||||||
TexDictionary::find(const char *name)
|
TexDictionary::find(const char *name)
|
||||||
{
|
{
|
||||||
|
@ -151,8 +142,10 @@ Texture::read(const char *name, const char *mask)
|
||||||
Raster *raster = NULL;
|
Raster *raster = NULL;
|
||||||
Texture *tex;
|
Texture *tex;
|
||||||
|
|
||||||
if(currentTexDictionary && (tex = currentTexDictionary->find(name)))
|
if(currentTexDictionary && (tex = currentTexDictionary->find(name))){
|
||||||
|
tex->refCount++;
|
||||||
return tex;
|
return tex;
|
||||||
|
}
|
||||||
tex = Texture::create(NULL);
|
tex = Texture::create(NULL);
|
||||||
strncpy(tex->name, name, 32);
|
strncpy(tex->name, name, 32);
|
||||||
strncpy(tex->mask, mask, 32);
|
strncpy(tex->mask, mask, 32);
|
||||||
|
|
|
@ -8,14 +8,26 @@ struct RGBA
|
||||||
uint8 alpha;
|
uint8 alpha;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct RGBAf
|
||||||
|
{
|
||||||
|
float32 red;
|
||||||
|
float32 green;
|
||||||
|
float32 blue;
|
||||||
|
float32 alpha;
|
||||||
|
};
|
||||||
|
|
||||||
struct V2d
|
struct V2d
|
||||||
{
|
{
|
||||||
float32 x, y;
|
float32 x, y;
|
||||||
|
void set(float32 x, float32 y){
|
||||||
|
this->x = x; this->y = y; }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct V3d
|
struct V3d
|
||||||
{
|
{
|
||||||
float32 x, y, z;
|
float32 x, y, z;
|
||||||
|
void set(float32 x, float32 y, float32 z){
|
||||||
|
this->x = x; this->y = y; this->z = z; }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LLLink
|
struct LLLink
|
||||||
|
@ -35,6 +47,12 @@ struct LLLink
|
||||||
#define LLLinkGetData(linkvar,type,entry) \
|
#define LLLinkGetData(linkvar,type,entry) \
|
||||||
((type*)(((uint8*)(linkvar))-offsetof(type,entry)))
|
((type*)(((uint8*)(linkvar))-offsetof(type,entry)))
|
||||||
|
|
||||||
|
// Have to be careful since the link might be deleted.
|
||||||
|
#define FORLIST(_link, _list) \
|
||||||
|
for(LLLink *_next = NULL, *_link = (_list).link.next; \
|
||||||
|
_next = (_link)->next, (_link) != (_list).end(); \
|
||||||
|
(_link) = _next)
|
||||||
|
|
||||||
struct LinkList
|
struct LinkList
|
||||||
{
|
{
|
||||||
LLLink link;
|
LLLink link;
|
||||||
|
@ -60,14 +78,14 @@ struct LinkList
|
||||||
LLLink *end(void){
|
LLLink *end(void){
|
||||||
return &this->link;
|
return &this->link;
|
||||||
}
|
}
|
||||||
|
int32 count(void){
|
||||||
|
int32 n = 0;
|
||||||
|
FORLIST(lnk, (*this))
|
||||||
|
n++;
|
||||||
|
return n;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Have to be careful since the link might be deleted.
|
|
||||||
#define FORLIST(_link, _list) \
|
|
||||||
for(LLLink *_next = NULL, *_link = (_list).link.next; \
|
|
||||||
_next = (_link)->next, (_link) != (_list).end(); \
|
|
||||||
(_link) = _next)
|
|
||||||
|
|
||||||
struct Object
|
struct Object
|
||||||
{
|
{
|
||||||
uint8 type;
|
uint8 type;
|
||||||
|
@ -544,7 +562,7 @@ struct Light : PluginBase<Light>
|
||||||
enum { ID = 3 };
|
enum { ID = 3 };
|
||||||
ObjectWithFrame object;
|
ObjectWithFrame object;
|
||||||
float32 radius;
|
float32 radius;
|
||||||
float32 red, green, blue;
|
RGBAf color;
|
||||||
float32 minusCosAngle;
|
float32 minusCosAngle;
|
||||||
|
|
||||||
// clump link handled by plugin in RW
|
// clump link handled by plugin in RW
|
||||||
|
@ -560,6 +578,7 @@ struct Light : PluginBase<Light>
|
||||||
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);
|
||||||
|
int32 getType(void){ return this->object.subType; }
|
||||||
static Light *streamRead(Stream *stream);
|
static Light *streamRead(Stream *stream);
|
||||||
bool streamWrite(Stream *stream);
|
bool streamWrite(Stream *stream);
|
||||||
uint32 streamGetSize(void);
|
uint32 streamGetSize(void);
|
||||||
|
@ -583,7 +602,7 @@ struct Camera : PluginBase<Camera>
|
||||||
ObjectWithFrame object;
|
ObjectWithFrame object;
|
||||||
V2d viewWindow;
|
V2d viewWindow;
|
||||||
V2d viewOffset;
|
V2d viewOffset;
|
||||||
float32 nearClip, farClip;
|
float32 nearPlane, farPlane;
|
||||||
float32 fogPlane;
|
float32 fogPlane;
|
||||||
int32 projection;
|
int32 projection;
|
||||||
|
|
||||||
|
@ -605,7 +624,7 @@ struct Camera : PluginBase<Camera>
|
||||||
struct Clump : PluginBase<Clump>
|
struct Clump : PluginBase<Clump>
|
||||||
{
|
{
|
||||||
enum { ID = 2 };
|
enum { ID = 2 };
|
||||||
ObjectWithFrame object;
|
Object object;
|
||||||
LinkList atomics;
|
LinkList atomics;
|
||||||
LinkList lights;
|
LinkList lights;
|
||||||
LinkList cameras;
|
LinkList cameras;
|
||||||
|
@ -613,17 +632,17 @@ struct Clump : PluginBase<Clump>
|
||||||
static Clump *create(void);
|
static Clump *create(void);
|
||||||
Clump *clone(void);
|
Clump *clone(void);
|
||||||
void destroy(void);
|
void destroy(void);
|
||||||
int32 countAtomics(void);
|
int32 countAtomics(void) { return this->atomics.count(); }
|
||||||
void addAtomic(Atomic *a){
|
void addAtomic(Atomic *a){
|
||||||
a->clump = this;
|
a->clump = this;
|
||||||
this->atomics.append(&a->inClump);
|
this->atomics.append(&a->inClump);
|
||||||
}
|
}
|
||||||
int32 countLights(void);
|
int32 countLights(void) { return this->lights.count(); }
|
||||||
void addLight(Light *l){
|
void addLight(Light *l){
|
||||||
l->clump = this;
|
l->clump = this;
|
||||||
this->lights.append(&l->inClump);
|
this->lights.append(&l->inClump);
|
||||||
}
|
}
|
||||||
int32 countCameras(void);
|
int32 countCameras(void) { return this->cameras.count(); }
|
||||||
void addCamera(Camera *c){
|
void addCamera(Camera *c){
|
||||||
c->clump = this;
|
c->clump = this;
|
||||||
this->cameras.append(&c->inClump);
|
this->cameras.append(&c->inClump);
|
||||||
|
@ -648,7 +667,7 @@ struct TexDictionary : PluginBase<TexDictionary>
|
||||||
|
|
||||||
static TexDictionary *create(void);
|
static TexDictionary *create(void);
|
||||||
void destroy(void);
|
void destroy(void);
|
||||||
int32 count(void);
|
int32 count(void) { return this->textures.count(); }
|
||||||
void add(Texture *t){
|
void add(Texture *t){
|
||||||
t->dict = this;
|
t->dict = this;
|
||||||
this->textures.append(&t->inDict);
|
this->textures.append(&t->inDict);
|
||||||
|
@ -685,7 +704,8 @@ struct Animation
|
||||||
void *keyframes;
|
void *keyframes;
|
||||||
void *customData;
|
void *customData;
|
||||||
|
|
||||||
Animation(AnimInterpolatorInfo*, int32 numFrames, int32 flags, float duration);
|
static Animation *create(AnimInterpolatorInfo*, int32 numFrames, int32 flags, float duration);
|
||||||
|
void destroy(void);
|
||||||
static Animation *streamRead(Stream *stream);
|
static Animation *streamRead(Stream *stream);
|
||||||
static Animation *streamReadLegacy(Stream *stream);
|
static Animation *streamReadLegacy(Stream *stream);
|
||||||
bool streamWrite(Stream *stream);
|
bool streamWrite(Stream *stream);
|
||||||
|
@ -708,23 +728,43 @@ struct UVAnimKeyFrame
|
||||||
float uv[6];
|
float uv[6];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct UVAnimDictionary;
|
||||||
|
|
||||||
|
// RW does it differently...maybe we should implement RtDict
|
||||||
|
// and make it more general?
|
||||||
|
|
||||||
struct UVAnimCustomData
|
struct UVAnimCustomData
|
||||||
{
|
{
|
||||||
char name[32];
|
char name[32];
|
||||||
int32 nodeToUVChannel[8];
|
int32 nodeToUVChannel[8];
|
||||||
// RW has a refcount
|
int32 refCount;
|
||||||
|
|
||||||
|
void destroy(Animation *anim);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// This should be more general probably
|
||||||
|
struct UVAnimDictEntry
|
||||||
|
{
|
||||||
|
Animation *anim;
|
||||||
|
LLLink inDict;
|
||||||
|
static UVAnimDictEntry *fromDict(LLLink *lnk){
|
||||||
|
return LLLinkGetData(lnk, UVAnimDictEntry, inDict); }
|
||||||
|
};
|
||||||
|
|
||||||
|
// This too
|
||||||
struct UVAnimDictionary
|
struct UVAnimDictionary
|
||||||
{
|
{
|
||||||
// TODO: linked list probably
|
LinkList animations;
|
||||||
int32 numAnims;
|
|
||||||
Animation **anims;
|
static UVAnimDictionary *create(void);
|
||||||
|
void destroy(void);
|
||||||
|
int32 count(void) { return this->animations.count(); }
|
||||||
|
void add(Animation *anim);
|
||||||
|
Animation *find(const char *name);
|
||||||
|
|
||||||
static UVAnimDictionary *streamRead(Stream *stream);
|
static UVAnimDictionary *streamRead(Stream *stream);
|
||||||
bool streamWrite(Stream *stream);
|
bool streamWrite(Stream *stream);
|
||||||
uint32 streamGetSize(void);
|
uint32 streamGetSize(void);
|
||||||
Animation *find(const char *name);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern UVAnimDictionary *currentUVAnimDictionary;
|
extern UVAnimDictionary *currentUVAnimDictionary;
|
||||||
|
|
|
@ -97,6 +97,8 @@ main(int argc, char *argv[])
|
||||||
//in.open(data, len);
|
//in.open(data, len);
|
||||||
StreamFile in;
|
StreamFile in;
|
||||||
in.open(argv[0], "rb");
|
in.open(argv[0], "rb");
|
||||||
|
currentUVAnimDictionary = NULL;
|
||||||
|
currentTexDictionary = TexDictionary::create();
|
||||||
ChunkHeaderInfo header;
|
ChunkHeaderInfo header;
|
||||||
readChunkHeaderInfo(&in, &header);
|
readChunkHeaderInfo(&in, &header);
|
||||||
if(header.type == ID_UVANIMDICT){
|
if(header.type == ID_UVANIMDICT){
|
||||||
|
@ -124,6 +126,11 @@ main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
//FORLIST(lnk, c->lights){
|
||||||
|
// Light *l = Light::fromClump(lnk);
|
||||||
|
// printf("%p %p\n", l, lnk);
|
||||||
|
// printf("%d %f %f %f\n", l->getType(), l->color.red, l->color.green, l->color.blue);
|
||||||
|
//}
|
||||||
|
|
||||||
int32 platform = findPlatform(c);
|
int32 platform = findPlatform(c);
|
||||||
if(platform){
|
if(platform){
|
||||||
|
@ -185,6 +192,9 @@ main(int argc, char *argv[])
|
||||||
// out.close();
|
// out.close();
|
||||||
// delete[] data;
|
// delete[] data;
|
||||||
|
|
||||||
|
if(currentUVAnimDictionary)
|
||||||
|
currentUVAnimDictionary->destroy();
|
||||||
|
//currentTexDictionary->destroy();
|
||||||
c->destroy();
|
c->destroy();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -105,7 +105,7 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug - null|x64'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug - null|x64'">
|
||||||
<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);$(SolutionDir)</IncludePath>
|
<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);$(SolutionDir)</IncludePath>
|
||||||
<LibraryPath>$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(SolutionDir)$(Configuration)</LibraryPath>
|
<LibraryPath>$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(SolutionDir)$(Platform)\$(Configuration);$(LibraryPath)</LibraryPath>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);$(SolutionDir)</IncludePath>
|
<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);$(SolutionDir)</IncludePath>
|
||||||
|
@ -161,7 +161,7 @@
|
||||||
<Optimization>Disabled</Optimization>
|
<Optimization>Disabled</Optimization>
|
||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
|
Loading…
Reference in New Issue