From 111cd438053335222f83b0905504129ebc9672e5 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Wed, 18 May 2022 02:15:19 +0200 Subject: [PATCH] Move members related to collision mask from RenderObject to Bone --- Aquaria/DSQ.cpp | 11 ++----- Aquaria/DSQ.h | 1 - Aquaria/Game.cpp | 2 +- Aquaria/Game.h | 2 +- BBGE/RenderObject.cpp | 70 +---------------------------------------- BBGE/RenderObject.h | 7 +---- BBGE/SkeletalSprite.cpp | 68 +++++++++++++++++++++++++++++++++++++++ BBGE/SkeletalSprite.h | 7 +++++ 8 files changed, 81 insertions(+), 87 deletions(-) diff --git a/Aquaria/DSQ.cpp b/Aquaria/DSQ.cpp index be175c3..0fff6c2 100644 --- a/Aquaria/DSQ.cpp +++ b/Aquaria/DSQ.cpp @@ -2923,9 +2923,9 @@ void DSQ::doSaveSlotMenu(SaveSlotMode ssm, const Vector &position) std::string DSQ::getEntityFlagName(Entity *e) { - if (!dsq->game) return ""; + if (!game) return ""; std::ostringstream os; - os << dsq->game->sceneName << e->startPos.x << e->startPos.y; + os << game->sceneName << e->startPos.x << e->startPos.y; return os.str(); } @@ -2947,13 +2947,6 @@ void doAlphabetInputKey(int d, char c, char map[], std::string *text, char upper } } -void DSQ::generateCollisionMask(RenderObject *r) -{ - Quad *q = dynamic_cast(r); - if (q) - game->generateCollisionMask(q); -} - void DSQ::onConfirmYes() { dsq->confirmDone = 1; diff --git a/Aquaria/DSQ.h b/Aquaria/DSQ.h index 246a374..6206ed5 100644 --- a/Aquaria/DSQ.h +++ b/Aquaria/DSQ.h @@ -258,7 +258,6 @@ public: void takeScreenshotKey(); - void generateCollisionMask(RenderObject *r); void toggleRenderCollisionShapes(); void voice(const std::string &file, float volMod = -1); diff --git a/Aquaria/Game.cpp b/Aquaria/Game.cpp index 9bcc65a..b2189d7 100644 --- a/Aquaria/Game.cpp +++ b/Aquaria/Game.cpp @@ -1067,7 +1067,7 @@ void Game::setTimerText(float time) timerText->setText(os.str()); } -void Game::generateCollisionMask(Quad *q, float overrideCollideRadius /* = 0 */) +void Game::generateCollisionMask(Bone *q, float overrideCollideRadius /* = 0 */) { if (q->texture) { diff --git a/Aquaria/Game.h b/Aquaria/Game.h index 48371df..e91b688 100644 --- a/Aquaria/Game.h +++ b/Aquaria/Game.h @@ -304,7 +304,7 @@ public: void setTimerTextAlpha(float a, float t); void setTimerText(float time); - void generateCollisionMask(Quad *q, float overrideCollideRadius=0); + void generateCollisionMask(Bone *q, float overrideCollideRadius=0); std::string fromScene, toNode; int toFlip; char fromWarpType; diff --git a/BBGE/RenderObject.cpp b/BBGE/RenderObject.cpp index f8a7fc9..9dd513a 100644 --- a/BBGE/RenderObject.cpp +++ b/BBGE/RenderObject.cpp @@ -136,7 +136,6 @@ RenderObject::RenderObject() overrideCullRadiusSqr = 0; repeatTexture = false; alphaMod = 1; - collisionMaskRadius = 0; collideRadius = 0; motionBlurTransition = false; motionBlurFrameOffsetCounter = 0; @@ -770,44 +769,7 @@ void RenderObject::renderCall() void RenderObject::renderCollision() { - if (!collisionMask.empty()) - { - glPushAttrib(GL_ALL_ATTRIB_BITS); - glPushMatrix(); - glBindTexture(GL_TEXTURE_2D, 0); - - - - glLoadIdentity(); - core->setupRenderPositionAndScale(); - - - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - glColor4f(1,1,0,0.5); - - for (size_t i = 0; i < transformedCollisionMask.size(); i++) - { - Vector collide = this->transformedCollisionMask[i]; - - - - glTranslatef(collide.x, collide.y, 0); - RenderObject *parent = this->getTopParent(); - if (parent) - drawCircle(collideRadius*parent->scale.x, 45); - glTranslatef(-collide.x, -collide.y, 0); - } - - - glDisable(GL_BLEND); - glPopMatrix(); - glPopAttrib(); - - - } - else if (collideRadius > 0) + if (collideRadius > 0) { glPushMatrix(); glLoadIdentity(); @@ -818,8 +780,6 @@ void RenderObject::renderCollision() glTranslatef(internalOffset.x, internalOffset.y, 0); glEnable(GL_BLEND); - - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(1,0,0,0.5); drawCircle(collideRadius, 8); @@ -840,34 +800,6 @@ void RenderObject::deathNotify(RenderObject *r) deathNotifications.remove(r); } -Vector RenderObject::getCollisionMaskNormal(size_t index) -{ - Vector sum; - size_t num=0; - for (size_t i = 0; i < this->transformedCollisionMask.size(); i++) - { - if (i != index) - { - Vector diff = transformedCollisionMask[index] - transformedCollisionMask[i]; - if (diff.isLength2DIn(128)) - { - sum += diff; - num++; - } - } - } - if (!sum.isZero()) - { - sum /= num; - - sum.normalize2D(); - - - } - - return sum; -} - void RenderObject::lookAt(const Vector &pos, float t, float minAngle, float maxAngle, float offset) { Vector myPos = this->getWorldPosition(); diff --git a/BBGE/RenderObject.h b/BBGE/RenderObject.h index 4784817..bf605fa 100644 --- a/BBGE/RenderObject.h +++ b/BBGE/RenderObject.h @@ -217,8 +217,6 @@ public: virtual void unloadDevice(); virtual void reloadDevice(); - Vector getCollisionMaskNormal(size_t index); - //-------------------------------- Methods above, fields below static bool renderCollisionShape; @@ -271,10 +269,7 @@ public: float collideRadius; - std::vector collisionMask; - std::vector transformedCollisionMask; - float collisionMaskRadius; float alphaMod; @@ -311,7 +306,7 @@ protected: bool hasRenderPass(const int pass); inline void renderCall(); - void renderCollision(); + virtual void renderCollision(); bool repeatTexture; unsigned char pm; // unsigned char to save space diff --git a/BBGE/SkeletalSprite.cpp b/BBGE/SkeletalSprite.cpp index 895db3a..bc5c93f 100644 --- a/BBGE/SkeletalSprite.cpp +++ b/BBGE/SkeletalSprite.cpp @@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "MathFunctions.h" #include "SimpleIStringStream.h" #include "ReadXML.h" +#include "RenderBase.h" #include using namespace tinyxml2; @@ -77,6 +78,7 @@ Bone::Bone() : Quad() boneIdx = pidx = -1; rbp = false; segmentChain = 0; + collisionMaskRadius = 0; minDist = maxDist = 128; reverse = false; @@ -295,6 +297,72 @@ void Bone::spawnParticlesFromCollisionMask(const char *p, unsigned intv, int lay } } +void Bone::renderCollision() +{ + if (!collisionMask.empty()) + { + glPushAttrib(GL_ALL_ATTRIB_BITS); + glPushMatrix(); + glBindTexture(GL_TEXTURE_2D, 0); + + glLoadIdentity(); + core->setupRenderPositionAndScale(); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glColor4f(1,1,0,0.5); + + for (size_t i = 0; i < transformedCollisionMask.size(); i++) + { + Vector collide = this->transformedCollisionMask[i]; + + + + glTranslatef(collide.x, collide.y, 0); + RenderObject *parent = this->getTopParent(); + if (parent) + drawCircle(collideRadius*parent->scale.x, 45); + glTranslatef(-collide.x, -collide.y, 0); + } + + + glDisable(GL_BLEND); + glPopMatrix(); + glPopAttrib(); + } + else + Quad::renderCollision(); +} + +Vector Bone::getCollisionMaskNormal(size_t index) +{ + Vector sum; + size_t num=0; + for (size_t i = 0; i < this->transformedCollisionMask.size(); i++) + { + if (i != index) + { + Vector diff = transformedCollisionMask[index] - transformedCollisionMask[i]; + if (diff.isLength2DIn(128)) + { + sum += diff; + num++; + } + } + } + if (!sum.isZero()) + { + sum /= num; + + sum.normalize2D(); + + + } + + return sum; +} + bool BoneCommand::parse(Bone *b, SimpleIStringStream &is) { diff --git a/BBGE/SkeletalSprite.h b/BBGE/SkeletalSprite.h index 126ead6..d09d46d 100644 --- a/BBGE/SkeletalSprite.h +++ b/BBGE/SkeletalSprite.h @@ -92,11 +92,18 @@ public: int originalRenderPass; // stores the render pass originally set in the XML file. For AC_RESET_PASS. void spawnParticlesFromCollisionMask(const char *p, unsigned intv, int layer, float rotz = 0); + Vector getCollisionMaskNormal(size_t index); + + virtual void renderCollision(); protected: std::vector emitters; int minDist, maxDist, reverse; std::vector segments; +public: + std::vector collisionMask; + std::vector transformedCollisionMask; + float collisionMaskRadius; }; class BoneCommand