From 2993145f2a9176caab2176e4d37f74c377ec9ec2 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Thu, 20 Jul 2023 22:28:20 +0200 Subject: [PATCH 01/21] "3" is not a valid internalformat for glTexImage2D() --- BBGE/ScreenTransition.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BBGE/ScreenTransition.cpp b/BBGE/ScreenTransition.cpp index e451ac5..2cdb2ed 100644 --- a/BBGE/ScreenTransition.cpp +++ b/BBGE/ScreenTransition.cpp @@ -53,7 +53,7 @@ void ScreenTransition::createTexture() glBindTexture(GL_TEXTURE_2D, screen_texture); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR); //GL_NEAREST); //GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR); //GL_NEAREST); //GL_NEAREST); - glTexImage2D(GL_TEXTURE_2D,0,3, textureWidth, textureHeight, 0 , GL_RGB, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_2D,0,GL_RGB, textureWidth, textureHeight, 0 , GL_RGB, GL_UNSIGNED_BYTE, NULL); glBindTexture(GL_TEXTURE_2D,0); } From defaa6085009abe564a31b4b590fa4fc95d120f2 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Thu, 20 Jul 2023 22:27:50 +0200 Subject: [PATCH 02/21] don't quadruple overdraw points in grid debug render --- BBGE/RenderGrid.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/BBGE/RenderGrid.cpp b/BBGE/RenderGrid.cpp index 2a54175..5f4a5c2 100644 --- a/BBGE/RenderGrid.cpp +++ b/BBGE/RenderGrid.cpp @@ -202,17 +202,13 @@ void RenderGrid::renderDebugPoints(const RenderState& rs) const glPointSize(2); glColor3f(1,0,0); glBegin(GL_POINTS); - const size_t NX = grid.width()-1; - const size_t NY = grid.height()-1; - for (size_t y = 0; y < NY; y++) + const size_t W = grid.width(); + const size_t H = grid.height(); + for (size_t y = 0; y < H; y++) { - for (size_t x = 0; x < NX; x++) - { - glVertex2f(grid(x,y).x, grid(x,y).y); - glVertex2f(grid(x,y+1).x, grid(x,y+1).y); - glVertex2f(grid(x+1,y+1).x, grid(x+1,y+1).y); - glVertex2f(grid(x+1,y).x, grid(x+1,y).y); - } + const Vector * const row = grid.row(y); + for (size_t x = 0; x < W; x++) + glVertex2f(row[x].x, row[x].y); } glEnd(); } From fa72328d5c9237c35cbf1c58defef71840fda943 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Thu, 20 Jul 2023 22:26:09 +0200 Subject: [PATCH 03/21] Fix missing textures in ingredient pickup effect and new recipe notification --- Aquaria/Game.cpp | 4 ++-- Aquaria/Ingredient.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Aquaria/Game.cpp b/Aquaria/Game.cpp index 5200789..a1ffe44 100644 --- a/Aquaria/Game.cpp +++ b/Aquaria/Game.cpp @@ -238,7 +238,7 @@ Game::~Game() void Game::pickupIngredientEffects(IngredientData *data) { - Quad *q = new Quad("gfx/ingredients/" + data->gfx, Vector(800-20 + core->getVirtualOffX(), (570-2*(100*miniMapRender->scale.y))+ingOffY)); + Quad *q = new Quad("ingredients/" + data->gfx, Vector(800-20 + core->getVirtualOffX(), (570-2*(100*miniMapRender->scale.y))+ingOffY)); q->scale = Vector(0.8f, 0.8f); q->followCamera = 1; q->alpha.ensureData(); @@ -5005,7 +5005,7 @@ void Game::learnedRecipe(Recipe *r, bool effects) { if (effects) { - setControlHint(os.str(), 0, 0, 0, 3, std::string("gfx/ingredients/") + data->gfx); + setControlHint(os.str(), 0, 0, 0, 3, "ingredients/" + data->gfx); } } } diff --git a/Aquaria/Ingredient.cpp b/Aquaria/Ingredient.cpp index 1e2df3c..a477918 100644 --- a/Aquaria/Ingredient.cpp +++ b/Aquaria/Ingredient.cpp @@ -64,7 +64,7 @@ Ingredient::Ingredient(const Vector &pos, IngredientData *data, int amount) lifeSpan = 30; if (data) { - setTexture("Ingredients/"+data->gfx); + setTexture("ingredients/"+data->gfx); } int mag = 600; if (isRotKind()) From e27a0312299119fd41f9a423befb39226f350443 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Tue, 1 Aug 2023 22:39:34 +0200 Subject: [PATCH 04/21] Get rid of GL functions with double precision that were accidentally used # Conflicts: # BBGE/OpenGLStubs.h --- BBGE/AfterEffect.cpp | 8 ++++---- BBGE/OpenGLStubs.h | 24 ++++++++++++------------ BBGE/ScreenTransition.cpp | 8 ++++---- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/BBGE/AfterEffect.cpp b/BBGE/AfterEffect.cpp index 1a0e5e7..07d7f4d 100644 --- a/BBGE/AfterEffect.cpp +++ b/BBGE/AfterEffect.cpp @@ -284,13 +284,13 @@ void AfterEffectManager::renderGrid() const // note that offx, offy are negative here! glBegin(GL_QUADS); - glTexCoord2d(0.0f, 0.0f); + glTexCoord2f(0.0f, 0.0f); glVertex3f(offx, vh+offy, 0.0f); - glTexCoord2d(percentX, 0.0f); + glTexCoord2f(percentX, 0.0f); glVertex3f( vw+offx, vh+offy, 0.0f); - glTexCoord2d(percentX, percentY); + glTexCoord2f(percentX, percentY); glVertex3f( vw+offx, offy, 0.0f); - glTexCoord2d(0.0f, percentY); + glTexCoord2f(0.0f, percentY); glVertex3f(offx, offy, 0.0f); glEnd(); diff --git a/BBGE/OpenGLStubs.h b/BBGE/OpenGLStubs.h index cd17466..b73a318 100644 --- a/BBGE/OpenGLStubs.h +++ b/BBGE/OpenGLStubs.h @@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ GL_FUNC(void,glBindTexture,(GLenum target,GLuint name),(target,name),) -GL_FUNC(void,glBitmap,(GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove, const GLubyte *bitmap),(width,height,xorig,yorig,xmove,ymove,bitmap),) +//GL_FUNC(void,glBitmap,(GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove, const GLubyte *bitmap),(width,height,xorig,yorig,xmove,ymove,bitmap),) GL_FUNC(void,glBlendFunc,(GLenum f,GLenum x),(f,x),) GL_FUNC(void,glClear,(GLbitfield a),(a),) GL_FUNC(void,glClearColor,(GLclampf r,GLclampf g,GLclampf b,GLclampf a),(r,g,b,a),) @@ -32,8 +32,8 @@ GL_FUNC(void,glCopyTexSubImage2D,(GLenum target, GLint level, GLint xoffset, GLi GL_FUNC(void,glDeleteTextures,(GLsizei n, const GLuint *textures),(n,textures),) GL_FUNC(void,glDisable,(GLenum cap),(cap),) GL_FUNC(void,glDisableClientState,(GLenum array),(array),) -//GL_FUNC(void,glDrawArrays,(GLenum mode, GLint first, GLsizei count),(mode,first,count),) -//GL_FUNC(void,glDrawElements,(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices),(mode,count,type,indices),) +GL_FUNC(void,glDrawArrays,(GLenum mode, GLint first, GLsizei count),(mode,first,count),) +GL_FUNC(void,glDrawElements,(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices),(mode,count,type,indices),) GL_FUNC(void,glEnable,(GLenum cap),(cap),) GL_FUNC(void,glEnableClientState,(GLenum array),(array),) GL_FUNC(void,glFinish,(void),(),) @@ -65,16 +65,16 @@ GL_FUNC(void,glViewport,(GLint x, GLint y, GLsizei width, GLsizei height),(x,y,w //GL_FUNC(void,glScissor,(GLint x, GLint y, GLsizei width, GLsizei height),(x,y,width,height),) GL_FUNC(void,glBegin,(GLenum e),(e),) GL_FUNC(void,glEnd,(void),(),) -GL_FUNC(void,glEndList,(void),(),) -GL_FUNC(void,glCallList,(GLuint list),(list),) +//GL_FUNC(void,glEndList,(void),(),) +//GL_FUNC(void,glCallList,(GLuint list),(list),) GL_FUNC(void,glClearDepth,(GLclampd x),(x),) GL_FUNC(void,glColor3f,(GLfloat r,GLfloat g,GLfloat b),(r,g,b),) -GL_FUNC(void,glDeleteLists,(GLuint list, GLsizei range),(list,range),) -GL_FUNC(void,glDrawPixels,(GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels),(width,height,format,type,pixels),) -GL_FUNC(GLuint,glGenLists,(GLsizei range),(range),return) -GL_FUNC(void,glNewList,(GLuint list, GLenum mode),(list,mode),) -GL_FUNC(void,glNormal3d,(GLdouble nx, GLdouble ny, GLdouble nz),(nx,ny,nz),) -GL_FUNC(void,glNormal3dv,(const GLdouble *v),(v),) +//GL_FUNC(void,glDeleteLists,(GLuint list, GLsizei range),(list,range),) +//GL_FUNC(void,glDrawPixels,(GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels),(width,height,format,type,pixels),) +//GL_FUNC(GLuint,glGenLists,(GLsizei range),(range),return) +//GL_FUNC(void,glNewList,(GLuint list, GLenum mode),(list,mode),) +//GL_FUNC(void,glNormal3d,(GLdouble nx, GLdouble ny, GLdouble nz),(nx,ny,nz),) +//GL_FUNC(void,glNormal3dv,(const GLdouble *v),(v),) GL_FUNC(void,glOrtho,(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar),(left,right,bottom,top,zNear,zFar),) GL_FUNC(void,glPopAttrib,(void),(),) GL_FUNC(void,glPopClientAttrib,(void),(),) @@ -82,7 +82,7 @@ GL_FUNC(void,glPushAttrib,(GLbitfield mask),(mask),) GL_FUNC(void,glPushClientAttrib,(GLbitfield mask),(mask),) GL_FUNC(void,glRasterPos2i,(GLint x, GLint y),(x,y),) GL_FUNC(void,glTexCoord2f,(GLfloat s, GLfloat t),(s,t),) -GL_FUNC(void,glTexCoord2d,(GLdouble s, GLdouble t),(s,t),) +//GL_FUNC(void,glTexCoord2d,(GLdouble s, GLdouble t),(s,t),) GL_FUNC(void,glVertex2f,(GLfloat x, GLfloat y),(x,y),) GL_FUNC(void,glVertex3f,(GLfloat x, GLfloat y, GLfloat z),(x,y,z),) GL_FUNC(void,glVertex3i,(GLint x, GLint y, GLint z),(x,y,z),) diff --git a/BBGE/ScreenTransition.cpp b/BBGE/ScreenTransition.cpp index 2cdb2ed..04bd213 100644 --- a/BBGE/ScreenTransition.cpp +++ b/BBGE/ScreenTransition.cpp @@ -124,13 +124,13 @@ void ScreenTransition::onRender(const RenderState& rs) const glBindTexture(GL_TEXTURE_2D, screen_texture); glBegin(GL_QUADS); - glTexCoord2d(0, 0); + glTexCoord2f(0, 0); glVertex3f(-width2, height2, 0.0); - glTexCoord2d(pw, 0); + glTexCoord2f(pw, 0); glVertex3f( width2, height2, 0.0); - glTexCoord2d(pw, ph); + glTexCoord2f(pw, ph); glVertex3f( width2, -height2, 0.0); - glTexCoord2d(0, ph); + glTexCoord2f(0, ph); glVertex3f(-width2, -height2, 0.0); glEnd(); From ff035a37fa5ec5780ded0490a4f2c91186b91b0b Mon Sep 17 00:00:00 2001 From: fgenesis Date: Tue, 1 Aug 2023 22:39:48 +0200 Subject: [PATCH 05/21] fix some asserts --- Aquaria/AnimationEditor.cpp | 4 ++-- BBGE/SkeletalSprite.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Aquaria/AnimationEditor.cpp b/Aquaria/AnimationEditor.cpp index 84011d2..024f3fe 100644 --- a/Aquaria/AnimationEditor.cpp +++ b/Aquaria/AnimationEditor.cpp @@ -1604,7 +1604,7 @@ void AnimationEditor::applyBoneToSplineGrid() Animation *a = editSprite->getCurrentAnimation(); BoneKeyframe *bk = a->getKeyframe(currentKey)->getBoneKeyframe(editingBone->boneIdx); assert(bk->controlpoints.size() == splinegrid->getSpline().ctrlX() * splinegrid->getSpline().ctrlY()); - assert(bk->grid.size() == editingBone->getDrawGrid().linearsize()); + assert(bk->grid.size() == editingBone->getGrid()->linearsize()); splinegrid->importControlPoints(&bk->controlpoints[0]); } } @@ -1616,7 +1616,7 @@ void AnimationEditor::applySplineGridToBone() Animation *a = editSprite->getCurrentAnimation(); BoneKeyframe *bk = a->getKeyframe(currentKey)->getBoneKeyframe(editingBone->boneIdx); assert(bk->controlpoints.size() == splinegrid->getSpline().ctrlX() * splinegrid->getSpline().ctrlY()); - assert(bk->grid.size() == editingBone->getDrawGrid().linearsize()); + assert(bk->grid.size() == editingBone->getGrid()->linearsize()); splinegrid->exportControlPoints(&bk->controlpoints[0]); BoneGridInterpolator *interp = a->getBoneGridInterpolator(editingBone->boneIdx); interp->updateGridAndBone(*bk, editingBone); diff --git a/BBGE/SkeletalSprite.cpp b/BBGE/SkeletalSprite.cpp index 7a6e70e..3ad7b5b 100644 --- a/BBGE/SkeletalSprite.cpp +++ b/BBGE/SkeletalSprite.cpp @@ -1073,7 +1073,7 @@ bool SkeletalSprite::saveSkeletal(const std::string &fn) const BoneGridInterpolator& bgip = a->interpolators[j]; XMLElement *interp = xml->NewElement("Interpolator"); Bone *bone = this->getBoneByIdx(bgip.idx); - assert(bone->gridType == Quad::GRID_INTERP); + assert(bone->grid->gridType == GRID_INTERP); if(bgip.storeBoneByIdx) interp->SetAttribute("bone", (int)bone->boneIdx); else From dacfde0416b482526e22a9d4570fc802196c1ea9 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Tue, 1 Aug 2023 22:43:25 +0200 Subject: [PATCH 06/21] more params to refreshElements*Callback() callback functions params now: idx, tex, active, layer, tag, x, y, scalex, scaley, rot, fh, fv, repeatscalex, repeatscaley --- Aquaria/ScriptInterface.cpp | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 2604339..5d10bf6 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -7656,12 +7656,32 @@ luaFunc(node_setElementsInLayerActive) static int pushElementData(lua_State *L, const Element *e) { - lua_pushinteger(L, e->templateIdx); - lua_pushstring(L, e->texture->name.c_str()); - lua_pushboolean(L, e->isElementActive()); - lua_pushinteger(L, e->bgLayer); - lua_pushinteger(L, e->tag); - return 5; + /* 1 */ lua_pushinteger(L, e->templateIdx); + /* 2 */ lua_pushstring(L, e->texture->name.c_str()); + /* 3 */ lua_pushboolean(L, e->isElementActive()); + /* 4 */ lua_pushinteger(L, e->bgLayer); + /* 5 */ lua_pushinteger(L, e->tag); + /* 6 */ lua_pushnumber(L, e->position.x); + /* 7 */ lua_pushnumber(L, e->position.y); + /* 8 */ lua_pushnumber(L, e->scale.x); + /* 9 */ lua_pushnumber(L, e->scale.y); + /* 10 */ lua_pushnumber(L, e->rotation.z); + /* 11 */ lua_pushboolean(L, e->isfh()); + /* 12 */ lua_pushboolean(L, e->isfv()); + + // 13, 14 + if(e->isRepeatingTextureToFill()) + { + lua_pushnumber(L, e->repeatToFillScale.x); + lua_pushnumber(L, e->repeatToFillScale.y); + } + else + { + lua_pushnil(L); + lua_pushnil(L); + } + + return 14; } // (layer, func) From 6a7aa66bab67496e10e24ef901f96777b14942d3 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Tue, 22 Aug 2023 21:28:05 +0200 Subject: [PATCH 07/21] splinegrid: allow changing point size to better acommodate very large or very small textures --- Aquaria/AnimationEditor.cpp | 10 ++++++++-- BBGE/SplineGrid.cpp | 16 +++++++++++++--- BBGE/SplineGrid.h | 4 ++++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/Aquaria/AnimationEditor.cpp b/Aquaria/AnimationEditor.cpp index 024f3fe..8b88289 100644 --- a/Aquaria/AnimationEditor.cpp +++ b/Aquaria/AnimationEditor.cpp @@ -739,11 +739,17 @@ void AnimationEditor::update(float dt) float spd = 1.0f; if (core->mouse.scrollWheelChange < 0) { - ctrlSprite->scale.x /= 1.12f; + if(splinegrid && core->getShiftState()) + splinegrid->setPointScale(std::max(splinegrid->getPointScale() / 1.12f, 0.05f)); + else + ctrlSprite->scale.x /= 1.12f; } else if (core->mouse.scrollWheelChange > 0) { - ctrlSprite->scale.x *= 1.12f; + if(splinegrid && core->getShiftState()) + splinegrid->setPointScale(splinegrid->getPointScale() * 1.12f); + else + ctrlSprite->scale.x *= 1.12f; } if (core->getKeyState(KEY_PGDN) && core->getShiftState()) { diff --git a/BBGE/SplineGrid.cpp b/BBGE/SplineGrid.cpp index 6a1e89e..3d7b2be 100644 --- a/BBGE/SplineGrid.cpp +++ b/BBGE/SplineGrid.cpp @@ -8,7 +8,7 @@ SplineGridCtrlPoint *SplineGridCtrlPoint::movingPoint; SplineGridCtrlPoint::SplineGridCtrlPoint() { setTexture("gui/open-menu"); - setWidthHeight(16, 16); + setWidthHeight(8, 8); } Vector SplineGridCtrlPoint::getSplinePosition() const @@ -70,7 +70,7 @@ void SplineGridCtrlPoint::onUpdate(float dt) } SplineGrid::SplineGrid() - : wasModified(false), deg(0) + : wasModified(false), deg(0), pointscale(1) { setWidthHeight(128, 128); renderQuad = true; @@ -165,6 +165,8 @@ SplineGridCtrlPoint* SplineGrid::createControlPoint(size_t x, size_t y) const Vector pos01(float(x) / float(cpx-1), float(y) / float(cpy-1)); SplineGridCtrlPoint *cp = new SplineGridCtrlPoint(); cp->position = (pos01 - Vector(0.5f, 0.5f)) * wh; + cp->scale.x = pointscale; + cp->scale.y = pointscale; this->addChild(cp, PM_POINTER); return cp; } @@ -214,4 +216,12 @@ void SplineGrid::onRender(const RenderState& rs) const } } - +void SplineGrid::setPointScale(const float scale) +{ + pointscale = scale; + for(size_t i = 0; i < ctrlp.size(); ++i) + { + ctrlp[i]->scale.x = scale; + ctrlp[i]->scale.y = scale; + } +} diff --git a/BBGE/SplineGrid.h b/BBGE/SplineGrid.h index 962e824..534252c 100644 --- a/BBGE/SplineGrid.h +++ b/BBGE/SplineGrid.h @@ -39,6 +39,9 @@ public: void importControlPoints(const Vector *controlpoints); void resetControlPoints(); + void setPointScale(const float scale); + float getPointScale() const { return pointscale; } + virtual void onRender(const RenderState& rs) const OVERRIDE; virtual void onUpdate(float dt) OVERRIDE; @@ -55,6 +58,7 @@ private: std::vector ctrlp; unsigned deg; BSpline2DWithPoints bsp; + float pointscale; }; From c1084a022d4134f66b3f583c09cffcc3af83d572 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Fri, 25 Aug 2023 20:13:56 +0200 Subject: [PATCH 08/21] forgot a virtual dtor --- BBGE/SplineGrid.cpp | 4 ++++ BBGE/SplineGrid.h | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/BBGE/SplineGrid.cpp b/BBGE/SplineGrid.cpp index 3d7b2be..1f11f4b 100644 --- a/BBGE/SplineGrid.cpp +++ b/BBGE/SplineGrid.cpp @@ -11,6 +11,10 @@ SplineGridCtrlPoint::SplineGridCtrlPoint() setWidthHeight(8, 8); } +SplineGridCtrlPoint::~SplineGridCtrlPoint() +{ +} + Vector SplineGridCtrlPoint::getSplinePosition() const { SplineGridCtrlPoint *p = (SplineGridCtrlPoint*)getParent(); diff --git a/BBGE/SplineGrid.h b/BBGE/SplineGrid.h index 534252c..3a0503d 100644 --- a/BBGE/SplineGrid.h +++ b/BBGE/SplineGrid.h @@ -17,6 +17,7 @@ class SplineGridCtrlPoint : public Quad { public: SplineGridCtrlPoint(); + virtual ~SplineGridCtrlPoint(); virtual void onUpdate(float dt) OVERRIDE; Vector getSplinePosition() const; void setSplinePosition(Vector pos); @@ -30,7 +31,7 @@ public: typedef Vector value_type; SplineGrid(); - ~SplineGrid(); + virtual ~SplineGrid(); // # of control points on each axis RenderGrid *resize(size_t w, size_t h, size_t xres, size_t yres, unsigned degx, unsigned degy); From bf58fe91c69cbf12200ab31fa027364962f9b9f8 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Wed, 13 Sep 2023 23:56:11 +0200 Subject: [PATCH 09/21] fix some rare crashes with dangling pointers - Always handle entity death ie. do pointer cleanup - Call Lua entityDied() only when EV_ENTITYDIED is set - EV_ENTITYDIED is now meaningless for non-scripted entities --- Aquaria/Avatar.cpp | 5 ----- Aquaria/Avatar.h | 2 -- Aquaria/Entity.cpp | 35 +++++++++++++++-------------------- Aquaria/Entity.h | 4 +--- Aquaria/Game.cpp | 5 +---- Aquaria/ScriptedEntity.cpp | 2 +- 6 files changed, 18 insertions(+), 35 deletions(-) diff --git a/Aquaria/Avatar.cpp b/Aquaria/Avatar.cpp index 90780d9..cc0c525 100644 --- a/Aquaria/Avatar.cpp +++ b/Aquaria/Avatar.cpp @@ -3063,11 +3063,6 @@ void Avatar::setBlockSinging(bool v) } } -bool Avatar::canSetBoneLock() -{ - return true; -} - void Avatar::onSetBoneLock() { Entity::onSetBoneLock(); diff --git a/Aquaria/Avatar.h b/Aquaria/Avatar.h index 36d4f2a..c36caa3 100644 --- a/Aquaria/Avatar.h +++ b/Aquaria/Avatar.h @@ -300,8 +300,6 @@ public: Web *web; float rollDelay; - bool canSetBoneLock() OVERRIDE; - void revert(); void doBindSong(); void doShieldSong(); diff --git a/Aquaria/Entity.cpp b/Aquaria/Entity.cpp index 46e44d1..ea941ad 100644 --- a/Aquaria/Entity.cpp +++ b/Aquaria/Entity.cpp @@ -61,17 +61,18 @@ void Entity::setIngredientData(const std::string &name) void Entity::entityDied(Entity *e) { for (size_t i = 0; i < targets.size(); i++) + if(targets[i] == e) + targets[i] = NULL; + + if (boneLock.on && boneLock.entity == e) { - targets[i] = 0; + setBoneLock(BoneLock(), true); } - if (boneLock.on) - { - if (boneLock.entity == e) - { - setBoneLock(BoneLock()); - } - } + if(riding == e) + riding = NULL; + if(ridingOnEntity == e) + ridingOnEntity = NULL; } void Entity::setBounceType(BounceType bt) @@ -98,14 +99,13 @@ void Entity::generateCollisionMask(int ovrCollideRadius) } } - - -bool Entity::setBoneLock(const BoneLock &bl) +bool Entity::setBoneLock(const BoneLock &bl, bool force) { - if (!canSetBoneLock()) return false; - - if (bl.on && boneLockDelay > 0) return false; - if (boneLock.on && bl.on) return false; + if(!force) + { + if (bl.on && boneLockDelay > 0) return false; + if (boneLock.on && bl.on) return false; + } if (boneLock.on && !bl.on) { @@ -138,11 +138,6 @@ bool Entity::setBoneLock(const BoneLock &bl) return true; } -bool Entity::canSetBoneLock() -{ - return true; -} - Entity::Entity() { addType(SCO_ENTITY); diff --git a/Aquaria/Entity.h b/Aquaria/Entity.h index 5a3e0b8..915726f 100644 --- a/Aquaria/Entity.h +++ b/Aquaria/Entity.h @@ -91,7 +91,7 @@ public: float health; float maxHealth; - bool setBoneLock(const BoneLock &boneLock); + bool setBoneLock(const BoneLock &boneLock, bool force = false); void heal(float a, int type=0); @@ -330,8 +330,6 @@ public: void setPoison(float m, float t); inline float getPoison() const { return poison; } - virtual bool canSetBoneLock(); - void initHair(int numSegments, float segmentLength, float width, const std::string &tex); void updateHair(float dt); void setHairHeadPosition(const Vector &pos); diff --git a/Aquaria/Game.cpp b/Aquaria/Game.cpp index a1ffe44..e959ab1 100644 --- a/Aquaria/Game.cpp +++ b/Aquaria/Game.cpp @@ -2333,10 +2333,7 @@ void Game::entityDied(Entity *eDead) FOR_ENTITIES(i) { e = *i; - if (e != eDead && e->isv(EV_ENTITYDIED,1)) - { - e->entityDied(eDead); - } + e->entityDied(eDead); } dsq->continuity.entityDied(eDead); diff --git a/Aquaria/ScriptedEntity.cpp b/Aquaria/ScriptedEntity.cpp index 4bfeb83..ac36cb7 100644 --- a/Aquaria/ScriptedEntity.cpp +++ b/Aquaria/ScriptedEntity.cpp @@ -688,7 +688,7 @@ void ScriptedEntity::entityDied(Entity *e) { CollideEntity::entityDied(e); - if (script) + if (script && e != this && e->isv(EV_ENTITYDIED,1)) { script->call("entityDied", this, e); } From ed5cd03a069f7ddddf2ee77304c0f6e070a4f447 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Thu, 14 Sep 2023 00:02:13 +0200 Subject: [PATCH 10/21] tiny cleanup --- Aquaria/Entity.cpp | 1 - Aquaria/Entity.h | 4 ---- 2 files changed, 5 deletions(-) diff --git a/Aquaria/Entity.cpp b/Aquaria/Entity.cpp index ea941ad..fdcdf20 100644 --- a/Aquaria/Entity.cpp +++ b/Aquaria/Entity.cpp @@ -1566,7 +1566,6 @@ void Entity::onUpdate(float dt) Quad::onUpdate(dt); Vector v = position - lastPos; - lastMove = v; if (position.isFollowingPath() && swimPath) { movementDetails(v); diff --git a/Aquaria/Entity.h b/Aquaria/Entity.h index 915726f..4915403 100644 --- a/Aquaria/Entity.h +++ b/Aquaria/Entity.h @@ -134,7 +134,6 @@ public: Entity *ridingOnEntity; Vector startPos; void rotateToVec(Vector addVec, float time, float offsetAngle=0); - virtual void applyVariation(int variation){} void popBubble(); void sound(const std::string &sound, float freq=1, float fadeOut=0); @@ -167,7 +166,6 @@ public: STATE_FOLLOW =23, STATE_TITLE =24 }; - virtual void onNotify(Entity *notify){} float followPath(Path *p, float speed, int dir, bool deleteOnEnd = false); bool touchAvatarDamage(int radius, float dmg, const Vector &override=Vector(-1,-1,-1), float speed=0, float pushTime = 0, Vector collidePos = Vector(0,0,0)); @@ -205,7 +203,6 @@ public: bool isFollowingPath(); void stopFollowingPath(); void overideMaxSpeed(int ms, float time); - void disableOverideMaxSpeed(); int currentEntityTarget; float moveToPos(Vector pos, float speed, int dieOnPathEnd=0, bool swim = false); bool isHit(); @@ -220,7 +217,6 @@ public: void idle(); void slowToStopPath(float t); bool isSlowingToStopPath(); - Vector lastMove; float damageTime; void setEntityProperty(EntityProperty ep, bool value=true); From 5a9025a2a74d30f9c6f29bf4c8a186b987e31ad7 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Thu, 14 Sep 2023 00:17:39 +0200 Subject: [PATCH 11/21] cleanup legacy entity targets; don't allocate 10 slots up front since barely any entity uses even slot 0 Also fix probably wrong target check in entity_hurtTarget() --- Aquaria/Entity.cpp | 54 +++++++++++++++++-------------------- Aquaria/Entity.h | 13 +++++---- Aquaria/ScriptInterface.cpp | 24 ++++++++--------- 3 files changed, 42 insertions(+), 49 deletions(-) diff --git a/Aquaria/Entity.cpp b/Aquaria/Entity.cpp index fdcdf20..901bf03 100644 --- a/Aquaria/Entity.cpp +++ b/Aquaria/Entity.cpp @@ -206,7 +206,6 @@ Entity::Entity() multColor = Vector(1,1,1); collideRadius = 24; entityType = EntityType(0); - targets.resize(10); frozenTimer = 0; canBeTargetedByAvatar = false; @@ -489,11 +488,8 @@ void Entity::stopFollowingPath() position.stopPath(); } -void Entity::flipToTarget(Vector pos) +void Entity::flipToPos(Vector pos) { - - - if (pos.x > position.x) { if (!isfh()) @@ -506,21 +502,27 @@ void Entity::flipToTarget(Vector pos) } } -Entity* Entity::getTargetEntity(int t) +Entity* Entity::getTargetEntity(size_t t) const { - return targets[t]; + return t < targets.size() ? targets[t] : NULL; } -void Entity::setTargetEntity(Entity *e, int t) +void Entity::setTargetEntity(Entity *e, size_t t) { + if(t < targets.size()) + { + targets[t] = e; + return; + } + + if(!e) + return; + + if(targets.size() <= t) + targets.resize(t + 1); targets[t] = e; } -bool Entity::hasTarget(int t) -{ - return (targets[t]!=0); -} - void Entity::destroy() { if (stopSoundsOnDeath) @@ -1860,25 +1862,21 @@ EntityType Entity::getEntityType() return entityType; } -/* types: - -*/ -Entity *Entity::findTarget(int dist, int type, int t) +Entity *Entity::findTarget(int dist, int type, size_t t) { - targets[t] = 0; + Entity *target = NULL; if (type == ET_AVATAR) { Vector d = game->avatar->position - this->position; if (d.getSquaredLength2D() < sqr(dist)) { - targets[t] = game->avatar; + target = game->avatar; } } else { int closestDist = -1; - Entity *target = 0; FOR_ENTITIES(i) { Entity *e = *i; @@ -1892,12 +1890,10 @@ Entity *Entity::findTarget(int dist, int type, int t) } } } - if (target) - { - targets[t] = target; - } } - return targets[t]; + setTargetEntity(target, t); + + return target; } void Entity::moveTowards(Vector p, float dt, int spd) @@ -1930,15 +1926,15 @@ void Entity::moveAroundAngle(int angle, float dt, int spd, int dir) moveAround(p, dt, spd, dir); } -void Entity::moveTowardsTarget(float dt, int spd, int t) +void Entity::moveTowardsTarget(float dt, int spd, size_t t) { - if (!targets[t]) return; + if (targets.size() < t || !targets[t]) return; moveTowards(targets[t]->position, dt, spd); } -void Entity::moveAroundTarget(float dt, int spd, int dir, int t) +void Entity::moveAroundTarget(float dt, int spd, int dir, size_t t) { - if (!targets[t]) return; + if (targets.size() < t || !targets[t]) return; moveAround(targets[t]->position, dt, spd, dir); } diff --git a/Aquaria/Entity.h b/Aquaria/Entity.h index 4915403..98216a1 100644 --- a/Aquaria/Entity.h +++ b/Aquaria/Entity.h @@ -176,8 +176,8 @@ public: void moveTowardsAngle(int angle, float dt, int spd); void moveAroundAngle(int angle, float dt, int spd, int dir); - void moveTowardsTarget(float dt, int spd, int t=0); - void moveAroundTarget(float dt, int spd, int d, int t=0); + void moveTowardsTarget(float dt, int spd, size_t t=0); + void moveAroundTarget(float dt, int spd, int d, size_t t=0); void moveAroundEntity(float dt, int spd, int d, Entity *e); void moveTowardsGroupCenter(float dt, int spd); void moveTowardsGroupHeading(float dt, int spd); @@ -185,13 +185,12 @@ public: void doSpellAvoidance(float dt, int range, float mod); void doEntityAvoidance(float dt, int range, float mod, Entity *ignore =0); void setMaxSpeed(float ms); - Entity *findTarget(int dist, int type, int t=0); + Entity *findTarget(int dist, int type, size_t t=0); - bool hasTarget(int t=0); bool isTargetInRange(int range, size_t t=0); void doGlint(const Vector &position, const Vector &scale=Vector(2,2), const std::string &tex="Glint", BlendType bt=BLEND_DEFAULT); - Entity *getTargetEntity(int t=0); - void setTargetEntity(Entity *e, int t=0); + Entity *getTargetEntity(size_t t=0) const; + void setTargetEntity(Entity *e, size_t t=0); virtual void activate(Entity *by, int source){} @@ -199,7 +198,7 @@ public: void setEntityType(EntityType et); EntityType getEntityType(); - void flipToTarget(Vector pos); + void flipToPos(Vector pos); bool isFollowingPath(); void stopFollowingPath(); void overideMaxSpeed(int ms, float time); diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 5d10bf6..3d69002 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -5990,7 +5990,7 @@ luaFunc(entity_flipToEntity) Entity *e2 = entity(L, 2); if (e && e2) { - e->flipToTarget(e2->position); + e->flipToPos(e2->position); } luaReturnNil(); } @@ -6002,7 +6002,7 @@ luaFunc(entity_flipToNode) PathNode *n = &p->nodes[0]; if (e && n) { - e->flipToTarget(n->position); + e->flipToPos(n->position); } luaReturnNil(); } @@ -7413,22 +7413,20 @@ luaFunc(entity_setActivationType) luaFunc(entity_hasTarget) { Entity *e = entity(L); - if (e) - luaReturnBool(e->hasTarget(e->currentEntityTarget)); - else - luaReturnBool(false); + luaReturnBool(e && e->getTargetEntity(e->currentEntityTarget)); } luaFunc(entity_hurtTarget) { Entity *e = entity(L); - if (e && e->getTargetEntity()) - { - DamageData d; - d.attacker = e; - d.damage = lua_tointeger(L, 2); - e->getTargetEntity(e->currentEntityTarget)->damage(d); - } + if (e) + if(Entity *t = e->getTargetEntity(e->currentEntityTarget)) + { + DamageData d; + d.attacker = e; + d.damage = lua_tointeger(L, 2); + t->damage(d); + } luaReturnNil(); } From fc920b30407e99ee59d1b93cdb4eb9e81a771c0f Mon Sep 17 00:00:00 2001 From: fgenesis Date: Thu, 14 Sep 2023 00:23:55 +0200 Subject: [PATCH 12/21] Add obj_getRenderPass() Lua func --- Aquaria/ScriptInterface.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 3d69002..fe559a0 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -1633,6 +1633,15 @@ luaFunc(obj_setRenderPass) luaReturnNil(); } +luaFunc(obj_getRenderPass) +{ + RenderObject *r = robj(L); + int pass = 0; + if (r) + pass = r->getRenderPass(); + luaReturnInt(pass); +} + luaFunc(obj_fh) { RenderObject *r = robj(L); @@ -2054,6 +2063,7 @@ luaFunc(quad_getBorderAlpha) RO_FUNC(getter, prefix, setUpdateCull ) \ RO_FUNC(getter, prefix, getUpdateCull ) \ RO_FUNC(getter, prefix, setRenderPass ) \ + RO_FUNC(getter, prefix, getRenderPass ) \ RO_FUNC(getter, prefix, setPositionX ) \ RO_FUNC(getter, prefix, setPositionY ) \ RO_FUNC(getter, prefix, enableMotionBlur ) \ From 67149a5b35e9c31e28d1fc4be11c77e8fcaa20ec Mon Sep 17 00:00:00 2001 From: fgenesis Date: Thu, 14 Sep 2023 01:13:43 +0200 Subject: [PATCH 13/21] Make all LR_* and ACTION_* enum values available to Lua --- Aquaria/CMakeLists.txt | 2 +- Aquaria/GameEnums.cpp | 189 ++++++++++++++++++++++++++++++++++++ Aquaria/GameEnums.h | 33 ++++--- Aquaria/NotEntities.h | 21 ---- Aquaria/ScriptInterface.cpp | 16 +++ 5 files changed, 225 insertions(+), 36 deletions(-) create mode 100644 Aquaria/GameEnums.cpp delete mode 100644 Aquaria/NotEntities.h diff --git a/Aquaria/CMakeLists.txt b/Aquaria/CMakeLists.txt index 35591e5..92e275e 100644 --- a/Aquaria/CMakeLists.txt +++ b/Aquaria/CMakeLists.txt @@ -32,6 +32,7 @@ SET(AQUARIA_SRCS FlockEntity.h Game.cpp Game.h + GameEnums.cpp GameEnums.h GameplayVariables.cpp GameStructs.cpp @@ -60,7 +61,6 @@ SET(AQUARIA_SRCS ModSelector.h Network.cpp Network.h - NotEntities.h ParticleEditor.cpp Path.cpp Path.h diff --git a/Aquaria/GameEnums.cpp b/Aquaria/GameEnums.cpp new file mode 100644 index 0000000..8e06176 --- /dev/null +++ b/Aquaria/GameEnums.cpp @@ -0,0 +1,189 @@ +#include "GameEnums.h" +#include "Base.h" + +// keep in sync with enum Layers +static const char *s_LayerNames[LR_MAX] = +{ + "LR_ZERO", + "LR_BACKDROP", + "LR_BACKGROUND", + "LR_SCENEBACKGROUNDIMAGE", + "LR_BACKDROP_ELEMENTS1", + "LR_BACKDROP_ELEMENTS2", + "LR_ENTITIES_MINUS4_PLACEHOLDER", + "LR_BACKDROP_ELEMENTS3", + "LR_BACKDROP_ELEMENTS4", + "LR_BACKDROP_ELEMENTS5", + "LR_BACKDROP_ELEMENTS6", + "LR_BACKGROUND_ELEMENTS1", + "LR_BACKGROUND_ELEMENTS2", + "LR_ENTITIES_MINUS3_PLACEHOLDER", + "LR_BACKGROUND_ELEMENTS3", + "LR_ENTITIES_MINUS2_PLACEHOLDER", + "LR_BLACKGROUND", + "LR_UPDATE_ELEMENTS_BG", + "LR_ELEMENTS1", + "LR_ELEMENTS2", + "LR_ELEMENTS3", + "LR_ELEMENTS4", + "LR_ELEMENTS5", + "LR_ELEMENTS6", + "LR_ELEMENTS7", + "LR_ELEMENTS8", + "LR_ELEMENTS9", + "LR_ELEMENTS10", + "LR_ELEMENTS11", + "LR_ELEMENTS12", + "LR_ELEMENTS13", + "LR_ELEMENTS14", + "LR_ELEMENTS15", + "LR_ELEMENTS16", + "LR_UPDATE_ELEMENTS_FG", + "LR_ENTITIES_MINUS4", + "LR_ENTITIES_MINUS3", + "LR_ENTITIES_MINUS2", + "LR_ENTITIES00", + "LR_ENTITIES0", + "LR_ENTITIES", + "LR_ENTITIES2", + "LR_WATERSURFACE", + "LR_WATERSURFACE2", + "LR_DARK_LAYER", + "LR_PROJECTILES", + "LR_LIGHTING", + "LR_PARTICLES", + "LR_PARTICLES2", + "LR_FOREGROUND_ELEMENTS1", + "LR_FOREGROUND_ELEMENTS2", + "LR_PARTICLES_TOP", + "LR_AFTER_EFFECTS", + "LR_SCENE_COLOR", + "LR_MENU", + "LR_MENU2", + "LR_HUD", + "LR_HUD2", + "LR_HUD3", + "LR_HUDUNDERLAY", + "LR_MINIMAP", + "LR_RECIPES", + "LR_WORLDMAP", + "LR_WORLDMAPHUD", + "LR_REGISTER_TEXT", + "LR_DAMAGESPRITE", + "LR_HELP", + "LR_TRANSITION", + "LR_OVERLAY", + "LR_FILEMENU", + "LR_CONFIRM", + "LR_CURSOR", + "LR_SUBTITLES", + "LR_PROGRESS", + "LR_DEBUG_TEXT", + "LR_BLACKBARS" +}; + +const char *EnumName(Layers lr) +{ + compile_assert(Countof(s_LayerNames) == LR_MAX); + + return lr < LR_MAX ? s_LayerNames[lr] : NULL; +} + +const char *s_AquariaActionNames_0[ACTION_MAX] = +{ + "ACTION_PRIMARY", + "ACTION_SECONDARY", + "ACTION_ESC", + "ACTION_TOGGLESCENEEDITO", + "ACTION_TOGGLEWORLDMAP", + "ACTION_TOGGLEGRID", + "ACTION_MENULEFT", + "ACTION_MENURIGHT", + "ACTION_MENUUP", + "ACTION_MENUDOWN", + "ACTION_PREVPAGE", + "ACTION_NEXTPAGE", + "ACTION_COOKFOOD", + "ACTION_FOODLEFT", + "ACTION_FOODRIGHT", + "ACTION_FOODDROP", + "ACTION_TOGGLEMENU" +}; + +const char *s_AquariaActionNames_100[ACTION_MAX] = +{ + "ACTION_SWIMUP", + "ACTION_SWIMDOWN", + "ACTION_SWIMLEFT", + "ACTION_SWIMRIGHT", + "ACTION_SINGUP", + "ACTION_SINGDOWN", + "ACTION_SINGLEFT", + "ACTION_SINGRIGHT", + "ACTION_SONGSLOT1", + "ACTION_SONGSLOT2", + "ACTION_SONGSLOT3", + "ACTION_SONGSLOT4", + "ACTION_SONGSLOT5", + "ACTION_SONGSLOT6", + "ACTION_SONGSLOT7", + "ACTION_SONGSLOT8", + "ACTION_SONGSLOT9", + "ACTION_SONGSLOT10", + "ACTION_SONGSLOTEND", + "ACTION_ROLL", + "ACTION_SLOW", + "ACTION_REVERT" +}; + +const char *s_AquariaActionNames_200[ACTION_MAX] = +{ + "ACTION_ZOOMIN", + "ACTION_ZOOMOUT", + "ACTION_CAMLEFT", + "ACTION_CAMRIGHT", + "ACTION_CAMUP", + "ACTION_CAMDOWN", + "ACTION_BONELEFT", + "ACTION_BONERIGHT", + "ACTION_BONEUP", + "ACTION_BONEDOWN", + "ACTION_BGLAYER1", + "ACTION_BGLAYER2", + "ACTION_BGLAYER3", + "ACTION_BGLAYER4", + "ACTION_BGLAYER5", + "ACTION_BGLAYER6", + "ACTION_BGLAYER7", + "ACTION_BGLAYER8", + "ACTION_BGLAYER9", + "ACTION_BGLAYER10", + "ACTION_BGLAYER11", + "ACTION_BGLAYER12", + "ACTION_BGLAYER13", + "ACTION_BGLAYER14", + "ACTION_BGLAYER15", + "ACTION_BGLAYER16", + "ACTION_BGLAYEREND", + "ACTION_MULTISELECT", + "ACTION_TOGGLEWORLDMAPEDITOR", + "ACTION_LOOK", + "ACTION_TOGGLEHELPSCREEN", + "ACTION_PLACE_AVATAR", + "ACTION_SCREENSHOT" +}; + +const char *EnumName(AquariaActions a) +{ + unsigned i = a; + if(i < Countof(s_AquariaActionNames_0)) + return s_AquariaActionNames_0[i]; + i -= 100; // no problem if this underflows + if(i < Countof(s_AquariaActionNames_100)) + return s_AquariaActionNames_100[i]; + i -= 100; + if(i < Countof(s_AquariaActionNames_200)) + return s_AquariaActionNames_200[i]; + + return NULL; +} diff --git a/Aquaria/GameEnums.h b/Aquaria/GameEnums.h index 63690ed..c7d3555 100644 --- a/Aquaria/GameEnums.h +++ b/Aquaria/GameEnums.h @@ -52,21 +52,21 @@ enum CursorType CURSOR_LOOK = 4 }; -enum AquariaActions +enum AquariaActions // Keep in sync with GameEnums.cpp { - ACTION_PRIMARY =0, - ACTION_SECONDARY =1, - ACTION_ESC =2, - ACTION_TOGGLESCENEEDITOR =3, - ACTION_TOGGLEWORLDMAP =4, + ACTION_PRIMARY, + ACTION_SECONDARY, + ACTION_ESC, + ACTION_TOGGLESCENEEDITOR, + ACTION_TOGGLEWORLDMAP, - ACTION_TOGGLEGRID =5, + ACTION_TOGGLEGRID, // Automatically sent on either ACTION_SWIM* or sufficient analog controller input - ACTION_MENULEFT =6, - ACTION_MENURIGHT =7, - ACTION_MENUUP =8, - ACTION_MENUDOWN =9, + ACTION_MENULEFT, + ACTION_MENURIGHT, + ACTION_MENUUP, + ACTION_MENUDOWN, ACTION_PREVPAGE, ACTION_NEXTPAGE, @@ -78,7 +78,7 @@ enum AquariaActions ACTION_TOGGLEMENU, - + // ------------------------ ACTION_SWIMUP = 100, ACTION_SWIMDOWN, ACTION_SWIMLEFT, @@ -106,6 +106,7 @@ enum AquariaActions ACTION_SLOW, // currently unused ACTION_REVERT, + // ------------------------ ACTION_ZOOMIN = 200, ACTION_ZOOMOUT, @@ -144,8 +145,11 @@ enum AquariaActions ACTION_LOOK , ACTION_TOGGLEHELPSCREEN, ACTION_PLACE_AVATAR, - ACTION_SCREENSHOT + ACTION_SCREENSHOT, + + ACTION_MAX }; +const char *EnumName(AquariaActions a); enum AuraType { @@ -232,7 +236,7 @@ enum VisualEffectsType VFX_MAX = 3 }; -enum Layers +enum Layers // keep in sync with GameEnums.cpp { // GAME WILL CLEAR THESE LR_ZERO = 0, @@ -313,6 +317,7 @@ enum Layers LR_BLACKBARS , LR_MAX }; +const char *EnumName(Layers lr); enum IngredientType diff --git a/Aquaria/NotEntities.h b/Aquaria/NotEntities.h deleted file mode 100644 index 565d1ee..0000000 --- a/Aquaria/NotEntities.h +++ /dev/null @@ -1,21 +0,0 @@ -/* -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. -*/ - diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index fe559a0..0217d48 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -11740,6 +11740,20 @@ static const struct { luaConstant(PATHSHAPE_CIRCLE), }; +template +static void luaRegisterEnums(lua_State *L, T first, T last) +{ + assert(first <= last); + for(T i = first; i <= last; i = T(i + 1)) + { + if(const char *name = EnumName(i)) + { + lua_pushinteger(L, i); + lua_setglobal(L, name); + } + } +} + //============================================================================================ // F U N C T I O N S //============================================================================================ @@ -11828,6 +11842,8 @@ lua_State *ScriptInterface::createLuaVM() lua_pushnumber(state, luaConstantTable[i].value); lua_setglobal(state, luaConstantTable[i].name); } + luaRegisterEnums(state, LR_ZERO, LR_MAX); + luaRegisterEnums(state, ACTION_PRIMARY, ACTION_MAX); // Add hooks to monitor global get/set operations if requested. if (complainOnGlobalVar) From 960bd90fc8d2a97ca2a225ec465aee032122224a Mon Sep 17 00:00:00 2001 From: fgenesis Date: Thu, 14 Sep 2023 01:14:22 +0200 Subject: [PATCH 14/21] kill ARRAYSIZE(), there's the safer Countof() --- Aquaria/StatsAndAchievements.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/Aquaria/StatsAndAchievements.cpp b/Aquaria/StatsAndAchievements.cpp index 8576432..164856b 100644 --- a/Aquaria/StatsAndAchievements.cpp +++ b/Aquaria/StatsAndAchievements.cpp @@ -24,10 +24,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "StatsAndAchievements.h" #include "ttvfs_stdio.h" -#ifndef ARRAYSIZE -#define ARRAYSIZE(x) (sizeof (x) / sizeof ((x)[0])) -#endif - #define _ACH_ID( id, name ) { id, #id, name, "", 0, 0 } static Achievement g_rgAchievements[] = @@ -153,7 +149,7 @@ void StatsAndAchievements::RunFrame() { requestedStats = true; - const size_t max_achievements = ARRAYSIZE(g_rgAchievements); + const size_t max_achievements = Countof(g_rgAchievements); VFILE *io = NULL; // Get generic achievement data... @@ -229,7 +225,7 @@ void StatsAndAchievements::RunFrame() // but only if we're not in a mod if (!dsq->mod.isActive()) { - for (size_t iAch = 0; iAch < ARRAYSIZE( g_rgAchievements ); ++iAch ) + for (size_t iAch = 0; iAch < Countof( g_rgAchievements ); ++iAch ) { EvaluateAchievement( g_rgAchievements[iAch] ); } @@ -252,7 +248,7 @@ void StatsAndAchievements::appendStringData(std::string &data) count = 0; data += "Unlocked:\n\n"; - for (size_t iAch = 0; iAch < ARRAYSIZE( g_rgAchievements ); ++iAch ) + for (size_t iAch = 0; iAch < Countof( g_rgAchievements ); ++iAch ) { const Achievement &ach = g_rgAchievements[iAch]; if (!ach.achieved) @@ -271,7 +267,7 @@ void StatsAndAchievements::appendStringData(std::string &data) count = 0; data += "Locked:\n\n"; - for (size_t iAch = 0; iAch < ARRAYSIZE( g_rgAchievements ); ++iAch ) + for (size_t iAch = 0; iAch < Countof( g_rgAchievements ); ++iAch ) { const Achievement &ach = g_rgAchievements[iAch]; if (ach.achieved) @@ -812,7 +808,7 @@ void StatsAndAchievements::StoreStatsIfNecessary() if (io == NULL) return; - const size_t max_achievements = ARRAYSIZE(g_rgAchievements); + const size_t max_achievements = Countof(g_rgAchievements); unsigned char *buf = new unsigned char[max_achievements]; for (size_t i = 0; i < max_achievements; i++) @@ -828,7 +824,7 @@ void StatsAndAchievements::StoreStatsIfNecessary() char cruft[101]; for (size_t i = 0; i < sizeof (cruft); i++) cruft[i] = (char) rand(); - if (fwrite(cruft, sizeof (cruft[0]), ARRAYSIZE(cruft), io) != ARRAYSIZE(cruft)) + if (fwrite(cruft, sizeof (cruft[0]), Countof(cruft), io) != Countof(cruft)) debugLog("Failed to write achievements 2"); fclose(io); From e253069509f79a00d93ebc49bad4dcc51621ef22 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Thu, 14 Sep 2023 01:17:11 +0200 Subject: [PATCH 15/21] stfu dumb msvc analyzer --- Aquaria/GameEnums.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aquaria/GameEnums.cpp b/Aquaria/GameEnums.cpp index 8e06176..3cc9340 100644 --- a/Aquaria/GameEnums.cpp +++ b/Aquaria/GameEnums.cpp @@ -86,7 +86,7 @@ const char *EnumName(Layers lr) { compile_assert(Countof(s_LayerNames) == LR_MAX); - return lr < LR_MAX ? s_LayerNames[lr] : NULL; + return lr < Countof(s_LayerNames) ? s_LayerNames[lr] : NULL; } const char *s_AquariaActionNames_0[ACTION_MAX] = From 60e3c4d7ad5fd5550e92dcdce7b51a25cfada4e2 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Thu, 14 Sep 2023 01:52:44 +0200 Subject: [PATCH 16/21] Fix Lua entityDied() never getting called; botched in bf58fe91c69cbf12200 --- Aquaria/ScriptedEntity.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aquaria/ScriptedEntity.cpp b/Aquaria/ScriptedEntity.cpp index ac36cb7..802b806 100644 --- a/Aquaria/ScriptedEntity.cpp +++ b/Aquaria/ScriptedEntity.cpp @@ -688,7 +688,7 @@ void ScriptedEntity::entityDied(Entity *e) { CollideEntity::entityDied(e); - if (script && e != this && e->isv(EV_ENTITYDIED,1)) + if (script && e != this && isv(EV_ENTITYDIED,1)) { script->call("entityDied", this, e); } From 7cd8f51b47b7c9e42a21853c399dd9b73c9f2519 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sun, 24 Sep 2023 18:04:40 +0200 Subject: [PATCH 17/21] Fix typo in 5a9025a2a74d30f9c that caused crashing --- Aquaria/Entity.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Aquaria/Entity.cpp b/Aquaria/Entity.cpp index 901bf03..5490180 100644 --- a/Aquaria/Entity.cpp +++ b/Aquaria/Entity.cpp @@ -1928,13 +1928,13 @@ void Entity::moveAroundAngle(int angle, float dt, int spd, int dir) void Entity::moveTowardsTarget(float dt, int spd, size_t t) { - if (targets.size() < t || !targets[t]) return; + if (t >= targets.size() || !targets[t]) return; moveTowards(targets[t]->position, dt, spd); } void Entity::moveAroundTarget(float dt, int spd, int dir, size_t t) { - if (targets.size() < t || !targets[t]) return; + if (t >= targets.size() || !targets[t]) return; moveAround(targets[t]->position, dt, spd, dir); } From 56b3439d120ffa30b118f037abe362188f658616 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Wed, 18 Oct 2023 02:16:14 +0200 Subject: [PATCH 18/21] support scaling bones in anim editor --- Aquaria/AnimationEditor.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Aquaria/AnimationEditor.cpp b/Aquaria/AnimationEditor.cpp index 8b88289..b697e59 100644 --- a/Aquaria/AnimationEditor.cpp +++ b/Aquaria/AnimationEditor.cpp @@ -774,6 +774,21 @@ void AnimationEditor::update(float dt) } } + if (editingBone) + { + float m = 0.2f; + if(core->getKeyState(KEY_NUMPADSLASH)) + { + editingBone->originalScale /= (1 + m*dt); + editingBone->scale = editingBone->originalScale; + } + if(core->getKeyState(KEY_NUMPADSTAR)) + { + editingBone->originalScale *= (1 + m*dt); + editingBone->scale = editingBone->originalScale; + } + } + if (editingBone && boneEdit == 1 && !splinegrid) { Vector add = core->mouse.change; From a1037091ad38a5b39dbb5889c140de2c33497245 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Wed, 18 Oct 2023 02:16:37 +0200 Subject: [PATCH 19/21] another int that should be float --- Aquaria/Entity.cpp | 2 +- Aquaria/Entity.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Aquaria/Entity.cpp b/Aquaria/Entity.cpp index 5490180..1d8faaa 100644 --- a/Aquaria/Entity.cpp +++ b/Aquaria/Entity.cpp @@ -85,7 +85,7 @@ BounceType Entity::getBounceType() return bounceType; } -void Entity::generateCollisionMask(int ovrCollideRadius) +void Entity::generateCollisionMask(float ovrCollideRadius) { if (this->skeletalSprite.isLoaded()) { diff --git a/Aquaria/Entity.h b/Aquaria/Entity.h index 98216a1..1c250ad 100644 --- a/Aquaria/Entity.h +++ b/Aquaria/Entity.h @@ -281,7 +281,7 @@ public: float getHealthPerc(); void setDeathScene(bool v); bool isDeathScene() const { return deathScene; } - void generateCollisionMask(int ovrCollideRadius=0); + void generateCollisionMask(float ovrCollideRadius=0); DamageData lastDamage; bool checkSplash(const Vector &override=Vector(0,0,0)); EatData eatData; From 83e3739340be626d141616016cbdc78422b6153f Mon Sep 17 00:00:00 2001 From: fgenesis Date: Tue, 24 Oct 2023 22:58:13 +0200 Subject: [PATCH 20/21] AnimationEditor: support copy absolute bone scale to clipboard --- Aquaria/AnimationEditor.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Aquaria/AnimationEditor.cpp b/Aquaria/AnimationEditor.cpp index b697e59..2cde2b3 100644 --- a/Aquaria/AnimationEditor.cpp +++ b/Aquaria/AnimationEditor.cpp @@ -209,6 +209,18 @@ void AnimationEditor::resetScaleOrSave() if (core->getCtrlState()) saveFile(); + else if(core->getAltState() && editingBone) + { + Vector scale(1,1); + Bone *b = editingBone; + do + scale *= b->scale; + while( (b = dynamic_cast(b->getParent())) ); // don't want to get entity scale; that's what the anim editor uses for zooming + std::ostringstream os; + os << scale.x; + if(!SDL_SetClipboardText(os.str().c_str())) + dsq->screenMessage("Scale copied to clipboard"); + } else editSprite->scale = Vector(1,1); } From 9fd024daddefbbc4a1b09be3da226df9cee00f4c Mon Sep 17 00:00:00 2001 From: fgenesis Date: Tue, 24 Oct 2023 23:05:33 +0200 Subject: [PATCH 21/21] Support h-flipping hair, minor hair cleanup, add Lua functions: + entity_exertHairSegmentForce + entity_setHairTextureFlip + entity_setHairWidth Sadly obj_fh() doesn't work on hairs for some reason and it just turns invisible --- Aquaria/Hair.cpp | 81 +++++++++++++++++-------------------- Aquaria/Hair.h | 9 ++--- Aquaria/ScriptInterface.cpp | 31 ++++++++++++++ 3 files changed, 71 insertions(+), 50 deletions(-) diff --git a/Aquaria/Hair.cpp b/Aquaria/Hair.cpp index 3509644..eb6a5de 100644 --- a/Aquaria/Hair.cpp +++ b/Aquaria/Hair.cpp @@ -29,6 +29,7 @@ Hair::Hair(int nodes, float segmentLength, float hairWidth) : RenderObject() { this->segmentLength = segmentLength; this->hairWidth = hairWidth; + this->_hairfh = false; cull = false; @@ -41,22 +42,12 @@ Hair::Hair(int nodes, float segmentLength, float hairWidth) : RenderObject() if (perc < 0) perc = 0; hairNodes[i].percent = 1.0f-perc; - hairNodes[i].position = hairNodes[i].originalPosition = hairNodes[i].defaultPosition = Vector(0, i*segmentLength, 0); + Vector p(0, i*segmentLength, 0); + hairNodes[i].position = p; + hairNodes[i].defaultPosition = p; } } -void Hair::exertWave(float dt) -{ - - -} - -void Hair::exertGravityWave(float dt) -{ - - -} - void Hair::setHeadPosition(const Vector &vec) { hairNodes[0].position = vec; @@ -75,46 +66,29 @@ HairNode *Hair::getHairNode(int idx) void Hair::onRender(const RenderState& rs) const { - - glBegin(GL_QUAD_STRIP); - float texBits = 1.0f / (hairNodes.size()-1); + const float texBits = 1.0f / (hairNodes.size()-1); + const Vector mul = !_hairfh ? Vector(1, 1) : Vector(-1, -1); Vector pl, pr; for (size_t i = 0; i < hairNodes.size(); i++) { - - if (i != hairNodes.size()-1) { Vector diffVec = hairNodes[i+1].position - hairNodes[i].position; diffVec.setLength2D(hairWidth); - pl = diffVec.getPerpendicularLeft(); - pr = diffVec.getPerpendicularRight(); + pl = diffVec.getPerpendicularLeft() * mul; + pr = diffVec.getPerpendicularRight() * mul; } - + Vector p = hairNodes[i].position; glTexCoord2f(0, texBits*i); - glVertex3f(hairNodes[i].position.x + pl.x, hairNodes[i].position.y + pl.y, 0); + glVertex3f(p.x + pl.x, p.y + pl.y, 0); glTexCoord2f(1, texBits*i); - glVertex3f( hairNodes[i].position.x + pr.x, hairNodes[i].position.y + pr.y, 0); - - - + glVertex3f(p.x + pr.x, p.y + pr.y, 0); } glEnd(); - - - -} - -void Hair::onUpdate(float dt) -{ - RenderObject::onUpdate(dt); - - - } void Hair::updatePositions() @@ -137,11 +111,7 @@ void Hair::updatePositions() hairNodes[i].position = hairNodes[i-1].position + diff; } - - } - - } void Hair::returnToDefaultPositions(float dt) @@ -162,23 +132,44 @@ void Hair::returnToDefaultPositions(float dt) void Hair::exertForce(const Vector &force, float dt, int usePerc) { - + const Vector f = force * dt; for (int i = hairNodes.size()-1; i >= 1; i--) { switch (usePerc) { case 0: - hairNodes[i].position += force*dt*hairNodes[i].percent; + hairNodes[i].position += f * hairNodes[i].percent; break; case 1: - hairNodes[i].position += force*dt*(1.0f-hairNodes[i].percent); + hairNodes[i].position += f * (1.0f-hairNodes[i].percent); break; case 2: default: - hairNodes[i].position += force*dt; + hairNodes[i].position += f; break; } } } +void Hair::exertNodeForce(size_t i, const Vector& force, float dt, int usePerc) +{ + const Vector f = force * dt; + if(i >= hairNodes.size()) + return; + + switch (usePerc) + { + case 0: + hairNodes[i].position += f * hairNodes[i].percent; + break; + case 1: + hairNodes[i].position += f * (1.0f-hairNodes[i].percent); + break; + case 2: + default: + hairNodes[i].position += f; + break; + } +} + diff --git a/Aquaria/Hair.h b/Aquaria/Hair.h index e195040..8e2ae49 100644 --- a/Aquaria/Hair.h +++ b/Aquaria/Hair.h @@ -25,14 +25,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. struct HairNode { - HairNode() : percent(0), problem(false), angleDiff(0) + HairNode() : percent(0) {} float percent; // percent of how much force is affected on this node Vector position; // position of the hair node Vector defaultPosition; // default position of the hair node - Vector originalPosition; - bool problem; - float angleDiff; }; class Hair : public RenderObject @@ -41,8 +38,10 @@ public: Hair(int nodes=40, float segmentLength=3, float width=18); void exertForce(const Vector &force, float dt, int usePerc=0); + void exertNodeForce(size_t idx, const Vector &force, float dt, int usePerc=0); void updatePositions(); void returnToDefaultPositions(float dt); + void setTextureFlip(bool flip) { _hairfh = flip; } float hairWidth; @@ -55,8 +54,8 @@ public: HairNode *getHairNode(int idx); protected: float segmentLength; - void onUpdate(float dt) OVERRIDE; void onRender(const RenderState& rs) const OVERRIDE; + bool _hairfh; }; #endif diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 0217d48..2bba764 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -8351,6 +8351,34 @@ luaFunc(entity_exertHairForce) luaReturnNil(); } +// entity idx x y dt +luaFunc(entity_exertHairSegmentForce) +{ + ScriptedEntity *se = scriptedEntity(L); + if (se) + { + if (se->hair) + se->hair->exertNodeForce(lua_tointeger(L, 2), Vector(lua_tonumber(L, 3), lua_tonumber(L, 4)), lua_tonumber(L, 5), lua_tonumber(L, 6)); + } + luaReturnNil(); +} + +luaFunc(entity_setHairTextureFlip) +{ + ScriptedEntity *se = scriptedEntity(L); + if (se && se->hair) + se->hair->setTextureFlip(getBool(L, 2)); + luaReturnNil(); +} + +luaFunc(entity_setHairWidth) +{ + ScriptedEntity *se = scriptedEntity(L); + if (se && se->hair) + se->hair->hairWidth = lua_tonumber(L, 2); + luaReturnNil(); +} + luaFunc(entity_initPart) { std::string partName(getString(L, 2)); @@ -10721,6 +10749,9 @@ static const struct { luaRegister(entity_setHairHeadPosition), luaRegister(entity_updateHair), luaRegister(entity_exertHairForce), + luaRegister(entity_exertHairSegmentForce), + luaRegister(entity_setHairTextureFlip), + luaRegister(entity_setHairWidth), luaRegister(entity_setName),