Bound Vec3 class to scripts

This commit is contained in:
Sachith Hasaranga Seneviratne 2014-06-07 08:07:18 +05:30
parent 85f6a7b576
commit 5498084cde
16 changed files with 155 additions and 33 deletions

@ -2,4 +2,10 @@ void onTrigger()
{
displayMessage("This trigger was added by another script");
jumpKartTo( 0, 67.90, 99.49 );
Vec3 a;
Vec3 b;
b=a;
Vec3 c = Vec3();
Vec3 d = Vec3(2,3,4);
printVec3(d);
}

@ -23,7 +23,8 @@
#include "karts/kart.hpp"
#include "modes/world.hpp"
#include "script_engine.hpp"
#include "scriptstdstring.h"
#include "scriptstdstring.hpp"
#include "scriptvec3.hpp"
#include <string.h> // strstr()
#include "states_screens/dialogs/tutorial_message_dialog.hpp"
#include "tracks/track_object_manager.hpp"
@ -33,7 +34,8 @@
using namespace Scripting;
namespace Scripting{
namespace Scripting
{
ScriptEngine::ScriptEngine()
{
@ -189,7 +191,8 @@ void ScriptEngine::configureEngine(asIScriptEngine *engine)
int r;
// Register the script string type
RegisterStdString(engine);
RegisterStdString(engine); //register std::string
RegisterVec3(engine); //register Vec3
Scripting::Track::registerScriptFunctions(m_engine);

@ -24,9 +24,11 @@
class TrackObjectPresentation;
namespace Scripting{
namespace Scripting
{
namespace Physics{
namespace Physics
{
void registerScriptFunctions(asIScriptEngine *engine);
asIScriptFunction*
registerScriptCallbacks(asIScriptEngine *engine);
@ -35,11 +37,13 @@ namespace Scripting{
void setCollision(std::string collider1, std::string collider2);
}
namespace Kart{
namespace Kart
{
void registerScriptFunctions(asIScriptEngine *engine);
}
namespace Track{
namespace Track
{
void registerScriptFunctions(asIScriptEngine *engine);
asIScriptFunction*
registerScriptCallbacks(asIScriptEngine *engine);
@ -47,21 +51,21 @@ namespace Scripting{
class ScriptEngine
{
public:
public:
ScriptEngine();
~ScriptEngine();
ScriptEngine();
~ScriptEngine();
void runScript(std::string scriptName);
void runScript(std::string scriptName);
private:
asIScriptEngine *m_engine;
private:
asIScriptEngine *m_engine;
void configureEngine(asIScriptEngine *engine);
int compileScript(asIScriptEngine *engine,std::string scriptName);
void configureEngine(asIScriptEngine *engine);
int compileScript(asIScriptEngine *engine,std::string scriptName);
}; // class ScriptEngine
}; // class ScriptEngine
}
#endif

@ -22,11 +22,15 @@
#include "modes/world.hpp"
#include "script_kart.hpp"
//debug
#include <iostream>
namespace Scripting{
namespace Scripting
{
namespace Kart{
namespace Kart
{
void squashKart(asIScriptGeneric *gen)
{
@ -95,7 +99,6 @@ namespace Scripting{
r = engine->RegisterGlobalFunction("void teleportKart(int id, float x, float y,float z)", asFUNCTION(teleportKart), asCALL_GENERIC); assert(r >= 0);
r = engine->RegisterGlobalFunction("void setVelocity(int id, float x, float y,float z)", asFUNCTION(setVelocity), asCALL_GENERIC); assert(r >= 0);
r = engine->RegisterGlobalFunction("void jumpKartTo(int id, float x, float y)", asFUNCTION(jumpKartTo), asCALL_GENERIC); assert(r >= 0);
}
}
}

@ -21,9 +21,11 @@
#include <angelscript.h>
namespace Scripting{
namespace Scripting
{
namespace Kart{
namespace Kart
{
void registerScriptFunctions(asIScriptEngine *engine);

@ -20,9 +20,11 @@
#include <angelscript.h>
#include "script_physics.hpp"
namespace Scripting{
namespace Scripting
{
namespace Physics{
namespace Physics
{
void getCollidingKart1(asIScriptGeneric *gen)
{

@ -22,9 +22,11 @@
#include <angelscript.h>
#include <string>
namespace Scripting{
namespace Scripting
{
namespace Physics{
namespace Physics
{
//private:
//IDs of kart collisions

@ -24,9 +24,11 @@
#include "tracks/track_object_manager.hpp"
#include "tracks/track.hpp"
namespace Scripting{
namespace Scripting
{
namespace Track{
namespace Track
{
asIScriptFunction* registerScriptCallbacks(asIScriptEngine *engine)
{

@ -21,9 +21,11 @@
#include <angelscript.h>
namespace Scripting{
namespace Scripting
{
namespace Track{
namespace Track
{
//script engine functions
void registerScriptFunctions(asIScriptEngine *engine);

@ -4,7 +4,7 @@
#include <assert.h>
#include <stdio.h> // sprintf
#include "scriptarray.h"
#include "scriptarray.hpp"
using namespace std;

@ -1,4 +1,4 @@
#include "scriptstdstring.h"
#include "scriptstdstring.hpp"
#include <assert.h> // assert()
#include <sstream> // std::stringstream
#include <string.h> // strstr()

@ -1,6 +1,6 @@
#include <assert.h>
#include "scriptstdstring.h"
#include "scriptarray.h"
#include "scriptstdstring.hpp"
#include "scriptarray.hpp"
#include <stdio.h>
#include <string.h>

@ -0,0 +1,66 @@
//
// 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 "karts/kart.hpp"
#include "modes/world.hpp"
#include "script_kart.hpp"
//debug
#include <iostream>
namespace Scripting
{
void Constructor(void *memory)
{
// Initialize the pre-allocated memory by calling the
// object constructor with the placement-new operator
new(memory)Vec3();
}
void Destructor(void *memory)
{
// Uninitialize the memory by calling the object destructor
((Vec3*)memory)->~Vec3();
}
void ConstructVector3FromFloats(float a, float b, float c, void *memory){
//Constructor using 3 floats
new (memory)(Vec3)(Vec3(a, b, c));
}
void printVec3(asIScriptGeneric *gen)
{
Vec3 *script_vec3 = (Vec3*)gen->GetArgObject(0);
std::cout << script_vec3->getX() << "," << script_vec3->getY() << "," << script_vec3->getZ() << std::endl;
}
void RegisterVec3(asIScriptEngine *engine)
{
int r;
r = engine->RegisterObjectType("Vec3", sizeof(Vec3), asOBJ_VALUE); assert(r >= 0);
// Register the behaviours
r = engine->RegisterObjectBehaviour("Vec3", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(Constructor), asCALL_CDECL_OBJLAST); assert(r >= 0);
r = engine->RegisterObjectBehaviour("Vec3", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(Destructor), asCALL_CDECL_OBJLAST); assert(r >= 0);
r = engine->RegisterObjectMethod("Vec3", "Vec3 &opAssign(const Vec3 &in)", asMETHODPR(Vec3, operator =, (const Vec3&), Vec3&), asCALL_THISCALL); assert(r >= 0);
r = engine->RegisterObjectBehaviour("Vec3", asBEHAVE_CONSTRUCT, "void f(float, float, float)", asFUNCTION(ConstructVector3FromFloats), asCALL_CDECL_OBJLAST); assert(r >= 0);
r = engine->RegisterGlobalFunction("void printVec3(Vec3 a)", asFUNCTION(printVec3), asCALL_GENERIC); assert(r >= 0);
}
}

@ -0,0 +1,30 @@
//
// 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_SCRIPTVEC3_HPP
#define HEADER_SCRIPTVEC3_HPP
#include <angelscript.h>
namespace Scripting
{
void RegisterVec3(asIScriptEngine *engine);
}
#endif