From fefb30a7b315ff2f185bfa01ef035f327c5ea055 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Mon, 26 Aug 2013 20:56:34 +0200 Subject: [PATCH] Allow entities and nodes to update while the game is paused. Added Lua functions: - node_setPauseFreeze() - entity_setPauseFreeze() - getFPS() Also fixed possible crash in entity_setStateTime(). --- Aquaria/Entity.cpp | 8 +++++++- Aquaria/Entity.h | 2 ++ Aquaria/Path.cpp | 3 ++- Aquaria/Path.h | 1 + Aquaria/ScriptInterface.cpp | 28 +++++++++++++++++++++++++++- 5 files changed, 39 insertions(+), 3 deletions(-) diff --git a/Aquaria/Entity.cpp b/Aquaria/Entity.cpp index 9bec306..fbfcb89 100644 --- a/Aquaria/Entity.cpp +++ b/Aquaria/Entity.cpp @@ -209,6 +209,7 @@ Entity::Entity() eatType = EAT_DEFAULT; stickToNaijasHead = false; spiritFreeze = true; + pauseFreeze = true; canLeaveWater = false; targetPriority = 0; //renderPass = RENDER_ALL; @@ -350,6 +351,11 @@ void Entity::setSpiritFreeze(bool v) spiritFreeze = v; } +void Entity::setPauseFreeze(bool v) +{ + pauseFreeze = v; +} + void Entity::setEntityProperty(EntityProperty ep, bool value) { entityProperties[int(ep)] = value; @@ -1145,7 +1151,7 @@ void Entity::update(float dt) Vector backupVel = vel; bool doUpdate = (updateCull == -1 || (position - core->screenCenter).isLength2DIn(updateCull)); - if (doUpdate && !dsq->game->isPaused()) + if (doUpdate && !(pauseFreeze && dsq->game->isPaused())) { if (!(getEntityType() == ET_AVATAR || getEntityType() == ET_INGREDIENT)) diff --git a/Aquaria/Entity.h b/Aquaria/Entity.h index a9ae2df..ad54317 100644 --- a/Aquaria/Entity.h +++ b/Aquaria/Entity.h @@ -428,6 +428,7 @@ public: virtual void shiftWorlds(WorldType lastWorld, WorldType worldType){} void setCanLeaveWater(bool v); void setSpiritFreeze(bool v); + void setPauseFreeze(bool v); void setEatType(EatType et, const std::string &file=""); EatType getEatType() { return eatType; } void setRiding(Entity *e); @@ -535,6 +536,7 @@ protected: bool stickToNaijasHead; bool spiritFreeze; + bool pauseFreeze; bool canLeaveWater; bool wasUnderWater; diff --git a/Aquaria/Path.cpp b/Aquaria/Path.cpp index 58e2959..cd34918 100644 --- a/Aquaria/Path.cpp +++ b/Aquaria/Path.cpp @@ -54,6 +54,7 @@ Path::Path() spawnEnemyDistance = 0; warpType = 0; spiritFreeze = true; + pauseFreeze = true; } void Path::clampPosition(Vector *pos, float radius) @@ -479,7 +480,7 @@ void Path::init() void Path::update(float dt) { - if (!dsq->game->isPaused() && !(spiritFreeze && dsq->game->isWorldPaused())) + if (!(pauseFreeze && dsq->game->isPaused()) && !(spiritFreeze && dsq->game->isWorldPaused())) { if (addEmitter && emitter) { diff --git a/Aquaria/Path.h b/Aquaria/Path.h index 7c85d83..b86b2f2 100644 --- a/Aquaria/Path.h +++ b/Aquaria/Path.h @@ -144,6 +144,7 @@ public: bool effectOn; bool spiritFreeze; + bool pauseFreeze; PathShape pathShape; diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 6391b5d..dff9401 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -2806,6 +2806,16 @@ luaFunc(entity_setSpiritFreeze) luaReturnNil(); } +luaFunc(entity_setPauseFreeze) +{ + Entity *e = entity(L); + if (e) + { + e->setPauseFreeze(getBool(L,2)); + } + luaReturnNil(); +} + luaFunc(node_setSpiritFreeze) { Path *e = path(L); @@ -2814,6 +2824,14 @@ luaFunc(node_setSpiritFreeze) luaReturnNil(); } +luaFunc(node_setPauseFreeze) +{ + Path *e = path(L); + if (e) + e->pauseFreeze = getBool(L,2); + luaReturnNil(); +} + luaFunc(entity_setFillGrid) { Entity *e = entity(L); @@ -6486,6 +6504,11 @@ luaFunc(getDT) luaReturnNum(core->get_current_dt()); } +luaFunc(getFPS) +{ + luaReturnInt(core->fps); +} + luaFunc(isNested) { luaReturnBool(core->isNested()); @@ -7234,7 +7257,7 @@ luaFunc(entity_setStateTime) float t = lua_tonumber(L, 2); if (e) e->setStateTime(t); - luaReturnNum(e->getStateTime()); + luaReturnNum(t); } luaFunc(entity_offsetUpdate) @@ -8317,6 +8340,7 @@ static const struct { luaRegister(getHalfTimer), luaRegister(getOldDT), luaRegister(getDT), + luaRegister(getFPS), luaRegister(setCostume), luaRegister(getCostume), luaRegister(getNoteName), @@ -8381,7 +8405,9 @@ static const struct { luaRegister(entity_setEatType), luaRegister(entity_setSpiritFreeze), + luaRegister(entity_setPauseFreeze), luaRegister(node_setSpiritFreeze), + luaRegister(node_setPauseFreeze), luaRegister(entity_setCanLeaveWater),