1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-02-15 17:15:58 +00:00

Script interface improvements & extensions.

- Pointer typechecks are now enabled by default.

- enabled all script warnings for non-FULL or DEMO builds by default

- Added generic obj_* functions that operate on any type of RenderObject.
  These give quite low-level control about the renderer, and are quite
  dangerous too.
  Subsequently, many functions sharing the same code (*_setPosition, for example)
  could be removed, and simply call the generic functions after a type check.

- Added interface function deathNotify(). The original logic of death
  notifiers was never used, so i thought i'd make use of it.
  This is useful in scripts to safely drop dangling pointers.

- removed sendEntityMessage, entity_setCollideWithAvatar, entity_setTouchDamage,
  which were essentially no-ops.

- Replaced all unnecessary luaReturnNum(0) and luaReturnInt(0),
  now it does only push a return value on the stack if the function
  is actually supposed to have a retun value.

- Allow variadic calling of entity_msg(). Now any parameters can be passed
  to the function, and the target entity will receive all of them.
  Any values returned from the entity's msg() callback will be returned
  by entity_msg() to the original caller. This allows nice RPC-like
  entity communication.

- fixed possible crash in debugLog, bone_update, entity_debugText

- added an override function for loadfile() that is case-insensitive like dofile()

- entity_createEntity returns the created entity now

- spawnParticleEffect returns the associated RenderObject

- Added some text rendering functions

- Added beam_setFirer()

- removed the underflow check in avatar_decrLeaches() I added earlier

- added a panic function for Lua.

- added the Lua debug library

- fixed a stupid typo in ScriptObject::isType() that made the type checks a lot less accurate

- misc stuff I forgot
This commit is contained in:
fgenesis 2012-02-05 20:22:54 +01:00
parent f2d112b693
commit 7ff0caaed8
28 changed files with 1564 additions and 1674 deletions

View file

@ -58,6 +58,11 @@ void Beam::setDamage(float dmg)
damageData.damage = dmg;
}
void Beam::setFirer(Entity *e)
{
damageData.attacker = e;
}
void Beam::onEndOfLife()
{
beams.remove(this);

View file

@ -4917,23 +4917,18 @@ std::string DSQ::getSaveDirectory()
return getUserDataFolder() + "/save";
}
void DSQ::spawnParticleEffect(const std::string &name, Vector position, float rotz, float t, int layer, float follow)
ParticleEffect *DSQ::spawnParticleEffect(const std::string &name, Vector position, float rotz, float t, int layer, float follow)
{
/*
ScriptedParticleEffect *e = new ScriptedParticleEffect(name);
e->position = position;
core->getTopStateData()->addRenderObject(e, LR_PARTICLES);
*/
if (t!=0)
{
PECue p(name, position, rotz, t);
pecue.push_back(p);
return NULL;
}
else
{
ParticleEffect *e = core->createParticleEffect(name, position, layer, rotz);
e->followCamera = follow;
}
ParticleEffect *e = core->createParticleEffect(name, position, layer, rotz);
e->followCamera = follow;
return e;
}
void DSQ::spawnAllIngredients(const Vector &position)

View file

@ -1377,7 +1377,7 @@ public:
bool runScriptNum(const std::string &name, const std::string &func="", float num=0);
void collectScriptGarbage();
void spawnParticleEffect(const std::string &name, Vector position, float rot=0, float t=0, int layer=LR_PARTICLES, float follow=0);
ParticleEffect *spawnParticleEffect(const std::string &name, Vector position, float rot=0, float t=0, int layer=LR_PARTICLES, float follow=0);
void spawnAllIngredients(const Vector &position);
std::string getDialogueFilename(const std::string &f);

View file

@ -225,7 +225,6 @@ Entity::Entity() : StateMachine(), DFSprite()
fillGridFromQuad = false;
dropChance = 0;
inCurrent = false;
collideWithAvatar = false;
entityProperties.resize(EP_MAX);
for (int i = 0; i < entityProperties.size(); i++)
{
@ -527,10 +526,6 @@ void Entity::followPath(Path *p, int speedType, int dir, bool deleteOnEnd)
}
}
void Entity::message(const std::string &msg, int v)
{
}
void Entity::moveToNode(Path *path, int speedType, int dieOnPathEnd, bool swim)
{
Vector start = position;

View file

@ -194,7 +194,7 @@ enum BounceType
BOUNCE_REAL = 1
};
class Entity : public ScriptObject, public DFSprite, public StateMachine
class Entity : public DFSprite, public StateMachine
{
public:
Entity();
@ -233,8 +233,9 @@ public:
bool canSetState(int state);
virtual void message(const std::string &msg, int v);
virtual void message(const std::string &msg, void *v) {}
virtual void message(const std::string &msg, int v) {}
virtual void messageVariadic(lua_State *L, int nparams) {}
bool isUnderWater(const Vector &o=Vector());
//virtual void onHitBySpell(Spell *spell) {}
@ -267,7 +268,6 @@ public:
virtual void saveExtraData(TiXmlElement *xml){}
virtual void loadExtraData(TiXmlElement *xml){}
Vector startPos;
virtual void onMessage(const std::string &msg){}
void getEXP(unsigned int exp);
void rotateToVec(Vector addVec, float time, int offsetAngle=0);
virtual void applyVariation(int variation){}
@ -377,7 +377,6 @@ public:
void setEntityProperty(EntityProperty ep, bool value=true);
bool isEntityProperty(EntityProperty ep);
bool collideWithAvatar;
virtual void song(SongType songType){}
bool updateCurrents(float dt);
void updateVel2(float dt, bool override=false);

View file

@ -8500,17 +8500,17 @@ Bone *Game::collideSkeletalVsLine(Entity *skeletal, Vector start, Vector end, fl
return closest;
}
bool Game::collideCircleVsLine(Entity *ent, Vector start, Vector end, float radius)
bool Game::collideCircleVsLine(RenderObject *r, Vector start, Vector end, float radius)
{
bool collision = false;
if (isTouchingLine(start, end, ent->position, radius+ent->collideRadius, &lastCollidePosition))
if (isTouchingLine(start, end, r->position, radius+r->collideRadius, &lastCollidePosition))
{
collision = true;
}
return collision;
}
bool Game::collideCircleVsLineAngle(Entity *ent, float angle, float startLen, float endLen, float radius, Vector basePos)
bool Game::collideCircleVsLineAngle(RenderObject *r, float angle, float startLen, float endLen, float radius, Vector basePos)
{
bool collision = false;
float rads = MathFunctions::toRadians(angle);
@ -8518,7 +8518,7 @@ bool Game::collideCircleVsLineAngle(Entity *ent, float angle, float startLen, fl
float cosv = cosf(rads);
Vector start=Vector(sinv,cosv)*startLen + basePos;
Vector end=Vector(sinv,cosv)*endLen + basePos;
if (isTouchingLine(start, end, ent->position, radius+ent->collideRadius, &lastCollidePosition))
if (isTouchingLine(start, end, r->position, radius+r->collideRadius, &lastCollidePosition))
{
collision = true;
}

View file

@ -678,8 +678,8 @@ public:
bool collideCircleVsCircle(Entity *a, Entity *b);
Bone *collideSkeletalVsCircle(Entity *skeletal, Entity *circle);
Bone *collideSkeletalVsLine(Entity *skeletal, Vector start, Vector end, float radius);
bool collideCircleVsLine(Entity *ent, Vector start, Vector end, float radius);
bool collideCircleVsLineAngle(Entity *ent, float angle, float startLen, float endLen, float radius, Vector basePos);
bool collideCircleVsLine(RenderObject *r, Vector start, Vector end, float radius);
bool collideCircleVsLineAngle(RenderObject *r, float angle, float startLen, float endLen, float radius, Vector basePos);
Bone *collideSkeletalVsCircle(Entity *skeletal, Vector pos, float radius);
void handleShotCollisions(Entity *e, bool hasShield=false);
void handleShotCollisionsSkeletal(Entity *e);

File diff suppressed because it is too large Load diff

View file

@ -59,6 +59,8 @@ 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);
// function(pointer, ...) - anything that is already on the stack is forwarded. Results are left on the stack.
bool callVariadic(const char *name, lua_State *L, int nparams, void *param);
lua_State *getLuaState() {return L;}
const std::string &getFile() {return file;}

View file

@ -96,14 +96,14 @@ void ScriptedEntity::message(const std::string &msg, int v)
Entity::message(msg, v);
}
void ScriptedEntity::message(const std::string &msg, void *v)
void ScriptedEntity::messageVariadic(lua_State *L, int nparams)
{
if (script)
{
if (!script->call("msg", this, msg.c_str(), v))
if (!script->callVariadic("msg", L, nparams, this))
luaDebugMsg("msg", script->getLastError());
}
Entity::message(msg, v);
Entity::messageVariadic(L, nparams);
}
void ScriptedEntity::warpSegments()
@ -459,7 +459,6 @@ void ScriptedEntity::onAlwaysUpdate(float dt)
Entity *followEntity = dsq->game->avatar;
if (followEntity && dsq->game->avatar->pullTarget == this)
{
collideWithAvatar = false;
//debugLog("followentity!");
Vector dist = followEntity->position - this->position;
if (dist.isLength2DIn(followEntity->collideRadius + collideRadius + 16))
@ -1020,3 +1019,13 @@ void ScriptedEntity::onExitState(int action)
CollideEntity::onExitState(action);
}
void ScriptedEntity::deathNotify(RenderObject *r)
{
if (script)
{
if (!script->call("deathNotify", this, r))
luaDebugMsg("deathNotify", script->getLastError());
}
CollideEntity::deathNotify(r);
}

View file

@ -47,7 +47,7 @@ public:
void lightFlare();
void entityDied(Entity *e);
void message(const std::string &msg, int v);
void message(const std::string &msg, void *v);
void messageVariadic(lua_State *L, int nparams);
static bool runningActivation;
@ -110,4 +110,5 @@ protected:
void onUpdate(float dt);
void onEnterState(int action);
void onExitState(int action);
virtual void deathNotify(RenderObject *r);
};

View file

@ -70,7 +70,7 @@ struct ShotData
};
class Shot : public ScriptObject, public Quad, public Segmented
class Shot : public Quad, public Segmented
{
public:
//Shot(DamageType damageType, Entity *firer, Vector pos, Entity *target, std::string tex="", float homingness=1000, int maxSpeed=400, int segments=10, float segMin=0.1, float segMax=5, float damage = 1, float lifeTime = 0);
@ -137,7 +137,7 @@ protected:
void onUpdate(float dt);
};
class Beam : public ScriptObject, public Quad
class Beam : public Quad
{
public:
Beam(Vector pos, float angle);
@ -153,7 +153,7 @@ public:
DamageData damageData;
void setDamage(float dmg);
void setFirer(Entity *e);
void setBeamWidth(int w);
protected:
int beamWidth;

View file

@ -23,7 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "../BBGE/Quad.h"
#include "Entity.h"
class Web : public ScriptObject, public RenderObject
class Web : public RenderObject
{
public:
Web();

18
BBGE/BaseText.h Normal file
View file

@ -0,0 +1,18 @@
#ifndef BASETEXT_H
#define BASETEXT_H
#include "RenderObject.h"
class BaseText : public RenderObject
{
public:
BaseText() { addType(SCO_TEXT); }
virtual ~BaseText() {}
virtual void setText(const std::string& text) = 0;
virtual void setWidth(int width) = 0;
virtual void setFontSize(int sz) = 0;
};
#endif

View file

@ -72,7 +72,7 @@ void BmpFont::load(const std::string &file, float scale, bool loadTexture)
}
Texture *fontTextureTest = 0;
BitmapText::BitmapText(BmpFont *bmpFont) : RenderObject()
BitmapText::BitmapText(BmpFont *bmpFont)
{
this->bmpFont = bmpFont;
bfePass =0;

View file

@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//#include "DrawText.h"
#include "RenderObject.h"
#include "BaseText.h"
#include "../ExternalLibs/glfont2/glfont2.h"
@ -49,7 +50,7 @@ struct BmpFont
Texture *overrideTexture;
};
class BitmapText : public RenderObject
class BitmapText : public BaseText
{
public:
BitmapText(BmpFont *bmpFont);

View file

@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "DebugFont.h"
DebugFont::DebugFont(int initSz, const std::string &initText) : RenderObject()
DebugFont::DebugFont(int initSz, const std::string &initText)
{
align = ALIGN_LEFT;
followCamera = 1;

View file

@ -21,8 +21,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#pragma once
#include "Core.h"
#include "BaseText.h"
class DebugFont : public RenderObject
class DebugFont : public BaseText
{
public:
DebugFont(int initFontSize=0, const std::string &initText="");

View file

@ -30,6 +30,7 @@ class Event
{
public:
Event() { data = 0; }
virtual ~Event() {}
virtual void act()=0;
void *data;
};

View file

@ -290,6 +290,7 @@ void Quad::initQuad()
Quad::Quad() : RenderObject()
{
addType(SCO_QUAD);
borderAlpha = 0.5;
//debugLog("Quad::Quad()");
initQuad();
@ -889,7 +890,7 @@ void Quad::onUpdate(float dt)
}
}
void Quad::setWidthHeight(int w, int h)
void Quad::setWidthHeight(float w, float h)
{
if (h == -1)
height = w;
@ -898,12 +899,12 @@ void Quad::setWidthHeight(int w, int h)
width = w;
}
void Quad::setWidth(int w)
void Quad::setWidth(float w)
{
width = w;
}
void Quad::setHeight(int h)
void Quad::setHeight(float h)
{
height = h;
}
@ -921,7 +922,6 @@ void Quad::onSetTexture()
PauseQuad::PauseQuad() : Quad(), pauseLevel(0)
{
addType(SCO_PAUSEQUAD);
}
void PauseQuad::onUpdate(float dt)

View file

@ -22,7 +22,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define __quad__
#include "RenderObject.h"
#include "ScriptObject.h"
class QuadLight
{
@ -70,9 +69,9 @@ public:
void spawnChildClone(float t);
void burn();
void unburn();
void setWidthHeight(int w, int h=-1);
void setWidth(int w);
void setHeight(int h);
void setWidthHeight(float w, float h=-1);
void setWidth(float w);
void setHeight(float h);
int getWidth() const {return int(width);}
int getHeight() const {return int(height);}
@ -150,7 +149,7 @@ private:
void initQuad();
};
class PauseQuad : public ScriptObject, public Quad
class PauseQuad : public Quad
{
public:
PauseQuad();

View file

@ -156,6 +156,7 @@ void RenderObject::clearColorMult()
RenderObject::RenderObject()
{
addType(SCO_RENDEROBJECT);
useOldDT = false;
updateAfterParent = false;
@ -1005,13 +1006,6 @@ void RenderObject::renderCollision()
}
void RenderObject::addDeathNotify(RenderObject *r)
{
deathNotifications.remove(r);
deathNotifications.push_back(r);
r->addDeathNotifyInternal(this);
}
void RenderObject::addDeathNotifyInternal(RenderObject *r)
{
deathNotifications.remove(r);
deathNotifications.push_back(r);
@ -1387,7 +1381,7 @@ void RenderObject::addChild(RenderObject *r, ParentManaged pm, RenderBeforeParen
if (r->parent)
{
errorLog("Engine does not support multiple parents");
exit(0);
return;
}
if (order == CHILD_BACK)

View file

@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "Base.h"
#include "Texture.h"
#include "Flags.h"
#include "ScriptObject.h"
class Core;
class StateData;
@ -72,7 +73,7 @@ typedef std::vector<RectShape> CollideRects;
class RenderObjectLayer;
class RenderObject
class RenderObject : public ScriptObject
{
public:
friend class Core;
@ -315,7 +316,6 @@ protected:
virtual void deathNotify(RenderObject *r);
virtual void onEndOfLife() {}
void addDeathNotifyInternal(RenderObject *r);
// spread parentManagedStatic flag to the entire child tree
void propogateParentManagedStatic();
void propogateAlpha();

View file

@ -25,16 +25,18 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static const char *scriptObjTypeNames[] =
{
/* (1 << 0) */ "Entity",
/* (1 << 1) */ "Ingredient",
/* (1 << 2) */ "CollideEntity",
/* (1 << 3) */ "ScriptedEntity",
/* (1 << 4) */ "Beam",
/* (1 << 5) */ "Shot",
/* (1 << 6) */ "Web",
/* (1 << 7) */ "Bone",
/* (1 << 8) */ "Path/Node",
/* (1 << 9) */ "PauseQuad",
/* (1 << 0) */ "RenderObject",
/* (1 << 1) */ "Entity",
/* (1 << 2) */ "Ingredient",
/* (1 << 3) */ "CollideEntity",
/* (1 << 4) */ "ScriptedEntity",
/* (1 << 5) */ "Beam",
/* (1 << 6) */ "Shot",
/* (1 << 7) */ "Web",
/* (1 << 8) */ "Bone",
/* (1 << 9) */ "Path/Node",
/* (1 <<10) */ "Quad",
/* (1 <<11) */ "Text",
NULL
};

View file

@ -26,16 +26,18 @@ enum ScriptObjectType
// If you change this enum, do not forget to adjust the string array in the cpp,
// and to add additional compile time assertions to ScriptInterface.cpp as necessary!
SCO_ENTITY = 0x0001,
SCO_INGREDIENT = 0x0002,
SCO_COLLIDE_ENTITY = 0x0004,
SCO_SCRIPTED_ENTITY = 0x0008,
SCO_BEAM = 0x0010,
SCO_SHOT = 0x0020,
SCO_WEB = 0x0040,
SCO_BONE = 0x0080,
SCO_PATH = 0x0100,
SCO_PAUSEQUAD = 0x0200,
SCO_RENDEROBJECT = 0x0001,
SCO_ENTITY = 0x0002,
SCO_INGREDIENT = 0x0004,
SCO_COLLIDE_ENTITY = 0x0008,
SCO_SCRIPTED_ENTITY = 0x0010,
SCO_BEAM = 0x0020,
SCO_SHOT = 0x0040,
SCO_WEB = 0x0080,
SCO_BONE = 0x0100,
SCO_PATH = 0x0200,
SCO_QUAD = 0x0400,
SCO_TEXT = 0x0800,
SCO_FORCE_32BIT = 0xFFFFFFFF
};
@ -59,7 +61,12 @@ public:
inline bool isType(ScriptObjectType bt) const
{
return (_objtype & bt) != 0;
return (_objtype & bt) == bt;
}
inline bool isExactType(ScriptObjectType bt) const
{
return _objtype == bt;
}
inline std::string getTypeString() const

View file

@ -37,7 +37,7 @@ enum AnimationCommand
class ParticleEffect;
class SkeletalSprite;
class Bone : public ScriptObject, public Quad
class Bone : public Quad
{
public:
Bone();

View file

@ -573,6 +573,7 @@ ENDIF(MSVC)
SET(LUA_SRCS
${LUASRCDIR}/lapi.c
${LUASRCDIR}/ldblib.c
${LUASRCDIR}/ldebug.c
${LUASRCDIR}/ldo.c
${LUASRCDIR}/ldump.c

View file

@ -99,15 +99,12 @@ function init(me)
entity_initSkeletal(me, "EnergyBoss")
entity_setState(me, STATE_IDLE)
entity_setCull(me, false)
entity_setCollideWithAvatar(me, true)
entity_setName(me, "EnergyBoss")
--entity_flipHorizontal(me)
entity_scale(me, 1.5, 1.5)
entity_setTouchDamage(me, 1)
--entity_setTouchPush(me, 1)
entity_setWeight(me, 800)