Added Kart sub-namespace

This commit is contained in:
Sachith Hasaranga Seneviratne
2014-05-28 13:13:45 +05:30
parent 0fd792ac5b
commit 34fec63f9c
7 changed files with 124 additions and 47 deletions

View File

@@ -94,13 +94,6 @@ void enableTrigger(asIScriptGeneric *gen)
std::string type = "action-trigger";
World::getWorld()->getTrack()->getTrackObjectManager()->enable(*str,type);
}
void squashKart(asIScriptGeneric *gen)
{
int id = (int)gen->GetArgDWord(0);
float time = gen->GetArgFloat(1);
AbstractKart* kart = World::getWorld()->getKart(id);
kart->setSquash(time,0.5); //0.5 * max speed is new max for squashed duration
}
void setCollision(int kartid1,int kartid2)
{
Scripting::Physics::setCollision(kartid1,kartid2);
@@ -247,12 +240,14 @@ void ScriptEngine::configureEngine(asIScriptEngine *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);
r = engine->RegisterGlobalFunction("void squashKart(int id, float time)", asFUNCTION(squashKart), asCALL_GENERIC); assert(r>=0);
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 );
Scripting::Physics::registerScriptFunctions(m_engine);
// It is possible to register the functions, properties, and types in
// configuration groups as well. When compiling the scripts it can then

View File

@@ -30,6 +30,10 @@ namespace Scripting{
void registerScriptFunctions(asIScriptEngine *engine);
void setCollision(int collider1,int collider2);
}
namespace Kart{
void registerScriptFunctions(asIScriptEngine *engine);
}
class ScriptEngine
{

View File

@@ -0,0 +1,52 @@
//
// 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> // assert()
#include <angelscript.h>
#include "io/file_manager.hpp"
#include <iostream> // cout
#include "karts/kart.hpp"
#include "modes/world.hpp"
#include "script_engine.hpp"
#include "scriptstdstring.h"
#include <string.h> // strstr()
#include "states_screens/dialogs/tutorial_message_dialog.hpp"
#include "tracks/track_object_manager.hpp"
#include "tracks/track.hpp"
namespace Scripting{
namespace Kart{
void squashKart(asIScriptGeneric *gen)
{
int id = (int)gen->GetArgDWord(0);
float time = gen->GetArgFloat(1);
AbstractKart* kart = World::getWorld()->getKart(id);
kart->setSquash(time, 0.5); //0.5 * max speed is new max for squashed duration
}
void registerScriptFunctions(asIScriptEngine *engine)
{
int r;
r = engine->RegisterGlobalFunction("void squashKart(int id, float time)", asFUNCTION(squashKart), asCALL_GENERIC); assert(r >= 0);
}
}
}

View File

@@ -0,0 +1,34 @@
//
// 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_KART_HPP
#define HEADER_SCRIPT_KART_HPP
#include <string>
#include <angelscript.h>
namespace Scripting{
namespace Kart{
void registerScriptFunctions(asIScriptEngine *engine);
}
}
#endif

View File

@@ -33,15 +33,6 @@
namespace Scripting{
namespace Physics{
// 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);
int m_collidingkartid1;
int m_collidingkartid2;

View File

@@ -26,18 +26,19 @@ namespace Scripting{
namespace Physics{
private:
//private:
int m_collidingkartid1;
int m_collidingkartid2;
public:
//public:
void setCollision(int collider1,int collider2);
void registerScriptFunctions(asIScriptEngine *engine);
asIScriptFunction*
registerScriptCallbacks(asIScriptEngine *engine);
void getCollidingKart1(asIScriptGeneric *gen);
void getCollidingKart2(asIScriptGeneric *gen);
}

View File

@@ -38,7 +38,7 @@
#include "tracks/model_definition_loader.hpp"
#include "tracks/track.hpp"
#include "tracks/track_object_manager.hpp"
#include "scriptengine/script_engine.hpp";
#include "scriptengine/script_engine.hpp"
#include <ISceneManager.h>
#include <IMeshSceneNode.h>
#include <ICameraSceneNode.h>
@@ -785,32 +785,32 @@ void TrackObjectPresentationActionTrigger::onTriggerItemApproached(Item* who)
}
else if (m_action == "tutorial_bananas")
{
Scripting::ScriptEngine* m_script_engine = World::getWorld()->getScriptEngine();
Scripting::ScriptEngine* m_script_engine = World::getWorld()->getScriptEngine();
m_action_active = false;
m_script_engine->runScript(m_action);
m_script_engine->runScript(m_action);
}
else if (m_action == "haybail")
else if (m_action == "haybail")
{
/*to activate this add the following line to stk-assets/farm/scene.xml
/*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"/>
<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"/>
*/
m_action_active=false;
Scripting::ScriptEngine* m_script_engine = World::getWorld()->getScriptEngine();
m_script_engine->runScript(m_action);
}
else if (m_action == "haybail-activate")
*/
m_action_active=false;
Scripting::ScriptEngine* m_script_engine = World::getWorld()->getScriptEngine();
m_script_engine->runScript(m_action);
}
else if (m_action == "haybail-activate")
{
/*to activate this add the following line to stk-assets/farm/scene.xml
/*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"/>
<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"/>
*/
m_action_active=false;
Scripting::ScriptEngine* m_script_engine = World::getWorld()->getScriptEngine();
m_script_engine->runScript(m_action);
}
*/
m_action_active=false;
Scripting::ScriptEngine* m_script_engine = World::getWorld()->getScriptEngine();
m_script_engine->runScript(m_action);
}
else if (m_action == "tutorial_giftboxes")
{
m_action_active = false;
@@ -894,17 +894,17 @@ void TrackObjectPresentationActionTrigger::onTriggerItemApproached(Item* who)
}
else
{
//TODO move all above functions into scripts and remove the ifs
//TODO move all above functions into scripts and remove the ifs
Scripting::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_script_engine->runScript(m_action);
/*
Catch exception -> script not found
fprintf(stderr, "[TrackObject] WARNING: unknown action <%s>\n",
m_action.c_str());
*/
*/
}
}