Action triggers addressable by name, scripts can enable/disable action triggers

This commit is contained in:
sachith500 2014-05-23 14:39:03 +05:30
parent cfef3e5456
commit 867f1607dd
8 changed files with 85 additions and 16 deletions

14
data/scripts/cycle1.as Normal file
View File

@ -0,0 +1,14 @@
void onTrigger()
{
/*to activate these 3 scripts add the following lines to stk-assets/20_harvest/scene.xml
<object type="action-trigger" action="cycle1" distance="30.0" xyz="139.86 10.21 80.94" hpr="0.0 -0.0 0.0" scale="7.00 7.00 7.00"/>
<object type="action-trigger" action="cycle2" distance="30.0" xyz="110.86 10.21 50.94" hpr="0.0 -0.0 0.0" scale="7.00 7.00 7.00"/>
<object type="action-trigger" action="cycle3" distance="30.0" xyz="-1.69 10.60 -42.19" hpr="0.0 -0.0 0.0" scale="7.00 7.00 7.00"/>
*/
displayMessage("1 triggered, 2 activated, 3 deactivated");
enableTrigger("cycle2");
disableTrigger("cycle3");
}

14
data/scripts/cycle2.as Normal file
View File

@ -0,0 +1,14 @@
void onTrigger()
{
/*to activate these 3 scripts add the following lines to stk-assets/20_harvest/scene.xml
<object type="action-trigger" action="cycle1" distance="30.0" xyz="139.86 10.21 80.94" hpr="0.0 -0.0 0.0" scale="7.00 7.00 7.00"/>
<object type="action-trigger" action="cycle2" distance="30.0" xyz="110.86 10.21 50.94" hpr="0.0 -0.0 0.0" scale="7.00 7.00 7.00"/>
<object type="action-trigger" action="cycle3" distance="30.0" xyz="-1.69 10.60 -42.19" hpr="0.0 -0.0 0.0" scale="7.00 7.00 7.00"/>
*/
displayMessage("2 triggered, 3 activated, 1 deactivated");
enableTrigger("cycle3");
disableTrigger("cycle1");
}

14
data/scripts/cycle3.as Normal file
View File

@ -0,0 +1,14 @@
void onTrigger()
{
/*to activate these 3 scripts add the following lines to stk-assets/20_harvest/scene.xml
<object type="action-trigger" action="cycle1" distance="30.0" xyz="139.86 10.21 80.94" hpr="0.0 -0.0 0.0" scale="7.00 7.00 7.00"/>
<object type="action-trigger" action="cycle2" distance="30.0" xyz="110.86 10.21 50.94" hpr="0.0 -0.0 0.0" scale="7.00 7.00 7.00"/>
<object type="action-trigger" action="cycle3" distance="30.0" xyz="-1.69 10.60 -42.19" hpr="0.0 -0.0 0.0" scale="7.00 7.00 7.00"/>
*/
displayMessage("3 triggered, 1 activated, 2 deactivated");
enableTrigger("cycle1");
disableTrigger("cycle2");
}

View File

@ -67,11 +67,23 @@ void displayMessage(asIScriptGeneric *gen){
}
void disableAnimation(asIScriptGeneric *gen){
std::string *str = (std::string*)gen->GetArgAddress(0);
World::getWorld()->getTrack()->getTrackObjectManager()->disable(*str);
std::string type = "mesh";
World::getWorld()->getTrack()->getTrackObjectManager()->disable(*str,type);
}
void enableAnimation(asIScriptGeneric *gen){
std::string *str = (std::string*)gen->GetArgAddress(0);
World::getWorld()->getTrack()->getTrackObjectManager()->enable(*str);
std::string type = "mesh";
World::getWorld()->getTrack()->getTrackObjectManager()->enable(*str,type);
}
void disableTrigger(asIScriptGeneric *gen){
std::string *str = (std::string*)gen->GetArgAddress(0);
std::string type = "action-trigger";
World::getWorld()->getTrack()->getTrackObjectManager()->disable(*str,type);
}
void enableTrigger(asIScriptGeneric *gen){
std::string *str = (std::string*)gen->GetArgAddress(0);
std::string type = "action-trigger";
World::getWorld()->getTrack()->getTrackObjectManager()->enable(*str,type);
}
void squashKart(asIScriptGeneric *gen){
int id = (int)gen->GetArgDWord(0);
@ -215,6 +227,8 @@ void ScriptEngine::configureEngine(asIScriptEngine *engine)
r = engine->RegisterGlobalFunction("void disableAnimation(string &in)", asFUNCTION(disableAnimation), asCALL_GENERIC); assert(r>=0);
r = engine->RegisterGlobalFunction("void enableAnimation(string &in)", asFUNCTION(enableAnimation), asCALL_GENERIC); assert(r>=0);
r = engine->RegisterGlobalFunction("void squashKart(int id, float time)", asFUNCTION(squashKart), 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);
// It is possible to register the functions, properties, and types in
// configuration groups as well. When compiling the scripts it can then

View File

@ -141,6 +141,8 @@ void TrackObject::init(const XMLNode &xml_node, scene::ISceneNode* parent,
std::string m_action;
xml_node.get("action", &m_action);
xml_node.get("distance", &m_distance);
m_name = m_action;
//adds action as name so that it can be found by using getName()
if (m_action == "garage")
{
m_garage = true;

View File

@ -87,22 +87,27 @@ void TrackObjectManager::reset()
} // reset
// ----------------------------------------------------------------------------
void TrackObjectManager::disable(std::string name){
void TrackObjectManager::disable(std::string name , std::string type){
TrackObject* curr;
for_in (curr,m_all_objects){
if (type != curr->getType())continue;
if (curr->getName() == (name)){
curr->setEnable(false);
curr->setEnable(false);
}
}
}
void TrackObjectManager::enable(std::string name){
void TrackObjectManager::enable(std::string name , std::string type){
TrackObject* curr;
for_in (curr,m_all_objects){
if (type != curr->getType())continue;
if (curr->getName() == (name)){
curr->setEnable(true);
curr->reset();
curr->setEnable(true);
}
}
@ -111,8 +116,8 @@ bool TrackObjectManager::getStatus(std::string name){
TrackObject* curr;
for_in (curr,m_all_objects){
if (curr->getName() == (name)){
//OutputDebugString("came here2");
return curr->isEnabled();
return curr->isEnabled();
}
}

View File

@ -55,8 +55,8 @@ public:
bool secondary_hits=true);
void reset();
void init();
void disable(std::string name);
void enable(std::string name);
void disable(std::string name , std::string type);
void enable (std::string name , std::string type);
bool getStatus(std::string name);
/** Enable or disable fog on objects */

View File

@ -47,9 +47,6 @@
#include <ILightSceneNode.h>
#include <IMeshManipulator.h>
//for testing
#include <time.h>
#include <iostream>
// ----------------------------------------------------------------------------
TrackObjectPresentation::TrackObjectPresentation(const XMLNode& xml_node)
@ -896,9 +893,18 @@ void TrackObjectPresentationActionTrigger::onTriggerItemApproached(Item* who)
return;
}
else
{
fprintf(stderr, "[TrackObject] WARNING: unknown action <%s>\n",
{
//TODO move all above functions into scripts and remove the ifs
ScriptEngine* m_script_engine = World::getWorld()->getScriptEngine();
m_action_active = false;
m_script_engine->runScript(m_action);
/*
Catch exception -> script not found
fprintf(stderr, "[TrackObject] WARNING: unknown action <%s>\n",
m_action.c_str());
*/
}
}