diff --git a/src/scriptengine/script_engine.cpp b/src/scriptengine/script_engine.cpp index 0b2169a6e..76fa29be7 100644 --- a/src/scriptengine/script_engine.cpp +++ b/src/scriptengine/script_engine.cpp @@ -35,15 +35,6 @@ using namespace Scripting; namespace Scripting{ -// Function prototypes for binding. - void displayMessage(asIScriptGeneric *gen); - void disableAnimation(asIScriptGeneric *gen); - void enableAnimation(asIScriptGeneric *gen); - void squashKart(asIScriptGeneric *gen); - void enableTrigger(asIScriptGeneric *gen); - void disableTrigger(asIScriptGeneric *gen); - - ScriptEngine::ScriptEngine() { // Create the script engine @@ -62,43 +53,6 @@ ScriptEngine::~ScriptEngine() m_engine->Release(); } - -// Displays the message specified in displayMessage( string message ) within the script -void displayMessage(asIScriptGeneric *gen) -{ - std::string *input = (std::string*)gen->GetArgAddress(0); - irr::core::stringw out = irr::core::stringw((*input).c_str()); //irr::core::stringw supported by message dialogs - new TutorialMessageDialog((out),true); -} -void disableAnimation(asIScriptGeneric *gen) -{ - std::string *str = (std::string*)gen->GetArgAddress(0); - std::string type = "mesh"; - World::getWorld()->getTrack()->getTrackObjectManager()->disable(*str,type); -} -void enableAnimation(asIScriptGeneric *gen) -{ - std::string *str = (std::string*)gen->GetArgAddress(0); - 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 setCollision(int kartid1,int kartid2) -{ - Scripting::Physics::setCollision(kartid1,kartid2); -} - std::string getScript(std::string scriptName) { std::string script_dir = file_manager->getAsset(FileManager::SCRIPT, ""); @@ -159,13 +113,13 @@ void ScriptEngine::runScript(std::string scriptName) //This is how you call a normal function with arguments //asIScriptFunction *func = engine->GetModule(0)->GetFunctionByDecl("void func(arg1Type, arg2Type)"); asIScriptFunction *func; - if (scriptName=="collisions")//TODO Better way to handle this? + if (scriptName=="collisions") { - func = m_engine->GetModule(0)->GetFunctionByDecl("void onCollision()"); + func = Scripting::Physics::registerScriptCallbacks(m_engine); } else { - func = m_engine->GetModule(0)->GetFunctionByDecl("void onTrigger()"); + func = Scripting::Track::registerScriptCallbacks(m_engine); } if( func == 0 ) { @@ -237,16 +191,11 @@ void ScriptEngine::configureEngine(asIScriptEngine *engine) // Register the script string type RegisterStdString(engine); - r = engine->RegisterGlobalFunction("void displayMessage(string &in)", asFUNCTION(displayMessage), asCALL_GENERIC); assert(r>=0); - 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); + Scripting::Track::registerScriptFunctions(m_engine); + Scripting::Kart::registerScriptFunctions(m_engine); - //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); + Scripting::Physics::registerScriptFunctions(m_engine); - //r = engine->RegisterGlobalFunction("uint getCollidingKart1()", asFUNCTION(getCollidingKart1), asCALL_GENERIC); assert( r >= 0 ); - //r = engine->RegisterGlobalFunction("uint getCollidingKart2()", asFUNCTION(getCollidingKart2), asCALL_GENERIC); assert( r >= 0 ); // It is possible to register the functions, properties, and types in diff --git a/src/scriptengine/script_engine.hpp b/src/scriptengine/script_engine.hpp index 74eedac38..3e3947f64 100644 --- a/src/scriptengine/script_engine.hpp +++ b/src/scriptengine/script_engine.hpp @@ -28,12 +28,20 @@ namespace Scripting{ namespace Physics{ void registerScriptFunctions(asIScriptEngine *engine); + asIScriptFunction* + registerScriptCallbacks(asIScriptEngine *engine); void setCollision(int collider1,int collider2); } namespace Kart{ void registerScriptFunctions(asIScriptEngine *engine); } + + namespace Track{ + void registerScriptFunctions(asIScriptEngine *engine); + asIScriptFunction* + registerScriptCallbacks(asIScriptEngine *engine); + } class ScriptEngine { diff --git a/src/scriptengine/script_kart.cpp b/src/scriptengine/script_kart.cpp index f92f73dec..af03f19de 100644 --- a/src/scriptengine/script_kart.cpp +++ b/src/scriptengine/script_kart.cpp @@ -20,7 +20,7 @@ #include #include "karts/kart.hpp" #include "modes/world.hpp" -#include "script_engine.hpp" +#include "script_kart.hpp" diff --git a/src/scriptengine/script_physics.cpp b/src/scriptengine/script_physics.cpp index 3e3dde371..f777f668a 100644 --- a/src/scriptengine/script_physics.cpp +++ b/src/scriptengine/script_physics.cpp @@ -18,16 +18,13 @@ #include #include -#include "script_engine.hpp" +#include "script_physics.hpp" namespace Scripting{ namespace Physics{ - int m_collidingkartid1; - int m_collidingkartid2; - void getCollidingKart1(asIScriptGeneric *gen) { gen->SetReturnDWord(m_collidingkartid1); diff --git a/src/scriptengine/script_physics.hpp b/src/scriptengine/script_physics.hpp index d8d690383..d6dcb2958 100644 --- a/src/scriptengine/script_physics.hpp +++ b/src/scriptengine/script_physics.hpp @@ -31,10 +31,18 @@ namespace Scripting{ //public: - void setCollision(int collider1,int collider2); + //script engine functions void registerScriptFunctions(asIScriptEngine *engine); asIScriptFunction* registerScriptCallbacks(asIScriptEngine *engine); + + + //game engine functions + void setCollision(int collider1, int collider2); + + + + //script-bound functions void getCollidingKart1(asIScriptGeneric *gen); void getCollidingKart2(asIScriptGeneric *gen); diff --git a/src/scriptengine/script_track.cpp b/src/scriptengine/script_track.cpp new file mode 100644 index 000000000..597ff5393 --- /dev/null +++ b/src/scriptengine/script_track.cpp @@ -0,0 +1,88 @@ +// +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2014 SuperTuxKart Team +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 3 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#include +#include +#include "modes/world.hpp" +#include "script_track.hpp" +#include "states_screens/dialogs/tutorial_message_dialog.hpp" +#include "tracks/track_object_manager.hpp" +#include "tracks/track.hpp" + +namespace Scripting{ + + namespace Track{ + + asIScriptFunction* registerScriptCallbacks(asIScriptEngine *engine) + { + asIScriptFunction *func; + func = engine->GetModule(0)->GetFunctionByDecl("void onTrigger()"); + return func; + } + void registerScriptFunctions(asIScriptEngine *engine) + { + int r; + + r = engine->RegisterGlobalFunction("void displayMessage(string &in)", asFUNCTION(displayMessage), asCALL_GENERIC); assert(r >= 0); + 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 enableTrigger(string &in)", asFUNCTION(enableTrigger), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterGlobalFunction("void disableTrigger(string &in)", asFUNCTION(disableTrigger), asCALL_GENERIC); assert(r >= 0); + + } + + + + + + // Displays the message specified in displayMessage( string message ) within the script + void displayMessage(asIScriptGeneric *gen) + { + std::string *input = (std::string*)gen->GetArgAddress(0); + irr::core::stringw out = irr::core::stringw((*input).c_str()); //irr::core::stringw supported by message dialogs + new TutorialMessageDialog((out), true); + } + void disableAnimation(asIScriptGeneric *gen) + { + std::string *str = (std::string*)gen->GetArgAddress(0); + std::string type = "mesh"; + World::getWorld()->getTrack()->getTrackObjectManager()->disable(*str, type); + } + void enableAnimation(asIScriptGeneric *gen) + { + std::string *str = (std::string*)gen->GetArgAddress(0); + 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); + } + + + + } +} diff --git a/src/scriptengine/script_track.hpp b/src/scriptengine/script_track.hpp new file mode 100644 index 000000000..95c4ab441 --- /dev/null +++ b/src/scriptengine/script_track.hpp @@ -0,0 +1,43 @@ +// +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2014 SuperTuxKart Team +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 3 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#ifndef HEADER_SCRIPT_TRACK_HPP +#define HEADER_SCRIPT_TRACK_HPP + +#include + +namespace Scripting{ + + namespace Track{ + + //script engine functions + void registerScriptFunctions(asIScriptEngine *engine); + asIScriptFunction* + registerScriptCallbacks(asIScriptEngine *engine); + + + //script-bound functions + void displayMessage(asIScriptGeneric *gen); + void disableAnimation(asIScriptGeneric *gen); + void enableAnimation(asIScriptGeneric *gen); + void enableTrigger(asIScriptGeneric *gen); + void disableTrigger(asIScriptGeneric *gen); + } + +} +#endif