1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2024-11-29 03:33:48 +00:00

add AC_SET_FH bone command; rework bone frames; some skel cleanups

- bone frames are no longer separate quads. this is probably a leftover
  from when crossfading was planned, but this was never implemented.
  now it's a simple texture swap.
- remove anim resetPassOnEnd attrib
- instead, add resetOnEnd that applies to everything that was changed via bone command
- resetOnEnd=true is the new default
This commit is contained in:
fgenesis 2023-12-21 06:04:09 +01:00
parent cd91ee51ef
commit cf2dc71a34
2 changed files with 46 additions and 72 deletions

View file

@ -137,51 +137,16 @@ void Bone::createStrip(bool vert, int num)
} }
Quad* Bone::addFrame(const std::string &gfx) void Bone::addFrame(const std::string &gfx)
{ {
renderQuad = false; framegfx.push_back(gfx);
Quad *q = new Quad();
q->setTexture(gfx);
q->renderBeforeParent = 1;
addChild(q, PM_POINTER);
return q;
} }
void Bone::showFrame(int idx) void Bone::showFrame(int idx)
{ {
size_t i = idx;
int c = 0; if(i < framegfx.size())
for (Children::iterator i = children.begin(); i != children.end(); i++) setTexture(framegfx[i]);
{
RenderObject *r = (*i);
if (idx == c)
{
if (r->alpha == 0)
{
r->alpha = 1;
// add option to turn on alpha fading
//r->alpha.interpolateTo(1, t);
}
else
{
r->alpha = 1;
}
}
else
{
if (r->alpha == 1)
{
r->alpha = 0;
//r->alpha.interpolateTo(0, t*2);
}
else
{
r->alpha = 0;
}
}
c++;
}
} }
@ -391,6 +356,11 @@ bool BoneCommand::parse(Bone *b, SimpleIStringStream &is)
} }
else if(type == "AC_RESET_PASS") else if(type == "AC_RESET_PASS")
command = AC_RESET_PASS; command = AC_RESET_PASS;
else if(type == "AC_SET_FH")
{
command = AC_SET_FH;
is >> slot;
}
else // fail else // fail
{ {
std::ostringstream os; std::ostringstream os;
@ -445,6 +415,19 @@ void BoneCommand::run()
case AC_RESET_PASS: case AC_RESET_PASS:
b->setRenderPass(b->originalRenderPass); b->setRenderPass(b->originalRenderPass);
break; break;
case AC_SET_FH:
{
bool should = false;
switch(slot)
{
case 0: should = b->originalFH; break;
case 1: should = !b->originalFH; break;
case 2: should = true; break;
default: should = false; break;
}
b->fhTo(should);
break;
}
case AC_SEGS_START: case AC_SEGS_START:
case AC_SEGS_STOP: case AC_SEGS_STOP:
break; break;
@ -605,7 +588,7 @@ void AnimationLayer::createTransitionAnimation(Animation& to, float time)
void AnimationLayer::stopAnimation() void AnimationLayer::stopAnimation()
{ {
if(s->loaded && getCurrentAnimation()->resetPassOnEnd) if(s->loaded && getCurrentAnimation()->resetOnEnd)
resetPass(); resetPass();
animating = false; animating = false;
if (!enqueuedAnimation.empty()) if (!enqueuedAnimation.empty())
@ -627,7 +610,7 @@ float AnimationLayer::getAnimationLength()
} }
Animation::Animation() Animation::Animation()
: resetPassOnEnd(false) : resetOnEnd(true)
{ {
} }
@ -980,7 +963,7 @@ bool SkeletalSprite::saveSkeletal(const std::string &fn)
bone->SetAttribute("gfx", this->bones[i]->gfx.c_str()); bone->SetAttribute("gfx", this->bones[i]->gfx.c_str());
bone->SetAttribute("pidx", this->bones[i]->pidx); bone->SetAttribute("pidx", this->bones[i]->pidx);
bone->SetAttribute("name", this->bones[i]->name.c_str()); bone->SetAttribute("name", this->bones[i]->name.c_str());
bone->SetAttribute("fh", this->bones[i]->isfh()); bone->SetAttribute("fh", this->bones[i]->originalFH);
bone->SetAttribute("fv", this->bones[i]->isfv()); bone->SetAttribute("fv", this->bones[i]->isfv());
bone->SetAttribute("gc", this->bones[i]->generateCollisionMask); bone->SetAttribute("gc", this->bones[i]->generateCollisionMask);
bone->SetAttribute("cr", this->bones[i]->collideRadius); bone->SetAttribute("cr", this->bones[i]->collideRadius);
@ -1039,21 +1022,11 @@ bool SkeletalSprite::saveSkeletal(const std::string &fn)
} }
for (Children::iterator j = this->bones[i]->children.begin(); j != this->bones[i]->children.end(); j++) for(size_t j = 0; j < this->bones[i]->framegfx.size(); ++j)
{ {
Bone *b = dynamic_cast<Bone*>(*j); XMLElement *frame = xml->NewElement("Frame");
Quad *q = dynamic_cast<Quad*>(*j); frame->SetAttribute("gfx", this->bones[i]->framegfx[j].c_str());
Particle *p = dynamic_cast<Particle*>(*j); bone->InsertEndChild(frame);
if (q && !b && !p)
{
XMLElement *frame = xml->NewElement("Frame");
frame->SetAttribute("gfx", q->texture->name.c_str());
if (q->getRenderPass() != 0)
{
frame->SetAttribute("pass", q->getRenderPass());
}
bone->InsertEndChild(frame);
}
} }
bones->InsertEndChild(bone); bones->InsertEndChild(bone);
} }
@ -1065,8 +1038,8 @@ bool SkeletalSprite::saveSkeletal(const std::string &fn)
Animation *a = &this->animations[i]; Animation *a = &this->animations[i];
XMLElement *animation = xml->NewElement("Animation"); XMLElement *animation = xml->NewElement("Animation");
animation->SetAttribute("name", a->name.c_str()); animation->SetAttribute("name", a->name.c_str());
if(a->resetPassOnEnd) if(!a->resetOnEnd)
animation->SetAttribute("resetPassOnEnd", a->resetPassOnEnd); animation->SetAttribute("resetOnEnd", a->resetOnEnd);
for (size_t j = 0; j < a->interpolators.size(); ++j) for (size_t j = 0; j < a->interpolators.size(); ++j)
{ {
@ -1205,6 +1178,7 @@ Bone *SkeletalSprite::initBone(int idx, std::string gfx, int pidx, bool rbp, std
b->pidx = pidx; b->pidx = pidx;
b->collideRadius = cr; b->collideRadius = cr;
b->name = name; b->name = name;
b->originalFH = fh;
if (fh) if (fh)
b->flipHorizontal(); b->flipHorizontal();
@ -1491,19 +1465,11 @@ void SkeletalSprite::loadSkeletal(const std::string &fn)
int frc=0; int frc=0;
while(fr) while(fr)
{ {
Quad *q=0;
std::string gfx; std::string gfx;
if (fr->Attribute("gfx")) if (fr->Attribute("gfx"))
{ {
gfx = fr->Attribute("gfx"); gfx = fr->Attribute("gfx");
q = newb->addFrame(gfx); newb->addFrame(gfx);
}
if (fr->Attribute("pass"))
{
if (q)
{
q->setRenderPass(atoi(fr->Attribute("pass")));
}
} }
fr = fr->NextSiblingElement("Frame"); fr = fr->NextSiblingElement("Frame");
frc++; frc++;
@ -1697,7 +1663,8 @@ void SkeletalSprite::loadSkeletal(const std::string &fn)
{ {
Animation newAnimation; Animation newAnimation;
newAnimation.name = animation->Attribute("name"); newAnimation.name = animation->Attribute("name");
newAnimation.resetPassOnEnd = animation->BoolAttribute("resetPassOnEnd"); if(animation->Attribute("resetOnEnd"))
newAnimation.resetOnEnd = animation->BoolAttribute("resetOnEnd");
stringToLower(newAnimation.name); stringToLower(newAnimation.name);
XMLElement *key = animation->FirstChildElement("Key"); XMLElement *key = animation->FirstChildElement("Key");
@ -1951,7 +1918,10 @@ void AnimationLayer::resetPass()
{ {
Bone *b = s->bones[i]; Bone *b = s->bones[i];
if (contains(b)) if (contains(b))
{
b->setRenderPass(b->originalRenderPass); b->setRenderPass(b->originalRenderPass);
b->fhTo(b->originalFH);
}
} }
} }

View file

@ -37,7 +37,8 @@ enum AnimationCommand
AC_SND_PLAY , AC_SND_PLAY ,
AC_SEGS_STOP, AC_SEGS_STOP,
AC_SET_PASS, AC_SET_PASS,
AC_RESET_PASS AC_RESET_PASS,
AC_SET_FH
}; };
class ParticleEffect; class ParticleEffect;
@ -58,7 +59,7 @@ public:
ANIM_ALL = ANIM_POS | ANIM_ROT ANIM_ALL = ANIM_POS | ANIM_ROT
}; };
void createStrip(bool vert, int num); void createStrip(bool vert, int num);
Quad* addFrame(const std::string &gfx); void addFrame(const std::string &gfx);
void showFrame(int i); void showFrame(int i);
void destroy() OVERRIDE; void destroy() OVERRIDE;
std::string gfx; std::string gfx;
@ -93,6 +94,7 @@ public:
bool fileRenderQuad; bool fileRenderQuad;
bool selectable; bool selectable;
int originalRenderPass; // stores the render pass originally set in the XML file. For AC_RESET_PASS. int originalRenderPass; // stores the render pass originally set in the XML file. For AC_RESET_PASS.
bool originalFH;
void spawnParticlesFromCollisionMask(const char *p, unsigned intv, int layer, float rotz = 0); void spawnParticlesFromCollisionMask(const char *p, unsigned intv, int layer, float rotz = 0);
Vector getCollisionMaskNormal(Vector pos, float dist) const; Vector getCollisionMaskNormal(Vector pos, float dist) const;
@ -107,6 +109,8 @@ public:
std::vector<Vector> collisionMask; std::vector<Vector> collisionMask;
std::vector<Vector> transformedCollisionMask; std::vector<Vector> transformedCollisionMask;
float collisionMaskRadius; float collisionMaskRadius;
std::vector<std::string> framegfx;
}; };
class BoneCommand class BoneCommand
@ -181,7 +185,7 @@ public:
size_t getSkeletalKeyframeIndex(SkeletalKeyframe *skey); size_t getSkeletalKeyframeIndex(SkeletalKeyframe *skey);
size_t getNumKeyframes(); size_t getNumKeyframes();
void reverse(); void reverse();
bool resetPassOnEnd; bool resetOnEnd;
BoneGridInterpolator *getBoneGridInterpolator(size_t boneIdx); BoneGridInterpolator *getBoneGridInterpolator(size_t boneIdx);
typedef std::vector <BoneGridInterpolator> Interpolators; typedef std::vector <BoneGridInterpolator> Interpolators;