mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2024-11-25 09:44:02 +00:00
Small refactor, add Scrtipable base, add node_v() Lua function
This commit is contained in:
parent
9c180ca5b7
commit
074e92c553
11 changed files with 73 additions and 34 deletions
|
@ -40,7 +40,6 @@ Path::Path()
|
|||
pathType = PATH_NONE;
|
||||
neverSpawned = true;
|
||||
spawnedEntity = 0;
|
||||
script = 0;
|
||||
updateFunction = activateFunction = false;
|
||||
cursorActivation = false;
|
||||
rect.setWidth(64);
|
||||
|
@ -215,11 +214,7 @@ void Path::destroy()
|
|||
emitter->safeKill();
|
||||
emitter = 0;
|
||||
}
|
||||
if (script)
|
||||
{
|
||||
dsq->scriptInterface.closeScript(script);
|
||||
script = 0;
|
||||
}
|
||||
closeScript();
|
||||
}
|
||||
|
||||
Path::~Path()
|
||||
|
@ -724,11 +719,6 @@ void Path::luaDebugMsg(const std::string &func, const std::string &msg)
|
|||
debugLog("luaScriptError: Path [" + name + "]: " + func + " : " + msg);
|
||||
}
|
||||
|
||||
int Path::pushLuaVars(lua_State *L)
|
||||
{
|
||||
return script ? script->pushLocalVars(L) : 0;
|
||||
}
|
||||
|
||||
MinimapIcon *Path::ensureMinimapIcon()
|
||||
{
|
||||
if(!minimapIcon)
|
||||
|
|
|
@ -24,12 +24,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
#include "../BBGE/Base.h"
|
||||
#include "../BBGE/Particles.h"
|
||||
#include "../BBGE/ScriptObject.h"
|
||||
#include "ScriptInterface.h"
|
||||
#include "Rect.h"
|
||||
#include "Scriptable.h"
|
||||
|
||||
#undef PATH_MAX // May be set by a system header.
|
||||
|
||||
struct MinimapIcon;
|
||||
class Entity;
|
||||
|
||||
class PathNode
|
||||
{
|
||||
|
@ -72,7 +73,7 @@ enum PathShape
|
|||
PATHSHAPE_CIRCLE = 1
|
||||
};
|
||||
|
||||
class Path : public ScriptObject
|
||||
class Path : public ScriptObject, public Scriptable
|
||||
{
|
||||
public:
|
||||
Path();
|
||||
|
@ -112,7 +113,6 @@ public:
|
|||
void refreshScript();
|
||||
MinimapIcon *ensureMinimapIcon();
|
||||
|
||||
Script *script;
|
||||
bool updateFunction;
|
||||
bool activateFunction;
|
||||
bool cursorActivation;
|
||||
|
@ -157,7 +157,6 @@ public:
|
|||
|
||||
int messageVariadic(lua_State *L, int nparams);
|
||||
void luaDebugMsg(const std::string &func, const std::string &msg);
|
||||
int pushLuaVars(lua_State *L);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -3057,6 +3057,12 @@ luaFunc(node_v)
|
|||
return n ? n->pushLuaVars(L) : 0;
|
||||
}
|
||||
|
||||
luaFunc(shot_v)
|
||||
{
|
||||
Shot *s = getShot(L);
|
||||
return s ? s->pushLuaVars(L) : 0;
|
||||
}
|
||||
|
||||
luaFunc(isQuitFlag)
|
||||
{
|
||||
luaReturnBool(dsq->isQuitFlag());
|
||||
|
@ -9938,6 +9944,7 @@ static const struct {
|
|||
|
||||
luaRegister(entity_v),
|
||||
luaRegister(node_v),
|
||||
luaRegister(shot_v),
|
||||
|
||||
luaRegister(isQuitFlag),
|
||||
luaRegister(isDeveloperKeys),
|
||||
|
|
21
Aquaria/Scriptable.cpp
Normal file
21
Aquaria/Scriptable.cpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include "Scriptable.h"
|
||||
#include "ScriptInterface.h"
|
||||
#include "DSQ.h"
|
||||
|
||||
Scriptable::Scriptable() : script(0)
|
||||
{
|
||||
}
|
||||
|
||||
int Scriptable::pushLuaVars(lua_State *L)
|
||||
{
|
||||
return script ? script->pushLocalVars(L) : 0;
|
||||
}
|
||||
|
||||
void Scriptable::closeScript()
|
||||
{
|
||||
if (script)
|
||||
{
|
||||
dsq->scriptInterface.closeScript(script);
|
||||
script = 0;
|
||||
}
|
||||
}
|
26
Aquaria/Scriptable.h
Normal file
26
Aquaria/Scriptable.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
#ifndef AQUARIA_SCRIPTABLE_H
|
||||
#define AQUARIA_SCRIPTABLE_H
|
||||
|
||||
class Script;
|
||||
struct lua_State;
|
||||
|
||||
// Object that has a script attached
|
||||
class Scriptable
|
||||
{
|
||||
public:
|
||||
Scriptable();
|
||||
|
||||
Script *script; // NULL if no script is attached
|
||||
|
||||
int pushLuaVars(lua_State *L);
|
||||
void closeScript();
|
||||
|
||||
// Note! Before you attempt to move here some common functions like message() or anything that takes a 'this'-pointer:
|
||||
// ScriptInterface uses raw pointers everywhere. 'this' is always passed as a void*, so if we make any such method that pushes 'this'
|
||||
// a method of the Scriptable class, then that would pass an offset pointer.
|
||||
// Eg. Entity *e casted to ((void*)e) is not the same as ((void*)(Scriptable*)e)! And since ScriptInterface does (Entity*)lua_touserdata(L, slot),
|
||||
// this would break horribly since the necessary type infos to fix the pointer are not preserved.
|
||||
// A fix would be to dynamic_cast from a common base class, but right now that isn't worth the hassle.
|
||||
};
|
||||
|
||||
#endif
|
|
@ -31,7 +31,6 @@ ScriptedEntity::ScriptedEntity(const std::string &scriptName, Vector position, E
|
|||
{
|
||||
addType(SCO_SCRIPTED_ENTITY);
|
||||
crushDelay = 0;
|
||||
script = 0;
|
||||
songNoteFunction = songNoteDoneFunction = true;
|
||||
addChild(&pullEmitter, PM_STATIC);
|
||||
|
||||
|
@ -93,11 +92,6 @@ int ScriptedEntity::messageVariadic(lua_State *L, int nparams)
|
|||
return Entity::messageVariadic(L, nparams);
|
||||
}
|
||||
|
||||
int ScriptedEntity::pushLuaVars(lua_State *L)
|
||||
{
|
||||
return script ? script->pushLocalVars(L) : 0;
|
||||
}
|
||||
|
||||
void ScriptedEntity::warpSegments()
|
||||
{
|
||||
Segmented::warpSegments(position);
|
||||
|
@ -394,11 +388,7 @@ void ScriptedEntity::destroy()
|
|||
{
|
||||
CollideEntity::destroy();
|
||||
|
||||
if (script)
|
||||
{
|
||||
dsq->scriptInterface.closeScript(script);
|
||||
script = 0;
|
||||
}
|
||||
closeScript();
|
||||
}
|
||||
|
||||
void ScriptedEntity::song(SongType songType)
|
||||
|
|
|
@ -24,11 +24,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
#include "CollideEntity.h"
|
||||
#include "Segmented.h"
|
||||
#include "Particles.h"
|
||||
#include "Scriptable.h"
|
||||
|
||||
struct lua_State;
|
||||
class Script;
|
||||
|
||||
class ScriptedEntity : public CollideEntity, public Segmented
|
||||
class ScriptedEntity : public CollideEntity, public Segmented, public Scriptable
|
||||
{
|
||||
public:
|
||||
ScriptedEntity(const std::string &scriptName, Vector position, EntityType et = ET_ENEMY);
|
||||
|
@ -50,7 +51,6 @@ public:
|
|||
void entityDied(Entity *e);
|
||||
void message(const std::string &msg, int v);
|
||||
int messageVariadic(lua_State *L, int nparams);
|
||||
int pushLuaVars(lua_State *L);
|
||||
|
||||
static bool runningActivation;
|
||||
|
||||
|
@ -105,7 +105,6 @@ protected:
|
|||
|
||||
void onHitWall();
|
||||
bool reverseSegments;
|
||||
Script *script;
|
||||
void onUpdate(float dt);
|
||||
void onEnterState(int action);
|
||||
void onExitState(int action);
|
||||
|
|
|
@ -298,7 +298,6 @@ Shot::Shot() : Quad(), Segmented(0,0)
|
|||
enqueuedForDelete = false;
|
||||
shotIdx = shots.size();
|
||||
shots.push_back(this);
|
||||
script = 0;
|
||||
updateScript = false;
|
||||
}
|
||||
|
||||
|
@ -431,8 +430,7 @@ void Shot::onEndOfLife()
|
|||
if(script)
|
||||
{
|
||||
script->call("dieNormal", this);
|
||||
dsq->scriptInterface.closeScript(script);
|
||||
script = 0;
|
||||
closeScript();
|
||||
}
|
||||
destroySegments(0.2f);
|
||||
dead = true;
|
||||
|
|
|
@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
#include "CollideEntity.h"
|
||||
#include "Segmented.h"
|
||||
#include "Scriptable.h"
|
||||
|
||||
class ParticleEffect;
|
||||
class Script;
|
||||
|
@ -73,7 +74,7 @@ struct ShotData
|
|||
|
||||
};
|
||||
|
||||
class Shot : public Quad, public Segmented
|
||||
class Shot : public Quad, public Segmented, public Scriptable
|
||||
{
|
||||
public:
|
||||
|
||||
|
@ -144,7 +145,6 @@ protected:
|
|||
bool fired;
|
||||
bool enqueuedForDelete;
|
||||
void onUpdate(float dt);
|
||||
Script *script;
|
||||
bool updateScript;
|
||||
|
||||
private:
|
||||
|
|
|
@ -453,6 +453,7 @@ SET(AQUARIA_SRCS
|
|||
${SRCDIR}/RecipeMenuEntry.cpp
|
||||
${SRCDIR}/SceneEditor.cpp
|
||||
${SRCDIR}/SchoolFish.cpp
|
||||
${SRCDIR}/Scriptable.cpp
|
||||
${SRCDIR}/ScriptedEntity.cpp
|
||||
${SRCDIR}/ScriptInterface.cpp
|
||||
${SRCDIR}/Segmented.cpp
|
||||
|
|
|
@ -631,6 +631,14 @@
|
|||
RelativePath="..\..\Aquaria\SchoolFish.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\Aquaria\Scriptable.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\Aquaria\Scriptable.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\Aquaria\ScriptedEntity.cpp"
|
||||
>
|
||||
|
|
Loading…
Reference in a new issue