From c598fde5e866af36facb564e5b41ab8d9067b146 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Thu, 17 Oct 2024 06:00:51 +0200 Subject: [PATCH] Change entity_setFillGrid() to allow skeleton grid filling, and whether to trim entity_isFillGrid() returns two bools now --- Aquaria/Entity.cpp | 13 ++++++++++++- Aquaria/Entity.h | 3 ++- Aquaria/Game.cpp | 10 ++++++---- Aquaria/ScriptInterface.cpp | 31 +++++++++++++++++++++++++++---- 4 files changed, 47 insertions(+), 10 deletions(-) diff --git a/Aquaria/Entity.cpp b/Aquaria/Entity.cpp index d2ce3be..5b93ec5 100644 --- a/Aquaria/Entity.cpp +++ b/Aquaria/Entity.cpp @@ -191,6 +191,7 @@ Entity::Entity() hair = 0; maxSpeedLerp = 1; fillGridFromQuad = false; + fillGridFromSkel = false; dropChance = 0; inCurrent = false; for (size_t i = 0; i < EP_MAX; i++) @@ -2422,7 +2423,17 @@ void Entity::fillGrid() { if (fillGridFromQuad) { - game->fillGridFromQuad(this, OT_INVISIBLEENT); + game->fillGridFromQuad(this, OT_INVISIBLEENT, fillGridFromQuad == 1); + } + if (fillGridFromSkel) + { + bool trim = fillGridFromSkel == 1; + for(size_t i = 0; i < skeletalSprite.bones.size(); ++i) + { + Bone *b = skeletalSprite.bones[i]; + if(b->generateCollisionMask && b->renderQuad) + game->fillGridFromQuad(b, OT_INVISIBLEENT, trim); + } } } diff --git a/Aquaria/Entity.h b/Aquaria/Entity.h index cd44460..90d3feb 100644 --- a/Aquaria/Entity.h +++ b/Aquaria/Entity.h @@ -439,7 +439,8 @@ protected: bool canBeTargetedByAvatar; bool stopSoundsOnDeath; public: - bool fillGridFromQuad; + unsigned char fillGridFromQuad; + unsigned char fillGridFromSkel; bool beautyFlip; }; diff --git a/Aquaria/Game.cpp b/Aquaria/Game.cpp index b6ebd20..a5474ec 100644 --- a/Aquaria/Game.cpp +++ b/Aquaria/Game.cpp @@ -342,10 +342,12 @@ void Game::fillGridFromQuad(Quad *q, ObsType obsType, bool trim) GridFiller f; f.obs = obsType; f.trim = trim; - f.fh = q->isfh(); - f.position = q->position; - f.rotation = q->rotation.z; - f.scale = q->scale; + f.fh = q->isfhr(); + Vector posrot = q->getWorldPositionAndRotation(); + f.position.x = posrot.x; + f.position.y = posrot.y; + f.rotation = posrot.z; + f.scale = q->getRealScale(); f.texture = q->texture.content(); f.width = q->width; f.height = q->height; diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index ebf0801..7b51bae 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -567,6 +567,24 @@ bool getBool(lua_State *L, int slot = 1) return false; } +static inline +int getBoolOrInt(lua_State *L, int slot = 1) +{ + if (lua_isnumber(L, slot)) + { + return lua_tointeger(L, slot); + } + else if (lua_islightuserdata(L, slot)) + { + return (lua_touserdata(L, slot) != NULL); + } + else if (lua_isboolean(L, slot)) + { + return !!lua_toboolean(L, slot); + } + return 0; +} + static inline Entity *entity(lua_State *L, int slot = 1) { @@ -777,7 +795,7 @@ static void safePath(lua_State *L, const std::string& path) //----------------------------------// #define luaFunc(func) static int l_##func(lua_State *L) -#define luaReturnBool(bool) do {lua_pushboolean(L, (bool)); return 1;} while(0) +#define luaReturnBool(b) do {lua_pushboolean(L, (b)); return 1;} while(0) #define luaReturnInt(num) do {lua_pushinteger(L, (num)); return 1;} while(0) #define luaReturnNum(num) do {lua_pushnumber(L, (num)); return 1;} while(0) #define luaReturnPtr(ptr) do {luaPushPointer(L, (ptr)); return 1;} while(0) @@ -3561,10 +3579,10 @@ luaFunc(node_setPauseFreeze) luaFunc(entity_setFillGrid) { Entity *e = entity(L); - bool b = getBool(L,2); if (e) { - e->fillGridFromQuad = b; + e->fillGridFromQuad = getBoolOrInt(L, 2); + e->fillGridFromSkel = getBoolOrInt(L, 3); } luaReturnNil(); } @@ -3572,7 +3590,12 @@ luaFunc(entity_setFillGrid) luaFunc(entity_isFillGrid) { Entity *e = entity(L); - luaReturnBool(e ? e->fillGridFromQuad : false); + if(!e) + return 0; + + lua_pushboolean(L, e->fillGridFromQuad); + lua_pushboolean(L, e->fillGridFromSkel); + return 2; } luaFunc(entity_getAimVector)