More work on scripting
This commit is contained in:
parent
78f9500b1d
commit
a29fa5c4a3
@ -185,10 +185,6 @@ public:
|
||||
* it. */
|
||||
bool isExplodeKartObject () const { return m_explode_kart; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns true if this object should cause a kart that touches it to
|
||||
* be flattened. */
|
||||
bool isFlattenKartObject () const { return m_flatten_kart; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Sets the interaction type */
|
||||
void setInteraction(std::string interaction);
|
||||
// ------------------------------------------------------------------------
|
||||
@ -197,6 +193,34 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
/** Add body to dynamic world */
|
||||
void addBody();
|
||||
// ------------------------------------------------------------------------
|
||||
// Methods usable by scripts
|
||||
|
||||
/**
|
||||
* \addtogroup Scripting
|
||||
* @{
|
||||
* \addtogroup Scripting_Track Track
|
||||
* @{
|
||||
* \addtogroup Scripting_PhysicalObject PhysicalObject (script binding)
|
||||
* Type returned by trackObject.getPhysicalObject()
|
||||
* @{
|
||||
*/
|
||||
/** Returns true if this object should cause a kart that touches it to
|
||||
* be flattened. */
|
||||
bool isFlattenKartObject() const { return m_flatten_kart; }
|
||||
void disable(void *memory)
|
||||
{
|
||||
((PhysicalObject*)(memory))->removeBody();
|
||||
}
|
||||
|
||||
//enables track object passed from the script
|
||||
void enable(void *memory)
|
||||
{
|
||||
((PhysicalObject*)(memory))->addBody();
|
||||
}
|
||||
/** @} */
|
||||
/** @} */
|
||||
/** @} */
|
||||
|
||||
LEAK_CHECK()
|
||||
}; // PhysicalObject
|
||||
|
@ -29,6 +29,7 @@ namespace Scripting
|
||||
namespace Physics
|
||||
{
|
||||
//Creates an explosion animation at specified Vec3 location
|
||||
// TODO: does this even belong in Physics?
|
||||
void createExplosion(asIScriptGeneric *gen)
|
||||
{
|
||||
//TODO: allow different types? sand etc
|
||||
|
@ -29,141 +29,68 @@
|
||||
#include "tracks/track_object_manager.hpp"
|
||||
|
||||
#include <angelscript.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <iostream> //debug
|
||||
|
||||
/** \cond DOXYGEN_IGNORE */
|
||||
namespace Scripting
|
||||
{
|
||||
|
||||
/** \endcond */
|
||||
namespace Track
|
||||
{
|
||||
/** \addtogroup Scripting
|
||||
* @{
|
||||
*/
|
||||
/** \addtogroup Scripting_Track Track
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*
|
||||
void disableAnimation(std::string *name, void *memory)
|
||||
{
|
||||
std::string *str = name;
|
||||
std::string type = "mesh";
|
||||
World::getWorld()->getTrack()->getTrackObjectManager()->disable(*str, type);
|
||||
}*/
|
||||
//disables track object passed from the script
|
||||
void disable(void *memory)
|
||||
{
|
||||
((PhysicalObject*)(memory))->removeBody();
|
||||
}
|
||||
//enables track object passed from the script
|
||||
void enable(void *memory)
|
||||
{
|
||||
((PhysicalObject*)(memory))->addBody();
|
||||
}
|
||||
//pause an animation
|
||||
void setPaused(bool mode, void *memory)
|
||||
{
|
||||
((ThreeDAnimation*)(memory))->setPaused(mode);
|
||||
}
|
||||
//move objects of type TrackObjectPresentation, to the specified location
|
||||
void movePresentation(Vec3 *new_pos, void *memory)
|
||||
{
|
||||
core::vector3df xyz = new_pos->toIrrVector();
|
||||
core::vector3df hpr = core::vector3df(0, 0, 0);
|
||||
core::vector3df scale = core::vector3df(1, 1, 1);
|
||||
((TrackObjectPresentation*)(memory))->move(xyz, hpr, scale, false);
|
||||
}
|
||||
//stop a sound
|
||||
void stop(void *memory)
|
||||
{
|
||||
((TrackObjectPresentationSound*)memory)->stopSound();
|
||||
}
|
||||
//play the specified sound once
|
||||
void playOnce(void *memory)
|
||||
{
|
||||
((TrackObjectPresentationSound*)memory)->triggerSound(false); //false = once
|
||||
}
|
||||
//play the specified sound continuously
|
||||
void playLoop(void *memory)
|
||||
{
|
||||
((TrackObjectPresentationSound*)memory)->triggerSound(true); //true = loop
|
||||
}
|
||||
//sets a loop for an animation (skeletal)
|
||||
void setLoop(int start, int end, void *memory)
|
||||
{
|
||||
((TrackObjectPresentationMesh*)(memory))->setLoop(start,end);
|
||||
}
|
||||
//sets the current frame for a skeletal animation
|
||||
void setCurrentFrame(int frame,void *memory)
|
||||
{
|
||||
((TrackObjectPresentationMesh*)(memory))->setCurrentFrame(frame);
|
||||
}
|
||||
//getter for current frame in a skeletal animation
|
||||
void getCurrentFrame(void *memory)
|
||||
{
|
||||
((TrackObjectPresentationMesh*)(memory))->getCurrentFrame();
|
||||
}
|
||||
//getter for key binding for player action enums
|
||||
void getKeyBinding(asIScriptGeneric *gen)
|
||||
{
|
||||
int Enum_value = (int)gen->GetArgDWord(0);
|
||||
InputDevice* device = input_manager->getDeviceManager()->getLatestUsedDevice();
|
||||
DeviceConfig* config = device->getConfiguration();
|
||||
irr::core::stringw control;
|
||||
PlayerAction ScriptAction = (PlayerAction)Enum_value;
|
||||
control = config->getBindingAsString(ScriptAction);
|
||||
std::string key = std::string(irr::core::stringc(control).c_str());
|
||||
void *key_pointer = &key;
|
||||
gen->SetReturnObject(key_pointer);
|
||||
}
|
||||
//generic track object getter, Entry point of track objects into scripts
|
||||
void getTrackObject(asIScriptGeneric *gen)
|
||||
{
|
||||
std::string *str = (std::string*)gen->GetArgAddress(0);
|
||||
TrackObject* t_obj = World::getWorld()->getTrack()->getTrackObjectManager()->getTrackObject(*str);
|
||||
gen->SetReturnObject(t_obj);
|
||||
}
|
||||
//runs the script specified by the given string
|
||||
void runScript(asIScriptGeneric *gen)
|
||||
{
|
||||
std::string *str = (std::string*)gen->GetArgAddress(0);
|
||||
ScriptEngine* script_engine = World::getWorld()->getScriptEngine();
|
||||
script_engine->runScript(*str);
|
||||
}
|
||||
/*TrackObject* getTrackObject(std::string *name)
|
||||
{
|
||||
TrackObject* t_obj = World::getWorld()->getTrack()->getTrackObjectManager()->getTrackObject(*name);
|
||||
return t_obj;
|
||||
std::string *str = name;
|
||||
std::string type = "mesh";
|
||||
World::getWorld()->getTrack()->getTrackObjectManager()->disable(*str, type);
|
||||
}*/
|
||||
|
||||
|
||||
// Displays the message specified in displayMessage( string message ) within the script
|
||||
void displayMessage(asIScriptGeneric *gen)
|
||||
/**
|
||||
* Get a track object by ID.
|
||||
* @return An object of type @ref Scripting_TrackObject
|
||||
*/
|
||||
TrackObject* getTrackObject(std::string* objID)
|
||||
{
|
||||
std::string *input = (std::string*)gen->GetArgAddress(0);
|
||||
irr::core::stringw out = StringUtils::utf8_to_wide(input->c_str());
|
||||
new TutorialMessageDialog((out), true);
|
||||
return World::getWorld()->getTrack()->getTrackObjectManager()->getTrackObject(*objID);
|
||||
}
|
||||
//generic disable method for track objects
|
||||
|
||||
// TODO: assign types for documentation
|
||||
/** Generic disable method for track objects */
|
||||
void disableTrackObject(asIScriptGeneric *gen)
|
||||
{
|
||||
std::string *str = (std::string*)gen->GetArgAddress(0);
|
||||
World::getWorld()->getTrack()->getTrackObjectManager()->disable(*str);
|
||||
}
|
||||
//generic enable method for track objects
|
||||
|
||||
/** Generic enable method for track objects */
|
||||
void enableTrackObject(asIScriptGeneric *gen)
|
||||
{
|
||||
std::string *str = (std::string*)gen->GetArgAddress(0);
|
||||
World::getWorld()->getTrack()->getTrackObjectManager()->enable(*str);
|
||||
}
|
||||
//disables an action trigger of specified ID
|
||||
|
||||
/** Disables an action trigger of specified ID */
|
||||
void disableTrigger(asIScriptGeneric *gen)
|
||||
{
|
||||
std::string *str = (std::string*)gen->GetArgAddress(0);
|
||||
World::getWorld()->getTrack()->getTrackObjectManager()->disable(*str);
|
||||
}
|
||||
//enables an action trigger of specified ID
|
||||
|
||||
/** Enables an action trigger of specified ID */
|
||||
void enableTrigger(asIScriptGeneric *gen)
|
||||
{
|
||||
std::string *str = (std::string*)gen->GetArgAddress(0);
|
||||
World::getWorld()->getTrack()->getTrackObjectManager()->enable(*str);
|
||||
}
|
||||
//Creates a trigger at the specified location
|
||||
|
||||
/** Creates a trigger at the specified location */
|
||||
void createTrigger(asIScriptGeneric *gen)
|
||||
{
|
||||
std::string *script_name = (std::string*)gen->GetArgAddress(0);
|
||||
@ -182,77 +109,193 @@ namespace Scripting
|
||||
tobj->setID(*script_name);
|
||||
World::getWorld()->getTrack()->getTrackObjectManager()->insertObject(tobj);
|
||||
}
|
||||
}
|
||||
|
||||
/** \cond DOXYGEN_IGNORE */
|
||||
namespace Track
|
||||
{
|
||||
/** \endcond */
|
||||
|
||||
// ----------- TrackObjectPresentationMesh methods -----------
|
||||
// TODO: this method is WRONG, we should in most cases move not the presentation but the entire object
|
||||
//void movePresentation(Vec3 *new_pos, void *memory)
|
||||
//{
|
||||
// core::vector3df xyz = new_pos->toIrrVector();
|
||||
// core::vector3df hpr = core::vector3df(0, 0, 0);
|
||||
// core::vector3df scale = core::vector3df(1, 1, 1);
|
||||
// ((TrackObjectPresentation*)(memory))->move(xyz, hpr, scale, false);
|
||||
//}
|
||||
|
||||
namespace Mesh
|
||||
{
|
||||
/**
|
||||
* \addtogroup Scripting_Mesh Mesh (script binding)
|
||||
* Type returned by trackObject.getMesh()
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** Sets a loop for a skeletal animation */
|
||||
// TODO: can we use a type and avoid void* ?
|
||||
void setLoop(int start, int end /** \cond DOXYGEN_IGNORE */, void *memory /** \endcond */)
|
||||
{
|
||||
((TrackObjectPresentationMesh*)(memory))->setLoop(start, end);
|
||||
}
|
||||
|
||||
/** Sets the current frame for a skeletal animation */
|
||||
void setCurrentFrame(int frame /** \cond DOXYGEN_IGNORE */, void *memory /** \endcond */)
|
||||
{
|
||||
((TrackObjectPresentationMesh*)(memory))->setCurrentFrame(frame);
|
||||
}
|
||||
|
||||
/** Get current frame in a skeletal animation */
|
||||
int getCurrentFrame(/** \cond DOXYGEN_IGNORE */void *memory /** \endcond */)
|
||||
{
|
||||
return ((TrackObjectPresentationMesh*)(memory))->getCurrentFrame();
|
||||
}
|
||||
/** @} */
|
||||
}
|
||||
|
||||
// ----------- Animator Object methods -----------
|
||||
|
||||
namespace Animator
|
||||
{
|
||||
/**
|
||||
* \addtogroup Scripting_Animator Animator (script binding)
|
||||
* Type returned by trackObject.getIPOAnimator()
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** Pause/resumes a curve-based animation */
|
||||
void setPaused(bool mode /** \cond DOXYGEN_IGNORE */, void *memory /** \endcond */)
|
||||
{
|
||||
((ThreeDAnimation*)(memory))->setPaused(mode);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
}
|
||||
|
||||
// ----------- Sound Object methods -----------
|
||||
|
||||
namespace SoundEmitter
|
||||
{
|
||||
/**
|
||||
* @addtogroup Scripting_SoundEmitter SoundEmitter (script binding)
|
||||
* Type returned by trackObject.getSoundEmitter()
|
||||
* @{
|
||||
*/
|
||||
|
||||
// TODO: adjust all signatures to type "void*" parameters if possible
|
||||
/** Stop a sound */
|
||||
void stop(/** \cond DOXYGEN_IGNORE */void *memory /** \endcond */)
|
||||
{
|
||||
((TrackObjectPresentationSound*)memory)->stopSound();
|
||||
}
|
||||
|
||||
/** Play the specified sound once */
|
||||
void playOnce(/** \cond DOXYGEN_IGNORE */void *memory /** \endcond */)
|
||||
{
|
||||
((TrackObjectPresentationSound*)memory)->triggerSound(false); //false = once
|
||||
}
|
||||
|
||||
/** Play the specified sound continuously */
|
||||
void playLoop(/** \cond DOXYGEN_IGNORE */void *memory /** \endcond */)
|
||||
{
|
||||
((TrackObjectPresentationSound*)memory)->triggerSound(true); //true = loop
|
||||
}
|
||||
/** @} */
|
||||
}
|
||||
|
||||
// ----------- ParticleEmitter Object methods -----------
|
||||
|
||||
namespace ParticleEmitter
|
||||
{
|
||||
/**
|
||||
* @addtogroup Scripting_ParticleEmitter ParticleEmitter (script binding)
|
||||
* Type returned by trackObject.getParticleEmitter()
|
||||
* @{
|
||||
*/
|
||||
|
||||
// TODO: adjust all signatures to type "void*" parameters if possible
|
||||
/** Stop particle emission */
|
||||
void stop(/** \cond DOXYGEN_IGNORE */ void *memory /** \endcond */)
|
||||
{
|
||||
((TrackObjectPresentationParticles*)memory)->stop();
|
||||
}
|
||||
|
||||
/** Play the specified sound once */
|
||||
void setEmissionRate(float rate /** \cond DOXYGEN_IGNORE */, void *memory /** \endcond */)
|
||||
{
|
||||
((TrackObjectPresentationParticles*)memory)->setRate(rate);
|
||||
}
|
||||
/** @} */
|
||||
}
|
||||
|
||||
/** @}*/
|
||||
/** @}*/
|
||||
|
||||
void registerScriptFunctions(asIScriptEngine *engine)
|
||||
{
|
||||
int r;
|
||||
|
||||
engine->SetDefaultNamespace("Track");
|
||||
r = engine->RegisterGlobalFunction("void disable(string &in)", asFUNCTION(disableTrackObject), asCALL_GENERIC); assert(r >= 0);
|
||||
r = engine->RegisterGlobalFunction("void enable(string &in)", asFUNCTION(enableTrackObject), asCALL_GENERIC); assert(r >= 0);
|
||||
r = engine->RegisterGlobalFunction("void enableTrigger(string &in)", asFUNCTION(enableTrigger), asCALL_GENERIC); assert(r >= 0);
|
||||
r = engine->RegisterGlobalFunction("void disableTrigger(string &in)", asFUNCTION(disableTrigger), asCALL_GENERIC); assert(r >= 0);
|
||||
r = engine->RegisterGlobalFunction("void createTrigger(string &in,Vec3 &in, float distance)",
|
||||
r = engine->RegisterGlobalFunction("void disableTrackObject(const string &in)", asFUNCTION(disableTrackObject), asCALL_GENERIC); assert(r >= 0);
|
||||
r = engine->RegisterGlobalFunction("void enableTrackObject(const string &in)", asFUNCTION(enableTrackObject), asCALL_GENERIC); assert(r >= 0);
|
||||
r = engine->RegisterGlobalFunction("void enableTrigger(const string &in)", asFUNCTION(enableTrigger), asCALL_GENERIC); assert(r >= 0);
|
||||
r = engine->RegisterGlobalFunction("void disableTrigger(const string &in)", asFUNCTION(disableTrigger), asCALL_GENERIC); assert(r >= 0);
|
||||
r = engine->RegisterGlobalFunction("void createTrigger(const string &in,Vec3 &in, float distance)",
|
||||
asFUNCTION(createTrigger), asCALL_GENERIC); assert(r >= 0);
|
||||
|
||||
/*
|
||||
//Test singleton, and various calling conventions
|
||||
// Register the track object manager as a singleton. The script will access it through the global property
|
||||
//r = engine->RegisterObjectType("TrackObjectManager", 0, asOBJ_REF | asOBJ_NOHANDLE); assert(r >= 0);
|
||||
r = engine->RegisterObjectType("TrackObjectManager", 0, asOBJ_REF | asOBJ_NOCOUNT); assert(r >= 0);
|
||||
|
||||
// Register the track object manager's methods
|
||||
TrackObjectManager* track_obj_manager = World::getWorld()->getTrack()->getTrackObjectManager();
|
||||
r = engine->RegisterGlobalProperty("TrackObjectManager track_obj_manager", track_obj_manager); assert(r >= 0);
|
||||
//r = engine->RegisterObjectMethod("TrackObjectManager", "void disable(string name , string type)", asMETHOD(TrackObjectManager, disable), asCALL_THISCALL); assert(r >= 0);
|
||||
//r = engine->RegisterObjectMethod("TrackObjectManager", "void disable(string &in name)", asFUNCTION(disableAnimation), asCALL_GENERIC); assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("TrackObjectManager", "void disable(string &in)", asFUNCTION(disableAnimation), asCALL_CDECL_OBJLAST); assert(r >= 0);
|
||||
*/
|
||||
//TrackObject
|
||||
r = engine->RegisterGlobalFunction("TrackObject@ getTrackObject(const string &in)", asFUNCTION(getTrackObject), asCALL_CDECL); assert(r >= 0);
|
||||
|
||||
r = engine->RegisterObjectType("TrackObject", 0, asOBJ_REF | asOBJ_NOCOUNT); assert(r >= 0);
|
||||
r = engine->RegisterGlobalFunction("TrackObject @getTrackObject(string &in)", asFUNCTION(getTrackObject), asCALL_GENERIC); assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("TrackObject", "void setEnable(bool status)", asMETHOD(TrackObject, setEnable), asCALL_THISCALL); assert(r >= 0);
|
||||
|
||||
|
||||
//PhysicalObject
|
||||
r = engine->RegisterObjectType("PhysicalObject", 0, asOBJ_REF | asOBJ_NOCOUNT); assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("TrackObject", "PhysicalObject @getPhysicalObject()", asMETHOD(TrackObject, getPhysicalObjectForScript), asCALL_THISCALL); assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("PhysicalObject", "bool isFlattener()", asMETHOD(PhysicalObject, isFlattenKartObject), asCALL_THISCALL); assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("PhysicalObject", "void disable()", asFUNCTION(disable), asCALL_CDECL_OBJLAST); assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("PhysicalObject", "void enable()", asFUNCTION(enable), asCALL_CDECL_OBJLAST); assert(r >= 0);
|
||||
|
||||
|
||||
//Mesh or Skeletal Animation
|
||||
r = engine->RegisterObjectType("Mesh", 0, asOBJ_REF | asOBJ_NOCOUNT); assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("TrackObject", "Mesh @getMesh()", asMETHOD(TrackObject, getMesh), asCALL_THISCALL); assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Mesh", "void setLoop(int start, int end)", asFUNCTION(setLoop), asCALL_CDECL_OBJLAST); assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Mesh", "int getCurrentFrame()", asFUNCTION(getCurrentFrame), asCALL_CDECL_OBJLAST); assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Mesh", "void setCurrentFrame(int frame)", asFUNCTION(setCurrentFrame), asCALL_CDECL_OBJLAST); assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Mesh", "void move(Vec3 &in)", asFUNCTION(movePresentation), asCALL_CDECL_OBJLAST); assert(r >= 0);
|
||||
|
||||
//Particle Emitter
|
||||
r = engine->RegisterObjectType("Mesh", 0, asOBJ_REF | asOBJ_NOCOUNT); assert(r >= 0); // TrackObjectPresentationMesh
|
||||
r = engine->RegisterObjectType("ParticleEmitter", 0, asOBJ_REF | asOBJ_NOCOUNT); assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("TrackObject", "ParticleEmitter @getParticleEmitter()", asMETHOD(TrackObject, getParticles), asCALL_THISCALL); assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("ParticleEmitter", "void move(Vec3 &in)", asFUNCTION(movePresentation), asCALL_CDECL_OBJLAST); assert(r >= 0);
|
||||
|
||||
//Sound Effect
|
||||
// TrackObject
|
||||
r = engine->RegisterObjectMethod("TrackObject", "void setEnable(bool status)", asMETHOD(TrackObject, setEnable), asCALL_THISCALL); assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("TrackObject", "SoundEmitter@ getSoundEmitter()", asMETHOD(TrackObject, getSoundEmitter), asCALL_THISCALL); assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("TrackObject", "PhysicalObject@ getPhysics()", asMETHOD(TrackObject, getPhysics), asCALL_THISCALL); assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("TrackObject", "Mesh@ getMesh()", asMETHOD(TrackObject, getMesh), asCALL_THISCALL); assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("TrackObject", "ParticleEmitter@ getParticleEmitter()", asMETHOD(TrackObject, getParticleEmitter), asCALL_THISCALL); assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("TrackObject", "Animator@ getIPOAnimator()", asMETHOD(TrackObject, getIPOAnimator), asCALL_THISCALL); assert(r >= 0);
|
||||
// TODO: add move method
|
||||
|
||||
// PhysicalObject
|
||||
r = engine->RegisterObjectMethod("PhysicalObject", "bool isFlattenKartObject()", asMETHOD(PhysicalObject, isFlattenKartObject), asCALL_THISCALL); assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("PhysicalObject", "void disable()", asMETHOD(PhysicalObject, disable), asCALL_THISCALL); assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("PhysicalObject", "void enable()", asMETHOD(PhysicalObject, enable), asCALL_THISCALL); assert(r >= 0);
|
||||
|
||||
// TrackObjectPresentationMesh (Mesh or Skeletal Animation)
|
||||
r = engine->RegisterObjectMethod("Mesh", "void setLoop(int start, int end)", asFUNCTION(Mesh::setLoop), asCALL_CDECL_OBJLAST); assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Mesh", "int getCurrentFrame()", asFUNCTION(Mesh::getCurrentFrame), asCALL_CDECL_OBJLAST); assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Mesh", "void setCurrentFrame(int frame)", asFUNCTION(Mesh::setCurrentFrame), asCALL_CDECL_OBJLAST); assert(r >= 0);
|
||||
//r = engine->RegisterObjectMethod("Mesh", "void move(Vec3 &in)", asFUNCTION(movePresentation), asCALL_CDECL_OBJLAST); assert(r >= 0);
|
||||
|
||||
// Particle Emitter
|
||||
r = engine->RegisterObjectMethod("ParticleEmitter", "void stop()", asFUNCTION(ParticleEmitter::stop), asCALL_CDECL_OBJLAST); assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("ParticleEmitter", "void setEmissionRate(float)", asFUNCTION(ParticleEmitter::setEmissionRate), asCALL_CDECL_OBJLAST); assert(r >= 0);
|
||||
|
||||
// Sound Effect
|
||||
r = engine->RegisterObjectType("SoundEmitter", 0, asOBJ_REF | asOBJ_NOCOUNT); assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("TrackObject", "SoundEmitter @getSoundEmitter()", asMETHOD(TrackObject, getSound), asCALL_THISCALL); assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("SoundEmitter", "void move(Vec3 &in)", asFUNCTION(movePresentation), asCALL_CDECL_OBJLAST); assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("SoundEmitter", "void stop()", asFUNCTION(stop), asCALL_CDECL_OBJLAST); assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("SoundEmitter", "void playOnce()", asFUNCTION(playOnce), asCALL_CDECL_OBJLAST); assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("SoundEmitter", "void playLoop()", asFUNCTION(playLoop), asCALL_CDECL_OBJLAST); assert(r >= 0);
|
||||
//r = engine->RegisterObjectMethod("SoundEmitter", "void move(Vec3 &in)", asFUNCTION(movePresentation), asCALL_CDECL_OBJLAST); assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("SoundEmitter", "void stop()", asFUNCTION(SoundEmitter::stop), asCALL_CDECL_OBJLAST); assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("SoundEmitter", "void playOnce()", asFUNCTION(SoundEmitter::playOnce), asCALL_CDECL_OBJLAST); assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("SoundEmitter", "void playLoop()", asFUNCTION(SoundEmitter::playLoop), asCALL_CDECL_OBJLAST); assert(r >= 0);
|
||||
|
||||
|
||||
|
||||
//Curve based Animation
|
||||
// Curve based Animation
|
||||
r = engine->RegisterObjectType("Animator", 0, asOBJ_REF | asOBJ_NOCOUNT); assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("TrackObject", "Animator @getAnimator()", asMETHOD(TrackObject, getAnimatorForScript), asCALL_THISCALL); assert(r >= 0);
|
||||
//fails due to insufficient visibility to scripts TODO : Decide whether to fix visibility or introduce wrappers
|
||||
//r = engine->RegisterObjectMethod("Animator", "void setPaused(bool mode)", asMETHOD(ThreeDAnimation, setPaused), asCALL_THISCALL); assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Animator", "void setPaused(bool mode)", asFUNCTION( setPaused ), asCALL_CDECL_OBJLAST); assert(r >= 0);
|
||||
|
||||
r = engine->RegisterGlobalFunction("void runScript(string &in)", asFUNCTION(runScript), asCALL_GENERIC); assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Animator", "void setPaused(bool mode)", asFUNCTION(Animator::setPaused), asCALL_CDECL_OBJLAST); assert(r >= 0);
|
||||
// TODO: add method to set current frame
|
||||
// TODO: add method to launch playback from frame X to frame Y
|
||||
// TODO: add method to register onAnimationComplete notifications ?
|
||||
}
|
||||
|
||||
/** \cond DOXYGEN_IGNORE */
|
||||
}
|
||||
}
|
||||
/** \endcond */
|
||||
|
||||
|
@ -101,6 +101,15 @@ namespace Scripting
|
||||
return StringUtils::wide_to_utf8(out.c_str());
|
||||
}
|
||||
|
||||
/** Runs the script specified by the given string */
|
||||
// TODO: type arguments
|
||||
void runScript(asIScriptGeneric *gen)
|
||||
{
|
||||
std::string *str = (std::string*)gen->GetArgAddress(0);
|
||||
ScriptEngine* script_engine = World::getWorld()->getScriptEngine();
|
||||
script_engine->runScript(*str);
|
||||
}
|
||||
|
||||
/** Log to the console */
|
||||
void logInfo(std::string* log)
|
||||
{
|
||||
@ -153,6 +162,8 @@ namespace Scripting
|
||||
r = engine->RegisterGlobalFunction("string insertValues(const string &in, const string &in, const string &in)", asFUNCTION(proxy_insertValues2), asCALL_CDECL); assert(r >= 0);
|
||||
r = engine->RegisterGlobalFunction("string insertValues(const string &in, const string &in, const string &in, const string &in)", asFUNCTION(proxy_insertValues3), asCALL_CDECL); assert(r >= 0);
|
||||
r = engine->RegisterGlobalFunction("string insertValues(const string &in, const string &in, const string &in, const string &in, const string &in)", asFUNCTION(proxy_insertValues4), asCALL_CDECL); assert(r >= 0);
|
||||
|
||||
r = engine->RegisterGlobalFunction("void runScript(string &in)", asFUNCTION(runScript), asCALL_GENERIC); assert(r >= 0);
|
||||
|
||||
r = engine->RegisterGlobalFunction("void logInfo(const string &in)", asFUNCTION(logInfo), asCALL_CDECL); assert(r >= 0);
|
||||
r = engine->RegisterGlobalFunction("void logWarning(const string &in)", asFUNCTION(logWarning), asCALL_CDECL); assert(r >= 0);
|
||||
|
@ -109,7 +109,6 @@ public:
|
||||
bool isAbsoluteCoord);
|
||||
|
||||
virtual void reset();
|
||||
void setEnable(bool mode);
|
||||
const core::vector3df& getPosition() const;
|
||||
const core::vector3df getAbsolutePosition() const;
|
||||
const core::vector3df& getRotation() const;
|
||||
@ -151,8 +150,6 @@ public:
|
||||
const PhysicalObject* getPhysicalObject() const { return m_physical_object; }
|
||||
// ------------------------------------------------------------------------
|
||||
PhysicalObject* getPhysicalObject() { return m_physical_object; }
|
||||
//Due to above overload AngelScript cannot decide which function to bind
|
||||
PhysicalObject* getPhysicalObjectForScript() { return m_physical_object; }
|
||||
// ------------------------------------------------------------------------
|
||||
const core::vector3df getInitXYZ() const { return m_init_xyz; }
|
||||
// ------------------------------------------------------------------------
|
||||
@ -165,20 +162,47 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
template<typename T>
|
||||
const T* getPresentation() const { return dynamic_cast<T*>(m_presentation); }
|
||||
|
||||
//specialized getters for scripts
|
||||
TrackObjectPresentationMesh* getMesh(){ return getPresentation<TrackObjectPresentationMesh>(); }
|
||||
|
||||
TrackObjectPresentationParticles* getParticles(){ return getPresentation<TrackObjectPresentationParticles>(); }
|
||||
|
||||
TrackObjectPresentationSound* getSound(){ return getPresentation<TrackObjectPresentationSound>(); }
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Methods usable by scripts
|
||||
/**
|
||||
* \addtogroup Scripting
|
||||
* @{
|
||||
* \addtogroup Scripting_Track Track
|
||||
* @{
|
||||
* \addtogroup Scripting_TrackObject TrackObject (script binding)
|
||||
* @{
|
||||
*/
|
||||
/** Should only be used on mesh track objects.
|
||||
* On the script side, the returned object is of type : @ref Scripting_Mesh
|
||||
*/
|
||||
TrackObjectPresentationMesh* getMesh() { return getPresentation<TrackObjectPresentationMesh>(); }
|
||||
/** Should only be used on particle emitter track objects.
|
||||
* On the script side, the returned object is of type : @ref Scripting_ParticleEmitter
|
||||
*/
|
||||
TrackObjectPresentationParticles* getParticleEmitter() { return getPresentation<TrackObjectPresentationParticles>(); }
|
||||
/** Should only be used on sound emitter track objects.
|
||||
* On the script side, the returned object is of type : @ref Scripting_SoundEmitter
|
||||
*/
|
||||
TrackObjectPresentationSound* getSoundEmitter(){ return getPresentation<TrackObjectPresentationSound>(); }
|
||||
// For angelscript. Needs to be named something different than getAnimator since it's overloaded.
|
||||
/** Should only be used on TrackObjects that use curve-based animation.
|
||||
* On the script side, the returned object is of type : @ref Scripting_Animator
|
||||
*/
|
||||
ThreeDAnimation* getIPOAnimator() { return m_animator; }
|
||||
// For angelscript. Needs to be named something different than getPhysicalObject since it's overloaded.
|
||||
/** Get the physics representation of an object.
|
||||
* On the script side, the returned object is of type : @ref Scripting_PhysicalObject
|
||||
*/
|
||||
PhysicalObject* getPhysics() { return m_physical_object; }
|
||||
/** Hide or show the object */
|
||||
void setEnable(bool mode);
|
||||
/* @} */
|
||||
/* @} */
|
||||
/* @} */
|
||||
// ------------------------------------------------------------------------
|
||||
ThreeDAnimation* getAnimator() { return m_animator; }
|
||||
// ------------------------------------------------------------------------
|
||||
const ThreeDAnimation* getAnimator() const { return m_animator; }
|
||||
//Due to above overload AngelScript cannot decide which function to bind
|
||||
ThreeDAnimation* getAnimatorForScript() { return m_animator; }
|
||||
// ------------------------------------------------------------------------
|
||||
void setPaused(bool mode){ m_animator->setPaused(mode); }
|
||||
// ------------------------------------------------------------------------
|
||||
|
@ -826,7 +826,24 @@ void TrackObjectPresentationParticles::triggerParticles()
|
||||
m_emitter->setParticleType(m_emitter->getParticlesInfo());
|
||||
}
|
||||
} // triggerParticles
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void TrackObjectPresentationParticles::stop()
|
||||
{
|
||||
if (m_emitter != NULL)
|
||||
{
|
||||
m_emitter->setCreationRateAbsolute(0.0f);
|
||||
m_emitter->clearParticles();
|
||||
}
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
void TrackObjectPresentationParticles::setRate(float rate)
|
||||
{
|
||||
if (m_emitter != NULL)
|
||||
{
|
||||
m_emitter->setCreationRateAbsolute(rate);
|
||||
m_emitter->setParticleType(m_emitter->getParticlesInfo());
|
||||
}
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
TrackObjectPresentationLight::TrackObjectPresentationLight(
|
||||
const XMLNode& xml_node,
|
||||
|
@ -312,6 +312,8 @@ public:
|
||||
|
||||
virtual void update(float dt) OVERRIDE;
|
||||
void triggerParticles();
|
||||
void stop();
|
||||
void setRate(float rate);
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the trigger condition for this object. */
|
||||
std::string& getTriggerCondition() { return m_trigger_condition; }
|
||||
|
Loading…
x
Reference in New Issue
Block a user