diff --git a/MiniEngine.cpp b/MiniEngine.cpp index ffc7594..0dc49e1 100644 --- a/MiniEngine.cpp +++ b/MiniEngine.cpp @@ -803,6 +803,63 @@ namespace MiniEngine SDL_StopTextInput(); } + Timer::Timer() + { + _enabled=false; + _detached=false; + id=-1; + } + + Timer::Timer(SDL_TimerCallback callback,Uint32 interval,void* param) : Timer() + { + _callback=callback; + _interval=interval; + _param=param; + } + + int Timer::enable() + { + if(_enabled) + { + return -1; + } + else + { + id=SDL_AddTimer(_interval,_callback,_param); + if(id<0) return -2; + _enabled=true; + return 0; + } + } + + int Timer::disable() + { + if(_enabled) + { + SDL_RemoveTimer(id); + _enabled=false; + id=-1; + return 0; + } + else + { + return -1; + } + } + + void Timer::detach() + { + _detached=true; + } + + Timer::~Timer() + { + if(!_detached) + { + disable(); + } + } + AudioPlayer::AudioPlayer() { if (!_sysAudioCounter) diff --git a/MiniEngine.h b/MiniEngine.h index b87c2ca..c1864f7 100644 --- a/MiniEngine.h +++ b/MiniEngine.h @@ -282,6 +282,26 @@ namespace MiniEngine }; }; + class Timer + { + public: + Timer(); + /// Uint32 func(Uint32,void*) ... + Timer(SDL_TimerCallback callback,Uint32 interval,void* param); + int enable(); + int disable(); + bool isenable(); + void detach(); + ~Timer(); + private: + SDL_TimerCallback _callback; + Uint32 _interval; + void* _param; + SDL_TimerID id; + bool _enabled; + bool _detached; + }; + class AudioPlayer { public: @@ -332,7 +352,6 @@ namespace MiniEngine Music m; }; - class Sound { public: