2011-08-03 20:05:33 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2007, 2010 - Bit-Blot
|
|
|
|
|
|
|
|
This file is part of Aquaria.
|
|
|
|
|
|
|
|
Aquaria is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
2012-09-23 02:51:13 +00:00
|
|
|
#ifndef SKELETALSPRITE_H
|
|
|
|
#define SKELETALSPRITE_H
|
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
#include "Quad.h"
|
|
|
|
#include "SimpleIStringStream.h"
|
2021-01-11 23:26:44 +00:00
|
|
|
#include <map>
|
2011-08-03 20:05:33 +00:00
|
|
|
// for 2d system only
|
|
|
|
|
|
|
|
enum AnimationCommand
|
|
|
|
{
|
|
|
|
AC_PRT_LOAD =0,
|
|
|
|
AC_PRT_START ,
|
|
|
|
AC_PRT_STOP ,
|
|
|
|
AC_SEGS_START ,
|
|
|
|
AC_FRM_SHOW ,
|
|
|
|
AC_SND_PLAY ,
|
2016-04-17 12:33:23 +00:00
|
|
|
AC_SEGS_STOP,
|
|
|
|
AC_SET_PASS,
|
2017-01-20 03:51:38 +00:00
|
|
|
AC_RESET_PASS
|
2011-08-03 20:05:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ParticleEffect;
|
|
|
|
class SkeletalSprite;
|
|
|
|
|
Script interface improvements & extensions.
- Pointer typechecks are now enabled by default.
- enabled all script warnings for non-FULL or DEMO builds by default
- Added generic obj_* functions that operate on any type of RenderObject.
These give quite low-level control about the renderer, and are quite
dangerous too.
Subsequently, many functions sharing the same code (*_setPosition, for example)
could be removed, and simply call the generic functions after a type check.
- Added interface function deathNotify(). The original logic of death
notifiers was never used, so i thought i'd make use of it.
This is useful in scripts to safely drop dangling pointers.
- removed sendEntityMessage, entity_setCollideWithAvatar, entity_setTouchDamage,
which were essentially no-ops.
- Replaced all unnecessary luaReturnNum(0) and luaReturnInt(0),
now it does only push a return value on the stack if the function
is actually supposed to have a retun value.
- Allow variadic calling of entity_msg(). Now any parameters can be passed
to the function, and the target entity will receive all of them.
Any values returned from the entity's msg() callback will be returned
by entity_msg() to the original caller. This allows nice RPC-like
entity communication.
- fixed possible crash in debugLog, bone_update, entity_debugText
- added an override function for loadfile() that is case-insensitive like dofile()
- entity_createEntity returns the created entity now
- spawnParticleEffect returns the associated RenderObject
- Added some text rendering functions
- Added beam_setFirer()
- removed the underflow check in avatar_decrLeaches() I added earlier
- added a panic function for Lua.
- added the Lua debug library
- fixed a stupid typo in ScriptObject::isType() that made the type checks a lot less accurate
- misc stuff I forgot
2012-02-05 19:22:54 +00:00
|
|
|
class Bone : public Quad
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2016-07-09 02:18:40 +00:00
|
|
|
friend class SkeletalSprite;
|
2011-08-03 20:05:33 +00:00
|
|
|
public:
|
|
|
|
Bone();
|
|
|
|
void setAnimated(int a);
|
|
|
|
|
|
|
|
enum {
|
|
|
|
ANIM_NONE = 0,
|
|
|
|
ANIM_POS = 1,
|
|
|
|
ANIM_ROT = 2,
|
|
|
|
ANIM_ALL = 10
|
|
|
|
};
|
|
|
|
void createStrip(bool vert, int num);
|
|
|
|
Quad* addFrame(const std::string &gfx);
|
|
|
|
void showFrame(int i);
|
|
|
|
void destroy();
|
|
|
|
std::string gfx;
|
|
|
|
std::string name;
|
2017-01-14 17:10:20 +00:00
|
|
|
size_t boneIdx;
|
2017-01-14 17:10:20 +00:00
|
|
|
int pidx, rbp;
|
2011-08-03 20:05:33 +00:00
|
|
|
std::string prt;
|
|
|
|
std::vector<Vector> changeStrip;
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
bool generateCollisionMask;
|
|
|
|
int animated;
|
|
|
|
Vector originalScale;
|
|
|
|
|
|
|
|
void addSegment(Bone *b);
|
2016-07-09 02:18:40 +00:00
|
|
|
ParticleEffect *getEmitter(unsigned slot) const;
|
2011-08-03 20:05:33 +00:00
|
|
|
|
|
|
|
int segmentChain;
|
|
|
|
|
|
|
|
void updateSegments();
|
|
|
|
void updateSegment(Bone *b, const Vector &diff);
|
|
|
|
|
|
|
|
SkeletalSprite *skeleton;
|
|
|
|
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
void setSegmentProps(int minDist, int maxDist, bool reverse);
|
|
|
|
Vector segmentOffset;
|
|
|
|
|
|
|
|
bool fileRenderQuad;
|
2016-04-18 20:08:36 +00:00
|
|
|
bool selectable;
|
2016-04-17 12:33:23 +00:00
|
|
|
int originalRenderPass; // stores the render pass originally set in the XML file. For AC_RESET_PASS.
|
2011-08-03 20:05:33 +00:00
|
|
|
|
|
|
|
protected:
|
2016-07-09 02:18:40 +00:00
|
|
|
std::vector<ParticleEffect*> emitters;
|
2011-08-03 20:05:33 +00:00
|
|
|
int minDist, maxDist, reverse;
|
|
|
|
std::vector<Bone*> segments;
|
|
|
|
};
|
|
|
|
|
|
|
|
class BoneCommand
|
|
|
|
{
|
|
|
|
public:
|
2016-04-17 13:16:55 +00:00
|
|
|
bool parse(Bone *b, SimpleIStringStream &is);
|
2011-08-03 20:05:33 +00:00
|
|
|
void run();
|
|
|
|
AnimationCommand command;
|
|
|
|
Bone *b;
|
|
|
|
|
|
|
|
int slot;
|
|
|
|
std::string file;
|
|
|
|
};
|
|
|
|
|
|
|
|
class BoneKeyframe
|
|
|
|
{
|
|
|
|
public:
|
2017-01-12 21:51:46 +00:00
|
|
|
BoneKeyframe() : idx(0), x(0), y(0), rot(0), sx(1), sy(1), doScale(0) {}
|
2017-01-14 17:10:20 +00:00
|
|
|
size_t idx;
|
|
|
|
int x, y, rot;
|
2011-08-03 20:05:33 +00:00
|
|
|
float sx, sy;
|
|
|
|
bool doScale;
|
|
|
|
std::vector<Vector> strip;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SkeletalKeyframe
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SkeletalKeyframe()
|
|
|
|
{
|
|
|
|
lerpType = 0;
|
|
|
|
t = 0;
|
|
|
|
}
|
|
|
|
int lerpType;
|
|
|
|
float t;
|
|
|
|
std::string sound;
|
|
|
|
std::vector<BoneKeyframe> keyframes;
|
2017-01-14 17:10:20 +00:00
|
|
|
BoneKeyframe *getBoneKeyframe(size_t idx);
|
2011-08-03 20:05:33 +00:00
|
|
|
std::string cmd;
|
|
|
|
std::vector<BoneCommand> commands;
|
|
|
|
|
|
|
|
void copyAllButTime(SkeletalKeyframe *copy);
|
|
|
|
};
|
|
|
|
|
|
|
|
class Animation
|
|
|
|
{
|
|
|
|
public:
|
2016-04-17 12:33:23 +00:00
|
|
|
Animation();
|
2011-08-03 20:05:33 +00:00
|
|
|
std::string name;
|
|
|
|
typedef std::vector <SkeletalKeyframe> Keyframes;
|
|
|
|
Keyframes keyframes;
|
2017-01-14 17:10:20 +00:00
|
|
|
SkeletalKeyframe *getKeyframe(size_t key);
|
2011-08-03 20:05:33 +00:00
|
|
|
SkeletalKeyframe *getLastKeyframe();
|
|
|
|
SkeletalKeyframe *getFirstKeyframe();
|
|
|
|
SkeletalKeyframe *getPrevKeyframe(float t);
|
2016-05-05 17:40:28 +00:00
|
|
|
SkeletalKeyframe *getNextKeyframe(float t);
|
2017-01-14 17:10:20 +00:00
|
|
|
void cloneKey(size_t key, float toffset);
|
|
|
|
void deleteKey(size_t key);
|
2011-08-03 20:05:33 +00:00
|
|
|
void reorderKeyframes();
|
|
|
|
float getAnimationLength();
|
2017-01-14 17:10:20 +00:00
|
|
|
size_t getSkeletalKeyframeIndex(SkeletalKeyframe *skey);
|
|
|
|
size_t getNumKeyframes();
|
2011-08-03 20:05:33 +00:00
|
|
|
void reverse();
|
2016-04-17 12:33:23 +00:00
|
|
|
bool resetPassOnEnd;
|
2011-08-03 20:05:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SkeletalSprite;
|
|
|
|
|
|
|
|
class AnimationLayer
|
|
|
|
{
|
|
|
|
public:
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
//----
|
|
|
|
AnimationLayer();
|
2016-05-05 17:40:28 +00:00
|
|
|
void setSkeletalSprite(SkeletalSprite *s);
|
2011-08-03 20:05:33 +00:00
|
|
|
Animation *getCurrentAnimation();
|
|
|
|
void animate(const std::string &animation, int loop);
|
|
|
|
void update(float dt);
|
|
|
|
void updateBones();
|
|
|
|
void stopAnimation();
|
|
|
|
float getAnimationLength();
|
2013-02-03 15:13:07 +00:00
|
|
|
bool createTransitionAnimation(const std::string& anim, float time);
|
2011-08-03 20:05:33 +00:00
|
|
|
void playAnimation(int idx, int loop);
|
|
|
|
void playCurrentAnimation(int loop);
|
2013-02-03 15:13:07 +00:00
|
|
|
void enqueueAnimation(const std::string& anim, int loop);
|
2011-08-03 20:05:33 +00:00
|
|
|
float transitionAnimate(std::string anim, float time, int loop);
|
|
|
|
void setTimeMultiplier(float t);
|
|
|
|
bool isAnimating();
|
2016-04-17 12:33:23 +00:00
|
|
|
bool contains(const Bone *b) const;
|
|
|
|
void resetPass();
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
//----
|
|
|
|
float fallThru;
|
|
|
|
float fallThruSpeed;
|
|
|
|
std::string name;
|
|
|
|
std::vector<int> ignoreBones;
|
|
|
|
std::vector<int> includeBones;
|
|
|
|
SkeletalSprite *s;
|
|
|
|
|
|
|
|
SkeletalKeyframe *lastNewKey;
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
float timer;
|
|
|
|
int loop;
|
|
|
|
Animation blendAnimation;
|
|
|
|
std::string enqueuedAnimation;
|
|
|
|
int enqueuedAnimationLoop;
|
|
|
|
//float timeMultiplier;
|
|
|
|
//HACK: should be a lerped float
|
|
|
|
InterpolatedVector timeMultiplier;
|
|
|
|
float animationLength;
|
2017-01-14 17:10:20 +00:00
|
|
|
size_t currentAnimation;
|
2011-08-03 20:05:33 +00:00
|
|
|
bool animating;
|
|
|
|
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SkeletalSprite : public RenderObject
|
|
|
|
{
|
|
|
|
public:
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
SkeletalSprite();
|
|
|
|
void loadSkeletal(const std::string &fn);
|
2013-12-28 03:42:02 +00:00
|
|
|
bool saveSkeletal(const std::string &fn);
|
2011-08-03 20:05:33 +00:00
|
|
|
void loadSkin(const std::string &fn);
|
|
|
|
|
2017-01-14 17:10:20 +00:00
|
|
|
Bone *getBoneByIdx(size_t idx);
|
2011-08-03 20:05:33 +00:00
|
|
|
Bone *getBoneByName(const std::string &name);
|
|
|
|
void animate(const std::string &animation, int loop = 0, int layer=0);
|
|
|
|
|
2016-05-05 17:40:28 +00:00
|
|
|
|
|
|
|
|
2017-01-14 17:10:20 +00:00
|
|
|
void setTime(float time, size_t layer=0);
|
2011-08-03 20:05:33 +00:00
|
|
|
|
|
|
|
void updateBones();
|
|
|
|
void playCurrentAnimation(int loop=0, int layer=0);
|
|
|
|
void stopAnimation(int layer=0);
|
|
|
|
void stopAllAnimations();
|
|
|
|
|
2012-03-13 23:58:59 +00:00
|
|
|
float transitionAnimate(const std::string& anim, float time, int loop=0, int layer=0);
|
2011-08-03 20:05:33 +00:00
|
|
|
|
|
|
|
bool isAnimating(int layer=0);
|
|
|
|
|
2016-05-05 17:40:28 +00:00
|
|
|
void setTimeMultiplier(float t, int layer=0);
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2012-01-31 17:02:18 +00:00
|
|
|
Bone* getSelectedBone(bool mouseBased = true);
|
2017-01-14 17:10:20 +00:00
|
|
|
Animation *getCurrentAnimation(size_t layer=0);
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
void nextAnimation();
|
|
|
|
void prevAnimation();
|
|
|
|
void lastAnimation();
|
|
|
|
void firstAnimation();
|
|
|
|
void updateSelectedBoneColor();
|
|
|
|
|
|
|
|
|
|
|
|
void setFreeze(bool f);
|
2016-05-05 17:40:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-03 15:13:07 +00:00
|
|
|
Animation *getAnimation(const std::string& anim);
|
2011-08-03 20:05:33 +00:00
|
|
|
|
|
|
|
std::vector<Animation> animations;
|
|
|
|
std::vector<Bone*> bones;
|
|
|
|
|
2017-01-20 03:51:38 +00:00
|
|
|
inline size_t getSelectedBoneIdx(void) { return selectedBone; }
|
2011-08-03 20:05:33 +00:00
|
|
|
void setSelectedBone(int b);
|
|
|
|
void selectPrevBone();
|
|
|
|
void selectNextBone();
|
|
|
|
|
|
|
|
bool isLoaded();
|
2017-01-20 03:51:38 +00:00
|
|
|
size_t getNumAnimLayers() const { return animLayers.size(); }
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2017-01-14 17:10:20 +00:00
|
|
|
AnimationLayer* getAnimationLayer(size_t l);
|
|
|
|
size_t getBoneIdx(Bone *b);
|
|
|
|
void toggleBone(size_t idx, int v);
|
2011-08-03 20:05:33 +00:00
|
|
|
|
|
|
|
void setAnimationKeyNotify(RenderObject *r);
|
|
|
|
|
|
|
|
std::string filenameLoaded;
|
|
|
|
|
|
|
|
static std::string animationPath, skinPath, secondaryAnimationPath;
|
2012-02-19 03:57:04 +00:00
|
|
|
static void clearCache();
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
protected:
|
|
|
|
bool frozen;
|
|
|
|
RenderObject *animKeyNotify;
|
|
|
|
bool loaded;
|
2017-01-14 17:10:20 +00:00
|
|
|
size_t selectedBone;
|
2011-08-03 20:05:33 +00:00
|
|
|
friend class AnimationLayer;
|
|
|
|
std::vector<AnimationLayer> animLayers;
|
2017-01-19 22:44:30 +00:00
|
|
|
Bone* initBone(int idx, std::string gfx, int pidx, bool rbp=false, std::string name="", float cr=0, bool fh=false, bool fv=false);
|
2011-08-03 20:05:33 +00:00
|
|
|
void deleteBones();
|
|
|
|
void onUpdate(float dt);
|
|
|
|
};
|
|
|
|
|
2012-09-23 02:51:13 +00:00
|
|
|
#endif
|