diff --git a/source/Core.cpp b/source/Core.cpp index 1fe8fb5b..e929eb4b 100644 --- a/source/Core.cpp +++ b/source/Core.cpp @@ -734,279 +734,163 @@ void Core::CompilerErrorHandler(HSQUIRRELVM vm, const SQChar * desc, const SQCha } // ------------------------------------------------------------------------------------------------ -Reference< CBlip > Core::CreateBlip(SQInt32 index, SQInt32 world, const Vector3 & pos, SQInt32 scale, \ - const Color4 & color, SQInt32 sprite, SQInt32 header, SqObj & payload) noexcept +Reference< CBlip > Core::NewBlip(SQInt32 index, SQInt32 world, SQFloat x, SQFloat y, SQFloat z, + SQInt32 scale, SQUint32 color, SQInt32 sprid, + SQInt32 header, SqObj & payload) noexcept { - // Attempt to create an instance on the server and obtain it's identifier - SQInt32 id = _Func->CreateCoordBlip(index, world, pos.x, pos.y, pos.z, scale, color.GetRGBA(), sprite); - // Attempt to activate the instance in the plugin at the received identifier - if (EntMan< CBlip >::Activate(id, true, world, scale, sprite, pos, color)) - { - // Trigger the specific event - OnBlipCreated(id, header, payload); - } - else - { - LogErr("Unable to create a new instance"); - } - // Return the obtained reference as is - return Reference< CBlip >(id); + // Attempt to create the entity and return a reference to it + return Reference< CBlip >(EntMan< CBlip >::Create(header, payload, true, + index, world, x, y, z, scale, color, sprid)); } // ------------------------------------------------------------------------------------------------ -Reference< CCheckpoint > Core::CreateCheckpoint(const Reference< CPlayer > & player, SQInt32 world, const Vector3 & pos, \ - const Color4 & color, SQFloat radius, SQInt32 header, SqObj & payload) noexcept +Reference< CCheckpoint > Core::NewCheckpoint(SQInt32 player, SQInt32 world, SQFloat x, SQFloat y, SQFloat z, + SQUint32 r, SQUint32 g, SQUint32 b, SQUint32 a, SQFloat radius, + SQInt32 header, SqObj & payload) noexcept { // See if the specified player reference is valid - if (!player) + if (!Reference< CPlayer >::Verify(player)) { - LogWrn("Attempting to create a instance on an invalid player: %d", _SCI32(player)); - } - // Attempt to create an instance on the server and obtain it's identifier - SQInt32 id = _Func->CreateCheckpoint(_SCI32(player), world, pos.x, pos.y, pos.z, color.r, color.g, color.b, color.a, radius); - // Attempt to activate the instance in the plugin at the received identifier - if (EntMan< CCheckpoint >::Activate(id, true)) - { - // Trigger the specific event - OnCheckpointCreated(id, header, payload); + LogWrn("Attempting to on an invalid player: %d", player); } + // Attempt to create the entity and return a reference to it else { - LogErr("Unable to create a new instance"); + return Reference< CCheckpoint >(EntMan< CCheckpoint >::Create(header, payload, true, + player, world, x, y, z, r, g, b, a, radius)); } - // Return the obtained reference as is - return Reference< CCheckpoint >(id); + // Return an invalid reference + return Reference< CCheckpoint >(); } // ------------------------------------------------------------------------------------------------ -Reference< CKeybind > Core::CreateKeybind(SQInt32 slot, bool release, SQInt32 primary, SQInt32 secondary, \ - SQInt32 alternative, SQInt32 header, SqObj & payload) noexcept +Reference< CKeybind > Core::NewKeybind(SQInt32 slot, bool release, + SQInt32 primary, SQInt32 secondary, SQInt32 alternative, + SQInt32 header, SqObj & payload) noexcept { - // Attempt to create an instance on the server and obtain it's identifier - SQInt32 id = _Func->RegisterKeyBind(slot, release, primary, secondary, alternative); - // Attempt to activate the instance in the plugin at the received identifier - if (EntMan< CKeybind >::Activate(id, true, primary, secondary, alternative, release)) - { - // Trigger the specific event - OnKeybindCreated(id, header, payload); - } - else - { - LogErr("Unable to create a new instance"); - } - // Return the obtained reference as is - return Reference< CKeybind >(id); + // Attempt to create the entity and return a reference to it + return Reference< CKeybind >(EntMan< CKeybind >::Create(header, payload, true, + slot, release, primary, secondary, alternative)); } // ------------------------------------------------------------------------------------------------ -Reference< CObject > Core::CreateObject(const CModel & model, SQInt32 world, const Vector3 & pos, SQInt32 alpha, \ - SQInt32 header, SqObj & payload) noexcept +Reference< CObject > Core::NewObject(SQInt32 model, SQInt32 world, SQFloat x, SQFloat y, SQFloat z, + SQInt32 alpha, + SQInt32 header, SqObj & payload) noexcept { // See if the specified model is valid - if (!model) + if (!CModel::Valid(model)) { - LogWrn("Attempting to create an instance with an invalid model: %d", _SCI32(model)); - } - // Attempt to create an instance on the server and obtain it's identifier - SQInt32 id = _Func->CreateObject(_SCI32(model), world, pos.x, pos.y, pos.z, alpha); - // Attempt to activate the instance in the plugin at the received identifier - if (EntMan< CObject >::Activate(id, true)) - { - // Trigger the specific event - OnObjectCreated(id, header, payload); + LogWrn("Attempting to using an invalid model: %d", model); } + // Attempt to create the entity and return a reference to it else { - LogErr("Unable to create a new instance"); + return Reference< CObject >(EntMan< CObject >::Create(header, payload, true, + model, world, x, y, z, alpha)); } - // Return the obtained reference as is - return Reference< CObject >(id); + // Return an invalid reference + return Reference< CObject >(); } // ------------------------------------------------------------------------------------------------ -Reference< CPickup > Core::CreatePickup(const CModel & model, SQInt32 world, SQInt32 quantity, const Vector3 & pos, \ - SQInt32 alpha, bool automatic, SQInt32 header, SqObj & payload) noexcept +Reference< CPickup > Core::NewPickup(SQInt32 model, SQInt32 world, SQInt32 quantity, + SQFloat x, SQFloat y, SQFloat z, SQInt32 alpha, bool automatic, + SQInt32 header, SqObj & payload) noexcept { // See if the specified model is valid - if (!model) + if (!CModel::Valid(model)) { - LogWrn("Attempting to create a instance with an invalid model: %d", _SCI32(model)); - } - // Attempt to create an instance on the server and obtain it's identifier - SQInt32 id = _Func->CreatePickup(_SCI32(model), world, quantity, pos.x, pos.y, pos.z, alpha, automatic); - // Attempt to activate the instance in the plugin at the received identifier - if (EntMan< CPickup >::Activate(id, true)) - { - // Trigger the specific event - OnPickupCreated(id, header, payload); + LogWrn("Attempting to using an invalid model: %d", model); } + // Attempt to create the entity and return a reference to it else { - LogErr("Unable to create a new instance"); + return Reference< CPickup >(EntMan< CPickup >::Create(header, payload, true, + model, world, quantity, x, y, z, alpha, automatic)); } - // Return the obtained reference as is - return Reference< CPickup >(id); + // Return an invalid reference + return Reference< CPickup >(); } // ------------------------------------------------------------------------------------------------ -Reference< CSphere > Core::CreateSphere(const Reference< CPlayer > & player, SQInt32 world, const Vector3 & pos, \ - const Color3 & color, SQFloat radius, SQInt32 header, SqObj & payload) noexcept +Reference< CSphere > Core::NewSphere(SQInt32 player, SQInt32 world, SQFloat x, SQFloat y, SQFloat z, + SQUint32 r, SQUint32 g, SQUint32 b, SQFloat radius, + SQInt32 header, SqObj & payload) noexcept { // See if the specified player reference is valid - if (!player) + if (!Reference< CPlayer >::Verify(player)) { - LogWrn("Attempting to create a instance on an invalid player: %d", _SCI32(player)); - } - // Attempt to create an instance on the server and obtain it's identifier - SQInt32 id = _Func->CreateSphere(_SCI32(player), world, pos.x, pos.y, pos.z, color.r, color.g, color.b, radius); - // Attempt to activate the instance in the plugin at the received identifier - if (EntMan< CSphere >::Activate(id, true)) - { - // Trigger the specific event - OnSphereCreated(id, header, payload); + LogWrn("Attempting to on an invalid player: %d", player); } + // Attempt to create the entity and return a reference to it else { - LogErr("Unable to create a new instance"); + return Reference< CSphere >(EntMan< CSphere >::Create(header, payload, true, + player, world, x, y, z, r, g, b, radius)); } - // Return the obtained reference as is - return Reference< CSphere >(id); + // Return an invalid reference + return Reference< CSphere >(); } // ------------------------------------------------------------------------------------------------ -Reference< CSprite > Core::CreateSprite(SQInt32 index, const String & file, const Vector2i & pos, const Vector2i & rot, \ - SQFloat angle, SQInt32 alpha, bool rel, SQInt32 header, SqObj & payload) noexcept +Reference< CSprite > Core::NewSprite(SQInt32 index, const SQChar * file, SQInt32 xp, SQInt32 yp, + SQInt32 xr, SQInt32 yr, SQFloat angle, SQInt32 alpha, bool rel, + SQInt32 header, SqObj & payload) noexcept { // See if the specified file path is valid - if (file.empty()) + if (!file) { - LogWrn("Attempting to create a instance with an empty path: %d", file.size()); - } - // Attempt to create an instance on the server and obtain it's identifier - SQInt32 id = _Func->CreateSprite(index, file.c_str(), pos.x, pos.y, rot.x, rot.y, angle, alpha, rel); - // Attempt to activate the instance in the plugin at the received identifier - if (EntMan< CSprite >::Activate(id, true, file)) - { - // Trigger the specific event - OnSpriteCreated(id, header, payload); + LogWrn("Attempting to with an empty path: null"); } + // Attempt to create the entity and return a reference to it else { - LogErr("Unable to create a new instance"); + return Reference< CSprite >(EntMan< CSprite >::Create(header, payload, true, + index, file, xp, yp, xr, yr, angle, alpha, rel)); } - // Return the obtained reference as is - return Reference< CSprite >(id); + // Return an invalid reference + return Reference< CSprite >(); } // ------------------------------------------------------------------------------------------------ -Reference< CTextdraw > Core::CreateTextdraw(SQInt32 index, const String & text, const Vector2i & pos, \ - const Color4 & color, bool rel, SQInt32 header, SqObj & payload) noexcept +Reference< CTextdraw > Core::NewTextdraw(SQInt32 index, const SQChar * text, SQInt32 xp, SQInt32 yp, + SQUint32 color, bool rel, + SQInt32 header, SqObj & payload) noexcept { // See if the specified text is valid - if (text.empty()) + if (!text) { - LogWrn("Attempting to create a instance with an empty text: %d", text.size()); - } - // Attempt to create an instance on the server and obtain it's identifier - SQInt32 id = _Func->CreateTextdraw(index, text.c_str(), pos.x, pos.y, color.GetRGBA(), rel); - // Attempt to activate the instance in the plugin at the received identifier - if (EntMan< CTextdraw >::Activate(id, true, text)) - { - // Trigger the specific event - OnTextdrawCreated(id, header, payload); + LogWrn("Attempting to using an empty text: null"); } + // Attempt to create the entity and return a reference to it else { - LogErr("Unable to create a new instance"); + return Reference< CTextdraw >(EntMan< CTextdraw >::Create(header, payload, true, + index, text, xp, yp, color, rel)); } - // Return the obtained reference as is - return Reference< CTextdraw >(id); + // Return an invalid reference + return Reference< CTextdraw >(); } // ------------------------------------------------------------------------------------------------ -Reference< CVehicle > Core::CreateVehicle(const CAutomobile & model, SQInt32 world, const Vector3 & pos, \ - SQFloat angle, SQInt32 primary, SQInt32 secondary, SQInt32 header, SqObj & payload) noexcept +Reference< CVehicle > Core::NewVehicle(SQInt32 model, SQInt32 world, SQFloat x, SQFloat y, SQFloat z, + SQFloat angle, SQInt32 primary, SQInt32 secondary, + SQInt32 header, SqObj & payload) noexcept { // See if the specified model is valid - if (!model) + if (!CAutomobile::Valid(model)) { - LogWrn("Attempting to create an instance with an invalid model: %d", _SCI32(model)); - } - // Attempt to create an instance on the server and obtain it's identifier - SQInt32 id = _Func->CreateVehicle(_SCI32(model), world, pos.x, pos.y, pos.z, angle, primary, secondary); - // Attempt to activate the instance in the plugin at the received identifier - if (EntMan< CVehicle >::Activate(id, true)) - { - // Trigger the specific event - OnVehicleCreated(id, header, payload); + LogWrn("Attempting to using an invalid model: %d", model); } + // Attempt to create the entity and return a reference to it else { - LogErr("Unable to create a new instance"); + return Reference< CVehicle >(EntMan< CVehicle >::Create(header, payload, true, + model, world, x, y, z, angle, primary, secondary)); } - // Return the obtained reference as is - return Reference< CVehicle >(id); -} - -// ------------------------------------------------------------------------------------------------ -bool Core::DestroyBlip(SQInt32 id, SQInt32 header, SqObj & payload) noexcept -{ - - return true; -} - -// ------------------------------------------------------------------------------------------------ -bool Core::DestroyCheckpoint(SQInt32 id, SQInt32 header, SqObj & payload) noexcept -{ - return true; -} - -// ------------------------------------------------------------------------------------------------ -bool Core::DestroyKeybind(SQInt32 id, SQInt32 header, SqObj & payload) noexcept -{ - return true; -} - -// ------------------------------------------------------------------------------------------------ -bool Core::DestroyObject(SQInt32 id, SQInt32 header, SqObj & payload) noexcept -{ - return true; -} - -// ------------------------------------------------------------------------------------------------ -bool Core::DestroyPickup(SQInt32 id, SQInt32 header, SqObj & payload) noexcept -{ - return true; -} - -// ------------------------------------------------------------------------------------------------ -bool Core::DestroyPlayer(SQInt32 id, SQInt32 header, SqObj & payload) noexcept -{ - return true; -} - -// ------------------------------------------------------------------------------------------------ -bool Core::DestroySphere(SQInt32 id, SQInt32 header, SqObj & payload) noexcept -{ - return true; -} - -// ------------------------------------------------------------------------------------------------ -bool Core::DestroySprite(SQInt32 id, SQInt32 header, SqObj & payload) noexcept -{ - return true; -} - -// ------------------------------------------------------------------------------------------------ -bool Core::DestroyTextdraw(SQInt32 id, SQInt32 header, SqObj & payload) noexcept -{ - return true; -} - -// ------------------------------------------------------------------------------------------------ -bool Core::DestroyVehicle(SQInt32 id, SQInt32 header, SqObj & payload) noexcept -{ - return true; + // Return an invalid reference + return Reference< CVehicle >(); } // ------------------------------------------------------------------------------------------------ @@ -1771,7 +1655,7 @@ void Core::OnEntityPool(SQInt32 type, SQInt32 id, bool deleted) noexcept case SQMOD_ENTITY_POOL_VEHICLE: if (deleted) { - DestroyVehicle(id, SQMOD_DESTROY_POOL, payload); + EntMan< CVehicle >::Deactivate(id, SQMOD_DESTROY_POOL, payload, true); } else if (EntMan< CVehicle >::Activate(id, false)) { @@ -1781,7 +1665,7 @@ void Core::OnEntityPool(SQInt32 type, SQInt32 id, bool deleted) noexcept case SQMOD_ENTITY_POOL_OBJECT: if (deleted) { - DestroyObject(id, SQMOD_DESTROY_POOL, payload); + EntMan< CObject >::Deactivate(id, SQMOD_DESTROY_POOL, payload, true); } else if (EntMan< CObject >::Activate(id, false)) { @@ -1791,7 +1675,7 @@ void Core::OnEntityPool(SQInt32 type, SQInt32 id, bool deleted) noexcept case SQMOD_ENTITY_POOL_PICKUP: if (deleted) { - DestroyPickup(id, SQMOD_DESTROY_POOL, payload); + EntMan< CPickup >::Deactivate(id, SQMOD_DESTROY_POOL, payload, true); } else if (EntMan< CPickup >::Activate(id, false)) { @@ -1804,9 +1688,9 @@ void Core::OnEntityPool(SQInt32 type, SQInt32 id, bool deleted) noexcept case SQMOD_ENTITY_POOL_SPRITE: if (deleted) { - DestroySprite(id, SQMOD_DESTROY_POOL, payload); + EntMan< CSprite >::Deactivate(id, SQMOD_DESTROY_POOL, payload, true); } - else if (EntMan< CSprite >::Activate(id, false, "")) + else if (EntMan< CSprite >::Activate(id, false)) { OnSpriteCreated(id, SQMOD_CREATE_POOL, payload); } @@ -1814,9 +1698,9 @@ void Core::OnEntityPool(SQInt32 type, SQInt32 id, bool deleted) noexcept case SQMOD_ENTITY_POOL_TEXTDRAW: if (deleted) { - DestroyTextdraw(id, SQMOD_DESTROY_POOL, payload); + EntMan< CTextdraw >::Deactivate(id, SQMOD_DESTROY_POOL, payload, true); } - else if (EntMan< CTextdraw >::Activate(id, false, "")) + else if (EntMan< CTextdraw >::Activate(id, false)) { OnTextdrawCreated(id, SQMOD_CREATE_POOL, payload); } @@ -1824,20 +1708,17 @@ void Core::OnEntityPool(SQInt32 type, SQInt32 id, bool deleted) noexcept case SQMOD_ENTITY_POOL_BLIP: if (deleted) { - DestroyBlip(id, SQMOD_DESTROY_POOL, payload); + EntMan< CBlip >::Deactivate(id, SQMOD_DESTROY_POOL, payload, true); } else { - SQInt32 world, scale, sprite; - SQUint32 pcolor; - Vector3 pos; - Color4 color; + SQInt32 world, scale, sprid; + SQUint32 color; + SQFloat x, y, z; // Get the blip information from the server - _Func->GetCoordBlipInfo(id, &world, &pos.x, &pos.y, &pos.z, &scale, &pcolor, &sprite); - // Unpack the retrieved color - color.SetRGBA(pcolor); - - if (EntMan< CBlip >::Activate(id, false, world, scale, sprite, pos, color)) + _Func->GetCoordBlipInfo(id, &world, &x, &y, &z, &scale, &color, &sprid); + // Attempt to activate this instance + if (EntMan< CBlip >::Activate(id, false, SQMOD_UNKNOWN, world, x, y, z, scale, color, sprid)) { OnBlipCreated(id, SQMOD_CREATE_POOL, payload); } diff --git a/source/Core.hpp b/source/Core.hpp index 6ad128e8..9cdc8bff 100644 --- a/source/Core.hpp +++ b/source/Core.hpp @@ -181,103 +181,65 @@ public: /* -------------------------------------------------------------------------------------------- * Creates a new Blip on the server */ - Reference< CBlip > CreateBlip(SQInt32 index, SQInt32 world, const Vector3 & pos, SQInt32 scale, \ - const Color4 & color, SQInt32 sprite, SQInt32 header, SqObj & payload) noexcept; + Reference< CBlip > NewBlip(SQInt32 index, SQInt32 world, SQFloat x, SQFloat y, SQFloat z, + SQInt32 scale, SQUint32 color, SQInt32 sprid, + SQInt32 header, SqObj & payload) noexcept; /* -------------------------------------------------------------------------------------------- * Creates a new Checkpoint on the server */ - Reference< CCheckpoint > CreateCheckpoint(const Reference< CPlayer > & player, SQInt32 world, const Vector3 & pos, \ - const Color4 & color, SQFloat radius, SQInt32 header, SqObj & payload) noexcept; + Reference< CCheckpoint > NewCheckpoint(SQInt32 player, SQInt32 world, SQFloat x, SQFloat y, SQFloat z, + SQUint32 r, SQUint32 g, SQUint32 b, SQUint32 a, SQFloat radius, + SQInt32 header, SqObj & payload) noexcept; /* -------------------------------------------------------------------------------------------- * Creates a new Keybind on the server */ - Reference< CKeybind > CreateKeybind(SQInt32 slot, bool release, SQInt32 primary, SQInt32 secondary, \ - SQInt32 alternative, SQInt32 header, SqObj & payload) noexcept; + Reference< CKeybind > NewKeybind(SQInt32 slot, bool release, + SQInt32 primary, SQInt32 secondary, SQInt32 alternative, + SQInt32 header, SqObj & payload) noexcept; /* -------------------------------------------------------------------------------------------- * Creates a new Object on the server */ - Reference< CObject > CreateObject(const CModel & model, SQInt32 world, const Vector3 & pos, SQInt32 alpha, \ - SQInt32 header, SqObj & payload) noexcept; + Reference< CObject > NewObject(SQInt32 model, SQInt32 world, SQFloat x, SQFloat y, SQFloat z, + SQInt32 alpha, + SQInt32 header, SqObj & payload) noexcept; /* -------------------------------------------------------------------------------------------- * Creates a new Pickup on the server */ - Reference< CPickup > CreatePickup(const CModel & model, SQInt32 world, SQInt32 quantity, const Vector3 & pos, \ - SQInt32 alpha, bool automatic, SQInt32 header, SqObj & payload) noexcept; + Reference< CPickup > NewPickup(SQInt32 model, SQInt32 world, SQInt32 quantity, + SQFloat x, SQFloat y, SQFloat z, SQInt32 alpha, bool automatic, + SQInt32 header, SqObj & payload) noexcept; /* -------------------------------------------------------------------------------------------- * Creates a new Sphere on the server */ - Reference< CSphere > CreateSphere(const Reference< CPlayer > & player, SQInt32 world, const Vector3 & pos, \ - const Color3 & color, SQFloat radius, SQInt32 header, SqObj & payload) noexcept; + Reference< CSphere > NewSphere(SQInt32 player, SQInt32 world, SQFloat x, SQFloat y, SQFloat z, + SQUint32 r, SQUint32 g, SQUint32 b, SQFloat radius, + SQInt32 header, SqObj & payload) noexcept; /* -------------------------------------------------------------------------------------------- * Creates a new Sprite on the server */ - Reference< CSprite > CreateSprite(SQInt32 index, const String & file, const Vector2i & pos, const Vector2i & rot, \ - SQFloat angle, SQInt32 alpha, bool rel, SQInt32 header, SqObj & payload) noexcept; + Reference< CSprite > NewSprite(SQInt32 index, const SQChar * file, SQInt32 xp, SQInt32 yp, + SQInt32 xr, SQInt32 yr, SQFloat angle, SQInt32 alpha, bool rel, + SQInt32 header, SqObj & payload) noexcept; /* -------------------------------------------------------------------------------------------- * Creates a new Textdraw on the server */ - Reference< CTextdraw > CreateTextdraw(SQInt32 index, const String & text, const Vector2i & pos, \ - const Color4 & color, bool rel, SQInt32 header, SqObj & payload) noexcept; + Reference< CTextdraw > NewTextdraw(SQInt32 index, const SQChar * text, SQInt32 xp, SQInt32 yp, + SQUint32 color, bool rel, + SQInt32 header, SqObj & payload) noexcept; /* -------------------------------------------------------------------------------------------- * Creates a new Vehicle on the server */ - Reference< CVehicle > CreateVehicle(const CAutomobile & model, SQInt32 world, const Vector3 & pos, SQFloat angle, \ - SQInt32 primary, SQInt32 secondary, SQInt32 header, SqObj & payload) noexcept; - -public: - - /* -------------------------------------------------------------------------------------------- - * Destroys a Blip created by the server - */ - bool DestroyBlip(SQInt32 id, SQInt32 header, SqObj & payload) noexcept; - - /* -------------------------------------------------------------------------------------------- - * Destroys a Checkpoint created by the server - */ - bool DestroyCheckpoint(SQInt32 id, SQInt32 header, SqObj & payload) noexcept; - - /* -------------------------------------------------------------------------------------------- - * Destroys a Keybind created by the server - */ - bool DestroyKeybind(SQInt32 id, SQInt32 header, SqObj & payload) noexcept; - - /* -------------------------------------------------------------------------------------------- - * Destroys a Object created by the server - */ - bool DestroyObject(SQInt32 id, SQInt32 header, SqObj & payload) noexcept; - - /* -------------------------------------------------------------------------------------------- - * Destroys a Pickup created by the server - */ - bool DestroyPickup(SQInt32 id, SQInt32 header, SqObj & payload) noexcept; - - /* -------------------------------------------------------------------------------------------- - * Destroys a Sphere created by the server - */ - bool DestroySphere(SQInt32 id, SQInt32 header, SqObj & payload) noexcept; - - /* -------------------------------------------------------------------------------------------- - * Destroys a Sprite created by the server - */ - bool DestroySprite(SQInt32 id, SQInt32 header, SqObj & payload) noexcept; - - /* -------------------------------------------------------------------------------------------- - * Destroys a Textdraw created by the server - */ - bool DestroyTextdraw(SQInt32 id, SQInt32 header, SqObj & payload) noexcept; - - /* -------------------------------------------------------------------------------------------- - * Destroys a Vehicle created by the server - */ - bool DestroyVehicle(SQInt32 id, SQInt32 header, SqObj & payload) noexcept; + Reference< CVehicle > NewVehicle(SQInt32 model, SQInt32 world, SQFloat x, SQFloat y, SQFloat z, + SQFloat angle, SQInt32 primary, SQInt32 secondary, + SQInt32 header, SqObj & payload) noexcept; public: diff --git a/source/Entity.cpp b/source/Entity.cpp index c7d9c11b..8c84b306 100644 --- a/source/Entity.cpp +++ b/source/Entity.cpp @@ -5,6 +5,159 @@ // ------------------------------------------------------------------------------------------------ namespace SqMod { +// ------------------------------------------------------------------------------------------------ +EBlipCreated & GBlipCreated() noexcept +{ + return _Core->BlipCreated; +} + +ECheckpointCreated & GCheckpointCreated() noexcept +{ + return _Core->CheckpointCreated; +} + +EKeybindCreated & GKeybindCreated() noexcept +{ + return _Core->KeybindCreated; +} + +EObjectCreated & GObjectCreated() noexcept +{ + return _Core->ObjectCreated; +} + +EPickupCreated & GPickupCreated() noexcept +{ + return _Core->PickupCreated; +} + +EPlayerCreated & GPlayerCreated() noexcept +{ + return _Core->PlayerCreated; +} + +ESphereCreated & GSphereCreated() noexcept +{ + return _Core->SphereCreated; +} + +ESpriteCreated & GSpriteCreated() noexcept +{ + return _Core->SpriteCreated; +} + +ETextdrawCreated & GTextdrawCreated() noexcept +{ + return _Core->TextdrawCreated; +} + +EVehicleCreated & GVehicleCreated() noexcept +{ + return _Core->VehicleCreated; +} + +// ------------------------------------------------------------------------------------------------ +EBlipDestroyed & GBlipDestroyed() noexcept +{ + return _Core->BlipDestroyed; +} + +ECheckpointDestroyed & GCheckpointDestroyed() noexcept +{ + return _Core->CheckpointDestroyed; +} + +EKeybindDestroyed & GKeybindDestroyed() noexcept +{ + return _Core->KeybindDestroyed; +} + +EObjectDestroyed & GObjectDestroyed() noexcept +{ + return _Core->ObjectDestroyed; +} + +EPickupDestroyed & GPickupDestroyed() noexcept +{ + return _Core->PickupDestroyed; +} + +EPlayerDestroyed & GPlayerDestroyed() noexcept +{ + return _Core->PlayerDestroyed; +} + +ESphereDestroyed & GSphereDestroyed() noexcept +{ + return _Core->SphereDestroyed; +} + +ESpriteDestroyed & GSpriteDestroyed() noexcept +{ + return _Core->SpriteDestroyed; +} + +ETextdrawDestroyed & GTextdrawDestroyed() noexcept +{ + return _Core->TextdrawDestroyed; +} + +EVehicleDestroyed & GVehicleDestroyed() noexcept +{ + return _Core->VehicleDestroyed; +} + +// ------------------------------------------------------------------------------------------------ +EBlipCustom & GBlipCustom() noexcept +{ + return _Core->BlipCustom; +} + +ECheckpointCustom & GCheckpointCustom() noexcept +{ + return _Core->CheckpointCustom; +} + +EKeybindCustom & GKeybindCustom() noexcept +{ + return _Core->KeybindCustom; +} + +EObjectCustom & GObjectCustom() noexcept +{ + return _Core->ObjectCustom; +} + +EPickupCustom & GPickupCustom() noexcept +{ + return _Core->PickupCustom; +} + +EPlayerCustom & GPlayerCustom() noexcept +{ + return _Core->PlayerCustom; +} + +ESphereCustom & GSphereCustom() noexcept +{ + return _Core->SphereCustom; +} + +ESpriteCustom & GSpriteCustom() noexcept +{ + return _Core->SpriteCustom; +} + +ETextdrawCustom & GTextdrawCustom() noexcept +{ + return _Core->TextdrawCustom; +} + +EVehicleCustom & GVehicleCustom() noexcept +{ + return _Core->VehicleCustom; +} + // ------------------------------------------------------------------------------------------------ bool Register_Entity(HSQUIRRELVM vm) { diff --git a/source/Entity.hpp b/source/Entity.hpp index 472dd772..33717997 100644 --- a/source/Entity.hpp +++ b/source/Entity.hpp @@ -17,7 +17,7 @@ namespace SqMod { /* ------------------------------------------------------------------------------------------------ - * ... + * Helper enum to have a numeric way of identifying entity types. */ enum EntityType { @@ -36,12 +36,54 @@ enum EntityType }; /* ------------------------------------------------------------------------------------------------ - * ... + * Helper functions used by the entity interfaces to obtain global signals from the core instance. +*/ +EBlipCreated & GBlipCreated() noexcept; +ECheckpointCreated & GCheckpointCreated() noexcept; +EKeybindCreated & GKeybindCreated() noexcept; +EObjectCreated & GObjectCreated() noexcept; +EPickupCreated & GPickupCreated() noexcept; +EPlayerCreated & GPlayerCreated() noexcept; +ESphereCreated & GSphereCreated() noexcept; +ESpriteCreated & GSpriteCreated() noexcept; +ETextdrawCreated & GTextdrawCreated() noexcept; +EVehicleCreated & GVehicleCreated() noexcept; + +/* ------------------------------------------------------------------------------------------------ + * Helper functions used by the entity interfaces to obtain global signals from the core instance. +*/ +EBlipDestroyed & GBlipDestroyed() noexcept; +ECheckpointDestroyed & GCheckpointDestroyed() noexcept; +EKeybindDestroyed & GKeybindDestroyed() noexcept; +EObjectDestroyed & GObjectDestroyed() noexcept; +EPickupDestroyed & GPickupDestroyed() noexcept; +EPlayerDestroyed & GPlayerDestroyed() noexcept; +ESphereDestroyed & GSphereDestroyed() noexcept; +ESpriteDestroyed & GSpriteDestroyed() noexcept; +ETextdrawDestroyed & GTextdrawDestroyed() noexcept; +EVehicleDestroyed & GVehicleDestroyed() noexcept; + +/* ------------------------------------------------------------------------------------------------ + * Helper functions used by the entity interfaces to obtain global signals from the core instance. +*/ +EBlipCustom & GBlipCustom() noexcept; +ECheckpointCustom & GCheckpointCustom() noexcept; +EKeybindCustom & GKeybindCustom() noexcept; +EObjectCustom & GObjectCustom() noexcept; +EPickupCustom & GPickupCustom() noexcept; +EPlayerCustom & GPlayerCustom() noexcept; +ESphereCustom & GSphereCustom() noexcept; +ESpriteCustom & GSpriteCustom() noexcept; +ETextdrawCustom & GTextdrawCustom() noexcept; +EVehicleCustom & GVehicleCustom() noexcept; + +/* ------------------------------------------------------------------------------------------------ + * Forward declaration of an entity interface. */ template < class T > class Ent; /* ------------------------------------------------------------------------------------------------ - * ... + * Specialized entity interface for the blip entity type. */ template <> class Ent< CBlip > { @@ -55,12 +97,21 @@ private: typedef Reference< CBlip > RefType; /* -------------------------------------------------------------------------------------------- - * ... + * Default destructor (disabled) + */ + Ent() = delete; + + /* -------------------------------------------------------------------------------------------- + * Helper structure that holds information about each entity instance of this type. */ typedef struct Blip { // ---------------------------------------------------------------------------------------- - Blip() noexcept : ID(-1), Root(0), Owned(false), Fresh(true) { /* ... */ } + Blip() noexcept + : ID(-1), Root(0), Owned(false), Fresh(true) + { + /* ... */ + } // ---------------------------------------------------------------------------------------- SQInt32 ID; @@ -93,21 +144,60 @@ private: EBlipCustom BlipCustom; // ---------------------------------------------------------------------------------------- - EBlipCreated & Created() noexcept { return BlipCreated; } - EBlipDestroyed & Destroyed() noexcept { return BlipDestroyed; } - EBlipCustom & Custom() noexcept { return BlipCustom; } + EBlipCreated & Created() noexcept + { + return BlipCreated; + } + + EBlipDestroyed & Destroyed() noexcept + { + return BlipDestroyed; + } + + EBlipCustom & Custom() noexcept + { + return BlipCustom; + } + + // ---------------------------------------------------------------------------------------- + EBlipCreated & GCreated() noexcept + { + return GBlipCreated(); + } + + EBlipDestroyed & GDestroyed() noexcept + { + return GBlipDestroyed(); + } + + EBlipCustom & GCustom() noexcept + { + return GBlipCustom(); + } } Instance; // -------------------------------------------------------------------------------------------- - static void Store(Instance & inst, SQInt32 world, SQInt32 scale, SQInt32 sprite, \ - const Vector3 & pos, const Color4 & color) noexcept + static void Store(Instance & inst) noexcept + { + inst.World = SQMOD_UNKNOWN; + inst.Scale = SQMOD_UNKNOWN; + inst.SprID = SQMOD_UNKNOWN; + inst.Position.Clear(); + inst.Color.Clear(); + } + + // -------------------------------------------------------------------------------------------- + static void Store(Instance & inst, SQInt32 index, SQInt32 world, SQFloat x, SQFloat y, SQFloat z, + SQInt32 scale, SQUint32 color, SQInt32 sprid) noexcept { inst.World = world; inst.Scale = scale; - inst.SprID = sprite; - inst.Position = pos; - inst.Color = color; + inst.SprID = sprid; + inst.Position.x = x; + inst.Position.y = y; + inst.Position.z = z; + inst.Color.SetRGBA(color); } // -------------------------------------------------------------------------------------------- @@ -118,6 +208,19 @@ private: inst.BlipCustom.Clear(); } + // -------------------------------------------------------------------------------------------- + static SQInt32 Create(SQInt32 index, SQInt32 world, SQFloat x, SQFloat y, SQFloat z, + SQInt32 scale, SQUint32 color, SQInt32 sprid) noexcept + { + return _Func->CreateCoordBlip(index, world, x, y, z, scale, color, sprid); + } + + // -------------------------------------------------------------------------------------------- + static void Destroy(SQInt32 id) noexcept + { + _Func->DestroyCoordBlip(id); + } + public: // -------------------------------------------------------------------------------------------- @@ -168,7 +271,7 @@ public: }; /* ------------------------------------------------------------------------------------------------ - * ... + * Specialized entity interface for the checkpoint entity type. */ template <> class Ent< CCheckpoint > { @@ -182,12 +285,21 @@ private: typedef Reference< CCheckpoint > RefType; /* -------------------------------------------------------------------------------------------- - * ... + * Default destructor (disabled) + */ + Ent() = delete; + + /* -------------------------------------------------------------------------------------------- + * Helper structure that holds information about each entity instance of this type. */ typedef struct Checkpoint { // ---------------------------------------------------------------------------------------- - Checkpoint() noexcept : ID(-1), Root(0), Owned(false), Fresh(true) { /* ... */ } + Checkpoint() noexcept + : ID(-1), Root(0), Owned(false), Fresh(true) + { + /* ... */ + } // ---------------------------------------------------------------------------------------- SQInt32 ID; @@ -211,9 +323,36 @@ private: ECheckpointExited CheckpointExited; // ---------------------------------------------------------------------------------------- - ECheckpointCreated & Created() noexcept { return CheckpointCreated; } - ECheckpointDestroyed & Destroyed() noexcept { return CheckpointDestroyed; } - ECheckpointCustom & Custom() noexcept { return CheckpointCustom; } + ECheckpointCreated & Created() noexcept + { + return CheckpointCreated; + } + + ECheckpointDestroyed & Destroyed() noexcept + { + return CheckpointDestroyed; + } + + ECheckpointCustom & Custom() noexcept + { + return CheckpointCustom; + } + + // ---------------------------------------------------------------------------------------- + ECheckpointCreated & GCreated() noexcept + { + return GCheckpointCreated(); + } + + ECheckpointDestroyed & GDestroyed() noexcept + { + return GCheckpointDestroyed(); + } + + ECheckpointCustom & GCustom() noexcept + { + return GCheckpointCustom(); + } } Instance; @@ -223,6 +362,13 @@ private: /* ... */ } + // -------------------------------------------------------------------------------------------- + static void Store(Instance & inst, SQInt32 player, SQInt32 world, SQFloat x, SQFloat y, SQFloat z, + SQUint32 r, SQUint32 g, SQUint32 b, SQUint32 a, SQFloat radius) noexcept + { + /* ... */ + } + // -------------------------------------------------------------------------------------------- static void Clear(Instance & inst) noexcept { @@ -233,6 +379,19 @@ private: inst.CheckpointExited.Clear(); } + // -------------------------------------------------------------------------------------------- + static SQInt32 Create(SQInt32 player, SQInt32 world, SQFloat x, SQFloat y, SQFloat z, + SQUint32 r, SQUint32 g, SQUint32 b, SQUint32 a, SQFloat radius) noexcept + { + return _Func->CreateCheckpoint(player, world, x, y, z, r, g, b, a, radius); + } + + // -------------------------------------------------------------------------------------------- + static void Destroy(SQInt32 id) noexcept + { + _Func->DeleteCheckpoint(id); + } + public: // -------------------------------------------------------------------------------------------- @@ -289,7 +448,7 @@ public: }; /* ------------------------------------------------------------------------------------------------ - * ... + * Specialized entity interface for the keybind entity type. */ template <> class Ent< CKeybind > { @@ -303,12 +462,21 @@ private: typedef Reference< CKeybind > RefType; /* -------------------------------------------------------------------------------------------- - * ... + * Default destructor (disabled) + */ + Ent() = delete; + + /* -------------------------------------------------------------------------------------------- + * Helper structure that holds information about each entity instance of this type. */ typedef struct Keybind { // ---------------------------------------------------------------------------------------- - Keybind() noexcept : ID(-1), Root(0), Owned(false), Fresh(true) { /* ... */ } + Keybind() noexcept + : ID(-1), Root(0), Owned(false), Fresh(true) + { + /* ... */ + } // ---------------------------------------------------------------------------------------- SQInt32 ID; @@ -340,15 +508,51 @@ private: EKeybindKeyRelease KeybindKeyRelease; // ---------------------------------------------------------------------------------------- - EKeybindCreated & Created() noexcept { return KeybindCreated; } - EKeybindDestroyed & Destroyed() noexcept { return KeybindDestroyed; } - EKeybindCustom & Custom() noexcept { return KeybindCustom; } + EKeybindCreated & Created() noexcept + { + return KeybindCreated; + } + + EKeybindDestroyed & Destroyed() noexcept + { + return KeybindDestroyed; + } + + EKeybindCustom & Custom() noexcept + { + return KeybindCustom; + } + + // ---------------------------------------------------------------------------------------- + EKeybindCreated & GCreated() noexcept + { + return GKeybindCreated(); + } + + EKeybindDestroyed & GDestroyed() noexcept + { + return GKeybindDestroyed(); + } + + EKeybindCustom & GCustom() noexcept + { + return GKeybindCustom(); + } } Instance; // -------------------------------------------------------------------------------------------- - static void Store(Instance & inst, SQInt32 primary, SQInt32 secondary, SQInt32 alternative, \ - bool release) noexcept + static void Store(Instance & inst) noexcept + { + inst.Primary = SQMOD_UNKNOWN; + inst.Secondary = SQMOD_UNKNOWN; + inst.Alternative = SQMOD_UNKNOWN; + inst.Release = false; + } + + // -------------------------------------------------------------------------------------------- + static void Store(Instance & inst, SQInt32 slot, bool release, SQInt32 primary, SQInt32 secondary, + SQInt32 alternative) noexcept { inst.Primary = primary; inst.Secondary = secondary; @@ -366,6 +570,19 @@ private: inst.KeybindKeyRelease.Clear(); } + // -------------------------------------------------------------------------------------------- + static SQInt32 Create(SQInt32 slot, bool release, SQInt32 primary, SQInt32 secondary, + SQInt32 alternative) noexcept + { + return _Func->RegisterKeyBind(slot, release, primary, secondary, alternative); + } + + // -------------------------------------------------------------------------------------------- + static void Destroy(SQInt32 id) noexcept + { + _Func->RemoveKeyBind(id); + } + public: // -------------------------------------------------------------------------------------------- @@ -422,7 +639,7 @@ public: }; /* ------------------------------------------------------------------------------------------------ - * ... + * Specialized entity interface for the object entity type. */ template <> class Ent< CObject > { @@ -436,12 +653,21 @@ private: typedef Reference< CObject > RefType; /* -------------------------------------------------------------------------------------------- - * ... + * Default destructor (disabled) + */ + Ent() = delete; + + /* -------------------------------------------------------------------------------------------- + * Helper structure that holds information about each entity instance of this type. */ typedef struct Object { // ---------------------------------------------------------------------------------------- - Object() noexcept : ID(-1), Root(0), Owned(false), Fresh(true) { /* ... */ } + Object() noexcept + : ID(-1), Root(0), Owned(false), Fresh(true) + { + /* ... */ + } // ---------------------------------------------------------------------------------------- SQInt32 ID; @@ -465,9 +691,36 @@ private: EObjectBump ObjectBump; // ---------------------------------------------------------------------------------------- - EObjectCreated & Created() noexcept { return ObjectCreated; } - EObjectDestroyed & Destroyed() noexcept { return ObjectDestroyed; } - EObjectCustom & Custom() noexcept { return ObjectCustom; } + EObjectCreated & Created() noexcept + { + return ObjectCreated; + } + + EObjectDestroyed & Destroyed() noexcept + { + return ObjectDestroyed; + } + + EObjectCustom & Custom() noexcept + { + return ObjectCustom; + } + + // ---------------------------------------------------------------------------------------- + EObjectCreated & GCreated() noexcept + { + return GObjectCreated(); + } + + EObjectDestroyed & GDestroyed() noexcept + { + return GObjectDestroyed(); + } + + EObjectCustom & GCustom() noexcept + { + return GObjectCustom(); + } } Instance; @@ -477,6 +730,13 @@ private: /* ... */ } + // -------------------------------------------------------------------------------------------- + static void Store(Instance & inst, SQInt32 model, SQInt32 world, SQFloat x, SQFloat y, SQFloat z, + SQInt32 alpha) noexcept + { + /* ... */ + } + // -------------------------------------------------------------------------------------------- static void Clear(Instance & inst) noexcept { @@ -487,6 +747,19 @@ private: inst.ObjectBump.Clear(); } + // -------------------------------------------------------------------------------------------- + static SQInt32 Create(SQInt32 model, SQInt32 world, SQFloat x, SQFloat y, SQFloat z, + SQInt32 alpha) noexcept + { + return _Func->CreateObject(model, world, x, y, z, alpha); + } + + // -------------------------------------------------------------------------------------------- + static void Destroy(SQInt32 id) noexcept + { + _Func->DeleteObject(id); + } + public: // -------------------------------------------------------------------------------------------- @@ -543,7 +816,7 @@ public: }; /* ------------------------------------------------------------------------------------------------ - * ... + * Specialized entity interface for the pickup entity type. */ template <> class Ent< CPickup > { @@ -557,12 +830,21 @@ private: typedef Reference< CPickup > RefType; /* -------------------------------------------------------------------------------------------- - * ... + * Default destructor (disabled) + */ + Ent() = delete; + + /* -------------------------------------------------------------------------------------------- + * Helper structure that holds information about each entity instance of this type. */ typedef struct Pickup { // ---------------------------------------------------------------------------------------- - Pickup() noexcept : ID(-1), Root(0), Owned(false), Fresh(true) { /* ... */ } + Pickup() noexcept + : ID(-1), Root(0), Owned(false), Fresh(true) + { + /* ... */ + } // ---------------------------------------------------------------------------------------- SQInt32 ID; @@ -587,9 +869,36 @@ private: EPickupCollected PickupCollected; // ---------------------------------------------------------------------------------------- - EPickupCreated & Created() noexcept { return PickupCreated; } - EPickupDestroyed & Destroyed() noexcept { return PickupDestroyed; } - EPickupCustom & Custom() noexcept { return PickupCustom; } + EPickupCreated & Created() noexcept + { + return PickupCreated; + } + + EPickupDestroyed & Destroyed() noexcept + { + return PickupDestroyed; + } + + EPickupCustom & Custom() noexcept + { + return PickupCustom; + } + + // ---------------------------------------------------------------------------------------- + EPickupCreated & GCreated() noexcept + { + return GPickupCreated(); + } + + EPickupDestroyed & GDestroyed() noexcept + { + return GPickupDestroyed(); + } + + EPickupCustom & GCustom() noexcept + { + return GPickupCustom(); + } } Instance; @@ -599,6 +908,13 @@ private: /* ... */ } + // -------------------------------------------------------------------------------------------- + static void Store(Instance & inst, SQInt32 model, SQInt32 world, SQInt32 quantity, + SQFloat x, SQFloat y, SQFloat z, SQInt32 alpha, bool automatic) noexcept + { + /* ... */ + } + // -------------------------------------------------------------------------------------------- static void Clear(Instance & inst) noexcept { @@ -610,6 +926,19 @@ private: inst.PickupCollected.Clear(); } + // -------------------------------------------------------------------------------------------- + static SQInt32 Create(SQInt32 model, SQInt32 world, SQInt32 quantity, + SQFloat x, SQFloat y, SQFloat z, SQInt32 alpha, bool automatic) noexcept + { + return _Func->CreatePickup(model, world, quantity, x, y, z, alpha, automatic); + } + + // -------------------------------------------------------------------------------------------- + static void Destroy(SQInt32 id) noexcept + { + _Func->DeletePickup(id); + } + public: // -------------------------------------------------------------------------------------------- @@ -668,7 +997,7 @@ public: }; /* ------------------------------------------------------------------------------------------------ - * ... + * Specialized entity interface for the player entity type. */ template <> class Ent< CPlayer > { @@ -682,12 +1011,21 @@ private: typedef Reference< CPlayer > RefType; /* -------------------------------------------------------------------------------------------- - * ... + * Default destructor (disabled) + */ + Ent() = delete; + + /* -------------------------------------------------------------------------------------------- + * Helper structure that holds information about each entity instance of this type. */ typedef struct Player { // ---------------------------------------------------------------------------------------- - Player() noexcept : ID(-1), Root(0), Owned(false), Fresh(true) { /* ... */ } + Player() noexcept + : ID(-1), Root(0), Owned(false), Fresh(true) + { + /* ... */ + } // ---------------------------------------------------------------------------------------- SQInt32 ID; @@ -768,9 +1106,36 @@ private: ESphereExited SphereExited; // ---------------------------------------------------------------------------------------- - EPlayerCreated & Created() noexcept { return PlayerCreated; } - EPlayerDestroyed & Destroyed() noexcept { return PlayerDestroyed; } - EPlayerCustom & Custom() noexcept { return PlayerCustom; } + EPlayerCreated & Created() noexcept + { + return PlayerCreated; + } + + EPlayerDestroyed & Destroyed() noexcept + { + return PlayerDestroyed; + } + + EPlayerCustom & Custom() noexcept + { + return PlayerCustom; + } + + // ---------------------------------------------------------------------------------------- + EPlayerCreated & GCreated() noexcept + { + return GPlayerCreated(); + } + + EPlayerDestroyed & GDestroyed() noexcept + { + return GPlayerDestroyed(); + } + + EPlayerCustom & GCustom() noexcept + { + return GPlayerCustom(); + } } Instance; @@ -847,6 +1212,18 @@ private: inst.SphereExited.Clear(); } + // -------------------------------------------------------------------------------------------- + static SQInt32 Create() noexcept + { + return SQMOD_UNKNOWN; + } + + // -------------------------------------------------------------------------------------------- + static void Destroy(SQInt32 id) noexcept + { + /* @TODO: Implement as kick. */ + } + public: // -------------------------------------------------------------------------------------------- @@ -1017,7 +1394,7 @@ public: }; /* ------------------------------------------------------------------------------------------------ - * ... + * Specialized entity interface for the sphere entity type. */ template <> class Ent< CSphere > { @@ -1031,12 +1408,21 @@ private: typedef Reference< CSphere > RefType; /* -------------------------------------------------------------------------------------------- - * ... + * Default destructor (disabled) + */ + Ent() = delete; + + /* -------------------------------------------------------------------------------------------- + * Helper structure that holds information about each entity instance of this type. */ typedef struct Sphere { // ---------------------------------------------------------------------------------------- - Sphere() noexcept : ID(-1), Root(0), Owned(false), Fresh(true) { /* ... */ } + Sphere() noexcept + : ID(-1), Root(0), Owned(false), Fresh(true) + { + /* ... */ + } // ---------------------------------------------------------------------------------------- SQInt32 ID; @@ -1060,9 +1446,36 @@ private: ESphereExited SphereExited; // ---------------------------------------------------------------------------------------- - ESphereCreated & Created() noexcept { return SphereCreated; } - ESphereDestroyed & Destroyed() noexcept { return SphereDestroyed; } - ESphereCustom & Custom() noexcept { return SphereCustom; } + ESphereCreated & Created() noexcept + { + return SphereCreated; + } + + ESphereDestroyed & Destroyed() noexcept + { + return SphereDestroyed; + } + + ESphereCustom & Custom() noexcept + { + return SphereCustom; + } + + // ---------------------------------------------------------------------------------------- + ESphereCreated & GCreated() noexcept + { + return GSphereCreated(); + } + + ESphereDestroyed & GDestroyed() noexcept + { + return GSphereDestroyed(); + } + + ESphereCustom & GCustom() noexcept + { + return GSphereCustom(); + } } Instance; @@ -1072,6 +1485,13 @@ private: /* ... */ } + // -------------------------------------------------------------------------------------------- + static void Store(Instance & inst, SQInt32 player, SQInt32 world, SQFloat x, SQFloat y, SQFloat z, + SQUint32 r, SQUint32 g, SQUint32 b, SQFloat radius) noexcept + { + /* ... */ + } + // -------------------------------------------------------------------------------------------- static void Clear(Instance & inst) noexcept { @@ -1082,6 +1502,19 @@ private: inst.SphereExited.Clear(); } + // -------------------------------------------------------------------------------------------- + static SQInt32 Create(SQInt32 player, SQInt32 world, SQFloat x, SQFloat y, SQFloat z, + SQUint32 r, SQUint32 g, SQUint32 b, SQFloat radius) noexcept + { + return _Func->CreateSphere(_SCI32(player), world, x, y, z, r, g, b, radius); + } + + // -------------------------------------------------------------------------------------------- + static void Destroy(SQInt32 id) noexcept + { + _Func->DeleteSphere(id); + } + public: // -------------------------------------------------------------------------------------------- @@ -1138,7 +1571,7 @@ public: }; /* ------------------------------------------------------------------------------------------------ - * ... + * Specialized entity interface for the sprite entity type. */ template <> class Ent< CSprite > { @@ -1152,12 +1585,21 @@ private: typedef Reference< CSprite > RefType; /* -------------------------------------------------------------------------------------------- - * ... + * Default destructor (disabled) + */ + Ent() = delete; + + /* -------------------------------------------------------------------------------------------- + * Helper structure that holds information about each entity instance of this type. */ typedef struct Sprite { // ---------------------------------------------------------------------------------------- - Sprite() noexcept : ID(-1), Root(0), Owned(false), Fresh(true) { /* ... */ } + Sprite() noexcept + : ID(-1), Root(0), Owned(false), Fresh(true) + { + /* ... */ + } // ---------------------------------------------------------------------------------------- SQInt32 ID; @@ -1182,16 +1624,50 @@ private: ESpriteCustom SpriteCustom; // ---------------------------------------------------------------------------------------- - ESpriteCreated & Created() noexcept { return SpriteCreated; } - ESpriteDestroyed & Destroyed() noexcept { return SpriteDestroyed; } - ESpriteCustom & Custom() noexcept { return SpriteCustom; } + ESpriteCreated & Created() noexcept + { + return SpriteCreated; + } + + ESpriteDestroyed & Destroyed() noexcept + { + return SpriteDestroyed; + } + + ESpriteCustom & Custom() noexcept + { + return SpriteCustom; + } + + // ---------------------------------------------------------------------------------------- + ESpriteCreated & GCreated() noexcept + { + return GSpriteCreated(); + } + + ESpriteDestroyed & GDestroyed() noexcept + { + return GSpriteDestroyed(); + } + + ESpriteCustom & GCustom() noexcept + { + return GSpriteCustom(); + } } Instance; // -------------------------------------------------------------------------------------------- - static void Store(Instance & inst, const String & path) noexcept + static void Store(Instance & inst) noexcept { - inst.Path = path; + inst.Path.clear(); + } + + // -------------------------------------------------------------------------------------------- + static void Store(Instance & inst, SQInt32 index, const SQChar * file, SQInt32 xp, SQInt32 yp, + SQInt32 xr, SQInt32 yr, SQFloat angle, SQInt32 alpha, bool rel) noexcept + { + inst.Path.assign(file); } // -------------------------------------------------------------------------------------------- @@ -1202,6 +1678,19 @@ private: inst.SpriteCustom.Clear(); } + // -------------------------------------------------------------------------------------------- + static SQInt32 Create(SQInt32 index, const SQChar * file, SQInt32 xp, SQInt32 yp, + SQInt32 xr, SQInt32 yr, SQFloat angle, SQInt32 alpha, bool rel) noexcept + { + return _Func->CreateSprite(index, file, xp, yp, xr, yr, angle, alpha, rel); + } + + // -------------------------------------------------------------------------------------------- + static void Destroy(SQInt32 id) noexcept + { + _Func->DestroySprite(id); + } + public: // -------------------------------------------------------------------------------------------- @@ -1253,7 +1742,7 @@ public: }; /* ------------------------------------------------------------------------------------------------ - * ... + * Specialized entity interface for the textdraw entity type. */ template <> class Ent< CTextdraw > { @@ -1267,12 +1756,21 @@ private: typedef Reference< CTextdraw > RefType; /* -------------------------------------------------------------------------------------------- - * ... + * Default destructor (disabled) + */ + Ent() = delete; + + /* -------------------------------------------------------------------------------------------- + * Helper structure that holds information about each entity instance of this type. */ typedef struct Textdraw { // ---------------------------------------------------------------------------------------- - Textdraw() noexcept : ID(-1), Root(0), Owned(false), Fresh(true) { /* ... */ } + Textdraw() noexcept + : ID(-1), Root(0), Owned(false), Fresh(true) + { + /* ... */ + } // ---------------------------------------------------------------------------------------- SQInt32 ID; @@ -1297,16 +1795,50 @@ private: ETextdrawCustom TextdrawCustom; // ---------------------------------------------------------------------------------------- - ETextdrawCreated & Created() noexcept { return TextdrawCreated; } - ETextdrawDestroyed & Destroyed() noexcept { return TextdrawDestroyed; } - ETextdrawCustom & Custom() noexcept { return TextdrawCustom; } + ETextdrawCreated & Created() noexcept + { + return TextdrawCreated; + } + + ETextdrawDestroyed & Destroyed() noexcept + { + return TextdrawDestroyed; + } + + ETextdrawCustom & Custom() noexcept + { + return TextdrawCustom; + } + + // ---------------------------------------------------------------------------------------- + ETextdrawCreated & GCreated() noexcept + { + return GTextdrawCreated(); + } + + ETextdrawDestroyed & GDestroyed() noexcept + { + return GTextdrawDestroyed(); + } + + ETextdrawCustom & GCustom() noexcept + { + return GTextdrawCustom(); + } } Instance; // -------------------------------------------------------------------------------------------- - static void Store(Instance & inst, const String & text) noexcept + static void Store(Instance & inst) noexcept { - inst.Text = text; + inst.Text.clear(); + } + + // -------------------------------------------------------------------------------------------- + static void Store(Instance & inst, SQInt32 index, const SQChar * text, SQInt32 xp, SQInt32 yp, + SQUint32 color, bool rel) noexcept + { + inst.Text.assign(text); } // -------------------------------------------------------------------------------------------- @@ -1317,6 +1849,19 @@ private: inst.TextdrawCustom.Clear(); } + // -------------------------------------------------------------------------------------------- + static SQInt32 Create(SQInt32 index, const SQChar * text, SQInt32 xp, SQInt32 yp, + SQUint32 color, bool rel) noexcept + { + return _Func->CreateTextdraw(index, text, xp, yp, color, rel); + } + + // -------------------------------------------------------------------------------------------- + static void Destroy(SQInt32 id) noexcept + { + _Func->DestroyTextdraw(id); + } + public: // -------------------------------------------------------------------------------------------- @@ -1368,7 +1913,7 @@ public: }; /* ------------------------------------------------------------------------------------------------ - * ... + * Specialized entity interface for the vehicle entity type. */ template <> class Ent< CVehicle > { @@ -1382,12 +1927,21 @@ private: typedef Reference< CVehicle > RefType; /* -------------------------------------------------------------------------------------------- - * ... + * Default destructor (disabled) + */ + Ent() = delete; + + /* -------------------------------------------------------------------------------------------- + * Helper structure that holds information about each entity instance of this type. */ typedef struct Vehicle { // ---------------------------------------------------------------------------------------- - Vehicle() noexcept : ID(-1), Root(0), Owned(false), Fresh(true) { /* ... */ } + Vehicle() noexcept + : ID(-1), Root(0), Owned(false), Fresh(true) + { + /* ... */ + } // ---------------------------------------------------------------------------------------- SQInt32 ID; @@ -1416,16 +1970,50 @@ private: EVehicleDisembark VehicleDisembark; // ---------------------------------------------------------------------------------------- - EVehicleCreated & Created() noexcept { return VehicleCreated; } - EVehicleDestroyed & Destroyed() noexcept { return VehicleDestroyed; } - EVehicleCustom & Custom() noexcept { return VehicleCustom; } + EVehicleCreated & Created() noexcept + { + return VehicleCreated; + } + + EVehicleDestroyed & Destroyed() noexcept + { + return VehicleDestroyed; + } + + EVehicleCustom & Custom() noexcept + { + return VehicleCustom; + } + + // ---------------------------------------------------------------------------------------- + EVehicleCreated & GCreated() noexcept + { + return GVehicleCreated(); + } + + EVehicleDestroyed & GDestroyed() noexcept + { + return GVehicleDestroyed(); + } + + EVehicleCustom & GCustom() noexcept + { + return GVehicleCustom(); + } } Instance; // -------------------------------------------------------------------------------------------- static void Store(Instance & inst) noexcept { + /* ... */ + } + // -------------------------------------------------------------------------------------------- + static void Store(Instance & inst, SQInt32 model, SQInt32 world, SQFloat x, SQFloat y, SQFloat z, + SQFloat angle, SQInt32 primary, SQInt32 secondary) noexcept + { + /* ... */ } // -------------------------------------------------------------------------------------------- @@ -1443,6 +2031,19 @@ private: inst.VehicleDisembark.Clear(); } + // -------------------------------------------------------------------------------------------- + static SQInt32 Create(SQInt32 model, SQInt32 world, SQFloat x, SQFloat y, SQFloat z, + SQFloat angle, SQInt32 primary, SQInt32 secondary) noexcept + { + return _Func->CreateVehicle(model, world, x, y, z, angle, primary, secondary); + } + + // -------------------------------------------------------------------------------------------- + static void Destroy(SQInt32 id) noexcept + { + _Func->DeleteVehicle(id); + } + public: // -------------------------------------------------------------------------------------------- @@ -1723,7 +2324,7 @@ public: */ operator bool () const noexcept { - return VALID_ENTITYEX(m_ID, Max); + return VALID_ENTITY(m_ID); } /* -------------------------------------------------------------------------------------------- @@ -1731,7 +2332,7 @@ public: */ bool operator ! () const noexcept { - return INVALID_ENTITYEX(m_ID, Max); + return INVALID_ENTITY(m_ID); } /* -------------------------------------------------------------------------------------------- @@ -1792,7 +2393,7 @@ public: */ const SQChar * GetGlobalTag() const noexcept { - if (VALID_ENTITYEX(m_ID, Max)) + if (VALID_ENTITY(m_ID)) { return s_Instances[m_ID].Tag.c_str(); } @@ -1809,7 +2410,7 @@ public: */ void SetGlobalTag(const SQChar * tag) const noexcept { - if (VALID_ENTITYEX(m_ID, Max)) + if (VALID_ENTITY(m_ID)) { s_Instances[m_ID].Tag.assign(tag); } @@ -1824,7 +2425,7 @@ public: */ SqObj & GetGlobalData() noexcept { - if (VALID_ENTITYEX(m_ID, Max)) + if (VALID_ENTITY(m_ID)) { return s_Instances[m_ID].Data; } @@ -1841,7 +2442,7 @@ public: */ void SetGlobalData(SqObj & data) const noexcept { - if (VALID_ENTITYEX(m_ID, Max)) + if (VALID_ENTITY(m_ID)) { s_Instances[m_ID].Data = data; } @@ -1892,7 +2493,7 @@ public: } /* -------------------------------------------------------------------------------------------- - * Return a new reference from the base reference + * Return a new reference from the base reference. */ T GetReference() const noexcept { @@ -1900,7 +2501,7 @@ public: } /* -------------------------------------------------------------------------------------------- - * Returns whether this entity reference points to an active entity + * Returns whether this entity reference points to an active entity. */ bool IsActive() const noexcept { @@ -1908,7 +2509,7 @@ public: } /* -------------------------------------------------------------------------------------------- - * Counts the number of active references for this entity + * Counts the number of active references for this entity. */ SQUint32 CountRefs() const noexcept { @@ -1933,7 +2534,7 @@ public: } /* -------------------------------------------------------------------------------------------- - * Counts the number of persistent references for this entity + * Counts the number of persistent references for this entity. */ SQUint32 CountPersistentRefs() const noexcept { @@ -1942,7 +2543,10 @@ public: if (VALID_ENTITYEX(m_ID, Max)) { // Count this instance if persistent - if (m_Persistent) ++refs; + if (m_Persistent) + { + ++refs; + } // Count backward references for (RefType * ref = m_Prev; ref; ref = ref->m_Prev) { @@ -1963,6 +2567,39 @@ public: return refs; } + /* -------------------------------------------------------------------------------------------- + * Destroy the referenced entity. + */ + bool Destroy() noexcept + { + return Destroy(0, NullData()); + } + + /* -------------------------------------------------------------------------------------------- + * Destroy the referenced entity. + */ + bool Destroy(SQInt32 header) noexcept + { + return Destroy(header, NullData()); + } + + /* -------------------------------------------------------------------------------------------- + * Destroy the referenced entity. + */ + bool Destroy(SQInt32 header, SqObj & payload) noexcept + { + if (VALID_ENTITY(m_ID)) + { + return EntMan< T >::Deactivate(m_ID, header, payload, true); + } + else + { + LogWrn(_SC("Attempting to using an invalid reference: %d"), Ent< T >::Name, m_ID); + } + + return false; + } + }; // ------------------------------------------------------------------------------------------------ @@ -1975,6 +2612,7 @@ template < class T > typename Ent< T >::Instances Reference< T >::s_Instances; template < class T > class EntMan { // -------------------------------------------------------------------------------------------- + friend class Reference< T >; friend class Core; public: @@ -1989,14 +2627,21 @@ private: static RefType NullRef; /* -------------------------------------------------------------------------------------------- - * Deactivates the specified entity instance + * Deactivates the specified entity instance. */ - static bool Deactivate(SQInt32 id, SqObj & payload) noexcept + static bool Deactivate(SQInt32 id, SQInt32 header, SqObj & payload, bool notify) noexcept { // Make sure this entity even exists if (RefType::Verify(id)) { - RefType * ref = 0, bkp = 0; + // Trigger this associated events if required + if (notify) + { + RefType::s_Instances[id].Destroyed().Emit(id, header, payload); + RefType::s_Instances[id].GDestroyed().Emit(id, header, payload); + } + + RefType * ref = 0, * bkp = 0; // Get the pointer to the first backward reference ref = RefType::s_Instances[id].Root->m_Prev; // Deactivate backward references @@ -2042,13 +2687,16 @@ private: } } + // Disable this entity instance + EntType::Destroy(id); + // Disable this entity instance RefType::s_Instances[id].ID = SQMOD_UNKNOWN; // Clear any events that are still listening EntType::Clear(RefType::s_Instances[id]); - // Sucessfully deactivated the instance + // Successfully deactivated the instance return true; } else @@ -2060,7 +2708,7 @@ private: } /* -------------------------------------------------------------------------------------------- - * Activates the specified entity instance + * Activates the specified entity instance. */ template < typename... Args > static bool Activate(SQInt32 id, bool owned, Args&&... args) noexcept { @@ -2078,7 +2726,7 @@ private: // @TODO Remove the reference from the chain, if somehow // is present there without being persistent - // Resurect backward references + // Resurrect backward references for (RefType * ref = RefType::s_Instances[id].Root->m_Prev; ref; ref = ref->m_Prev) { if (ref->m_Persistent) @@ -2086,7 +2734,8 @@ private: ref->m_ID = id; } } - // Resurect forward references + + // Resurrect forward references for (RefType * ref = RefType::s_Instances[id].Root->m_Next; ref; ref = ref->m_Next) { if (ref->m_Persistent) @@ -2121,6 +2770,32 @@ private: // Failed to activate the entity return false; } + + /* -------------------------------------------------------------------------------------------- + * Creates a new entity instance of the specified type. + */ + template < typename... Args > static SQInt32 Create(SQInt32 header, SqObj & payload, bool notify, Args&&... args) noexcept + { + // Attempt to create an instance on the server and obtain it's identifier + SQInt32 id = EntType::Create(std::forward< Args >(args)...); + // Attempt to activate the instance in the plugin at the received identifier + if (!Activate(id, true, std::forward< Args >(args)...)) + { + LogErr("Unable to instance", EntType::Name); + // Destroy this entity instance + EntType::Destroy(id); + // Replace the id with an invalid one + id = SQMOD_UNKNOWN; + } + // Trigger this associated events if required + else if (notify) + { + RefType::s_Instances[id].Created().Emit(id, header, payload); + RefType::s_Instances[id].GCreated().Emit(id, header, payload); + } + // Return the obtained entity identifier + return id; + } }; // ------------------------------------------------------------------------------------------------ @@ -2134,25 +2809,29 @@ template < class T > bool Register_Reference(HSQUIRRELVM vm, const SQChar * cnam // Output debugging information LogDbg("Beginning registration of <%s> type", cname); // Attempt to register the specified type - Sqrat::RootTable(vm).Bind(cname, Sqrat::Class< Reference< T > >(vm, cname) + Sqrat::RootTable(vm).Bind(cname, Sqrat::Class< Ref >(vm, cname) + /* Constructors */ .Ctor() .template Ctor< SQInt32 >() - + /* Metamethods */ .Func(_SC("_cmp"), &Ref::Cmp) .Func(_SC("_tostring"), &Ref::ToString) - + /* Functions */ .Prop(_SC("id"), &Ref::GetID, &Ref::SetID) .Prop(_SC("persistent"), &Ref::GetPersistent, &Ref::SetPersistent) .Prop(_SC("gtag"), &Ref::GetGlobalTag, &Ref::SetGlobalTag) .Prop(_SC("gdata"), &Ref::GetGlobalData, &Ref::SetGlobalData) .Prop(_SC("ltag"), &Ref::GetLocalTag, &Ref::SetLocalTag) .Prop(_SC("ldata"), &Ref::GetLocalData, &Ref::SetLocalData) - .Prop(_SC("max"), &Ref::GetMax) .Prop(_SC("sref"), &Ref::GetReference) .Prop(_SC("active"), &Ref::IsActive) .Prop(_SC("refs"), &Ref::CountRefs) .Prop(_SC("prefs"), &Ref::CountPersistentRefs) + /* Overloads */ + .template Overload< bool (Ref::*)(void) >(_SC("destroy"), &Ref::Destroy) + .template Overload< bool (Ref::*)(SQInt32) >(_SC("destroy"), &Ref::Destroy) + .template Overload< bool (Ref::*)(SQInt32, SqObj &) >(_SC("destroy"), &Ref::Destroy) ); // Output debugging information LogDbg("Registration of <%s> type was successful", cname); diff --git a/source/Misc/Automobile.cpp b/source/Misc/Automobile.cpp index 3f53084d..929cfb71 100644 --- a/source/Misc/Automobile.cpp +++ b/source/Misc/Automobile.cpp @@ -223,27 +223,27 @@ void CAutomobile::SetName(const SQChar * name) noexcept Reference< CVehicle > CAutomobile::Create(SQInt32 world, const Vector3 & pos, SQFloat angle, SQInt32 header, SqObj & payload) const noexcept { - return _Core->CreateVehicle(*this, world, pos, angle, SQMOD_UNKNOWN, SQMOD_UNKNOWN, header, payload); + return _Core->NewVehicle(m_ID, world, pos.x, pos.z, pos.y, angle, SQMOD_UNKNOWN, SQMOD_UNKNOWN, header, payload); } Reference< CVehicle > CAutomobile::Create(SQInt32 world, const Vector3 & pos, SQFloat angle, SQInt32 primary, SQInt32 secondary, SQInt32 header, SqObj & payload) const noexcept { - return _Core->CreateVehicle(*this, world, pos, angle, primary, secondary, header, payload); + return _Core->NewVehicle(*this, world, pos.x, pos.z, pos.y, angle, primary, secondary, header, payload); } Reference< CVehicle > CAutomobile::Create(SQInt32 world, SQFloat x, SQFloat y, SQFloat z, SQFloat angle, SQInt32 header, SqObj & payload) const noexcept { - return _Core->CreateVehicle(*this, world, Vector3(x, y, z), angle, SQMOD_UNKNOWN, SQMOD_UNKNOWN, header, payload); + return _Core->NewVehicle(*this, world, x, y, z, angle, SQMOD_UNKNOWN, SQMOD_UNKNOWN, header, payload); } Reference< CVehicle > CAutomobile::Create(SQInt32 world, SQFloat x, SQFloat y, SQFloat z, SQFloat angle, SQInt32 primary, SQInt32 secondary, SQInt32 header, SqObj & payload) const noexcept { - return _Core->CreateVehicle(*this, world, Vector3(x, y, z), angle, primary, secondary, header, payload); + return _Core->NewVehicle(*this, world, x, y, z, angle, primary, secondary, header, payload); } // ================================================================================================ diff --git a/source/Misc/Model.cpp b/source/Misc/Model.cpp index 731c1dbd..e8fd7b84 100644 --- a/source/Misc/Model.cpp +++ b/source/Misc/Model.cpp @@ -232,26 +232,26 @@ bool CModel::IsActuallyWeapon() const noexcept Reference< CObject > CModel::Object(SQInt32 world, const Vector3 & pos, SQInt32 alpha, SQInt32 header, \ SqObj & payload) const noexcept { - return _Core->CreateObject(*this, world, pos, alpha, header, payload); + return _Core->NewObject(m_ID, world, pos.x, pos.y, pos.z, alpha, header, payload); } Reference< CObject > CModel::Object(SQInt32 world, SQFloat x, SQFloat y, SQFloat z, SQInt32 alpha, \ SQInt32 header, SqObj & payload) const noexcept { - return _Core->CreateObject(*this, world, Vector3(x, y, z), alpha, header, payload); + return _Core->NewObject(m_ID, world, x, y, z, alpha, header, payload); } // ------------------------------------------------------------------------------------------------ Reference< CPickup > CModel::Pickup(SQInt32 world, SQInt32 quantity, const Vector3 & pos, SQInt32 alpha, \ bool automatic, SQInt32 header, SqObj & payload) const noexcept { - return _Core->CreatePickup(*this, world, quantity, pos, alpha, automatic, header, payload); + return _Core->NewPickup(m_ID, world, quantity, pos.x, pos.y, pos.z, alpha, automatic, header, payload); } Reference< CPickup > CModel::Pickup(SQInt32 world, SQInt32 quantity, SQFloat x, SQFloat y, SQFloat z, \ SQInt32 alpha, bool automatic, SQInt32 header, SqObj & payload) const noexcept { - return _Core->CreatePickup(*this, world, quantity, Vector3(x, y, z), alpha, automatic, header, payload); + return _Core->NewPickup(m_ID, world, quantity, x, y, z, alpha, automatic, header, payload); } // ================================================================================================ diff --git a/source/Misc/Shared.hpp b/source/Misc/Shared.hpp index d9bc0fd2..b9fd593d 100644 --- a/source/Misc/Shared.hpp +++ b/source/Misc/Shared.hpp @@ -166,6 +166,16 @@ protected: LogErr("Attempting to set global data for invalid automobile id: %d", id); } } + +public: + + /* -------------------------------------------------------------------------------------------- + * See if the specified identifier is valid and in bounds. + */ + static bool Valid(SQInt32 id) noexcept + { + return VALID_ENTITYGETEX(id, Max); + } }; // ------------------------------------------------------------------------------------------------