Merge branch 'master' of github.com:supertuxkart/stk-code
This commit is contained in:
commit
620a5b34f2
@ -31,6 +31,7 @@
|
|||||||
#include "scriptengine/script_utils.hpp"
|
#include "scriptengine/script_utils.hpp"
|
||||||
#include "scriptengine/scriptstdstring.hpp"
|
#include "scriptengine/scriptstdstring.hpp"
|
||||||
#include "scriptengine/scriptvec3.hpp"
|
#include "scriptengine/scriptvec3.hpp"
|
||||||
|
#include "scriptengine/scriptarray.hpp"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "states_screens/dialogs/tutorial_message_dialog.hpp"
|
#include "states_screens/dialogs/tutorial_message_dialog.hpp"
|
||||||
#include "tracks/track_object_manager.hpp"
|
#include "tracks/track_object_manager.hpp"
|
||||||
@ -307,9 +308,20 @@ namespace Scripting
|
|||||||
// Find the function for the function we want to execute.
|
// Find the function for the function we want to execute.
|
||||||
// This is how you call a normal function with arguments
|
// This is how you call a normal function with arguments
|
||||||
// asIScriptFunction *func = engine->GetModule(0)->GetFunctionByDecl("void func(arg1Type, arg2Type)");
|
// asIScriptFunction *func = engine->GetModule(0)->GetFunctionByDecl("void func(arg1Type, arg2Type)");
|
||||||
func = m_engine->GetModule(MODULE_ID_MAIN_SCRIPT_FILE)
|
asIScriptModule* module = m_engine->GetModule(MODULE_ID_MAIN_SCRIPT_FILE);
|
||||||
->GetFunctionByDecl(function_name.c_str());
|
|
||||||
|
if (module == NULL)
|
||||||
|
{
|
||||||
|
if (warn_if_not_found)
|
||||||
|
Log::warn("Scripting", "Scripting function was not found : %s (module not found)", function_name.c_str());
|
||||||
|
else
|
||||||
|
Log::debug("Scripting", "Scripting function was not found : %s (module not found)", function_name.c_str());
|
||||||
|
m_functions_cache[function_name] = NULL; // remember that this function is unavailable
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
func = module->GetFunctionByDecl(function_name.c_str());
|
||||||
|
|
||||||
if (func == NULL)
|
if (func == NULL)
|
||||||
{
|
{
|
||||||
if (warn_if_not_found)
|
if (warn_if_not_found)
|
||||||
@ -428,6 +440,7 @@ namespace Scripting
|
|||||||
// Register the script string type
|
// Register the script string type
|
||||||
RegisterStdString(engine); //register std::string
|
RegisterStdString(engine); //register std::string
|
||||||
RegisterVec3(engine); //register Vec3
|
RegisterVec3(engine); //register Vec3
|
||||||
|
RegisterScriptArray(engine, true);
|
||||||
|
|
||||||
Scripting::Track::registerScriptFunctions(m_engine);
|
Scripting::Track::registerScriptFunctions(m_engine);
|
||||||
Scripting::Challenges::registerScriptFunctions(m_engine);
|
Scripting::Challenges::registerScriptFunctions(m_engine);
|
||||||
|
@ -178,8 +178,11 @@ TrackObjectPresentationLibraryNode::TrackObjectPresentationLibraryNode(
|
|||||||
ModelDefinitionLoader& model_def_loader)
|
ModelDefinitionLoader& model_def_loader)
|
||||||
: TrackObjectPresentationSceneNode(xml_node)
|
: TrackObjectPresentationSceneNode(xml_node)
|
||||||
{
|
{
|
||||||
|
m_start_executed = false;
|
||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
xml_node.get("name", &name);
|
xml_node.get("name", &name);
|
||||||
|
m_name = name;
|
||||||
|
|
||||||
m_node = irr_driver->getSceneManager()->addEmptySceneNode();
|
m_node = irr_driver->getSceneManager()->addEmptySceneNode();
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@ -210,13 +213,17 @@ TrackObjectPresentationLibraryNode::TrackObjectPresentationLibraryNode(
|
|||||||
lib_path = track->getTrackFile("library/" + name);
|
lib_path = track->getTrackFile("library/" + name);
|
||||||
libroot = file_manager->createXMLTree(local_lib_node_path);
|
libroot = file_manager->createXMLTree(local_lib_node_path);
|
||||||
if (track != NULL)
|
if (track != NULL)
|
||||||
|
{
|
||||||
Scripting::ScriptEngine::getInstance()->loadScript(local_script_file_path, false);
|
Scripting::ScriptEngine::getInstance()->loadScript(local_script_file_path, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (file_manager->fileExists(lib_node_path))
|
else if (file_manager->fileExists(lib_node_path))
|
||||||
{
|
{
|
||||||
libroot = file_manager->createXMLTree(lib_node_path);
|
libroot = file_manager->createXMLTree(lib_node_path);
|
||||||
if (track != NULL)
|
if (track != NULL)
|
||||||
|
{
|
||||||
Scripting::ScriptEngine::getInstance()->loadScript(lib_script_file_path, false);
|
Scripting::ScriptEngine::getInstance()->loadScript(lib_script_file_path, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -272,6 +279,25 @@ TrackObjectPresentationLibraryNode::TrackObjectPresentationLibraryNode(
|
|||||||
m_parent = parent;
|
m_parent = parent;
|
||||||
} // TrackObjectPresentationLibraryNode
|
} // TrackObjectPresentationLibraryNode
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void TrackObjectPresentationLibraryNode::update(float dt)
|
||||||
|
{
|
||||||
|
if (!m_start_executed)
|
||||||
|
{
|
||||||
|
m_start_executed = true;
|
||||||
|
std::string fn_name = StringUtils::insertValues("void %s::onStart(const string)", m_name.c_str());
|
||||||
|
|
||||||
|
std::string lib_id = m_parent->getID();
|
||||||
|
std::string* lib_id_ptr = &lib_id;
|
||||||
|
|
||||||
|
Scripting::ScriptEngine::getInstance()->runFunction(false, fn_name,
|
||||||
|
[&](asIScriptContext* ctx) {
|
||||||
|
ctx->SetArgObject(0, lib_id_ptr);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
TrackObjectPresentationLibraryNode::~TrackObjectPresentationLibraryNode()
|
TrackObjectPresentationLibraryNode::~TrackObjectPresentationLibraryNode()
|
||||||
{
|
{
|
||||||
|
@ -186,11 +186,14 @@ class TrackObjectPresentationLibraryNode : public TrackObjectPresentationSceneNo
|
|||||||
{
|
{
|
||||||
TrackObject* m_parent;
|
TrackObject* m_parent;
|
||||||
using TrackObjectPresentationSceneNode::move;
|
using TrackObjectPresentationSceneNode::move;
|
||||||
|
std::string m_name;
|
||||||
|
bool m_start_executed;
|
||||||
public:
|
public:
|
||||||
TrackObjectPresentationLibraryNode(TrackObject* parent,
|
TrackObjectPresentationLibraryNode(TrackObject* parent,
|
||||||
const XMLNode& xml_node,
|
const XMLNode& xml_node,
|
||||||
ModelDefinitionLoader& model_def_loader);
|
ModelDefinitionLoader& model_def_loader);
|
||||||
virtual ~TrackObjectPresentationLibraryNode();
|
virtual ~TrackObjectPresentationLibraryNode();
|
||||||
|
virtual void update(float dt);
|
||||||
void move(const core::vector3df& xyz, const core::vector3df& hpr,
|
void move(const core::vector3df& xyz, const core::vector3df& hpr,
|
||||||
const core::vector3df& scale, bool isAbsoluteCoord, bool moveChildrenPhysicalBodies);
|
const core::vector3df& scale, bool isAbsoluteCoord, bool moveChildrenPhysicalBodies);
|
||||||
}; // TrackObjectPresentationLibraryNode
|
}; // TrackObjectPresentationLibraryNode
|
||||||
|
Loading…
x
Reference in New Issue
Block a user