All existing script functions decoupled from script engine, moved into namespaces of Kart,Track and Physics.(Corresponding to their game engine equivalents
This commit is contained in:
parent
8b9629fb5e
commit
6015b66f9a
@ -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
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -20,7 +20,7 @@
|
||||
#include <angelscript.h>
|
||||
#include "karts/kart.hpp"
|
||||
#include "modes/world.hpp"
|
||||
#include "script_engine.hpp"
|
||||
#include "script_kart.hpp"
|
||||
|
||||
|
||||
|
||||
|
@ -18,16 +18,13 @@
|
||||
|
||||
#include <assert.h>
|
||||
#include <angelscript.h>
|
||||
#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);
|
||||
|
@ -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);
|
||||
|
||||
|
88
src/scriptengine/script_track.cpp
Normal file
88
src/scriptengine/script_track.cpp
Normal file
@ -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 <assert.h>
|
||||
#include <angelscript.h>
|
||||
#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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
43
src/scriptengine/script_track.hpp
Normal file
43
src/scriptengine/script_track.hpp
Normal file
@ -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 <angelscript.h>
|
||||
|
||||
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
|
Loading…
x
Reference in New Issue
Block a user