Merge branch 'master' of github.com:supertuxkart/stk-code

This commit is contained in:
hiker 2017-01-20 14:15:55 +11:00
commit 620a5b34f2
3 changed files with 45 additions and 3 deletions

View File

@ -31,6 +31,7 @@
#include "scriptengine/script_utils.hpp"
#include "scriptengine/scriptstdstring.hpp"
#include "scriptengine/scriptvec3.hpp"
#include "scriptengine/scriptarray.hpp"
#include <string.h>
#include "states_screens/dialogs/tutorial_message_dialog.hpp"
#include "tracks/track_object_manager.hpp"
@ -307,9 +308,20 @@ namespace Scripting
// Find the function for the function we want to execute.
// This is how you call a normal function with arguments
// asIScriptFunction *func = engine->GetModule(0)->GetFunctionByDecl("void func(arg1Type, arg2Type)");
func = m_engine->GetModule(MODULE_ID_MAIN_SCRIPT_FILE)
->GetFunctionByDecl(function_name.c_str());
asIScriptModule* module = m_engine->GetModule(MODULE_ID_MAIN_SCRIPT_FILE);
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 (warn_if_not_found)
@ -428,6 +440,7 @@ namespace Scripting
// Register the script string type
RegisterStdString(engine); //register std::string
RegisterVec3(engine); //register Vec3
RegisterScriptArray(engine, true);
Scripting::Track::registerScriptFunctions(m_engine);
Scripting::Challenges::registerScriptFunctions(m_engine);

View File

@ -178,8 +178,11 @@ TrackObjectPresentationLibraryNode::TrackObjectPresentationLibraryNode(
ModelDefinitionLoader& model_def_loader)
: TrackObjectPresentationSceneNode(xml_node)
{
m_start_executed = false;
std::string name;
xml_node.get("name", &name);
m_name = name;
m_node = irr_driver->getSceneManager()->addEmptySceneNode();
#ifdef DEBUG
@ -210,13 +213,17 @@ TrackObjectPresentationLibraryNode::TrackObjectPresentationLibraryNode(
lib_path = track->getTrackFile("library/" + name);
libroot = file_manager->createXMLTree(local_lib_node_path);
if (track != NULL)
{
Scripting::ScriptEngine::getInstance()->loadScript(local_script_file_path, false);
}
}
else if (file_manager->fileExists(lib_node_path))
{
libroot = file_manager->createXMLTree(lib_node_path);
if (track != NULL)
{
Scripting::ScriptEngine::getInstance()->loadScript(lib_script_file_path, false);
}
}
else
{
@ -272,6 +279,25 @@ TrackObjectPresentationLibraryNode::TrackObjectPresentationLibraryNode(
m_parent = parent;
} // 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()
{

View File

@ -186,11 +186,14 @@ class TrackObjectPresentationLibraryNode : public TrackObjectPresentationSceneNo
{
TrackObject* m_parent;
using TrackObjectPresentationSceneNode::move;
std::string m_name;
bool m_start_executed;
public:
TrackObjectPresentationLibraryNode(TrackObject* parent,
const XMLNode& xml_node,
ModelDefinitionLoader& model_def_loader);
virtual ~TrackObjectPresentationLibraryNode();
virtual void update(float dt);
void move(const core::vector3df& xyz, const core::vector3df& hpr,
const core::vector3df& scale, bool isAbsoluteCoord, bool moveChildrenPhysicalBodies);
}; // TrackObjectPresentationLibraryNode