1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 00:37:15 +01:00

Initial implementation of the new event system.

Initial implementation of the new signals and slots class.
Fixed command parsing which compared a pointer to a character.
Buffer overflow fix in routines which used the limits from the entity tasks.
Switched from Sqrat::Object to Sqrat::LightObj in most places to avoid the overhead of the VM pointer.
Various other adjustments and improvements.
The plugin is currently in a broken state and crashes at shutdown. The bug is unknown at this point.
This commit is contained in:
Sandu Liviu Catalin 2017-02-21 21:24:59 +02:00
parent 178b30bb20
commit 41e04e5167
39 changed files with 4859 additions and 3992 deletions

View File

@ -469,6 +469,7 @@
<Unit filename="../source/CoreEntity.cpp" />
<Unit filename="../source/CoreEvents.cpp" />
<Unit filename="../source/CoreFuncs.cpp" />
<Unit filename="../source/CoreInst.cpp" />
<Unit filename="../source/CoreUtils.cpp" />
<Unit filename="../source/Entity/Blip.cpp" />
<Unit filename="../source/Entity/Blip.hpp" />
@ -540,8 +541,6 @@
<Unit filename="../source/Misc/Player.cpp" />
<Unit filename="../source/Misc/Player.hpp" />
<Unit filename="../source/Misc/Register.cpp" />
<Unit filename="../source/Misc/Signal.cpp" />
<Unit filename="../source/Misc/Signal.hpp" />
<Unit filename="../source/Misc/Vehicle.cpp" />
<Unit filename="../source/Misc/Vehicle.hpp" />
<Unit filename="../source/Misc/Weapon.cpp" />
@ -549,6 +548,8 @@
<Unit filename="../source/Register.cpp" />
<Unit filename="../source/Routine.cpp" />
<Unit filename="../source/Routine.hpp" />
<Unit filename="../source/Signal.cpp" />
<Unit filename="../source/Signal.hpp" />
<Unit filename="../source/SqBase.hpp" />
<Unit filename="../source/Tasks.cpp" />
<Unit filename="../source/Tasks.hpp" />

View File

@ -108,6 +108,11 @@ bool SToB(CSStr str);
*/
Object & NullObject();
/* ------------------------------------------------------------------------------------------------
* Retrieve a reference to a null script object.
*/
LightObj & NullLightObj();
/* ------------------------------------------------------------------------------------------------
* Retrieve a reference to a null/empty script table.
*/
@ -1303,83 +1308,6 @@ typedef BitGuard< Uint8 > BitGuardU8;
typedef BitGuard< Uint16 > BitGuardU16;
typedef BitGuard< Uint32 > BitGuardU32;
/* ------------------------------------------------------------------------------------------------
* RAII approach to make sure an instance is deleted regardless of what exceptions are thrown.
*/
template < typename T > struct DeleteGuard
{
private:
// --------------------------------------------------------------------------------------------
T * m_Ptr; // Pointer to the instance to manage.
public:
/* --------------------------------------------------------------------------------------------
* Default constructor.
*/
DeleteGuard(T * ptr)
: m_Ptr(ptr)
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled)
*/
DeleteGuard(const DeleteGuard & o) = delete;
/* --------------------------------------------------------------------------------------------
* Move constructor. (disabled)
*/
DeleteGuard(DeleteGuard && o) = delete;
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~DeleteGuard()
{
if (m_Ptr)
{
delete m_Ptr;
}
}
/* --------------------------------------------------------------------------------------------
* Copy assignment operator. (disabled)
*/
DeleteGuard & operator = (const DeleteGuard & o) = delete;
/* --------------------------------------------------------------------------------------------
* Move assignment operator. (disabled)
*/
DeleteGuard & operator = (DeleteGuard && o) = delete;
/* --------------------------------------------------------------------------------------------
* Implicit conversion the managed instance type.
*/
operator T * () const
{
return m_Ptr;
}
/* --------------------------------------------------------------------------------------------
* Retrieve the managed instance.
*/
T * Get() const
{
return m_Ptr;
}
/* --------------------------------------------------------------------------------------------
* Release the managed instance.
*/
void Release()
{
m_Ptr = nullptr;
}
};
/* ------------------------------------------------------------------------------------------------
* RAII approach to make sure a value is assigned regardless of what exceptions are thrown.
*/

View File

@ -235,6 +235,14 @@ Object & NullObject()
return o;
}
// ------------------------------------------------------------------------------------------------
LightObj & NullLightObj()
{
static LightObj o;
o.Release();
return o;
}
// ------------------------------------------------------------------------------------------------
Table & NullTable()
{

View File

@ -111,7 +111,7 @@ struct PlayerName
};
// ------------------------------------------------------------------------------------------------
static const Object & Blip_FindBySprID(Int32 sprid)
static const LightObj & Blip_FindBySprID(Int32 sprid)
{
// Perform a range check on the specified identifier
if (sprid < 0)
@ -131,7 +131,7 @@ static const Object & Blip_FindBySprID(Int32 sprid)
}
}
// Unable to locate a blip matching the specified identifier
return NullObject();
return NullLightObj();
}
/* ------------------------------------------------------------------------------------------------
@ -227,7 +227,7 @@ static inline Array Player_AllWhereNameMatches(bool neg, bool cs, CSStr name)
/* ------------------------------------------------------------------------------------------------
* Retrieve the first player where the name matches or not the specified one.
*/
static inline Object Player_FirstWhereNameEquals(bool neg, bool cs, CSStr name)
static inline LightObj Player_FirstWhereNameEquals(bool neg, bool cs, CSStr name)
{
SQMOD_VALID_NAME_STR(name)
// Create a new element receiver
@ -243,7 +243,7 @@ static inline Object Player_FirstWhereNameEquals(bool neg, bool cs, CSStr name)
/* ------------------------------------------------------------------------------------------------
* Retrieve the first player where the name begins or not with the specified string.
*/
static inline Object Player_FirstWhereNameBegins(bool neg, bool cs, CSStr name)
static inline LightObj Player_FirstWhereNameBegins(bool neg, bool cs, CSStr name)
{
SQMOD_VALID_NAME_STR(name)
// Create a new element receiver
@ -259,7 +259,7 @@ static inline Object Player_FirstWhereNameBegins(bool neg, bool cs, CSStr name)
/* ------------------------------------------------------------------------------------------------
* Retrieve the first player where the name ends or not with the specified string.
*/
static inline Object Player_FirstWhereNameEnds(bool neg, bool cs, CSStr name)
static inline LightObj Player_FirstWhereNameEnds(bool neg, bool cs, CSStr name)
{
SQMOD_VALID_NAME_STR(name)
// Create a new element receiver
@ -275,7 +275,7 @@ static inline Object Player_FirstWhereNameEnds(bool neg, bool cs, CSStr name)
/* ------------------------------------------------------------------------------------------------
* Retrieve the first player where the name contains or not the specified string.
*/
static inline Object Player_FirstWhereNameContains(bool neg, bool cs, CSStr name)
static inline LightObj Player_FirstWhereNameContains(bool neg, bool cs, CSStr name)
{
SQMOD_VALID_NAME_STR(name)
// Create a new element receiver
@ -291,7 +291,7 @@ static inline Object Player_FirstWhereNameContains(bool neg, bool cs, CSStr name
/* ------------------------------------------------------------------------------------------------
* Retrieve the first player where the name matches or not the specified filter.
*/
static inline Object Player_FirstWhereNameMatches(bool neg, bool cs, CSStr name)
static inline LightObj Player_FirstWhereNameMatches(bool neg, bool cs, CSStr name)
{
SQMOD_VALID_NAME_STR(name)
// Create a new element receiver
@ -307,7 +307,7 @@ static inline Object Player_FirstWhereNameMatches(bool neg, bool cs, CSStr name)
/* --------------------------------------------------------------------------------------------
* Process all entities of this type where the name matches or not the specified one.
*/
static inline Uint32 Player_EachWhereNameEquals(bool neg, bool cs, CSStr name, Object & env, Function & func)
static inline Uint32 Player_EachWhereNameEquals(bool neg, bool cs, CSStr name, LightObj & env, Function & func)
{
SQMOD_VALID_NAME_STR(name)
// Create a new element forwarder
@ -323,7 +323,7 @@ static inline Uint32 Player_EachWhereNameEquals(bool neg, bool cs, CSStr name, O
/* --------------------------------------------------------------------------------------------
* Process all entities of this type where the name matches or not the specified one.
*/
static inline Uint32 Player_EachWhereNameEqualsData(bool neg, bool cs, CSStr name, Object & data, Object & env, Function & func)
static inline Uint32 Player_EachWhereNameEqualsData(bool neg, bool cs, CSStr name, LightObj & data, LightObj & env, Function & func)
{
SQMOD_VALID_NAME_STR(name)
// Create a new element forwarder
@ -339,7 +339,7 @@ static inline Uint32 Player_EachWhereNameEqualsData(bool neg, bool cs, CSStr nam
/* --------------------------------------------------------------------------------------------
* Process all entities of this type where the name begins with the specified string.
*/
static inline Uint32 Player_EachWhereNameBegins(bool neg, bool cs, CSStr name, Object & env, Function & func)
static inline Uint32 Player_EachWhereNameBegins(bool neg, bool cs, CSStr name, LightObj & env, Function & func)
{
SQMOD_VALID_NAME_STR(name)
// Create a new element forwarder
@ -355,7 +355,7 @@ static inline Uint32 Player_EachWhereNameBegins(bool neg, bool cs, CSStr name, O
/* --------------------------------------------------------------------------------------------
* Process all entities of this type where the name begins with the specified string.
*/
static inline Uint32 Player_EachWhereNameBeginsData(bool neg, bool cs, CSStr name, Object & data, Object & env, Function & func)
static inline Uint32 Player_EachWhereNameBeginsData(bool neg, bool cs, CSStr name, LightObj & data, LightObj & env, Function & func)
{
SQMOD_VALID_NAME_STR(name)
// Create a new element forwarder
@ -371,7 +371,7 @@ static inline Uint32 Player_EachWhereNameBeginsData(bool neg, bool cs, CSStr nam
/* --------------------------------------------------------------------------------------------
* Process all entities of this type where the name ends or not with the specified string.
*/
static inline Uint32 Player_EachWhereNameEnds(bool neg, bool cs, CSStr name, Object & env, Function & func)
static inline Uint32 Player_EachWhereNameEnds(bool neg, bool cs, CSStr name, LightObj & env, Function & func)
{
SQMOD_VALID_NAME_STR(name)
// Create a new element forwarder
@ -387,7 +387,7 @@ static inline Uint32 Player_EachWhereNameEnds(bool neg, bool cs, CSStr name, Obj
/* --------------------------------------------------------------------------------------------
* Process all entities of this type where the name ends or not with the specified string.
*/
static inline Uint32 Player_EachWhereNameEndsData(bool neg, bool cs, CSStr name, Object & data, Object & env, Function & func)
static inline Uint32 Player_EachWhereNameEndsData(bool neg, bool cs, CSStr name, LightObj & data, LightObj & env, Function & func)
{
SQMOD_VALID_NAME_STR(name)
// Create a new element forwarder
@ -403,7 +403,7 @@ static inline Uint32 Player_EachWhereNameEndsData(bool neg, bool cs, CSStr name,
/* --------------------------------------------------------------------------------------------
* Process all entities of this type where the name contains the specified string.
*/
static inline Uint32 Player_EachWhereNameContains(bool neg, bool cs, CSStr name, Object & env, Function & func)
static inline Uint32 Player_EachWhereNameContains(bool neg, bool cs, CSStr name, LightObj & env, Function & func)
{
SQMOD_VALID_NAME_STR(name)
// Create a new element forwarder
@ -419,7 +419,7 @@ static inline Uint32 Player_EachWhereNameContains(bool neg, bool cs, CSStr name,
/* --------------------------------------------------------------------------------------------
* Process all entities of this type where the name contains the specified string.
*/
static inline Uint32 Player_EachWhereNameContainsData(bool neg, bool cs, CSStr name, Object & data, Object & env, Function & func)
static inline Uint32 Player_EachWhereNameContainsData(bool neg, bool cs, CSStr name, LightObj & data, LightObj & env, Function & func)
{
SQMOD_VALID_NAME_STR(name)
// Create a new element forwarder
@ -435,7 +435,7 @@ static inline Uint32 Player_EachWhereNameContainsData(bool neg, bool cs, CSStr n
/* --------------------------------------------------------------------------------------------
* Process all entities of this type where the name matches the specified filter.
*/
static inline Uint32 Player_EachWhereNameMatches(bool neg, bool cs, CSStr name, Object & env, Function & func)
static inline Uint32 Player_EachWhereNameMatches(bool neg, bool cs, CSStr name, LightObj & env, Function & func)
{
SQMOD_VALID_NAME_STR(name)
// Create a new element forwarder
@ -451,7 +451,7 @@ static inline Uint32 Player_EachWhereNameMatches(bool neg, bool cs, CSStr name,
/* --------------------------------------------------------------------------------------------
* Process all entities of this type where the name matches the specified filter.
*/
static inline Uint32 Player_EachWhereNameMatchesData(bool neg, bool cs, CSStr name, Object & data, Object & env, Function & func)
static inline Uint32 Player_EachWhereNameMatchesData(bool neg, bool cs, CSStr name, LightObj & data, LightObj & env, Function & func)
{
SQMOD_VALID_NAME_STR(name)
// Create a new element forwarder

View File

@ -457,7 +457,7 @@ template <> struct InstSpec< CBlip >
/* --------------------------------------------------------------------------------------------
* Reference to the NULL instance.
*/
static inline Object & Null()
static inline LightObj & Null()
{
return Core::Get().GetNullBlip();
}
@ -498,7 +498,7 @@ template <> struct InstSpec< CCheckpoint >
/* --------------------------------------------------------------------------------------------
* Reference to the NULL instance.
*/
static inline Object & Null()
static inline LightObj & Null()
{
return Core::Get().GetNullCheckpoint();
}
@ -539,7 +539,7 @@ template <> struct InstSpec< CKeybind >
/* --------------------------------------------------------------------------------------------
* Reference to the NULL instance.
*/
static inline Object & Null()
static inline LightObj & Null()
{
return Core::Get().GetNullKeybind();
}
@ -580,7 +580,7 @@ template <> struct InstSpec< CObject >
/* --------------------------------------------------------------------------------------------
* Reference to the NULL instance.
*/
static inline Object & Null()
static inline LightObj & Null()
{
return Core::Get().GetNullObject();
}
@ -621,7 +621,7 @@ template <> struct InstSpec< CPickup >
/* --------------------------------------------------------------------------------------------
* Reference to the NULL instance.
*/
static inline Object & Null()
static inline LightObj & Null()
{
return Core::Get().GetNullPickup();
}
@ -662,7 +662,7 @@ template <> struct InstSpec< CPlayer >
/* --------------------------------------------------------------------------------------------
* Reference to the NULL instance.
*/
static inline Object & Null()
static inline LightObj & Null()
{
return Core::Get().GetNullPlayer();
}
@ -703,7 +703,7 @@ template <> struct InstSpec< CVehicle >
/* --------------------------------------------------------------------------------------------
* Reference to the NULL instance.
*/
static inline Object & Null()
static inline LightObj & Null()
{
return Core::Get().GetNullVehicle();
}
@ -776,7 +776,7 @@ template < typename T > struct AppendElemFunc
template < typename T > struct RecvElemFunc
{
// --------------------------------------------------------------------------------------------
Object mObj; // Reference to the received object.
LightObj mObj; // Reference to the received object.
/* --------------------------------------------------------------------------------------------
* Default constructor.
@ -798,7 +798,7 @@ template < typename T > struct RecvElemFunc
/* --------------------------------------------------------------------------------------------
* Implicit cast to the managed object.
*/
operator Object ()
operator LightObj ()
{
return mObj;
}
@ -806,7 +806,7 @@ template < typename T > struct RecvElemFunc
/* --------------------------------------------------------------------------------------------
* Implicit cast to the managed object.
*/
operator Object & ()
operator LightObj & ()
{
return mObj;
}
@ -814,7 +814,7 @@ template < typename T > struct RecvElemFunc
/* --------------------------------------------------------------------------------------------
* Implicit cast to the managed object.
*/
operator const Object & () const
operator const LightObj & () const
{
return mObj;
}
@ -834,7 +834,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Base constructor.
*/
ForwardElemFunc(Object & env, Function & func)
ForwardElemFunc(LightObj & env, Function & func)
: mFunc(env.IsNull() ? func : Function(env.GetVM(), env, func.GetFunc())), mCount(0)
{
if (mFunc.IsNull())
@ -894,13 +894,13 @@ public:
// --------------------------------------------------------------------------------------------
Function mFunc; // The script callback to forward the element.
Object mData; // The script payload to accompany the element.
LightObj mData; // The script payload to accompany the element.
Uint32 mCount; // The number of elements forwarded by this functor.
/* --------------------------------------------------------------------------------------------
* Base constructor.
*/
ForwardElemDataFunc(Object & data, Object & env, Function & func)
ForwardElemDataFunc(LightObj & data, LightObj & env, Function & func)
: mFunc(env.IsNull() ? func : Function(env.GetVM(), env, func.GetFunc())), mData(data), mCount(0)
{
if (mFunc.IsNull())
@ -945,7 +945,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Implicit cast to the managed payload.
*/
operator Object ()
operator LightObj ()
{
return mData;
}
@ -953,7 +953,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Implicit cast to the managed payload.
*/
operator Object & ()
operator LightObj & ()
{
return mData;
}
@ -961,7 +961,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Implicit cast to the managed payload.
*/
operator const Object & () const
operator const LightObj & () const
{
return mData;
}
@ -1066,7 +1066,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Find the entity that matches the specified identifier.
*/
static inline const Object & FindByID(Int32 id)
static inline const LightObj & FindByID(Int32 id)
{
// Perform a range check on the specified identifier
if (INVALID_ENTITYEX(id, Inst::Max))
@ -1186,7 +1186,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the first entity of this type where the tag matches or not the specified one.
*/
static inline Object FirstWhereTagEquals(bool neg, bool cs, CSStr tag)
static inline LightObj FirstWhereTagEquals(bool neg, bool cs, CSStr tag)
{
SQMOD_VALID_TAG_STR(tag)
// Create a new element receiver
@ -1201,7 +1201,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the first entity of this type where the tag begins or not with the specified string.
*/
static inline Object FirstWhereTagBegins(bool neg, bool cs, CSStr tag)
static inline LightObj FirstWhereTagBegins(bool neg, bool cs, CSStr tag)
{
SQMOD_VALID_TAG_STR(tag)
// Create a new element receiver
@ -1216,7 +1216,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the first entity of this type where the tag ends or not with the specified string.
*/
static inline Object FirstWhereTagEnds(bool neg, bool cs, CSStr tag)
static inline LightObj FirstWhereTagEnds(bool neg, bool cs, CSStr tag)
{
SQMOD_VALID_TAG_STR(tag)
// Create a new element receiver
@ -1231,7 +1231,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the first entity of this type where the tag contains or not the specified string.
*/
static inline Object FirstWhereTagContains(bool neg, bool cs, CSStr tag)
static inline LightObj FirstWhereTagContains(bool neg, bool cs, CSStr tag)
{
SQMOD_VALID_TAG_STR(tag)
// Create a new element receiver
@ -1246,7 +1246,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the first entity of this type where the tag matches or not the specified filter.
*/
static inline Object FirstWhereTagMatches(bool neg, bool cs, CSStr tag)
static inline LightObj FirstWhereTagMatches(bool neg, bool cs, CSStr tag)
{
SQMOD_VALID_TAG_STR(tag)
// Create a new element receiver
@ -1261,7 +1261,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Process all active entities of this type.
*/
static inline Uint32 EachActive(Object & env, Function & func)
static inline Uint32 EachActive(LightObj & env, Function & func)
{
// Create a new element forwarder
ForwardElem fwd(env, func);
@ -1275,7 +1275,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Process all active entities of this type.
*/
static inline Uint32 EachActiveData(Object & data, Object & env, Function & func)
static inline Uint32 EachActiveData(LightObj & data, LightObj & env, Function & func)
{
// Create a new element forwarder
ForwardElemData fwd(data, env, func);
@ -1289,7 +1289,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Process all entities of this type where the tag matches or not the specified one.
*/
static inline Uint32 EachWhereTagEquals(bool neg, bool cs, CSStr tag, Object & env, Function & func)
static inline Uint32 EachWhereTagEquals(bool neg, bool cs, CSStr tag, LightObj & env, Function & func)
{
SQMOD_VALID_TAG_STR(tag)
// Create a new element forwarder
@ -1304,7 +1304,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Process all entities of this type where the tag matches or not the specified one.
*/
static inline Uint32 EachWhereTagEqualsData(bool neg, bool cs, CSStr tag, Object & data, Object & env, Function & func)
static inline Uint32 EachWhereTagEqualsData(bool neg, bool cs, CSStr tag, LightObj & data, LightObj & env, Function & func)
{
SQMOD_VALID_TAG_STR(tag)
// Create a new element forwarder
@ -1319,7 +1319,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Process all entities of this type where the tag begins with the specified string.
*/
static inline Uint32 EachWhereTagBegins(bool neg, bool cs, CSStr tag, Object & env, Function & func)
static inline Uint32 EachWhereTagBegins(bool neg, bool cs, CSStr tag, LightObj & env, Function & func)
{
SQMOD_VALID_TAG_STR(tag)
// Create a new element forwarder
@ -1334,7 +1334,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Process all entities of this type where the tag begins with the specified string.
*/
static inline Uint32 EachWhereTagBeginsData(bool neg, bool cs, CSStr tag, Object & data, Object & env, Function & func)
static inline Uint32 EachWhereTagBeginsData(bool neg, bool cs, CSStr tag, LightObj & data, LightObj & env, Function & func)
{
SQMOD_VALID_TAG_STR(tag)
// Create a new element forwarder
@ -1349,7 +1349,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Process all entities of this type where the tag ends or not with the specified string.
*/
static inline Uint32 EachWhereTagEnds(bool neg, bool cs, CSStr tag, Object & env, Function & func)
static inline Uint32 EachWhereTagEnds(bool neg, bool cs, CSStr tag, LightObj & env, Function & func)
{
SQMOD_VALID_TAG_STR(tag)
// Create a new element forwarder
@ -1364,7 +1364,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Process all entities of this type where the tag ends or not with the specified string.
*/
static inline Uint32 EachWhereTagEndsData(bool neg, bool cs, CSStr tag, Object & data, Object & env, Function & func)
static inline Uint32 EachWhereTagEndsData(bool neg, bool cs, CSStr tag, LightObj & data, LightObj & env, Function & func)
{
SQMOD_VALID_TAG_STR(tag)
// Create a new element forwarder
@ -1379,7 +1379,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Process all entities of this type where the tag contains the specified string.
*/
static inline Uint32 EachWhereTagContains(bool neg, bool cs, CSStr tag, Object & env, Function & func)
static inline Uint32 EachWhereTagContains(bool neg, bool cs, CSStr tag, LightObj & env, Function & func)
{
SQMOD_VALID_TAG_STR(tag)
// Create a new element forwarder
@ -1394,7 +1394,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Process all entities of this type where the tag contains the specified string.
*/
static inline Uint32 EachWhereTagContainsData(bool neg, bool cs, CSStr tag, Object & data, Object & env, Function & func)
static inline Uint32 EachWhereTagContainsData(bool neg, bool cs, CSStr tag, LightObj & data, LightObj & env, Function & func)
{
SQMOD_VALID_TAG_STR(tag)
// Create a new element forwarder
@ -1409,7 +1409,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Process all entities of this type where the tag match the specified filter.
*/
static inline Uint32 EachWhereTagMatches(bool neg, bool cs, CSStr tag, Object & env, Function & func)
static inline Uint32 EachWhereTagMatches(bool neg, bool cs, CSStr tag, LightObj & env, Function & func)
{
SQMOD_VALID_TAG_STR(tag)
// Create a new element forwarder
@ -1424,7 +1424,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Process all entities of this type where the tag match the specified filter.
*/
static inline Uint32 EachWhereTagMatchesData(bool neg, bool cs, CSStr tag, Object & data, Object & env, Function & func)
static inline Uint32 EachWhereTagMatchesData(bool neg, bool cs, CSStr tag, LightObj & data, LightObj & env, Function & func)
{
SQMOD_VALID_TAG_STR(tag)
// Create a new element forwarder

View File

@ -38,6 +38,11 @@ enum Intersection
SQMODI_INSIDE,
};
/* ------------------------------------------------------------------------------------------------
* Helper used to reference and keep track of signal instances.
*/
typedef std::pair< Signal *, LightObj > SignalPair;
/* ------------------------------------------------------------------------------------------------
* Forward declarations of the logging functions to avoid including the logger everywhere.
* Primary logging functions.
@ -193,6 +198,16 @@ const ULongInt & GetULongInt();
const ULongInt & GetULongInt(Uint64 n);
const ULongInt & GetULongInt(CSStr s);
/* ------------------------------------------------------------------------------------------------
* Initialize a signal instance into the specified pair.
*/
extern void InitSignalPair(SignalPair & sp, LightObj & et, const char * name);
/* ------------------------------------------------------------------------------------------------
* Reset/release the specified signal pair.
*/
extern void ResetSignalPair(SignalPair & sp, bool clear = true);
/* ------------------------------------------------------------------------------------------------
* A simple implementation of name filtering.
*/

View File

@ -212,7 +212,7 @@ Int32 Controller::Run(const Guard & guard, CCStr command)
++split;
}
// Are there any arguments specified?
if (split != '\0')
if (*split != '\0')
{
// Save the command name
ctx.mCommand.assign(command, (split - command));
@ -665,13 +665,13 @@ bool Controller::Parse(Context & ctx)
{
// Let's us know if the whole argument was part of the resulted value
CStr next = nullptr;
// Attempt to extract the integer value from the string
// Attempt to extract the float value from the string
#ifdef SQUSEDOUBLE
const Float64 value = std::strtod(str, &next);
#else
const Float32 value = std::strtof(str, &next);
#endif // SQUSEDOUBLE
// See if this whole string was indeed an integer
// See if this whole string was indeed an float
if (next == end)
{
// Remember the current stack size

View File

@ -1,6 +1,7 @@
// ------------------------------------------------------------------------------------------------
#include "Core.hpp"
#include "Logger.hpp"
#include "Signal.hpp"
#include "SqMod.h"
// ------------------------------------------------------------------------------------------------
@ -30,15 +31,6 @@
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// --------------------------------------------------------------------------------------------
#define SQMOD_CATCH_EVENT_EXCEPTION(action) /*
*/ catch (const Sqrat::Exception & e) /*
*/ { /*
*/ LogErr("Squirrel exception caught " action); /*
*/ Logger::Get().Debug("%s", e.what()); /*
*/ } /*
*/
// ------------------------------------------------------------------------------------------------
extern bool RegisterAPI(HSQUIRRELVM vm);
@ -50,9 +42,6 @@ extern void TerminateRoutines();
extern void TerminateCommands();
extern void TerminateSignals();
// ------------------------------------------------------------------------------------------------
extern void CleanupTasks(Int32 id, Int32 type);
// ------------------------------------------------------------------------------------------------
extern Buffer GetRealFilePath(CSStr path);
@ -121,7 +110,7 @@ public:
{
for (auto & ent : container)
{
ent.Destroy(destroy, SQMOD_DESTROY_CLEANUP, NullObject());
ent.Destroy(destroy, SQMOD_DESTROY_CLEANUP, NullLightObj());
}
}
@ -151,6 +140,7 @@ Core::Core()
, m_Pickups()
, m_Players()
, m_Vehicles()
, m_Events()
, m_CircularLocks(0)
, m_ReloadHeader(0)
, m_ReloadPayload()
@ -278,6 +268,7 @@ bool Core::Initialize()
NullArray() = Array();
NullTable() = Table();
NullObject() = Object();
NullLightObj() = LightObj();
NullFunction() = Function();
cLogDbg(m_Verbosity >= 1, "Registering the standard libraries");
@ -311,6 +302,14 @@ bool Core::Initialize()
return false; // Can't execute scripts without a valid API!
}
// Initialize the module global events
InitEvents();
// Initialize load stage signals
InitSignalPair(mOnPreLoad, NullLightObj(), nullptr);
InitSignalPair(mOnPostLoad, NullLightObj(), nullptr);
InitSignalPair(mOnUnload, NullLightObj(), nullptr);
CSimpleIniA::TNamesDepend scripts;
// Attempt to retrieve the list of keys to make sure there's actually something to process
if (conf.GetAllKeys("Scripts", scripts) && scripts.size() > 0)
@ -412,34 +411,28 @@ bool Core::Execute()
}
// Create the null entity instances
m_NullBlip = Object(new CBlip(-1));
m_NullCheckpoint = Object(new CCheckpoint(-1));
m_NullKeybind = Object(new CKeybind(-1));
m_NullObject = Object(new CObject(-1));
m_NullPickup = Object(new CPickup(-1));
m_NullPlayer = Object(new CPlayer(-1));
m_NullVehicle = Object(new CVehicle(-1));
m_NullBlip = LightObj(new CBlip(-1));
m_NullCheckpoint = LightObj(new CCheckpoint(-1));
m_NullKeybind = LightObj(new CKeybind(-1));
m_NullObject = LightObj(new CObject(-1));
m_NullPickup = LightObj(new CPickup(-1));
m_NullPlayer = LightObj(new CPlayer(-1));
m_NullVehicle = LightObj(new CVehicle(-1));
m_LockPreLoadSignal = true;
// Trigger functions that must initialize stuff before the loaded event is triggered
for (FuncData & fn : m_PreLoadSignal)
{
Emit(fn.first, fn.second);
}
// Clear the functions
m_PreLoadSignal.clear();
// Trigger callbacks that must initialize stuff before the loaded event is triggered
(*mOnPreLoad.first)();
// Clear the callbacks
ResetSignalPair(mOnPreLoad);
// Notify the script callback that the scripts were loaded
EmitScriptLoaded();
m_LockPostLoadSignal = true;
// Trigger functions that must initialize stuff after the loaded event is triggered
for (FuncData & fn : m_PostLoadSignal)
{
Emit(fn.first, fn.second);
}
// Clear the functions
m_PostLoadSignal.clear();
// Trigger callbacks that must initialize stuff after the loaded event is triggered
(*mOnPostLoad.first)();
// Clear the callbacks
ResetSignalPair(mOnPostLoad);
// Import already existing entities
ImportPlayers();
@ -449,7 +442,6 @@ bool Core::Execute()
ImportObjects();
ImportPickups();
ImportVehicles();
// Successfully executed
return (m_Executed = true);
}
@ -462,13 +454,10 @@ void Core::Terminate(bool shutdown)
if (m_VM)
{
m_LockUnloadSignal = true;
// Trigger functions that must de-initialize stuff before the scripts are unloaded
for (FuncData & fn : m_UnloadSignal)
{
Emit(fn.first, fn.second, shutdown);
}
// Clear the functions
m_UnloadSignal.clear();
// Trigger callbacks that must de-initialize stuff before the scripts are unloaded
(*mOnUnload.first)();
// Clear the callbacks
ResetSignalPair(mOnUnload);
cLogDbg(m_Verbosity >= 1, "Signaling outside plug-ins to release their resources");
// Tell modules to do their monkey business
@ -497,6 +486,7 @@ void Core::Terminate(bool shutdown)
NullArray().Release();
NullTable().Release();
NullObject().Release();
NullLightObj().Release();
NullFunction().ReleaseGently();
// Release null entity instances
m_NullBlip.Release();
@ -506,16 +496,12 @@ void Core::Terminate(bool shutdown)
m_NullPickup.Release();
m_NullPlayer.Release();
m_NullVehicle.Release();
// Clear any functions added during shutdown
m_PreLoadSignal.clear();
m_PostLoadSignal.clear();
m_UnloadSignal.clear();
// Is there a VM to close?
if (m_VM)
{
cLogDbg(m_Verbosity >= 1, "Releasing any final resources and all loaded scripts");
// Release all script callbacks
ResetFunc();
DropEvents();
// Release the script instances
m_Scripts.clear();
m_PendingScripts.clear(); // Just in case
@ -847,376 +833,4 @@ void Core::CompilerErrorHandler(HSQUIRRELVM /*vm*/, CSStr desc, CSStr src, SQInt
LogFtl("Message: %s\n[\n=>Location: %s\n=>Line: %d\n=>Column: %d\n]", desc, src, line, column);
}
// ------------------------------------------------------------------------------------------------
void Core::BindPreLoad(Object & env, Function & func, Object & payload)
{
if (m_LockPreLoadSignal)
{
STHROWF("Cannot bind functions to pre-load signal anymore");
}
else if (func.IsNull())
{
STHROWF("Cannot bind null as callback to pre-load signal");
}
// Does this function need a custom environment?
else if (env.IsNull())
{
m_PreLoadSignal.emplace_back(func, payload);
}
// Assign the specified environment and function
else
{
m_PreLoadSignal.emplace_back(Function(env.GetVM(), env, func.GetFunc()), payload);
}
}
// ------------------------------------------------------------------------------------------------
void Core::BindPostLoad(Object & env, Function & func, Object & payload)
{
if (m_LockPostLoadSignal)
{
STHROWF("Cannot bind functions to post-load signal anymore");
}
else if (func.IsNull())
{
STHROWF("Cannot bind null as callback to post-load signal");
}
// Does this function need a custom environment?
else if (env.IsNull())
{
m_PostLoadSignal.emplace_back(func, payload);
}
// Assign the specified environment and function
else
{
m_PostLoadSignal.emplace_back(Function(env.GetVM(), env, func.GetFunc()), payload);
}
}
// ------------------------------------------------------------------------------------------------
void Core::BindUnload(Object & env, Function & func, Object & payload)
{
if (m_LockUnloadSignal)
{
STHROWF("Cannot bind functions to unload signal anymore");
}
else if (func.IsNull())
{
STHROWF("Cannot bind null as callback to unload signal");
}
// Does this function need a custom environment?
else if (env.IsNull())
{
m_UnloadSignal.emplace_back(func, payload);
}
// Assign the specified environment and function
else
{
m_UnloadSignal.emplace_back(Function(env.GetVM(), env, func.GetFunc()), payload);
}
}
// ------------------------------------------------------------------------------------------------
void Core::BindEvent(Int32 id, Object & env, Function & func)
{
// Obtain the function instance called for this event
Function & event = GetEvent(id);
// Is the specified callback function null?
if (func.IsNull())
{
event.ReleaseGently(); // Then release the current callback
}
// Does this function need a custom environment?
else if (env.IsNull())
{
event = func;
}
// Assign the specified environment and function
else
{
event = Function(env.GetVM(), env, func.GetFunc());
}
}
// ------------------------------------------------------------------------------------------------
void Core::BlipInst::Destroy(bool destroy, Int32 header, Object & payload)
{
// Should we notify that this entity is being cleaned up?
if (VALID_ENTITY(mID))
{
// Don't leave exceptions to prevent us from releasing this instance
try
{
Core::Get().EmitBlipDestroyed(mID, header, payload);
}
SQMOD_CATCH_EVENT_EXCEPTION("while destroying blip")
}
// Is there a manager instance associated with this entity?
if (mInst)
{
// Prevent further use of this entity
mInst->m_ID = -1;
// Release user data to avoid dangling or circular references
mInst->m_Data.Release();
}
// Prevent further use of the manager instance
mInst = nullptr;
// Release the script object, if any
mObj.Release();
// Release tasks, if any
CleanupTasks(mID, ENT_BLIP);
// Are we supposed to clean up this entity? (only at reload)
if (destroy && VALID_ENTITY(mID) && (mFlags & ENF_OWNED))
{
// Block the entity pool changes notification from triggering the destroy event
const BitGuardU16 bg(mFlags, static_cast< Uint16 >(ENF_LOCKED));
// Now attempt to destroy this entity from the server
_Func->DestroyCoordBlip(mID);
}
// Reset the instance to it's initial state
Core::ResetInst(*this);
// Don't release the callbacks abruptly
Core::ResetFunc(*this);
}
// ------------------------------------------------------------------------------------------------
void Core::CheckpointInst::Destroy(bool destroy, Int32 header, Object & payload)
{
// Should we notify that this entity is being cleaned up?
if (VALID_ENTITY(mID))
{
// Don't leave exceptions to prevent us from releasing this instance
try
{
Core::Get().EmitCheckpointDestroyed(mID, header, payload);
}
SQMOD_CATCH_EVENT_EXCEPTION("while destroying checkpoint")
}
// Is there a manager instance associated with this entity?
if (mInst)
{
// Prevent further use of this entity
mInst->m_ID = -1;
// Release user data to avoid dangling or circular references
mInst->m_Data.Release();
}
// Prevent further use of the manager instance
mInst = nullptr;
// Release the script object, if any
mObj.Release();
// Release tasks, if any
CleanupTasks(mID, ENT_CHECKPOINT);
// Are we supposed to clean up this entity? (only at reload)
if (destroy && VALID_ENTITY(mID) && (mFlags & ENF_OWNED))
{
// Block the entity pool changes notification from triggering the destroy event
const BitGuardU16 bg(mFlags, static_cast< Uint16 >(ENF_LOCKED));
// Now attempt to destroy this entity from the server
_Func->DeleteCheckPoint(mID);
}
// Reset the instance to it's initial state
Core::ResetInst(*this);
// Don't release the callbacks abruptly
Core::ResetFunc(*this);
}
// ------------------------------------------------------------------------------------------------
void Core::KeybindInst::Destroy(bool destroy, Int32 header, Object & payload)
{
// Should we notify that this entity is being cleaned up?
if (VALID_ENTITY(mID))
{
// Don't leave exceptions to prevent us from releasing this instance
try
{
Core::Get().EmitKeybindDestroyed(mID, header, payload);
}
SQMOD_CATCH_EVENT_EXCEPTION("while destroying keybind")
}
// Is there a manager instance associated with this entity?
if (mInst)
{
// Prevent further use of this entity
mInst->m_ID = -1;
// Release user data to avoid dangling or circular references
mInst->m_Data.Release();
}
// Prevent further use of the manager instance
mInst = nullptr;
// Release the script object, if any
mObj.Release();
// Release tasks, if any
CleanupTasks(mID, ENT_KEYBIND);
// Are we supposed to clean up this entity? (only at reload)
if (destroy && VALID_ENTITY(mID) && (mFlags & ENF_OWNED))
{
// Block the entity pool changes notification from triggering the destroy event
const BitGuardU16 bg(mFlags, static_cast< Uint16 >(ENF_LOCKED));
// Now attempt to destroy this entity from the server
_Func->RemoveKeyBind(mID);
}
// Reset the instance to it's initial state
Core::ResetInst(*this);
// Don't release the callbacks abruptly
Core::ResetFunc(*this);
}
// ------------------------------------------------------------------------------------------------
void Core::ObjectInst::Destroy(bool destroy, Int32 header, Object & payload)
{
// Should we notify that this entity is being cleaned up?
if (VALID_ENTITY(mID))
{
// Don't leave exceptions to prevent us from releasing this instance
try
{
Core::Get().EmitObjectDestroyed(mID, header, payload);
}
SQMOD_CATCH_EVENT_EXCEPTION("while destroying object")
}
// Is there a manager instance associated with this entity?
if (mInst)
{
// Prevent further use of this entity
mInst->m_ID = -1;
// Release user data to avoid dangling or circular references
mInst->m_Data.Release();
}
// Prevent further use of the manager instance
mInst = nullptr;
// Release the script object, if any
mObj.Release();
// Release tasks, if any
CleanupTasks(mID, ENT_OBJECT);
// Are we supposed to clean up this entity? (only at reload)
if (destroy && VALID_ENTITY(mID) && (mFlags & ENF_OWNED))
{
// Block the entity pool changes notification from triggering the destroy event
const BitGuardU16 bg(mFlags, static_cast< Uint16 >(ENF_LOCKED));
// Now attempt to destroy this entity from the server
_Func->DeleteObject(mID);
}
// Reset the instance to it's initial state
Core::ResetInst(*this);
// Don't release the callbacks abruptly
Core::ResetFunc(*this);
}
// ------------------------------------------------------------------------------------------------
void Core::PickupInst::Destroy(bool destroy, Int32 header, Object & payload)
{
// Should we notify that this entity is being cleaned up?
if (VALID_ENTITY(mID))
{
// Don't leave exceptions to prevent us from releasing this instance
try
{
Core::Get().EmitPickupDestroyed(mID, header, payload);
}
SQMOD_CATCH_EVENT_EXCEPTION("while destroying pickup")
}
// Is there a manager instance associated with this entity?
if (mInst)
{
// Prevent further use of this entity
mInst->m_ID = -1;
// Release user data to avoid dangling or circular references
mInst->m_Data.Release();
}
// Prevent further use of the manager instance
mInst = nullptr;
// Release the script object, if any
mObj.Release();
// Release tasks, if any
CleanupTasks(mID, ENT_PICKUP);
// Are we supposed to clean up this entity? (only at reload)
if (destroy && VALID_ENTITY(mID) && (mFlags & ENF_OWNED))
{
// Block the entity pool changes notification from triggering the destroy event
const BitGuardU16 bg(mFlags, static_cast< Uint16 >(ENF_LOCKED));
// Now attempt to destroy this entity from the server
_Func->DeletePickup(mID);
}
// Reset the instance to it's initial state
Core::ResetInst(*this);
// Don't release the callbacks abruptly
Core::ResetFunc(*this);
}
// ------------------------------------------------------------------------------------------------
void Core::PlayerInst::Destroy(bool /*destroy*/, Int32 header, Object & payload)
{
// Should we notify that this entity is being cleaned up?
if (VALID_ENTITY(mID))
{
// Don't leave exceptions to prevent us from releasing this instance
try
{
Core::Get().EmitPlayerDestroyed(mID, header, payload);
}
SQMOD_CATCH_EVENT_EXCEPTION("while destroying player")
}
// Is there a manager instance associated with this entity?
if (mInst)
{
// Prevent further use of this entity
mInst->m_ID = -1;
// Release user data to avoid dangling or circular references
mInst->m_Data.Release();
// Release the used memory buffer
mInst->m_Buffer.ResetAll();
}
// Prevent further use of the manager instance
mInst = nullptr;
// Release the script object, if any
mObj.Release();
// Release tasks, if any
CleanupTasks(mID, ENT_PLAYER);
// Reset the instance to it's initial state
Core::ResetInst(*this);
// Don't release the callbacks abruptly
Core::ResetFunc(*this);
}
// ------------------------------------------------------------------------------------------------
void Core::VehicleInst::Destroy(bool destroy, Int32 header, Object & payload)
{
// Should we notify that this entity is being cleaned up?
if (VALID_ENTITY(mID))
{
// Don't leave exceptions to prevent us from releasing this instance
try
{
Core::Get().EmitVehicleDestroyed(mID, header, payload);
}
SQMOD_CATCH_EVENT_EXCEPTION("while destroying vehicle")
}
// Is there a manager instance associated with this entity?
if (mInst)
{
// Prevent further use of this entity
mInst->m_ID = -1;
// Release user data to avoid dangling or circular references
mInst->m_Data.Release();
}
// Prevent further use of the manager instance
mInst = nullptr;
// Release the script object, if any
mObj.Release();
// Release tasks, if any
CleanupTasks(mID, ENT_VEHICLE);
// Are we supposed to clean up this entity? (only at reload)
if (destroy && VALID_ENTITY(mID) && (mFlags & ENF_OWNED))
{
// Block the entity pool changes notification from triggering the destroy event
const BitGuardU16 bg(mFlags, static_cast< Uint16 >(ENF_LOCKED));
// Now attempt to destroy this entity from the server
_Func->DeleteVehicle(mID);
}
// Reset the instance to it's initial state
Core::ResetInst(*this);
// Don't release the callbacks abruptly
Core::ResetFunc(*this);
}
} // Namespace:: SqMod

File diff suppressed because it is too large Load Diff

View File

@ -34,7 +34,7 @@ void Core::ImportBlips()
m_Blips[i].mPosition.SetVector3Ex(x, y, z);
m_Blips[i].mColor.SetRGBA(color);
// Attempt to allocate the instance
AllocBlip(i, false, SQMOD_CREATE_IMPORT, NullObject());
AllocBlip(i, false, SQMOD_CREATE_IMPORT, NullLightObj());
}
}
}
@ -47,7 +47,7 @@ void Core::ImportCheckpoints()
// See if this entity exists on the server and whether was not allocated already
if (_Func->CheckEntityExists(vcmpEntityPoolCheckPoint, i) && INVALID_ENTITY(m_Checkpoints[i].mID))
{
AllocCheckpoint(i, false, SQMOD_CREATE_IMPORT, NullObject());
AllocCheckpoint(i, false, SQMOD_CREATE_IMPORT, NullLightObj());
}
}
}
@ -55,6 +55,12 @@ void Core::ImportCheckpoints()
// ------------------------------------------------------------------------------------------------
void Core::ImportKeybinds()
{
/* @NOTE This function is disabled because VC:MP server seems bugged
* and does not return vcmpErrorNoSuchEntity when the keybind does not exist.
* Therefore causing incorrect behavior in the plugin.
*/
return;
// Information about the key-bind entity
Uint8 release = 0;
Int32 first = -1, second = -1, third = -1;
@ -71,7 +77,7 @@ void Core::ImportKeybinds()
m_Keybinds[i].mThird = third;
m_Keybinds[i].mRelease = release;
// Attempt to allocate the instance
AllocKeybind(i, false, SQMOD_CREATE_IMPORT, NullObject());
AllocKeybind(i, false, SQMOD_CREATE_IMPORT, NullLightObj());
}
}
}
@ -84,7 +90,7 @@ void Core::ImportObjects()
// See if this entity exists on the server and whether was not allocated already
if (_Func->CheckEntityExists(vcmpEntityPoolObject, i) && INVALID_ENTITY(m_Objects[i].mID))
{
AllocObject(i, false, SQMOD_CREATE_IMPORT, NullObject());
AllocObject(i, false, SQMOD_CREATE_IMPORT, NullLightObj());
}
}
}
@ -97,7 +103,7 @@ void Core::ImportPickups()
// See if this entity exists on the server and whether was not allocated already
if (_Func->CheckEntityExists(vcmpEntityPoolPickup, i) && (INVALID_ENTITY(m_Pickups[i].mID)))
{
AllocPickup(i, false, SQMOD_CREATE_IMPORT, NullObject());
AllocPickup(i, false, SQMOD_CREATE_IMPORT, NullLightObj());
}
}
}
@ -110,7 +116,7 @@ void Core::ImportPlayers()
// See if this entity exists on the server and whether was not allocated already
if (_Func->IsPlayerConnected(i) && (INVALID_ENTITY(m_Players[i].mID)))
{
ConnectPlayer(i, SQMOD_CREATE_IMPORT, NullObject());
ConnectPlayer(i, SQMOD_CREATE_IMPORT, NullLightObj());
}
}
}
@ -123,13 +129,13 @@ void Core::ImportVehicles()
// See if this entity exists on the server and whether was not allocated already
if (_Func->CheckEntityExists(vcmpEntityPoolVehicle, i) && INVALID_ENTITY(m_Vehicles[i].mID))
{
AllocVehicle(i, false, SQMOD_CREATE_IMPORT, NullObject());
AllocVehicle(i, false, SQMOD_CREATE_IMPORT, NullLightObj());
}
}
}
// --------------------------------------------------------------------------------------------
Core::BlipInst & Core::AllocBlip(Int32 id, bool owned, Int32 header, Object & payload)
Core::BlipInst & Core::AllocBlip(Int32 id, bool owned, Int32 header, LightObj & payload)
{
// Make sure that the specified entity identifier is valid
if (INVALID_ENTITYEX(id, SQMOD_BLIP_POOL))
@ -144,13 +150,17 @@ Core::BlipInst & Core::AllocBlip(Int32 id, bool owned, Int32 header, Object & pa
return inst; // Return the existing instance
}
// Instantiate the entity manager
inst.mInst = new CBlip(id);
DeleteGuard< CBlip > dg(new CBlip(id));
// Create the script object
inst.mObj = Object(inst.mInst, m_VM);
inst.mObj = LightObj(inst.mInst, m_VM);
// Store the manager instance itself
inst.mInst = dg.Get();
// The instance is now managed by the script
dg.Release();
// Make sure that both the instance and script object could be created
if (!inst.mInst || inst.mObj.IsNull())
{
ResetInst(inst);
inst.ResetInstance();
// Now we can throw the error
STHROWF("Unable to create a blip instance for: %d", id);
}
@ -165,6 +175,8 @@ Core::BlipInst & Core::AllocBlip(Int32 id, bool owned, Int32 header, Object & pa
{
inst.mFlags ^= ENF_OWNED;
}
// Initialize the instance events
inst.InitEvents();
// Let the script callbacks know about this entity
EmitBlipCreated(id, header, payload);
// Return the allocated instance
@ -172,7 +184,7 @@ Core::BlipInst & Core::AllocBlip(Int32 id, bool owned, Int32 header, Object & pa
}
// --------------------------------------------------------------------------------------------
Core::CheckpointInst & Core::AllocCheckpoint(Int32 id, bool owned, Int32 header, Object & payload)
Core::CheckpointInst & Core::AllocCheckpoint(Int32 id, bool owned, Int32 header, LightObj & payload)
{
// Make sure that the specified entity identifier is valid
if (INVALID_ENTITYEX(id, SQMOD_CHECKPOINT_POOL))
@ -187,13 +199,17 @@ Core::CheckpointInst & Core::AllocCheckpoint(Int32 id, bool owned, Int32 header,
return inst; // Return the existing instance
}
// Instantiate the entity manager
inst.mInst = new CCheckpoint(id);
DeleteGuard< CCheckpoint > dg(new CCheckpoint(id));
// Create the script object
inst.mObj = Object(inst.mInst, m_VM);
inst.mObj = LightObj(inst.mInst, m_VM);
// Store the manager instance itself
inst.mInst = dg.Get();
// The instance is now managed by the script
dg.Release();
// Make sure that both the instance and script object could be created
if (!inst.mInst || inst.mObj.IsNull())
{
ResetInst(inst);
inst.ResetInstance();
// Now we can throw the error
STHROWF("Unable to create a checkpoint instance for: %d", id);
}
@ -208,6 +224,8 @@ Core::CheckpointInst & Core::AllocCheckpoint(Int32 id, bool owned, Int32 header,
{
inst.mFlags ^= ENF_OWNED;
}
// Initialize the instance events
inst.InitEvents();
// Let the script callbacks know about this entity
EmitCheckpointCreated(id, header, payload);
// Return the allocated instance
@ -215,7 +233,7 @@ Core::CheckpointInst & Core::AllocCheckpoint(Int32 id, bool owned, Int32 header,
}
// --------------------------------------------------------------------------------------------
Core::KeybindInst & Core::AllocKeybind(Int32 id, bool owned, Int32 header, Object & payload)
Core::KeybindInst & Core::AllocKeybind(Int32 id, bool owned, Int32 header, LightObj & payload)
{
// Make sure that the specified entity identifier is valid
if (INVALID_ENTITYEX(id, SQMOD_KEYBIND_POOL))
@ -230,13 +248,17 @@ Core::KeybindInst & Core::AllocKeybind(Int32 id, bool owned, Int32 header, Objec
return inst; // Return the existing instance
}
// Instantiate the entity manager
inst.mInst = new CKeybind(id);
DeleteGuard< CKeybind > dg(new CKeybind(id));
// Create the script object
inst.mObj = Object(inst.mInst, m_VM);
inst.mObj = LightObj(inst.mInst, m_VM);
// Store the manager instance itself
inst.mInst = dg.Get();
// The instance is now managed by the script
dg.Release();
// Make sure that both the instance and script object could be created
if (!inst.mInst || inst.mObj.IsNull())
{
ResetInst(inst);
inst.ResetInstance();
// Now we can throw the error
STHROWF("Unable to create a keybind instance for: %d", id);
}
@ -251,6 +273,8 @@ Core::KeybindInst & Core::AllocKeybind(Int32 id, bool owned, Int32 header, Objec
{
inst.mFlags ^= ENF_OWNED;
}
// Initialize the instance events
inst.InitEvents();
// Let the script callbacks know about this entity
EmitKeybindCreated(id, header, payload);
// Return the allocated instance
@ -258,7 +282,7 @@ Core::KeybindInst & Core::AllocKeybind(Int32 id, bool owned, Int32 header, Objec
}
// --------------------------------------------------------------------------------------------
Core::ObjectInst & Core::AllocObject(Int32 id, bool owned, Int32 header, Object & payload)
Core::ObjectInst & Core::AllocObject(Int32 id, bool owned, Int32 header, LightObj & payload)
{
// Make sure that the specified entity identifier is valid
if (INVALID_ENTITYEX(id, SQMOD_OBJECT_POOL))
@ -273,13 +297,17 @@ Core::ObjectInst & Core::AllocObject(Int32 id, bool owned, Int32 header, Object
return inst; // Return the existing instance
}
// Instantiate the entity manager
inst.mInst = new CObject(id);
DeleteGuard< CObject > dg(new CObject(id));
// Create the script object
inst.mObj = Object(inst.mInst, m_VM);
inst.mObj = LightObj(inst.mInst, m_VM);
// Store the manager instance itself
inst.mInst = dg.Get();
// The instance is now managed by the script
dg.Release();
// Make sure that both the instance and script object could be created
if (!inst.mInst || inst.mObj.IsNull())
{
ResetInst(inst);
inst.ResetInstance();
// Now we can throw the error
STHROWF("Unable to create a object instance for: %d", id);
}
@ -294,6 +322,8 @@ Core::ObjectInst & Core::AllocObject(Int32 id, bool owned, Int32 header, Object
{
inst.mFlags ^= ENF_OWNED;
}
// Initialize the instance events
inst.InitEvents();
// Let the script callbacks know about this entity
EmitObjectCreated(id, header, payload);
// Return the allocated instance
@ -301,7 +331,7 @@ Core::ObjectInst & Core::AllocObject(Int32 id, bool owned, Int32 header, Object
}
// --------------------------------------------------------------------------------------------
Core::PickupInst & Core::AllocPickup(Int32 id, bool owned, Int32 header, Object & payload)
Core::PickupInst & Core::AllocPickup(Int32 id, bool owned, Int32 header, LightObj & payload)
{
// Make sure that the specified entity identifier is valid
if (INVALID_ENTITYEX(id, SQMOD_PICKUP_POOL))
@ -316,13 +346,17 @@ Core::PickupInst & Core::AllocPickup(Int32 id, bool owned, Int32 header, Object
return inst; // Return the existing instance
}
// Instantiate the entity manager
inst.mInst = new CPickup(id);
DeleteGuard< CPickup > dg(new CPickup(id));
// Create the script object
inst.mObj = Object(inst.mInst, m_VM);
inst.mObj = LightObj(inst.mInst, m_VM);
// Store the manager instance itself
inst.mInst = dg.Get();
// The instance is now managed by the script
dg.Release();
// Make sure that both the instance and script object could be created
if (!inst.mInst || inst.mObj.IsNull())
{
ResetInst(inst);
inst.ResetInstance();
// Now we can throw the error
STHROWF("Unable to create a pickup instance for: %d", id);
}
@ -337,6 +371,8 @@ Core::PickupInst & Core::AllocPickup(Int32 id, bool owned, Int32 header, Object
{
inst.mFlags ^= ENF_OWNED;
}
// Initialize the instance events
inst.InitEvents();
// Let the script callbacks know about this entity
EmitPickupCreated(id, header, payload);
// Return the allocated instance
@ -344,7 +380,7 @@ Core::PickupInst & Core::AllocPickup(Int32 id, bool owned, Int32 header, Object
}
// --------------------------------------------------------------------------------------------
Core::VehicleInst & Core::AllocVehicle(Int32 id, bool owned, Int32 header, Object & payload)
Core::VehicleInst & Core::AllocVehicle(Int32 id, bool owned, Int32 header, LightObj & payload)
{
// Make sure that the specified entity identifier is valid
if (INVALID_ENTITYEX(id, SQMOD_VEHICLE_POOL))
@ -359,13 +395,17 @@ Core::VehicleInst & Core::AllocVehicle(Int32 id, bool owned, Int32 header, Objec
return inst; // Return the existing instance
}
// Instantiate the entity manager
inst.mInst = new CVehicle(id);
DeleteGuard< CVehicle > dg(new CVehicle(id));
// Create the script object
inst.mObj = Object(inst.mInst, m_VM);
inst.mObj = LightObj(inst.mInst, m_VM);
// Store the manager instance itself
inst.mInst = dg.Get();
// The instance is now managed by the script
dg.Release();
// Make sure that both the instance and script object could be created
if (!inst.mInst || inst.mObj.IsNull())
{
ResetInst(inst);
inst.ResetInstance();
// Now we can throw the error
STHROWF("Unable to create a vehicle instance for: %d", id);
}
@ -380,6 +420,8 @@ Core::VehicleInst & Core::AllocVehicle(Int32 id, bool owned, Int32 header, Objec
{
inst.mFlags ^= ENF_OWNED;
}
// Initialize the instance events
inst.InitEvents();
// Let the script callbacks know about this entity
EmitVehicleCreated(id, header, payload);
// Return the allocated instance
@ -387,7 +429,7 @@ Core::VehicleInst & Core::AllocVehicle(Int32 id, bool owned, Int32 header, Objec
}
// --------------------------------------------------------------------------------------------
void Core::DeallocBlip(Int32 id, bool destroy, Int32 header, Object & payload)
void Core::DeallocBlip(Int32 id, bool destroy, Int32 header, LightObj & payload)
{
// Make sure that the specified entity identifier is valid
if (INVALID_ENTITYEX(id, SQMOD_BLIP_POOL))
@ -404,7 +446,7 @@ void Core::DeallocBlip(Int32 id, bool destroy, Int32 header, Object & payload)
}
// --------------------------------------------------------------------------------------------
void Core::DeallocCheckpoint(Int32 id, bool destroy, Int32 header, Object & payload)
void Core::DeallocCheckpoint(Int32 id, bool destroy, Int32 header, LightObj & payload)
{
// Make sure that the specified entity identifier is valid
if (INVALID_ENTITYEX(id, SQMOD_CHECKPOINT_POOL))
@ -421,7 +463,7 @@ void Core::DeallocCheckpoint(Int32 id, bool destroy, Int32 header, Object & payl
}
// --------------------------------------------------------------------------------------------
void Core::DeallocKeybind(Int32 id, bool destroy, Int32 header, Object & payload)
void Core::DeallocKeybind(Int32 id, bool destroy, Int32 header, LightObj & payload)
{
// Make sure that the specified entity identifier is valid
if (INVALID_ENTITYEX(id, SQMOD_KEYBIND_POOL))
@ -438,7 +480,7 @@ void Core::DeallocKeybind(Int32 id, bool destroy, Int32 header, Object & payload
}
// --------------------------------------------------------------------------------------------
void Core::DeallocObject(Int32 id, bool destroy, Int32 header, Object & payload)
void Core::DeallocObject(Int32 id, bool destroy, Int32 header, LightObj & payload)
{
// Make sure that the specified entity identifier is valid
if (INVALID_ENTITYEX(id, SQMOD_OBJECT_POOL))
@ -455,7 +497,7 @@ void Core::DeallocObject(Int32 id, bool destroy, Int32 header, Object & payload)
}
// --------------------------------------------------------------------------------------------
void Core::DeallocPickup(Int32 id, bool destroy, Int32 header, Object & payload)
void Core::DeallocPickup(Int32 id, bool destroy, Int32 header, LightObj & payload)
{
// Make sure that the specified entity identifier is valid
if (INVALID_ENTITYEX(id, SQMOD_PICKUP_POOL))
@ -472,7 +514,7 @@ void Core::DeallocPickup(Int32 id, bool destroy, Int32 header, Object & payload)
}
// --------------------------------------------------------------------------------------------
void Core::DeallocVehicle(Int32 id, bool destroy, Int32 header, Object & payload)
void Core::DeallocVehicle(Int32 id, bool destroy, Int32 header, LightObj & payload)
{
// Make sure that the specified entity identifier is valid
if (INVALID_ENTITYEX(id, SQMOD_VEHICLE_POOL))
@ -489,9 +531,9 @@ void Core::DeallocVehicle(Int32 id, bool destroy, Int32 header, Object & payload
}
// --------------------------------------------------------------------------------------------
Object & Core::NewBlip(Int32 index, Int32 world, Float32 x, Float32 y, Float32 z,
LightObj & Core::NewBlip(Int32 index, Int32 world, Float32 x, Float32 y, Float32 z,
Int32 scale, Uint32 color, Int32 sprid,
Int32 header, Object & payload)
Int32 header, LightObj & payload)
{
// Request the server to create this entity
const Int32 id = _Func->CreateCoordBlip(index, world, x, y, z, scale, color, sprid);
@ -517,9 +559,9 @@ Object & Core::NewBlip(Int32 index, Int32 world, Float32 x, Float32 y, Float32 z
}
// --------------------------------------------------------------------------------------------
Object & Core::NewCheckpoint(Int32 player, Int32 world, bool sphere, Float32 x, Float32 y, Float32 z,
LightObj & Core::NewCheckpoint(Int32 player, Int32 world, bool sphere, Float32 x, Float32 y, Float32 z,
Uint8 r, Uint8 g, Uint8 b, Uint8 a, Float32 radius,
Int32 header, Object & payload)
Int32 header, LightObj & payload)
{
// Request the server to create this entity
const Int32 id = _Func->CreateCheckPoint(player, world, sphere, x, y, z, r, g, b, a, radius);
@ -549,8 +591,8 @@ Object & Core::NewCheckpoint(Int32 player, Int32 world, bool sphere, Float32 x,
}
// --------------------------------------------------------------------------------------------
Object & Core::NewKeybind(Int32 slot, bool release, Int32 primary, Int32 secondary, Int32 alternative,
Int32 header, Object & payload)
LightObj & Core::NewKeybind(Int32 slot, bool release, Int32 primary, Int32 secondary, Int32 alternative,
Int32 header, LightObj & payload)
{
// Should we obtain a new keybind slot automatically?
if (slot < 0)
@ -581,8 +623,8 @@ Object & Core::NewKeybind(Int32 slot, bool release, Int32 primary, Int32 seconda
}
// --------------------------------------------------------------------------------------------
Object & Core::NewObject(Int32 model, Int32 world, Float32 x, Float32 y, Float32 z, Int32 alpha,
Int32 header, Object & payload)
LightObj & Core::NewObject(Int32 model, Int32 world, Float32 x, Float32 y, Float32 z, Int32 alpha,
Int32 header, LightObj & payload)
{
// Request the server to create this entity
const Int32 id = _Func->CreateObject(model, world, x, y, z, alpha);
@ -608,9 +650,9 @@ Object & Core::NewObject(Int32 model, Int32 world, Float32 x, Float32 y, Float32
}
// --------------------------------------------------------------------------------------------
Object & Core::NewPickup(Int32 model, Int32 world, Int32 quantity,
LightObj & Core::NewPickup(Int32 model, Int32 world, Int32 quantity,
Float32 x, Float32 y, Float32 z, Int32 alpha, bool automatic,
Int32 header, Object & payload)
Int32 header, LightObj & payload)
{
// Request the server to create this entity
const Int32 id = _Func->CreatePickup(model, world, quantity, x, y, z, alpha, automatic);
@ -636,9 +678,9 @@ Object & Core::NewPickup(Int32 model, Int32 world, Int32 quantity,
}
// --------------------------------------------------------------------------------------------
Object & Core::NewVehicle(Int32 model, Int32 world, Float32 x, Float32 y, Float32 z,
LightObj & Core::NewVehicle(Int32 model, Int32 world, Float32 x, Float32 y, Float32 z,
Float32 angle, Int32 primary, Int32 secondary,
Int32 header, Object & payload)
Int32 header, LightObj & payload)
{
// Request the server to create this entity
@ -669,7 +711,7 @@ Object & Core::NewVehicle(Int32 model, Int32 world, Float32 x, Float32 y, Float3
}
// --------------------------------------------------------------------------------------------
bool Core::DelBlip(Int32 id, Int32 header, Object & payload)
bool Core::DelBlip(Int32 id, Int32 header, LightObj & payload)
{
// Attempt to destroy and deallocate the specified entity instance
DeallocBlip(id, true, header, payload);
@ -678,7 +720,7 @@ bool Core::DelBlip(Int32 id, Int32 header, Object & payload)
}
// ------------------------------------------------------------------------------------------------
bool Core::DelCheckpoint(Int32 id, Int32 header, Object & payload)
bool Core::DelCheckpoint(Int32 id, Int32 header, LightObj & payload)
{
// Attempt to destroy and deallocate the specified entity instance
DeallocCheckpoint(id, true, header, payload);
@ -687,7 +729,7 @@ bool Core::DelCheckpoint(Int32 id, Int32 header, Object & payload)
}
// ------------------------------------------------------------------------------------------------
bool Core::DelKeybind(Int32 id, Int32 header, Object & payload)
bool Core::DelKeybind(Int32 id, Int32 header, LightObj & payload)
{
// Attempt to destroy and deallocate the specified entity instance
DeallocKeybind(id, true, header, payload);
@ -696,7 +738,7 @@ bool Core::DelKeybind(Int32 id, Int32 header, Object & payload)
}
// ------------------------------------------------------------------------------------------------
bool Core::DelObject(Int32 id, Int32 header, Object & payload)
bool Core::DelObject(Int32 id, Int32 header, LightObj & payload)
{
// Attempt to destroy and deallocate the specified entity instance
DeallocObject(id, true, header, payload);
@ -705,7 +747,7 @@ bool Core::DelObject(Int32 id, Int32 header, Object & payload)
}
// ------------------------------------------------------------------------------------------------
bool Core::DelPickup(Int32 id, Int32 header, Object & payload)
bool Core::DelPickup(Int32 id, Int32 header, LightObj & payload)
{
// Attempt to destroy and deallocate the specified entity instance
DeallocPickup(id, true, header, payload);
@ -714,7 +756,7 @@ bool Core::DelPickup(Int32 id, Int32 header, Object & payload)
}
// ------------------------------------------------------------------------------------------------
bool Core::DelVehicle(Int32 id, Int32 header, Object & payload)
bool Core::DelVehicle(Int32 id, Int32 header, LightObj & payload)
{
// Attempt to destroy and deallocate the specified entity instance
DeallocVehicle(id, true, header, payload);
@ -723,7 +765,7 @@ bool Core::DelVehicle(Int32 id, Int32 header, Object & payload)
}
// ------------------------------------------------------------------------------------------------
void Core::ConnectPlayer(Int32 id, Int32 header, Object & payload)
void Core::ConnectPlayer(Int32 id, Int32 header, LightObj & payload)
{
// Make sure that the specified entity identifier is valid
if (INVALID_ENTITYEX(id, SQMOD_PLAYER_POOL))
@ -740,11 +782,11 @@ void Core::ConnectPlayer(Int32 id, Int32 header, Object & payload)
// Instantiate the entity manager
inst.mInst = new CPlayer(id);
// Create the script object
inst.mObj = Object(inst.mInst, m_VM);
inst.mObj = LightObj(inst.mInst, m_VM);
// Make sure that both the instance and script object could be created
if (!inst.mInst || inst.mObj.IsNull())
{
ResetInst(inst);
inst.ResetInstance();
STHROWF("Unable to create a player instance for: %d", id);
}
// Assign the specified entity identifier
@ -761,7 +803,7 @@ void Core::ConnectPlayer(Int32 id, Int32 header, Object & payload)
}
// ------------------------------------------------------------------------------------------------
void Core::DisconnectPlayer(Int32 id, Int32 header, Object & payload)
void Core::DisconnectPlayer(Int32 id, Int32 header, LightObj & payload)
{
// Make sure that the specified entity identifier is valid
if (INVALID_ENTITYEX(id, SQMOD_PLAYER_POOL))

File diff suppressed because it is too large Load Diff

View File

@ -42,51 +42,12 @@ static SQInteger SqLoadScript(HSQUIRRELVM vm)
}
// ------------------------------------------------------------------------------------------------
static void SqBindPreLoad(Object & env, Function & func)
static SQInteger SqGetEvents(HSQUIRRELVM vm)
{
Core::Get().BindPreLoad(env, func, NullObject());
}
// ------------------------------------------------------------------------------------------------
static void SqBindPostLoad(Object & env, Function & func)
{
Core::Get().BindPostLoad(env, func, NullObject());
}
// ------------------------------------------------------------------------------------------------
static void SqBindUnload(Object & env, Function & func)
{
Core::Get().BindUnload(env, func, NullObject());
}
// ------------------------------------------------------------------------------------------------
static void SqBindPreLoadEx(Object & env, Function & func, Object & payload)
{
Core::Get().BindPreLoad(env, func, payload);
}
// ------------------------------------------------------------------------------------------------
static void SqBindPostLoadEx(Object & env, Function & func, Object & payload)
{
Core::Get().BindPostLoad(env, func, payload);
}
// ------------------------------------------------------------------------------------------------
static void SqBindUnloadEx(Object & env, Function & func, Object & payload)
{
Core::Get().BindUnload(env, func, payload);
}
// ------------------------------------------------------------------------------------------------
static void SqBindEvent(Int32 id, Object & env, Function & func)
{
Core::Get().BindEvent(id, env, func);
}
// ------------------------------------------------------------------------------------------------
static void SqCustomEvent(Int32 group, Int32 header, Object & payload)
{
Core::Get().EmitCustomEvent(group, header, payload);
// Push the events table object on the stack
sq_pushobject(vm, Core::Get().GetEvents().mObj);
// Specify that we're returning a value
return 1;
}
// ------------------------------------------------------------------------------------------------
@ -102,7 +63,7 @@ static void SqSetReloadStatus(bool toggle)
}
// ------------------------------------------------------------------------------------------------
static void SqReloadBecause(Int32 header, Object & payload)
static void SqReloadBecause(Int32 header, LightObj & payload)
{
// Assign the reload info
Core::Get().SetReloadInfo(header, payload);
@ -111,7 +72,7 @@ static void SqReloadBecause(Int32 header, Object & payload)
}
// ------------------------------------------------------------------------------------------------
static void SqSetReloadInfo(Int32 header, Object & payload)
static void SqSetReloadInfo(Int32 header, LightObj & payload)
{
Core::Get().SetReloadInfo(header, payload);
}
@ -123,7 +84,7 @@ static Int32 SqGetReloadHeader()
}
// ------------------------------------------------------------------------------------------------
static Object & SqGetReloadPayload()
static LightObj & SqGetReloadPayload()
{
return Core::Get().GetReloadPayload();
}
@ -159,7 +120,7 @@ static void SetOption(CSStr name, CSStr value)
}
// ------------------------------------------------------------------------------------------------
static Object & GetBlip(Int32 id)
static LightObj & GetBlip(Int32 id)
{
// Validate the identifier first
if (INVALID_ENTITYEX(id, SQMOD_BLIP_POOL))
@ -171,7 +132,7 @@ static Object & GetBlip(Int32 id)
}
// ------------------------------------------------------------------------------------------------
static Object & GetCheckpoint(Int32 id)
static LightObj & GetCheckpoint(Int32 id)
{
// Validate the identifier first
if (INVALID_ENTITYEX(id, SQMOD_CHECKPOINT_POOL))
@ -183,7 +144,7 @@ static Object & GetCheckpoint(Int32 id)
}
// ------------------------------------------------------------------------------------------------
static Object & GetKeybind(Int32 id)
static LightObj & GetKeybind(Int32 id)
{
// Validate the identifier first
if (INVALID_ENTITYEX(id, SQMOD_KEYBIND_POOL))
@ -195,7 +156,7 @@ static Object & GetKeybind(Int32 id)
}
// ------------------------------------------------------------------------------------------------
static Object & GetObject(Int32 id)
static LightObj & GetObject(Int32 id)
{
// Validate the identifier first
if (INVALID_ENTITYEX(id, SQMOD_OBJECT_POOL))
@ -207,7 +168,7 @@ static Object & GetObject(Int32 id)
}
// ------------------------------------------------------------------------------------------------
static Object & GetPickup(Int32 id)
static LightObj & GetPickup(Int32 id)
{
// Validate the identifier first
if (INVALID_ENTITYEX(id, SQMOD_PICKUP_POOL))
@ -219,7 +180,7 @@ static Object & GetPickup(Int32 id)
}
// ------------------------------------------------------------------------------------------------
static Object & GetPlayer(Int32 id)
static LightObj & GetPlayer(Int32 id)
{
// Validate the identifier first
if (INVALID_ENTITYEX(id, SQMOD_PLAYER_POOL))
@ -231,7 +192,7 @@ static Object & GetPlayer(Int32 id)
}
// ------------------------------------------------------------------------------------------------
static Object & GetVehicle(Int32 id)
static LightObj & GetVehicle(Int32 id)
{
// Validate the identifier first
if (INVALID_ENTITYEX(id, SQMOD_VEHICLE_POOL))
@ -243,7 +204,7 @@ static Object & GetVehicle(Int32 id)
}
// ------------------------------------------------------------------------------------------------
static bool DelBlip(Int32 id, Int32 header, Object & payload)
static bool DelBlip(Int32 id, Int32 header, LightObj & payload)
{
// Validate the identifier first
if (INVALID_ENTITYEX(id, SQMOD_BLIP_POOL))
@ -255,7 +216,7 @@ static bool DelBlip(Int32 id, Int32 header, Object & payload)
}
// ------------------------------------------------------------------------------------------------
static bool DelCheckpoint(Int32 id, Int32 header, Object & payload)
static bool DelCheckpoint(Int32 id, Int32 header, LightObj & payload)
{
// Validate the identifier first
if (INVALID_ENTITYEX(id, SQMOD_CHECKPOINT_POOL))
@ -267,7 +228,7 @@ static bool DelCheckpoint(Int32 id, Int32 header, Object & payload)
}
// ------------------------------------------------------------------------------------------------
static bool DelKeybind(Int32 id, Int32 header, Object & payload)
static bool DelKeybind(Int32 id, Int32 header, LightObj & payload)
{
// Validate the identifier first
if (INVALID_ENTITYEX(id, SQMOD_KEYBIND_POOL))
@ -279,7 +240,7 @@ static bool DelKeybind(Int32 id, Int32 header, Object & payload)
}
// ------------------------------------------------------------------------------------------------
static bool DelObject(Int32 id, Int32 header, Object & payload)
static bool DelObject(Int32 id, Int32 header, LightObj & payload)
{
// Validate the identifier first
if (INVALID_ENTITYEX(id, SQMOD_OBJECT_POOL))
@ -291,7 +252,7 @@ static bool DelObject(Int32 id, Int32 header, Object & payload)
}
// ------------------------------------------------------------------------------------------------
static bool DelPickup(Int32 id, Int32 header, Object & payload)
static bool DelPickup(Int32 id, Int32 header, LightObj & payload)
{
// Validate the identifier first
if (INVALID_ENTITYEX(id, SQMOD_PICKUP_POOL))
@ -303,7 +264,7 @@ static bool DelPickup(Int32 id, Int32 header, Object & payload)
}
// ------------------------------------------------------------------------------------------------
static bool DelVehicle(Int32 id, Int32 header, Object & payload)
static bool DelVehicle(Int32 id, Int32 header, LightObj & payload)
{
// Validate the identifier first
if (INVALID_ENTITYEX(id, SQMOD_VEHICLE_POOL))
@ -319,14 +280,6 @@ void Register_Core(HSQUIRRELVM vm)
{
RootTable(vm)
.Bind(_SC("SqCore"), Table(vm)
.Func(_SC("Bind"), &SqBindEvent)
.Func(_SC("BindPreLoad"), &SqBindPreLoad)
.Func(_SC("BindPostLoad"), &SqBindPostLoad)
.Func(_SC("BindUnload"), &SqBindUnload)
.Func(_SC("BindPreLoadEx"), &SqBindPreLoadEx)
.Func(_SC("BindPostLoadEx"), &SqBindPostLoadEx)
.Func(_SC("BindUnloadEx"), &SqBindUnloadEx)
.Func(_SC("CustomEvent"), &SqCustomEvent)
.Func(_SC("Reload"), &SqSetReloadStatus)
.Func(_SC("Reloading"), &SqGetReloadStatus)
.Func(_SC("ReloadBecause"), &SqReloadBecause)
@ -352,6 +305,7 @@ void Register_Core(HSQUIRRELVM vm)
.Func(_SC("DestroyPickup"), &DelPickup)
.Func(_SC("DestroyVehicle"), &DelVehicle)
.SquirrelFunc(_SC("LoadScript"), &SqLoadScript)
.SquirrelFunc(_SC("On"), &SqGetEvents)
);
}

787
source/CoreInst.cpp Normal file
View File

@ -0,0 +1,787 @@
// ------------------------------------------------------------------------------------------------
#include "Core.hpp"
#include "Signal.hpp"
#include "Logger.hpp"
// ------------------------------------------------------------------------------------------------
#include "Entity/Blip.hpp"
#include "Entity/Checkpoint.hpp"
#include "Entity/Keybind.hpp"
#include "Entity/Object.hpp"
#include "Entity/Pickup.hpp"
#include "Entity/Player.hpp"
#include "Entity/Vehicle.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// --------------------------------------------------------------------------------------------
#define SQMOD_CATCH_EVENT_EXCEPTION(action) /*
*/ catch (const Sqrat::Exception & e) /*
*/ { /*
*/ LogErr("Squirrel exception caught " action); /*
*/ Logger::Get().Debug("%s", e.what()); /*
*/ } /*
*/
// ------------------------------------------------------------------------------------------------
extern void CleanupTasks(Int32 id, Int32 type);
// ------------------------------------------------------------------------------------------------
void Core::BlipInst::Destroy(bool destroy, Int32 header, LightObj & payload)
{
// Should we notify that this entity is being cleaned up?
if (VALID_ENTITY(mID))
{
// Don't leave exceptions to prevent us from releasing this instance
try
{
Core::Get().EmitBlipDestroyed(mID, header, payload);
}
SQMOD_CATCH_EVENT_EXCEPTION("while destroying blip")
}
// Is there a manager instance associated with this entity?
if (mInst)
{
// Prevent further use of this entity
mInst->m_ID = -1;
// Release user data to avoid dangling or circular references
mInst->m_Data.Release();
}
// Prevent further use of the manager instance
mInst = nullptr;
// Release the script object, if any
mObj.Release();
// Release tasks, if any
CleanupTasks(mID, ENT_BLIP);
// Are we supposed to clean up this entity? (only at reload)
if (destroy && VALID_ENTITY(mID) && (mFlags & ENF_OWNED))
{
// Block the entity pool changes notification from triggering the destroy event
const BitGuardU16 bg(mFlags, static_cast< Uint16 >(ENF_LOCKED));
// Now attempt to destroy this entity from the server
_Func->DestroyCoordBlip(mID);
}
// Reset the instance to it's initial state
ResetInstance();
// Don't release the callbacks abruptly
DropEvents();
}
// ------------------------------------------------------------------------------------------------
void Core::CheckpointInst::Destroy(bool destroy, Int32 header, LightObj & payload)
{
// Should we notify that this entity is being cleaned up?
if (VALID_ENTITY(mID))
{
// Don't leave exceptions to prevent us from releasing this instance
try
{
Core::Get().EmitCheckpointDestroyed(mID, header, payload);
}
SQMOD_CATCH_EVENT_EXCEPTION("while destroying checkpoint")
}
// Is there a manager instance associated with this entity?
if (mInst)
{
// Prevent further use of this entity
mInst->m_ID = -1;
// Release user data to avoid dangling or circular references
mInst->m_Data.Release();
}
// Prevent further use of the manager instance
mInst = nullptr;
// Release the script object, if any
mObj.Release();
// Release tasks, if any
CleanupTasks(mID, ENT_CHECKPOINT);
// Are we supposed to clean up this entity? (only at reload)
if (destroy && VALID_ENTITY(mID) && (mFlags & ENF_OWNED))
{
// Block the entity pool changes notification from triggering the destroy event
const BitGuardU16 bg(mFlags, static_cast< Uint16 >(ENF_LOCKED));
// Now attempt to destroy this entity from the server
_Func->DeleteCheckPoint(mID);
}
// Reset the instance to it's initial state
ResetInstance();
// Don't release the callbacks abruptly
DropEvents();
}
// ------------------------------------------------------------------------------------------------
void Core::KeybindInst::Destroy(bool destroy, Int32 header, LightObj & payload)
{
// Should we notify that this entity is being cleaned up?
if (VALID_ENTITY(mID))
{
// Don't leave exceptions to prevent us from releasing this instance
try
{
Core::Get().EmitKeybindDestroyed(mID, header, payload);
}
SQMOD_CATCH_EVENT_EXCEPTION("while destroying keybind")
}
// Is there a manager instance associated with this entity?
if (mInst)
{
// Prevent further use of this entity
mInst->m_ID = -1;
// Release user data to avoid dangling or circular references
mInst->m_Data.Release();
}
// Prevent further use of the manager instance
mInst = nullptr;
// Release the script object, if any
mObj.Release();
// Release tasks, if any
CleanupTasks(mID, ENT_KEYBIND);
// Are we supposed to clean up this entity? (only at reload)
if (destroy && VALID_ENTITY(mID) && (mFlags & ENF_OWNED))
{
// Block the entity pool changes notification from triggering the destroy event
const BitGuardU16 bg(mFlags, static_cast< Uint16 >(ENF_LOCKED));
// Now attempt to destroy this entity from the server
_Func->RemoveKeyBind(mID);
}
// Reset the instance to it's initial state
ResetInstance();
// Don't release the callbacks abruptly
DropEvents();
}
// ------------------------------------------------------------------------------------------------
void Core::ObjectInst::Destroy(bool destroy, Int32 header, LightObj & payload)
{
// Should we notify that this entity is being cleaned up?
if (VALID_ENTITY(mID))
{
// Don't leave exceptions to prevent us from releasing this instance
try
{
Core::Get().EmitObjectDestroyed(mID, header, payload);
}
SQMOD_CATCH_EVENT_EXCEPTION("while destroying object")
}
// Is there a manager instance associated with this entity?
if (mInst)
{
// Prevent further use of this entity
mInst->m_ID = -1;
// Release user data to avoid dangling or circular references
mInst->m_Data.Release();
}
// Prevent further use of the manager instance
mInst = nullptr;
// Release the script object, if any
mObj.Release();
// Release tasks, if any
CleanupTasks(mID, ENT_OBJECT);
// Are we supposed to clean up this entity? (only at reload)
if (destroy && VALID_ENTITY(mID) && (mFlags & ENF_OWNED))
{
// Block the entity pool changes notification from triggering the destroy event
const BitGuardU16 bg(mFlags, static_cast< Uint16 >(ENF_LOCKED));
// Now attempt to destroy this entity from the server
_Func->DeleteObject(mID);
}
// Reset the instance to it's initial state
ResetInstance();
// Don't release the callbacks abruptly
DropEvents();
}
// ------------------------------------------------------------------------------------------------
void Core::PickupInst::Destroy(bool destroy, Int32 header, LightObj & payload)
{
// Should we notify that this entity is being cleaned up?
if (VALID_ENTITY(mID))
{
// Don't leave exceptions to prevent us from releasing this instance
try
{
Core::Get().EmitPickupDestroyed(mID, header, payload);
}
SQMOD_CATCH_EVENT_EXCEPTION("while destroying pickup")
}
// Is there a manager instance associated with this entity?
if (mInst)
{
// Prevent further use of this entity
mInst->m_ID = -1;
// Release user data to avoid dangling or circular references
mInst->m_Data.Release();
}
// Prevent further use of the manager instance
mInst = nullptr;
// Release the script object, if any
mObj.Release();
// Release tasks, if any
CleanupTasks(mID, ENT_PICKUP);
// Are we supposed to clean up this entity? (only at reload)
if (destroy && VALID_ENTITY(mID) && (mFlags & ENF_OWNED))
{
// Block the entity pool changes notification from triggering the destroy event
const BitGuardU16 bg(mFlags, static_cast< Uint16 >(ENF_LOCKED));
// Now attempt to destroy this entity from the server
_Func->DeletePickup(mID);
}
// Reset the instance to it's initial state
ResetInstance();
// Don't release the callbacks abruptly
DropEvents();
}
// ------------------------------------------------------------------------------------------------
void Core::PlayerInst::Destroy(bool /*destroy*/, Int32 header, LightObj & payload)
{
// Should we notify that this entity is being cleaned up?
if (VALID_ENTITY(mID))
{
// Don't leave exceptions to prevent us from releasing this instance
try
{
Core::Get().EmitPlayerDestroyed(mID, header, payload);
}
SQMOD_CATCH_EVENT_EXCEPTION("while destroying player")
}
// Is there a manager instance associated with this entity?
if (mInst)
{
// Prevent further use of this entity
mInst->m_ID = -1;
// Release user data to avoid dangling or circular references
mInst->m_Data.Release();
// Release the used memory buffer
mInst->m_Buffer.ResetAll();
}
// Prevent further use of the manager instance
mInst = nullptr;
// Release the script object, if any
mObj.Release();
// Release tasks, if any
CleanupTasks(mID, ENT_PLAYER);
// Reset the instance to it's initial state
ResetInstance();
// Don't release the callbacks abruptly
DropEvents();
}
// ------------------------------------------------------------------------------------------------
void Core::VehicleInst::Destroy(bool destroy, Int32 header, LightObj & payload)
{
// Should we notify that this entity is being cleaned up?
if (VALID_ENTITY(mID))
{
// Don't leave exceptions to prevent us from releasing this instance
try
{
Core::Get().EmitVehicleDestroyed(mID, header, payload);
}
SQMOD_CATCH_EVENT_EXCEPTION("while destroying vehicle")
}
// Is there a manager instance associated with this entity?
if (mInst)
{
// Prevent further use of this entity
mInst->m_ID = -1;
// Release user data to avoid dangling or circular references
mInst->m_Data.Release();
}
// Prevent further use of the manager instance
mInst = nullptr;
// Release the script object, if any
mObj.Release();
// Release tasks, if any
CleanupTasks(mID, ENT_VEHICLE);
// Are we supposed to clean up this entity? (only at reload)
if (destroy && VALID_ENTITY(mID) && (mFlags & ENF_OWNED))
{
// Block the entity pool changes notification from triggering the destroy event
const BitGuardU16 bg(mFlags, static_cast< Uint16 >(ENF_LOCKED));
// Now attempt to destroy this entity from the server
_Func->DeleteVehicle(mID);
}
// Reset the instance to it's initial state
ResetInstance();
// Don't release the callbacks abruptly
DropEvents();
}
// ------------------------------------------------------------------------------------------------
void Core::BlipInst::ResetInstance()
{
mID = -1;
mFlags = ENF_DEFAULT;
mWorld = -1;
mScale = -1;
mSprID = -1;
mPosition.Clear();
mColor.Clear();
}
// ------------------------------------------------------------------------------------------------
void Core::CheckpointInst::ResetInstance()
{
mID = -1;
mFlags = ENF_DEFAULT;
}
// ------------------------------------------------------------------------------------------------
void Core::KeybindInst::ResetInstance()
{
mID = -1;
mFlags = ENF_DEFAULT;
mFirst = -1;
mSecond = -1;
mThird = -1;
mRelease = -1;
}
// ------------------------------------------------------------------------------------------------
void Core::ObjectInst::ResetInstance()
{
mID = -1;
mFlags = ENF_DEFAULT;
}
// ------------------------------------------------------------------------------------------------
void Core::PickupInst::ResetInstance()
{
mID = -1;
mFlags = ENF_DEFAULT;
}
// ------------------------------------------------------------------------------------------------
void Core::PlayerInst::ResetInstance()
{
mID = -1;
mFlags = ENF_DEFAULT;
mTrackPosition = 0;
mTrackHeading = 0;
mTrackPositionHeader = 0;
mTrackPositionPayload.Release();
mKickBanHeader = 0;
mKickBanPayload.Release();
mLastWeapon = -1;
mLastHealth = 0.0;
mLastArmour = 0.0;
mLastHeading = 0.0;
mLastPosition.Clear();
mAuthority = 0;
}
// ------------------------------------------------------------------------------------------------
void Core::VehicleInst::ResetInstance()
{
mID = -1;
mFlags = ENF_DEFAULT;
mTrackPosition = 0;
mTrackRotation = 0;
mLastPrimaryColor = -1;
mLastSecondaryColor = -1;
mLastHealth = 0.0;
mLastPosition.Clear();
mLastRotation.Clear();
}
// ------------------------------------------------------------------------------------------------
void Core::BlipInst::InitEvents()
{
// Ignore the call if already initialized
if (!mEvents.IsNull())
{
return;
}
// Create a new table on the stack
sq_newtableex(DefaultVM::Get(), 4);
// Grab the table object from the stack
mEvents = LightObj(-1, DefaultVM::Get());
// Pop the table object from the stack
sq_pop(DefaultVM::Get(), 1);
// Proceed to initializing the events
InitSignalPair(mOnDestroyed, mEvents, "Destroyed");
InitSignalPair(mOnCustom, mEvents, "Custom");
}
// ------------------------------------------------------------------------------------------------
void Core::BlipInst::DropEvents()
{
ResetSignalPair(mOnDestroyed);
ResetSignalPair(mOnCustom);
mEvents.Release();
}
// ------------------------------------------------------------------------------------------------
void Core::CheckpointInst::InitEvents()
{
// Ignore the call if already initialized
if (!mEvents.IsNull())
{
return;
}
// Create a new table on the stack
sq_newtableex(DefaultVM::Get(), 8);
// Grab the table object from the stack
mEvents = LightObj(-1, DefaultVM::Get());
// Pop the table object from the stack
sq_pop(DefaultVM::Get(), 1);
// Proceed to initializing the events
InitSignalPair(mOnDestroyed, mEvents, "Destroyed");
InitSignalPair(mOnCustom, mEvents, "Custom");
InitSignalPair(mOnEntered, mEvents, "Entered");
InitSignalPair(mOnExited, mEvents, "Exited");
InitSignalPair(mOnWorld, mEvents, "World");
InitSignalPair(mOnRadius, mEvents, "Radius");
}
// ------------------------------------------------------------------------------------------------
void Core::CheckpointInst::DropEvents()
{
ResetSignalPair(mOnDestroyed);
ResetSignalPair(mOnCustom);
ResetSignalPair(mOnEntered);
ResetSignalPair(mOnExited);
ResetSignalPair(mOnWorld);
ResetSignalPair(mOnRadius);
mEvents.Release();
}
// ------------------------------------------------------------------------------------------------
void Core::KeybindInst::InitEvents()
{
// Ignore the call if already initialized
if (!mEvents.IsNull())
{
return;
}
// Create a new table on the stack
sq_newtableex(DefaultVM::Get(), 8);
// Grab the table object from the stack
mEvents = LightObj(-1, DefaultVM::Get());
// Pop the table object from the stack
sq_pop(DefaultVM::Get(), 1);
// Proceed to initializing the events
InitSignalPair(mOnDestroyed, mEvents, "Destroyed");
InitSignalPair(mOnCustom, mEvents, "Custom");
InitSignalPair(mOnKeyPress, mEvents, "KeyPress");
InitSignalPair(mOnKeyRelease, mEvents, "KeyRelease");
}
// ------------------------------------------------------------------------------------------------
void Core::KeybindInst::DropEvents()
{
ResetSignalPair(mOnDestroyed);
ResetSignalPair(mOnCustom);
ResetSignalPair(mOnKeyPress);
ResetSignalPair(mOnKeyRelease);
mEvents.Release();
}
// ------------------------------------------------------------------------------------------------
void Core::ObjectInst::InitEvents()
{
// Ignore the call if already initialized
if (!mEvents.IsNull())
{
return;
}
// Create a new table on the stack
sq_newtableex(DefaultVM::Get(), 12);
// Grab the table object from the stack
mEvents = LightObj(-1, DefaultVM::Get());
// Pop the table object from the stack
sq_pop(DefaultVM::Get(), 1);
// Proceed to initializing the events
InitSignalPair(mOnDestroyed, mEvents, "Destroyed");
InitSignalPair(mOnCustom, mEvents, "Custom");
InitSignalPair(mOnShot, mEvents, "Shot");
InitSignalPair(mOnTouched, mEvents, "Touched");
InitSignalPair(mOnWorld, mEvents, "World");
InitSignalPair(mOnAlpha, mEvents, "Alpha");
InitSignalPair(mOnReport, mEvents, "Report");
}
// ------------------------------------------------------------------------------------------------
void Core::ObjectInst::DropEvents()
{
ResetSignalPair(mOnDestroyed);
ResetSignalPair(mOnCustom);
ResetSignalPair(mOnShot);
ResetSignalPair(mOnTouched);
ResetSignalPair(mOnWorld);
ResetSignalPair(mOnAlpha);
ResetSignalPair(mOnReport);
mEvents.Release();
}
// ------------------------------------------------------------------------------------------------
void Core::PickupInst::InitEvents()
{
// Ignore the call if already initialized
if (!mEvents.IsNull())
{
return;
}
// Create a new table on the stack
sq_newtableex(DefaultVM::Get(), 16);
// Grab the table object from the stack
mEvents = LightObj(-1, DefaultVM::Get());
// Pop the table object from the stack
sq_pop(DefaultVM::Get(), 1);
// Proceed to initializing the events
InitSignalPair(mOnDestroyed, mEvents, "Destroyed");
InitSignalPair(mOnCustom, mEvents, "Custom");
InitSignalPair(mOnRespawn, mEvents, "Respawn");
InitSignalPair(mOnClaimed, mEvents, "Claimed");
InitSignalPair(mOnCollected, mEvents, "Collected");
InitSignalPair(mOnWorld, mEvents, "World");
InitSignalPair(mOnAlpha, mEvents, "Alpha");
InitSignalPair(mOnAutomatic, mEvents, "Automatic");
InitSignalPair(mOnAutoTimer, mEvents, "AutoTimer");
}
// ------------------------------------------------------------------------------------------------
void Core::PickupInst::DropEvents()
{
ResetSignalPair(mOnDestroyed);
ResetSignalPair(mOnCustom);
ResetSignalPair(mOnRespawn);
ResetSignalPair(mOnClaimed);
ResetSignalPair(mOnCollected);
ResetSignalPair(mOnWorld);
ResetSignalPair(mOnAlpha);
ResetSignalPair(mOnAutomatic);
ResetSignalPair(mOnAutoTimer);
mEvents.Release();
}
// ------------------------------------------------------------------------------------------------
void Core::PlayerInst::InitEvents()
{
// Ignore the call if already initialized
if (!mEvents.IsNull())
{
return;
}
// Create a new table on the stack
sq_newtableex(DefaultVM::Get(), 86);
// Grab the table object from the stack
mEvents = LightObj(-1, DefaultVM::Get());
// Pop the table object from the stack
sq_pop(DefaultVM::Get(), 1);
// Proceed to initializing the events
InitSignalPair(mOnDestroyed, mEvents, "Destroyed");
InitSignalPair(mOnCustom, mEvents, "Custom");
InitSignalPair(mOnRequestClass, mEvents, "RequestClass");
InitSignalPair(mOnRequestSpawn, mEvents, "RequestSpawn");
InitSignalPair(mOnSpawn, mEvents, "Spawn");
InitSignalPair(mOnWasted, mEvents, "Wasted");
InitSignalPair(mOnKilled, mEvents, "Killed");
InitSignalPair(mOnEmbarking, mEvents, "Embarking");
InitSignalPair(mOnEmbarked, mEvents, "Embarked");
InitSignalPair(mOnDisembark, mEvents, "Disembark");
InitSignalPair(mOnRename, mEvents, "Rename");
InitSignalPair(mOnState, mEvents, "State");
InitSignalPair(mOnStateNone, mEvents, "StateNone");
InitSignalPair(mOnStateNormal, mEvents, "StateNormal");
InitSignalPair(mOnStateAim, mEvents, "StateAim");
InitSignalPair(mOnStateDriver, mEvents, "StateDriver");
InitSignalPair(mOnStatePassenger, mEvents, "StatePassenger");
InitSignalPair(mOnStateEnterDriver, mEvents, "StateEnterDriver");
InitSignalPair(mOnStateEnterPassenger, mEvents, "StateEnterPassenger");
InitSignalPair(mOnStateExit, mEvents, "StateExit");
InitSignalPair(mOnStateUnspawned, mEvents, "StateUnspawned");
InitSignalPair(mOnAction, mEvents, "Action");
InitSignalPair(mOnActionNone, mEvents, "ActionNone");
InitSignalPair(mOnActionNormal, mEvents, "ActionNormal");
InitSignalPair(mOnActionAiming, mEvents, "ActionAiming");
InitSignalPair(mOnActionShooting, mEvents, "ActionShooting");
InitSignalPair(mOnActionJumping, mEvents, "ActionJumping");
InitSignalPair(mOnActionLieDown, mEvents, "ActionLieDown");
InitSignalPair(mOnActionGettingUp, mEvents, "ActionGettingUp");
InitSignalPair(mOnActionJumpVehicle, mEvents, "ActionJumpVehicle");
InitSignalPair(mOnActionDriving, mEvents, "ActionDriving");
InitSignalPair(mOnActionDying, mEvents, "ActionDying");
InitSignalPair(mOnActionWasted, mEvents, "ActionWasted");
InitSignalPair(mOnActionEmbarking, mEvents, "ActionEmbarking");
InitSignalPair(mOnActionDisembarking, mEvents, "ActionDisembarking");
InitSignalPair(mOnBurning, mEvents, "Burning");
InitSignalPair(mOnCrouching, mEvents, "Crouching");
InitSignalPair(mOnGameKeys, mEvents, "GameKeys");
InitSignalPair(mOnStartTyping, mEvents, "StartTyping");
InitSignalPair(mOnStopTyping, mEvents, "StopTyping");
InitSignalPair(mOnAway, mEvents, "Away");
InitSignalPair(mOnMessage, mEvents, "Message");
InitSignalPair(mOnCommand, mEvents, "Command");
InitSignalPair(mOnPrivateMessage, mEvents, "PrivateMessage");
InitSignalPair(mOnKeyPress, mEvents, "KeyPress");
InitSignalPair(mOnKeyRelease, mEvents, "KeyRelease");
InitSignalPair(mOnSpectate, mEvents, "Spectate");
InitSignalPair(mOnCrashreport, mEvents, "Crashreport");
InitSignalPair(mOnObjectShot, mEvents, "ObjectShot");
InitSignalPair(mOnObjectTouched, mEvents, "ObjectTouched");
InitSignalPair(mOnPickupClaimed, mEvents, "PickupClaimed");
InitSignalPair(mOnPickupCollected, mEvents, "PickupCollected");
InitSignalPair(mOnCheckpointEntered, mEvents, "CheckpointEntered");
InitSignalPair(mOnCheckpointExited, mEvents, "CheckpointExited");
InitSignalPair(mOnClientScriptData, mEvents, "ClientScriptData");
InitSignalPair(mOnUpdate, mEvents, "Update");
InitSignalPair(mOnHealth, mEvents, "Health");
InitSignalPair(mOnArmour, mEvents, "Armour");
InitSignalPair(mOnWeapon, mEvents, "Weapon");
InitSignalPair(mOnHeading, mEvents, "Heading");
InitSignalPair(mOnPosition, mEvents, "Position");
InitSignalPair(mOnOption, mEvents, "Option");
InitSignalPair(mOnAdmin, mEvents, "Admin");
InitSignalPair(mOnWorld, mEvents, "World");
InitSignalPair(mOnTeam, mEvents, "Team");
InitSignalPair(mOnSkin, mEvents, "Skin");
InitSignalPair(mOnMoney, mEvents, "Money");
InitSignalPair(mOnScore, mEvents, "Score");
InitSignalPair(mOnWantedLevel, mEvents, "WantedLevel");
InitSignalPair(mOnImmunity, mEvents, "Immunity");
InitSignalPair(mOnAlpha, mEvents, "Alpha");
}
// ------------------------------------------------------------------------------------------------
void Core::PlayerInst::DropEvents()
{
ResetSignalPair(mOnDestroyed);
ResetSignalPair(mOnCustom);
ResetSignalPair(mOnRequestClass);
ResetSignalPair(mOnRequestSpawn);
ResetSignalPair(mOnSpawn);
ResetSignalPair(mOnWasted);
ResetSignalPair(mOnKilled);
ResetSignalPair(mOnEmbarking);
ResetSignalPair(mOnEmbarked);
ResetSignalPair(mOnDisembark);
ResetSignalPair(mOnRename);
ResetSignalPair(mOnState);
ResetSignalPair(mOnStateNone);
ResetSignalPair(mOnStateNormal);
ResetSignalPair(mOnStateAim);
ResetSignalPair(mOnStateDriver);
ResetSignalPair(mOnStatePassenger);
ResetSignalPair(mOnStateEnterDriver);
ResetSignalPair(mOnStateEnterPassenger);
ResetSignalPair(mOnStateExit);
ResetSignalPair(mOnStateUnspawned);
ResetSignalPair(mOnAction);
ResetSignalPair(mOnActionNone);
ResetSignalPair(mOnActionNormal);
ResetSignalPair(mOnActionAiming);
ResetSignalPair(mOnActionShooting);
ResetSignalPair(mOnActionJumping);
ResetSignalPair(mOnActionLieDown);
ResetSignalPair(mOnActionGettingUp);
ResetSignalPair(mOnActionJumpVehicle);
ResetSignalPair(mOnActionDriving);
ResetSignalPair(mOnActionDying);
ResetSignalPair(mOnActionWasted);
ResetSignalPair(mOnActionEmbarking);
ResetSignalPair(mOnActionDisembarking);
ResetSignalPair(mOnBurning);
ResetSignalPair(mOnCrouching);
ResetSignalPair(mOnGameKeys);
ResetSignalPair(mOnStartTyping);
ResetSignalPair(mOnStopTyping);
ResetSignalPair(mOnAway);
ResetSignalPair(mOnMessage);
ResetSignalPair(mOnCommand);
ResetSignalPair(mOnPrivateMessage);
ResetSignalPair(mOnKeyPress);
ResetSignalPair(mOnKeyRelease);
ResetSignalPair(mOnSpectate);
ResetSignalPair(mOnCrashreport);
ResetSignalPair(mOnObjectShot);
ResetSignalPair(mOnObjectTouched);
ResetSignalPair(mOnPickupClaimed);
ResetSignalPair(mOnPickupCollected);
ResetSignalPair(mOnCheckpointEntered);
ResetSignalPair(mOnCheckpointExited);
ResetSignalPair(mOnClientScriptData);
ResetSignalPair(mOnUpdate);
ResetSignalPair(mOnHealth);
ResetSignalPair(mOnArmour);
ResetSignalPair(mOnWeapon);
ResetSignalPair(mOnHeading);
ResetSignalPair(mOnPosition);
ResetSignalPair(mOnOption);
ResetSignalPair(mOnAdmin);
ResetSignalPair(mOnWorld);
ResetSignalPair(mOnTeam);
ResetSignalPair(mOnSkin);
ResetSignalPair(mOnMoney);
ResetSignalPair(mOnScore);
ResetSignalPair(mOnWantedLevel);
ResetSignalPair(mOnImmunity);
ResetSignalPair(mOnAlpha);
mEvents.Release();
}
// ------------------------------------------------------------------------------------------------
void Core::VehicleInst::InitEvents()
{
// Ignore the call if already initialized
if (!mEvents.IsNull())
{
return;
}
// Create a new table on the stack
sq_newtableex(DefaultVM::Get(), 32);
// Grab the table object from the stack
mEvents = LightObj(-1, DefaultVM::Get());
// Pop the table object from the stack
sq_pop(DefaultVM::Get(), 1);
// Proceed to initializing the events
InitSignalPair(mOnDestroyed, mEvents, "Destroyed");
InitSignalPair(mOnCustom, mEvents, "Custom");
InitSignalPair(mOnEmbarking, mEvents, "Embarking");
InitSignalPair(mOnEmbarked, mEvents, "Embarked");
InitSignalPair(mOnDisembark, mEvents, "Disembark");
InitSignalPair(mOnExplode, mEvents, "Explode");
InitSignalPair(mOnRespawn, mEvents, "Respawn");
InitSignalPair(mOnUpdate, mEvents, "Update");
InitSignalPair(mOnColor, mEvents, "Color");
InitSignalPair(mOnHealth, mEvents, "Health");
InitSignalPair(mOnPosition, mEvents, "Position");
InitSignalPair(mOnRotation, mEvents, "Rotation");
InitSignalPair(mOnOption, mEvents, "Option");
InitSignalPair(mOnWorld, mEvents, "World");
InitSignalPair(mOnImmunity, mEvents, "Immunity");
InitSignalPair(mOnPartStatus, mEvents, "PartStatus");
InitSignalPair(mOnTyreStatus, mEvents, "TyreStatus");
InitSignalPair(mOnDamageData, mEvents, "DamageData");
InitSignalPair(mOnRadio, mEvents, "Radio");
InitSignalPair(mOnHandlingRule, mEvents, "HandlingRule");
}
// ------------------------------------------------------------------------------------------------
void Core::VehicleInst::DropEvents()
{
ResetSignalPair(mOnDestroyed);
ResetSignalPair(mOnCustom);
ResetSignalPair(mOnEmbarking);
ResetSignalPair(mOnEmbarked);
ResetSignalPair(mOnDisembark);
ResetSignalPair(mOnExplode);
ResetSignalPair(mOnRespawn);
ResetSignalPair(mOnUpdate);
ResetSignalPair(mOnColor);
ResetSignalPair(mOnHealth);
ResetSignalPair(mOnPosition);
ResetSignalPair(mOnRotation);
ResetSignalPair(mOnOption);
ResetSignalPair(mOnWorld);
ResetSignalPair(mOnImmunity);
ResetSignalPair(mOnPartStatus);
ResetSignalPair(mOnTyreStatus);
ResetSignalPair(mOnDamageData);
ResetSignalPair(mOnRadio);
ResetSignalPair(mOnHandlingRule);
mEvents.Release();
}
} // Namespace:: SqMod

View File

@ -42,691 +42,272 @@ void Core::ClearContainer(EntityType type)
}
// ------------------------------------------------------------------------------------------------
void Core::ResetInst(BlipInst & inst)
void Core::InitEvents()
{
inst.mID = -1;
inst.mFlags = ENF_DEFAULT;
inst.mWorld = -1;
inst.mScale = -1;
inst.mSprID = -1;
inst.mPosition.Clear();
inst.mColor.Clear();
}
// ------------------------------------------------------------------------------------------------
void Core::ResetInst(CheckpointInst & inst)
{
inst.mID = -1;
inst.mFlags = ENF_DEFAULT;
}
// ------------------------------------------------------------------------------------------------
void Core::ResetInst(KeybindInst & inst)
{
inst.mID = -1;
inst.mFlags = ENF_DEFAULT;
inst.mFirst = -1;
inst.mSecond = -1;
inst.mThird = -1;
inst.mRelease = -1;
}
// ------------------------------------------------------------------------------------------------
void Core::ResetInst(ObjectInst & inst)
{
inst.mID = -1;
inst.mFlags = ENF_DEFAULT;
}
// ------------------------------------------------------------------------------------------------
void Core::ResetInst(PickupInst & inst)
{
inst.mID = -1;
inst.mFlags = ENF_DEFAULT;
}
// ------------------------------------------------------------------------------------------------
void Core::ResetInst(PlayerInst & inst)
{
inst.mID = -1;
inst.mFlags = ENF_DEFAULT;
inst.mTrackPosition = 0;
inst.mTrackHeading = 0;
inst.mTrackPositionHeader = 0;
inst.mTrackPositionPayload.Release();
inst.mKickBanHeader = 0;
inst.mKickBanPayload.Release();
inst.mLastWeapon = -1;
inst.mLastHealth = 0.0;
inst.mLastArmour = 0.0;
inst.mLastHeading = 0.0;
inst.mLastPosition.Clear();
inst.mAuthority = 0;
}
// ------------------------------------------------------------------------------------------------
void Core::ResetInst(VehicleInst & inst)
{
inst.mID = -1;
inst.mFlags = ENF_DEFAULT;
inst.mTrackPosition = 0;
inst.mTrackRotation = 0;
inst.mLastPrimaryColor = -1;
inst.mLastSecondaryColor = -1;
inst.mLastHealth = 0.0;
inst.mLastPosition.Clear();
inst.mLastRotation.Clear();
}
// ------------------------------------------------------------------------------------------------
void Core::ResetFunc(BlipInst & inst)
{
inst.mOnDestroyed.ReleaseGently();
inst.mOnCustom.ReleaseGently();
}
// ------------------------------------------------------------------------------------------------
void Core::ResetFunc(CheckpointInst & inst)
{
inst.mOnDestroyed.ReleaseGently();
inst.mOnCustom.ReleaseGently();
inst.mOnEntered.ReleaseGently();
inst.mOnExited.ReleaseGently();
inst.mOnWorld.ReleaseGently();
inst.mOnRadius.ReleaseGently();
}
// ------------------------------------------------------------------------------------------------
void Core::ResetFunc(KeybindInst & inst)
{
inst.mOnDestroyed.ReleaseGently();
inst.mOnCustom.ReleaseGently();
inst.mOnKeyPress.ReleaseGently();
inst.mOnKeyRelease.ReleaseGently();
}
// ------------------------------------------------------------------------------------------------
void Core::ResetFunc(ObjectInst & inst)
{
inst.mOnDestroyed.ReleaseGently();
inst.mOnCustom.ReleaseGently();
inst.mOnShot.ReleaseGently();
inst.mOnTouched.ReleaseGently();
inst.mOnWorld.ReleaseGently();
inst.mOnAlpha.ReleaseGently();
inst.mOnReport.ReleaseGently();
}
// ------------------------------------------------------------------------------------------------
void Core::ResetFunc(PickupInst & inst)
{
inst.mOnDestroyed.ReleaseGently();
inst.mOnCustom.ReleaseGently();
inst.mOnRespawn.ReleaseGently();
inst.mOnClaimed.ReleaseGently();
inst.mOnCollected.ReleaseGently();
inst.mOnWorld.ReleaseGently();
inst.mOnAlpha.ReleaseGently();
inst.mOnAutomatic.ReleaseGently();
inst.mOnAutoTimer.ReleaseGently();
}
// ------------------------------------------------------------------------------------------------
void Core::ResetFunc(PlayerInst & inst)
{
inst.mOnDestroyed.ReleaseGently();
inst.mOnCustom.ReleaseGently();
inst.mOnRequestClass.ReleaseGently();
inst.mOnRequestSpawn.ReleaseGently();
inst.mOnSpawn.ReleaseGently();
inst.mOnWasted.ReleaseGently();
inst.mOnKilled.ReleaseGently();
inst.mOnEmbarking.ReleaseGently();
inst.mOnEmbarked.ReleaseGently();
inst.mOnDisembark.ReleaseGently();
inst.mOnRename.ReleaseGently();
inst.mOnState.ReleaseGently();
inst.mOnStateNone.ReleaseGently();
inst.mOnStateNormal.ReleaseGently();
inst.mOnStateAim.ReleaseGently();
inst.mOnStateDriver.ReleaseGently();
inst.mOnStatePassenger.ReleaseGently();
inst.mOnStateEnterDriver.ReleaseGently();
inst.mOnStateEnterPassenger.ReleaseGently();
inst.mOnStateExit.ReleaseGently();
inst.mOnStateUnspawned.ReleaseGently();
inst.mOnAction.ReleaseGently();
inst.mOnActionNone.ReleaseGently();
inst.mOnActionNormal.ReleaseGently();
inst.mOnActionAiming.ReleaseGently();
inst.mOnActionShooting.ReleaseGently();
inst.mOnActionJumping.ReleaseGently();
inst.mOnActionLieDown.ReleaseGently();
inst.mOnActionGettingUp.ReleaseGently();
inst.mOnActionJumpVehicle.ReleaseGently();
inst.mOnActionDriving.ReleaseGently();
inst.mOnActionDying.ReleaseGently();
inst.mOnActionWasted.ReleaseGently();
inst.mOnActionEmbarking.ReleaseGently();
inst.mOnActionDisembarking.ReleaseGently();
inst.mOnBurning.ReleaseGently();
inst.mOnCrouching.ReleaseGently();
inst.mOnGameKeys.ReleaseGently();
inst.mOnStartTyping.ReleaseGently();
inst.mOnStopTyping.ReleaseGently();
inst.mOnAway.ReleaseGently();
inst.mOnMessage.ReleaseGently();
inst.mOnCommand.ReleaseGently();
inst.mOnPrivateMessage.ReleaseGently();
inst.mOnKeyPress.ReleaseGently();
inst.mOnKeyRelease.ReleaseGently();
inst.mOnSpectate.ReleaseGently();
inst.mOnCrashreport.ReleaseGently();
inst.mOnObjectShot.ReleaseGently();
inst.mOnObjectTouched.ReleaseGently();
inst.mOnPickupClaimed.ReleaseGently();
inst.mOnPickupCollected.ReleaseGently();
inst.mOnCheckpointEntered.ReleaseGently();
inst.mOnCheckpointExited.ReleaseGently();
inst.mOnClientScriptData.ReleaseGently();
inst.mOnUpdate.ReleaseGently();
inst.mOnHealth.ReleaseGently();
inst.mOnArmour.ReleaseGently();
inst.mOnWeapon.ReleaseGently();
inst.mOnHeading.ReleaseGently();
inst.mOnPosition.ReleaseGently();
inst.mOnOption.ReleaseGently();
inst.mOnAdmin.ReleaseGently();
inst.mOnWorld.ReleaseGently();
inst.mOnTeam.ReleaseGently();
inst.mOnSkin.ReleaseGently();
inst.mOnMoney.ReleaseGently();
inst.mOnScore.ReleaseGently();
inst.mOnWantedLevel.ReleaseGently();
inst.mOnImmunity.ReleaseGently();
inst.mOnAlpha.ReleaseGently();
}
// ------------------------------------------------------------------------------------------------
void Core::ResetFunc(VehicleInst & inst)
{
inst.mOnDestroyed.ReleaseGently();
inst.mOnCustom.ReleaseGently();
inst.mOnEmbarking.ReleaseGently();
inst.mOnEmbarked.ReleaseGently();
inst.mOnDisembark.ReleaseGently();
inst.mOnExplode.ReleaseGently();
inst.mOnRespawn.ReleaseGently();
inst.mOnUpdate.ReleaseGently();
inst.mOnColor.ReleaseGently();
inst.mOnHealth.ReleaseGently();
inst.mOnPosition.ReleaseGently();
inst.mOnRotation.ReleaseGently();
inst.mOnOption.ReleaseGently();
inst.mOnWorld.ReleaseGently();
inst.mOnImmunity.ReleaseGently();
inst.mOnPartStatus.ReleaseGently();
inst.mOnTyreStatus.ReleaseGently();
inst.mOnDamageData.ReleaseGently();
inst.mOnRadio.ReleaseGently();
inst.mOnHandlingRule.ReleaseGently();
}
// ------------------------------------------------------------------------------------------------
void Core::ResetFunc()
{
Core::Get().mOnCustomEvent.ReleaseGently();
Core::Get().mOnBlipCreated.ReleaseGently();
Core::Get().mOnCheckpointCreated.ReleaseGently();
Core::Get().mOnKeybindCreated.ReleaseGently();
Core::Get().mOnObjectCreated.ReleaseGently();
Core::Get().mOnPickupCreated.ReleaseGently();
Core::Get().mOnPlayerCreated.ReleaseGently();
Core::Get().mOnVehicleCreated.ReleaseGently();
Core::Get().mOnBlipDestroyed.ReleaseGently();
Core::Get().mOnCheckpointDestroyed.ReleaseGently();
Core::Get().mOnKeybindDestroyed.ReleaseGently();
Core::Get().mOnObjectDestroyed.ReleaseGently();
Core::Get().mOnPickupDestroyed.ReleaseGently();
Core::Get().mOnPlayerDestroyed.ReleaseGently();
Core::Get().mOnVehicleDestroyed.ReleaseGently();
Core::Get().mOnBlipCustom.ReleaseGently();
Core::Get().mOnCheckpointCustom.ReleaseGently();
Core::Get().mOnKeybindCustom.ReleaseGently();
Core::Get().mOnObjectCustom.ReleaseGently();
Core::Get().mOnPickupCustom.ReleaseGently();
Core::Get().mOnPlayerCustom.ReleaseGently();
Core::Get().mOnVehicleCustom.ReleaseGently();
Core::Get().mOnServerStartup.ReleaseGently();
Core::Get().mOnServerShutdown.ReleaseGently();
Core::Get().mOnServerFrame.ReleaseGently();
Core::Get().mOnIncomingConnection.ReleaseGently();
Core::Get().mOnPlayerRequestClass.ReleaseGently();
Core::Get().mOnPlayerRequestSpawn.ReleaseGently();
Core::Get().mOnPlayerSpawn.ReleaseGently();
Core::Get().mOnPlayerWasted.ReleaseGently();
Core::Get().mOnPlayerKilled.ReleaseGently();
Core::Get().mOnPlayerEmbarking.ReleaseGently();
Core::Get().mOnPlayerEmbarked.ReleaseGently();
Core::Get().mOnPlayerDisembark.ReleaseGently();
Core::Get().mOnPlayerRename.ReleaseGently();
Core::Get().mOnPlayerState.ReleaseGently();
Core::Get().mOnStateNone.ReleaseGently();
Core::Get().mOnStateNormal.ReleaseGently();
Core::Get().mOnStateAim.ReleaseGently();
Core::Get().mOnStateDriver.ReleaseGently();
Core::Get().mOnStatePassenger.ReleaseGently();
Core::Get().mOnStateEnterDriver.ReleaseGently();
Core::Get().mOnStateEnterPassenger.ReleaseGently();
Core::Get().mOnStateExit.ReleaseGently();
Core::Get().mOnStateUnspawned.ReleaseGently();
Core::Get().mOnPlayerAction.ReleaseGently();
Core::Get().mOnActionNone.ReleaseGently();
Core::Get().mOnActionNormal.ReleaseGently();
Core::Get().mOnActionAiming.ReleaseGently();
Core::Get().mOnActionShooting.ReleaseGently();
Core::Get().mOnActionJumping.ReleaseGently();
Core::Get().mOnActionLieDown.ReleaseGently();
Core::Get().mOnActionGettingUp.ReleaseGently();
Core::Get().mOnActionJumpVehicle.ReleaseGently();
Core::Get().mOnActionDriving.ReleaseGently();
Core::Get().mOnActionDying.ReleaseGently();
Core::Get().mOnActionWasted.ReleaseGently();
Core::Get().mOnActionEmbarking.ReleaseGently();
Core::Get().mOnActionDisembarking.ReleaseGently();
Core::Get().mOnPlayerBurning.ReleaseGently();
Core::Get().mOnPlayerCrouching.ReleaseGently();
Core::Get().mOnPlayerGameKeys.ReleaseGently();
Core::Get().mOnPlayerStartTyping.ReleaseGently();
Core::Get().mOnPlayerStopTyping.ReleaseGently();
Core::Get().mOnPlayerAway.ReleaseGently();
Core::Get().mOnPlayerMessage.ReleaseGently();
Core::Get().mOnPlayerCommand.ReleaseGently();
Core::Get().mOnPlayerPrivateMessage.ReleaseGently();
Core::Get().mOnPlayerKeyPress.ReleaseGently();
Core::Get().mOnPlayerKeyRelease.ReleaseGently();
Core::Get().mOnPlayerSpectate.ReleaseGently();
Core::Get().mOnPlayerCrashreport.ReleaseGently();
Core::Get().mOnVehicleExplode.ReleaseGently();
Core::Get().mOnVehicleRespawn.ReleaseGently();
Core::Get().mOnObjectShot.ReleaseGently();
Core::Get().mOnObjectTouched.ReleaseGently();
Core::Get().mOnObjectWorld.ReleaseGently();
Core::Get().mOnObjectAlpha.ReleaseGently();
Core::Get().mOnObjectReport.ReleaseGently();
Core::Get().mOnPickupClaimed.ReleaseGently();
Core::Get().mOnPickupCollected.ReleaseGently();
Core::Get().mOnPickupRespawn.ReleaseGently();
Core::Get().mOnPickupWorld.ReleaseGently();
Core::Get().mOnPickupAlpha.ReleaseGently();
Core::Get().mOnPickupAutomatic.ReleaseGently();
Core::Get().mOnPickupAutoTimer.ReleaseGently();
Core::Get().mOnCheckpointEntered.ReleaseGently();
Core::Get().mOnCheckpointExited.ReleaseGently();
Core::Get().mOnCheckpointWorld.ReleaseGently();
Core::Get().mOnCheckpointRadius.ReleaseGently();
Core::Get().mOnEntityPool.ReleaseGently();
Core::Get().mOnClientScriptData.ReleaseGently();
Core::Get().mOnPlayerUpdate.ReleaseGently();
Core::Get().mOnVehicleUpdate.ReleaseGently();
Core::Get().mOnPlayerHealth.ReleaseGently();
Core::Get().mOnPlayerArmour.ReleaseGently();
Core::Get().mOnPlayerWeapon.ReleaseGently();
Core::Get().mOnPlayerHeading.ReleaseGently();
Core::Get().mOnPlayerPosition.ReleaseGently();
Core::Get().mOnPlayerOption.ReleaseGently();
Core::Get().mOnPlayerAdmin.ReleaseGently();
Core::Get().mOnPlayerWorld.ReleaseGently();
Core::Get().mOnPlayerTeam.ReleaseGently();
Core::Get().mOnPlayerSkin.ReleaseGently();
Core::Get().mOnPlayerMoney.ReleaseGently();
Core::Get().mOnPlayerScore.ReleaseGently();
Core::Get().mOnPlayerWantedLevel.ReleaseGently();
Core::Get().mOnPlayerImmunity.ReleaseGently();
Core::Get().mOnPlayerAlpha.ReleaseGently();
Core::Get().mOnVehicleColor.ReleaseGently();
Core::Get().mOnVehicleHealth.ReleaseGently();
Core::Get().mOnVehiclePosition.ReleaseGently();
Core::Get().mOnVehicleRotation.ReleaseGently();
Core::Get().mOnVehicleOption.ReleaseGently();
Core::Get().mOnVehicleWorld.ReleaseGently();
Core::Get().mOnVehicleImmunity.ReleaseGently();
Core::Get().mOnVehiclePartStatus.ReleaseGently();
Core::Get().mOnVehicleTyreStatus.ReleaseGently();
Core::Get().mOnVehicleDamageData.ReleaseGently();
Core::Get().mOnVehicleRadio.ReleaseGently();
Core::Get().mOnVehicleHandlingRule.ReleaseGently();
Core::Get().mOnServerOption.ReleaseGently();
Core::Get().mOnScriptReload.ReleaseGently();
Core::Get().mOnScriptLoaded.ReleaseGently();
}
// ------------------------------------------------------------------------------------------------
Function & Core::GetEvent(Int32 evid)
{
switch (evid)
// Ignore the call if already initialized
if (!m_Events.IsNull())
{
case EVT_CUSTOMEVENT: return mOnCustomEvent;
case EVT_BLIPCREATED: return mOnBlipCreated;
case EVT_CHECKPOINTCREATED: return mOnCheckpointCreated;
case EVT_KEYBINDCREATED: return mOnKeybindCreated;
case EVT_OBJECTCREATED: return mOnObjectCreated;
case EVT_PICKUPCREATED: return mOnPickupCreated;
case EVT_PLAYERCREATED: return mOnPlayerCreated;
case EVT_VEHICLECREATED: return mOnVehicleCreated;
case EVT_BLIPDESTROYED: return mOnBlipDestroyed;
case EVT_CHECKPOINTDESTROYED: return mOnCheckpointDestroyed;
case EVT_KEYBINDDESTROYED: return mOnKeybindDestroyed;
case EVT_OBJECTDESTROYED: return mOnObjectDestroyed;
case EVT_PICKUPDESTROYED: return mOnPickupDestroyed;
case EVT_PLAYERDESTROYED: return mOnPlayerDestroyed;
case EVT_VEHICLEDESTROYED: return mOnVehicleDestroyed;
case EVT_BLIPCUSTOM: return mOnBlipCustom;
case EVT_CHECKPOINTCUSTOM: return mOnCheckpointCustom;
case EVT_KEYBINDCUSTOM: return mOnKeybindCustom;
case EVT_OBJECTCUSTOM: return mOnObjectCustom;
case EVT_PICKUPCUSTOM: return mOnPickupCustom;
case EVT_PLAYERCUSTOM: return mOnPlayerCustom;
case EVT_VEHICLECUSTOM: return mOnVehicleCustom;
case EVT_SERVERSTARTUP: return mOnServerStartup;
case EVT_SERVERSHUTDOWN: return mOnServerShutdown;
case EVT_SERVERFRAME: return mOnServerFrame;
case EVT_INCOMINGCONNECTION: return mOnIncomingConnection;
case EVT_PLAYERREQUESTCLASS: return mOnPlayerRequestClass;
case EVT_PLAYERREQUESTSPAWN: return mOnPlayerRequestSpawn;
case EVT_PLAYERSPAWN: return mOnPlayerSpawn;
case EVT_PLAYERWASTED: return mOnPlayerWasted;
case EVT_PLAYERKILLED: return mOnPlayerKilled;
case EVT_PLAYEREMBARKING: return mOnPlayerEmbarking;
case EVT_PLAYEREMBARKED: return mOnPlayerEmbarked;
case EVT_PLAYERDISEMBARK: return mOnPlayerDisembark;
case EVT_PLAYERRENAME: return mOnPlayerRename;
case EVT_PLAYERSTATE: return mOnPlayerState;
case EVT_STATENONE: return mOnStateNone;
case EVT_STATENORMAL: return mOnStateNormal;
case EVT_STATEAIM: return mOnStateAim;
case EVT_STATEDRIVER: return mOnStateDriver;
case EVT_STATEPASSENGER: return mOnStatePassenger;
case EVT_STATEENTERDRIVER: return mOnStateEnterDriver;
case EVT_STATEENTERPASSENGER: return mOnStateEnterPassenger;
case EVT_STATEEXIT: return mOnStateExit;
case EVT_STATEUNSPAWNED: return mOnStateUnspawned;
case EVT_PLAYERACTION: return mOnPlayerAction;
case EVT_ACTIONNONE: return mOnActionNone;
case EVT_ACTIONNORMAL: return mOnActionNormal;
case EVT_ACTIONAIMING: return mOnActionAiming;
case EVT_ACTIONSHOOTING: return mOnActionShooting;
case EVT_ACTIONJUMPING: return mOnActionJumping;
case EVT_ACTIONLIEDOWN: return mOnActionLieDown;
case EVT_ACTIONGETTINGUP: return mOnActionGettingUp;
case EVT_ACTIONJUMPVEHICLE: return mOnActionJumpVehicle;
case EVT_ACTIONDRIVING: return mOnActionDriving;
case EVT_ACTIONDYING: return mOnActionDying;
case EVT_ACTIONWASTED: return mOnActionWasted;
case EVT_ACTIONEMBARKING: return mOnActionEmbarking;
case EVT_ACTIONDISEMBARKING: return mOnActionDisembarking;
case EVT_PLAYERBURNING: return mOnPlayerBurning;
case EVT_PLAYERCROUCHING: return mOnPlayerCrouching;
case EVT_PLAYERGAMEKEYS: return mOnPlayerGameKeys;
case EVT_PLAYERSTARTTYPING: return mOnPlayerStartTyping;
case EVT_PLAYERSTOPTYPING: return mOnPlayerStopTyping;
case EVT_PLAYERAWAY: return mOnPlayerAway;
case EVT_PLAYERMESSAGE: return mOnPlayerMessage;
case EVT_PLAYERCOMMAND: return mOnPlayerCommand;
case EVT_PLAYERPRIVATEMESSAGE: return mOnPlayerPrivateMessage;
case EVT_PLAYERKEYPRESS: return mOnPlayerKeyPress;
case EVT_PLAYERKEYRELEASE: return mOnPlayerKeyRelease;
case EVT_PLAYERSPECTATE: return mOnPlayerSpectate;
case EVT_PLAYERCRASHREPORT: return mOnPlayerCrashreport;
case EVT_VEHICLEEXPLODE: return mOnVehicleExplode;
case EVT_VEHICLERESPAWN: return mOnVehicleRespawn;
case EVT_OBJECTSHOT: return mOnObjectShot;
case EVT_OBJECTTOUCHED: return mOnObjectTouched;
case EVT_OBJECTWORLD: return mOnObjectWorld;
case EVT_OBJECTALPHA: return mOnObjectAlpha;
case EVT_OBJECTREPORT: return mOnObjectReport;
case EVT_PICKUPCLAIMED: return mOnPickupClaimed;
case EVT_PICKUPCOLLECTED: return mOnPickupCollected;
case EVT_PICKUPRESPAWN: return mOnPickupRespawn;
case EVT_PICKUPWORLD: return mOnPickupWorld;
case EVT_PICKUPALPHA: return mOnPickupAlpha;
case EVT_PICKUPAUTOMATIC: return mOnPickupAutomatic;
case EVT_PICKUPAUTOTIMER: return mOnPickupAutoTimer;
case EVT_CHECKPOINTENTERED: return mOnCheckpointEntered;
case EVT_CHECKPOINTEXITED: return mOnCheckpointExited;
case EVT_CHECKPOINTWORLD: return mOnCheckpointWorld;
case EVT_CHECKPOINTRADIUS: return mOnCheckpointRadius;
case EVT_ENTITYPOOL: return mOnEntityPool;
case EVT_CLIENTSCRIPTDATA: return mOnClientScriptData;
case EVT_PLAYERUPDATE: return mOnPlayerUpdate;
case EVT_VEHICLEUPDATE: return mOnVehicleUpdate;
case EVT_PLAYERHEALTH: return mOnPlayerHealth;
case EVT_PLAYERARMOUR: return mOnPlayerArmour;
case EVT_PLAYERWEAPON: return mOnPlayerWeapon;
case EVT_PLAYERHEADING: return mOnPlayerHeading;
case EVT_PLAYERPOSITION: return mOnPlayerPosition;
case EVT_PLAYEROPTION: return mOnPlayerOption;
case EVT_PLAYERADMIN: return mOnPlayerAdmin;
case EVT_PLAYERWORLD: return mOnPlayerWorld;
case EVT_PLAYERTEAM: return mOnPlayerTeam;
case EVT_PLAYERSKIN: return mOnPlayerSkin;
case EVT_PLAYERMONEY: return mOnPlayerMoney;
case EVT_PLAYERSCORE: return mOnPlayerScore;
case EVT_PLAYERWANTEDLEVEL: return mOnPlayerWantedLevel;
case EVT_PLAYERIMMUNITY: return mOnPlayerImmunity;
case EVT_PLAYERALPHA: return mOnPlayerAlpha;
case EVT_VEHICLECOLOR: return mOnVehicleColor;
case EVT_VEHICLEHEALTH: return mOnVehicleHealth;
case EVT_VEHICLEPOSITION: return mOnVehiclePosition;
case EVT_VEHICLEROTATION: return mOnVehicleRotation;
case EVT_VEHICLEOPTION: return mOnVehicleOption;
case EVT_VEHICLEWORLD: return mOnVehicleWorld;
case EVT_VEHICLEIMMUNITY: return mOnVehicleImmunity;
case EVT_VEHICLEPARTSTATUS: return mOnVehiclePartStatus;
case EVT_VEHICLETYRESTATUS: return mOnVehicleTyreStatus;
case EVT_VEHICLEDAMAGEDATA: return mOnVehicleDamageData;
case EVT_VEHICLERADIO: return mOnVehicleRadio;
case EVT_VEHICLEHANDLINGRULE: return mOnVehicleHandlingRule;
case EVT_SERVEROPTION: return mOnServerOption;
case EVT_SCRIPTRELOAD: return mOnScriptReload;
case EVT_SCRIPTLOADED: return mOnScriptLoaded;
default: return NullFunction();
return;
}
// Create a new table on the stack
sq_newtableex(DefaultVM::Get(), 128);
// Grab the table object from the stack
m_Events = LightObj(-1, DefaultVM::Get());
// Pop the table object from the stack
sq_pop(DefaultVM::Get(), 1);
// Proceed to initializing the events
InitSignalPair(mOnCustomEvent, m_Events, "CustomEvent");
InitSignalPair(mOnBlipCreated, m_Events, "BlipCreated");
InitSignalPair(mOnCheckpointCreated, m_Events, "CheckpointCreated");
InitSignalPair(mOnKeybindCreated, m_Events, "KeybindCreated");
InitSignalPair(mOnObjectCreated, m_Events, "ObjectCreated");
InitSignalPair(mOnPickupCreated, m_Events, "PickupCreated");
InitSignalPair(mOnPlayerCreated, m_Events, "PlayerCreated");
InitSignalPair(mOnVehicleCreated, m_Events, "VehicleCreated");
InitSignalPair(mOnBlipDestroyed, m_Events, "BlipDestroyed");
InitSignalPair(mOnCheckpointDestroyed, m_Events, "CheckpointDestroyed");
InitSignalPair(mOnKeybindDestroyed, m_Events, "KeybindDestroyed");
InitSignalPair(mOnObjectDestroyed, m_Events, "ObjectDestroyed");
InitSignalPair(mOnPickupDestroyed, m_Events, "PickupDestroyed");
InitSignalPair(mOnPlayerDestroyed, m_Events, "PlayerDestroyed");
InitSignalPair(mOnVehicleDestroyed, m_Events, "VehicleDestroyed");
InitSignalPair(mOnBlipCustom, m_Events, "BlipCustom");
InitSignalPair(mOnCheckpointCustom, m_Events, "CheckpointCustom");
InitSignalPair(mOnKeybindCustom, m_Events, "KeybindCustom");
InitSignalPair(mOnObjectCustom, m_Events, "ObjectCustom");
InitSignalPair(mOnPickupCustom, m_Events, "PickupCustom");
InitSignalPair(mOnPlayerCustom, m_Events, "PlayerCustom");
InitSignalPair(mOnVehicleCustom, m_Events, "VehicleCustom");
InitSignalPair(mOnServerStartup, m_Events, "ServerStartup");
InitSignalPair(mOnServerShutdown, m_Events, "ServerShutdown");
InitSignalPair(mOnServerFrame, m_Events, "ServerFrame");
InitSignalPair(mOnIncomingConnection, m_Events, "IncomingConnection");
InitSignalPair(mOnPlayerRequestClass, m_Events, "PlayerRequestClass");
InitSignalPair(mOnPlayerRequestSpawn, m_Events, "PlayerRequestSpawn");
InitSignalPair(mOnPlayerSpawn, m_Events, "PlayerSpawn");
InitSignalPair(mOnPlayerWasted, m_Events, "PlayerWasted");
InitSignalPair(mOnPlayerKilled, m_Events, "PlayerKilled");
InitSignalPair(mOnPlayerEmbarking, m_Events, "PlayerEmbarking");
InitSignalPair(mOnPlayerEmbarked, m_Events, "PlayerEmbarked");
InitSignalPair(mOnPlayerDisembark, m_Events, "PlayerDisembark");
InitSignalPair(mOnPlayerRename, m_Events, "PlayerRename");
InitSignalPair(mOnPlayerState, m_Events, "PlayerState");
InitSignalPair(mOnStateNone, m_Events, "StateNone");
InitSignalPair(mOnStateNormal, m_Events, "StateNormal");
InitSignalPair(mOnStateAim, m_Events, "StateAim");
InitSignalPair(mOnStateDriver, m_Events, "StateDriver");
InitSignalPair(mOnStatePassenger, m_Events, "StatePassenger");
InitSignalPair(mOnStateEnterDriver, m_Events, "StateEnterDriver");
InitSignalPair(mOnStateEnterPassenger, m_Events, "StateEnterPassenger");
InitSignalPair(mOnStateExit, m_Events, "StateExit");
InitSignalPair(mOnStateUnspawned, m_Events, "StateUnspawned");
InitSignalPair(mOnPlayerAction, m_Events, "PlayerAction");
InitSignalPair(mOnActionNone, m_Events, "ActionNone");
InitSignalPair(mOnActionNormal, m_Events, "ActionNormal");
InitSignalPair(mOnActionAiming, m_Events, "ActionAiming");
InitSignalPair(mOnActionShooting, m_Events, "ActionShooting");
InitSignalPair(mOnActionJumping, m_Events, "ActionJumping");
InitSignalPair(mOnActionLieDown, m_Events, "ActionLieDown");
InitSignalPair(mOnActionGettingUp, m_Events, "ActionGettingUp");
InitSignalPair(mOnActionJumpVehicle, m_Events, "ActionJumpVehicle");
InitSignalPair(mOnActionDriving, m_Events, "ActionDriving");
InitSignalPair(mOnActionDying, m_Events, "ActionDying");
InitSignalPair(mOnActionWasted, m_Events, "ActionWasted");
InitSignalPair(mOnActionEmbarking, m_Events, "ActionEmbarking");
InitSignalPair(mOnActionDisembarking, m_Events, "ActionDisembarking");
InitSignalPair(mOnPlayerBurning, m_Events, "PlayerBurning");
InitSignalPair(mOnPlayerCrouching, m_Events, "PlayerCrouching");
InitSignalPair(mOnPlayerGameKeys, m_Events, "PlayerGameKeys");
InitSignalPair(mOnPlayerStartTyping, m_Events, "PlayerStartTyping");
InitSignalPair(mOnPlayerStopTyping, m_Events, "PlayerStopTyping");
InitSignalPair(mOnPlayerAway, m_Events, "PlayerAway");
InitSignalPair(mOnPlayerMessage, m_Events, "PlayerMessage");
InitSignalPair(mOnPlayerCommand, m_Events, "PlayerCommand");
InitSignalPair(mOnPlayerPrivateMessage, m_Events, "PlayerPrivateMessage");
InitSignalPair(mOnPlayerKeyPress, m_Events, "PlayerKeyPress");
InitSignalPair(mOnPlayerKeyRelease, m_Events, "PlayerKeyRelease");
InitSignalPair(mOnPlayerSpectate, m_Events, "PlayerSpectate");
InitSignalPair(mOnPlayerCrashreport, m_Events, "PlayerCrashreport");
InitSignalPair(mOnVehicleExplode, m_Events, "VehicleExplode");
InitSignalPair(mOnVehicleRespawn, m_Events, "VehicleRespawn");
InitSignalPair(mOnObjectShot, m_Events, "ObjectShot");
InitSignalPair(mOnObjectTouched, m_Events, "ObjectTouched");
InitSignalPair(mOnObjectWorld, m_Events, "ObjectWorld");
InitSignalPair(mOnObjectAlpha, m_Events, "ObjectAlpha");
InitSignalPair(mOnObjectReport, m_Events, "ObjectReport");
InitSignalPair(mOnPickupClaimed, m_Events, "PickupClaimed");
InitSignalPair(mOnPickupCollected, m_Events, "PickupCollected");
InitSignalPair(mOnPickupRespawn, m_Events, "PickupRespawn");
InitSignalPair(mOnPickupWorld, m_Events, "PickupWorld");
InitSignalPair(mOnPickupAlpha, m_Events, "PickupAlpha");
InitSignalPair(mOnPickupAutomatic, m_Events, "PickupAutomatic");
InitSignalPair(mOnPickupAutoTimer, m_Events, "PickupAutoTimer");
InitSignalPair(mOnCheckpointEntered, m_Events, "CheckpointEntered");
InitSignalPair(mOnCheckpointExited, m_Events, "CheckpointExited");
InitSignalPair(mOnCheckpointWorld, m_Events, "CheckpointWorld");
InitSignalPair(mOnCheckpointRadius, m_Events, "CheckpointRadius");
InitSignalPair(mOnEntityPool, m_Events, "EntityPool");
InitSignalPair(mOnClientScriptData, m_Events, "ClientScriptData");
InitSignalPair(mOnPlayerUpdate, m_Events, "PlayerUpdate");
InitSignalPair(mOnVehicleUpdate, m_Events, "VehicleUpdate");
InitSignalPair(mOnPlayerHealth, m_Events, "PlayerHealth");
InitSignalPair(mOnPlayerArmour, m_Events, "PlayerArmour");
InitSignalPair(mOnPlayerWeapon, m_Events, "PlayerWeapon");
InitSignalPair(mOnPlayerHeading, m_Events, "PlayerHeading");
InitSignalPair(mOnPlayerPosition, m_Events, "PlayerPosition");
InitSignalPair(mOnPlayerOption, m_Events, "PlayerOption");
InitSignalPair(mOnPlayerAdmin, m_Events, "PlayerAdmin");
InitSignalPair(mOnPlayerWorld, m_Events, "PlayerWorld");
InitSignalPair(mOnPlayerTeam, m_Events, "PlayerTeam");
InitSignalPair(mOnPlayerSkin, m_Events, "PlayerSkin");
InitSignalPair(mOnPlayerMoney, m_Events, "PlayerMoney");
InitSignalPair(mOnPlayerScore, m_Events, "PlayerScore");
InitSignalPair(mOnPlayerWantedLevel, m_Events, "PlayerWantedLevel");
InitSignalPair(mOnPlayerImmunity, m_Events, "PlayerImmunity");
InitSignalPair(mOnPlayerAlpha, m_Events, "PlayerAlpha");
InitSignalPair(mOnVehicleColor, m_Events, "VehicleColor");
InitSignalPair(mOnVehicleHealth, m_Events, "VehicleHealth");
InitSignalPair(mOnVehiclePosition, m_Events, "VehiclePosition");
InitSignalPair(mOnVehicleRotation, m_Events, "VehicleRotation");
InitSignalPair(mOnVehicleOption, m_Events, "VehicleOption");
InitSignalPair(mOnVehicleWorld, m_Events, "VehicleWorld");
InitSignalPair(mOnVehicleImmunity, m_Events, "VehicleImmunity");
InitSignalPair(mOnVehiclePartStatus, m_Events, "VehiclePartStatus");
InitSignalPair(mOnVehicleTyreStatus, m_Events, "VehicleTyreStatus");
InitSignalPair(mOnVehicleDamageData, m_Events, "VehicleDamageData");
InitSignalPair(mOnVehicleRadio, m_Events, "VehicleRadio");
InitSignalPair(mOnVehicleHandlingRule, m_Events, "VehicleHandlingRule");
InitSignalPair(mOnServerOption, m_Events, "ServerOption");
InitSignalPair(mOnScriptReload, m_Events, "ScriptReload");
InitSignalPair(mOnScriptLoaded, m_Events, "ScriptLoaded");
}
// ------------------------------------------------------------------------------------------------
Function & Core::GetBlipEvent(Int32 id, Int32 evid)
void Core::DropEvents()
{
BlipInst & inst = m_Blips.at(id);
switch (evid)
{
case EVT_BLIPDESTROYED: return inst.mOnDestroyed;
case EVT_BLIPCUSTOM: return inst.mOnCustom;
default: return NullFunction();
}
}
// ------------------------------------------------------------------------------------------------
Function & Core::GetCheckpointEvent(Int32 id, Int32 evid)
{
CheckpointInst & inst = m_Checkpoints.at(id);
switch (evid)
{
case EVT_CHECKPOINTDESTROYED: return inst.mOnDestroyed;
case EVT_CHECKPOINTCUSTOM: return inst.mOnCustom;
case EVT_CHECKPOINTENTERED: return inst.mOnEntered;
case EVT_CHECKPOINTEXITED: return inst.mOnExited;
case EVT_CHECKPOINTWORLD: return inst.mOnWorld;
case EVT_CHECKPOINTRADIUS: return inst.mOnRadius;
default: return NullFunction();
}
}
// ------------------------------------------------------------------------------------------------
Function & Core::GetKeybindEvent(Int32 id, Int32 evid)
{
KeybindInst & inst = m_Keybinds.at(id);
switch (evid)
{
case EVT_KEYBINDDESTROYED: return inst.mOnDestroyed;
case EVT_KEYBINDCUSTOM: return inst.mOnCustom;
case EVT_PLAYERKEYPRESS: return inst.mOnKeyPress;
case EVT_PLAYERKEYRELEASE: return inst.mOnKeyRelease;
default: return NullFunction();
}
}
// ------------------------------------------------------------------------------------------------
Function & Core::GetObjectEvent(Int32 id, Int32 evid)
{
ObjectInst & inst = m_Objects.at(id);
switch (evid)
{
case EVT_OBJECTDESTROYED: return inst.mOnDestroyed;
case EVT_OBJECTCUSTOM: return inst.mOnCustom;
case EVT_OBJECTSHOT: return inst.mOnShot;
case EVT_OBJECTTOUCHED: return inst.mOnTouched;
case EVT_OBJECTWORLD: return inst.mOnWorld;
case EVT_OBJECTALPHA: return inst.mOnAlpha;
case EVT_OBJECTREPORT: return inst.mOnReport;
default: return NullFunction();
}
}
// ------------------------------------------------------------------------------------------------
Function & Core::GetPickupEvent(Int32 id, Int32 evid)
{
PickupInst & inst = m_Pickups.at(id);
switch (evid)
{
case EVT_PICKUPDESTROYED: return inst.mOnDestroyed;
case EVT_PICKUPCUSTOM: return inst.mOnCustom;
case EVT_PICKUPRESPAWN: return inst.mOnRespawn;
case EVT_PICKUPCLAIMED: return inst.mOnClaimed;
case EVT_PICKUPCOLLECTED: return inst.mOnCollected;
case EVT_PICKUPWORLD: return inst.mOnWorld;
case EVT_PICKUPALPHA: return inst.mOnAlpha;
case EVT_PICKUPAUTOMATIC: return inst.mOnAutomatic;
case EVT_PICKUPAUTOTIMER: return inst.mOnAutoTimer;
default: return NullFunction();
}
}
// ------------------------------------------------------------------------------------------------
Function & Core::GetPlayerEvent(Int32 id, Int32 evid)
{
PlayerInst & inst = m_Players.at(id);
switch (evid)
{
case EVT_PLAYERDESTROYED: return inst.mOnDestroyed;
case EVT_PLAYERCUSTOM: return inst.mOnCustom;
case EVT_PLAYERREQUESTCLASS: return inst.mOnRequestClass;
case EVT_PLAYERREQUESTSPAWN: return inst.mOnRequestSpawn;
case EVT_PLAYERSPAWN: return inst.mOnSpawn;
case EVT_PLAYERWASTED: return inst.mOnWasted;
case EVT_PLAYERKILLED: return inst.mOnKilled;
case EVT_PLAYEREMBARKING: return inst.mOnEmbarking;
case EVT_PLAYEREMBARKED: return inst.mOnEmbarked;
case EVT_PLAYERDISEMBARK: return inst.mOnDisembark;
case EVT_PLAYERRENAME: return inst.mOnRename;
case EVT_PLAYERSTATE: return inst.mOnState;
case EVT_STATENONE: return inst.mOnStateNone;
case EVT_STATENORMAL: return inst.mOnStateNormal;
case EVT_STATEAIM: return inst.mOnStateAim;
case EVT_STATEDRIVER: return inst.mOnStateDriver;
case EVT_STATEPASSENGER: return inst.mOnStatePassenger;
case EVT_STATEENTERDRIVER: return inst.mOnStateEnterDriver;
case EVT_STATEENTERPASSENGER: return inst.mOnStateEnterPassenger;
case EVT_STATEEXIT: return inst.mOnStateExit;
case EVT_STATEUNSPAWNED: return inst.mOnStateUnspawned;
case EVT_PLAYERACTION: return inst.mOnAction;
case EVT_ACTIONNONE: return inst.mOnActionNone;
case EVT_ACTIONNORMAL: return inst.mOnActionNormal;
case EVT_ACTIONAIMING: return inst.mOnActionAiming;
case EVT_ACTIONSHOOTING: return inst.mOnActionShooting;
case EVT_ACTIONJUMPING: return inst.mOnActionJumping;
case EVT_ACTIONLIEDOWN: return inst.mOnActionLieDown;
case EVT_ACTIONGETTINGUP: return inst.mOnActionGettingUp;
case EVT_ACTIONJUMPVEHICLE: return inst.mOnActionJumpVehicle;
case EVT_ACTIONDRIVING: return inst.mOnActionDriving;
case EVT_ACTIONDYING: return inst.mOnActionDying;
case EVT_ACTIONWASTED: return inst.mOnActionWasted;
case EVT_ACTIONEMBARKING: return inst.mOnActionEmbarking;
case EVT_ACTIONDISEMBARKING: return inst.mOnActionDisembarking;
case EVT_PLAYERBURNING: return inst.mOnBurning;
case EVT_PLAYERCROUCHING: return inst.mOnCrouching;
case EVT_PLAYERGAMEKEYS: return inst.mOnGameKeys;
case EVT_PLAYERSTARTTYPING: return inst.mOnStartTyping;
case EVT_PLAYERSTOPTYPING: return inst.mOnStopTyping;
case EVT_PLAYERAWAY: return inst.mOnAway;
case EVT_PLAYERMESSAGE: return inst.mOnMessage;
case EVT_PLAYERCOMMAND: return inst.mOnCommand;
case EVT_PLAYERPRIVATEMESSAGE: return inst.mOnPrivateMessage;
case EVT_PLAYERKEYPRESS: return inst.mOnKeyPress;
case EVT_PLAYERKEYRELEASE: return inst.mOnKeyRelease;
case EVT_PLAYERSPECTATE: return inst.mOnSpectate;
case EVT_PLAYERCRASHREPORT: return inst.mOnCrashreport;
case EVT_OBJECTSHOT: return inst.mOnObjectShot;
case EVT_OBJECTTOUCHED: return inst.mOnObjectTouched;
case EVT_PICKUPCLAIMED: return inst.mOnPickupClaimed;
case EVT_PICKUPCOLLECTED: return inst.mOnPickupCollected;
case EVT_CHECKPOINTENTERED: return inst.mOnCheckpointEntered;
case EVT_CHECKPOINTEXITED: return inst.mOnCheckpointExited;
case EVT_CLIENTSCRIPTDATA: return inst.mOnClientScriptData;
case EVT_PLAYERUPDATE: return inst.mOnUpdate;
case EVT_PLAYERHEALTH: return inst.mOnHealth;
case EVT_PLAYERARMOUR: return inst.mOnArmour;
case EVT_PLAYERWEAPON: return inst.mOnWeapon;
case EVT_PLAYERHEADING: return inst.mOnHeading;
case EVT_PLAYERPOSITION: return inst.mOnPosition;
case EVT_PLAYEROPTION: return inst.mOnOption;
case EVT_PLAYERADMIN: return inst.mOnAdmin;
case EVT_PLAYERWORLD: return inst.mOnWorld;
case EVT_PLAYERTEAM: return inst.mOnTeam;
case EVT_PLAYERSKIN: return inst.mOnSkin;
case EVT_PLAYERMONEY: return inst.mOnMoney;
case EVT_PLAYERSCORE: return inst.mOnScore;
case EVT_PLAYERWANTEDLEVEL: return inst.mOnWantedLevel;
case EVT_PLAYERIMMUNITY: return inst.mOnImmunity;
case EVT_PLAYERALPHA: return inst.mOnAlpha;
default: return NullFunction();
}
}
// ------------------------------------------------------------------------------------------------
Function & Core::GetVehicleEvent(Int32 id, Int32 evid)
{
VehicleInst & inst = m_Vehicles.at(id);
switch (evid)
{
case EVT_PLAYEREMBARKING: return inst.mOnEmbarking;
case EVT_PLAYEREMBARKED: return inst.mOnEmbarked;
case EVT_PLAYERDISEMBARK: return inst.mOnDisembark;
case EVT_VEHICLEEXPLODE: return inst.mOnExplode;
case EVT_VEHICLERESPAWN: return inst.mOnRespawn;
case EVT_VEHICLEUPDATE: return inst.mOnUpdate;
case EVT_VEHICLECOLOR: return inst.mOnColor;
case EVT_VEHICLEHEALTH: return inst.mOnHealth;
case EVT_VEHICLEPOSITION: return inst.mOnPosition;
case EVT_VEHICLEROTATION: return inst.mOnRotation;
case EVT_VEHICLEOPTION: return inst.mOnOption;
case EVT_VEHICLEWORLD: return inst.mOnWorld;
case EVT_VEHICLEIMMUNITY: return inst.mOnImmunity;
case EVT_VEHICLEPARTSTATUS: return inst.mOnPartStatus;
case EVT_VEHICLETYRESTATUS: return inst.mOnTyreStatus;
case EVT_VEHICLEDAMAGEDATA: return inst.mOnDamageData;
case EVT_VEHICLERADIO: return inst.mOnRadio;
case EVT_VEHICLEHANDLINGRULE: return inst.mOnHandlingRule;
default: return NullFunction();
}
ResetSignalPair(mOnCustomEvent);
ResetSignalPair(mOnBlipCreated);
ResetSignalPair(mOnCheckpointCreated);
ResetSignalPair(mOnKeybindCreated);
ResetSignalPair(mOnObjectCreated);
ResetSignalPair(mOnPickupCreated);
ResetSignalPair(mOnPlayerCreated);
ResetSignalPair(mOnVehicleCreated);
ResetSignalPair(mOnBlipDestroyed);
ResetSignalPair(mOnCheckpointDestroyed);
ResetSignalPair(mOnKeybindDestroyed);
ResetSignalPair(mOnObjectDestroyed);
ResetSignalPair(mOnPickupDestroyed);
ResetSignalPair(mOnPlayerDestroyed);
ResetSignalPair(mOnVehicleDestroyed);
ResetSignalPair(mOnBlipCustom);
ResetSignalPair(mOnCheckpointCustom);
ResetSignalPair(mOnKeybindCustom);
ResetSignalPair(mOnObjectCustom);
ResetSignalPair(mOnPickupCustom);
ResetSignalPair(mOnPlayerCustom);
ResetSignalPair(mOnVehicleCustom);
ResetSignalPair(mOnServerStartup);
ResetSignalPair(mOnServerShutdown);
ResetSignalPair(mOnServerFrame);
ResetSignalPair(mOnIncomingConnection);
ResetSignalPair(mOnPlayerRequestClass);
ResetSignalPair(mOnPlayerRequestSpawn);
ResetSignalPair(mOnPlayerSpawn);
ResetSignalPair(mOnPlayerWasted);
ResetSignalPair(mOnPlayerKilled);
ResetSignalPair(mOnPlayerEmbarking);
ResetSignalPair(mOnPlayerEmbarked);
ResetSignalPair(mOnPlayerDisembark);
ResetSignalPair(mOnPlayerRename);
ResetSignalPair(mOnPlayerState);
ResetSignalPair(mOnStateNone);
ResetSignalPair(mOnStateNormal);
ResetSignalPair(mOnStateAim);
ResetSignalPair(mOnStateDriver);
ResetSignalPair(mOnStatePassenger);
ResetSignalPair(mOnStateEnterDriver);
ResetSignalPair(mOnStateEnterPassenger);
ResetSignalPair(mOnStateExit);
ResetSignalPair(mOnStateUnspawned);
ResetSignalPair(mOnPlayerAction);
ResetSignalPair(mOnActionNone);
ResetSignalPair(mOnActionNormal);
ResetSignalPair(mOnActionAiming);
ResetSignalPair(mOnActionShooting);
ResetSignalPair(mOnActionJumping);
ResetSignalPair(mOnActionLieDown);
ResetSignalPair(mOnActionGettingUp);
ResetSignalPair(mOnActionJumpVehicle);
ResetSignalPair(mOnActionDriving);
ResetSignalPair(mOnActionDying);
ResetSignalPair(mOnActionWasted);
ResetSignalPair(mOnActionEmbarking);
ResetSignalPair(mOnActionDisembarking);
ResetSignalPair(mOnPlayerBurning);
ResetSignalPair(mOnPlayerCrouching);
ResetSignalPair(mOnPlayerGameKeys);
ResetSignalPair(mOnPlayerStartTyping);
ResetSignalPair(mOnPlayerStopTyping);
ResetSignalPair(mOnPlayerAway);
ResetSignalPair(mOnPlayerMessage);
ResetSignalPair(mOnPlayerCommand);
ResetSignalPair(mOnPlayerPrivateMessage);
ResetSignalPair(mOnPlayerKeyPress);
ResetSignalPair(mOnPlayerKeyRelease);
ResetSignalPair(mOnPlayerSpectate);
ResetSignalPair(mOnPlayerCrashreport);
ResetSignalPair(mOnVehicleExplode);
ResetSignalPair(mOnVehicleRespawn);
ResetSignalPair(mOnObjectShot);
ResetSignalPair(mOnObjectTouched);
ResetSignalPair(mOnObjectWorld);
ResetSignalPair(mOnObjectAlpha);
ResetSignalPair(mOnObjectReport);
ResetSignalPair(mOnPickupClaimed);
ResetSignalPair(mOnPickupCollected);
ResetSignalPair(mOnPickupRespawn);
ResetSignalPair(mOnPickupWorld);
ResetSignalPair(mOnPickupAlpha);
ResetSignalPair(mOnPickupAutomatic);
ResetSignalPair(mOnPickupAutoTimer);
ResetSignalPair(mOnCheckpointEntered);
ResetSignalPair(mOnCheckpointExited);
ResetSignalPair(mOnCheckpointWorld);
ResetSignalPair(mOnCheckpointRadius);
ResetSignalPair(mOnEntityPool);
ResetSignalPair(mOnClientScriptData);
ResetSignalPair(mOnPlayerUpdate);
ResetSignalPair(mOnVehicleUpdate);
ResetSignalPair(mOnPlayerHealth);
ResetSignalPair(mOnPlayerArmour);
ResetSignalPair(mOnPlayerWeapon);
ResetSignalPair(mOnPlayerHeading);
ResetSignalPair(mOnPlayerPosition);
ResetSignalPair(mOnPlayerOption);
ResetSignalPair(mOnPlayerAdmin);
ResetSignalPair(mOnPlayerWorld);
ResetSignalPair(mOnPlayerTeam);
ResetSignalPair(mOnPlayerSkin);
ResetSignalPair(mOnPlayerMoney);
ResetSignalPair(mOnPlayerScore);
ResetSignalPair(mOnPlayerWantedLevel);
ResetSignalPair(mOnPlayerImmunity);
ResetSignalPair(mOnPlayerAlpha);
ResetSignalPair(mOnVehicleColor);
ResetSignalPair(mOnVehicleHealth);
ResetSignalPair(mOnVehiclePosition);
ResetSignalPair(mOnVehicleRotation);
ResetSignalPair(mOnVehicleOption);
ResetSignalPair(mOnVehicleWorld);
ResetSignalPair(mOnVehicleImmunity);
ResetSignalPair(mOnVehiclePartStatus);
ResetSignalPair(mOnVehicleTyreStatus);
ResetSignalPair(mOnVehicleDamageData);
ResetSignalPair(mOnVehicleRadio);
ResetSignalPair(mOnVehicleHandlingRule);
ResetSignalPair(mOnServerOption);
ResetSignalPair(mOnScriptReload);
ResetSignalPair(mOnScriptLoaded);
}
} // Namespace:: SqMod

View File

@ -20,7 +20,7 @@ SQInteger CBlip::SqGetNull(HSQUIRRELVM vm)
}
// ------------------------------------------------------------------------------------------------
Object & CBlip::GetNull()
LightObj & CBlip::GetNull()
{
return Core::Get().GetNullBlip();
}
@ -72,7 +72,7 @@ CBlip & CBlip::ApplyTag(const StackStrF & tag)
}
// ------------------------------------------------------------------------------------------------
Object & CBlip::GetData()
LightObj & CBlip::GetData()
{
// Validate the managed identifier
Validate();
@ -81,7 +81,7 @@ Object & CBlip::GetData()
}
// ------------------------------------------------------------------------------------------------
void CBlip::SetData(Object & data)
void CBlip::SetData(LightObj & data)
{
// Validate the managed identifier
Validate();
@ -90,7 +90,7 @@ void CBlip::SetData(Object & data)
}
// ------------------------------------------------------------------------------------------------
bool CBlip::Destroy(Int32 header, Object & payload)
bool CBlip::Destroy(Int32 header, LightObj & payload)
{
// Validate the managed identifier
Validate();
@ -99,31 +99,16 @@ bool CBlip::Destroy(Int32 header, Object & payload)
}
// ------------------------------------------------------------------------------------------------
void CBlip::BindEvent(Int32 evid, Object & env, Function & func) const
LightObj & CBlip::GetEvents() const
{
// Validate the managed identifier
Validate();
// Obtain the function instance called for this event
Function & event = Core::Get().GetBlipEvent(m_ID, evid);
// Is the specified callback function null?
if (func.IsNull())
{
event.ReleaseGently(); // Then release the current callback
}
// Does this function need a custom environment?
else if (env.IsNull())
{
event = func;
}
// Assign the specified environment and function
else
{
event = Function(env.GetVM(), env, func.GetFunc());
}
// Return the associated event table
return Core::Get().GetBlip(m_ID).mEvents;
}
// ------------------------------------------------------------------------------------------------
void CBlip::CustomEvent(Int32 header, Object & payload) const
void CBlip::CustomEvent(Int32 header, LightObj & payload) const
{
// Validate the managed identifier
Validate();
@ -240,62 +225,62 @@ Int32 CBlip::GetColorA() const
}
// ------------------------------------------------------------------------------------------------
static Object & Blip_CreateEx(Int32 world, Float32 x, Float32 y, Float32 z, Int32 scale,
static LightObj & Blip_CreateEx(Int32 world, Float32 x, Float32 y, Float32 z, Int32 scale,
Uint8 r, Uint8 g, Uint8 b, Uint8 a, Int32 sprid)
{
return Core::Get().NewBlip(-1, world, x, y, z, scale, SQMOD_PACK_RGBA(r, g, b, a), sprid,
SQMOD_CREATE_DEFAULT, NullObject());
SQMOD_CREATE_DEFAULT, NullLightObj());
}
static Object & Blip_CreateEx(Int32 world, Float32 x, Float32 y, Float32 z, Int32 scale,
static LightObj & Blip_CreateEx(Int32 world, Float32 x, Float32 y, Float32 z, Int32 scale,
Uint8 r, Uint8 g, Uint8 b, Uint8 a, Int32 sprid,
Int32 header, Object & payload)
Int32 header, LightObj & payload)
{
return Core::Get().NewBlip(-1, world, x, y, z, scale, SQMOD_PACK_RGBA(r, g, b, a), sprid,
header, payload);
}
// ------------------------------------------------------------------------------------------------
static Object & Blip_CreateEx(Int32 index, Int32 world, Float32 x, Float32 y, Float32 z,
static LightObj & Blip_CreateEx(Int32 index, Int32 world, Float32 x, Float32 y, Float32 z,
Int32 scale, Uint8 r, Uint8 g, Uint8 b, Uint8 a, Int32 sprid)
{
return Core::Get().NewBlip(index, world, x, y, z, scale, SQMOD_PACK_RGBA(r, g, b, a), sprid,
SQMOD_CREATE_DEFAULT, NullObject());
SQMOD_CREATE_DEFAULT, NullLightObj());
}
static Object & Blip_CreateEx(Int32 index, Int32 world, Float32 x, Float32 y, Float32 z, Int32 scale,
static LightObj & Blip_CreateEx(Int32 index, Int32 world, Float32 x, Float32 y, Float32 z, Int32 scale,
Uint8 r, Uint8 g, Uint8 b, Uint8 a, Int32 sprid,
Int32 header, Object & payload)
Int32 header, LightObj & payload)
{
return Core::Get().NewBlip(index, world, x, y, z, scale, SQMOD_PACK_RGBA(r, g, b, a), sprid,
header, payload);
}
// ------------------------------------------------------------------------------------------------
static Object & Blip_Create(Int32 world, const Vector3 & pos, Int32 scale, const Color4 & color,
static LightObj & Blip_Create(Int32 world, const Vector3 & pos, Int32 scale, const Color4 & color,
Int32 sprid)
{
return Core::Get().NewBlip(-1, world, pos.x, pos.y, pos.z, scale, color.GetRGBA(), sprid,
SQMOD_CREATE_DEFAULT, NullObject());
SQMOD_CREATE_DEFAULT, NullLightObj());
}
static Object & Blip_Create(Int32 world, const Vector3 & pos, Int32 scale, const Color4 & color,
Int32 sprid, Int32 header, Object & payload)
static LightObj & Blip_Create(Int32 world, const Vector3 & pos, Int32 scale, const Color4 & color,
Int32 sprid, Int32 header, LightObj & payload)
{
return Core::Get().NewBlip(-1, world, pos.x, pos.y, pos.z, scale, color.GetRGBA(), sprid,
header, payload);
}
// ------------------------------------------------------------------------------------------------
static Object & Blip_Create(Int32 index, Int32 world, const Vector3 & pos, Int32 scale,
static LightObj & Blip_Create(Int32 index, Int32 world, const Vector3 & pos, Int32 scale,
const Color4 & color, Int32 sprid)
{
return Core::Get().NewBlip(index, world, pos.x, pos.y, pos.z, scale, color.GetRGBA(), sprid,
SQMOD_CREATE_DEFAULT, NullObject());
SQMOD_CREATE_DEFAULT, NullLightObj());
}
static Object & Blip_Create(Int32 index, Int32 world, const Vector3 & pos, Int32 scale,
const Color4 & color, Int32 sprid, Int32 header, Object & payload)
static LightObj & Blip_Create(Int32 index, Int32 world, const Vector3 & pos, Int32 scale,
const Color4 & color, Int32 sprid, Int32 header, LightObj & payload)
{
return Core::Get().NewBlip(index, world, pos.x, pos.y, pos.z, scale, color.GetRGBA(), sprid,
header, payload);
@ -312,18 +297,18 @@ void Register_CBlip(HSQUIRRELVM vm)
// Static Values
.SetStaticValue(_SC("MaxID"), CBlip::Max)
// Core Properties
.Prop(_SC("On"), &CBlip::GetEvents)
.Prop(_SC("ID"), &CBlip::GetID)
.Prop(_SC("Tag"), &CBlip::GetTag, &CBlip::SetTag)
.Prop(_SC("Data"), &CBlip::GetData, &CBlip::SetData)
.Prop(_SC("Active"), &CBlip::IsActive)
// Core Methods
.Func(_SC("Bind"), &CBlip::BindEvent)
.FmtFunc(_SC("SetTag"), &CBlip::ApplyTag)
.Func(_SC("CustomEvent"), &CBlip::CustomEvent)
// Core Overloads
.Overload< bool (CBlip::*)(void) >(_SC("Destroy"), &CBlip::Destroy)
.Overload< bool (CBlip::*)(Int32) >(_SC("Destroy"), &CBlip::Destroy)
.Overload< bool (CBlip::*)(Int32, Object &) >(_SC("Destroy"), &CBlip::Destroy)
.Overload< bool (CBlip::*)(Int32, LightObj &) >(_SC("Destroy"), &CBlip::Destroy)
// Properties
.Prop(_SC("World"), &CBlip::GetWorld)
.Prop(_SC("Scale"), &CBlip::GetScale)
@ -340,21 +325,21 @@ void Register_CBlip(HSQUIRRELVM vm)
.Prop(_SC("Blue"), &CBlip::GetColorB)
.Prop(_SC("Alpha"), &CBlip::GetColorA)
// Static Overloads
.StaticOverload< Object & (*)(Int32, Float32, Float32, Float32, Int32, Uint8, Uint8, Uint8, Uint8, Int32) >
.StaticOverload< LightObj & (*)(Int32, Float32, Float32, Float32, Int32, Uint8, Uint8, Uint8, Uint8, Int32) >
(_SC("CreateEx"), &Blip_CreateEx)
.StaticOverload< Object & (*)(Int32, Float32, Float32, Float32, Int32, Uint8, Uint8, Uint8, Uint8, Int32, Int32, Object &) >
.StaticOverload< LightObj & (*)(Int32, Float32, Float32, Float32, Int32, Uint8, Uint8, Uint8, Uint8, Int32, Int32, LightObj &) >
(_SC("CreateEx"), &Blip_CreateEx)
.StaticOverload< Object & (*)(Int32, Int32, Float32, Float32, Float32, Int32, Uint8, Uint8, Uint8, Uint8, Int32) >
.StaticOverload< LightObj & (*)(Int32, Int32, Float32, Float32, Float32, Int32, Uint8, Uint8, Uint8, Uint8, Int32) >
(_SC("CreateEx"), &Blip_CreateEx)
.StaticOverload< Object & (*)(Int32, Int32, Float32, Float32, Float32, Int32, Uint8, Uint8, Uint8, Uint8, Int32, Int32, Object &) >
.StaticOverload< LightObj & (*)(Int32, Int32, Float32, Float32, Float32, Int32, Uint8, Uint8, Uint8, Uint8, Int32, Int32, LightObj &) >
(_SC("CreateEx"), &Blip_CreateEx)
.StaticOverload< Object & (*)(Int32, const Vector3 &, Int32, const Color4 &, Int32) >
.StaticOverload< LightObj & (*)(Int32, const Vector3 &, Int32, const Color4 &, Int32) >
(_SC("Create"), &Blip_Create)
.StaticOverload< Object & (*)(Int32, const Vector3 &, Int32, const Color4 &, Int32, Int32, Object &) >
.StaticOverload< LightObj & (*)(Int32, const Vector3 &, Int32, const Color4 &, Int32, Int32, LightObj &) >
(_SC("Create"), &Blip_Create)
.StaticOverload< Object & (*)(Int32, Int32, const Vector3 &, Int32, const Color4 &, Int32) >
.StaticOverload< LightObj & (*)(Int32, Int32, const Vector3 &, Int32, const Color4 &, Int32) >
(_SC("Create"), &Blip_Create)
.StaticOverload< Object & (*)(Int32, Int32, const Vector3 &, Int32, const Color4 &, Int32, Int32, Object &) >
.StaticOverload< LightObj & (*)(Int32, Int32, const Vector3 &, Int32, const Color4 &, Int32, Int32, LightObj &) >
(_SC("Create"), &Blip_Create)
// Raw Squirrel Methods
.SquirrelFunc(_SC("NullInst"), &CBlip::SqGetNull)

View File

@ -30,7 +30,7 @@ private:
/* --------------------------------------------------------------------------------------------
* User data associated with this instance.
*/
Object m_Data;
LightObj m_Data;
/* --------------------------------------------------------------------------------------------
* Base constructor.
@ -93,7 +93,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the associated null entity instance.
*/
static Object & GetNull();
static LightObj & GetNull();
/* --------------------------------------------------------------------------------------------
* Retrieve the identifier of the entity managed by this instance.
@ -129,19 +129,19 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user data.
*/
Object & GetData();
LightObj & GetData();
/* --------------------------------------------------------------------------------------------
* Modify the associated user data.
*/
void SetData(Object & data);
void SetData(LightObj & data);
/* --------------------------------------------------------------------------------------------
* Destroy the managed blip entity.
*/
bool Destroy()
{
return Destroy(0, NullObject());
return Destroy(0, NullLightObj());
}
/* --------------------------------------------------------------------------------------------
@ -149,23 +149,23 @@ public:
*/
bool Destroy(Int32 header)
{
return Destroy(header, NullObject());
return Destroy(header, NullLightObj());
}
/* --------------------------------------------------------------------------------------------
* Destroy the managed blip entity.
*/
bool Destroy(Int32 header, Object & payload);
bool Destroy(Int32 header, LightObj & payload);
/* --------------------------------------------------------------------------------------------
* Bind to an event supported by this entity type.
* Retrieve the events table of this entity.
*/
void BindEvent(Int32 evid, Object & env, Function & func) const;
LightObj & GetEvents() const;
/* --------------------------------------------------------------------------------------------
* Emit a custom event for the managed entity
*/
void CustomEvent(Int32 header, Object & payload) const;
void CustomEvent(Int32 header, LightObj & payload) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the world in which the referenced blip entity exists.

View File

@ -33,7 +33,7 @@ SQInteger CCheckpoint::SqGetNull(HSQUIRRELVM vm)
}
// ------------------------------------------------------------------------------------------------
Object & CCheckpoint::GetNull()
LightObj & CCheckpoint::GetNull()
{
return Core::Get().GetNullCheckpoint();
}
@ -85,7 +85,7 @@ CCheckpoint & CCheckpoint::ApplyTag(const StackStrF & tag)
}
// ------------------------------------------------------------------------------------------------
Object & CCheckpoint::GetData()
LightObj & CCheckpoint::GetData()
{
// Validate the managed identifier
Validate();
@ -94,7 +94,7 @@ Object & CCheckpoint::GetData()
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::SetData(Object & data)
void CCheckpoint::SetData(LightObj & data)
{
// Validate the managed identifier
Validate();
@ -103,7 +103,7 @@ void CCheckpoint::SetData(Object & data)
}
// ------------------------------------------------------------------------------------------------
bool CCheckpoint::Destroy(Int32 header, Object & payload)
bool CCheckpoint::Destroy(Int32 header, LightObj & payload)
{
// Validate the managed identifier
Validate();
@ -112,31 +112,16 @@ bool CCheckpoint::Destroy(Int32 header, Object & payload)
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::BindEvent(Int32 evid, Object & env, Function & func) const
LightObj & CCheckpoint::GetEvents() const
{
// Validate the managed identifier
Validate();
// Obtain the function instance called for this event
Function & event = Core::Get().GetCheckpointEvent(m_ID, evid);
// Is the specified callback function null?
if (func.IsNull())
{
event.ReleaseGently(); // Then release the current callback
}
// Does this function need a custom environment?
else if (env.IsNull())
{
event = func;
}
// Assign the specified environment and function
else
{
event = Function(env.GetVM(), env, func.GetFunc());
}
// Return the associated event table
return Core::Get().GetCheckpoint(m_ID).mEvents;
}
// ------------------------------------------------------------------------------------------------
void CCheckpoint::CustomEvent(Int32 header, Object & payload) const
void CCheckpoint::CustomEvent(Int32 header, LightObj & payload) const
{
// Validate the managed identifier
Validate();
@ -302,7 +287,7 @@ void CCheckpoint::SetRadius(Float32 radius)
}
// ------------------------------------------------------------------------------------------------
Object & CCheckpoint::GetOwner() const
LightObj & CCheckpoint::GetOwner() const
{
// Validate the managed identifier
Validate();
@ -488,32 +473,32 @@ void CCheckpoint::SetColorA(Int32 a) const
}
// ------------------------------------------------------------------------------------------------
static Object & Checkpoint_CreateEx(Int32 world, bool sphere, Float32 x, Float32 y, Float32 z,
static LightObj & Checkpoint_CreateEx(Int32 world, bool sphere, Float32 x, Float32 y, Float32 z,
Uint8 r, Uint8 g, Uint8 b, Uint8 a, Float32 radius)
{
return Core::Get().NewCheckpoint(-1, world, sphere, x, y, z, r, g, b, a, radius,
SQMOD_CREATE_DEFAULT, NullObject());
SQMOD_CREATE_DEFAULT, NullLightObj());
}
static Object & Checkpoint_CreateEx(Int32 world, bool sphere, Float32 x, Float32 y, Float32 z,
static LightObj & Checkpoint_CreateEx(Int32 world, bool sphere, Float32 x, Float32 y, Float32 z,
Uint8 r, Uint8 g, Uint8 b, Uint8 a, Float32 radius,
Int32 header, Object & payload)
Int32 header, LightObj & payload)
{
return Core::Get().NewCheckpoint(-1, world, sphere, x, y, z, r, g, b, a,
radius, header, payload);
}
// ------------------------------------------------------------------------------------------------
static Object & Checkpoint_Create(Int32 world, bool sphere, const Vector3 & pos,
static LightObj & Checkpoint_Create(Int32 world, bool sphere, const Vector3 & pos,
const Color4 & color, Float32 radius)
{
return Core::Get().NewCheckpoint(-1, world, sphere, pos.x, pos.y, pos.z,
color.r, color.g, color.b, color.a, radius,
SQMOD_CREATE_DEFAULT, NullObject());
SQMOD_CREATE_DEFAULT, NullLightObj());
}
static Object & Checkpoint_Create(Int32 world, bool sphere, const Vector3 & pos,
const Color4 & color, Float32 radius, Int32 header, Object & payload)
static LightObj & Checkpoint_Create(Int32 world, bool sphere, const Vector3 & pos,
const Color4 & color, Float32 radius, Int32 header, LightObj & payload)
{
return Core::Get().NewCheckpoint(-1, world, sphere, pos.x, pos.y, pos.z,
color.r, color.g, color.b, color.a, radius, header, payload);
@ -530,18 +515,18 @@ void Register_CCheckpoint(HSQUIRRELVM vm)
// Static Values
.SetStaticValue(_SC("MaxID"), CCheckpoint::Max)
// Core Properties
.Prop(_SC("On"), &CCheckpoint::GetEvents)
.Prop(_SC("ID"), &CCheckpoint::GetID)
.Prop(_SC("Tag"), &CCheckpoint::GetTag, &CCheckpoint::SetTag)
.Prop(_SC("Data"), &CCheckpoint::GetData, &CCheckpoint::SetData)
.Prop(_SC("Active"), &CCheckpoint::IsActive)
// Core Methods
.Func(_SC("Bind"), &CCheckpoint::BindEvent)
.FmtFunc(_SC("SetTag"), &CCheckpoint::ApplyTag)
.Func(_SC("CustomEvent"), &CCheckpoint::CustomEvent)
// Core Overloads
.Overload< bool (CCheckpoint::*)(void) >(_SC("Destroy"), &CCheckpoint::Destroy)
.Overload< bool (CCheckpoint::*)(Int32) >(_SC("Destroy"), &CCheckpoint::Destroy)
.Overload< bool (CCheckpoint::*)(Int32, Object &) >(_SC("Destroy"), &CCheckpoint::Destroy)
.Overload< bool (CCheckpoint::*)(Int32, LightObj &) >(_SC("Destroy"), &CCheckpoint::Destroy)
// Properties
.Prop(_SC("Sphere"), &CCheckpoint::IsSphere)
.Prop(_SC("World"), &CCheckpoint::GetWorld, &CCheckpoint::SetWorld)
@ -569,13 +554,13 @@ void Register_CCheckpoint(HSQUIRRELVM vm)
.Overload< void (CCheckpoint::*)(Uint8, Uint8, Uint8, Uint8) const >
(_SC("SetColor"), &CCheckpoint::SetColorEx)
// Static Overloads
.StaticOverload< Object & (*)(Int32, bool, Float32, Float32, Float32, Uint8, Uint8, Uint8, Uint8, Float32) >
.StaticOverload< LightObj & (*)(Int32, bool, Float32, Float32, Float32, Uint8, Uint8, Uint8, Uint8, Float32) >
(_SC("CreateEx"), &Checkpoint_CreateEx)
.StaticOverload< Object & (*)(Int32, bool, Float32, Float32, Float32, Uint8, Uint8, Uint8, Uint8, Float32, Int32, Object &) >
.StaticOverload< LightObj & (*)(Int32, bool, Float32, Float32, Float32, Uint8, Uint8, Uint8, Uint8, Float32, Int32, LightObj &) >
(_SC("CreateEx"), &Checkpoint_CreateEx)
.StaticOverload< Object & (*)(Int32, bool, const Vector3 &, const Color4 &, Float32) >
.StaticOverload< LightObj & (*)(Int32, bool, const Vector3 &, const Color4 &, Float32) >
(_SC("Create"), &Checkpoint_Create)
.StaticOverload< Object & (*)(Int32, bool, const Vector3 &, const Color4 &, Float32, Int32, Object &) >
.StaticOverload< LightObj & (*)(Int32, bool, const Vector3 &, const Color4 &, Float32, Int32, LightObj &) >
(_SC("Create"), &Checkpoint_Create)
// Raw Squirrel Methods
.SquirrelFunc(_SC("NullInst"), &CCheckpoint::SqGetNull)

View File

@ -46,7 +46,7 @@ private:
/* --------------------------------------------------------------------------------------------
* User data associated with this instance.
*/
Object m_Data;
LightObj m_Data;
/* --------------------------------------------------------------------------------------------
* Prevent events from triggering themselves.
@ -114,7 +114,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the associated null entity instance.
*/
static Object & GetNull();
static LightObj & GetNull();
/* --------------------------------------------------------------------------------------------
* Retrieve the identifier of the entity managed by this instance.
@ -150,19 +150,19 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user data.
*/
Object & GetData();
LightObj & GetData();
/* --------------------------------------------------------------------------------------------
* Modify the associated user data.
*/
void SetData(Object & data);
void SetData(LightObj & data);
/* --------------------------------------------------------------------------------------------
* Destroy the managed checkpoint entity.
*/
bool Destroy()
{
return Destroy(0, NullObject());
return Destroy(0, NullLightObj());
}
/* --------------------------------------------------------------------------------------------
@ -170,23 +170,23 @@ public:
*/
bool Destroy(Int32 header)
{
return Destroy(header, NullObject());
return Destroy(header, NullLightObj());
}
/* --------------------------------------------------------------------------------------------
* Destroy the managed checkpoint entity.
*/
bool Destroy(Int32 header, Object & payload);
bool Destroy(Int32 header, LightObj & payload);
/* --------------------------------------------------------------------------------------------
* Bind to an event supported by this entity type.
* Retrieve the events table of this entity.
*/
void BindEvent(Int32 evid, Object & env, Function & func) const;
LightObj & GetEvents() const;
/* --------------------------------------------------------------------------------------------
* Emit a custom event for the managed entity
*/
void CustomEvent(Int32 header, Object & payload) const;
void CustomEvent(Int32 header, LightObj & payload) const;
/* --------------------------------------------------------------------------------------------
* See if the managed checkpoint entity is streamed for the specified player.
@ -256,7 +256,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the owner of the managed checkpoint entity.
*/
Object & GetOwner() const;
LightObj & GetOwner() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the owner identifier of the managed checkpoint entity.

View File

@ -20,7 +20,7 @@ SQInteger CKeybind::SqGetNull(HSQUIRRELVM vm)
}
// ------------------------------------------------------------------------------------------------
Object & CKeybind::GetNull()
LightObj & CKeybind::GetNull()
{
return Core::Get().GetNullKeybind();
}
@ -72,7 +72,7 @@ CKeybind & CKeybind::ApplyTag(const StackStrF & tag)
}
// ------------------------------------------------------------------------------------------------
Object & CKeybind::GetData()
LightObj & CKeybind::GetData()
{
// Validate the managed identifier
Validate();
@ -81,7 +81,7 @@ Object & CKeybind::GetData()
}
// ------------------------------------------------------------------------------------------------
void CKeybind::SetData(Object & data)
void CKeybind::SetData(LightObj & data)
{
// Validate the managed identifier
Validate();
@ -90,7 +90,7 @@ void CKeybind::SetData(Object & data)
}
// ------------------------------------------------------------------------------------------------
bool CKeybind::Destroy(Int32 header, Object & payload)
bool CKeybind::Destroy(Int32 header, LightObj & payload)
{
// Validate the managed identifier
Validate();
@ -99,31 +99,16 @@ bool CKeybind::Destroy(Int32 header, Object & payload)
}
// ------------------------------------------------------------------------------------------------
void CKeybind::BindEvent(Int32 evid, Object & env, Function & func) const
LightObj & CKeybind::GetEvents() const
{
// Validate the managed identifier
Validate();
// Obtain the function instance called for this event
Function & event = Core::Get().GetKeybindEvent(m_ID, evid);
// Is the specified callback function null?
if (func.IsNull())
{
event.ReleaseGently(); // Then release the current callback
}
// Does this function need a custom environment?
else if (env.IsNull())
{
event = func;
}
// Assign the specified environment and function
else
{
event = Function(env.GetVM(), env, func.GetFunc());
}
// Return the associated event table
return Core::Get().GetKeybind(m_ID).mEvents;
}
// ------------------------------------------------------------------------------------------------
void CKeybind::CustomEvent(Int32 header, Object & payload) const
void CKeybind::CustomEvent(Int32 header, LightObj & payload) const
{
// Validate the managed identifier
Validate();
@ -168,28 +153,28 @@ bool CKeybind::IsRelease() const
}
// ------------------------------------------------------------------------------------------------
static Object & Keybind_CreateEx(Int32 slot, bool release, Int32 primary, Int32 secondary,
static LightObj & Keybind_CreateEx(Int32 slot, bool release, Int32 primary, Int32 secondary,
Int32 alternative)
{
return Core::Get().NewKeybind(slot, release, primary, secondary, alternative,
SQMOD_CREATE_DEFAULT, NullObject());
SQMOD_CREATE_DEFAULT, NullLightObj());
}
static Object & Keybind_CreateEx(Int32 slot, bool release, Int32 primary, Int32 secondary,
Int32 alternative, Int32 header, Object & payload)
static LightObj & Keybind_CreateEx(Int32 slot, bool release, Int32 primary, Int32 secondary,
Int32 alternative, Int32 header, LightObj & payload)
{
return Core::Get().NewKeybind(slot, release, primary, secondary, alternative, header, payload);
}
// ------------------------------------------------------------------------------------------------
static Object & Keybind_Create(bool release, Int32 primary, Int32 secondary, Int32 alternative)
static LightObj & Keybind_Create(bool release, Int32 primary, Int32 secondary, Int32 alternative)
{
return Core::Get().NewKeybind(-1, release, primary, secondary, alternative,
SQMOD_CREATE_DEFAULT, NullObject());
SQMOD_CREATE_DEFAULT, NullLightObj());
}
static Object & Keybind_Create(bool release, Int32 primary, Int32 secondary, Int32 alternative,
Int32 header, Object & payload)
static LightObj & Keybind_Create(bool release, Int32 primary, Int32 secondary, Int32 alternative,
Int32 header, LightObj & payload)
{
return Core::Get().NewKeybind(-1, release, primary, secondary, alternative, header, payload);
}
@ -211,18 +196,18 @@ void Register_CKeybind(HSQUIRRELVM vm)
// Static Values
.SetStaticValue(_SC("MaxID"), CKeybind::Max)
// Core Properties
.Prop(_SC("On"), &CKeybind::GetEvents)
.Prop(_SC("ID"), &CKeybind::GetID)
.Prop(_SC("Tag"), &CKeybind::GetTag, &CKeybind::SetTag)
.Prop(_SC("Data"), &CKeybind::GetData, &CKeybind::SetData)
.Prop(_SC("Active"), &CKeybind::IsActive)
// Core Methods
.Func(_SC("Bind"), &CKeybind::BindEvent)
.FmtFunc(_SC("SetTag"), &CKeybind::ApplyTag)
.Func(_SC("CustomEvent"), &CKeybind::CustomEvent)
// Core Overloads
.Overload< bool (CKeybind::*)(void) >(_SC("Destroy"), &CKeybind::Destroy)
.Overload< bool (CKeybind::*)(Int32) >(_SC("Destroy"), &CKeybind::Destroy)
.Overload< bool (CKeybind::*)(Int32, Object &) >(_SC("Destroy"), &CKeybind::Destroy)
.Overload< bool (CKeybind::*)(Int32, LightObj &) >(_SC("Destroy"), &CKeybind::Destroy)
// Properties
.Prop(_SC("First"), &CKeybind::GetFirst)
.Prop(_SC("Second"), &CKeybind::GetSecond)
@ -231,13 +216,13 @@ void Register_CKeybind(HSQUIRRELVM vm)
// Static Functions
.StaticFunc(_SC("UnusedSlot"), &Keybind_UnusedSlot)
// Static Overloads
.StaticOverload< Object & (*)(Int32, bool, Int32, Int32, Int32) >
.StaticOverload< LightObj & (*)(Int32, bool, Int32, Int32, Int32) >
(_SC("CreateEx"), &Keybind_CreateEx)
.StaticOverload< Object & (*)(Int32, bool, Int32, Int32, Int32, Int32, Object &) >
.StaticOverload< LightObj & (*)(Int32, bool, Int32, Int32, Int32, Int32, LightObj &) >
(_SC("CreateEx"), &Keybind_CreateEx)
.StaticOverload< Object & (*)(bool, Int32, Int32, Int32) >
.StaticOverload< LightObj & (*)(bool, Int32, Int32, Int32) >
(_SC("Create"), &Keybind_Create)
.StaticOverload< Object & (*)(bool, Int32, Int32, Int32, Int32, Object &) >
.StaticOverload< LightObj & (*)(bool, Int32, Int32, Int32, Int32, LightObj &) >
(_SC("Create"), &Keybind_Create)
// Raw Squirrel Methods
.SquirrelFunc(_SC("NullInst"), &CKeybind::SqGetNull)

View File

@ -30,7 +30,7 @@ private:
/* --------------------------------------------------------------------------------------------
* User data associated with this instance.
*/
Object m_Data;
LightObj m_Data;
/* --------------------------------------------------------------------------------------------
* Base constructor.
@ -93,7 +93,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the associated null entity instance.
*/
static Object & GetNull();
static LightObj & GetNull();
/* --------------------------------------------------------------------------------------------
* Retrieve the identifier of the entity managed by this instance.
@ -129,19 +129,19 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user data.
*/
Object & GetData();
LightObj & GetData();
/* --------------------------------------------------------------------------------------------
* Modify the associated user data.
*/
void SetData(Object & data);
void SetData(LightObj & data);
/* --------------------------------------------------------------------------------------------
* Destroy the managed destroy entity.
*/
bool Destroy()
{
return Destroy(0, NullObject());
return Destroy(0, NullLightObj());
}
/* --------------------------------------------------------------------------------------------
@ -149,23 +149,23 @@ public:
*/
bool Destroy(Int32 header)
{
return Destroy(header, NullObject());
return Destroy(header, NullLightObj());
}
/* --------------------------------------------------------------------------------------------
* Destroy the managed destroy entity.
*/
bool Destroy(Int32 header, Object & payload);
bool Destroy(Int32 header, LightObj & payload);
/* --------------------------------------------------------------------------------------------
* Bind to an event supported by this entity type.
* Retrieve the events table of this entity.
*/
void BindEvent(Int32 evid, Object & env, Function & func) const;
LightObj & GetEvents() const;
/* --------------------------------------------------------------------------------------------
* Emit a custom event for the managed entity
*/
void CustomEvent(Int32 header, Object & payload) const;
void CustomEvent(Int32 header, LightObj & payload) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the first key code of the managed keybind entity.

View File

@ -27,7 +27,7 @@ SQInteger CObject::SqGetNull(HSQUIRRELVM vm)
}
// ------------------------------------------------------------------------------------------------
Object & CObject::GetNull()
LightObj & CObject::GetNull()
{
return Core::Get().GetNullObject();
}
@ -85,7 +85,7 @@ CObject & CObject::ApplyTag(const StackStrF & tag)
}
// ------------------------------------------------------------------------------------------------
Object & CObject::GetData()
LightObj & CObject::GetData()
{
// Validate the managed identifier
Validate();
@ -94,7 +94,7 @@ Object & CObject::GetData()
}
// ------------------------------------------------------------------------------------------------
void CObject::SetData(Object & data)
void CObject::SetData(LightObj & data)
{
// Validate the managed identifier
Validate();
@ -103,7 +103,7 @@ void CObject::SetData(Object & data)
}
// ------------------------------------------------------------------------------------------------
bool CObject::Destroy(Int32 header, Object & payload)
bool CObject::Destroy(Int32 header, LightObj & payload)
{
// Validate the managed identifier
Validate();
@ -112,31 +112,16 @@ bool CObject::Destroy(Int32 header, Object & payload)
}
// ------------------------------------------------------------------------------------------------
void CObject::BindEvent(Int32 evid, Object & env, Function & func) const
LightObj & CObject::GetEvents() const
{
// Validate the managed identifier
Validate();
// Obtain the function instance called for this event
Function & event = Core::Get().GetObjectEvent(m_ID, evid);
// Is the specified callback function null?
if (func.IsNull())
{
event.ReleaseGently(); // Then release the current callback
}
// Does this function need a custom environment?
else if (env.IsNull())
{
event = func;
}
// Assign the specified environment and function
else
{
event = Function(env.GetVM(), env, func.GetFunc());
}
// Return the associated event table
return Core::Get().GetObject(m_ID).mEvents;
}
// ------------------------------------------------------------------------------------------------
void CObject::CustomEvent(Int32 header, Object & payload) const
void CObject::CustomEvent(Int32 header, LightObj & payload) const
{
// Validate the managed identifier
Validate();
@ -854,27 +839,27 @@ void CObject::RotateByEulerZ(Float32 z) const
}
// ------------------------------------------------------------------------------------------------
static Object & Object_CreateEx(Int32 model, Int32 world, Float32 x, Float32 y, Float32 z,
static LightObj & Object_CreateEx(Int32 model, Int32 world, Float32 x, Float32 y, Float32 z,
Int32 alpha)
{
return Core::Get().NewObject(model, world, x, y, z, alpha, SQMOD_CREATE_DEFAULT, NullObject());
return Core::Get().NewObject(model, world, x, y, z, alpha, SQMOD_CREATE_DEFAULT, NullLightObj());
}
static Object & Object_CreateEx(Int32 model, Int32 world, Float32 x, Float32 y, Float32 z,
Int32 alpha, Int32 header, Object & payload)
static LightObj & Object_CreateEx(Int32 model, Int32 world, Float32 x, Float32 y, Float32 z,
Int32 alpha, Int32 header, LightObj & payload)
{
return Core::Get().NewObject(model, world, x, y, z, alpha, header, payload);
}
// ------------------------------------------------------------------------------------------------
static Object & Object_Create(Int32 model, Int32 world, const Vector3 & pos, Int32 alpha)
static LightObj & Object_Create(Int32 model, Int32 world, const Vector3 & pos, Int32 alpha)
{
return Core::Get().NewObject(model, world, pos.x, pos.y, pos.z, alpha,
SQMOD_CREATE_DEFAULT, NullObject());
SQMOD_CREATE_DEFAULT, NullLightObj());
}
static Object & Object_Create(Int32 model, Int32 world, const Vector3 & pos, Int32 alpha,
Int32 header, Object & payload)
static LightObj & Object_Create(Int32 model, Int32 world, const Vector3 & pos, Int32 alpha,
Int32 header, LightObj & payload)
{
return Core::Get().NewObject(model, world, pos.x, pos.y, pos.z, alpha, header, payload);
}
@ -897,18 +882,18 @@ void Register_CObject(HSQUIRRELVM vm)
.Var(_SC("RotateToEulerDuration"), &CObject::mRotateToEulerDuration)
.Var(_SC("RotateByEulerDuration"), &CObject::mRotateByEulerDuration)
// Core Properties
.Prop(_SC("On"), &CObject::GetEvents)
.Prop(_SC("ID"), &CObject::GetID)
.Prop(_SC("Tag"), &CObject::GetTag, &CObject::SetTag)
.Prop(_SC("Data"), &CObject::GetData, &CObject::SetData)
.Prop(_SC("Active"), &CObject::IsActive)
// Core Methods
.Func(_SC("Bind"), &CObject::BindEvent)
.FmtFunc(_SC("SetTag"), &CObject::ApplyTag)
.Func(_SC("CustomEvent"), &CObject::CustomEvent)
// Core Overloads
.Overload< bool (CObject::*)(void) >(_SC("Destroy"), &CObject::Destroy)
.Overload< bool (CObject::*)(Int32) >(_SC("Destroy"), &CObject::Destroy)
.Overload< bool (CObject::*)(Int32, Object &) >(_SC("Destroy"), &CObject::Destroy)
.Overload< bool (CObject::*)(Int32, LightObj &) >(_SC("Destroy"), &CObject::Destroy)
// Properties
.Prop(_SC("Model"), &CObject::GetModel)
.Prop(_SC("World"), &CObject::GetWorld, &CObject::SetWorld)
@ -982,13 +967,13 @@ void Register_CObject(HSQUIRRELVM vm)
.Overload< void (CObject::*)(Float32, Float32, Float32, Uint32) const >
(_SC("RotateByEuler"), &CObject::RotateByEulerEx)
// Static Overloads
.StaticOverload< Object & (*)(Int32, Int32, Float32, Float32, Float32, Int32) >
.StaticOverload< LightObj & (*)(Int32, Int32, Float32, Float32, Float32, Int32) >
(_SC("CreateEx"), &Object_CreateEx)
.StaticOverload< Object & (*)(Int32, Int32, Float32, Float32, Float32, Int32, Int32, Object &) >
.StaticOverload< LightObj & (*)(Int32, Int32, Float32, Float32, Float32, Int32, Int32, LightObj &) >
(_SC("CreateEx"), &Object_CreateEx)
.StaticOverload< Object & (*)(Int32, Int32, const Vector3 &, Int32) >
.StaticOverload< LightObj & (*)(Int32, Int32, const Vector3 &, Int32) >
(_SC("Create"), &Object_Create)
.StaticOverload< Object & (*)(Int32, Int32, const Vector3 &, Int32, Int32, Object &) >
.StaticOverload< LightObj & (*)(Int32, Int32, const Vector3 &, Int32, Int32, LightObj &) >
(_SC("Create"), &Object_Create)
// Raw Squirrel Methods
.SquirrelFunc(_SC("NullInst"), &CObject::SqGetNull)

View File

@ -44,7 +44,7 @@ private:
/* --------------------------------------------------------------------------------------------
* User data associated with this instance.
*/
Object m_Data;
LightObj m_Data;
/* --------------------------------------------------------------------------------------------
* Prevent events from triggering themselves.
@ -130,7 +130,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the associated null entity instance.
*/
static Object & GetNull();
static LightObj & GetNull();
/* --------------------------------------------------------------------------------------------
* Retrieve the identifier of the entity managed by this instance.
@ -166,19 +166,19 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user data.
*/
Object & GetData();
LightObj & GetData();
/* --------------------------------------------------------------------------------------------
* Modify the associated user data.
*/
void SetData(Object & data);
void SetData(LightObj & data);
/* --------------------------------------------------------------------------------------------
* Destroy the managed object entity.
*/
bool Destroy()
{
return Destroy(0, NullObject());
return Destroy(0, NullLightObj());
}
/* --------------------------------------------------------------------------------------------
@ -186,23 +186,23 @@ public:
*/
bool Destroy(Int32 header)
{
return Destroy(header, NullObject());
return Destroy(header, NullLightObj());
}
/* --------------------------------------------------------------------------------------------
* Destroy the managed object entity.
*/
bool Destroy(Int32 header, Object & payload);
bool Destroy(Int32 header, LightObj & payload);
/* --------------------------------------------------------------------------------------------
* Bind to an event supported by this entity type.
* Retrieve the events table of this entity.
*/
void BindEvent(Int32 evid, Object & env, Function & func) const;
LightObj & GetEvents() const;
/* --------------------------------------------------------------------------------------------
* Emit a custom event for the managed entity
*/
void CustomEvent(Int32 header, Object & payload) const;
void CustomEvent(Int32 header, LightObj & payload) const;
/* --------------------------------------------------------------------------------------------
* See if the managed object entity is streamed for the specified player.

View File

@ -25,7 +25,7 @@ SQInteger CPickup::SqGetNull(HSQUIRRELVM vm)
}
// ------------------------------------------------------------------------------------------------
Object & CPickup::GetNull()
LightObj & CPickup::GetNull()
{
return Core::Get().GetNullPickup();
}
@ -77,7 +77,7 @@ CPickup & CPickup::ApplyTag(const StackStrF & tag)
}
// ------------------------------------------------------------------------------------------------
Object & CPickup::GetData()
LightObj & CPickup::GetData()
{
// Validate the managed identifier
Validate();
@ -86,7 +86,7 @@ Object & CPickup::GetData()
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetData(Object & data)
void CPickup::SetData(LightObj & data)
{
// Validate the managed identifier
Validate();
@ -95,7 +95,7 @@ void CPickup::SetData(Object & data)
}
// ------------------------------------------------------------------------------------------------
bool CPickup::Destroy(Int32 header, Object & payload)
bool CPickup::Destroy(Int32 header, LightObj & payload)
{
// Validate the managed identifier
Validate();
@ -104,31 +104,16 @@ bool CPickup::Destroy(Int32 header, Object & payload)
}
// ------------------------------------------------------------------------------------------------
void CPickup::BindEvent(Int32 evid, Object & env, Function & func) const
LightObj & CPickup::GetEvents() const
{
// Validate the managed identifier
Validate();
// Obtain the function instance called for this event
Function & event = Core::Get().GetPickupEvent(m_ID, evid);
// Is the specified callback function null?
if (func.IsNull())
{
event.ReleaseGently(); // Then release the current callback
}
// Does this function need a custom environment?
else if (env.IsNull())
{
event = func;
}
// Assign the specified environment and function
else
{
event = Function(env.GetVM(), env, func.GetFunc());
}
// Return the associated event table
return Core::Get().GetPickup(m_ID).mEvents;
}
// ------------------------------------------------------------------------------------------------
void CPickup::CustomEvent(Int32 header, Object & payload) const
void CPickup::CustomEvent(Int32 header, LightObj & payload) const
{
// Validate the managed identifier
Validate();
@ -413,30 +398,30 @@ void CPickup::SetPositionZ(Float32 z) const
}
// ------------------------------------------------------------------------------------------------
static Object & Pickup_CreateEx(Int32 model, Int32 world, Int32 quantity,
static LightObj & Pickup_CreateEx(Int32 model, Int32 world, Int32 quantity,
Float32 x, Float32 y, Float32 z, Int32 alpha, bool automatic)
{
return Core::Get().NewPickup(model, world, quantity, x, y, z, alpha, automatic,
SQMOD_CREATE_DEFAULT, NullObject());
SQMOD_CREATE_DEFAULT, NullLightObj());
}
static Object & Pickup_CreateEx(Int32 model, Int32 world, Int32 quantity,
static LightObj & Pickup_CreateEx(Int32 model, Int32 world, Int32 quantity,
Float32 x, Float32 y, Float32 z, Int32 alpha, bool automatic,
Int32 header, Object & payload)
Int32 header, LightObj & payload)
{
return Core::Get().NewPickup(model, world, quantity, x, y, z, alpha, automatic, header, payload);
}
// ------------------------------------------------------------------------------------------------
static Object & Pickup_Create(Int32 model, Int32 world, Int32 quantity, const Vector3 & pos,
static LightObj & Pickup_Create(Int32 model, Int32 world, Int32 quantity, const Vector3 & pos,
Int32 alpha, bool automatic)
{
return Core::Get().NewPickup(model, world, quantity, pos.x, pos.y, pos.z, alpha, automatic,
SQMOD_CREATE_DEFAULT, NullObject());
SQMOD_CREATE_DEFAULT, NullLightObj());
}
static Object & Pickup_Create(Int32 model, Int32 world, Int32 quantity, const Vector3 & pos,
Int32 alpha, bool automatic, Int32 header, Object & payload)
static LightObj & Pickup_Create(Int32 model, Int32 world, Int32 quantity, const Vector3 & pos,
Int32 alpha, bool automatic, Int32 header, LightObj & payload)
{
return Core::Get().NewPickup(model, world, quantity, pos.x, pos.y, pos.z, alpha, automatic,
header, payload);
@ -453,18 +438,18 @@ void Register_CPickup(HSQUIRRELVM vm)
// Static Values
.SetStaticValue(_SC("MaxID"), CPickup::Max)
// Core Properties
.Prop(_SC("On"), &CPickup::GetEvents)
.Prop(_SC("ID"), &CPickup::GetID)
.Prop(_SC("Tag"), &CPickup::GetTag, &CPickup::SetTag)
.Prop(_SC("Data"), &CPickup::GetData, &CPickup::SetData)
.Prop(_SC("Active"), &CPickup::IsActive)
// Core Methods
.Func(_SC("Bind"), &CPickup::BindEvent)
.FmtFunc(_SC("SetTag"), &CPickup::ApplyTag)
.Func(_SC("CustomEvent"), &CPickup::CustomEvent)
// Core Overloads
.Overload< bool (CPickup::*)(void) >(_SC("Destroy"), &CPickup::Destroy)
.Overload< bool (CPickup::*)(Int32) >(_SC("Destroy"), &CPickup::Destroy)
.Overload< bool (CPickup::*)(Int32, Object &) >(_SC("Destroy"), &CPickup::Destroy)
.Overload< bool (CPickup::*)(Int32, LightObj &) >(_SC("Destroy"), &CPickup::Destroy)
// Properties
.Prop(_SC("Model"), &CPickup::GetModel)
.Prop(_SC("World"), &CPickup::GetWorld, &CPickup::SetWorld)
@ -485,13 +470,13 @@ void Register_CPickup(HSQUIRRELVM vm)
.Func(_SC("SetPos"), &CPickup::SetPositionEx)
.Func(_SC("SetPosition"), &CPickup::SetPositionEx)
// Static Overloads
.StaticOverload< Object & (*)(Int32, Int32, Int32, Float32, Float32, Float32, Int32, bool) >
.StaticOverload< LightObj & (*)(Int32, Int32, Int32, Float32, Float32, Float32, Int32, bool) >
(_SC("CreateEx"), &Pickup_CreateEx)
.StaticOverload< Object & (*)(Int32, Int32, Int32, Float32, Float32, Float32, Int32, bool, Int32, Object &) >
.StaticOverload< LightObj & (*)(Int32, Int32, Int32, Float32, Float32, Float32, Int32, bool, Int32, LightObj &) >
(_SC("CreateEx"), &Pickup_CreateEx)
.StaticOverload< Object & (*)(Int32, Int32, Int32, const Vector3 &, Int32, bool) >
.StaticOverload< LightObj & (*)(Int32, Int32, Int32, const Vector3 &, Int32, bool) >
(_SC("Create"), &Pickup_Create)
.StaticOverload< Object & (*)(Int32, Int32, Int32, const Vector3 &, Int32, bool, Int32, Object &) >
.StaticOverload< LightObj & (*)(Int32, Int32, Int32, const Vector3 &, Int32, bool, Int32, LightObj &) >
(_SC("Create"), &Pickup_Create)
// Raw Squirrel Methods
.SquirrelFunc(_SC("NullInst"), &CPickup::SqGetNull)

View File

@ -44,7 +44,7 @@ private:
/* --------------------------------------------------------------------------------------------
* User data associated with this instance.
*/
Object m_Data;
LightObj m_Data;
/* --------------------------------------------------------------------------------------------
* Prevent events from triggering themselves.
@ -112,7 +112,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the associated null entity instance.
*/
static Object & GetNull();
static LightObj & GetNull();
/* --------------------------------------------------------------------------------------------
* Retrieve the identifier of the entity managed by this instance.
@ -148,19 +148,19 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user data.
*/
Object & GetData();
LightObj & GetData();
/* --------------------------------------------------------------------------------------------
* Modify the associated user data.
*/
void SetData(Object & data);
void SetData(LightObj & data);
/* --------------------------------------------------------------------------------------------
* Destroy the managed pickup entity.
*/
bool Destroy()
{
return Destroy(0, NullObject());
return Destroy(0, NullLightObj());
}
/* --------------------------------------------------------------------------------------------
@ -168,23 +168,23 @@ public:
*/
bool Destroy(Int32 header)
{
return Destroy(header, NullObject());
return Destroy(header, NullLightObj());
}
/* --------------------------------------------------------------------------------------------
* Destroy the managed pickup entity.
*/
bool Destroy(Int32 header, Object & payload);
bool Destroy(Int32 header, LightObj & payload);
/* --------------------------------------------------------------------------------------------
* Bind to an event supported by this entity type.
* Retrieve the events table of this entity.
*/
void BindEvent(Int32 evid, Object & env, Function & func) const;
LightObj & GetEvents() const;
/* --------------------------------------------------------------------------------------------
* Emit a custom event for the managed entity
*/
void CustomEvent(Int32 header, Object & payload) const;
void CustomEvent(Int32 header, LightObj & payload) const;
/* --------------------------------------------------------------------------------------------
* See if the managed pickup entity is streamed for the specified player.

View File

@ -41,7 +41,7 @@ SQInteger CPlayer::SqGetNull(HSQUIRRELVM vm)
}
// ------------------------------------------------------------------------------------------------
Object & CPlayer::GetNull()
LightObj & CPlayer::GetNull()
{
return Core::Get().GetNullPlayer();
}
@ -107,7 +107,7 @@ CPlayer & CPlayer::ApplyTag(const StackStrF & tag)
}
// ------------------------------------------------------------------------------------------------
Object & CPlayer::GetData()
LightObj & CPlayer::GetData()
{
// Validate the managed identifier
Validate();
@ -116,7 +116,7 @@ Object & CPlayer::GetData()
}
// ------------------------------------------------------------------------------------------------
void CPlayer::SetData(Object & data)
void CPlayer::SetData(LightObj & data)
{
// Validate the managed identifier
Validate();
@ -125,31 +125,16 @@ void CPlayer::SetData(Object & data)
}
// ------------------------------------------------------------------------------------------------
void CPlayer::BindEvent(Int32 evid, Object & env, Function & func) const
LightObj & CPlayer::GetEvents() const
{
// Validate the managed identifier
Validate();
// Obtain the function instance called for this event
Function & event = Core::Get().GetPlayerEvent(m_ID, evid);
// Is the specified callback function null?
if (func.IsNull())
{
event.ReleaseGently(); // Then release the current callback
}
// Does this function need a custom environment?
else if (env.IsNull())
{
event = func;
}
// Assign the specified environment and function
else
{
event = Function(env.GetVM(), env, func.GetFunc());
}
// Return the associated event table
return Core::Get().GetPlayer(m_ID).mEvents;
}
// ------------------------------------------------------------------------------------------------
void CPlayer::CustomEvent(Int32 header, Object & payload) const
void CPlayer::CustomEvent(Int32 header, LightObj & payload) const
{
// Validate the managed identifier
Validate();
@ -265,13 +250,13 @@ void CPlayer::Kick() const
Validate();
// Store the default header and payload
Core::Get().GetPlayer(m_ID).mKickBanHeader = vcmpDisconnectReasonKick;
Core::Get().GetPlayer(m_ID).mKickBanPayload = NullObject();
Core::Get().GetPlayer(m_ID).mKickBanPayload = NullLightObj();
// Perform the requested operation
_Func->KickPlayer(m_ID);
}
// ------------------------------------------------------------------------------------------------
void CPlayer::KickBecause(Int32 header, Object & payload) const
void CPlayer::KickBecause(Int32 header, LightObj & payload) const
{
// Validate the managed identifier
Validate();
@ -289,13 +274,13 @@ void CPlayer::Ban() const
Validate();
// Store the default header and payload
Core::Get().GetPlayer(m_ID).mKickBanHeader = vcmpDisconnectReasonKick;
Core::Get().GetPlayer(m_ID).mKickBanPayload = NullObject();
Core::Get().GetPlayer(m_ID).mKickBanPayload = NullLightObj();
// Perform the requested operation
_Func->BanPlayer(m_ID);
}
// ------------------------------------------------------------------------------------------------
void CPlayer::BanBecause(Int32 header, Object & payload) const
void CPlayer::BanBecause(Int32 header, LightObj & payload) const
{
// Validate the managed identifier
Validate();
@ -379,11 +364,11 @@ Int32 CPlayer::GetOption(Int32 option_id) const
// ------------------------------------------------------------------------------------------------
void CPlayer::SetOption(Int32 option_id, bool toggle)
{
SetOptionEx(option_id, toggle, 0, NullObject());
SetOptionEx(option_id, toggle, 0, NullLightObj());
}
// ------------------------------------------------------------------------------------------------
void CPlayer::SetOptionEx(Int32 option_id, bool toggle, Int32 header, Object & payload)
void CPlayer::SetOptionEx(Int32 option_id, bool toggle, Int32 header, LightObj & payload)
{
// Validate the managed identifier
Validate();
@ -1099,7 +1084,7 @@ Int32 CPlayer::GetVehicleSlot() const
}
// ------------------------------------------------------------------------------------------------
Object & CPlayer::GetVehicle() const
LightObj & CPlayer::GetVehicle() const
{
// Validate the managed identifier
Validate();
@ -1112,7 +1097,7 @@ Object & CPlayer::GetVehicle() const
return Core::Get().GetVehicle(id).mObj;
}
// Default to a null object
return NullObject();
return NullLightObj();
}
// ------------------------------------------------------------------------------------------------
@ -1300,7 +1285,7 @@ void CPlayer::SetAnimation(Int32 anim, Int32 group) const
}
// ------------------------------------------------------------------------------------------------
Object & CPlayer::StandingOnVehicle() const
LightObj & CPlayer::StandingOnVehicle() const
{
// Validate the managed identifier
Validate();
@ -1313,11 +1298,11 @@ Object & CPlayer::StandingOnVehicle() const
return Core::Get().GetVehicle(id).mObj;
}
// Default to a null object
return NullObject();
return NullLightObj();
}
// ------------------------------------------------------------------------------------------------
Object & CPlayer::StandingOnObject() const
LightObj & CPlayer::StandingOnObject() const
{
// Validate the managed identifier
Validate();
@ -1330,7 +1315,7 @@ Object & CPlayer::StandingOnObject() const
return Core::Get().GetObject(id).mObj;
}
// Default to a null object
return NullObject();
return NullLightObj();
}
// ------------------------------------------------------------------------------------------------
@ -1343,7 +1328,7 @@ bool CPlayer::IsAway() const
}
// ------------------------------------------------------------------------------------------------
Object & CPlayer::GetSpectator() const
LightObj & CPlayer::GetSpectator() const
{
// Validate the managed identifier
Validate();
@ -1356,7 +1341,7 @@ Object & CPlayer::GetSpectator() const
return Core::Get().GetPlayer(id).mObj;
}
// Default to a null object
return NullObject();
return NullLightObj();
}
// ------------------------------------------------------------------------------------------------
@ -1392,20 +1377,20 @@ void CPlayer::PlaySound(Int32 sound_id) const
}
// ------------------------------------------------------------------------------------------------
Object & CPlayer::CreateCheckpointEx(Int32 world, bool sphere, Float32 x, Float32 y, Float32 z,
LightObj & CPlayer::CreateCheckpointEx(Int32 world, bool sphere, Float32 x, Float32 y, Float32 z,
Uint8 r, Uint8 g, Uint8 b, Uint8 a, Float32 radius) const
{
// Validate the managed identifier
Validate();
// Perform the requested operation
return Core::Get().NewCheckpoint(m_ID, world, sphere, x, y, z, r, g, b, a, radius,
SQMOD_CREATE_DEFAULT, NullObject());
SQMOD_CREATE_DEFAULT, NullLightObj());
}
// ------------------------------------------------------------------------------------------------
Object & CPlayer::CreateCheckpointEx(Int32 world, bool sphere, Float32 x, Float32 y, Float32 z,
LightObj & CPlayer::CreateCheckpointEx(Int32 world, bool sphere, Float32 x, Float32 y, Float32 z,
Uint8 r, Uint8 g, Uint8 b, Uint8 a, Float32 radius,
Int32 header, Object & payload) const
Int32 header, LightObj & payload) const
{
// Validate the managed identifier
Validate();
@ -1415,7 +1400,7 @@ Object & CPlayer::CreateCheckpointEx(Int32 world, bool sphere, Float32 x, Float3
}
// ------------------------------------------------------------------------------------------------
Object & CPlayer::CreateCheckpoint(Int32 world, bool sphere, const Vector3 & pos,
LightObj & CPlayer::CreateCheckpoint(Int32 world, bool sphere, const Vector3 & pos,
const Color4 & color, Float32 radius) const
{
// Validate the managed identifier
@ -1423,12 +1408,12 @@ Object & CPlayer::CreateCheckpoint(Int32 world, bool sphere, const Vector3 & pos
// Perform the requested operation
return Core::Get().NewCheckpoint(m_ID, world, sphere, pos.x, pos.y, pos.z,
color.r, color.g, color.b, color.a, radius,
SQMOD_CREATE_DEFAULT, NullObject());
SQMOD_CREATE_DEFAULT, NullLightObj());
}
// ------------------------------------------------------------------------------------------------
Object & CPlayer::CreateCheckpoint(Int32 world, bool sphere, const Vector3 & pos, const Color4 & color,
Float32 radius, Int32 header, Object & payload) const
LightObj & CPlayer::CreateCheckpoint(Int32 world, bool sphere, const Vector3 & pos, const Color4 & color,
Float32 radius, Int32 header, LightObj & payload) const
{
// Validate the managed identifier
Validate();
@ -1502,7 +1487,7 @@ void CPlayer::SetTrackPosition(SQInteger num) const
}
// ------------------------------------------------------------------------------------------------
void CPlayer::SetTrackPositionEx(SQInteger num, Int32 header, const Object & payload) const
void CPlayer::SetTrackPositionEx(SQInteger num, Int32 header, const LightObj & payload) const
{
// Validate the managed identifier
Validate();
@ -2315,7 +2300,7 @@ SQInteger CPlayer::AnnounceEx(HSQUIRRELVM vm)
}
// ------------------------------------------------------------------------------------------------
static const Object & Player_FindAuto(Object & by)
static const LightObj & Player_FindAuto(Object & by)
{
switch (by.GetType())
{
@ -2342,7 +2327,7 @@ static const Object & Player_FindAuto(Object & by)
default: STHROWF("Unsupported search identifier");
}
// Default to a null object
return NullObject();
return NullLightObj();
}
// ================================================================================================
@ -2366,12 +2351,12 @@ void Register_CPlayer(HSQUIRRELVM vm)
.Var(_SC("AnnouncePostfix"), &CPlayer::mAnnouncePostfix)
.Var(_SC("LimitPrefixPostfixMessage"), &CPlayer::mLimitPrefixPostfixMessage)
// Core Properties
.Prop(_SC("On"), &CPlayer::GetEvents)
.Prop(_SC("ID"), &CPlayer::GetID)
.Prop(_SC("Tag"), &CPlayer::GetTag, &CPlayer::SetTag)
.Prop(_SC("Data"), &CPlayer::GetData, &CPlayer::SetData)
.Prop(_SC("Active"), &CPlayer::IsActive)
// Core Methods
.Func(_SC("Bind"), &CPlayer::BindEvent)
.FmtFunc(_SC("SetTag"), &CPlayer::ApplyTag)
.Func(_SC("CustomEvent"), &CPlayer::CustomEvent)
// Properties
@ -2510,13 +2495,13 @@ void Register_CPlayer(HSQUIRRELVM vm)
(_SC("SetAnimation"), &CPlayer::SetAnimation)
.Overload< void (CPlayer::*)(Int32, Int32) const >
(_SC("SetAnimation"), &CPlayer::SetAnimation)
.Overload< Object & (CPlayer::*)(Int32, bool, Float32, Float32, Float32, Uint8, Uint8, Uint8, Uint8, Float32) const >
.Overload< LightObj & (CPlayer::*)(Int32, bool, Float32, Float32, Float32, Uint8, Uint8, Uint8, Uint8, Float32) const >
(_SC("CreateCheckpointEx"), &CPlayer::CreateCheckpointEx)
.Overload< Object & (CPlayer::*)(Int32, bool, Float32, Float32, Float32, Uint8, Uint8, Uint8, Uint8, Float32, Int32, Object &) const >
.Overload< LightObj & (CPlayer::*)(Int32, bool, Float32, Float32, Float32, Uint8, Uint8, Uint8, Uint8, Float32, Int32, LightObj &) const >
(_SC("CreateCheckpointEx"), &CPlayer::CreateCheckpointEx)
.Overload< Object & (CPlayer::*)(Int32, bool, const Vector3 &, const Color4 &, Float32) const >
.Overload< LightObj & (CPlayer::*)(Int32, bool, const Vector3 &, const Color4 &, Float32) const >
(_SC("CreateCheckpoint"), &CPlayer::CreateCheckpoint)
.Overload< Object & (CPlayer::*)(Int32, bool, const Vector3 &, const Color4 &, Float32, Int32, Object &) const >
.Overload< LightObj & (CPlayer::*)(Int32, bool, const Vector3 &, const Color4 &, Float32, Int32, LightObj &) const >
(_SC("CreateCheckpoint"), &CPlayer::CreateCheckpoint)
// Static Functions
.StaticFunc(_SC("Find"), &Player_FindAuto)

View File

@ -55,7 +55,7 @@ private:
/* --------------------------------------------------------------------------------------------
* User data associated with this instance.
*/
Object m_Data;
LightObj m_Data;
/* --------------------------------------------------------------------------------------------
* Buffer used to generate client data.
@ -181,7 +181,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the associated null entity instance.
*/
static Object & GetNull();
static LightObj & GetNull();
/* --------------------------------------------------------------------------------------------
* Retrieve the identifier of the entity managed by this instance.
@ -217,22 +217,22 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user data.
*/
Object & GetData();
LightObj & GetData();
/* --------------------------------------------------------------------------------------------
* Modify the associated user data.
*/
void SetData(Object & data);
void SetData(LightObj & data);
/* --------------------------------------------------------------------------------------------
* Bind to an event supported by this entity type.
* Retrieve the events table of this entity.
*/
void BindEvent(Int32 evid, Object & env, Function & func) const;
LightObj & GetEvents() const;
/* --------------------------------------------------------------------------------------------
* Emit a custom event for the managed entity
*/
void CustomEvent(Int32 header, Object & payload) const;
void CustomEvent(Int32 header, LightObj & payload) const;
/* --------------------------------------------------------------------------------------------
* See whether the managed player entity is connected.
@ -277,7 +277,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Kick the managed player entity from the server.
*/
void KickBecause(Int32 header, Object & payload) const;
void KickBecause(Int32 header, LightObj & payload) const;
/* --------------------------------------------------------------------------------------------
* Ban the managed player entity from the server.
@ -287,7 +287,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Ban the managed player entity from the server.
*/
void BanBecause(Int32 header, Object & payload) const;
void BanBecause(Int32 header, LightObj & payload) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the key of the managed player entity.
@ -322,7 +322,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Modify the current option value of the managed player entity.
*/
void SetOptionEx(Int32 option_id, bool toggle, Int32 header, Object & payload);
void SetOptionEx(Int32 option_id, bool toggle, Int32 header, LightObj & payload);
/* --------------------------------------------------------------------------------------------
* Retrieve the world in which the managed player entity exists.
@ -612,7 +612,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the vehicle in which the managed player entity is embarked.
*/
Object & GetVehicle() const;
LightObj & GetVehicle() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the vehicle identifier in which the managed player entity is embarked.
@ -707,12 +707,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the vehicle that the managed player entity is standing on.
*/
Object & StandingOnVehicle() const;
LightObj & StandingOnVehicle() const;
/* --------------------------------------------------------------------------------------------
* Retrieve the object that the managed player entity is standing on.
*/
Object & StandingOnObject() const;
LightObj & StandingOnObject() const;
/* --------------------------------------------------------------------------------------------
* See whether the managed player entity is away.
@ -722,7 +722,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the player that the managed player entity is spectating.
*/
Object & GetSpectator() const;
LightObj & GetSpectator() const;
/* --------------------------------------------------------------------------------------------
* Set the managed player entity to spectate the specified player entity.
@ -743,27 +743,27 @@ public:
/* --------------------------------------------------------------------------------------------
* Create a checkpoint or sphere for this player.
*/
Object & CreateCheckpointEx(Int32 world, bool sphere, Float32 x, Float32 y, Float32 z,
LightObj & CreateCheckpointEx(Int32 world, bool sphere, Float32 x, Float32 y, Float32 z,
Uint8 r, Uint8 g, Uint8 b, Uint8 a, Float32 radius) const;
/* --------------------------------------------------------------------------------------------
* Create a checkpoint or sphere for this player.
*/
Object & CreateCheckpointEx(Int32 world, bool sphere, Float32 x, Float32 y, Float32 z,
LightObj & CreateCheckpointEx(Int32 world, bool sphere, Float32 x, Float32 y, Float32 z,
Uint8 r, Uint8 g, Uint8 b, Uint8 a, Float32 radius,
Int32 header, Object & payload) const;
Int32 header, LightObj & payload) const;
/* --------------------------------------------------------------------------------------------
* Create a checkpoint or sphere for this player.
*/
Object & CreateCheckpoint(Int32 world, bool sphere, const Vector3 & pos,
LightObj & CreateCheckpoint(Int32 world, bool sphere, const Vector3 & pos,
const Color4 & color, Float32 radius) const;
/* --------------------------------------------------------------------------------------------
* Create a checkpoint or sphere for this player.
*/
Object & CreateCheckpoint(Int32 world, bool sphere, const Vector3 & pos, const Color4 & color,
Float32 radius, Int32 header, Object & payload) const;
LightObj & CreateCheckpoint(Int32 world, bool sphere, const Vector3 & pos, const Color4 & color,
Float32 radius, Int32 header, LightObj & payload) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the authority level of the managed player entity.
@ -798,7 +798,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Modify the amount of tracked position changes for the managed player entity.
*/
void SetTrackPositionEx(SQInteger num, Int32 header, const Object & payload) const;
void SetTrackPositionEx(SQInteger num, Int32 header, const LightObj & payload) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the amount of tracked heading changes for the managed player entity.

View File

@ -29,7 +29,7 @@ SQInteger CVehicle::SqGetNull(HSQUIRRELVM vm)
}
// ------------------------------------------------------------------------------------------------
Object & CVehicle::GetNull()
LightObj & CVehicle::GetNull()
{
return Core::Get().GetNullVehicle();
}
@ -81,7 +81,7 @@ CVehicle & CVehicle::ApplyTag(const StackStrF & tag)
}
// ------------------------------------------------------------------------------------------------
Object & CVehicle::GetData()
LightObj & CVehicle::GetData()
{
// Validate the managed identifier
Validate();
@ -90,7 +90,7 @@ Object & CVehicle::GetData()
}
// ------------------------------------------------------------------------------------------------
void CVehicle::SetData(Object & data)
void CVehicle::SetData(LightObj & data)
{
// Validate the managed identifier
Validate();
@ -99,7 +99,7 @@ void CVehicle::SetData(Object & data)
}
// ------------------------------------------------------------------------------------------------
bool CVehicle::Destroy(Int32 header, Object & payload)
bool CVehicle::Destroy(Int32 header, LightObj & payload)
{
// Validate the managed identifier
Validate();
@ -108,31 +108,16 @@ bool CVehicle::Destroy(Int32 header, Object & payload)
}
// ------------------------------------------------------------------------------------------------
void CVehicle::BindEvent(Int32 evid, Object & env, Function & func) const
LightObj & CVehicle::GetEvents() const
{
// Validate the managed identifier
Validate();
// Obtain the function instance called for this event
Function & event = Core::Get().GetVehicleEvent(m_ID, evid);
// Is the specified callback function null?
if (func.IsNull())
{
event.ReleaseGently(); // Then release the current callback
}
// Does this function need a custom environment?
else if (env.IsNull())
{
event = func;
}
// Assign the specified environment and function
else
{
event = Function(env.GetVM(), env, func.GetFunc());
}
// Return the associated event table
return Core::Get().GetVehicle(m_ID).mEvents;
}
// ------------------------------------------------------------------------------------------------
void CVehicle::CustomEvent(Int32 header, Object & payload) const
void CVehicle::CustomEvent(Int32 header, LightObj & payload) const
{
// Validate the managed identifier
Validate();
@ -184,12 +169,12 @@ void CVehicle::SetOption(Int32 option_id, bool toggle)
// Prevent this event from triggering while executed
BitGuardU32 bg(m_CircularLocks, VEHICLECL_EMIT_VEHICLE_OPTION);
// Now forward the event call
Core::Get().EmitVehicleOption(m_ID, option_id, value, 0, NullObject());
Core::Get().EmitVehicleOption(m_ID, option_id, value, 0, NullLightObj());
}
}
// ------------------------------------------------------------------------------------------------
void CVehicle::SetOptionEx(Int32 option_id, bool toggle, Int32 header, Object & payload)
void CVehicle::SetOptionEx(Int32 option_id, bool toggle, Int32 header, LightObj & payload)
{
// Attempt to obtain the current value of the specified option
const bool value = _Func->GetVehicleOption(m_ID, static_cast< vcmpVehicleOption >(option_id));
@ -269,7 +254,7 @@ Int32 CVehicle::GetModel() const
}
// ------------------------------------------------------------------------------------------------
Object & CVehicle::GetOccupant(Int32 slot) const
LightObj & CVehicle::GetOccupant(Int32 slot) const
{
// Validate the managed identifier
Validate();
@ -1725,30 +1710,30 @@ void CVehicle::SetRelativeTurnSpeedZ(Float32 z) const
}
// ------------------------------------------------------------------------------------------------
static Object & Vehicle_CreateEx(Int32 model, Int32 world, Float32 x, Float32 y, Float32 z, Float32 angle,
static LightObj & Vehicle_CreateEx(Int32 model, Int32 world, Float32 x, Float32 y, Float32 z, Float32 angle,
Int32 primary, Int32 secondary)
{
return Core::Get().NewVehicle(model, world, x, y, z, angle, primary, secondary,
SQMOD_CREATE_DEFAULT, NullObject());
SQMOD_CREATE_DEFAULT, NullLightObj());
}
static Object & Vehicle_CreateEx(Int32 model, Int32 world, Float32 x, Float32 y, Float32 z, Float32 angle,
Int32 primary, Int32 secondary, Int32 header, Object & payload)
static LightObj & Vehicle_CreateEx(Int32 model, Int32 world, Float32 x, Float32 y, Float32 z, Float32 angle,
Int32 primary, Int32 secondary, Int32 header, LightObj & payload)
{
return Core::Get().NewVehicle(model, world, x, y, z, angle, primary, secondary,
header, payload);
}
// ------------------------------------------------------------------------------------------------
static Object & Vehicle_Create(Int32 model, Int32 world, const Vector3 & pos, Float32 angle,
static LightObj & Vehicle_Create(Int32 model, Int32 world, const Vector3 & pos, Float32 angle,
Int32 primary, Int32 secondary)
{
return Core::Get().NewVehicle(model, world, pos.x, pos.y, pos.z, angle, primary, secondary,
SQMOD_CREATE_DEFAULT, NullObject());
SQMOD_CREATE_DEFAULT, NullLightObj());
}
static Object & Vehicle_Create(Int32 model, Int32 world, const Vector3 & pos, Float32 angle,
Int32 primary, Int32 secondary, Int32 header, Object & payload)
static LightObj & Vehicle_Create(Int32 model, Int32 world, const Vector3 & pos, Float32 angle,
Int32 primary, Int32 secondary, Int32 header, LightObj & payload)
{
return Core::Get().NewVehicle(model, world, pos.x, pos.y, pos.z, angle, primary, secondary,
header, payload);
@ -1765,18 +1750,18 @@ void Register_CVehicle(HSQUIRRELVM vm)
// Static Values
.SetStaticValue(_SC("MaxID"), CVehicle::Max)
// Core Properties
.Prop(_SC("On"), &CVehicle::GetEvents)
.Prop(_SC("ID"), &CVehicle::GetID)
.Prop(_SC("Tag"), &CVehicle::GetTag, &CVehicle::SetTag)
.Prop(_SC("Data"), &CVehicle::GetData, &CVehicle::SetData)
.Prop(_SC("Active"), &CVehicle::IsActive)
// Core Methods
.Func(_SC("Bind"), &CVehicle::BindEvent)
.FmtFunc(_SC("SetTag"), &CVehicle::ApplyTag)
.Func(_SC("CustomEvent"), &CVehicle::CustomEvent)
// Core Overloads
.Overload< bool (CVehicle::*)(void) >(_SC("Destroy"), &CVehicle::Destroy)
.Overload< bool (CVehicle::*)(Int32) >(_SC("Destroy"), &CVehicle::Destroy)
.Overload< bool (CVehicle::*)(Int32, Object &) >(_SC("Destroy"), &CVehicle::Destroy)
.Overload< bool (CVehicle::*)(Int32, LightObj &) >(_SC("Destroy"), &CVehicle::Destroy)
// Properties
.Prop(_SC("SyncSource"), &CVehicle::GetSyncSource)
.Prop(_SC("SyncType"), &CVehicle::GetSyncType)
@ -1918,13 +1903,13 @@ void Register_CVehicle(HSQUIRRELVM vm)
.Overload< bool (CVehicle::*)(CPlayer &, Int32, bool, bool) const >
(_SC("Embark"), &CVehicle::Embark)
// Static Overloads
.StaticOverload< Object & (*)(Int32, Int32, Float32, Float32, Float32, Float32, Int32, Int32) >
.StaticOverload< LightObj & (*)(Int32, Int32, Float32, Float32, Float32, Float32, Int32, Int32) >
(_SC("CreateEx"), &Vehicle_CreateEx)
.StaticOverload< Object & (*)(Int32, Int32, Float32, Float32, Float32, Float32, Int32, Int32, Int32, Object &) >
.StaticOverload< LightObj & (*)(Int32, Int32, Float32, Float32, Float32, Float32, Int32, Int32, Int32, LightObj &) >
(_SC("CreateEx"), &Vehicle_CreateEx)
.StaticOverload< Object & (*)(Int32, Int32, const Vector3 &, Float32, Int32, Int32) >
.StaticOverload< LightObj & (*)(Int32, Int32, const Vector3 &, Float32, Int32, Int32) >
(_SC("Create"), &Vehicle_Create)
.StaticOverload< Object & (*)(Int32, Int32, const Vector3 &, Float32, Int32, Int32, Int32, Object &) >
.StaticOverload< LightObj & (*)(Int32, Int32, const Vector3 &, Float32, Int32, Int32, Int32, LightObj &) >
(_SC("Create"), &Vehicle_Create)
// Raw Squirrel Methods
.SquirrelFunc(_SC("NullInst"), &CVehicle::SqGetNull)

View File

@ -50,7 +50,7 @@ private:
/* --------------------------------------------------------------------------------------------
* User data associated with this instance.
*/
Object m_Data;
LightObj m_Data;
/* --------------------------------------------------------------------------------------------
* Prevent events from triggering themselves.
@ -118,7 +118,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the associated null entity instance.
*/
static Object & GetNull();
static LightObj & GetNull();
/* --------------------------------------------------------------------------------------------
* Retrieve the identifier of the entity managed by this instance.
@ -154,19 +154,19 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user data.
*/
Object & GetData();
LightObj & GetData();
/* --------------------------------------------------------------------------------------------
* Modify the associated user data.
*/
void SetData(Object & data);
void SetData(LightObj & data);
/* --------------------------------------------------------------------------------------------
* Destroy the managed vehicle entity.
*/
bool Destroy()
{
return Destroy(0, NullObject());
return Destroy(0, NullLightObj());
}
/* --------------------------------------------------------------------------------------------
@ -174,23 +174,23 @@ public:
*/
bool Destroy(Int32 header)
{
return Destroy(header, NullObject());
return Destroy(header, NullLightObj());
}
/* --------------------------------------------------------------------------------------------
* Destroy the managed vehicle entity.
*/
bool Destroy(Int32 header, Object & payload);
bool Destroy(Int32 header, LightObj & payload);
/* --------------------------------------------------------------------------------------------
* Bind to an event supported by this entity type.
* Retrieve the events table of this entity.
*/
void BindEvent(Int32 evid, Object & env, Function & func) const;
LightObj & GetEvents() const;
/* --------------------------------------------------------------------------------------------
* Emit a custom event for the managed entity
*/
void CustomEvent(Int32 header, Object & payload) const;
void CustomEvent(Int32 header, LightObj & payload) const;
/* --------------------------------------------------------------------------------------------
* See if the managed vehicle entity is streamed for the specified player.
@ -210,7 +210,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Modify the current option value of the managed vehicle entity.
*/
void SetOptionEx(Int32 option_id, bool toggle, Int32 header, Object & payload);
void SetOptionEx(Int32 option_id, bool toggle, Int32 header, LightObj & payload);
/* --------------------------------------------------------------------------------------------
* Retrieve the synchronization source of the managed vehicle entity.
@ -240,7 +240,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the slot occupant from the managed vehicle entity.
*/
Object & GetOccupant(Int32 slot) const;
LightObj & GetOccupant(Int32 slot) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the slot occupant identifier from the managed vehicle entity.

View File

@ -237,7 +237,7 @@ static void OnPlayerConnect(int32_t player_id)
// Attempt to forward the event
try
{
Core::Get().ConnectPlayer(player_id, SQMOD_CREATE_AUTOMATIC, NullObject());
Core::Get().ConnectPlayer(player_id, SQMOD_CREATE_AUTOMATIC, NullLightObj());
}
SQMOD_CATCH_EVENT_EXCEPTION(OnPlayerConnect)
// See if a reload was requested
@ -257,7 +257,7 @@ static void OnPlayerDisconnect(int32_t player_id, vcmpDisconnectReason reason)
}
else
{
Core::Get().DisconnectPlayer(player_id, reason, NullObject());
Core::Get().DisconnectPlayer(player_id, reason, NullLightObj());
}
}
SQMOD_CATCH_EVENT_EXCEPTION(OnPlayerDisconnect)
@ -875,6 +875,7 @@ SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs * funcs, PluginCallback
// Stop here!
return SQMOD_FAILURE;
}
// Bind to the server callbacks
_Clbk->OnServerInitialise = OnServerInitialise;
_Clbk->OnServerShutdown = OnServerShutdown;

View File

@ -365,12 +365,12 @@ void SetServerOption(Int32 option_id, bool toggle)
}
else
{
Core::Get().EmitServerOption(option_id, toggle, 0, NullObject());
Core::Get().EmitServerOption(option_id, toggle, 0, NullLightObj());
}
}
// ------------------------------------------------------------------------------------------------
void SetServerOptionEx(Int32 option_id, bool toggle, Int32 header, Object & payload)
void SetServerOptionEx(Int32 option_id, bool toggle, Int32 header, LightObj & payload)
{
if (_Func->SetServerOption(static_cast< vcmpServerOption >(option_id),
toggle) == vcmpErrorArgumentOutOfBounds)

View File

@ -170,7 +170,7 @@ void SetServerOption(Int32 option_id, bool toggle);
/* ------------------------------------------------------------------------------------------------
* Modify a server option.
*/
void SetServerOptionEx(Int32 option_id, bool toggle, Int32 header, Object & payload);
void SetServerOptionEx(Int32 option_id, bool toggle, Int32 header, LightObj & payload);
/* ------------------------------------------------------------------------------------------------
* Retrieve the world bounds.

View File

@ -18,7 +18,7 @@
namespace SqMod {
// ------------------------------------------------------------------------------------------------
static const Object & FindPlayer(Object & by)
static const LightObj & FindPlayer(Object & by)
{
switch (by.GetType())
{
@ -45,7 +45,7 @@ static const Object & FindPlayer(Object & by)
default: STHROWF("Unsupported search identifier");
}
// Default to a null object
return NullObject();
return NullLightObj();
}
// ------------------------------------------------------------------------------------------------

View File

@ -1,973 +0,0 @@
// ------------------------------------------------------------------------------------------------
#include "Misc/Signal.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(Typename, _SC("SqSignalWrapper"))
// ------------------------------------------------------------------------------------------------
Signal::SignalContainer Signal::s_Signals;
Signal::FreeSignals Signal::s_FreeSignals;
// ------------------------------------------------------------------------------------------------
void Signal::Terminate()
{
// Terminate named signals
for (const auto & s : s_Signals)
{
// Clear slots
s.second.mPtr->Clear();
// Release the name
s.second.mPtr->m_Name.clear();
// Release whatever is in the user data
s.second.mPtr->m_Data.Release();
}
// Finally clear the container itself
s_Signals.clear();
// Create a copy so we don't invalidate iterators when destructor removes the instances
FreeSignals fsig(s_FreeSignals);
// Terminate anonymous signals
for (const auto & s : fsig)
{
// Clear slots
s->Clear();
// Release whatever is in the user data
s->m_Data.Release();
}
// Finally clear the container itself
s_FreeSignals.clear();
}
// ------------------------------------------------------------------------------------------------
Object Signal::CreateFree()
{
// Remember the current stack size
const StackGuard sg;
// Create the signal instance
DeleteGuard< Signal > dg(new Signal());
// Attempt to create the signal instance
ClassType< Signal >::PushInstance(DefaultVM::Get(), dg.Get());
// This is now managed by the script
dg.Release();
// Return the created signal
return Var< Object >(DefaultVM::Get(), -1).value;
}
// ------------------------------------------------------------------------------------------------
Object Signal::Create(const StackStrF & name)
{
// Validate the signal name
if (name.mLen <= 0)
{
return CreateFree();
}
// Create a copy of the name
String sname(name.mPtr, name.mLen);
// Compute the hash of the specified name
const std::size_t hash = std::hash< String >{}(sname);
// See if the signal already exists
for (const auto & e : s_Signals)
{
if (e.first == hash)
{
return e.second.mObj; // Found a match so let's return it
}
}
// Remember the current stack size
const StackGuard sg;
// Create the signal instance
DeleteGuard< Signal > dg(new Signal(std::move(sname)));
// Grab the signal instance pointer
Signal * ptr = dg.Get();
// Attempt to create the signal instance
ClassType< Signal >::PushInstance(DefaultVM::Get(), ptr);
// This is now managed by the script
dg.Release();
// Grab a reference to the instance created on the stack
s_Signals.emplace_back(hash, SignalReference(ptr, Var< Object >(DefaultVM::Get(), -1).value));
// Return the created signal
return s_Signals.back().second.mObj;
}
// ------------------------------------------------------------------------------------------------
void Signal::Remove(const StackStrF & name)
{
// Validate the signal name
if (name.mLen <= 0)
{
STHROWF("Signals without names cannot be removed manually");
}
// Create a copy of the name
String sname(name.mPtr, name.mLen);
// Compute the hash of the specified name
const std::size_t hash = std::hash< String >{}(sname);
// Iterator to the existing signal, if any
SignalContainer::const_iterator itr = s_Signals.cbegin();
// Search for a signal with this name
for (; itr != s_Signals.cend(); ++itr)
{
if (itr->first == hash)
{
break;
}
}
// Did we find anything?
if (itr != s_Signals.cend())
{
// Clear the name
itr->second.mPtr->m_Name.clear();
// Put it on the free list
s_FreeSignals.push_back(itr->second.mPtr);
// Finally, remove it from the named list
s_Signals.erase(itr);
}
}
// ------------------------------------------------------------------------------------------------
Object Signal::Fetch(const StackStrF & name)
{
// Validate the signal name
if (name.mLen <= 0)
{
STHROWF("Signals without names cannot be retrieved manually");
}
// Create a copy of the name
String sname(name.mPtr, name.mLen);
// Compute the hash of the specified name
const std::size_t hash = std::hash< String >{}(sname);
// Search for a signal with this name
for (const auto & e : s_Signals)
{
if (e.first == hash)
{
return e.second.mObj; // Found a match so let's return it
}
}
// No such signal exists
STHROWF("Unknown signal named (%s)", sname.c_str());
// SHOULD NOT REACH THIS POINT!
return NullObject();
}
// ------------------------------------------------------------------------------------------------
Signal::Signal()
: m_Head(nullptr), m_Data(), m_Name()
{
s_FreeSignals.push_back(this);
}
// ------------------------------------------------------------------------------------------------
Signal::Signal(const CSStr name)
: Signal(String(name ? name : _SC("")))
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Signal::Signal(const String & name)
: Signal(String(name))
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
Signal::Signal(String && name)
: m_Head(nullptr), m_Data(), m_Name(std::move(name))
{
if (m_Name.empty())
{
s_FreeSignals.push_back(this);
}
}
// ------------------------------------------------------------------------------------------------
Signal::~Signal()
{
Clear();
if (m_Name.empty())
{
s_FreeSignals.erase(std::remove(s_FreeSignals.begin(), s_FreeSignals.end(), this),
s_FreeSignals.end());
}
}
// ------------------------------------------------------------------------------------------------
SQInteger Signal::Count() const
{
// Don't attempt to count anything if there's no head
if (m_Head == nullptr)
{
return 0;
}
// Final count
Uint32 count = 0;
// Walk down the chain and count all nodes
for (Slot * node = m_Head; node != nullptr; node = node->mNext)
{
++count;
}
// Return the count
return count;
}
// ------------------------------------------------------------------------------------------------
void Signal::Clear()
{
// Don't attempt to clear anything if there's no head
if (m_Head == nullptr)
{
return;
}
// Walk down the chain and delete all nodes
for (Slot * node = m_Head, * next = nullptr; node != nullptr; node = next)
{
// Grab the next node upfront
next = node->mNext;
// Delete the node instance
delete node;
}
// Reset the head
m_Head = nullptr;
}
// ------------------------------------------------------------------------------------------------
void Signal::Connect(Object & env, Function & func)
{
// Don't attempt to search anything if there's no head
if (m_Head == nullptr)
{
m_Head = new Slot(env, func, nullptr);
// We're done here
return;
}
const Slot slot{env, func};
// Don't attempt to search anything if there's only one element
if (m_Head->mNext == nullptr)
{
// Is it already inserted?
if (*m_Head != slot)
{
m_Head = new Slot(env, func, m_Head);
}
// We're done here
return;
}
// Walk down the chain and find an already matching node
for (Slot * node = m_Head; node != nullptr; node = node->mNext)
{
if (*node == slot)
{
return; // Already connected
}
}
// Connect now
m_Head = new Slot(env, func, m_Head);
}
// ------------------------------------------------------------------------------------------------
bool Signal::Connected(Object & env, Function & func) const
{
// Don't attempt to search anything if there's no head
if (m_Head == nullptr)
{
return false;
}
const Slot slot{env, func};
// Walk down the chain and find a matching node
for (Slot * node = m_Head; node != nullptr; node = node->mNext)
{
if (*node == slot)
{
return true; // Found it
}
}
// No such slot exists
return false;
}
// ------------------------------------------------------------------------------------------------
void Signal::Disconnect(Object & env, Function & func)
{
// Don't attempt to search anything if there's no head
if (m_Head == nullptr)
{
return;
}
const Slot slot{env, func};
// Walk down the chain and remove the matching nodes
for (Slot * node = m_Head, * next = nullptr; node != nullptr; node = next)
{
// Grab the next node upfront
next = node->mNext;
// Is this our node?
if (*node == slot)
{
// Is this the head?
if (node == m_Head)
{
m_Head = next; // Move the head to the next one
}
// Detach it from the chain
node->Detach();
// Delete the node instance
delete node;
}
}
}
// ------------------------------------------------------------------------------------------------
void Signal::DisconnectThis(Object & env)
{
// Don't attempt to search anything if there's no head
if (m_Head == nullptr)
{
return;
}
const SQHash hash = Slot{env, NullFunction()}.mEnvHash;
// Walk down the chain and remove the matching nodes
for (Slot * node = m_Head, * next = nullptr; node != nullptr; node = next)
{
// Grab the next node upfront
next = node->mNext;
// Is this our node?
if (node->mEnvHash == hash)
{
// Is this the head?
if (node == m_Head)
{
m_Head = next; // Move the head to the next one
}
// Detach it from the chain
node->Detach();
// Delete the node instance
delete node;
}
}
}
// ------------------------------------------------------------------------------------------------
void Signal::DisconnectFunc(Function & func)
{
// Don't attempt to search anything if there's no head
if (m_Head == nullptr)
{
return;
}
const SQHash hash = Slot{NullObject(), func}.mFuncHash;
// Walk down the chain and remove the matching nodes
for (Slot * node = m_Head, * next = nullptr; node != nullptr; node = next)
{
// Grab the next node upfront
next = node->mNext;
// Is this our node?
if (node->mFuncHash == hash)
{
// Is this the head?
if (node == m_Head)
{
m_Head = next; // Move the head to the next one
}
// Detach it from the chain
node->Detach();
// Delete the node instance
delete node;
}
}
}
// ------------------------------------------------------------------------------------------------
Uint32 Signal::CountThis(Object & env) const
{
// Don't attempt to count anything if there's no head
if (m_Head == nullptr)
{
return 0;
}
const SQHash hash = Slot{env, NullFunction()}.mEnvHash;
// Final count
Uint32 count = 0;
// Walk down the chain and count the matching nodes
for (Slot * node = m_Head; node != nullptr; node = node->mNext)
{
// Is this our node?
if (node->mEnvHash == hash)
{
++count;
}
}
// Return the count
return count;
}
// ------------------------------------------------------------------------------------------------
Uint32 Signal::CountFunc(Function & func) const
{
// Don't attempt to count anything if there's no head
if (m_Head == nullptr)
{
return 0;
}
const SQHash hash = Slot{NullObject(), func}.mFuncHash;
// Final count
Uint32 count = 0;
// Walk down the chain and count the matching nodes
for (Slot * node = m_Head; node != nullptr; node = node->mNext)
{
// Is this our node?
if (node->mFuncHash == hash)
{
++count;
}
}
// Return the count
return count;
}
// ------------------------------------------------------------------------------------------------
void Signal::Head(Object & env, Function & func)
{
// Don't attempt to search anything if there's no head
if (m_Head == nullptr)
{
m_Head = new Slot(env, func, nullptr);
// We're done here
return;
}
const Slot slot{env, func};
// Don't attempt to search anything if there's only one element
if (m_Head->mNext == nullptr)
{
// Is it already inserted?
if (*m_Head != slot)
{
m_Head = new Slot(env, func, m_Head);
}
// We're done here
return;
}
// Grab the head node
Slot * node = m_Head;
// Walk down the chain and find a matching node
for (; node != nullptr; node = node->mNext)
{
if (*node == slot)
{
break; // Found it
}
}
// Have we found anything?
if (node == nullptr)
{
m_Head = new Slot(env, func, m_Head); // Lead everyone
}
// Is it the head already?
else if (m_Head != node)
{
node->AttachNext(m_Head);
// We're the head now
m_Head = node;
}
}
// ------------------------------------------------------------------------------------------------
void Signal::Tail(Object & env, Function & func)
{
// Don't attempt to search anything if there's no head
if (m_Head == nullptr)
{
m_Head = new Slot(env, func, nullptr);
// We're done here
return;
}
const Slot slot{env, func};
// Don't attempt to search anything if there's only one element
if (m_Head->mNext == nullptr)
{
// Is it already inserted?
if (*m_Head != slot)
{
m_Head->mNext = new Slot(env, func, nullptr);
// Link with the head
m_Head->mNext->mPrev = m_Head;
}
// We're done here
return;
}
// Grab the head node
Slot * node = m_Head, * prev = nullptr;
// Walk down the chain and find a matching node
for (; node != nullptr; prev = node, node = node->mNext)
{
if (*node == slot)
{
break; // Found it
}
}
// Have we found anything?
if (node == nullptr)
{
// Create the slot now
node = new Slot(env, func, nullptr);
}
else
{
// Walk down the chain until the end
while (prev->mNext != nullptr)
{
prev = prev->mNext;
}
// Finally, detach the node from it's current position
node->Detach();
}
// Knowing 'prev' points to last element
node->AttachPrev(prev);
}
// ------------------------------------------------------------------------------------------------
SQInteger Signal::SqEmit(HSQUIRRELVM vm)
{
const Int32 top = sq_gettop(vm);
// The signal instance
Signal * signal = nullptr;
// Attempt to extract the signal instance
try
{
signal = Var< Signal * >(vm, 1).value;
}
catch (const Sqrat::Exception & e)
{
return sq_throwerror(vm, e.what());
}
// Do we have a valid signal instance?
if (!signal)
{
return sq_throwerror(vm, "Invalid signal instance");
}
// Walk down the chain and trigger slots
for (Slot * node = signal->m_Head, * next = nullptr; node != nullptr; node = next)
{
// Grab the next node upfront
next = node->mNext;
// Remember the current stack size
const StackGuard sg(vm);
// Push the callback object
sq_pushobject(vm, node->mFuncRef);
// Is there an explicit environment?
if (sq_isnull(node->mEnvRef))
{
sq_pushroottable(vm);
}
else
{
sq_pushobject(vm, node->mEnvRef);
}
// Are there any parameters to forward?
if (top > 1)
{
for (SQInteger i = 2; i <= top; ++i)
{
sq_push(vm, i);
}
}
// Make the function call and store the result
const SQRESULT res = sq_call(vm, top, false, ErrorHandling::IsEnabled());
// Validate the result
if (SQ_FAILED(res))
{
return res; // Propagate the error
}
}
// Specify that we don't return anything
return 0;
}
// ------------------------------------------------------------------------------------------------
SQInteger Signal::SqQuery(HSQUIRRELVM vm)
{
const Int32 top = sq_gettop(vm);
// Do we have the collector environment?
if (top <= 1)
{
return sq_throwerror(vm, "Missing collector environment");
}
// Do we have the collector function?
else if (top <= 2)
{
return sq_throwerror(vm, "Missing collector callback");
}
// The signal instance
Signal * signal = nullptr;
// Attempt to extract the signal instance and collector
try
{
signal = Var< Signal * >(vm, 1).value;
}
catch (const Sqrat::Exception & e)
{
return sq_throwerror(vm, e.what());
}
// Do we have a valid signal instance?
if (!signal)
{
return sq_throwerror(vm, "Invalid signal instance");
}
// The collector
HSQOBJECT cenv, cfunc;
// Grab the collector environment
SQRESULT res = sq_getstackobj(vm, 2, &cenv);
// Validate the result
if (SQ_FAILED(res))
{
return res; // Propagate the error
}
// Was there a valid environment?
else if (sq_isnull(cenv))
{
// Remember the current stack size
const StackGuard sg(vm);
// Default to the root table
sq_pushroottable(vm);
// Try to grab the collector environment again
SQRESULT res = sq_getstackobj(vm, -1, &cenv);
// Validate the result
if (SQ_FAILED(res))
{
return res; // Propagate the error
}
}
// Grab the collector function
res = sq_getstackobj(vm, 3, &cfunc);
// Validate the result
if (SQ_FAILED(res))
{
return res; // Propagate the error
}
// Some dummy checks to make sure the collector is a callable object
else if (!sq_isfunction(cfunc) && !sq_isclosure(cfunc) && !sq_isnativeclosure(cfunc))
{
return sq_throwerror(vm, "Invalid collector");
}
// Walk down the chain and trigger slots
for (Slot * node = signal->m_Head, * next = nullptr; node != nullptr; node = next)
{
// Grab the next node upfront
next = node->mNext;
// Remember the current stack size
const StackGuard sg(vm);
// Push the callback object
sq_pushobject(vm, node->mFuncRef);
// Is there an explicit environment?
if (sq_isnull(node->mEnvRef))
{
sq_pushroottable(vm);
}
else
{
sq_pushobject(vm, node->mEnvRef);
}
// Are there any parameters to forward?
if (top > 3)
{
for (SQInteger i = 4; i <= top; ++i)
{
sq_push(vm, i);
}
}
// Make the function call and store the result
res = sq_call(vm, top - 2, true, ErrorHandling::IsEnabled());
// Validate the result
if (SQ_FAILED(res))
{
return res; // Propagate the error
}
// Push the collector onto the stack
sq_pushobject(vm, cfunc);
sq_pushobject(vm, cenv);
// Push the returned value
sq_push(vm, -3);
// Make the function call and store the result
res = sq_call(vm, 2, false, ErrorHandling::IsEnabled());
// Validate the result
if (SQ_FAILED(res))
{
return res; // Propagate the error
}
}
// Specify that we don't return anything
return 0;
}
// ------------------------------------------------------------------------------------------------
SQInteger Signal::SqConsume(HSQUIRRELVM vm)
{
const Int32 top = sq_gettop(vm);
// The signal instance
Signal * signal = nullptr;
// Attempt to extract the signal instance
try
{
signal = Var< Signal * >(vm, 1).value;
}
catch (const Sqrat::Exception & e)
{
return sq_throwerror(vm, e.what());
}
// Do we have a valid signal instance?
if (!signal)
{
return sq_throwerror(vm, "Invalid signal instance");
}
// Default to not consumed
SQBool ret = SQFalse;
// Walk down the chain and trigger slots
for (Slot * node = signal->m_Head, * next = nullptr; node != nullptr; node = next)
{
// Grab the next node upfront
next = node->mNext;
// Remember the current stack size
const StackGuard sg(vm);
// Push the callback object
sq_pushobject(vm, node->mFuncRef);
// Is there an explicit environment?
if (sq_isnull(node->mEnvRef))
{
sq_pushroottable(vm);
}
else
{
sq_pushobject(vm, node->mEnvRef);
}
// Are there any parameters to forward?
if (top > 1)
{
for (SQInteger i = 2; i <= top; ++i)
{
sq_push(vm, i);
}
}
// Make the function call and store the result
const SQRESULT res = sq_call(vm, top, true, ErrorHandling::IsEnabled());
// Validate the result
if (SQ_FAILED(res))
{
return res; // Propagate the error
}
// Is the returned value not null?
else if (sq_gettype(vm, -1) != OT_NULL)
{
// Obtain the returned value
sq_tobool(vm, -1, &ret);
// Should we proceed to the next slot or stop here?
if (ret == SQTrue)
{
break; // The slot consumed the signal
}
}
}
// Forward the returned value to the invoker
sq_pushbool(vm, ret);
// Specify that we returned something
return 1;
}
// ------------------------------------------------------------------------------------------------
SQInteger Signal::SqApprove(HSQUIRRELVM vm)
{
const Int32 top = sq_gettop(vm);
// The signal instance
Signal * signal = nullptr;
// Attempt to extract the signal instance
try
{
signal = Var< Signal * >(vm, 1).value;
}
catch (const Sqrat::Exception & e)
{
return sq_throwerror(vm, e.what());
}
// Do we have a valid signal instance?
if (!signal)
{
return sq_throwerror(vm, "Invalid signal instance");
}
// Default to approved
SQBool ret = SQTrue;
// Walk down the chain and trigger slots
for (Slot * node = signal->m_Head, * next = nullptr; node != nullptr; node = next)
{
// Grab the next node upfront
next = node->mNext;
// Remember the current stack size
const StackGuard sg(vm);
// Push the callback object
sq_pushobject(vm, node->mFuncRef);
// Is there an explicit environment?
if (sq_isnull(node->mEnvRef))
{
sq_pushroottable(vm);
}
else
{
sq_pushobject(vm, node->mEnvRef);
}
// Are there any parameters to forward?
if (top > 1)
{
for (SQInteger i = 2; i <= top; ++i)
{
sq_push(vm, i);
}
}
// Make the function call and store the result
const SQRESULT res = sq_call(vm, top, true, ErrorHandling::IsEnabled());
// Validate the result
if (SQ_FAILED(res))
{
return res; // Propagate the error
}
// Is the returned value not null?
else if (sq_gettype(vm, -1) != OT_NULL)
{
// Obtain the returned value
sq_tobool(vm, -1, &ret);
// Should we proceed to the next slot or stop here?
if (ret == SQFalse)
{
break; // The slot did not approve the signal
}
}
}
// Forward the returned value to the invoker
sq_pushbool(vm, ret);
// Specify that we returned something
return 1;
}
// ------------------------------------------------------------------------------------------------
SQInteger Signal::SqRequest(HSQUIRRELVM vm)
{
const Int32 top = sq_gettop(vm);
// The signal instance
Signal * signal = nullptr;
// Attempt to extract the signal instance
try
{
signal = Var< Signal * >(vm, 1).value;
}
catch (const Sqrat::Exception & e)
{
return sq_throwerror(vm, e.what());
}
// Do we have a valid signal instance?
if (!signal)
{
return sq_throwerror(vm, "Invalid signal instance");
}
// Walk down the chain and trigger slots
for (Slot * node = signal->m_Head, * next = nullptr; node != nullptr; node = next)
{
// Grab the next node upfront
next = node->mNext;
// Remember the current stack size
const StackGuard sg(vm);
// Push the callback object
sq_pushobject(vm, node->mFuncRef);
// Is there an explicit environment?
if (sq_isnull(node->mEnvRef))
{
sq_pushroottable(vm);
}
else
{
sq_pushobject(vm, node->mEnvRef);
}
// Are there any parameters to forward?
if (top > 1)
{
for (SQInteger i = 2; i <= top; ++i)
{
sq_push(vm, i);
}
}
// Make the function call and store the result
const SQRESULT res = sq_call(vm, top, true, ErrorHandling::IsEnabled());
// Validate the result
if (SQ_FAILED(res))
{
return res; // Propagate the error
}
// Is the returned value not null?
else if (sq_gettype(vm, -1) != OT_NULL)
{
// Push back the returned value
sq_push(vm, -1);
// Specify that we returned something
return 1;
}
}
// Specify that we returned nothing
return 0;
}
// ================================================================================================
void Register_Signal(HSQUIRRELVM vm)
{
RootTable(vm).Bind(Typename::Str,
Class< Signal, NoConstructor< Signal > >(vm, Typename::Str)
// Meta-methods
.SquirrelFunc(_SC("_typename"), &Typename::Fn)
.Func(_SC("_tostring"), &Signal::ToString)
// Core Properties
.Prop(_SC("Data"), &Signal::GetData, &Signal::SetData)
.Prop(_SC("Slots"), &Signal::Count)
// Core Methods
.Func(_SC("Clear"), &Signal::Clear)
.Func(_SC("Connect"), &Signal::Connect)
.Func(_SC("Connected"), &Signal::Connected)
.Func(_SC("Disconnect"), &Signal::Disconnect)
.Func(_SC("EliminateThis"), &Signal::DisconnectThis)
.Func(_SC("EliminateFunc"), &Signal::DisconnectFunc)
.Func(_SC("CountThis"), &Signal::CountThis)
.Func(_SC("CountFunc"), &Signal::CountFunc)
.Func(_SC("Head"), &Signal::Head)
.Func(_SC("Tail"), &Signal::Tail)
// Squirrel Functions
.SquirrelFunc(_SC("Emit"), &Signal::SqEmit)
.SquirrelFunc(_SC("Broadcast"), &Signal::SqEmit)
.SquirrelFunc(_SC("Query"), &Signal::SqQuery)
.SquirrelFunc(_SC("Consume"), &Signal::SqConsume)
.SquirrelFunc(_SC("Approve"), &Signal::SqApprove)
.SquirrelFunc(_SC("Request"), &Signal::SqRequest)
);
RootTable(vm)
.FmtFunc(_SC("SqSignal"), &Signal::Fetch)
.FmtFunc(_SC("SqCreateSignal"), &Signal::Create)
.FmtFunc(_SC("SqRemoveSignal"), &Signal::Remove);
}
/* ------------------------------------------------------------------------------------------------
* Forward the call to terminate the signals.
*/
void TerminateSignals()
{
Signal::Terminate();
}
} // Namespace:: SqMod

View File

@ -1,539 +0,0 @@
#ifndef _MISC_SIGNAL_HPP_
#define _MISC_SIGNAL_HPP_
// ------------------------------------------------------------------------------------------------
#include "Base/Shared.hpp"
// ------------------------------------------------------------------------------------------------
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
class Signal;
/* ------------------------------------------------------------------------------------------------
* Helper class used to reference and keep track of signal instances.
*/
struct SignalReference
{
// --------------------------------------------------------------------------------------------
Signal * mPtr; // A raw pointer to the signal instance.
Object mObj; // A managed reference to the signal instance.
/* --------------------------------------------------------------------------------------------
* Explicit constructor.
*/
SignalReference(Signal * ptr, const Object & ref)
: mPtr(ptr), mObj(ref)
{
/* ... */
}
/* --------------------------------------------------------------------------------------------
* Copy constructor.
*/
SignalReference(const SignalReference & o) = default;
/* --------------------------------------------------------------------------------------------
* Move constructor.
*/
SignalReference(SignalReference && o) = default;
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~SignalReference() = default;
/* --------------------------------------------------------------------------------------------
* Copy assignment operator.
*/
SignalReference & operator = (const SignalReference & o) = default;
/* --------------------------------------------------------------------------------------------
* Move assignment operator.
*/
SignalReference & operator = (SignalReference && o) = default;
};
/* ------------------------------------------------------------------------------------------------
* Utility class for for delivering events to one or more listeners.
*/
class Signal
{
private:
/* --------------------------------------------------------------------------------------------
* Used to store a script callback and the unique hash associated with it for quick searching.
*/
struct Slot
{
// ----------------------------------------------------------------------------------------
SQHash mEnvHash; // The hash of the specified environment.
SQHash mFuncHash; // The hash of the specified callback.
HSQOBJECT mEnvRef; // The specified script environment.
HSQOBJECT mFuncRef; // The specified script callback.
// ----------------------------------------------------------------------------------------
Slot * mPrev; // Previous slot in the chain.
Slot * mNext; // Next slot in the chain.
/* ----------------------------------------------------------------------------------------
* Forwarding constructor.
*/
Slot(Object & env, Function & func)
: Slot(env.GetObject(), func.GetFunc(), nullptr)
{
/* ... */
}
/* ----------------------------------------------------------------------------------------
* Forwarding constructor.
*/
Slot(Object & env, Function & func, Slot * head)
: Slot(env.GetObject(), func.GetFunc(), head)
{
/* ... */
}
/* ----------------------------------------------------------------------------------------
* Base constructor.
*/
Slot(HSQOBJECT & env, HSQOBJECT & func, Slot * head)
: mEnvHash(0)
, mFuncHash(0)
, mEnvRef(env)
, mFuncRef(func)
, mPrev(nullptr)
, mNext(head)
{
HSQUIRRELVM vm = DefaultVM::Get();
// Remember the current stack size
const StackGuard sg(vm);
// Is there an explicit environment?
if (!sq_isnull(mEnvRef))
{
// Keep a reference to this environment
sq_addref(vm, &mEnvRef);
// Push the environment on the stack
sq_pushobject(vm, mEnvRef);
// Grab the hash of the environment object
mEnvHash = sq_gethash(vm, -1);
}
// Is there an explicit function?
if (!sq_isnull(mFuncRef))
{
// Keep a reference to this function
sq_addref(vm, &mFuncRef);
// Push the callback on the stack
sq_pushobject(vm, mFuncRef);
// Grab the hash of the callback object
mFuncHash = sq_gethash(vm, -1);
}
// Was there a previous head?
if (mNext != nullptr)
{
// Steal the slot before the head
mPrev = mNext->mPrev;
// Did that head slot had a slot behind it?
if (mPrev != nullptr)
{
// Tell it we're the next slot now
mPrev->mNext = this;
}
// Tell the previous head that we're behind it now
mNext->mPrev = this;
}
}
/* ----------------------------------------------------------------------------------------
* Copy constructor. (disabled)
*/
Slot(const Slot & o) = delete;
/* ----------------------------------------------------------------------------------------
* Move constructor.
*/
Slot(Slot && o)
: mEnvHash(o.mEnvHash)
, mFuncHash(o.mFuncHash)
, mEnvRef(o.mEnvRef)
, mFuncRef(o.mFuncRef)
, mPrev(o.mPrev)
, mNext(o.mNext)
{
// Take ownership
sq_resetobject(&o.mEnvRef);
sq_resetobject(&o.mFuncRef);
o.mPrev = nullptr;
o.mNext = nullptr;
// Attach to the chain
Attach();
}
/* ----------------------------------------------------------------------------------------
* Destructor.
*/
~Slot()
{
Release();
// Detach from the chain
Detach();
}
/* ----------------------------------------------------------------------------------------
* Copy assignment operator. (disabled)
*/
Slot & operator = (const Slot & o) = delete;
/* ----------------------------------------------------------------------------------------
* Move assignment operator.
*/
Slot & operator = (Slot && o)
{
if (this != &o)
{
// Release current resources, if any
Release();
// Replicate data
mEnvHash = o.mEnvHash;
mFuncHash = o.mFuncHash;
mEnvRef = o.mEnvRef;
mFuncRef = o.mFuncRef;
mPrev = o.mPrev;
mNext = o.mNext;
// Take ownership
sq_resetobject(&o.mEnvRef);
sq_resetobject(&o.mFuncRef);
o.mPrev = nullptr;
o.mNext = nullptr;
// Attach to the chain
Attach();
}
return *this;
}
/* ----------------------------------------------------------------------------------------
* Equality comparison operator.
*/
bool operator == (const Slot & o) const
{
return (mEnvHash == o.mEnvHash) && (mFuncHash == o.mFuncHash);
}
/* ----------------------------------------------------------------------------------------
* Inequality comparison operator.
*/
bool operator != (const Slot & o) const
{
return (mEnvHash != o.mEnvHash) || (mFuncHash != o.mFuncHash);
}
/* ----------------------------------------------------------------------------------------
* Release managed script resources.
*/
void Release()
{
// Should we release any environment object?
if (!sq_isnull(mEnvRef))
{
sq_release(DefaultVM::Get(), &mEnvRef);
sq_resetobject(&mEnvRef);
}
// Should we release any callback object?
if (!sq_isnull(mFuncRef))
{
sq_release(DefaultVM::Get(), &mFuncRef);
sq_resetobject(&mFuncRef);
}
}
/* ----------------------------------------------------------------------------------------
* Attach the slot to the chain.
*/
void Attach()
{
// Is there a slot after us?
if (mNext != nullptr)
{
// Tell it that we're behind it
mNext->mPrev = this;
}
// Is there a node behind us?
if (mPrev != nullptr)
{
// Tell it that we're ahead of it
mPrev->mNext = this;
}
}
/* ----------------------------------------------------------------------------------------
* Detach the slot from the chain.
*/
void Detach()
{
// Is there a slot after us?
if (mNext != nullptr)
{
// Tell it we're no longer behind it
mNext->mPrev = mPrev;
}
// Is there a node behind us?
if (mPrev != nullptr)
{
// Tell it we're no longer ahead of it
mPrev->mNext = mNext;
}
mPrev = mNext = nullptr;
}
/* ----------------------------------------------------------------------------------------
* Attach the slot after another slot.
*/
void AttachNext(Slot * node)
{
Detach();
// Assign the slot ahead of us
mNext = node;
// Is there a node to attach to?
if (mNext != nullptr)
{
// Steal the previous slot
mPrev = mNext->mPrev;
// Was there a previous slot?
if (mPrev != nullptr)
{
mPrev->mNext = this; // Tell it we're the next slot now
}
// Place ourself behind
mNext->mPrev = this;
}
}
/* ----------------------------------------------------------------------------------------
* Attach the slot before another slot.
*/
void AttachPrev(Slot * node)
{
Detach();
// Assign the slot behind us
mPrev = node;
// Is there a node to attach to?
if (mPrev != nullptr)
{
// Steal the next slot
mNext = mPrev->mNext;
// Was there a next slot?
if (mNext != nullptr)
{
mNext->mPrev = this; // Tell it we're the previous slot now
}
// Place ourself ahead
mPrev->mNext = this;
}
}
};
// --------------------------------------------------------------------------------------------
Slot * m_Head; // The chain of slots bound to this signal.
Object m_Data; // User data associated with this instance.
String m_Name; // The name that identifies this signal.
/* --------------------------------------------------------------------------------------------
* Default constructor.
*/
Signal();
/* --------------------------------------------------------------------------------------------
* Base constructor.
*/
explicit Signal(const CSStr name);
/* --------------------------------------------------------------------------------------------
* Base constructor.
*/
Signal(const String & name);
/* --------------------------------------------------------------------------------------------
* Base constructor.
*/
Signal(String && name);
public:
/* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled)
*/
Signal(const Signal & o) = delete;
/* --------------------------------------------------------------------------------------------
* Move constructor. (disabled)
*/
Signal(Signal && o) = delete;
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~Signal();
/* --------------------------------------------------------------------------------------------
* Copy assignment operator. (disabled)
*/
Signal & operator = (const Signal & o) = delete;
/* --------------------------------------------------------------------------------------------
* Move assignment operator. (disabled)
*/
Signal & operator = (Signal && o) = delete;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
const String & ToString() const
{
return m_Name;
}
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user data.
*/
Object & GetData()
{
return m_Data;
}
/* --------------------------------------------------------------------------------------------
* Modify the associated user data.
*/
void SetData(Object & data)
{
m_Data = data;
}
/* --------------------------------------------------------------------------------------------
* The number of slots connected to the signal.
*/
SQInteger Count() const;
/* --------------------------------------------------------------------------------------------
* Clear all slots connected to the signal.
*/
void Clear();
/* --------------------------------------------------------------------------------------------
* Connect a function with a specific environment to the signal.
*/
void Connect(Object & env, Function & func);
/* --------------------------------------------------------------------------------------------
* See whether a function with a specific environment is connected to the signal.
*/
bool Connected(Object & env, Function & func) const;
/* --------------------------------------------------------------------------------------------
* Disconnect a function with a specific environment from the signal.
*/
void Disconnect(Object & env, Function & func);
/* --------------------------------------------------------------------------------------------
* Disconnect all functions with a specific environment from the signal.
*/
void DisconnectThis(Object & env);
/* --------------------------------------------------------------------------------------------
* Disconnect all matching functions regardless of the environment from the signal.
*/
void DisconnectFunc(Function & func);
/* --------------------------------------------------------------------------------------------
* Count all functions with a specific environment from the signal.
*/
Uint32 CountThis(Object & env) const;
/* --------------------------------------------------------------------------------------------
* Count all matching functions regardless of the environment from the signal.
*/
Uint32 CountFunc(Function & func) const;
/* --------------------------------------------------------------------------------------------
* Make sure that specified slot is positioned ahead of all other slots.
*/
void Head(Object & env, Function & func);
/* --------------------------------------------------------------------------------------------
* Make sure that specified slot is positioned behind of all other slots.
*/
void Tail(Object & env, Function & func);
/* --------------------------------------------------------------------------------------------
* Emit the event to the connected slots.
*/
static SQInteger SqEmit(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Emit the event to the connected slots and collect returned values.
*/
static SQInteger SqQuery(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Emit the event to the connected slots and see if they consume it.
*/
static SQInteger SqConsume(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Emit the event to the connected slots and see if they approve it.
*/
static SQInteger SqApprove(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Emit the event to the connected slots and see if they return something.
*/
static SQInteger SqRequest(HSQUIRRELVM vm);
private:
// --------------------------------------------------------------------------------------------
typedef std::pair< std::size_t, SignalReference > SignalElement;
typedef std::vector< SignalElement > SignalContainer;
typedef std::vector< Signal * > FreeSignals;
// --------------------------------------------------------------------------------------------
static SignalContainer s_Signals; // List of all created signals.
static FreeSignals s_FreeSignals; // List of signals without a name.
public:
/* --------------------------------------------------------------------------------------------
* Terminate all signal instances and release any script resources.
*/
static void Terminate();
/* --------------------------------------------------------------------------------------------
* Create a free signal without a specific name.
*/
static Object CreateFree();
/* --------------------------------------------------------------------------------------------
* Create a new signal with the specified name.
*/
static Object Create(const StackStrF & name);
/* --------------------------------------------------------------------------------------------
* Remove the signal with the specified name.
*/
static void Remove(const StackStrF & name);
/* --------------------------------------------------------------------------------------------
* Retrieve the signal with the specified name.
*/
static Object Fetch(const StackStrF & name);
};
} // Namespace:: SqMod
#endif // _MISC_SIGNAL_HPP_

1716
source/Signal.cpp Normal file

File diff suppressed because it is too large Load Diff

767
source/Signal.hpp Normal file
View File

@ -0,0 +1,767 @@
#ifndef _SIGNAL_HPP_
#define _SIGNAL_HPP_
// ------------------------------------------------------------------------------------------------
#include "Base/Shared.hpp"
// ------------------------------------------------------------------------------------------------
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
struct Signal;
struct SignalWrapper;
/* ------------------------------------------------------------------------------------------------
* Class used to deliver events to one or more listeners.
*/
struct Signal
{
friend class SignalWrapper;
// --------------------------------------------------------------------------------------------
typedef unsigned int SizeType; // Type of value used to represent sizes and/or indexes.
// --------------------------------------------------------------------------------------------
enum { SMB_SIZE = 8 };
/* --------------------------------------------------------------------------------------------
* Default constructor.
*/
Signal();
/* --------------------------------------------------------------------------------------------
* Default constructor.
*/
explicit Signal(const char * name)
: Signal(String(name))
{
//...
}
/* --------------------------------------------------------------------------------------------
* Default constructor.
*/
explicit Signal(const String & name)
: Signal(String(name))
{
//...
}
/* --------------------------------------------------------------------------------------------
* Default constructor.
*/
Signal(String && name);
/* --------------------------------------------------------------------------------------------
* Copy constructor (disabled).
*/
Signal(const Signal & o) = delete;
/* --------------------------------------------------------------------------------------------
* Move constructor (disabled).
*/
Signal(Signal && o) = delete;
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~Signal();
/* --------------------------------------------------------------------------------------------
* Copy assignment operator (disabled).
*/
Signal & operator = (const Signal & o) = delete;
/* --------------------------------------------------------------------------------------------
* Move assignment operator (disabled).
*/
Signal & operator = (Signal && o) = delete;
protected:
/* --------------------------------------------------------------------------------------------
* Adjust the internal buffer size if necessary.
*/
bool AdjustSlots(SizeType capacity);
/* --------------------------------------------------------------------------------------------
* Structure responsible for storing information about a slot.
*/
struct Slot {
SQHash mThisHash; // The hash of the specified environment.
SQHash mFuncHash; // The hash of the specified callback.
HSQOBJECT mThisRef; // The specified script environment.
HSQOBJECT mFuncRef; // The specified script callback.
/* ----------------------------------------------------------------------------------------
* Default constructor.
*/
Slot()
: mThisHash(0)
, mFuncHash(0)
, mThisRef()
, mFuncRef()
{
sq_resetobject(&mThisRef);
sq_resetobject(&mFuncRef);
}
/* ----------------------------------------------------------------------------------------
* Forwarding constructor.
*/
Slot(Object & env, Function & func)
: Slot(env.GetObject(), func.GetFunc())
{
/* ... */
}
/* ----------------------------------------------------------------------------------------
* Base constructor.
*/
Slot(HSQOBJECT & env, HSQOBJECT & func)
: mThisHash(0)
, mFuncHash(0)
, mThisRef(env)
, mFuncRef(func)
{
HSQUIRRELVM vm = DefaultVM::Get();
// Remember the current stack size
const StackGuard sg(vm);
// Is there an explicit environment?
if (!sq_isnull(mThisRef))
{
// Keep a reference to this environment
sq_addref(vm, &mThisRef);
// Push the environment on the stack
sq_pushobject(vm, mThisRef);
// Grab the hash of the environment object
mThisHash = sq_gethash(vm, -1);
}
// Is there an explicit function?
if (!sq_isnull(mFuncRef))
{
// Keep a reference to this function
sq_addref(vm, &mFuncRef);
// Push the callback on the stack
sq_pushobject(vm, mFuncRef);
// Grab the hash of the callback object
mFuncHash = sq_gethash(vm, -1);
}
}
/* ----------------------------------------------------------------------------------------
* Base constructor.
*/
Slot(HSQOBJECT & env, HSQOBJECT & func, SQHash envh, SQHash funch)
: mThisHash(envh)
, mFuncHash(funch)
, mThisRef(env)
, mFuncRef(func)
{
}
/* ----------------------------------------------------------------------------------------
* Copy constructor.
*/
Slot(const Slot & o)
: mThisHash(o.mThisHash)
, mFuncHash(o.mFuncHash)
, mThisRef(o.mThisRef)
, mFuncRef(o.mFuncRef)
{
// Track reference
if (mFuncHash != 0)
{
sq_addref(DefaultVM::Get(), &mThisRef);
sq_addref(DefaultVM::Get(), &mFuncRef);
}
}
/* ----------------------------------------------------------------------------------------
* Move constructor.
*/
Slot(Slot && o)
: mThisHash(o.mThisHash)
, mFuncHash(o.mFuncHash)
, mThisRef(o.mThisRef)
, mFuncRef(o.mFuncRef)
{
// Take ownership
sq_resetobject(&o.mThisRef);
sq_resetobject(&o.mFuncRef);
}
/* ----------------------------------------------------------------------------------------
* Destructor.
*/
~Slot()
{
Release();
}
/* ----------------------------------------------------------------------------------------
* Copy assignment operator. (disabled)
*/
Slot & operator = (const Slot & o)
{
if (this != &o)
{
// Release current resources, if any
Release();
// Replicate data
mThisHash = o.mThisHash;
mFuncHash = o.mFuncHash;
mThisRef = o.mThisRef;
mFuncRef = o.mFuncRef;
// Track reference
sq_addref(DefaultVM::Get(), &const_cast< HSQOBJECT & >(o.mThisRef));
sq_addref(DefaultVM::Get(), &const_cast< HSQOBJECT & >(o.mFuncRef));
}
return *this;
}
/* ----------------------------------------------------------------------------------------
* Move assignment operator.
*/
Slot & operator = (Slot && o)
{
if (this != &o)
{
// Release current resources, if any
Release();
// Replicate data
mThisHash = o.mThisHash;
mFuncHash = o.mFuncHash;
mThisRef = o.mThisRef;
mFuncRef = o.mFuncRef;
// Take ownership
sq_resetobject(&o.mThisRef);
sq_resetobject(&o.mFuncRef);
}
return *this;
}
/* ----------------------------------------------------------------------------------------
* Equality comparison operator.
*/
bool operator == (const Slot & o) const
{
return (mThisHash == o.mThisHash) && (mFuncHash == o.mFuncHash);
}
/* ----------------------------------------------------------------------------------------
* Inequality comparison operator.
*/
bool operator != (const Slot & o) const
{
return (mThisHash != o.mThisHash) || (mFuncHash != o.mFuncHash);
}
/* ----------------------------------------------------------------------------------------
* Release managed script resources.
*/
bool Available() const
{
return (mFuncHash == 0);
}
/* ----------------------------------------------------------------------------------------
* Release managed script resources.
*/
void Release()
{
// Should we release any environment object?
if (mThisHash != 0)
{
sq_release(DefaultVM::Get(), &mThisRef);
sq_resetobject(&mThisRef);
// Also reset the hash
mThisHash = 0;
}
// Should we release any callback object?
if (mFuncHash != 0)
{
sq_release(DefaultVM::Get(), &mFuncRef);
sq_resetobject(&mFuncRef);
// Also reset the hash
mFuncHash = 0;
}
}
/* ----------------------------------------------------------------------------------------
* Swap the values of two slots.
*/
void Swap(Slot & s)
{
// Swap the environment hash
SQHash h = mThisHash;
mThisHash = s.mThisHash;
s.mThisHash = h;
// Swap the callback hash
h = mFuncHash;
mFuncHash = s.mFuncHash;
s.mFuncHash = h;
// Swap the environment object
HSQOBJECT o = mThisRef;
mThisRef = s.mThisRef;
s.mThisRef = o;
// Swap the callback object
o = mFuncRef;
mFuncRef = s.mFuncRef;
s.mFuncRef = o;
}
};
// --------------------------------------------------------------------------------------------
typedef Slot ValueType; // Value type used to represent a slot.
typedef ValueType & Reference; // Reference to the stored value type
typedef const ValueType & ConstReference; // Constant reference to the stored value type.
typedef ValueType * Pointer; // Pointer to the stored value type
typedef const ValueType * ConstPointer; // Constant pointer to the stored value type.
// --------------------------------------------------------------------------------------------
/// Execution scope used to adjust iterators when removing slots or adjusting the buffer.
struct Scope {
// ----------------------------------------------------------------------------------------
Pointer mItr; ///< Currently executed slot.
Pointer mEnd; ///< Where the execution ends.
Scope * mParent; ///< Previous execution scope.
Scope * mChild; ///< Next execution scope.
// ----------------------------------------------------------------------------------------
/// Default constructor.
Scope(Scope * parent, Pointer begin, Pointer end)
: mItr(begin), mEnd(end), mParent(parent), mChild(nullptr)
{
if (mParent != nullptr) mParent->mChild = this;
}
// ----------------------------------------------------------------------------------------
/// Destructor.
~Scope() {
if (mParent != nullptr) mParent->mChild = nullptr;
}
// ----------------------------------------------------------------------------------------
/// Adjust the iterators to account for the fact that the specified slot was removed.
void Descend(Pointer ptr);
/// Adjust the iterators to account for the fact that the specified slot is now leading.
void Lead(Pointer ptr);
/// Adjust the iterators to account for the fact that the specified slot is now tailing.
void Tail(Pointer ptr);
/// Adjust the iterators to finish the execution abruptly.
void Finish();
};
private:
// --------------------------------------------------------------------------------------------
SizeType m_Used; // The number of stored slots that are valid.
SizeType m_Size; // The size of the memory allocated for slots.
Pointer m_Slots; // Pointer to the memory containing the slots.
// --------------------------------------------------------------------------------------------
Scope * m_Scope; // Current execution state.
// --------------------------------------------------------------------------------------------
String m_Name; // The name that identifies this signal.
LightObj m_Data; // User data associated with this instance.
// --------------------------------------------------------------------------------------------
ValueType m_SMB[SMB_SIZE]{}; // Small buffer optimization.
public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
const String & ToString() const
{
return m_Name;
}
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user data.
*/
LightObj & GetData()
{
return m_Data;
}
/* --------------------------------------------------------------------------------------------
* Modify the associated user data.
*/
void SetData(LightObj & data)
{
m_Data = data;
}
/* --------------------------------------------------------------------------------------------
* The number of slots connected to the signal.
*/
SQInteger GetUsed() const
{
return static_cast< SQInteger >(m_Used);
}
/* --------------------------------------------------------------------------------------------
* Clear all slots connected to the signal.
*/
void ClearSlots();
/* --------------------------------------------------------------------------------------------
* See if there are any slots connected.
*/
bool IsEmpty() const
{
return (m_Used == 0);
}
protected:
/* --------------------------------------------------------------------------------------------
* Connect the specified slot to the signal.
*/
SQInteger Connect(SignalWrapper & w);
/* --------------------------------------------------------------------------------------------
* Connect the specified slot but not before disconnecting all other occurrences.
*/
SQInteger ConnectOnce(SignalWrapper & w);
/* --------------------------------------------------------------------------------------------
* Disconnect all occurrences of the specified slot from the signal.
*/
SQInteger Disconnect(SignalWrapper & w);
/* --------------------------------------------------------------------------------------------
* See if the specified slot is connected to the signal.
*/
SQInteger Exists(SignalWrapper & w);
/* --------------------------------------------------------------------------------------------
* See if the specified slot environment is connected to the signal.
*/
SQInteger ExistsThis(SignalWrapper & w);
/* --------------------------------------------------------------------------------------------
* See if the specified slot callback is connected to the signal.
*/
SQInteger ExistsFunc(SignalWrapper & w);
/* --------------------------------------------------------------------------------------------
* Count all occurrences of the specified slot.
*/
SQInteger Count(SignalWrapper & w);
/* --------------------------------------------------------------------------------------------
* Count all occurrences of the specified slot environment.
*/
SQInteger CountThis(SignalWrapper & w);
/* --------------------------------------------------------------------------------------------
* Count all occurrences of the specified slot callback.
*/
SQInteger CountFunc(SignalWrapper & w);
/* --------------------------------------------------------------------------------------------
* Move all occurrences of the specified slot to the front.
*/
SQInteger Lead(SignalWrapper & w);
/* --------------------------------------------------------------------------------------------
* Move all occurrences of the specified slot environment to the front.
*/
SQInteger LeadThis(SignalWrapper & w);
/* --------------------------------------------------------------------------------------------
* Move all occurrences of the specified slot callback to the front.
*/
SQInteger LeadFunc(SignalWrapper & w);
/* --------------------------------------------------------------------------------------------
* Move all occurrences of the specified slot to the back.
*/
SQInteger Tail(SignalWrapper & w);
/* --------------------------------------------------------------------------------------------
* Move all occurrences of the specified slot environment to the back.
*/
SQInteger TailThis(SignalWrapper & w);
/* --------------------------------------------------------------------------------------------
* Move all occurrences of the specified slot callback to the back.
*/
SQInteger TailFunc(SignalWrapper & w);
/* --------------------------------------------------------------------------------------------
* Remove all occurrences of the specified slot.
*/
SQInteger Eliminate(SignalWrapper & w);
/* --------------------------------------------------------------------------------------------
* Remove all occurrences of the specified slot environment.
*/
SQInteger EliminateThis(SignalWrapper & w);
/* --------------------------------------------------------------------------------------------
* Remove all occurrences of the specified slot callback.
*/
SQInteger EliminateFunc(SignalWrapper & w);
public:
/* --------------------------------------------------------------------------------------------
* Squirrel wrapper for the `Connect` method of this class.
*/
static SQInteger SqConnect(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Squirrel wrapper for the `ConnectOnce` method of this class.
*/
static SQInteger SqConnectOnce(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Squirrel wrapper for the `Exists` method of this class.
*/
static SQInteger SqExists(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Squirrel wrapper for the `Disconnect` method of this class.
*/
static SQInteger SqDisconnect(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Squirrel wrapper for the `ExistsThis` method of this class.
*/
static SQInteger SqExistsThis(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Squirrel wrapper for the `ExistsFunc` method of this class.
*/
static SQInteger SqExistsFunc(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Squirrel wrapper for the `Count` method of this class.
*/
static SQInteger SqCount(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Squirrel wrapper for the `CountThis` method of this class.
*/
static SQInteger SqCountThis(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Squirrel wrapper for the `CountFunc` method of this class.
*/
static SQInteger SqCountFunc(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Squirrel wrapper for the `Lead` method of this class.
*/
static SQInteger SqLead(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Squirrel wrapper for the `LeadThis` method of this class.
*/
static SQInteger SqLeadThis(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Squirrel wrapper for the `LeadFunc` method of this class.
*/
static SQInteger SqLeadFunc(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Squirrel wrapper for the `Tail` method of this class.
*/
static SQInteger SqTail(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Squirrel wrapper for the `TailThis` method of this class.
*/
static SQInteger SqTailThis(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Squirrel wrapper for the `TailFunc` method of this class.
*/
static SQInteger SqTailFunc(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Squirrel wrapper for the `Eliminate` method of this class.
*/
static SQInteger SqEliminate(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Squirrel wrapper for the `EliminateThis` method of this class.
*/
static SQInteger SqEliminateThis(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Squirrel wrapper for the `EliminateFunc` method of this class.
*/
static SQInteger SqEliminateFunc(HSQUIRRELVM vm);
protected:
/* --------------------------------------------------------------------------------------------
* Emit the event to the connected slots.
*/
SQInteger Emit(HSQUIRRELVM vm, SQInteger top);
/* --------------------------------------------------------------------------------------------
* Emit the event to the connected slots and collect returned values.
*/
SQInteger Query(HSQUIRRELVM vm, SQInteger top);
/* --------------------------------------------------------------------------------------------
* Emit the event to the connected slots and see if they consume it.
*/
SQInteger Consume(HSQUIRRELVM vm, SQInteger top);
/* --------------------------------------------------------------------------------------------
* Emit the event to the connected slots and see if they approve it.
*/
SQInteger Approve(HSQUIRRELVM vm, SQInteger top);
/* --------------------------------------------------------------------------------------------
* Emit the event to the connected slots and see if they return something.
*/
SQInteger Request(HSQUIRRELVM vm, SQInteger top);
public:
/* --------------------------------------------------------------------------------------------
* Squirrel wrapper for the `Emit` method of this class.
*/
static SQInteger SqEmit(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Squirrel wrapper for the `Query` method of this class.
*/
static SQInteger SqQuery(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Squirrel wrapper for the `Consume` method of this class.
*/
static SQInteger SqConsume(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Squirrel wrapper for the `Approve` method of this class.
*/
static SQInteger SqApprove(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Squirrel wrapper for the `Request` method of this class.
*/
static SQInteger SqRequest(HSQUIRRELVM vm);
protected:
// --------------------------------------------------------------------------------------------
typedef std::pair< std::size_t, SignalPair > SignalElement;
typedef std::vector< SignalElement > SignalPool;
typedef std::vector< Signal * > FreeSignals;
// --------------------------------------------------------------------------------------------
static SignalPool s_Signals; // List of all created signals.
static FreeSignals s_FreeSignals; // List of signals without a name.
/* --------------------------------------------------------------------------------------------
* Specialization for when there are no arguments given.
*/
void PushParameters()
{
//...
}
/* --------------------------------------------------------------------------------------------
* Specialization for when there's only one argument given/remaining.
*/
template < typename T > void PushParameters(T v)
{
Var< T >::push(DefaultVM::Get(), v);
}
/* --------------------------------------------------------------------------------------------
* Specialization for when there's more than one argument given.
*/
template < typename T, typename... Args > void PushParameters(T v, Args... args)
{
Var< T >::push(DefaultVM::Get(), v);
PushParameters(args...);
}
public:
/* --------------------------------------------------------------------------------------------
* Terminate all signal instances and release any script resources.
*/
static void Terminate();
/* --------------------------------------------------------------------------------------------
* Create a free signal without a specific name.
*/
static LightObj CreateFree();
/* --------------------------------------------------------------------------------------------
* Create a new signal with the specified name.
*/
static LightObj Create(const StackStrF & name);
/* --------------------------------------------------------------------------------------------
* Remove the signal with the specified name.
*/
static void Remove(const StackStrF & name);
/* --------------------------------------------------------------------------------------------
* Retrieve the signal with the specified name.
*/
static const LightObj & Fetch(const StackStrF & name);
/* --------------------------------------------------------------------------------------------
* Emit a signal from the module.
*/
template < typename... Args > void operator () (Args&&... args)
{
// Are there any slots connected?
if (!m_Used) return;
// Enter a new execution scope
Scope scope(m_Scope, m_Slots, m_Slots + m_Used);
// Activate the current scope and create a guard to restore it
const AutoAssign< Scope * > aa(m_Scope, scope.mParent, &scope);
// Grab the default virtual machine
HSQUIRRELVM vm = DefaultVM::Get();
// Process the slots from this scope
while (scope.mItr != scope.mEnd)
{
// Grab a reference to the current slot
const Slot & slot = *(scope.mItr++);
// Push the callback object
sq_pushobject(vm, slot.mFuncRef);
// Is there an explicit environment?
if (slot.mThisHash == 0)
{
sq_pushroottable(vm);
}
else
{
sq_pushobject(vm, slot.mThisRef);
}
// Push the given parameters on the stack
PushParameters(args...);
// Make the function call and store the result
const SQRESULT res = sq_call(vm, 1 + sizeof...(Args), false, ErrorHandling::IsEnabled());
// Pop the callback object from the stack
sq_pop(vm, 1);
// Validate the result
if (SQ_FAILED(res))
{
SQTHROW(vm, LastErrorString(vm)); // Stop emitting signals
}
}
}
};
} // Namespace:: SqMod
#endif // _SIGNAL_HPP_

View File

@ -241,6 +241,7 @@ typedef std::basic_string< SQChar > String;
// ------------------------------------------------------------------------------------------------
class Core;
class Logger;
class Signal;
// ------------------------------------------------------------------------------------------------
class CmdManager;

View File

@ -184,7 +184,7 @@ void Tasks::Deinitialize()
}
// ------------------------------------------------------------------------------------------------
Object & Tasks::FindEntity(Int32 id, Int32 type)
LightObj & Tasks::FindEntity(Int32 id, Int32 type)
{
switch (type)
{
@ -195,7 +195,7 @@ Object & Tasks::FindEntity(Int32 id, Int32 type)
case ENT_PICKUP: return Core::Get().GetPickup(id).mObj;
case ENT_PLAYER: return Core::Get().GetPlayer(id).mObj;
case ENT_VEHICLE: return Core::Get().GetVehicle(id).mObj;
default: return NullObject();
default: return NullLightObj();
}
}

View File

@ -328,7 +328,7 @@ protected:
/* --------------------------------------------------------------------------------------------
* Retrieve the instance of the specified entity.
*/
static Object & FindEntity(Int32 id, Int32 type);
static LightObj & FindEntity(Int32 id, Int32 type);
/* --------------------------------------------------------------------------------------------
* Find an unoccupied task slot.