diff --git a/src/common/runtime.cpp b/src/common/runtime.cpp index e03f0b22d..227356a23 100644 --- a/src/common/runtime.cpp +++ b/src/common/runtime.cpp @@ -104,7 +104,7 @@ namespace love int luax_register_gc(lua_State * L, const char * mname, Module * m) { lua_getglobal(L, "love"); - lua_getfield(L, -1, "__fin"); + lua_getfield(L, -1, "_fin"); userdata * u = (userdata *)lua_newuserdata(L, sizeof(userdata)); u->own = true; @@ -117,7 +117,7 @@ namespace love lua_setfield(L, -2, mname); - lua_pop(L, 2); // __fin, love + lua_pop(L, 2); // _fin, love return 0; } diff --git a/src/love.cpp b/src/love.cpp index 812e2dc84..9428596d9 100644 --- a/src/love.cpp +++ b/src/love.cpp @@ -63,9 +63,9 @@ DECLSPEC int luaopen_love(lua_State * L) lua_setfield(L, -2, love::lua_constants[i].name); } - // Create the __fin table. + // Create the _fin table. lua_newtable(L); - lua_setfield(L, -2, "__fin"); + lua_setfield(L, -2, "_fin"); // Resources. love::luax_newtype(L, "Data", love::LOVE_DATA_BITS, new love::MemoryData((void*)love::Vera_ttf_data, love::Vera_ttf_size)); @@ -115,7 +115,7 @@ int main(int argc, char ** argv) lua_pushstring(L, argv[i]); lua_rawseti(L, -2, i); } - lua_setfield(L, -2, "__args"); + lua_setfield(L, -2, "_args"); lua_pop(L, 1); } @@ -126,7 +126,7 @@ int main(int argc, char ** argv) { lua_getglobal(L, "love"); lua_pushboolean(L, 1); - lua_setfield(L, -2, "__exe"); + lua_setfield(L, -2, "_exe"); lua_pop(L, 1); } diff --git a/src/modules/audio/Source.cpp b/src/modules/audio/Source.cpp index 283267a1c..9ec9a8ae1 100644 --- a/src/modules/audio/Source.cpp +++ b/src/modules/audio/Source.cpp @@ -25,7 +25,7 @@ namespace love namespace audio { Source::Source() - : audible(0) + : audible(0), looping(false) { } @@ -56,5 +56,15 @@ namespace audio return audible; } + void Source::setLooping(bool looping) + { + this->looping = looping; + } + + bool Source::isLooping() const + { + return looping; + } + } // audio } // love diff --git a/src/modules/audio/Source.h b/src/modules/audio/Source.h index 409f41e28..074c465a7 100644 --- a/src/modules/audio/Source.h +++ b/src/modules/audio/Source.h @@ -33,6 +33,7 @@ namespace audio { protected: Audible * audible; + bool looping; public: Source(); virtual ~Source(); @@ -52,6 +53,9 @@ namespace audio virtual void setVolume(float volume) = 0; virtual float getVolume() const = 0; + + void setLooping(bool looping); + bool isLooping() const; }; // Source diff --git a/src/modules/audio/openal/Music.cpp b/src/modules/audio/openal/Music.cpp index f200ec95d..1d6080a03 100644 --- a/src/modules/audio/openal/Music.cpp +++ b/src/modules/audio/openal/Music.cpp @@ -55,7 +55,7 @@ namespace openal { for(int i = 0; i < NUM_BUFFERS; i++) { - if(!stream(buffers[i])) + if(!stream(s, buffers[i])) { std::cout << "Could not stream music." << std::endl; return; @@ -82,7 +82,7 @@ namespace openal // Get a free buffer. alSourceUnqueueBuffers(source, 1, &buffer); - if(stream(buffer)) + if(stream(s, buffer)) alSourceQueueBuffers(source, 1, &buffer); } } @@ -111,8 +111,11 @@ namespace openal play(s); } - bool Music::stream(ALuint buffer) + bool Music::stream(love::audio::Source * source, ALuint buffer) { + if(source->isLooping() && decoder->isFinished()) + decoder->rewind(); + // Get more sound data. int decoded = decoder->decode(); @@ -131,6 +134,7 @@ namespace openal return false; } + } // openal } // audio } // love \ No newline at end of file diff --git a/src/modules/audio/openal/Music.h b/src/modules/audio/openal/Music.h index ad69fee9d..69d642c66 100644 --- a/src/modules/audio/openal/Music.h +++ b/src/modules/audio/openal/Music.h @@ -48,10 +48,10 @@ namespace openal Pool * pool; love::sound::Decoder * decoder; ALuint source; + public: Music(Pool * pool, love::sound::Decoder * decoder); virtual ~Music(); - // Implements Audible. void play(love::audio::Source * source); @@ -63,7 +63,7 @@ namespace openal love::audio::Music * clone(); private: - bool stream(ALuint buffer); + bool stream(love::audio::Source * source, ALuint buffer); }; // Sound } // openal diff --git a/src/modules/audio/openal/Sound.cpp b/src/modules/audio/openal/Sound.cpp index 18c7e886b..ec4cdc740 100644 --- a/src/modules/audio/openal/Sound.cpp +++ b/src/modules/audio/openal/Sound.cpp @@ -58,12 +58,16 @@ namespace openal source = pool->find(s); if(source) + { alSourcei(source, AL_BUFFER, buffer); + alSourcei(source, AL_LOOPING, s->isLooping() ? AL_TRUE : AL_FALSE); + } } void Sound::update(love::audio::Source * s) { - // No need. + // Looping mode could have changed. + alSourcei(source, AL_LOOPING, s->isLooping() ? AL_TRUE : AL_FALSE); } void Sound::stop(love::audio::Source * s) diff --git a/src/modules/audio/wrap_Source.cpp b/src/modules/audio/wrap_Source.cpp index 19e6d43fd..4e06eae32 100644 --- a/src/modules/audio/wrap_Source.cpp +++ b/src/modules/audio/wrap_Source.cpp @@ -59,11 +59,28 @@ namespace audio return 1; } + int _wrap_Source_setLooping(lua_State * L) + { + Source * t = luax_checksource(L, 1); + t->setLooping(luax_toboolean(L, 2)); + return 0; + } + + int _wrap_Source_isLooping(lua_State * L) + { + Source * t = luax_checksource(L, 1); + luax_pushboolean(L, t->isLooping()); + return 1; + } + + static const luaL_Reg wrap_Source_functions[] = { { "setPitch", _wrap_Source_setPitch }, { "getPitch", _wrap_Source_getPitch }, { "setVolume", _wrap_Source_setVolume }, { "getVolume", _wrap_Source_getVolume }, + { "setLooping", _wrap_Source_setLooping }, + { "isLooping", _wrap_Source_isLooping }, { 0, 0 } }; diff --git a/src/modules/audio/wrap_Source.h b/src/modules/audio/wrap_Source.h index e41c03922..24e565ec3 100644 --- a/src/modules/audio/wrap_Source.h +++ b/src/modules/audio/wrap_Source.h @@ -33,6 +33,8 @@ namespace audio int _wrap_Source_getPitch(lua_State * L); int _wrap_Source_setVolume(lua_State * L); int _wrap_Source_getVolume(lua_State * L); + int _wrap_Source_setLooping(lua_State * L); + int _wrap_Source_isLooping(lua_State * L); int wrap_Source_open(lua_State * L); } // audio diff --git a/src/modules/filesystem/physfs/Filesystem.cpp b/src/modules/filesystem/physfs/Filesystem.cpp index 55fe85af5..8a5c0a4c7 100644 --- a/src/modules/filesystem/physfs/Filesystem.cpp +++ b/src/modules/filesystem/physfs/Filesystem.cpp @@ -32,9 +32,7 @@ namespace physfs Filesystem::Filesystem() : open_count(0), buffer(0) { - // TODO: love.exe << fail - if(!PHYSFS_init("love.exe")) - throw Exception(PHYSFS_getLastError()); + } Filesystem::~Filesystem() @@ -47,6 +45,12 @@ namespace physfs return "love.filesystem.physfs"; } + void Filesystem::init(const char * arg0) + { + if(!PHYSFS_init(arg0)) + throw Exception(PHYSFS_getLastError()); + } + bool Filesystem::setIdentity( const char * ident ) { // Check whether save directory is already set. diff --git a/src/modules/filesystem/physfs/Filesystem.h b/src/modules/filesystem/physfs/Filesystem.h index 109806035..f199adf78 100644 --- a/src/modules/filesystem/physfs/Filesystem.h +++ b/src/modules/filesystem/physfs/Filesystem.h @@ -91,10 +91,13 @@ namespace physfs public: Filesystem(); + ~Filesystem(); const char * getName() const; + void init(const char * arg0); + /** * This sets up the save directory. If the * it is already set up, nothing happens. diff --git a/src/modules/filesystem/physfs/wrap_Filesystem.cpp b/src/modules/filesystem/physfs/wrap_Filesystem.cpp index bc6ca6fd3..6c83b3df9 100644 --- a/src/modules/filesystem/physfs/wrap_Filesystem.cpp +++ b/src/modules/filesystem/physfs/wrap_Filesystem.cpp @@ -36,6 +36,22 @@ namespace physfs return false; } + int _wrap_init(lua_State * L) + { + const char * arg0 = luaL_checkstring(L, 1); + + try + { + instance->init(arg0); + } + catch(Exception & e) + { + return luaL_error(L, e.what()); + } + + return 0; + } + int _wrap_setIdentity(lua_State * L) { const char * arg = luaL_checkstring(L, 1); @@ -200,6 +216,7 @@ namespace physfs // List of functions to wrap. const luaL_Reg wrap_Filesystem_functions[] = { + { "init", _wrap_init }, { "setIdentity", _wrap_setIdentity }, { "setSource", _wrap_setSource }, { "newFile", _wrap_newFile }, diff --git a/src/modules/filesystem/physfs/wrap_Filesystem.h b/src/modules/filesystem/physfs/wrap_Filesystem.h index 6f9c65623..cfb60c0fe 100644 --- a/src/modules/filesystem/physfs/wrap_Filesystem.h +++ b/src/modules/filesystem/physfs/wrap_Filesystem.h @@ -33,6 +33,7 @@ namespace filesystem namespace physfs { bool hack_setupWriteDirectory(); + int _wrap_init(lua_State * L); int _wrap_setIdentity(lua_State * L); int _wrap_setSource(lua_State * L); int _wrap_newFile(lua_State * L); diff --git a/src/scripts/boot.lua b/src/scripts/boot.lua index 0f2885e39..ffc215a2c 100644 --- a/src/scripts/boot.lua +++ b/src/scripts/boot.lua @@ -96,15 +96,16 @@ function love.boot() require("love.filesystem") -- Prints the arguments passes to the app. - if love.__args then - for i,v in pairs(love.__args) do + if love._args then + for i,v in pairs(love._args) do print(i,v) end end -- Sets the source for the game. - if love.__args[1] and love.__args[1] ~= "" then - love.filesystem.setSource(love.path.getfull(love.__args[1])) + if love._args[1] and love._args[1] ~= "" then + love.filesystem.init(love._args[0]) + love.filesystem.setSource(love.path.getfull(love._args[1])) else -- Do not set a source, load the default game. love.defaultscreen()