Audio: Clean up threading and add AudioStream fadein (RGSS3)

This commit is contained in:
Jonas Kulla 2014-09-30 09:13:12 +02:00
parent 46497eae01
commit 51a0f3903c
10 changed files with 228 additions and 146 deletions

48
src/sdl-util.h Normal file
View file

@ -0,0 +1,48 @@
#ifndef SDLUTIL_H
#define SDLUTIL_H
#include <SDL_atomic.h>
#include <SDL_thread.h>
#include <string>
struct AtomicFlag
{
AtomicFlag()
{
clear();
}
void set()
{
SDL_AtomicSet(&atom, 1);
}
void clear()
{
SDL_AtomicSet(&atom, 0);
}
operator bool() const
{
return SDL_AtomicGet(&atom);
}
private:
mutable SDL_atomic_t atom;
};
template<class C, void (C::*func)()>
int __sdlThreadFun(void *obj)
{
(static_cast<C*>(obj)->*func)();
return 0;
}
template<class C, void (C::*func)()>
SDL_Thread *createSDLThread(C *obj, const std::string &name = std::string())
{
return SDL_CreateThread(__sdlThreadFun<C, func>, name.c_str(), obj);
}
#endif // SDLUTIL_H