From aeba86bddfeceb14a215674355802b0c3779d033 Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Sat, 26 Mar 2016 18:17:31 +0200 Subject: [PATCH] Implement function to retrieve all active textdraws. --- source/Entity/Textdraw.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/source/Entity/Textdraw.cpp b/source/Entity/Textdraw.cpp index 520b46a6..be7f25de 100644 --- a/source/Entity/Textdraw.cpp +++ b/source/Entity/Textdraw.cpp @@ -430,6 +430,7 @@ static const Object & Textdraw_FindByID(Int32 id) return NullObject(); } +// ------------------------------------------------------------------------------------------------ static const Object & Textdraw_FindByTag(CSStr tag) { // Perform a validity check on the specified tag @@ -453,6 +454,35 @@ static const Object & Textdraw_FindByTag(CSStr tag) return NullObject(); } +// ------------------------------------------------------------------------------------------------ +static Array Textdraw_FindActive() +{ + // Remember the initial stack size + StackGuard sg; + // Obtain the ends of the entity pool + Core::Textdraws::const_iterator itr = _Core->GetTextdraws().cbegin(); + Core::Textdraws::const_iterator end = _Core->GetTextdraws().cend(); + // Allocate an empty array on the stack + sq_newarray(DefaultVM::Get(), 0); + // Process each entity in the pool + for (; itr != end; ++itr) + { + // Is this entity instance active? + if (VALID_ENTITY(itr->mID)) + { + // Push the script object on the stack + sq_pushobject(DefaultVM::Get(), (HSQOBJECT &)((*itr).mObj)); + // Append the object at the back of the array + if (SQ_FAILED(sq_arrayappend(DefaultVM::Get(), -1))) + { + STHROWF("Unable to append entity instance to the list"); + } + } + } + // Return the array at the top of the stack + return Var< Array >(DefaultVM::Get(), -1).value; +} + // ================================================================================================ void Register_CTextdraw(HSQUIRRELVM vm) { @@ -508,6 +538,7 @@ void Register_CTextdraw(HSQUIRRELVM vm) // Static Functions .StaticFunc(_SC("FindByID"), &Textdraw_FindByID) .StaticFunc(_SC("FindByTag"), &Textdraw_FindByTag) + .StaticFunc(_SC("FindActive"), &Textdraw_FindActive) // Static Overloads .StaticOverload< Object & (*)(CSStr, Int32, Int32, Uint8, Uint8, Uint8, Uint8, bool) > (_SC("CreateEx"), &Textdraw_CreateEx)