Merge remote-tracking branch 'origin/master' into graphical_chassis_to_physical_chassis
This commit is contained in:
commit
e755a7eda8
@ -374,7 +374,7 @@ void Item::collected(const AbstractKart *kart, float t)
|
||||
|
||||
if (m_listener != NULL)
|
||||
{
|
||||
m_listener->onTriggerItemApproached(this);
|
||||
m_listener->onTriggerItemApproached();
|
||||
}
|
||||
|
||||
if (dynamic_cast<ThreeStrikesBattle*>(World::getWorld()) != NULL)
|
||||
|
@ -51,7 +51,7 @@ class TriggerItemListener
|
||||
{
|
||||
public:
|
||||
virtual ~TriggerItemListener() {}
|
||||
virtual void onTriggerItemApproached(Item* who) = 0;
|
||||
virtual void onTriggerItemApproached() = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -173,7 +173,13 @@ public:
|
||||
{
|
||||
return m_kart_info[kart_index].m_track_sector;
|
||||
} // getTrackSector
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
void setLastTriggeredCheckline(unsigned int kart_index, int index)
|
||||
{
|
||||
if (m_kart_info.size() == 0)
|
||||
return;
|
||||
m_kart_info[kart_index].m_track_sector.setLastTriggeredCheckline(index);
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns how far the kart has driven so far (i.e.
|
||||
* number-of-laps-finished times track-length plus distance-on-track.
|
||||
|
@ -128,6 +128,7 @@ void OverWorld::update(float dt)
|
||||
m_karts[n]->setEnergy(100.0f);
|
||||
}
|
||||
|
||||
/*
|
||||
TrackObjectManager* tom = getTrack()->getTrackObjectManager();
|
||||
PtrVector<TrackObject>& objects = tom->getObjects();
|
||||
for(unsigned int i=0; i<objects.size(); i++)
|
||||
@ -145,6 +146,7 @@ void OverWorld::update(float dt)
|
||||
obj->reset();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
if (m_return_to_garage)
|
||||
{
|
||||
|
@ -172,7 +172,7 @@ void Physics::update(float dt)
|
||||
Scripting::ScriptEngine* script_engine = World::getWorld()->getScriptEngine();
|
||||
int kartid1 = p->getUserPointer(0)->getPointerKart()->getWorldKartId();
|
||||
int kartid2 = p->getUserPointer(1)->getPointerKart()->getWorldKartId();
|
||||
script_engine->runFunction("void onKartKartCollision(int, int)",
|
||||
script_engine->runFunction(false, "void onKartKartCollision(int, int)",
|
||||
[=](asIScriptContext* ctx) {
|
||||
ctx->SetArgDWord(0, kartid1);
|
||||
ctx->SetArgDWord(1, kartid2);
|
||||
@ -201,7 +201,7 @@ void Physics::update(float dt)
|
||||
|
||||
if (scripting_function.size() > 0)
|
||||
{
|
||||
script_engine->runFunction("void " + scripting_function + "(int, const string, const string)",
|
||||
script_engine->runFunction(true, "void " + scripting_function + "(int, const string, const string)",
|
||||
[&](asIScriptContext* ctx) {
|
||||
ctx->SetArgDWord(0, kartId);
|
||||
ctx->SetArgObject(1, lib_id_ptr);
|
||||
@ -274,7 +274,7 @@ void Physics::update(float dt)
|
||||
std::string scripting_function = obj->getOnItemCollisionFunction();
|
||||
if (scripting_function.size() > 0)
|
||||
{
|
||||
script_engine->runFunction("void " + scripting_function + "(int, int, const string)",
|
||||
script_engine->runFunction(true, "void " + scripting_function + "(int, int, const string)",
|
||||
[&](asIScriptContext* ctx) {
|
||||
ctx->SetArgDWord(0, (int)flyable->getType());
|
||||
ctx->SetArgDWord(1, flyable->getOwnerId());
|
||||
|
@ -175,20 +175,20 @@ namespace Scripting
|
||||
/** runs the specified script
|
||||
* \param string scriptName = name of script to run
|
||||
*/
|
||||
void ScriptEngine::runFunction(std::string function_name)
|
||||
void ScriptEngine::runFunction(bool warn_if_not_found, std::string function_name)
|
||||
{
|
||||
std::function<void(asIScriptContext*)> callback;
|
||||
std::function<void(asIScriptContext*)> get_return_value;
|
||||
runFunction(function_name, callback, get_return_value);
|
||||
runFunction(warn_if_not_found, function_name, callback, get_return_value);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void ScriptEngine::runFunction(std::string function_name,
|
||||
void ScriptEngine::runFunction(bool warn_if_not_found, std::string function_name,
|
||||
std::function<void(asIScriptContext*)> callback)
|
||||
{
|
||||
std::function<void(asIScriptContext*)> get_return_value;
|
||||
runFunction(function_name, callback, get_return_value);
|
||||
runFunction(warn_if_not_found, function_name, callback, get_return_value);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -196,7 +196,7 @@ namespace Scripting
|
||||
/** runs the specified script
|
||||
* \param string scriptName = name of script to run
|
||||
*/
|
||||
void ScriptEngine::runFunction(std::string function_name,
|
||||
void ScriptEngine::runFunction(bool warn_if_not_found, std::string function_name,
|
||||
std::function<void(asIScriptContext*)> callback,
|
||||
std::function<void(asIScriptContext*)> get_return_value)
|
||||
{
|
||||
@ -217,7 +217,10 @@ namespace Scripting
|
||||
|
||||
if (func == NULL)
|
||||
{
|
||||
Log::debug("Scripting", "Scripting function was not found : %s", function_name.c_str());
|
||||
if (warn_if_not_found)
|
||||
Log::warn("Scripting", "Scripting function was not found : %s", function_name.c_str());
|
||||
else
|
||||
Log::debug("Scripting", "Scripting function was not found : %s", function_name.c_str());
|
||||
m_functions_cache[function_name] = NULL; // remember that this function is unavailable
|
||||
return;
|
||||
}
|
||||
@ -233,6 +236,8 @@ namespace Scripting
|
||||
|
||||
if (func == NULL)
|
||||
{
|
||||
if (warn_if_not_found)
|
||||
Log::warn("Scripting", "Scripting function was not found : %s", function_name.c_str());
|
||||
return; // function unavailable
|
||||
}
|
||||
|
||||
@ -425,7 +430,7 @@ namespace Scripting
|
||||
curr.m_time -= dt;
|
||||
if (curr.m_time <= 0.0)
|
||||
{
|
||||
runFunction("void " + curr.m_callback_name + "()");
|
||||
runFunction(true, "void " + curr.m_callback_name + "()");
|
||||
m_pending_timeouts.erase(m_pending_timeouts.begin() + i);
|
||||
}
|
||||
}
|
||||
|
@ -47,10 +47,10 @@ namespace Scripting
|
||||
ScriptEngine();
|
||||
~ScriptEngine();
|
||||
|
||||
void runFunction(std::string function_name);
|
||||
void runFunction(std::string function_name,
|
||||
void runFunction(bool warn_if_not_found, std::string function_name);
|
||||
void runFunction(bool warn_if_not_found, std::string function_name,
|
||||
std::function<void(asIScriptContext*)> callback);
|
||||
void runFunction(std::string function_name,
|
||||
void runFunction(bool warn_if_not_found, std::string function_name,
|
||||
std::function<void(asIScriptContext*)> callback,
|
||||
std::function<void(asIScriptContext*)> get_return_value);
|
||||
void evalScript(std::string script_fragment);
|
||||
|
@ -101,11 +101,11 @@ namespace Scripting
|
||||
return StringUtils::wide_to_utf8(out.c_str());
|
||||
}
|
||||
|
||||
/** Runs the script specified by the given string */
|
||||
/** Runs the script function specified by the given string */
|
||||
void runScript(const std::string* str)
|
||||
{
|
||||
ScriptEngine* script_engine = World::getWorld()->getScriptEngine();
|
||||
script_engine->runFunction(*str);
|
||||
script_engine->runFunction(true, *str);
|
||||
}
|
||||
|
||||
/** Generate a random integer value */
|
||||
|
77
src/tracks/check_cylinder.cpp
Normal file
77
src/tracks/check_cylinder.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
//
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2009-2015 Joerg Henrichs
|
||||
//
|
||||
// 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 "tracks/check_cylinder.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "io/xml_node.hpp"
|
||||
#include "items/item.hpp"
|
||||
#include "modes/world.hpp"
|
||||
#include "race/race_manager.hpp"
|
||||
|
||||
CheckCylinder::CheckCylinder(const XMLNode &node, unsigned int index, TriggerItemListener* listener)
|
||||
: CheckStructure(node, index)
|
||||
{
|
||||
m_radius2 = 1;
|
||||
m_height = 0;
|
||||
m_listener = listener;
|
||||
node.get("height", &m_height);
|
||||
node.get("radius", &m_radius2);
|
||||
m_radius2 *= m_radius2;
|
||||
node.get("xyz", &m_center_point);
|
||||
unsigned int num_karts = race_manager->getNumberOfKarts();
|
||||
m_is_inside.resize(num_karts);
|
||||
m_distance2.resize(num_karts);
|
||||
for (unsigned int i=0; i<num_karts; i++)
|
||||
{
|
||||
m_is_inside[i] = false;
|
||||
}
|
||||
} // CheckCylinder
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** True if going from old_pos to new_pos enters or leaves this sphere. This
|
||||
* function is called from update (of the checkline structure). It also
|
||||
* updates the flag about which karts are inside
|
||||
* \param old_pos Position in previous frame.
|
||||
* \param new_pos Position in current frame.
|
||||
* \param kart_id Index of the kart, can be used to store kart specific
|
||||
* additional data.
|
||||
*/
|
||||
bool CheckCylinder::isTriggered(const Vec3 &old_pos, const Vec3 &new_pos,
|
||||
unsigned int kart_id)
|
||||
{
|
||||
// TODO: this is the code for a sphere, rewrite for cylinder
|
||||
Vec3 old_pos_xz(old_pos.x(), 0.0f, old_pos.z());
|
||||
Vec3 new_pos_xz(new_pos.x(), 0.0f, new_pos.z());
|
||||
Vec3 center_xz(m_center_point.x(), 0.0f, m_center_point.z());
|
||||
float old_dist2 = (old_pos_xz - center_xz).length2();
|
||||
float new_dist2 = (new_pos_xz - center_xz).length2();
|
||||
m_is_inside[kart_id] = new_dist2<m_radius2;
|
||||
m_distance2[kart_id] = new_dist2;
|
||||
// Trigger if the kart goes from outside (or border) to inside,
|
||||
// or inside ro outside (or border).
|
||||
bool triggered = (old_dist2>=m_radius2 && new_dist2 < m_radius2) ||
|
||||
(old_dist2< m_radius2 && new_dist2 >=m_radius2);
|
||||
|
||||
if (triggered && m_listener != NULL)
|
||||
m_listener->onTriggerItemApproached();
|
||||
|
||||
return triggered;
|
||||
} // isTriggered
|
69
src/tracks/check_cylinder.hpp
Normal file
69
src/tracks/check_cylinder.hpp
Normal file
@ -0,0 +1,69 @@
|
||||
//
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2009-2015 Joerg Henrichs
|
||||
//
|
||||
// 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_CHECK_CYLINDER_HPP
|
||||
#define HEADER_CHECK_CYLINDER_HPP
|
||||
|
||||
#include "tracks/check_structure.hpp"
|
||||
|
||||
class XMLNode;
|
||||
class CheckManager;
|
||||
class TriggerItemListener;
|
||||
|
||||
/** This class implements a check sphere that is used to change the ambient
|
||||
* light if a kart is inside this sphere. Besides a normal radius this
|
||||
* sphere also has a 2nd 'inner' radius: player karts inside the inner
|
||||
* radius will have the full new ambient light, karts outside the default
|
||||
* light, and karts in between will mix the light dependent on distance.
|
||||
*
|
||||
* \ingroup tracks
|
||||
*/
|
||||
class CheckCylinder : public CheckStructure
|
||||
{
|
||||
private:
|
||||
/** Center of the sphere. */
|
||||
Vec3 m_center_point;
|
||||
/** Squared radius of the cylinder. */
|
||||
float m_radius2;
|
||||
float m_height;
|
||||
/** A flag for each kart to indicate if it's inside of the sphere. */
|
||||
std::vector<bool> m_is_inside;
|
||||
/** Stores the distance of each kart from the center of this sphere.
|
||||
* This saves some computations. */
|
||||
std::vector<float> m_distance2;
|
||||
TriggerItemListener* m_listener;
|
||||
public:
|
||||
CheckCylinder(const XMLNode &node, unsigned int index,
|
||||
TriggerItemListener* listener);
|
||||
virtual ~CheckCylinder() {};
|
||||
virtual bool isTriggered(const Vec3 &old_pos, const Vec3 &new_pos,
|
||||
unsigned int kart_id);
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns if kart indx is currently inside of the sphere. */
|
||||
bool isInside(int index) const { return m_is_inside[index]; }
|
||||
// -------------------------------------------------------------------------
|
||||
/** Returns the squared distance of kart index from the enter of
|
||||
* this sphere. */
|
||||
float getDistance2ForKart(int index) const { return m_distance2[index];}
|
||||
// -------------------------------------------------------------------------
|
||||
/** Returns the square of the radius of this sphere. */
|
||||
float getRadius2() const { return m_radius2; }
|
||||
}; // CheckCylinder
|
||||
|
||||
#endif
|
||||
|
@ -55,27 +55,42 @@ void CheckLap::reset(const Track &track)
|
||||
* is called from update (of the checkline structure).
|
||||
* \param old_pos Position in previous frame.
|
||||
* \param new_pos Position in current frame.
|
||||
* \param indx Index of the kart, can be used to store kart specific
|
||||
* \param kart_index Index of the kart, can be used to store kart specific
|
||||
* additional data.
|
||||
*/
|
||||
bool CheckLap::isTriggered(const Vec3 &old_pos, const Vec3 &new_pos,
|
||||
unsigned int indx)
|
||||
unsigned int kart_index)
|
||||
{
|
||||
float track_length = World::getWorld()->getTrack()->getTrackLength();
|
||||
LinearWorld *lin_world = dynamic_cast<LinearWorld*>(World::getWorld());
|
||||
World* w = World::getWorld();
|
||||
LinearWorld* lin_world = dynamic_cast<LinearWorld*>(w);
|
||||
if (lin_world != NULL)
|
||||
{
|
||||
lin_world->getTrackSector(kart_index).setLastTriggeredCheckline(m_index);
|
||||
}
|
||||
|
||||
float track_length = w->getTrack()->getTrackLength();
|
||||
// Can happen if a non-lap based race mode is used with a scene file that
|
||||
// has check defined.
|
||||
if(!lin_world)
|
||||
return false;
|
||||
float current_distance = lin_world->getDistanceDownTrackForKart(indx);
|
||||
bool result =(m_previous_distance[indx]>0.95f*track_length &&
|
||||
float current_distance = lin_world->getDistanceDownTrackForKart(kart_index);
|
||||
bool result = (m_previous_distance[kart_index]>0.95f*track_length &&
|
||||
current_distance<7.0f);
|
||||
if(UserConfigParams::m_check_debug && result)
|
||||
|
||||
if (UserConfigParams::m_check_debug && result)
|
||||
{
|
||||
Log::info("CheckLap", "Kart %s crossed start line from %f to %f.",
|
||||
World::getWorld()->getKart(indx)->getIdent().c_str(),
|
||||
m_previous_distance[indx], current_distance);
|
||||
World::getWorld()->getKart(kart_index)->getIdent().c_str(),
|
||||
m_previous_distance[kart_index], current_distance);
|
||||
}
|
||||
|
||||
m_previous_distance[indx] = current_distance;
|
||||
m_previous_distance[kart_index] = current_distance;
|
||||
|
||||
if (result)
|
||||
{
|
||||
LinearWorld* lw = dynamic_cast<LinearWorld*>(w);
|
||||
if (lw != NULL)
|
||||
lw->setLastTriggeredCheckline(kart_index, m_index);
|
||||
}
|
||||
return result;
|
||||
} // isTriggered
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "io/xml_node.hpp"
|
||||
#include "karts/abstract_kart.hpp"
|
||||
#include "modes/linear_world.hpp"
|
||||
#include "modes/world.hpp"
|
||||
#include "race/race_manager.hpp"
|
||||
|
||||
@ -151,14 +152,15 @@ void CheckLine::changeDebugColor(bool is_active)
|
||||
* additional data.
|
||||
*/
|
||||
bool CheckLine::isTriggered(const Vec3 &old_pos, const Vec3 &new_pos,
|
||||
unsigned int indx)
|
||||
unsigned int kart_index)
|
||||
{
|
||||
World* w = World::getWorld();
|
||||
core::vector2df p=new_pos.toIrrVector2d();
|
||||
bool sign = m_line.getPointOrientation(p)>=0;
|
||||
bool result;
|
||||
// If the sign has changed, i.e. the infinite line was crossed somewhere,
|
||||
// check if the finite line was actually crossed:
|
||||
if(sign!=m_previous_sign[indx] &&
|
||||
if (sign != m_previous_sign[kart_index] &&
|
||||
m_line.intersectWith(core::line2df(old_pos.toIrrVector2d(),
|
||||
new_pos.toIrrVector2d()),
|
||||
m_cross_point) )
|
||||
@ -175,17 +177,24 @@ bool CheckLine::isTriggered(const Vec3 &old_pos, const Vec3 &new_pos,
|
||||
if(World::getWorld()->getNumKarts()>0)
|
||||
Log::info("CheckLine", "Kart %s crosses line, but wrong height "
|
||||
"(%f vs %f).",
|
||||
World::getWorld()->getKart(indx)->getIdent().c_str(),
|
||||
World::getWorld()->getKart(kart_index)->getIdent().c_str(),
|
||||
new_pos.getY(), m_min_height);
|
||||
else
|
||||
Log::info("CheckLine", "Kart %d crosses line, but wrong height "
|
||||
"(%f vs %f).",
|
||||
indx, new_pos.getY(), m_min_height);
|
||||
kart_index, new_pos.getY(), m_min_height);
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
result = false;
|
||||
m_previous_sign[indx] = sign;
|
||||
m_previous_sign[kart_index] = sign;
|
||||
|
||||
if (result)
|
||||
{
|
||||
LinearWorld* lw = dynamic_cast<LinearWorld*>(w);
|
||||
if (lw != NULL)
|
||||
lw->setLastTriggeredCheckline(kart_index, m_index);
|
||||
}
|
||||
return result;
|
||||
} // isTriggered
|
||||
|
@ -59,8 +59,7 @@ void CheckManager::load(const XMLNode &node)
|
||||
}
|
||||
else if(type=="check-sphere")
|
||||
{
|
||||
AmbientLightSphere *cs = new AmbientLightSphere(*check_node,
|
||||
i);
|
||||
CheckSphere *cs = new CheckSphere(*check_node, i);
|
||||
m_all_checks.push_back(cs);
|
||||
} // checksphere
|
||||
else
|
||||
|
@ -44,6 +44,7 @@ private:
|
||||
CheckManager() {m_all_checks.clear();};
|
||||
~CheckManager();
|
||||
public:
|
||||
void add(CheckStructure* strct) { m_all_checks.push_back(strct); }
|
||||
void load(const XMLNode &node);
|
||||
void update(float dt);
|
||||
void reset(const Track &track);
|
||||
|
@ -198,13 +198,6 @@ void CheckStructure::changeStatus(const std::vector<int> &indices,
|
||||
*/
|
||||
void CheckStructure::trigger(unsigned int kart_index)
|
||||
{
|
||||
World* w = World::getWorld();
|
||||
LinearWorld* lw = dynamic_cast<LinearWorld*>(w);
|
||||
if (lw != NULL)
|
||||
{
|
||||
lw->getTrackSector(kart_index).setLastTriggeredCheckline(m_index);
|
||||
}
|
||||
|
||||
switch(m_check_type)
|
||||
{
|
||||
case CT_NEW_LAP :
|
||||
|
@ -1200,7 +1200,7 @@ bool Track::loadMainTrack(const XMLNode &root)
|
||||
unsigned char result = -1;
|
||||
Scripting::ScriptEngine* script_engine = World::getWorld()->getScriptEngine();
|
||||
std::function<void(asIScriptContext*)> null_callback;
|
||||
script_engine->runFunction("bool " + condition + "()", null_callback,
|
||||
script_engine->runFunction(true, "bool " + condition + "()", null_callback,
|
||||
[&](asIScriptContext* ctx) { result = ctx->GetReturnByte(); });
|
||||
if (result == 0)
|
||||
continue;
|
||||
@ -1217,7 +1217,7 @@ bool Track::loadMainTrack(const XMLNode &root)
|
||||
unsigned char result = -1;
|
||||
Scripting::ScriptEngine* script_engine = World::getWorld()->getScriptEngine();
|
||||
std::function<void(asIScriptContext*)> null_callback;
|
||||
script_engine->runFunction("bool " + neg_condition + "()", null_callback,
|
||||
script_engine->runFunction(true, "bool " + neg_condition + "()", null_callback,
|
||||
[&](asIScriptContext* ctx) { result = ctx->GetReturnByte(); });
|
||||
if (result != 0)
|
||||
continue;
|
||||
@ -1488,7 +1488,7 @@ void Track::update(float dt)
|
||||
if (!m_startup_run) // first time running update = good point to run startup script
|
||||
{
|
||||
Scripting::ScriptEngine* script_engine = World::getWorld()->getScriptEngine();
|
||||
script_engine->runFunction("void onStart()");
|
||||
script_engine->runFunction(false, "void onStart()");
|
||||
m_startup_run = true;
|
||||
}
|
||||
m_track_object_manager->update(dt);
|
||||
|
@ -71,9 +71,7 @@ TrackObject::TrackObject(const core::vector3df& xyz, const core::vector3df& hpr,
|
||||
m_presentation = presentation;
|
||||
m_is_driveable = false;
|
||||
m_soccer_ball = false;
|
||||
m_garage = false;
|
||||
m_initially_visible = false;
|
||||
m_distance = 0;
|
||||
m_type = "";
|
||||
|
||||
if (m_interaction != "ghost" && m_interaction != "none" &&
|
||||
@ -127,9 +125,6 @@ void TrackObject::init(const XMLNode &xml_node, scene::ISceneNode* parent,
|
||||
m_soccer_ball = false;
|
||||
xml_node.get("soccer_ball", &m_soccer_ball);
|
||||
|
||||
m_garage = false;
|
||||
m_distance = 0;
|
||||
|
||||
std::string type;
|
||||
xml_node.get("type", &type );
|
||||
|
||||
@ -147,7 +142,7 @@ void TrackObject::init(const XMLNode &xml_node, scene::ISceneNode* parent,
|
||||
unsigned char result = -1;
|
||||
Scripting::ScriptEngine* script_engine = World::getWorld()->getScriptEngine();
|
||||
std::function<void(asIScriptContext*)> null_callback;
|
||||
script_engine->runFunction("bool " + condition + "()", null_callback,
|
||||
script_engine->runFunction(true, "bool " + condition + "()", null_callback,
|
||||
[&](asIScriptContext* ctx) { result = ctx->GetReturnByte(); });
|
||||
|
||||
if (result == 0)
|
||||
@ -179,16 +174,9 @@ void TrackObject::init(const XMLNode &xml_node, scene::ISceneNode* parent,
|
||||
}
|
||||
else if (type == "action-trigger")
|
||||
{
|
||||
std::string m_action;
|
||||
xml_node.get("action", &m_action);
|
||||
xml_node.get("distance", &m_distance);
|
||||
m_name = m_action;
|
||||
//adds action as name so that it can be found by using getName()
|
||||
if (m_action == "garage")
|
||||
{
|
||||
m_garage = true;
|
||||
}
|
||||
|
||||
std::string action;
|
||||
xml_node.get("action", &action);
|
||||
m_name = action; //adds action as name so that it can be found by using getName()
|
||||
m_presentation = new TrackObjectPresentationActionTrigger(xml_node);
|
||||
}
|
||||
else if (type == "billboard")
|
||||
|
@ -80,13 +80,9 @@ protected:
|
||||
|
||||
bool m_soccer_ball;
|
||||
|
||||
bool m_garage;
|
||||
|
||||
/** True if a kart can drive on this object. This will */
|
||||
bool m_is_driveable;
|
||||
|
||||
float m_distance;
|
||||
|
||||
PhysicalObject* m_physical_object;
|
||||
|
||||
ThreeDAnimation* m_animator;
|
||||
@ -161,10 +157,6 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
bool isSoccerBall() const { return m_soccer_ball; }
|
||||
// ------------------------------------------------------------------------
|
||||
bool isGarage() const { return m_garage; }
|
||||
// ------------------------------------------------------------------------
|
||||
float getDistance() const { return m_distance; }
|
||||
// ------------------------------------------------------------------------
|
||||
const PhysicalObject* getPhysicalObject() const { return m_physical_object; }
|
||||
// ------------------------------------------------------------------------
|
||||
PhysicalObject* getPhysicalObject() { return m_physical_object; }
|
||||
|
@ -40,6 +40,9 @@
|
||||
#include "modes/world.hpp"
|
||||
#include "scriptengine/script_engine.hpp"
|
||||
#include "states_screens/dialogs/tutorial_message_dialog.hpp"
|
||||
#include "tracks/check_cylinder.hpp"
|
||||
#include "tracks/check_manager.hpp"
|
||||
#include "tracks/check_sphere.hpp"
|
||||
#include "tracks/model_definition_loader.hpp"
|
||||
#include "tracks/track.hpp"
|
||||
#include "tracks/track_manager.hpp"
|
||||
@ -649,7 +652,7 @@ void TrackObjectPresentationSound::update(float dt)
|
||||
} // update
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void TrackObjectPresentationSound::onTriggerItemApproached(Item* who)
|
||||
void TrackObjectPresentationSound::onTriggerItemApproached()
|
||||
{
|
||||
if (m_sound != NULL && m_sound->getStatus() != SFXBase::SFX_PLAYING)
|
||||
{
|
||||
@ -935,12 +938,40 @@ TrackObjectPresentationActionTrigger::TrackObjectPresentationActionTrigger(
|
||||
xml_node.get("distance", &trigger_distance);
|
||||
xml_node.get("action", &m_action );
|
||||
|
||||
std::string trigger_type;
|
||||
xml_node.get("trigger-type", &trigger_type);
|
||||
if (trigger_type == "point")
|
||||
{
|
||||
m_type = TRIGGER_TYPE_POINT;
|
||||
}
|
||||
else if (trigger_type == "cylinder")
|
||||
{
|
||||
m_type = TRIGGER_TYPE_CYLINDER;
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
|
||||
m_action_active = true;
|
||||
|
||||
if (m_action.size() == 0)
|
||||
Log::warn("TrackObject", "Action-trigger has no action defined.");
|
||||
|
||||
ItemManager::get()->newItem(m_init_xyz, trigger_distance, this);
|
||||
if (m_type == TRIGGER_TYPE_POINT)
|
||||
{
|
||||
// TODO: rewrite as a sphere check structure?
|
||||
ItemManager::get()->newItem(m_init_xyz, trigger_distance, this);
|
||||
// CheckManager::get()->add(new CheckSphere(xml_node, 0 /* TODO what is this? */));
|
||||
}
|
||||
else if (m_type == TRIGGER_TYPE_CYLINDER)
|
||||
{
|
||||
CheckManager::get()->add(new CheckCylinder(xml_node, 0 /* TODO what is this? */, this));
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
} // TrackObjectPresentationActionTrigger
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -956,11 +987,12 @@ TrackObjectPresentationActionTrigger::TrackObjectPresentationActionTrigger(
|
||||
float trigger_distance = distance;
|
||||
m_action = script_name;
|
||||
m_action_active = true;
|
||||
m_type = TRIGGER_TYPE_POINT;
|
||||
ItemManager::get()->newItem(m_init_xyz, trigger_distance, this);
|
||||
} // TrackObjectPresentationActionTrigger
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void TrackObjectPresentationActionTrigger::onTriggerItemApproached(Item* who)
|
||||
void TrackObjectPresentationActionTrigger::onTriggerItemApproached()
|
||||
{
|
||||
if (!m_action_active) return;
|
||||
|
||||
@ -971,6 +1003,6 @@ void TrackObjectPresentationActionTrigger::onTriggerItemApproached(Item* who)
|
||||
Camera* camera = Camera::getActiveCamera();
|
||||
if (camera != NULL && camera->getKart() != NULL)
|
||||
idKart = camera->getKart()->getWorldKartId();
|
||||
script_engine->runFunction("void " + m_action + "(int)",
|
||||
script_engine->runFunction(true, "void " + m_action + "(int)",
|
||||
[=](asIScriptContext* ctx) { ctx->SetArgDWord(0, idKart); });
|
||||
} // onTriggerItemApproached
|
||||
|
@ -270,7 +270,7 @@ public:
|
||||
TrackObjectPresentationSound(const XMLNode& xml_node,
|
||||
scene::ISceneNode* parent);
|
||||
virtual ~TrackObjectPresentationSound();
|
||||
virtual void onTriggerItemApproached(Item* who) OVERRIDE;
|
||||
virtual void onTriggerItemApproached() OVERRIDE;
|
||||
virtual void update(float dt) OVERRIDE;
|
||||
virtual void move(const core::vector3df& xyz, const core::vector3df& hpr,
|
||||
const core::vector3df& scale, bool isAbsoluteCoord) OVERRIDE;
|
||||
@ -349,6 +349,13 @@ public:
|
||||
}; // TrackObjectPresentationLight
|
||||
|
||||
// ============================================================================
|
||||
|
||||
enum ActionTriggerType
|
||||
{
|
||||
TRIGGER_TYPE_POINT = 0,
|
||||
TRIGGER_TYPE_CYLINDER = 1
|
||||
};
|
||||
|
||||
/** \ingroup tracks
|
||||
* A track object representation that consists of an action trigger
|
||||
*/
|
||||
@ -361,6 +368,8 @@ private:
|
||||
|
||||
bool m_action_active;
|
||||
|
||||
ActionTriggerType m_type;
|
||||
|
||||
public:
|
||||
TrackObjectPresentationActionTrigger(const XMLNode& xml_node);
|
||||
TrackObjectPresentationActionTrigger(const core::vector3df& xyz,
|
||||
@ -369,7 +378,7 @@ public:
|
||||
|
||||
virtual ~TrackObjectPresentationActionTrigger() {}
|
||||
|
||||
virtual void onTriggerItemApproached(Item* who) OVERRIDE;
|
||||
virtual void onTriggerItemApproached() OVERRIDE;
|
||||
// ------------------------------------------------------------------------
|
||||
/** Reset the trigger (i.e. sets it to active again). */
|
||||
virtual void reset() OVERRIDE { m_action_active = true; }
|
||||
|
Loading…
x
Reference in New Issue
Block a user