Trigger scripts now work by binding to the FUNCTION pointed by the trigger action instead of by the FILENAME. Started adding files into a structure similiar to that present in the tracks/ directory

This commit is contained in:
Sachith Hasaranga Seneviratne 2014-06-19 19:02:00 +05:30
parent 97c17692e8
commit f86b5f91af
11 changed files with 63 additions and 10 deletions

View File

@ -0,0 +1,10 @@
void onStart()
{
displayMessage("Track Loaded");
//For green valley sheep test. See sheep_approach.as
createTrigger("haybail_deactivate", 69.97 ,8.08 ,-107.84, 20.00); //follows xzy for now
createTrigger("haybail",100.72, 10.20,-26.22 , 30.00);
}

View File

@ -0,0 +1,35 @@
void haybail()
{
/*to activate this add the following line to stk-assets/farm/scene.xml
<object type="action-trigger" action="haybail" distance="30.0" xyz="100.72 10.20 -26.22" hpr="0.0 -0.0 0.0" scale="7.00 7.00 7.00"/>
*/
displayMessage("Haybail deactivated");
//disableAnimation("hayBail.b3d");
TrackObject @t_obj = getTrackObject("hayBail.b3d");
//t_obj.setEnable(false);
PhysicalObject @haybail = t_obj.getPhysicalObject();
haybail.disable();
Mesh @haybailMesh = t_obj.getMesh();
Animator @haybailAnimator = t_obj.getAnimator();
haybailAnimator.setPaused(true);
//if (haybail.isFlattener())squashKart(0,35.0);
}
void haybail_deactivate()
{
/*to activate this add the following line to stk-assets/farm/scene.xml
<object type="action-trigger" action="haybail-activate" distance="10.0" xyz="69.97 8.08 -107.84" hpr="0.0 -0.0 0.0" scale="7.00 7.00 7.00"/>
*/
displayMessage("Haybail reactivated");
//enableAnimation("hayBail.b3d");
squashKart(0,35.0); //id of kart,time to squash
TrackObject @t_obj = getTrackObject("hayBail.b3d");
Animator @haybailAnimator = t_obj.getAnimator();
haybailAnimator.setPaused(false);
}

View File

@ -0,0 +1,4 @@
void onUpdate()
{
}

View File

@ -1,4 +1,4 @@
void onUpdate()
void onStart()
{
displayMessage("Track Loaded");

View File

@ -58,7 +58,8 @@ ScriptEngine::~ScriptEngine()
std::string getScript(std::string scriptName)
{
std::string script_dir = file_manager->getAsset(FileManager::SCRIPT, "");
script_dir += World::getWorld()->getTrack()->getIdent() + "/";
if (scriptName != "update" && scriptName != "collisions" && scriptName!="start") scriptName = "triggers";
script_dir += scriptName + ".as";
FILE *f = fopen(script_dir.c_str(), "rb");
if( f == 0 )
@ -129,7 +130,8 @@ void ScriptEngine::runScript(std::string scriptName)
}
else
{
func = Scripting::Track::registerScriptCallbacks(m_engine);
//trigger type can have different names
func = Scripting::Track::registerScriptCallbacks(m_engine , scriptName);
}
if( func == 0 )
{

View File

@ -47,7 +47,7 @@ namespace Scripting
void registerScriptFunctions(asIScriptEngine *engine);
asIScriptFunction*
registerScriptCallbacks(asIScriptEngine *engine);
registerScriptCallbacks(asIScriptEngine *engine, std::string scriptName);
asIScriptFunction*
registerUpdateScriptCallbacks(asIScriptEngine *engine);

View File

@ -25,6 +25,7 @@
#include "tracks/track_object.hpp"
#include "tracks/track.hpp"
#include "animations/three_d_animation.hpp"
#include <iostream> //debug
namespace Scripting
{
@ -32,16 +33,17 @@ namespace Scripting
namespace Track
{
asIScriptFunction* registerScriptCallbacks(asIScriptEngine *engine)
asIScriptFunction* registerScriptCallbacks(asIScriptEngine *engine, std::string scriptName)
{
asIScriptFunction *func;
func = engine->GetModule(0)->GetFunctionByDecl("void onTrigger()");
std::string function_name = "void " + scriptName + "()";
func = engine->GetModule(0)->GetFunctionByDecl(function_name.c_str());
return func;
}
asIScriptFunction* registerStartScriptCallbacks(asIScriptEngine *engine)
{
asIScriptFunction *func;
func = engine->GetModule(0)->GetFunctionByDecl("void onUpdate()");
func = engine->GetModule(0)->GetFunctionByDecl("void onStart()");
return func;
}
asIScriptFunction* registerUpdateScriptCallbacks(asIScriptEngine *engine)
@ -188,7 +190,7 @@ namespace Scripting
float y = gen->GetArgFloat(2);
float z = gen->GetArgFloat(3);
float distance = gen->GetArgFloat(4); //triggering distance
core::vector3df posi(0, 0, 0);
core::vector3df posi(x, y, z);
core::vector3df hpr(0, 0, 0);
core::vector3df scale(1.0f, 1.0f, 1.0f);
TrackObjectPresentationActionTrigger* newtrigger =

View File

@ -30,7 +30,7 @@ namespace Scripting
//script engine functions
void registerScriptFunctions(asIScriptEngine *engine);
asIScriptFunction*
registerScriptCallbacks(asIScriptEngine *engine);
registerScriptCallbacks(asIScriptEngine *engine , std::string scriptName);
//script-bound functions

View File

@ -778,7 +778,7 @@ TrackObjectPresentationActionTrigger::TrackObjectPresentationActionTrigger
(const core::vector3df& xyz,std::string script_name, float distance)
:TrackObjectPresentation(xyz)
{
m_init_xyz = core::vector3df(0, 0, 0);
m_init_xyz = xyz;
m_init_hpr = core::vector3df(0, 0, 0);
m_init_scale = core::vector3df(1, 1, 1);
float trigger_distance = distance;