1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-10-15 07:27:19 +02:00

Implement a new event to receive notifications when a vehicle world has changed.

This commit is contained in:
Sandu Liviu Catalin
2016-08-18 14:38:00 +03:00
parent eed7ec0358
commit ebc168e558
6 changed files with 40 additions and 8 deletions

View File

@@ -186,10 +186,10 @@ void CVehicle::SetOption(Int32 option_id, bool toggle)
{
STHROWF("Invalid option identifier: %d", option_id);
}
else if (!(m_CircularLocks & VCL_EMIT_VEHICLE_OPTION))
else if (!(m_CircularLocks & VEHICLECL_EMIT_VEHICLE_OPTION))
{
// Prevent this event from triggering while executed
BitGuardU32 bg(m_CircularLocks, VCL_EMIT_VEHICLE_OPTION);
BitGuardU32 bg(m_CircularLocks, VEHICLECL_EMIT_VEHICLE_OPTION);
// Now forward the event call
Core::Get().EmitVehicleOption(m_ID, option_id, value, 0, NullObject());
}
@@ -206,10 +206,10 @@ void CVehicle::SetOptionEx(Int32 option_id, bool toggle, Int32 header, Object &
{
STHROWF("Invalid option identifier: %d", option_id);
}
else if (!(m_CircularLocks & VCL_EMIT_VEHICLE_OPTION))
else if (!(m_CircularLocks & VEHICLECL_EMIT_VEHICLE_OPTION))
{
// Prevent this event from triggering while executed
BitGuardU32 bg(m_CircularLocks, VCL_EMIT_VEHICLE_OPTION);
BitGuardU32 bg(m_CircularLocks, VEHICLECL_EMIT_VEHICLE_OPTION);
// Now forward the event call
Core::Get().EmitVehicleOption(m_ID, option_id, value, header, payload);
}
@@ -243,12 +243,27 @@ Int32 CVehicle::GetWorld() const
}
// ------------------------------------------------------------------------------------------------
void CVehicle::SetWorld(Int32 world) const
void CVehicle::SetWorld(Int32 world)
{
// Validate the managed identifier
Validate();
// Perform the requested operation
// Grab the current value for this property
const Int32 current = _Func->GetVehicleWorld(m_ID);
// Don't even bother if it's the same value
if (current == world)
{
return;
}
// Avoid property unwind from a recursive call
_Func->SetVehicleWorld(m_ID, world);
// Avoid infinite recursive event loops
if (!(m_CircularLocks & VEHICLECL_EMIT_VEHICLE_WORLD))
{
// Prevent this event from triggering while executed
BitGuardU32 bg(m_CircularLocks, VEHICLECL_EMIT_VEHICLE_WORLD);
// Now forward the event call
Core::Get().EmitVehicleWorld(m_ID, current, world);
}
}
// ------------------------------------------------------------------------------------------------

View File

@@ -12,7 +12,8 @@ namespace SqMod {
*/
enum VehicleCircularLocks
{
VCL_EMIT_VEHICLE_OPTION = (1 << 0)
VEHICLECL_EMIT_VEHICLE_OPTION = (1 << 0),
VEHICLECL_EMIT_VEHICLE_WORLD = (2 << 0)
};
/* ------------------------------------------------------------------------------------------------
@@ -228,7 +229,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Modify the world in which the managed vehicle entity exists.
*/
void SetWorld(Int32 world) const;
void SetWorld(Int32 world);
/* --------------------------------------------------------------------------------------------
* Retrieve the vehicle model of the managed vehicle entity.