From d97bb25b9e57f278598d15d384b493d7320185cd Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sat, 19 Oct 2013 17:30:42 +0200 Subject: [PATCH 1/3] Add some Lua functions, changes to hair. + beam_getEndPos() + entity_setCurrentHealth() + entity_setMaxHealth() + beam_getEndPos() + entity_hasAnimation() - Add 3 new parameters to entity_damage: shot, hitX, hitY - entity_getAnimationLength() supports string as 2nd parameter now. This will lookup an animation's length via name. Passing an ANIMLAYER_* constant works as it used to. --- Aquaria/Entity.cpp | 2 +- Aquaria/Hair.cpp | 15 +----------- Aquaria/Hair.h | 8 ++---- Aquaria/ScriptInterface.cpp | 49 ++++++++++++++++++++++++++++++++++--- 4 files changed, 50 insertions(+), 24 deletions(-) diff --git a/Aquaria/Entity.cpp b/Aquaria/Entity.cpp index fbfcb89..e9e180e 100644 --- a/Aquaria/Entity.cpp +++ b/Aquaria/Entity.cpp @@ -3107,7 +3107,7 @@ bool Entity::doCollisionAvoidance(float dt, int search, float mod, Vector *vp, i return false; } -void Entity::initHair(int numSegments, int segmentLength, int width, const std::string &tex) +void Entity::initHair(int numSegments, float segmentLength, float width, const std::string &tex) { if (hair) { diff --git a/Aquaria/Hair.cpp b/Aquaria/Hair.cpp index 80cc0f0..09f5177 100644 --- a/Aquaria/Hair.cpp +++ b/Aquaria/Hair.cpp @@ -25,13 +25,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // nodes = 40 // segmentLength = 3 -Hair::Hair(int nodes, int segmentLength, int hairWidth) : RenderObject() +Hair::Hair(int nodes, float segmentLength, float hairWidth) : RenderObject() { this->segmentLength = segmentLength; this->hairWidth = hairWidth; - waveTimer = 0; - waveAmount = 5; - //hairWidth = 10; cull = false; @@ -46,7 +43,6 @@ Hair::Hair(int nodes, int segmentLength, int hairWidth) : RenderObject() hairNodes[i].percent = 1.0f-perc; hairNodes[i].position = hairNodes[i].originalPosition = hairNodes[i].defaultPosition = Vector(0, i*segmentLength, 0); } - hairTimer = 0; } void Hair::exertWave(float dt) @@ -196,15 +192,6 @@ void Hair::onRender() #endif } -void Hair::updateWaveTimer(float dt) -{ - waveTimer += dt; - for (int i = 1; i < hairNodes.size(); i++) - { - hairNodes[i].defaultPosition = hairNodes[i].originalPosition + Vector(cosf(waveTimer+i)*waveAmount*hairNodes[i].percent, 0, 0); - } -} - void Hair::onUpdate(float dt) { RenderObject::onUpdate(dt); diff --git a/Aquaria/Hair.h b/Aquaria/Hair.h index 14ae3c9..2bb495f 100644 --- a/Aquaria/Hair.h +++ b/Aquaria/Hair.h @@ -38,13 +38,13 @@ struct HairNode class Hair : public RenderObject { public: - Hair(int nodes=40, int segmentLength=3, int width=18); + Hair(int nodes=40, float segmentLength=3, float width=18); void exertForce(const Vector &force, float dt, int usePerc=0); void updatePositions(); void returnToDefaultPositions(float dt); - int hairWidth; + float hairWidth; std::vector hairNodes; @@ -54,10 +54,6 @@ public: void exertGravityWave(float dt); HairNode *getHairNode(int idx); protected: - float hairTimer; - void updateWaveTimer(float dt); - int waveAmount; - float waveTimer; float segmentLength; void onUpdate(float dt); void onRender(); diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 22b627e..2a5fdd9 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -3815,17 +3815,29 @@ luaFunc(entity_getAnimationLength) { Entity *e = entity(L); float ret=0; - int layer = lua_tonumber(L, 2); if (e) { - if (Animation *anim = e->skeletalSprite.getCurrentAnimation(layer)) + Animation *anim = 0; + if (lua_isstring(L, 2)) + anim = e->skeletalSprite.getAnimation(lua_tostring(L, 2)); + else { - ret = anim->getAnimationLength(); + int layer = lua_tointeger(L, 2); + anim = e->skeletalSprite.getCurrentAnimation(layer); } + if (anim) + ret = anim->getAnimationLength(); } luaReturnNum(ret); } +luaFunc(entity_hasAnimation) +{ + Entity *e = entity(L); + Animation *anim = e->skeletalSprite.getAnimation(getString(L, 2)); + luaReturnBool(anim != NULL); +} + luaFunc(entity_isFollowingPath) { Entity *e = entity(L); @@ -4233,6 +4245,15 @@ luaFunc(beam_setPosition_override) luaReturnNil(); } +luaFunc(beam_getEndPos) +{ + Beam *b = beam(L); + Vector v; + if (b) + v = b->endPos; + luaReturnVec2(v.x, v.y); +} + luaFunc(getStringBank) { luaReturnStr(dsq->continuity.stringBank.get(lua_tointeger(L, 1)).c_str()); @@ -4411,6 +4432,8 @@ luaFunc(entity_damage) d.damageType = (DamageType)lua_tointeger(L, 4); d.effectTime = lua_tonumber(L, 5); d.useTimer = !getBool(L, 6); + d.shot = lua_isuserdata(L, 7) ? getShot(L, 7) : NULL; + d.hitPos = Vector(lua_tonumber(L, 8), lua_tonumber(L, 9)); didDamage = e->damage(d); } luaReturnBool(didDamage); @@ -4448,6 +4471,22 @@ luaFunc(entity_setHealth) luaReturnNil(); } +luaFunc(entity_setCurrentHealth) +{ + Entity *e = entity(L, 1); + if (e) + e->health = lua_tonumber(L, 2); + luaReturnNil(); +} + +luaFunc(entity_setMaxHealth) +{ + Entity *e = entity(L, 1); + if (e) + e->maxHealth = lua_tonumber(L, 2); + luaReturnNil(); +} + luaFunc(entity_changeHealth) { Entity *e = entity(L, 1); @@ -8716,6 +8755,7 @@ static const struct { luaRegister(beam_setBeamWidth), luaRegister(beam_setFirer), luaRegister(beam_setDamageType), + luaRegister(beam_getEndPos), luaRegister(getStringBank), @@ -9297,6 +9337,8 @@ static const struct { luaRegister(entity_setHealth), + luaRegister(entity_setCurrentHealth), + luaRegister(entity_setMaxHealth), luaRegister(entity_changeHealth), luaRegister(node_setActive), @@ -9325,6 +9367,7 @@ static const struct { luaRegister(entity_isAnimating), luaRegister(entity_getAnimationName), luaRegister(entity_getAnimationLength), + luaRegister(entity_hasAnimation), luaRegister(entity_setCull), From b0c098bbcdd149cccb55633fa922a3d51cd84a2f Mon Sep 17 00:00:00 2001 From: fgenesis Date: Mon, 21 Oct 2013 02:34:30 +0200 Subject: [PATCH 2/3] Compile fix for prev. commit --- Aquaria/Entity.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aquaria/Entity.h b/Aquaria/Entity.h index 190ad3b..4b4719a 100644 --- a/Aquaria/Entity.h +++ b/Aquaria/Entity.h @@ -486,7 +486,7 @@ public: virtual bool canSetBoneLock(); - void initHair(int numSegments, int segmentLength, int width, const std::string &tex); + void initHair(int numSegments, float segmentLength, float width, const std::string &tex); void updateHair(float dt); void setHairHeadPosition(const Vector &pos); void exertHairForce(const Vector &force, float dt); From fa6ca8d60acfa9a0cb6785f41c74b352ffed082a Mon Sep 17 00:00:00 2001 From: fgenesis Date: Mon, 21 Oct 2013 02:34:57 +0200 Subject: [PATCH 3/3] Add 2 Lua functions: + obj_getWorldScale() + obj_getParent() --- Aquaria/ScriptInterface.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 2a5fdd9..c74edd8 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -1535,6 +1535,21 @@ luaFunc(obj_fadeAlphaWithLife) luaReturnNil(); } +luaFunc(obj_getWorldScale) +{ + RenderObject *r = robj(L); + Vector s; + if (r) + s = r->getRealScale(); + luaReturnVec2(s.x, s.y); +} + +luaFunc(obj_getParent) +{ + RenderObject *r = robj(L); + luaReturnPtr(r ? r->getParent() : NULL); +} + // ----- end RenderObject common functions ----- @@ -1746,6 +1761,8 @@ luaFunc(quad_getBorderAlpha) RO_FUNC(getter, prefix, collideCircleVsLineAngle) \ RO_FUNC(getter, prefix, getVectorToObj ) \ RO_FUNC(getter, prefix, fadeAlphaWithLife ) \ + RO_FUNC(getter, prefix, getWorldScale ) \ + RO_FUNC(getter, prefix, getParent ) \ MK_ALIAS(prefix, fh, flipHorizontal ) \ MK_ALIAS(prefix, fv, flipVertical )