From 273b608214e99e815cc6995e1499085db6810b78 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Wed, 14 Mar 2012 00:58:59 +0100 Subject: [PATCH] Misc fixes and cleanups; fixed variadic Lua calls to self. Script interface: - entity_msg() will no longer corrupt the Lua stack if sending messages to itself. - added more info to non-critical Lua errors ("attempt to call a nil value", etc) - replaced many lua_tostring() with getString(), which does never return NULL. This prevents possible crashes when a non-string parameter is passed to functions expecting a string. Misc: - Removed classes BoxElement, DFSprite, Datafile, and related references. They were essentially unused. - Removed unused Element class member variables. - Show more lines in the in-game console. --- Aquaria/Avatar.cpp | 11 --- Aquaria/Avatar.h | 2 - Aquaria/DSQ.cpp | 61 +--------------- Aquaria/DSQ.h | 3 +- Aquaria/Element.cpp | 20 +----- Aquaria/Element.h | 33 +-------- Aquaria/Entity.cpp | 8 +-- Aquaria/Entity.h | 4 +- Aquaria/Game.cpp | 13 ++-- Aquaria/ScriptInterface.cpp | 139 ++++++++++++++++++------------------ Aquaria/ScriptedEntity.cpp | 2 +- Aquaria/ScriptedEntity.h | 2 +- BBGE/SkeletalSprite.cpp | 2 +- BBGE/SkeletalSprite.h | 2 +- CMakeLists.txt | 6 +- 15 files changed, 95 insertions(+), 213 deletions(-) diff --git a/Aquaria/Avatar.cpp b/Aquaria/Avatar.cpp index 0f76c8f..afdb7ee 100644 --- a/Aquaria/Avatar.cpp +++ b/Aquaria/Avatar.cpp @@ -4664,8 +4664,6 @@ Avatar::Avatar() : Entity(), ActionMapper() text = 0; - burstBar = 0; - /* chargeGraphic = new Particle; { @@ -9286,15 +9284,6 @@ void Avatar::onUpdate(float dt) if (ignoreInputDelay < 0) ignoreInputDelay = 0; } - - if (burstBar && burstBar->alpha == 1) - { - float amount = burst; - if (amount > 1) amount = 1; - if (amount < 0) amount = 0; - burstBar->frame = (19-(amount*19)); - } - //checkSpecial(); } //fuuugly diff --git a/Aquaria/Avatar.h b/Aquaria/Avatar.h index 14ad8c0..a77f7f8 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. #include "../BBGE/Particles.h" #include "../BBGE/BitmapFont.h" -#include "../BBGE/DFSprite.h" #include "DSQ.h" #include "Hair.h" @@ -156,7 +155,6 @@ public: bool isCharging(); void slowToRest(); void debugMsg(const std::string &msg); - DFSprite *burstBar; void setBlind(float time); void onBlindTest(); diff --git a/Aquaria/DSQ.cpp b/Aquaria/DSQ.cpp index bb7bc5f..578fa76 100644 --- a/Aquaria/DSQ.cpp +++ b/Aquaria/DSQ.cpp @@ -125,12 +125,10 @@ static void Linux_CopyTree(const char *src, const char *dst) #endif -float titTimer = 0; - const int saveSlotPageSize = 4; int maxPages = 15; #ifdef AQUARIA_BUILD_CONSOLE -const int MAX_CONSOLELINES = 14; +const int MAX_CONSOLELINES = 18; #endif DSQ *dsq = 0; @@ -2476,7 +2474,7 @@ void DSQ::clickRingEffect(Vector pos, int type, Vector color, float ut) } } -Entity *DSQ::getEntityByName(std::string name) +Entity *DSQ::getEntityByName(const std::string& name) { Entity *e = 0; FOR_ENTITIES(i) @@ -4737,61 +4735,6 @@ void DSQ::playVisualEffect(int vfx, Vector position, Entity *target) } } -// get the closest, active, in range element to the vector -/* -Element *DSQ::getElementAtVector(const Vector &vec) -{ - Element *returnElement = 0; - int smallestDistance = 9999; - for (int i = 0; i < elements.size(); i++) - { - if (elements[i]->isActive() && elements[i]->getTotalInteractions() > 0) - { - int distanceToElementI = elements[i]->getFakeDistanceFromCenterToVector(vec); - if (elements[i]->isVectorInActivationRange(vec) && distanceToElementI < smallestDistance) - { - smallestDistance = distanceToElementI; - returnElement = elements[i]; - } - } - } - return returnElement; -} -*/ - -Element *DSQ::getElementWithType(Element::Type type) -{ - for (int i = 0; i < elements.size(); i++) - { - if (elements[i]->getElementType() == type) - { - return elements[i]; - } - } - return 0; -} - -/* -Element *DSQ::getClosestElementWithType(Element::Type type, Element *e) -{ - Element *returnElement = 0; - long smallestDistance = 999999; - for (int i = 0; i < elements.size(); i++) - { - if (elements[i]->isActive() && elements[i]->getElementType() == type) - { - long distanceToElementI = elements[i]->getFakeDistanceFromCenterToVector(e->position); - if (distanceToElementI < smallestDistance) - { - smallestDistance = distanceToElementI; - returnElement = elements[i]; - } - } - } - return returnElement; -} -*/ - void DSQ::addElement(Element *e) { elements.push_back(e); diff --git a/Aquaria/DSQ.h b/Aquaria/DSQ.h index 8b241ae..6f287da 100644 --- a/Aquaria/DSQ.h +++ b/Aquaria/DSQ.h @@ -1307,7 +1307,6 @@ public: int getNumElements() const {return elements.size();} Element *getElement(int idx) const {return elements[idx];} Element *getFirstElementOnLayer(int layer) const {return layer<0 || layer>15 ? 0 : firstElementOnLayer[layer];} - Element *getElementWithType(Element::Type type); void clearElements(); // Used only by scene editor: void removeElement(int idx); @@ -1353,7 +1352,7 @@ public: void toggleInputMode(); void shakeCamera(float mag, float time); Vector avStart; - Entity *getEntityByName(std::string name); + Entity *getEntityByName(const std::string &name); Entity *getEntityByNameNoCase(std::string name); void doSavePoint(const Vector &position); diff --git a/Aquaria/Element.cpp b/Aquaria/Element.cpp index e448ffd..c4a94ef 100644 --- a/Aquaria/Element.cpp +++ b/Aquaria/Element.cpp @@ -22,25 +22,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "Game.h" #include "Avatar.h" -ElementActivationRange::ElementActivationRange() : radius(64), type(CIRCLE) -{ -} - -ElementActivationRange::Type ElementActivationRange::getType() -{ - return type; -} - -Element::Element(Element::Type elementType) : Quad(), type(elementType) +Element::Element() : Quad() { elementFlag = EF_NONE; - angleFromGroupCenter = distFromGroupCenter = 0; wavyFlip = false; - parallax = 1; elementEffectIndex = -1; elementActive = true; bgLayer = 0; - dontSave = false; wavyAngleOffset=0; wavyMagnitude=0; @@ -52,7 +40,6 @@ Element::Element(Element::Type elementType) : Quad(), type(elementType) wavyRadius = 0; wavyMin = 0; wavyMax = 0; - oldRotation = 0; templateIdx = -1; setStatic(true); @@ -429,11 +416,6 @@ void Element::fillGrid() } } -Element::Type Element::getElementType() -{ - return type; -} - // override this functionality as needed bool Element::canSeeAvatar(Avatar *avatar) { diff --git a/Aquaria/Element.h b/Aquaria/Element.h index bdfc00f..e3b156b 100644 --- a/Aquaria/Element.h +++ b/Aquaria/Element.h @@ -25,22 +25,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. class Avatar; -class ElementActivationRange -{ -public: - ElementActivationRange(); - void isVectorInRange(); - enum Type - { - CIRCLE, - RECT - }; - float radius; - Type getType(); -protected: - Type type; -}; - enum ElementFlag { @@ -61,26 +45,18 @@ enum ElementFlag class Element : public Quad { public: - enum Type - { - UNDEFINED, - BOX - }; - - Element(Type elementType); + Element(); ~Element(); void destroy(); //void interact(Interaction::Type interactionType, Avatar *avatar); bool canSeeAvatar(Avatar *avatar); void update(float dt); bool isActive(); - Type getElementType(); //InteractionContainer interactions; int templateIdx; int bgLayer; Element *bgLayerNext; float getSortDepth(); - bool dontSave; void render(); //Flags elementFlags; ElementFlag elementFlag; @@ -89,8 +65,6 @@ public: int getElementEffectIndex(); void setElementEffectByIndex(int e); void setElementActive(bool v) { elementActive = v; } - float parallax; - float angleFromGroupCenter, distFromGroupCenter, oldRotation; protected: void setGridFromWavy(); float wavyAngleOffset, wavyMagnitude, wavyLerpIn; @@ -101,10 +75,8 @@ protected: void updateEffects(float dt); int elementEffectIndex, elementEffectType; bool elementActive; - ElementActivationRange activationRange; - Type type; }; - +/* class BoxElement : public Element { public: @@ -113,6 +85,7 @@ public: protected: int ww,hh; }; +*/ typedef std::vector ElementContainer; diff --git a/Aquaria/Entity.cpp b/Aquaria/Entity.cpp index 6645bec..54a4e9a 100644 --- a/Aquaria/Entity.cpp +++ b/Aquaria/Entity.cpp @@ -165,7 +165,7 @@ bool Entity::canSetBoneLock() return true; } -Entity::Entity() : StateMachine(), DFSprite() +Entity::Entity() { addType(SCO_ENTITY); poison = 0.0f; @@ -1266,7 +1266,7 @@ void Entity::update(float dt) //skeletalSprite.setFreeze(true); if (frozenTimer == 0 || getState() == STATE_PUSH) - DFSprite::update(dt); + AnimatedSprite::update(dt); onAlwaysUpdate(dt); // always, always update: @@ -1873,7 +1873,7 @@ void Entity::onUpdate(float dt) } } - DFSprite::onUpdate(dt); + AnimatedSprite::onUpdate(dt); Vector v = position - lastPos; lastMove = v; @@ -2971,7 +2971,7 @@ void Entity::render() blurShader.bind(); set = true; } - DFSprite::render(); + AnimatedSprite::render(); //if (beautyFlip && blurShader.isLoaded() && flipScale.isInterpolating()) if (set) blurShader.unbind(); diff --git a/Aquaria/Entity.h b/Aquaria/Entity.h index 4b0b697..551a550 100644 --- a/Aquaria/Entity.h +++ b/Aquaria/Entity.h @@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #pragma once -#include "../BBGE/DFSprite.h" +#include "../BBGE/AnimatedSprite.h" #include "../BBGE/StateMachine.h" #include "../ExternalLibs/tinyxml.h" #include "../BBGE/SkeletalSprite.h" @@ -194,7 +194,7 @@ enum BounceType BOUNCE_REAL = 1 }; -class Entity : public DFSprite, public StateMachine +class Entity : public AnimatedSprite, public StateMachine { public: Entity(); diff --git a/Aquaria/Game.cpp b/Aquaria/Game.cpp index 8c2cb53..ff563ac 100644 --- a/Aquaria/Game.cpp +++ b/Aquaria/Game.cpp @@ -1898,7 +1898,7 @@ Element* Game::createElement(int idx, Vector position, int bgLayer, RenderObject if (!et) et = this->getElementTemplateByIdx(idx); - Element *element = new Element(Element::UNDEFINED); + Element *element = new Element(); if (et) { element->setTexture(et->gfx); @@ -4951,7 +4951,7 @@ bool Game::loadSceneXML(std::string scene) saveFile->InsertEndChild(newSF); } - + /* TiXmlElement *boxElement = doc.FirstChildElement("BoxElement"); while (boxElement) { @@ -4962,7 +4962,7 @@ bool Game::loadSceneXML(std::string scene) dsq->addElement(b); boxElement = boxElement->NextSiblingElement("BoxElement"); } - + */ TiXmlElement *simpleElements = doc.FirstChildElement("SE"); while (simpleElements) { @@ -5620,12 +5620,7 @@ void Game::saveScene(std::string scene) for (i = 0; i < dsq->getNumElements(); i++) { Element *e = dsq->getElement(i); - if (!e->dontSave) - { - if (e->getElementType() == Element::BOX) {} - else - simpleElements[e->bgLayer] << e->templateIdx << " " << int(e->position.x) << " " << int(e->position.y) << " " << int(e->rotation.z) << " " << e->scale.x << " " << e->scale.y << " " << int(e->isfh()) << " " << int(e->isfv()) << " " << e->elementFlag << " " << e->getElementEffectIndex() << " " << e->isRepeatingTextureToFill() << " "; - } + simpleElements[e->bgLayer] << e->templateIdx << " " << int(e->position.x) << " " << int(e->position.y) << " " << int(e->rotation.z) << " " << e->scale.x << " " << e->scale.y << " " << int(e->isfh()) << " " << int(e->isfv()) << " " << e->elementFlag << " " << e->getElementEffectIndex() << " " << e->isRepeatingTextureToFill() << " "; } if (dsq->game->entitySaveData.size() > 0) diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 3cad9e8..5f6477a 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -525,8 +525,8 @@ Bone *bone(lua_State *L, int slot = 1) static inline Path *pathFromName(lua_State *L, int slot = 1) { - std::string s = lua_tostring(L, slot); - stringToLowerUserData(s); + std::string s = getString(L, slot); + stringToLower(s); Path *p = dsq->game->getPathByName(s); if (!p) { @@ -1568,7 +1568,7 @@ luaFunc(cureAllStatus) luaFunc(setMusicToPlay) { if (lua_isstring(L, 1)) - dsq->game->setMusicToPlay(lua_tostring(L, 1)); + dsq->game->setMusicToPlay(getString(L, 1)); luaReturnNil(); } @@ -2210,8 +2210,6 @@ luaFunc(debugLog) const char *s = lua_tostring(L, 1); if(s) debugLog(s); - else - scriptError("debugLog() not a string"); luaReturnStr(s); } @@ -2220,8 +2218,6 @@ luaFunc(errorLog) const char *s = lua_tostring(L, 1); if(s) errorLog(s); - else - scriptError("errorLog() not a string"); luaReturnStr(s); } @@ -2256,7 +2252,7 @@ luaFunc(entity_setSegmentTexture) RenderObject *ro = e->getSegment(lua_tonumber(L, 2)); if (ro) { - ro->setTexture(lua_tostring(L, 3)); + ro->setTexture(getString(L, 3)); } } luaReturnNil(); @@ -2295,7 +2291,6 @@ luaFunc(entity_findNearestEntityOfType) luaFunc(createShot) { - std::string shotData = lua_tostring(L, 1); Entity *e = entity(L,2); Entity *t = 0; if (lua_touserdata(L, 3) != NULL) @@ -2308,7 +2303,7 @@ luaFunc(createShot) aim.y = lua_tonumber(L, 7); - s = dsq->game->fireShot(shotData, e, t, pos, aim); + s = dsq->game->fireShot(getString(L, 1), e, t, pos, aim); luaReturnPtr(s); } @@ -2325,7 +2320,7 @@ luaFunc(entity_sound) // so a cheap hack like this fixes it without changing older scripts. -- FG if (freq >= 100) freq *= 0.001f; - e->sound(lua_tostring(L, 2), freq, lua_tonumber(L, 4)); + e->sound(getString(L, 2), freq, lua_tonumber(L, 4)); } luaReturnNil(); } @@ -2337,7 +2332,7 @@ luaFunc(entity_playSfx) if (e && !dsq->isSkippingCutscene()) { PlaySfx sfx = dsq->calcPositionalSfx(e->position, lua_tonumber(L, 7)); - sfx.name = lua_tostring(L, 2); + sfx.name = getString(L, 2); sfx.freq = lua_tonumber(L, 3); float vol = lua_tonumber(L, 4); sfx.loops = lua_tonumber(L, 5); @@ -2572,7 +2567,7 @@ luaFunc(avatar_getSpellCharge) luaFunc(jumpState) { - dsq->enqueueJumpState(lua_tostring(L, 1), getBool(L, 2)); + dsq->enqueueJumpState(getString(L, 1), getBool(L, 2)); luaReturnNil(); } @@ -2855,7 +2850,7 @@ luaFunc(entity_createEntity) Entity *e = entity(L); Entity *ret = NULL; if (e) - ret = dsq->game->createEntity(dsq->getEntityTypeIndexByName(lua_tostring(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, 0, 0, true); luaReturnPtr(ret); } @@ -3241,15 +3236,10 @@ luaFunc(entity_initSkeletal) ScriptedEntity *e = scriptedEntity(L); e->renderQuad = false; e->setWidthHeight(128, 128); - e->skeletalSprite.loadSkeletal(lua_tostring(L, 2)); - if (lua_isstring(L, 3)) - { - std::string s = lua_tostring(L, 3); - if (!s.empty()) - { - e->skeletalSprite.loadSkin(s); - } - } + e->skeletalSprite.loadSkeletal(getString(L, 2)); + const char *s = lua_tostring(L, 3); + if (s && *s) + e->skeletalSprite.loadSkin(s); luaReturnNil(); } @@ -3301,7 +3291,7 @@ luaFunc(entity_animate) transition = 0; else if (transition == 0) transition = 0.2; - ret = skel->transitionAnimate(lua_tostring(L, 2), transition, lua_tointeger(L, 3), lua_tointeger(L, 4)); + ret = skel->transitionAnimate(getString(L, 2), transition, lua_tointeger(L, 3), lua_tointeger(L, 4)); } luaReturnNum(ret); } @@ -3334,8 +3324,8 @@ luaFunc(spawnAroundEntity) Entity *e = entity(L); int num = lua_tonumber(L, 2); int radius = lua_tonumber(L, 3); - std::string entType = lua_tostring(L, 4); - std::string name = lua_tostring(L, 5); + std::string entType = getString(L, 4); + std::string name = getString(L, 5); int idx = dsq->game->getIdxForEntityType(entType); if (e) { @@ -3424,7 +3414,7 @@ luaFunc(isPlat) luaFunc(createEntity) { - std::string type = lua_tostring(L, 1); + std::string type = getString(L, 1); std::string name; if (lua_isstring(L, 2)) name = lua_tostring(L, 2); @@ -3483,7 +3473,7 @@ luaFunc(setCameraLerpDelay) luaFunc(setControlHint) { - std::string str = lua_tostring(L, 1); + std::string str = getString(L, 1); bool left = getBool(L, 2); bool right = getBool(L, 3); bool middle = getBool(L, 4); @@ -3657,7 +3647,7 @@ luaFunc(getWallNormal) luaFunc(incrFlag) { - std::string f = lua_tostring(L, 1); + std::string f = getString(L, 1); int v = 1; if (lua_isnumber(L, 2)) v = lua_tointeger(L, 2); @@ -3667,7 +3657,7 @@ luaFunc(incrFlag) luaFunc(decrFlag) { - std::string f = lua_tostring(L, 1); + std::string f = getString(L, 1); int v = 1; if (lua_isnumber(L, 2)) v = lua_tointeger(L, 2); @@ -4129,7 +4119,7 @@ luaFunc(entity_initSegments) { ScriptedEntity *se = scriptedEntity(L); if (se) - se->initSegments(lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4), lua_tostring(L, 5), lua_tostring(L, 6), lua_tointeger(L, 7), lua_tointeger(L, 8), lua_tonumber(L, 9), lua_tointeger(L, 10)); + se->initSegments(lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4), getString(L, 5), getString(L, 6), lua_tointeger(L, 7), lua_tointeger(L, 8), lua_tonumber(L, 9), lua_tointeger(L, 10)); luaReturnNil(); } @@ -4304,7 +4294,7 @@ luaFunc(setNaijaHeadTexture) Avatar *a = dsq->game->avatar; if (a) { - a->setHeadTexture(lua_tostring(L, 1), lua_tonumber(L, 2)); + a->setHeadTexture(getString(L, 1), lua_tonumber(L, 2)); } luaReturnNil(); } @@ -4459,7 +4449,7 @@ luaFunc(setupBasicEntity) ScriptedEntity *se = scriptedEntity(L); //-- texture, health, manaballamount, exp, money, collideRadius, initState if (se) - se->setupBasicEntity(lua_tostring(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5), lua_tointeger(L, 6), lua_tointeger(L, 7), lua_tointeger(L, 8), lua_tointeger(L, 9), lua_tointeger(L, 10), lua_tointeger(L, 11), lua_tointeger(L, 12), lua_tointeger(L, 13), lua_tointeger(L, 14)); + se->setupBasicEntity(getString(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5), lua_tointeger(L, 6), lua_tointeger(L, 7), lua_tointeger(L, 8), lua_tointeger(L, 9), lua_tointeger(L, 10), lua_tointeger(L, 11), lua_tointeger(L, 12), lua_tointeger(L, 13), lua_tointeger(L, 14)); luaReturnNil(); } @@ -4497,7 +4487,7 @@ luaFunc(entity_setDeathSound) Entity *e = entity(L); if (e) { - e->deathSound = lua_tostring(L, 2); + e->deathSound = getString(L, 2); } luaReturnNil(); } @@ -4767,7 +4757,7 @@ luaFunc(entity_getBoneByIdx) luaFunc(entity_getBoneByName) { Entity *e = entity(L); - luaReturnPtr(e ? e->skeletalSprite.getBoneByName(lua_tostring(L, 2)) : NULL); + luaReturnPtr(e ? e->skeletalSprite.getBoneByName(getString(L, 2)) : NULL); } luaFunc(bone_getIndex) @@ -4794,9 +4784,10 @@ luaFunc(bone_isName) { Bone *b = bone(L); bool v = false; - if (b) + const char *s = lua_tostring(L, 2); + if (b && s) { - v = b->name == lua_tostring(L, 2); + v = b->name == s; } luaReturnBool(v); } @@ -4911,7 +4902,7 @@ luaFunc(entity_setCurrentTarget) luaFunc(setMiniMapHint) { - std::istringstream is(lua_tostring(L, 1)); + std::istringstream is(getString(L, 1)); is >> dsq->game->miniMapHint.scene >> dsq->game->miniMapHint.warpAreaType; dsq->game->updateMiniMapHintPosition(); @@ -4920,10 +4911,10 @@ luaFunc(setMiniMapHint) luaFunc(entityFollowEntity) { - Entity *e = dsq->getEntityByName(lua_tostring(L, 1)); + Entity *e = dsq->getEntityByName(getString(L, 1)); if (e) { - e->followEntity = dsq->getEntityByName(lua_tostring(L, 2)); + e->followEntity = dsq->getEntityByName(getString(L, 2)); } luaReturnNil(); @@ -4967,7 +4958,7 @@ luaFunc(toggleInput) luaFunc(warpAvatar) { dsq->game->positionToAvatar = Vector(lua_tointeger(L, 2),lua_tointeger(L, 3)); - dsq->game->transitionToScene(lua_tostring(L, 1)); + dsq->game->transitionToScene(getString(L, 1)); luaReturnNil(); } @@ -5165,7 +5156,7 @@ luaFunc(stopMusic) luaFunc(playMusic) { float crossfadeTime = 0.8; - dsq->sound->playMusic(std::string(lua_tostring(L, 1)), SLT_LOOP, SFT_CROSS, crossfadeTime); + dsq->sound->playMusic(getString(L, 1), SLT_LOOP, SFT_CROSS, crossfadeTime); luaReturnNil(); } @@ -5179,7 +5170,7 @@ luaFunc(playMusicStraight) luaFunc(playMusicOnce) { float crossfadeTime = 0.8; - dsq->sound->playMusic(std::string(lua_tostring(L, 1)), SLT_NONE, SFT_CROSS, crossfadeTime); + dsq->sound->playMusic(getString(L, 1), SLT_NONE, SFT_CROSS, crossfadeTime); luaReturnNil(); } @@ -5618,7 +5609,7 @@ luaFunc(wait) luaFunc(warpNaijaToEntity) { - Entity *e = dsq->getEntityByName(lua_tostring(L, 1)); + Entity *e = dsq->getEntityByName(getString(L, 1)); if (e) { dsq->overlay->alpha.interpolateTo(1, 1); @@ -5914,7 +5905,7 @@ luaFunc(entity_rotateToTarget) luaFunc(entity_partWidthHeight) { ScriptedEntity *e = scriptedEntity(L); - Quad *r = (Quad*)e->partMap[lua_tostring(L, 2)]; + Quad *r = (Quad*)e->partMap[getString(L, 2)]; if (r) { int w = lua_tointeger(L, 3); @@ -5927,7 +5918,7 @@ luaFunc(entity_partWidthHeight) luaFunc(entity_partSetSegs) { ScriptedEntity *e = scriptedEntity(L); - Quad *r = (Quad*)e->partMap[lua_tostring(L, 2)]; + Quad *r = (Quad*)e->partMap[getString(L, 2)]; if (r) { r->setSegs(lua_tointeger(L, 3), lua_tointeger(L, 4), lua_tonumber(L, 5), lua_tonumber(L, 6), lua_tonumber(L, 7), lua_tonumber(L, 8), lua_tonumber(L, 9), lua_tointeger(L, 10)); @@ -6011,7 +6002,7 @@ luaFunc(node_setEffectOn) Path *p = path(L, 1); if (p) p->setEffectOn(getBool(L, 2)); - luaReturnNum(0); + luaReturnNil(); } luaFunc(node_activate) @@ -6038,12 +6029,11 @@ luaFunc(node_setElementsInLayerActive) { if (e && p->isCoordinateInside(e->position)) { - debugLog("setting an element to the value"); e->setElementActive(v); } } } - luaReturnNum(0); + luaReturnNil(); } luaFunc(node_getNumEntitiesIn) @@ -6312,7 +6302,7 @@ luaFunc(entity_partAlpha) ScriptedEntity *e = scriptedEntity(L); if (e) { - RenderObject *r = e->partMap[lua_tostring(L, 2)]; + RenderObject *r = e->partMap[getString(L, 2)]; if (r) { float start = lua_tonumber(L, 3); @@ -6329,7 +6319,7 @@ luaFunc(entity_partBlendType) { ScriptedEntity *e = scriptedEntity(L); if (e) - e->partMap[lua_tostring(L, 2)]->setBlendType(lua_tointeger(L, 3)); + e->partMap[getString(L, 2)]->setBlendType(lua_tointeger(L, 3)); luaReturnInt(0); } @@ -6338,7 +6328,7 @@ luaFunc(entity_partRotate) ScriptedEntity *e = scriptedEntity(L); if (e) { - RenderObject *r = e->partMap[lua_tostring(L, 2)]; + RenderObject *r = e->partMap[getString(L, 2)]; if (r) { r->rotation.interpolateTo(Vector(0,0,lua_tointeger(L, 3)), lua_tonumber(L, 4), lua_tointeger(L, 5), lua_tointeger(L, 6), lua_tointeger(L, 7)); @@ -6405,7 +6395,7 @@ luaFunc(entity_initHair) ScriptedEntity *se = scriptedEntity(L); if (se) { - se->initHair(lua_tonumber(L, 2), lua_tonumber(L, 3), lua_tonumber(L, 4), lua_tostring(L, 5)); + se->initHair(lua_tonumber(L, 2), lua_tonumber(L, 3), lua_tonumber(L, 4), getString(L, 5)); } luaReturnNil(); } @@ -6463,8 +6453,8 @@ luaFunc(entity_exertHairForce) luaFunc(entity_initPart) { - std::string partName(lua_tostring(L, 2)); - std::string partTex(lua_tostring(L, 3)); + std::string partName(getString(L, 2)); + std::string partTex(getString(L, 3)); Vector partPosition(lua_tointeger(L, 4), lua_tointeger(L, 5)); int renderAfter = lua_tointeger(L, 6); bool partFlipH = lua_tointeger(L, 7); @@ -6612,7 +6602,7 @@ luaFunc(entity_fireGas) int radius = lua_tointeger(L, 2); float life = lua_tonumber(L, 3); float damage = lua_tonumber(L, 4); - std::string gfx = lua_tostring(L, 5); + std::string gfx = getString(L, 5); float colorx = lua_tonumber(L, 6); float colory = lua_tonumber(L, 7); float colorz = lua_tonumber(L, 8); @@ -6730,7 +6720,7 @@ luaFunc(fade3) luaFunc(vision) { - dsq->vision(lua_tostring(L, 1), lua_tonumber(L, 2), getBool(L, 3)); + dsq->vision(getString(L, 1), lua_tonumber(L, 2), getBool(L, 3)); luaReturnNil(); } @@ -6747,19 +6737,19 @@ luaFunc(voice) vmod = -1; else if (vmod == -1) vmod = 0; - dsq->voice(lua_tostring(L, 1), vmod); + dsq->voice(getString(L, 1), vmod); luaReturnNil(); } luaFunc(voiceOnce) { - dsq->voiceOnce(lua_tostring(L, 1)); + dsq->voiceOnce(getString(L, 1)); luaReturnNil(); } luaFunc(voiceInterupt) { - dsq->voiceInterupt(lua_tostring(L, 1)); + dsq->voiceInterupt(getString(L, 1)); luaReturnNil(); } @@ -9046,6 +9036,9 @@ bool Script::doCall(int nparams, int nrets) else { lastError = lua_tostring(L, -1); + lastError += " ["; + lastError += luaFormatStackInfo(L); + lastError += "]"; lua_pop(L, 1); result = false; } @@ -9186,22 +9179,32 @@ bool Script::call(const char *name, void *param1, void *param2, void *param3, fl bool Script::callVariadic(const char *name, lua_State *fromL, int nparams, void *param) { - // clone topmost nparams elements, they will be popped by xmove - for (int i = 0; i < nparams; ++i) - lua_pushvalue(fromL, -nparams); - lookupFunc(name); // [f] luaPushPointer(L, param); // [f, p] - // Move them to the other stack - lua_xmove(fromL, L, nparams); // [f, p, ...] + if (L != fromL) + { + // clone topmost nparams elements, they will be popped by xmove + for (int i = 0; i < nparams; ++i) + lua_pushvalue(fromL, -nparams); + + // Move them to the other stack + lua_xmove(fromL, L, nparams); // [f, p, ...] + } + else + { + // Same stack, insert pointer param below the parameters which are already there + lua_insert(L, -(nparams + 2)); + // and the function, now below the pointer param + lua_insert(L, -(nparams + 2)); + } // Do the call bool success = doCall(nparams + 1, LUA_MULTRET); // after returning from the call, push everything that is left on the stack - // (= what the function returned) back onto the caller's stack. - if (success) + // (= what the function returned) back onto the caller's stack, if not already there. + if (success && L != fromL) { // clone elements again int count = lua_gettop(L); diff --git a/Aquaria/ScriptedEntity.cpp b/Aquaria/ScriptedEntity.cpp index 0e25137..832d887 100644 --- a/Aquaria/ScriptedEntity.cpp +++ b/Aquaria/ScriptedEntity.cpp @@ -250,7 +250,7 @@ void ScriptedEntity::setupEntity(const std::string &tex, int lcode) this->layer = dsq->getEntityLayerToLayer(lcode); } -void ScriptedEntity::setupBasicEntity(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 ScriptedEntity::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) { //this->updateCull = updateCull; updateCull = -1; diff --git a/Aquaria/ScriptedEntity.h b/Aquaria/ScriptedEntity.h index 5675e0b..432ba5c 100644 --- a/Aquaria/ScriptedEntity.h +++ b/Aquaria/ScriptedEntity.h @@ -35,7 +35,7 @@ public: void resetTimer(float t); void setEntityLayer(int layer); void setupEntity(const std::string &tex, int layer=0); - void setupBasicEntity(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 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); diff --git a/BBGE/SkeletalSprite.cpp b/BBGE/SkeletalSprite.cpp index 8bc22a2..9bf8afc 100644 --- a/BBGE/SkeletalSprite.cpp +++ b/BBGE/SkeletalSprite.cpp @@ -740,7 +740,7 @@ void SkeletalSprite::animate(const std::string &animation, int loop, int layer) animLayers[layer].animate(animation, loop); } -float SkeletalSprite::transitionAnimate(std::string anim, float time, int loop, int layer) +float SkeletalSprite::transitionAnimate(const std::string& anim, float time, int loop, int layer) { AnimationLayer *animLayer = getAnimationLayer(layer); if (animLayer) diff --git a/BBGE/SkeletalSprite.h b/BBGE/SkeletalSprite.h index 668c92f..6d2165f 100644 --- a/BBGE/SkeletalSprite.h +++ b/BBGE/SkeletalSprite.h @@ -217,7 +217,7 @@ public: void stopAnimation(int layer=0); void stopAllAnimations(); - float transitionAnimate(std::string anim, float time, int loop=0, int layer=0); + float transitionAnimate(const std::string& anim, float time, int loop=0, int layer=0); bool isAnimating(int layer=0); diff --git a/CMakeLists.txt b/CMakeLists.txt index ee72437..380819f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -294,7 +294,6 @@ SET(AQUARIA_SRCS ${SRCDIR}/Avatar.cpp ${SRCDIR}/Beam.cpp ${SRCDIR}/BitBlotLogo.cpp - ${SRCDIR}/BoxElement.cpp ${SRCDIR}/CollideEntity.cpp ${SRCDIR}/Continuity.cpp ${SRCDIR}/Credits.cpp @@ -348,6 +347,7 @@ SET(AQUARIA_SRCS # Apparently not used at the moment. Listed here just for completeness. SET(AQUARIA_SRCS_UNUSED + ${SRCDIR}/BoxElement.cpp ${SRCDIR}/BubbleRender.cpp ${SRCDIR}/FFTNotes.cpp ${SRCDIR}/StarRenderer.cpp @@ -370,10 +370,8 @@ SET(BBGE_SRCS ${BBGEDIR}/Core.cpp ${BBGEDIR}/Cube.cpp ${BBGEDIR}/DarkLayer.cpp - ${BBGEDIR}/Datafile.cpp ${BBGEDIR}/DebugFont.cpp ${BBGEDIR}/DeflateCompressor.cpp - ${BBGEDIR}/DFSprite.cpp ${BBGEDIR}/Effects.cpp ${BBGEDIR}/Emitter.cpp ${BBGEDIR}/Event.cpp @@ -450,6 +448,8 @@ SET(BBGE_SRCS_UNUSED ${BBGEDIR}/BloomEffect.cpp ${BBGEDIR}/CShim.cpp ${BBGEDIR}/Cutscene.cpp + ${BBGEDIR}/Datafile.cpp + ${BBGEDIR}/DFSprite.cpp ${BBGEDIR}/FileVars.cpp ${BBGEDIR}/Light.cpp ${BBGEDIR}/LightCone.cpp