diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/3rdparty/luax/luax.h | 28 | ||||
-rw-r--r-- | src/libjin/modules.h | 12 | ||||
-rw-r--r-- | src/lua/audio/luaopen_Source.cpp | 92 | ||||
-rw-r--r-- | src/lua/audio/luaopen_audio.cpp | 73 | ||||
-rw-r--r-- | src/lua/embed/boot.lua.h | 3 |
5 files changed, 178 insertions, 30 deletions
diff --git a/src/3rdparty/luax/luax.h b/src/3rdparty/luax/luax.h index d3047b9..3a5b17d 100644 --- a/src/3rdparty/luax/luax.h +++ b/src/3rdparty/luax/luax.h @@ -59,20 +59,20 @@ #define luax_checknumber luaL_checknumber #define luax_checkinteger luaL_checkinteger #define luax_checkstring luaL_checkstring -#define luax_checkbool luaL_checkinteger -//bool luax_checkbool(lua_State *L, int numArg) -//{ -// bool b = false; -// if (lua_type(L, numArg) == LUA_TBOOLEAN) -// { -// b = lua_toboolean(L, numArg); -// } -// else -// { -// luaL_typerror(L, numArg, lua_typename(L, LUA_TBOOLEAN)); -// } -// return b; -//} +//#define luax_checkbool luaL_checkinteger +inline bool luax_checkbool(lua_State *L, int numArg) +{ + bool b = false; + if (lua_type(L, numArg) == LUA_TBOOLEAN) + { + b = lua_toboolean(L, numArg); + } + else + { + luaL_typerror(L, numArg, lua_typename(L, LUA_TBOOLEAN)); + } + return b; +} /** * Oprating tables. diff --git a/src/libjin/modules.h b/src/libjin/modules.h index 171c691..2e8e36f 100644 --- a/src/libjin/modules.h +++ b/src/libjin/modules.h @@ -6,7 +6,7 @@ #define JIN_MODULES_AUDIO 1 #define JIN_AUDIO_SDLAUDIO 1 -#define JIN_AUDIO_OPENAL 1 +#define JIN_AUDIO_OPENAL 0 #define JIN_MODULES_RENDER 1 @@ -21,22 +21,22 @@ #define JIN_MODULES_NET 1 -#define JIN_MODULES_PHYSICS 1 +#define JIN_MODULES_PHYSICS 0 #define JIN_PHYSICS_BOX2D 1 #define JIN_PHYSICS_NEWTON 1 -#define JIN_MODULES_TILEMAP 1 +#define JIN_MODULES_TILEMAP 0 -#define JIN_MODULES_UI 1 +#define JIN_MODULES_UI 0 -#define JIN_MODULES_TOOLS 1 +#define JIN_MODULES_TOOLS 0 #define JIN_TOOLS_COMPONENT 1 #define JIN_TOOLS_EVENTMSGCENTER 1 #define JIN_TOOLS_XML 1 #define JIN_TOOLS_CSV 1 #define JIN_TOOLS_JSON 1 -#define JIN_MODULES_THREAD 1 +#define JIN_MODULES_THREAD 0 #define JIN_MODULES_TIME 1 #define JIN_TIME_SDL 1 diff --git a/src/lua/audio/luaopen_Source.cpp b/src/lua/audio/luaopen_Source.cpp index 8ecaf7e..0b8391a 100644 --- a/src/lua/audio/luaopen_Source.cpp +++ b/src/lua/audio/luaopen_Source.cpp @@ -1,26 +1,108 @@ #include "lua/luax.h" +#include "libjin/jin.h" +#include "../luaopen_types.h" namespace jin { namespace lua { + using namespace jin::audio; + + static inline SDLSource* checkSource(lua_State* L) + { + Proxy* proxy = (Proxy*)luax_checktype(L, 1, TYPE_SOURCE); + if (proxy != 0 && proxy != nullptr) + return (SDLSource*)proxy->object; + return nullptr; + } + static int l_play(lua_State* L) { + SDLSource* src = checkSource(L); + src->play(); + return 0; + } - return 0; + static int l_stop(lua_State* L) + { + SDLSource* src = checkSource(L); + src->stop(); + return 0; + } + + static int l_pause(lua_State* L) + { + SDLSource* src = checkSource(L); + src->pause(); + return 0; + } + + static int l_rewind(lua_State* L) + { + SDLSource* src = checkSource(L); + src->rewind(); + return 0; + } + + static int l_resume(lua_State* L) + { + SDLSource* src = checkSource(L); + src->resume(); + return 0; + } + + static int l_isStop(lua_State* L) + { + SDLSource* src = checkSource(L); + bool isStop = src->isStopped(); + luax_pushboolean(L, isStop); + return 1; + } + + static int l_isPaused(lua_State* L) + { + SDLSource* src = checkSource(L); + bool isPaused = src->isPaused(); + luax_pushboolean(L, isPaused); + return 1; + } + + static int l_setVolume(lua_State* L) + { + SDLSource* src = checkSource(L); + float volume = luax_checknumber(L, 2); + src->setVolume(volume); + return 0; + } + + static int l_setLoop(lua_State* L) + { + SDLSource* src = checkSource(L); + bool loop = luax_checkbool(L, 2); + src->setLoop(loop); + return 0; } static const luaL_Reg f[] = { - {"play", l_play}, + { "play", l_play }, + { "stop", l_stop }, + { "pause", l_pause }, + { "resume", l_resume }, + { "rewind", l_rewind }, + { "isStop", l_isStop }, + { "isPaused", l_isPaused }, + { "setVolume", l_setVolume }, + { "setLoop", l_setLoop }, {0, 0} }; - + int luaopen_Source(lua_State* L) { + luax_newtype(L, TYPE_SOURCE, f); - return 1; + return 0; } } -} +}
\ No newline at end of file diff --git a/src/lua/audio/luaopen_audio.cpp b/src/lua/audio/luaopen_audio.cpp index 9a6bade..4f4f955 100644 --- a/src/lua/audio/luaopen_audio.cpp +++ b/src/lua/audio/luaopen_audio.cpp @@ -1,15 +1,19 @@ #include "lua/luax.h" +#include "../luaopen_types.h" #include "libjin/jin.h" namespace jin { namespace lua { + using namespace jin::filesystem; using namespace jin::audio; static int l_init(lua_State* L) { SDLAudio::Setting setting; + setting.samplerate = 44100; + setting.samples = 44100; if (! SDLAudio::get()->init(&setting)) { luax_error(L, "could not init audio"); @@ -19,21 +23,82 @@ namespace lua luax_pushboolean(L, true); return 1; } - + + static int l_play(lua_State* L) + { + SDLAudio::get()->play(); + return 0; + } + + static int l_stop(lua_State* L) + { + SDLAudio::get()->stop(); + return 0; + } + + static int l_pause(lua_State* L) + { + SDLAudio::get()->pause(); + return 0; + } + + static int l_resume(lua_State* L) + { + SDLAudio::get()->resume(); + return 0; + } + + static int l_setVolume(lua_State* L) + { + float volume = luax_checknumber(L, 1); + SDLAudio::get()->setVolume(volume); + return 0; + } + static int l_newSound(lua_State* L) { - - return 0; + Filesystem* fs = Filesystem::get(); + const char* f = luax_checkstring(L, 1); + if (!fs->exists(f)) + { + printf("Error: no such image %s\n", f); + exit(1); + } + Buffer b; + fs->read(f, &b); + + Proxy* proxy = (Proxy*)luax_newinstance(L, TYPE_SOURCE, sizeof(Proxy)); + SDLSource* src = SDLSource::createSource(b.data, b.size); + proxy->bind(src); + return 1; } - static const luaL_Reg f[] = { + static int l_destroy(lua_State* L) + { + SDLAudio* audio = SDLAudio::get(); + audio->quit(); + return 0; + } + + static const luaL_Reg f[] = { {"init", l_init}, + {"play", l_play }, + {"stop", l_stop}, + {"pause", l_pause}, + {"resume", l_resume}, + {"setVolume",l_setVolume}, {"Sound", l_newSound}, + // + {"destroy",l_destroy}, {0, 0} }; + extern int luaopen_Source(lua_State* L); + int luaopen_audio(lua_State* L) { + luaopen_Source(L); + luax_newlib(L, f); return 1; diff --git a/src/lua/embed/boot.lua.h b/src/lua/embed/boot.lua.h index ab241f1..0b04fc1 100644 --- a/src/lua/embed/boot.lua.h +++ b/src/lua/embed/boot.lua.h @@ -19,7 +19,7 @@ conf.title = conf.title or ("jin v" .. jin.version()) -- initialize subsystems jin.graphics.init(conf) ---jin.audio.init(conf) +jin.audio.init(conf) -- open debug mode, must after jin.graphics.init if jin._argv[3] == '-d' then @@ -131,6 +131,7 @@ local function main() end -- quit subsystems jin.graphics.destroy() + jin.audio.destroy() -- exit whole game jin.core.quit() end |