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

Don't destroy entity instances from the server at server shutdown.

This commit is contained in:
Sandu Liviu Catalin 2016-07-16 17:52:55 +03:00
parent 0599b57087
commit 3fab6d931f
3 changed files with 41 additions and 41 deletions

View File

@ -100,12 +100,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Default constructor.
*/
ContainerCleaner(T & container, EntityType type)
ContainerCleaner(T & container, EntityType type, bool shutdown)
: m_Type(type)
{
for (auto & ent : container)
{
ent.Destroy();
ent.Destroy(shutdown);
}
}
@ -150,7 +150,7 @@ Core::~Core()
{
if (m_VM)
{
Terminate();
Terminate(true);
}
}
@ -436,7 +436,7 @@ bool Core::Execute()
}
// ------------------------------------------------------------------------------------------------
void Core::Terminate()
void Core::Terminate(bool shutdown)
{
if (m_VM)
{
@ -446,13 +446,13 @@ void Core::Terminate()
}
LogDbg("Clearing the entity containers");
// Release all entity resources by clearing the containers
const ContainerCleaner< Players > cc_players(m_Players, ENT_PLAYER);
const ContainerCleaner< Vehicles > cc_vehicles(m_Vehicles, ENT_VEHICLE);
const ContainerCleaner< Objects > cc_objects(m_Objects, ENT_OBJECT);
const ContainerCleaner< Pickups > cc_pickups(m_Pickups, ENT_PICKUP);
const ContainerCleaner< Checkpoints > cc_checkpoints(m_Checkpoints, ENT_CHECKPOINT);
const ContainerCleaner< Blips > cc_blips(m_Blips, ENT_BLIP);
const ContainerCleaner< Keybinds > cc_keybinds(m_Keybinds, ENT_KEYBIND);
const ContainerCleaner< Players > cc_players(m_Players, ENT_PLAYER, shutdown);
const ContainerCleaner< Vehicles > cc_vehicles(m_Vehicles, ENT_VEHICLE, shutdown);
const ContainerCleaner< Objects > cc_objects(m_Objects, ENT_OBJECT, shutdown);
const ContainerCleaner< Pickups > cc_pickups(m_Pickups, ENT_PICKUP, shutdown);
const ContainerCleaner< Checkpoints > cc_checkpoints(m_Checkpoints, ENT_CHECKPOINT, shutdown);
const ContainerCleaner< Blips > cc_blips(m_Blips, ENT_BLIP, shutdown);
const ContainerCleaner< Keybinds > cc_keybinds(m_Keybinds, ENT_KEYBIND, shutdown);
LogDbg("Terminating routines an commands");
// Release all resources from routines
TerminateRoutines();
@ -509,7 +509,7 @@ bool Core::Reload()
return false; // Request denied!
}
// Terminate the current VM and release resources
Terminate();
Terminate(false);
// Reset the reload header after termination
m_ReloadHeader = -1;
// Attempt to initialize the central core and load resources
@ -724,7 +724,7 @@ void Core::BindEvent(Int32 id, Object & env, Function & func)
}
// ------------------------------------------------------------------------------------------------
void Core::BlipInst::Destroy()
void Core::BlipInst::Destroy(bool shutdown)
{
// Should we notify that this entity is being cleaned up?
if (VALID_ENTITY(mID))
@ -739,8 +739,8 @@ void Core::BlipInst::Destroy()
// Release user data to avoid dangling or circular references
mInst->m_Data.Release();
}
// Are we supposed to clean up this entity?
if (VALID_ENTITY(mID) && (mFlags & ENF_OWNED))
// Are we supposed to clean up this entity? (only at reload)
if (!shutdown && 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));
@ -754,7 +754,7 @@ void Core::BlipInst::Destroy()
}
// ------------------------------------------------------------------------------------------------
void Core::CheckpointInst::Destroy()
void Core::CheckpointInst::Destroy(bool shutdown)
{
// Should we notify that this entity is being cleaned up?
if (VALID_ENTITY(mID))
@ -769,8 +769,8 @@ void Core::CheckpointInst::Destroy()
// Release user data to avoid dangling or circular references
mInst->m_Data.Release();
}
// Are we supposed to clean up this entity?
if (VALID_ENTITY(mID) && (mFlags & ENF_OWNED))
// Are we supposed to clean up this entity? (only at reload)
if (!shutdown && 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));
@ -784,7 +784,7 @@ void Core::CheckpointInst::Destroy()
}
// ------------------------------------------------------------------------------------------------
void Core::KeybindInst::Destroy()
void Core::KeybindInst::Destroy(bool shutdown)
{
// Should we notify that this entity is being cleaned up?
if (VALID_ENTITY(mID))
@ -799,8 +799,8 @@ void Core::KeybindInst::Destroy()
// Release user data to avoid dangling or circular references
mInst->m_Data.Release();
}
// Are we supposed to clean up this entity?
if (VALID_ENTITY(mID) && (mFlags & ENF_OWNED))
// Are we supposed to clean up this entity? (only at reload)
if (!shutdown && 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));
@ -814,7 +814,7 @@ void Core::KeybindInst::Destroy()
}
// ------------------------------------------------------------------------------------------------
void Core::ObjectInst::Destroy()
void Core::ObjectInst::Destroy(bool shutdown)
{
// Should we notify that this entity is being cleaned up?
if (VALID_ENTITY(mID))
@ -829,8 +829,8 @@ void Core::ObjectInst::Destroy()
// Release user data to avoid dangling or circular references
mInst->m_Data.Release();
}
// Are we supposed to clean up this entity?
if (VALID_ENTITY(mID) && (mFlags & ENF_OWNED))
// Are we supposed to clean up this entity? (only at reload)
if (!shutdown && 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));
@ -844,7 +844,7 @@ void Core::ObjectInst::Destroy()
}
// ------------------------------------------------------------------------------------------------
void Core::PickupInst::Destroy()
void Core::PickupInst::Destroy(bool shutdown)
{
// Should we notify that this entity is being cleaned up?
if (VALID_ENTITY(mID))
@ -859,8 +859,8 @@ void Core::PickupInst::Destroy()
// Release user data to avoid dangling or circular references
mInst->m_Data.Release();
}
// Are we supposed to clean up this entity?
if (VALID_ENTITY(mID) && (mFlags & ENF_OWNED))
// Are we supposed to clean up this entity? (only at reload)
if (!shutdown && 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));
@ -874,7 +874,7 @@ void Core::PickupInst::Destroy()
}
// ------------------------------------------------------------------------------------------------
void Core::PlayerInst::Destroy()
void Core::PlayerInst::Destroy(bool /*shutdown*/)
{
// Should we notify that this entity is being cleaned up?
if (VALID_ENTITY(mID))
@ -898,7 +898,7 @@ void Core::PlayerInst::Destroy()
}
// ------------------------------------------------------------------------------------------------
void Core::VehicleInst::Destroy()
void Core::VehicleInst::Destroy(bool shutdown)
{
// Should we notify that this entity is being cleaned up?
if (VALID_ENTITY(mID))
@ -913,8 +913,8 @@ void Core::VehicleInst::Destroy()
// Release user data to avoid dangling or circular references
mInst->m_Data.Release();
}
// Are we supposed to clean up this entity?
if (VALID_ENTITY(mID) && (mFlags & ENF_OWNED))
// Are we supposed to clean up this entity? (only at reload)
if (!shutdown && 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));

View File

@ -101,7 +101,7 @@ protected:
/* ----------------------------------------------------------------------------------------
* Destroy the entity instance from the server, if necessary.
*/
void Destroy();
void Destroy(bool shutdown = false);
// ----------------------------------------------------------------------------------------
Int32 mID; // The unique number that identifies this entity on the server.
@ -152,7 +152,7 @@ protected:
/* ----------------------------------------------------------------------------------------
* Destroy the entity instance from the server, if necessary.
*/
void Destroy();
void Destroy(bool shutdown = false);
// ----------------------------------------------------------------------------------------
Int32 mID; // The unique number that identifies this entity on the server.
@ -196,7 +196,7 @@ protected:
/* ----------------------------------------------------------------------------------------
* Destroy the entity instance from the server, if necessary.
*/
void Destroy();
void Destroy(bool shutdown = false);
// ----------------------------------------------------------------------------------------
Int32 mID; // The unique number that identifies this entity on the server.
@ -246,7 +246,7 @@ protected:
/* ----------------------------------------------------------------------------------------
* Destroy the entity instance from the server, if necessary.
*/
void Destroy();
void Destroy(bool shutdown = false);
// ----------------------------------------------------------------------------------------
Int32 mID; // The unique number that identifies this entity on the server.
@ -290,7 +290,7 @@ protected:
/* ----------------------------------------------------------------------------------------
* Destroy the entity instance from the server, if necessary.
*/
void Destroy();
void Destroy(bool shutdown = false);
// ----------------------------------------------------------------------------------------
Int32 mID; // The unique number that identifies this entity on the server.
@ -335,7 +335,7 @@ protected:
/* ----------------------------------------------------------------------------------------
* Destroy the entity instance from the server, if necessary.
*/
void Destroy();
void Destroy(bool shutdown = false);
// ----------------------------------------------------------------------------------------
Int32 mID; // The unique number that identifies this entity on the server.
@ -455,7 +455,7 @@ protected:
/* ----------------------------------------------------------------------------------------
* Destroy the entity instance from the server, if necessary.
*/
void Destroy();
void Destroy(bool shutdown = false);
// ----------------------------------------------------------------------------------------
Int32 mID; // The unique number that identifies this entity on the server.
@ -564,7 +564,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Terminate the plug-in core.
*/
void Terminate();
void Terminate(bool shutdown = false);
/* --------------------------------------------------------------------------------------------
* Reload the plug-in core.

View File

@ -132,7 +132,7 @@ static void OnServerShutdown(void)
// Tell the script that the server is shutting down
Core::Get().EmitServerShutdown();
// Deallocate and release everything obtained at startup
Core::Get().Terminate();
Core::Get().Terminate(true);
}
SQMOD_CATCH_EVENT_EXCEPTION(OnServerShutdown)
// See if a reload was requested (quite useless here but why not)
@ -936,7 +936,7 @@ SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs * funcs, PluginCallback
{
LogFtl("Unable to initialize the plug-in central core");
// Attempt to terminate
Core::Get().Terminate();
Core::Get().Terminate(false);
// Stop here!
return SQMOD_FAILURE;
}