From 1705b091aaa734a7358e3ad17bae3be3b8d0603a Mon Sep 17 00:00:00 2001 From: fgenesis Date: Thu, 13 Dec 2012 18:33:58 +0100 Subject: [PATCH 001/103] Fix influenced particles not positioned correctly if SpawnLocal = 1 --- BBGE/ParticleManager.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/BBGE/ParticleManager.cpp b/BBGE/ParticleManager.cpp index bd19c51..030c064 100644 --- a/BBGE/ParticleManager.cpp +++ b/BBGE/ParticleManager.cpp @@ -155,6 +155,9 @@ void ParticleManager::updateParticle(Particle *p, float dt) if (suckPos) { Vector dir = (*suckPos) - p->emitter->getWorldCollidePosition(p->pos); + //HACK: what? -> + if (!p->emitter->data.spawnLocal && p->emitter->getParent()) + dir += p->emitter->getParent()->position; dir.setLength2D(p->emitter->data.suckStr); p->vel += dir * dt; } From 5d7466532386094f81a543a6b92b36bf25dd6a2a Mon Sep 17 00:00:00 2001 From: fgenesis Date: Thu, 13 Dec 2012 18:36:13 +0100 Subject: [PATCH 002/103] Faster mousewheel zoom for SceneEditor + reload songbank when reloading a map in the editor --- Aquaria/SceneEditor.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Aquaria/SceneEditor.cpp b/Aquaria/SceneEditor.cpp index bfe068d..81e0aa2 100644 --- a/Aquaria/SceneEditor.cpp +++ b/Aquaria/SceneEditor.cpp @@ -2594,6 +2594,7 @@ void SceneEditor::loadScene() Shot::loadShotBank(dsq->shotBank1, dsq->shotBank2); dsq->game->loadEntityTypeList(); dsq->loadElementEffects(); + dsq->continuity.loadSongBank(); } void SceneEditor::saveScene() @@ -3563,14 +3564,14 @@ void SceneEditor::update(float dt) if (core->getShiftState() && !core->getCtrlState()) // hackish: to prevent accidental recache() nextElement(); else - zoom /= 1.05f; + zoom /= 1.12f; } else if (core->mouse.scrollWheelChange > 0) { if (core->getShiftState() && !core->getCtrlState()) // hackish: to prevent accidental entity selection prevElement(); else - zoom *= 1.05f; + zoom *= 1.12f; } if (zoom.x < 0.04f) zoom.x = zoom.y = 0.04f; From b242d80c7501c0421867f0fbe62a47198fabed0a Mon Sep 17 00:00:00 2001 From: fgenesis Date: Thu, 13 Dec 2012 18:45:07 +0100 Subject: [PATCH 003/103] Some fixes (...) - Get colliding hair segment - drop AnimatedSprite & Interpolator classes - repair entity_setAutoSkeletalUpdate() - remove some old code --- Aquaria/Avatar.cpp | 84 +------------------------------------ Aquaria/Avatar.h | 12 ------ Aquaria/Entity.cpp | 10 ++--- Aquaria/Entity.h | 5 +-- Aquaria/Game.cpp | 25 ++++++----- Aquaria/Game.h | 2 +- Aquaria/ScriptInterface.cpp | 16 ++++++- Aquaria/ScriptedEntity.cpp | 8 +--- Aquaria/ScriptedEntity.h | 1 - CMakeLists.txt | 4 +- 10 files changed, 38 insertions(+), 129 deletions(-) diff --git a/Aquaria/Avatar.cpp b/Aquaria/Avatar.cpp index c2d43f5..d75802f 100644 --- a/Aquaria/Avatar.cpp +++ b/Aquaria/Avatar.cpp @@ -4584,7 +4584,6 @@ Avatar::Avatar() : Entity(), ActionMapper() this->pushingOffWallEffect = 0; lockToWallFallTimer = 0; swimming = false; - dodgeDelay = 0; charging = false; bursting = false; animatedBurst = false; @@ -4595,8 +4594,6 @@ Avatar::Avatar() : Entity(), ActionMapper() splashDelay = 0; avatar = this; - frame = 0; - particleDelay = 0; swimming = false; @@ -5006,44 +5003,6 @@ void Avatar::setActiveSpell(Spells spell) } */ -void Avatar::dodge(std::string dir) -{ - if (bursting) return; - if (!canMove) return; - if (dodgeDelay == 0) - { - Vector mov; - - if (dir == "right") - mov = Vector(1,0); - else if (dir == "left") - mov = Vector(-1, 0); - else if (dir == "down") - mov = Vector(0, 1); - else if (dir == "up") - mov = Vector(0, -1); - - Vector lastPosition = position; - //position += mov * 80; - - dodgeVec = mov * 8000; - vel += mov * vars->maxDodgeSpeed; - //dodgeEffectTimer = 0.125; - state.dodgeEffectTimer.start(/*0.125*/vars->dodgeTime); - /* - float vlen = vel.getLength2D(); - mov |= 500; - vel += mov; - */ - /* - if (dsq->game->collideCircleWithGrid(position, 24)) - { - position = lastPosition; - } - */ - } -} - void Avatar::startBackFlip() { if (boneLock.on) return; @@ -5284,29 +5243,6 @@ void Avatar::startWallBurst(bool useCursor) } } -void Avatar::doDodgeInput(const std::string &action, int s) -{ - if (s) - { - if (tapped.empty()) - { - tapped = action; - state.tapTimer.start(0.25); - } - else if (tapped == action) - { - if (state.tapTimer.isActive()) - dodge(action); - tapped = ""; - dodgeDelay = 1.0; - } - else - { - tapped = ""; - } - } -} - Vector Avatar::getKeyDir() { Vector dir; @@ -5983,13 +5919,7 @@ int Avatar::getBeamWidth() void Avatar::onEnterState(int action) { Entity::onEnterState(action); - if (action == STATE_TRANSFORM) - { - animator.stop(); - frame = 0; - animate(anim_fish); - } - else if (action == STATE_PUSH) + if (action == STATE_PUSH) { state.lockedToWall = false; state.crawlingOnWall = false; @@ -7983,10 +7913,6 @@ void Avatar::onUpdate(float dt) { } - if (state.tapTimer.updateCheck(dt)) - { - tapped = ""; - } if (pushingOffWallEffect > 0) { pushingOffWallEffect -= dt; @@ -8035,14 +7961,6 @@ void Avatar::onUpdate(float dt) } } */ - if (dodgeDelay > 0) - { - dodgeDelay -= dt; - if (dodgeDelay <= 0) - { - dodgeDelay = 0; - } - } if (text) { diff --git a/Aquaria/Avatar.h b/Aquaria/Avatar.h index b4232f5..93cc73d 100644 --- a/Aquaria/Avatar.h +++ b/Aquaria/Avatar.h @@ -127,7 +127,6 @@ public: float shotDelay; //Timer shockTimer; Timer useItemDelay; - Timer tapTimer; Timer lockToWallDelay; float spellCharge; bool lockedToWall; @@ -151,8 +150,6 @@ public: virtual ~Avatar(); void destroy(); void action(int actionID, int state); - // anim data - AnimData anim_swim, anim_stopTransition, anim_idle, anim_idle2, anim_burst, anim_fish; AvatarState state; void setIgnoreInputDelay(float delay) { @@ -518,19 +515,10 @@ protected: bool charging; - AnimData tongueAnim; - - //Quad *chargeGraphic; - - Vector lastPush; - std::string tapped; - float dodgeDelay; float pushingOffWallEffect; float lockToWallFallTimer; - void dodge(std::string dir); - void doDodgeInput(const std::string &action, int state); Vector dodgeVec; Vector wallPushVec, wallTurnVec; diff --git a/Aquaria/Entity.cpp b/Aquaria/Entity.cpp index 54a4e9a..4dd5c95 100644 --- a/Aquaria/Entity.cpp +++ b/Aquaria/Entity.cpp @@ -501,9 +501,9 @@ void Entity::followPath(Path *p, int speedType, int dir, bool deleteOnEnd) position.data->path.addPathNode(pn.position, float(i/float(p->nodes.size()))); } } - debugLog("Calculating Time"); + //debugLog("Calculating Time"); float time = position.data->path.getLength()/(float)dsq->continuity.getSpeedType(speedType); - debugLog("Starting"); + //debugLog("Starting"); position.data->path.getPathNode(0)->value = position; position.startPath(time);//, 1.0f/2.0f); } @@ -1266,7 +1266,7 @@ void Entity::update(float dt) //skeletalSprite.setFreeze(true); if (frozenTimer == 0 || getState() == STATE_PUSH) - AnimatedSprite::update(dt); + Quad::update(dt); onAlwaysUpdate(dt); // always, always update: @@ -1873,7 +1873,7 @@ void Entity::onUpdate(float dt) } } - AnimatedSprite::onUpdate(dt); + Quad::onUpdate(dt); Vector v = position - lastPos; lastMove = v; @@ -2971,7 +2971,7 @@ void Entity::render() blurShader.bind(); set = true; } - AnimatedSprite::render(); + Quad::render(); //if (beautyFlip && blurShader.isLoaded() && flipScale.isInterpolating()) if (set) blurShader.unbind(); diff --git a/Aquaria/Entity.h b/Aquaria/Entity.h index cc4d125..646cb6d 100644 --- a/Aquaria/Entity.h +++ b/Aquaria/Entity.h @@ -21,7 +21,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef ENTITY_H #define ENTITY_H -#include "../BBGE/AnimatedSprite.h" #include "../BBGE/StateMachine.h" #include "../ExternalLibs/tinyxml.h" #include "../BBGE/SkeletalSprite.h" @@ -195,7 +194,7 @@ enum BounceType BOUNCE_REAL = 1 }; -class Entity : public AnimatedSprite, public StateMachine +class Entity : public Quad, public StateMachine { public: Entity(); @@ -592,7 +591,7 @@ protected: void updateBoneLock(); int pushMaxSpeed; - + std::string currentAnim; protected: diff --git a/Aquaria/Game.cpp b/Aquaria/Game.cpp index 68d699b..fd07cb8 100644 --- a/Aquaria/Game.cpp +++ b/Aquaria/Game.cpp @@ -8346,26 +8346,25 @@ bool Game::collideCircleVsCircle(Entity *a, Entity *b) return (a->position - b->position).isLength2DIn(a->collideRadius + b->collideRadius); } -bool Game::collideHairVsCircle(Entity *a, int num, const Vector &pos2, int radius, float perc) +bool Game::collideHairVsCircle(Entity *a, int num, const Vector &pos2, int radius, float perc, int *colSegment) { if (perc == 0) perc = 1; bool c = false; - if (a->hair) + if (a && a->hair) { - if (a) + if (num == 0) + num = a->hair->hairNodes.size(); + // HACK: minus 2 + for (int i = 0; i < num; i++) { - if (num == 0) - num = a->hair->hairNodes.size(); - // HACK: minus 2 - for (int i = 0; i < num; i++) + // + a->hair->position + c = ((a->hair->hairNodes[i].position) - pos2).isLength2DIn(a->hair->hairWidth*perc + radius); + if (c) { - // + a->hair->position - c = ((a->hair->hairNodes[i].position) - pos2).isLength2DIn(a->hair->hairWidth*perc + radius); - if (c) - { - return true; - } + if (colSegment) + *colSegment = i; + return true; } } } diff --git a/Aquaria/Game.h b/Aquaria/Game.h index c7789ee..258687c 100644 --- a/Aquaria/Game.h +++ b/Aquaria/Game.h @@ -677,7 +677,7 @@ public: bool collideBoxWithGrid(const Vector& position, int w, int h); bool collideCircleWithGrid(const Vector& position, int r); - bool collideHairVsCircle(Entity *a, int num, const Vector &pos2, int radius, float perc=0); + bool collideHairVsCircle(Entity *a, int num, const Vector &pos2, int radius, float perc=0, int *colSegment=0); bool collideCircleVsCircle(Entity *a, Entity *b); Bone *collideSkeletalVsCircle(Entity *skeletal, Entity *circle); diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 303e3af..43bbd08 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -4140,9 +4140,16 @@ luaFunc(entity_collideHairVsCircle) int num = lua_tonumber(L, 3); // perc: percent of hairWidth to use as collide radius float perc = lua_tonumber(L, 4); - col = dsq->game->collideHairVsCircle(e, num, e2->position, e2->collideRadius, perc); + int colSegment; + col = dsq->game->collideHairVsCircle(e, num, e2->position, e2->collideRadius, perc, &colSegment); + if(col) + { + lua_pushboolean(L, true); + lua_pushinteger(L, colSegment); + return 2; + } } - luaReturnBool(col); + luaReturnBool(false); } luaFunc(entity_collideSkeletalVsCircleForListByName) @@ -4276,7 +4283,12 @@ luaFunc(entity_updateSkeletal) { Entity *e = entity(L); if (e) + { + bool oldIgnore = e->skeletalSprite.ignoreUpdate; + e->skeletalSprite.ignoreUpdate = false; e->skeletalSprite.update(lua_tonumber(L, 2)); + e->skeletalSprite.ignoreUpdate = oldIgnore; + } luaReturnNil(); } diff --git a/Aquaria/ScriptedEntity.cpp b/Aquaria/ScriptedEntity.cpp index 90e7e04..92c485f 100644 --- a/Aquaria/ScriptedEntity.cpp +++ b/Aquaria/ScriptedEntity.cpp @@ -30,7 +30,6 @@ ScriptedEntity::ScriptedEntity(const std::string &scriptName, Vector position, E { addType(SCO_SCRIPTED_ENTITY); crushDelay = 0; - autoSkeletalSpriteUpdate = true; script = 0; songNoteFunction = songNoteDoneFunction = true; addChild(&pullEmitter, PM_STATIC); @@ -83,7 +82,7 @@ ScriptedEntity::ScriptedEntity(const std::string &scriptName, Vector position, E void ScriptedEntity::setAutoSkeletalUpdate(bool v) { - autoSkeletalSpriteUpdate = v; + skeletalSprite.ignoreUpdate = !v; } void ScriptedEntity::message(const std::string &msg, int v) @@ -640,13 +639,8 @@ void ScriptedEntity::onUpdate(float dt) } */ - if (!autoSkeletalSpriteUpdate) - skeletalSprite.ignoreUpdate = true; - CollideEntity::onUpdate(dt); - if (!autoSkeletalSpriteUpdate) - skeletalSprite.ignoreUpdate = false; //updateStrands(dt); if (becomeSolidDelay) diff --git a/Aquaria/ScriptedEntity.h b/Aquaria/ScriptedEntity.h index a838728..8a1eb4e 100644 --- a/Aquaria/ScriptedEntity.h +++ b/Aquaria/ScriptedEntity.h @@ -93,7 +93,6 @@ protected: void onDieEaten(); void luaDebugMsg(const std::string &func, const std::string &msg); float crushDelay; - bool autoSkeletalSpriteUpdate; int beforePullMaxSpeed; bool songNoteFunction, preUpdateFunc; bool songNoteDoneFunction; diff --git a/CMakeLists.txt b/CMakeLists.txt index 204c987..8c160d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -373,7 +373,6 @@ SET(BBGE_SRCS ${BBGEDIR}/ActionMapper.cpp ${BBGEDIR}/ActionSet.cpp ${BBGEDIR}/AfterEffect.cpp - ${BBGEDIR}/AnimatedSprite.cpp ${BBGEDIR}/Base.cpp ${BBGEDIR}/BitmapFont.cpp ${BBGEDIR}/Collision.cpp @@ -387,7 +386,6 @@ SET(BBGE_SRCS ${BBGEDIR}/Flags.cpp ${BBGEDIR}/FrameBuffer.cpp ${BBGEDIR}/Gradient.cpp - ${BBGEDIR}/Interpolator.cpp ${BBGEDIR}/Joystick.cpp ${BBGEDIR}/LensFlare.cpp ${BBGEDIR}/Localization.cpp @@ -460,12 +458,14 @@ SET(PNG_SRCS # Apparently not used at the moment. Listed here just for completeness. SET(BBGE_SRCS_UNUSED + ${BBGEDIR}/AnimatedSprite.cpp ${BBGEDIR}/BloomEffect.cpp ${BBGEDIR}/CShim.cpp ${BBGEDIR}/Cutscene.cpp ${BBGEDIR}/Datafile.cpp ${BBGEDIR}/DFSprite.cpp ${BBGEDIR}/FileVars.cpp + ${BBGEDIR}/Interpolator.cpp ${BBGEDIR}/Light.cpp ${BBGEDIR}/LightCone.cpp ${BBGEDIR}/Model.cpp From 8b67ece9075a0135b8e2a63b976609ee6249b3b7 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Thu, 13 Dec 2012 19:48:47 +0100 Subject: [PATCH 004/103] Changed a bunch of enums in Entity.h This simplifies a few things. First, the values of DamageType are now continous, with the benefit that they can now be stored in a std::bitset. Second, this repairs entity_getNearestEntity(..., ET_AVATAR) or DT_ENEMY as param, because these were 0, but the game expected -1 as universal value. This way, any entity was returned when querying for ET_AVATAR or DT_ENEMY. Now, 0 is the universal/NONE value, which should avoid mistakes like this. --- Aquaria/Entity.cpp | 15 ++--- Aquaria/Entity.h | 124 ++++++++++++++++++------------------ Aquaria/ScriptInterface.cpp | 4 +- 3 files changed, 71 insertions(+), 72 deletions(-) diff --git a/Aquaria/Entity.cpp b/Aquaria/Entity.cpp index 4dd5c95..02e83a7 100644 --- a/Aquaria/Entity.cpp +++ b/Aquaria/Entity.cpp @@ -1690,15 +1690,12 @@ void Entity::moveOutOfWall() void Entity::clearDamageTargets() { - disabledDamageTypes.clear(); + disabledDamageTypes.reset(); } void Entity::setDamageTarget(DamageType dt, bool v) { - if (v) - disabledDamageTypes.erase(dt); - else - disabledDamageTypes.insert(dt); + disabledDamageTypes.set(dt, !v); } void Entity::setEatType(EatType et, const std::string &file) @@ -1719,17 +1716,17 @@ void Entity::setAllDamageTargets(bool v) else { for (int i = DT_ENEMY; i < DT_ENEMY_REALMAX; i++) - disabledDamageTypes.insert(DamageType(i)); + disabledDamageTypes.set(DamageType(i)); for (int i = DT_AVATAR; i < DT_AVATAR_REALMAX; i++) - disabledDamageTypes.insert(DamageType(i)); + disabledDamageTypes.set(DamageType(i)); for (int i = DT_AVATAR_MAX; i < DT_REALMAX; i++) - disabledDamageTypes.insert(DamageType(i)); + disabledDamageTypes.set(DamageType(i)); } } bool Entity::isDamageTarget(DamageType dt) { - return disabledDamageTypes.find(dt) == disabledDamageTypes.end(); + return disabledDamageTypes.test(dt); } float Entity::getHealthPerc() diff --git a/Aquaria/Entity.h b/Aquaria/Entity.h index 646cb6d..5794c97 100644 --- a/Aquaria/Entity.h +++ b/Aquaria/Entity.h @@ -21,6 +21,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef ENTITY_H #define ENTITY_H +#include + #include "../BBGE/StateMachine.h" #include "../ExternalLibs/tinyxml.h" #include "../BBGE/SkeletalSprite.h" @@ -75,70 +77,70 @@ enum EV enum DamageType { - DT_NONE = -1, - DT_ENEMY = 0, - DT_ENEMY_ENERGYBLAST = 1, - DT_ENEMY_SHOCK = 2, - DT_ENEMY_BITE = 3, - DT_ENEMY_TRAP = 4, - DT_ENEMY_WEB = 5, - DT_ENEMY_BEAM = 6, - DT_ENEMY_GAS = 7, - DT_ENEMY_INK = 8, - DT_ENEMY_POISON = 9, - DT_ENEMY_ACTIVEPOISON = 10, - DT_ENEMY_CREATOR = 11, - DT_ENEMY_MANTISBOMB = 12, - DT_ENEMY_REALMAX , - DT_ENEMY_MAX = 13, + DT_NONE, + DT_ENEMY, + DT_ENEMY_ENERGYBLAST, + DT_ENEMY_SHOCK, + DT_ENEMY_BITE, + DT_ENEMY_TRAP, + DT_ENEMY_WEB, + DT_ENEMY_BEAM, + DT_ENEMY_GAS, + DT_ENEMY_INK, + DT_ENEMY_POISON, + DT_ENEMY_ACTIVEPOISON, + DT_ENEMY_CREATOR, + DT_ENEMY_MANTISBOMB, + DT_ENEMY_REALMAX, + DT_ENEMY_MAX, - DT_AVATAR = 1000, - DT_AVATAR_ENERGYBLAST = 1001, - DT_AVATAR_SHOCK = 1002, - DT_AVATAR_BITE = 1003, - DT_AVATAR_VOMIT = 1004, - DT_AVATAR_ACID = 1005, - DT_AVATAR_SPORECHILD = 1006, - DT_AVATAR_LIZAP = 1007, - DT_AVATAR_NATURE = 1008, - DT_AVATAR_ENERGYROLL = 1009, - DT_AVATAR_VINE = 1010, - DT_AVATAR_EAT = 1011, - DT_AVATAR_EAT_BASICSHOT = 1011, - DT_AVATAR_EAT_MAX = 1012, - DT_AVATAR_LANCEATTACH = 1013, - DT_AVATAR_LANCE = 1014, - DT_AVATAR_CREATORSHOT = 1015, - DT_AVATAR_DUALFORMLI = 1016, - DT_AVATAR_DUALFORMNAIJA = 1017, - DT_AVATAR_BUBBLE = 1018, - DT_AVATAR_SEED = 1019, - DT_AVATAR_PET = 1020, - DT_AVATAR_PETNAUTILUS = 1021, - DT_AVATAR_PETBITE = 1022, - DT_AVATAR_REALMAX , - DT_AVATAR_MAX = 1030, - DT_TOUCH = 1031, - DT_CRUSH = 1032, - DT_SPIKES = 1033, - DT_STEAM = 1034, + DT_AVATAR, + DT_AVATAR_ENERGYBLAST, + DT_AVATAR_SHOCK, + DT_AVATAR_BITE, + DT_AVATAR_VOMIT, + DT_AVATAR_ACID, + DT_AVATAR_SPORECHILD, + DT_AVATAR_LIZAP, + DT_AVATAR_NATURE, + DT_AVATAR_ENERGYROLL, + DT_AVATAR_VINE, + DT_AVATAR_EAT, + DT_AVATAR_EAT_BASICSHOT, + DT_AVATAR_EAT_MAX, + DT_AVATAR_LANCEATTACH, + DT_AVATAR_LANCE, + DT_AVATAR_CREATORSHOT, + DT_AVATAR_DUALFORMLI, + DT_AVATAR_DUALFORMNAIJA, + DT_AVATAR_BUBBLE, + DT_AVATAR_SEED, + DT_AVATAR_PET, + DT_AVATAR_PETNAUTILUS, + DT_AVATAR_PETBITE, + DT_AVATAR_REALMAX, + DT_AVATAR_MAX, + DT_TOUCH, + DT_CRUSH, + DT_SPIKES, + DT_STEAM, DT_REALMAX }; enum EatType { - EAT_NONE = -1, - EAT_DEFAULT = 0, - EAT_FILE = 1, + EAT_NONE, + EAT_DEFAULT, + EAT_FILE, EAT_MAX }; enum ObsCheck { - OBSCHECK_RANGE = 0, - OBSCHECK_4DIR = 1, - OBSCHECK_DOWN = 2, - OBSCHECK_8DIR = 3 + OBSCHECK_RANGE, + OBSCHECK_4DIR, + OBSCHECK_DOWN, + OBSCHECK_8DIR, }; class Shot; @@ -169,13 +171,13 @@ struct DamageData enum EntityType { - ET_NOTYPE =-1, - ET_AVATAR =0, - ET_ENEMY =1, - ET_PET =2, - ET_FLOCK =3, - ET_NEUTRAL =4, - ET_INGREDIENT =5 + ET_NOTYPE, + ET_AVATAR, + ET_ENEMY, + ET_PET, + ET_FLOCK, + ET_NEUTRAL, + ET_INGREDIENT, }; enum EntityProperty @@ -406,7 +408,7 @@ public: void setDamageTarget(DamageType dt, bool v); bool isDamageTarget(DamageType dt); - typedef std::set DisabledDamageTypes; + typedef std::bitset DisabledDamageTypes; int targetRange; int getTargetRange() { return targetRange; } diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 43bbd08..54aa8a6 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -6315,9 +6315,9 @@ luaFunc(entity_getNearestEntity) Entity *e = *i; if (e != me && e != ignore && e->isPresent() && e->isNormalLayer()) { - if (type == 0 || e->getEntityType() == type) + if (type == ET_NOTYPE || e->getEntityType() == type) { - if (damageTarget == 0 || e->isDamageTarget((DamageType)damageTarget)) + if (damageTarget == DT_NONE || e->isDamageTarget((DamageType)damageTarget)) { if (!name || ((nocasecmp(e->name, name)==0) == nameCheck)) { From 0f13f0835763fb98c2da937b45ff5333143b1e89 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Thu, 13 Dec 2012 19:57:30 +0100 Subject: [PATCH 005/103] Remove unused stuff - entity group IDs - entity node groups (?!) - WaterFont.[cpp|h] --- Aquaria/Entity.cpp | 94 ----------------------- Aquaria/Entity.h | 11 --- Aquaria/Game.cpp | 144 +++--------------------------------- Aquaria/Game.h | 14 ++-- Aquaria/SceneEditor.cpp | 60 +-------------- Aquaria/ScriptInterface.cpp | 25 +------ Aquaria/Shot.cpp | 2 +- CMakeLists.txt | 2 +- 8 files changed, 21 insertions(+), 331 deletions(-) diff --git a/Aquaria/Entity.cpp b/Aquaria/Entity.cpp index 02e83a7..c4d5d70 100644 --- a/Aquaria/Entity.cpp +++ b/Aquaria/Entity.cpp @@ -217,7 +217,6 @@ Entity::Entity() targetRange = 32; //energyChargeTarget = energyShotTarget = true; deathSound = "GenericDeath"; - groupID = 0; entityID = 0; //assignUniqueID(); hair = 0; @@ -349,50 +348,6 @@ void Entity::setSpiritFreeze(bool v) spiritFreeze = v; } -Vector Entity::getGroupCenter() -{ - Vector position; - int sz = 0; - FOR_ENTITIES(i) - { - Entity *e = *i; - if (e->getGroupID() == this->getGroupID()) - { - position += e->position; - sz++; - } - } - position/=sz; - return position; -} - -Vector Entity::getGroupHeading() -{ - Vector v; - int sz = 0; - FOR_ENTITIES(i) - { - Entity *e = *i; - if (e->getGroupID() == this->getGroupID()) - { - v += e->vel; - sz++; - } - } - v/=sz; - return v; -} - -int Entity::getGroupID() -{ - return groupID; -} - -void Entity::setGroupID(int g) -{ - groupID = g; -} - void Entity::setEntityProperty(EntityProperty ep, bool value) { entityProperties[int(ep)] = value; @@ -574,37 +529,6 @@ void Entity::moveToNode(Path *path, int speedType, int dieOnPathEnd, bool swim) //position.startPath(((position.data->path.getNumPathNodes()*TILE_SIZE*4)-2)/dsq->continuity.getSpeedType(speedType)); } -void Entity::addNodeToNodeGroup(int group, Path *p) -{ - nodeGroups[group].push_back(p); -} - -void Entity::removeNodeFromAllNodeGroups(Path *p) -{ - for (int j = 0; j < nodeGroups.size(); j++) - { - for (int i = 0; i < nodeGroups[j].size(); i++) - { - if (nodeGroups[j][i] == p) - { - nodeGroups[j][i] = 0; - } - } - } -} - -void Entity::setNodeGroupActive(int group, bool v) -{ - for (int i = 0; i < nodeGroups[group].size(); i++) - { - Path *p = nodeGroups[group][i]; - if (p) - { - p->setActive(v); - } - } -} - void Entity::stopFollowingPath() { position.stopPath(); @@ -2455,24 +2379,6 @@ void Entity::moveTowardsTarget(float dt, int spd, int t) moveTowards(targets[t]->position, dt, spd); } -void Entity::moveTowardsGroupCenter(float dt, int speed) -{ - if (getGroupID() != 0) - { - moveTowards(getGroupCenter(), dt, speed); - } -} - -void Entity::moveTowardsGroupHeading(float dt, int speed) -{ - if (getGroupID() != 0) - { - Vector d = getGroupHeading() - position; - d.setLength2D(speed*dt); - vel += d; - } -} - void Entity::moveAroundTarget(float dt, int spd, int dir, int t) { if (!targets[t]) return; diff --git a/Aquaria/Entity.h b/Aquaria/Entity.h index 5794c97..3786187 100644 --- a/Aquaria/Entity.h +++ b/Aquaria/Entity.h @@ -392,10 +392,6 @@ public: InterpolatedVector maxSpeedLerp; Hair *hair; - void setGroupID(int gid); - int getGroupID(); - Vector getGroupCenter(); - Vector getGroupHeading(); void assignUniqueID(); int entityID; @@ -424,12 +420,6 @@ public: bool isCrawling() { return crawling; } */ void flipToVel(); - typedef std::vector NodeGroup; - typedef std::map NodeGroups; - NodeGroups nodeGroups; - void addNodeToNodeGroup(int group, Path *p); - void setNodeGroupActive(int group, bool v); - void removeNodeFromAllNodeGroups(Path *p); bool isInCurrent() { return inCurrent; } void clearTargetPoints(); void addTargetPoint(const Vector &point); @@ -546,7 +536,6 @@ protected: //Vector backupPos, backupVel; virtual void onIdle() {} - int groupID; virtual void onHeal(int type){} virtual void onDamage(DamageData &d){} virtual void onHealthChange(float change){} diff --git a/Aquaria/Game.cpp b/Aquaria/Game.cpp index fd07cb8..8379a06 100644 --- a/Aquaria/Game.cpp +++ b/Aquaria/Game.cpp @@ -2532,7 +2532,7 @@ int Game::getIdxForEntityType(std::string type) return -1; } -Entity *Game::createEntity(int idx, int id, Vector position, int rot, bool createSaveData, std::string name, EntityType et, Entity::NodeGroups *nodeGroups, int gid, bool doPostInit) +Entity *Game::createEntity(int idx, int id, Vector position, int rot, bool createSaveData, std::string name, EntityType et, bool doPostInit) { std::string type; for (int i = 0; i < dsq->game->entityTypeList.size(); i++) @@ -2541,7 +2541,7 @@ Entity *Game::createEntity(int idx, int id, Vector position, int rot, bool creat if (ec->idx == idx) { type = ec->name; - return createEntity(type, id, position, rot, createSaveData, name, et, nodeGroups, gid, doPostInit); + return createEntity(type, id, position, rot, createSaveData, name, et, doPostInit); } } return 0; @@ -2580,7 +2580,7 @@ void Game::ensureLimit(Entity *e, int num, int state) } } -Entity* Game::establishEntity(Entity *e, int id, Vector position, int rot, bool createSaveData, std::string name, EntityType et, Entity::NodeGroups *nodeGroups, int gid, bool doPostInit) +Entity* Game::establishEntity(Entity *e, int id, Vector position, int rot, bool createSaveData, std::string name, EntityType et, bool doPostInit) { // e->layer must be set BEFORE calling this function! @@ -2615,12 +2615,6 @@ Entity* Game::establishEntity(Entity *e, int id, Vector position, int rot, bool } } - // get node groups before calling init - if (nodeGroups) - { - e->nodeGroups = (*nodeGroups); - } - // NOTE: init cannot be called after "addRenderObject" for some unknown reason e->init(); @@ -2629,8 +2623,6 @@ Entity* Game::establishEntity(Entity *e, int id, Vector position, int rot, bool if (!name.empty()) e->name = name; - e->setGroupID(gid); - e->rotation.z = rot; int idx = getIdxForEntityType(type); @@ -2640,7 +2632,7 @@ Entity* Game::establishEntity(Entity *e, int id, Vector position, int rot, bool if (createSaveData) { int idx = dsq->game->getIdxForEntityType(type); - entitySaveData.push_back(EntitySaveData(e, idx, usePos.x, usePos.y, rot, e->getGroupID(), e->getID(), e->name)); + entitySaveData.push_back(EntitySaveData(e, idx, usePos.x, usePos.y, rot, e->getID(), e->name)); } addRenderObject(e, e->layer); @@ -2653,7 +2645,7 @@ Entity* Game::establishEntity(Entity *e, int id, Vector position, int rot, bool return e; } -Entity *Game::createEntity(const std::string &t, int id, Vector position, int rot, bool createSaveData, std::string name, EntityType et, Entity::NodeGroups *nodeGroups, int gid, bool doPostInit) +Entity *Game::createEntity(const std::string &t, int id, Vector position, int rot, bool createSaveData, std::string name, EntityType et, bool doPostInit) { std::string type = t; stringToLower(type); @@ -2663,7 +2655,7 @@ Entity *Game::createEntity(const std::string &t, int id, Vector position, int ro e = new ScriptedEntity(type, position, et); - return establishEntity(e, id, position, rot, createSaveData, name, et, nodeGroups, gid, doPostInit); + return establishEntity(e, id, position, rot, createSaveData, name, et, doPostInit); } void Game::initEntities() @@ -5109,110 +5101,11 @@ bool Game::loadSceneXML(std::string scene) TiXmlElement *entitiesNode = doc.FirstChildElement("Entities"); while(entitiesNode) { - if (entitiesNode->Attribute("d")) - { - SimpleIStringStream is(entitiesNode->Attribute("d")); - int idx, x, y; - while (is >> idx) - { - is >> x >> y; - dsq->game->createEntity(idx, 0, Vector(x,y), 0, true, ""); - } - } - if (entitiesNode->Attribute("e")) - { - SimpleIStringStream is(entitiesNode->Attribute("e")); - int idx, x, y, rot; - while (is >> idx) - { - is >> x >> y >> rot; - if (idx == 32) - { - std::ostringstream os; - os << "read in rot as: " << rot; - debugLog(os.str()); - } - dsq->game->createEntity(idx, 0, Vector(x,y), rot, true, ""); - } - } - if (entitiesNode->Attribute("f")) - { - SimpleIStringStream is(entitiesNode->Attribute("f")); - int idx, x, y, rot, group; - while (is >> idx) - { - is >> x >> y >> rot >> group; - Entity *e = dsq->game->createEntity(idx, 0, Vector(x,y), rot, true, ""); - e->setGroupID(group); - } - } - if (entitiesNode->Attribute("g")) - { - SimpleIStringStream is(entitiesNode->Attribute("g")); - int idx, x, y, rot, group, id; - while (is >> idx) - { - is >> x >> y >> rot >> group >> id; - Entity *e = dsq->game->createEntity(idx, id, Vector(x,y), rot, true, ""); - e->setGroupID(group); - } - } - if (entitiesNode->Attribute("h")) - { - SimpleIStringStream is(entitiesNode->Attribute("h")); - int idx, x, y, rot, groupID, id; - Entity::NodeGroups *ng; - Entity::NodeGroups nodeGroups; - while (is >> idx) - { - int numNodeGroups = 0; - is >> x >> y >> rot >> groupID >> id; - is >> numNodeGroups; - - ng = 0; - nodeGroups.clear(); - if (numNodeGroups > 0) - { - ng = &nodeGroups; - for (int i = 0; i < numNodeGroups; i++) - { - int sz; - is >> sz; - for (int j = 0; j < sz; j++) - { - int idx; - is >> idx; - if (idx >= 0 && idx < getNumPaths()) - { - nodeGroups[i].push_back(getPath(idx)); - } - } - } - } - - dsq->game->createEntity(idx, id, Vector(x,y), rot, true, "", ET_ENEMY, ng, groupID); - // setting group ID - } - } - if (entitiesNode->Attribute("i")) - { - SimpleIStringStream is(entitiesNode->Attribute("i")); - int idx, x, y, rot, groupID, id; - Entity::NodeGroups nodeGroups; - while (is >> idx) - { - is >> x >> y >> rot >> groupID >> id; - - dsq->game->createEntity(idx, id, Vector(x,y), rot, true, "", ET_ENEMY, 0, groupID); - // setting group ID - } - } if (entitiesNode->Attribute("j")) { SimpleIStringStream is(entitiesNode->Attribute("j")); int idx, x, y, rot, groupID, id; std::string name; - Entity::NodeGroups nodeGroups; while (is >> idx) { name=""; @@ -5221,10 +5114,9 @@ bool Game::loadSceneXML(std::string scene) is >> x >> y >> rot >> groupID >> id; if (!name.empty()) - dsq->game->createEntity(name, id, Vector(x,y), rot, true, "", ET_ENEMY, 0, groupID); + dsq->game->createEntity(name, id, Vector(x,y), rot, true, "", ET_ENEMY); else - dsq->game->createEntity(idx, id, Vector(x,y), rot, true, "", ET_ENEMY, 0, groupID); - // setting group ID + dsq->game->createEntity(idx, id, Vector(x,y), rot, true, "", ET_ENEMY); } } entitiesNode = entitiesNode->NextSiblingElement("Entities"); @@ -5341,22 +5233,6 @@ void Game::setWarpAreaSceneName(WarpArea &warpArea) } } -Entity *Game::getEntityInGroup(int gid, int iter) -{ - int c = 0; - FOR_ENTITIES(i) - { - Entity *e = *i; - if (e->getGroupID() == gid) - { - if (iter == c) - return e; - c++; - } - } - return 0; -} - bool Game::loadScene(std::string scene) { stringToLower(scene); @@ -5552,8 +5428,8 @@ bool Game::saveScene(std::string scene) else os << "INVALID" << " "; } - - os << e->x << " " << e->y << " " << e->rot << " " << e->group << " " << e->id << " "; + // group ID no longer used + os << e->x << " " << e->y << " " << e->rot << " " << 0 << " " << e->id << " "; } entitiesNode.SetAttribute("j", os.str()); saveFile.InsertEndChild(entitiesNode); diff --git a/Aquaria/Game.h b/Aquaria/Game.h index 258687c..773b5c8 100644 --- a/Aquaria/Game.h +++ b/Aquaria/Game.h @@ -418,7 +418,6 @@ public: void closeMainMenu(); void setBackgroundGradient(); - void addSpringPlant(); bool isOn(); @@ -472,12 +471,10 @@ public: void moveLayer(); void moveElementToLayer(Element *e, int bgLayer); void toggleElementRepeat(); - void setGroup(); bool multiSelecting; Vector multiSelectPoint; std::vector selectedElements; void fixEntityIDs(); - void bindNodeToEntity(); Vector groupCenter; Vector getSelectedElementsCenter(); @@ -610,9 +607,9 @@ enum ObsType struct EntitySaveData { public: - EntitySaveData(Entity *e, int idx, int x, int y, int rot, int group, int id, const std::string &name) : e(e), idx(idx), x(x), y(y), rot(rot), group(group), id(id), name(name) {} + EntitySaveData(Entity *e, int idx, int x, int y, int rot, int id, const std::string &name) : e(e), idx(idx), x(x), y(y), rot(rot), id(id), name(name) {} Entity *e; - int idx, x, y, rot, group, id; + int idx, x, y, rot, id; std::string name; }; @@ -699,7 +696,6 @@ public: WarpAreas warpAreas; void postInitEntities(); - Entity *getEntityInGroup(int gid, int iter); EntityClass *getEntityClassForEntityType(const std::string &type); void warpToArea(WarpArea *area); @@ -744,9 +740,9 @@ public: MiniMapHint miniMapHint; void updateMiniMapHintPosition(); EntitySaveData *getEntitySaveDataForEntity(Entity *e, Vector pos); - Entity *createEntity(int idx, int id, Vector position, int rot, bool createSaveData, std::string name, EntityType = ET_ENEMY, Entity::NodeGroups *nodeGroups=0, int groupID=0, bool doPostInit=false); - Entity *createEntity(const std::string &type, int id, Vector position, int rot, bool createSaveData, std::string name, EntityType = ET_ENEMY, Entity::NodeGroups *nodeGroups=0, int groupID=0, bool doPostInit=false); - Entity *establishEntity(Entity *e, int id=0, Vector position=Vector(0,0), int rot=0, bool createSaveData=false, std::string name="", EntityType = ET_ENEMY, Entity::NodeGroups *nodeGroups=0, int groupID=0, bool doPostInit=false); + Entity *createEntity(int idx, int id, Vector position, int rot, bool createSaveData, std::string name, EntityType = ET_ENEMY, bool doPostInit=false); + Entity *createEntity(const std::string &type, int id, Vector position, int rot, bool createSaveData, std::string name, EntityType = ET_ENEMY, bool doPostInit=false); + Entity *establishEntity(Entity *e, int id=0, Vector position=Vector(0,0), int rot=0, bool createSaveData=false, std::string name="", EntityType = ET_ENEMY,bool doPostInit=false); void setCameraFollow(RenderObject *r); void setCameraFollowEntity(Entity *e); void setMenuDescriptionText(const std::string &text); diff --git a/Aquaria/SceneEditor.cpp b/Aquaria/SceneEditor.cpp index 81e0aa2..d087619 100644 --- a/Aquaria/SceneEditor.cpp +++ b/Aquaria/SceneEditor.cpp @@ -643,9 +643,6 @@ void SceneEditor::init() addAction(MakeFunctionEvent(SceneEditor, mouseButtonLeftUp), MOUSE_BUTTON_LEFT, 0); addAction(MakeFunctionEvent(SceneEditor, mouseButtonRightUp), MOUSE_BUTTON_RIGHT, 0); - // removed in fc3 - //addAction(MakeFunctionEvent(SceneEditor, bindNodeToEntity), KEY_B, 0); - addAction(MakeFunctionEvent(SceneEditor, alignHorz), KEY_C, 1); addAction(MakeFunctionEvent(SceneEditor, alignVert), KEY_V, 1); @@ -879,38 +876,6 @@ void SceneEditor::createAquarian() inCreateAqurian = false; } -void SceneEditor::bindNodeToEntity() -{ - if (editType == ET_PATHS) - { - Path *p = getSelectedPath(); - if (p) - { - std::istringstream is(dsq->getUserInputString("Enter group number")); - int group = 0; - is >> group; - Entity *e = getEntityAtCursor(); - if (e) - { - e->removeNodeFromAllNodeGroups(p); - e->addNodeToNodeGroup(group, p); - } - else - { - debugLog("no entity at cursor"); - } - } - } -} - -void SceneEditor::addSpringPlant() -{ - /* - SpringPlant *s = new SpringPlant(dsq->getGameCursorPosition()); - dsq->game->addRenderObject(s, LR_ENTITIES); - */ -} - Path *SceneEditor::getSelectedPath() { if (selectedIdx >= 0 && selectedIdx < dsq->game->getNumPaths()) @@ -1472,7 +1437,6 @@ void SceneEditor::updateEntitySaveData(Entity *editingEntity) os << "idx2: " << editingEntity->entityTypeIdx << " "; os << "name: " << editingEntity->name; //os << "state: " << editingEntity->getState(); - os << "groupID: " << editingEntity->getGroupID(); debugLog(os.str()); //debugLog("changing entity save data"); d->x = editingEntity->position.x; @@ -1484,7 +1448,6 @@ void SceneEditor::updateEntitySaveData(Entity *editingEntity) debugLog(os2.str()); */ d->rot = editingEntity->rotation.z; - d->group = editingEntity->getGroupID(); } else { @@ -1636,25 +1599,6 @@ void SceneEditor::toggleElementHurt() } } -void SceneEditor::setGroup() -{ - if (editingEntity) - { - std::ostringstream os; - os << editingEntity->getGroupID(); - Entity *backup = editingEntity; - std::string value = dsq->getUserInputString("Enter Group", os.str()); - int group = 0; - if (!value.empty()) - { - std::istringstream is(value); - is >> group; - } - backup->setGroupID(group); - updateEntitySaveData(backup); - } -} - void SceneEditor::toggleElementRepeat() { if (editingElement) @@ -3135,9 +3079,9 @@ void SceneEditor::placeElement() else if (editType == ET_ENTITIES) { if (!selectedEntity.nameBased) - dsq->game->createEntity(selectedEntity.index, 0, dsq->getGameCursorPosition(), 0, true, "", ET_ENEMY, 0, 0, true); + dsq->game->createEntity(selectedEntity.index, 0, dsq->getGameCursorPosition(), 0, true, "", ET_ENEMY, true); else - dsq->game->createEntity(selectedEntity.name, 0, dsq->getGameCursorPosition(), 0, true, "", ET_ENEMY, 0, 0, true); + dsq->game->createEntity(selectedEntity.name, 0, dsq->getGameCursorPosition(), 0, true, "", ET_ENEMY, true); } else if (editType == ET_PATHS) { diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 54aa8a6..705f76e 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -2907,7 +2907,7 @@ luaFunc(entity_createEntity) Entity *e = entity(L); Entity *ret = NULL; if (e) - ret = dsq->game->createEntity(dsq->getEntityTypeIndexByName(getString(L, 2)), 0, e->position, 0, false, "", ET_ENEMY, 0, 0, true); + ret = dsq->game->createEntity(dsq->getEntityTypeIndexByName(getString(L, 2)), 0, e->position, 0, false, "", ET_ENEMY, true); luaReturnPtr(ret); } @@ -3505,7 +3505,7 @@ luaFunc(createEntity) int y = lua_tointeger(L, 4); Entity *e = 0; - e = dsq->game->createEntity(type, 0, Vector(x, y), 0, false, name, ET_ENEMY, 0, 0, true); + e = dsq->game->createEntity(type, 0, Vector(x, y), 0, false, name, ET_ENEMY, true); luaReturnPtr(e); } @@ -6048,24 +6048,6 @@ luaFunc(entity_partSetSegs) luaReturnNil(); } -luaFunc(getEntityInGroup) -{ - int gid = lua_tonumber(L, 1); - int iter = lua_tonumber(L, 2); - luaReturnPtr(dsq->game->getEntityInGroup(gid, iter)); -} - -luaFunc(entity_getGroupID) -{ - Entity *e = entity(L); - int id = 0; - if(e) - { - id = e->getGroupID(); - } - luaReturnNum(id); -} - luaFunc(entity_getID) { Entity *e = entity(L); @@ -7290,8 +7272,6 @@ static const struct { luaRegister(getWaterLevel), luaRegister(setWaterLevel), - luaRegister(getEntityInGroup), - luaRegister(createQuad), luaRegister(setupEntity), @@ -7469,7 +7449,6 @@ static const struct { luaRegister(entity_move), luaRegister(entity_getID), - luaRegister(entity_getGroupID), luaRegister(getEntityByID), diff --git a/Aquaria/Shot.cpp b/Aquaria/Shot.cpp index 9bde459..af07a4e 100644 --- a/Aquaria/Shot.cpp +++ b/Aquaria/Shot.cpp @@ -515,7 +515,7 @@ void Shot::onHitWall() { if (!shotData->spawnEntity.empty()) { - dsq->game->createEntity(shotData->spawnEntity, 0, position, 0, false, "", ET_ENEMY, 0, 0, true); + dsq->game->createEntity(shotData->spawnEntity, 0, position, 0, false, "", ET_ENEMY, true); //(shotData->spawnEntity, 0, position, 0, false, ""); if (shotData->spawnEntity == "NatureFormFlowers") { diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c160d4..6c16bd0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -348,7 +348,6 @@ SET(AQUARIA_SRCS ${SRCDIR}/SubtitlePlayer.cpp ${SRCDIR}/ToolTip.cpp ${SRCDIR}/UserSettings.cpp - ${SRCDIR}/WaterFont.cpp ${SRCDIR}/WaterSurfaceRender.cpp ${SRCDIR}/Web.cpp ${SRCDIR}/WorldMapRender.cpp @@ -361,6 +360,7 @@ SET(AQUARIA_SRCS_UNUSED ${SRCDIR}/BubbleRender.cpp ${SRCDIR}/FFTNotes.cpp ${SRCDIR}/StarRenderer.cpp + ${SRCDIR}/WaterFont.cpp ) IF(MACOSX) From ad4bc9bd2156c7a74ba2c50bc2c4772b9bcb216f Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sat, 15 Dec 2012 22:46:39 +0100 Subject: [PATCH 006/103] Revert "Changed a bunch of enums in Entity.h" This reverts commit 8b67ece9075a0135b8e2a63b976609ee6249b3b7. --- Aquaria/Entity.cpp | 15 +++-- Aquaria/Entity.h | 124 ++++++++++++++++++------------------ Aquaria/ScriptInterface.cpp | 4 +- 3 files changed, 72 insertions(+), 71 deletions(-) diff --git a/Aquaria/Entity.cpp b/Aquaria/Entity.cpp index c4d5d70..cf49e82 100644 --- a/Aquaria/Entity.cpp +++ b/Aquaria/Entity.cpp @@ -1614,12 +1614,15 @@ void Entity::moveOutOfWall() void Entity::clearDamageTargets() { - disabledDamageTypes.reset(); + disabledDamageTypes.clear(); } void Entity::setDamageTarget(DamageType dt, bool v) { - disabledDamageTypes.set(dt, !v); + if (v) + disabledDamageTypes.erase(dt); + else + disabledDamageTypes.insert(dt); } void Entity::setEatType(EatType et, const std::string &file) @@ -1640,17 +1643,17 @@ void Entity::setAllDamageTargets(bool v) else { for (int i = DT_ENEMY; i < DT_ENEMY_REALMAX; i++) - disabledDamageTypes.set(DamageType(i)); + disabledDamageTypes.insert(DamageType(i)); for (int i = DT_AVATAR; i < DT_AVATAR_REALMAX; i++) - disabledDamageTypes.set(DamageType(i)); + disabledDamageTypes.insert(DamageType(i)); for (int i = DT_AVATAR_MAX; i < DT_REALMAX; i++) - disabledDamageTypes.set(DamageType(i)); + disabledDamageTypes.insert(DamageType(i)); } } bool Entity::isDamageTarget(DamageType dt) { - return disabledDamageTypes.test(dt); + return disabledDamageTypes.find(dt) == disabledDamageTypes.end(); } float Entity::getHealthPerc() diff --git a/Aquaria/Entity.h b/Aquaria/Entity.h index 3786187..76f10b3 100644 --- a/Aquaria/Entity.h +++ b/Aquaria/Entity.h @@ -21,8 +21,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef ENTITY_H #define ENTITY_H -#include - #include "../BBGE/StateMachine.h" #include "../ExternalLibs/tinyxml.h" #include "../BBGE/SkeletalSprite.h" @@ -77,70 +75,70 @@ enum EV enum DamageType { - DT_NONE, - DT_ENEMY, - DT_ENEMY_ENERGYBLAST, - DT_ENEMY_SHOCK, - DT_ENEMY_BITE, - DT_ENEMY_TRAP, - DT_ENEMY_WEB, - DT_ENEMY_BEAM, - DT_ENEMY_GAS, - DT_ENEMY_INK, - DT_ENEMY_POISON, - DT_ENEMY_ACTIVEPOISON, - DT_ENEMY_CREATOR, - DT_ENEMY_MANTISBOMB, - DT_ENEMY_REALMAX, - DT_ENEMY_MAX, + DT_NONE = -1, + DT_ENEMY = 0, + DT_ENEMY_ENERGYBLAST = 1, + DT_ENEMY_SHOCK = 2, + DT_ENEMY_BITE = 3, + DT_ENEMY_TRAP = 4, + DT_ENEMY_WEB = 5, + DT_ENEMY_BEAM = 6, + DT_ENEMY_GAS = 7, + DT_ENEMY_INK = 8, + DT_ENEMY_POISON = 9, + DT_ENEMY_ACTIVEPOISON = 10, + DT_ENEMY_CREATOR = 11, + DT_ENEMY_MANTISBOMB = 12, + DT_ENEMY_REALMAX , + DT_ENEMY_MAX = 13, - DT_AVATAR, - DT_AVATAR_ENERGYBLAST, - DT_AVATAR_SHOCK, - DT_AVATAR_BITE, - DT_AVATAR_VOMIT, - DT_AVATAR_ACID, - DT_AVATAR_SPORECHILD, - DT_AVATAR_LIZAP, - DT_AVATAR_NATURE, - DT_AVATAR_ENERGYROLL, - DT_AVATAR_VINE, - DT_AVATAR_EAT, - DT_AVATAR_EAT_BASICSHOT, - DT_AVATAR_EAT_MAX, - DT_AVATAR_LANCEATTACH, - DT_AVATAR_LANCE, - DT_AVATAR_CREATORSHOT, - DT_AVATAR_DUALFORMLI, - DT_AVATAR_DUALFORMNAIJA, - DT_AVATAR_BUBBLE, - DT_AVATAR_SEED, - DT_AVATAR_PET, - DT_AVATAR_PETNAUTILUS, - DT_AVATAR_PETBITE, - DT_AVATAR_REALMAX, - DT_AVATAR_MAX, - DT_TOUCH, - DT_CRUSH, - DT_SPIKES, - DT_STEAM, + DT_AVATAR = 1000, + DT_AVATAR_ENERGYBLAST = 1001, + DT_AVATAR_SHOCK = 1002, + DT_AVATAR_BITE = 1003, + DT_AVATAR_VOMIT = 1004, + DT_AVATAR_ACID = 1005, + DT_AVATAR_SPORECHILD = 1006, + DT_AVATAR_LIZAP = 1007, + DT_AVATAR_NATURE = 1008, + DT_AVATAR_ENERGYROLL = 1009, + DT_AVATAR_VINE = 1010, + DT_AVATAR_EAT = 1011, + DT_AVATAR_EAT_BASICSHOT = 1011, + DT_AVATAR_EAT_MAX = 1012, + DT_AVATAR_LANCEATTACH = 1013, + DT_AVATAR_LANCE = 1014, + DT_AVATAR_CREATORSHOT = 1015, + DT_AVATAR_DUALFORMLI = 1016, + DT_AVATAR_DUALFORMNAIJA = 1017, + DT_AVATAR_BUBBLE = 1018, + DT_AVATAR_SEED = 1019, + DT_AVATAR_PET = 1020, + DT_AVATAR_PETNAUTILUS = 1021, + DT_AVATAR_PETBITE = 1022, + DT_AVATAR_REALMAX , + DT_AVATAR_MAX = 1030, + DT_TOUCH = 1031, + DT_CRUSH = 1032, + DT_SPIKES = 1033, + DT_STEAM = 1034, DT_REALMAX }; enum EatType { - EAT_NONE, - EAT_DEFAULT, - EAT_FILE, + EAT_NONE = -1, + EAT_DEFAULT = 0, + EAT_FILE = 1, EAT_MAX }; enum ObsCheck { - OBSCHECK_RANGE, - OBSCHECK_4DIR, - OBSCHECK_DOWN, - OBSCHECK_8DIR, + OBSCHECK_RANGE = 0, + OBSCHECK_4DIR = 1, + OBSCHECK_DOWN = 2, + OBSCHECK_8DIR = 3 }; class Shot; @@ -171,13 +169,13 @@ struct DamageData enum EntityType { - ET_NOTYPE, - ET_AVATAR, - ET_ENEMY, - ET_PET, - ET_FLOCK, - ET_NEUTRAL, - ET_INGREDIENT, + ET_NOTYPE =-1, + ET_AVATAR =0, + ET_ENEMY =1, + ET_PET =2, + ET_FLOCK =3, + ET_NEUTRAL =4, + ET_INGREDIENT =5 }; enum EntityProperty @@ -404,7 +402,7 @@ public: void setDamageTarget(DamageType dt, bool v); bool isDamageTarget(DamageType dt); - typedef std::bitset DisabledDamageTypes; + typedef std::set DisabledDamageTypes; int targetRange; int getTargetRange() { return targetRange; } diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 705f76e..b11b028 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -6297,9 +6297,9 @@ luaFunc(entity_getNearestEntity) Entity *e = *i; if (e != me && e != ignore && e->isPresent() && e->isNormalLayer()) { - if (type == ET_NOTYPE || e->getEntityType() == type) + if (type == 0 || e->getEntityType() == type) { - if (damageTarget == DT_NONE || e->isDamageTarget((DamageType)damageTarget)) + if (damageTarget == 0 || e->isDamageTarget((DamageType)damageTarget)) { if (!name || ((nocasecmp(e->name, name)==0) == nameCheck)) { From b6ae2a6baa14eed501b62486a4aa10c61747bdcd Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sat, 15 Dec 2012 23:08:59 +0100 Subject: [PATCH 007/103] Fix problems intended to fix in (reverted) 8b67ece. --- Aquaria/ScriptInterface.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index b11b028..c39f08f 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -2321,7 +2321,7 @@ luaFunc(entity_findNearestEntityOfType) Entity *nearest = 0; if (e) { - int et = (EntityType)lua_tointeger(L, 2); + EntityType et = (EntityType)lua_tointeger(L, 2); int maxRange = lua_tointeger(L, 3); float smallestDist = HUGE_VALF; Entity *closest = 0; @@ -6284,8 +6284,13 @@ luaFunc(entity_getNearestEntity) } float range = lua_tointeger(L, 3); - int type = lua_tointeger(L, 4); - int damageTarget = lua_tointeger(L, 5); + EntityType type = ET_NOTYPE; + if (lua_isnumber(L, 4)) + type = (EntityType)lua_tointeger(L, 4); + + DamageType damageTarget = DT_NONE; + if (lua_isnumber(L, 5)) + damageTarget = (DamageType)lua_tointeger(L, 5); Entity *closest = 0; Entity *ignore = 0; if (lua_isuserdata(L, 6)) @@ -6297,9 +6302,9 @@ luaFunc(entity_getNearestEntity) Entity *e = *i; if (e != me && e != ignore && e->isPresent() && e->isNormalLayer()) { - if (type == 0 || e->getEntityType() == type) + if (type == ET_NONE || e->getEntityType() == type) { - if (damageTarget == 0 || e->isDamageTarget((DamageType)damageTarget)) + if (damageTarget == DT_NONE || e->isDamageTarget((DamageType)damageTarget)) { if (!name || ((nocasecmp(e->name, name)==0) == nameCheck)) { @@ -6486,7 +6491,7 @@ luaFunc(entity_switchLayer) toLayer = dsq->getEntityLayerToLayer(lcode); if (e->getEntityType() == ET_AVATAR) - toLayer = LR_ENTITIES; + toLayer = LR_ENTITIES; core->switchRenderObjectLayer(e, toLayer); } From 9eb5b9828a6b0f5dae2b04fe98ecb57acf54a65d Mon Sep 17 00:00:00 2001 From: fgenesis Date: Wed, 19 Dec 2012 06:23:51 +0100 Subject: [PATCH 008/103] clean out some dead code and some old commented out code --- Aquaria/Avatar.cpp | 1987 +------------------------------------------- Aquaria/Avatar.h | 80 +- Aquaria/DSQ.cpp | 10 +- Aquaria/DSQ.h | 1 - Aquaria/Entity.cpp | 33 - Aquaria/Entity.h | 2 - Aquaria/Game.cpp | 5 +- BBGE/Core.cpp | 3 - BBGE/Core.h | 2 +- 9 files changed, 24 insertions(+), 2099 deletions(-) diff --git a/Aquaria/Avatar.cpp b/Aquaria/Avatar.cpp index d75802f..82c3101 100644 --- a/Aquaria/Avatar.cpp +++ b/Aquaria/Avatar.cpp @@ -117,9 +117,6 @@ const float NOTE_ACCEPT_DISTANCE = 25; // we accept a note. const float NOTE_ACCEPT_ANGLE_OFFSET = 15; -volatile int micNote = -1; -bool openedFromMicInput = false; - const int requiredDualFormCharge = 3; bool usingDigital = false; @@ -462,7 +459,7 @@ void SongIcon::onUpdate(float dt) } if (alpha.x == 1) { - if ((!openedFromMicInput && isCoordinateInRadius(core->mouse.position, NOTE_ACCEPT_DISTANCE)) || micNote == note) + if (isCoordinateInRadius(core->mouse.position, NOTE_ACCEPT_DISTANCE)) { //if (delay == 0) if (true) @@ -487,7 +484,7 @@ void SongIcon::onUpdate(float dt) } } } - else if (openedFromMicInput || !isCoordinateInRadius(core->mouse.position, NOTE_ACCEPT_DISTANCE*1.25f)) + else if (!isCoordinateInRadius(core->mouse.position, NOTE_ACCEPT_DISTANCE*1.25f)) { if (cursorIsIn) { @@ -727,7 +724,6 @@ AvatarState::AvatarState() wasUnderWater = true; blind = false; lockedToWall = false; - crawlingOnWall = false; shotDelay = 0; spellCharge = 0; leachTimer = 0; @@ -738,14 +734,6 @@ AvatarState::AvatarState() blinkTimer = 0; } -// 0 1 2 3 4 5 6 7 8 9 -const int spellManaCost [] = { 0, 3, 1, 1, 2, 1, 4, 1, 1, 2}; -const float spellChargeMins [] = { 0, 1.25, 0, 0, 0.75, 0, 0.5, 0, 0, 3}; -//const float spellChargeMaxs [] = { 0.75, 1.5, 1.9, 1, 1, 1, 0.75, 1, 1, 3}; -const float spellCastDelays [] = { 0.05, 0.2, 0.4, 0.1, 0.1, 0.1, 0.2, 0.1, 0.1, 0.1 }; - -bool avatarDebugEnabled = false; - void Avatar::toggleMovement(bool on) { canMove = on; @@ -946,30 +934,6 @@ void Avatar::updatePosition() updateHair(0); } -void Avatar::debugMsg(const std::string &msg) -{ - if (avatarDebugEnabled) - { - BitmapText *txt = new BitmapText(&dsq->font); - txt->setLife(2); - txt->setDecayRate(1); - txt->position = this->position; - txt->setText(msg); - txt->fadeAlphaWithLife = true; - core->getTopStateData()->addRenderObject(txt, LR_DEBUG_TEXT); - } -} - -void Avatar::onBlindTest() -{ - setBlind(5); -} - -void Avatar::onToggleDebugMessages() -{ - avatarDebugEnabled = !avatarDebugEnabled; -} - void Avatar::updateHair(float dt) { static float hairTimer = 0; @@ -1451,170 +1415,9 @@ void Avatar::clearTargets() } } -void Avatar::slowToRest() -{ - vel.capLength2D(50); - /* - if (vel.getSquaredLength2D() > sqr(50)) - { - vel.setLength2D(50); - } - */ - bursting = swimming = false; - skeletalSprite.stopAnimation(1); - rotation.interpolateTo(Vector(0,0,0), 0.2, 0, 0, 1); -} - -/* -#define SPECWIDTH 368 -#define SPECHEIGHT 127 -BYTE *specbuf = 0; -*/ - -volatile int curMicNote = -1, lastMicNote=-1; - -#ifdef BBGE_BUILD_RECORD - volatile float timeFromLastNote=0; - volatile float timerFreq; - volatile float lastLargest=0; - volatile bool inMe = false; - volatile __int64 lastTick = 0; -#endif - - /* -BOOL CALLBACK recordCallback(HRECORD handle, const void *buf, DWORD len, DWORD user) -{ - -#ifdef BBGE_BUILD_RECORD - if (inMe) return TRUE; - inMe = true; - - //if (!dsq->game->avatar->isSinging()) return FALSE; - //int x,y; - - //timerFreq = - __int64 freq=0; - QueryPerformanceFrequency((LARGE_INTEGER*)&freq); - __int64 curTime=0; - QueryPerformanceCounter((LARGE_INTEGER*)&curTime); - if (lastTick == 0) - { - lastTick = curTime; - } - - float fft[4096]; // get the FFT data - BASS_ChannelGetData(handle,fft,BASS_DATA_FFT4096); - - int v = 0; - int c = 0; - float largest = -1; - - //128 - //for (int i = 5; i < 13; i++) - for (int i = 12; i < 64; i++) - { - if (fft[i] > 0.01f && (fft[i] > largest || largest == -1)) - { - largest = fft[i]; - v = i; - } - } - - int v2=0; - largest = -1; - // find the next largest - - float dt = (float(curTime-lastTick)/float(freq)); - lastTick = curTime; - int posMicNote=-1; - if (c != 0) - v /= float(c); - int ov = v; - float factor=1.0; - int octave = dsq->user.audio.octave; - - int minNote = 12;///6; - int maxNote = minNote + 25; // 8 - int octRange = 11; - - minNote += (octRange)*octave; - maxNote += (octRange)*octave; - - posMicNote = dsq->fftnotes.getNoteFromFFT(v, octave); - - //if (lastLargest 0.0001f) - { - micNote = curMicNote; - timeFromLastNote = 0; - } - if (curMicNote == -1) - micNote = -1; - lastMicNote = curMicNote; - - inMe = false; -#endif - return TRUE; -} -*/ - -/* - -class FoodIcon2 : public Quad -{ -}; - -class FoodIcon : public Quad -{ -public: - FoodIcon(IngredientEffectType iet); - - IngredientEffectType type; - - void -}; - -void Avatar::openFoodInterface() -{ - if (!singing && !pickingPullTarget && health > 0 && !isEntityDead() && !blockSinging) - { - // build it - foodIcons.clear(); - - foodIcons.resize(8); - } -} -*/ - void Avatar::openSingingInterface() { - if (!singing && !pickingPullTarget && health > 0 && !isEntityDead() && !blockSinging) + if (!singing && health > 0 && !isEntityDead() && !blockSinging) { //core->mouse.position = Vector(400,300); if (dsq->inputMode != INPUT_MOUSE) @@ -1635,19 +1438,10 @@ void Avatar::openSingingInterface() } currentSong.notes.clear(); - // songInterfaceTimer = 0; dsq->game->songLineRender->clear(); - //if (avatarRecord) - //{ - // if (dsq->useMic && !dsq->autoSingMenuOpen && dsq->user.audio.micOn) - // { - // //avatarRecord=BASS_RecordStart(44100,1,0,&recordCallback,0); - // BASS_ChannelPlay(avatarRecord, false); - // } - //} if (dsq->inputMode == INPUT_JOYSTICK) { @@ -1686,48 +1480,6 @@ void Avatar::closeSingingInterface() dsq->continuity.castSong(currentSongIdx); currentSongIdx = SONG_NONE; } - - /* - if (avatarRecord) - { - if (dsq->useMic && !dsq->autoSingMenuOpen && dsq->user.audio.micOn) - { - //BASS_ChannelStop(avatarRecord); - BASS_ChannelPause(avatarRecord); - //BASS_RecordFree(); - //avatarRecord = 0; - - } - } - */ - - lastMicNote = curMicNote = micNote = -1; - } -} - -void Avatar::openFormInterface() -{ - if (!inFormInterface) - { - inFormInterface = true; - - for(int i = 0; i < formIcons.size(); i++) - { - formIcons[i]->alpha.interpolateTo(1, 0.1); - } - } -} - -void Avatar::closeFormInterface() -{ - if (inFormInterface) - { - inFormInterface = false; - - for (int i = 0; i < formIcons.size(); i++) - { - formIcons[i]->alpha.interpolateTo(0, 0.1); - } } } @@ -1874,7 +1626,6 @@ void Avatar::changeForm(FormType form, bool effects, bool onInit, FormType lastF state.abilityDelay = 0; formAbilityDelay = 0; dsq->continuity.form = form; - ropeState = 0; formTimer = 0; if (effects) { @@ -2092,33 +1843,10 @@ void Avatar::singNote(int note) { currentSong.notes.push_back(note); lastNote = note; - //int song = dsq->continuity.checkSong(currentSong); - //int song = dsq->continuity.checkSongAssisted(currentSong); - //int song = dsq->continuity.checkSongAssisted(currentSong); - /* - std::ostringstream os; - os << "sung note: " << note; - debugLog(os.str()); - */ - //currentSongIdx = song; - /* - if (song != -1) - { - */ - /* - std::ostringstream os; - os << "Sung Song: " << song; - debugLog(os.str()); - */ - // close in a few seconds - //closeSingingInterface(); - //} } void Avatar::updateSingingInterface(float dt) { - - //if (singing) if (songIcons.size()>0 && songIcons[0]->alpha.x > 0) { if (dsq->inputMode != INPUT_JOYSTICK && !core->mouse.change.isZero()) @@ -2902,12 +2630,6 @@ void Avatar::formAbility(int ability) { if (chargeLevelAttained == 2) { - /* - shockTimer = 1; - damageDelay = 0.2; - didShockDamage = false; - */ - didShockDamage = false; if (dsq->continuity.hasFormUpgrade(FORMUPGRADE_ENERGY2)) doShock("EnergyTendril2"); else @@ -3438,70 +3160,6 @@ void Avatar::doShock(const std::string &shotName) { targets.clear(); } - - - /* - // old method - for (int i = 0; i < entitiesToHit.size(); i++) - { - Entity *e = entitiesToHit[i]; - DamageData d; - d.attacker = this; - d.damageType = DT_AVATAR_SHOCK; - d.damage = 3; - e->damage(d); - - dsq->playVisualEffect(VFX_SHOCKHIT, e->position, e); - - EnergyTendril *t = new EnergyTendril(this, e); - core->addRenderObject(t, LR_PARTICLES); - - e->shock(); - } - */ - - //HACK: WHAT DOES THIS VARIABLE DO EXACTLY? - didShockDamage = true; - - - //loseTargets(); -} - -void Avatar::updateShock(float dt) -{ - /* - if (shockTimer > 0) - { - float shockTime = 0.75; - castShockTimer += dt; - std::vector closestEntities; - unsigned int c=0; - const float shotDelayTime = 0.05; - - - if (damageDelay > 0) - { - damageDelay -= dt; - if (damageDelay <= 0) - damageDelay = 0; - } - - if (damageDelay == 0) - { - } - - if (damageDelay == 0) - { - damageDelay = 999; - } - - shockTimer -= dt; - if (shockTimer < 0) - { - shockTimer = 0; - } - } - */ } void Avatar::formAbilityUpdate(float dt) @@ -3534,58 +3192,6 @@ void Avatar::formAbilityUpdate(float dt) break; case FORM_ENERGY: { - /* - if (core->mouse.buttons.right && mana > 0 && !core->mouse.buttons.left) - { - float shockTime = 0.75; - castShockTimer += dt; - std::vector closestEntities; - unsigned int c=0; - const float shotDelayTime = 0.05; - - - int maxHit = 2 + dsq->continuity.getSpellLevel(SPELL_SHOCK)*2; - FOR_ENTITIES (i) - { - Entity *e = *i; - Vector d = e->position - this->position; - if (e != this && !e->isEntityDead() && e->isAffectedBySpell(SPELL_SHOCK) && d.getSquaredLength2D() < sqr(400+(dsq->continuity.getSpellLevel(SPELL_SHOCK)-1)*100)) - { - state.shotDelay += dt; - if (state.shotDelay > shotDelayTime) - { - state.shotDelay -= shotDelayTime; - - EnergyTendril *t = new EnergyTendril(avatar->position, e->position); - core->addRenderObject(t, LR_PARTICLES); - } - e->offset.x = rand()%5; - e->shock(); - DamageData d; - d.attacker = this; - d.spellType = SPELL_SHOCK; - d.damage = 1+(dsq->continuity.getSpellLevel(SPELL_SHOCK)-1)*1; - e->hit(d); - c ++; - } - if (c >= maxHit) - break; - } - //std::ostringstream os; - //os << "castShockTimer: " << castShockTimer << " - shockTime: " << shockTime; - //debugLog(os.str()); - if (castShockTimer > shockTime) - { - castShockTimer -= shockTime; - mana --; - } - } - else - { - state.shotDelay = 0; - endShock(); - } - */ } break; } @@ -3600,14 +3206,6 @@ bool Avatar::isMouseInputEnabled() return true; } -int rmb_flag = 0; -void Avatar::rmbd2() -{ - rmb_flag = 1; - rmbd(); - rmb_flag = 0; -} - void Avatar::rmbd() { //core->setDockIcon("BitBlot"); @@ -3616,7 +3214,7 @@ void Avatar::rmbd() { //if (isCoordinateInRadius(dsq->getGameCursorPosition(), 96)) ///Vector diff = core->mouse.position - c; - if (dsq->inputMode == INPUT_MOUSE && !rmb_flag) + if (dsq->inputMode == INPUT_MOUSE) { Vector diff = getVectorToCursorFromScreenCentre(); if (diff.getSquaredLength2D() < sqr(openSingingInterfaceRadius)) @@ -3629,13 +3227,8 @@ void Avatar::rmbd() } else { - if (spellCastDelay == 0) - startCharge(0); + startCharge(0); } - /* - if (spellCastDelay == 0) - startCharging(1); - */ } void Avatar::rmbu() @@ -3654,17 +3247,6 @@ void Avatar::rmbu() dsq->cursorGlow->alpha.interpolateTo(0, 0.2); dsq->cursorBlinker->alpha.interpolateTo(0, 0.2); - if (pickingPullTarget) - { - if (potentialPullTarget) - { - pullTarget = potentialPullTarget; - debugLog("Calling start pull"); - pullTarget->startPull(); - } - closePullTargetInterface(); - } - if (singing) { closeSingingInterface(); @@ -3681,16 +3263,6 @@ void Avatar::rmbu() pathToActivate->activate(); pathToActivate = 0; } - - - - /* - if (charging) - { - formAbility(1); - endCharge(); - } - */ } bool Avatar::canCharge(int ability) @@ -3701,22 +3273,9 @@ bool Avatar::canCharge(int ability) if (ability == 0) return true; break; case FORM_BEAST: - //if (inTummy) return true; + return false; break; case FORM_DUAL: - /* - if (dualFormMode == DUALFORM_NAIJA) - { - if (dualFormCharge >= requiredDualFormCharge) - { - return true; - } - } - else - { - return true; - } - */ return true; break; case FORM_NATURE: @@ -3746,17 +3305,8 @@ void Avatar::startCharge(int ability) dsq->loops.charge = core->sound->playSfx(sfx); state.spellCharge = 0; - spellChargeMin = 0; chargeLevelAttained = 0; - /* - chargeGraphic->alpha = 0; - chargeGraphic->scale = Vector(0,0); - chargeGraphic->alpha.interpolateTo(0.6, chargeMax, 0); - float sz = 1.5; - chargeGraphic->scale.interpolateTo(Vector(sz,sz), chargeMax, 0); - */ - switch(dsq->continuity.form) { case FORM_ENERGY: @@ -3779,7 +3329,6 @@ void Avatar::startCharge(int ability) chargingEmitter->start(); charging = true; - abilityCharging = ability; } if (!canCharge(ability)) @@ -3795,11 +3344,6 @@ void Avatar::setBlockSinging(bool v) bool Avatar::canSetBoneLock() { - /* - if (dsq->continuity.form == FORM_FISH || dsq->continuity.form == FORM_SPIRIT) - return false; - */ - return true; } @@ -3849,13 +3393,6 @@ void Avatar::lmbd() } } } - /* - else - { - if (spellCastDelay == 0) - startCharging(0); - } - */ } void Avatar::fallOffWall() @@ -3910,17 +3447,6 @@ void Avatar::endCharge() dsq->loops.charge = BBGE_AUDIO_NOCHANNEL; } - - /* - std::ostringstream os; - os << "spellCharge: " << spellCharge; - debugLog(os.str()); - */ - /* - chargeGraphic->alpha.interpolateTo(0, 0.5, 0); - chargeGraphic->scale.interpolateTo(Vector(0,0), 1.0, 0); - */ - chargingEmitter->stop(); charging = false; @@ -3931,37 +3457,6 @@ void Avatar::endCharge() Vector Avatar::getWallNormal(TileVector t) { return dsq->game->getWallNormal(t.worldVector(), 5)*-1; - - /* - Vector accum; - int c = 0; - for (int x = -2; x <= 2; x++) - { - for (int y = -2; y <= 2; y++) - { - TileVector check = t; - check.x+=x; - check.y+=y; - if (!dsq->game->isObstructed(check)) - { - Vector v(check.x, check.y); - c++; - accum+= v; - } - //check.x+x, check.y+y - } - } - if (c > 0) - { - accum /= c; - //accum.normalize2D(); - accum.setLength2D(-1); - return accum; - } - Vector v = vel; - v.setLength2D(-1); - return v; - */ } int Avatar::getSingingInterfaceRadius() @@ -3993,7 +3488,6 @@ void Avatar::lockToWallCommon() stopRoll(); core->sound->playSfx("LockToWall", 1.0, 0);//, (1000+rand()%100)/1000.0f); //bursting = false; - animatedBurst = false; this->burst = 1; //lastLockToWallPos = position; @@ -4016,11 +3510,6 @@ void Avatar::lockToWall() if (vel.x == 0 && vel.y == 0) return; if (dsq->game->isPaused()) return; - /* - Vector opos = position; - position = lastPosition; - */ - TileVector t(position); TileVector myTile = t; // 3 + 4 @@ -4029,12 +3518,7 @@ void Avatar::lockToWall() m.setLength2D(3); t.x += int(m.x); t.y += int(m.y); - /* - TileVector t2 = t; - m.setLength2D(4); - t2.x += int(m.x); - t2.y += int(m.y); - */ + m.setLength2D(2); TileVector tback = myTile; tback.x += int(m.x); @@ -4046,27 +3530,6 @@ void Avatar::lockToWall() tnext.x += int(add.x); tnext.y += int(add.y); - // find the fraking wall - /* - TileVector actualWall = myTile; - Vector lastWall; - Vector getWall(myTile.x, myTile.y); - for (int i = -1; i < 5; i++) - { - getWall.x += add.x*i; - getWall.y += add.y*i; - if (lastWall.isZero()) - lastWall = getWall; - TileVector test(getWall.x, getWall.y); - if (dsq->game->isObstructed(test)) - break; - lastWall = getWall; - } - actualWall = TileVector(lastWall.x, lastWall.y); - */ - - Vector diff = lastLockToWallPos - position; - bool good = true; if (!dsq->game->isObstructed(t)) { @@ -4168,12 +3631,6 @@ void Avatar::lockToWall() } else { - - /* - position = TileVector(position).worldVector(); - lastPosition = position; - */ - if (!dsq->mod.isActive() && !dsq->continuity.getFlag("lockedToWall")) { @@ -4190,9 +3647,6 @@ void Avatar::lockToWall() else lockToWallFallTimer = -1; - //wallPushVec = getWallNormal(t); - - wallPushVec = wallNormal; wallPushVec *= 2000; wallPushVec.z = 0; @@ -4248,47 +3702,12 @@ void Avatar::lockToWall() { time = len/spd; } - /* - std::ostringstream os; - os << "time: " << time; - debugLog(os.str()); - */ offset.interpolateTo(offdiff, time); - /* - if (tileType == OT_INVISIBLEIN) - { - goIn = wallNormal; - goIn.setLength2D(-28); - } - else - { - Vector diff = uset.worldVector()-position; - goIn = diff; - } - offset.interpolateTo(goIn, 0.05); - */ wallLockTile = t; vel = Vector(0,0,0); vel2 = 0; - - /* - Vector oldPos = position; - - while (true) - { - Vector m = vel; - m |= 1; - position += m; - TileVector t(position); - if (dsq->game->isObstructed(t, OT_BLACK)) - { - position = oldPos; - break; - } - } - */ } } else @@ -4405,28 +3824,6 @@ void Avatar::setNearestPullTarget() } } -void Avatar::openPullTargetInterface() -{ - debugLog("Open pull target"); - if (pullTarget) - { - pullTarget->stopPull(); - } - pullTarget = 0; - potentialPullTarget = 0; - pickingPullTarget = true; - // change the cursor - dsq->cursor->color = Vector(0.5,0.5,1); -} - -void Avatar::closePullTargetInterface() -{ - debugLog("close pull target"); - pickingPullTarget = false; - potentialPullTarget = 0; - dsq->cursor->color = Vector(1,1,1); -} - void Avatar::createWeb() { web = new Web; @@ -4455,7 +3852,6 @@ Avatar::Avatar() : Entity(), ActionMapper() urchinDelay = 0; jellyDelay = 0; - warpIn = false; #ifdef AQ_TEST_QUADTRAIL quadTrail = new QuadTrail(100, 32); quadTrail->setTexture("Particles/QuadTrail"); @@ -4485,7 +3881,6 @@ Avatar::Avatar() : Entity(), ActionMapper() //registerEntityDied = true; setv(EV_ENTITYDIED, 1); - wallJumps = 0; wallBurstTimer = 0; beautyFlip = false; invincibleBreak = true; @@ -4494,7 +3889,6 @@ Avatar::Avatar() : Entity(), ActionMapper() songInterfaceTimer = 0; quickSongCastDelay = 0; flourish = false; - tummyAmount=0; blockSinging = false; singing = false; @@ -4519,31 +3913,17 @@ Avatar::Avatar() : Entity(), ActionMapper() fallGravityTimer = 0; lastOutOfWaterMaxSpeed = 0; //chargeGraphic = 0; - tummyTimer = 0; - inTummy = EAT_NONE; - ropeTimer = shieldPoints = auraTimer = 0; + shieldPoints = auraTimer = 0; glow = 0; fireDelay = 0; - inFormInterface = false; looking = false; - canWarpDelay = 0.5; - canWarp = false; rollDidOne = 0; lastQuad = lastQuadDir = rollDelay = rolling = 0; - stopTimer = 0; - doubleClickDelay = 0; - damageDelay = 0; - didShockDamage = false; chargeLevelAttained = 0; - shockTimer = 0; activeAura = AURA_NONE; - ropeState = 0; movingOn = false; currentMaxSpeed = 0; - abilityCharging = -1; - pickingPullTarget = false; - potentialPullTarget = 0; pullTarget = 0; revertTimer = 0; currentSongIdx = -1; @@ -4556,7 +3936,6 @@ Avatar::Avatar() : Entity(), ActionMapper() activateEntity = 0; canMove = true; - castShockTimer = 0; //scale = Vector(0.5, 0.5); scale = Vector(0.5, 0.5); @@ -4569,9 +3948,6 @@ Avatar::Avatar() : Entity(), ActionMapper() targets.resize(1); - - lastEntityActivation = 0; - entityToActivate = 0; pathToActivate = 0; zoomOverriden = false; @@ -4580,17 +3956,14 @@ Avatar::Avatar() : Entity(), ActionMapper() zoomVel = 0; myZoom = Vector(1,1); - spellChargeMin = spellCastDelay = 0; this->pushingOffWallEffect = 0; lockToWallFallTimer = 0; swimming = false; charging = false; bursting = false; - animatedBurst = false; burst = 1; burstDelay = 0; ignoreInputDelay = 0; - idleAnimDelay = 2; splashDelay = 0; avatar = this; @@ -4654,27 +4027,6 @@ Avatar::Avatar() : Entity(), ActionMapper() fader->alpha = 0; dsq->game->addRenderObject(fader, LR_AFTER_EFFECTS); - text = 0; - - /* - chargeGraphic = new Particle; - { - chargeGraphic->setBlendType(RenderObject::BLEND_ADD); - chargeGraphic->setTexture("glow"); - chargeGraphic->alpha = 0; - //chargeGraphic->color = Vector(1,,0); - chargeGraphic->width = 128; - chargeGraphic->height = 128; - chargeGraphic->scale = Vector(0,0); - chargeGraphic->parentManagedPointer = 1; - //chargeGraphic->positionSnapTo = &this->position; - chargeGraphic->rotation.interpolateTo(Vector(0,0,360), 1, -1, 1); - chargeGraphic->position = Vector(16, 58); - //chargeGraphic->color = Vector(1,0.2,0.1); - } - //skeletalSprite.getBoneByIdx(3)->addChild(chargeGraphic); - */ - debugLog("Avatar 6"); targetQuads.resize(targets.size()); @@ -4728,10 +4080,6 @@ Avatar::Avatar() : Entity(), ActionMapper() chargingEmitter = new ParticleEffect; dsq->getTopStateData()->addRenderObject(chargingEmitter, LR_PARTICLES); - /* - addChild(&chargingEmitter); - chargingEmitter.parentManagedStatic = true; - */ chargeEmitter = new ParticleEffect; dsq->getTopStateData()->addRenderObject(chargeEmitter, LR_PARTICLES_TOP); @@ -4742,19 +4090,6 @@ Avatar::Avatar() : Entity(), ActionMapper() rightHandEmitter = new ParticleEffect; dsq->getTopStateData()->addRenderObject(rightHandEmitter, LR_PARTICLES); - /* - leftHandEmitter = new ParticleEffect; - dsq->getTopStateData()->addRenderObject(`, LR_PARTICLES); - - rightHandEmitter = new ParticlesEffect; - dsq->getTopStateData()->addRenderObject(rightHandEmitter, LR_PARTICLES); - */ - - /* - addChild(&chargeEmitter); - chargeEmitter.parentManagedStatic = true; - */ - addChild(&biteLeftEmitter, PM_STATIC); biteLeftEmitter.load("BiteLeft"); @@ -4792,30 +4127,6 @@ Avatar::Avatar() : Entity(), ActionMapper() debugLog("Avatar 9"); - if (dsq->useMic) - { - debugLog("useMic...initing recording"); - - /* - debugLog("RecordStart..."); - avatarRecord = BASS_RecordStart(44100,1,0,&recordCallback,0); - - if (avatarRecord) - { - if (dsq->autoSingMenuOpen) - { - } - else - { - debugLog("ChannelPause..."); - BASS_ChannelPause(avatarRecord); - } - } - debugLog("...done"); - */ - } - - debugLog("Avatar 10"); setDamageTarget(DT_AVATAR_LANCE, false); //changeForm(FORM_NORMAL, false); @@ -4943,8 +4254,6 @@ void Avatar::destroy() { Entity::destroy(); - text = 0; - if (dsq->loops.shield != BBGE_AUDIO_NOCHANNEL) { core->sound->fadeSfx(dsq->loops.shield, SFT_OUT, 1); @@ -4959,24 +4268,6 @@ void Avatar::destroy() avatar = 0; } -void Avatar::fireRope() -{ - ropeVel = getAim(); - ropeVel.z = 0; - if (!ropeVel.isLength2DIn(1)) - { - ropeTimer = 0.2; - ropeState = 1; - ropePos = position; - //ropeVel = core->mouse.position - Vector(400,300); - - ropeVel.setLength2D(7000); - //ropeVel |= 500; - } - else - ropeVel = Vector(0,0,0); -} - void Avatar::toggleZoom() { if (core->globalScale.isInterpolating()) return; @@ -4989,20 +4280,8 @@ void Avatar::toggleZoom() else if (core->globalScale.x == 0.25) core->globalScale.interpolateTo(Vector(1,1),0.2); - /* - else if (core->globalScale.x == 1.5) - core->globalScale.interpolateTo(Vector(1,1),0.2); - */ - } -/* -void Avatar::setActiveSpell(Spells spell) -{ - activeSpell = spell; -} -*/ - void Avatar::startBackFlip() { if (boneLock.on) return; @@ -5050,24 +4329,6 @@ void Avatar::startBurstCommon() void Avatar::startBurst() { - //getVectorToCursorFromScreenCentre() - //!bursting && burst == 1 - //&& - /* - bool nearWallProblem = false; - if (vel.isLength2DIn(200)) - { - if () - { - nearWallProblem = false - } - else - { - nearWallProblem = true; - } - } - */ - //&& !vel.isLength2DIn(32) if (!riding && dsq->continuity.form != FORM_SPIRIT && (joystickMove || getVectorToCursor().getSquaredLength2D() > sqr(BURST_DISTANCE)) && getState() != STATE_PUSH && (!skeletalSprite.getCurrentAnimation() || (skeletalSprite.getCurrentAnimation()->name != "spin")) && _isUnderWater && !isActing(ACTION_ROLL)) @@ -5146,35 +4407,6 @@ void Avatar::startWallBurst(bool useCursor) if (goDir.x != 0 || goDir.y != 0) { lastBurstType = BURST_WALL; - /* - if (wallBurstTimer > 0) - { - Vector wallJumpDir = position - lastWallJumpPos; - if (lastWallJumpPos.isZero() || wallJumpDir.dot2D(lastWallJumpPos) > 0.2f) - { - std::ostringstream os; - os << "wallJumps: " << wallJumps; - debugLog(os.str()); - wallJumps++; - } - else - { - debugLog("failed angle"); - stopWallJump(); - } - } - wallBurstTimer = 0.8f - 0.1f * wallJumps; - if (wallBurstTimer <= 0) - { - // super boost! - debugLog("super boost!"); - wallJumps = 0; - } - - - lastWallJumpPos = position; - lastWallJumpDir = position - lastWallJumpPos; - */ dsq->rumble(0.22, 0.22, 0.2); bittenEntities.clear(); @@ -5201,10 +4433,6 @@ void Avatar::startWallBurst(bool useCursor) vel = wallPushVec; this->state.lockedToWall = false; skeletalSprite.stopAllAnimations(); - if (wallJumps > 0) - { - dsq->sound->playSfx("WallJump", 255, 0, 1000+wallJumps*100); - } dsq->game->playBurstSound(pushingOffWallEffect>0); skeletalSprite.animate(getBurstAnimName(), 0); bursting = true; @@ -5212,33 +4440,6 @@ void Avatar::startWallBurst(bool useCursor) ripples = true; startBurstCommon(); - /* - if (core->afterEffectManager) - core->afterEffectManager->addEffect(new ShockEffect(Vector(core->width/2, core->height/2),core->screenCenter,0.04,0.06,15,0.2f)); - */ - - - /* - float len = wallPushVec.getLength2D(); - goDir |= len; - goDir.z = 0; - - Vector test = goDir; - test |= TILE_SIZE*2; - if (dsq->game->isObstructed(TileVector(position + test))) - { - } - else - wallPushVec = goDir; - */ - /* - wallPushVec = Vector((wallPushVec.x+goDir.x)/2, (wallPushVec.y+goDir.y)/2); - wallPushVec |= len; - */ - } - else - { - //wallPushVec |= 10; } } } @@ -5286,18 +4487,6 @@ Vector Avatar::getFakeCursorPosition() Vector Avatar::getVectorToCursorFromScreenCentre() { - /* - if (core->joystickEnabled) - { - Vector joy(core->joystate.lX-(65536/2), core->joystate.lY-(65536/2)); - float len = (joy.getLength2D() * 600) / 65536; - joy.setLength2D(len); - std::ostringstream os; - os << "joy (" << joy.x << ", " << joy.y << ")"; - debugLog(os.str()); - return joy; - } - */ if (game->cameraOffBounds) return getVectorToCursor(); else @@ -5321,20 +4510,6 @@ Vector Avatar::getVectorToCursor(bool trueMouse) //return core->mouse.position - Vector(400,300); } -void Avatar::startWallCrawl() -{ - lastWallNormal = wallNormal; - state.crawlingOnWall = true; - skeletalSprite.transitionAnimate("crawl", 0.1, -1); -} - -void Avatar::stopWallCrawl() -{ - state.crawlingOnWall = false; - state.lockedToWall = false; - idle(); -} - void Avatar::action(int id, int state) { if (id == ACTION_PRIMARY) { if (state) lmbd(); else lmbu(); } @@ -5344,31 +4519,15 @@ void Avatar::action(int id, int state) { if (isMiniMapCursorOkay()) { - if (this->state.lockedToWall && !this->state.crawlingOnWall) + if (this->state.lockedToWall) { Vector test = getVectorToCursor(); if (test.isLength2DIn(minMouse)) { fallOffWall(); - // previously didn't fall off wall with mouse.... why? - /* - //fallOffWall(); - if (dsq->inputMode == INPUT_JOYSTICK || dsq->inputMode == INPUT_KEYBOARD) - fallOffWall(); - */ } - /* - else if (test.isLength2DIn(maxMouse)) - { - this->state.lockedToWall = false; - idle(); - } - */ else { - //if (dsq->continuity.setFlag("lockedToWall", 1) - - //!boneLock.entity && if (boneLock.entity) wallNormal = boneLock.wallNormal; @@ -5406,15 +4565,6 @@ void Avatar::action(int id, int state) } } - /* - else - { - wallNormal = getWallNormal(TileVector(position)); - Vector left = wallNormal.getPerpendicularLeft(); - Vector right = wallNormal.getPerpendicularRight(); - position += left*0.1f; - } - */ } else { @@ -5430,24 +4580,7 @@ void Avatar::action(int id, int state) } } } - /* - // song note keys - else if (!action.empty() && action[0] == 's') - { - if (isSinging()) - { - int count=0; - std::istringstream is(action.substr(1, action.size())); - is >> count; - count--; - if (count >= 0 && count <= 7) - { - core->setMousePosition(songIcons[count]->position); - } - } - } - */ else if (id >= ACTION_SONGSLOT1 && id < ACTION_SONGSLOTEND) { if (canQuickSong()) @@ -5555,240 +4688,6 @@ void Avatar::action(int id, int state) } } -void Avatar::doRangePull(float dt) -{ - int range = 4; - Vector total; - - Vector dest = position + vel*dt; - TileVector t(dest); - std::vector vectors; - for (int x = t.x-range; x <= t.x+range; x++) - { - for (int y = t.y-range; y <= t.y+range; y++) - { - TileVector tile(x,y); - if (!(tile.x == t.x && tile.y == t.y) && !dsq->game->isObstructed(tile) - && !dsq->game->isObstructed(TileVector(tile.x+1, tile.y)) - && !dsq->game->isObstructed(TileVector(tile.x, tile.y+1)) - && !dsq->game->isObstructed(TileVector(tile.x-1, tile.y)) - && !dsq->game->isObstructed(TileVector(tile.x, tile.y+1)) - ) - { - vectors.push_back(tile.worldVector()); - /* - Vector obs = tile.worldVector(); - Vector mov = position - obs; - - int len = range*TILE_SIZE - mov.getLength2D(); - if (len < 0) len = 1; - mov |= len; - total += mov; - */ - } - } - } - - unsigned int amount = 5; - if (amount > vectors.size()) - amount = vectors.size(); - std::vectorsmallestDists; - smallestDists.resize(amount); - int i = 0; - for (i = 0; i < smallestDists.size(); i++) - { - smallestDists[i] = 0x7FFFFFFF; - } - std::vector closestVectors; - closestVectors.resize(amount); - for (i = 0; i < vectors.size(); i++) - { - Vector diff = dest - vectors[i]; - int dist = diff.getSquaredLength2D(); - for (int j = 0; j < smallestDists.size(); j++) - { - if (dist < smallestDists[j]) - { - for (int k = smallestDists.size()-1; k > j; k--) - { - smallestDists[k] = smallestDists[k-1]; - closestVectors[k] = closestVectors[k-1]; - } - smallestDists[j] = dist; - closestVectors[j] = vectors[i]; - } - } - } - - for (i = 0; i < closestVectors.size(); i++) - { - Vector obs = closestVectors[i]; - if (obs.x == 0 && obs.y == 0) continue; - Vector mov = obs - position; - - int len = range*TILE_SIZE - mov.getLength2D(); - if (len < 0) len = 0; - else - { - mov.setLength2D(len); - total += mov; - } - } - - if (total.x != 0 || total.y != 0) - { - //float vlen = vel.getLength2D(); - //float len = (range*TILE_SIZE - avgDist)/range*TILE_SIZE; - //if (len > 0) - { - if (bursting && swimming) - { - total.setLength2D(dt*4000); - } - else if (swimming) - { - //vel = Vector(0,0,0); - //vel |= vlen; - total.setLength2D(dt*1000); - } - else - { - total.setLength2D(dt*200); - } - vel += total; - } - /* - if (vlen < 250) - { - total |= 200*dt; - } - else - */ - /* - { - total |= 500*dt; - } - */ - - } -} - -void Avatar::doRangePush(float dt) -{ - // current not used - /* - if (vel.getSquaredLength2D() < sqr(1)) return; - int range = 4; - Vector total; - TileVector t(position); - std::vector vectors; - for (int x = t.x-range; x <= t.x+range; x++) - { - for (int y = t.y-range; y <= t.y+range; y++) - { - TileVector tile(x,y); - if (dsq->game->isObstructed(tile)) - { - vectors.push_back(tile.worldVector()); - } - } - } - - int amount = 5; - if (amount > vectors.size()) - amount = vectors.size(); - std::vectorsmallestDists; - smallestDists.resize(amount); - for (int i = 0; i < smallestDists.size(); i++) - { - smallestDists[i] = 0x7FFFFFFF; - } - std::vector closestVectors; - closestVectors.resize(amount); - for (int i = 0; i < vectors.size(); i++) - { - Vector diff = position - vectors[i]; - int dist = diff.getSquaredLength2D(); - for (int j = 0; j < smallestDists.size(); j++) - { - if (dist < smallestDists[j]) - { - for (int k = smallestDists.size()-1; k > j; k--) - { - smallestDists[k] = smallestDists[k-1]; - closestVectors[k] = closestVectors[k-1]; - } - smallestDists[j] = dist; - closestVectors[j] = vectors[i]; - } - } - } - - float tot=0; - int c = 0; - for (int i = 0; i < smallestDists.size(); i++) - { - if (smallestDists[i] < HUGE_VALF) - { - tot += smallestDists[i]; - c++; - } - } - float avgDist = range*TILE_SIZE; - if (c > 0) - { - avgDist = tot / c; - } - - - - for (int i = 0; i < closestVectors.size(); i++) - { - Vector obs = closestVectors[i]; - if (obs.x == 0 && obs.y == 0) continue; - Vector mov = position - obs; - - int len = range*range*TILE_SIZE - mov.getLength2D(); - if (len < 0) len = 0; - else - { - mov |= len; - total += mov; - } - } - - if (total.x != 0 || total.y != 0) - { - float vlen = vel.getLength2D(); - //float len = (range*TILE_SIZE - avgDist)/range*TILE_SIZE; - //if (len > 0) - { - float totLen = 0; - if (swimming) - { - totLen = dt*600; - } - else - { - totLen = dt*50; - } - total |= totLen; - - Vector perp = vel; - Vector n = vel; - n.normalize2D(); - float d = total.dot2D(n); - perp |= d; - total -= perp; - total |= totLen; - lastPush = total; - vel += total; - } - } - */ - -} - void Avatar::render() { @@ -5802,74 +4701,11 @@ void Avatar::render() Entity::render(); - if (ropeState != 0) - { -#ifdef BBGE_BUILD_OPENGL - glPushMatrix(); - glColor4f(1.0f,0.0f,0.0f,1.0f); - glBegin(GL_LINES); - glVertex3f(position.x, position.y, 0); - glVertex3f(ropePos.x, ropePos.y, 0); - glEnd(); - glPopMatrix(); -#endif - } - - /* - if (activeAura == AURA_SHIELD) - { - glPushMatrix(); - glColor4f(0,0.5,1,1); - glTranslatef(shieldPosition.x, shieldPosition.y, 0); - drawCircle(AURA_SHIELD_RADIUS, 8); - glPopMatrix(); - } - */ - } void Avatar::onRender() { Entity::onRender(); - - /* - // HACK - if (RenderObject::renderPaths) - { - glPushMatrix(); - glLoadIdentity(); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glColor4f(1, 0, 0, 0.5); - glTranslatef(400, 300, 0); - drawCircle(64); - glPopMatrix(); - } - */ - - //dsq->print(20, 600-100, "Naija: Hello there. My name is fred."); - /* - std::ostringstream os; - os << lastPush.x << ", " << lastPush.y; - debugLog(os.str()); - */ - /* - glPopMatrix(); - glPushMatrix(); - glTranslatef(position.x, position.y, position.z); - //glRotatef(0, 0, 1, -rotation.z); - glDisable(GL_BLEND); - glPointSize(12); - glDisable(GL_LIGHTING); - glColor3f(1,0,0); - glBegin(GL_LINES); - //glColor3f(1, 0, 0); - glVertex3f(0,0,0); - //glColor3f(1, 0, 0); - glVertex3f(lastPush.x*50, lastPush.y*50, 0); - glEnd(); - glPopMatrix(); - */ } int Avatar::getBeamWidth() @@ -5922,26 +4758,10 @@ void Avatar::onEnterState(int action) if (action == STATE_PUSH) { state.lockedToWall = false; - state.crawlingOnWall = false; Animation *a = skeletalSprite.getCurrentAnimation(); if (!a || (a && a->name != "pushed")) skeletalSprite.animate("pushed", 0); } - else if (action == STATE_EATING) - { - /* - // the problems with this: - // 1. what happens out of water? - // 2. is the delay too long? - // could just play a sound and then spawn some kind of particle effect - disableInput(); - idle(); - vel=vel2=Vector(0,0); - skeletalSprite.animate("eat", 0, ANIM_OVERRIDE); - core->main(1); - enableInput(); - */ - } } void Avatar::onExitState(int action) @@ -5954,10 +4774,6 @@ void Avatar::onExitState(int action) else if (action == STATE_PUSH) { skeletalSprite.transitionAnimate("spin", 0.1); - /* - rotation.z = rotation.z+360; - rotation.interpolateTo(Vector(0,0,rotation.z-360-90), 0.5); - */ } } @@ -6022,25 +4838,6 @@ void Avatar::splash(bool down) } dsq->spawnParticleEffect("Splash", position, a); - - - //Vector(position.x, dsq->game->waterLevel.x)); - /* - Quad *splash = new Quad; - splash->setTexture("splash"); - splash->position = this->position; - splash->position.y = dsq->game->waterLevel-splash->width.x/2; - float t = 0.5; - splash->alpha.path.addPathNode(0, 0); - splash->alpha.path.addPathNode(1, 0.25); - splash->alpha.path.addPathNode(0, 1); - splash->alpha.startPath(t); - splash->scale = Vector(1.5, 0.9); - splash->scale.interpolateTo(Vector(0.5,1.2),t); - splash->setLife(1); - splash->setDecayRate(0.9); - core->getTopStateData()->addRenderObject(splash, LR_PARTICLES); - */ } void Avatar::clampVelocity() @@ -6313,13 +5110,11 @@ void Avatar::stopBurst() //burstDelay = BURST_DELAY; burstDelay = 0; bursting = false; - animatedBurst = false; wakeEmitter.stop(); ripples = false; biteLeftEmitter.stop(); biteRightEmitter.stop(); -// lastWallJumpPos = Vector(0,0,0); } int Avatar::getCursorQuadrant() @@ -6341,7 +5136,6 @@ int Avatar::getCursorQuadrant() int Avatar::getQuadrantDirection(int lastQuad, int quad) { int diff = quad - lastQuad; - //if (lastQuad==0) return 0; if ((lastQuad==4 && quad == 1)) { diff = 1; @@ -6372,18 +5166,11 @@ void Avatar::startRoll(int dir) } Animation *a = skeletalSprite.getCurrentAnimation(); - //debugLog("start roll!"); if (!a || a->name != getRollAnimName()) { skeletalSprite.transitionAnimate(getRollAnimName(), 0.2, -1); } - /* - rollRightEmitter.load("RollRight"); - rollLeftEmitter.load("RollLeft"); - rollRightEmitter.start(); - rollLeftEmitter.start(); - */ rollRightEmitter.stop(); rollLeftEmitter.stop(); @@ -6413,23 +5200,9 @@ void Avatar::startRoll(int dir) { core->sound->fadeSfx(dsq->loops.roll, SFT_OUT, 0.5); } - /* - //HACK: make this dt based - static int rollBits = 0; - rollBits = rollBits + 1; - if (rollBits > 6) - { - if (_isUnderWater) - core->sound->playSfx("Roll2"); - rollBits = 0; - } - */ + rollDir = dir; - /* - if (core->afterEffectManager) - core->afterEffectManager->addEffect(new ShockEffect(Vector(core->width/2, core->height/2),core->screenCenter,0.04,0.06,15,0.2f)); - */ if (_isUnderWater && core->afterEffectManager) core->afterEffectManager->addEffect(new ShockEffect(Vector(core->width/2, core->height/2),core->screenCenter,0.08,0.05,22,0.2f, 1.2)); @@ -6458,8 +5231,6 @@ void Avatar::stopRoll() void Avatar::stopWallJump() { wallBurstTimer = 0; - wallJumps = 0; - lastWallJumpPos = Vector(0,0,0); } void Avatar::updateWallJump(float dt) @@ -6487,11 +5258,6 @@ void Avatar::updateRoll(float dt) if (rollDelay > 0) { - /* - std::ostringstream os; - os << "rollDelay: " << rollDelay; - debugLog(os.str()); - */ rollDelay -= dt; if (rollDelay <= 0) { @@ -6514,19 +5280,6 @@ void Avatar::updateRoll(float dt) if (rolling) { - /* - FOR_ENTITIES (i) - { - Entity *e = *i; - if (e->getEntityType() == ET_ENEMY && (e->position - this->position).isLength2DIn(350)) - { - //e->move(dt, 500, 1, this); - Vector diff = (position - e->position); - diff.setLength2D(1000*dt); - e->vel2 += diff; - } - } - */ if (dsq->continuity.form == FORM_ENERGY && dsq->continuity.hasFormUpgrade(FORMUPGRADE_ENERGY1)) { FOR_ENTITIES(i) @@ -6554,14 +5307,6 @@ void Avatar::updateRoll(float dt) } } - /* - //HACK: -ish, fixes low frame rate roll stuck problem? - // nope - if (rollDelay == 0) - { - rollDelay = 0.01; - } - */ // NOTE: does this fix the roll problem? if (rollDelay <= 0) stopRoll(); @@ -6615,19 +5360,6 @@ void Avatar::updateRoll(float dt) } } } - /* - std::ostringstream os; - os << "quad: " << quad << " lastQuad: " << lastQuad << " lastQuadDir: " << lastQuadDir; - debugLog(os.str()); - */ - - - /* - if (lastQuad != 0) - { - lastQuadDir = quadDir; - } - */ lastQuadDir = quadDir; @@ -6648,28 +5380,6 @@ int Avatar::getBurstDistance() return BURST_DISTANCE; } -void Avatar::updateTummy(float dt) -{ - if (dsq->continuity.form == FORM_BEAST) - { - //dsq->shakeCamera(5, 0.1); - - /* - if (inTummy > 0) - { - tummyTimer += dt; - if (tummyTimer > TUMMY_TIME) - { - //core->sound->playSfx("Digest"); - //heal(inTummy); - inTummy = 0; - } - } - */ - - } -} - void Avatar::setWasUnderWater() { state.wasUnderWater = isUnderWater(); @@ -6814,7 +5524,6 @@ void Avatar::updateLookAt(float dt) { if (lastHeadTexture.empty()) { - //if (dsq->continuity.form == FORM_NORMAL) setHeadTexture("blink", 0.1); if (chance(50)) { @@ -6876,20 +5585,8 @@ void Avatar::updateLookAt(float dt) bone_head->rotationOffset.z = oldRot - bone_head->rotation.z; bone_head->rotationOffset.interpolateTo(Vector(0,0,0), t); bone_head->internalOffset.interpolateTo(Vector(0,0,0), t); - /* - std::ostringstream os; - os << "rotationOffset lerp " << bone_head->rotationOffset.z; - debugLog(os.str()); - */ } - /* - bone_head->rotationOffset = bone_head->rotation.z; - bone_head->rotation.z = 0; - bone_head->rotationOffset.interpolateTo(0, 0.2); - */ - //state.updateLookAtTime += dt*10; - //state.updateLookAtTime += dt; state.updateLookAtTime += dt*4*2; bone_head->internalOffset.interpolateTo(Vector(0,0), 0.2); } @@ -6899,23 +5596,7 @@ void Avatar::updateLookAt(float dt) state.lookAtEntity = dsq->game->getNearestEntity(position, 800, this, ET_NOTYPE, DT_NONE, LR_ENTITIES0, LR_ENTITIES2); if (state.lookAtEntity && state.lookAtEntity->isv(EV_LOOKAT, 1)) { - /* - std::ostringstream os; - os << "Nearest: " << state.lookAtEntity->name; - debugLog(os.str()); - */ - state.updateLookAtTime = 0; - //if (dsq->continuity.form == FORM_NORMAL) - //setHeadTexture("blink", 0.1); - - /* - if (state.lookAtEntity->getEntityType() == ET_NEUTRAL) - { - //if (dsq->continuity.form == FORM_NORMAL) - //setHeadTexture("smile", 1); - } - */ if (!state.lookAtEntity->naijaReaction.empty()) { @@ -6925,15 +5606,8 @@ void Avatar::updateLookAt(float dt) else { state.lookAtEntity = 0; - /* - std::ostringstream os; - os << state.updateLookAtTime << " : found no entities"; - debugLog(os.str()); - */ - //state.updateLookAtTime -= 0.3f; - } - //skeletalSprite.animate("blink", 2, ANIMLAYER_HEADOVERRIDE); + } } } } @@ -6950,70 +5624,13 @@ bool lastCursorKeyboard = false; bool Avatar::isMiniMapCursorOkay() { -//!(dsq->getMouseButtonState(0) || dsq->getMouseButtonState(1)) return ((dsq->inputMode != INPUT_MOUSE) || (!dsq->game->miniMapRender || !dsq->game->miniMapRender->isCursorIn())); } -void Avatar::updateCursorFromKeyboard() -{ - /* - // why return when singing?? - //if (isSinging()) return; - if (!isInputEnabled()) return; - - Vector diff; - int dist = 200; - if (isActing(ACTION_SINGLEFT)) - diff.x = -dist; - if (isActing(ACTION_SINGRIGHT)) - diff.x = dist; - if (isActing(ACTION_SINGUP)) - diff.y = -dist; - if (isActing(ACTION_SINGDOWN)) - diff.y = dist; - if (!diff.isZero()) - { - diff.setLength2D(dist); - core->mouse.position = Vector(400,300) + diff; - lastCursorKeyboard = true; - } - else if (lastCursorKeyboard) - { - debugLog("HEY!: lastCursorKeyboard mouse position reset"); - core->mouse.position = Vector(400,300); - lastCursorKeyboard = false; - dsq->toggleCursor(false, 0.2); - } - - //!diff.isZero() || - if (isInputEnabled() && (!core->mouse.change.isZero())) - { - dsq->toggleCursor(true, 0.2); - } - */ -} - void Avatar::onUpdate(float dt) { BBGE_PROF(Avatar_onUpdate); - // animation debug code - /* - for (int i = 0; i < 8; i++) - { - if (skeletalSprite.getAnimationLayer(i)) - { - if (skeletalSprite.getAnimationLayer(i)->isAnimating()) - { - std::ostringstream os; - os << "anim layer: " << i << " - " << skeletalSprite.getAnimationLayer(i)->getCurrentAnimation()->name; - debugLog(os.str()); - //debugLog("anim layer 0: " + skeletalSprite.getAnimationLayer(0)->getCurrentAnimation()->name); - } - } - } - */ - looking = 0; #ifdef AQ_TEST_QUADTRAIL @@ -7048,16 +5665,6 @@ void Avatar::onUpdate(float dt) vel = Vector(0,0); } - if (canWarpDelay > 0) - { - canWarpDelay = canWarpDelay - dt; - if (canWarpDelay < 0) - { - canWarp = true; - canWarpDelay = 0; - } - } - if (fireDelay > 0) { fireDelay -= dt; @@ -7067,13 +5674,6 @@ void Avatar::onUpdate(float dt) } } - if (doubleClickDelay > 0) - { - doubleClickDelay = doubleClickDelay - dt; - if (doubleClickDelay < 0) doubleClickDelay = 0; - } - - if (isInputEnabled()) { if (web) @@ -7139,35 +5739,6 @@ void Avatar::onUpdate(float dt) } } - /* - if (!targets.empty()) - { - if (targets[0] && (targets[0]->position - this->position).getSquaredLength2D() > sqr(TARGET_RANGE)) - { - clearTargets(); - } - } - */ - //spawnChildClone(4); - if (!core->cameraRot.isInterpolating()) - // 10 - core->cameraRot.interpolateTo(Vector(0,0,360), 30, -1); - /* - for (int i = 0; i < targets.size(); i++) - { - if (targets[i] && !this->isEntityDead()) - { - targetQuads[i]->alpha.interpolateTo(1,0.1); - targetQuads[i]->position = targets[i]->position; - } - else - { - if (targetQuads[i]->alpha.getValue()>0) - targetQuads[i]->alpha.interpolateTo(0,0.1); - } - } - */ - Entity::onUpdate(dt); if (isEntityDead() && skeletalSprite.getCurrentAnimation()->name != "dead") @@ -7359,8 +5930,6 @@ void Avatar::onUpdate(float dt) } - //skeletalSprite.getBoneByIdx(3)->getWorldPosition(); - state.wasUnderWater = _isUnderWater; if (!_isUnderWater) @@ -7385,30 +5954,6 @@ void Avatar::onUpdate(float dt) } } - /* - if (core->afterEffectManager && _isUnderWater) - { - if (swimming && vel.getSquaredLength2D() > sqr(200)) - { - rippleTimer += dt; - while (rippleTimer > RIPPLE_INTERVAL) - { - // 0.01 20 - core->afterEffectManager->addEffect(new ShockEffect(Vector(core->width/2, core->height/2),core->screenCenter,0.05,0.08,15,0.2f, 1.2)); - - //core->afterEffectManager->addEffect(new ShockEffect(Vector(400,300),0.01,0.002f,15,0.1f)); - rippleTimer = 0; - } - } - } - */ - - - /* - bobTimer += dt*2; - offset.y = sinf(bobTimer)*5 - 2.5f; - */ - if (isEntityDead()) { updateHair(dt); @@ -7470,7 +6015,6 @@ void Avatar::onUpdate(float dt) tripDelay -= dt; if (tripDelay < 0) { -; tripDelay = 0.15; tripCount ++; if (tripCount > 10) @@ -7529,28 +6073,10 @@ void Avatar::onUpdate(float dt) lastPosition = position; } - - updateCursorFromKeyboard(); updateFormVisualEffects(dt); - updateShock(dt); updateRoll(dt); - updateTummy(dt); updateWallJump(dt); - if (dsq->autoSingMenuOpen) - { - if (micNote != -1 && !this->isSinging()) - { - openedFromMicInput = true; - openSingingInterface(); - } - if (micNote == -1 && isSinging() && openedFromMicInput) - { - openedFromMicInput = false; - closeSingingInterface(); - } - } - if (formAbilityDelay > 0) { formAbilityDelay -= dt; @@ -7575,49 +6101,6 @@ void Avatar::onUpdate(float dt) } updateAura(dt); - switch(ropeState) - { - case 1: - { - if (ropeTimer > 0) - { - ropeTimer -= dt; - if (ropeTimer < 0) - { - ropeState = 0; - ropeTimer = 0; - } - } - ropePos += ropeVel*dt; - if (dsq->game->isObstructed(TileVector(ropePos))) - { - ropeState = 2; - ropeTimer = 2; - } - std::ostringstream os; - os << "ropePos (" << ropePos.x << ", " << ropePos.y << ")"; - debugLog(os.str()); - } - break; - case 2: - if (ropeTimer > 0) - { - ropeTimer -= dt; - if (ropeTimer < 0) - { - ropeState = 0; - ropeTimer = 0; - } - } - Vector add = (ropePos - position); - if (add.getSquaredLength2D() > sqr(200)) - { - add.setLength2D(4000); - vel += add*dt; - } - break; - } - updateSingingInterface(dt); @@ -7628,53 +6111,10 @@ void Avatar::onUpdate(float dt) pullTarget->stopPull(); pullTarget = 0; } - else - { - /* - static float c = 0; - c += dt; - if (c > 0.2f) - { - EnergyTendril *t = new EnergyTendril(avatar->position, pullTarget->position); - core->addRenderObject(t, LR_PARTICLES); - c -= dt; - } - */ - } } formTimer += dt; - /* - if (formTimer > 2.0f && dsq->continuity.form == FORM_SPIRIT) - { - changeForm(FORM_NORMAL, true); - } - */ - if (pickingPullTarget) - { - //debugLog("picking pull target"); - Entity *closest = 0; - float smallestDist = HUGE_VALF; - FOR_ENTITIES(i) - { - Entity *e = *i; - - if (e->isPullable() && e->life == 1) - { - if (e->isCoordinateInside(dsq->getGameCursorPosition())) - { - float dist = (e->position - dsq->getGameCursorPosition()).getSquaredLength2D(); - if (dist < smallestDist) - { - smallestDist = dist; - closest = e; - } - } - } - } - potentialPullTarget = closest; - } if (dsq->continuity.form == FORM_SPIRIT) { @@ -7700,10 +6140,6 @@ void Avatar::onUpdate(float dt) static bool revertButtonsAreDown = false; if (inputEnabled && (dsq->inputMode == INPUT_KEYBOARD || dsq->inputMode == INPUT_MOUSE) && (!pathToActivate && !entityToActivate)) { - //debugLog("update stuff"); - ///*&& dsq->continuity.form != FORM_SPIRIT*/ - //|| isActing(ACTION_PRIMARY) - //|| isActing(ACTION_SECONDARY) if (dsq->continuity.form != FORM_NORMAL && (core->mouse.pure_buttons.left && core->mouse.pure_buttons.right) && getVectorToCursor(true).isLength2DIn(minMouse)) { if (!revertButtonsAreDown) @@ -7740,97 +6176,11 @@ void Avatar::onUpdate(float dt) revertButtonsAreDown = false; } - /* - if (this->state.crawlingOnWall) - { - if (isActing("a1")) - { - wallNormal = dsq->game->getWallNormal(position); - if (wallNormal.dot2D(lastWallNormal)<=0.3f) - { - stopWallCrawl(); - } - else - { - Vector left = wallNormal.getPerpendicularLeft(); - Vector right = wallNormal.getPerpendicularRight(); - - - Vector test = getVectorToCursor(); - if (!test.isLength2DIn(64)) - { - test.normalize2D(); - - Vector move; - if (test.dot2D(left)>0) - move = left; - else - move = right; - - move.setLength2D(800); - - if (move.x > 0 && !isfh()) - flipHorizontal(); - if (move.x < 0 && isfh()) - flipHorizontal(); - - position += move*dt; - rotateToVec(wallNormal, 0.1); - } - else - { - stopWallCrawl(); - } - } - } - else - { - stopWallCrawl(); - } - } - */ - //if (core->getNestedMains() == 1) { - if (leaches > 3) - { - /* - const float leachHurtInterval = 3; - state.leachTimer += dt; - if (state.leachTimer > leachHurtInterval) - { - state.leachTimer -= leachHurtInterval; - DamageData d; - d.damage = int(leaches/3); - damage(d); - //hit(0, 0, SPELL_NONE, int(leaches/3)); - } - */ - } - - if (getState() != STATE_TRANSFORM && dsq->continuity.getWorldType() == WT_NORMAL) - //if (dsq->continuity.form == FORM_ENERGY) { - //if (dsq->continuity.selectedSpell == SPELL_SHOCK) - formAbilityUpdate(dt); - - // is this really necessary?? - // YES! - // this allows the player to start charging quickly after firing - /* - if (isActing("charge") && !charging && spellCastDelay == 0 && inputEnabled) - { - this->rmbd(); - } - */ - // maybe not useful anymore - /* - if (!isActing("charge") && charging && spellChargeDelay == 0 && inputEnabled) - { - } - */ } if (state.useItemDelay.updateCheck(dt)) @@ -7849,29 +6199,6 @@ void Avatar::onUpdate(float dt) removeBlindEffects(); } } - - /*&& this->getSelectedSpell() == SPELL_ENERGYBLAST*/ - /* - // HACK: hacked out for now - // FINDTARGET - - if (charging && !targets.empty() && targets[0] == 0 && state.spellCharge > 0.2f - && dsq->continuity.form == FORM_ENERGY) - { - FOR_ENTITIES (i) - { - Entity *e = *i; - if (e && e != this && e->isAvatarAttackTarget() && !e->isEntityDead() && e->isAffectedBySpell(SPELL_ENERGYBLAST)) - { - ScriptedEntity *se = (ScriptedEntity*)e; - if ((e->position - dsq->getGameCursorPosition()).getSquaredLength2D() < sqr(64)) - { - targets[0] = e; - } - } - } - } - */ } @@ -7900,15 +6227,6 @@ void Avatar::onUpdate(float dt) } } - if (spellCastDelay > 0) - { - spellCastDelay -= dt; - if (spellCastDelay <= 0) - { - spellCastDelay = 0; - } - } - if (state.lockToWallDelay.updateCheck(dt)) { } @@ -7918,7 +6236,6 @@ void Avatar::onUpdate(float dt) pushingOffWallEffect -= dt; if (pushingOffWallEffect <= 0) { - lastLockToWallPos = Vector(0,0); pushingOffWallEffect = 0; if (vel.getSquaredLength2D() > sqr(1200)) { @@ -7926,53 +6243,9 @@ void Avatar::onUpdate(float dt) } } } - /* - if (beamFiring) - { - // collides enemies with beam as well - beam->width = getBeamWidth(); - Vector diff = dsq->getGameCursorPosition() - this->position; - diff |= beam->width.getValue()/2.0f; - beam->position = this->position + diff; - float angle=0; - MathFunctions::calculateAngleBetweenVectorsInDegrees(this->position, dsq->getGameCursorPosition(), angle); - beam->rotation.z = angle+90; - beam->position.z = 3; - //collideBeamWithEntities(); - } - */ - if (state.dodgeEffectTimer.updateCheck(dt)) - { - vel.capLength2D(vars->maxSwimSpeed); - /* - if (vel.getSquaredLength2D() > sqr(vars->maxSwimSpeed)) - vel.setLength2D(vars->maxSwimSpeed); - */ - } - /* - if (dodgeEffectTimer > 0) - { - dodgeEffectTimer -= dt; - if (dodgeEffectTimer <= 0) - { - dodgeEffectTimer = 0; - if (vel.getSquaredLength2D() > sqr(vars->maxSwimSpeed)) - vel |= vars->maxSwimSpeed; - } - } - */ - - if (text) - { - text->position = position + Vector(100); - } if (charging) { - /* - chargeGraphic->position = this->position; - chargeGraphic->position.z = position.z + 0.05f; - */ state.spellCharge += dt; switch (dsq->continuity.form) { @@ -7999,37 +6272,11 @@ void Avatar::onUpdate(float dt) chargingEmitter->load("ChargedDualForm"); chargingEmitter->start(); - - - - //chargeVisualEffect("particles/energy-charge-2"); } - /* - if (state.spellCharge >= 1.5f && chargeLevelAttained<2) - { - chargeLevelAttained = 2; - - core->sound->playSfx("PowerUp"); - //debugLog("charge visual effect 2"); - chargeEmitter->load("EnergyCharge"); - chargeEmitter->start(); - - //chargeVisualEffect("particles/energy-charge-2"); - } - */ } break; case FORM_ENERGY: { - /* - if (state.spellCharge >= 0.99f && chargeLevelAttained<1) - { - chargeLevelAttained = 1; - debugLog("charge visual effect 1"); - chargeVisualEffect("energy-charge-1"); - - } - */ if (state.spellCharge >= 1.5f && chargeLevelAttained<2) { chargeLevelAttained = 2; @@ -8056,26 +6303,6 @@ void Avatar::onUpdate(float dt) chargingEmitter->load("ChargingNature2"); chargingEmitter->start(); } - /* - if (state.spellCharge >= 0.5f && chargeLevelAttained<1) - { - chargeLevelAttained = 1; - core->sound->playSfx("PowerUp"); - chargeEmitter->load("ChargeNature"); - chargeEmitter->start(); - } - - if (state.spellCharge >= 2.0f && chargeLevelAttained<2) - { - chargeLevelAttained = 2; - core->sound->playSfx("PowerUp"); - chargeEmitter->load("ChargeNature2"); - chargeEmitter->start(); - - chargingEmitter->load("ChargingNature2"); - chargingEmitter->start(); - } - */ } break; } @@ -8185,7 +6412,7 @@ void Avatar::onUpdate(float dt) } } - if (!(state.lockedToWall || state.dodgeEffectTimer.isActive()) && _isUnderWater && dsq->continuity.getWorldType() == WT_NORMAL && canMove) + if (!state.lockedToWall && _isUnderWater && dsq->continuity.getWorldType() == WT_NORMAL && canMove) { if (bursting) { @@ -8208,18 +6435,8 @@ void Avatar::onUpdate(float dt) } if (inputEnabled && _isUnderWater) { - if (bursting) + if(bursting) { - // disable check to stop burst - /* - if (!isActing("a1")) - { - stopBurst(); - //bursting = false; - //burstDelay = BURST_DELAY; - //animatedBurst = false; - } - */ } else if (burstDelay > 0) { @@ -8238,7 +6455,7 @@ void Avatar::onUpdate(float dt) bool moved = false; //check to make sure there's still a wall there, if not fall off - if (state.lockedToWall && !state.crawlingOnWall) + if (state.lockedToWall) { rotateToVec(wallPushVec, dt*2); if (!boneLock.on && !dsq->game->isObstructed(wallLockTile)) @@ -8248,7 +6465,7 @@ void Avatar::onUpdate(float dt) } } - if (getState() != STATE_PUSH && !state.lockedToWall && inputEnabled && !ignoreInputDelay && _isUnderWater && canMove) + if (getState() != STATE_PUSH && !state.lockedToWall && inputEnabled && _isUnderWater && canMove) { float a = 800*dt; Vector lastVel = vel; @@ -8260,8 +6477,6 @@ void Avatar::onUpdate(float dt) static bool lastDown; float len = 0; - //dsq->continuity.toggleMoveMode && - //!dsq->continuity.toggleMoveMode && if (isMiniMapCursorOkay() && !isActing(ACTION_ROLL) && _isUnderWater && !riding && !boneLock.on && @@ -8291,12 +6506,6 @@ void Avatar::onUpdate(float dt) { if (dsq->inputMode == INPUT_JOYSTICK) addVec = Vector(0,0,0); - /* - if (dsq->inputMode == INPUT_JOYSTICK && !core->mouse.buttons.left) - { - addVec = Vector(0,0,0); - } - */ } @@ -8442,8 +6651,8 @@ void Avatar::onUpdate(float dt) add.setLength2D(BURST_ACCEL*dt); vel += add; - if (pushingOffWallEffect > 0 || wallJumps > 0) - currentMaxSpeed = vars->maxWallJumpBurstSpeed + 50*wallJumps; + if (pushingOffWallEffect > 0) + currentMaxSpeed = vars->maxWallJumpBurstSpeed; else currentMaxSpeed = vars->maxBurstSpeed; @@ -8452,8 +6661,6 @@ void Avatar::onUpdate(float dt) { if (pushingOffWallEffect > 0) currentMaxSpeed = vars->maxWallJumpSpeed; - else if (state.dodgeEffectTimer.isActive()) - currentMaxSpeed = vars->maxDodgeSpeed; else { if (isActing(ACTION_SLOW) || isMovingSlow) @@ -8493,9 +6700,6 @@ void Avatar::onUpdate(float dt) if (currentMaxSpeed < 0) currentMaxSpeed = 1; - if (ropeState == 2 && currentMaxSpeed < vars->maxWallJumpBurstSpeed) - currentMaxSpeed = vars->maxWallJumpBurstSpeed; - /* if (inCurrent) { @@ -8580,8 +6784,6 @@ void Avatar::onUpdate(float dt) { if (getState() == STATE_IDLE && !rolling) skeletalSprite.transitionAnimate(getBurstAnimName(), ANIM_TRANSITION); - //animate(anim_burst); - animatedBurst = true; } } } @@ -8637,19 +6839,6 @@ void Avatar::onUpdate(float dt) } if (isLockable()) lockToWall(); - /* - if (isActing("left")) - addVec += Vector(-a, 0); - if (isActing("right")) - addVec += Vector(a, 0); - */ - /* - if (isActing("up")) - addVec += Vector(0, -a); - if (isActing("down")) - addVec += Vector(0, a); - */ - //vel += addVec; } if (!moved) @@ -8657,7 +6846,6 @@ void Avatar::onUpdate(float dt) if (swimming) { swimming = false; - idleAnimDelay = 0; if (dsq->continuity.form == FORM_FISH) rotation.interpolateTo(0, 0.2); } @@ -8706,9 +6894,6 @@ void Avatar::onUpdate(float dt) if (!inCurrent) currentMaxSpeed = vars->maxSwimSpeed; - if (ropeState == 2 && currentMaxSpeed < vars->maxWallJumpBurstSpeed) - currentMaxSpeed = vars->maxWallJumpBurstSpeed; - if (!state.lockedToWall && !bursting) { if (getState() == STATE_IDLE && inputEnabled) @@ -8717,22 +6902,6 @@ void Avatar::onUpdate(float dt) if (a && a->name != getIdleAnimName() && a->name != "pushed" && a->name != "spin" && !rolling) skeletalSprite.transitionAnimate(getIdleAnimName(), ANIM_TRANSITION, -1); } - /* - idleAnimDelay -= dt; - if (idleAnimDelay <= 0) - { - idleAnimDelay = 1.5;//anim_idle.time*2; - - //if (currentAction == IDLE && (!skeletalSprite.isAnimating() || skeletalSprite.getCurrentAnimation()->name=="swim" - // || skeletalSprite.getCurrentAnimation()->name=="a1")) - if (currentAction == STATE_IDLE) - { - skeletalSprite.transitionAnimate("idle", ANIM_TRANSITION); - } - - //animate(anim_idle); - } - */ } } @@ -8750,7 +6919,6 @@ void Avatar::onUpdate(float dt) if (swimming) { - //static bool lastSpreadUp = false; if (!rolling && !internalOffset.isInterpolating()) { int spread = 8; @@ -8760,25 +6928,10 @@ void Avatar::onUpdate(float dt) internalOffset = Vector(-spread, 0); internalOffset.interpolateTo(Vector(spread, 0), t, -1, 1, 1); - /* - rotationOffset = Vector(-rotSpread, 0); - rotationOffset.interpolateTo(Vector(rotSpread, 0), t, -1, 1, 1); - */ - for (int i = 0; i < int((t*0.5f)/0.01f); i++) { internalOffset.update(0.01); - //rotationOffset.update(0.01); } - /* - if (lastSpreadUp) - internalOffset.interpolateTo(Vector(spread, 0), t, 1, 1, 1); - else - internalOffset.interpolateTo(Vector(-spread, 0), t, 1, 1, 1); - */ - - //lastSpreadUp = !lastSpreadUp; - //internalOffset.update(t*0.5f); } if (dsq->continuity.form != FORM_ENERGY && dsq->continuity.form != FORM_DUAL && dsq->continuity.form != FORM_FISH) @@ -8903,11 +7056,6 @@ void Avatar::onUpdate(float dt) } - if (state.dodgeEffectTimer.isActive()) - { - vel += dodgeVec*dt; - } - if (!state.lockedToWall && !bursting && _isUnderWater && swimming && !isFollowingPath()) { //debugLog("collision avoidance"); @@ -8917,15 +7065,6 @@ void Avatar::onUpdate(float dt) doCollisionAvoidance(dt, 2, 1.0, 0, 800, OT_HURT); } - // friction for extraVel - if (!extraVel.isZero()) - { - Vector d = extraVel; - d.setLength2D(100); - extraVel -= d*dt; - } - - if (!game->isShuttingDownGameState()) { updateCurrents(dt); @@ -8971,7 +7110,7 @@ void Avatar::onUpdate(float dt) os << "vel (" << vel.x << ", " << vel.y << ")"; debugLog(os.str()); */ - Vector mov = (moveVel * dt) + (extraVel * dt); + Vector mov = (moveVel * dt); Vector omov = mov; mov.capLength2D(TILE_SIZE); /* @@ -9104,19 +7243,6 @@ void Avatar::onUpdate(float dt) // && dsq->game->getPercObsInArea(position, 4) < 0.75f if (!inCurrent) { - /* - int px=int(position.x); - int py=int(position.y); - int llpx=int(lastLastPosition.x); - int llpy=int(lastLastPosition.y); - if (px == llpx && py == llpy) - { - - } - else - { - */ - //doBounce(); if (bursting) { //vel = 0; @@ -9145,7 +7271,6 @@ void Avatar::onUpdate(float dt) //vel = (n + vel)*0.5f; } } - //} } } } @@ -9164,39 +7289,6 @@ void Avatar::onUpdate(float dt) } } } - - /* - if (swimming) - { - int px=int(position.x); - int py=int(position.y); - int llpx=int(lastLastPosition.x); - int llpy=int(lastLastPosition.y); - if (px == llpx && py == llpy) - { - if (isNearObstruction(4)) - { - vel = 0; - Vector n = dsq->game->getWallNormal(position, 6); - if (!n.isZero()) - { - Vector add = n * 100; - Vector f = getForward(); - n = (n + f * 100); - n *= 0.5f; - vel += n; - } - } - } - } - */ - - if (ignoreInputDelay>0) - { - ignoreInputDelay -= dt; - if (ignoreInputDelay < 0) - ignoreInputDelay = 0; - } } //fuuugly @@ -9226,23 +7318,6 @@ void Avatar::checkNearWall() if (!inCurrent && bursting && !state.lockedToWall && !vel.isZero() && !riding && _isUnderWater) { - /* - int mult = 1; - if (isfh()) - mult = -1; - */ - /* - Vector n = dsq->game->getWallNormal(position, 8); - if (!n.isZero()) - { - state.nearWall = true; - float t=0.2; - rotateToVec(n, t, 0); - skeletalSprite.transitionAnimate("wall", t); - } - else - state.nearWall = false; - */ int checkRange = 11; Vector v = vel; v.normalize2D(); @@ -9280,32 +7355,6 @@ void Avatar::checkNearWall() } } -void Avatar::checkSpecial() -{ - /* - if (dsq->continuity.getFlag("VedhaFollow1") == 7) - { - int total = 0, c = 0; - FOR_ENTITIES (i) - { - Entity *e = *i; - if (e->name == "PracticeEnemy") - { - total++; - if (e->isEntityDead()) - c++; - } - } - if (total == c) - { - health = maxHealth; - dsq->continuity.setFlag("VedhaFollow1", 8); - dsq->getEntityByName("Vedha")->activate(); - } - } - */ -} - void Avatar::onWarp() { avatar->setv(EV_NOINPUTNOVEL, 0); diff --git a/Aquaria/Avatar.h b/Aquaria/Avatar.h index 93cc73d..675aedb 100644 --- a/Aquaria/Avatar.h +++ b/Aquaria/Avatar.h @@ -22,7 +22,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define AVATAR_H #include "../BBGE/Particles.h" -#include "../BBGE/BitmapFont.h" #include "DSQ.h" #include "Hair.h" @@ -30,9 +29,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "Web.h" -class SpringPlant; - -//class Item; class TileVector; class SongIcon; @@ -106,20 +102,10 @@ protected: void onUpdate(float dt); }; -class FormIcon : public Quad -{ -public: - FormIcon(); -protected: - bool cursorIsIn; - void onUpdate(float dt); -}; - class AvatarState { public: AvatarState(); - Timer dodgeEffectTimer; Timer blindTimer; float abilityDelay; bool blind; @@ -131,7 +117,6 @@ public: float spellCharge; bool lockedToWall; float leachTimer; - bool crawlingOnWall; bool nearWall; float swimTimer, rollTimer; float updateLookAtTime; @@ -151,20 +136,13 @@ public: void destroy(); void action(int actionID, int state); AvatarState state; - void setIgnoreInputDelay(float delay) - { - ignoreInputDelay = delay; - } float burst, burstTimer; float burstDelay; bool bursting; BurstType lastBurstType; //void damage(int amount); bool isCharging(); - void slowToRest(); - void debugMsg(const std::string &msg); void setBlind(float time); - void onBlindTest(); void revive(); @@ -182,10 +160,8 @@ public: Entity *entityToActivate; Path *pathToActivate; - Entity *lastEntityActivation; void shift(); void applyWorldEffects(WorldType type); - Vector extraVel; void toggleMovement(bool on); @@ -220,16 +196,11 @@ public: void changeForm(FormType form, bool effects=true, bool onInit=false, FormType lastForm=FORM_NONE); void singNote(int note); std::vector songIcons; - std::vector formIcons; - //std::vector currentsong; Song currentSong; int currentSongIdx; Entity *pullTarget; - bool pickingPullTarget; - void openPullTargetInterface(); - void closePullTargetInterface(); void setNearestPullTarget(); void formAbility(int ability); @@ -243,16 +214,11 @@ public: bool canDie; - bool warpIn; Vector warpInLocal; float biteDelay, urchinDelay, jellyDelay; bool movingOn; - int ropeState; - float ropeTimer; - Vector ropePos, ropeVel; - void fireRope(); void render(); void activateAura(AuraType aura); void stopAura(); @@ -264,7 +230,6 @@ public: void updateFormVisualEffects(float dt); bool isSinging(); bool isLockable(); - float stopTimer; int getCursorQuadrant(); void onWarp(); int getBurstDistance(); @@ -275,16 +240,12 @@ public: int rollDir; std::string getBurstAnimName(); std::string getRollAnimName(); - void startWallCrawl(); - void stopWallCrawl(); void updateDualFormChargeEffects(); TileVector wallLockTile; - Vector wallNormal, lastWallNormal; + Vector wallNormal; - void openFormInterface(); - void closeFormInterface(); void fallOffWall(); float fireDelay; @@ -293,8 +254,6 @@ public: AuraType activeAura; float auraTimer; bool fireAtNearestValidEntity(const std::string &shot); - EatType inTummy; - float tummyTimer; void checkNearWall(); Vector getAim(); @@ -306,7 +265,6 @@ public: void updatePosition(); float quickSongCastDelay; void onAnimationKeyPassed(int key); - int tummyAmount; bool isSwimming(); @@ -369,23 +327,17 @@ protected: int curWebPoint; void checkUpgradeForShot(Shot *s); int getNumShots(); - void updateCursorFromKeyboard(); void lockToWallCommon(); void onSetBoneLock(); void onUpdateBoneLock(); - - - InterpolatedVector cursorPos; void adjustHeadRot(); std::string lastHeadTexture; void updateDualFormGlow(float dt); Vector getTendrilAimVector(int i, int max); void applyRidingPosition(); - Vector lastWallJumpPos, lastWallJumpDir; void stopWallJump(); void updateWallJump(float dt); - int wallJumps; float wallBurstTimer; float targetUpdateDelay; std::vector targets; @@ -410,7 +362,6 @@ protected: int shieldPoints; - bool inFormInterface; void onIdle(); void onHeal(int type); ParticleEffect biteLeftEmitter, biteRightEmitter, swimEmitter, auraHitEmitter; @@ -419,7 +370,6 @@ protected: ParticleEffect *leftHandEmitter, *rightHandEmitter; ParticleEffect *chargingEmitter, *chargeEmitter; void updateCursor(float dt); - float canWarpDelay; bool rolling; int rollDidOne; @@ -427,19 +377,12 @@ protected: void stopRoll(); int getQuadrantDirection(int lastQuad, int quad); void updateRoll(float dt); - void updateTummy(float dt); int lastQuad, lastQuadDir; void onDamage(DamageData &d); void updateHair(float dt); void lostTarget(int i, Entity *e); - float doubleClickDelay; - - float damageDelay; - bool didShockDamage; - void updateShock(float dt); - float shockTimer; Vector shieldPosition; void updateAura(float dt); @@ -455,15 +398,12 @@ protected: void clampVelocity(); bool canCharge(int ability); - int abilityCharging; void formAbilityUpdate(float dt); - Entity *potentialPullTarget; float revertTimer; void endCharge(); Entity *activateEntity; bool canMove; - float castShockTimer; void onEnterState(int action); void onExitState(int action); @@ -472,28 +412,17 @@ protected: void applyBlindEffects(); void removeBlindEffects(); - - //bool blind; - bool animatedBurst; - float zoomVel; // implement "bobbing" in a lower class int getBeamWidth(); Vector getWallNormal(TileVector t); - void onToggleDebugMessages(); - float spellCastDelay; - float spellChargeMin; bool checkWarpAreas(); - void checkSpecial(); void toggleZoom(); float ignoreInputDelay; - float idleAnimDelay; float splashDelay; //Hair *hair; - BitmapText *text; - //Item *currentItem; void onUpdate(float dt); void onRender(); @@ -503,26 +432,19 @@ protected: Quad *glow; bool swimming; - void doRangePush(float dt); - void doRangePull(float dt); - void lmbd(); void lmbu(); void rmbd(); - void rmbd2(); void rmbu(); bool charging; - Vector lastPush; - float pushingOffWallEffect; float lockToWallFallTimer; Vector dodgeVec; Vector wallPushVec, wallTurnVec; - Vector lastLockToWallPos; diff --git a/Aquaria/DSQ.cpp b/Aquaria/DSQ.cpp index 41e31d2..f67f612 100644 --- a/Aquaria/DSQ.cpp +++ b/Aquaria/DSQ.cpp @@ -198,8 +198,6 @@ DSQ::DSQ(std::string fileSystem) : Core(fileSystem, LR_MAX, APPNAME, PARTICLE_AM menuSelectDelay = 0; modSelectorScr = 0; blackout = 0; - useMic = false; - autoSingMenuOpen = false; inputMode = INPUT_MOUSE; overlay = 0; recentSaveSlot = -1; @@ -4492,7 +4490,7 @@ void DSQ::onUpdate(float dt) dsq->setInputMode(INPUT_MOUSE); } - if (isDeveloperKeys()) + /*if (isDeveloperKeys()) { if (core->getCtrlState()) { @@ -4505,7 +4503,7 @@ void DSQ::onUpdate(float dt) if (core->getKeyState(KEY_DOWN)) core->adjustWindowPosition(0, 5); } - } + }*/ if (isDeveloperKeys() && cmDebug && cmDebug->alpha == 1 && fpsText) { @@ -4534,8 +4532,7 @@ void DSQ::onUpdate(float dt) os << "maxSpeed: " << dsq->game->avatar->currentMaxSpeed << " - "; os << "lockedToWall: " << dsq->game->avatar->state.lockedToWall; os << std::endl; - os << "crwlng: " << avatar->state.crawlingOnWall; - os << " swmng: " << avatar->isSwimming(); + os << "swmng: " << avatar->isSwimming(); os << " dualFormCharge: " << continuity.dualFormCharge; os << std::endl; os << "vel(" << avatar->vel.x << ", " << avatar->vel.y << ") "; @@ -4546,7 +4543,6 @@ void DSQ::onUpdate(float dt) os << "inp: " << avatar->isInputEnabled() << std::endl; os << "wallNormal(" << avatar->wallNormal.x << ", " << avatar->wallNormal.y << ")" << std::endl; os << "burst: " << avatar->burst << " burstTimer: " << avatar->burstTimer << std::endl; - os << "inTummy: " << avatar->inTummy << " tummyAmount: " << avatar->tummyAmount << std::endl; os << "inCurrent: " << avatar->isInCurrent() << std::endl; os << "qsongCastDelay: " << avatar->quickSongCastDelay << std::endl; os << "singing: " << dsq->game->avatar->singing << " blockSinging: " << dsq->game->avatar->isBlockSinging(); diff --git a/Aquaria/DSQ.h b/Aquaria/DSQ.h index 48ef1f2..57b7df0 100644 --- a/Aquaria/DSQ.h +++ b/Aquaria/DSQ.h @@ -1452,7 +1452,6 @@ public: void rumble(float leftMotor, float rightMotor, float time); void vision(std::string folder, int num, bool ignoreMusic = false); - bool useMic, autoSingMenuOpen; void watch(float t, int canQuit = 0); std::string lastVoiceFile; diff --git a/Aquaria/Entity.cpp b/Aquaria/Entity.cpp index cf49e82..b6b945c 100644 --- a/Aquaria/Entity.cpp +++ b/Aquaria/Entity.cpp @@ -551,39 +551,6 @@ void Entity::flipToTarget(Vector pos) } } -bool Entity::isCollideAgainst(Entity *e) -{ - if (this == e) return false; - if (getEntityType()==ET_PET || getEntityType()==ET_AVATAR || getEntityType() == ET_NEUTRAL) - { - if (e->getEntityType()==ET_ENEMY || e->getEntityType()==ET_NEUTRAL) - { - return true; - } - } - if (getEntityType() == ET_ENEMY) - { - if (e->getEntityType()==ET_PET || e->getEntityType()==ET_AVATAR || e->getEntityType()==ET_NEUTRAL) - return true; - } - return false; -} - -bool Entity::isOpposedTo(Entity *e) -{ - if (getEntityType()==ET_PET || getEntityType()==ET_AVATAR || getEntityType() == ET_NEUTRAL) - { - if (e->getEntityType()==ET_ENEMY || e->getEntityType()==ET_NEUTRAL) - return true; - } - if (getEntityType() == ET_ENEMY) - { - if (e->getEntityType()==ET_PET || e->getEntityType()==ET_AVATAR) - return true; - } - return false; -} - Entity* Entity::getTargetEntity(int t) { return targets[t]; diff --git a/Aquaria/Entity.h b/Aquaria/Entity.h index 76f10b3..c069447 100644 --- a/Aquaria/Entity.h +++ b/Aquaria/Entity.h @@ -341,8 +341,6 @@ public: void setEntityType(EntityType et); EntityType getEntityType(); - bool isOpposedTo(Entity *e); - bool isCollideAgainst(Entity *e); void flipToTarget(Vector pos); bool isFollowingPath(); void stopFollowingPath(); diff --git a/Aquaria/Game.cpp b/Aquaria/Game.cpp index 8379a06..5f2e90b 100644 --- a/Aquaria/Game.cpp +++ b/Aquaria/Game.cpp @@ -4138,8 +4138,7 @@ void Game::toggleOverrideZoom(bool on) if (!on && avatar->zoomOverriden == true) { dsq->globalScale.stop(); - dsq->game->avatar->myZoom = dsq->globalScale; - //dsq->game->avatar->myZoom.interpolateTo(Vector(1,1), 1.0); + avatar->myZoom = dsq->globalScale; } avatar->zoomOverriden = on; } @@ -8400,8 +8399,6 @@ void Game::preLocalWarp(LocalWarpType localWarpType) { dsq->game->avatar->warpInLocal = Vector(0,0,0); } - - dsq->game->avatar->warpIn = !dsq->game->avatar->warpIn; dsq->screenTransition->capture(); core->resetTimer(); diff --git a/BBGE/Core.cpp b/BBGE/Core.cpp index 68d7c4f..b71581c 100644 --- a/BBGE/Core.cpp +++ b/BBGE/Core.cpp @@ -1778,7 +1778,6 @@ void Core::onUpdate(float dt) //script.update(dt); cameraPos.update(dt); - cameraRot.update(dt); globalScale.update(dt); if (afterEffectManager) @@ -3162,10 +3161,8 @@ void Core::clearBuffers() void Core::setupRenderPositionAndScale() { #ifdef BBGE_BUILD_OPENGL - //glRotatef(cameraRot.z, 0, 0, 1); glScalef(globalScale.x*globalResolutionScale.x*screenCapScale.x, globalScale.y*globalResolutionScale.y*screenCapScale.y, globalScale.z*globalResolutionScale.z); glTranslatef(-(cameraPos.x+cameraOffset.x), -(cameraPos.y+cameraOffset.y), -(cameraPos.z+cameraOffset.z)); - //glRotatef(180, 0, 1, 0); #endif } diff --git a/BBGE/Core.h b/BBGE/Core.h index 2d62bda..84b08cb 100644 --- a/BBGE/Core.h +++ b/BBGE/Core.h @@ -1133,7 +1133,7 @@ public: virtual void onPlayedVoice(const std::string &name){} - InterpolatedVector cameraPos, cameraRot; + InterpolatedVector cameraPos; int fps; bool loopDone; From f9ce5c01727fc43b212ff51797a3dd02aed96374 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sun, 23 Dec 2012 22:32:19 +0100 Subject: [PATCH 009/103] Animation editor enhancement: Move/rotate bones across all keyframes --- Aquaria/AnimationEditor.cpp | 57 ++++++++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 7 deletions(-) diff --git a/Aquaria/AnimationEditor.cpp b/Aquaria/AnimationEditor.cpp index 0b15386..ed800f6 100644 --- a/Aquaria/AnimationEditor.cpp +++ b/Aquaria/AnimationEditor.cpp @@ -1057,11 +1057,34 @@ void AnimationEditor::applyTranslation() { if (editingBone) { - BoneKeyframe *b = editSprite->getCurrentAnimation()->getKeyframe(currentKey)->getBoneKeyframe(editingBone->boneIdx); - if (b) + if (!core->getShiftState()) { - b->x = editingBone->position.x; - b->y = editingBone->position.y; + // one bone mode + BoneKeyframe *b = editSprite->getCurrentAnimation()->getKeyframe(currentKey)->getBoneKeyframe(editingBone->boneIdx); + if (b) + { + b->x = editingBone->position.x; + b->y = editingBone->position.y; + } + } + else + { + BoneKeyframe *bcur = editSprite->getCurrentAnimation()->getKeyframe(currentKey)->getBoneKeyframe(editingBone->boneIdx); + if (bcur) + { + int xdiff = editingBone->position.x - bcur->x; + int ydiff = editingBone->position.y - bcur->y; + // all bones mode + for (int i = 0; i < editSprite->getCurrentAnimation()->getNumKeyframes(); ++i) + { + BoneKeyframe *b = editSprite->getCurrentAnimation()->getKeyframe(i)->getBoneKeyframe(editingBone->boneIdx); + if (b) + { + b->x += xdiff; + b->y += ydiff; + } + } + } } } } @@ -1149,10 +1172,30 @@ void AnimationEditor::rmbu() { if (editingBone) { - BoneKeyframe *b = editSprite->getCurrentAnimation()->getKeyframe(currentKey)->getBoneKeyframe(editingBone->boneIdx); - if (b) + if (!core->getShiftState()) { - b->rot = int(editingBone->rotation.z); + // one bone mode + BoneKeyframe *b = editSprite->getCurrentAnimation()->getKeyframe(currentKey)->getBoneKeyframe(editingBone->boneIdx); + if (b) + { + b->rot = int(editingBone->rotation.z); + } + } + else + { + BoneKeyframe *bcur = editSprite->getCurrentAnimation()->getKeyframe(currentKey)->getBoneKeyframe(editingBone->boneIdx); + if (bcur) + { + int rotdiff = editingBone->rotation.z - bcur->rot; + for (int i = 0; i < editSprite->getCurrentAnimation()->getNumKeyframes(); ++i) + { + BoneKeyframe *b = editSprite->getCurrentAnimation()->getKeyframe(i)->getBoneKeyframe(editingBone->boneIdx); + if (b) + { + b->rot += rotdiff; + } + } + } } } } From c358c9825668888a7fabebc1d0c62ee37620ff17 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sun, 23 Dec 2012 22:42:34 +0100 Subject: [PATCH 010/103] add some Lua constants --- Aquaria/ScriptInterface.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index c39f08f..3df16ad 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -8292,6 +8292,7 @@ static const struct { luaConstant(OBSCHECK_RANGE), luaConstant(OBSCHECK_4DIR), luaConstant(OBSCHECK_DOWN), + luaConstant(OBSCHECK_8DIR), luaConstant(EV_WALLOUT), luaConstant(EV_WALLTRANS), @@ -8416,6 +8417,8 @@ static const struct { luaConstantFromClass(BLEND_DEFAULT, RenderObject), luaConstantFromClass(BLEND_ADD, RenderObject), {"BLEND_ADDITIVE", RenderObject::BLEND_ADD}, + luaConstantFromClass(BLEND_SUB, RenderObject), + luaConstantFromClass(BLEND_MULT, RenderObject), {"ENDING_NAIJACAVE", 10}, {"ENDING_NAIJACAVEDONE", 11}, @@ -8751,6 +8754,11 @@ static const struct { luaConstant(ANIMLAYER_ARMOVERRIDE), luaConstant(ANIMLAYER_UPPERBODYIDLE), luaConstant(ANIMLAYER_HEADOVERRIDE), + + luaConstantFromClass(ANIM_NONE, Bone), + luaConstantFromClass(ANIM_POS, Bone), + luaConstantFromClass(ANIM_ROT, Bone), + luaConstantFromClass(ANIM_ALL, Bone), }; //============================================================================================ From 366838d800bdf2e470ccbc6f8f176e2fcc4c3c8c Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sun, 23 Dec 2012 22:43:46 +0100 Subject: [PATCH 011/103] little enhancement to scene editor: show more entity details --- Aquaria/SceneEditor.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Aquaria/SceneEditor.cpp b/Aquaria/SceneEditor.cpp index d087619..ae8dc7a 100644 --- a/Aquaria/SceneEditor.cpp +++ b/Aquaria/SceneEditor.cpp @@ -3318,12 +3318,16 @@ void SceneEditor::updateText() os << "entities (" << dsq->entities.size() << ")"; if (editingEntity) { + os.precision(1); + os << std::fixed; os << " id: " << editingEntity->getID() << " name: " << editingEntity->name << " flag:" << dsq->continuity.getEntityFlag(dsq->game->sceneName, editingEntity->getID()) << " fh:" << editingEntity->isfh() << " fv:" << editingEntity->isfv() - << " state:" << editingEntity->getState(); + << " state:" << editingEntity->getState() + << " et:" << editingEntity->getEntityType() + << " hp:" << editingEntity->health << "/" << editingEntity->maxHealth; } break; case ET_PATHS: From 32aca3b768d06a3e87d1ee93bbe366ce11ccca51 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Thu, 3 Jan 2013 00:36:24 +0100 Subject: [PATCH 012/103] Move hair functions to Entity; add quad_setSegs() & obj_setRealRenderPass() --- Aquaria/Entity.cpp | 36 ++++++++++++++++++++ Aquaria/Entity.h | 5 +++ Aquaria/ScriptInterface.cpp | 68 ++++++++++++++++++++++++------------- Aquaria/ScriptedEntity.cpp | 35 ------------------- Aquaria/ScriptedEntity.h | 4 --- 5 files changed, 85 insertions(+), 63 deletions(-) diff --git a/Aquaria/Entity.cpp b/Aquaria/Entity.cpp index b6b945c..b7f9597 100644 --- a/Aquaria/Entity.cpp +++ b/Aquaria/Entity.cpp @@ -3096,3 +3096,39 @@ 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) +{ + if (hair) + { + errorLog("Trying to init hair when hair is already present"); + } + hair = new Hair(numSegments, segmentLength, width); + hair->setTexture(tex); + dsq->game->addRenderObject(hair, layer); +} + + +void Entity::setHairHeadPosition(const Vector &pos) +{ + if (hair) + { + hair->setHeadPosition(pos); + } +} + +void Entity::updateHair(float dt) +{ + if (hair) + { + hair->updatePositions(); + } +} + +void Entity::exertHairForce(const Vector &force, float dt) +{ + if (hair) + { + hair->exertForce(force, dt); + } +} + diff --git a/Aquaria/Entity.h b/Aquaria/Entity.h index c069447..11b3e1c 100644 --- a/Aquaria/Entity.h +++ b/Aquaria/Entity.h @@ -481,6 +481,11 @@ public: virtual bool canSetBoneLock(); + void initHair(int numSegments, int segmentLength, int width, const std::string &tex); + void updateHair(float dt); + void setHairHeadPosition(const Vector &pos); + void exertHairForce(const Vector &force, float dt); + protected: bool calledEntityDied; Path *waterBubble; diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 3df16ad..8002c2c 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -1270,6 +1270,15 @@ luaFunc(obj_setRenderPass) luaReturnNil(); } +luaFunc(obj_setRealRenderPass) +{ + RenderObject *r = robj(L); + int pass = lua_tointeger(L, 2); + if (r) + r->setRenderPass(pass); + luaReturnNil(); +} + luaFunc(obj_fh) { RenderObject *r = robj(L); @@ -1467,6 +1476,14 @@ luaFunc(quad_setHeight) luaReturnNil(); } +luaFunc(quad_setSegs) +{ + Quad *b = getQuad(L); + if (b) + b->setSegs(lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tonumber(L, 4), lua_tonumber(L, 5), lua_tonumber(L, 6), lua_tonumber(L, 7), lua_tonumber(L, 8), lua_tointeger(L, 9)); + luaReturnNil(); +} + // --- standard set/get functions for each type, wrapping RenderObject functions --- @@ -1544,6 +1561,7 @@ luaFunc(quad_setHeight) RO_FUNC(getter, prefix, setCullRadius ) \ RO_FUNC(getter, prefix, setUpdateCull ) \ RO_FUNC(getter, prefix, setRenderPass ) \ + RO_FUNC(getter, prefix, setRealRenderPass ) \ RO_FUNC(getter, prefix, setPositionX ) \ RO_FUNC(getter, prefix, setPositionY ) \ RO_FUNC(getter, prefix, enableMotionBlur ) \ @@ -1558,7 +1576,8 @@ luaFunc(quad_setHeight) Q_FUNC(getter, prefix, setVisible ) \ Q_FUNC(getter, prefix, isVisible ) \ Q_FUNC(getter, prefix, setWidth ) \ - Q_FUNC(getter, prefix, setHeight ) + Q_FUNC(getter, prefix, setHeight ) \ + Q_FUNC(getter, prefix, setSegs ) // This should reflect the internal class hierarchy, // e.g. a Beam is a Quad, so it can use quad_* functions @@ -1571,7 +1590,7 @@ luaFunc(quad_setHeight) MAKE_ROBJ_FUNCS(getWeb, web ) \ MAKE_ROBJ_FUNCS(getText, text ) -// first time, create them. (There is a second use of this further down, with differet MK_* macros) +// first time, create them. (There is a second use of this further down, with different MK_* macros) EXPAND_FUNC_PROTOTYPES @@ -2839,22 +2858,6 @@ luaFunc(bone_lookAtEntity) luaReturnNil(); } -luaFunc(bone_setSegs) -{ - Bone *b = bone(L); - if (b) - b->setSegs(lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tonumber(L, 4), lua_tonumber(L, 5), lua_tonumber(L, 6), lua_tonumber(L, 7), lua_tonumber(L, 8), lua_tointeger(L, 9)); - luaReturnNil(); -} - -luaFunc(entity_setSegs) -{ - Entity *e = entity(L); - if (e) - e->setSegs(lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tonumber(L, 4), lua_tonumber(L, 5), lua_tonumber(L, 6), lua_tonumber(L, 7), lua_tonumber(L, 8), lua_tointeger(L, 9)); - luaReturnNil(); -} - luaFunc(entity_resetTimer) { ScriptedEntity *se = scriptedEntity(L); @@ -6501,7 +6504,7 @@ luaFunc(entity_switchLayer) // entity numSegments segmentLength width texture luaFunc(entity_initHair) { - ScriptedEntity *se = scriptedEntity(L); + Entity *se = entity(L); if (se) { se->initHair(lua_tonumber(L, 2), lua_tonumber(L, 3), lua_tonumber(L, 4), getString(L, 5)); @@ -6509,9 +6512,26 @@ luaFunc(entity_initHair) luaReturnNil(); } +luaFunc(entity_getHair) +{ + Entity *e = entity(L); + luaReturnPtr(e ? e->hair : NULL); +} + +luaFunc(entity_clearHair) +{ + Entity *e = entity(L); + if (e) + { + e->hair->safeKill(); + e->hair = 0; + } + luaReturnNil(); +} + luaFunc(entity_getHairPosition) { - ScriptedEntity *se = scriptedEntity(L); + Entity *se = entity(L); float x=0; float y=0; int idx = lua_tonumber(L, 2); @@ -6530,7 +6550,7 @@ luaFunc(entity_getHairPosition) // entity x y z luaFunc(entity_setHairHeadPosition) { - ScriptedEntity *se = scriptedEntity(L); + Entity *se = entity(L); if (se) { se->setHairHeadPosition(Vector(lua_tonumber(L, 2), lua_tonumber(L, 3))); @@ -6540,7 +6560,7 @@ luaFunc(entity_setHairHeadPosition) luaFunc(entity_updateHair) { - ScriptedEntity *se = scriptedEntity(L); + Entity *se = entity(L); if (se) { se->updateHair(lua_tonumber(L, 2)); @@ -7385,8 +7405,6 @@ static const struct { luaRegister(entity_setTargetRange), luaRegister(bone_addSegment), - luaRegister(entity_setSegs), - luaRegister(bone_setSegs), luaRegister(bone_setSegmentOffset), luaRegister(bone_setSegmentProps), @@ -7866,6 +7884,8 @@ static const struct { luaRegister(entity_initHair), luaRegister(entity_getHairPosition), + luaRegister(entity_getHair), + luaRegister(entity_clearHair), luaRegister(entity_setHairHeadPosition), luaRegister(entity_updateHair), diff --git a/Aquaria/ScriptedEntity.cpp b/Aquaria/ScriptedEntity.cpp index 92c485f..67aa2a1 100644 --- a/Aquaria/ScriptedEntity.cpp +++ b/Aquaria/ScriptedEntity.cpp @@ -180,41 +180,6 @@ void ScriptedEntity::registerNewPart(RenderObject *r, const std::string &name) partMap[name] = r; } -void ScriptedEntity::initHair(int numSegments, int segmentLength, int width, const std::string &tex) -{ - if (hair) - { - errorLog("Trying to init hair when hair is already present"); - } - hair = new Hair(numSegments, segmentLength, width); - hair->setTexture(tex); - dsq->game->addRenderObject(hair, layer); -} - -void ScriptedEntity::setHairHeadPosition(const Vector &pos) -{ - if (hair) - { - hair->setHeadPosition(pos); - } -} - -void ScriptedEntity::updateHair(float dt) -{ - if (hair) - { - hair->updatePositions(); - } -} - -void ScriptedEntity::exertHairForce(const Vector &force, float dt) -{ - if (hair) - { - hair->exertForce(force, dt); - } -} - void ScriptedEntity::initSegments(int numSegments, int minDist, int maxDist, std::string bodyTex, std::string tailTex, int w, int h, float taper, bool reverseSegments) { this->reverseSegments = reverseSegments; diff --git a/Aquaria/ScriptedEntity.h b/Aquaria/ScriptedEntity.h index 8a1eb4e..3c13dc7 100644 --- a/Aquaria/ScriptedEntity.h +++ b/Aquaria/ScriptedEntity.h @@ -38,7 +38,6 @@ public: void setEntityLayer(int layer); void setupEntity(const std::string &tex, int layer=0); void setupBasicEntity(const std::string& texture, int health, int manaBall, int exp, int money, int collideRadius, int state, int w, int h, int expType, bool hitEntity, int updateCull, int layer); - void initHair(int numSegments, int segmentLength, int width, const std::string &tex); void initSegments(int numSegments, int minDist, int maxDist, std::string bodyTex, std::string tailTex, int w, int h, float taper, bool reverseSegments); void registerNewPart(RenderObject *r, const std::string &name); typedef std::map PartMap; @@ -72,9 +71,6 @@ public: bool isEntityInside(); void becomeSolid(); - void updateHair(float dt); - void setHairHeadPosition(const Vector &pos); - void exertHairForce(const Vector &force, float dt); std::string deathParticleEffect; ParticleEffect pullEmitter; From 8712657e7513fbc17cb456bccbeccd8563657803 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Thu, 3 Jan 2013 00:36:33 +0100 Subject: [PATCH 013/103] vcproj update --- win/vc90/BBGE.vcproj | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/win/vc90/BBGE.vcproj b/win/vc90/BBGE.vcproj index 6705212..b6cf501 100644 --- a/win/vc90/BBGE.vcproj +++ b/win/vc90/BBGE.vcproj @@ -200,14 +200,6 @@ RelativePath="..\..\BBGE\AfterEffect.h" > - - - - @@ -316,14 +308,6 @@ RelativePath="..\..\BBGE\Gradient.h" > - - - - From cbd3658b2723c74c46846c389f07e2ebe6cb8349 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Thu, 3 Jan 2013 02:43:33 +0100 Subject: [PATCH 014/103] Fix *_setRenderPass() regression from 7ff0caaed8. Remove obj_setRealRenderPass() again. This corrects render pass overriding, especially Li's arm, which was supposed to be in front of the hug; and being eaten by a grouper, where Naija stayed visible because the grouper skeletal's render pass was not set correctly. --- Aquaria/ScriptInterface.cpp | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 8002c2c..f29eab0 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -1262,15 +1262,6 @@ luaFunc(obj_setLayer) } luaFunc(obj_setRenderPass) -{ - RenderObject *r = robj(L); - int pass = lua_tointeger(L, 2); - if (r) - r->setOverrideRenderPass(pass); - luaReturnNil(); -} - -luaFunc(obj_setRealRenderPass) { RenderObject *r = robj(L); int pass = lua_tointeger(L, 2); @@ -1561,7 +1552,6 @@ luaFunc(quad_setSegs) RO_FUNC(getter, prefix, setCullRadius ) \ RO_FUNC(getter, prefix, setUpdateCull ) \ RO_FUNC(getter, prefix, setRenderPass ) \ - RO_FUNC(getter, prefix, setRealRenderPass ) \ RO_FUNC(getter, prefix, setPositionX ) \ RO_FUNC(getter, prefix, setPositionY ) \ RO_FUNC(getter, prefix, enableMotionBlur ) \ @@ -3633,13 +3623,24 @@ luaFunc(entity_setEntityLayer) luaReturnNil(); } +// Note that this overrides the generic obj_setRenderPass function for entities. +// (It's registered as "entity_setRenderPass" to Lua) +luaFunc(entity_setRenderPass_override) +{ + Entity *e = entity(L); + int pass = lua_tointeger(L, 2); + if (e) + e->setOverrideRenderPass(pass); + luaReturnNil(); +} + // intended to be used for setting max health and refilling it all luaFunc(entity_setHealth) { Entity *e = entity(L, 1); if (e) e->health = e->maxHealth = lua_tonumber(L, 2); - luaReturnNum(0); + luaReturnNil(); } luaFunc(entity_changeHealth) @@ -3647,7 +3648,7 @@ luaFunc(entity_changeHealth) Entity *e = entity(L, 1); if (e) e->health += lua_tonumber(L, 2); - luaReturnNum(0); + luaReturnNil(); } luaFunc(entity_heal) @@ -8103,6 +8104,7 @@ static const struct { {"bone_getPosition", l_bone_getWorldPosition}, { "entity_delete", l_entity_delete_override }, + { "entity_setRenderPass", l_entity_setRenderPass_override }, // -- deprecated/compatibility related functions below here -- From 3dbc92b16e42c7e489030c501b38e32ced721e7b Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sun, 3 Feb 2013 16:12:19 +0100 Subject: [PATCH 015/103] readme update --- README.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.txt b/README.txt index 1fe8854..299db66 100644 --- a/README.txt +++ b/README.txt @@ -18,6 +18,9 @@ Follow these steps to build Aquaria. build-essential cmake liblua5.1-0-dev libogg-dev libvorbis-dev libopenal-dev libsdl1.2-dev +For Lua, libogg, and libvorbis the included versions can be used instead, +thus a system-wide install of these libs is not required. + 2- Create a sub-directory 'cmake-build' and move into it $ mkdir cmake-build @@ -28,6 +31,9 @@ $ cd cmake-build $ cmake .. 4- If you miss some dependencies, install them and run cmake again. + Due to windows lacking package management, it is recommended + to set all AQUARIA_INTERNAL_* cmake variables to TRUE for win32 + builds, or for statically linked linux builds. 5- run make @@ -39,6 +45,7 @@ $ make $ cp aquaria ~/aquaria/ $ cp -r ../games_scripts/* ~/aquaria +$ cp -r ../files/* ~/aquaria You should *not* remove any file from the aquaria installation, just replace some of them with the versions included in this folder. From 76c31f8147a5dca480cd9e15c2e32768107d4376 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sun, 3 Feb 2013 16:13:07 +0100 Subject: [PATCH 016/103] minor fixups (Entity::revive() and some skeletal stuff) --- Aquaria/Entity.cpp | 2 +- Aquaria/Entity.h | 2 +- BBGE/SkeletalSprite.cpp | 7 ++++--- BBGE/SkeletalSprite.h | 6 +++--- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Aquaria/Entity.cpp b/Aquaria/Entity.cpp index b7f9597..957266c 100644 --- a/Aquaria/Entity.cpp +++ b/Aquaria/Entity.cpp @@ -812,7 +812,7 @@ void Entity::heal(float a, int type) } } -void Entity::revive(int a) +void Entity::revive(float a) { entityDead = false; health = 0; diff --git a/Aquaria/Entity.h b/Aquaria/Entity.h index 11b3e1c..4bb1306 100644 --- a/Aquaria/Entity.h +++ b/Aquaria/Entity.h @@ -351,7 +351,7 @@ public: bool isHit(); bool pathBurst(bool wallJump = false); Timer burstTimer; - void revive(int a); + void revive(float a); void setName(const std::string &name); void doFriction(float dt); void doFriction(float dt, int len); diff --git a/BBGE/SkeletalSprite.cpp b/BBGE/SkeletalSprite.cpp index 63a0976..9ff1b90 100644 --- a/BBGE/SkeletalSprite.cpp +++ b/BBGE/SkeletalSprite.cpp @@ -461,7 +461,7 @@ void AnimationLayer::playAnimation(int idx, int loop) //doNextKeyframe(); } -void AnimationLayer::enqueueAnimation(std::string anim, int loop) +void AnimationLayer::enqueueAnimation(const std::string& anim, int loop) { enqueuedAnimation = anim; enqueuedAnimationLoop = loop; @@ -514,7 +514,7 @@ Animation* AnimationLayer::getCurrentAnimation() return &s->animations[currentAnimation]; } -bool AnimationLayer::createTransitionAnimation(std::string anim, float time) +bool AnimationLayer::createTransitionAnimation(const std::string& anim, float time) { //Animation *a = getCurrentAnimation(); Animation *to = s->getAnimation(anim); @@ -555,6 +555,7 @@ void AnimationLayer::stopAnimation() { animate(enqueuedAnimation, enqueuedAnimationLoop); enqueuedAnimation = ""; + enqueuedAnimationLoop = 0; } } @@ -1145,7 +1146,7 @@ void SkeletalSprite::deleteBones() bones.clear(); } -Animation *SkeletalSprite::getAnimation(std::string anim) +Animation *SkeletalSprite::getAnimation(const std::string& anim) { for (int i = 0; i < animations.size(); i++) { diff --git a/BBGE/SkeletalSprite.h b/BBGE/SkeletalSprite.h index 518f687..b170765 100644 --- a/BBGE/SkeletalSprite.h +++ b/BBGE/SkeletalSprite.h @@ -163,10 +163,10 @@ public: void updateBones(); void stopAnimation(); float getAnimationLength(); - bool createTransitionAnimation(std::string anim, float time); + bool createTransitionAnimation(const std::string& anim, float time); void playAnimation(int idx, int loop); void playCurrentAnimation(int loop); - void enqueueAnimation(std::string anim, int loop); + void enqueueAnimation(const std::string& anim, int loop); float transitionAnimate(std::string anim, float time, int loop); void setTimeMultiplier(float t); bool isAnimating(); @@ -240,7 +240,7 @@ public: - Animation *getAnimation(std::string anim); + Animation *getAnimation(const std::string& anim); std::vector animations; std::vector bones; From 188469102b451e36c0306b9d21b9270a6663230d Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sun, 3 Feb 2013 16:13:54 +0100 Subject: [PATCH 017/103] add 3 new Lua functions: entity_getAnimationLoop() entity_getAnimLayerTimeMult() obj_getLayer() --- Aquaria/ScriptInterface.cpp | 42 ++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index f29eab0..2c8a17d 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -1261,6 +1261,12 @@ luaFunc(obj_setLayer) luaReturnNil(); } +luaFunc(obj_getLayer) +{ + RenderObject *r = robj(L); + luaReturnInt(r ? r->layer : 0); +} + luaFunc(obj_setRenderPass) { RenderObject *r = robj(L); @@ -1538,6 +1544,7 @@ luaFunc(quad_setSegs) RO_FUNC(getter, prefix, moveToFront ) \ RO_FUNC(getter, prefix, moveToBack ) \ RO_FUNC(getter, prefix, setLayer ) \ + RO_FUNC(getter, prefix, getLayer ) \ RO_FUNC(getter, prefix, setRenderBeforeParent) \ RO_FUNC(getter, prefix, addChild ) \ RO_FUNC(getter, prefix, fh ) \ @@ -3344,6 +3351,21 @@ luaFunc(entity_setAnimLayerTimeMult) luaReturnNum(t); } +luaFunc(entity_getAnimLayerTimeMult) +{ + Entity *e = entity(L); + float t = 0; + if (e) + { + AnimationLayer *l = e->skeletalSprite.getAnimationLayer(lua_tointeger(L, 2)); + if (l) + { + t = l->timeMultiplier.x; + } + } + luaReturnNum(t); +} + luaFunc(entity_animate) { SkeletalSprite *skel = getSkeletalSprite(entity(L)); @@ -3372,6 +3394,19 @@ luaFunc(entity_stopAnimation) luaReturnNil(); } +luaFunc(entity_getAnimationLoop) +{ + int loop = 0; + SkeletalSprite *skel = getSkeletalSprite(entity(L)); + if (skel) + { + AnimationLayer *animlayer = skel->getAnimationLayer(lua_tointeger(L, 2)); + if (animlayer) + loop = animlayer->loop ? animlayer->loop : animlayer->enqueuedAnimationLoop; + } + luaReturnInt(loop); +} + // entity, x, y, time, ease, relative luaFunc(entity_move) { @@ -7589,7 +7624,9 @@ static const struct { luaRegister(entity_doCollisionAvoidance), luaRegister(entity_animate), luaRegister(entity_setAnimLayerTimeMult), + luaRegister(entity_getAnimLayerTimeMult), luaRegister(entity_stopAnimation), + luaRegister(entity_getAnimationLoop), luaRegister(entity_setCurrentTarget), luaRegister(entity_stopInterpolating), @@ -8776,11 +8813,6 @@ static const struct { luaConstant(ANIMLAYER_ARMOVERRIDE), luaConstant(ANIMLAYER_UPPERBODYIDLE), luaConstant(ANIMLAYER_HEADOVERRIDE), - - luaConstantFromClass(ANIM_NONE, Bone), - luaConstantFromClass(ANIM_POS, Bone), - luaConstantFromClass(ANIM_ROT, Bone), - luaConstantFromClass(ANIM_ALL, Bone), }; //============================================================================================ From 4433237f3abc4c383d6de07cb4a7c9e6962dc1e2 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Mon, 4 Feb 2013 15:16:57 +0100 Subject: [PATCH 018/103] Add more script functions + little fix in entity poisoning shot_getEffectTime() shot_isIgnoreShield() shot_getFirer() shot_setTarget() shot_getTarget() getLastCollideTileType() collideCircleWithGrid() entity_getMaxHealth() entity_setPoison() entity_getPoison() OT_* constants --- Aquaria/Entity.cpp | 3 +- Aquaria/Entity.h | 1 + Aquaria/ScriptInterface.cpp | 87 +++++++++++++++++++++++++++++++++++-- 3 files changed, 86 insertions(+), 5 deletions(-) diff --git a/Aquaria/Entity.cpp b/Aquaria/Entity.cpp index 957266c..8211f08 100644 --- a/Aquaria/Entity.cpp +++ b/Aquaria/Entity.cpp @@ -1646,7 +1646,8 @@ void Entity::setPoison(float m, float t) { poison = m; poisonTimer.start(t); - poisonBitTimer.start(dsq->continuity.poisonBitTime); + if (poison) + poisonBitTimer.start(dsq->continuity.poisonBitTime); } void Entity::onUpdate(float dt) diff --git a/Aquaria/Entity.h b/Aquaria/Entity.h index 4bb1306..b4cadcd 100644 --- a/Aquaria/Entity.h +++ b/Aquaria/Entity.h @@ -478,6 +478,7 @@ public: void setRidingData(const Vector &pos, float rot, bool fh); bool isGoingToBeEaten(); void setPoison(float m, float t); + inline float getPoison() const { return poison; } virtual bool canSetBoneLock(); diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 2c8a17d..9cb7299 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -1841,6 +1841,38 @@ luaFunc(shot_setAimVector) luaReturnNil(); } +luaFunc(shot_getEffectTime) +{ + Shot *shot = getShot(L); + luaReturnNum((shot && shot->shotData) ? shot->shotData->effectTime : 0.0f); +} + +luaFunc(shot_isIgnoreShield) +{ + Shot *shot = getShot(L); + luaReturnBool((shot && shot->shotData) ? shot->shotData->ignoreShield : false); +} + +luaFunc(shot_getFirer) +{ + Shot *shot = getShot(L); + luaReturnPtr(shot ? shot->firer : NULL); +} + +luaFunc(shot_setTarget) +{ + Shot *shot = getShot(L); + if(shot) + shot->setTarget(entity(L, 2)); + luaReturnNil(); +} + +luaFunc(shot_getTarget) +{ + Shot *shot = getShot(L); + luaReturnPtr(shot ? shot->target : NULL); +} + luaFunc(entity_setVel) { Entity *e = entity(L); @@ -2977,6 +3009,18 @@ luaFunc(getLastCollidePosition) luaReturnVec2(dsq->game->lastCollidePosition.x, dsq->game->lastCollidePosition.y); } +luaFunc(getLastCollideTileType) +{ + luaReturnInt(dsq->game->lastCollideTileType); +} + +luaFunc(collideCircleWithGrid) +{ + bool c = dsq->game->collideCircleWithGrid(Vector(lua_tonumber(L, 1), lua_tonumber(L, 2)), lua_tonumber(L, 3)); + luaReturnBool(c); +} + + luaFunc(entity_isNearGround) { Entity *e = entity(L); @@ -4238,10 +4282,13 @@ luaFunc(entity_debugText) luaFunc(entity_getHealth) { Entity *e = entity(L); - if (e) - luaReturnNum(e->health); - else - luaReturnNum(0); + luaReturnNum(e ? e->health : 0); +} + +luaFunc(entity_getMaxHealth) +{ + Entity *e = entity(L); + luaReturnNum(e ? e->maxHealth : 0); } luaFunc(entity_initSegments) @@ -7136,6 +7183,20 @@ luaFunc(entity_setFlag) luaReturnNil(); } +luaFunc(entity_setPoison) +{ + Entity *e = entity(L); + if(e) + e->setPoison(lua_tonumber(L, 2), lua_tonumber(L, 3)); + luaReturnNil(); +} + +luaFunc(entity_getPoison) +{ + Entity *e = entity(L); + luaReturnNum(e ? e->getPoison() : 0.0f); +} + luaFunc(entity_getFlag) { Entity *e = entity(L); @@ -7540,6 +7601,7 @@ static const struct { luaRegister(entity_partAlpha), luaRegister(entity_getHealth), + luaRegister(entity_getMaxHealth), luaRegister(entity_pushTarget), luaRegister(entity_msg), luaRegister(entity_updateMovement), @@ -7886,6 +7948,11 @@ static const struct { luaRegister(shot_setAimVector), luaRegister(shot_setOut), + luaRegister(shot_getEffectTime), + luaRegister(shot_isIgnoreShield), + luaRegister(shot_getFirer), + luaRegister(shot_setTarget), + luaRegister(shot_getTarget), luaRegister(entity_pathBurst), luaRegister(entity_handleShotCollisions), luaRegister(entity_handleShotCollisionsSkeletal), @@ -8086,6 +8153,8 @@ static const struct { luaRegister(entity_getNearestBoneToPosition), luaRegister(entity_getNearestNode), + luaRegister(entity_setPoison), + luaRegister(entity_getPoison), luaRegister(node_getNearestEntity), luaRegister(node_getNearestNode), @@ -8105,6 +8174,8 @@ static const struct { luaRegister(getWallNormal), luaRegister(getLastCollidePosition), + luaRegister(getLastCollideTileType), + luaRegister(collideCircleWithGrid), luaRegister(getScreenVirtualOff), luaRegister(getScreenSize), @@ -8813,6 +8884,14 @@ static const struct { luaConstant(ANIMLAYER_ARMOVERRIDE), luaConstant(ANIMLAYER_UPPERBODYIDLE), luaConstant(ANIMLAYER_HEADOVERRIDE), + + luaConstant(OT_EMPTY), + luaConstant(OT_BLACK), + luaConstant(OT_BLACKINVIS), + luaConstant(OT_INVISIBLE), + luaConstant(OT_INVISIBLEIN), + luaConstant(OT_HURT), + luaConstant(OT_INVISIBLEENT), }; //============================================================================================ From ab6e92f256a12c4c0dcb9fa0bd5685a64b4e293b Mon Sep 17 00:00:00 2001 From: fgenesis Date: Wed, 6 Feb 2013 21:01:22 +0100 Subject: [PATCH 019/103] Add EV_NOAVOID and bone_lookAtPosition() --- Aquaria/Entity.cpp | 2 +- Aquaria/Entity.h | 3 ++- Aquaria/ScriptInterface.cpp | 12 ++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Aquaria/Entity.cpp b/Aquaria/Entity.cpp index 8211f08..35c1b57 100644 --- a/Aquaria/Entity.cpp +++ b/Aquaria/Entity.cpp @@ -2788,7 +2788,7 @@ void Entity::doEntityAvoidance(float dt, int range, float mod, Entity *ignore) { Entity *e = *i; - if (e != this && e != ignore && e->ridingOnEntity != this) + if (e != this && e != ignore && e->ridingOnEntity != this && !e->getv(EV_NOAVOID)) { diff = (this->position - e->position); if (diff.isLength2DIn(range) && !diff.isZero()) diff --git a/Aquaria/Entity.h b/Aquaria/Entity.h index b4cadcd..336ccf3 100644 --- a/Aquaria/Entity.h +++ b/Aquaria/Entity.h @@ -70,7 +70,8 @@ enum EV EV_MINIMAP = 19, // should the entity show up on the minimap? EV_SOULSCREAMRADIUS = 20, // 0-n: size of radius for naija's dual form scream attack, -1: always hit EV_WEBSLOW = 21, // 100 by default, multiplied by dt and then divided into vel - EV_MAX = 22 + EV_NOAVOID = 22, // if 1: doEntityAvoidance() will ignore this entity + EV_MAX = 23 }; enum DamageType diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 9cb7299..45232af 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -2887,6 +2887,16 @@ luaFunc(bone_lookAtEntity) luaReturnNil(); } +luaFunc(bone_lookAtPosition) +{ + Bone *b = bone(L); + if (b) + { + b->lookAt(Vector(lua_tonumber(L, 2), lua_tonumber(L, 3)), lua_tonumber(L, 4), lua_tonumber(L, 5), lua_tonumber(L, 6), lua_tonumber(L, 7)); + } + luaReturnNil(); +} + luaFunc(entity_resetTimer) { ScriptedEntity *se = scriptedEntity(L); @@ -7510,6 +7520,7 @@ static const struct { luaRegister(bone_showFrame), luaRegister(bone_lookAtEntity), + luaRegister(bone_lookAtPosition), luaRegister(entity_partSetSegs), @@ -8446,6 +8457,7 @@ static const struct { luaConstant(EV_MINIMAP), luaConstant(EV_SOULSCREAMRADIUS), luaConstant(EV_WEBSLOW), + luaConstant(EV_NOAVOID), luaConstant(EV_MAX), {"EVT_NONE", 0}, From aa60f7cac22466544f96f58043fa005f3fb8c356 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Wed, 27 Feb 2013 00:06:16 +0100 Subject: [PATCH 020/103] Fix oversight in the Lua interface that would cause certain quad_*() functions not to be registered. Really wonder why this never failed, and I just noticed this by accident... --- Aquaria/ScriptInterface.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 45232af..48d4510 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -6379,7 +6379,7 @@ luaFunc(entity_getNearestEntity) nameCheck = false; } - float range = lua_tointeger(L, 3); + float range = lua_tonumber(L, 3); EntityType type = ET_NOTYPE; if (lua_isnumber(L, 4)) type = (EntityType)lua_tointeger(L, 4); @@ -8218,6 +8218,8 @@ static const struct { // obj_* are not in the define above MAKE_ROBJ_FUNCS(_, obj) + // same for quad_* base functions + MAKE_QUAD_FUNCS(_, quad) // -- overrides / special cases-- From 23e0707c5bb889e0323c4d79be72b21babe721c5 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Wed, 27 Feb 2013 01:54:38 +0100 Subject: [PATCH 021/103] Add Lua func entity_getSkeletalName() and do not abort when a skin file is not found. Also warn on missing skeletal file. --- Aquaria/ScriptInterface.cpp | 10 ++++++++++ BBGE/SkeletalSprite.cpp | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 48d4510..62dbce7 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -3369,6 +3369,15 @@ luaFunc(entity_loadSkin) luaReturnNil(); } +luaFunc(entity_getSkeletalName) +{ + Entity *e = entity(L); + const char *s = ""; + if (e && e->skeletalSprite.isLoaded()) + s = e->skeletalSprite.filenameLoaded.c_str(); + luaReturnStr(s); +} + luaFunc(entity_idle) { Entity *e = entity(L); @@ -7652,6 +7661,7 @@ static const struct { luaRegister(entity_warpSegments), luaRegister(entity_initSkeletal), luaRegister(entity_loadSkin), + luaRegister(entity_getSkeletalName), luaRegister(entity_initStrands), luaRegister(entity_hurtTarget), diff --git a/BBGE/SkeletalSprite.cpp b/BBGE/SkeletalSprite.cpp index 9ff1b90..c37744f 100644 --- a/BBGE/SkeletalSprite.cpp +++ b/BBGE/SkeletalSprite.cpp @@ -1172,7 +1172,7 @@ void SkeletalSprite::loadSkin(const std::string &fn) file = core->adjustFilenameCase(file); - if (!exists(file,1)) + if (!exists(file)) { errorLog("Could not load skin[" + file + "]"); return; @@ -1304,6 +1304,7 @@ void SkeletalSprite::loadSkeletal(const std::string &fn) if (!exists(file)) { filenameLoaded = ""; + errorLog("Could not load skeletal[" + file + "]"); return; } From eef2289fb239d2e7a469ed3434e7d2894c22699c Mon Sep 17 00:00:00 2001 From: fgenesis Date: Fri, 1 Mar 2013 01:14:59 +0100 Subject: [PATCH 022/103] allow mods to use treasure scripts + remove debug spam in entity_getID() --- Aquaria/Game.cpp | 12 ++++++++++-- Aquaria/Game.h | 1 + Aquaria/ScriptInterface.cpp | 10 +--------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Aquaria/Game.cpp b/Aquaria/Game.cpp index 5f2e90b..4b838e1 100644 --- a/Aquaria/Game.cpp +++ b/Aquaria/Game.cpp @@ -819,7 +819,7 @@ void TreasureSlot::onUpdate(float dt) { doubleClickTimer = 0; - dsq->runScriptNum("scripts/global/menu-treasures.lua", "useTreasure", flag); + dsq->game->onUseTreasure(flag); } else { @@ -7152,10 +7152,18 @@ void Game::onUseTreasure() if (selectedTreasureFlag != -1) { - dsq->runScriptNum("scripts/global/menu-treasures.lua", "useTreasure", selectedTreasureFlag); + onUseTreasure(selectedTreasureFlag); } } +void Game::onUseTreasure(int flag) +{ + if(dsq->mod.isActive()) + dsq->runScriptNum(dsq->mod.getPath() + "scripts/menu-treasures.lua", "useTreasure", flag); + else + dsq->runScriptNum("scripts/global/menu-treasures.lua", "useTreasure", flag); +} + Recipe *Game::findRecipe(const std::vector &list) { if (list.size() < 2) return 0; diff --git a/Aquaria/Game.h b/Aquaria/Game.h index 773b5c8..d2030d3 100644 --- a/Aquaria/Game.h +++ b/Aquaria/Game.h @@ -939,6 +939,7 @@ public: void onRecipes(); void updateCookList(); void onUseTreasure(); + void onUseTreasure(int flag); void onPrevFoodPage(); void onNextFoodPage(); diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 62dbce7..c7cfa1f 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -6156,15 +6156,7 @@ luaFunc(entity_partSetSegs) luaFunc(entity_getID) { Entity *e = entity(L); - int id = 0; - if (e) - { - id = e->getID(); - std::ostringstream os; - os << "id: " << id; - debugLog(os.str()); - } - luaReturnNum(id); + luaReturnNum(e ? e->getID() : 0); } luaFunc(getEntityByID) From 0784d1b9dffefd53e1666e1b979c4dce46b975e9 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Wed, 6 Mar 2013 02:06:52 +0100 Subject: [PATCH 023/103] Shot Lua API update + related internal changes. With this change, shots are no longer stored in a std::list. In the current code, the global shot store may be modified while iterating, this did not cause problems with the list implementation, but would easily crash if a shot is removed while iterating. To fix this, a 2nd vector stores shots to be deleted from the global store and does so when no iteration is in progress and modifying the vector is safe. Added functions: getFirstShot -- for iterating over all shots on the map getNextShot shot_setFirer shot_setExtraDamage shot_getExtraDamage shot_getDamage shot_getDamageType shot_getName --- Aquaria/Avatar.cpp | 24 ++++++------- Aquaria/DSQ.cpp | 2 ++ Aquaria/Entity.cpp | 2 +- Aquaria/Game.cpp | 8 +++-- Aquaria/ScriptInterface.cpp | 72 +++++++++++++++++++++++++++++++++++-- Aquaria/Shot.cpp | 49 ++++++++++++++++--------- Aquaria/Shot.h | 15 ++++++-- 7 files changed, 134 insertions(+), 38 deletions(-) diff --git a/Aquaria/Avatar.cpp b/Aquaria/Avatar.cpp index 82c3101..0c9aa0a 100644 --- a/Aquaria/Avatar.cpp +++ b/Aquaria/Avatar.cpp @@ -2921,7 +2921,7 @@ void Avatar::formAbility(int ability) for (i = Shot::shots.begin(); i != Shot::shots.end(); i++) { Shot *s = (*i); - if (s->shotData && !s->shotData->invisible) + if (s->isActive() && s->shotData && !s->shotData->invisible) { if (!s->firer || s->firer->getEntityType()==ET_ENEMY) { @@ -4935,23 +4935,23 @@ void Avatar::updateAura(float dt) */ for (Shot::Shots::iterator i = Shot::shots.begin(); i != Shot::shots.end(); ++i) { - //&& (*i)->life > 0.2f - if ((*i) && dsq->game->isDamageTypeEnemy((*i)->getDamageType()) && (*i)->firer != this - && (!(*i)->shotData || !(*i)->shotData->ignoreShield)) + Shot *s = *i; + if (s->isActive() && dsq->game->isDamageTypeEnemy(s->getDamageType()) && s->firer != this + && (!s->shotData || !s->shotData->ignoreShield)) { - Vector diff = (*i)->position - shieldPosition; + Vector diff = s->position - shieldPosition; if (diff.getSquaredLength2D() < sqr(AURA_SHIELD_RADIUS)) { - shieldPoints -= (*i)->getDamage(); + shieldPoints -= s->getDamage(); auraHitEmitter.start(); - dsq->spawnParticleEffect("ReflectShot", (*i)->position); + dsq->spawnParticleEffect("ReflectShot", s->position); core->sound->playSfx("Shield-Hit"); - (*i)->position += diff; - //(*i)->target = 0; - diff.setLength2D((*i)->maxSpeed); - (*i)->velocity = diff; - (*i)->reflectFromEntity(this); + s->position += diff; + //s->target = 0; + diff.setLength2D(s->maxSpeed); + s->velocity = diff; + s->reflectFromEntity(this); } } } diff --git a/Aquaria/DSQ.cpp b/Aquaria/DSQ.cpp index f67f612..538549b 100644 --- a/Aquaria/DSQ.cpp +++ b/Aquaria/DSQ.cpp @@ -4665,6 +4665,8 @@ void DSQ::onUpdate(float dt) lockMouse(); Network::update(); + + Shot::clearShotGarbage(); } void DSQ::lockMouse() diff --git a/Aquaria/Entity.cpp b/Aquaria/Entity.cpp index 35c1b57..8e7f027 100644 --- a/Aquaria/Entity.cpp +++ b/Aquaria/Entity.cpp @@ -2912,7 +2912,7 @@ void Entity::doSpellAvoidance(float dt, int range, float mod) { Shot *s = (Shot*)(*i); - if ((s->position - this->position).getSquaredLength2D() < sqr(range)) + if (s->isActive() && (s->position - this->position).getSquaredLength2D() < sqr(range)) { for (int j = 0; j < ignoreShotDamageTypes.size(); j++) { diff --git a/Aquaria/Game.cpp b/Aquaria/Game.cpp index 4b838e1..0c20846 100644 --- a/Aquaria/Game.cpp +++ b/Aquaria/Game.cpp @@ -6253,6 +6253,7 @@ void Game::applyState() //core->afterEffectManager->addEffect(new RippleEffect()); } Shot::shots.clear(); + Shot::deleteShots.clear(); backdropQuad = 0; clearObsRows(); inGameMenu = false; @@ -8491,7 +8492,7 @@ void Game::handleShotCollisions(Entity *e, bool hasShield) for (Shot::Shots::iterator i = Shot::shots.begin(); i != Shot::shots.end(); i++) { Shot *shot = *i; - if (isEntityCollideWithShot(e, shot) && (!hasShield || (!shot->shotData || !shot->shotData->ignoreShield))) + if (shot->isActive() && isEntityCollideWithShot(e, shot) && (!hasShield || (!shot->shotData || !shot->shotData->ignoreShield))) { Vector collidePoint = e->position+e->offset; if (e->getNumTargetPoints()>0) @@ -8523,7 +8524,7 @@ void Game::handleShotCollisionsSkeletal(Entity *e) for (Shot::Shots::iterator i = Shot::shots.begin(); i != Shot::shots.end(); i++) { Shot *shot = *i; - if (isEntityCollideWithShot(e, shot)) + if (shot->isActive() && isEntityCollideWithShot(e, shot)) { Bone *b = collideSkeletalVsCircle(e, shot->position, shot->collideRadius); if (b) @@ -8540,7 +8541,7 @@ void Game::handleShotCollisionsHair(Entity *e, int num) for (Shot::Shots::iterator i = Shot::shots.begin(); i != Shot::shots.end(); i++) { Shot *shot = *i; - if (isEntityCollideWithShot(e, shot)) + if (shot->isActive() && isEntityCollideWithShot(e, shot)) { bool b = collideHairVsCircle(e, num, shot->position, 8); if (b) @@ -10886,6 +10887,7 @@ void Game::removeState() debugLog("killAllShots"); Shot::killAllShots(); + Shot::clearShotGarbage(); debugLog("killAllBeams"); Beam::killAllBeams(); debugLog("killAllWebs"); diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index c7cfa1f..cbaf63b 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -1811,6 +1811,22 @@ luaFunc(web_getNumPoints) luaReturnInt(num); } +luaFunc(getFirstShot) +{ + luaReturnPtr(Shot::getFirstShot()); +} + +luaFunc(getNextShot) +{ + luaReturnPtr(Shot::getNextShot()); +} + +luaFunc(shot_getName) +{ + Shot *s = getShot(L); + luaReturnStr(s ? s->getName() : ""); +} + luaFunc(shot_setOut) { Shot *shot = getShot(L); @@ -1859,11 +1875,26 @@ luaFunc(shot_getFirer) luaReturnPtr(shot ? shot->firer : NULL); } +luaFunc(shot_setFirer) +{ + Shot *shot = getShot(L); + if(shot) + { + Entity *e = lua_isuserdata(L, 2) ? entity(L, 2) : NULL; + shot->firer = e; + } + + luaReturnNil(); +} + luaFunc(shot_setTarget) { Shot *shot = getShot(L); if(shot) - shot->setTarget(entity(L, 2)); + { + Entity *e = lua_isuserdata(L, 2) ? entity(L, 2) : NULL; + shot->setTarget(e); + } luaReturnNil(); } @@ -1873,6 +1904,32 @@ luaFunc(shot_getTarget) luaReturnPtr(shot ? shot->target : NULL); } +luaFunc(shot_setExtraDamage) +{ + Shot *shot = getShot(L); + if(shot) + shot->extraDamage = lua_tonumber(L, 2); + luaReturnNil(); +} + +luaFunc(shot_getExtraDamage) +{ + Shot *shot = getShot(L); + luaReturnNum(shot ? shot->extraDamage : 0.0f); +} + +luaFunc(shot_getDamage) +{ + Shot *shot = getShot(L); + luaReturnNum(shot ? shot->getDamage() : 0.0f); +} + +luaFunc(shot_getDamageType) +{ + Shot *shot = getShot(L); + luaReturnNum(shot ? shot->getDamageType() : DT_NONE); +} + luaFunc(entity_setVel) { Entity *e = entity(L); @@ -5275,7 +5332,10 @@ luaFunc(entity_getRandomTargetPoint) luaFunc(playVisualEffect) { - dsq->playVisualEffect(lua_tonumber(L, 1), Vector(lua_tonumber(L, 2), lua_tonumber(L, 3))); + Entity *target = NULL; + if(lua_isuserdata(L, 4)) + target = entity(L, 4); + dsq->playVisualEffect(lua_tonumber(L, 1), Vector(lua_tonumber(L, 2), lua_tonumber(L, 3)), target); luaReturnNil(); } @@ -7959,13 +8019,21 @@ static const struct { luaRegister(createSpore), + luaRegister(getFirstShot), + luaRegister(getNextShot), luaRegister(shot_setAimVector), luaRegister(shot_setOut), luaRegister(shot_getEffectTime), luaRegister(shot_isIgnoreShield), + luaRegister(shot_setFirer), luaRegister(shot_getFirer), luaRegister(shot_setTarget), luaRegister(shot_getTarget), + luaRegister(shot_setExtraDamage), + luaRegister(shot_getExtraDamage), + luaRegister(shot_getDamage), + luaRegister(shot_getDamageType), + luaRegister(shot_getName), luaRegister(entity_pathBurst), luaRegister(entity_handleShotCollisions), luaRegister(entity_handleShotCollisionsSkeletal), diff --git a/Aquaria/Shot.cpp b/Aquaria/Shot.cpp index af07a4e..12a33cc 100644 --- a/Aquaria/Shot.cpp +++ b/Aquaria/Shot.cpp @@ -26,7 +26,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../BBGE/MathFunctions.h" Shot::Shots Shot::shots; +Shot::Shots Shot::deleteShots; Shot::ShotBank Shot::shotBank; +unsigned int Shot::shotsIter = 0; std::string Shot::shotBankPath = ""; @@ -92,6 +94,9 @@ void ShotData::bankLoad(const std::string &file, const std::string &path) checkDamageTarget = true; } + this->name = file; + stringToLower(this->name); + debugLog(usef); char *data = readFile(core->adjustFilenameCase(usef).c_str()); if (!data) @@ -335,6 +340,7 @@ Shot::Shot() : Quad(), Segmented(0,0) fired = false; target = 0; dead = false; + shotIdx = shots.size(); shots.push_back(this); } @@ -479,7 +485,9 @@ void Shot::setLifeTime(float l) void Shot::onEndOfLife() { destroySegments(0.2); - shots.remove(this); + deleteShots.push_back(this); + dead = true; + if (emitter) { emitter->killParticleEffect(); @@ -531,24 +539,31 @@ void Shot::onHitWall() void Shot::killAllShots() { - std::queueshotDeleteQueue; - for (Shots::iterator i = shots.begin(); i != shots.end(); i++) - { - shotDeleteQueue.push(*i); - } - Shot *s = 0; - while (!shotDeleteQueue.empty()) - { - s = shotDeleteQueue.front(); - if (s) - { - s->safeKill(); - } - shotDeleteQueue.pop(); - } - shots.clear(); + for (Shots::iterator i = shots.begin(); i != shots.end(); ++i) + (*i)->safeKill(); } +void Shot::clearShotGarbage() +{ + for(size_t i = 0; i < deleteShots.size(); ++i) + { + Shot *s = deleteShots[i]; + const unsigned int idx = s->shotIdx; + // move last shot to deleted one and shorten vector + if(idx < shots.size() && shots[idx] == s) + { + Shot *lastshot = shots.back(); + shots[idx] = lastshot; + lastshot->shotIdx = idx; + shots.pop_back(); + } + else + errorLog("Shot::clearShotGarbage(): wrong index in shot vector"); + } + deleteShots.clear(); +} + + void Shot::reflectFromEntity(Entity *e) { Entity *oldFirer = firer; diff --git a/Aquaria/Shot.h b/Aquaria/Shot.h index c94d911..657a55c 100644 --- a/Aquaria/Shot.h +++ b/Aquaria/Shot.h @@ -29,7 +29,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. struct ShotData { ShotData(); - std::string texture; + std::string texture, name; std::string hitSfx, bounceSfx, fireSfx; std::string hitPrt, trailPrt, firePrt, bouncePrt; std::string spawnEntity; @@ -79,11 +79,15 @@ public: //void destroy(); void reflectFromEntity(Entity *e); void setParticleEffect(const std::string &particleEffect); - typedef std::list Shots; - static Shots shots; + typedef std::vector Shots; + static Shots shots, deleteShots; + static unsigned int shotsIter; // for script + static Shot *getFirstShot() { shotsIter = 0; return getNextShot(); } + static Shot *getNextShot() { return shotsIter < shots.size() ? shots[shotsIter++] : NULL; } static std::string shotBankPath; static void targetDied(Entity *t); static void killAllShots(); + static void clearShotGarbage(); Entity *target, *firer; int maxSpeed, targetPt; @@ -117,6 +121,8 @@ public: void updatePosition(); bool isHitEnts() const; bool isObstructed(float dt) const; + inline bool isActive() const { return !dead; } + inline const char *getName() const { return shotData ? shotData->name.c_str() : ""; } float extraDamage; protected: @@ -136,6 +142,9 @@ protected: bool dead; void onUpdate(float dt); + +private: + unsigned int shotIdx; }; class Beam : public Quad From 1217432561eb6751382151b84569c8ca35ca523a Mon Sep 17 00:00:00 2001 From: fgenesis Date: Wed, 13 Mar 2013 23:28:38 +0100 Subject: [PATCH 024/103] allow arbitrary damage type IDs in shots instead of only "DT_*" string constants --- Aquaria/Game.cpp | 4 ++-- Aquaria/Shot.cpp | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Aquaria/Game.cpp b/Aquaria/Game.cpp index 0c20846..5583d05 100644 --- a/Aquaria/Game.cpp +++ b/Aquaria/Game.cpp @@ -6252,7 +6252,7 @@ void Game::applyState() core->afterEffectManager->clear(); //core->afterEffectManager->addEffect(new RippleEffect()); } - Shot::shots.clear(); + Shot::shots.clear(); // the shots were deleted elsewhere, drop any remaining pointers Shot::deleteShots.clear(); backdropQuad = 0; clearObsRows(); @@ -10887,7 +10887,7 @@ void Game::removeState() debugLog("killAllShots"); Shot::killAllShots(); - Shot::clearShotGarbage(); + Shot::clearShotGarbage(); // make sure there are no pointers left (would lead to a crash on shutdown otherwise) debugLog("killAllBeams"); Beam::killAllBeams(); debugLog("killAllWebs"); diff --git a/Aquaria/Shot.cpp b/Aquaria/Shot.cpp index 12a33cc..b52b762 100644 --- a/Aquaria/Shot.cpp +++ b/Aquaria/Shot.cpp @@ -230,6 +230,8 @@ void ShotData::bankLoad(const std::string &file, const std::string &path) damageType = DT_ENEMY_CREATOR; else if (bt == "DT_ENEMY_MANTISBOMB") damageType = DT_ENEMY_MANTISBOMB; + else + damageType = (DamageType)atoi(bt.c_str()); } else if (token == "Invisible") inf >> invisible; From b199e40efd36397b2bb6383f6bbebd1fa36cc06c Mon Sep 17 00:00:00 2001 From: fgenesis Date: Thu, 14 Mar 2013 16:33:37 +0100 Subject: [PATCH 025/103] forgot to register Lua func obj_getLife() and related --- Aquaria/ScriptInterface.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index cbaf63b..879d9cc 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -1521,6 +1521,7 @@ luaFunc(quad_setSegs) RO_FUNC(getter, prefix, setBlendType ) \ RO_FUNC(getter, prefix, setTexture ) \ RO_FUNC(getter, prefix, delete ) \ + RO_FUNC(getter, prefix, getLife ) \ RO_FUNC(getter, prefix, setLife ) \ RO_FUNC(getter, prefix, setDecayRate ) \ RO_FUNC(getter, prefix, addDeathNotify ) \ From 1168eaf1d974765396bd9faf3effb6c6072b488d Mon Sep 17 00:00:00 2001 From: fgenesis Date: Fri, 12 Apr 2013 09:17:45 +0200 Subject: [PATCH 026/103] Remove some dead code + fix clang warning. --- Aquaria/Avatar.cpp | 16 ------- Aquaria/Avatar.h | 1 - Aquaria/Continuity.cpp | 35 ---------------- Aquaria/DSQ.h | 28 ------------- Aquaria/Game.cpp | 83 ------------------------------------- Aquaria/Game.h | 9 ---- Aquaria/ScriptInterface.cpp | 13 +----- 7 files changed, 1 insertion(+), 184 deletions(-) diff --git a/Aquaria/Avatar.cpp b/Aquaria/Avatar.cpp index 0c9aa0a..e07cd37 100644 --- a/Aquaria/Avatar.cpp +++ b/Aquaria/Avatar.cpp @@ -2431,22 +2431,6 @@ bool Avatar::fireAtNearestValidEntity(const std::string &shot) return firedShot; } -void Avatar::spawnSeed() -{ - // max spore children/seeds = 50 - if (dsq->game->getNumberOfEntitiesNamed("SporeChild") < 4) - { - if (!dsq->game->isObstructed(TileVector(position))) - { - dsq->game->createEntity("SporeChild", 0, position, 0, 0, ""); - } - } - else - { - // visual effect and/or sound effect - } -} - Vector Avatar::getFacing() { if (vel.isLength2DIn(2) && rotation.z == 0) diff --git a/Aquaria/Avatar.h b/Aquaria/Avatar.h index 675aedb..0b8a196 100644 --- a/Aquaria/Avatar.h +++ b/Aquaria/Avatar.h @@ -358,7 +358,6 @@ protected: float fallGravityTimer; Vector fallGravity; int lastOutOfWaterMaxSpeed; - void spawnSeed(); int shieldPoints; diff --git a/Aquaria/Continuity.cpp b/Aquaria/Continuity.cpp index 8d4190c..7e712a3 100644 --- a/Aquaria/Continuity.cpp +++ b/Aquaria/Continuity.cpp @@ -2997,40 +2997,6 @@ int Continuity::getPathFlag(Path *p) return entityFlags[os2.str()]; } -SporeChildData *Continuity::getSporeChildDataForEntity(Entity *e) -{ - SporeChildData *scd=0; - for (int i = 0; i < sporeChildData.size(); i++) - { - if (sporeChildData[i].entity == e) - { - scd = &sporeChildData[i]; - break; - } - } - return scd; -} - -void Continuity::registerSporeChildData(Entity *e) -{ - if (!dsq->game->creatingSporeChildren) - { - SporeChildData *scd=0; - if (!(scd = getSporeChildDataForEntity(e))) - { - SporeChildData d; - sporeChildData.push_back(d); - scd = &sporeChildData[sporeChildData.size()-1]; - } - if (scd) - { - scd->state = e->getState(); - scd->health = e->health; - scd->entity = e; - } - } -} - class GemGet : public Quad { public: @@ -3285,7 +3251,6 @@ void Continuity::reset() loadPetData(); formUpgrades.clear(); - sporeChildData.clear(); auraType = AURA_NONE; for (int i = 0; i < MAX_FLAGS; i++) diff --git a/Aquaria/DSQ.h b/Aquaria/DSQ.h index 57b7df0..1b496bc 100644 --- a/Aquaria/DSQ.h +++ b/Aquaria/DSQ.h @@ -826,28 +826,6 @@ public: void load(); }; -enum CMStat -{ - CM_ID =0, - CM_EGO, - CM_SEGO -}; - -class WordColoring -{ -public: - std::string word; - Vector color; -}; - -struct SporeChildData -{ - SporeChildData() : state(0), entity(0), health(0) {} - int state; - int health; - Entity *entity; -}; - const int FLAG_LI = 1000, FLAG_LICOMBAT = 1001; const int FLAG_COOKS = 21; @@ -1065,12 +1043,6 @@ public: AuraType auraType; float auraTimer; - SporeChildData *getSporeChildDataForEntity(Entity *e); - void registerSporeChildData(Entity *e); - - std::vector sporeChildData; - - EatData *getEatData(const std::string &name); void loadEatBank(); diff --git a/Aquaria/Game.cpp b/Aquaria/Game.cpp index 5583d05..b05b816 100644 --- a/Aquaria/Game.cpp +++ b/Aquaria/Game.cpp @@ -1867,18 +1867,6 @@ void Game::transitionToScene(std::string scene) core->enqueueJumpState("Game", false); } -void Game::transitionToSceneUnder(std::string scene) -{ - if (avatar) - { - avatar->onWarp(); - } - sceneToLoad = scene; - stringToLower(sceneToLoad); - core->pushState("Game"); -} - - ElementTemplate *Game::getElementTemplateByIdx(int idx) { for (int i = 0; i < elementTemplates.size(); i++) @@ -2706,34 +2694,6 @@ EntitySaveData *Game::getEntitySaveDataForEntity(Entity *e, Vector pos) return 0; } -void Game::spawnSporeChildren() -{ - creatingSporeChildren = true; - SporeChildData *scd; - int sz = dsq->continuity.sporeChildData.size(); - for (int i=0; i < sz; i++) - { - scd = &dsq->continuity.sporeChildData[i]; - scd->entity = 0; - } - int c = 0; - for (int i=0; i < sz; i++) - { - scd = &dsq->continuity.sporeChildData[i]; - Entity *e = dsq->game->createEntity("SporeChild", 0, avatar->position+Vector(0,2+c*2), 0, 0, ""); - if (e) - { - e->setState(scd->state); - if (scd->health < 1) - scd->health = 1; - e->health = scd->health; - scd->entity = e; - } - c++; - } - creatingSporeChildren = false; -} - void Game::setTimerTextAlpha(float a, float t) { timerText->alpha.interpolateTo(a, t); @@ -5767,46 +5727,6 @@ void Game::updateParticlePause() } } -void Game::warpKey1() -{ - if (core->getCtrlState()) - { - dsq->game->avatar->heal(1000); - dsq->game->avatar->fhTo(true); - warpToSceneNode("OPENWATER02", "WARPKEY"); - } -} - -void Game::warpKey2() -{ - if (core->getCtrlState()) - { - dsq->game->avatar->heal(1000); - dsq->game->avatar->fhTo(true); - warpToSceneNode("VEIL01", "WARPKEY"); - } -} - -void Game::warpKey3() -{ - if (core->getCtrlState()) - { - dsq->game->avatar->heal(1000); - dsq->game->avatar->fhTo(true); - warpToSceneNode("FOREST03", "WARPKEY"); - } -} - -void Game::warpKey4() -{ - if (core->getCtrlState()) - { - dsq->game->avatar->heal(1000); - dsq->game->avatar->fhTo(true); - warpToSceneNode("ABYSS01", "WARPKEY"); - } -} - int game_collideParticle(Vector pos) { bool aboveWaterLine = (pos.y <= dsq->game->waterLevel.x+20); @@ -6760,9 +6680,6 @@ void Game::applyState() toNode = ""; - - spawnSporeChildren(); - createInGameMenu(); hideInGameMenu(false); diff --git a/Aquaria/Game.h b/Aquaria/Game.h index d2030d3..33a5bc6 100644 --- a/Aquaria/Game.h +++ b/Aquaria/Game.h @@ -125,7 +125,6 @@ typedef std::vector EntityGroups; enum EditTypes { - ET_NONE =-1, ET_ELEMENTS =0, ET_ENTITIES =1, ET_PATHS =2, @@ -648,7 +647,6 @@ public: void updatePreviewRecipe(); void transitionToScene(std::string scene); - void transitionToSceneUnder(std::string scene); bool loadScene(std::string scene); void clearGrid(int v = 0); @@ -882,9 +880,6 @@ public: int worldMapIndex; - void spawnSporeChildren(); - - bool creatingSporeChildren; bool loadingScene; WaterSurfaceRender *waterSurfaceRender; @@ -1048,10 +1043,6 @@ protected: void warpPrep(); - void warpKey1(); - void warpKey2(); - void warpKey3(); - void warpKey4(); bool shuttingDownGameState; void onOptionsMenu(); bool optionsMenu, foodMenu, petMenu, treasureMenu, keyConfigMenu; diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 879d9cc..fb7e210 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -5240,16 +5240,6 @@ luaFunc(warpNaijaToSceneNode) luaReturnNil(); } -luaFunc(registerSporeChildData) -{ - Entity *e = entity(L); - if (e) - { - dsq->continuity.registerSporeChildData(e); - } - luaReturnNil(); -} - luaFunc(entity_setDamageTarget) { Entity *e = entity(L); @@ -6460,7 +6450,7 @@ luaFunc(entity_getNearestEntity) Entity *e = *i; if (e != me && e != ignore && e->isPresent() && e->isNormalLayer()) { - if (type == ET_NONE || e->getEntityType() == type) + if (type == ET_NOTYPE || e->getEntityType() == type) { if (damageTarget == DT_NONE || e->isDamageTarget((DamageType)damageTarget)) { @@ -7773,7 +7763,6 @@ static const struct { luaRegister(entity_sound), luaRegister(entity_playSfx), - luaRegister(registerSporeChildData), luaRegister(registerSporeDrop), luaRegister(getIngredientGfx), From 15884e3b0232aa3f4d461b61e4e00d6881c98f1d Mon Sep 17 00:00:00 2001 From: fgenesis Date: Mon, 15 Apr 2013 00:38:18 +0200 Subject: [PATCH 027/103] Some script fixes that were overlooked and caused warnings in the dev builds --- game_scripts/scripts/.gitignore | 2 ++ game_scripts/scripts/entities/energygodspirit.lua | 2 +- game_scripts/scripts/entities/finalspiritcommon.lua | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 game_scripts/scripts/.gitignore diff --git a/game_scripts/scripts/.gitignore b/game_scripts/scripts/.gitignore new file mode 100644 index 0000000..fa9ed09 --- /dev/null +++ b/game_scripts/scripts/.gitignore @@ -0,0 +1,2 @@ +vox/* +entities/*.txt diff --git a/game_scripts/scripts/entities/energygodspirit.lua b/game_scripts/scripts/entities/energygodspirit.lua index bcb303c..4611eba 100644 --- a/game_scripts/scripts/entities/energygodspirit.lua +++ b/game_scripts/scripts/entities/energygodspirit.lua @@ -32,7 +32,7 @@ v.attackDelay = 0 v.noteQuad = 0 - +v.holdingNote = false v.maxHits = 6 v.hits = v.maxHits diff --git a/game_scripts/scripts/entities/finalspiritcommon.lua b/game_scripts/scripts/entities/finalspiritcommon.lua index 92a7582..cad965d 100644 --- a/game_scripts/scripts/entities/finalspiritcommon.lua +++ b/game_scripts/scripts/entities/finalspiritcommon.lua @@ -223,7 +223,7 @@ function enterState(me) bone_rotate(v.glow, 0, 1, 0, 0, 1) bone_rotate(v.glow, 360, 1, -1) end - bone_rotate(v.boneNote, -entity_getRotation(me)) + bone_rotate(v.noteBone, -entity_getRotation(me)) end function exitState(me) From d6180e7134dcc188977d6934f73c82f607746596 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Mon, 15 Apr 2013 03:40:08 +0200 Subject: [PATCH 028/103] Oops, compile fix for 1168eaf1d974 --- Aquaria/DSQ.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/Aquaria/DSQ.h b/Aquaria/DSQ.h index 1b496bc..4242ed4 100644 --- a/Aquaria/DSQ.h +++ b/Aquaria/DSQ.h @@ -986,8 +986,6 @@ public: std::string naijaModel; - std::vector wordColoring; - FormType form; void learnFormUpgrade(FormUpgradeType form); From 17e0ec9d2ec3c3e8208664fe72bcfeb9e13efc13 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sun, 21 Apr 2013 15:58:52 +0200 Subject: [PATCH 029/103] Remove hack that keeps setting avatar collide radius. --- Aquaria/Avatar.cpp | 25 ++++++++++++------------- Aquaria/DSQ.cpp | 2 +- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/Aquaria/Avatar.cpp b/Aquaria/Avatar.cpp index e07cd37..ed30791 100644 --- a/Aquaria/Avatar.cpp +++ b/Aquaria/Avatar.cpp @@ -117,6 +117,9 @@ const float NOTE_ACCEPT_DISTANCE = 25; // we accept a note. const float NOTE_ACCEPT_ANGLE_OFFSET = 15; +const int COLLIDE_RADIUS_NORMAL = 10; +const int COLLIDE_RADIUS_FISH = 8; + const int requiredDualFormCharge = 3; bool usingDigital = false; @@ -1590,6 +1593,8 @@ void Avatar::changeForm(FormType form, bool effects, bool onInit, FormType lastF return; } //rotationOffset.interpolateTo(Vector(0,0,0), 0.5); + + collideRadius = COLLIDE_RADIUS_NORMAL; } break; case FORM_SUN: @@ -1720,6 +1725,8 @@ void Avatar::changeForm(FormType form, bool effects, bool onInit, FormType lastF refreshModel("FishForm", ""); //rotationOffset.interpolateTo(Vector(0,0,-90), 0.5); //refreshModel("NaijaFish", ""); + + collideRadius = COLLIDE_RADIUS_FISH; } break; case FORM_SUN: @@ -4117,6 +4124,10 @@ Avatar::Avatar() : Entity(), ActionMapper() refreshNormalForm(); + if(dsq->continuity.form) + collideRadius = COLLIDE_RADIUS_FISH; + else + collideRadius = COLLIDE_RADIUS_NORMAL; } void Avatar::revert() @@ -7059,15 +7070,6 @@ void Avatar::onUpdate(float dt) vel2 = Vector(0,0,0); } - //int collideCircle = 24;//24; // 48 - int collideCircle = 10; - if (dsq->continuity.form == FORM_FISH) - collideCircle = 8; - // just for external access - // HACK: should always be using collide radius :| ? - - //updateMovement - collideRadius = collideCircle; if (!state.lockedToWall && !isFollowingPath() && !riding) { /*collideCheck:*/ @@ -7119,10 +7121,7 @@ void Avatar::onUpdate(float dt) //Vector testPosition = position + (vel *dt)*2; position = newPosition; - - int hw = collideCircle; - - if (dsq->game->collideCircleWithGrid(position, hw)) + if (dsq->game->collideCircleWithGrid(position, collideRadius)) { if (dsq->game->lastCollideTileType == OT_HURT && dsq->continuity.getWorldType() != WT_SPIRIT diff --git a/Aquaria/DSQ.cpp b/Aquaria/DSQ.cpp index 538549b..bc4fff4 100644 --- a/Aquaria/DSQ.cpp +++ b/Aquaria/DSQ.cpp @@ -4541,7 +4541,7 @@ void DSQ::onUpdate(float dt) os << "rot: " << avatar->rotation.z << " rotoff: " << avatar->rotationOffset.z << std::endl; os << "p(" << int(avatar->position.x) << ", " << int(avatar->position.y) << ")" << std::endl; os << "inp: " << avatar->isInputEnabled() << std::endl; - os << "wallNormal(" << avatar->wallNormal.x << ", " << avatar->wallNormal.y << ")" << std::endl; + os << "wallNormal(" << avatar->wallNormal.x << ", " << avatar->wallNormal.y << ") collradius: " << avatar->collideRadius << std::endl; os << "burst: " << avatar->burst << " burstTimer: " << avatar->burstTimer << std::endl; os << "inCurrent: " << avatar->isInCurrent() << std::endl; os << "qsongCastDelay: " << avatar->quickSongCastDelay << std::endl; From 4c0f2989463d36e6f7f47359a968d4d9487cd5d7 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sun, 21 Apr 2013 15:59:19 +0200 Subject: [PATCH 030/103] Add quad_getWidth(), quad_getWidth() Lua functions --- Aquaria/ScriptInterface.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index fb7e210..04e965a 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -1457,6 +1457,18 @@ luaFunc(quad_setVisible) luaReturnNil(); } +luaFunc(quad_getWidth) +{ + Quad *q = getQuad(L); + luaReturnNum(q ? q->width : 0.0f); +} + +luaFunc(quad_getHeight) +{ + Quad *q = getQuad(L); + luaReturnNum(q ? q->height : 0.0f); +} + luaFunc(quad_setWidth) { Quad *q = getQuad(L); @@ -1575,6 +1587,8 @@ luaFunc(quad_setSegs) Q_FUNC(getter, prefix, isVisible ) \ Q_FUNC(getter, prefix, setWidth ) \ Q_FUNC(getter, prefix, setHeight ) \ + Q_FUNC(getter, prefix, getWidth ) \ + Q_FUNC(getter, prefix, getHeight ) \ Q_FUNC(getter, prefix, setSegs ) // This should reflect the internal class hierarchy, From 25262144f3c8f61b77637c5c0593d8b193a97cf3 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sun, 21 Apr 2013 18:46:56 +0200 Subject: [PATCH 031/103] Add Lua functions: entity_setVel2() entity_setVel2Len() entity_getVel2Len() node_isEffectOn() --- Aquaria/ScriptInterface.cpp | 65 +++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 18 deletions(-) diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 04e965a..2606cec 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -3773,7 +3773,7 @@ luaFunc(entity_damage) { DamageData d; //d.attacker = e; - d.attacker = entity(L, 2); + d.attacker = lua_isuserdata(L, 2) ? entity(L, 2) : NULL; d.damage = lua_tonumber(L, 3); d.damageType = (DamageType)lua_tointeger(L, 4); didDamage = e->damage(d); @@ -4814,9 +4814,7 @@ luaFunc(entity_moveTowardsAngle) { Entity *e = entity(L); if (e) - { e->moveTowardsAngle(lua_tointeger(L, 2), lua_tonumber(L, 3), lua_tointeger(L, 4)); - } luaReturnNil(); } @@ -4824,9 +4822,7 @@ luaFunc(entity_moveAroundAngle) { Entity *e = entity(L); if (e) - { e->moveTowardsAngle(lua_tointeger(L, 2), lua_tonumber(L, 3), lua_tonumber(L, 4)); - } luaReturnNil(); } @@ -4834,9 +4830,7 @@ luaFunc(entity_moveTowards) { Entity *e = entity(L); if (e) - { e->moveTowards(Vector(lua_tonumber(L, 2), lua_tonumber(L, 3)), lua_tonumber(L, 4), lua_tonumber(L, 5)); - } luaReturnNil(); } @@ -4844,9 +4838,7 @@ luaFunc(entity_moveAround) { Entity *e = entity(L); if (e) - { e->moveAround(Vector(lua_tonumber(L, 2), lua_tonumber(L, 3)), lua_tonumber(L, 4), lua_tonumber(L, 5), lua_tonumber(L, 6)); - } luaReturnNil(); } @@ -4854,12 +4846,43 @@ luaFunc(entity_addVel2) { Entity *e = entity(L); if (e) - { e->vel2 += Vector(lua_tonumber(L, 2), lua_tonumber(L, 3)); + luaReturnNil(); +} + +luaFunc(entity_setVel2) +{ + Entity *e = entity(L); + if (e) + { + e->vel2 = Vector(lua_tonumber(L, 2), lua_tonumber(L, 3)); } luaReturnNil(); } +luaFunc(entity_getVel2Len) +{ + Entity *e = entity(L); + luaReturnNum(e ? e->vel2.getLength2D() : 0.0f); +} + +luaFunc(entity_setVel2Len) +{ + Entity *e = entity(L); + if(e) + e->vel2.setLength2D(lua_tonumber(L, 2)); + luaReturnNil(); +}; + +luaFunc(entity_getVel2) +{ + Entity *e = entity(L); + Vector vel2; + if(e) + vel2 = e->vel2; + luaReturnVec2(vel2.x, vel2.y); +} + luaFunc(entity_isValidTarget) { Entity *e = entity(L); @@ -6271,6 +6294,12 @@ luaFunc(node_setEffectOn) luaReturnNil(); } +luaFunc(node_isEffectOn) +{ + Path *p = path(L, 1); + luaReturnBool(p ? p->effectOn : false); +} + luaFunc(node_activate) { Path *p = path(L); @@ -8055,14 +8084,6 @@ static const struct { luaRegister(entity_waitForPath), luaRegister(entity_watchForPath), - luaRegister(entity_addVel), - luaRegister(entity_addVel2), - luaRegister(entity_addRandomVel), - - luaRegister(entity_clearVel), - luaRegister(entity_clearVel2), - - luaRegister(entity_revive), luaRegister(entity_getTarget), @@ -8119,6 +8140,7 @@ static const struct { luaRegister(node_getAmount), luaRegister(node_getSize), luaRegister(node_setEffectOn), + luaRegister(node_isEffectOn), luaRegister(toggleSteam), luaRegister(toggleVersionLabel), @@ -8222,6 +8244,13 @@ static const struct { luaRegister(entity_clearVel), luaRegister(entity_velTowards), + luaRegister(entity_setVel2), + luaRegister(entity_setVel2Len), + luaRegister(entity_getVel2Len), + luaRegister(entity_addVel2), + luaRegister(entity_getVel2), + luaRegister(entity_clearVel2), + luaRegister(updateMusic), From 0c768a711de6e36ffb5573e124196b4f3ec01b90 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sun, 21 Apr 2013 18:47:51 +0200 Subject: [PATCH 032/103] Cause less memory stress in InterpolatedVector assignment --- BBGE/Vector.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/BBGE/Vector.h b/BBGE/Vector.h index 9cb705b..e56fbac 100644 --- a/BBGE/Vector.h +++ b/BBGE/Vector.h @@ -500,11 +500,18 @@ public: x = vec.x; y = vec.y; z = vec.z; - delete data; if (vec.data) - data = new InterpolatedVectorData(*vec.data); + { + if (data) + *data = *vec.data; + else + data = new InterpolatedVectorData(*vec.data); + } else + { + delete data; data = NULL; + } return *this; } From 9f4a82509a7fefa63b465d8899243a56d5f6b7bf Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sun, 21 Apr 2013 20:24:14 +0200 Subject: [PATCH 033/103] Fix typo added in 17e0ec9d2ec3c. --- Aquaria/Avatar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aquaria/Avatar.cpp b/Aquaria/Avatar.cpp index ed30791..2fb40f7 100644 --- a/Aquaria/Avatar.cpp +++ b/Aquaria/Avatar.cpp @@ -4124,7 +4124,7 @@ Avatar::Avatar() : Entity(), ActionMapper() refreshNormalForm(); - if(dsq->continuity.form) + if(dsq->continuity.form == FORM_FISH) collideRadius = COLLIDE_RADIUS_FISH; else collideRadius = COLLIDE_RADIUS_NORMAL; From 4a3c1dc74567f2ff321466000e9c15fb50298b9b Mon Sep 17 00:00:00 2001 From: fgenesis Date: Mon, 22 Apr 2013 01:08:36 +0200 Subject: [PATCH 034/103] Allow node scripts to catch quick song 1-9 action --- Aquaria/Game.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Aquaria/Game.cpp b/Aquaria/Game.cpp index b05b816..bc00dd7 100644 --- a/Aquaria/Game.cpp +++ b/Aquaria/Game.cpp @@ -6921,6 +6921,18 @@ void Game::bindInput() addAction(ACTION_MENUUP, JOY1_STICK_UP); addAction(ACTION_MENUDOWN, JOY1_STICK_DOWN); + // To capture quick song keys via script + dsq->user.control.actionSet.importAction(this, "SongSlot1", ACTION_SONGSLOT1); + dsq->user.control.actionSet.importAction(this, "SongSlot2", ACTION_SONGSLOT2); + dsq->user.control.actionSet.importAction(this, "SongSlot3", ACTION_SONGSLOT3); + dsq->user.control.actionSet.importAction(this, "SongSlot4", ACTION_SONGSLOT4); + dsq->user.control.actionSet.importAction(this, "SongSlot5", ACTION_SONGSLOT5); + dsq->user.control.actionSet.importAction(this, "SongSlot6", ACTION_SONGSLOT6); + dsq->user.control.actionSet.importAction(this, "SongSlot7", ACTION_SONGSLOT7); + dsq->user.control.actionSet.importAction(this, "SongSlot8", ACTION_SONGSLOT8); + dsq->user.control.actionSet.importAction(this, "SongSlot9", ACTION_SONGSLOT9); + dsq->user.control.actionSet.importAction(this, "SongSlot10", ACTION_SONGSLOT10); + if (avatar) avatar->bindInput(); From 61826746187adba02d2d6c891abd0268ceeaebf1 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Mon, 22 Apr 2013 01:15:20 +0200 Subject: [PATCH 035/103] Add createShockEffect() Lua function and rename castSong() to singSong(). castSong() existing in the global Lua namespace caused it to be removed and stored as an interface function as soon as a script was loaded. The function was apparently never used in the game or other mod scripts, thus renaming it now should be safe. --- Aquaria/ScriptInterface.cpp | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 2606cec..7565a66 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -34,6 +34,7 @@ extern "C" #include "Entity.h" #include "Web.h" #include "GridRender.h" +#include "AfterEffect.h" #include "../BBGE/MathFunctions.h" @@ -1701,7 +1702,11 @@ luaFunc(hasFormUpgrade) luaReturnBool(dsq->continuity.hasFormUpgrade((FormUpgradeType)lua_tointeger(L, 1))); } -luaFunc(castSong) +// this used to be castSong(), but that name is already taken by an interface function. +// For compatibility, at the end of the Lua function table this is registered as +// castSong() as well, so that scripts/mods not using the castSong() interface function +// in songs.lua will work as expected. -- FG +luaFunc(singSong) { dsq->continuity.castSong(lua_tonumber(L, 1)); luaReturnNil(); @@ -5373,6 +5378,22 @@ luaFunc(playNoEffect) luaReturnNil(); } +luaFunc(createShockEffect) +{ + if (core->afterEffectManager) + { + core->afterEffectManager->addEffect(new ShockEffect( + Vector(lua_tonumber(L, 1), lua_tonumber(L, 2)), // position + Vector(lua_tonumber(L, 3), lua_tonumber(L, 4)), // original position + lua_tonumber(L, 5), // amplitude + lua_tonumber(L, 6), // amplitude decay + lua_tonumber(L, 7), // frequency + lua_tonumber(L, 8), // wave length + lua_tonumber(L, 9))); // time multiplier + } + luaReturnNil(); +} + luaFunc(emote) { int emote = lua_tonumber(L, 1); @@ -7837,6 +7858,7 @@ static const struct { luaRegister(playVisualEffect), luaRegister(playNoEffect), + luaRegister(createShockEffect), luaRegister(setOverrideMusic), @@ -7949,7 +7971,7 @@ static const struct { luaRegister(hasFormUpgrade), - luaRegister(castSong), + luaRegister(singSong), luaRegister(isObstructed), luaRegister(isObstructedBlock), luaRegister(getObstruction), @@ -8344,6 +8366,8 @@ static const struct { {"bone_setColor", l_bone_color}, + {"castSong", l_singSong}, + }; //============================================================================================ From d992e280cc87cb616f991b0b5b2ea2c243ce0c55 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Mon, 22 Apr 2013 01:18:40 +0200 Subject: [PATCH 036/103] Oops, forgot to save before push. --- Aquaria/ScriptInterface.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 7565a66..d5570a7 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -1702,10 +1702,7 @@ luaFunc(hasFormUpgrade) luaReturnBool(dsq->continuity.hasFormUpgrade((FormUpgradeType)lua_tointeger(L, 1))); } -// this used to be castSong(), but that name is already taken by an interface function. -// For compatibility, at the end of the Lua function table this is registered as -// castSong() as well, so that scripts/mods not using the castSong() interface function -// in songs.lua will work as expected. -- FG +// This used to be castSong(), but that name is already taken by an interface function. -- FG luaFunc(singSong) { dsq->continuity.castSong(lua_tonumber(L, 1)); @@ -8366,8 +8363,6 @@ static const struct { {"bone_setColor", l_bone_color}, - {"castSong", l_singSong}, - }; //============================================================================================ From f835f6c83c6f10cb808afe30d2e1022ca9a6363b Mon Sep 17 00:00:00 2001 From: fgenesis Date: Mon, 22 Apr 2013 02:39:58 +0200 Subject: [PATCH 037/103] Allow nodes to catch revert action --- Aquaria/Avatar.cpp | 5 ++++- Aquaria/DSQ.h | 1 + Aquaria/Game.cpp | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Aquaria/Avatar.cpp b/Aquaria/Avatar.cpp index 2fb40f7..a4c030f 100644 --- a/Aquaria/Avatar.cpp +++ b/Aquaria/Avatar.cpp @@ -152,7 +152,7 @@ void Avatar::bindInput() dsq->user.control.actionSet.importAction(this, "PrimaryAction", ACTION_PRIMARY); dsq->user.control.actionSet.importAction(this, "SecondaryAction", ACTION_SECONDARY); - dsq->user.control.actionSet.importAction(this, "Revert", MakeFunctionEvent(Avatar, revert), 0); + dsq->user.control.actionSet.importAction(this, "Revert", ACTION_REVERT); dsq->user.control.actionSet.importAction(this, "SwimUp", ACTION_SWIMUP); dsq->user.control.actionSet.importAction(this, "SwimDown", ACTION_SWIMDOWN); @@ -4510,6 +4510,9 @@ void Avatar::action(int id, int state) if (id == ACTION_PRIMARY) { if (state) lmbd(); else lmbu(); } if (id == ACTION_SECONDARY) { if (state) rmbd(); else rmbu(); } + if (id == ACTION_REVERT && !state) + revert(); + if (id == ACTION_PRIMARY && state)// !state { if (isMiniMapCursorOkay()) diff --git a/Aquaria/DSQ.h b/Aquaria/DSQ.h index 4242ed4..d951255 100644 --- a/Aquaria/DSQ.h +++ b/Aquaria/DSQ.h @@ -122,6 +122,7 @@ enum AquariaActions ACTION_ROLL, ACTION_SLOW, // currently unused + ACTION_REVERT, ACTION_ZOOMIN = 200, ACTION_ZOOMOUT, diff --git a/Aquaria/Game.cpp b/Aquaria/Game.cpp index bc00dd7..de66c8b 100644 --- a/Aquaria/Game.cpp +++ b/Aquaria/Game.cpp @@ -6933,6 +6933,8 @@ void Game::bindInput() dsq->user.control.actionSet.importAction(this, "SongSlot9", ACTION_SONGSLOT9); dsq->user.control.actionSet.importAction(this, "SongSlot10", ACTION_SONGSLOT10); + dsq->user.control.actionSet.importAction(this, "Revert", ACTION_REVERT); + if (avatar) avatar->bindInput(); From ad10db82adc4b3986f2a6ce5f2ad4576587aa735 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Mon, 22 Apr 2013 02:40:29 +0200 Subject: [PATCH 038/103] Add Lua functions: isPaused(), isInGameMenu(), isInEditor() --- Aquaria/ScriptInterface.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index d5570a7..5ea30bc 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -3701,6 +3701,21 @@ luaFunc(unpause) luaReturnNil(); } +luaFunc(isPaused) +{ + luaReturnBool(dsq->game->isPaused()); +} + +luaFunc(isInGameMenu) +{ + luaReturnBool(dsq->game->isInGameMenu()); +} + +luaFunc(isInEditor) +{ + luaReturnBool(dsq->game->isSceneEditorActive()); +} + luaFunc(clearControlHint) { dsq->game->clearControlHint(); @@ -7595,6 +7610,9 @@ static const struct { luaRegister(pause), luaRegister(unpause), + luaRegister(isPaused), + luaRegister(isInGameMenu), + luaRegister(isInEditor), luaRegister(vector_normalize), From 65b1983c61586a0f09761fd9070776ececd0ac62 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Mon, 22 Apr 2013 02:42:53 +0200 Subject: [PATCH 039/103] Make script="x" setting in songs.xml accept other values than boolean. The value 2 is now used to indicate that both script and internal handler should be called. --- Aquaria/Continuity.cpp | 7 ++++++- Aquaria/DSQ.h | 2 +- Aquaria/Game.cpp | 13 ------------- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/Aquaria/Continuity.cpp b/Aquaria/Continuity.cpp index 7e712a3..063dd8a 100644 --- a/Aquaria/Continuity.cpp +++ b/Aquaria/Continuity.cpp @@ -1392,6 +1392,10 @@ void Continuity::castSong(int num) effect->setPositionSnapTo(&dsq->game->avatar->position); dsq->game->addRenderObject(effect, LR_PARTICLES); + + // song->script == 0: internal handler only + // song->script == 1: script handler only + // song->script == 2: both if (song->script) { if (dsq->mod.isActive()) @@ -1399,7 +1403,8 @@ void Continuity::castSong(int num) else dsq->runScriptNum("songs.lua", "castSong", num); } - else + + if (song->script != 1) { switch((SongType)num) { diff --git a/Aquaria/DSQ.h b/Aquaria/DSQ.h index d951255..5043f36 100644 --- a/Aquaria/DSQ.h +++ b/Aquaria/DSQ.h @@ -312,7 +312,7 @@ struct Song Song() { index=0; script=0; } int index; SongNotes notes; - bool script; + int script; }; const int MAX_FLAGS = 1024; diff --git a/Aquaria/Game.cpp b/Aquaria/Game.cpp index de66c8b..cab97ab 100644 --- a/Aquaria/Game.cpp +++ b/Aquaria/Game.cpp @@ -6851,24 +6851,11 @@ void Game::bindInput() #ifdef AQUARIA_BUILD_SCENEEDITOR if (dsq->canOpenEditor()) { - //addAction(MakeFunctionEvent(Game, toggleSceneEditor), KEY_TAB, 0); addAction(ACTION_TOGGLESCENEEDITOR, KEY_TAB); } #endif - - /* - if (dsq->user.demo.warpKeys) - { - addAction(MakeFunctionEvent(Game, warpKey1), KEY_1, 1); - addAction(MakeFunctionEvent(Game, warpKey2), KEY_2, 1); - addAction(MakeFunctionEvent(Game, warpKey3), KEY_3, 1); - addAction(MakeFunctionEvent(Game, warpKey4), KEY_4, 1); - } - */ - - dsq->user.control.actionSet.importAction(this, "PrimaryAction", ACTION_PRIMARY); dsq->user.control.actionSet.importAction(this, "Escape", ACTION_ESC); From cba3535487be473933d01a2b3eaa31731cd448b9 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Mon, 22 Apr 2013 23:36:31 +0200 Subject: [PATCH 040/103] Keep track of total number of GL render calls --- Aquaria/DSQ.cpp | 2 +- BBGE/Core.cpp | 6 +++++- BBGE/Core.h | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Aquaria/DSQ.cpp b/Aquaria/DSQ.cpp index bc4fff4..d58645f 100644 --- a/Aquaria/DSQ.cpp +++ b/Aquaria/DSQ.cpp @@ -4590,7 +4590,7 @@ void DSQ::onUpdate(float dt) if (isDeveloperKeys() && fpsText && cmDebug && cmDebug->alpha == 1) { std::ostringstream os; - os << "FPS: " << core->fps << " | ROC: " << core->renderObjectCount; + os << "FPS: " << core->fps << " | ROC: " << core->renderObjectCount << " | RC: " << Core::dbg_numRenderCalls; os << " | p: " << core->processedRenderObjectCount << " | t: " << core->totalRenderObjectCount; os << " | s: " << dsq->continuity.seconds; os << " | evQ: " << core->eventQueue.getSize(); diff --git a/BBGE/Core.cpp b/BBGE/Core.cpp index b71581c..3bb0f1e 100644 --- a/BBGE/Core.cpp +++ b/BBGE/Core.cpp @@ -1840,11 +1840,13 @@ void Core::setSDLGLAttributes() #define GLAPIENTRY #endif +unsigned int Core::dbg_numRenderCalls = 0; + #ifdef BBGE_BUILD_OPENGL_DYNAMIC #define GL_FUNC(ret,fn,params,call,rt) \ extern "C" { \ static ret (GLAPIENTRY *p##fn) params = NULL; \ - ret GLAPIENTRY fn params { rt p##fn call; } \ + ret GLAPIENTRY fn params { ++Core::dbg_numRenderCalls; rt p##fn call; } \ } #include "OpenGLStubs.h" #undef GL_FUNC @@ -3006,6 +3008,8 @@ void Core::main(float runTime) updateCullData(); + dbg_numRenderCalls = 0; + if (settings.renderOn) { if (verbose) debugLog("dark layer prerender"); diff --git a/BBGE/Core.h b/BBGE/Core.h index 84b08cb..8e45ab3 100644 --- a/BBGE/Core.h +++ b/BBGE/Core.h @@ -1310,6 +1310,7 @@ public: int zgaSave(const char *filename, short int width, short int height, unsigned char pixelDepth, unsigned char *imageData); volatile int dbg_numThreadDecoders; + static unsigned int dbg_numRenderCalls; protected: From 0490afe7a28623349afd4a4e7f6a71a2dfbceb9e Mon Sep 17 00:00:00 2001 From: fgenesis Date: Mon, 22 Apr 2013 23:38:10 +0200 Subject: [PATCH 041/103] Script interface additions: + entity_isDeathScene() + getNearestEntity() + entity_getDistanceToPoint() Add color transition time parameter to fade(), fade2(), fade3() --- Aquaria/Entity.h | 1 + Aquaria/ScriptInterface.cpp | 41 ++++++++++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/Aquaria/Entity.h b/Aquaria/Entity.h index 336ccf3..724aa64 100644 --- a/Aquaria/Entity.h +++ b/Aquaria/Entity.h @@ -436,6 +436,7 @@ public: void setDieTimer(float v) { dieTimer = v; } float getHealthPerc(); void setDeathScene(bool v); + bool isDeathScene() const { return deathScene; } void generateCollisionMask(int ovrCollideRadius=0); DamageData lastDamage; bool checkSplash(const Vector &override=Vector(0,0,0)); diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 5ea30bc..f6e801e 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -4564,6 +4564,18 @@ luaFunc(entity_getDistanceToTarget) luaReturnNum(dist); } +luaFunc(entity_getDistanceToPoint) +{ + Entity *e = entity(L); + float dist = 0; + if (e) + { + Vector p(lua_tonumber(L, 2), lua_tonumber(L, 3)); + dist = (p - e->position).getLength2D(); + } + luaReturnNum(dist); +} + luaFunc(entity_watchEntity) { Entity *e = entity(L); @@ -5204,6 +5216,12 @@ luaFunc(entity_setDeathScene) luaReturnNil(); } +luaFunc(entity_isDeathScene) +{ + Entity *e = entity(L); + luaReturnBool(e ? e->isDeathScene() : false); +} + luaFunc(entity_setCurrentTarget) { Entity *e = entity(L); @@ -6546,6 +6564,20 @@ luaFunc(entity_getNearestEntity) luaReturnPtr(closest); } +luaFunc(getNearestEntity) +{ + Vector p(lua_tonumber(L, 1), lua_tonumber(L, 2)); + int radius = lua_tointeger(L, 3); + Entity *ignore = lua_isuserdata(L, 4) ? entity(L, 4) : NULL; + EntityType et = lua_isnumber(L, 5) ? (EntityType)lua_tointeger(L, 5) : ET_NOTYPE; + DamageType dt = lua_isnumber(L, 6) ? (DamageType)lua_tointeger(L, 6) : DT_NONE; + int lrStart = lua_isnumber(L, 7) ? lua_tointeger(L, 7) : -1; + int lrEnd = lua_isnumber(L, 8) ? lua_tointeger(L, 8) : -1; + + Entity *target = dsq->game->getNearestEntity(p, radius, ignore, ET_ENEMY, dt, lrStart, lrEnd); + luaReturnPtr(target); +} + luaFunc(findWall) { int x = lua_tonumber(L, 1); @@ -7049,21 +7081,21 @@ luaFunc(getMouseWorldPos) luaFunc(fade) { - dsq->overlay->color = Vector(lua_tonumber(L, 3), lua_tonumber(L, 4), lua_tonumber(L, 5)); + dsq->overlay->color.interpolateTo(Vector(lua_tonumber(L, 3), lua_tonumber(L, 4), lua_tonumber(L, 5)), lua_tonumber(L, 6)); dsq->overlay->alpha.interpolateTo(lua_tonumber(L, 1), lua_tonumber(L, 2)); luaReturnNil(); } luaFunc(fade2) { - dsq->overlay2->color = Vector(lua_tonumber(L, 3), lua_tonumber(L, 4), lua_tonumber(L, 5)); + dsq->overlay2->color.interpolateTo(Vector(lua_tonumber(L, 3), lua_tonumber(L, 4), lua_tonumber(L, 5)), lua_tonumber(L, 6)); dsq->overlay2->alpha.interpolateTo(lua_tonumber(L, 1), lua_tonumber(L, 2)); luaReturnNil(); } luaFunc(fade3) { - dsq->overlay3->color = Vector(lua_tonumber(L, 3), lua_tonumber(L, 4), lua_tonumber(L, 5)); + dsq->overlay3->color.interpolateTo(Vector(lua_tonumber(L, 3), lua_tonumber(L, 4), lua_tonumber(L, 5)), lua_tonumber(L, 6)); dsq->overlay3->alpha.interpolateTo(lua_tonumber(L, 1), lua_tonumber(L, 2)); luaReturnNil(); } @@ -7557,6 +7589,7 @@ static const struct { luaRegister(entity_setBoneLock), luaRegister(entity_setIngredient), luaRegister(entity_setDeathScene), + luaRegister(entity_isDeathScene), luaRegister(entity_setBeautyFlip), luaRegister(entity_setInvincible), @@ -7708,6 +7741,7 @@ static const struct { luaRegister(entity_getVectorToEntity), luaRegister(entity_getDistanceToTarget), + luaRegister(entity_getDistanceToPoint), luaRegister(entity_move), luaRegister(entity_getID), @@ -8302,6 +8336,7 @@ static const struct { luaRegister(entity_getNearestEntity), luaRegister(entity_getNearestBoneToPosition), + luaRegister(getNearestEntity), luaRegister(entity_getNearestNode), luaRegister(entity_setPoison), From 405045b3fbe9553430ed068ebe74cdcdb648d5a3 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Mon, 22 Apr 2013 23:41:48 +0200 Subject: [PATCH 042/103] Do not collide shots with entity if shot->firer == entity. This check was already done if entity was ET_ENEMY, but it seems more correct to me to check this for all cases. Hope this doesn't break anything. --- Aquaria/Game.cpp | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/Aquaria/Game.cpp b/Aquaria/Game.cpp index cab97ab..bc20925 100644 --- a/Aquaria/Game.cpp +++ b/Aquaria/Game.cpp @@ -1233,6 +1233,8 @@ Game::Game() : StateObject() loadEntityTypeList(); + lastCollideMaskIndex = -1; + } @@ -8356,7 +8358,7 @@ void Game::registerSporeDrop(const Vector &pos, int t) bool Game::isEntityCollideWithShot(Entity *e, Shot *shot) { - if (!shot->isHitEnts()) + if (!shot->isHitEnts() || shot->firer == e) { return false; } @@ -8367,24 +8369,17 @@ bool Game::isEntityCollideWithShot(Entity *e, Shot *shot) } if (e->getEntityType() == ET_ENEMY) { - if (shot->firer != e) + if (shot->getDamageType() == DT_AVATAR_BITE) { - if (shot->getDamageType() == DT_AVATAR_BITE) + Avatar::BittenEntities::iterator i; + for (i = avatar->bittenEntities.begin(); i != avatar->bittenEntities.end(); i++) { - Avatar::BittenEntities::iterator i; - for (i = avatar->bittenEntities.begin(); i != avatar->bittenEntities.end(); i++) + if (e == (*i)) { - if (e == (*i)) - { - return false; - } + return false; } - return true; } - } - else - { - return false; + return true; } } else if (e->getEntityType() == ET_AVATAR) From 035ad963f5ab891fdb499358427ef70ca0064d34 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Tue, 23 Apr 2013 00:57:13 +0200 Subject: [PATCH 043/103] Add Lua func: avatar_isBlockSinging() --- Aquaria/ScriptInterface.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index f6e801e..9741251 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -2693,6 +2693,11 @@ luaFunc(avatar_setBlockSinging) luaReturnNil(); } +luaFunc(avatar_isBlockSinging) +{ + luaReturnBool(dsq->game->avatar->isBlockSinging()); +} + luaFunc(avatar_fallOffWall) { dsq->game->avatar->fallOffWall(); @@ -8049,6 +8054,7 @@ static const struct { luaRegister(avatar_fallOffWall), luaRegister(avatar_setBlockSinging), + luaRegister(avatar_isBlockSinging), luaRegister(avatar_toggleMovement), From 3ed40e73d3c102c148c708181b59de3a5fca3526 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Wed, 24 Apr 2013 04:51:26 +0200 Subject: [PATCH 044/103] Minor refactor & add Lua funcs: + avatar_setShieldActive() + entity_isFillGrid() * entity_setBoneLock() code made easier to read and not warn on no lock entity + entity_getMaxSpeedLerp() + entity_isEntityInside() --- Aquaria/Avatar.cpp | 29 +++++++++++++++++++++ Aquaria/Avatar.h | 2 ++ Aquaria/Continuity.cpp | 36 ++----------------------- Aquaria/DSQ.h | 1 - Aquaria/Entity.cpp | 11 ++++++++ Aquaria/Entity.h | 2 ++ Aquaria/ScriptInterface.cpp | 52 +++++++++++++++++++++++++++++++------ Aquaria/ScriptedEntity.cpp | 26 ------------------- Aquaria/ScriptedEntity.h | 1 - 9 files changed, 90 insertions(+), 70 deletions(-) diff --git a/Aquaria/Avatar.cpp b/Aquaria/Avatar.cpp index a4c030f..1b47b1b 100644 --- a/Aquaria/Avatar.cpp +++ b/Aquaria/Avatar.cpp @@ -4686,6 +4686,35 @@ void Avatar::action(int id, int state) } } +void Avatar::doBindSong() +{ + if (pullTarget) + { + pullTarget->stopPull(); + pullTarget = 0; + core->sound->playSfx("Denied"); + } + else + { + dsq->game->bindIngredients(); + setNearestPullTarget(); + if (!pullTarget) + { + core->sound->playSfx("Denied"); + } + else + { + core->sound->playSfx("Bind"); + } + } +} + +void Avatar::doShieldSong() +{ + core->sound->playSfx("Shield-On"); + activateAura(AURA_SHIELD); +} + void Avatar::render() { diff --git a/Aquaria/Avatar.h b/Aquaria/Avatar.h index 0b8a196..d3a787e 100644 --- a/Aquaria/Avatar.h +++ b/Aquaria/Avatar.h @@ -317,6 +317,8 @@ public: bool canSetBoneLock(); void revert(); + void doBindSong(); + void doShieldSong(); int leaches; diff --git a/Aquaria/Continuity.cpp b/Aquaria/Continuity.cpp index 063dd8a..31a6ac3 100644 --- a/Aquaria/Continuity.cpp +++ b/Aquaria/Continuity.cpp @@ -1347,16 +1347,6 @@ Song *Continuity::getSongByIndex(int idx) return &songBank[idx]; } -int Continuity::getSongBankSize() -{ - int c = 0; - for (SongMap::iterator i = songBank.begin(); i != songBank.end(); i++) - { - c++; - } - return c; -} - void Continuity::castSong(int num) { if (!dsq->continuity.hasSong((SongType)num)) return; @@ -1409,32 +1399,10 @@ void Continuity::castSong(int num) switch((SongType)num) { case SONG_SHIELDAURA: - core->sound->playSfx("Shield-On"); - dsq->game->avatar->activateAura(AURA_SHIELD); + dsq->game->avatar->doShieldSong(); break; case SONG_BIND: - //debugLog("sang pull"); - if (dsq->game->avatar->pullTarget) - { - dsq->game->avatar->pullTarget->stopPull(); - dsq->game->avatar->pullTarget = 0; - core->sound->playSfx("Denied"); - } - else - { - dsq->game->bindIngredients(); - dsq->game->avatar->setNearestPullTarget(); - if (!dsq->game->avatar->pullTarget) - { - core->sound->playSfx("Denied"); - } - else - { - core->sound->playSfx("Bind"); - } - } - //dsq->game->avatar->openPullTargetInterface(); - //pickingPullTarget = true; + dsq->game->avatar->doBindSong(); break; case SONG_ENERGYFORM: dsq->game->avatar->changeForm(FORM_ENERGY); diff --git a/Aquaria/DSQ.h b/Aquaria/DSQ.h index 5043f36..e24d4ff 100644 --- a/Aquaria/DSQ.h +++ b/Aquaria/DSQ.h @@ -996,7 +996,6 @@ public: FormUpgrades formUpgrades; void loadSongBank(); - int getSongBankSize(); void loadIntoSongBank(const std::string &file); int checkSong(const Song &song); int checkSongAssisted(const Song &song); diff --git a/Aquaria/Entity.cpp b/Aquaria/Entity.cpp index 8e7f027..f0c1e8f 100644 --- a/Aquaria/Entity.cpp +++ b/Aquaria/Entity.cpp @@ -3133,3 +3133,14 @@ void Entity::exertHairForce(const Vector &force, float dt) } } +bool Entity::isEntityInside() +{ + FOR_ENTITIES(i) + { + Entity *e = *i; + if (e && e->life == 1 && e != this && e->ridingOnEntity != this && isCoordinateInside(e->position)) + return true; + + } + return false; +} diff --git a/Aquaria/Entity.h b/Aquaria/Entity.h index 724aa64..d89154e 100644 --- a/Aquaria/Entity.h +++ b/Aquaria/Entity.h @@ -489,6 +489,8 @@ public: void setHairHeadPosition(const Vector &pos); void exertHairForce(const Vector &force, float dt); + bool isEntityInside(); + protected: bool calledEntityDied; Path *waterBubble; diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 9741251..a4e0753 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -2112,18 +2112,22 @@ luaFunc(entity_setRidingData) luaFunc(entity_setBoneLock) { Entity *e = entity(L); - Entity *e2 = entity(L, 2); - Bone *b = 0; - if (lua_isuserdata(L, 3)) - b = bone(L, 3); bool ret = false; if (e) { BoneLock bl; - bl.entity = e2; - bl.bone = b; - bl.on = true; - bl.collisionMaskIndex = dsq->game->lastCollideMaskIndex; + if (lua_isuserdata(L, 2)) + { + Entity *e2 = entity(L, 2); + Bone *b = 0; + if (lua_isuserdata(L, 3)) + b = bone(L, 3); + + bl.entity = e2; + bl.bone = b; + bl.on = true; + bl.collisionMaskIndex = dsq->game->lastCollideMaskIndex; + } ret = e->setBoneLock(bl); } luaReturnBool(ret); @@ -2553,6 +2557,12 @@ luaFunc(entity_setFillGrid) luaReturnNil(); } +luaFunc(entity_isFillGrid) +{ + Entity *e = entity(L); + luaReturnBool(e ? e->fillGridFromQuad : false); +} + luaFunc(entity_getAimVector) { Entity *e = entity(L); @@ -2731,6 +2741,16 @@ luaFunc(avatar_isShieldActive) luaReturnBool(v); } +luaFunc(avatar_setShieldActive) +{ + bool on = getBool(L, 1); + if (on) + dsq->game->avatar->activateAura(AURA_SHIELD); + else + dsq->game->avatar->stopAura(); + luaReturnNil(); +} + luaFunc(avatar_getStillTimer) { luaReturnNum(dsq->game->avatar->stillTimer.getValue()); @@ -5049,6 +5069,12 @@ luaFunc(entity_setMaxSpeedLerp) luaReturnNil(); } +luaFunc(entity_getMaxSpeedLerp) +{ + Entity *e = entity(L); + luaReturnNum(e ? e->maxSpeedLerp.x : 0.0f); +} + // note: this is a weaker setState than perform // this is so that things can override it // for example getting PUSH-ed (Force) or FROZEN (bubbled) @@ -6165,6 +6191,12 @@ luaFunc(entity_getDistanceToEntity) luaReturnNum(d); } +luaFunc(entity_isEntityInside) +{ + Entity *e = entity(L); + luaReturnBool(e ? e->isEntityInside() : false); +} + // entity_istargetInRange luaFunc(entity_isTargetInRange) { @@ -7844,6 +7876,7 @@ static const struct { luaRegister(entity_isTargetInRange), luaRegister(entity_getDistanceToEntity), + luaRegister(entity_isEntityInside), luaRegister(entity_isInvincible), @@ -7860,6 +7893,7 @@ static const struct { luaRegister(entity_setMaxSpeed), luaRegister(entity_getMaxSpeed), luaRegister(entity_setMaxSpeedLerp), + luaRegister(entity_getMaxSpeedLerp), luaRegister(entity_setState), luaRegister(entity_getState), luaRegister(entity_getEnqueuedState), @@ -8050,6 +8084,7 @@ static const struct { luaRegister(avatar_isRolling), luaRegister(avatar_isOnWall), luaRegister(avatar_isShieldActive), + luaRegister(avatar_setShieldActive), luaRegister(avatar_getRollDirection), luaRegister(avatar_fallOffWall), @@ -8278,6 +8313,7 @@ static const struct { luaRegister(entity_setTexture), luaRegister(entity_setFillGrid), + luaRegister(entity_isFillGrid), luaRegister(entity_push), diff --git a/Aquaria/ScriptedEntity.cpp b/Aquaria/ScriptedEntity.cpp index 67aa2a1..10f4c9e 100644 --- a/Aquaria/ScriptedEntity.cpp +++ b/Aquaria/ScriptedEntity.cpp @@ -759,32 +759,6 @@ void ScriptedEntity::songNoteDone(int note, float len) } } -bool ScriptedEntity::isEntityInside() -{ - bool v = false; - int avatars = 0; - FOR_ENTITIES(i) - { - Entity *e = *i; - if (e->getEntityType() == ET_AVATAR) - avatars ++; - if (e && e->life == 1 && e != this && e->ridingOnEntity != this) - { - if (isCoordinateInside(e->position)) - { - /* - Vector diff = (e->position - position); - diff.setLength2D(100); - e->vel += diff; - */ - v = true; - } - } - - } - return v; -} - void ScriptedEntity::becomeSolid() { //vel = 0; diff --git a/Aquaria/ScriptedEntity.h b/Aquaria/ScriptedEntity.h index 3c13dc7..f943f6a 100644 --- a/Aquaria/ScriptedEntity.h +++ b/Aquaria/ScriptedEntity.h @@ -68,7 +68,6 @@ public: typedef std::vector Strands; Strands strands; int strandSpacing; - bool isEntityInside(); void becomeSolid(); std::string deathParticleEffect; From 55ead19076abb29b7ed4222206b3fd41c164a60c Mon Sep 17 00:00:00 2001 From: fgenesis Date: Thu, 25 Apr 2013 02:51:54 +0200 Subject: [PATCH 045/103] Remove spirit form dependency on WorldType, and add related Lua interfaces. This commit introduces a second pause mode: Full game pause (as in menu), and world pause (as in spirit form). All related checks are no longer done against WT_* constants, but against the new world pause which is functionally equivalent, but more flexible. Continuity::worldType is now only used to toggle world pause correctly, and to apply some related graphical effects. The world pause can also be controlled via script without actually switching forms. Added Lua functions: + node_setSpiritFreeze() + quad_setPauseLevel() + isWorldPaused() + setWorldPaused() --- Aquaria/Avatar.cpp | 13 ++++--------- Aquaria/Avatar.h | 1 - Aquaria/Continuity.cpp | 8 +++++++- Aquaria/DSQ.cpp | 1 + Aquaria/Entity.cpp | 6 +++--- Aquaria/Game.cpp | 4 ++-- Aquaria/Game.h | 4 ++++ Aquaria/Ingredient.cpp | 2 +- Aquaria/Mod.cpp | 1 + Aquaria/Path.cpp | 13 ++++--------- Aquaria/Path.h | 1 + Aquaria/ScriptInterface.cpp | 33 +++++++++++++++++++++++++++++++++ Aquaria/Shot.cpp | 2 +- BBGE/Quad.cpp | 1 + BBGE/ScriptObject.cpp | 1 + BBGE/ScriptObject.h | 1 + 16 files changed, 65 insertions(+), 27 deletions(-) diff --git a/Aquaria/Avatar.cpp b/Aquaria/Avatar.cpp index 1b47b1b..4bfb56f 100644 --- a/Aquaria/Avatar.cpp +++ b/Aquaria/Avatar.cpp @@ -752,11 +752,6 @@ bool Avatar::isSinging() return singing; } -void Avatar::shift() -{ - dsq->continuity.shiftWorlds(); -} - void Avatar::applyWorldEffects(WorldType type) { static bool oldfh=false; @@ -5275,7 +5270,7 @@ void Avatar::updateWallJump(float dt) void Avatar::updateRoll(float dt) { - if (!inputEnabled || dsq->continuity.getWorldType() == WT_SPIRIT) + if (!inputEnabled || dsq->game->isWorldPaused()) { if (rolling) stopRoll(); @@ -6205,7 +6200,7 @@ void Avatar::onUpdate(float dt) //if (core->getNestedMains() == 1) { - if (getState() != STATE_TRANSFORM && dsq->continuity.getWorldType() == WT_NORMAL) + if (getState() != STATE_TRANSFORM && !dsq->game->isWorldPaused()) { formAbilityUpdate(dt); } @@ -6439,7 +6434,7 @@ void Avatar::onUpdate(float dt) } } - if (!state.lockedToWall && _isUnderWater && dsq->continuity.getWorldType() == WT_NORMAL && canMove) + if (!state.lockedToWall && _isUnderWater && !dsq->game->isWorldPaused() && canMove) { if (bursting) { @@ -7156,7 +7151,7 @@ void Avatar::onUpdate(float dt) if (dsq->game->collideCircleWithGrid(position, collideRadius)) { if (dsq->game->lastCollideTileType == OT_HURT - && dsq->continuity.getWorldType() != WT_SPIRIT + && !dsq->game->isWorldPaused() && dsq->continuity.form != FORM_NATURE) { DamageData d; diff --git a/Aquaria/Avatar.h b/Aquaria/Avatar.h index d3a787e..f7be754 100644 --- a/Aquaria/Avatar.h +++ b/Aquaria/Avatar.h @@ -160,7 +160,6 @@ public: Entity *entityToActivate; Path *pathToActivate; - void shift(); void applyWorldEffects(WorldType type); void toggleMovement(bool on); diff --git a/Aquaria/Continuity.cpp b/Aquaria/Continuity.cpp index 31a6ac3..8d58c58 100644 --- a/Aquaria/Continuity.cpp +++ b/Aquaria/Continuity.cpp @@ -1916,9 +1916,15 @@ void Continuity::shiftWorlds() { WorldType lastWorld = worldType; if (worldType == WT_NORMAL) + { worldType = WT_SPIRIT; + dsq->game->setWorldPaused(true); + } else if (worldType == WT_SPIRIT) + { worldType = WT_NORMAL; + dsq->game->setWorldPaused(false); + } FOR_ENTITIES(i) { Entity *e = *i; @@ -2018,7 +2024,7 @@ void Continuity::applyWorldEffects(WorldType type, bool transition, bool affectM dsq->game->avatar->enableInput(); */ } - worldType = type; + //worldType = type; } void Continuity::eatBeast(const EatData &eatData) diff --git a/Aquaria/DSQ.cpp b/Aquaria/DSQ.cpp index d58645f..6f0079e 100644 --- a/Aquaria/DSQ.cpp +++ b/Aquaria/DSQ.cpp @@ -4576,6 +4576,7 @@ void DSQ::onUpdate(float dt) os << "altState: " << core->getKeyState(KEY_LALT) << " | " << core->getKeyState(KEY_RALT) << std::endl; os << "PMFree: " << particleManager->getFree() << " Active: " << particleManager->getNumActive() << std::endl; os << "cameraPos: (" << dsq->cameraPos.x << ", " << dsq->cameraPos.y << ")" << std::endl; + os << "worldType: " << continuity.getWorldType() << " worldPaused: " << game->isWorldPaused() << std::endl; os << "voiceTime: " << dsq->sound->getVoiceTime() << " bNat: " << dsq->game->bNatural; int ca, ma; dsq->sound->getStats(&ca, &ma); diff --git a/Aquaria/Entity.cpp b/Aquaria/Entity.cpp index f0c1e8f..e4d464d 100644 --- a/Aquaria/Entity.cpp +++ b/Aquaria/Entity.cpp @@ -1142,9 +1142,9 @@ void Entity::update(float dt) if (doUpdate && !dsq->game->isPaused()) { - if (getEntityType() == ET_ENEMY || getEntityType() == ET_NEUTRAL || getEntityType() == ET_PET) + if (!(getEntityType() == ET_AVATAR || getEntityType() == ET_INGREDIENT)) { - if (spiritFreeze && dsq->continuity.getWorldType() == WT_SPIRIT) + if (spiritFreeze && dsq->game->isWorldPaused()) { // possible bug here because of return return; @@ -1382,7 +1382,7 @@ bool Entity::updateCurrents(float dt) // why? { //Path *p = dsq->game->getNearestPath(position, PATH_CURRENT); - if (dsq->continuity.getWorldType() != WT_SPIRIT) + if (!dsq->game->isWorldPaused()) { for (Path *p = dsq->game->getFirstPathOfType(PATH_CURRENT); p; p = p->nextOfType) { diff --git a/Aquaria/Game.cpp b/Aquaria/Game.cpp index bc20925..02bb0ef 100644 --- a/Aquaria/Game.cpp +++ b/Aquaria/Game.cpp @@ -1234,7 +1234,7 @@ Game::Game() : StateObject() loadEntityTypeList(); lastCollideMaskIndex = -1; - + worldPaused = false; } @@ -5719,7 +5719,7 @@ void Game::updateParticlePause() { core->particlesPaused = 2; } - else if (dsq->continuity.getWorldType() == WT_SPIRIT) + else if (this->isWorldPaused()) { core->particlesPaused = 1; } diff --git a/Aquaria/Game.h b/Aquaria/Game.h index 33a5bc6..125b13e 100644 --- a/Aquaria/Game.h +++ b/Aquaria/Game.h @@ -1001,6 +1001,9 @@ public: void toggleHelpScreen(bool on, const std::string &label=""); void onToggleHelpScreen(); + void setWorldPaused(bool b) { worldPaused = b; } + bool isWorldPaused() const { return worldPaused; } + protected: void onHelpUp(); @@ -1158,6 +1161,7 @@ protected: std::vector menu; Quad *menuBg, *menuBg2; bool paused; + bool worldPaused; Vector getClosestPointOnTriangle(Vector a, Vector b, Vector c, Vector p); Vector getClosestPointOnLine(Vector a, Vector b, Vector p); diff --git a/Aquaria/Ingredient.cpp b/Aquaria/Ingredient.cpp index d31d980..97b9e42 100644 --- a/Aquaria/Ingredient.cpp +++ b/Aquaria/Ingredient.cpp @@ -109,7 +109,7 @@ void Ingredient::eat(Entity *e) void Ingredient::onUpdate(float dt) { if (dsq->game->isPaused()) return; - if (dsq->continuity.getWorldType() == WT_SPIRIT) return; + if (dsq->game->isWorldPaused()) return; Vector lastPosition = position; Entity::onUpdate(dt); diff --git a/Aquaria/Mod.cpp b/Aquaria/Mod.cpp index 693b9f0..beac053 100644 --- a/Aquaria/Mod.cpp +++ b/Aquaria/Mod.cpp @@ -284,6 +284,7 @@ void Mod::stop() debugMenu = false; shuttingDown = false; dsq->scriptInterface.reset(); + dsq->game->setWorldPaused(false); } void Mod::update(float dt) diff --git a/Aquaria/Path.cpp b/Aquaria/Path.cpp index 41da549..400d4b4 100644 --- a/Aquaria/Path.cpp +++ b/Aquaria/Path.cpp @@ -53,12 +53,7 @@ Path::Path() spawnEnemyNumber = 0; spawnEnemyDistance = 0; warpType = 0; - /* - rect.x1 = -10; - rect.x2 = 20; - rect.y1 = -256; - rect.y2 = 256; - */ + spiritFreeze = true; } void Path::clampPosition(Vector *pos, int radius) @@ -484,7 +479,7 @@ void Path::init() void Path::update(float dt) { - if (!dsq->game->isPaused() && dsq->continuity.getWorldType() == WT_NORMAL) + if (!dsq->game->isPaused() && !(spiritFreeze && dsq->game->isWorldPaused())) { if (addEmitter && emitter) { @@ -523,7 +518,7 @@ void Path::update(float dt) { spawnedEntity = 0; } - if (pathType == PATH_CURRENT && dsq->continuity.getWorldType() == WT_NORMAL) + if (pathType == PATH_CURRENT && !dsq->game->isWorldPaused()) { animOffset -= currentMod*(dt/830); /* @@ -559,7 +554,7 @@ void Path::update(float dt) } } - if (pathType == PATH_STEAM && dsq->continuity.getWorldType() == WT_NORMAL && effectOn) + if (pathType == PATH_STEAM && !dsq->game->isWorldPaused() && effectOn) { animOffset -= 1000*0.00002f; diff --git a/Aquaria/Path.h b/Aquaria/Path.h index b3369a2..8087008 100644 --- a/Aquaria/Path.h +++ b/Aquaria/Path.h @@ -143,6 +143,7 @@ public: std::string gem; bool effectOn; + bool spiritFreeze; PathShape pathShape; diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index a4e0753..f6f9ed0 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -377,6 +377,7 @@ void compile_time_assertions() compile_assert(oo(Path) == oo(Quad)); compile_assert(oo(Path) == oo(Avatar)); compile_assert(oo(Path) == oo(BaseText)); + compile_assert(oo(Path) == oo(PauseQuad)); #undef oo } #endif @@ -2351,6 +2352,17 @@ luaFunc(getWorldType) luaReturnNum((int)dsq->continuity.getWorldType()); } +luaFunc(isWorldPaused) +{ + luaReturnBool(dsq->game->isWorldPaused()); +} + +luaFunc(setWorldPaused) +{ + dsq->game->setWorldPaused(getBool(L, 1)); + luaReturnNil(); +} + luaFunc(getNearestNodeByType) { int x = lua_tonumber(L, 1); @@ -2546,6 +2558,14 @@ luaFunc(entity_setSpiritFreeze) luaReturnNil(); } +luaFunc(node_setSpiritFreeze) +{ + Path *e = path(L); + if (e) + e->spiritFreeze = getBool(L,2); + luaReturnNil(); +} + luaFunc(entity_setFillGrid) { Entity *e = entity(L); @@ -4755,6 +4775,15 @@ luaFunc(createQuad) luaReturnPtr(q); } +luaFunc(quad_setPauseLevel) +{ + Quad *q = getQuad(L); + ENSURE_TYPE(q, SCO_PAUSEQUAD); + if (q) + ((PauseQuad*)q)->pauseLevel = lua_tointeger(L, 2); + luaReturnNil(); +} + luaFunc(setupEntity) { ScriptedEntity *se = scriptedEntity(L); @@ -7597,11 +7626,14 @@ static const struct { luaRegister(getNoteName), luaRegister(getWorldType), + luaRegister(setWorldPaused), + luaRegister(isWorldPaused), luaRegister(getWaterLevel), luaRegister(setWaterLevel), luaRegister(createQuad), + luaRegister(quad_setPauseLevel), luaRegister(setupEntity), luaRegister(setActivePet), @@ -7651,6 +7683,7 @@ static const struct { luaRegister(entity_setEatType), luaRegister(entity_setSpiritFreeze), + luaRegister(node_setSpiritFreeze), luaRegister(entity_setCanLeaveWater), diff --git a/Aquaria/Shot.cpp b/Aquaria/Shot.cpp index b52b762..98fac54 100644 --- a/Aquaria/Shot.cpp +++ b/Aquaria/Shot.cpp @@ -778,7 +778,7 @@ bool Shot::isObstructed(float dt) const void Shot::onUpdate(float dt) { if (dsq->game->isPaused()) return; - if (dsq->continuity.getWorldType() != WT_NORMAL) return; + if (dsq->game->isWorldPaused()) return; if (!shotData) return; diff --git a/BBGE/Quad.cpp b/BBGE/Quad.cpp index 5fa50ee..517125b 100644 --- a/BBGE/Quad.cpp +++ b/BBGE/Quad.cpp @@ -802,6 +802,7 @@ void Quad::onSetTexture() PauseQuad::PauseQuad() : Quad(), pauseLevel(0) { + addType(SCO_PAUSEQUAD); } void PauseQuad::onUpdate(float dt) diff --git a/BBGE/ScriptObject.cpp b/BBGE/ScriptObject.cpp index 452edbe..442797b 100644 --- a/BBGE/ScriptObject.cpp +++ b/BBGE/ScriptObject.cpp @@ -37,6 +37,7 @@ static const char *scriptObjTypeNames[] = /* (1 << 9) */ "Path/Node", /* (1 <<10) */ "Quad", /* (1 <<11) */ "Text", + /* (1 <<12) */ "PauseQuad", NULL }; diff --git a/BBGE/ScriptObject.h b/BBGE/ScriptObject.h index 08cd693..4c2ff20 100644 --- a/BBGE/ScriptObject.h +++ b/BBGE/ScriptObject.h @@ -39,6 +39,7 @@ enum ScriptObjectType SCO_PATH = 0x0200, SCO_QUAD = 0x0400, SCO_TEXT = 0x0800, + SCO_PAUSEQUAD = 0x1000, SCO_FORCE_32BIT = 0xFFFFFFFF }; From e8a7889f82e575ad4c5f76ab2e4078f9d343a820 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Fri, 26 Apr 2013 00:34:06 +0200 Subject: [PATCH 046/103] Decouple form specific effects from the actual form. Most hardcoded form == FORM_* checks all over the place have been replaced. Now, forms change certain avatar properties, which are in turn checked in the places that previously had these explicit form checks. This allows specifying functionality via scripting, for additional forms with new effects or a new combination of existing effects. OT_HURT now deals damage of type DT_WALLHURT, and by setting avatar->setDamageTarget(DT_WALLHURT, false) collision with walls can be made harmless (exactly as nature form used to be). Add related Lua functions: + setWorldType() - Change WT without actually switching to spirit form + setCanActivate() + avatar_setCanBurst() + avatar_canBurst() + avatar_setCanLockToWall() + avatar_canLockToWall() + avatar_setCanSwimAgainstCurrents() + avatar_canSwimAgainstCurrents() + getSceneColor() + DT_WALLHURT --- Aquaria/Avatar.cpp | 78 +++++++++++++++++-------------------- Aquaria/Avatar.h | 15 ++++++- Aquaria/Continuity.cpp | 2 +- Aquaria/DSQ.cpp | 4 ++ Aquaria/Entity.cpp | 4 +- Aquaria/Entity.h | 1 + Aquaria/ScriptInterface.cpp | 67 ++++++++++++++++++++++++++++++- 7 files changed, 124 insertions(+), 47 deletions(-) diff --git a/Aquaria/Avatar.cpp b/Aquaria/Avatar.cpp index 4bfb56f..7587178 100644 --- a/Aquaria/Avatar.cpp +++ b/Aquaria/Avatar.cpp @@ -744,7 +744,7 @@ void Avatar::toggleMovement(bool on) bool Avatar::isLockable() { - return (bursting || !_isUnderWater) && (boneLockDelay == 0) && (dsq->continuity.form != FORM_FISH); + return (bursting || !_isUnderWater) && (boneLockDelay == 0) && canLockToWall(); } bool Avatar::isSinging() @@ -1590,6 +1590,7 @@ void Avatar::changeForm(FormType form, bool effects, bool onInit, FormType lastF //rotationOffset.interpolateTo(Vector(0,0,0), 0.5); collideRadius = COLLIDE_RADIUS_NORMAL; + setCanLockToWall(true); } break; case FORM_SUN: @@ -1601,9 +1602,13 @@ void Avatar::changeForm(FormType form, bool effects, bool onInit, FormType lastF position = bodyPosition; dsq->continuity.warpLiToAvatar(); spiritBeaconEmitter.start(); + setCanActivateStuff(true); + setCanLockToWall(true); + setCanBurst(true); + setDamageTarget(DT_WALLHURT, true); break; case FORM_BEAST: - //dsq->game->sceneColor3.interpolateTo(Vector(1, 1, 1), 0.5); + setCanSwimAgainstCurrents(false); break; case FORM_DUAL: if (dsq->continuity.hasLi()) @@ -1613,6 +1618,9 @@ void Avatar::changeForm(FormType form, bool effects, bool onInit, FormType lastF dsq->game->li->setState(STATE_IDLE); } break; + case FORM_NATURE: + setDamageTarget(DT_WALLHURT, true); + break; default: if (leftHandEmitter && rightHandEmitter) { @@ -1722,6 +1730,7 @@ void Avatar::changeForm(FormType form, bool effects, bool onInit, FormType lastF //refreshModel("NaijaFish", ""); collideRadius = COLLIDE_RADIUS_FISH; + setCanLockToWall(false); } break; case FORM_SUN: @@ -1753,42 +1762,13 @@ void Avatar::changeForm(FormType form, bool effects, bool onInit, FormType lastF hair->setTexture("Naija/Cape-NatureForm"); hair->alphaMod = 1.0; } - /* - skeletalSprite.loadSkin("ChildTeira"); - refreshModel(); - */ - /* - if (dsq->game->sceneNatureForm == "forest") - { - debugLog("Forest Form"); - dsq->continuity.form = FORM_NATURE_FOREST; - } - else if (dsq->game->sceneNatureForm == "sun") - { - dsq->continuity.form = FORM_NATURE_SUN; - debugLog("Sun Form"); - } - else if (dsq->game->sceneNatureForm == "fire") - { - dsq->continuity.form = FORM_NATURE_FIRE; - debugLog("Fire Form"); - } - else if (dsq->game->sceneNatureForm == "dark") - { - dsq->continuity.form = FORM_NATURE_DARK; - debugLog("Dark Form"); - } - else if (dsq->game->sceneNatureForm == "rock" || dsq->game->sceneNatureForm.empty()) - { - dsq->continuity.form = FORM_NATURE_ROCK; - debugLog("Rock Form"); - } - */ + setDamageTarget(DT_WALLHURT, false); break; case FORM_BEAST: { refreshModel("Naija", "BeastForm"); + setCanSwimAgainstCurrents(true); } break; case FORM_SPIRIT: @@ -1796,6 +1776,10 @@ void Avatar::changeForm(FormType form, bool effects, bool onInit, FormType lastF bodyOffset = offset; fallOffWall(); dsq->continuity.shiftWorlds(); + setCanActivateStuff(false); + setCanLockToWall(false); + setCanBurst(false); + setDamageTarget(DT_WALLHURT, false); if (onInit) { @@ -3490,8 +3474,8 @@ void Avatar::lockToWallCommon() void Avatar::lockToWall() { if (riding) return; - if (inCurrent && dsq->continuity.form != FORM_BEAST) return; - if (dsq->continuity.form == FORM_FISH || dsq->continuity.form == FORM_SPIRIT) return; + if (inCurrent && !canSwimAgainstCurrents()) return; + if (!canLockToWall()) return; if (state.lockedToWall) return; if (vel.x == 0 && vel.y == 0) return; if (dsq->game->isPaused()) return; @@ -3589,7 +3573,7 @@ void Avatar::lockToWall() } } - if (dsq->game->getGrid(t)==OT_HURT && dsq->continuity.form != FORM_NATURE) + if (dsq->game->getGrid(t)==OT_HURT && isDamageTarget(DT_WALLHURT)) { good = false; } @@ -4123,6 +4107,12 @@ Avatar::Avatar() : Entity(), ActionMapper() collideRadius = COLLIDE_RADIUS_FISH; else collideRadius = COLLIDE_RADIUS_NORMAL; + + // defaults for normal form + _canActivateStuff = true; + _canBurst = true; + _canLockToWall = true; + _canSwimAgainstCurrents = false; } void Avatar::revert() @@ -4319,7 +4309,7 @@ void Avatar::startBurstCommon() void Avatar::startBurst() { - if (!riding && dsq->continuity.form != FORM_SPIRIT && (joystickMove || getVectorToCursor().getSquaredLength2D() > sqr(BURST_DISTANCE)) + if (!riding && canBurst() && (joystickMove || getVectorToCursor().getSquaredLength2D() > sqr(BURST_DISTANCE)) && getState() != STATE_PUSH && (!skeletalSprite.getCurrentAnimation() || (skeletalSprite.getCurrentAnimation()->name != "spin")) && _isUnderWater && !isActing(ACTION_ROLL)) { @@ -5409,7 +5399,12 @@ void Avatar::setWasUnderWater() bool Avatar::canActivateStuff() { - return dsq->continuity.form != FORM_SPIRIT; + return _canActivateStuff; +} + +void Avatar::setCanActivateStuff(bool on) +{ + _canActivateStuff = on; } bool Avatar::canQuickSong() @@ -7142,7 +7137,6 @@ void Avatar::onUpdate(float dt) else omov -= mov; - lastLastPosition = position; lastPosition = position; Vector newPosition = position + mov; //Vector testPosition = position + (vel *dt)*2; @@ -7151,11 +7145,11 @@ void Avatar::onUpdate(float dt) if (dsq->game->collideCircleWithGrid(position, collideRadius)) { if (dsq->game->lastCollideTileType == OT_HURT - && !dsq->game->isWorldPaused() - && dsq->continuity.form != FORM_NATURE) + && isDamageTarget(DT_WALLHURT)) { DamageData d; d.damage = 1; + d.damageType = DT_WALLHURT; damage(d); vel2 = Vector(0,0,0); //doCollisionAvoidance(1, 3, 1); @@ -7338,7 +7332,7 @@ void Avatar::checkNearWall() { t.x = oT.x + v.x*i; t.y = oT.y + v.y*i; - if (dsq->game->isObstructed(t) && dsq->game->getGrid(t) != OT_HURT) + if (dsq->game->isObstructed(t, ~OT_HURT)) { obs = true; break; diff --git a/Aquaria/Avatar.h b/Aquaria/Avatar.h index f7be754..d93c2e4 100644 --- a/Aquaria/Avatar.h +++ b/Aquaria/Avatar.h @@ -283,6 +283,7 @@ public: void endOfGameState(); bool canQuickSong(); bool canActivateStuff(); + void setCanActivateStuff(bool on); bool hasThingToActivate(); float biteTimer; @@ -319,6 +320,15 @@ public: void doBindSong(); void doShieldSong(); + bool canBurst() const { return _canBurst; } + void setCanBurst(bool b) { _canBurst = b; } + + bool canLockToWall() const { return _canLockToWall; } + void setCanLockToWall(bool b) { _canLockToWall = b; } + + bool canSwimAgainstCurrents() const { return _canSwimAgainstCurrents; } + void setCanSwimAgainstCurrents(bool b) { _canSwimAgainstCurrents = b; } + int leaches; protected: @@ -451,7 +461,10 @@ protected: void lockToWall(); void doShock(const std::string &shotName); - Vector lastLastPosition; + bool _canActivateStuff; + bool _canBurst; + bool _canLockToWall; + bool _canSwimAgainstCurrents; }; diff --git a/Aquaria/Continuity.cpp b/Aquaria/Continuity.cpp index 8d58c58..18ee693 100644 --- a/Aquaria/Continuity.cpp +++ b/Aquaria/Continuity.cpp @@ -2024,7 +2024,7 @@ void Continuity::applyWorldEffects(WorldType type, bool transition, bool affectM dsq->game->avatar->enableInput(); */ } - //worldType = type; + worldType = type; } void Continuity::eatBeast(const EatData &eatData) diff --git a/Aquaria/DSQ.cpp b/Aquaria/DSQ.cpp index 6f0079e..77343d0 100644 --- a/Aquaria/DSQ.cpp +++ b/Aquaria/DSQ.cpp @@ -4564,6 +4564,10 @@ void DSQ::onUpdate(float dt) os << " headRot: " << b->rotation.z; os << std::endl; os << "fh: " << dsq->game->avatar->isfh() << " fv: " << dsq->game->avatar->isfv() << std::endl; + os << "canActivate: " << dsq->game->avatar->canActivateStuff(); + os << " canBurst: " << dsq->game->avatar->canBurst(); + os << " canLTW: " << dsq->game->avatar->canLockToWall(); + os << " canSAC: " << dsq->game->avatar->canSwimAgainstCurrents() << std::endl; } // DO NOT CALL AVATAR-> beyond this point diff --git a/Aquaria/Entity.cpp b/Aquaria/Entity.cpp index e4d464d..67cfd20 100644 --- a/Aquaria/Entity.cpp +++ b/Aquaria/Entity.cpp @@ -1419,7 +1419,7 @@ bool Entity::updateCurrents(float dt) float useLen = len; if (useLen < 500) useLen = 500; - if (!(this->getEntityType() == ET_AVATAR && dsq->continuity.form == FORM_BEAST && dsq->game->avatar->bursting)) + if (!(this->getEntityType() == ET_AVATAR && dsq->game->avatar->canSwimAgainstCurrents() && dsq->game->avatar->bursting)) { doCollisionAvoidance(1, 4, 1, &vel2, useLen); } @@ -1439,7 +1439,7 @@ bool Entity::updateCurrents(float dt) } } } - if (this->getEntityType() == ET_AVATAR && dsq->continuity.form == FORM_BEAST) + if (this->getEntityType() == ET_AVATAR && dsq->game->avatar->canSwimAgainstCurrents()) { int cap = 100; if (!vel.isZero()) diff --git a/Aquaria/Entity.h b/Aquaria/Entity.h index d89154e..2cd38c6 100644 --- a/Aquaria/Entity.h +++ b/Aquaria/Entity.h @@ -123,6 +123,7 @@ enum DamageType DT_CRUSH = 1032, DT_SPIKES = 1033, DT_STEAM = 1034, + DT_WALLHURT = 1035, DT_REALMAX }; diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index f6f9ed0..3de9180 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -1580,6 +1580,7 @@ luaFunc(quad_setSegs) RO_FUNC(getter, prefix, disableMotionBlur ) \ RO_FUNC(getter, prefix, collideCircleVsLine) \ RO_FUNC(getter, prefix, collideCircleVsLineAngle) \ + RO_FUNC(getter, prefix, getVectorToObj ) \ MK_ALIAS(prefix, fh, flipHorizontal ) \ MK_ALIAS(prefix, fv, flipVertical ) @@ -2352,6 +2353,14 @@ luaFunc(getWorldType) luaReturnNum((int)dsq->continuity.getWorldType()); } +luaFunc(setWorldType) +{ + WorldType wt = (WorldType)lua_tointeger(L, 1); + bool trans = getBool(L, 2); + dsq->continuity.applyWorldEffects(wt, trans, 1); // last arg is not used + luaReturnNil(); +} + luaFunc(isWorldPaused) { luaReturnBool(dsq->game->isWorldPaused()); @@ -2709,6 +2718,47 @@ luaFunc(avatar_setCanDie) luaReturnNil(); } +// not naming this avatar_* because it rather belongs into the UI category... +luaFunc(setCanActivate) +{ + dsq->game->avatar->setCanActivateStuff(getBool(L, 1)); + luaReturnNil(); +} + +luaFunc(avatar_setCanBurst) +{ + dsq->game->avatar->setCanBurst(getBool(L, 1)); + luaReturnNil(); +} + +luaFunc(avatar_canBurst) +{ + luaReturnBool(dsq->game->avatar->canBurst()); +} + +luaFunc(avatar_setCanLockToWall) +{ + dsq->game->avatar->setCanBurst(getBool(L, 1)); + luaReturnNil(); +} + +luaFunc(avatar_canLockToWall) +{ + luaReturnBool(dsq->game->avatar->canBurst()); +} + +luaFunc(avatar_setCanSwimAgainstCurrents) +{ + dsq->game->avatar->setCanSwimAgainstCurrents(getBool(L, 1)); + luaReturnNil(); +} + +luaFunc(avatar_canSwimAgainstCurrents) +{ + luaReturnBool(dsq->game->avatar->canSwimAgainstCurrents()); +} + + luaFunc(avatar_toggleCape) { dsq->game->avatar->toggleCape(getBool(L,1)); @@ -3773,6 +3823,12 @@ luaFunc(setSceneColor) luaReturnNil(); } +luaFunc(getSceneColor) +{ + const Vector& c = dsq->game->sceneColor3; + luaReturnVec3(c.x, c.y, c.z); +} + luaFunc(setCameraLerpDelay) { dsq->game->cameraLerpDelay = lua_tonumber(L, 1); @@ -7626,6 +7682,7 @@ static const struct { luaRegister(getNoteName), luaRegister(getWorldType), + luaRegister(setWorldType), luaRegister(setWorldPaused), luaRegister(isWorldPaused), @@ -7704,9 +7761,16 @@ static const struct { luaRegister(avatar_setCanDie), + luaRegister(setCanActivate), luaRegister(avatar_toggleCape), luaRegister(avatar_setPullTarget), + luaRegister(avatar_setCanLockToWall), + luaRegister(avatar_canLockToWall), + luaRegister(avatar_setCanBurst), + luaRegister(avatar_canBurst), + luaRegister(avatar_setCanSwimAgainstCurrents), + luaRegister(avatar_canSwimAgainstCurrents), luaRegister(avatar_clampPosition), luaRegister(avatar_updatePosition), @@ -8318,7 +8382,7 @@ static const struct { luaRegister(setSceneColor), - + luaRegister(getSceneColor), luaRegister(entity_watchEntity), @@ -9129,6 +9193,7 @@ static const struct { luaConstant(DT_CRUSH), luaConstant(DT_SPIKES), luaConstant(DT_STEAM), + luaConstant(DT_WALLHURT), luaConstant(FRAME_TIME), From ec7dd94a1cfae1e61aabbf1af8c467a4acd678ee Mon Sep 17 00:00:00 2001 From: fgenesis Date: Fri, 26 Apr 2013 05:03:24 +0200 Subject: [PATCH 047/103] Forms decoupling #2. Added Lua functions: + avatar_setCanCollideWithShots() + avatar_canCollideWithShots() + avatar_setCollisionAvoidanceData() --- Aquaria/Avatar.cpp | 29 ++++++++++++++++++++++------- Aquaria/Avatar.h | 9 +++++++++ Aquaria/ScriptInterface.cpp | 20 ++++++++++++++++++++ 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/Aquaria/Avatar.cpp b/Aquaria/Avatar.cpp index 7587178..b14bcd4 100644 --- a/Aquaria/Avatar.cpp +++ b/Aquaria/Avatar.cpp @@ -120,6 +120,12 @@ const float NOTE_ACCEPT_ANGLE_OFFSET = 15; const int COLLIDE_RADIUS_NORMAL = 10; const int COLLIDE_RADIUS_FISH = 8; +const int COLLIDE_RANGE_NORMAL = 2; +const int COLLIDE_RANGE_FISH = 1; + +const float COLLIDE_MOD_NORMAL = 1.0f; +const float COLLIDE_MOD_FISH = 0.1f; + const int requiredDualFormCharge = 3; bool usingDigital = false; @@ -1591,6 +1597,7 @@ void Avatar::changeForm(FormType form, bool effects, bool onInit, FormType lastF collideRadius = COLLIDE_RADIUS_NORMAL; setCanLockToWall(true); + setCollisionAvoidanceData(COLLIDE_RANGE_NORMAL, COLLIDE_MOD_NORMAL); } break; case FORM_SUN: @@ -1731,6 +1738,7 @@ void Avatar::changeForm(FormType form, bool effects, bool onInit, FormType lastF collideRadius = COLLIDE_RADIUS_FISH; setCanLockToWall(false); + setCollisionAvoidanceData(COLLIDE_RANGE_FISH, COLLIDE_MOD_FISH); } break; case FORM_SUN: @@ -4113,6 +4121,10 @@ Avatar::Avatar() : Entity(), ActionMapper() _canBurst = true; _canLockToWall = true; _canSwimAgainstCurrents = false; + _canCollideWithShots = true; + + _collisionAvoidMod = COLLIDE_MOD_NORMAL; + _collisionAvoidRange = COLLIDE_RANGE_NORMAL; } void Avatar::revert() @@ -5407,6 +5419,12 @@ void Avatar::setCanActivateStuff(bool on) _canActivateStuff = on; } +void Avatar::setCollisionAvoidanceData(int range, float mod) +{ + _collisionAvoidRange = range; + _collisionAvoidMod = mod; +} + bool Avatar::canQuickSong() { return !isSinging() && !isEntityDead() && isInputEnabled() && quickSongCastDelay <= 0; @@ -7073,13 +7091,9 @@ void Avatar::onUpdate(float dt) } - if (!state.lockedToWall && !bursting && _isUnderWater && swimming && !isFollowingPath()) + if (!state.lockedToWall && !bursting && _isUnderWater && swimming && !isFollowingPath() && _collisionAvoidRange > 0) { - //debugLog("collision avoidance"); - if (dsq->continuity.form == FORM_FISH) - doCollisionAvoidance(dt, 1, 0.1, 0, 800, OT_HURT); - else - doCollisionAvoidance(dt, 2, 1.0, 0, 800, OT_HURT); + doCollisionAvoidance(dt, _collisionAvoidRange, _collisionAvoidMod, 0, 800, OT_HURT); } if (!game->isShuttingDownGameState()) @@ -7312,7 +7326,8 @@ void Avatar::onUpdate(float dt) rightHandEmitter->position = boneRightHand->getWorldCollidePosition(Vector(0,16)); } - dsq->game->handleShotCollisions(this, (activeAura == AURA_SHIELD)); + if(canCollideWithShots()) + dsq->game->handleShotCollisions(this, (activeAura == AURA_SHIELD)); } diff --git a/Aquaria/Avatar.h b/Aquaria/Avatar.h index d93c2e4..afad10d 100644 --- a/Aquaria/Avatar.h +++ b/Aquaria/Avatar.h @@ -329,6 +329,11 @@ public: bool canSwimAgainstCurrents() const { return _canSwimAgainstCurrents; } void setCanSwimAgainstCurrents(bool b) { _canSwimAgainstCurrents = b; } + bool canCollideWithShots() const { return _canCollideWithShots; } + void setCollideWithShots(bool b) { _canCollideWithShots = b; } + + void setCollisionAvoidanceData(int range, float mod); + int leaches; protected: @@ -465,6 +470,10 @@ protected: bool _canBurst; bool _canLockToWall; bool _canSwimAgainstCurrents; + bool _canCollideWithShots; + + int _collisionAvoidRange; + float _collisionAvoidMod; }; diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 3de9180..93d3c6c 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -2758,6 +2758,23 @@ luaFunc(avatar_canSwimAgainstCurrents) luaReturnBool(dsq->game->avatar->canSwimAgainstCurrents()); } +luaFunc(avatar_setCanCollideWithShots) +{ + dsq->game->avatar->setCollideWithShots(getBool(L, 1)); + luaReturnNil(); +} + +luaFunc(avatar_canCollideWithShots) +{ + luaReturnBool(dsq->game->avatar->canCollideWithShots()); +} + +luaFunc(avatar_setCollisionAvoidanceData) +{ + dsq->game->avatar->setCollisionAvoidanceData(lua_tointeger(L, 1), lua_tonumber(L, 2)); + luaReturnNil(); +} + luaFunc(avatar_toggleCape) { @@ -7771,6 +7788,9 @@ static const struct { luaRegister(avatar_canBurst), luaRegister(avatar_setCanSwimAgainstCurrents), luaRegister(avatar_canSwimAgainstCurrents), + luaRegister(avatar_setCanCollideWithShots), + luaRegister(avatar_canCollideWithShots), + luaRegister(avatar_setCollisionAvoidanceData), luaRegister(avatar_clampPosition), luaRegister(avatar_updatePosition), From a52b26c782a6b1407bfb2ea443858d70d1f660df Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sat, 27 Apr 2013 01:12:50 +0200 Subject: [PATCH 048/103] Forms decoupling #3. Added Lua functions: + setSeeMapMode() --- Aquaria/Avatar.cpp | 6 ++---- Aquaria/Avatar.h | 11 +++++++++++ Aquaria/MiniMapRender.cpp | 12 ++++++++++-- Aquaria/ScriptInterface.cpp | 11 ++++++++++- 4 files changed, 33 insertions(+), 7 deletions(-) diff --git a/Aquaria/Avatar.cpp b/Aquaria/Avatar.cpp index b14bcd4..dd2cb05 100644 --- a/Aquaria/Avatar.cpp +++ b/Aquaria/Avatar.cpp @@ -4125,6 +4125,8 @@ Avatar::Avatar() : Entity(), ActionMapper() _collisionAvoidMod = COLLIDE_MOD_NORMAL; _collisionAvoidRange = COLLIDE_RANGE_NORMAL; + + _seeMapMode = SEE_MAP_DEFAULT; } void Avatar::revert() @@ -4884,10 +4886,6 @@ void Avatar::clampVelocity() } } - - - - if (!inCurrent || (inCurrent && withCurrent)) { if (dsq->continuity.form == FORM_FISH) diff --git a/Aquaria/Avatar.h b/Aquaria/Avatar.h index afad10d..28ed710 100644 --- a/Aquaria/Avatar.h +++ b/Aquaria/Avatar.h @@ -66,6 +66,13 @@ enum AvatarAnimLayers ANIMLAYER_MAX }; +enum SeeMapMode +{ + SEE_MAP_NEVER = 0, + SEE_MAP_DEFAULT = 1, + SEE_MAP_ALWAYS = 2, +} + class SongIconParticle : public Quad { public: @@ -334,6 +341,9 @@ public: void setCollisionAvoidanceData(int range, float mod); + void setSeeMapMode(SeeMapMode mode) { _seeMapMode = mode; } + SeeMapMode getSeeMapMode() const { return _seeMapMode; } + int leaches; protected: @@ -471,6 +481,7 @@ protected: bool _canLockToWall; bool _canSwimAgainstCurrents; bool _canCollideWithShots; + SeeMapMode _seeMapMode; int _collisionAvoidRange; float _collisionAvoidMod; diff --git a/Aquaria/MiniMapRender.cpp b/Aquaria/MiniMapRender.cpp index 095db91..77e6668 100644 --- a/Aquaria/MiniMapRender.cpp +++ b/Aquaria/MiniMapRender.cpp @@ -258,11 +258,18 @@ void MiniMapRender::onUpdate(float dt) if (dsq->darkLayer.isUsed() && dsq->game->avatar) { - if (dsq->continuity.form != FORM_SUN && dsq->game->avatar->isInDarkness()) + const SeeMapMode mapmode = dsq->game->avatar->getSeeMapMode(); + + if(mapmode == SEE_MAP_ALWAYS) + radarHide = false; + else if(mapmode == SEE_MAP_NEVER) + radarHide = true; + else if (dsq->continuity.form != FORM_SUN && dsq->game->avatar->isInDarkness()) { radarHide = true; } - else + + if(!radarHide) { for (Path *p = dsq->game->getFirstPathOfType(PATH_RADARHIDE); p; p = p->nextOfType) { @@ -273,6 +280,7 @@ void MiniMapRender::onUpdate(float dt) } } } + float t = dt*2; if (radarHide) { diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 93d3c6c..e9506b7 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -2725,6 +2725,12 @@ luaFunc(setCanActivate) luaReturnNil(); } +luaFunc(setSeeMapMode) +{ + dsq->game->avatar->setSeeMapMode((SeeMapMode)lua_tointeger(L, 1)); + luaReturnNil(); +} + luaFunc(avatar_setCanBurst) { dsq->game->avatar->setCanBurst(getBool(L, 1)); @@ -2775,7 +2781,6 @@ luaFunc(avatar_setCollisionAvoidanceData) luaReturnNil(); } - luaFunc(avatar_toggleCape) { dsq->game->avatar->toggleCape(getBool(L,1)); @@ -9241,6 +9246,10 @@ static const struct { luaConstant(OT_INVISIBLEIN), luaConstant(OT_HURT), luaConstant(OT_INVISIBLEENT), + + luaConstant(SEE_MAP_NEVER), + luaConstant(SEE_MAP_DEFAULT), + luaConstant(SEE_MAP_ALWAYS), }; //============================================================================================ From 4c8fc05de8a5ec5182f1c1c7135f3c28975a46ad Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sun, 28 Apr 2013 22:33:59 +0200 Subject: [PATCH 049/103] Fix sound problems in energyboss and warning in predatorytunicate script. Thx Diablodoct0r for reporting the latter. --- game_scripts/scripts/entities/energyboss.lua | 12 ++++++------ game_scripts/scripts/entities/predatorytunicate.lua | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/game_scripts/scripts/entities/energyboss.lua b/game_scripts/scripts/entities/energyboss.lua index 519babe..d2a6b2f 100644 --- a/game_scripts/scripts/entities/energyboss.lua +++ b/game_scripts/scripts/entities/energyboss.lua @@ -367,7 +367,7 @@ function update(me, dt) end end if entity_isState(me, STATE_MOVING) and entity_x(me) >= node_x(v.maxMove) then - if entity_isInterpolating() then + if entity_isInterpolating(me) then entity_animate(me, "idle") end entity_stopInterpolating(me) @@ -400,7 +400,7 @@ function enterState(me) entity_stopInterpolating(me) entity_animate(me, "idle", LOOP_INF) elseif entity_isState(me, STATE_ATTACK) then - playSfx("EnergyBoss-Attack", 900+math.random(200)) + playSfx("EnergyBoss-Attack", (900+math.random(200)) / 1000) local x, y = bone_getPosition(v.bone_jaw) if entity_isPositionInRange(v.naija, x, y, 600) and entity_y(v.naija) < y+64 @@ -441,12 +441,12 @@ function enterState(me) end v.attackDelay = 0 v.fireDelay = 0 - playSfx("EnergyBoss-Hurt", 900+math.random(200)) + playSfx("EnergyBoss-Hurt", (900+math.random(200)) / 1000) entity_animate(me, "hurt") entity_setPosition(me, entity_x(me)-500, entity_y(me), 1.6) elseif entity_isState(me, STATE_HITBARRIER) then entity_stopInterpolating(me) - playSfx("EnergyBoss-Die", 1100+math.random(200)) + playSfx("EnergyBoss-Die", (1100+math.random(200)) / 1000) entity_animate(me, "hitBarrier") entity_spawnParticlesFromCollisionMask(me, "energyboss-hit", 4) @@ -459,7 +459,7 @@ function enterState(me) entity_setPosition(me, node_x(backNode), entity_y(me), -800) elseif entity_isState(me, STATE_COLLAPSE) then clearShots() - playSfx("EnergyBoss-Die", 1000) + playSfx("EnergyBoss-Die") setFlag(FLAG_ENERGYBOSSDEAD, 1) entity_setDamageTarget(me, DT_AVATAR_ENERGYBLAST, false) entity_setDamageTarget(me, DT_AVATAR_SHOCK, false) @@ -504,7 +504,7 @@ function enterState(me) --end elseif entity_isState(me, STATE_INTRO) then v.awoken = true - playSfx("EnergyBoss-Die", 800) + playSfx("EnergyBoss-Die", 0.8) shakeCamera(10, 3) entity_stopInterpolating(me) entity_animate(me, "roar") diff --git a/game_scripts/scripts/entities/predatorytunicate.lua b/game_scripts/scripts/entities/predatorytunicate.lua index 1960c0b..b6f6871 100644 --- a/game_scripts/scripts/entities/predatorytunicate.lua +++ b/game_scripts/scripts/entities/predatorytunicate.lua @@ -28,6 +28,7 @@ v.getOutHits = 0 v.hx = 0 v.hy = 0 v.hurtTimer = 0 +v.trapDelay = 0 local STATE_TRAP = 1001 local STATE_TRAPPED = 1002 From 7d158f5f1ceb49aa71a3970eef30d8e83c92feb3 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sun, 28 Apr 2013 22:44:28 +0200 Subject: [PATCH 050/103] Fix typos in a52b26c782a6 --- Aquaria/Avatar.h | 2 +- Aquaria/ScriptInterface.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Aquaria/Avatar.h b/Aquaria/Avatar.h index 28ed710..dea3095 100644 --- a/Aquaria/Avatar.h +++ b/Aquaria/Avatar.h @@ -71,7 +71,7 @@ enum SeeMapMode SEE_MAP_NEVER = 0, SEE_MAP_DEFAULT = 1, SEE_MAP_ALWAYS = 2, -} +}; class SongIconParticle : public Quad { diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index e9506b7..d6b4ca4 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -7784,6 +7784,7 @@ static const struct { luaRegister(avatar_setCanDie), luaRegister(setCanActivate), + luaRegister(setSeeMapMode), luaRegister(avatar_toggleCape), luaRegister(avatar_setPullTarget), From a6929c51f288415a527c1cf3c4ee478188ac514a Mon Sep 17 00:00:00 2001 From: fgenesis Date: Tue, 30 Apr 2013 00:50:45 +0200 Subject: [PATCH 051/103] Fix bug introduced in 0784d1b9dff. Thx Diablodoct0r for reporting. Not sure if bug was harmless, maybe... --- Aquaria/Shot.cpp | 8 +++++++- Aquaria/Shot.h | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Aquaria/Shot.cpp b/Aquaria/Shot.cpp index 98fac54..757b041 100644 --- a/Aquaria/Shot.cpp +++ b/Aquaria/Shot.cpp @@ -342,6 +342,7 @@ Shot::Shot() : Quad(), Segmented(0,0) fired = false; target = 0; dead = false; + enqueuedForDelete = false; shotIdx = shots.size(); shots.push_back(this); } @@ -487,7 +488,6 @@ void Shot::setLifeTime(float l) void Shot::onEndOfLife() { destroySegments(0.2); - deleteShots.push_back(this); dead = true; if (emitter) @@ -495,6 +495,12 @@ void Shot::onEndOfLife() emitter->killParticleEffect(); emitter = 0; } + + if (!enqueuedForDelete) + { + enqueuedForDelete = true; + deleteShots.push_back(this); + } } void Shot::doHitEffects() diff --git a/Aquaria/Shot.h b/Aquaria/Shot.h index 657a55c..3864dd2 100644 --- a/Aquaria/Shot.h +++ b/Aquaria/Shot.h @@ -128,7 +128,6 @@ public: protected: float waveTimer; - bool fired; void suicide(); @@ -141,6 +140,8 @@ protected: void onEndOfLife(); bool dead; + bool fired; + bool enqueuedForDelete; void onUpdate(float dt); private: From 811b015983df68ea785283956e728df72873e43d Mon Sep 17 00:00:00 2001 From: fgenesis Date: Thu, 2 May 2013 01:53:15 +0200 Subject: [PATCH 052/103] "Fix" warning in cc_sunkencity.lua Thx Diablodoct0r for reporting. --- game_scripts/scripts/entities/cc_sunkencity.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/game_scripts/scripts/entities/cc_sunkencity.lua b/game_scripts/scripts/entities/cc_sunkencity.lua index 264bfc9..d793215 100644 --- a/game_scripts/scripts/entities/cc_sunkencity.lua +++ b/game_scripts/scripts/entities/cc_sunkencity.lua @@ -220,7 +220,10 @@ function postInit(me) updateLocation(me) end +-- Both exist. Different spelling. Yay for consistency. +-- Keeping them both, should ensure behavior as it used to be, just without warnings. -- FG v.incutscene = false +v.inCutScene = false local function cutsceneintro(me, node) v.incutscene = true From 12ea97f051b01b4ec1b52afaf68fd642bd610b98 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Thu, 2 May 2013 04:31:07 +0200 Subject: [PATCH 053/103] Disable all glEnable/glDisable() calls for GL_CULL_FACE, except one glDisable() during renderer init. GL_CULL_FACE is effectively always disabled, except for quad strip rendering, and keeping GL_CULL_FACE disabled there does not seem to cause any visual artifacts. Instead, it enhances skeletal animation possibilities (e.g. flipping bone strips over without it disappearing) --- Aquaria/Beam.cpp | 2 +- Aquaria/CurrentRender.cpp | 4 ++-- Aquaria/Hair.cpp | 4 ++-- Aquaria/SteamRender.cpp | 4 ++-- Aquaria/Web.cpp | 2 +- Aquaria/WorldMapRender.cpp | 6 +++--- BBGE/Base.cpp | 4 ++-- BBGE/BitmapFont.cpp | 4 ++-- BBGE/Emitter.cpp | 2 +- BBGE/Quad.cpp | 4 ++-- BBGE/QuadTrail.cpp | 2 +- BBGE/RenderObject.cpp | 6 +++--- BBGE/RoundedRect.cpp | 4 ++-- 13 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Aquaria/Beam.cpp b/Aquaria/Beam.cpp index 003fc7b..00dd262 100644 --- a/Aquaria/Beam.cpp +++ b/Aquaria/Beam.cpp @@ -142,7 +142,7 @@ void Beam::render() void Beam::onRender() { #ifdef BBGE_BUILD_OPENGL - glDisable(GL_CULL_FACE); + //glDisable(GL_CULL_FACE); Vector diff = endPos - position; Vector side = diff; //side.normalize2D(); diff --git a/Aquaria/CurrentRender.cpp b/Aquaria/CurrentRender.cpp index 7118480..fd40034 100644 --- a/Aquaria/CurrentRender.cpp +++ b/Aquaria/CurrentRender.cpp @@ -62,7 +62,7 @@ void CurrentRender::onRender() { #ifdef BBGE_BUILD_OPENGL // note: Leave cull_face disabled!? - glDisable(GL_CULL_FACE); + //glDisable(GL_CULL_FACE); //int qs = 0; for (Path *p = dsq->game->getFirstPathOfType(PATH_CURRENT); p; p = p->nextOfType) { @@ -308,7 +308,7 @@ void CurrentRender::onRender() //glEnd(); } - glEnable(GL_CULL_FACE); + //glEnable(GL_CULL_FACE); /* std::ostringstream os; diff --git a/Aquaria/Hair.cpp b/Aquaria/Hair.cpp index 69200da..80cc0f0 100644 --- a/Aquaria/Hair.cpp +++ b/Aquaria/Hair.cpp @@ -130,7 +130,7 @@ HairNode *Hair::getHairNode(int idx) void Hair::onRender() { #ifdef BBGE_BUILD_OPENGL - glDisable(GL_CULL_FACE); + //glDisable(GL_CULL_FACE); glBegin(GL_QUAD_STRIP); float texBits = 1.0f / (hairNodes.size()-1); @@ -192,7 +192,7 @@ void Hair::onRender() } */ - glEnable(GL_CULL_FACE); + //glEnable(GL_CULL_FACE); #endif } diff --git a/Aquaria/SteamRender.cpp b/Aquaria/SteamRender.cpp index a6a5281..6502670 100644 --- a/Aquaria/SteamRender.cpp +++ b/Aquaria/SteamRender.cpp @@ -41,7 +41,7 @@ void SteamRender::onUpdate(float dt) void SteamRender::onRender() { #ifdef BBGE_BUILD_OPENGL - glDisable(GL_CULL_FACE); + //glDisable(GL_CULL_FACE); //int qs = 0; for (Path *p = dsq->game->getFirstPathOfType(PATH_STEAM); p; p = p->nextOfType) @@ -121,7 +121,7 @@ void SteamRender::onRender() } } - glEnable(GL_CULL_FACE); + //glEnable(GL_CULL_FACE); #endif } diff --git a/Aquaria/Web.cpp b/Aquaria/Web.cpp index 262df92..1e25a31 100644 --- a/Aquaria/Web.cpp +++ b/Aquaria/Web.cpp @@ -150,7 +150,7 @@ void Web::onRender() //glDisable(GL_BLEND); glLineWidth(4); - glDisable(GL_CULL_FACE); + //glDisable(GL_CULL_FACE); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBegin(GL_LINES); diff --git a/Aquaria/WorldMapRender.cpp b/Aquaria/WorldMapRender.cpp index e9f1b9f..add5195 100644 --- a/Aquaria/WorldMapRender.cpp +++ b/Aquaria/WorldMapRender.cpp @@ -266,9 +266,9 @@ protected: q->setBlendType(BLEND_ADD); addChild(q, PM_POINTER); - std::ostringstream os; - os << "children: " << children.size(); - debugLog(os.str()); + //std::ostringstream os; + //os << "children: " << children.size(); + //debugLog(os.str()); } else { diff --git a/BBGE/Base.cpp b/BBGE/Base.cpp index ebaa09c..6feee42 100644 --- a/BBGE/Base.cpp +++ b/BBGE/Base.cpp @@ -301,7 +301,7 @@ bool exists(const std::string &f, bool makeFatal, bool skipVFS) void drawCircle(float radius, int stepSize) { #ifdef BBGE_BUILD_OPENGL - glDisable(GL_CULL_FACE); + //glDisable(GL_CULL_FACE); glBegin(GL_POLYGON); { @@ -312,7 +312,7 @@ void drawCircle(float radius, int stepSize) } glEnd(); - glEnable(GL_CULL_FACE); + //glEnable(GL_CULL_FACE); #endif } diff --git a/BBGE/BitmapFont.cpp b/BBGE/BitmapFont.cpp index dca022e..9bf0fc2 100644 --- a/BBGE/BitmapFont.cpp +++ b/BBGE/BitmapFont.cpp @@ -317,7 +317,7 @@ void BitmapText::onRender() glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); */ - glDisable(GL_CULL_FACE); + //glDisable(GL_CULL_FACE); //glScalef(1, -1, 0); @@ -374,7 +374,7 @@ void BitmapText::onRender() } } - glEnable(GL_CULL_FACE); + //glEnable(GL_CULL_FACE); glBindTexture(GL_TEXTURE_2D, 0); #endif diff --git a/BBGE/Emitter.cpp b/BBGE/Emitter.cpp index d92a57a..31c693e 100644 --- a/BBGE/Emitter.cpp +++ b/BBGE/Emitter.cpp @@ -306,7 +306,7 @@ void Emitter::onRender() if (data.flipH || (data.copyParentFlip && (pe->isfh() || (pe->getParent() && pe->getParent()->isfh())))) { - glDisable(GL_CULL_FACE); + //glDisable(GL_CULL_FACE); glRotatef(180, 0, 1, 0); } diff --git a/BBGE/Quad.cpp b/BBGE/Quad.cpp index 517125b..fdcfa38 100644 --- a/BBGE/Quad.cpp +++ b/BBGE/Quad.cpp @@ -499,7 +499,7 @@ void Quad::onRender() if (!strip.empty()) { //glDisable(GL_BLEND);gggg - glDisable(GL_CULL_FACE); + //glDisable(GL_CULL_FACE); const float texBits = 1.0f / (strip.size()-1); @@ -517,7 +517,7 @@ void Quad::onRender() } glEnd(); - glEnable(GL_CULL_FACE); + //glEnable(GL_CULL_FACE); glBindTexture( GL_TEXTURE_2D, 0 ); glColor4f(1,0,0,1); glPointSize(64); diff --git a/BBGE/QuadTrail.cpp b/BBGE/QuadTrail.cpp index 3a2ecd8..a299b4e 100644 --- a/BBGE/QuadTrail.cpp +++ b/BBGE/QuadTrail.cpp @@ -59,7 +59,7 @@ void QuadTrail::onRender() if (numPoints < 2) return; #ifdef BBGE_BUILD_OPENGL - glDisable(GL_CULL_FACE); + //glDisable(GL_CULL_FACE); int c = 0; Vector p, diff, dl, dr; Vector lastPoint; diff --git a/BBGE/RenderObject.cpp b/BBGE/RenderObject.cpp index 032c4c8..69b5e6d 100644 --- a/BBGE/RenderObject.cpp +++ b/BBGE/RenderObject.cpp @@ -629,7 +629,7 @@ void RenderObject::renderCall() glTranslatef(position.x, position.y, position.z); if (isfh()) { - glDisable(GL_CULL_FACE); + //glDisable(GL_CULL_FACE); glRotatef(180, 0, 1, 0); } @@ -655,7 +655,7 @@ void RenderObject::renderCall() glTranslatef(pos.x, pos.y, pos.z); if (isfh()) { - glDisable(GL_CULL_FACE); + //glDisable(GL_CULL_FACE); glRotatef(180, 0, 1, 0); } glRotatef(rotation.z+rotationOffset.z, 0, 0, 1); @@ -714,7 +714,7 @@ void RenderObject::renderCall() glRotatef(rotation.z+rotationOffset.z, 0, 0, 1); if (isfh()) { - glDisable(GL_CULL_FACE); + //glDisable(GL_CULL_FACE); glRotatef(180, 0, 1, 0); } #endif diff --git a/BBGE/RoundedRect.cpp b/BBGE/RoundedRect.cpp index 1657159..4eb86dc 100644 --- a/BBGE/RoundedRect.cpp +++ b/BBGE/RoundedRect.cpp @@ -105,7 +105,7 @@ void RoundedRect::onRender() //glBindTexture(GL_TEXTURE_2D, 0); int w2 = width/2; int h2 = height/2; - glDisable(GL_CULL_FACE); + //glDisable(GL_CULL_FACE); float iter = 0.1f; glBegin(GL_QUADS); @@ -167,7 +167,7 @@ void RoundedRect::onRender() glEnd(); - glEnable(GL_CULL_FACE); + //glEnable(GL_CULL_FACE); } void RoundedRect::show() From 45821d15ffc30432248d8b6b1bdd50d256c6652b Mon Sep 17 00:00:00 2001 From: fgenesis Date: Thu, 2 May 2013 23:30:06 +0200 Subject: [PATCH 054/103] Fix regression from 7ff0caaed8. This fixes a glitch in the final boss' last form. Due to a missing Beam::trace() call, the beam's angle was not updated, and it always pointed into the upper left corner. --- Aquaria/ScriptInterface.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index d6b4ca4..d101194 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -3758,6 +3758,19 @@ luaFunc(beam_setFirer) luaReturnNil(); } +// Note the additional trace() call +luaFunc(beam_setPosition_override) +{ + Beam *b = beam(L); + if (b) + { + b->position.interpolateTo(Vector(lua_tonumber(L, 2), lua_tonumber(L, 3)), + lua_tonumber(L, 4), lua_tonumber(L, 5), lua_tonumber(L, 6), lua_tonumber(L, 7)); + b->trace(); + } + luaReturnNil(); +} + luaFunc(getStringBank) { luaReturnStr(dsq->continuity.stringBank.get(lua_tointeger(L, 1)).c_str()); @@ -8566,6 +8579,7 @@ static const struct { {"bone_getPosition", l_bone_getWorldPosition}, { "entity_delete", l_entity_delete_override }, { "entity_setRenderPass", l_entity_setRenderPass_override }, + { "beam_setPosition", l_beam_setPosition_override }, // -- deprecated/compatibility related functions below here -- From 02f18daed5ad81a31d5d606be6077301300494dd Mon Sep 17 00:00:00 2001 From: fgenesis Date: Thu, 2 May 2013 23:30:06 +0200 Subject: [PATCH 055/103] Fix regression from 7ff0caaed8. This fixes a glitch in the final boss' last form. Due to a missing Beam::trace() call, the beam's angle was not updated, and it always pointed into the upper left corner. --- Aquaria/ScriptInterface.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 5ea30bc..0714f94 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -3641,6 +3641,19 @@ luaFunc(beam_setFirer) luaReturnNil(); } +// Note the additional trace() call +luaFunc(beam_setPosition_override) +{ + Beam *b = beam(L); + if (b) + { + b->position.interpolateTo(Vector(lua_tonumber(L, 2), lua_tonumber(L, 3)), + lua_tonumber(L, 4), lua_tonumber(L, 5), lua_tonumber(L, 6), lua_tonumber(L, 7)); + b->trace(); + } + luaReturnNil(); +} + luaFunc(getStringBank) { luaReturnStr(dsq->continuity.stringBank.get(lua_tointeger(L, 1)).c_str()); @@ -8366,6 +8379,7 @@ static const struct { {"bone_getPosition", l_bone_getWorldPosition}, { "entity_delete", l_entity_delete_override }, { "entity_setRenderPass", l_entity_setRenderPass_override }, + { "beam_setPosition", l_beam_setPosition_override }, // -- deprecated/compatibility related functions below here -- From c62d9f2370b2a12713ecb5beedbdb54405eeaad7 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Fri, 10 May 2013 22:22:35 +0200 Subject: [PATCH 056/103] Re-introduce AfterEffect shader functonality, part 1. This repairs pixel/vertex shader code that was seemingly experimented with during testing, but it was never used and no shaders ever made it to the data files. --- Aquaria/DSQ.cpp | 4 +- Aquaria/Entity.cpp | 23 +-- Aquaria/Entity.h | 4 +- Aquaria/Game.cpp | 4 +- Aquaria/Game.h | 3 +- BBGE/BBGECompileConfig.h | 2 +- BBGE/Shader.cpp | 408 ++++++++++++++++++--------------------- BBGE/Shader.h | 24 +-- 8 files changed, 216 insertions(+), 256 deletions(-) diff --git a/Aquaria/DSQ.cpp b/Aquaria/DSQ.cpp index 77343d0..99427b2 100644 --- a/Aquaria/DSQ.cpp +++ b/Aquaria/DSQ.cpp @@ -1532,10 +1532,10 @@ This build is not yet final, and as such there are a couple things lacking. They renderObjectLayerOrder[LR_ENTITIES_MINUS3] = -1; renderObjectLayerOrder[LR_ENTITIES_MINUS2] = -1; - if (!Entity::blurShader.isLoaded()) + /*if (!Entity::blurShader.isLoaded()) { //Entity::blurShader.load("data/shaders/stan.vert", "data/shaders/hoblur.frag"); - } + }*/ setMousePosition(core->center); diff --git a/Aquaria/Entity.cpp b/Aquaria/Entity.cpp index 67cfd20..e394019 100644 --- a/Aquaria/Entity.cpp +++ b/Aquaria/Entity.cpp @@ -27,7 +27,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "ScriptedEntity.h" #include "Shot.h" -Shader Entity::blurShader; +//Shader Entity::blurShader; void Entity::stopPull() { @@ -1080,7 +1080,7 @@ void Entity::onFHScale() copySkel.alpha.interpolateTo(0, 0.5); */ //skeletalSprite.alpha.interpolateTo(1,sct); - blurShaderAnim.interpolateTo(Vector(blurMin,0,0), sct); + //blurShaderAnim.interpolateTo(Vector(blurMin,0,0), sct); fhScale = 0; } @@ -1105,8 +1105,8 @@ void Entity::onFH() flipScale.interpolateTo(Vector(0.6, 1), sct); - blurShaderAnim = Vector(blurMin); - blurShaderAnim.interpolateTo(Vector(blurMax,0,0), sct/2); + //blurShaderAnim = Vector(blurMin); + //blurShaderAnim.interpolateTo(Vector(blurMax,0,0), sct/2); fhScale = 1; } @@ -1681,7 +1681,7 @@ void Entity::onUpdate(float dt) break; } - blurShaderAnim.update(dt); + //blurShaderAnim.update(dt); } @@ -2832,23 +2832,18 @@ void Entity::render() // HACK: need to multiply base + etc skeletalSprite.setColorMult(this->color, this->alpha.x); - bool set=false; + /*bool set=false; if (beautyFlip && blurShader.isLoaded() && flipScale.isInterpolating() && dsq->user.video.blur) { - /* - std::ostringstream os; - os << "blurShaderAnim: " << blurShaderAnim.x; - debugLog(os.str()); - */ //swizzle blurShader.setValue(color.x, color.y, color.z, blurShaderAnim.x); blurShader.bind(); set = true; - } + }*/ Quad::render(); //if (beautyFlip && blurShader.isLoaded() && flipScale.isInterpolating()) - if (set) - blurShader.unbind(); + //if (set) + // blurShader.unbind(); renderBorder = false; skeletalSprite.clearColorMult(); color = bcolor; diff --git a/Aquaria/Entity.h b/Aquaria/Entity.h index 2cd38c6..70c7a51 100644 --- a/Aquaria/Entity.h +++ b/Aquaria/Entity.h @@ -452,7 +452,7 @@ public: //bool registerEntityDied; bool clampToSurface(int tcheck=0, Vector usePos=Vector(0,0), TileVector hitTile=TileVector(0,0)); bool checkSurface(int tcheck, int state, float statet); - static Shader blurShader; + //static Shader blurShader; std::string naijaReaction; Vector lookAtPoint; Vector getLookAtPoint(); @@ -518,7 +518,7 @@ protected: int lance; Bone *lanceBone; void updateLance(float dt); - InterpolatedVector blurShaderAnim; + //InterpolatedVector blurShaderAnim; int fhScale, fvScale; diff --git a/Aquaria/Game.cpp b/Aquaria/Game.cpp index 02bb0ef..733399b 100644 --- a/Aquaria/Game.cpp +++ b/Aquaria/Game.cpp @@ -9972,7 +9972,7 @@ void Game::update(float dt) if (avatar) { - tintColor.update(dt); + /*tintColor.update(dt); if (core->afterEffectManager) { if (tintColor.isInterpolating()) @@ -9981,7 +9981,7 @@ void Game::update(float dt) core->afterEffectManager->setActiveShader(AS_NONE); core->afterEffectManager->glowShader.setValue(tintColor.x, tintColor.y, tintColor.z, 1); - } + }*/ if (avatar->isRolling()) particleManager->addInfluence(ParticleInfluence(avatar->position, 300, 800, true)); diff --git a/Aquaria/Game.h b/Aquaria/Game.h index 125b13e..d9c103e 100644 --- a/Aquaria/Game.h +++ b/Aquaria/Game.h @@ -892,7 +892,8 @@ public: std::string getNoteName(int n, const std::string &pre=""); void selectEntityFromGroups(); - InterpolatedVector cameraInterp, tintColor; + InterpolatedVector cameraInterp; + //InterpolatedVector tintColor; float getWaterLevel(); void setMusicToPlay(const std::string &musicToPlay); Vector lastCollidePosition; diff --git a/BBGE/BBGECompileConfig.h b/BBGE/BBGECompileConfig.h index 762a1c6..125b5bf 100644 --- a/BBGE/BBGECompileConfig.h +++ b/BBGE/BBGECompileConfig.h @@ -5,7 +5,7 @@ #define BBGE_BUILD_SDL 1 #define BBGE_BUILD_FRAMEBUFFER 1 -//#define BBGE_BUILD_SHADERS 1 +#define BBGE_BUILD_SHADERS 1 #define BBGE_BUILD_OPENGL 1 #define BBGE_BUILD_OPENGL_DYNAMIC 1 #define BBGE_BUILD_FMOD_OPENAL_BRIDGE 1 diff --git a/BBGE/Shader.cpp b/BBGE/Shader.cpp index 90c7c5e..99a2e7c 100644 --- a/BBGE/Shader.cpp +++ b/BBGE/Shader.cpp @@ -18,10 +18,8 @@ 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. */ + #include "Shader.h" -#ifdef BBGE_BUILD_WINDOWS - #include -#endif #ifdef BBGE_BUILD_SHADERS // GL_ARB_shader_objects @@ -38,6 +36,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB = NULL; PFNGLUNIFORM4FARBPROC glUniform4fARB = NULL; PFNGLUNIFORM1IARBPROC glUniform1iARB = NULL; + PFNGLUNIFORM1FARBPROC glUniform1fARB = NULL; #endif bool Shader::_wasInited = false; @@ -73,22 +72,6 @@ void Shader::staticInit() } else { -#ifdef BBGE_BUILD_GLFW - glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC)glfwGetProcAddress("glCreateProgramObjectARB"); - glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC)glfwGetProcAddress("glDeleteObjectARB"); - glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC)glfwGetProcAddress("glUseProgramObjectARB"); - glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC)glfwGetProcAddress("glCreateShaderObjectARB"); - glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC)glfwGetProcAddress("glShaderSourceARB"); - glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC)glfwGetProcAddress("glCompileShaderARB"); - glGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC)glfwGetProcAddress("glGetObjectParameterivARB"); - glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC)glfwGetProcAddress("glAttachObjectARB"); - glGetInfoLogARB = (PFNGLGETINFOLOGARBPROC)glfwGetProcAddress("glGetInfoLogARB"); - glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC)glfwGetProcAddress("glLinkProgramARB"); - glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC)glfwGetProcAddress("glGetUniformLocationARB"); - glUniform4fARB = (PFNGLUNIFORM4FARBPROC)glfwGetProcAddress("glUniform4fARB"); - glUniform1iARB = (PFNGLUNIFORM1IARBPROC)glfwGetProcAddress("glUniform1iARB"); -#endif - #ifdef BBGE_BUILD_SDL glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC)SDL_GL_GetProcAddress("glCreateProgramObjectARB"); glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC)SDL_GL_GetProcAddress("glDeleteObjectARB"); @@ -103,13 +86,14 @@ void Shader::staticInit() glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC)SDL_GL_GetProcAddress("glGetUniformLocationARB"); glUniform4fARB = (PFNGLUNIFORM4FARBPROC)SDL_GL_GetProcAddress("glUniform4fARB"); glUniform1iARB = (PFNGLUNIFORM1IARBPROC)SDL_GL_GetProcAddress("glUniform1iARB"); + glUniform1fARB = (PFNGLUNIFORM1FARBPROC)SDL_GL_GetProcAddress("glUniform1fARB"); #endif if( !glCreateProgramObjectARB || !glDeleteObjectARB || !glUseProgramObjectARB || !glCreateShaderObjectARB || !glCreateShaderObjectARB || !glCompileShaderARB || !glGetObjectParameterivARB || !glAttachObjectARB || !glGetInfoLogARB || !glLinkProgramARB || !glGetUniformLocationARB || !glUniform4fARB || - !glUniform1iARB ) + !glUniform1iARB || !glUniform1fARB ) { glCreateProgramObjectARB = 0; debugLog("One or more GL_ARB_shader_objects functions were not found"); @@ -132,88 +116,32 @@ end: Shader::Shader() { - loaded = false; - mode = 0; #ifdef BBGE_BUILD_OPENGL - g_vertexShader = 0; - g_fragmentShader = 0; g_programObj = 0; - vx = vy = vz = vw = 0; - g_location_texture = 0; - g_location_mode = 0; - g_location_value = 0; #endif } Shader::~Shader() +{ + unload(); +} + +void Shader::unload() { #ifdef BBGE_BUILD_SHADERS if (!_useShaders) return; - if (g_vertexShader) - glDeleteObjectARB( g_vertexShader ); - if (g_fragmentShader) - glDeleteObjectARB( g_fragmentShader ); if (g_programObj) + { glDeleteObjectARB( g_programObj ); + g_programObj = 0; + } #endif } bool Shader::isLoaded() { - return loaded; -} - -void Shader::setMode(int mode) -{ - this->mode = mode; -} - -void Shader::setValue(float x, float y, float z, float w) -{ - vx = x; - vy = y; - vz = z; - vw = w; -} - -unsigned char *readShaderFile( const char *fileName ) -{ - debugLog("readShaderFile()"); -#ifdef BBGE_BUILD_WINDOWS - FILE *file = fopen( fileName, "r" ); // FIXME: should this code ever be re-activated, adjust to VFS! -- fg - - if( file == NULL ) - { - errorLog("Cannot open shader file!"); - return 0; - } - - struct _stat fileStats; - - if( _stat( fileName, &fileStats ) != 0 ) - { - errorLog("Cannot get file stats for shader file!"); - return 0; - } - - - unsigned char *buffer = new unsigned char[fileStats.st_size]; - - int bytes = fread( buffer, 1, fileStats.st_size, file ); - - buffer[bytes] = 0; - - fclose( file ); - - debugLog("End readShaderFile()"); - - return buffer; - -#else - debugLog("End readShaderFile()"); - return 0; -#endif + return g_programObj != 0; } void Shader::reload() @@ -226,13 +154,7 @@ void Shader::bind() #ifdef BBGE_BUILD_SHADERS if (!_useShaders) return; - glUseProgramObjectARB( g_programObj ); - if( g_location_texture != -1 ) - glUniform1iARB( g_location_texture, 0 ); - if ( g_location_mode ) - glUniform1iARB( g_location_mode, mode); - if ( g_location_value ) - glUniform4fARB( g_location_value, vx, vy, vz, vw); + glUseProgramObjectARB(g_programObj); #endif } @@ -241,150 +163,190 @@ void Shader::unbind() #ifdef BBGE_BUILD_SHADERS if (!_useShaders) return; - glUseProgramObjectARB( NULL ); + glUseProgramObjectARB(0); #endif } +unsigned int Shader::_compileShader(int type, const char *src, char *errbuf, size_t errbufsize) +{ +#ifdef BBGE_BUILD_SHADERS + GLint compiled = 0; + GLhandleARB handle = glCreateShaderObjectARB(type); + + glShaderSourceARB( handle, 1, &src, NULL ); + glCompileShaderARB( handle); + + glGetObjectParameterivARB(handle, GL_OBJECT_COMPILE_STATUS_ARB, &compiled); + glGetInfoLogARB(handle, errbufsize, NULL, errbuf); + if(!compiled) + { + glDeleteObjectARB(handle); + handle = 0; + } + GLint err = glGetError(); + if(err != GL_NO_ERROR) + { + std::ostringstream os; + os << "Shader::_compileShader: Unexpected error " << err; + errorLog(os.str()); + } + return handle; +#endif + return 0; +} + void Shader::load(const std::string &file, const std::string &fragFile) { staticInit(); - loaded = false; - -#ifdef BBGE_BUILD_SHADERS if(!_useShaders) return; debugLog("Shader::load("+file+", "+fragFile+")"); - g_location_texture = 0; - g_location_mode = 0; - g_location_value = 0; + this->vertFile = file; + this->fragFile = fragFile; - try - { + char *vertCode = file.length() ? readFile(file) : NULL; + char *fragCode = fragFile.length() ? readFile(fragFile) : NULL; - debugLog("Shader::load 1"); - this->vertFile = file; - this->fragFile = fragFile; - // - // If the required extension is present, get the addresses of its - // functions that we wish to use... - // + loadSrc(vertCode, fragCode); - const char *vertexShaderStrings[1]; - const char *fragmentShaderStrings[1]; - GLint bVertCompiled; - GLint bFragCompiled; - GLint bLinked; - char str[4096]; - - // - // Create the vertex shader... - // - - debugLog("Shader::load 2"); - - g_vertexShader = glCreateShaderObjectARB( GL_VERTEX_SHADER_ARB ); - - unsigned char *vertexShaderAssembly = readShaderFile( file.c_str() ); - vertexShaderStrings[0] = (char*)vertexShaderAssembly; - glShaderSourceARB( g_vertexShader, 1, vertexShaderStrings, NULL ); - glCompileShaderARB( g_vertexShader); - delete[] vertexShaderAssembly; - - glGetObjectParameterivARB( g_vertexShader, GL_OBJECT_COMPILE_STATUS_ARB, - &bVertCompiled ); - if( bVertCompiled == false ) - //if (true) - { - glGetInfoLogARB(g_vertexShader, sizeof(str), NULL, str); - std::ostringstream os; - os << "Vertex Shader Compile Error: " << str; - debugLog(os.str()); - return; - } - - // - // Create the fragment shader... - // - - debugLog("Shader::load 3"); - - g_fragmentShader = glCreateShaderObjectARB( GL_FRAGMENT_SHADER_ARB ); - - unsigned char *fragmentShaderAssembly = readShaderFile( fragFile.c_str() ); - fragmentShaderStrings[0] = (char*)fragmentShaderAssembly; - glShaderSourceARB( g_fragmentShader, 1, fragmentShaderStrings, NULL ); - glCompileShaderARB( g_fragmentShader ); - delete[] fragmentShaderAssembly; - - glGetObjectParameterivARB( g_fragmentShader, GL_OBJECT_COMPILE_STATUS_ARB, - &bFragCompiled ); - if( bFragCompiled == false ) - { - glGetInfoLogARB( g_fragmentShader, sizeof(str), NULL, str ); - std::ostringstream os; - os << "Fragment Shader Compile Error: " << str; - debugLog(os.str()); - return; - } - - debugLog("Shader::load 4"); - - // - // Create a program object and attach the two compiled shaders... - // - - - g_programObj = glCreateProgramObjectARB(); - - if (!g_programObj || !g_vertexShader || !g_fragmentShader) - { - debugLog("programObj / vertexShader / fragmentShader problem"); - return; - } - - glAttachObjectARB( g_programObj, g_vertexShader ); - glAttachObjectARB( g_programObj, g_fragmentShader ); - - // - // Link the program object and print out the info log... - // - - glLinkProgramARB( g_programObj ); - glGetObjectParameterivARB( g_programObj, GL_OBJECT_LINK_STATUS_ARB, &bLinked ); - - debugLog("Shader::load 5"); - - if( bLinked == false ) - { - glGetInfoLogARB( g_programObj, sizeof(str), NULL, str ); - std::ostringstream os; - os << "Shader Linking Error: " << str; - debugLog(os.str()); - return; - } - - // - // Locate some parameters by name so we can set them later... - // - - debugLog("Shader::load 6"); - - g_location_texture = glGetUniformLocationARB( g_programObj, "tex" ); - g_location_mode = glGetUniformLocationARB( g_programObj, "mode" ); - g_location_value = glGetUniformLocationARB( g_programObj, "value" ); - - debugLog("Shader::load 7"); - - loaded = true; - } - catch(...) - { - debugLog("caught exception in shader::load"); - loaded = false; - } -#endif - debugLog("End Shader::load()"); + delete [] vertCode; + delete [] fragCode; } +void Shader::loadSrc(const char *vertCode, const char *fragCode) +{ + unload(); + + if(!_useShaders) + return; + +#ifdef BBGE_BUILD_SHADERS + + char str[4096]; + + GLhandleARB vertexShader = 0; + GLhandleARB fragmentShader = 0; + + // + // Create the vertex shader... + // + if(vertCode && !(vertexShader = _compileShader(GL_VERTEX_SHADER_ARB, vertCode, str, sizeof(str)))) + { + std::ostringstream os; + os << "Vertex Shader Compile Error [" << vertFile << "]:\n" << str; + errorLog(os.str()); + return; + } + + // + // Create the fragment shader... + // + if(fragCode && !(fragmentShader = _compileShader(GL_FRAGMENT_SHADER_ARB, fragCode, str, sizeof(str)))) + { + std::ostringstream os; + os << "Fragment Shader Compile Error [" << fragFile << "]:\n" << str; + errorLog(os.str()); + return; + } + + // + // Create a program object and attach the two compiled shaders... + // + + g_programObj = glCreateProgramObjectARB(); + + if (!(g_programObj && (vertexShader || fragmentShader))) + { + errorLog("programObj / vertexShader / fragmentShader problem"); + unload(); + return; + } + + // + // Link the program object and print out the info log... + // + if(vertexShader) + glAttachObjectARB( g_programObj, vertexShader ); + if(fragmentShader) + glAttachObjectARB( g_programObj, fragmentShader ); + + glLinkProgramARB( g_programObj ); + + // Shader objects will be deleted as soon as the program object is deleted + if(vertexShader) + glDeleteObjectARB(vertexShader); + if(fragmentShader) + glDeleteObjectARB(fragmentShader); + + GLint bLinked; + glGetObjectParameterivARB( g_programObj, GL_OBJECT_LINK_STATUS_ARB, &bLinked ); + + + if(!bLinked) + { + glGetInfoLogARB( g_programObj, sizeof(str), NULL, str ); + std::ostringstream os; + os << "Shader Linking Error: " << str; + errorLog(os.str()); + unload(); + return; + } + +#endif +} + +// TODO: I'm not quite sure but i bet this sucks. +// Design a good caching policy and simplify the implementation, +// but keep shader dynamism and shaders generated at runtime in mind. +// No idea if and how much runtime performance it costs +// to query the uniform locations everytime. +// -- FG + +static void shaderUniformError(const char *func, const char *var) +{ + GLint err = glGetError(); + /*std::ostringstream os; + os << "Shader::" << func << "(" << var << ") -- undef uniform (Error: " << err << ")"; + debugLog(os.str());*/ +} + +void Shader::setInt(const char *name, int x) +{ +#if BBGE_BUILD_SHADERS + if(!g_programObj) + return; + GLint loc = glGetUniformLocationARB(g_programObj, name); + if(loc != -1) + glUniform1iARB(loc, x); + else + shaderUniformError("setInt", name); +#endif +} + +void Shader::setFloat(const char *name, float x) +{ +#if BBGE_BUILD_SHADERS + if(!g_programObj) + return; + GLint loc = glGetUniformLocationARB(g_programObj, name); + if(loc != -1) + glUniform1fARB(loc, x); + else + shaderUniformError("setFloat", name); +#endif +} + +void Shader::setFloat4(const char *name, float x, float y, float z, float w) +{ +#if BBGE_BUILD_SHADERS + if(!g_programObj) + return; + GLint loc = glGetUniformLocationARB(g_programObj, name); + if(loc != -1) + glUniform4fARB(loc, x, y, z, w); + else + shaderUniformError("setFloat4", name); +#endif +} diff --git a/BBGE/Shader.h b/BBGE/Shader.h index 1eb4cd9..0586272 100644 --- a/BBGE/Shader.h +++ b/BBGE/Shader.h @@ -30,28 +30,30 @@ public: ~Shader(); bool isLoaded(); void load(const std::string &file, const std::string &fragFile); + void loadSrc(const char *vertCode, const char *fragCode); void reload(); + void unload(); void bind(); void unbind(); - void setMode(int mode); - void setValue(float x, float y, float z, float w); - std::string vertFile, fragFile; + + // TODO: design a good API for this... + void setInt(const char *name, int x); + void setFloat(const char *name, float x); + void setFloat4(const char *name, float x, float y, float z, float w); + + protected: + std::string vertFile, fragFile; #ifdef BBGE_BUILD_OPENGL GLuint g_programObj; - GLuint g_vertexShader; - GLuint g_fragmentShader; - GLuint g_location_texture; - GLuint g_location_mode; - GLuint g_location_value; #endif - int mode; - float vx, vy, vz, vw; - bool loaded; +private: static void staticInit(); static bool _wasInited; static bool _useShaders; + + static unsigned int _compileShader(int type, const char *src, char *errbuf, size_t errbufsize); }; #endif From 2ac3ad9fb1ff005cf6b48023e3d0238d3d9cae5f Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sun, 12 May 2013 00:05:57 +0200 Subject: [PATCH 057/103] Fixes & enhancements to shader interface code --- BBGE/ScriptObject.cpp | 1 + BBGE/ScriptObject.h | 1 + BBGE/Shader.cpp | 193 ++++++++++++++++++++++++++++---------- BBGE/Shader.h | 48 ++++++++-- ExternalLibs/algorithmx.h | 34 +++++++ 5 files changed, 221 insertions(+), 56 deletions(-) create mode 100644 ExternalLibs/algorithmx.h diff --git a/BBGE/ScriptObject.cpp b/BBGE/ScriptObject.cpp index 442797b..60b5d01 100644 --- a/BBGE/ScriptObject.cpp +++ b/BBGE/ScriptObject.cpp @@ -38,6 +38,7 @@ static const char *scriptObjTypeNames[] = /* (1 <<10) */ "Quad", /* (1 <<11) */ "Text", /* (1 <<12) */ "PauseQuad", + /* (1 <<13) */ "Shader", NULL }; diff --git a/BBGE/ScriptObject.h b/BBGE/ScriptObject.h index 4c2ff20..a6bbb0a 100644 --- a/BBGE/ScriptObject.h +++ b/BBGE/ScriptObject.h @@ -40,6 +40,7 @@ enum ScriptObjectType SCO_QUAD = 0x0400, SCO_TEXT = 0x0800, SCO_PAUSEQUAD = 0x1000, + SCO_SHADER = 0x2000, SCO_FORCE_32BIT = 0xFFFFFFFF }; diff --git a/BBGE/Shader.cpp b/BBGE/Shader.cpp index 99a2e7c..1c8f4a8 100644 --- a/BBGE/Shader.cpp +++ b/BBGE/Shader.cpp @@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "Shader.h" +#include "algorithmx.h" #ifdef BBGE_BUILD_SHADERS // GL_ARB_shader_objects @@ -34,9 +35,16 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. PFNGLGETINFOLOGARBPROC glGetInfoLogARB = NULL; PFNGLLINKPROGRAMARBPROC glLinkProgramARB = NULL; PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB = NULL; - PFNGLUNIFORM4FARBPROC glUniform4fARB = NULL; - PFNGLUNIFORM1IARBPROC glUniform1iARB = NULL; - PFNGLUNIFORM1FARBPROC glUniform1fARB = NULL; + PFNGLGETACTIVEUNIFORMARBPROC glGetActiveUniformARB = NULL; + PFNGLUNIFORM1FVARBPROC glUniform1fvARB = NULL; + PFNGLUNIFORM2FVARBPROC glUniform2fvARB = NULL; + PFNGLUNIFORM3FVARBPROC glUniform3fvARB = NULL; + PFNGLUNIFORM4FVARBPROC glUniform4fvARB = NULL; + PFNGLUNIFORM1IVARBPROC glUniform1ivARB = NULL; + PFNGLUNIFORM2IVARBPROC glUniform2ivARB = NULL; + PFNGLUNIFORM3IVARBPROC glUniform3ivARB = NULL; + PFNGLUNIFORM4IVARBPROC glUniform4ivARB = NULL; + #endif bool Shader::_wasInited = false; @@ -84,16 +92,23 @@ void Shader::staticInit() glGetInfoLogARB = (PFNGLGETINFOLOGARBPROC)SDL_GL_GetProcAddress("glGetInfoLogARB"); glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC)SDL_GL_GetProcAddress("glLinkProgramARB"); glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC)SDL_GL_GetProcAddress("glGetUniformLocationARB"); - glUniform4fARB = (PFNGLUNIFORM4FARBPROC)SDL_GL_GetProcAddress("glUniform4fARB"); - glUniform1iARB = (PFNGLUNIFORM1IARBPROC)SDL_GL_GetProcAddress("glUniform1iARB"); - glUniform1fARB = (PFNGLUNIFORM1FARBPROC)SDL_GL_GetProcAddress("glUniform1fARB"); + glGetActiveUniformARB = (PFNGLGETACTIVEUNIFORMARBPROC)SDL_GL_GetProcAddress("glGetActiveUniformARB"); + glUniform1fvARB = (PFNGLUNIFORM1FVARBPROC)SDL_GL_GetProcAddress("glUniform1fvARB"); + glUniform2fvARB = (PFNGLUNIFORM2FVARBPROC)SDL_GL_GetProcAddress("glUniform2fvARB"); + glUniform3fvARB = (PFNGLUNIFORM3FVARBPROC)SDL_GL_GetProcAddress("glUniform3fvARB"); + glUniform4fvARB = (PFNGLUNIFORM4FVARBPROC)SDL_GL_GetProcAddress("glUniform4fvARB"); + glUniform1ivARB = (PFNGLUNIFORM1IVARBPROC)SDL_GL_GetProcAddress("glUniform1ivARB"); + glUniform2ivARB = (PFNGLUNIFORM2IVARBPROC)SDL_GL_GetProcAddress("glUniform2ivARB"); + glUniform3ivARB = (PFNGLUNIFORM3IVARBPROC)SDL_GL_GetProcAddress("glUniform3ivARB"); + glUniform4ivARB = (PFNGLUNIFORM4IVARBPROC)SDL_GL_GetProcAddress("glUniform4ivARB"); #endif if( !glCreateProgramObjectARB || !glDeleteObjectARB || !glUseProgramObjectARB || !glCreateShaderObjectARB || !glCreateShaderObjectARB || !glCompileShaderARB || !glGetObjectParameterivARB || !glAttachObjectARB || !glGetInfoLogARB || - !glLinkProgramARB || !glGetUniformLocationARB || !glUniform4fARB || - !glUniform1iARB || !glUniform1fARB ) + !glLinkProgramARB || !glGetUniformLocationARB || !glGetActiveUniformARB || + !glUniform1fvARB || !glUniform2fvARB || !glUniform3fvARB || !glUniform4fvARB || + !glUniform1ivARB || !glUniform2ivARB || !glUniform3ivARB || !glUniform4ivARB) { glCreateProgramObjectARB = 0; debugLog("One or more GL_ARB_shader_objects functions were not found"); @@ -116,6 +131,10 @@ end: Shader::Shader() { + addType(SCO_SHADER); + numUniforms = -1; + uniformsDirty = false; + #ifdef BBGE_BUILD_OPENGL g_programObj = 0; #endif @@ -139,7 +158,7 @@ void Shader::unload() #endif } -bool Shader::isLoaded() +bool Shader::isLoaded() const { return g_programObj != 0; } @@ -155,6 +174,7 @@ void Shader::bind() if (!_useShaders) return; glUseProgramObjectARB(g_programObj); + _flushUniforms(); #endif } @@ -217,6 +237,7 @@ void Shader::load(const std::string &file, const std::string &fragFile) void Shader::loadSrc(const char *vertCode, const char *fragCode) { + staticInit(); unload(); if(!_useShaders) @@ -232,7 +253,7 @@ void Shader::loadSrc(const char *vertCode, const char *fragCode) // // Create the vertex shader... // - if(vertCode && !(vertexShader = _compileShader(GL_VERTEX_SHADER_ARB, vertCode, str, sizeof(str)))) + if(vertCode && *vertCode && !(vertexShader = _compileShader(GL_VERTEX_SHADER_ARB, vertCode, str, sizeof(str)))) { std::ostringstream os; os << "Vertex Shader Compile Error [" << vertFile << "]:\n" << str; @@ -243,7 +264,7 @@ void Shader::loadSrc(const char *vertCode, const char *fragCode) // // Create the fragment shader... // - if(fragCode && !(fragmentShader = _compileShader(GL_FRAGMENT_SHADER_ARB, fragCode, str, sizeof(str)))) + if(fragCode && *fragCode && !(fragmentShader = _compileShader(GL_FRAGMENT_SHADER_ARB, fragCode, str, sizeof(str)))) { std::ostringstream os; os << "Fragment Shader Compile Error [" << fragFile << "]:\n" << str; @@ -294,59 +315,131 @@ void Shader::loadSrc(const char *vertCode, const char *fragCode) return; } + _queryUniforms(); + #endif } -// TODO: I'm not quite sure but i bet this sucks. -// Design a good caching policy and simplify the implementation, -// but keep shader dynamism and shaders generated at runtime in mind. -// No idea if and how much runtime performance it costs -// to query the uniform locations everytime. -// -- FG - -static void shaderUniformError(const char *func, const char *var) +void Shader::_setUniform(Uniform *u) { - GLint err = glGetError(); - /*std::ostringstream os; - os << "Shader::" << func << "(" << var << ") -- undef uniform (Error: " << err << ")"; - debugLog(os.str());*/ + /*if(u->location == -1) + { + u->location = glGetUniformLocationARB(g_programObj, u->name); + if(u->location == -1) + { + u->dirty = false; + return; + } + }*/ + switch(u->type) + { + case GL_FLOAT: glUniform1fvARB(u->location, 1, u->data.f); break; + case GL_FLOAT_VEC2_ARB: glUniform2fvARB(u->location, 1, u->data.f); break; + case GL_FLOAT_VEC3_ARB: glUniform3fvARB(u->location, 1, u->data.f); break; + case GL_FLOAT_VEC4_ARB: glUniform4fvARB(u->location, 1, u->data.f); break; + case GL_INT: glUniform1ivARB(u->location, 1, u->data.i); break; + case GL_INT_VEC2_ARB: glUniform2ivARB(u->location, 1, u->data.i); break; + case GL_INT_VEC3_ARB: glUniform3ivARB(u->location, 1, u->data.i); break; + case GL_INT_VEC4_ARB: glUniform4ivARB(u->location, 1, u->data.i); break; + } + u->dirty = false; } -void Shader::setInt(const char *name, int x) +void Shader::_flushUniforms() +{ + if(!uniformsDirty) + return; + uniformsDirty = false; + + for(size_t i = 0; i < uniforms.size(); ++i) + { + Uniform &u = uniforms[i]; + if(u.dirty) + _setUniform(&u); + } +} + +// for sorting +bool Shader::_sortUniform(const Uniform& a, const char *bname) +{ + return strcmp(a.name, bname) < 0; +} + +bool Shader::Uniform::operator< (const Uniform& b) const +{ + return Shader::_sortUniform(*this, &b.name[0]); +} + +void Shader::_queryUniforms() +{ + glGetObjectParameterivARB(g_programObj, GL_OBJECT_ACTIVE_UNIFORMS_ARB , &numUniforms); + + if (numUniforms <= 0) + return; + + uniforms.reserve(numUniforms); + + for (unsigned int i = 0; i < numUniforms; ++i) + { + Uniform u; + GLint size = 0; + GLenum type = 0; + glGetActiveUniformARB(g_programObj, i, sizeof(u.name), NULL, &size, &type, &u.name[0]); + if(!type || !size) + continue; + u.location = glGetUniformLocationARB(g_programObj, u.name); + if(u.location == -1) + continue; + u.dirty = false; + u.type = type; + memset(&u.data, 0, sizeof(u.data)); + + uniforms.push_back(u); + } + + // sort to be able to do binary search later + std::sort(uniforms.begin(), uniforms.end()); +} + +int Shader::_getUniformIndex(const char *name) +{ + // binary search + UniformVec::iterator it = stdx_fg::lower_bound(uniforms.begin(), uniforms.end(), name, _sortUniform); + return int(it - uniforms.begin()); +} + +void Shader::setInt(const char *name, int x, int y /* = 0 */, int z /* = 0 */, int w /* = 0 */) { #if BBGE_BUILD_SHADERS - if(!g_programObj) + if(!g_programObj || numUniforms <= 0) return; - GLint loc = glGetUniformLocationARB(g_programObj, name); - if(loc != -1) - glUniform1iARB(loc, x); - else - shaderUniformError("setInt", name); + int idx = _getUniformIndex(name); + if(unsigned(idx) >= uniforms.size()) + return; + Uniform& u = uniforms[idx]; + u.data.i[0] = x; + u.data.i[1] = y; + u.data.i[2] = z; + u.data.i[3] = w; + u.dirty = true; + uniformsDirty = true; #endif } -void Shader::setFloat(const char *name, float x) +void Shader::setFloat(const char *name, float x, float y /* = 0 */, float z /* = 0 */, float w /* = 0 */) { #if BBGE_BUILD_SHADERS - if(!g_programObj) + if(!g_programObj || numUniforms <= 0) return; - GLint loc = glGetUniformLocationARB(g_programObj, name); - if(loc != -1) - glUniform1fARB(loc, x); - else - shaderUniformError("setFloat", name); -#endif -} - -void Shader::setFloat4(const char *name, float x, float y, float z, float w) -{ -#if BBGE_BUILD_SHADERS - if(!g_programObj) - return; - GLint loc = glGetUniformLocationARB(g_programObj, name); - if(loc != -1) - glUniform4fARB(loc, x, y, z, w); - else - shaderUniformError("setFloat4", name); + int idx = _getUniformIndex(name); + if(unsigned(idx) >= uniforms.size()) + return; + Uniform& u = uniforms[idx]; + u.data.f[0] = x; + u.data.f[1] = y; + u.data.f[2] = z; + u.data.f[3] = w; + u.dirty = true; + uniformsDirty = true; #endif } diff --git a/BBGE/Shader.h b/BBGE/Shader.h index 0586272..3d21050 100644 --- a/BBGE/Shader.h +++ b/BBGE/Shader.h @@ -22,13 +22,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define BBGE_SHADER_H #include "Base.h" +#include "ScriptObject.h" -class Shader +class Shader : public ScriptObject { public: Shader(); ~Shader(); - bool isLoaded(); + bool isLoaded() const; void load(const std::string &file, const std::string &fragFile); void loadSrc(const char *vertCode, const char *fragCode); void reload(); @@ -36,16 +37,16 @@ public: void bind(); void unbind(); - // TODO: design a good API for this... - void setInt(const char *name, int x); - void setFloat(const char *name, float x); - void setFloat4(const char *name, float x, float y, float z, float w); + void setInt(const char *name, int x, int y = 0, int z = 0, int w = 0); + void setFloat(const char *name, float x, float y = 0, float z = 0, float w = 0); + // TODO: other setters needed? protected: std::string vertFile, fragFile; #ifdef BBGE_BUILD_OPENGL GLuint g_programObj; + int numUniforms; #endif private: @@ -54,6 +55,41 @@ private: static bool _useShaders; static unsigned int _compileShader(int type, const char *src, char *errbuf, size_t errbufsize); + + struct Uniform + { + int location; // GL location variable + int type; + bool dirty; // need to flush if true + union + { + struct + { + int i[4]; + }; + struct + { + float f[4]; + }; + } data; + char name[32]; + + bool operator< (const Uniform&) const; + }; + + static bool _sortUniform(const Uniform& a, const char *bname); + + void _queryUniforms(); + void _flushUniforms(); + void _registerUniform(); + + void _setUniform(Uniform *u); + int _getUniformIndex(const char *name); + + typedef std::vector UniformVec; + UniformVec uniforms; + + bool uniformsDirty; }; #endif diff --git a/ExternalLibs/algorithmx.h b/ExternalLibs/algorithmx.h new file mode 100644 index 0000000..44f85a0 --- /dev/null +++ b/ExternalLibs/algorithmx.h @@ -0,0 +1,34 @@ +#ifndef STDXfg_ALGORITHMX_H +#define STDXfg_ALGORITHMX_H + +// Some std:: namespace enhancements + +#include + +namespace stdx_fg { + +template +ForwardIterator lower_bound(ForwardIterator first, ForwardIterator last, const T& val, Compare comp) +{ + ForwardIterator it; + typename std::iterator_traits::difference_type count, step; + count = std::distance(first,last); + while(count > 0) + { + it = first; + step = count/2; + std::advance (it,step); + if (comp(*it, val)) + { + first= ++it; + count -= step+1; + } + else + count = step; + } + return first; +} + +} // end namespace stdx_fg + +#endif From 8c80cf6318500adee6c64a1e707cc0422a4d15ad Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sun, 12 May 2013 00:06:26 +0200 Subject: [PATCH 058/103] Add shader interface API to Lua API --- Aquaria/ScriptInterface.cpp | 90 ++++++++++++++++++++++++++++++++++++- BBGE/AfterEffect.cpp | 12 +++++ BBGE/AfterEffect.h | 1 + 3 files changed, 102 insertions(+), 1 deletion(-) diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index d101194..c4517ea 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -361,7 +361,7 @@ static void scriptError(lua_State *L, const std::string& msg) // - The C++ standard allows offsetof() only on POD-types. Oh well, it probably works anyways. // If it does not compile for some reason, comment it out, hope for the best, and go ahead. #if !(defined(__GNUC__) && __GNUC__ <= 2) -void compile_time_assertions() +static void compile_time_assertions() { #define oo(cls) offsetof(cls, _objtype) compile_assert(oo(Path) == oo(RenderObject)); @@ -378,6 +378,7 @@ void compile_time_assertions() compile_assert(oo(Path) == oo(Avatar)); compile_assert(oo(Path) == oo(BaseText)); compile_assert(oo(Path) == oo(PauseQuad)); + compile_assert(oo(Path) == oo(Shader)); #undef oo } #endif @@ -458,6 +459,12 @@ std::string getString(lua_State *L, int slot = 1) return sr; } +static inline +const char *getCString(lua_State *L, int slot = 1) +{ + return lua_isstring(L, slot) ? lua_tostring(L, slot) : NULL; +} + static inline Shot *getShot(lua_State *L, int slot = 1) { @@ -579,6 +586,16 @@ BaseText *getText(lua_State *L, int slot = 1) return q; } +static inline +Shader *getShader(lua_State *L, int slot = 1) +{ + Shader *q = (Shader*)lua_touserdata(L, slot); + ENSURE_TYPE(q, SCO_SHADER); + if (!q) + scriptDebug(L, "Invalid Shader"); + return q; +} + static SkeletalSprite *getSkeletalSprite(Entity *e) { return e ? &e->skeletalSprite : NULL; @@ -7680,6 +7697,70 @@ luaFunc(text_setWidth) luaReturnNil(); } +luaFunc(loadShader) +{ + const char *vertRaw = getCString(L, 1); + const char *fragRaw = getCString(L, 2); + std::string vert, frag; + if(vertRaw) + findFile_helper(vertRaw, vert); + if(fragRaw) + findFile_helper(fragRaw, frag); + Shader *sh = new Shader(); + sh->load(vert, frag); + if(!sh->isLoaded()) + { + delete sh; + sh = NULL; + } + luaReturnPtr(sh); +} + +luaFunc(createShader) +{ + Shader *sh = new Shader(); + sh->loadSrc(getCString(L, 1), getCString(L, 2)); + if(!sh->isLoaded()) + { + delete sh; + sh = NULL; + } + luaReturnPtr(sh); +} + +luaFunc(shader_setAsAfterEffect) +{ + core->afterEffectManager->scriptShader = lua_isuserdata(L, 1) ? getShader(L, 1) : NULL; + luaReturnNil(); +} + +luaFunc(shader_setInt) +{ + Shader *sh = getShader(L, 1); + const char *name = getCString(L, 2); + if(sh && name) + sh->setInt(name, lua_tointeger(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5), lua_tointeger(L, 6)); + luaReturnNil(); +} + +luaFunc(shader_setFloat) +{ + Shader *sh = getShader(L, 1); + const char *name = getCString(L, 2); + if(sh && name) + sh->setFloat(name, lua_tonumber(L, 3), lua_tonumber(L, 4), lua_tonumber(L, 5), lua_tonumber(L, 6)); + luaReturnNil(); +} + +luaFunc(shader_delete) +{ + Shader *sh = getShader(L); + delete sh; + if(core->afterEffectManager->scriptShader == sh) + core->afterEffectManager->scriptShader = NULL; + luaReturnNil(); +} + //-------------------------------------------------------------------------------------------- @@ -8550,6 +8631,13 @@ static const struct { luaRegister(text_setFontSize), luaRegister(text_setWidth), + luaRegister(loadShader), + luaRegister(createShader), + luaRegister(shader_setAsAfterEffect), + luaRegister(shader_setFloat), + luaRegister(shader_setInt), + luaRegister(shader_delete), + luaRegister(isQuad), luaRegister(isNode), luaRegister(isObject), diff --git a/BBGE/AfterEffect.cpp b/BBGE/AfterEffect.cpp index 2879cf8..5e7a091 100644 --- a/BBGE/AfterEffect.cpp +++ b/BBGE/AfterEffect.cpp @@ -35,6 +35,7 @@ AfterEffectManager::AfterEffectManager(int xDivs, int yDivs) activeShader = AS_NONE; numEffects = 0; bRenderGridPoints = true; + scriptShader = 0; screenWidth = core->getWindowWidth(); screenHeight = core->getWindowHeight(); @@ -245,6 +246,7 @@ void AfterEffectManager::setActiveShader(ActiveShader as) activeShader = as; } + void AfterEffectManager::renderGrid() { #ifdef BBGE_BUILD_OPENGL @@ -278,11 +280,21 @@ void AfterEffectManager::renderGrid() activeShader = &glowShader; break; } + + if(scriptShader) + activeShader = scriptShader; + } if (activeShader) + { + //while(glGetError() != GL_NO_ERROR) {} + activeShader->bind(); + activeShader->setInt("tex", 0); + } + screenWidth = core->getWindowWidth(); screenHeight = core->getWindowHeight(); diff --git a/BBGE/AfterEffect.h b/BBGE/AfterEffect.h index fd755d3..bfe70f7 100644 --- a/BBGE/AfterEffect.h +++ b/BBGE/AfterEffect.h @@ -125,6 +125,7 @@ public: int textureWidth, textureHeight; Shader blurShader, bwShader, washoutShader, motionBlurShader, glowShader; + Shader *scriptShader; Vector ** drawGrid; From 6666787f6d3f636e28329ca687b3aac9c63a0efe Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sun, 12 May 2013 00:06:38 +0200 Subject: [PATCH 059/103] vcproj update --- win/vc90/BBGE.vcproj | 4 ---- win/vc90/external.vcproj | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/win/vc90/BBGE.vcproj b/win/vc90/BBGE.vcproj index b6cf501..ef5d40e 100644 --- a/win/vc90/BBGE.vcproj +++ b/win/vc90/BBGE.vcproj @@ -352,10 +352,6 @@ RelativePath="..\..\BBGE\ParticleManager.cpp" > - - diff --git a/win/vc90/external.vcproj b/win/vc90/external.vcproj index 0eb936d..ef30d30 100644 --- a/win/vc90/external.vcproj +++ b/win/vc90/external.vcproj @@ -1219,6 +1219,10 @@ Filter="h;hpp;hxx;hm;inl;inc;xsd" UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > + + From cfd9b0ca5b0169b95323a1cd1591c6ef36b97fac Mon Sep 17 00:00:00 2001 From: fgenesis Date: Wed, 15 May 2013 01:56:50 +0200 Subject: [PATCH 060/103] Fix bug in shader uniform assignment --- BBGE/Shader.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/BBGE/Shader.cpp b/BBGE/Shader.cpp index 1c8f4a8..d29707e 100644 --- a/BBGE/Shader.cpp +++ b/BBGE/Shader.cpp @@ -405,6 +405,9 @@ int Shader::_getUniformIndex(const char *name) { // binary search UniformVec::iterator it = stdx_fg::lower_bound(uniforms.begin(), uniforms.end(), name, _sortUniform); + // because lower_bound returns the first element that compares less, it might not be the correct one + if(it != uniforms.end() && strcmp(it->name, name)) + return -1; return int(it - uniforms.begin()); } From 57171492341a69ca0e6ec3792bc7a58a9a3fee03 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Thu, 16 May 2013 01:55:10 +0200 Subject: [PATCH 061/103] Enable shaders for CMake build --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c16bd0..567f696 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -219,7 +219,7 @@ ADD_DEFINITIONS(-DTIXML_USE_STL=1) ADD_DEFINITIONS(-DBBGE_SKIP_CONFIG_HEADERS=1) # if this is not defined, it will use .h files to set the necessary defines ADD_DEFINITIONS(-DBBGE_BUILD_SDL=1) ADD_DEFINITIONS(-DBBGE_BUILD_FRAMEBUFFER=1) -#ADD_DEFINITIONS(-DBBGE_BUILD_SHADERS=1) +ADD_DEFINITIONS(-DBBGE_BUILD_SHADERS=1) ADD_DEFINITIONS(-DBBGE_BUILD_OPENGL=1) ADD_DEFINITIONS(-DBBGE_BUILD_OPENGL_DYNAMIC=1) ADD_DEFINITIONS(-DBBGE_BUILD_FMOD_OPENAL_BRIDGE=1) From 36247593d4fc568dd2a56f8923fb9800ead4b769 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Thu, 16 May 2013 03:54:20 +0200 Subject: [PATCH 062/103] Fix possible crash due to unsafe shot iteration. Fixes regression introduced in 0784d1b9dff. With a std::list it was okay to create shots while iterating with an iterator, but not so with a std::vector. Now using index access, which is safe with push_back() operations. --- Aquaria/Game.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Aquaria/Game.cpp b/Aquaria/Game.cpp index 733399b..1f44e86 100644 --- a/Aquaria/Game.cpp +++ b/Aquaria/Game.cpp @@ -8402,9 +8402,9 @@ void Game::handleShotCollisions(Entity *e, bool hasShield) { BBGE_PROF(Game_handleShotCollisions); bool isRegValid=true; - for (Shot::Shots::iterator i = Shot::shots.begin(); i != Shot::shots.end(); i++) + for (size_t i = 0; i < Shot::shots.size(); ++i) { - Shot *shot = *i; + Shot *shot = Shot::shots[i]; if (shot->isActive() && isEntityCollideWithShot(e, shot) && (!hasShield || (!shot->shotData || !shot->shotData->ignoreShield))) { Vector collidePoint = e->position+e->offset; @@ -8434,9 +8434,9 @@ bool Game::isDamageTypeEnemy(DamageType dt) void Game::handleShotCollisionsSkeletal(Entity *e) { BBGE_PROF(Game_HSSKELETAL); - for (Shot::Shots::iterator i = Shot::shots.begin(); i != Shot::shots.end(); i++) + for (size_t i = 0; i < Shot::shots.size(); ++i) { - Shot *shot = *i; + Shot *shot = Shot::shots[i]; if (shot->isActive() && isEntityCollideWithShot(e, shot)) { Bone *b = collideSkeletalVsCircle(e, shot->position, shot->collideRadius); @@ -8451,9 +8451,9 @@ void Game::handleShotCollisionsSkeletal(Entity *e) void Game::handleShotCollisionsHair(Entity *e, int num) { - for (Shot::Shots::iterator i = Shot::shots.begin(); i != Shot::shots.end(); i++) + for (size_t i = 0; i < Shot::shots.size(); ++i) { - Shot *shot = *i; + Shot *shot = Shot::shots[i]; if (shot->isActive() && isEntityCollideWithShot(e, shot)) { bool b = collideHairVsCircle(e, num, shot->position, 8); From 8fbed64db32cacffce8b16f90b30d62c4bbeab3a Mon Sep 17 00:00:00 2001 From: fgenesis Date: Thu, 16 May 2013 03:54:20 +0200 Subject: [PATCH 063/103] Fix possible crash due to unsafe shot iteration. Fixes regression introduced in 0784d1b9dff. With a std::list it was okay to create shots while iterating with an iterator, but not so with a std::vector. Now using index access, which is safe with push_back() operations. --- Aquaria/Game.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Aquaria/Game.cpp b/Aquaria/Game.cpp index cab97ab..63748d7 100644 --- a/Aquaria/Game.cpp +++ b/Aquaria/Game.cpp @@ -8407,9 +8407,9 @@ void Game::handleShotCollisions(Entity *e, bool hasShield) { BBGE_PROF(Game_handleShotCollisions); bool isRegValid=true; - for (Shot::Shots::iterator i = Shot::shots.begin(); i != Shot::shots.end(); i++) + for (size_t i = 0; i < Shot::shots.size(); ++i) { - Shot *shot = *i; + Shot *shot = Shot::shots[i]; if (shot->isActive() && isEntityCollideWithShot(e, shot) && (!hasShield || (!shot->shotData || !shot->shotData->ignoreShield))) { Vector collidePoint = e->position+e->offset; @@ -8439,9 +8439,9 @@ bool Game::isDamageTypeEnemy(DamageType dt) void Game::handleShotCollisionsSkeletal(Entity *e) { BBGE_PROF(Game_HSSKELETAL); - for (Shot::Shots::iterator i = Shot::shots.begin(); i != Shot::shots.end(); i++) + for (size_t i = 0; i < Shot::shots.size(); ++i) { - Shot *shot = *i; + Shot *shot = Shot::shots[i]; if (shot->isActive() && isEntityCollideWithShot(e, shot)) { Bone *b = collideSkeletalVsCircle(e, shot->position, shot->collideRadius); @@ -8456,9 +8456,9 @@ void Game::handleShotCollisionsSkeletal(Entity *e) void Game::handleShotCollisionsHair(Entity *e, int num) { - for (Shot::Shots::iterator i = Shot::shots.begin(); i != Shot::shots.end(); i++) + for (size_t i = 0; i < Shot::shots.size(); ++i) { - Shot *shot = *i; + Shot *shot = Shot::shots[i]; if (shot->isActive() && isEntityCollideWithShot(e, shot)) { bool b = collideHairVsCircle(e, num, shot->position, 8); From f7740eb6e8f163e9ce748c7ba4b543a321cb65c8 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sun, 19 May 2013 20:14:00 +0200 Subject: [PATCH 064/103] add beam_setDamageType() Lua function --- Aquaria/ScriptInterface.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index c4517ea..5f53ff2 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -3746,6 +3746,16 @@ luaFunc(beam_setDamage) luaReturnNil(); } +luaFunc(beam_setDamageType) +{ + Beam *b = beam(L); + if (b) + { + b->damageData.damageType = (DamageType)lua_tointeger(L, 2); + } + luaReturnNil(); +} + luaFunc(beam_setBeamWidth) { Beam *b = beam(L); @@ -7950,6 +7960,7 @@ static const struct { luaRegister(beam_setDamage), luaRegister(beam_setBeamWidth), luaRegister(beam_setFirer), + luaRegister(beam_setDamageType), luaRegister(getStringBank), From 0611568d3efc7aead1ca3edc13d0f1f88b3ce388 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Fri, 24 May 2013 03:34:10 +0200 Subject: [PATCH 065/103] Add precacher for mods --- Aquaria/DSQ.cpp | 2 ++ Aquaria/DSQ.h | 2 ++ Aquaria/Mod.cpp | 22 ++++++++++++++++++++++ BBGE/Precacher.cpp | 13 ++++++++++--- BBGE/Precacher.h | 2 ++ 5 files changed, 38 insertions(+), 3 deletions(-) diff --git a/Aquaria/DSQ.cpp b/Aquaria/DSQ.cpp index 99427b2..dca1cc4 100644 --- a/Aquaria/DSQ.cpp +++ b/Aquaria/DSQ.cpp @@ -2334,6 +2334,8 @@ void DSQ::playPositionalSfx(const std::string &name, const Vector &position, flo void DSQ::shutdown() { + mod.stop(); + Network::shutdown(); scriptInterface.shutdown(); diff --git a/Aquaria/DSQ.h b/Aquaria/DSQ.h index e24d4ff..3be5ae6 100644 --- a/Aquaria/DSQ.h +++ b/Aquaria/DSQ.h @@ -257,6 +257,7 @@ class Mod { public: Mod(); + ~Mod(); void clear(); void setActive(bool v); void start(); @@ -297,6 +298,7 @@ protected: std::string name; std::string path; + Precacher modcache; }; class AquariaScreenTransition : public ScreenTransition diff --git a/Aquaria/Mod.cpp b/Aquaria/Mod.cpp index beac053..4a38b9c 100644 --- a/Aquaria/Mod.cpp +++ b/Aquaria/Mod.cpp @@ -39,6 +39,11 @@ Mod::Mod() shuttingDown = false; } +Mod::~Mod() +{ + modcache.clean(); +} + /* queue for actual stop and recache which happens in game::applystate @@ -182,6 +187,23 @@ void Mod::recache() core->resetTimer(); } + + if(active) + { + modcache.setBaseDir(dsq->secondaryTexturePath); + std::string fname = path; + if(fname[fname.length() - 1] != '/') + fname += '/'; + fname += "precache.txt"; + fname = localisePath(fname, dsq->mod.getPath()); + fname = core->adjustFilenameCase(fname); + if (exists(fname)) + modcache.precacheList(fname); + } + else + { + modcache.clean(); + } } void Mod::start() diff --git a/BBGE/Precacher.cpp b/BBGE/Precacher.cpp index 24e1585..3d604b8 100644 --- a/BBGE/Precacher.cpp +++ b/BBGE/Precacher.cpp @@ -34,6 +34,11 @@ Precacher::~Precacher() errorLog ("Precacher shutdown unclean"); } +void Precacher::setBaseDir(const std::string& dir) +{ + basedirOverride = dir; +} + void Precacher::clean() { for (unsigned int i = 0; i < renderObjects.size(); i++) @@ -88,6 +93,8 @@ void Precacher::precacheTex(const std::string &tex) } if (tex.empty()) return; + std::string basedir = basedirOverride.empty() ? core->getBaseTextureDirectory() : basedirOverride; + if (core->debugLogTextures) debugLog("PRECACHING: " + tex); @@ -99,7 +106,7 @@ void Precacher::precacheTex(const std::string &tex) int loc = tex.find('*'); std::string path = tex.substr(0, loc); std::string type = tex.substr(loc+1, tex.size()); - path = core->getBaseTextureDirectory() + path; + path = basedir + path; forEachFile(path, type, precacherCallback, (intptr_t)this); return; } @@ -108,9 +115,9 @@ void Precacher::precacheTex(const std::string &tex) if (loadProgressCallback) loadProgressCallback(); std::string t = tex; - if (tex.find(core->getBaseTextureDirectory()) != std::string::npos) + if (tex.find(basedir) != std::string::npos) { - t = tex.substr(core->getBaseTextureDirectory().size(), tex.size()); + t = tex.substr(basedir.size(), tex.size()); } Quad *q = new Quad; q->setTexture(t); diff --git a/BBGE/Precacher.h b/BBGE/Precacher.h index 87e9a05..4893123 100644 --- a/BBGE/Precacher.h +++ b/BBGE/Precacher.h @@ -32,11 +32,13 @@ public: void precacheList(const std::string &list, void progressCallback() = NULL); void clean(); void loadTextureRange(const std::string &file, const std::string &type, int start, int end); + void setBaseDir(const std::string& dir); std::vector renderObjects; private: bool cleaned; void (*loadProgressCallback)(); + std::string basedirOverride; }; #endif From 1ea1408ac48009c3e94334139bdfc217d15ec541 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Fri, 24 May 2013 03:36:50 +0200 Subject: [PATCH 066/103] Animation editor enhancement. New key combo: Pressing Ctrl+Shift while moving/rotating a bone will move/rotate it globally, for all keys in all animations. --- Aquaria/AnimationEditor.cpp | 57 ++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 10 deletions(-) diff --git a/Aquaria/AnimationEditor.cpp b/Aquaria/AnimationEditor.cpp index ed800f6..105c094 100644 --- a/Aquaria/AnimationEditor.cpp +++ b/Aquaria/AnimationEditor.cpp @@ -1074,14 +1074,33 @@ void AnimationEditor::applyTranslation() { int xdiff = editingBone->position.x - bcur->x; int ydiff = editingBone->position.y - bcur->y; - // all bones mode - for (int i = 0; i < editSprite->getCurrentAnimation()->getNumKeyframes(); ++i) + if(!core->getCtrlState()) { - BoneKeyframe *b = editSprite->getCurrentAnimation()->getKeyframe(i)->getBoneKeyframe(editingBone->boneIdx); - if (b) + // all bones in one anim mode + for (int i = 0; i < editSprite->getCurrentAnimation()->getNumKeyframes(); ++i) { - b->x += xdiff; - b->y += ydiff; + BoneKeyframe *b = editSprite->getCurrentAnimation()->getKeyframe(i)->getBoneKeyframe(editingBone->boneIdx); + if (b) + { + b->x += xdiff; + b->y += ydiff; + } + } + } + else + { + // all bones in all anims mode + for (int a = 0; a < editSprite->animations.size(); ++a) + { + for (int i = 0; i < editSprite->animations[a].getNumKeyframes(); ++i) + { + BoneKeyframe *b = editSprite->animations[a].getKeyframe(i)->getBoneKeyframe(editingBone->boneIdx); + if (b) + { + b->x += xdiff; + b->y += ydiff; + } + } } } } @@ -1187,12 +1206,30 @@ void AnimationEditor::rmbu() if (bcur) { int rotdiff = editingBone->rotation.z - bcur->rot; - for (int i = 0; i < editSprite->getCurrentAnimation()->getNumKeyframes(); ++i) + if (!core->getCtrlState()) { - BoneKeyframe *b = editSprite->getCurrentAnimation()->getKeyframe(i)->getBoneKeyframe(editingBone->boneIdx); - if (b) + for (int i = 0; i < editSprite->getCurrentAnimation()->getNumKeyframes(); ++i) { - b->rot += rotdiff; + BoneKeyframe *b = editSprite->getCurrentAnimation()->getKeyframe(i)->getBoneKeyframe(editingBone->boneIdx); + if (b) + { + b->rot += rotdiff; + } + } + } + else + { + // all bones in all anims mode + for (int a = 0; a < editSprite->animations.size(); ++a) + { + for (int i = 0; i < editSprite->animations[a].getNumKeyframes(); ++i) + { + BoneKeyframe *b = editSprite->animations[a].getKeyframe(i)->getBoneKeyframe(editingBone->boneIdx); + if (b) + { + b->rot += rotdiff; + } + } } } } From f5f890aade8c5371e43c4543df03babb5adc052f Mon Sep 17 00:00:00 2001 From: fgenesis Date: Mon, 10 Jun 2013 00:59:46 +0200 Subject: [PATCH 067/103] Make particle suck positions accessible to Lua, use suckpos 2, fix possible crash in entity_clearHair() --- Aquaria/Avatar.cpp | 10 ++++++---- Aquaria/ScriptInterface.cpp | 26 +++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/Aquaria/Avatar.cpp b/Aquaria/Avatar.cpp index dd2cb05..e4b8bad 100644 --- a/Aquaria/Avatar.cpp +++ b/Aquaria/Avatar.cpp @@ -2158,7 +2158,8 @@ void Avatar::loseTargets() void Avatar::updateTargetQuads(float dt) { - particleManager->setSuckPosition(1, dsq->getGameCursorPosition()); + const Vector cursorpos = dsq->getGameCursorPosition(); + particleManager->setSuckPosition(1, cursorpos); /* for (int i = 0; i < targetQuads.size(); i++) @@ -2189,7 +2190,8 @@ void Avatar::updateTargetQuads(float dt) targets[i].pos = e->getTargetPoint(targets[i].targetPt); if (i == 0) { - particleManager->setSuckPosition(1, targets[i].pos); + particleManager->setSuckPosition(1, targets[i].pos); // suckpos 1 is overridden elsewhere later + particleManager->setSuckPosition(2, targets[i].pos); } /* @@ -2202,7 +2204,7 @@ void Avatar::updateTargetQuads(float dt) } else { - targetQuads[i]->position = dsq->getGameCursorPosition(); + targetQuads[i]->position = cursorpos; //targetQuads[i]->alpha.interpolateTo(0, 0.1); } } @@ -2222,7 +2224,7 @@ void Avatar::updateTargetQuads(float dt) debugLog(os.str()); */ - targetQuads[i]->position = dsq->getGameCursorPosition(); + targetQuads[i]->position = cursorpos; if (dsq->continuity.form == FORM_ENERGY && isInputEnabled()) { if (dsq->inputMode == INPUT_JOYSTICK && targetQuads[i]->isRunning()) diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 5f53ff2..12ada91 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -3021,6 +3021,27 @@ luaFunc(spawnParticleEffect) luaReturnPtr(pe); } +luaFunc(setNumSuckPositions) +{ + particleManager->setNumSuckPositions(lua_tointeger(L, 0)); + luaReturnNil(); +} + +luaFunc(setSuckPosition) +{ + particleManager->setSuckPosition(lua_tointeger(L, 0), Vector(lua_tonumber(L, 1), lua_tonumber(L, 2))); + luaReturnNil(); +} + +luaFunc(getSuckPosition) +{ + Vector *v = particleManager->getSuckPosition(lua_tointeger(L, 0)); + if(v) + luaReturnVec2(v->x, v->y); + luaReturnVec2(0.0f, 0.0f); +} + + luaFunc(bone_showFrame) { Bone *b = bone(L); @@ -6958,7 +6979,7 @@ luaFunc(entity_getHair) luaFunc(entity_clearHair) { Entity *e = entity(L); - if (e) + if (e && e->hair) { e->hair->safeKill(); e->hair = 0; @@ -8157,6 +8178,9 @@ static const struct { luaRegister(resetTimer), luaRegister(addInfluence), + luaRegister(setSuckPosition), + luaRegister(setSuckPosition); + luaRegister(setNumSuckPositions), luaRegister(setupBasicEntity), luaRegister(playMusic), luaRegister(playMusicStraight), From 336c821eb2c42380cd99d5b189674b7710c66562 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Mon, 10 Jun 2013 01:02:47 +0200 Subject: [PATCH 068/103] Thou shall not push without compiling. --- Aquaria/ScriptInterface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 12ada91..9d06c79 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -8179,7 +8179,7 @@ static const struct { luaRegister(addInfluence), luaRegister(setSuckPosition), - luaRegister(setSuckPosition); + luaRegister(setSuckPosition), luaRegister(setNumSuckPositions), luaRegister(setupBasicEntity), luaRegister(playMusic), From dcc676afbc61e66b6664cf86d14967e0d95e8601 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Mon, 10 Jun 2013 01:20:50 +0200 Subject: [PATCH 069/103] ... AND THOU SHALL TEST YOUR CODE BEFORE PUSH --- Aquaria/ScriptInterface.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 9d06c79..77e312a 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -3023,19 +3023,19 @@ luaFunc(spawnParticleEffect) luaFunc(setNumSuckPositions) { - particleManager->setNumSuckPositions(lua_tointeger(L, 0)); + particleManager->setNumSuckPositions(lua_tointeger(L, 1)); luaReturnNil(); } luaFunc(setSuckPosition) { - particleManager->setSuckPosition(lua_tointeger(L, 0), Vector(lua_tonumber(L, 1), lua_tonumber(L, 2))); + particleManager->setSuckPosition(lua_tointeger(L, 1), Vector(lua_tonumber(L, 2), lua_tonumber(L, 3))); luaReturnNil(); } luaFunc(getSuckPosition) { - Vector *v = particleManager->getSuckPosition(lua_tointeger(L, 0)); + Vector *v = particleManager->getSuckPosition(lua_tointeger(L, 1)); if(v) luaReturnVec2(v->x, v->y); luaReturnVec2(0.0f, 0.0f); From c698b4128a778263424c40d218952796d4e781b3 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Tue, 11 Jun 2013 09:02:56 +0200 Subject: [PATCH 070/103] Fix copypaste mistake in avatar_canLockToWall() & avatar_setCanLockToWall(). Add functions: - obj_getAlphaMod() - obj_getColor() --- Aquaria/ScriptInterface.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 77e312a..f21ded2 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -865,6 +865,12 @@ luaFunc(obj_alphaMod) luaReturnNil() } +luaFunc(obj_getAlphaMod) +{ + RenderObject *r = robj(L); + luaReturnNum(r ? r->alphaMod : 0.0f); +} + luaFunc(obj_getAlpha) { RenderObject *r = robj(L); @@ -883,6 +889,16 @@ luaFunc(obj_color) luaReturnNil(); } +luaFunc(obj_getColor) +{ + RenderObject *r = robj(L); + Vector c; + if(r) + c = r->color; + luaReturnVec3(c.x, c.y, c.z); +} + + luaFunc(obj_rotate) { RenderObject *r = robj(L); @@ -1535,7 +1551,9 @@ luaFunc(quad_setSegs) RO_FUNC(getter, prefix, alpha ) \ RO_FUNC(getter, prefix, alphaMod ) \ RO_FUNC(getter, prefix, getAlpha ) \ + RO_FUNC(getter, prefix, getAlphaMod ) \ RO_FUNC(getter, prefix, color ) \ + RO_FUNC(getter, prefix, getColor ) \ RO_FUNC(getter, prefix, rotate ) \ RO_FUNC(getter, prefix, rotateOffset ) \ RO_FUNC(getter, prefix, getRotation ) \ @@ -2761,13 +2779,13 @@ luaFunc(avatar_canBurst) luaFunc(avatar_setCanLockToWall) { - dsq->game->avatar->setCanBurst(getBool(L, 1)); + dsq->game->avatar->setCanLockToWall(getBool(L, 1)); luaReturnNil(); } luaFunc(avatar_canLockToWall) { - luaReturnBool(dsq->game->avatar->canBurst()); + luaReturnBool(dsq->game->avatar->canLockToWall()); } luaFunc(avatar_setCanSwimAgainstCurrents) From 3485199bec073aafcde759b3dc42189afae699f6 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sat, 15 Jun 2013 00:58:32 +0200 Subject: [PATCH 071/103] temp commit - work on shaders --- Aquaria/Avatar.cpp | 32 ------- Aquaria/Game.cpp | 5 - Aquaria/ScriptInterface.cpp | 12 ++- Aquaria/UserSettings.cpp | 8 -- Aquaria/UserSettings.h | 2 - BBGE/AfterEffect.cpp | 186 +++++++++++++----------------------- BBGE/AfterEffect.h | 22 +---- 7 files changed, 75 insertions(+), 192 deletions(-) diff --git a/Aquaria/Avatar.cpp b/Aquaria/Avatar.cpp index e4b8bad..1abb763 100644 --- a/Aquaria/Avatar.cpp +++ b/Aquaria/Avatar.cpp @@ -5742,38 +5742,6 @@ void Avatar::onUpdate(float dt) } - - // setup shader - if (core->afterEffectManager) - { - - /* - if (!_isUnderWater) - { - core->afterEffectManager->setActiveShader(AS_WASHOUT); - //core->afterEffectManager->setActiveShader(AS_NONE); - } - else - */ - if (dsq->user.video.shader != AS_NONE) - { - core->afterEffectManager->setActiveShader((ActiveShader)dsq->user.video.shader); - } - else - { - if (damageTimer.isActive() && dsq->isShakingCamera()) - { - if (dsq->user.video.blur) - core->afterEffectManager->setActiveShader(AS_BLUR); - } - else - { - core->afterEffectManager->setActiveShader(AS_NONE); - } - - } - } - Entity::onUpdate(dt); if (isEntityDead() && skeletalSprite.getCurrentAnimation()->name != "dead") diff --git a/Aquaria/Game.cpp b/Aquaria/Game.cpp index 1f44e86..5f2de4e 100644 --- a/Aquaria/Game.cpp +++ b/Aquaria/Game.cpp @@ -10719,11 +10719,6 @@ void Game::removeState() elementUpdateList.clear(); - if (core->afterEffectManager) - { - //core->afterEffectManager->blurShader.setMode(0); - core->afterEffectManager->setActiveShader(AS_NONE); - } dsq->setCursor(CURSOR_NORMAL); dsq->darkLayer.toggle(0); dsq->shakeCamera(0,0); diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index f21ded2..0987607 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -3995,6 +3995,8 @@ luaFunc(entity_damage) d.attacker = lua_isuserdata(L, 2) ? entity(L, 2) : NULL; d.damage = lua_tonumber(L, 3); d.damageType = (DamageType)lua_tointeger(L, 4); + d.effectTime = lua_tonumber(L, 5); + d.useTimer = !getBool(L, 6); didDamage = e->damage(d); } luaReturnBool(didDamage); @@ -7779,7 +7781,9 @@ luaFunc(createShader) luaFunc(shader_setAsAfterEffect) { - core->afterEffectManager->scriptShader = lua_isuserdata(L, 1) ? getShader(L, 1) : NULL; + int idx = lua_tointeger(L, 2); + if(idx < core->afterEffectManager->scriptShader.size()) + core->afterEffectManager->scriptShader[idx] = lua_isuserdata(L, 1) ? getShader(L, 1) : NULL; luaReturnNil(); } @@ -7805,8 +7809,10 @@ luaFunc(shader_delete) { Shader *sh = getShader(L); delete sh; - if(core->afterEffectManager->scriptShader == sh) - core->afterEffectManager->scriptShader = NULL; + size_t sz = core->afterEffectManager->scriptShader.size(); + for(size_t i = 0; i < sz; ++i) + if(core->afterEffectManager->scriptShader[i] == sh) + core->afterEffectManager->scriptShader[i] = NULL; luaReturnNil(); } diff --git a/Aquaria/UserSettings.cpp b/Aquaria/UserSettings.cpp index 49e19f4..32d47e9 100644 --- a/Aquaria/UserSettings.cpp +++ b/Aquaria/UserSettings.cpp @@ -91,12 +91,6 @@ void UserSettings::save() TiXmlElement xml_video("Video"); { - TiXmlElement xml_shader("Shader"); - { - xml_shader.SetAttribute("num", video.shader); - } - xml_video.InsertEndChild(xml_shader); - TiXmlElement xml_blur("Blur"); { xml_blur.SetAttribute("on", video.blur); @@ -413,8 +407,6 @@ void UserSettings::load(bool doApply, const std::string &overrideFile) TiXmlElement *xml_video = doc.FirstChildElement("Video"); if (xml_video) { - readInt(xml_video, "Shader", "num", &video.shader); - readInt(xml_video, "Blur", "on", &video.blur); readInt(xml_video, "NoteEffects", "on", &video.noteEffects); diff --git a/Aquaria/UserSettings.h b/Aquaria/UserSettings.h index 1e31763..1c4607e 100644 --- a/Aquaria/UserSettings.h +++ b/Aquaria/UserSettings.h @@ -100,7 +100,6 @@ public: numParticles = 2048; parallaxOn0 = parallaxOn1 = parallaxOn2 = 1; saveSlotScreens = 1; - shader = 0; blur = 1; noteEffects = 0; fpsSmoothing = 30; @@ -115,7 +114,6 @@ public: displaylists = 0; worldMapRevealMethod = 0; } - int shader; int blur; int noteEffects; int fpsSmoothing; diff --git a/BBGE/AfterEffect.cpp b/BBGE/AfterEffect.cpp index 5e7a091..474c22c 100644 --- a/BBGE/AfterEffect.cpp +++ b/BBGE/AfterEffect.cpp @@ -32,10 +32,9 @@ Effect::Effect() AfterEffectManager::AfterEffectManager(int xDivs, int yDivs) { active = false; - activeShader = AS_NONE; numEffects = 0; bRenderGridPoints = true; - scriptShader = 0; + scriptShader.resize(10, 0); screenWidth = core->getWindowWidth(); screenHeight = core->getWindowHeight(); @@ -44,46 +43,11 @@ AfterEffectManager::AfterEffectManager(int xDivs, int yDivs) this->yDivs = 0; drawGrid = 0; - -#ifdef BBGE_BUILD_OPENGL - this->xDivs = xDivs; this->yDivs = yDivs; - //cameraPointer = nCameraPointer; - //Asssuming the resolutions values are > 256 and < 2048 - //Set the texture heights and widths - if (core->frameBuffer.isInited()) - { - textureWidth = core->frameBuffer.getWidth(); - textureHeight = core->frameBuffer.getHeight(); - } - else - { - if (screenWidth <= 512) - textureWidth = 512; - else if (screenWidth <= 1024) - textureWidth = 1024; - else - textureWidth = 2048; - if (screenHeight <= 512) - textureHeight = 512; - else if (screenHeight <= 1024) - textureHeight = 1024; - else - textureHeight = 2048; - } - - //create our texture - glGenTextures(1,&texture); - glBindTexture(GL_TEXTURE_2D,texture); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); - glTexImage2D(GL_TEXTURE_2D, 0, 3, textureWidth, textureHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); - -#endif - //BuildMip(); + reloadDevice(); if (xDivs != 0 && yDivs != 0) { @@ -99,14 +63,6 @@ AfterEffectManager::AfterEffectManager(int xDivs, int yDivs) void AfterEffectManager::loadShaders() { - /* - blurShader.load("data/shaders/stan.vert", "data/shaders/blur.frag"); - bwShader.load("data/shaders/stan.vert", "data/shaders/bw.frag"); - washoutShader.load("data/shaders/stan.vert", "data/shaders/washout.frag"); - //motionBlurShader.load("data/shaders/stan.vert", "data/shaders/hoblur.frag"); - motionBlurShader.load("data/shaders/stan.vert", "data/shaders/blur.frag"); - glowShader.load("data/shaders/stan.vert", "data/shaders/glow.frag"); - */ } AfterEffectManager::~AfterEffectManager() @@ -191,29 +147,6 @@ void AfterEffectManager::destroyEffect(int id) openSpots.push(id); } -void AfterEffectManager::capture() -{ - /* -#ifdef BBGE_BUILD_OPENGL - glBindTexture(GL_TEXTURE_2D,texture); - glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, screenWidth, screenHeight); -#endif - */ - if (core->frameBuffer.isInited()) - { - core->frameBuffer.endCapture(); - //core->enable2D(core->pixelScale); - } - else - { -#ifdef BBGE_BUILD_OPENGL - glBindTexture(GL_TEXTURE_2D,texture); - glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, screenWidth, screenHeight); -#endif - } -//glDisable(GL_TEXTURE_2D); - -} void AfterEffectManager::render() { #ifdef BBGE_BUILD_OPENGL @@ -225,7 +158,7 @@ void AfterEffectManager::render() glDisable (GL_ALPHA_TEST); glDisable(GL_BLEND); - capture(); + core->frameBuffer.endCapture(); glTranslatef(core->cameraPos.x, core->cameraPos.y, 0); glScalef(core->invGlobalScale, core->invGlobalScale,0); /* @@ -241,48 +174,33 @@ void AfterEffectManager::render() #endif } -void AfterEffectManager::setActiveShader(ActiveShader as) -{ - activeShader = as; -} - - void AfterEffectManager::renderGrid() { #ifdef BBGE_BUILD_OPENGL - //glBindTexture(GL_TEXTURE_2D, texture); + + + int shadersOn = 0; + int firstShader = -1; + int lastShader = -1; + for (size_t i = 0; i < scriptShader.size(); ++i) + { + if(scriptShader[i]) + { + ++shadersOn; + if(firstShader < 0) + firstShader = i; + lastShader = i; + } + } + if (core->frameBuffer.isInited()) core->frameBuffer.bindTexture(); - else - glBindTexture(GL_TEXTURE_2D, texture); - - - //bwShader.bind(); Shader *activeShader=0; if (core->frameBuffer.isInited()) { - switch(this->activeShader) - { - case AS_BLUR: - activeShader = &blurShader; - break; - case AS_BW: - activeShader = &bwShader; - break; - case AS_WASHOUT: - activeShader = &washoutShader; - break; - case AS_MOTIONBLUR: - activeShader = &motionBlurShader; - break; - case AS_GLOW: - activeShader = &glowShader; - break; - } - - if(scriptShader) - activeShader = scriptShader; + if(scriptShader.size() && scriptShader[0]) + activeShader = scriptShader[0]; } @@ -359,6 +277,40 @@ void AfterEffectManager::renderGrid() } } + if (activeShader) + activeShader->unbind(); + + float width2 = float(vw)/2; + float height2 = float(vh)/2; + + /* + for(size_t i = 1; i < scriptShader.size(); ++i) + { + if(scriptShader[i]) + { + if (core->frameBuffer.isInited()) + core->frameBuffer.startCapture(); + + scriptShader[i]->bind(); + scriptShader[i]->setInt("tex", 0); + glBegin(GL_QUADS); + glTexCoord2d(0.0f, 0.0f); + glVertex3f(-width2, height2, 0.0f); + glTexCoord2d(percentX, 0.0f); + glVertex3f( width2, height2, 0.0f); + glTexCoord2d(percentX, percentY); + glVertex3f( width2, -height2, 0.0f); + glTexCoord2d(0.0f, percentY); + glVertex3f(-width2, -height2, 0.0f); + glEnd(); + scriptShader[i]->unbind(); + + capture(); + } + } + */ + + // uncomment to render grid points /* glBindTexture(GL_TEXTURE_2D, 0); @@ -394,9 +346,6 @@ void AfterEffectManager::renderGrid() //glDisable(GL_TEXTURE_2D); RenderObject::lastTextureApplied = 0; glBindTexture(GL_TEXTURE_2D, 0); - - if (activeShader) - activeShader->unbind(); //bwShader.unbind(); //glActiveTextureARB(GL_TEXTURE0_ARB); @@ -427,8 +376,7 @@ void AfterEffectManager::renderGridPoints() void AfterEffectManager::unloadDevice() { - if (texture) - glDeleteTextures(1,&texture); + backupBuffer.unloadDevice(); } void AfterEffectManager::reloadDevice() @@ -443,22 +391,16 @@ void AfterEffectManager::reloadDevice() } else { - if (screenWidth <= 1024) - textureWidth = 1024; - else - textureWidth = 2048; - if (screenHeight <= 1024) - textureHeight = 1024; - else - textureHeight = 2048; + textureWidth = screenWidth; + sizePowerOf2Texture(textureWidth); + textureHeight = screenHeight; + sizePowerOf2Texture(textureHeight); } - //create our texture - glGenTextures(1,&texture); - glBindTexture(GL_TEXTURE_2D,texture); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); - glTexImage2D(GL_TEXTURE_2D, 0, 3, textureWidth, textureHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); + if(backupBuffer.isInited()) + backupBuffer.reloadDevice(); + else + backupBuffer.init(-1, -1, true); } void AfterEffectManager::addEffect(Effect *e) diff --git a/BBGE/AfterEffect.h b/BBGE/AfterEffect.h index bfe70f7..c43a11d 100644 --- a/BBGE/AfterEffect.h +++ b/BBGE/AfterEffect.h @@ -72,16 +72,6 @@ public: float time; }; -enum ActiveShader -{ - AS_NONE = 0, - AS_BLUR , - AS_BW , - AS_WASHOUT , - AS_MOTIONBLUR , - AS_GLOW -}; - class AfterEffectManager { public: @@ -96,7 +86,6 @@ public: void resetGrid(); - void capture(); void render(); void renderGrid(); void renderGridPoints(); @@ -111,12 +100,6 @@ public: bool active; - void setActiveShader(ActiveShader as); - -#ifdef BBGE_BUILD_OPENGL - GLuint texture; -#endif - bool bRenderGridPoints; int numEffects; @@ -124,12 +107,11 @@ public: int screenWidth, screenHeight; int textureWidth, textureHeight; - Shader blurShader, bwShader, washoutShader, motionBlurShader, glowShader; - Shader *scriptShader; + std::vector scriptShader; Vector ** drawGrid; - ActiveShader activeShader; + FrameBuffer backupBuffer; }; From 836de140936f1140255e0e86147e4a6800fe0446 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sat, 15 Jun 2013 02:38:49 +0200 Subject: [PATCH 072/103] Implement multi-pass postprocessing shader. This allows attaching multiple shader programs, processing the entire screen as texture. Chaining shaders works, each shader will use the output of the previous shader as input. --- BBGE/AfterEffect.cpp | 161 +++++++++++++++++++++++-------------------- BBGE/AfterEffect.h | 1 + BBGE/Shader.cpp | 7 ++ 3 files changed, 96 insertions(+), 73 deletions(-) diff --git a/BBGE/AfterEffect.cpp b/BBGE/AfterEffect.cpp index 474c22c..85f5cc8 100644 --- a/BBGE/AfterEffect.cpp +++ b/BBGE/AfterEffect.cpp @@ -63,6 +63,28 @@ AfterEffectManager::AfterEffectManager(int xDivs, int yDivs) void AfterEffectManager::loadShaders() { + deleteShaders(); + + Shader *sh = new Shader(); + sh->load("data/shaders/test.vert", "data/shaders/test.frag"); + if(sh->isLoaded()) + scriptShader[0] = sh; + else + delete sh; + + sh = new Shader(); + sh->load("data/shaders/test2.vert", "data/shaders/test2.frag"); + if(sh->isLoaded()) + scriptShader[1] = sh; + else + delete sh; + + sh = new Shader(); + sh->load("data/shaders/test3.vert", "data/shaders/test3.frag"); + if(sh->isLoaded()) + scriptShader[2] = sh; + else + delete sh; } AfterEffectManager::~AfterEffectManager() @@ -77,6 +99,7 @@ AfterEffectManager::~AfterEffectManager() delete[] drawGrid; } deleteEffects(); + deleteShaders(); } void AfterEffectManager::deleteEffects() @@ -94,6 +117,18 @@ void AfterEffectManager::deleteEffects() openSpots.pop(); } +void AfterEffectManager::deleteShaders() +{ + for(size_t i = 0; i < scriptShader.size(); ++i) + { + if(scriptShader[i]) + { + delete scriptShader[i]; + scriptShader[i] = 0; + } + } +} + void AfterEffectManager::clear() { deleteEffects(); @@ -149,24 +184,18 @@ void AfterEffectManager::destroyEffect(int id) void AfterEffectManager::render() { + assert(core->frameBuffer.isInited()); + #ifdef BBGE_BUILD_OPENGL glPushMatrix(); - //glDisable(GL_BLEND); - //glEnable(GL_BLEND); - //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - //glBlendFunc(GL_SRC_ALPHA, GL_ONE); + glDisable (GL_ALPHA_TEST); glDisable(GL_BLEND); core->frameBuffer.endCapture(); glTranslatef(core->cameraPos.x, core->cameraPos.y, 0); glScalef(core->invGlobalScale, core->invGlobalScale,0); - /* - static float angle; - angle += 0.03f; - */ - //glRotatef(angle, 0, 0, 1); - //glColor4f(1,1,1,0.75); + glColor4f(1,1,1,1); renderGrid(); //renderGridPoints(); @@ -178,78 +207,45 @@ void AfterEffectManager::renderGrid() { #ifdef BBGE_BUILD_OPENGL - - int shadersOn = 0; int firstShader = -1; int lastShader = -1; + Shader *activeShader = 0; for (size_t i = 0; i < scriptShader.size(); ++i) { if(scriptShader[i]) { - ++shadersOn; if(firstShader < 0) + { firstShader = i; + activeShader = scriptShader[i]; + } lastShader = i; } } - if (core->frameBuffer.isInited()) - core->frameBuffer.bindTexture(); - - Shader *activeShader=0; - if (core->frameBuffer.isInited()) - { - if(scriptShader.size() && scriptShader[0]) - activeShader = scriptShader[0]; - - } - - if (activeShader) - { - //while(glGetError() != GL_NO_ERROR) {} - - activeShader->bind(); - - activeShader->setInt("tex", 0); - } - screenWidth = core->getWindowWidth(); screenHeight = core->getWindowHeight(); - /* - float percentX, percentY; - percentX = 1; - percentY = 0.5; - */ - - /* - percentX = (float)textureWidth/(float)screenWidth; - percentY = (float)textureHeight/(float)screenHeight; - */ - float percentX, percentY; percentX = (float)screenWidth/(float)textureWidth; percentY = (float)screenHeight/(float)textureHeight; - - /* - if (screenWidth <= textureWidth) - { - percentX = (float)screenWidth/(float)textureWidth; - percentY = (float)screenHeight/(float)textureHeight; - } - else - { - percentY = 10; - } - */ - - int vw = core->getVirtualWidth(); int vh = core->getVirtualHeight(); int offx = -core->getVirtualOffX(); int offy = -core->getVirtualOffY(); + core->frameBuffer.bindTexture(); + + if(activeShader) + { + activeShader->bind(); + activeShader->setInt("tex", 0); + + if(firstShader != lastShader) + backupBuffer.startCapture(); + } + //float div = xDivs; for (int i = 0; i < (xDivs-1); i++) { @@ -283,32 +279,48 @@ void AfterEffectManager::renderGrid() float width2 = float(vw)/2; float height2 = float(vh)/2; - /* - for(size_t i = 1; i < scriptShader.size(); ++i) + + if(firstShader != lastShader) { - if(scriptShader[i]) + // From here on: secondary shader passes. + // We just outputted to the backup buffer... + FrameBuffer *fbIn = &core->frameBuffer; + FrameBuffer *fbOut = &backupBuffer; + + + for(int i = firstShader + 1; i <= lastShader; ++i) { - if (core->frameBuffer.isInited()) - core->frameBuffer.startCapture(); + activeShader = scriptShader[i]; + if(!activeShader) + continue; + + // Swap and exchange framebuffers. The old output buffer serves as texture input for the other one + fbOut->endCapture(); + std::swap(fbIn, fbOut); + fbIn->bindTexture(); + + // If this is the last pass, do not render to a frame buffer again + if(i != lastShader) + fbOut->startCapture(); + + activeShader->bind(); + activeShader->setInt("tex", 0); - scriptShader[i]->bind(); - scriptShader[i]->setInt("tex", 0); + // note that offx, offy are negative here! glBegin(GL_QUADS); glTexCoord2d(0.0f, 0.0f); - glVertex3f(-width2, height2, 0.0f); + glVertex3f(offx, vh+offy, 0.0f); glTexCoord2d(percentX, 0.0f); - glVertex3f( width2, height2, 0.0f); + glVertex3f( vw+offx, vh+offy, 0.0f); glTexCoord2d(percentX, percentY); - glVertex3f( width2, -height2, 0.0f); + glVertex3f( vw+offx, offy, 0.0f); glTexCoord2d(0.0f, percentY); - glVertex3f(-width2, -height2, 0.0f); + glVertex3f(offx, offy, 0.0f); glEnd(); - scriptShader[i]->unbind(); - - capture(); + + activeShader->unbind(); } } - */ // uncomment to render grid points @@ -377,6 +389,7 @@ void AfterEffectManager::renderGridPoints() void AfterEffectManager::unloadDevice() { backupBuffer.unloadDevice(); + deleteShaders(); } void AfterEffectManager::reloadDevice() @@ -401,6 +414,8 @@ void AfterEffectManager::reloadDevice() backupBuffer.reloadDevice(); else backupBuffer.init(-1, -1, true); + + loadShaders(); } void AfterEffectManager::addEffect(Effect *e) diff --git a/BBGE/AfterEffect.h b/BBGE/AfterEffect.h index c43a11d..1de7063 100644 --- a/BBGE/AfterEffect.h +++ b/BBGE/AfterEffect.h @@ -91,6 +91,7 @@ public: void renderGridPoints(); void loadShaders(); + void deleteShaders(); void unloadDevice(); void reloadDevice(); diff --git a/BBGE/Shader.cpp b/BBGE/Shader.cpp index d29707e..faed2a3 100644 --- a/BBGE/Shader.cpp +++ b/BBGE/Shader.cpp @@ -192,6 +192,13 @@ unsigned int Shader::_compileShader(int type, const char *src, char *errbuf, siz #ifdef BBGE_BUILD_SHADERS GLint compiled = 0; GLhandleARB handle = glCreateShaderObjectARB(type); + if(!handle) + { + std::ostringstream os; + os << "Failed to create shader object of type " << type; + debugLog(os.str()); + return 0; + } glShaderSourceARB( handle, 1, &src, NULL ); glCompileShaderARB( handle); From 486e8f92ad4e29c0639b4d6ecf1a70ad8db1260a Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sat, 15 Jun 2013 03:00:20 +0200 Subject: [PATCH 073/103] Make the dark layer affected by postprocessing shaders. This has the side effect that elements on the dark layer will now properly wiggle when affected by water ripples. Before this patch, the dark layer was always drawn above the postprocessed screen content, unaffected. --- BBGE/Core.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/BBGE/Core.cpp b/BBGE/Core.cpp index 3bb0f1e..9f68f9f 100644 --- a/BBGE/Core.cpp +++ b/BBGE/Core.cpp @@ -3852,10 +3852,6 @@ void Core::render(int startLayer, int endLayer, bool useFrameBufferIfAvail) int i = renderObjectLayerOrder[c]; if (i == -1) continue; if ((startLayer != -1 && endLayer != -1) && (i < startLayer || i > endLayer)) continue; - if (afterEffectManager && afterEffectManager->active && i == afterEffectManagerLayer) - { - afterEffectManager->render(); - } if (i == postProcessingFx.layer) { @@ -3885,6 +3881,11 @@ void Core::render(int startLayer, int endLayer, bool useFrameBufferIfAvail) } } + if (afterEffectManager && afterEffectManager->active && i == afterEffectManagerLayer) + { + afterEffectManager->render(); + } + RenderObjectLayer *r = &renderObjectLayers[i]; RenderObject::rlayer = r; if (r->visible) From 6962a3e3ab59c2f1b44519a5b10ce53097b0ed2d Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sat, 15 Jun 2013 04:11:11 +0200 Subject: [PATCH 074/103] Improvements to shader API; use handles instead of raw pointers. --- Aquaria/ScriptInterface.cpp | 75 ++++++++++++----------- BBGE/AfterEffect.cpp | 118 +++++++++++++++++++++++++++--------- BBGE/AfterEffect.h | 16 ++++- BBGE/Shader.cpp | 1 - BBGE/Shader.h | 2 +- 5 files changed, 145 insertions(+), 67 deletions(-) diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 0987607..3c2b116 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -378,7 +378,6 @@ static void compile_time_assertions() compile_assert(oo(Path) == oo(Avatar)); compile_assert(oo(Path) == oo(BaseText)); compile_assert(oo(Path) == oo(PauseQuad)); - compile_assert(oo(Path) == oo(Shader)); #undef oo } #endif @@ -7750,6 +7749,7 @@ luaFunc(text_setWidth) luaFunc(loadShader) { + int handle = 0; const char *vertRaw = getCString(L, 1); const char *fragRaw = getCString(L, 2); std::string vert, frag; @@ -7757,62 +7757,68 @@ luaFunc(loadShader) findFile_helper(vertRaw, vert); if(fragRaw) findFile_helper(fragRaw, frag); - Shader *sh = new Shader(); - sh->load(vert, frag); - if(!sh->isLoaded()) - { - delete sh; - sh = NULL; - } - luaReturnPtr(sh); + + if(core->afterEffectManager) + handle = core->afterEffectManager->loadShaderFile(vert.c_str(), frag.c_str()); + + luaReturnInt(handle); } luaFunc(createShader) { - Shader *sh = new Shader(); - sh->loadSrc(getCString(L, 1), getCString(L, 2)); - if(!sh->isLoaded()) - { - delete sh; - sh = NULL; - } - luaReturnPtr(sh); + int handle = 0; + if(core->afterEffectManager) + handle = core->afterEffectManager->loadShaderSrc(getCString(L, 1), getCString(L, 2)); + luaReturnInt(handle); } luaFunc(shader_setAsAfterEffect) { - int idx = lua_tointeger(L, 2); - if(idx < core->afterEffectManager->scriptShader.size()) - core->afterEffectManager->scriptShader[idx] = lua_isuserdata(L, 1) ? getShader(L, 1) : NULL; + int handle = lua_tointeger(L, 1); + int pos = lua_tointeger(L, 2); + bool done = false; + + if(core->afterEffectManager) + done = core->afterEffectManager->setShaderPipelinePos(handle, pos); + + luaReturnBool(done); +} + +luaFunc(shader_setNumAfterEffects) +{ + if(core->afterEffectManager) + core->afterEffectManager->setShaderPipelineSize(lua_tointeger(L, 1)); luaReturnNil(); } luaFunc(shader_setInt) { - Shader *sh = getShader(L, 1); - const char *name = getCString(L, 2); - if(sh && name) - sh->setInt(name, lua_tointeger(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5), lua_tointeger(L, 6)); + if(core->afterEffectManager) + { + Shader *sh = core->afterEffectManager->getShaderPtr(lua_tointeger(L, 1)); + const char *name = getCString(L, 2); + if(sh && name) + sh->setInt(name, lua_tointeger(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5), lua_tointeger(L, 6)); + } luaReturnNil(); } luaFunc(shader_setFloat) { - Shader *sh = getShader(L, 1); - const char *name = getCString(L, 2); - if(sh && name) - sh->setFloat(name, lua_tonumber(L, 3), lua_tonumber(L, 4), lua_tonumber(L, 5), lua_tonumber(L, 6)); + if(core->afterEffectManager) + { + Shader *sh = core->afterEffectManager->getShaderPtr(lua_tointeger(L, 1)); + const char *name = getCString(L, 2); + if(sh && name) + sh->setFloat(name, lua_tonumber(L, 3), lua_tonumber(L, 4), lua_tonumber(L, 5), lua_tonumber(L, 6)); + } luaReturnNil(); } luaFunc(shader_delete) { - Shader *sh = getShader(L); - delete sh; - size_t sz = core->afterEffectManager->scriptShader.size(); - for(size_t i = 0; i < sz; ++i) - if(core->afterEffectManager->scriptShader[i] == sh) - core->afterEffectManager->scriptShader[i] = NULL; + if(core->afterEffectManager) + core->afterEffectManager->unloadShader(lua_tointeger(L, 1)); luaReturnNil(); } @@ -8693,6 +8699,7 @@ static const struct { luaRegister(loadShader), luaRegister(createShader), luaRegister(shader_setAsAfterEffect), + luaRegister(shader_setNumAfterEffects), luaRegister(shader_setFloat), luaRegister(shader_setInt), luaRegister(shader_delete), diff --git a/BBGE/AfterEffect.cpp b/BBGE/AfterEffect.cpp index 85f5cc8..938d535 100644 --- a/BBGE/AfterEffect.cpp +++ b/BBGE/AfterEffect.cpp @@ -34,7 +34,7 @@ AfterEffectManager::AfterEffectManager(int xDivs, int yDivs) active = false; numEffects = 0; bRenderGridPoints = true; - scriptShader.resize(10, 0); + shaderPipeline.resize(10, 0); screenWidth = core->getWindowWidth(); screenHeight = core->getWindowHeight(); @@ -65,26 +65,7 @@ void AfterEffectManager::loadShaders() { deleteShaders(); - Shader *sh = new Shader(); - sh->load("data/shaders/test.vert", "data/shaders/test.frag"); - if(sh->isLoaded()) - scriptShader[0] = sh; - else - delete sh; - - sh = new Shader(); - sh->load("data/shaders/test2.vert", "data/shaders/test2.frag"); - if(sh->isLoaded()) - scriptShader[1] = sh; - else - delete sh; - - sh = new Shader(); - sh->load("data/shaders/test3.vert", "data/shaders/test3.frag"); - if(sh->isLoaded()) - scriptShader[2] = sh; - else - delete sh; + // ...Load shaders here... } AfterEffectManager::~AfterEffectManager() @@ -119,12 +100,15 @@ void AfterEffectManager::deleteEffects() void AfterEffectManager::deleteShaders() { - for(size_t i = 0; i < scriptShader.size(); ++i) + for(size_t i = 0; i < shaderPipeline.size(); ++i) + shaderPipeline[i] = 0; + + for(size_t i = 0; i < loadedShaders.size(); ++i) { - if(scriptShader[i]) + if(loadedShaders[i]) { - delete scriptShader[i]; - scriptShader[i] = 0; + delete loadedShaders[i]; + loadedShaders[i] = 0; } } } @@ -210,14 +194,14 @@ void AfterEffectManager::renderGrid() int firstShader = -1; int lastShader = -1; Shader *activeShader = 0; - for (size_t i = 0; i < scriptShader.size(); ++i) + for (size_t i = 0; i < shaderPipeline.size(); ++i) { - if(scriptShader[i]) + if(shaderPipeline[i]) { if(firstShader < 0) { firstShader = i; - activeShader = scriptShader[i]; + activeShader = shaderPipeline[i]; } lastShader = i; } @@ -290,7 +274,7 @@ void AfterEffectManager::renderGrid() for(int i = firstShader + 1; i <= lastShader; ++i) { - activeShader = scriptShader[i]; + activeShader = shaderPipeline[i]; if(!activeShader) continue; @@ -567,3 +551,79 @@ void RippleEffect::update(float dt, Vector ** drawGrid, int xDivs, int yDivs) } } } + +int AfterEffectManager::loadShaderFile(const char *vert, const char *frag) +{ + Shader *sh = new Shader(); + sh->load(vert, frag); + if(!sh->isLoaded()) + { + delete sh; + return 0; + } + return _insertShader(sh); +} + +int AfterEffectManager::loadShaderSrc(const char *vert, const char *frag) +{ + Shader *sh = new Shader(); + sh->loadSrc(vert, frag); + if(!sh->isLoaded()) + { + delete sh; + return 0; + } + return _insertShader(sh); +} + +Shader *AfterEffectManager::getShaderPtr(int handle) +{ + size_t idx = handle - 1; + return idx < loadedShaders.size() ? loadedShaders[idx] : 0; +} + +void AfterEffectManager::setShaderPipelineSize(size_t size) +{ + shaderPipeline.resize(size, 0); +} + +bool AfterEffectManager::setShaderPipelinePos(int handle, size_t pos) +{ + if(pos < shaderPipeline.size()) + { + shaderPipeline[pos] = getShaderPtr(handle); + return true; + } + return false; +} + +// returns handle (= index + 1) +int AfterEffectManager::_insertShader(Shader *sh) +{ + for(size_t i = 0; i < loadedShaders.size(); ++i) + { + if(!loadedShaders[i]) + { + loadedShaders[i] = sh; + return i+1; + } + } + loadedShaders.push_back(sh); + return loadedShaders.size(); +} + +void AfterEffectManager::unloadShader(int handle) +{ + Shader *sh = getShaderPtr(handle); + if(!sh) + return; + + for(size_t i = 0; i < shaderPipeline.size(); ++i) + if(shaderPipeline[i] == sh) + shaderPipeline[i] = 0; + + size_t idx = handle - 1; + loadedShaders[idx] = 0; + delete sh; +} + diff --git a/BBGE/AfterEffect.h b/BBGE/AfterEffect.h index 1de7063..90c7d9f 100644 --- a/BBGE/AfterEffect.h +++ b/BBGE/AfterEffect.h @@ -108,11 +108,23 @@ public: int screenWidth, screenHeight; int textureWidth, textureHeight; - std::vector scriptShader; + Vector ** drawGrid; - Vector ** drawGrid; + // returns handle > 0 on success + int loadShaderFile(const char *vert, const char *frag); + int loadShaderSrc(const char *vert, const char *frag); + Shader *getShaderPtr(int handle); + void setShaderPipelineSize(size_t size); + bool setShaderPipelinePos(int handle, size_t pos); + void unloadShader(int handle); +protected: + int _insertShader(Shader *sh); + + std::vector shaderPipeline; // Shaders are applied in this order. Can contain the same pointer more than once. + std::vector loadedShaders; FrameBuffer backupBuffer; + }; diff --git a/BBGE/Shader.cpp b/BBGE/Shader.cpp index faed2a3..c6468bc 100644 --- a/BBGE/Shader.cpp +++ b/BBGE/Shader.cpp @@ -131,7 +131,6 @@ end: Shader::Shader() { - addType(SCO_SHADER); numUniforms = -1; uniformsDirty = false; diff --git a/BBGE/Shader.h b/BBGE/Shader.h index 3d21050..2b978e7 100644 --- a/BBGE/Shader.h +++ b/BBGE/Shader.h @@ -24,7 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "Base.h" #include "ScriptObject.h" -class Shader : public ScriptObject +class Shader { public: Shader(); From 13eca9785f328cc02b4a3d654e31d111b29b7484 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Wed, 19 Jun 2013 02:08:24 +0200 Subject: [PATCH 075/103] Intial support for package paths (as suggested by smls). This commit is mainly intended to ease packaging for linux. Unless environment variable AQUARIA_DATA_PATH is set, there are two directories which are checked by the game: If AQUARIA_DEFAULT_DATA_DIR is defined, it will chdir there for main operation. If it's not defined, it chdirs into the directory where the executable is located. Then, if AQUARIA_EXTRA_DATA_DIR is defined, it will mount this directory and all contents into the working path, so that the files present there will override those from the working directory when accessed by the game. Setting the environment variable AQUARIA_DATA_PATH will disable this behavior altogether and use *only* AQUARIA_DATA_PATH as working dir. --- Aquaria/DSQ.cpp | 3 ++- Aquaria/DSQ.h | 2 +- Aquaria/Main.cpp | 19 ++++++++++++++++--- BBGE/Core.cpp | 14 +++++++++++++- BBGE/Core.h | 3 ++- CMakeLists.txt | 13 +++++++++++++ 6 files changed, 47 insertions(+), 7 deletions(-) diff --git a/Aquaria/DSQ.cpp b/Aquaria/DSQ.cpp index bc4fff4..ae5b482 100644 --- a/Aquaria/DSQ.cpp +++ b/Aquaria/DSQ.cpp @@ -153,7 +153,8 @@ Vector savesz; #define APPNAME "Aquaria" #endif -DSQ::DSQ(std::string fileSystem) : Core(fileSystem, LR_MAX, APPNAME, PARTICLE_AMOUNT_DEFAULT, "Aquaria") +DSQ::DSQ(const std::string& fileSystem, const std::string& extraDataDir) +: Core(fileSystem, extraDataDir, LR_MAX, APPNAME, PARTICLE_AMOUNT_DEFAULT, "Aquaria") { // 2048 //createDirectory(getSaveDirectory()); diff --git a/Aquaria/DSQ.h b/Aquaria/DSQ.h index 5043f36..258617e 100644 --- a/Aquaria/DSQ.h +++ b/Aquaria/DSQ.h @@ -1227,7 +1227,7 @@ enum NagType class DSQ : public Core { public: - DSQ(std::string fileSystem); + DSQ(const std::string& fileSystem, const std::string& extraDataDir); ~DSQ(); void init(); diff --git a/Aquaria/Main.cpp b/Aquaria/Main.cpp index 215c659..290e54d 100644 --- a/Aquaria/Main.cpp +++ b/Aquaria/Main.cpp @@ -83,18 +83,31 @@ static void CheckConfig(void) extern "C" int main(int argc,char *argv[]) { std::string dsqParam = ""; // fileSystem + std::string extraDataDir = ""; + const char *envPath = 0; #ifdef BBGE_BUILD_UNIX - const char *envPath = getenv("AQUARIA_DATA_PATH"); - if (envPath != NULL) + envPath = getenv("AQUARIA_DATA_PATH"); + if (envPath) + { dsqParam = envPath; + } #endif +#ifdef AQUARIA_DEFAULT_DATA_DIR + if(!envPath) + dsqParam = AQUARIA_DEFAULT_DATA_DIR; +#endif +#ifdef AQUARIA_EXTRA_DATA_DIR + if(!envPath) + extraDataDir = AQUARIA_EXTRA_DATA_DIR; +#endif + #endif CheckConfig(); { - DSQ dsql(dsqParam); + DSQ dsql(dsqParam, extraDataDir); dsql.init(); dsql.main(); dsql.shutdown(); diff --git a/BBGE/Core.cpp b/BBGE/Core.cpp index b71581c..5f865ce 100644 --- a/BBGE/Core.cpp +++ b/BBGE/Core.cpp @@ -41,6 +41,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #if BBGE_BUILD_WINDOWS #include +#include #endif #ifdef BBGE_BUILD_SDL @@ -884,12 +885,13 @@ static bool checkWritable(const std::string& path, bool warn, bool critical) const float SORT_DELAY = 10; -Core::Core(const std::string &filesystem, int numRenderLayers, const std::string &appName, int particleSize, std::string userDataSubFolder) +Core::Core(const std::string &filesystem, const std::string& extraDataDir, int numRenderLayers, const std::string &appName, int particleSize, std::string userDataSubFolder) : ActionMapper(), StateManager(), appName(appName) { sound = NULL; screenCapScale = Vector(1,1,1); timeUpdateType = TIMEUPDATE_DYNAMIC; + _extraDataDir = extraDataDir; fixedFPS = 60; @@ -1093,6 +1095,13 @@ void Core::initPlatform(const std::string &filesystem) } #endif #ifdef BBGE_BUILD_WINDOWS + if(filesystem.length()) + { + if(_chdir(filesystem.c_str()) != 0) + { + debugLog("chdir failed: " + filesystem); + } + } // FIXME: filesystem not handled #endif } @@ -4858,6 +4867,9 @@ void Core::setupFileAccess() //vfs.AddArchive("aqfiles.zip", false, ""); + if(_extraDataDir.length()) + vfs.MountExternalPath(_extraDataDir.c_str(), "", true, true); + debugLog("Done"); #endif diff --git a/BBGE/Core.h b/BBGE/Core.h index 84b08cb..d0b0f0b 100644 --- a/BBGE/Core.h +++ b/BBGE/Core.h @@ -973,7 +973,7 @@ public: NO_DESTROY }; // init - Core(const std::string &filesystem, int numRenderLayers, const std::string &appName="BBGE", int particleSize=1024, std::string userDataSubFolder=""); + Core(const std::string &filesystem, const std::string& extraDataDir, int numRenderLayers, const std::string &appName="BBGE", int particleSize=1024, std::string userDataSubFolder=""); void initPlatform(const std::string &filesystem); ~Core(); @@ -1402,6 +1402,7 @@ protected: virtual void onRender(){} void setupFileAccess(); + std::string _extraDataDir; }; extern Core *core; diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c16bd0..552eb09 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -211,6 +211,19 @@ if (NOT(AQUARIA_CUSTOM_BUILD_ID STREQUAL "")) ADD_DEFINITIONS("-DAQUARIA_CUSTOM_BUILD_ID=\"${AQUARIA_CUSTOM_BUILD_ID}\"") endif (NOT(AQUARIA_CUSTOM_BUILD_ID STREQUAL "")) +# Custom data directories +SET(AQUARIA_DEFAULT_DATA_DIR "" CACHE STRING + "Default data directory (for package maintainers only)") +if(NOT(AQUARIA_DEFAULT_DATA_DIR STREQUAL "")) + ADD_DEFINITIONS("-DAQUARIA_DEFAULT_DATA_DIR=\"${AQUARIA_DEFAULT_DATA_DIR}\"") +endif(NOT(AQUARIA_DEFAULT_DATA_DIR STREQUAL "")) + +SET(AQUARIA_EXTRA_DATA_DIR "" CACHE STRING + "Extra data directory, overrides files from default datadir (for package maintainers only)") +if(NOT(AQUARIA_EXTRA_DATA_DIR STREQUAL "")) + ADD_DEFINITIONS("-DAQUARIA_EXTRA_DATA_DIR=\"${AQUARIA_EXTRA_DATA_DIR}\"") +endif(NOT(AQUARIA_EXTRA_DATA_DIR STREQUAL "")) + # Aquaria/BBGE specific defines... ADD_DEFINITIONS(-DGL_GLEXT_LEGACY=1) From 84a73b59f99f15b0ab009f7606f190f4394963ad Mon Sep 17 00:00:00 2001 From: fgenesis Date: Wed, 19 Jun 2013 02:26:12 +0200 Subject: [PATCH 076/103] Hopefully fixed piranha pet script warning (thx `Nax for reporting) --- game_scripts/scripts/entities/pet_piranha.lua | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/game_scripts/scripts/entities/pet_piranha.lua b/game_scripts/scripts/entities/pet_piranha.lua index 0bf82f7..fb8ec02 100644 --- a/game_scripts/scripts/entities/pet_piranha.lua +++ b/game_scripts/scripts/entities/pet_piranha.lua @@ -132,15 +132,17 @@ function update(me, dt) if entity_hasTarget(me) then target = entity_getTarget(me) - --[[ - ox, oy = entity_getOffset(target) - cx = entity_x(target) + ox + entity_velx(target) - cy = entity_y(target) + oy + entity_vely(target) - ]]-- - cx, cy = entity_getTargetPoint(target, v.tpoint) - cx = cx + entity_velx(target) - cy = cy + entity_vely(target) - dist = 40 + if target ~= 0 then + --[[ + ox, oy = entity_getOffset(target) + cx = entity_x(target) + ox + entity_velx(target) + cy = entity_y(target) + oy + entity_vely(target) + ]]-- + cx, cy = entity_getTargetPoint(target, v.tpoint) + cx = cx + entity_velx(target) + cy = cy + entity_vely(target) + dist = 40 + end --debugLog(string.format("distTimer: %f", v.distTimer)) v.distTimer = v.distTimer + dt * 0.5 @@ -160,8 +162,10 @@ function update(me, dt) end end - entity_flipToEntity(me, target) - entity_rotateToEntity(me, target) + if target ~= 0 then + entity_flipToEntity(me, target) + entity_rotateToEntity(me, target) + end local a = t x = x + math.sin(a)*dist From 61395779a1fbc4d94d889b088d36f648d2e83c91 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Wed, 19 Jun 2013 15:09:05 +0200 Subject: [PATCH 077/103] Do not try to load .zip files in _mods automatically. This has been a great source of confusion and it's better to remove it. --- Aquaria/DSQ.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Aquaria/DSQ.cpp b/Aquaria/DSQ.cpp index dca1cc4..31f1b97 100644 --- a/Aquaria/DSQ.cpp +++ b/Aquaria/DSQ.cpp @@ -2154,7 +2154,6 @@ void DSQ::loadMods() // first load the packages, then enumerate XMLs forEachFile(mod.getBaseModPath(), ".aqmod", loadModPackagesCallback, 0); - forEachFile(mod.getBaseModPath(), ".zip", loadModPackagesCallback, 0); #endif forEachFile(mod.getBaseModPath(), ".xml", loadModsCallback, 0); From f8bdac10a24508bee46ac38da8de145bd2555d62 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Wed, 19 Jun 2013 17:44:37 +0200 Subject: [PATCH 078/103] Use more sane defaults for CMake --- CMakeLists.txt | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 552eb09..b7da214 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ INCLUDE(CheckCCompilerFlag) INCLUDE(CheckFunctionExists) IF(NOT CMAKE_BUILD_TYPE) - SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "None Debug Release RelWithDebInfo MinSizeRel" FORCE) + SET(CMAKE_BUILD_TYPE Release CACHE STRING "None Debug Release RelWithDebInfo MinSizeRel" FORCE) ENDIF(NOT CMAKE_BUILD_TYPE) IF(APPLE) @@ -16,6 +16,17 @@ IF(CMAKE_SYSTEM_NAME STREQUAL "Haiku") SET(HAIKU TRUE) ENDIF() +IF(WIN32) + SET(WIN32_TRUE TRUE) +ELSE(WIN32) + SET(WIN32_TRUE FALSE) +ENDIF(WIN32) + +# if no build type was provided, set a default one +IF(NOT CMAKE_BUILD_TYPE) + SET(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build (Debug, RelWithDebInfo, Release)" FORCE) +ENDIF(NOT CMAKE_BUILD_TYPE) + OPTION(AQUARIA_DEVELOPER_BUILD "Developer Build?" FALSE) OPTION(AQUARIA_DEMO_BUILD "Demo Build?" FALSE) OPTION(AQUARIA_USE_VFS "Use Virtual File System? Required for some additional features." TRUE) @@ -42,7 +53,7 @@ SET(PNGDIR ${EXTLIBDIR}/glpng/png) ### zlib -OPTION(AQUARIA_INTERNAL_ZLIB "Always use included zlib library" FALSE) +OPTION(AQUARIA_INTERNAL_ZLIB "Always use included zlib library" TRUE) if(NOT AQUARIA_INTERNAL_ZLIB) find_package(ZLIB) endif(NOT AQUARIA_INTERNAL_ZLIB) @@ -52,7 +63,7 @@ endif(NOT ZLIB_FOUND) ### PNG -OPTION(AQUARIA_INTERNAL_PNG "Always use included PNG library" FALSE) +OPTION(AQUARIA_INTERNAL_PNG "Always use included PNG library" TRUE) if(NOT AQUARIA_INTERNAL_PNG) find_package(PNG) endif(NOT AQUARIA_INTERNAL_PNG) @@ -66,7 +77,7 @@ STRING(REGEX REPLACE "^.*PNG_LIBPNG_VER[^0-9]*([0-9]+).*$" "\\1" PNG_LIBPNG_VER ### FreeType -OPTION(AQUARIA_INTERNAL_FREETYPE "Always use included FreeType library" FALSE) +OPTION(AQUARIA_INTERNAL_FREETYPE "Always use included FreeType library" TRUE) if(NOT AQUARIA_INTERNAL_FREETYPE) find_package(Freetype) endif(NOT AQUARIA_INTERNAL_FREETYPE) @@ -76,7 +87,7 @@ endif(NOT FREETYPE_FOUND) ### Lua -OPTION(AQUARIA_INTERNAL_LUA "Always use included Lua library" FALSE) +OPTION(AQUARIA_INTERNAL_LUA "Always use included Lua library" TRUE) if(NOT AQUARIA_INTERNAL_LUA) find_package(Lua51) endif(NOT AQUARIA_INTERNAL_LUA) @@ -86,7 +97,7 @@ endif(NOT LUA51_FOUND) ### Ogg/Vorbis -OPTION(AQUARIA_INTERNAL_OGGVORBIS "Always use included Ogg/Vorbis libraries" FALSE) +OPTION(AQUARIA_INTERNAL_OGGVORBIS "Always use included Ogg/Vorbis libraries" TRUE) if(NOT AQUARIA_INTERNAL_OGGVORBIS) # CMake doesn't seem to have a module for libogg or libvorbis yet, so # we roll our own based on existing find_package modules. @@ -148,7 +159,7 @@ endif(NOT OGGVORBIS_FOUND) ### SDL -OPTION(AQUARIA_INTERNAL_SDL "Always use included SDL library" FALSE) +OPTION(AQUARIA_INTERNAL_SDL "Always use included SDL library" ${WIN32_TRUE}) if(NOT AQUARIA_INTERNAL_SDL) find_package(SDL) endif(NOT AQUARIA_INTERNAL_SDL) @@ -172,7 +183,7 @@ endif(NOT SDL_FOUND) ### OpenAL -OPTION(AQUARIA_INTERNAL_OPENAL "Always use included OpenAL library" FALSE) +OPTION(AQUARIA_INTERNAL_OPENAL "Always use included OpenAL library" ${WIN32_TRUE}) if(NOT AQUARIA_INTERNAL_OPENAL) find_package(OpenAL) endif(NOT AQUARIA_INTERNAL_OPENAL) @@ -289,6 +300,11 @@ IF(CMAKE_COMPILER_IS_GNUCC) IF(AQUARIA_GCC_HAS_STACKPROT) ADD_DEFINITIONS(-fno-stack-protector) ENDIF(AQUARIA_GCC_HAS_STACKPROT) + + # -O3 breaks on some GCC/MinGW versions, make sure CMake does not set this as default. + # Exceptions are not used, excluding support for release builds adds less bulk as well. + set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG" CACHE STRING "Flags used for release builds" FORCE) + set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG -fno-exceptions" CACHE STRING "Flags used for release builds" FORCE) # !!! FIXME: probably not safe long-term. # CMake mailing list had this hack for getting rid of -rdynamic: From 98399f6bc38d84b3494b90e41c5d480ade22e839 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Wed, 19 Jun 2013 18:35:06 +0200 Subject: [PATCH 079/103] More win32 cmake fixes, should now hopefully compile out of the box --- CMakeLists.txt | 33 +++++++++++++++++--------------- ExternalLibs/glfont2/glfont2.cpp | 18 ++++++++--------- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b7da214..8581adb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -200,19 +200,19 @@ endif (NOT OPENAL_FOUND) ################ End of external libraries -INCLUDE_DIRECTORIES(${BBGEDIR}) -INCLUDE_DIRECTORIES(${BBGEDIR}/GL) -INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIRS}) -INCLUDE_DIRECTORIES(${PNG_INCLUDE_DIR}) -INCLUDE_DIRECTORIES(${SRCDIR}) -INCLUDE_DIRECTORIES(${FTGLDIR}/include) -INCLUDE_DIRECTORIES(${FREETYPE_INCLUDE_DIRS}) -INCLUDE_DIRECTORIES(${LUA_INCLUDE_DIR}) -INCLUDE_DIRECTORIES(${OGGVORBIS_INCLUDE_DIRS}) -INCLUDE_DIRECTORIES(${SDL_INCLUDE_DIR}) -INCLUDE_DIRECTORIES(${OPENAL_INCLUDE_DIR}) -INCLUDE_DIRECTORIES(${EXTLIBDIR}) -INCLUDE_DIRECTORIES(${EXTLIBDIR}/ttvfs) +INCLUDE_DIRECTORIES("${BBGEDIR}") +INCLUDE_DIRECTORIES("${BBGEDIR}/GL") +INCLUDE_DIRECTORIES("${ZLIB_INCLUDE_DIRS}") +INCLUDE_DIRECTORIES("${PNG_INCLUDE_DIR}") +INCLUDE_DIRECTORIES("${SRCDIR}") +INCLUDE_DIRECTORIES("${FTGLDIR}/include") +INCLUDE_DIRECTORIES("${FREETYPE_INCLUDE_DIRS}") +INCLUDE_DIRECTORIES("${LUA_INCLUDE_DIR}") +INCLUDE_DIRECTORIES("${OGGVORBIS_INCLUDE_DIRS}") +INCLUDE_DIRECTORIES("${SDL_INCLUDE_DIR}") +INCLUDE_DIRECTORIES("${OPENAL_INCLUDE_DIR}") +INCLUDE_DIRECTORIES("${EXTLIBDIR}") +INCLUDE_DIRECTORIES("${EXTLIBDIR}/ttvfs") # Custom build ID: e.g. "-custom", " (my very own build)" @@ -647,12 +647,15 @@ SET(LUA_SRCS ) IF(AQUARIA_USE_VFS) - ADD_SUBDIRECTORY(${EXTLIBDIR}/ttvfs) - ADD_SUBDIRECTORY(${EXTLIBDIR}/ttvfs_zip) + ADD_SUBDIRECTORY("${EXTLIBDIR}/ttvfs") + ADD_SUBDIRECTORY("${EXTLIBDIR}/ttvfs_zip") SET(OPTIONAL_LIBS ${OPTIONAL_LIBS} "ttvfs") SET(OPTIONAL_LIBS ${OPTIONAL_LIBS} "ttvfs_zip") ENDIF(AQUARIA_USE_VFS) +IF(WIN32) + SET(OPTIONAL_LIBS ${OPTIONAL_LIBS} "ws2_32") +ENDIF(WIN32) IF(MACOSX) SET(OPTIONAL_LIBS ${OPTIONAL_LIBS} "-framework Carbon") diff --git a/ExternalLibs/glfont2/glfont2.cpp b/ExternalLibs/glfont2/glfont2.cpp index 7cff0ff..bb8e9ca 100644 --- a/ExternalLibs/glfont2/glfont2.cpp +++ b/ExternalLibs/glfont2/glfont2.cpp @@ -11,15 +11,15 @@ #include "ByteBuffer.h" using namespace std; -//OpenGL headers -/* -#ifdef _WINDOWS -#include -#endif -#include -*/ -#include "GL/gl.h" +#ifdef _WIN32 /* Stupid Windows needs to include windows.h before gl.h */ +#undef FAR +#define WIN32_LEAN_AND_MEAN +#define NOMINMAX +#include +#undef GetCharWidth +#endif +#include "gl.h" //glFont header #include "glfont2.h" @@ -232,7 +232,7 @@ int GLFont::GetCharWidth (unsigned char c) if (c == ' ' && glfont_char->dx <= 0) { GLFontChar *glfont_a = &header.chars['a' - header.start_char]; - glfont_char->dx = glfont_a->dx*0.75; + glfont_char->dx = glfont_a->dx*0.75f; glfont_char->dy = glfont_a->dy; } From 4e1c2746ef8b7315bde7dfa589a9dfbe5b1a6aa0 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Wed, 19 Jun 2013 18:44:24 +0200 Subject: [PATCH 080/103] Add support for "override" data directory (as suggested by smls). Now it loads in this order: AQUARIA_DEFAULT_DATA_DIR AQUARIA_DEFAULT_DATA_DIR/override AQUARIA_EXTRA_DATA_DIR --- BBGE/Core.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/BBGE/Core.cpp b/BBGE/Core.cpp index 5f865ce..d521236 100644 --- a/BBGE/Core.cpp +++ b/BBGE/Core.cpp @@ -4863,8 +4863,16 @@ void Core::setupFileAccess() vfs.Prepare(); - // TODO: mount and other stuff + ttvfs::VFSDir *override = vfs.GetDir("override"); + if(override) + { + debugLog("Mounting override dir..."); + override->load(true); + vfs.Mount("override", "", true); + } + + // If we ever want to read from a container... //vfs.AddArchive("aqfiles.zip", false, ""); if(_extraDataDir.length()) From 0d98efadc4721b1c6f7f7c1c4f9a0e759fc3cee0 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Wed, 19 Jun 2013 18:45:19 +0200 Subject: [PATCH 081/103] Seems this line was lost... --- BBGE/Core.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/BBGE/Core.cpp b/BBGE/Core.cpp index d521236..16af6c9 100644 --- a/BBGE/Core.cpp +++ b/BBGE/Core.cpp @@ -4876,7 +4876,10 @@ void Core::setupFileAccess() //vfs.AddArchive("aqfiles.zip", false, ""); if(_extraDataDir.length()) + { + debugLog("Mounting extra data dir: " + _extraDataDir); vfs.MountExternalPath(_extraDataDir.c_str(), "", true, true); + } debugLog("Done"); From 1bbd9e097dd0ba94fbc72f173f3e16ac71284d06 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Thu, 20 Jun 2013 04:49:20 +0200 Subject: [PATCH 082/103] Initial supported for scripted ingredients, not fully tested. This adds a few additional interface functions, to be defined in: scripts/global/cooking.lua, or _mods/XYZ/scripts/cooking.lua Added functions: cookFailure(a,b,c) - Called when no recipe could be found for ingredients a,b,c getIngredientString() - Called by the menu. Expected to return effects description for scripted ingredient.. useIngredient(name) - Called when a scripted ingredient will be eaten. Return true to eat. Use a line like this in ingredients.txt: LuaLoaf sealoaf Loaf (script) to enable calling useIngredient() upon eating. --- Aquaria/Continuity.cpp | 74 +++++++++++++++---- Aquaria/DSQ.h | 7 +- Aquaria/Game.cpp | 87 +++++++++------------- Aquaria/Game.h | 2 + Aquaria/Ingredient.cpp | 13 +--- Aquaria/SceneEditor.cpp | 8 +- Aquaria/ScriptInterface.cpp | 141 ++++++++++++++++++++++++++++++++++-- Aquaria/ScriptInterface.h | 6 ++ 8 files changed, 250 insertions(+), 88 deletions(-) diff --git a/Aquaria/Continuity.cpp b/Aquaria/Continuity.cpp index 18ee693..1a39f32 100644 --- a/Aquaria/Continuity.cpp +++ b/Aquaria/Continuity.cpp @@ -61,7 +61,7 @@ bool Continuity::isIngredientFull(IngredientData *data) { if (nocasecmp(ingredients[i]->name, data->name)==0) { - if (ingredients[i]->amount >= MAX_INGREDIENT_AMOUNT) + if (ingredients[i]->amount >= ingredients[i]->maxAmount) return true; else return false; @@ -70,22 +70,23 @@ bool Continuity::isIngredientFull(IngredientData *data) return false; } -void Continuity::pickupIngredient(IngredientData *d, int amount, bool effects) +void Continuity::pickupIngredient(IngredientData *d, int amount, bool effects, bool learn) { - learnRecipe(d->name, effects); + if(learn) + learnRecipe(d->name, effects); if (!getIngredientHeldByName(d->name)) { ingredients.push_back(d); } - if (d->amount < MAX_INGREDIENT_AMOUNT - amount) + if (d->amount < d->maxAmount - amount) { d->amount += amount; } else { - d->amount = MAX_INGREDIENT_AMOUNT; + d->amount = d->maxAmount; } } @@ -607,8 +608,10 @@ std::string Continuity::getAllIEString(IngredientData *data) return os.str(); } -void Continuity::applyIngredientEffects(IngredientData *data) +// returns true if eaten +bool Continuity::applyIngredientEffects(IngredientData *data) { + bool eaten = true; float y =0; for (int i = 0; i < data->effects.size(); i++) { @@ -841,28 +844,36 @@ void Continuity::applyIngredientEffects(IngredientData *data) // this item should only affect li if naija drops it and li eats it. } break; + case IET_SCRIPT: + { + // If this fails, it will still be eaten + if(dsq->game->cookingScript) + dsq->game->cookingScript->call("useIngredient", data->name.c_str(), &eaten); + } default: { char str[256]; sprintf((char*)&str, "ingredient effect not defined, index[%d]", int(useType)); errorLog(str); + eaten = false; } break; } } + return eaten; } std::string Continuity::getIngredientAffectsString(IngredientData *data) { - - /* - std::string str; - for (int i = 0; i < data->effects.size(); i++) + if(data->type == IET_SCRIPT) { - str += splitCamelCase(getIngredientDescription(data->effects[i].type)) + "\n"; + if(dsq->game->cookingScript) + { + std::string ret = ""; + dsq->game->cookingScript->call("getIngredientString", data->name.c_str(), &ret); + return ret; + } } - return str; - */ return getAllIEString(data); } @@ -920,6 +931,7 @@ void Continuity::loadIngredientData(const std::string &file) InStream in(file.c_str()); bool recipes = false; + bool extradata = false; while (std::getline(in, line)) { std::istringstream inLine(line); @@ -931,6 +943,11 @@ void Continuity::loadIngredientData(const std::string &file) recipes = true; break; } + else if(name == "==Extra==") + { + extradata = true; + break; + } inLine >> gfx >> type; std::getline(inLine, effects); @@ -944,7 +961,7 @@ void Continuity::loadIngredientData(const std::string &file) if (p1 != std::string::npos && p2 != std::string::npos) { effects = effects.substr(p1+1, p2-(p1+1)); - std::istringstream fxLine(effects); + SimpleIStringStream fxLine(effects.c_str(), SimpleIStringStream::REUSE); std::string bit; while (fxLine >> bit) { @@ -1032,6 +1049,10 @@ void Continuity::loadIngredientData(const std::string &file) { fx.type = IET_LI; } + else if (bit.find("script") != std::string::npos) + { + fx.type = IET_SCRIPT; + } int c = 0; while (c < bit.size()) @@ -1052,6 +1073,31 @@ void Continuity::loadIngredientData(const std::string &file) ingredientData.push_back(data); } + if(extradata) + { + while (in >> line) + { + SimpleIStringStream inLine(line.c_str(), SimpleIStringStream::REUSE); + int maxAmount = MAX_INGREDIENT_AMOUNT; + int rotKind = 1; + inLine >> name >> maxAmount >> rotKind; + if (name == "==Recipes==") + { + recipes = true; + continue; + } + IngredientData *data = getIngredientDataByName(name); + if(!data) + { + errorLog("Specifying data for undefined ingredient: " + name); + continue; + } + + data->maxAmount = maxAmount; + data->rotKind = rotKind; + } + } + if (recipes) { bool quitNext = false; diff --git a/Aquaria/DSQ.h b/Aquaria/DSQ.h index 3be5ae6..b4df465 100644 --- a/Aquaria/DSQ.h +++ b/Aquaria/DSQ.h @@ -685,6 +685,7 @@ enum IngredientEffectType IET_POISON = 17, IET_BLIND = 18, IET_ALLSTATUS = 19, + IET_SCRIPT = 20, IET_MAX }; @@ -715,9 +716,11 @@ public: std::string displayName; const IngredientType type; int amount; + int maxAmount; int held; int marked; bool sorted; + bool rotKind; bool hasIET(IngredientEffectType iet); typedef std::vector IngredientEffects; @@ -1051,7 +1054,7 @@ public: std::string getSongNameBySlot(int slot); void toggleLiCombat(bool t); - void pickupIngredient(IngredientData *i, int amount, bool effects=true); + void pickupIngredient(IngredientData *i, int amount, bool effects=true, bool learn=true); int indexOfIngredientData(const IngredientData* data) const; IngredientData *getIngredientHeldByName(const std::string &name) const; // an ingredient that the player actually has; in the ingredients list IngredientData *getIngredientDataByName(const std::string &name); // an ingredient in the general data list; ingredientData @@ -1059,7 +1062,7 @@ public: IngredientData *getIngredientHeldByIndex(int idx) const; IngredientData *getIngredientDataByIndex(int idx); - void applyIngredientEffects(IngredientData *data); + bool applyIngredientEffects(IngredientData *data); void loadIngredientData(const std::string &file); void loadIngredientDisplayNames(const std::string& file); diff --git a/Aquaria/Game.cpp b/Aquaria/Game.cpp index 5f2de4e..6e2ddfd 100644 --- a/Aquaria/Game.cpp +++ b/Aquaria/Game.cpp @@ -394,7 +394,7 @@ void FoodSlot::refresh(bool effects) { std::ostringstream os; if (i->amount > 1) - os << i->amount << "/" << MAX_INGREDIENT_AMOUNT; + os << i->amount << "/" << i->maxAmount; label->setText(os.str()); setTexture("Ingredients/" + i->gfx); renderQuad = true; @@ -456,10 +456,13 @@ void FoodSlot::eatMe() if (!ingredient->effects.empty()) { - ingredient->amount--; - dsq->continuity.applyIngredientEffects(ingredient); - dsq->continuity.removeEmptyIngredients(); - dsq->game->refreshFoodSlots(true); + bool eaten = dsq->continuity.applyIngredientEffects(ingredient); + if(eaten) + { + ingredient->amount--; + dsq->continuity.removeEmptyIngredients(); + dsq->game->refreshFoodSlots(true); + } } else { @@ -533,7 +536,7 @@ void FoodSlot::onUpdate(float dt) Vector wp = getWorldPosition(); - if ((dsq->game->lips->getWorldPosition() - getWorldPosition()).isLength2DIn(32)) + if ((dsq->game->lips->getWorldPosition() - wp).isLength2DIn(32)) { dsq->menuSelectDelay = 0.5; @@ -548,7 +551,7 @@ void FoodSlot::onUpdate(float dt) bool droppedIn = false; for (int i = 0; i < foodHolders.size(); i++) { - bool in = (foodHolders[i]->getWorldPosition() - getWorldPosition()).isLength2DIn(32); + bool in = (foodHolders[i]->getWorldPosition() - wp).isLength2DIn(32); if (in) { droppedIn = true; @@ -587,11 +590,6 @@ void FoodSlot::onUpdate(float dt) label->alpha = 1; grabTime = 0; - if (dsq->inputMode == INPUT_JOYSTICK) - { - dsq->game->adjustFoodSlotCursor(); - } - return; } else @@ -1236,6 +1234,8 @@ Game::Game() : StateObject() lastCollideMaskIndex = -1; worldPaused = false; + cookingScript = 0; + } Game::~Game() @@ -5836,41 +5836,6 @@ float Game::getHalfTimer(float mod) return halfTimer*mod; } -void Game::adjustFoodSlotCursor() -{ - // using visible slots now, don't need this atm - return; - /* - for (int i = 0; i < foodSlots.size(); i++) - { - if (foodSlots[i]->isCursorIn()) - { - if (!foodSlots[i]->getIngredient() || foodSlots[i]->getIngredient()->amount <= 0) - { - foodSlots[i]->setFocus(false); - i--; - while (i >= 0) - { - if (foodSlots[i]->getIngredient() && foodSlots[i]->getIngredient()->amount > 0) - { - //cursor->position = foodSlots[i]->getWorldPosition(); - foodSlots[i]->setFocus(true); - break; - } - i--; - } - if (i <= -1) - { - menu[5]->setFocus(true); - //cursor->position = menu[5]->getWorldPosition(); - } - } - break; - } - } - */ -} - void Game::action(int id, int state) { for (int i = 0; i < paths.size(); i++) @@ -5994,7 +5959,6 @@ void Game::action(int id, int state) if (foodSlots[i]->isCursorIn() && foodSlots[i]->getIngredient()) { foodSlots[i]->moveRight(); - adjustFoodSlotCursor(); break; } } @@ -6031,7 +5995,6 @@ void Game::action(int id, int state) if (ingrIndex >= 0) { foodSlots[ingrIndex]->discard(); - adjustFoodSlotCursor(); } } } @@ -6709,6 +6672,14 @@ void Game::applyState() musicToPlay = overrideMusic; } + if(cookingScript) + dsq->scriptInterface.closeScript(cookingScript); + + if (dsq->mod.isActive()) + cookingScript = dsq->scriptInterface.openScript(dsq->mod.getPath() + "scripts/cooking.lua", true); + else + cookingScript = dsq->scriptInterface.openScript("scripts/global/cooking.lua", true); + //INFO: this used to be here to start fading out the music // before the level had begun /* @@ -7244,7 +7215,20 @@ void Game::onCook() if (r) data = dsq->continuity.getIngredientDataByName(r->result); - else + else if(cookingScript) + { + const char *p1 = cookList[0]->name.c_str(); + const char *p2 = cookList[1]->name.c_str(); + const char *p3 = cookList.size() >= 3 ? cookList[2]->name.c_str() : ""; + std::string ingname; + cookingScript->call("cookFailure", p1, p2, p3, &ingname); + if(ingname.length()) + data = dsq->continuity.getIngredientDataByName(ingname); + if(!data) + goto endcook; + } + + if(!data) { dsq->sound->playSfx("Denied"); data = dsq->continuity.getIngredientDataByName("SeaLoaf"); @@ -7424,6 +7408,8 @@ void Game::onCook() } refreshFoodSlots(true); +endcook: + AquariaGuiElement::canDirMoveGlobal = true; isCooking = false; @@ -8740,7 +8726,6 @@ void Game::refreshFoodSlots(bool effects) { foodSlots[i]->refresh(effects); } - adjustFoodSlotCursor(); } void Game::refreshTreasureSlots() diff --git a/Aquaria/Game.h b/Aquaria/Game.h index d9c103e..3585cca 100644 --- a/Aquaria/Game.h +++ b/Aquaria/Game.h @@ -714,6 +714,8 @@ public: Ingredient *getNearestIngredient(const Vector &pos, int radius); Entity *getNearestEntity(const Vector &pos, int radius, Entity *ignore = 0, EntityType et=ET_NOTYPE, DamageType dt=DT_NONE, int lrStart=-1, int lrEnd=-1); + Script *cookingScript; + void spawnManaBall(Vector pos, float a); bool updateMusic(); std::string overrideMusic; diff --git a/Aquaria/Ingredient.cpp b/Aquaria/Ingredient.cpp index 97b9e42..f5b759d 100644 --- a/Aquaria/Ingredient.cpp +++ b/Aquaria/Ingredient.cpp @@ -22,8 +22,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "Avatar.h" IngredientData::IngredientData(const std::string &name, const std::string &gfx, IngredientType type) -: name(name), gfx(gfx), amount(0), held(0), type(type), marked(0), sorted(false) +: name(name), gfx(gfx), amount(0), maxAmount(MAX_INGREDIENT_AMOUNT), held(0), type(type), marked(0), sorted(false) , displayName(dsq->continuity.getIngredientDisplayName(name)) +, rotKind(type == IT_OIL || type == IT_EGG) { } @@ -83,15 +84,7 @@ void Ingredient::destroy() bool Ingredient::isRotKind() { - if (data) - { - if (data->type == IT_OIL || data->type == IT_EGG) - { - return false; - } - return true; - } - return false; + return data && data->rotKind; } IngredientData *Ingredient::getIngredientData() diff --git a/Aquaria/SceneEditor.cpp b/Aquaria/SceneEditor.cpp index ae8dc7a..cf173fb 100644 --- a/Aquaria/SceneEditor.cpp +++ b/Aquaria/SceneEditor.cpp @@ -3578,10 +3578,10 @@ void SceneEditor::update(float dt) (dsq->getGameCursorPosition().y - cursorOffset.y)*factor); //editingElement->scale=oldScale + add; Vector sz = oldScale + add; - if (sz.x < 64) - sz.x = 64; - if (sz.y < 64) - sz.y = 64; + if (sz.x < 32) + sz.x = 32; + if (sz.y < 32) + sz.y = 32; editingPath->rect.x1 = -sz.x/2; editingPath->rect.x2 = sz.x/2; editingPath->rect.y1 = -sz.y/2; diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 3c2b116..a9652de 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -76,6 +76,7 @@ static const char * const interfaceFunctions[] = { "activate", "animationKey", "castSong", + "cookFailure", "damage", "deathNotify", "dieEaten", @@ -84,6 +85,7 @@ static const char * const interfaceFunctions[] = { "entityDied", "exitState", "exitTimer", + "getIngredientString", "hitEntity", "hitSurface", "init", @@ -98,6 +100,7 @@ static const char * const interfaceFunctions[] = { "songNoteDone", "sporesDropped", "update", + "useIngredient", "useTreasure", NULL }; @@ -2997,11 +3000,6 @@ luaFunc(entity_followPath) luaReturnNil(); } -luaFunc(getIngredientGfx) -{ - luaReturnStr(dsq->continuity.getIngredientGfx(getString(L, 1)).c_str()); -} - luaFunc(spawnIngredient) { int times = lua_tonumber(L, 4); @@ -6728,6 +6726,13 @@ luaFunc(ing_hasIET) luaReturnBool(has); } +luaFunc(ing_getIngredientName) +{ + Ingredient *i = getIng(L, 1); + IngredientData *data = i ? i->getIngredientData() : 0; + luaReturnStr(data ? data->name.c_str() : ""); +} + luaFunc(entity_getNearestEntity) { Entity *me = entity(L); @@ -7704,6 +7709,82 @@ luaFunc(getScreenSize) luaReturnVec2(core->width, core->height); } +luaFunc(inv_isFull) +{ + IngredientData *data = dsq->continuity.getIngredientDataByName(getString(L, 1)); + bool full = false; + if(data) + full = dsq->continuity.isIngredientFull(data); + luaReturnBool(full); +} + +luaFunc(inv_getMaxAmount) +{ + IngredientData *data = dsq->continuity.getIngredientDataByName(getString(L, 1)); + luaReturnInt(data ? data->maxAmount : 0); +} + +luaFunc(inv_getAmount) +{ + IngredientData *data = dsq->continuity.getIngredientDataByName(getString(L, 1)); + luaReturnInt(data ? data->amount : 0); +} + +luaFunc(inv_add) +{ + IngredientData *data = dsq->continuity.getIngredientDataByName(getString(L, 1)); + if(data) + dsq->continuity.pickupIngredient(data, lua_tointeger(L, 2), false, false); + luaReturnNil(); +} + +luaFunc(inv_getGfx) +{ + luaReturnStr(dsq->continuity.getIngredientGfx(getString(L, 1)).c_str()); +} + +luaFunc(inv_remove) +{ + IngredientData *data = dsq->continuity.getIngredientDataByName(getString(L, 1)); + if(data && data->amount > 0) + { + data->amount--; + dsq->game->dropIngrNames.push_back(data->name); + dsq->continuity.removeEmptyIngredients(); + if(dsq->game->isInGameMenu()) + dsq->game->refreshFoodSlots(true); + } + luaReturnNil(); +} + +luaFunc(inv_getType) +{ + IngredientData *data = dsq->continuity.getIngredientDataByName(getString(L, 1)); + luaReturnInt(data ? data->type : 0); +} + +luaFunc(inv_getDisplayName) +{ + IngredientData *data = dsq->continuity.getIngredientDataByName(getString(L, 1)); + luaReturnStr(data ? data->displayName.c_str() : ""); +} + +luaFunc(inv_pickupEffect) +{ + IngredientData *data = dsq->continuity.getIngredientDataByName(getString(L, 1)); + if(data) + dsq->game->pickupIngredientEffects(data); + luaReturnNil(); +} + +luaFunc(learnRecipe) +{ + std::string name = getString(L, 1); + bool show = getBool(L, 2); + dsq->continuity.learnRecipe(name, show); + luaReturnNil(); +} + luaFunc(createDebugText) { DebugFont *txt = new DebugFont(lua_tointeger(L, 2), getString(L, 1)); @@ -7876,6 +7957,7 @@ static const struct { luaRegister(reconstructEntityGrid), luaRegister(ing_hasIET), + luaRegister(ing_getIngredientName), luaRegister(esetv), luaRegister(esetvf), @@ -8196,8 +8278,6 @@ static const struct { luaRegister(registerSporeDrop), - luaRegister(getIngredientGfx), - luaRegister(spawnIngredient), luaRegister(spawnAllIngredients), luaRegister(spawnParticleEffect), @@ -8690,6 +8770,17 @@ static const struct { luaRegister(getScreenVirtualOff), luaRegister(getScreenSize), + luaRegister(inv_isFull), + luaRegister(inv_getMaxAmount), + luaRegister(inv_getAmount), + luaRegister(inv_add), + luaRegister(inv_getGfx), + luaRegister(inv_remove), + luaRegister(inv_getType), + luaRegister(inv_getDisplayName), + luaRegister(inv_pickupEffect), + luaRegister(learnRecipe), + luaRegister(createDebugText), luaRegister(createBitmapText), luaRegister(text_setText), @@ -8746,6 +8837,7 @@ static const struct { {"entity_rotateTo", l_entity_rotate}, {"entity_setColor", l_entity_color}, {"entity_setInternalOffset", l_entity_internalOffset}, + {"getIngredientGfx", l_inv_getGfx}, {"bone_setColor", l_bone_color}, @@ -9972,6 +10064,41 @@ bool Script::call(const char *name, void *param1, void *param2, void *param3, fl return true; } +bool Script::call(const char *name, const char *param, bool *ret) +{ + lookupFunc(name); + lua_pushstring(L, param); + if (!doCall(1, 1)) + return false; + *ret = lua_toboolean(L, -1); + lua_pop(L, 1); + return true; +} + +bool Script::call(const char *name, const char *param, std::string *ret) +{ + lookupFunc(name); + lua_pushstring(L, param); + if (!doCall(1, 1)) + return false; + *ret = getString(L, -1); + lua_pop(L, 1); + return true; +} + +bool Script::call(const char *name, const char *param1, const char *param2, const char *param3, std::string *ret) +{ + lookupFunc(name); + lua_pushstring(L, param1); + lua_pushstring(L, param2); + lua_pushstring(L, param3); + if (!doCall(3, 1)) + return false; + *ret = getString(L, -1); + lua_pop(L, 1); + return true; +} + int Script::callVariadic(const char *name, lua_State *fromL, int nparams, void *param) { int oldtop = lua_gettop(L); diff --git a/Aquaria/ScriptInterface.h b/Aquaria/ScriptInterface.h index bf23dca..2815764 100644 --- a/Aquaria/ScriptInterface.h +++ b/Aquaria/ScriptInterface.h @@ -60,6 +60,12 @@ public: bool call(const char *name, void *param1, void *param2, void *param3, void *param4); // boolean = function(pointer, pointer, pointer, number, number, number, number, pointer) bool call(const char *name, void *param1, void *param2, void *param3, float param4, float param5, float param6, float param7, void *param8, bool *ret1); + // boolean = function(string) + bool call(const char *name, const char *param, bool *ret); + // string = function(string) + bool call(const char *name, const char *param, std::string *ret); + // string = function(string, string, string) + bool call(const char *name, const char *param1, const char *param2, const char *param3, std::string *ret); // function(pointer, ...) - anything that is already on the stack is forwarded. Results are left on the stack. // Returns how many values the called function returned, or -1 in case of error. int callVariadic(const char *name, lua_State *L, int nparams, void *param); From 25727244ad2437ebf424c983f6f04ef4789c45cb Mon Sep 17 00:00:00 2001 From: fgenesis Date: Thu, 20 Jun 2013 05:15:07 +0200 Subject: [PATCH 083/103] Little correction to prev commit Only handle cooking failure if the function call was successful. Otherwise, fallback to SeaLoaf. --- Aquaria/Game.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Aquaria/Game.cpp b/Aquaria/Game.cpp index 6e2ddfd..3270fbc 100644 --- a/Aquaria/Game.cpp +++ b/Aquaria/Game.cpp @@ -7221,11 +7221,13 @@ void Game::onCook() const char *p2 = cookList[1]->name.c_str(); const char *p3 = cookList.size() >= 3 ? cookList[2]->name.c_str() : ""; std::string ingname; - cookingScript->call("cookFailure", p1, p2, p3, &ingname); - if(ingname.length()) - data = dsq->continuity.getIngredientDataByName(ingname); - if(!data) - goto endcook; + if(cookingScript->call("cookFailure", p1, p2, p3, &ingname)) + { + if(ingname.length()) + data = dsq->continuity.getIngredientDataByName(ingname); + if(!data) + goto endcook; + } } if(!data) From 54d609a8b507ddcab2127b88735e70adf07c1091 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Thu, 20 Jun 2013 20:01:51 +0200 Subject: [PATCH 084/103] Make avatar respect maxspeed lerp, allow changing speed multiplier via script. Some extra functions. Add one additional not-timed speed multiplier that also ignores influence by currents. Lua functions added: - avatar_setSpeedMult(num, time) - avatar_setSpeedMult2(num) - avatar_getSpeedMult() - avatar_getSpeedMult2() - entity_isInCurrent(entity) - entity_getNumTargetPoints(entity) --- Aquaria/Avatar.cpp | 10 +++------- Aquaria/Continuity.cpp | 1 + Aquaria/DSQ.h | 2 ++ Aquaria/ScriptInterface.cpp | 40 +++++++++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 7 deletions(-) diff --git a/Aquaria/Avatar.cpp b/Aquaria/Avatar.cpp index 1abb763..c597fd4 100644 --- a/Aquaria/Avatar.cpp +++ b/Aquaria/Avatar.cpp @@ -4911,13 +4911,9 @@ void Avatar::clampVelocity() } - setMaxSpeed(currentMaxSpeed * useSpeedMult); - //float cheatLen = vel.getSquaredLength2D(); - vel.capLength2D(getMaxSpeed()); - /* - if (cheatLen > sqr(getMaxSpeed())) - vel.setLength2D(getMaxSpeed()); - */ + setMaxSpeed(currentMaxSpeed * useSpeedMult * dsq->continuity.speedMult2); + + vel.capLength2D(getMaxSpeed() * maxSpeedLerp.x); } void Avatar::activateAura(AuraType aura) diff --git a/Aquaria/Continuity.cpp b/Aquaria/Continuity.cpp index 1a39f32..ed509af 100644 --- a/Aquaria/Continuity.cpp +++ b/Aquaria/Continuity.cpp @@ -3209,6 +3209,7 @@ void Continuity::reset() //worldMapTiles.clear(); speedMult = biteMult = fishPoison = defenseMult = 1; + speedMult2 = 1; poison = 0; energyMult = 0; light = petPower = 0; diff --git a/Aquaria/DSQ.h b/Aquaria/DSQ.h index b4df465..777a11b 100644 --- a/Aquaria/DSQ.h +++ b/Aquaria/DSQ.h @@ -1102,6 +1102,8 @@ public: Timer energyTimer, poisonTimer, poisonBitTimer; Timer webTimer, webBitTimer, lightTimer, petPowerTimer; + float speedMult2; + void eatBeast(const EatData &eatData); void removeNaijaEat(int idx); void removeLastNaijaEat(); diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index a9652de..856f1fb 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -2898,6 +2898,28 @@ luaFunc(avatar_getSpellCharge) luaReturnNum(dsq->game->avatar->state.spellCharge); } +luaFunc(avatar_setSpeedMult) +{ + dsq->continuity.setSpeedMultiplier(lua_tonumber(L, 1), lua_tonumber(L, 2)); + luaReturnNil(); +} + +luaFunc(avatar_setSpeedMult2) +{ + dsq->continuity.speedMult2 = lua_tonumber(L, 1); + luaReturnNil(); +} + +luaFunc(avatar_getSpeedMult) +{ + luaReturnNum(dsq->continuity.speedMult); +} + +luaFunc(avatar_getSpeedMult2) +{ + luaReturnNum(dsq->continuity.speedMult2); +} + luaFunc(jumpState) { dsq->enqueueJumpState(getString(L, 1), getBool(L, 2)); @@ -3208,6 +3230,11 @@ luaFunc(entity_checkSplash) luaReturnBool(ret); } +luaFunc(entity_isInCurrent) +{ + Entity *e = entity(L); + luaReturnBool(e ? e->isInCurrent() : false); +} luaFunc(entity_isUnderWater) { @@ -5609,6 +5636,12 @@ luaFunc(entity_getRandomTargetPoint) luaReturnNum(idx); } +luaFunc(entity_getNumTargetPoints) +{ + Entity *e = entity(L); + luaReturnInt(e ? e->getNumTargetPoints() : 0); +} + luaFunc(playVisualEffect) { Entity *target = NULL; @@ -8066,9 +8099,11 @@ static const struct { luaRegister(entity_isUnderWater), luaRegister(entity_checkSplash), + luaRegister(entity_isInCurrent), luaRegister(entity_getRandomTargetPoint), luaRegister(entity_getTargetPoint), + luaRegister(entity_getNumTargetPoints), luaRegister(entity_setTargetRange), @@ -8453,6 +8488,11 @@ static const struct { luaRegister(avatar_setBlockSinging), luaRegister(avatar_isBlockSinging), + luaRegister(avatar_setSpeedMult), + luaRegister(avatar_setSpeedMult2), + luaRegister(avatar_getSpeedMult), + luaRegister(avatar_getSpeedMult2), + luaRegister(avatar_toggleMovement), From 416b521a12c935d27db2c9fe9904bece5a11533a Mon Sep 17 00:00:00 2001 From: fgenesis Date: Thu, 20 Jun 2013 21:39:17 +0200 Subject: [PATCH 085/103] Initial support for loading android save files. Apparently there is a new map with the index 55 -- a related entry was added to the worldmap.txt file to prevent data loss, just in case. field is not yet handled missing. Hopefully the resulting format can be loaded on android without problems, especially because both "ingr" and "ingrNames" fields appear in the StartData tag now. --- Aquaria/Continuity.cpp | 37 ++++++++++++++++++++++++++- files/data/worldmap.txt | 56 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 files/data/worldmap.txt diff --git a/Aquaria/Continuity.cpp b/Aquaria/Continuity.cpp index ed509af..87514f2 100644 --- a/Aquaria/Continuity.cpp +++ b/Aquaria/Continuity.cpp @@ -2461,6 +2461,7 @@ void Continuity::saveFile(int slot, Vector position, unsigned char *scrShotData, startData.SetAttribute("scene", dsq->game->sceneName); startData.SetAttribute("exp", dsq->continuity.exp); startData.SetAttribute("h", dsq->continuity.maxHealth); + // ANDROID TODO: "ch" field startData.SetAttribute("naijaModel", dsq->continuity.naijaModel); startData.SetAttribute("costume", dsq->continuity.costume); startData.SetAttribute("form", dsq->continuity.form); @@ -2479,6 +2480,16 @@ void Continuity::saveFile(int slot, Vector position, unsigned char *scrShotData, } startData.SetAttribute("songs", os2.str()); + // new format as used by android version + std::ostringstream ingrNames; + for (int i = 0; i < ingredients.size(); i++) + { + IngredientData *data = ingredients[i]; + ingrNames << data->name << " " << data->amount << " "; + } + startData.SetAttribute("ingrNames", ingrNames.str()); + + // for compatibility with older versions std::ostringstream ingrOs; for (int i = 0; i < ingredients.size(); i++) { @@ -2551,6 +2562,9 @@ std::string Continuity::getSaveFileName(int slot, const std::string &pfix) void Continuity::loadFileData(int slot, TiXmlDocument &doc) { std::string teh_file = dsq->continuity.getSaveFileName(slot, "aqs"); + if(!exists(teh_file)) + teh_file = dsq->continuity.getSaveFileName(slot, "bin"); + if (exists(teh_file)) { unsigned long size = 0; @@ -2810,7 +2824,9 @@ void Continuity::loadFile(int slot) if (!tile) { - errorLog("tile dummy"); + std::ostringstream os; + os << "tile dummy: dropping data for worldmap tile index " << idx; + debugLog(os.str()); tile = &dummy; } @@ -2853,6 +2869,23 @@ void Continuity::loadFile(int slot) dsq->continuity.form = FormType(atoi(startData->Attribute("form"))); } + if (startData->Attribute("ingrNames")) + { + std::istringstream is(startData->Attribute("ingrNames")); + std::string name; + while (is >> name) + { + int amount=0; + is >> amount; + IngredientData *data = getIngredientDataByName(name); + if (data) + { + data->amount = 0; + pickupIngredient(data, amount, false); + } + } + } + if (startData->Attribute("ingr")) { std::istringstream is(startData->Attribute("ingr")); @@ -2916,6 +2949,8 @@ void Continuity::loadFile(int slot) } } + // TODO ANDROID: "ch" field + if (startData->Attribute("h")) { int read = atoi(startData->Attribute("h")); diff --git a/files/data/worldmap.txt b/files/data/worldmap.txt new file mode 100644 index 0000000..089a59e --- /dev/null +++ b/files/data/worldmap.txt @@ -0,0 +1,56 @@ +0 1008 MAINAREA 0 5 -0.667596 -1.2 1 1 +1 1006 NAIJACAVE 1 2.5 398.484 -188.954 1 1 +2 1005 VEDHACAVE 1 2 14.4108 -19.2 1 0.36 +3 1015 ABYSS01 0 5 319.096 639.447 0 1 +4 1015 ABYSS03 0 5 638.433 637.068 0 1 +5 1009 OPENWATER02 0 5 319.17 -0.0658667 0 1 +6 1009 OPENWATER03 0 5 638.633 -0.399733 0 1 +7 1009 OPENWATER04 0 5 319.025 319.734 0 1 +8 1009 OPENWATER06 0 5 638.63 317.827 0 1 +9 1007 SONGCAVE02 1 2 128.578 159.092 0 0.387867 +10 1007 SONGCAVE 1 5 118.842 147.471 0 0.599717 +11 1014 VEIL01 0 5 638.579 -639.354 0 1 +12 1014 VEIL02 0 5 958.132 -639.401 0 1 +13 1009 VEIL03 0 5 638.221 -319.998 0 1 +14 1010 FOREST02 0 5 -0.0961994 -639.541 0 1 +15 1010 FOREST03 0 5 319.841 -639.163 0 1 +16 1010 FOREST04 0 5 -0.0881051 -320.302 0 1 +17 1010 FOREST05 0 5 319.692 -320.261 0 1 +18 1025 FORESTSPRITECAVE 1 2 295.55 -631.495 0 0.45125 +19 1026 FISHCAVE 1 2 -18.0111 -342.826 0 0.51796 +20 1013 SUNTEMPLE 1 5 961.345 -687.826 0 0.22643 +21 1016 SUNKENCITY01 1 2.5 -40.8617 906.841 0 1 +22 1016 SUNKENCITY02 1 5 116.437 802.774 0 1 +23 1000 BOILERROOM 1 2 49.228 940.225 0 1 +24 1004 ENERGYTEMPLE01 1 2.5 -168.536 -8.8143 0 1 +25 1004 ENERGYTEMPLE02 1 0.5 -232.22 -0.657245 0 1 +26 1004 ENERGYTEMPLE03 1 2.5 -110.834 56.4481 0 1 +27 1004 ENERGYTEMPLE04 1 4 -246.593 145.535 0 1 +28 1004 ENERGYTEMPLE05 1 2 -207.873 175.936 0 1 +29 1004 ENERGYTEMPLE06 1 2 -225.836 41.8167 0 1 +30 1011 MITHALAS01 0 5 958.305 -0.399733 0 1 +31 1011 MITHALAS02 1 5 1178.23 40.9613 0 1 +32 1012 CATHEDRAL02 1 5 1458.63 70.988 0 1 +33 1012 CATHEDRAL03 1 5 1491.23 315.666 0 1 +34 1012 CATHEDRAL04 1 5 1231.44 457.454 0 1 +35 1029 LICAVE 1 2 796.398 -663.693 0 0.500888 +36 1013 SUNWORMTEST 1 4 987.255 -699.643 0 0.213937 +37 1010 TREE02 0 2 -11.9703 -830.088 0 1 +38 1028 SEAHORSE 1 5 803.549 308.257 0 1 +39 1027 TURTLECAVE 1 5 371.817 -730.55 0 1 +40 1019 ICECAVE 1 5 917.784 686.531 0 1 +41 1002 FROZENVEIL 0 5 1646.98 -590.166 0 1 +42 1003 BUBBLECAVE02 1 5 1841.07 -709.693 0 1 +43 1024 MERMOGCAVE 1 2 482.591 -781.434 0 1 +44 1023 TRAININGCAVE 1 4 247.338 -85.5629 1 1 +45 1021 FINAL01 1 5 398.925 949.441 0 1 +46 1021 FINAL02 1 5 79.3004 949.894 0 1 +47 1021 FINAL03 1 5 718.257 958.177 0 1 +48 1021 FINAL04 1 5 402.406 1269.56 0 1 +49 1021 FINALBOSS 1 5 667.938 1486.98 0 1 +50 1018 OCTOCAVE 1 2 834.888 -606.756 0 0.831527 +51 1009 OPENWATER05 0 5 270.156 327.801 0 1.01408 +52 1020 THIRTEENLAIR 1 5 417.62 -121.396 0 1 +53 1030 KINGJELLYCAVE 1 2 328.989 605.32 0 0.356187 +54 1020 WEIRDCAVE 1 0.5 548.557 709.137 0 1 +55 19 UNKNOWN 0 1 0 0 0 1 From fe5f6faa466d67525297456567cba1e68c8446d8 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Fri, 21 Jun 2013 00:40:19 +0200 Subject: [PATCH 086/103] More save data compat with android version (world map gem data) --- Aquaria/Continuity.cpp | 81 ++++++++++++++++++++++++++++++++++++++---- Aquaria/DSQ.h | 1 + 2 files changed, 75 insertions(+), 7 deletions(-) diff --git a/Aquaria/Continuity.cpp b/Aquaria/Continuity.cpp index 87514f2..8cff2f3 100644 --- a/Aquaria/Continuity.cpp +++ b/Aquaria/Continuity.cpp @@ -2356,15 +2356,32 @@ void Continuity::saveFile(int slot, Vector position, unsigned char *scrShotData, if (hasUserString) os << spacesToUnderscores((*i).userString) << " "; - - /* - std::ostringstream os2; - os2 << "Saving a Gem called [" << (*i).name << "] with userString [" << (*i).userString << "] pos (" << (*i).pos.x << ", " << (*i).pos.y << ")\n"; - os2 << os.str() << "\n"; - debugLog(os2.str()); - */ } gems.SetAttribute("c", os.str()); + + // This is the format used in the android version. Keeping this commented out for now, + // but it should be used instead of the code above in some time -- FG + os.str(""); + bool hasMapName = false; + os << this->gems.size() << " "; + for (Gems::iterator i = this->gems.begin(); i != this->gems.end(); i++) + { + os << (*i).name << " "; + hasMapName = !(*i).mapName.empty(); + os << hasMapName << " "; + if(hasMapName) + os << (*i).mapName << " "; // warning: this will fail to load if the map name contains whitespace + + os << (*i).pos.x << " " << (*i).pos.y << " "; + os << (*i).canMove << " "; + + hasUserString = !(*i).userString.empty(); + os << hasUserString << " "; + if (hasUserString) + os << spacesToUnderscores((*i).userString) << " "; + } + gems.SetAttribute("d", os.str()); + } doc.InsertEndChild(gems); @@ -2748,6 +2765,7 @@ void Continuity::loadFile(int slot) this->gems.push_back(g); } } + // num [name mapX mapY canMove hasUserString (userString)] else if (gems->Attribute("c")) { std::string s = gems->Attribute("c"); @@ -2785,6 +2803,54 @@ void Continuity::loadFile(int slot) g.userString = underscoresToSpaces(g.userString); this->gems.push_back(g); + std::ostringstream os; + os << "Loading a Gem called [" << g.name << "] with userString [" << g.userString << "] pos (" << g.pos.x << ", " << g.pos.y << ")\n"; + debugLog(os.str()); + } + } + // num [name hasMapName (mapName) mapX mapY canMove hasUserString (userString)] + else if (gems->Attribute("d")) + { + std::string s = gems->Attribute("d"); + std::istringstream is(s); + + int num = 0; + is >> num; + + bool hasUserString = false; + bool hasMapName = false; + GemData g; + + std::ostringstream os; + os << "continuity num: [" << num << "]" << std::endl; + os << "data: [" << s << "]" << std::endl; + debugLog(os.str()); + + for (int i = 0; i < num; i++) + { + g.pos = Vector(0,0,0); + g.canMove = false; + g.userString = ""; + g.mapName = ""; + + hasUserString=false; + hasMapName = false; + + is >> g.name; + is >> hasMapName; + if(hasMapName) + is >> g.mapName; + + is >> g.pos.x >> g.pos.y; + is >> g.canMove; + is >> hasUserString; + + if (hasUserString) + is >> g.userString; + + g.userString = underscoresToSpaces(g.userString); + this->gems.push_back(g); + std::ostringstream os; os << "Loading a Gem called [" << g.name << "] with userString [" << g.userString << "] pos (" << g.pos.x << ", " << g.pos.y << ")\n"; debugLog(os.str()); @@ -3134,6 +3200,7 @@ GemData *Continuity::pickupGem(std::string name, bool effects) { GemData g; g.name = name; + g.mapName = dsq->game->sceneName; int sz = gems.size(); //HACK: (hacky) using effects to determine the starting position of the gem diff --git a/Aquaria/DSQ.h b/Aquaria/DSQ.h index 777a11b..3886e1d 100644 --- a/Aquaria/DSQ.h +++ b/Aquaria/DSQ.h @@ -618,6 +618,7 @@ struct GemData GemData() { canMove=false; } std::string name; std::string userString; + std::string mapName; bool canMove; Vector pos; }; From 46516eefc8594f35f57c561e2f8841bb27f7cc64 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Fri, 21 Jun 2013 00:41:07 +0200 Subject: [PATCH 087/103] ooops --- Aquaria/Continuity.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Aquaria/Continuity.cpp b/Aquaria/Continuity.cpp index 8cff2f3..11a9e39 100644 --- a/Aquaria/Continuity.cpp +++ b/Aquaria/Continuity.cpp @@ -2361,6 +2361,7 @@ void Continuity::saveFile(int slot, Vector position, unsigned char *scrShotData, // This is the format used in the android version. Keeping this commented out for now, // but it should be used instead of the code above in some time -- FG + /* os.str(""); bool hasMapName = false; os << this->gems.size() << " "; @@ -2381,6 +2382,7 @@ void Continuity::saveFile(int slot, Vector position, unsigned char *scrShotData, os << spacesToUnderscores((*i).userString) << " "; } gems.SetAttribute("d", os.str()); + */ } doc.InsertEndChild(gems); From 2c99f010a475ac17aecd7cacf994cc322fea6e78 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Fri, 21 Jun 2013 03:33:35 +0200 Subject: [PATCH 088/103] Fixes to scripted ingredients, now it actually works --- Aquaria/Continuity.cpp | 77 +++++++++++++++++++++++------------------- Aquaria/DSQ.cpp | 1 + Aquaria/DSQ.h | 1 + 3 files changed, 45 insertions(+), 34 deletions(-) diff --git a/Aquaria/Continuity.cpp b/Aquaria/Continuity.cpp index 11a9e39..3a1ed8c 100644 --- a/Aquaria/Continuity.cpp +++ b/Aquaria/Continuity.cpp @@ -850,6 +850,7 @@ bool Continuity::applyIngredientEffects(IngredientData *data) if(dsq->game->cookingScript) dsq->game->cookingScript->call("useIngredient", data->name.c_str(), &eaten); } + break; default: { char str[256]; @@ -921,6 +922,43 @@ void Continuity::clearIngredientData() ingredientData.clear(); } +void Continuity::loadIngredientData() +{ + if(ingredients.size()) + { + debugLog("Can't reload ingredient data, inventory is not empty"); + return; // ... because otherwise there would be dangling pointers and it would crash. + } + + clearIngredientData(); + ingredientDescriptions.clear(); + ingredientDisplayNames.clear(); + recipes.clear(); + + loadIngredientDisplayNames("data/ingredientnames.txt"); + + std::string fname = localisePath("data/ingredientnames.txt"); + loadIngredientDisplayNames(fname); + + if(dsq->mod.isActive()) + { + fname = localisePath(dsq->mod.getPath() + "ingredientnames.txt", dsq->mod.getPath()); + loadIngredientDisplayNames(fname); + } + + if(dsq->mod.isActive()) + { + //load mod ingredients + loadIngredientData(dsq->mod.getPath() + "ingredients.txt"); + } + + //load ingredients for the main game + if(ingredientData.empty() && recipes.empty()) + { + loadIngredientData("data/ingredients.txt"); + } +} + void Continuity::loadIngredientData(const std::string &file) { std::string line, name, gfx, type, effects; @@ -961,7 +999,7 @@ void Continuity::loadIngredientData(const std::string &file) if (p1 != std::string::npos && p2 != std::string::npos) { effects = effects.substr(p1+1, p2-(p1+1)); - SimpleIStringStream fxLine(effects.c_str(), SimpleIStringStream::REUSE); + std::istringstream fxLine(effects); std::string bit; while (fxLine >> bit) { @@ -1075,7 +1113,7 @@ void Continuity::loadIngredientData(const std::string &file) if(extradata) { - while (in >> line) + while (std::getline(in, line)) { SimpleIStringStream inLine(line.c_str(), SimpleIStringStream::REUSE); int maxAmount = MAX_INGREDIENT_AMOUNT; @@ -1084,7 +1122,7 @@ void Continuity::loadIngredientData(const std::string &file) if (name == "==Recipes==") { recipes = true; - continue; + break; } IngredientData *data = getIngredientDataByName(name); if(!data) @@ -3343,40 +3381,11 @@ void Continuity::reset() worldMap.load(); - ingredients.clear(); naijaEats.clear(); - foodSortType = 0; + ingredients.clear(); - //load ingredients - - ingredientDisplayNames.clear(); - - loadIngredientDisplayNames("data/ingredientnames.txt"); - - std::string fname = localisePath("data/ingredientnames.txt"); - loadIngredientDisplayNames(fname); - - if(dsq->mod.isActive()) - { - fname = localisePath(dsq->mod.getPath() + "ingredientnames.txt", dsq->mod.getPath()); - loadIngredientDisplayNames(fname); - } - - ingredientDescriptions.clear(); - ingredientData.clear(); - recipes.clear(); - - if(dsq->mod.isActive()) - { - //load mod ingredients - loadIngredientData(dsq->mod.getPath() + "ingredients.txt"); - } - - //load ingredients for the main game - if(ingredientData.empty() && recipes.empty()) { - loadIngredientData("data/ingredients.txt"); - } + loadIngredientData(); // must be after clearing ingredients loadPetData(); diff --git a/Aquaria/DSQ.cpp b/Aquaria/DSQ.cpp index 31f1b97..cfa6aca 100644 --- a/Aquaria/DSQ.cpp +++ b/Aquaria/DSQ.cpp @@ -614,6 +614,7 @@ void DSQ::debugMenu() core->afterEffectManager->loadShaders(); } dsq->user.load(); + dsq->continuity.loadIngredientData(); } else if (c == '2') { diff --git a/Aquaria/DSQ.h b/Aquaria/DSQ.h index 3886e1d..b4a6461 100644 --- a/Aquaria/DSQ.h +++ b/Aquaria/DSQ.h @@ -1065,6 +1065,7 @@ public: bool applyIngredientEffects(IngredientData *data); + void loadIngredientData(); void loadIngredientData(const std::string &file); void loadIngredientDisplayNames(const std::string& file); bool hasIngredients() const { return !ingredients.empty(); } From 8da8b5462bc1235ae1a2f2d93a76cca1bc61beda Mon Sep 17 00:00:00 2001 From: fgenesis Date: Fri, 21 Jun 2013 20:35:24 +0200 Subject: [PATCH 089/103] Remove unnecessary exception handling. Hopefully fixes build on linux. --- BBGE/Core.cpp | 11 +- BBGE/Resource.h | 4 - BBGE/Shader.cpp | 232 ++++++++++++++++++++---------------------- BBGE/StateManager.cpp | 13 +-- 4 files changed, 116 insertions(+), 144 deletions(-) diff --git a/BBGE/Core.cpp b/BBGE/Core.cpp index 16af6c9..ac767ce 100644 --- a/BBGE/Core.cpp +++ b/BBGE/Core.cpp @@ -3956,15 +3956,8 @@ void Core::clearResources() { deletedResources.push_back (resources[i]); Resource *r = resources[i]; - try - { - r->destroy(); - delete r; - } - catch(...) - { - errorLog("Resource could not be deleted " + resourceNames[i]); - } + r->destroy(); + delete r; } } resourceNames.clear(); diff --git a/BBGE/Resource.h b/BBGE/Resource.h index 6de0875..5ea7f6d 100644 --- a/BBGE/Resource.h +++ b/BBGE/Resource.h @@ -45,10 +45,6 @@ public: ref--; if (ref == 0) destroy(); - /* - else if (ref < 0) - throw std::exception("ref count out of bounds < 0"); - */ } int getRef() { return ref; } std::string name; diff --git a/BBGE/Shader.cpp b/BBGE/Shader.cpp index 90c7c5e..65ca1c1 100644 --- a/BBGE/Shader.cpp +++ b/BBGE/Shader.cpp @@ -260,130 +260,122 @@ void Shader::load(const std::string &file, const std::string &fragFile) g_location_mode = 0; g_location_value = 0; - try + debugLog("Shader::load 1"); + this->vertFile = file; + this->fragFile = fragFile; + // + // If the required extension is present, get the addresses of its + // functions that we wish to use... + // + + const char *vertexShaderStrings[1]; + const char *fragmentShaderStrings[1]; + GLint bVertCompiled; + GLint bFragCompiled; + GLint bLinked; + char str[4096]; + + // + // Create the vertex shader... + // + + debugLog("Shader::load 2"); + + g_vertexShader = glCreateShaderObjectARB( GL_VERTEX_SHADER_ARB ); + + unsigned char *vertexShaderAssembly = readShaderFile( file.c_str() ); + vertexShaderStrings[0] = (char*)vertexShaderAssembly; + glShaderSourceARB( g_vertexShader, 1, vertexShaderStrings, NULL ); + glCompileShaderARB( g_vertexShader); + delete[] vertexShaderAssembly; + + glGetObjectParameterivARB( g_vertexShader, GL_OBJECT_COMPILE_STATUS_ARB, + &bVertCompiled ); + if( bVertCompiled == false ) + //if (true) { - - debugLog("Shader::load 1"); - this->vertFile = file; - this->fragFile = fragFile; - // - // If the required extension is present, get the addresses of its - // functions that we wish to use... - // - - const char *vertexShaderStrings[1]; - const char *fragmentShaderStrings[1]; - GLint bVertCompiled; - GLint bFragCompiled; - GLint bLinked; - char str[4096]; - - // - // Create the vertex shader... - // - - debugLog("Shader::load 2"); - - g_vertexShader = glCreateShaderObjectARB( GL_VERTEX_SHADER_ARB ); - - unsigned char *vertexShaderAssembly = readShaderFile( file.c_str() ); - vertexShaderStrings[0] = (char*)vertexShaderAssembly; - glShaderSourceARB( g_vertexShader, 1, vertexShaderStrings, NULL ); - glCompileShaderARB( g_vertexShader); - delete[] vertexShaderAssembly; - - glGetObjectParameterivARB( g_vertexShader, GL_OBJECT_COMPILE_STATUS_ARB, - &bVertCompiled ); - if( bVertCompiled == false ) - //if (true) - { - glGetInfoLogARB(g_vertexShader, sizeof(str), NULL, str); - std::ostringstream os; - os << "Vertex Shader Compile Error: " << str; - debugLog(os.str()); - return; - } - - // - // Create the fragment shader... - // - - debugLog("Shader::load 3"); - - g_fragmentShader = glCreateShaderObjectARB( GL_FRAGMENT_SHADER_ARB ); - - unsigned char *fragmentShaderAssembly = readShaderFile( fragFile.c_str() ); - fragmentShaderStrings[0] = (char*)fragmentShaderAssembly; - glShaderSourceARB( g_fragmentShader, 1, fragmentShaderStrings, NULL ); - glCompileShaderARB( g_fragmentShader ); - delete[] fragmentShaderAssembly; - - glGetObjectParameterivARB( g_fragmentShader, GL_OBJECT_COMPILE_STATUS_ARB, - &bFragCompiled ); - if( bFragCompiled == false ) - { - glGetInfoLogARB( g_fragmentShader, sizeof(str), NULL, str ); - std::ostringstream os; - os << "Fragment Shader Compile Error: " << str; - debugLog(os.str()); - return; - } - - debugLog("Shader::load 4"); - - // - // Create a program object and attach the two compiled shaders... - // - - - g_programObj = glCreateProgramObjectARB(); - - if (!g_programObj || !g_vertexShader || !g_fragmentShader) - { - debugLog("programObj / vertexShader / fragmentShader problem"); - return; - } - - glAttachObjectARB( g_programObj, g_vertexShader ); - glAttachObjectARB( g_programObj, g_fragmentShader ); - - // - // Link the program object and print out the info log... - // - - glLinkProgramARB( g_programObj ); - glGetObjectParameterivARB( g_programObj, GL_OBJECT_LINK_STATUS_ARB, &bLinked ); - - debugLog("Shader::load 5"); - - if( bLinked == false ) - { - glGetInfoLogARB( g_programObj, sizeof(str), NULL, str ); - std::ostringstream os; - os << "Shader Linking Error: " << str; - debugLog(os.str()); - return; - } - - // - // Locate some parameters by name so we can set them later... - // - - debugLog("Shader::load 6"); - - g_location_texture = glGetUniformLocationARB( g_programObj, "tex" ); - g_location_mode = glGetUniformLocationARB( g_programObj, "mode" ); - g_location_value = glGetUniformLocationARB( g_programObj, "value" ); - - debugLog("Shader::load 7"); - - loaded = true; + glGetInfoLogARB(g_vertexShader, sizeof(str), NULL, str); + std::ostringstream os; + os << "Vertex Shader Compile Error: " << str; + debugLog(os.str()); + return; } - catch(...) + + // + // Create the fragment shader... + // + + debugLog("Shader::load 3"); + + g_fragmentShader = glCreateShaderObjectARB( GL_FRAGMENT_SHADER_ARB ); + + unsigned char *fragmentShaderAssembly = readShaderFile( fragFile.c_str() ); + fragmentShaderStrings[0] = (char*)fragmentShaderAssembly; + glShaderSourceARB( g_fragmentShader, 1, fragmentShaderStrings, NULL ); + glCompileShaderARB( g_fragmentShader ); + delete[] fragmentShaderAssembly; + + glGetObjectParameterivARB( g_fragmentShader, GL_OBJECT_COMPILE_STATUS_ARB, + &bFragCompiled ); + if( bFragCompiled == false ) { - debugLog("caught exception in shader::load"); - loaded = false; + glGetInfoLogARB( g_fragmentShader, sizeof(str), NULL, str ); + std::ostringstream os; + os << "Fragment Shader Compile Error: " << str; + debugLog(os.str()); + return; } + + debugLog("Shader::load 4"); + + // + // Create a program object and attach the two compiled shaders... + // + + + g_programObj = glCreateProgramObjectARB(); + + if (!g_programObj || !g_vertexShader || !g_fragmentShader) + { + debugLog("programObj / vertexShader / fragmentShader problem"); + return; + } + + glAttachObjectARB( g_programObj, g_vertexShader ); + glAttachObjectARB( g_programObj, g_fragmentShader ); + + // + // Link the program object and print out the info log... + // + + glLinkProgramARB( g_programObj ); + glGetObjectParameterivARB( g_programObj, GL_OBJECT_LINK_STATUS_ARB, &bLinked ); + + debugLog("Shader::load 5"); + + if( bLinked == false ) + { + glGetInfoLogARB( g_programObj, sizeof(str), NULL, str ); + std::ostringstream os; + os << "Shader Linking Error: " << str; + debugLog(os.str()); + return; + } + + // + // Locate some parameters by name so we can set them later... + // + + debugLog("Shader::load 6"); + + g_location_texture = glGetUniformLocationARB( g_programObj, "tex" ); + g_location_mode = glGetUniformLocationARB( g_programObj, "mode" ); + g_location_value = glGetUniformLocationARB( g_programObj, "value" ); + + debugLog("Shader::load 7"); + + loaded = true; + #endif debugLog("End Shader::load()"); } diff --git a/BBGE/StateManager.cpp b/BBGE/StateManager.cpp index e82aefb..8845e4f 100644 --- a/BBGE/StateManager.cpp +++ b/BBGE/StateManager.cpp @@ -122,19 +122,10 @@ void StateData::eraseRenderObjects() for (int i = 0; i < renderObjects.size(); i++) { RenderObject *r = renderObjects[i]; - //try + if (r && !r->isDead()) { - if (r && !r->isDead()) - { - core->enqueueRenderObjectDeletion(renderObjects[i]); - } + core->enqueueRenderObjectDeletion(renderObjects[i]); } - /* - catch(...) - { - debugLog("Caught exception in StateData::eraseRenderObjects"); - } - */ } renderObjects.clear(); } From 211eb80c0aad00f86647e8ac419ca02ceaa62da6 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sat, 22 Jun 2013 23:51:29 +0200 Subject: [PATCH 090/103] Fix typo setting ingredient rotKind default value to the opposite of what it should be --- Aquaria/Ingredient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aquaria/Ingredient.cpp b/Aquaria/Ingredient.cpp index f5b759d..ef791f0 100644 --- a/Aquaria/Ingredient.cpp +++ b/Aquaria/Ingredient.cpp @@ -24,7 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. IngredientData::IngredientData(const std::string &name, const std::string &gfx, IngredientType type) : name(name), gfx(gfx), amount(0), maxAmount(MAX_INGREDIENT_AMOUNT), held(0), type(type), marked(0), sorted(false) , displayName(dsq->continuity.getIngredientDisplayName(name)) -, rotKind(type == IT_OIL || type == IT_EGG) +, rotKind(!(type == IT_OIL && type == IT_EGG)) { } From 7891a2f0113d8b9508bad01dd1b7e62e771862ab Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sun, 23 Jun 2013 02:53:47 +0200 Subject: [PATCH 091/103] Fix naija not moving properly on machines with very high FPS. This bug occured when standing still and attempting to move, having high FPS and very low difftime. With near-zero vel, it was not built up enough per frame, therefore velLen was always < 2 and was subsequently reset back to 0, which resulted in naija never actually moving. This bug could be reproduced by holding Shift+F with 60 FPS, and then holding an arrow key. Thanks to `Nax for reporting the problem. (Cleaned out some cruft too, the actual change is the last line of the diff) --- Aquaria/Avatar.cpp | 101 +-------------------------------------------- 1 file changed, 2 insertions(+), 99 deletions(-) diff --git a/Aquaria/Avatar.cpp b/Aquaria/Avatar.cpp index c597fd4..556b8da 100644 --- a/Aquaria/Avatar.cpp +++ b/Aquaria/Avatar.cpp @@ -6467,13 +6467,9 @@ void Avatar::onUpdate(float dt) if (getState() != STATE_PUSH && !state.lockedToWall && inputEnabled && _isUnderWater && canMove) { float a = 800*dt; - Vector lastVel = vel; Vector addVec; bool isMovingSlow = false; - static Vector lastMousePos; - Vector pos = lastMousePos - dsq->getGameCursorPosition(); - static bool lastDown; float len = 0; @@ -6481,8 +6477,6 @@ void Avatar::onUpdate(float dt) _isUnderWater && !riding && !boneLock.on && (movingOn || ((dsq->inputMode == INPUT_JOYSTICK || dsq->inputMode== INPUT_KEYBOARD) || (core->mouse.buttons.left || bursting)))) { - //addVec = getVectorToCursorFr - //(dsq->inputMode != INPUT_JOYSTICK && dsq->inputMode != INPUT_KEYBOARD) if (dsq->inputMode == INPUT_MOUSE || !this->singing) { addVec = getVectorToCursorFromScreenCentre();//getVectorToCursor(); @@ -6507,23 +6501,11 @@ void Avatar::onUpdate(float dt) addVec = Vector(0,0,0); } - - - /* - if (!core->mouse.buttons.left && bursting) - { - addVec = vel; - } - */ - if (!addVec.isLength2DIn(minMouse)) { //if (core->mouse.buttons.left) { len = addVec.getLength2D(); - // addVec is always overwritten below; I assume this is old code? --achurch - //if (len > 200) - // addVec.setLength2D(a *10); if (len > 100) addVec.setLength2D(a *2); else @@ -6557,31 +6539,11 @@ void Avatar::onUpdate(float dt) stopBurst(); } } - //vel = Vector(0,0,0); } addVec = Vector(0,0,0); } } - - //addVec |= a; - /* - if (pos.getSquaredLength2D() > 10000) - { - startBurst(); - } - */ } - else - { - } - lastDown = core->mouse.buttons.left; - - /* - std::ostringstream os; - os << "addVec(" << addVec.x << ", " << addVec.y << ")"; - debugLog(os.str()); - */ - lastMousePos = dsq->getGameCursorPosition(); if (!rolling && !state.backFlip && !flourish) { @@ -6614,20 +6576,6 @@ void Avatar::onUpdate(float dt) } } - - /* - // HACK: joystick code / slow - if (addVec.x == 0 && addVec.y == 0) - { - float jpos[2]; - glfwGetJoystickPos(GLFW_JOYSTICK_1, jpos, 2); - const float deadZone = 0.1; - if (fabsf(jpos[0]) > deadZone || fabsf(jpos[1]) > deadZone) - addVec = Vector(jpos[0]*a, -jpos[1]*a); - } - */ - - // will not get here if not underwater if (isLockable()) lockToWall(); @@ -6635,18 +6583,10 @@ void Avatar::onUpdate(float dt) { currentMaxSpeed=0; vel += addVec; - //addVec |= a; - //float cheatLen = vel.getSquaredLength2D(); + if (bursting) { Vector add = addVec; - /* - // HACK: this will let the player boost in one direction while turning to face another - if (!core->mouse.buttons.left) - { - add = vel; - } - */ add.setLength2D(BURST_ACCEL*dt); vel += add; @@ -6664,33 +6604,16 @@ void Avatar::onUpdate(float dt) { if (isActing(ACTION_SLOW) || isMovingSlow) { - /* - int spdRange = maxMouse - minMouse; - float p = (len - minMouse) / spdRange; - int spd = p * vars->maxSwimSpeed;// + minMouse - currentMaxSpeed = spd; - */ currentMaxSpeed = vars->maxSlowSwimSpeed; } - //else if (dsq->continuity.getWorldType() == WT_NORMAL) else currentMaxSpeed = vars->maxSwimSpeed; - /* - else - currentMaxSpeed = vars->maxDreamWorldSpeed; - */ } } - /* - if (dsq->continuity.form == FORM_SPIRIT) - currentMaxSpeed *= 0.5f; - */ - if (leaches > 0) { currentMaxSpeed -= leaches*60; - // vel |= vel.getLength2D()-1*leaches; } if (state.blind) @@ -6699,19 +6622,6 @@ void Avatar::onUpdate(float dt) if (currentMaxSpeed < 0) currentMaxSpeed = 1; - /* - if (inCurrent) - { - ropeState = 0; - currentMaxSpeed = 1200; - } - */ - - //clampVelocity(); - - - //float angle; - if (getState() == STATE_TRANSFORM) rotateToVec(addVec, 0.1, 90); else @@ -6739,13 +6649,6 @@ void Avatar::onUpdate(float dt) } else { - /* - if (bursting && !core->mouse.buttons.left) - { - } - else - rotateToVec(addVec, 0.1); - */ if (!state.nearWall && !flourish) rotateToVec(addVec, 0.1); } @@ -7074,7 +6977,7 @@ void Avatar::onUpdate(float dt) { /*collideCheck:*/ - if (vel.getLength2D() < sqr(2)) + if (!isSwimming() && vel.getLength2D() < sqr(2)) { vel = Vector(0,0,0); } From 2bc3882a69693c925846ccda39cca6b5b98f6fb6 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sun, 23 Jun 2013 03:15:55 +0200 Subject: [PATCH 092/103] Add missing map #55 to the world map: The whale. --- files/data/worldmap.txt | 2 +- files/gfx/gui/worldmap/whale.png | Bin 0 -> 2795 bytes 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 files/gfx/gui/worldmap/whale.png diff --git a/files/data/worldmap.txt b/files/data/worldmap.txt index 089a59e..f82cc39 100644 --- a/files/data/worldmap.txt +++ b/files/data/worldmap.txt @@ -53,4 +53,4 @@ 52 1020 THIRTEENLAIR 1 5 417.62 -121.396 0 1 53 1030 KINGJELLYCAVE 1 2 328.989 605.32 0 0.356187 54 1020 WEIRDCAVE 1 0.5 548.557 709.137 0 1 -55 19 UNKNOWN 0 1 0 0 0 1 +55 1001 WHALE 1 2.52755 505.274 741.664 0 0.526182 diff --git a/files/gfx/gui/worldmap/whale.png b/files/gfx/gui/worldmap/whale.png new file mode 100644 index 0000000000000000000000000000000000000000..016b8d1b9c4bda113e61b6937d511e85a4d30487 GIT binary patch literal 2795 zcmeAS@N?(olHy`uVBq!ia0y~yU}OMc4mJh`hM1xiX&_#4kh>GZx^prw85kH?(j9#r z85lP9bN@+XWnf@XNcITwWnidMV_;}#VPN>hz`)S(f`OsbfPvvv0t1893 zCA|M8(s#UA#oK5+kbszk^LMyZD7*)nkwAED&k0?G4_{$<^*i~RSe z^ya^qZNLBhs;zxv9{$PgUH5ORS5G(2i?4q3c1PLY%J}n#AJ5TPz~I+n{Uf*g^Xso% zdt-0D|D9t0siJ;ux#W6&xntAsUbmil|C;rb;_mFvKX&}uWAoJV=R9FnkprCt4h3yaa_SSkA{Ey>G*nc&*dR@4d`rpT)M|Tug z7TaH*{UcE1K;>ci@TFh3uAcn=qu;;Po{w!?KGq%i!P#NmviNi)qm1b9UH>a$cjefd zX2-qaWqQ1{NyuW;643*KYxULt?ReCGeev^szu)TANi_B!SF`$gk1OFmQ^fiok7Zwe zr>v|{{DLR&E4B?9=K-yXWpqt^Z!=vo1I&G z@AOBlhS`$hvp;T5ji0Xn;8cB0!Nz5dvG zjo*g%&u!hEZC=h$ZrrPVZc}f(#mC17@>4g|PB>n%_{(m29V5SMUsJDq3rv;gD?6z% zapL2y`tL@zx%{jf?&ofl+W&lit;4aNa<<1UHTCDR-+$bDecSum4;}nWH}~tDza7jt z=iPR(Lpz-Q&VSEyY-8`E;@7pmf_C0{AHwkbeA?ctch}`Seq|cB-tOu8!ln27j(67o z6WV#lJ%EAVeD>G9%^!c2|M~SnwLam*x2WnnXDuGe=Xu85Q`T-cKJ(!m-!+^1FUoct0=-7ICniezgAgjt{H66?>df48}I&9}1S zgM(OTvt-6E?{6?JZ(|xbIDB*#FsRAxb5>u#u!fOI zm|LTvv;F-AP7Q|ah66{KxDp;cv@T)dIv}NBu(5$@M#T@lxeZJk*oKX^FE3gDF& Date: Sun, 23 Jun 2013 03:18:23 +0200 Subject: [PATCH 093/103] Savefile: Use ingr only if ingrNames does not exist. Using ingrNames is a lot safer for changing ingredients.txt. --- Aquaria/Continuity.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Aquaria/Continuity.cpp b/Aquaria/Continuity.cpp index 3a1ed8c..a3c0e90 100644 --- a/Aquaria/Continuity.cpp +++ b/Aquaria/Continuity.cpp @@ -2991,8 +2991,7 @@ void Continuity::loadFile(int slot) } } } - - if (startData->Attribute("ingr")) + else if (startData->Attribute("ingr")) // use this only if ingrNames does not exist. { std::istringstream is(startData->Attribute("ingr")); int idx; From 7faee73f141518b216cb317209216997b48aa537 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sun, 23 Jun 2013 04:43:24 +0200 Subject: [PATCH 094/103] Android save compat: Support "ch" (current health) value, and make maxHealth float. --- Aquaria/Continuity.cpp | 21 +++++++++++++++++---- Aquaria/DSQ.h | 2 +- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Aquaria/Continuity.cpp b/Aquaria/Continuity.cpp index a3c0e90..71d0a6d 100644 --- a/Aquaria/Continuity.cpp +++ b/Aquaria/Continuity.cpp @@ -2518,7 +2518,7 @@ void Continuity::saveFile(int slot, Vector position, unsigned char *scrShotData, startData.SetAttribute("scene", dsq->game->sceneName); startData.SetAttribute("exp", dsq->continuity.exp); startData.SetAttribute("h", dsq->continuity.maxHealth); - // ANDROID TODO: "ch" field + startData.SetAttribute("ch", dsq->continuity.health); startData.SetAttribute("naijaModel", dsq->continuity.naijaModel); startData.SetAttribute("costume", dsq->continuity.costume); startData.SetAttribute("form", dsq->continuity.form); @@ -3054,11 +3054,9 @@ void Continuity::loadFile(int slot) } } - // TODO ANDROID: "ch" field - if (startData->Attribute("h")) { - int read = atoi(startData->Attribute("h")); + float read = strtof(startData->Attribute("h"), NULL); maxHealth = read; health = read; std::ostringstream os; @@ -3071,6 +3069,21 @@ void Continuity::loadFile(int slot) dsq->game->avatar->health = maxHealth; } } + + if (startData->Attribute("ch")) + { + float h = strtof(startData->Attribute("ch"), NULL); + health = h; + std::ostringstream os; + os << "CurHealth read as: " << health; + debugLog(os.str()); + + if (dsq->game->avatar) + { + dsq->game->avatar->health = h; + } + } + if (startData->Attribute("seconds")) { std::istringstream is(startData->Attribute("seconds")); diff --git a/Aquaria/DSQ.h b/Aquaria/DSQ.h index b4a6461..555b04d 100644 --- a/Aquaria/DSQ.h +++ b/Aquaria/DSQ.h @@ -951,7 +951,7 @@ public: std::string getSaveFileName(int slot, const std::string &pfix); - int maxHealth; + float maxHealth; float health; bool hudVisible; unsigned int exp; From 26d056d92450be7d4b1b40635a4f5534c6ecbf78 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sun, 23 Jun 2013 18:50:10 +0200 Subject: [PATCH 095/103] Slightly more sensible error/msgbox handling --- Aquaria/AquariaMenuItem.cpp | 11 +--------- Aquaria/Continuity.cpp | 2 +- Aquaria/DSQ.cpp | 11 +++++----- Aquaria/Game.cpp | 5 ++--- Aquaria/GameplayVariables.cpp | 3 +-- Aquaria/ScriptInterface.cpp | 4 ++-- Aquaria/StringBank.cpp | 3 +++ BBGE/Base.cpp | 33 ++++++++++++++--------------- BBGE/Base.h | 6 ++---- BBGE/Core.cpp | 40 +++++++++-------------------------- BBGE/Core.h | 2 -- BBGE/SkeletalSprite.cpp | 3 +-- BBGE/StateManager.cpp | 2 +- BBGE/Texture.cpp | 2 -- BBGE/Vector.cpp | 4 ++-- 15 files changed, 48 insertions(+), 83 deletions(-) diff --git a/Aquaria/AquariaMenuItem.cpp b/Aquaria/AquariaMenuItem.cpp index 71d8689..c288058 100644 --- a/Aquaria/AquariaMenuItem.cpp +++ b/Aquaria/AquariaMenuItem.cpp @@ -569,8 +569,7 @@ void AquariaKeyConfig::onUpdate(float dt) if (!ai) { - errorLog("Could not find actionInput: " + actionInputName); - exit(-1); + exit_error("Could not find actionInput: " + actionInputName); } switch(inputSetType) { @@ -589,14 +588,6 @@ void AquariaKeyConfig::onUpdate(float dt) } } - /* - if (k == 0) - { - errorLog("AquariaKeyConfig::onUpdate"); - exit(-1); - } - */ - int *value = 0; if (inputSetType == INPUTSET_OTHER) diff --git a/Aquaria/Continuity.cpp b/Aquaria/Continuity.cpp index 71d0a6d..3dcd985 100644 --- a/Aquaria/Continuity.cpp +++ b/Aquaria/Continuity.cpp @@ -2659,7 +2659,7 @@ void Continuity::loadFile(int slot) if (startData->Attribute("mod")) { #ifdef AQUARIA_DEMO - exit(-1); + exit_error("The demo version does not support loading savegames from mods, sorry."); #else dsq->mod.load(startData->Attribute("mod")); #endif diff --git a/Aquaria/DSQ.cpp b/Aquaria/DSQ.cpp index cfa6aca..2d20ce1 100644 --- a/Aquaria/DSQ.cpp +++ b/Aquaria/DSQ.cpp @@ -922,12 +922,14 @@ This build is not yet final, and as such there are a couple things lacking. They // steam gets inited in here Core::init(); - // steam callbacks are inited here - dsq->continuity.init(); + dsq->continuity.stringBank.load(); vars = &v; v.load(); + // steam callbacks are inited here + dsq->continuity.init(); + // do copy stuff #ifdef BBGE_BUILD_UNIX std::string fn; @@ -997,8 +999,7 @@ This build is not yet final, and as such there are a couple things lacking. They { std::ostringstream os; os << "Aspect ratio for resolution [" << user.video.resx << ", " << user.video.resy << "] not supported."; - errorLog(os.str()); - exit(0); + exit_error(os.str()); } setFilter(dsq_filter); @@ -1041,7 +1042,7 @@ This build is not yet final, and as such there are a couple things lacking. They if (!createWindow(user.video.resx, user.video.resy, user.video.bits, user.video.full, "Aquaria")) #endif { - msg("Failed to create window"); + exit_error("Failed to create window"); return; } diff --git a/Aquaria/Game.cpp b/Aquaria/Game.cpp index 3270fbc..1520c8d 100644 --- a/Aquaria/Game.cpp +++ b/Aquaria/Game.cpp @@ -2432,8 +2432,7 @@ void Game::loadEntityTypeList() std::string line; if(!in) { - core->messageBox(dsq->continuity.stringBank.get(2008), dsq->continuity.stringBank.get(2016)); - exit(1); + exit_error(dsq->continuity.stringBank.get(2008).c_str()); } while (std::getline(in, line)) { @@ -5213,7 +5212,7 @@ bool Game::loadScene(std::string scene) } if (i == allowedMaps.size()) { - exit(-1); + exit_error("Demo version refuses to load this map, sorry."); } #endif diff --git a/Aquaria/GameplayVariables.cpp b/Aquaria/GameplayVariables.cpp index bd04c5d..8d7bfcd 100644 --- a/Aquaria/GameplayVariables.cpp +++ b/Aquaria/GameplayVariables.cpp @@ -27,8 +27,7 @@ void GameplayVariables::load() InStream inFile("data/variables.txt"); if(!inFile) { - core->messageBox(dsq->continuity.stringBank.get(2008), dsq->continuity.stringBank.get(2017)); - exit(1); + exit_error(dsq->continuity.stringBank.get(2017)); } std::string s; inFile >> s >> maxSlowSwimSpeed; diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 856f1fb..cb51bf3 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -713,8 +713,8 @@ luaFunc(indexWarnInstance) luaFunc(panicHandler) { - errorLog(luaFormatStackInfo(L) + ": Lua PANIC: " + getString(L, -1)); - exit(1); + std::string err = luaFormatStackInfo(L) + ": Lua PANIC: " + getString(L, -1); + exit_error(err); } static bool findFile_helper(const char *rawname, std::string &fname) diff --git a/Aquaria/StringBank.cpp b/Aquaria/StringBank.cpp index d1d144f..abdbb8d 100644 --- a/Aquaria/StringBank.cpp +++ b/Aquaria/StringBank.cpp @@ -41,6 +41,9 @@ void StringBank::load() fname = localisePath(dsq->mod.getPath() + "stringbank.txt", dsq->mod.getPath()); _load(fname); } + + if(stringMap.empty()) + exit_error("Failed to load data/stringbank.txt"); } void StringBank::_load(const std::string &file) diff --git a/BBGE/Base.cpp b/BBGE/Base.cpp index 6feee42..b996122 100644 --- a/BBGE/Base.cpp +++ b/BBGE/Base.cpp @@ -291,8 +291,7 @@ bool exists(const std::string &f, bool makeFatal, bool skipVFS) if (makeFatal && !e) { - errorLog(std::string("Could not open [" + f + "]")); - exit(0); + exit_error("Could not open [" + f + "]"); } return e; @@ -316,10 +315,10 @@ void drawCircle(float radius, int stepSize) #endif } -void fatalError(const std::string &message) +void exit_error(const std::string &message) { - msg(message); - exit(0); + errorLog(message); + exit(1); } std::string parseCommand(const std::string &line, const std::string &command) @@ -424,8 +423,7 @@ void errorLog(const std::string &s) } else { - //msg("Core Not Initialized"); - //MessageBox(0, s.c_str(), "ErrorLog (Core Not Initalized)", MB_OK); + messageBox("Error!", s); } } @@ -775,17 +773,18 @@ std::vector getFileList(std::string path, std::string type, int par return list; } -std::string msg(const std::string &message) +void messageBox(const std::string& title, const std::string &msg) { - core->msg(message); - return message; -} - -void msgVector(const std::string &name, const Vector &vec) -{ - std::ostringstream os; - os << name << ": (" << vec.x <<", " << vec.y << ", " << vec.z << ")"; - msg (os.str()); +#ifdef BBGE_BUILD_WINDOWS + MessageBox (0,msg.c_str(),title.c_str(),MB_OK); +#elif defined(BBGE_BUILD_MACOSX) + cocoaMessageBox(title, msg); +#elif defined(BBGE_BUILD_UNIX) + // !!! FIXME: probably don't want the whole GTK+ dependency in here... + fprintf(stderr, "%s: %s\n", title.c_str(), msg.c_str()); +#else +#error Please define your platform. +#endif } Vector getNearestPointOnLine(Vector a, Vector b, Vector c) diff --git a/BBGE/Base.h b/BBGE/Base.h index 586a944..9c34277 100644 --- a/BBGE/Base.h +++ b/BBGE/Base.h @@ -257,11 +257,9 @@ bool isVectorInRect(const Vector &vec, const Vector &coord1, const Vector &coord std::string parseCommand(const std::string &line, const std::string &command); -std::string msg(const std::string &message); +void messageBox(const std::string &title, const std::string& msg); -void msgVector(const std::string &name, const Vector &vec); - -void fatalError(const std::string &message); +void exit_error(const std::string &message); unsigned hash(const std::string &string); diff --git a/BBGE/Core.cpp b/BBGE/Core.cpp index 9f68f9f..e1aa0d2 100644 --- a/BBGE/Core.cpp +++ b/BBGE/Core.cpp @@ -817,7 +817,7 @@ bool Core::getMetaState() void Core::errorLog(const std::string &s) { - messageBox("Message", s); + messageBox("Error!", s); debugLog(s); } @@ -827,16 +827,7 @@ void cocoaMessageBox(const std::string &title, const std::string &msg); void Core::messageBox(const std::string &title, const std::string &msg) { -#ifdef BBGE_BUILD_WINDOWS - MessageBox (0,msg.c_str(),title.c_str(),MB_OK); -#elif defined(BBGE_BUILD_MACOSX) - cocoaMessageBox(title, msg); -#elif defined(BBGE_BUILD_UNIX) - // !!! FIXME: probably don't want the whole GTK+ dependency in here... - fprintf(stderr, "%s: %s\n", title.c_str(), msg.c_str()); -#else -#error Please define your platform. -#endif + ::messageBox(title, msg); } void Core::debugLog(const std::string &s) @@ -1267,7 +1258,7 @@ void Core::init() if((SDL_Init(0))==-1) { - exit(0); + exit_error("Failed to init SDL"); } #endif @@ -1910,16 +1901,15 @@ bool Core::initGraphicsLibrary(int width, int height, bool fullscreen, int vsync { if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) { - errorLog(std::string("SDL Error: ") + std::string(SDL_GetError())); - exit(0); + exit_error(std::string("SDL Error: ") + std::string(SDL_GetError())); } #if BBGE_BUILD_OPENGL_DYNAMIC if (SDL_GL_LoadLibrary(NULL) == -1) { - errorLog(std::string("SDL_GL_LoadLibrary Error: ") + std::string(SDL_GetError())); + std::string err = std::string("SDL_GL_LoadLibrary Error: ") + std::string(SDL_GetError()); SDL_Quit(); - exit(0); + exit_error(err); } #endif } @@ -1943,9 +1933,8 @@ bool Core::initGraphicsLibrary(int width, int height, bool fullscreen, int vsync { std::ostringstream os; os << "Couldn't set resolution [" << width << "x" << height << "]\n" << SDL_GetError(); - errorLog(os.str()); SDL_Quit(); - exit(0); + exit_error(os.str()); } #if BBGE_BUILD_OPENGL_DYNAMIC @@ -1953,9 +1942,8 @@ bool Core::initGraphicsLibrary(int width, int height, bool fullscreen, int vsync { std::ostringstream os; os << "Couldn't load OpenGL symbols we need\n"; - errorLog(os.str()); SDL_Quit(); - exit(0); + exit_error(os.str()); } #endif } @@ -2625,13 +2613,6 @@ void Core::setDockIcon(const std::string &ident) { } -void Core::msg(const std::string &message) -{ -#ifdef BBGE_BUILD_WINDOWS - MessageBox(0, message.c_str(), "Message", MB_OK); -#endif -} - void Core::setMousePosition(const Vector &p) { Vector lp = core->mouse.position; @@ -4847,14 +4828,13 @@ void Core::setupFileAccess() debugLog("Init VFS..."); if(!ttvfs::checkCompat()) - exit(1); + exit_error("ttvfs not compatible"); vfs.AddArchiveLoader(new ttvfs::VFSZipArchiveLoader); if(!vfs.LoadFileSysRoot(false)) { - errorLog("Failed to setup file access"); - exit(1); + exit_error("Failed to setup file access"); } vfs.Prepare(); diff --git a/BBGE/Core.h b/BBGE/Core.h index 8e45ab3..1c514c9 100644 --- a/BBGE/Core.h +++ b/BBGE/Core.h @@ -1175,8 +1175,6 @@ public: void saveSizedScreenshotTGA(const std::string &filename, int sz, int crop34); void saveCenteredScreenshotTGA(const std::string &filename, int sz); - virtual void msg(const std::string &message); - bool minimized; std::string getEnqueuedJumpState(); int cullRadius; diff --git a/BBGE/SkeletalSprite.cpp b/BBGE/SkeletalSprite.cpp index c37744f..ea0a5d3 100644 --- a/BBGE/SkeletalSprite.cpp +++ b/BBGE/SkeletalSprite.cpp @@ -507,8 +507,7 @@ Animation* AnimationLayer::getCurrentAnimation() { std::ostringstream os; os << "skel: " << s->filenameLoaded << " currentAnimation: " << currentAnimation << " is out of range\n error in anim file?"; - errorLog(os.str()); - exit(-1); + exit_error(os.str()); return 0; } return &s->animations[currentAnimation]; diff --git a/BBGE/StateManager.cpp b/BBGE/StateManager.cpp index e82aefb..eb3195a 100644 --- a/BBGE/StateManager.cpp +++ b/BBGE/StateManager.cpp @@ -288,7 +288,7 @@ void StateManager::registerStateObject(StateObject *stateObject, const std::stri //getNameFromDerivedClassTypeName(c); if (stateObject->name.empty()) { - fatalError("StateManager::registerStateObject - Empty name."); + exit_error("StateManager::registerStateObject - Empty name."); } if (!stateObjects[stateObject->name]) diff --git a/BBGE/Texture.cpp b/BBGE/Texture.cpp index a15e69c..97cd22b 100644 --- a/BBGE/Texture.cpp +++ b/BBGE/Texture.cpp @@ -446,7 +446,6 @@ void Texture::loadPNG(const std::string &file) width = 64; height = 64; Texture::textureError = TEXERR_FILENOTFOUND; - //exit(1); return; } @@ -483,7 +482,6 @@ void Texture::loadPNG(const std::string &file) width = 64; height = 64; Texture::textureError = TEXERR_FILENOTFOUND; - //exit(1); } diff --git a/BBGE/Vector.cpp b/BBGE/Vector.cpp index 94eeb49..73b24bc 100644 --- a/BBGE/Vector.cpp +++ b/BBGE/Vector.cpp @@ -306,12 +306,12 @@ Vector VectorPath::getValue(float usePercent) if (!from && !target) { - msg ("returning first value"); + errorLog("returning first value"); return pathNodes[0].value; } else if (!from && target) { - msg("Unexpected Path node result (UPDATE: Could use current value as from?)"); + errorLog("Unexpected Path node result (UPDATE: Could use current value as from?)"); } else if (from && !target) { From 7dca65351cec4524589497e960d1c7a6f9efbc86 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sun, 23 Jun 2013 22:28:46 +0200 Subject: [PATCH 096/103] Implement loading/saving some more state data. This is the final commit for android savegame compatibility. Thanks to Andrew Church for explaining the new attributes and their format. --- Aquaria/Avatar.h | 3 +- Aquaria/Continuity.cpp | 187 ++++++++++++++++++++++++++++++++++++++++- Aquaria/Web.cpp | 8 ++ Aquaria/Web.h | 1 + 4 files changed, 195 insertions(+), 4 deletions(-) diff --git a/Aquaria/Avatar.h b/Aquaria/Avatar.h index dea3095..0287a1d 100644 --- a/Aquaria/Avatar.h +++ b/Aquaria/Avatar.h @@ -345,6 +345,7 @@ public: SeeMapMode getSeeMapMode() const { return _seeMapMode; } int leaches; + float shieldPoints; protected: void setSongIconPositions(); @@ -385,8 +386,6 @@ protected: Vector fallGravity; int lastOutOfWaterMaxSpeed; - int shieldPoints; - void onIdle(); void onHeal(int type); ParticleEffect biteLeftEmitter, biteRightEmitter, swimEmitter, auraHitEmitter; diff --git a/Aquaria/Continuity.cpp b/Aquaria/Continuity.cpp index 3dcd985..8ad5fde 100644 --- a/Aquaria/Continuity.cpp +++ b/Aquaria/Continuity.cpp @@ -2580,6 +2580,74 @@ void Continuity::saveFile(int slot, Vector position, unsigned char *scrShotData, } startData.SetAttribute("intFlags", fos.str()); + // Additional data for the android version + +#define SINGLE_FLOAT_ATTR(name, cond, val) \ + do { if((cond) && (val)) { \ + std::ostringstream osf; \ + osf << (val); \ + startData.SetAttribute(name, osf.str()); \ + }} while(0) + + SINGLE_FLOAT_ATTR("blind", dsq->game->avatar->state.blind, dsq->game->avatar->state.blindTimer.getValue()); + SINGLE_FLOAT_ATTR("invincible", invincibleTimer.isActive(), invincibleTimer.getValue()); + SINGLE_FLOAT_ATTR("regen", regenTimer.isActive(), regenTimer.getValue()); + SINGLE_FLOAT_ATTR("trip", tripTimer.isActive(), tripTimer.getValue()); + SINGLE_FLOAT_ATTR("shieldPoints", true, dsq->game->avatar->shieldPoints); + SINGLE_FLOAT_ATTR("webTimer", webTimer.isActive(), webTimer.getValue()); // Extension; not present in the android version + +#undef SINGLE_FLOAT_ATTR + +#define TIMER_AND_VALUE_ATTR(name, timer, val) \ + do { if(((timer).isActive()) && (val)) { \ + std::ostringstream osf; \ + osf << (val) << " " << ((timer).getValue()); \ + startData.SetAttribute((name), osf.str()); \ + }} while(0) + + TIMER_AND_VALUE_ATTR("biteMult", biteMultTimer, biteMult); + TIMER_AND_VALUE_ATTR("speedMult", speedMultTimer, speedMult); + TIMER_AND_VALUE_ATTR("defenseMult", defenseMultTimer, defenseMult); + TIMER_AND_VALUE_ATTR("energyMult", energyTimer, energyMult); + TIMER_AND_VALUE_ATTR("petPower", petPowerTimer, petPower); + TIMER_AND_VALUE_ATTR("liPower", liPowerTimer, liPower); + TIMER_AND_VALUE_ATTR("light", lightTimer, light); + +#undef TIMER_AND_VALUE_ATTR + + if(poisonTimer.isActive()) + { + std::ostringstream osp; + osp << poison << " " << poisonTimer.getValue() << " " << poisonBitTimer.getValue(); + startData.SetAttribute("poison", osp.str()); + } + + if(dsq->game->avatar->activeAura != AURA_NONE) + { + std::ostringstream osa; + osa << dsq->game->avatar->activeAura << " " << dsq->game->avatar->auraTimer; + startData.SetAttribute("aura", osa.str()); + } + + // FIXME: Web is a bit weird. There are 2 webBitTimer variables in use, one in Continuity, one in Avatar. + // Because the avatar one ticks every 0.5 seconds, it will be hardly noticeable if that timer is off. + // So we just use the Continuty timers and hope for the best. -- FG + if(webTimer.isActive() && dsq->game->avatar->web) + { + Web *w = dsq->game->avatar->web; + const int nump = w->getNumPoints(); + std::ostringstream osw; + osw << webBitTimer.getValue() << " " << nump << " "; + for(int i = 0; i < nump; ++i) + { + Vector v = w->getPoint(i); + osw << v.x << " " << v.y << " "; + } + startData.SetAttribute("web", osw.str()); + } + + // end extra android data + doc.InsertEndChild(startData); @@ -3094,9 +3162,124 @@ void Continuity::loadFile(int slot) dsq->continuity.costume = startData->Attribute("costume"); } - //dsq->game->positionToAvatar = Vector(500,400); dsq->game->sceneToLoad = startData->Attribute("scene"); - //dsq->game->transitionToScene(); + + // Additional data introduced in the android version + + if(startData->Attribute("blind")) + { + float timer = strtof(startData->Attribute("blind"), NULL); + if(dsq->game->avatar) + dsq->game->avatar->setBlind(timer); + } + + if(startData->Attribute("invincible")) + { + float timer = strtof(startData->Attribute("invincible"), NULL); + setInvincible(timer); + } + + if(startData->Attribute("regen")) + { + float timer = strtof(startData->Attribute("regen"), NULL); + setRegen(timer); + } + + if(startData->Attribute("trip")) + { + float timer = strtof(startData->Attribute("trip"), NULL); + setTrip(timer); + } + + if(startData->Attribute("aura")) + { + std::istringstream is(startData->Attribute("aura")); + int type = AURA_NONE; + float timer = 0.0f; + is >> type >> timer; + auraTimer = timer; + auraType = (AuraType)type; + if(dsq->game->avatar) + { + dsq->game->avatar->activateAura((AuraType)type); + dsq->game->avatar->auraTimer = timer; + } + } + + if(startData->Attribute("shieldPoints")) + { + float sp = strtof(startData->Attribute("shieldPoints"), NULL); + if(dsq->game->avatar) + dsq->game->avatar->shieldPoints = sp; + } + +#define LOAD_MULTI_SIMPLE(attr, mth) \ + do { if(startData->Attribute(attr)) \ + { \ + std::istringstream is(startData->Attribute(attr)); \ + float value = 0.0f, timer = 0.0f; \ + is >> value >> timer; \ + this->mth(value, timer); \ + }} while(0) + + LOAD_MULTI_SIMPLE("biteMult", setBiteMultiplier); + LOAD_MULTI_SIMPLE("speedMult", setSpeedMultiplier); + LOAD_MULTI_SIMPLE("defenseMult", setDefenseMultiplier); + LOAD_MULTI_SIMPLE("energyMult", setEnergy); + LOAD_MULTI_SIMPLE("petPower", setPetPower); + LOAD_MULTI_SIMPLE("liPower", setLiPower); + LOAD_MULTI_SIMPLE("light", setLight); + +#undef LOAD_MULTI_SIMPLE + + if(startData->Attribute("poison")) + { + std::istringstream is(startData->Attribute("poison")); + float p = 0.0f, pt = 0.0f, pbit = 0.0f; + is >> p >> pt >> pbit; + setPoison(p, pt); + poisonBitTimer.start(pbit); + } + + // FIXME: the total web time is seemingly not saved in the file. + // Not sure if the calculation of the remaining time is correct. + // Especially because there are two webBitTimer variables in use (in Continuity and Avatar), + // and both of them access the avatar web. It's thus likely that more points were added than intended. -- FG + if(startData->Attribute("web")) + { + std::istringstream is(startData->Attribute("web")); + float wbit = 0.0f; + int nump = 0; + is >> wbit >> nump; + // 2 web points are added in setWeb() by default, so we exclude them from the calculation + float remainTime = webTime - (0.5 * (nump - 2)); // Avatar::webBitTimer ticks every 0.5 secs + if(nump > 1 && remainTime > 0 && dsq->game->avatar) + { + if(!dsq->game->avatar->web) + dsq->game->avatar->createWeb(); + Web *w = dsq->game->avatar->web; + for(int i = 0; i < nump; ++i) + { + Vector v; + is >> v.x >> v.y; + if(i < w->getNumPoints()) + w->setPoint(i, v); + else + w->addPoint(v); + } + webBitTimer.start(wbit); + webTimer.start(remainTime); + } + } + + // This is AFAIK not in the android version, but let's add this for completeness + // and to avoid the mess described above. + if(startData->Attribute("webTimer")) + { + float timer = strtof(startData->Attribute("webTimer"), NULL); + webTimer.start(timer); + } + } } diff --git a/Aquaria/Web.cpp b/Aquaria/Web.cpp index 1e25a31..ae8c8e7 100644 --- a/Aquaria/Web.cpp +++ b/Aquaria/Web.cpp @@ -82,6 +82,14 @@ void Web::setPoint(int pt, const Vector &v) points[pt] = v; } +Vector Web::getPoint(int pt) const +{ + Vector v; + if (pt >= 0 || pt < points.size()) + v = points[pt]; + return v; +} + int Web::getNumPoints() { return points.size(); diff --git a/Aquaria/Web.h b/Aquaria/Web.h index 78762d0..8236ac8 100644 --- a/Aquaria/Web.h +++ b/Aquaria/Web.h @@ -30,6 +30,7 @@ public: Web(); int addPoint(const Vector &point = Vector(0,0)); void setPoint(int pt, const Vector &v); + Vector getPoint(int pt) const; void setParentEntity(Entity *e); int getNumPoints(); typedef std::list Webs; From f8ed78d33192db3a5ba5cd1d8fed4b5ba418d65c Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sun, 23 Jun 2013 22:41:35 +0200 Subject: [PATCH 097/103] High framerate problem wasn't fully fixed, let's try this again. Little addition to 7891a2f0113d8. --- Aquaria/Avatar.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Aquaria/Avatar.cpp b/Aquaria/Avatar.cpp index 556b8da..f5c8885 100644 --- a/Aquaria/Avatar.cpp +++ b/Aquaria/Avatar.cpp @@ -6977,7 +6977,11 @@ void Avatar::onUpdate(float dt) { /*collideCheck:*/ - if (!isSwimming() && vel.getLength2D() < sqr(2)) + // Beware: This code may cause clamping vel to zero if the framerate is very high. + // Starting with zero vel, low difftimes will cause an addVec small enough that this + // check will always trigger, and vel will never get larger than zero. + // Under water and swimming check should hopefully prevent this from happening. -- FG + if (_isUnderWater && !isSwimming() && vel.getLength2D() < sqr(2)) { vel = Vector(0,0,0); } From aba216d1ddf6799ff9f3a3bf6bbe6aadfc6de40b Mon Sep 17 00:00:00 2001 From: fgenesis Date: Mon, 24 Jun 2013 02:54:57 +0200 Subject: [PATCH 098/103] Fix little problem added in 54d609a8b507dd. Respecting maxspeed lerp is not a good idea, there are nodes that set this (normalpass, energypass, just to name two). This causes way too fast swimming while the maxspeed lerp is > 1. --- Aquaria/Avatar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aquaria/Avatar.cpp b/Aquaria/Avatar.cpp index f5c8885..941a4bc 100644 --- a/Aquaria/Avatar.cpp +++ b/Aquaria/Avatar.cpp @@ -4913,7 +4913,7 @@ void Avatar::clampVelocity() setMaxSpeed(currentMaxSpeed * useSpeedMult * dsq->continuity.speedMult2); - vel.capLength2D(getMaxSpeed() * maxSpeedLerp.x); + vel.capLength2D(getMaxSpeed() /* * maxSpeedLerp.x*/); } void Avatar::activateAura(AuraType aura) From 9b658cb53160062a4b0062bc7e0958cc01a8e9f0 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Mon, 24 Jun 2013 03:09:58 +0200 Subject: [PATCH 099/103] Allow overriding title screen version nuber completely. --- Aquaria/AquariaCompileConfig.h | 3 +++ Aquaria/DSQ.cpp | 8 +++++++- Aquaria/Network.cpp | 3 +++ CMakeLists.txt | 7 +++++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Aquaria/AquariaCompileConfig.h b/Aquaria/AquariaCompileConfig.h index 194b230..a7b9cd6 100644 --- a/Aquaria/AquariaCompileConfig.h +++ b/Aquaria/AquariaCompileConfig.h @@ -12,6 +12,9 @@ #define AQUARIA_CUSTOM_BUILD_ID "" + // If defined, this is shown instead of "Aquaria vx.x.x ..." on the title screen. + //#define AQUARIA_OVERRIDE_VERSION_STRING "Aquaria OSE v1.000" + #endif diff --git a/Aquaria/DSQ.cpp b/Aquaria/DSQ.cpp index 0b7ca9f..838259c 100644 --- a/Aquaria/DSQ.cpp +++ b/Aquaria/DSQ.cpp @@ -844,7 +844,13 @@ void loadBitForTexPrecache() } -void DSQ::setVersionLabelText() { +void DSQ::setVersionLabelText() +{ +#ifdef AQUARIA_OVERRIDE_VERSION_STRING + versionLabel->setText(AQUARIA_OVERRIDE_VERSION_STRING); + return; +#endif + std::ostringstream os; os << "Aquaria"; diff --git a/Aquaria/Network.cpp b/Aquaria/Network.cpp index 6dba942..cbd2a84 100644 --- a/Aquaria/Network.cpp +++ b/Aquaria/Network.cpp @@ -146,6 +146,9 @@ static void init() #ifdef AQUARIA_CUSTOM_BUILD_ID os << AQUARIA_CUSTOM_BUILD_ID; #endif +#ifdef AQUARIA_OVERRIDE_VERSION_STRING + os << "|" << AQUARIA_OVERRIDE_VERSION_STRING; +#endif const char *loc = getUsedLocale(); if(*loc) diff --git a/CMakeLists.txt b/CMakeLists.txt index 624c0e9..665ae5a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -222,6 +222,13 @@ if (NOT(AQUARIA_CUSTOM_BUILD_ID STREQUAL "")) ADD_DEFINITIONS("-DAQUARIA_CUSTOM_BUILD_ID=\"${AQUARIA_CUSTOM_BUILD_ID}\"") endif (NOT(AQUARIA_CUSTOM_BUILD_ID STREQUAL "")) +# Custom version string override (displayed as-is instead of "Aquaria vx.x.x ..." on the title screen +SET(AQUARIA_OVERRIDE_VERSION_STRING "" CACHE STRING + "Text to display instead of the Aquaria version ID on the title screen. (Overrides AQUARIA_CUSTOM_BUILD_ID as well)") +if (NOT(AQUARIA_OVERRIDE_VERSION_STRING STREQUAL "")) + ADD_DEFINITIONS("-AQUARIA_OVERRIDE_VERSION_STRING=\"${AQUARIA_OVERRIDE_VERSION_STRING}\"") +endif (NOT(AQUARIA_OVERRIDE_VERSION_STRING STREQUAL "")) + # Custom data directories SET(AQUARIA_DEFAULT_DATA_DIR "" CACHE STRING "Default data directory (for package maintainers only)") From 1897329071bc417a3d93e008955817f44b2aa9f0 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Mon, 24 Jun 2013 03:39:48 +0200 Subject: [PATCH 100/103] Allow downloading data while the game is minimized. With this change, downloads should no longer abort when the game is minimized for more than a few seconds. --- Aquaria/DSQ.cpp | 13 +++---------- Aquaria/DSQ.h | 3 +++ Aquaria/Network.cpp | 3 +++ BBGE/Core.cpp | 9 ++++++++- BBGE/Core.h | 2 ++ 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Aquaria/DSQ.cpp b/Aquaria/DSQ.cpp index 838259c..f9bd757 100644 --- a/Aquaria/DSQ.cpp +++ b/Aquaria/DSQ.cpp @@ -5133,16 +5133,9 @@ void DSQ::cutsceneEffects(bool on) } } -void pauseSound() +void DSQ::onBackgroundUpdate() { - if (dsq && dsq->sound) { - dsq->sound->pause(); - } + Network::update(); + Core::onBackgroundUpdate(); } -void resumeSound() -{ - if (dsq && dsq->sound) { - dsq->sound->resume(); - } -} diff --git a/Aquaria/DSQ.h b/Aquaria/DSQ.h index a1db87e..68533b9 100644 --- a/Aquaria/DSQ.h +++ b/Aquaria/DSQ.h @@ -1563,6 +1563,9 @@ public: void pauseCutscene(bool on); bool canSkipCutscene(); bool isSkippingCutscene(); + + virtual void onBackgroundUpdate(); + protected: Quad *cutscene_bg; diff --git a/Aquaria/Network.cpp b/Aquaria/Network.cpp index cbd2a84..e1358f5 100644 --- a/Aquaria/Network.cpp +++ b/Aquaria/Network.cpp @@ -244,6 +244,9 @@ void download(RequestData *rq) void update() { + if(!netUp) + return; + RequestDataHolder h; while(notifyRequests.pop(h)) h.rq->notify(h.ev, h.recvd, h.total); diff --git a/BBGE/Core.cpp b/BBGE/Core.cpp index c659d2e..f514807 100644 --- a/BBGE/Core.cpp +++ b/BBGE/Core.cpp @@ -2727,6 +2727,13 @@ bool Core::isWindowFocus() return true; } +void Core::onBackgroundUpdate() +{ +#if BBGE_BUILD_SDL + SDL_Delay(200); +#endif +} + void Core::main(float runTime) { bool verbose = coreVerboseDebug; @@ -2911,7 +2918,7 @@ void Core::main(float runTime) { pollEvents(); //debugLog("app not in input focus"); - SDL_Delay(200); + onBackgroundUpdate(); resetTimer(); } diff --git a/BBGE/Core.h b/BBGE/Core.h index fbdc4ed..e265dda 100644 --- a/BBGE/Core.h +++ b/BBGE/Core.h @@ -1310,6 +1310,8 @@ public: volatile int dbg_numThreadDecoders; static unsigned int dbg_numRenderCalls; + virtual void onBackgroundUpdate(); + protected: std::string fpsDebugString; From 9d2dcc2d0fa9ab997398cf7f3dcfd7ed25b52aa9 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Mon, 24 Jun 2013 19:54:25 +0200 Subject: [PATCH 101/103] Update ttvfs to current HEAD --- ExternalLibs/ttvfs/VFSDefines.h | 1 + ExternalLibs/ttvfs/VFSDir.cpp | 2 +- ExternalLibs/ttvfs/VFSTools.cpp | 122 +++++++------------------- ExternalLibs/ttvfs/VFSTools.h | 12 +-- ExternalLibs/ttvfs_zip/VFSFileZip.cpp | 4 +- 5 files changed, 44 insertions(+), 97 deletions(-) diff --git a/ExternalLibs/ttvfs/VFSDefines.h b/ExternalLibs/ttvfs/VFSDefines.h index 4439bda..7cd8642 100644 --- a/ExternalLibs/ttvfs/VFSDefines.h +++ b/ExternalLibs/ttvfs/VFSDefines.h @@ -29,6 +29,7 @@ // performance matters, and you implemented actual locking into the Mutex class. // If no Mutex implementation is provided, its operations are no-ops, beware! // Note: This adds a *lot* of overhead. Better ensure thread safety yourself, externally. Really! +// (Also note that this feature is *UNTESTED*. Don't activate.) //#define VFS_THREADSAFE // By default, ttvfs uses a std::map to store stuff. diff --git a/ExternalLibs/ttvfs/VFSDir.cpp b/ExternalLibs/ttvfs/VFSDir.cpp index 940b87d..536ab72 100644 --- a/ExternalLibs/ttvfs/VFSDir.cpp +++ b/ExternalLibs/ttvfs/VFSDir.cpp @@ -394,7 +394,7 @@ unsigned int VFSDirReal::load(bool recursive) unsigned int sum = li.size(); li.clear(); - GetDirList(fullname(), li, false); + GetDirList(fullname(), li, 0); for(std::deque::iterator it = li.begin(); it != li.end(); ++it) { // subdir was already present, move over and erase diff --git a/ExternalLibs/ttvfs/VFSTools.cpp b/ExternalLibs/ttvfs/VFSTools.cpp index 6a34e28..f3d04ca 100644 --- a/ExternalLibs/ttvfs/VFSTools.cpp +++ b/ExternalLibs/ttvfs/VFSTools.cpp @@ -18,9 +18,9 @@ # include #else # ifdef __HAIKU__ -# include +# include # else -# include +# include # endif # include #endif @@ -30,24 +30,12 @@ VFS_NAMESPACE_START -std::string stringToLower(std::string s) -{ - std::transform(s.begin(), s.end(), s.begin(), tolower); - return s; -} - -std::string stringToUpper(std::string s) -{ - std::transform(s.begin(), s.end(), s.begin(), toupper); - return s; -} - -void makeLowercase(std::string& s) +void stringToLower(std::string& s) { std::transform(s.begin(), s.end(), s.begin(), tolower); } -void makeUppercase(std::string& s) +void stringToUpper(std::string& s) { std::transform(s.begin(), s.end(), s.begin(), toupper); } @@ -109,7 +97,7 @@ static bool _IsDir(const char *path, dirent *dp) char *pathname = (char*)alloca(len1 + 1 + len2 + 1 + 13); strcpy (pathname, path); - /* Avoid UNC-path "//name" on Cygwin. */ + /* Avoid UNC-path "//name" on Cygwin. */ if (len1 > 0 && pathname[len1 - 1] != '/') strcat (pathname, "/"); @@ -125,9 +113,9 @@ static bool _IsFile(const char *path, dirent *dp) { return !_IsDir(path, dp); } -#endif +#endif // DT_DIR -#endif +#endif // !_WIN32 // returns list of *plain* file names in given directory, // without paths, and without anything else @@ -177,7 +165,7 @@ void GetFileList(const char *path, StringList& files) // returns a list of directory names in the given directory, *without* the source dir. // if getting the dir list recursively, all paths are added, except *again* the top source dir beeing queried. -void GetDirList(const char *path, StringList &dirs, bool recursive /* = false */) +void GetDirList(const char *path, StringList &dirs, int depth /* = 0 */) { #if !_WIN32 DIR * dirp; @@ -185,6 +173,8 @@ void GetDirList(const char *path, StringList &dirs, bool recursive /* = false */ dirp = opendir(path); if(dirp) { + std::string pathstr(path); + MakeSlashTerminated(pathstr); while((dp = readdir(dirp))) // assignment is intentional { if (_IsDir(path, dp)) // only add if it is a directory @@ -192,11 +182,13 @@ void GetDirList(const char *path, StringList &dirs, bool recursive /* = false */ if(strcmp(dp->d_name, ".") != 0 && strcmp(dp->d_name, "..") != 0) { dirs.push_back(dp->d_name); - if (recursive) // needing a better way to do that + if (depth) // needing a better way to do that { - std::deque newdirs; - GetDirList(dp->d_name, newdirs, true); - std::string d(dp->d_name); + std::string d = dp->d_name; + std::string subdir = pathstr + d; + MakeSlashTerminated(d); + StringList newdirs; + GetDirList(subdir.c_str(), newdirs, depth - 1); for(std::deque::iterator it = newdirs.begin(); it != newdirs.end(); ++it) dirs.push_back(d + *it); } @@ -207,12 +199,10 @@ void GetDirList(const char *path, StringList &dirs, bool recursive /* = false */ } #else - - std::string search(path); - MakeSlashTerminated(search); - search += "*"; + std::string pathstr(path); + MakeSlashTerminated(pathstr); WIN32_FIND_DATA fil; - HANDLE hFil = FindFirstFile(search.c_str(),&fil); + HANDLE hFil = FindFirstFile((pathstr + '*').c_str(),&fil); if(hFil != INVALID_HANDLE_VALUE) { do @@ -222,14 +212,15 @@ void GetDirList(const char *path, StringList &dirs, bool recursive /* = false */ if (!strcmp(fil.cFileName, ".") || !strcmp(fil.cFileName, "..")) continue; - std::string d(fil.cFileName); - dirs.push_back(d); + dirs.push_back(fil.cFileName); - if (recursive) // need a better way to do that + if (depth) // need a better way to do that { + std::string d = fil.cFileName; + std::string subdir = pathstr + d; + MakeSlashTerminated(d); StringList newdirs; - GetDirList(d.c_str(), newdirs, true); - + GetDirList(subdir.c_str(), newdirs, depth - 1); for(std::deque::iterator it = newdirs.begin(); it != newdirs.end(); ++it) dirs.push_back(d + *it); } @@ -280,8 +271,10 @@ bool CreateDirRec(const char *dir) StringList li; StrSplit(dir, "/\\", li, false); std::string d; - d.reserve(strlen(dir)); - bool last; + d.reserve(strlen(dir) + 1); + if(*dir == '/') + d += '/'; + bool last = false; for(StringList::iterator it = li.begin(); it != li.end(); ++it) { d += *it; @@ -407,55 +400,6 @@ std::string StripLastPath(const std::string& s) return s.substr(0, pos); } -void GetFileListRecursive(std::string dir, StringList& files, bool withQueriedDir /* = false */) -{ - std::stack stk; - - if(withQueriedDir) - { - stk.push(dir); - while(stk.size()) - { - dir = stk.top(); - stk.pop(); - MakeSlashTerminated(dir); - - StringList li; - GetFileList(dir.c_str(), li); - for(std::deque::iterator it = li.begin(); it != li.end(); ++it) - files.push_back(dir + *it); - - li.clear(); - GetDirList(dir.c_str(), li, true); - for(std::deque::iterator it = li.begin(); it != li.end(); ++it) - stk.push(dir + *it); - } - } - else - { - std::string topdir = dir; - MakeSlashTerminated(topdir); - stk.push(""); - while(stk.size()) - { - dir = stk.top(); - stk.pop(); - MakeSlashTerminated(dir); - - StringList li; - dir = topdir + dir; - GetFileList(dir.c_str(), li); - for(std::deque::iterator it = li.begin(); it != li.end(); ++it) - files.push_back(dir + *it); - - li.clear(); - GetDirList(dir.c_str(), li, true); - for(std::deque::iterator it = li.begin(); it != li.end(); ++it) - stk.push(dir + *it); - } - } -} - // from http://board.byuu.org/viewtopic.php?f=10&t=1089&start=15 bool WildcardMatch(const char *str, const char *pattern) { @@ -464,7 +408,8 @@ bool WildcardMatch(const char *str, const char *pattern) { if(*pattern != *str && *pattern != '?') return false; - pattern++, str++; + ++pattern; + ++str; } while(*str) @@ -472,7 +417,7 @@ bool WildcardMatch(const char *str, const char *pattern) if(*pattern == '*') { if(!*++pattern) - return 1; + return true; mp = pattern; cp = str + 1; } @@ -488,7 +433,8 @@ bool WildcardMatch(const char *str, const char *pattern) } } - while(*pattern++ == '*'); + while(*pattern == '*') + ++pattern; return !*pattern; } diff --git a/ExternalLibs/ttvfs/VFSTools.h b/ExternalLibs/ttvfs/VFSTools.h index 36d3832..34b6f64 100644 --- a/ExternalLibs/ttvfs/VFSTools.h +++ b/ExternalLibs/ttvfs/VFSTools.h @@ -1,6 +1,9 @@ // VFSTools.h - useful functions and misc stuff // For conditions of distribution and use, see copyright notice in VFS.h +// Not all of these functions are used by ttvfs, but are added for user convenience. +// Everyone needs some path/file mangling functions at some point. + #ifndef VFS_TOOLS_H #define VFS_TOOLS_H @@ -13,12 +16,10 @@ VFS_NAMESPACE_START typedef std::deque StringList; -std::string stringToUpper(const std::string& s); -std::string stringToLower(const std::string& s); -void makeUppercase(std::string& s); -void makeLowercase(std::string& s); +void stringToUpper(std::string& s); +void stringToLower(std::string& s); void GetFileList(const char *, StringList& files); -void GetDirList(const char *, StringList& dirs, bool recursive = false); +void GetDirList(const char *, StringList& dirs, int depth = 0); // recursion depth: 0 = subdirs of current, 1 = subdirs one level down, ..., -1 = deep recursion bool FileExists(const char *); bool IsDirectory(const char *); bool CreateDir(const char*); @@ -30,7 +31,6 @@ const char *PathToFileName(const char *str); void MakeSlashTerminated(std::string& s); std::string StripFileExtension(const std::string& s); std::string StripLastPath(const std::string& s); -void GetFileListRecursive(std::string dir, StringList& files, bool withQueriedDir = false); bool WildcardMatch(const char *str, const char *pattern); size_t strnNLcpy(char *dst, const char *src, unsigned int n = -1); char *fastcat(char *s, const char *add); diff --git a/ExternalLibs/ttvfs_zip/VFSFileZip.cpp b/ExternalLibs/ttvfs_zip/VFSFileZip.cpp index 9bacaf9..2f4ecb3 100644 --- a/ExternalLibs/ttvfs_zip/VFSFileZip.cpp +++ b/ExternalLibs/ttvfs_zip/VFSFileZip.cpp @@ -163,9 +163,9 @@ const void *VFSFileZip::getBuf(allocator_func alloc /* = NULL */, delete_func de _delfunc = del; if(!zip_reader_reopen_vfsfile(_zip, 0)) - return false; // can happen if the underlying zip file was deleted + return NULL; // can happen if the underlying zip file was deleted if(!mz_zip_reader_extract_to_mem(_zip, _zipstat.m_file_index, _buf, sz, 0)) - return false; // this should not happen + return NULL; // this should not happen if(_mode.find("b") == std::string::npos) // text mode? { From 153dd522c9c0e29895b2976a8642bbec7e313373 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Wed, 26 Jun 2013 00:34:35 +0200 Subject: [PATCH 102/103] Fixed handling of IET_SCRIPT, rename Lua callback func getIngredientString() to getIngredientEffectString(), compile fix --- Aquaria/Continuity.cpp | 18 ++++++++---------- Aquaria/ScriptInterface.cpp | 3 ++- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Aquaria/Continuity.cpp b/Aquaria/Continuity.cpp index 8ad5fde..18ae971 100644 --- a/Aquaria/Continuity.cpp +++ b/Aquaria/Continuity.cpp @@ -591,6 +591,14 @@ std::string Continuity::getIEString(IngredientData *data, int i) case IET_LI: return dsq->continuity.stringBank.get(227); break; + case IET_SCRIPT: + if(dsq->game->cookingScript) + { + std::string ret = ""; + dsq->game->cookingScript->call("getIngredientEffectString", data->name.c_str(), &ret); + return ret; + } + break; } return ""; @@ -866,16 +874,6 @@ bool Continuity::applyIngredientEffects(IngredientData *data) std::string Continuity::getIngredientAffectsString(IngredientData *data) { - if(data->type == IET_SCRIPT) - { - if(dsq->game->cookingScript) - { - std::string ret = ""; - dsq->game->cookingScript->call("getIngredientString", data->name.c_str(), &ret); - return ret; - } - } - return getAllIEString(data); } diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index cb51bf3..6c7483f 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -85,7 +85,7 @@ static const char * const interfaceFunctions[] = { "entityDied", "exitState", "exitTimer", - "getIngredientString", + "getIngredientEffectString", "hitEntity", "hitSurface", "init", @@ -715,6 +715,7 @@ luaFunc(panicHandler) { std::string err = luaFormatStackInfo(L) + ": Lua PANIC: " + getString(L, -1); exit_error(err); + return 0; } static bool findFile_helper(const char *rawname, std::string &fname) From c243d6a69bc0f948b644d47dcb97def02b032360 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Wed, 26 Jun 2013 05:22:13 +0200 Subject: [PATCH 103/103] Fix typos in CMakeLists.txt