mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2024-11-08 08:47:17 +01:00
Dumb approach to recive some kind of asserts if the program crashes because a component was used after it was deleted.
This commit is contained in:
parent
3762b5e2ca
commit
ff6cacaf68
@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
#include <vcmp.h>
|
#include <vcmp.h>
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
namespace SqMod {
|
namespace SqMod {
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
CmdManager * _Cmd = nullptr;
|
SQMOD_MANAGEDPTR_TYPE(CmdManager) _Cmd = SQMOD_MANAGEDPTR_MAKE(CmdManager, nullptr);
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
SQInteger CmdListener::Typename(HSQUIRRELVM vm)
|
SQInteger CmdListener::Typename(HSQUIRRELVM vm)
|
||||||
|
@ -21,7 +21,7 @@ class CmdListener;
|
|||||||
CSStr CmdArgSpecToStr(Uint8 spec);
|
CSStr CmdArgSpecToStr(Uint8 spec);
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
extern CmdManager * _Cmd;
|
extern SQMOD_MANAGEDPTR_TYPE(CmdManager) _Cmd;
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------------------------------
|
||||||
* Manages command instances and processes executed commands.
|
* Manages command instances and processes executed commands.
|
||||||
@ -188,10 +188,10 @@ public:
|
|||||||
{
|
{
|
||||||
if (!_Cmd)
|
if (!_Cmd)
|
||||||
{
|
{
|
||||||
_Cmd = new CmdManager();
|
_Cmd = SQMOD_MANAGEDPTR_MAKE(CmdManager, new CmdManager());
|
||||||
}
|
}
|
||||||
|
|
||||||
return _Cmd;
|
return SQMOD_MANAGEDPTR_GET(_Cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
434
source/Core.cpp
434
source/Core.cpp
@ -46,7 +46,7 @@ extern Int32 RunCommand(Int32 invoker, CSStr command);
|
|||||||
extern void TerminateCommand();
|
extern void TerminateCommand();
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
Core * _Core = NULL;
|
SQMOD_MANAGEDPTR_TYPE(Core) _Core = SQMOD_MANAGEDPTR_MAKE(Core, nullptr);
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------------------------------
|
||||||
* Utility class used to release the destroy lock if unable to complete the process.
|
* Utility class used to release the destroy lock if unable to complete the process.
|
||||||
@ -56,7 +56,7 @@ struct EntLockGuard
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------------------
|
||||||
Uint16 & m_Flags;
|
Uint16 & m_Flags; // Reference to the guarded entity flags.
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ public:
|
|||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
Core::Core()
|
Core::Core()
|
||||||
: m_State(0)
|
: m_State(0)
|
||||||
, m_VM(NULL)
|
, m_VM(nullptr)
|
||||||
, m_Scripts()
|
, m_Scripts()
|
||||||
, m_Options()
|
, m_Options()
|
||||||
, m_Blips()
|
, m_Blips()
|
||||||
@ -371,7 +371,7 @@ void Core::Terminate()
|
|||||||
m_Scripts.clear();
|
m_Scripts.clear();
|
||||||
// Assertions during close may cause double delete!
|
// Assertions during close may cause double delete!
|
||||||
HSQUIRRELVM sq_vm = m_VM;
|
HSQUIRRELVM sq_vm = m_VM;
|
||||||
m_VM = NULL;
|
m_VM = nullptr;
|
||||||
// Attempt to close the VM
|
// Attempt to close the VM
|
||||||
sq_close(sq_vm);
|
sq_close(sq_vm);
|
||||||
}
|
}
|
||||||
@ -442,7 +442,7 @@ SQInteger Core::RuntimeErrorHandler(HSQUIRRELVM vm)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
CSStr err_msg = NULL;
|
CSStr err_msg = nullptr;
|
||||||
|
|
||||||
if (SQ_SUCCEEDED(sq_getstring(vm, 2, &err_msg)))
|
if (SQ_SUCCEEDED(sq_getstring(vm, 2, &err_msg)))
|
||||||
{
|
{
|
||||||
@ -890,7 +890,7 @@ void Core::DeallocBlip(Int32 id, bool destroy, Int32 header, Object & payload)
|
|||||||
// Release associated script callbacks
|
// Release associated script callbacks
|
||||||
ResetFunc(inst);
|
ResetFunc(inst);
|
||||||
// Prevent further use of the manager instance
|
// Prevent further use of the manager instance
|
||||||
inst.mInst = NULL;
|
inst.mInst = nullptr;
|
||||||
// Release the script object, if any
|
// Release the script object, if any
|
||||||
inst.mObj.Release();
|
inst.mObj.Release();
|
||||||
}
|
}
|
||||||
@ -939,7 +939,7 @@ void Core::DeallocCheckpoint(Int32 id, bool destroy, Int32 header, Object & payl
|
|||||||
// Release associated script callbacks
|
// Release associated script callbacks
|
||||||
ResetFunc(inst);
|
ResetFunc(inst);
|
||||||
// Prevent further use of the manager instance
|
// Prevent further use of the manager instance
|
||||||
inst.mInst = NULL;
|
inst.mInst = nullptr;
|
||||||
// Release the script object, if any
|
// Release the script object, if any
|
||||||
inst.mObj.Release();
|
inst.mObj.Release();
|
||||||
}
|
}
|
||||||
@ -988,7 +988,7 @@ void Core::DeallocForcefield(Int32 id, bool destroy, Int32 header, Object & payl
|
|||||||
// Release associated script callbacks
|
// Release associated script callbacks
|
||||||
ResetFunc(inst);
|
ResetFunc(inst);
|
||||||
// Prevent further use of the manager instance
|
// Prevent further use of the manager instance
|
||||||
inst.mInst = NULL;
|
inst.mInst = nullptr;
|
||||||
// Release the script object, if any
|
// Release the script object, if any
|
||||||
inst.mObj.Release();
|
inst.mObj.Release();
|
||||||
}
|
}
|
||||||
@ -1037,7 +1037,7 @@ void Core::DeallocKeybind(Int32 id, bool destroy, Int32 header, Object & payload
|
|||||||
// Release associated script callbacks
|
// Release associated script callbacks
|
||||||
ResetFunc(inst);
|
ResetFunc(inst);
|
||||||
// Prevent further use of the manager instance
|
// Prevent further use of the manager instance
|
||||||
inst.mInst = NULL;
|
inst.mInst = nullptr;
|
||||||
// Release the script object, if any
|
// Release the script object, if any
|
||||||
inst.mObj.Release();
|
inst.mObj.Release();
|
||||||
}
|
}
|
||||||
@ -1086,7 +1086,7 @@ void Core::DeallocObject(Int32 id, bool destroy, Int32 header, Object & payload)
|
|||||||
// Release associated script callbacks
|
// Release associated script callbacks
|
||||||
ResetFunc(inst);
|
ResetFunc(inst);
|
||||||
// Prevent further use of the manager instance
|
// Prevent further use of the manager instance
|
||||||
inst.mInst = NULL;
|
inst.mInst = nullptr;
|
||||||
// Release the script object, if any
|
// Release the script object, if any
|
||||||
inst.mObj.Release();
|
inst.mObj.Release();
|
||||||
}
|
}
|
||||||
@ -1135,7 +1135,7 @@ void Core::DeallocPickup(Int32 id, bool destroy, Int32 header, Object & payload)
|
|||||||
// Release associated script callbacks
|
// Release associated script callbacks
|
||||||
ResetFunc(inst);
|
ResetFunc(inst);
|
||||||
// Prevent further use of the manager instance
|
// Prevent further use of the manager instance
|
||||||
inst.mInst = NULL;
|
inst.mInst = nullptr;
|
||||||
// Release the script object, if any
|
// Release the script object, if any
|
||||||
inst.mObj.Release();
|
inst.mObj.Release();
|
||||||
}
|
}
|
||||||
@ -1184,7 +1184,7 @@ void Core::DeallocSprite(Int32 id, bool destroy, Int32 header, Object & payload)
|
|||||||
// Release associated script callbacks
|
// Release associated script callbacks
|
||||||
ResetFunc(inst);
|
ResetFunc(inst);
|
||||||
// Prevent further use of the manager instance
|
// Prevent further use of the manager instance
|
||||||
inst.mInst = NULL;
|
inst.mInst = nullptr;
|
||||||
// Release the script object, if any
|
// Release the script object, if any
|
||||||
inst.mObj.Release();
|
inst.mObj.Release();
|
||||||
}
|
}
|
||||||
@ -1233,7 +1233,7 @@ void Core::DeallocTextdraw(Int32 id, bool destroy, Int32 header, Object & payloa
|
|||||||
// Release associated script callbacks
|
// Release associated script callbacks
|
||||||
ResetFunc(inst);
|
ResetFunc(inst);
|
||||||
// Prevent further use of the manager instance
|
// Prevent further use of the manager instance
|
||||||
inst.mInst = NULL;
|
inst.mInst = nullptr;
|
||||||
// Release the script object, if any
|
// Release the script object, if any
|
||||||
inst.mObj.Release();
|
inst.mObj.Release();
|
||||||
}
|
}
|
||||||
@ -1282,7 +1282,7 @@ void Core::DeallocVehicle(Int32 id, bool destroy, Int32 header, Object & payload
|
|||||||
// Release associated script callbacks
|
// Release associated script callbacks
|
||||||
ResetFunc(inst);
|
ResetFunc(inst);
|
||||||
// Prevent further use of the manager instance
|
// Prevent further use of the manager instance
|
||||||
inst.mInst = NULL;
|
inst.mInst = nullptr;
|
||||||
// Release the script object, if any
|
// Release the script object, if any
|
||||||
inst.mObj.Release();
|
inst.mObj.Release();
|
||||||
}
|
}
|
||||||
@ -1580,7 +1580,7 @@ void Core::DisconnectPlayer(Int32 id, Int32 header, Object & payload)
|
|||||||
// Release associated script callbacks
|
// Release associated script callbacks
|
||||||
ResetFunc(inst);
|
ResetFunc(inst);
|
||||||
// Prevent further use of the manager instance
|
// Prevent further use of the manager instance
|
||||||
inst.mInst = NULL;
|
inst.mInst = nullptr;
|
||||||
// Release the script object, if any
|
// Release the script object, if any
|
||||||
inst.mObj.Release();
|
inst.mObj.Release();
|
||||||
}
|
}
|
||||||
@ -2565,7 +2565,7 @@ void Core::ResetInst(PlayerInst & inst)
|
|||||||
inst.mAuthority = 0;
|
inst.mAuthority = 0;
|
||||||
for (unsigned n = 0; n < SQMOD_PLAYER_MSG_PREFIXES; ++n)
|
for (unsigned n = 0; n < SQMOD_PLAYER_MSG_PREFIXES; ++n)
|
||||||
{
|
{
|
||||||
inst.mPrefixes[n].clear();
|
inst.mPrefixes[n].assign("");
|
||||||
}
|
}
|
||||||
inst.mMessageColor = 0x6599FFFF;
|
inst.mMessageColor = 0x6599FFFF;
|
||||||
inst.mAnnounceStyle = 1;
|
inst.mAnnounceStyle = 1;
|
||||||
@ -2594,247 +2594,247 @@ void Core::ResetInst(VehicleInst & inst)
|
|||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
void Core::ResetFunc(BlipInst & inst)
|
void Core::ResetFunc(BlipInst & inst)
|
||||||
{
|
{
|
||||||
inst.mOnDestroyed.Release();
|
inst.mOnDestroyed.ReleaseGently();
|
||||||
inst.mOnCustom.Release();
|
inst.mOnCustom.ReleaseGently();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::ResetFunc(CheckpointInst & inst)
|
void Core::ResetFunc(CheckpointInst & inst)
|
||||||
{
|
{
|
||||||
inst.mOnDestroyed.Release();
|
inst.mOnDestroyed.ReleaseGently();
|
||||||
inst.mOnCustom.Release();
|
inst.mOnCustom.ReleaseGently();
|
||||||
inst.mOnEntered.Release();
|
inst.mOnEntered.ReleaseGently();
|
||||||
inst.mOnExited.Release();
|
inst.mOnExited.ReleaseGently();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::ResetFunc(ForcefieldInst & inst)
|
void Core::ResetFunc(ForcefieldInst & inst)
|
||||||
{
|
{
|
||||||
inst.mOnDestroyed.Release();
|
inst.mOnDestroyed.ReleaseGently();
|
||||||
inst.mOnCustom.Release();
|
inst.mOnCustom.ReleaseGently();
|
||||||
inst.mOnEntered.Release();
|
inst.mOnEntered.ReleaseGently();
|
||||||
inst.mOnExited.Release();
|
inst.mOnExited.ReleaseGently();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::ResetFunc(KeybindInst & inst)
|
void Core::ResetFunc(KeybindInst & inst)
|
||||||
{
|
{
|
||||||
inst.mOnDestroyed.Release();
|
inst.mOnDestroyed.ReleaseGently();
|
||||||
inst.mOnCustom.Release();
|
inst.mOnCustom.ReleaseGently();
|
||||||
inst.mOnKeyPress.Release();
|
inst.mOnKeyPress.ReleaseGently();
|
||||||
inst.mOnKeyRelease.Release();
|
inst.mOnKeyRelease.ReleaseGently();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::ResetFunc(ObjectInst & inst)
|
void Core::ResetFunc(ObjectInst & inst)
|
||||||
{
|
{
|
||||||
inst.mOnDestroyed.Release();
|
inst.mOnDestroyed.ReleaseGently();
|
||||||
inst.mOnCustom.Release();
|
inst.mOnCustom.ReleaseGently();
|
||||||
inst.mOnShot.Release();
|
inst.mOnShot.ReleaseGently();
|
||||||
inst.mOnBump.Release();
|
inst.mOnBump.ReleaseGently();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::ResetFunc(PickupInst & inst)
|
void Core::ResetFunc(PickupInst & inst)
|
||||||
{
|
{
|
||||||
inst.mOnDestroyed.Release();
|
inst.mOnDestroyed.ReleaseGently();
|
||||||
inst.mOnCustom.Release();
|
inst.mOnCustom.ReleaseGently();
|
||||||
inst.mOnRespawn.Release();
|
inst.mOnRespawn.ReleaseGently();
|
||||||
inst.mOnClaimed.Release();
|
inst.mOnClaimed.ReleaseGently();
|
||||||
inst.mOnCollected.Release();
|
inst.mOnCollected.ReleaseGently();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::ResetFunc(PlayerInst & inst)
|
void Core::ResetFunc(PlayerInst & inst)
|
||||||
{
|
{
|
||||||
inst.mOnDestroyed.Release();
|
inst.mOnDestroyed.ReleaseGently();
|
||||||
inst.mOnCustom.Release();
|
inst.mOnCustom.ReleaseGently();
|
||||||
inst.mOnAway.Release();
|
inst.mOnAway.ReleaseGently();
|
||||||
inst.mOnGameKeys.Release();
|
inst.mOnGameKeys.ReleaseGently();
|
||||||
inst.mOnRename.Release();
|
inst.mOnRename.ReleaseGently();
|
||||||
inst.mOnRequestClass.Release();
|
inst.mOnRequestClass.ReleaseGently();
|
||||||
inst.mOnRequestSpawn.Release();
|
inst.mOnRequestSpawn.ReleaseGently();
|
||||||
inst.mOnSpawn.Release();
|
inst.mOnSpawn.ReleaseGently();
|
||||||
inst.mOnStartTyping.Release();
|
inst.mOnStartTyping.ReleaseGently();
|
||||||
inst.mOnStopTyping.Release();
|
inst.mOnStopTyping.ReleaseGently();
|
||||||
inst.mOnChat.Release();
|
inst.mOnChat.ReleaseGently();
|
||||||
inst.mOnCommand.Release();
|
inst.mOnCommand.ReleaseGently();
|
||||||
inst.mOnMessage.Release();
|
inst.mOnMessage.ReleaseGently();
|
||||||
inst.mOnHealth.Release();
|
inst.mOnHealth.ReleaseGently();
|
||||||
inst.mOnArmour.Release();
|
inst.mOnArmour.ReleaseGently();
|
||||||
inst.mOnWeapon.Release();
|
inst.mOnWeapon.ReleaseGently();
|
||||||
inst.mOnMove.Release();
|
inst.mOnMove.ReleaseGently();
|
||||||
inst.mOnWasted.Release();
|
inst.mOnWasted.ReleaseGently();
|
||||||
inst.mOnKilled.Release();
|
inst.mOnKilled.ReleaseGently();
|
||||||
inst.mOnTeamKill.Release();
|
inst.mOnTeamKill.ReleaseGently();
|
||||||
inst.mOnSpectate.Release();
|
inst.mOnSpectate.ReleaseGently();
|
||||||
inst.mOnCrashreport.Release();
|
inst.mOnCrashreport.ReleaseGently();
|
||||||
inst.mOnBurning.Release();
|
inst.mOnBurning.ReleaseGently();
|
||||||
inst.mOnCrouching.Release();
|
inst.mOnCrouching.ReleaseGently();
|
||||||
inst.mOnState.Release();
|
inst.mOnState.ReleaseGently();
|
||||||
inst.mOnAction.Release();
|
inst.mOnAction.ReleaseGently();
|
||||||
inst.mOnStateNone.Release();
|
inst.mOnStateNone.ReleaseGently();
|
||||||
inst.mOnStateNormal.Release();
|
inst.mOnStateNormal.ReleaseGently();
|
||||||
inst.mOnStateShooting.Release();
|
inst.mOnStateShooting.ReleaseGently();
|
||||||
inst.mOnStateDriver.Release();
|
inst.mOnStateDriver.ReleaseGently();
|
||||||
inst.mOnStatePassenger.Release();
|
inst.mOnStatePassenger.ReleaseGently();
|
||||||
inst.mOnStateEnterDriver.Release();
|
inst.mOnStateEnterDriver.ReleaseGently();
|
||||||
inst.mOnStateEnterPassenger.Release();
|
inst.mOnStateEnterPassenger.ReleaseGently();
|
||||||
inst.mOnStateExitVehicle.Release();
|
inst.mOnStateExitVehicle.ReleaseGently();
|
||||||
inst.mOnStateUnspawned.Release();
|
inst.mOnStateUnspawned.ReleaseGently();
|
||||||
inst.mOnActionNone.Release();
|
inst.mOnActionNone.ReleaseGently();
|
||||||
inst.mOnActionNormal.Release();
|
inst.mOnActionNormal.ReleaseGently();
|
||||||
inst.mOnActionAiming.Release();
|
inst.mOnActionAiming.ReleaseGently();
|
||||||
inst.mOnActionShooting.Release();
|
inst.mOnActionShooting.ReleaseGently();
|
||||||
inst.mOnActionJumping.Release();
|
inst.mOnActionJumping.ReleaseGently();
|
||||||
inst.mOnActionLieDown.Release();
|
inst.mOnActionLieDown.ReleaseGently();
|
||||||
inst.mOnActionGettingUp.Release();
|
inst.mOnActionGettingUp.ReleaseGently();
|
||||||
inst.mOnActionJumpVehicle.Release();
|
inst.mOnActionJumpVehicle.ReleaseGently();
|
||||||
inst.mOnActionDriving.Release();
|
inst.mOnActionDriving.ReleaseGently();
|
||||||
inst.mOnActionDying.Release();
|
inst.mOnActionDying.ReleaseGently();
|
||||||
inst.mOnActionWasted.Release();
|
inst.mOnActionWasted.ReleaseGently();
|
||||||
inst.mOnActionEmbarking.Release();
|
inst.mOnActionEmbarking.ReleaseGently();
|
||||||
inst.mOnActionDisembarking.Release();
|
inst.mOnActionDisembarking.ReleaseGently();
|
||||||
inst.mOnKeyPress.Release();
|
inst.mOnKeyPress.ReleaseGently();
|
||||||
inst.mOnKeyRelease.Release();
|
inst.mOnKeyRelease.ReleaseGently();
|
||||||
inst.mOnEmbarking.Release();
|
inst.mOnEmbarking.ReleaseGently();
|
||||||
inst.mOnEmbarked.Release();
|
inst.mOnEmbarked.ReleaseGently();
|
||||||
inst.mOnDisembark.Release();
|
inst.mOnDisembark.ReleaseGently();
|
||||||
inst.mOnPickupClaimed.Release();
|
inst.mOnPickupClaimed.ReleaseGently();
|
||||||
inst.mOnPickupCollected.Release();
|
inst.mOnPickupCollected.ReleaseGently();
|
||||||
inst.mOnObjectShot.Release();
|
inst.mOnObjectShot.ReleaseGently();
|
||||||
inst.mOnObjectBump.Release();
|
inst.mOnObjectBump.ReleaseGently();
|
||||||
inst.mOnCheckpointEntered.Release();
|
inst.mOnCheckpointEntered.ReleaseGently();
|
||||||
inst.mOnCheckpointExited.Release();
|
inst.mOnCheckpointExited.ReleaseGently();
|
||||||
inst.mOnForcefieldEntered.Release();
|
inst.mOnForcefieldEntered.ReleaseGently();
|
||||||
inst.mOnForcefieldExited.Release();
|
inst.mOnForcefieldExited.ReleaseGently();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::ResetFunc(SpriteInst & inst)
|
void Core::ResetFunc(SpriteInst & inst)
|
||||||
{
|
{
|
||||||
inst.mOnDestroyed.Release();
|
inst.mOnDestroyed.ReleaseGently();
|
||||||
inst.mOnCustom.Release();
|
inst.mOnCustom.ReleaseGently();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::ResetFunc(TextdrawInst & inst)
|
void Core::ResetFunc(TextdrawInst & inst)
|
||||||
{
|
{
|
||||||
inst.mOnDestroyed.Release();
|
inst.mOnDestroyed.ReleaseGently();
|
||||||
inst.mOnCustom.Release();
|
inst.mOnCustom.ReleaseGently();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::ResetFunc(VehicleInst & inst)
|
void Core::ResetFunc(VehicleInst & inst)
|
||||||
{
|
{
|
||||||
inst.mOnDestroyed.Release();
|
inst.mOnDestroyed.ReleaseGently();
|
||||||
inst.mOnCustom.Release();
|
inst.mOnCustom.ReleaseGently();
|
||||||
inst.mOnRespawn.Release();
|
inst.mOnRespawn.ReleaseGently();
|
||||||
inst.mOnExplode.Release();
|
inst.mOnExplode.ReleaseGently();
|
||||||
inst.mOnHealth.Release();
|
inst.mOnHealth.ReleaseGently();
|
||||||
inst.mOnMove.Release();
|
inst.mOnMove.ReleaseGently();
|
||||||
inst.mOnEmbarking.Release();
|
inst.mOnEmbarking.ReleaseGently();
|
||||||
inst.mOnEmbarked.Release();
|
inst.mOnEmbarked.ReleaseGently();
|
||||||
inst.mOnDisembark.Release();
|
inst.mOnDisembark.ReleaseGently();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::ResetFunc()
|
void Core::ResetFunc()
|
||||||
{
|
{
|
||||||
mOnBlipCreated.Release();
|
mOnBlipCreated.ReleaseGently();
|
||||||
mOnCheckpointCreated.Release();
|
mOnCheckpointCreated.ReleaseGently();
|
||||||
mOnForcefieldCreated.Release();
|
mOnForcefieldCreated.ReleaseGently();
|
||||||
mOnKeybindCreated.Release();
|
mOnKeybindCreated.ReleaseGently();
|
||||||
mOnObjectCreated.Release();
|
mOnObjectCreated.ReleaseGently();
|
||||||
mOnPickupCreated.Release();
|
mOnPickupCreated.ReleaseGently();
|
||||||
mOnPlayerCreated.Release();
|
mOnPlayerCreated.ReleaseGently();
|
||||||
mOnSpriteCreated.Release();
|
mOnSpriteCreated.ReleaseGently();
|
||||||
mOnTextdrawCreated.Release();
|
mOnTextdrawCreated.ReleaseGently();
|
||||||
mOnVehicleCreated.Release();
|
mOnVehicleCreated.ReleaseGently();
|
||||||
mOnBlipDestroyed.Release();
|
mOnBlipDestroyed.ReleaseGently();
|
||||||
mOnCheckpointDestroyed.Release();
|
mOnCheckpointDestroyed.ReleaseGently();
|
||||||
mOnForcefieldDestroyed.Release();
|
mOnForcefieldDestroyed.ReleaseGently();
|
||||||
mOnKeybindDestroyed.Release();
|
mOnKeybindDestroyed.ReleaseGently();
|
||||||
mOnObjectDestroyed.Release();
|
mOnObjectDestroyed.ReleaseGently();
|
||||||
mOnPickupDestroyed.Release();
|
mOnPickupDestroyed.ReleaseGently();
|
||||||
mOnPlayerDestroyed.Release();
|
mOnPlayerDestroyed.ReleaseGently();
|
||||||
mOnSpriteDestroyed.Release();
|
mOnSpriteDestroyed.ReleaseGently();
|
||||||
mOnTextdrawDestroyed.Release();
|
mOnTextdrawDestroyed.ReleaseGently();
|
||||||
mOnVehicleDestroyed.Release();
|
mOnVehicleDestroyed.ReleaseGently();
|
||||||
mOnBlipCustom.Release();
|
mOnBlipCustom.ReleaseGently();
|
||||||
mOnCheckpointCustom.Release();
|
mOnCheckpointCustom.ReleaseGently();
|
||||||
mOnForcefieldCustom.Release();
|
mOnForcefieldCustom.ReleaseGently();
|
||||||
mOnKeybindCustom.Release();
|
mOnKeybindCustom.ReleaseGently();
|
||||||
mOnObjectCustom.Release();
|
mOnObjectCustom.ReleaseGently();
|
||||||
mOnPickupCustom.Release();
|
mOnPickupCustom.ReleaseGently();
|
||||||
mOnPlayerCustom.Release();
|
mOnPlayerCustom.ReleaseGently();
|
||||||
mOnSpriteCustom.Release();
|
mOnSpriteCustom.ReleaseGently();
|
||||||
mOnTextdrawCustom.Release();
|
mOnTextdrawCustom.ReleaseGently();
|
||||||
mOnVehicleCustom.Release();
|
mOnVehicleCustom.ReleaseGently();
|
||||||
mOnPlayerAway.Release();
|
mOnPlayerAway.ReleaseGently();
|
||||||
mOnPlayerGameKeys.Release();
|
mOnPlayerGameKeys.ReleaseGently();
|
||||||
mOnPlayerRename.Release();
|
mOnPlayerRename.ReleaseGently();
|
||||||
mOnPlayerRequestClass.Release();
|
mOnPlayerRequestClass.ReleaseGently();
|
||||||
mOnPlayerRequestSpawn.Release();
|
mOnPlayerRequestSpawn.ReleaseGently();
|
||||||
mOnPlayerSpawn.Release();
|
mOnPlayerSpawn.ReleaseGently();
|
||||||
mOnPlayerStartTyping.Release();
|
mOnPlayerStartTyping.ReleaseGently();
|
||||||
mOnPlayerStopTyping.Release();
|
mOnPlayerStopTyping.ReleaseGently();
|
||||||
mOnPlayerChat.Release();
|
mOnPlayerChat.ReleaseGently();
|
||||||
mOnPlayerCommand.Release();
|
mOnPlayerCommand.ReleaseGently();
|
||||||
mOnPlayerMessage.Release();
|
mOnPlayerMessage.ReleaseGently();
|
||||||
mOnPlayerHealth.Release();
|
mOnPlayerHealth.ReleaseGently();
|
||||||
mOnPlayerArmour.Release();
|
mOnPlayerArmour.ReleaseGently();
|
||||||
mOnPlayerWeapon.Release();
|
mOnPlayerWeapon.ReleaseGently();
|
||||||
mOnPlayerMove.Release();
|
mOnPlayerMove.ReleaseGently();
|
||||||
mOnPlayerWasted.Release();
|
mOnPlayerWasted.ReleaseGently();
|
||||||
mOnPlayerKilled.Release();
|
mOnPlayerKilled.ReleaseGently();
|
||||||
mOnPlayerTeamKill.Release();
|
mOnPlayerTeamKill.ReleaseGently();
|
||||||
mOnPlayerSpectate.Release();
|
mOnPlayerSpectate.ReleaseGently();
|
||||||
mOnPlayerCrashreport.Release();
|
mOnPlayerCrashreport.ReleaseGently();
|
||||||
mOnPlayerBurning.Release();
|
mOnPlayerBurning.ReleaseGently();
|
||||||
mOnPlayerCrouching.Release();
|
mOnPlayerCrouching.ReleaseGently();
|
||||||
mOnPlayerState.Release();
|
mOnPlayerState.ReleaseGently();
|
||||||
mOnPlayerAction.Release();
|
mOnPlayerAction.ReleaseGently();
|
||||||
mOnStateNone.Release();
|
mOnStateNone.ReleaseGently();
|
||||||
mOnStateNormal.Release();
|
mOnStateNormal.ReleaseGently();
|
||||||
mOnStateShooting.Release();
|
mOnStateShooting.ReleaseGently();
|
||||||
mOnStateDriver.Release();
|
mOnStateDriver.ReleaseGently();
|
||||||
mOnStatePassenger.Release();
|
mOnStatePassenger.ReleaseGently();
|
||||||
mOnStateEnterDriver.Release();
|
mOnStateEnterDriver.ReleaseGently();
|
||||||
mOnStateEnterPassenger.Release();
|
mOnStateEnterPassenger.ReleaseGently();
|
||||||
mOnStateExitVehicle.Release();
|
mOnStateExitVehicle.ReleaseGently();
|
||||||
mOnStateUnspawned.Release();
|
mOnStateUnspawned.ReleaseGently();
|
||||||
mOnActionNone.Release();
|
mOnActionNone.ReleaseGently();
|
||||||
mOnActionNormal.Release();
|
mOnActionNormal.ReleaseGently();
|
||||||
mOnActionAiming.Release();
|
mOnActionAiming.ReleaseGently();
|
||||||
mOnActionShooting.Release();
|
mOnActionShooting.ReleaseGently();
|
||||||
mOnActionJumping.Release();
|
mOnActionJumping.ReleaseGently();
|
||||||
mOnActionLieDown.Release();
|
mOnActionLieDown.ReleaseGently();
|
||||||
mOnActionGettingUp.Release();
|
mOnActionGettingUp.ReleaseGently();
|
||||||
mOnActionJumpVehicle.Release();
|
mOnActionJumpVehicle.ReleaseGently();
|
||||||
mOnActionDriving.Release();
|
mOnActionDriving.ReleaseGently();
|
||||||
mOnActionDying.Release();
|
mOnActionDying.ReleaseGently();
|
||||||
mOnActionWasted.Release();
|
mOnActionWasted.ReleaseGently();
|
||||||
mOnActionEmbarking.Release();
|
mOnActionEmbarking.ReleaseGently();
|
||||||
mOnActionDisembarking.Release();
|
mOnActionDisembarking.ReleaseGently();
|
||||||
mOnVehicleRespawn.Release();
|
mOnVehicleRespawn.ReleaseGently();
|
||||||
mOnVehicleExplode.Release();
|
mOnVehicleExplode.ReleaseGently();
|
||||||
mOnVehicleHealth.Release();
|
mOnVehicleHealth.ReleaseGently();
|
||||||
mOnVehicleMove.Release();
|
mOnVehicleMove.ReleaseGently();
|
||||||
mOnPickupRespawn.Release();
|
mOnPickupRespawn.ReleaseGently();
|
||||||
mOnKeybindKeyPress.Release();
|
mOnKeybindKeyPress.ReleaseGently();
|
||||||
mOnKeybindKeyRelease.Release();
|
mOnKeybindKeyRelease.ReleaseGently();
|
||||||
mOnVehicleEmbarking.Release();
|
mOnVehicleEmbarking.ReleaseGently();
|
||||||
mOnVehicleEmbarked.Release();
|
mOnVehicleEmbarked.ReleaseGently();
|
||||||
mOnVehicleDisembark.Release();
|
mOnVehicleDisembark.ReleaseGently();
|
||||||
mOnPickupClaimed.Release();
|
mOnPickupClaimed.ReleaseGently();
|
||||||
mOnPickupCollected.Release();
|
mOnPickupCollected.ReleaseGently();
|
||||||
mOnObjectShot.Release();
|
mOnObjectShot.ReleaseGently();
|
||||||
mOnObjectBump.Release();
|
mOnObjectBump.ReleaseGently();
|
||||||
mOnCheckpointEntered.Release();
|
mOnCheckpointEntered.ReleaseGently();
|
||||||
mOnCheckpointExited.Release();
|
mOnCheckpointExited.ReleaseGently();
|
||||||
mOnForcefieldEntered.Release();
|
mOnForcefieldEntered.ReleaseGently();
|
||||||
mOnForcefieldExited.Release();
|
mOnForcefieldExited.ReleaseGently();
|
||||||
mOnServerFrame.Release();
|
mOnServerFrame.ReleaseGently();
|
||||||
mOnServerStartup.Release();
|
mOnServerStartup.ReleaseGently();
|
||||||
mOnServerShutdown.Release();
|
mOnServerShutdown.ReleaseGently();
|
||||||
mOnInternalCommand.Release();
|
mOnInternalCommand.ReleaseGently();
|
||||||
mOnLoginAttempt.Release();
|
mOnLoginAttempt.ReleaseGently();
|
||||||
mOnCustomEvent.Release();
|
mOnCustomEvent.ReleaseGently();
|
||||||
mOnWorldOption.Release();
|
mOnWorldOption.ReleaseGently();
|
||||||
mOnWorldToggle.Release();
|
mOnWorldToggle.ReleaseGently();
|
||||||
mOnScriptReload.Release();
|
mOnScriptReload.ReleaseGently();
|
||||||
mOnScriptUnload.Release();
|
mOnScriptUnload.ReleaseGently();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
namespace SqMod {
|
namespace SqMod {
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
extern Core * _Core;
|
extern SQMOD_MANAGEDPTR_TYPE(Core) _Core;
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------------------------------
|
||||||
* ...
|
* ...
|
||||||
@ -471,10 +471,10 @@ public:
|
|||||||
{
|
{
|
||||||
if (!_Core)
|
if (!_Core)
|
||||||
{
|
{
|
||||||
_Core = new Core();
|
_Core = SQMOD_MANAGEDPTR_MAKE(Core, new Core());
|
||||||
}
|
}
|
||||||
|
|
||||||
return _Core;
|
return SQMOD_MANAGEDPTR_GET(_Core);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
@ -59,7 +59,7 @@ enum
|
|||||||
namespace SqMod {
|
namespace SqMod {
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------------------
|
||||||
Logger * _Log = NULL;
|
SQMOD_MANAGEDPTR_TYPE(Logger) _Log = SQMOD_MANAGEDPTR_MAKE(Logger, nullptr);
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------------------------------
|
||||||
* ...
|
* ...
|
||||||
|
@ -23,7 +23,7 @@ enum LogLvl
|
|||||||
};
|
};
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------------------
|
||||||
extern Logger * _Log;
|
extern SQMOD_MANAGEDPTR_TYPE(Logger) _Log;
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
class Logger
|
class Logger
|
||||||
@ -49,10 +49,10 @@ public:
|
|||||||
{
|
{
|
||||||
if (!_Log)
|
if (!_Log)
|
||||||
{
|
{
|
||||||
return _Log = new Logger();
|
return _Log = SQMOD_MANAGEDPTR_MAKE(Logger, new Logger());
|
||||||
}
|
}
|
||||||
|
|
||||||
return _Log;
|
return SQMOD_MANAGEDPTR_GET(_Log);
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------------------
|
||||||
|
113
source/Main.cpp
113
source/Main.cpp
@ -25,20 +25,20 @@ void DestroyComponents()
|
|||||||
// Destroy command component
|
// Destroy command component
|
||||||
if (_Cmd)
|
if (_Cmd)
|
||||||
{
|
{
|
||||||
delete _Cmd;
|
SQMOD_MANAGEDPTR_DEL(CmdManager, _Cmd);
|
||||||
_Cmd = NULL;
|
SQMOD_MANAGEDPTR_MAKE(CmdManager, nullptr);
|
||||||
}
|
}
|
||||||
// Destroy core component
|
// Destroy core component
|
||||||
if (_Core)
|
if (_Core)
|
||||||
{
|
{
|
||||||
delete _Core;
|
SQMOD_MANAGEDPTR_DEL(Core, _Core);
|
||||||
_Core = NULL;
|
SQMOD_MANAGEDPTR_MAKE(Core, nullptr);
|
||||||
}
|
}
|
||||||
// Destroy logger component
|
// Destroy logger component
|
||||||
if (_Log)
|
if (_Log)
|
||||||
{
|
{
|
||||||
delete _Log;
|
SQMOD_MANAGEDPTR_DEL(Logger, _Log);
|
||||||
_Log = NULL;
|
SQMOD_MANAGEDPTR_MAKE(Logger, nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,22 +54,19 @@ SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs * funcs, PluginCallback
|
|||||||
OutputMessage("--------------------------------------------------------------------");
|
OutputMessage("--------------------------------------------------------------------");
|
||||||
puts("");
|
puts("");
|
||||||
|
|
||||||
_Log = Logger::Get();
|
|
||||||
// Verify that core components are working
|
// Verify that core components are working
|
||||||
if (!_Log)
|
if (!Logger::Get())
|
||||||
{
|
{
|
||||||
puts("[SQMOD] Unable to start because the logging class could not be instantiated");
|
puts("[SQMOD] Unable to start because the logging class could not be instantiated");
|
||||||
return SQMOD_FAILURE;
|
return SQMOD_FAILURE;
|
||||||
}
|
}
|
||||||
_Core = Core::Get();
|
if (!Core::Get())
|
||||||
if (!_Core)
|
|
||||||
{
|
{
|
||||||
DestroyComponents();
|
DestroyComponents();
|
||||||
puts("[SQMOD] Unable to start because the central core class could not be instantiated");
|
puts("[SQMOD] Unable to start because the central core class could not be instantiated");
|
||||||
return SQMOD_FAILURE;
|
return SQMOD_FAILURE;
|
||||||
}
|
}
|
||||||
_Cmd = CmdManager::Get();
|
if (!CmdManager::Get())
|
||||||
if (!_Cmd)
|
|
||||||
{
|
{
|
||||||
DestroyComponents();
|
DestroyComponents();
|
||||||
puts("[SQMOD] Unable to start because the command class could not be instantiated");
|
puts("[SQMOD] Unable to start because the command class could not be instantiated");
|
||||||
@ -594,7 +591,7 @@ static void VC_PlayerState(int player, int previous, int current)
|
|||||||
case SQMOD_PLAYER_STATE_UNSPAWNED:
|
case SQMOD_PLAYER_STATE_UNSPAWNED:
|
||||||
_Core->EmitStateUnspawned(player, previous);
|
_Core->EmitStateUnspawned(player, previous);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SQMOD_CATCH_EVENT_EXCEPTION(PlayerState)
|
SQMOD_CATCH_EVENT_EXCEPTION(PlayerState)
|
||||||
}
|
}
|
||||||
@ -775,49 +772,49 @@ void BindCallbacks()
|
|||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
void UnbindCallbacks()
|
void UnbindCallbacks()
|
||||||
{
|
{
|
||||||
_Clbk->OnInitServer = NULL;
|
_Clbk->OnInitServer = nullptr;
|
||||||
_Clbk->OnShutdownServer = NULL;
|
_Clbk->OnShutdownServer = nullptr;
|
||||||
_Clbk->OnFrame = NULL;
|
_Clbk->OnFrame = nullptr;
|
||||||
_Clbk->OnPlayerConnect = NULL;
|
_Clbk->OnPlayerConnect = nullptr;
|
||||||
_Clbk->OnPlayerDisconnect = NULL;
|
_Clbk->OnPlayerDisconnect = nullptr;
|
||||||
_Clbk->OnPlayerBeginTyping = NULL;
|
_Clbk->OnPlayerBeginTyping = nullptr;
|
||||||
_Clbk->OnPlayerEndTyping = NULL;
|
_Clbk->OnPlayerEndTyping = nullptr;
|
||||||
_Clbk->OnPlayerRequestClass = NULL;
|
_Clbk->OnPlayerRequestClass = nullptr;
|
||||||
_Clbk->OnPlayerRequestSpawn = NULL;
|
_Clbk->OnPlayerRequestSpawn = nullptr;
|
||||||
_Clbk->OnPlayerSpawn = NULL;
|
_Clbk->OnPlayerSpawn = nullptr;
|
||||||
_Clbk->OnPlayerDeath = NULL;
|
_Clbk->OnPlayerDeath = nullptr;
|
||||||
_Clbk->OnPlayerUpdate = NULL;
|
_Clbk->OnPlayerUpdate = nullptr;
|
||||||
_Clbk->OnPlayerRequestEnter = NULL;
|
_Clbk->OnPlayerRequestEnter = nullptr;
|
||||||
_Clbk->OnPlayerEnterVehicle = NULL;
|
_Clbk->OnPlayerEnterVehicle = nullptr;
|
||||||
_Clbk->OnPlayerExitVehicle = NULL;
|
_Clbk->OnPlayerExitVehicle = nullptr;
|
||||||
_Clbk->OnPickupClaimPicked = NULL;
|
_Clbk->OnPickupClaimPicked = nullptr;
|
||||||
_Clbk->OnPickupPickedUp = NULL;
|
_Clbk->OnPickupPickedUp = nullptr;
|
||||||
_Clbk->OnPickupRespawn = NULL;
|
_Clbk->OnPickupRespawn = nullptr;
|
||||||
_Clbk->OnVehicleUpdate = NULL;
|
_Clbk->OnVehicleUpdate = nullptr;
|
||||||
_Clbk->OnVehicleExplode = NULL;
|
_Clbk->OnVehicleExplode = nullptr;
|
||||||
_Clbk->OnVehicleRespawn = NULL;
|
_Clbk->OnVehicleRespawn = nullptr;
|
||||||
_Clbk->OnObjectShot = NULL;
|
_Clbk->OnObjectShot = nullptr;
|
||||||
_Clbk->OnObjectBump = NULL;
|
_Clbk->OnObjectBump = nullptr;
|
||||||
_Clbk->OnPublicMessage = NULL;
|
_Clbk->OnPublicMessage = nullptr;
|
||||||
_Clbk->OnCommandMessage = NULL;
|
_Clbk->OnCommandMessage = nullptr;
|
||||||
_Clbk->OnPrivateMessage = NULL;
|
_Clbk->OnPrivateMessage = nullptr;
|
||||||
_Clbk->OnInternalCommand = NULL;
|
_Clbk->OnInternalCommand = nullptr;
|
||||||
_Clbk->OnLoginAttempt = NULL;
|
_Clbk->OnLoginAttempt = nullptr;
|
||||||
_Clbk->OnEntityPoolChange = NULL;
|
_Clbk->OnEntityPoolChange = nullptr;
|
||||||
_Clbk->OnKeyBindDown = NULL;
|
_Clbk->OnKeyBindDown = nullptr;
|
||||||
_Clbk->OnKeyBindUp = NULL;
|
_Clbk->OnKeyBindUp = nullptr;
|
||||||
_Clbk->OnPlayerAwayChange = NULL;
|
_Clbk->OnPlayerAwayChange = nullptr;
|
||||||
_Clbk->OnPlayerSpectate = NULL;
|
_Clbk->OnPlayerSpectate = nullptr;
|
||||||
_Clbk->OnPlayerCrashReport = NULL;
|
_Clbk->OnPlayerCrashReport = nullptr;
|
||||||
_Clbk->OnServerPerformanceReport = NULL;
|
_Clbk->OnServerPerformanceReport = nullptr;
|
||||||
_Clbk->OnPlayerNameChange = NULL;
|
_Clbk->OnPlayerNameChange = nullptr;
|
||||||
_Clbk->OnPlayerStateChange = NULL;
|
_Clbk->OnPlayerStateChange = nullptr;
|
||||||
_Clbk->OnPlayerActionChange = NULL;
|
_Clbk->OnPlayerActionChange = nullptr;
|
||||||
_Clbk->OnPlayerOnFireChange = NULL;
|
_Clbk->OnPlayerOnFireChange = nullptr;
|
||||||
_Clbk->OnPlayerCrouchChange = NULL;
|
_Clbk->OnPlayerCrouchChange = nullptr;
|
||||||
_Clbk->OnPlayerGameKeysChange = NULL;
|
_Clbk->OnPlayerGameKeysChange = nullptr;
|
||||||
_Clbk->OnCheckpointEntered = NULL;
|
_Clbk->OnCheckpointEntered = nullptr;
|
||||||
_Clbk->OnCheckpointExited = NULL;
|
_Clbk->OnCheckpointExited = nullptr;
|
||||||
_Clbk->OnSphereEntered = NULL;
|
_Clbk->OnSphereEntered = nullptr;
|
||||||
_Clbk->OnSphereExited = NULL;
|
_Clbk->OnSphereExited = nullptr;
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,8 @@
|
|||||||
#include <sqconfig.h>
|
#include <sqconfig.h>
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
#include <stddef.h>
|
#include <cstddef>
|
||||||
|
#include <cassert>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------------------------------
|
||||||
@ -269,6 +270,143 @@ typedef LongInt< Uint64 > ULongInt;
|
|||||||
*/
|
*/
|
||||||
typedef std::basic_string< SQChar > String;
|
typedef std::basic_string< SQChar > String;
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------------------------------
|
||||||
|
* A simple managed pointer used to identify if components are still used after shutdown.
|
||||||
|
*/
|
||||||
|
template < typename T > class ManagedPtr
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
|
||||||
|
T * m_Ptr;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Base constructor.
|
||||||
|
*/
|
||||||
|
ManagedPtr(T * ptr)
|
||||||
|
: m_Ptr(ptr)
|
||||||
|
{
|
||||||
|
/* ... */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Copy constructor. (disabled)
|
||||||
|
*/
|
||||||
|
ManagedPtr(const ManagedPtr & o) = delete;
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Move constructor. (disabled)
|
||||||
|
*/
|
||||||
|
ManagedPtr(ManagedPtr && o)
|
||||||
|
: m_Ptr(o.m_Ptr)
|
||||||
|
{
|
||||||
|
o.m_Ptr = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Destructor.
|
||||||
|
*/
|
||||||
|
~ManagedPtr()
|
||||||
|
{
|
||||||
|
if (m_Ptr)
|
||||||
|
{
|
||||||
|
delete m_Ptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Copy assignment operator. (disabled)
|
||||||
|
*/
|
||||||
|
ManagedPtr & operator = (const ManagedPtr & o) = delete;
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Move assignment operator. (disabled)
|
||||||
|
*/
|
||||||
|
ManagedPtr & operator = (ManagedPtr && o)
|
||||||
|
{
|
||||||
|
if (m_Ptr != o.m_Ptr)
|
||||||
|
{
|
||||||
|
if (m_Ptr)
|
||||||
|
{
|
||||||
|
delete m_Ptr;
|
||||||
|
}
|
||||||
|
m_Ptr = o.m_Ptr;
|
||||||
|
o.m_Ptr = nullptr;
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Implicit conversion to boolean for use in boolean operations.
|
||||||
|
*/
|
||||||
|
operator bool () const
|
||||||
|
{
|
||||||
|
return m_Ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Implicit conversion to the managed pointer type.
|
||||||
|
*/
|
||||||
|
operator T * () const
|
||||||
|
{
|
||||||
|
return m_Ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Implicit conversion to the managed pointer type.
|
||||||
|
*/
|
||||||
|
operator const T * () const
|
||||||
|
{
|
||||||
|
return m_Ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Member operator for dereferencing the managed pointer.
|
||||||
|
*/
|
||||||
|
T * operator -> () const
|
||||||
|
{
|
||||||
|
assert(m_Ptr != nullptr);
|
||||||
|
return m_Ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Indirection operator for obtaining a reference of the managed pointer.
|
||||||
|
*/
|
||||||
|
T & operator * () const
|
||||||
|
{
|
||||||
|
assert(m_Ptr != nullptr);
|
||||||
|
return *m_Ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Retrieve the managed pointer in it's raw form.
|
||||||
|
*/
|
||||||
|
T * Get() const
|
||||||
|
{
|
||||||
|
return m_Ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#define SQMOD_MANAGEDPTR_TYPE(t) ManagedPtr< t >
|
||||||
|
#define SQMOD_MANAGEDPTR_REF(t) ManagedPtr< t > &
|
||||||
|
#define SQMOD_MANAGEDPTR_MAKE(t, p) ManagedPtr< t >(p)
|
||||||
|
#define SQMOD_MANAGEDPTR_DEL(t, p) p = ManagedPtr< t >(nullptr)
|
||||||
|
#define SQMOD_MANAGEDPTR_GET(p) p.Get();
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#define SQMOD_MANAGEDPTR_TYPE(t) t *
|
||||||
|
#define SQMOD_MANAGEDPTR_REF(t) t *
|
||||||
|
#define SQMOD_MANAGEDPTR_MAKE(t, p) p
|
||||||
|
#define SQMOD_MANAGEDPTR_DEL(t, p) delete p
|
||||||
|
#define SQMOD_MANAGEDPTR_GET(p) p
|
||||||
|
|
||||||
|
#endif // _DEBUG
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------------------------------
|
||||||
* FORWARD DECLARATIONS
|
* FORWARD DECLARATIONS
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user