You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openmw-tes3coop/apps/openmw-mp/Script/API/TimerAPI.hpp

61 lines
1.3 KiB
C++

#ifndef OPENMW_TIMERAPI_HPP
#define OPENMW_TIMERAPI_HPP
#include <string>
#include <Script/FFI.hpp>
#include <unordered_map>
namespace mwmp
{
class TimerAPI;
class Timer: public FFI
{
friend class TimerAPI;
public:
Timer(ScriptFunc callback, long msec, const std::string& def, va_list args);
~Timer();
void Tick(int timerId);
bool IsEnded();
void Stop();
void Start();
void Restart(int msec);
const char *GetDefinition();
private:
double startTime, targetMsec;
//std::string publ, arg_types;
//Script *scr;
bool isEnded;
char *def;
};
class TimerAPI
{
public:
static int CreateTimer(ScriptFunc callback, long msec, const std::string& def, va_list args);
static void FreeTimer(int timerid);
static void ResetTimer(int timerid, long msec);
static void StartTimer(int timerid);
static void StopTimer(int timerid);
static bool IsTimerElapsed(int timerid);
static int GetTimerId();
static const char *GetDefinition(int timerid);
static void Terminate();
static void Tick();
private:
static std::unordered_map<int, Timer* > timers;
static int pointer;
static int lastTimerId;
};
}
#endif //OPENMW_TIMERAPI_HPP