Work on scripting, namely improving interaction with library objects

This commit is contained in:
Marianne Gagnon 2015-06-05 19:34:46 -04:00
parent 238578c921
commit cb510840ae
6 changed files with 57 additions and 120 deletions

View File

@ -196,10 +196,8 @@ void Physics::update(float dt)
std::string lib_id;
std::string* lib_id_ptr = NULL;
if (library != NULL)
{
lib_id = library->getID();
lib_id_ptr = &lib_id;
}
if (scripting_function.size() > 0)
{

View File

@ -57,33 +57,9 @@ namespace Scripting
* Get a track object by ID.
* @return An object of type @ref Scripting_TrackObject
*/
TrackObject* getTrackObject(std::string* objID)
TrackObject* getTrackObject(std::string* libraryInstance, std::string* objID)
{
return World::getWorld()->getTrack()->getTrackObjectManager()->getTrackObject(*objID);
}
/** Hide/disable a track object */
void disableTrackObject(std::string* objID)
{
World::getWorld()->getTrack()->getTrackObjectManager()->disable(*objID);
}
/** Show/enable a track objects */
void enableTrackObject(std::string* objID)
{
World::getWorld()->getTrack()->getTrackObjectManager()->enable(*objID);
}
/** Disables an action trigger of specified ID */
void disableTrigger(std::string* triggerID)
{
World::getWorld()->getTrack()->getTrackObjectManager()->disable(*triggerID);
}
/** Enables an action trigger of specified ID */
void enableTrigger(std::string* triggerID)
{
World::getWorld()->getTrack()->getTrackObjectManager()->enable(*triggerID);
return World::getWorld()->getTrack()->getTrackObjectManager()->getTrackObject(*libraryInstance, *objID);
}
/** Creates a trigger at the specified location */
@ -250,18 +226,18 @@ namespace Scripting
r = engine->RegisterObjectType("SoundEmitter", 0, asOBJ_REF | asOBJ_NOCOUNT); assert(r >= 0);
r = engine->RegisterObjectType("Animator", 0, asOBJ_REF | asOBJ_NOCOUNT); assert(r >= 0);
r = engine->RegisterGlobalFunction("void disableTrackObject(const string &in)", asFUNCTION(disableTrackObject), asCALL_CDECL); assert(r >= 0);
r = engine->RegisterGlobalFunction("void enableTrackObject(const string &in)", asFUNCTION(enableTrackObject), asCALL_CDECL); assert(r >= 0);
r = engine->RegisterGlobalFunction("void enableTrigger(const string &in)", asFUNCTION(enableTrigger), asCALL_CDECL); assert(r >= 0);
r = engine->RegisterGlobalFunction("void disableTrigger(const string &in)", asFUNCTION(disableTrigger), asCALL_CDECL); assert(r >= 0);
//r = engine->RegisterGlobalFunction("void disableTrackObject(const string &in)", asFUNCTION(disableTrackObject), asCALL_CDECL); assert(r >= 0);
//r = engine->RegisterGlobalFunction("void enableTrackObject(const string &in)", asFUNCTION(enableTrackObject), asCALL_CDECL); assert(r >= 0);
//r = engine->RegisterGlobalFunction("void enableTrigger(const string &in)", asFUNCTION(enableTrigger), asCALL_CDECL); assert(r >= 0);
//r = engine->RegisterGlobalFunction("void disableTrigger(const string &in)", asFUNCTION(disableTrigger), asCALL_CDECL); assert(r >= 0);
r = engine->RegisterGlobalFunction("void createTrigger(const string &in, const Vec3 &in, float distance)",
asFUNCTION(createTrigger), asCALL_CDECL); assert(r >= 0);
r = engine->RegisterGlobalFunction("TrackObject@ getTrackObject(const string &in)", asFUNCTION(getTrackObject), asCALL_CDECL); assert(r >= 0);
r = engine->RegisterGlobalFunction("TrackObject@ getTrackObject(const string &in, const string &in)", asFUNCTION(getTrackObject), asCALL_CDECL); assert(r >= 0);
r = engine->RegisterGlobalFunction("void exitRace()", asFUNCTION(exitRace), asCALL_CDECL); assert(r >= 0);
r = engine->RegisterGlobalFunction("void pauseRace()", asFUNCTION(pauseRace), asCALL_CDECL); assert(r >= 0);
// TrackObject
r = engine->RegisterObjectMethod("TrackObject", "void setEnable(bool status)", asMETHOD(TrackObject, setEnable), asCALL_THISCALL); assert(r >= 0);
r = engine->RegisterObjectMethod("TrackObject", "void setEnabled(bool status)", asMETHOD(TrackObject, setEnabled), 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);

View File

@ -286,7 +286,7 @@ void TrackObject::reset()
{
if (m_presentation ) m_presentation->reset();
if (m_animator ) m_animator->reset();
if(m_physical_object) m_physical_object->reset();
if (m_physical_object) m_physical_object->reset();
} // reset
// ----------------------------------------------------------------------------
@ -294,10 +294,29 @@ void TrackObject::reset()
* disabled objects will not be displayed anymore.
* \param mode Enable (true) or disable (false) this object.
*/
void TrackObject::setEnable(bool mode)
void TrackObject::setEnabled(bool enabled)
{
m_enabled = mode;
if (m_presentation != NULL) m_presentation->setEnable(m_enabled);
if (m_enabled == enabled)
return;
m_enabled = enabled;
if (m_presentation != NULL)
m_presentation->setEnable(m_enabled);
if (enabled)
reset(); // TODO: not sure why there is a reset here
if (getType() == "mesh")
{
if (m_physical_object != NULL)
{
if (enabled)
m_physical_object->addBody();
else
m_physical_object->removeBody();
}
}
} // setEnable
// ----------------------------------------------------------------------------

View File

@ -207,7 +207,7 @@ public:
*/
PhysicalObject* getPhysics() { return m_physical_object; }
/** Hide or show the object */
void setEnable(bool mode);
void setEnabled(bool mode);
/* @} */
/* @} */
/* @} */

View File

@ -81,95 +81,42 @@ void TrackObjectManager::reset()
for (TrackObject* curr : m_all_objects)
{
curr->reset();
if (!curr->isEnabled())
{
//PhysicalObjects may need to be added
if (curr->getType() == "mesh")
{
if (curr->getPhysicalObject() != NULL)
curr->getPhysicalObject()->addBody();
}
}
curr->setEnable(true);
curr->setEnabled(true);
}
} // reset
// ----------------------------------------------------------------------------
/** disables all track objects with a particular ID
* \param name Name or ID for disabling
*/
void TrackObjectManager::disable(std::string name)
{
for (TrackObject* curr : m_all_objects)
{
if (curr->getName() == (name) || curr->getID() == (name))
{
curr->setEnable(false);
if (curr->getType() == "mesh")
{
if (curr->getPhysicalObject()!=NULL)
curr->getPhysicalObject()->removeBody();
}
}
}
}
// ----------------------------------------------------------------------------
/** enables all track objects with a particular ID
* \param name Name or ID for enabling
*/
void TrackObjectManager::enable(std::string name)
{
for (TrackObject* curr : m_all_objects)
{
if (curr->getName() == (name) || curr->getID() == (name))
{
curr->reset();
curr->setEnable(true);
if (curr->getType() == "mesh")
{
if (curr->getPhysicalObject() != NULL)
curr->getPhysicalObject()->addBody();
}
}
}
}
// ----------------------------------------------------------------------------
/** returns activation status for all track objects
* with a particular ID
* \param name Name or ID of track object
*/
bool TrackObjectManager::getStatus(std::string name)
{
for (TrackObject* curr : m_all_objects){
if (curr->getName() == (name)||curr->getID()==(name))
{
return curr->isEnabled();
}
}
//object not found
return false;
}
// ----------------------------------------------------------------------------
/** returns a reference to the track object
* with a particular ID
* \param name Name or ID of track object
*/
TrackObject* TrackObjectManager::getTrackObject(std::string name)
TrackObject* TrackObjectManager::getTrackObject(const std::string& libraryInstance,
const std::string& name)
{
for (TrackObject* curr : m_all_objects)
{
if (curr->getName() == (name) || curr->getID() == (name))
//if (curr->getParentLibrary() != NULL)
// Log::info("TrackObjectManager", "Found %s::%s", curr->getParentLibrary()->getID().c_str(), curr->getID().c_str());
//else
// Log::info("TrackObjectManager", "Found ::%s", curr->getID().c_str());
if (curr->getParentLibrary() == NULL)
{
if (libraryInstance.size() > 0)
continue;
}
else
{
if (libraryInstance != curr->getParentLibrary()->getID())
continue;
}
if (curr->getID() == name)
{
return curr;
}
}
//object not found
Log::warn("TrackObjectManager", "Object not found : %s::%s", libraryInstance.c_str(), name.c_str());
return NULL;
}
/** Handles an explosion, i.e. it makes sure that all physical objects are

View File

@ -62,9 +62,6 @@ public:
void update(float dt);
void handleExplosion(const Vec3 &pos, const PhysicalObject *mp,
bool secondary_hits=true);
void disable(std::string name);
void enable (std::string name);
bool getStatus(std::string name);
void castRay(const btVector3 &from,
const btVector3 &to, btVector3 *hit_point,
const Material **material, btVector3 *normal = NULL,
@ -77,7 +74,7 @@ public:
void removeObject(TrackObject* who);
TrackObject* getTrackObject(std::string name);
TrackObject* getTrackObject(const std::string& libraryInstance, const std::string& name);
PtrVector<TrackObject>& getObjects() { return m_all_objects; }
const PtrVector<TrackObject>& getObjects() const { return m_all_objects; }