mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-06-08 17:42:05 +00:00
simplify bonelocking, add Lua functions
- does no longer depend on collision mask - remove global Game::lastCollideMaskIndex - remove the horribly convoluted and now unused RenderObject::getInvRotPosition() + Lua func entity_getBoneLockDelay() + Lua func entity_setBoneLockDelay()
This commit is contained in:
parent
7e93956e9c
commit
640f08af13
8 changed files with 46 additions and 118 deletions
|
@ -3139,9 +3139,6 @@ void Avatar::onSetBoneLock()
|
||||||
skeletalSprite.transitionAnimate("wallLookUp", 0.2f, -1);
|
skeletalSprite.transitionAnimate("wallLookUp", 0.2f, -1);
|
||||||
lockToWallCommon();
|
lockToWallCommon();
|
||||||
state.lockedToWall = 1;
|
state.lockedToWall = 1;
|
||||||
wallNormal = boneLock.localOffset;
|
|
||||||
wallNormal.normalize2D();
|
|
||||||
rotateToVec(wallNormal, 0.1f);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -100,40 +100,36 @@ void Entity::generateCollisionMask(int ovrCollideRadius)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Entity::setBoneLock(const BoneLock &boneLock)
|
bool Entity::setBoneLock(const BoneLock &bl)
|
||||||
{
|
{
|
||||||
if (!canSetBoneLock()) return false;
|
if (!canSetBoneLock()) return false;
|
||||||
|
|
||||||
if (boneLock.on && boneLockDelay > 0) return false;
|
if (bl.on && boneLockDelay > 0) return false;
|
||||||
if (this->boneLock.on && boneLock.on) return false;
|
if (boneLock.on && bl.on) return false;
|
||||||
|
|
||||||
if (this->boneLock.on && !boneLock.on)
|
if (boneLock.on && !bl.on)
|
||||||
{
|
{
|
||||||
boneLockDelay = 0.1f;
|
boneLockDelay = 0.1f;
|
||||||
this->boneLock = boneLock;
|
boneLock = bl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!boneLock.entity)
|
if (!bl.entity)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
this->boneLock = boneLock;
|
boneLock = bl;
|
||||||
|
Quad *lockObj = bl.bone;
|
||||||
|
if(!lockObj)
|
||||||
|
lockObj = bl.entity;
|
||||||
|
|
||||||
if (!boneLock.bone)
|
Vector posAndRot = lockObj->getWorldPositionAndRotation();
|
||||||
{
|
boneLock.origRot = posAndRot.z;
|
||||||
this->boneLock.circleOffset = this->position - (boneLock.entity->getWorldPosition());
|
posAndRot.z = 0;
|
||||||
this->boneLock.circleOffset.setLength2D(boneLock.entity->collideRadius);
|
Vector offs = position - posAndRot;
|
||||||
this->boneLock.origRot = boneLock.entity->rotation.z;
|
boneLock.circleOffset = offs;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this->boneLock.localOffset = this->position - (boneLock.bone->getWorldPosition());
|
|
||||||
this->boneLock.localOffset = boneLock.bone->getInvRotPosition(this->boneLock.localOffset);
|
|
||||||
this->boneLock.origRot = boneLock.bone->getWorldRotation();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setv(EV_BONELOCKED, boneLock.on);
|
setv(EV_BONELOCKED, bl.on);
|
||||||
|
|
||||||
onSetBoneLock();
|
onSetBoneLock();
|
||||||
|
|
||||||
|
@ -1612,24 +1608,18 @@ void Entity::updateBoneLock()
|
||||||
{
|
{
|
||||||
if (boneLock.on)
|
if (boneLock.on)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
Vector lastPosition = position;
|
Vector lastPosition = position;
|
||||||
|
const Quad *lockObj = boneLock.bone;
|
||||||
|
if(!lockObj)
|
||||||
|
lockObj = boneLock.entity;
|
||||||
|
|
||||||
if (boneLock.bone)
|
Vector posAndRot = lockObj->getWorldPositionAndRotation();
|
||||||
{
|
Vector currentOffset = getRotatedVector(boneLock.circleOffset, posAndRot.z - boneLock.origRot);
|
||||||
position = boneLock.bone->transformedCollisionMask[boneLock.collisionMaskIndex];
|
posAndRot.z = 0;
|
||||||
boneLock.wallNormal = boneLock.bone->getCollisionMaskNormal(boneLock.collisionMaskIndex);
|
position = posAndRot + currentOffset;
|
||||||
rotateToVec(boneLock.wallNormal, 0.01f);
|
currentOffset.normalize2D();
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Vector currentOffset = getRotatedVector(boneLock.circleOffset, boneLock.entity->rotation.z - boneLock.origRot);
|
|
||||||
position = boneLock.entity->getWorldPosition() + currentOffset;
|
|
||||||
boneLock.wallNormal = currentOffset;
|
boneLock.wallNormal = currentOffset;
|
||||||
boneLock.wallNormal.normalize2D();
|
rotateToVec(currentOffset, 0.01f);
|
||||||
rotateToVec(boneLock.wallNormal, 0.01f);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dsq->game->collideCircleWithGrid(position, collideRadius))
|
if (dsq->game->collideCircleWithGrid(position, collideRadius))
|
||||||
{
|
{
|
||||||
|
@ -1638,12 +1628,7 @@ void Entity::updateBoneLock()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
onUpdateBoneLock();
|
onUpdateBoneLock();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,11 +42,9 @@ struct BoneLock
|
||||||
BoneLock() : entity(0), bone(0), on(false), origRot(0) {}
|
BoneLock() : entity(0), bone(0), on(false), origRot(0) {}
|
||||||
Entity *entity;
|
Entity *entity;
|
||||||
Bone *bone;
|
Bone *bone;
|
||||||
Vector localOffset;
|
|
||||||
bool on;
|
bool on;
|
||||||
float origRot;
|
float origRot;
|
||||||
Vector wallNormal, circleOffset;
|
Vector wallNormal, circleOffset;
|
||||||
int collisionMaskIndex;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// The Lance is an ability that never made it into the released version of the game.
|
// The Lance is an ability that never made it into the released version of the game.
|
||||||
|
@ -344,6 +342,7 @@ public:
|
||||||
|
|
||||||
void updateSoundPosition();
|
void updateSoundPosition();
|
||||||
void updateBoneLock();
|
void updateBoneLock();
|
||||||
|
float boneLockDelay;
|
||||||
|
|
||||||
Vector getPushVec() const { return pushVec; }
|
Vector getPushVec() const { return pushVec; }
|
||||||
float getPushDamage() const { return pushDamage; }
|
float getPushDamage() const { return pushDamage; }
|
||||||
|
@ -358,7 +357,6 @@ protected:
|
||||||
|
|
||||||
std::vector<DamageType> ignoreShotDamageTypes;
|
std::vector<DamageType> ignoreShotDamageTypes;
|
||||||
Timer vineDamageTimer;
|
Timer vineDamageTimer;
|
||||||
float boneLockDelay;
|
|
||||||
virtual void onSetBoneLock(){}
|
virtual void onSetBoneLock(){}
|
||||||
virtual void onUpdateBoneLock(){}
|
virtual void onUpdateBoneLock(){}
|
||||||
BoneLock boneLock;
|
BoneLock boneLock;
|
||||||
|
|
|
@ -223,7 +223,6 @@ Game::Game() : StateObject()
|
||||||
|
|
||||||
loadEntityTypeList();
|
loadEntityTypeList();
|
||||||
|
|
||||||
lastCollideMaskIndex = -1;
|
|
||||||
worldPaused = false;
|
worldPaused = false;
|
||||||
|
|
||||||
cookingScript = 0;
|
cookingScript = 0;
|
||||||
|
@ -3958,7 +3957,6 @@ Bone *Game::collideSkeletalVsCircle(Entity *skeletal, Vector pos, float radius)
|
||||||
{
|
{
|
||||||
closest = b;
|
closest = b;
|
||||||
smallestDist = dist;
|
smallestDist = dist;
|
||||||
lastCollideMaskIndex = i;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -382,8 +382,6 @@ public:
|
||||||
bool isShuttingDownGameState() { return shuttingDownGameState; }
|
bool isShuttingDownGameState() { return shuttingDownGameState; }
|
||||||
void warpToSceneNode(std::string scene, std::string node);
|
void warpToSceneNode(std::string scene, std::string node);
|
||||||
|
|
||||||
int lastCollideMaskIndex;
|
|
||||||
|
|
||||||
void ensureLimit(Entity *e, int num, int state=0);
|
void ensureLimit(Entity *e, int num, int state=0);
|
||||||
|
|
||||||
void rebuildElementUpdateList();
|
void rebuildElementUpdateList();
|
||||||
|
|
|
@ -2883,8 +2883,8 @@ luaFunc(entity_getBoneLockData)
|
||||||
lua_pushnumber(L, b.origRot);
|
lua_pushnumber(L, b.origRot);
|
||||||
lua_pushnumber(L, b.wallNormal.x);
|
lua_pushnumber(L, b.wallNormal.x);
|
||||||
lua_pushnumber(L, b.wallNormal.y);
|
lua_pushnumber(L, b.wallNormal.y);
|
||||||
lua_pushnumber(L, b.localOffset.x);
|
lua_pushnumber(L, b.circleOffset.x);
|
||||||
lua_pushnumber(L, b.localOffset.y);
|
lua_pushnumber(L, b.circleOffset.y);
|
||||||
return 7;
|
return 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2950,7 +2950,6 @@ luaFunc(entity_setBoneLock)
|
||||||
bl.entity = e2;
|
bl.entity = e2;
|
||||||
bl.bone = b;
|
bl.bone = b;
|
||||||
bl.on = true;
|
bl.on = true;
|
||||||
bl.collisionMaskIndex = dsq->game->lastCollideMaskIndex;
|
|
||||||
}
|
}
|
||||||
ret = e->setBoneLock(bl);
|
ret = e->setBoneLock(bl);
|
||||||
}
|
}
|
||||||
|
@ -2989,6 +2988,21 @@ luaFunc(entity_setBoneLockOffset)
|
||||||
luaReturnBool(ret);
|
luaReturnBool(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
luaFunc(entity_setBoneLockDelay)
|
||||||
|
{
|
||||||
|
if(Entity *e = entity(L))
|
||||||
|
e->boneLockDelay = lua_tonumber(L, 2);
|
||||||
|
luaReturnNil();
|
||||||
|
}
|
||||||
|
|
||||||
|
luaFunc(entity_getBoneLockDelay)
|
||||||
|
{
|
||||||
|
float t = 0;
|
||||||
|
if(Entity *e = entity(L))
|
||||||
|
t = e->boneLockDelay;
|
||||||
|
luaReturnNum(t);
|
||||||
|
}
|
||||||
|
|
||||||
luaFunc(entity_setIngredient)
|
luaFunc(entity_setIngredient)
|
||||||
{
|
{
|
||||||
Entity *e = entity(L);
|
Entity *e = entity(L);
|
||||||
|
@ -9972,6 +9986,8 @@ static const struct {
|
||||||
luaRegister(entity_setBoneLock),
|
luaRegister(entity_setBoneLock),
|
||||||
luaRegister(entity_setBoneLockRotation),
|
luaRegister(entity_setBoneLockRotation),
|
||||||
luaRegister(entity_setBoneLockOffset),
|
luaRegister(entity_setBoneLockOffset),
|
||||||
|
luaRegister(entity_setBoneLockDelay),
|
||||||
|
luaRegister(entity_getBoneLockDelay),
|
||||||
luaRegister(entity_setIngredient),
|
luaRegister(entity_setIngredient),
|
||||||
luaRegister(entity_setDeathScene),
|
luaRegister(entity_setDeathScene),
|
||||||
luaRegister(entity_isDeathScene),
|
luaRegister(entity_isDeathScene),
|
||||||
|
|
|
@ -122,69 +122,6 @@ RenderObject* RenderObject::getTopParent() const
|
||||||
return lastp;
|
return lastp;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef BBGE_USE_GLM
|
|
||||||
static glm::mat4 getInvRotation(const RenderObject *p)
|
|
||||||
{
|
|
||||||
glm::mat4 m = glm::rotate(-(p->rotation.z + p->rotationOffset.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
|
||||||
if(p->isfh())
|
|
||||||
m *= glm::rotate(180.0f, glm::vec3(0.0f, 1.0f, 0.0f));
|
|
||||||
return m;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Vector RenderObject::getInvRotPosition(const Vector &vec) const
|
|
||||||
{
|
|
||||||
#ifdef BBGE_USE_GLM
|
|
||||||
glm::mat4 m = getInvRotation(this);
|
|
||||||
for(RenderObject *p = parent; p; p = p->parent)
|
|
||||||
m *= getInvRotation(p);
|
|
||||||
m *= glm::translate(vec.x, vec.y, 0.0f);
|
|
||||||
float x = m[3][0];
|
|
||||||
float y = m[3][1];
|
|
||||||
float z = m[3][2];
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
glPushMatrix();
|
|
||||||
glLoadIdentity();
|
|
||||||
|
|
||||||
std::vector<const RenderObject*>chain;
|
|
||||||
const RenderObject *p = this;
|
|
||||||
while(p)
|
|
||||||
{
|
|
||||||
chain.push_back(p);
|
|
||||||
p = p->parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = chain.size()-1; i >= 0; i--)
|
|
||||||
{
|
|
||||||
glRotatef(-(chain[i]->rotation.z+chain[i]->rotationOffset.z), 0, 0, 1);
|
|
||||||
|
|
||||||
if (chain[i]->isfh())
|
|
||||||
{
|
|
||||||
|
|
||||||
glRotatef(180, 0, 1, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (vec.x != 0 || vec.y != 0)
|
|
||||||
{
|
|
||||||
|
|
||||||
glTranslatef(vec.x, vec.y, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
float m[16];
|
|
||||||
glGetFloatv(GL_MODELVIEW_MATRIX, m);
|
|
||||||
float x = m[12];
|
|
||||||
float y = m[13];
|
|
||||||
float z = m[14];
|
|
||||||
|
|
||||||
glPopMatrix();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return Vector(x,y,z);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef BBGE_USE_GLM
|
#ifdef BBGE_USE_GLM
|
||||||
static glm::mat4 matrixChain(const RenderObject *ro)
|
static glm::mat4 matrixChain(const RenderObject *ro)
|
||||||
{
|
{
|
||||||
|
|
|
@ -185,7 +185,6 @@ public:
|
||||||
|
|
||||||
Vector getWorldPosition() const;
|
Vector getWorldPosition() const;
|
||||||
Vector getWorldCollidePosition(const Vector &vec=Vector(0,0,0)) const;
|
Vector getWorldCollidePosition(const Vector &vec=Vector(0,0,0)) const;
|
||||||
Vector getInvRotPosition(const Vector &vec) const;
|
|
||||||
|
|
||||||
RenderObject *getTopParent() const;
|
RenderObject *getTopParent() const;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue