This commit is contained in:
Benau 2019-10-10 15:56:18 +08:00
parent 57bd4d9a91
commit edb338da88
6 changed files with 16 additions and 22 deletions

View File

@ -28,7 +28,7 @@
#include "tracks/check_manager.hpp"
CheckCylinder::CheckCylinder(const XMLNode &node,
std::function<void()> triggering_function)
std::function<void(int)> triggering_function)
: CheckStructure(CheckManager::get()->getCheckStructureCount())
{
m_radius2 = 1;
@ -76,7 +76,7 @@ bool CheckCylinder::isTriggered(const Vec3 &old_pos, const Vec3 &new_pos,
(old_dist2< m_radius2 && new_dist2 >=m_radius2);
if (triggered && m_triggering_function)
m_triggering_function();
m_triggering_function(kart_id);
return triggered;
} // isTriggered

View File

@ -48,10 +48,10 @@ private:
* This saves some computations. */
std::vector<float> m_distance2;
/** Function to call when triggered. */
std::function<void()> m_triggering_function;
std::function<void(int)> m_triggering_function;
public:
CheckCylinder(const XMLNode &node,
std::function<void()> triggering_function);
std::function<void(int)> triggering_function);
virtual ~CheckCylinder() {};
virtual bool isTriggered(const Vec3 &old_pos, const Vec3 &new_pos,
int kart_id);

View File

@ -27,7 +27,7 @@
* \param triggering_function callback function to be used when triggered
*/
CheckTrigger::CheckTrigger(const Vec3& center, float distance,
std::function<void()> triggering_function)
std::function<void(int)> triggering_function)
: CheckStructure(CheckManager::get()->getCheckStructureCount()),
m_center(center), m_distance2(distance * distance),
m_triggering_function(triggering_function)

View File

@ -38,7 +38,7 @@ private:
const float m_distance2;
/** Function to call when triggered. */
const std::function<void()> m_triggering_function;
const std::function<void(int)> m_triggering_function;
/** Time since last trigger, if any triggering between 2 seconds ignored
* (like items). */
@ -46,7 +46,7 @@ private:
public:
CheckTrigger(const Vec3& center, float distance,
std::function<void()> triggering_function);
std::function<void(int)> triggering_function);
// ------------------------------------------------------------------------
virtual ~CheckTrigger() {}
// ------------------------------------------------------------------------
@ -55,7 +55,7 @@ public:
// ------------------------------------------------------------------------
virtual void trigger(unsigned int kart_index) OVERRIDE
{
m_triggering_function();
m_triggering_function(kart_index);
CheckStructure::trigger(kart_index);
}
}; // CheckSphere

View File

@ -687,7 +687,7 @@ TrackObjectPresentationSound::TrackObjectPresentationSound(
CheckManager::get()->add(
new CheckTrigger(m_init_xyz, trigger_distance, std::bind(
&TrackObjectPresentationSound::onTriggerItemApproached,
this)));
this, std::placeholders::_1)));
}
if (disable_for_multiplayer)
@ -735,7 +735,7 @@ void TrackObjectPresentationSound::updateGraphics(float dt)
} // update
// ----------------------------------------------------------------------------
void TrackObjectPresentationSound::onTriggerItemApproached()
void TrackObjectPresentationSound::onTriggerItemApproached(int kart_id)
{
if (m_sound != NULL && m_sound->getStatus() != SFXBase::SFX_PLAYING && m_enabled)
{
@ -1105,13 +1105,13 @@ TrackObjectPresentationActionTrigger::TrackObjectPresentationActionTrigger(
CheckManager::get()->add(
new CheckTrigger(m_init_xyz, trigger_distance, std::bind(
&TrackObjectPresentationActionTrigger::onTriggerItemApproached,
this)));
this, std::placeholders::_1)));
}
else if (m_type == TRIGGER_TYPE_CYLINDER)
{
CheckManager::get()->add(new CheckCylinder(xml_node, std::bind(
&TrackObjectPresentationActionTrigger::onTriggerItemApproached,
this)));
this, std::placeholders::_1)));
}
else
{
@ -1137,11 +1137,11 @@ TrackObjectPresentationActionTrigger::TrackObjectPresentationActionTrigger(
CheckManager::get()->add(
new CheckTrigger(m_init_xyz, trigger_distance, std::bind(
&TrackObjectPresentationActionTrigger::onTriggerItemApproached,
this)));
this, std::placeholders::_1)));
} // TrackObjectPresentationActionTrigger
// ----------------------------------------------------------------------------
void TrackObjectPresentationActionTrigger::onTriggerItemApproached()
void TrackObjectPresentationActionTrigger::onTriggerItemApproached(int kart_id)
{
if (m_reenable_timeout > StkTime::getMonoTimeMs())
{
@ -1149,12 +1149,6 @@ void TrackObjectPresentationActionTrigger::onTriggerItemApproached()
}
setReenableTimeout(m_xml_reenable_timeout);
int kart_id = 0;
Camera* camera = Camera::getActiveCamera();
if (camera != NULL && camera->getKart() != NULL)
{
kart_id = camera->getKart()->getWorldKartId();
}
if (!m_library_id.empty() && !m_triggered_object.empty() &&
!m_library_name.empty())
{

View File

@ -294,7 +294,7 @@ public:
scene::ISceneNode* parent,
bool disable_for_multiplayer);
virtual ~TrackObjectPresentationSound();
void onTriggerItemApproached();
void onTriggerItemApproached(int kart_id);
virtual void updateGraphics(float dt) OVERRIDE;
virtual void move(const core::vector3df& xyz, const core::vector3df& hpr,
const core::vector3df& scale, bool isAbsoluteCoord) OVERRIDE;
@ -408,7 +408,7 @@ public:
virtual ~TrackObjectPresentationActionTrigger() {}
void onTriggerItemApproached();
void onTriggerItemApproached(int kart_id);
// ------------------------------------------------------------------------
/** Reset the trigger (i.e. sets it to active again). */
virtual void reset() OVERRIDE