mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-06-30 22:17:13 +02:00
Do not overwrite the core state upon receiving recursive event calls from the server.
And allow the script to implement a similar approach.
This commit is contained in:
@ -1375,6 +1375,70 @@ public:
|
||||
SignalPair mOnScriptLoaded;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Structure used to preserve the core state across recursive event calls from the server.
|
||||
*/
|
||||
struct CoreState
|
||||
{
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Backup the current core state.
|
||||
*/
|
||||
CoreState()
|
||||
: m_State(Core::Get().GetState())
|
||||
{
|
||||
//...
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Backup the current core state and set the given state.
|
||||
*/
|
||||
CoreState(int s)
|
||||
: m_State(Core::Get().GetState())
|
||||
{
|
||||
Core::Get().SetState(s);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor (disabled).
|
||||
*/
|
||||
CoreState(const CoreState & o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor (disabled).
|
||||
*/
|
||||
CoreState(CoreState && o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor. Restore the grabbed core state.
|
||||
*/
|
||||
~CoreState()
|
||||
{
|
||||
Core::Get().SetState(m_State);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
CoreState & operator = (const CoreState & o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator (disabled).
|
||||
*/
|
||||
CoreState & operator = (CoreState && o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the guarded state.
|
||||
*/
|
||||
int GetValue() const
|
||||
{
|
||||
return m_State;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
int m_State; // The core state at the time when this instance was created.
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
#endif // _CORE_HPP_
|
||||
|
Reference in New Issue
Block a user