mirror of
				https://github.com/VCMP-SqMod/SqMod.git
				synced 2025-11-04 08:17:19 +01:00 
			
		
		
		
	Implement a new event to receive notifications when an object alpha has changed.
This commit is contained in:
		@@ -256,6 +256,7 @@ protected:
 | 
			
		||||
        Function        mOnShot;
 | 
			
		||||
        Function        mOnTouched;
 | 
			
		||||
        Function        mOnWorld;
 | 
			
		||||
        Function        mOnAlpha;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -1008,6 +1009,7 @@ public:
 | 
			
		||||
    void EmitCheckpointWorld(Int32 checkpoint_id, Int32 old_world, Int32 new_world);
 | 
			
		||||
    void EmitCheckpointRadius(Int32 checkpoint_id, Float32 old_radius, Float32 new_radius);
 | 
			
		||||
    void EmitObjectWorld(Int32 object_id, Int32 old_world, Int32 new_world);
 | 
			
		||||
    void EmitObjectAlpha(Int32 object_id, Int32 old_alpha, Int32 new_alpha, Int32 time);
 | 
			
		||||
    void EmitPlayerHealth(Int32 player_id, Float32 old_health, Float32 new_health);
 | 
			
		||||
    void EmitPlayerArmour(Int32 player_id, Float32 old_armour, Float32 new_armour);
 | 
			
		||||
    void EmitPlayerWeapon(Int32 player_id, Int32 old_weapon, Int32 new_weapon);
 | 
			
		||||
@@ -1153,6 +1155,7 @@ private:
 | 
			
		||||
    Function    mOnObjectShot;
 | 
			
		||||
    Function    mOnObjectTouched;
 | 
			
		||||
    Function    mOnObjectWorld;
 | 
			
		||||
    Function    mOnObjectAlpha;
 | 
			
		||||
    Function    mOnPickupClaimed;
 | 
			
		||||
    Function    mOnPickupCollected;
 | 
			
		||||
    Function    mOnPickupRespawn;
 | 
			
		||||
 
 | 
			
		||||
@@ -700,6 +700,14 @@ void Core::EmitObjectWorld(Int32 object_id, Int32 old_world, Int32 new_world)
 | 
			
		||||
    Emit(mOnObjectWorld, _object.mObj, old_world, new_world);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
void Core::EmitObjectAlpha(Int32 object_id, Int32 old_alpha, Int32 new_alpha, Int32 time)
 | 
			
		||||
{
 | 
			
		||||
    ObjectInst & _object = m_Objects.at(object_id);
 | 
			
		||||
    Emit(_object.mOnAlpha, old_alpha, new_alpha, time);
 | 
			
		||||
    Emit(mOnObjectAlpha, _object.mObj, old_alpha, new_alpha, time);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
void Core::EmitPlayerHealth(Int32 player_id, Float32 old_health, Float32 new_health)
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
@@ -153,6 +153,7 @@ void Core::ResetFunc(ObjectInst & inst)
 | 
			
		||||
    inst.mOnShot.ReleaseGently();
 | 
			
		||||
    inst.mOnTouched.ReleaseGently();
 | 
			
		||||
    inst.mOnWorld.ReleaseGently();
 | 
			
		||||
    inst.mOnAlpha.ReleaseGently();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -346,6 +347,7 @@ void Core::ResetFunc()
 | 
			
		||||
    Core::Get().mOnObjectShot.ReleaseGently();
 | 
			
		||||
    Core::Get().mOnObjectTouched.ReleaseGently();
 | 
			
		||||
    Core::Get().mOnObjectWorld.ReleaseGently();
 | 
			
		||||
    Core::Get().mOnObjectAlpha.ReleaseGently();
 | 
			
		||||
    Core::Get().mOnPickupClaimed.ReleaseGently();
 | 
			
		||||
    Core::Get().mOnPickupCollected.ReleaseGently();
 | 
			
		||||
    Core::Get().mOnPickupRespawn.ReleaseGently();
 | 
			
		||||
@@ -471,6 +473,7 @@ Function & Core::GetEvent(Int32 evid)
 | 
			
		||||
        case EVT_OBJECTSHOT:            return mOnObjectShot;
 | 
			
		||||
        case EVT_OBJECTTOUCHED:         return mOnObjectTouched;
 | 
			
		||||
        case EVT_OBJECTWORLD:           return mOnObjectWorld;
 | 
			
		||||
        case EVT_OBJECTALPHA:           return mOnObjectAlpha;
 | 
			
		||||
        case EVT_PICKUPCLAIMED:         return mOnPickupClaimed;
 | 
			
		||||
        case EVT_PICKUPCOLLECTED:       return mOnPickupCollected;
 | 
			
		||||
        case EVT_PICKUPRESPAWN:         return mOnPickupRespawn;
 | 
			
		||||
@@ -574,6 +577,7 @@ Function & Core::GetObjectEvent(Int32 id, Int32 evid)
 | 
			
		||||
        case EVT_OBJECTSHOT:            return inst.mOnShot;
 | 
			
		||||
        case EVT_OBJECTTOUCHED:         return inst.mOnTouched;
 | 
			
		||||
        case EVT_OBJECTWORLD:           return inst.mOnWorld;
 | 
			
		||||
        case EVT_OBJECTALPHA:           return inst.mOnAlpha;
 | 
			
		||||
        default:                        return NullFunction();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -217,21 +217,33 @@ Int32 CObject::GetAlpha() const
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
void CObject::SetAlpha(Int32 alpha) const
 | 
			
		||||
void CObject::SetAlpha(Int32 alpha)
 | 
			
		||||
{
 | 
			
		||||
    // Validate the managed identifier
 | 
			
		||||
    Validate();
 | 
			
		||||
    // Perform the requested operation
 | 
			
		||||
    _Func->SetObjectAlpha(m_ID, alpha, 0);
 | 
			
		||||
    SetAlphaEx(alpha, 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
void CObject::SetAlphaEx(Int32 alpha, Uint32 time) const
 | 
			
		||||
void CObject::SetAlphaEx(Int32 alpha, Uint32 time)
 | 
			
		||||
{
 | 
			
		||||
    // Validate the managed identifier
 | 
			
		||||
    Validate();
 | 
			
		||||
    // Perform the requested operation
 | 
			
		||||
    // Grab the current value for this property
 | 
			
		||||
    const Int32 current = _Func->GetObjectAlpha(m_ID);
 | 
			
		||||
    // Don't even bother if it's the same value
 | 
			
		||||
    if (current == alpha)
 | 
			
		||||
    {
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
    // Avoid property unwind from a recursive call
 | 
			
		||||
    _Func->SetObjectAlpha(m_ID, alpha, time);
 | 
			
		||||
    // Avoid infinite recursive event loops
 | 
			
		||||
    if (!(m_CircularLocks & OBJECTCL_EMIT_OBJECT_ALPHA))
 | 
			
		||||
    {
 | 
			
		||||
        // Prevent this event from triggering while executed
 | 
			
		||||
        BitGuardU32 bg(m_CircularLocks, OBJECTCL_EMIT_OBJECT_ALPHA);
 | 
			
		||||
        // Now forward the event call
 | 
			
		||||
        Core::Get().EmitObjectAlpha(m_ID, current, alpha, time);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ------------------------------------------------------------------------------------------------
 | 
			
		||||
 
 | 
			
		||||
@@ -12,7 +12,8 @@ namespace SqMod {
 | 
			
		||||
*/
 | 
			
		||||
enum ObjectCircularLocks
 | 
			
		||||
{
 | 
			
		||||
    OBJECTCL_EMIT_OBJECT_WORLD  = (1 << 0)
 | 
			
		||||
    OBJECTCL_EMIT_OBJECT_WORLD  = (1 << 0),
 | 
			
		||||
    OBJECTCL_EMIT_OBJECT_ALPHA  = (2 << 0)
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/* ------------------------------------------------------------------------------------------------
 | 
			
		||||
@@ -235,12 +236,12 @@ public:
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Modify the alpha of the managed object entity.
 | 
			
		||||
    */
 | 
			
		||||
    void SetAlpha(Int32 alpha) const;
 | 
			
		||||
    void SetAlpha(Int32 alpha);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Modify the alpha of the managed object entity over the specified time.
 | 
			
		||||
    */
 | 
			
		||||
    void SetAlphaEx(Int32 alpha, Uint32 time) const;
 | 
			
		||||
    void SetAlphaEx(Int32 alpha, Uint32 time);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Move the managed object entity to the specified position over the specified time.
 | 
			
		||||
 
 | 
			
		||||
@@ -362,6 +362,7 @@ enum EventType
 | 
			
		||||
    EVT_OBJECTSHOT,
 | 
			
		||||
    EVT_OBJECTTOUCHED,
 | 
			
		||||
    EVT_OBJECTWORLD,
 | 
			
		||||
    EVT_OBJECTALPHA,
 | 
			
		||||
    EVT_PICKUPCLAIMED,
 | 
			
		||||
    EVT_PICKUPCOLLECTED,
 | 
			
		||||
    EVT_PICKUPRESPAWN,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user