2016-01-12 03:41:44 +00:00
|
|
|
#ifndef OPENMW_TIMERAPI_HPP
|
|
|
|
#define OPENMW_TIMERAPI_HPP
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2019-01-16 15:52:22 +00:00
|
|
|
#include <Script/FFI.hpp>
|
|
|
|
#include <unordered_map>
|
2016-01-12 03:41:44 +00:00
|
|
|
|
|
|
|
namespace mwmp
|
|
|
|
{
|
|
|
|
|
|
|
|
class TimerAPI;
|
|
|
|
|
2019-01-16 15:52:22 +00:00
|
|
|
class Timer: public FFI
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
|
|
|
friend class TimerAPI;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2019-01-16 15:52:22 +00:00
|
|
|
Timer(ScriptFunc callback, long msec, const std::string& def, va_list args);
|
|
|
|
~Timer();
|
|
|
|
|
|
|
|
void Tick(int timerId);
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2018-12-30 02:15:53 +00:00
|
|
|
bool IsEnded();
|
2016-01-12 03:41:44 +00:00
|
|
|
void Stop();
|
|
|
|
void Start();
|
|
|
|
void Restart(int msec);
|
2019-01-16 15:52:22 +00:00
|
|
|
const char *GetDefinition();
|
2016-01-12 03:41:44 +00:00
|
|
|
private:
|
2016-07-26 22:55:21 +00:00
|
|
|
double startTime, targetMsec;
|
2019-01-15 10:45:31 +00:00
|
|
|
//std::string publ, arg_types;
|
|
|
|
//Script *scr;
|
2018-12-30 02:15:53 +00:00
|
|
|
bool isEnded;
|
2019-01-16 15:52:22 +00:00
|
|
|
char *def;
|
2016-01-12 03:41:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class TimerAPI
|
|
|
|
{
|
|
|
|
public:
|
2019-01-16 15:52:22 +00:00
|
|
|
static int CreateTimer(ScriptFunc callback, long msec, const std::string& def, va_list args);
|
2016-11-16 17:27:46 +00:00
|
|
|
static void FreeTimer(int timerid);
|
|
|
|
static void ResetTimer(int timerid, long msec);
|
|
|
|
static void StartTimer(int timerid);
|
|
|
|
static void StopTimer(int timerid);
|
2018-12-30 02:15:53 +00:00
|
|
|
static bool IsTimerElapsed(int timerid);
|
2019-01-16 15:52:22 +00:00
|
|
|
static int GetTimerId();
|
|
|
|
static const char *GetDefinition(int timerid);
|
2016-01-12 03:41:44 +00:00
|
|
|
|
|
|
|
static void Terminate();
|
|
|
|
|
|
|
|
static void Tick();
|
|
|
|
private:
|
|
|
|
static std::unordered_map<int, Timer* > timers;
|
|
|
|
static int pointer;
|
2019-01-16 15:52:22 +00:00
|
|
|
static int lastTimerId;
|
2016-01-12 03:41:44 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif //OPENMW_TIMERAPI_HPP
|