1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-06-08 17:42:05 +00:00

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()
This commit is contained in:
fgenesis 2013-04-25 02:51:54 +02:00
parent 3ed40e73d3
commit 55ead19076
16 changed files with 65 additions and 27 deletions

View file

@ -752,11 +752,6 @@ bool Avatar::isSinging()
return singing; return singing;
} }
void Avatar::shift()
{
dsq->continuity.shiftWorlds();
}
void Avatar::applyWorldEffects(WorldType type) void Avatar::applyWorldEffects(WorldType type)
{ {
static bool oldfh=false; static bool oldfh=false;
@ -5275,7 +5270,7 @@ void Avatar::updateWallJump(float dt)
void Avatar::updateRoll(float dt) void Avatar::updateRoll(float dt)
{ {
if (!inputEnabled || dsq->continuity.getWorldType() == WT_SPIRIT) if (!inputEnabled || dsq->game->isWorldPaused())
{ {
if (rolling) if (rolling)
stopRoll(); stopRoll();
@ -6205,7 +6200,7 @@ void Avatar::onUpdate(float dt)
//if (core->getNestedMains() == 1) //if (core->getNestedMains() == 1)
{ {
if (getState() != STATE_TRANSFORM && dsq->continuity.getWorldType() == WT_NORMAL) if (getState() != STATE_TRANSFORM && !dsq->game->isWorldPaused())
{ {
formAbilityUpdate(dt); 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) if (bursting)
{ {
@ -7156,7 +7151,7 @@ void Avatar::onUpdate(float dt)
if (dsq->game->collideCircleWithGrid(position, collideRadius)) if (dsq->game->collideCircleWithGrid(position, collideRadius))
{ {
if (dsq->game->lastCollideTileType == OT_HURT if (dsq->game->lastCollideTileType == OT_HURT
&& dsq->continuity.getWorldType() != WT_SPIRIT && !dsq->game->isWorldPaused()
&& dsq->continuity.form != FORM_NATURE) && dsq->continuity.form != FORM_NATURE)
{ {
DamageData d; DamageData d;

View file

@ -160,7 +160,6 @@ public:
Entity *entityToActivate; Entity *entityToActivate;
Path *pathToActivate; Path *pathToActivate;
void shift();
void applyWorldEffects(WorldType type); void applyWorldEffects(WorldType type);
void toggleMovement(bool on); void toggleMovement(bool on);

View file

@ -1916,9 +1916,15 @@ void Continuity::shiftWorlds()
{ {
WorldType lastWorld = worldType; WorldType lastWorld = worldType;
if (worldType == WT_NORMAL) if (worldType == WT_NORMAL)
{
worldType = WT_SPIRIT; worldType = WT_SPIRIT;
dsq->game->setWorldPaused(true);
}
else if (worldType == WT_SPIRIT) else if (worldType == WT_SPIRIT)
{
worldType = WT_NORMAL; worldType = WT_NORMAL;
dsq->game->setWorldPaused(false);
}
FOR_ENTITIES(i) FOR_ENTITIES(i)
{ {
Entity *e = *i; Entity *e = *i;
@ -2018,7 +2024,7 @@ void Continuity::applyWorldEffects(WorldType type, bool transition, bool affectM
dsq->game->avatar->enableInput(); dsq->game->avatar->enableInput();
*/ */
} }
worldType = type; //worldType = type;
} }
void Continuity::eatBeast(const EatData &eatData) void Continuity::eatBeast(const EatData &eatData)

View file

@ -4576,6 +4576,7 @@ void DSQ::onUpdate(float dt)
os << "altState: " << core->getKeyState(KEY_LALT) << " | " << core->getKeyState(KEY_RALT) << std::endl; os << "altState: " << core->getKeyState(KEY_LALT) << " | " << core->getKeyState(KEY_RALT) << std::endl;
os << "PMFree: " << particleManager->getFree() << " Active: " << particleManager->getNumActive() << std::endl; os << "PMFree: " << particleManager->getFree() << " Active: " << particleManager->getNumActive() << std::endl;
os << "cameraPos: (" << dsq->cameraPos.x << ", " << dsq->cameraPos.y << ")" << 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; os << "voiceTime: " << dsq->sound->getVoiceTime() << " bNat: " << dsq->game->bNatural;
int ca, ma; int ca, ma;
dsq->sound->getStats(&ca, &ma); dsq->sound->getStats(&ca, &ma);

View file

@ -1142,9 +1142,9 @@ void Entity::update(float dt)
if (doUpdate && !dsq->game->isPaused()) 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 // possible bug here because of return
return; return;
@ -1382,7 +1382,7 @@ bool Entity::updateCurrents(float dt)
// why? // why?
{ {
//Path *p = dsq->game->getNearestPath(position, PATH_CURRENT); //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) for (Path *p = dsq->game->getFirstPathOfType(PATH_CURRENT); p; p = p->nextOfType)
{ {

View file

@ -1234,7 +1234,7 @@ Game::Game() : StateObject()
loadEntityTypeList(); loadEntityTypeList();
lastCollideMaskIndex = -1; lastCollideMaskIndex = -1;
worldPaused = false;
} }
@ -5719,7 +5719,7 @@ void Game::updateParticlePause()
{ {
core->particlesPaused = 2; core->particlesPaused = 2;
} }
else if (dsq->continuity.getWorldType() == WT_SPIRIT) else if (this->isWorldPaused())
{ {
core->particlesPaused = 1; core->particlesPaused = 1;
} }

View file

@ -1001,6 +1001,9 @@ public:
void toggleHelpScreen(bool on, const std::string &label=""); void toggleHelpScreen(bool on, const std::string &label="");
void onToggleHelpScreen(); void onToggleHelpScreen();
void setWorldPaused(bool b) { worldPaused = b; }
bool isWorldPaused() const { return worldPaused; }
protected: protected:
void onHelpUp(); void onHelpUp();
@ -1158,6 +1161,7 @@ protected:
std::vector<AquariaMenuItem*> menu; std::vector<AquariaMenuItem*> menu;
Quad *menuBg, *menuBg2; Quad *menuBg, *menuBg2;
bool paused; bool paused;
bool worldPaused;
Vector getClosestPointOnTriangle(Vector a, Vector b, Vector c, Vector p); Vector getClosestPointOnTriangle(Vector a, Vector b, Vector c, Vector p);
Vector getClosestPointOnLine(Vector a, Vector b, Vector p); Vector getClosestPointOnLine(Vector a, Vector b, Vector p);

View file

@ -109,7 +109,7 @@ void Ingredient::eat(Entity *e)
void Ingredient::onUpdate(float dt) void Ingredient::onUpdate(float dt)
{ {
if (dsq->game->isPaused()) return; if (dsq->game->isPaused()) return;
if (dsq->continuity.getWorldType() == WT_SPIRIT) return; if (dsq->game->isWorldPaused()) return;
Vector lastPosition = position; Vector lastPosition = position;
Entity::onUpdate(dt); Entity::onUpdate(dt);

View file

@ -284,6 +284,7 @@ void Mod::stop()
debugMenu = false; debugMenu = false;
shuttingDown = false; shuttingDown = false;
dsq->scriptInterface.reset(); dsq->scriptInterface.reset();
dsq->game->setWorldPaused(false);
} }
void Mod::update(float dt) void Mod::update(float dt)

View file

@ -53,12 +53,7 @@ Path::Path()
spawnEnemyNumber = 0; spawnEnemyNumber = 0;
spawnEnemyDistance = 0; spawnEnemyDistance = 0;
warpType = 0; warpType = 0;
/* spiritFreeze = true;
rect.x1 = -10;
rect.x2 = 20;
rect.y1 = -256;
rect.y2 = 256;
*/
} }
void Path::clampPosition(Vector *pos, int radius) void Path::clampPosition(Vector *pos, int radius)
@ -484,7 +479,7 @@ void Path::init()
void Path::update(float dt) 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) if (addEmitter && emitter)
{ {
@ -523,7 +518,7 @@ void Path::update(float dt)
{ {
spawnedEntity = 0; spawnedEntity = 0;
} }
if (pathType == PATH_CURRENT && dsq->continuity.getWorldType() == WT_NORMAL) if (pathType == PATH_CURRENT && !dsq->game->isWorldPaused())
{ {
animOffset -= currentMod*(dt/830); 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; animOffset -= 1000*0.00002f;

View file

@ -143,6 +143,7 @@ public:
std::string gem; std::string gem;
bool effectOn; bool effectOn;
bool spiritFreeze;
PathShape pathShape; PathShape pathShape;

View file

@ -377,6 +377,7 @@ void compile_time_assertions()
compile_assert(oo(Path) == oo(Quad)); compile_assert(oo(Path) == oo(Quad));
compile_assert(oo(Path) == oo(Avatar)); compile_assert(oo(Path) == oo(Avatar));
compile_assert(oo(Path) == oo(BaseText)); compile_assert(oo(Path) == oo(BaseText));
compile_assert(oo(Path) == oo(PauseQuad));
#undef oo #undef oo
} }
#endif #endif
@ -2351,6 +2352,17 @@ luaFunc(getWorldType)
luaReturnNum((int)dsq->continuity.getWorldType()); luaReturnNum((int)dsq->continuity.getWorldType());
} }
luaFunc(isWorldPaused)
{
luaReturnBool(dsq->game->isWorldPaused());
}
luaFunc(setWorldPaused)
{
dsq->game->setWorldPaused(getBool(L, 1));
luaReturnNil();
}
luaFunc(getNearestNodeByType) luaFunc(getNearestNodeByType)
{ {
int x = lua_tonumber(L, 1); int x = lua_tonumber(L, 1);
@ -2546,6 +2558,14 @@ luaFunc(entity_setSpiritFreeze)
luaReturnNil(); luaReturnNil();
} }
luaFunc(node_setSpiritFreeze)
{
Path *e = path(L);
if (e)
e->spiritFreeze = getBool(L,2);
luaReturnNil();
}
luaFunc(entity_setFillGrid) luaFunc(entity_setFillGrid)
{ {
Entity *e = entity(L); Entity *e = entity(L);
@ -4755,6 +4775,15 @@ luaFunc(createQuad)
luaReturnPtr(q); 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) luaFunc(setupEntity)
{ {
ScriptedEntity *se = scriptedEntity(L); ScriptedEntity *se = scriptedEntity(L);
@ -7597,11 +7626,14 @@ static const struct {
luaRegister(getNoteName), luaRegister(getNoteName),
luaRegister(getWorldType), luaRegister(getWorldType),
luaRegister(setWorldPaused),
luaRegister(isWorldPaused),
luaRegister(getWaterLevel), luaRegister(getWaterLevel),
luaRegister(setWaterLevel), luaRegister(setWaterLevel),
luaRegister(createQuad), luaRegister(createQuad),
luaRegister(quad_setPauseLevel),
luaRegister(setupEntity), luaRegister(setupEntity),
luaRegister(setActivePet), luaRegister(setActivePet),
@ -7651,6 +7683,7 @@ static const struct {
luaRegister(entity_setEatType), luaRegister(entity_setEatType),
luaRegister(entity_setSpiritFreeze), luaRegister(entity_setSpiritFreeze),
luaRegister(node_setSpiritFreeze),
luaRegister(entity_setCanLeaveWater), luaRegister(entity_setCanLeaveWater),

View file

@ -778,7 +778,7 @@ bool Shot::isObstructed(float dt) const
void Shot::onUpdate(float dt) void Shot::onUpdate(float dt)
{ {
if (dsq->game->isPaused()) return; if (dsq->game->isPaused()) return;
if (dsq->continuity.getWorldType() != WT_NORMAL) return; if (dsq->game->isWorldPaused()) return;
if (!shotData) return; if (!shotData) return;

View file

@ -802,6 +802,7 @@ void Quad::onSetTexture()
PauseQuad::PauseQuad() : Quad(), pauseLevel(0) PauseQuad::PauseQuad() : Quad(), pauseLevel(0)
{ {
addType(SCO_PAUSEQUAD);
} }
void PauseQuad::onUpdate(float dt) void PauseQuad::onUpdate(float dt)

View file

@ -37,6 +37,7 @@ static const char *scriptObjTypeNames[] =
/* (1 << 9) */ "Path/Node", /* (1 << 9) */ "Path/Node",
/* (1 <<10) */ "Quad", /* (1 <<10) */ "Quad",
/* (1 <<11) */ "Text", /* (1 <<11) */ "Text",
/* (1 <<12) */ "PauseQuad",
NULL NULL
}; };

View file

@ -39,6 +39,7 @@ enum ScriptObjectType
SCO_PATH = 0x0200, SCO_PATH = 0x0200,
SCO_QUAD = 0x0400, SCO_QUAD = 0x0400,
SCO_TEXT = 0x0800, SCO_TEXT = 0x0800,
SCO_PAUSEQUAD = 0x1000,
SCO_FORCE_32BIT = 0xFFFFFFFF SCO_FORCE_32BIT = 0xFFFFFFFF
}; };