1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 08:47:17 +01: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

@ -495,6 +495,7 @@ protected:
Function mOnPosition; Function mOnPosition;
Function mOnRotation; Function mOnRotation;
Function mOnOption; Function mOnOption;
Function mOnWorld;
}; };
public: public:
@ -1015,6 +1016,7 @@ public:
void EmitVehiclePosition(Int32 vehicle_id); void EmitVehiclePosition(Int32 vehicle_id);
void EmitVehicleRotation(Int32 vehicle_id); void EmitVehicleRotation(Int32 vehicle_id);
void EmitVehicleOption(Int32 vehicle_id, Int32 option_id, bool value, Int32 header, Object & payload); void EmitVehicleOption(Int32 vehicle_id, Int32 option_id, bool value, Int32 header, Object & payload);
void EmitVehicleWorld(Int32 vehicle_id, Int32 old_world, Int32 new_world);
void EmitServerOption(Int32 option, bool value, Int32 header, Object & payload); void EmitServerOption(Int32 option, bool value, Int32 header, Object & payload);
void EmitScriptReload(Int32 header, Object & payload); void EmitScriptReload(Int32 header, Object & payload);
void EmitScriptLoaded(); void EmitScriptLoaded();
@ -1161,6 +1163,7 @@ private:
Function mOnVehiclePosition; Function mOnVehiclePosition;
Function mOnVehicleRotation; Function mOnVehicleRotation;
Function mOnVehicleOption; Function mOnVehicleOption;
Function mOnVehicleWorld;
Function mOnServerOption; Function mOnServerOption;
Function mOnScriptReload; Function mOnScriptReload;
Function mOnScriptLoaded; Function mOnScriptLoaded;

View File

@ -838,6 +838,14 @@ void Core::EmitVehicleOption(Int32 vehicle_id, Int32 option_id, bool value,
Emit(mOnVehicleOption, _vehicle.mObj, option_id, value, header, payload); Emit(mOnVehicleOption, _vehicle.mObj, option_id, value, header, payload);
} }
// ------------------------------------------------------------------------------------------------
void Core::EmitVehicleWorld(Int32 vehicle_id, Int32 old_world, Int32 new_world)
{
VehicleInst & _vehicle = m_Vehicles.at(vehicle_id);
Emit(_vehicle.mOnWorld, old_world, new_world);
Emit(mOnVehicleWorld, _vehicle.mObj, old_world, new_world);
}
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void Core::EmitServerOption(Int32 option, bool value, Int32 header, Object & payload) void Core::EmitServerOption(Int32 option, bool value, Int32 header, Object & payload)
{ {

View File

@ -254,6 +254,7 @@ void Core::ResetFunc(VehicleInst & inst)
inst.mOnPosition.ReleaseGently(); inst.mOnPosition.ReleaseGently();
inst.mOnRotation.ReleaseGently(); inst.mOnRotation.ReleaseGently();
inst.mOnOption.ReleaseGently(); inst.mOnOption.ReleaseGently();
inst.mOnWorld.ReleaseGently();
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -364,6 +365,7 @@ void Core::ResetFunc()
Core::Get().mOnVehiclePosition.ReleaseGently(); Core::Get().mOnVehiclePosition.ReleaseGently();
Core::Get().mOnVehicleRotation.ReleaseGently(); Core::Get().mOnVehicleRotation.ReleaseGently();
Core::Get().mOnVehicleOption.ReleaseGently(); Core::Get().mOnVehicleOption.ReleaseGently();
Core::Get().mOnVehicleWorld.ReleaseGently();
Core::Get().mOnServerOption.ReleaseGently(); Core::Get().mOnServerOption.ReleaseGently();
Core::Get().mOnScriptReload.ReleaseGently(); Core::Get().mOnScriptReload.ReleaseGently();
Core::Get().mOnScriptLoaded.ReleaseGently(); Core::Get().mOnScriptLoaded.ReleaseGently();
@ -479,6 +481,7 @@ Function & Core::GetEvent(Int32 evid)
case EVT_VEHICLEPOSITION: return mOnVehiclePosition; case EVT_VEHICLEPOSITION: return mOnVehiclePosition;
case EVT_VEHICLEROTATION: return mOnVehicleRotation; case EVT_VEHICLEROTATION: return mOnVehicleRotation;
case EVT_VEHICLEOPTION: return mOnVehicleOption; case EVT_VEHICLEOPTION: return mOnVehicleOption;
case EVT_VEHICLEWORLD: return mOnVehicleWorld;
case EVT_SERVEROPTION: return mOnServerOption; case EVT_SERVEROPTION: return mOnServerOption;
case EVT_SCRIPTRELOAD: return mOnScriptReload; case EVT_SCRIPTRELOAD: return mOnScriptReload;
case EVT_SCRIPTLOADED: return mOnScriptLoaded; case EVT_SCRIPTLOADED: return mOnScriptLoaded;
@ -661,6 +664,7 @@ Function & Core::GetVehicleEvent(Int32 id, Int32 evid)
case EVT_VEHICLEPOSITION: return inst.mOnPosition; case EVT_VEHICLEPOSITION: return inst.mOnPosition;
case EVT_VEHICLEROTATION: return inst.mOnRotation; case EVT_VEHICLEROTATION: return inst.mOnRotation;
case EVT_VEHICLEOPTION: return inst.mOnOption; case EVT_VEHICLEOPTION: return inst.mOnOption;
case EVT_VEHICLEWORLD: return inst.mOnWorld;
default: return NullFunction(); default: return NullFunction();
} }
} }

View File

@ -186,10 +186,10 @@ void CVehicle::SetOption(Int32 option_id, bool toggle)
{ {
STHROWF("Invalid option identifier: %d", option_id); 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 // 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 // Now forward the event call
Core::Get().EmitVehicleOption(m_ID, option_id, value, 0, NullObject()); 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); 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 // 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 // Now forward the event call
Core::Get().EmitVehicleOption(m_ID, option_id, value, header, payload); 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 the managed identifier
Validate(); 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); _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 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. * 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. * Retrieve the vehicle model of the managed vehicle entity.

View File

@ -390,6 +390,7 @@ enum EventType
EVT_VEHICLEPOSITION, EVT_VEHICLEPOSITION,
EVT_VEHICLEROTATION, EVT_VEHICLEROTATION,
EVT_VEHICLEOPTION, EVT_VEHICLEOPTION,
EVT_VEHICLEWORLD,
EVT_SERVEROPTION, EVT_SERVEROPTION,
EVT_SCRIPTRELOAD, EVT_SCRIPTRELOAD,
EVT_SCRIPTLOADED, EVT_SCRIPTLOADED,