1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-11-06 09:17:17 +01:00

Forgot to decrease the number of occupied slots when removing tasks. And also to reset it when clearing them.

Removed the used tasks counter completely because it's useless and has a high risk of producing nasty bugs.
This commit is contained in:
Sandu Liviu Catalin
2016-11-17 19:59:47 +02:00
parent 23d9caeac3
commit 2f27188b52
2 changed files with 36 additions and 26 deletions

View File

@@ -78,8 +78,7 @@ private:
*/
~Task()
{
Release();
Clear();
Terminate();
}
/* ----------------------------------------------------------------------------------------
@@ -105,6 +104,16 @@ private:
*/
void Init(HSQOBJECT & inst, HSQOBJECT & func, Interval intrv, Iterator itr, Int32 id, Int32 type);
/* ----------------------------------------------------------------------------------------
* Release managed script resources.
*/
void Release();
/* ----------------------------------------------------------------------------------------
* Execute the managed task.
*/
Interval Execute();
/* ----------------------------------------------------------------------------------------
* Clear the arguments.
*/
@@ -120,12 +129,7 @@ private:
}
/* ----------------------------------------------------------------------------------------
* Release managed script resources.
*/
void Release();
/* ----------------------------------------------------------------------------------------
* Terminate the task
* Terminate the task.
*/
void Terminate()
{
@@ -133,11 +137,6 @@ private:
Clear();
}
/* ----------------------------------------------------------------------------------------
* Execute the managed task.
*/
Interval Execute();
/* ----------------------------------------------------------------------------------------
* Retrieve the associated user tag.
*/
@@ -267,7 +266,6 @@ private:
};
// --------------------------------------------------------------------------------------------
static Uint32 s_Used; // The number of occupied slots.
static Time s_Last; // Last time point.
static Time s_Prev; // Previous time point.
static Interval s_Intervals[SQMOD_MAX_TASKS]; // List of intervals to be processed.
@@ -364,6 +362,24 @@ protected:
public:
/* --------------------------------------------------------------------------------------------
* Retrieve the number of used tasks slots.
*/
static SQInteger GetUsed()
{
SQInteger n = 0;
// Iterate task list
for (const auto & t : s_Tasks)
{
if (VALID_ENTITY(t.mEntity))
{
++n;
}
}
// Return the final count
return n;
}
/* --------------------------------------------------------------------------------------------
* Cleanup all tasks associated with the specified entity.
*/