Amaroq7 / SPMod

SourcePawn Scripting Engine for Half-Life 1 based games
GNU General Public License v3.0
27 stars 12 forks source link

Timer manager #10

Closed Amaroq7 closed 5 years ago

Amaroq7 commented 6 years ago

Description

Timer manager should responsible for creating, executing, removing tasks. Timer would be destroyed after finished execution (one time task) or by using Remove(). Timer with repeat flag could be destroyed returning PluginStop in its callback or by executing Remove().

Example plugin api:

enum TimerFlag
{
    None = 0,
    Repeat = (1<<0)
};

typeset TimerCallback
{
    function PluginReturn (Task task);
    function PluginReturn (Task task, any data);
};

methodmap Task
{
    Task(float time, TimerCallback func, any data = 0, TimerFlag flags = None);
    Remove();
    Trigger();
    Change(float interval, bool trigger = true);
};

How do we replicate the issue?

n/a

Expected behavior (i.e. solution)

SPMod should expose api for plugins and modules to manage timers.

Other Comments

n/a

Mistrick commented 6 years ago

Suggestion for flags InstantCall - call callback after creating task without waiting timer Annoying example

TaskCallback(id);
set_task(1.0, "TaskCallback", id, .flags = "b");
fant1kua commented 6 years ago

My suggestion is to add pause and unpause methods . It can help us to show user HUD when user is alive (spawn) and pause it when he was dying.