From f89e0d8cd6f77e03935b0d4795715046b61a7914 Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Thu, 29 Oct 2015 22:07:15 +0200 Subject: [PATCH] Untested implementation of the Blip reference type. --- source/Entity/Blip.cpp | 144 +++++++++++++++++++++++++++++++++++++++-- source/Entity/Blip.hpp | 41 ++++++++++++ 2 files changed, 178 insertions(+), 7 deletions(-) diff --git a/source/Entity/Blip.cpp b/source/Entity/Blip.cpp index 416601b4..03511004 100644 --- a/source/Entity/Blip.cpp +++ b/source/Entity/Blip.cpp @@ -4,24 +4,154 @@ namespace SqMod { // ------------------------------------------------------------------------------------------------ -bool Register_CBlip(HSQUIRRELVM vm) +SQInteger CBlip::GetWorld() const noexcept { - if (!Register_Reference< CBlip >(vm, _SC("BaseBlip"))) + if (VALID_ENTITY(m_ID)) { - LogDbg("Unable to register the base class for type"); + RefType::Get(m_ID).World; + } + else + { + LogWrn(_SC("Attempting to using an invalid reference: %d"), m_ID); + } + return SQMOD_UNKNOWN; +} - return false; +// ------------------------------------------------------------------------------------------------ +SQInteger CBlip::GetScale() const noexcept +{ + if (VALID_ENTITY(m_ID)) + { + RefType::Get(m_ID).Scale; + } + else + { + LogWrn(_SC("Attempting to using an invalid reference: %d"), m_ID); + } + return SQMOD_UNKNOWN; +} + +// ------------------------------------------------------------------------------------------------ +const Vector3 & CBlip::GetPosition() const noexcept +{ + if (VALID_ENTITY(m_ID)) + { + RefType::Get(m_ID).Position; + } + else + { + LogWrn(_SC("Attempting to using an invalid reference: %d"), m_ID); } - LogDbg("Beginning registration of type"); + return Vector3::NIL; +} +// ------------------------------------------------------------------------------------------------ +SQFloat CBlip::GetPositionX() const noexcept +{ + if (VALID_ENTITY(m_ID)) + { + RefType::Get(m_ID).Position.x; + } + else + { + LogWrn(_SC("Attempting to using an invalid reference: %d"), m_ID); + } + + return 0.0; +} + +// ------------------------------------------------------------------------------------------------ +SQFloat CBlip::GetPositionY() const noexcept +{ + if (VALID_ENTITY(m_ID)) + { + RefType::Get(m_ID).Position.y; + } + else + { + LogWrn(_SC("Attempting to using an invalid reference: %d"), m_ID); + } + + return 0.0; +} + +// ------------------------------------------------------------------------------------------------ +SQFloat CBlip::GetPositionZ() const noexcept +{ + if (VALID_ENTITY(m_ID)) + { + RefType::Get(m_ID).Position.z; + } + else + { + LogWrn(_SC("Attempting to using an invalid reference: %d"), m_ID); + } + + return 0.0; +} + +// ------------------------------------------------------------------------------------------------ +const Color4 & CBlip::GetColor() const noexcept +{ + if (VALID_ENTITY(m_ID)) + { + RefType::Get(m_ID).Color; + } + else + { + LogWrn(_SC("Attempting to using an invalid reference: %d"), m_ID); + } + + return Color4::NIL; +} + +// ------------------------------------------------------------------------------------------------ +SQInt32 CBlip::GetSprID() const noexcept +{ + if (VALID_ENTITY(m_ID)) + { + RefType::Get(m_ID).SprID; + } + else + { + LogWrn(_SC("Attempting to using an invalid reference: %d"), m_ID); + } + + return SQMOD_UNKNOWN; +} + +// ================================================================================================ +bool Register_CBlip(HSQUIRRELVM vm) +{ + // Attempt to register the base reference type before the actual implementation + if (!Register_Reference< CBlip >(vm, _SC("BaseBlip"))) + { + LogFtl("Unable to register the base class for type"); + // Registration failed + return false; + } + // Output debugging information + LogDbg("Beginning registration of type"); + // Attempt to register the actual reference that implements all of the entity functionality Sqrat::RootTable(vm).Bind(_SC("CBlip"), Sqrat::DerivedClass< CBlip, Reference< CBlip > >(vm, _SC("CBlip")) + /* Constructors */ .Ctor() .Ctor< SQInt32 >() + /* Properties */ + .Prop(_SC("world"), &CBlip::GetWorld) + .Prop(_SC("scale"), &CBlip::GetScale) + .Prop(_SC("pos"), &CBlip::GetPosition) + .Prop(_SC("position"), &CBlip::GetPosition) + .Prop(_SC("color"), &CBlip::GetColor) + .Prop(_SC("spr_id"), &CBlip::GetSprID) + .Prop(_SC("pos_x"), &CBlip::GetPositionX) + .Prop(_SC("pos_y"), &CBlip::GetPositionY) + .Prop(_SC("pos_z"), &CBlip::GetPositionZ) ); - + // Output debugging information LogDbg("Registration of type was successful"); - + // Registration succeeded return true; } diff --git a/source/Entity/Blip.hpp b/source/Entity/Blip.hpp index 517d694c..ac76fb6a 100644 --- a/source/Entity/Blip.hpp +++ b/source/Entity/Blip.hpp @@ -13,8 +13,49 @@ namespace SqMod { class CBlip : public Reference< CBlip > { public: + // -------------------------------------------------------------------------------------------- using RefType::Reference; + + /* -------------------------------------------------------------------------------------------- + * + */ + SQInteger GetWorld() const noexcept; + + /* -------------------------------------------------------------------------------------------- + * + */ + SQInteger GetScale() const noexcept; + + /* -------------------------------------------------------------------------------------------- + * + */ + const Vector3 & GetPosition() const noexcept; + + /* -------------------------------------------------------------------------------------------- + * + */ + SQFloat GetPositionX() const noexcept; + + /* -------------------------------------------------------------------------------------------- + * + */ + SQFloat GetPositionY() const noexcept; + + /* -------------------------------------------------------------------------------------------- + * + */ + SQFloat GetPositionZ() const noexcept; + + /* -------------------------------------------------------------------------------------------- + * + */ + const Color4 & GetColor() const noexcept; + + /* -------------------------------------------------------------------------------------------- + * + */ + SQInt32 GetSprID() const noexcept; }; } // Namespace:: SqMod