diff --git a/platform/msvc2008/audio/audio.vcproj b/platform/msvc2008/audio/audio.vcproj index 421818471..dddaf7314 100644 --- a/platform/msvc2008/audio/audio.vcproj +++ b/platform/msvc2008/audio/audio.vcproj @@ -188,22 +188,6 @@ RelativePath="..\..\..\src\modules\audio\openal\Audio.h" > - - - - - - - @@ -220,22 +204,6 @@ RelativePath="..\..\..\src\modules\audio\openal\Pool.h" > - - - - - - - @@ -272,38 +240,6 @@ RelativePath="..\..\..\src\modules\audio\null\Audio.h" > - - - - - - - - - - - - - - @@ -321,22 +257,10 @@ > - - - - - - @@ -369,38 +293,6 @@ RelativePath="..\..\..\src\modules\audio\wrap_Audio.h" > - - - - - - - - - - - - - - diff --git a/platform/msvc2008/love.vcproj b/platform/msvc2008/love.vcproj index 714bb5ebb..e9c77141b 100644 --- a/platform/msvc2008/love.vcproj +++ b/platform/msvc2008/love.vcproj @@ -182,14 +182,6 @@ RelativePath="..\..\src\modules\audio\Audio.h" > - - - - @@ -238,54 +230,6 @@ RelativePath="..\..\src\modules\audio\wrap_Audio.h" > - - - - - - - - - - - - - - - - - - - - @@ -337,30 +281,6 @@ RelativePath="..\..\src\modules\audio\openal\Audio.h" > - - - - - - - - - - @@ -385,30 +305,6 @@ RelativePath="..\..\src\modules\audio\openal\Pool.h" > - - - - - - - - - - @@ -461,54 +357,6 @@ RelativePath="..\..\src\modules\audio\null\Audio.h" > - - - - - - - - - - - - - - - - - - - - diff --git a/platform/msvc2008/sound/sound.vcproj b/platform/msvc2008/sound/sound.vcproj index a0cee06ae..ec1e550bd 100644 --- a/platform/msvc2008/sound/sound.vcproj +++ b/platform/msvc2008/sound/sound.vcproj @@ -61,7 +61,7 @@ /> - - - - - - - diff --git a/src/common/runtime.cpp b/src/common/runtime.cpp index 3db3f3705..f102f9613 100644 --- a/src/common/runtime.cpp +++ b/src/common/runtime.cpp @@ -24,6 +24,7 @@ #include "Module.h" #include "Object.h" #include "Reference.h" +#include "StringMap.h" // STD #include @@ -50,6 +51,14 @@ namespace love return 1; } + static int w__typeOf(lua_State * L) + { + Proxy * p = (Proxy *)lua_touserdata(L, 1); + Type t = luax_type(L, 2); + luax_pushboolean(L, p->flags.at(t)); + return 1; + } + Reference * luax_refif(lua_State * L, int type) { Reference * r = 0; @@ -178,6 +187,15 @@ namespace love lua_pushcclosure(L, w__tostring, 1); lua_setfield(L, -2, "__tostring"); + // Add tostring to as type() as well. + lua_pushstring(L, tname); + lua_pushcclosure(L, w__tostring, 1); + lua_setfield(L, -2, "type"); + + // Add typeOf + lua_pushcfunction(L, w__typeOf); + lua_setfield(L, -2, "typeOf"); + if(f != 0) luaL_register(L, 0, f); @@ -316,5 +334,70 @@ namespace love } } + StringMap::Entry typeEntries[] = + { + {"Invalid", INVALID_ID}, + + {"Object", OBJECT_ID}, + {"Data", DATA_ID}, + {"Module", MODULE_ID}, + + // Filesystem + {"File", FILESYSTEM_FILE_ID}, + {"FileData", FILESYSTEM_FILE_DATA_ID}, + + // Font + {"GlyphData", FONT_GLYPH_DATA_ID}, + {"Rasterizer", FONT_RASTERIZER_ID}, + + // Graphics + {"Drawable", GRAPHICS_DRAWABLE_ID}, + {"Image", GRAPHICS_IMAGE_ID}, + {"Quad", GRAPHICS_QUAD_ID}, + {"Glyph", GRAPHICS_GLYPH_ID}, + {"Font", GRAPHICS_FONT_ID}, + {"ParticleSystem", GRAPHICS_PARTICLE_SYSTEM_ID}, + {"SpriteBatch", GRAPHICS_SPRITE_BATCH_ID}, + {"VertexBuffer", GRAPHICS_VERTEX_BUFFER_ID}, + + // Image + {"ImageData", IMAGE_IMAGE_DATA_ID}, + + // Audio + {"Source", AUDIO_SOURCE_ID}, + + // Sound + {"SoundData", SOUND_SOUND_DATA_ID}, + {"Decoder", SOUND_DECODER_ID}, + + // Physics + {"World", PHYSICS_WORLD_ID}, + {"Contact", PHYSICS_CONTACT_ID}, + {"Body", PHYSICS_BODY_ID}, + {"Shape", PHYSICS_SHAPE_ID}, + {"CircleShape", PHYSICS_CIRCLE_SHAPE_ID}, + {"PolygonShape", PHYSICS_POLYGON_SHAPE_ID}, + {"Joint", PHYSICS_JOINT_ID}, + {"MouseJoint", PHYSICS_MOUSE_JOINT_ID}, + {"DistanceJoint", PHYSICS_DISTANCE_JOINT_ID}, + {"PrismaticJoint", PHYSICS_PRISMATIC_JOINT_ID}, + {"RevoluteJoint", PHYSICS_REVOLUTE_JOINT_ID}, + {"PulleyJoint", PHYSICS_PULLEY_JOINT_ID}, + {"GearJoint", PHYSICS_GEAR_JOINT_ID}, + + // The modules themselves. Only add abstracted modules here. + {"filesystem", MODULE_FILESYSTEM_ID}, + {"image", MODULE_IMAGE_ID}, + {"sound", MODULE_SOUND_ID}, + }; + + StringMap types(typeEntries, sizeof(typeEntries)); + + Type luax_type(lua_State * L, int idx) + { + Type t = INVALID_ID; + types.find(luaL_checkstring(L, idx), t); + return t; + } } // love diff --git a/src/common/runtime.h b/src/common/runtime.h index 54fce90a6..8d155ede6 100644 --- a/src/common/runtime.h +++ b/src/common/runtime.h @@ -252,6 +252,8 @@ namespace love **/ int luax_getregistry(lua_State * L, Registry r); + Type luax_type(lua_State * L, int idx); + /** * Converts the value at idx to the specified type without checking that * this conversion is valid. If the type has been previously verified with diff --git a/src/common/types.h b/src/common/types.h index 448146df6..baf33f374 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -28,8 +28,9 @@ namespace love { enum Type { + INVALID_ID = 0, // Cross-module types. - OBJECT_ID = 0, + OBJECT_ID, DATA_ID, MODULE_ID, @@ -46,8 +47,6 @@ namespace love GRAPHICS_IMAGE_ID, GRAPHICS_QUAD_ID, GRAPHICS_GLYPH_ID, - GRAPHICS_ANIMATION_ID, - GRAPHICS_COLOR_ID, GRAPHICS_FONT_ID, GRAPHICS_PARTICLE_SYSTEM_ID, GRAPHICS_SPRITE_BATCH_ID, @@ -57,9 +56,6 @@ namespace love IMAGE_IMAGE_DATA_ID, // Audio - AUDIO_AUDIBLE_ID, - AUDIO_SOUND_ID, - AUDIO_MUSIC_ID, AUDIO_SOURCE_ID, // Sound @@ -87,10 +83,12 @@ namespace love MODULE_SOUND_ID, // Count the number of bits needed. - BIT_SIZE + TYPE_MAX_ENUM }; - typedef std::bitset bits; + typedef std::bitset bits; + + const bits INVALID_T = bits(1) << INVALID_ID; const bits OBJECT_T = bits(1) << OBJECT_ID; const bits DATA_T = (bits(1) << DATA_ID) | OBJECT_T; @@ -108,8 +106,6 @@ namespace love const bits GRAPHICS_IMAGE_T = (bits(1) << GRAPHICS_IMAGE_ID) | GRAPHICS_DRAWABLE_T; const bits GRAPHICS_QUAD_T = (bits(1) << GRAPHICS_QUAD_ID) | OBJECT_T; const bits GRAPHICS_GLYPH_T = (bits(1) << GRAPHICS_GLYPH_ID) | GRAPHICS_DRAWABLE_T; - const bits GRAPHICS_ANIMATION_T = (bits(1) << GRAPHICS_ANIMATION_ID) | GRAPHICS_DRAWABLE_T; - const bits GRAPHICS_COLOR_T = (bits(1) << GRAPHICS_COLOR_ID) | OBJECT_T; const bits GRAPHICS_FONT_T = (bits(1) << GRAPHICS_FONT_ID) | OBJECT_T; const bits GRAPHICS_PARTICLE_SYSTEM_T = (bits(1) << GRAPHICS_PARTICLE_SYSTEM_ID) | GRAPHICS_DRAWABLE_T; const bits GRAPHICS_SPRITE_BATCH_T = (bits(1) << GRAPHICS_SPRITE_BATCH_ID) | GRAPHICS_DRAWABLE_T; @@ -119,9 +115,6 @@ namespace love const bits IMAGE_IMAGE_DATA_T = (bits(1) << IMAGE_IMAGE_DATA_ID) | DATA_T; // Audio. - const bits AUDIO_AUDIBLE_T = (bits(1) << AUDIO_AUDIBLE_ID) | OBJECT_T; - const bits AUDIO_SOUND_T = (bits(1) << AUDIO_SOUND_ID) | AUDIO_AUDIBLE_T; - const bits AUDIO_MUSIC_T = (bits(1) << AUDIO_MUSIC_ID) | AUDIO_AUDIBLE_T; const bits AUDIO_SOURCE_T = (bits(1) << AUDIO_SOURCE_ID) | OBJECT_T; // Sound. @@ -148,6 +141,9 @@ namespace love const bits MODULE_IMAGE_T = (bits(1) << MODULE_IMAGE_ID) | MODULE_T; const bits MODULE_SOUND_T = (bits(1) << MODULE_SOUND_ID) | MODULE_T; + bool getType(const char * in, Type & out); + bool getType(Type in, const char *& out); + } // love #endif // LOVE_TYPES_H diff --git a/src/modules/audio/Audible.h b/src/modules/audio/Audible.h deleted file mode 100644 index 4352c3fc7..000000000 --- a/src/modules/audio/Audible.h +++ /dev/null @@ -1,48 +0,0 @@ -/** -* Copyright (c) 2006-2009 LOVE Development Team -* -* This software is provided 'as-is', without any express or implied -* warranty. In no event will the authors be held liable for any damages -* arising from the use of this software. -* -* Permission is granted to anyone to use this software for any purpose, -* including commercial applications, and to alter it and redistribute it -* freely, subject to the following restrictions: -* -* 1. The origin of this software must not be misrepresented; you must not -* claim that you wrote the original software. If you use this software -* in a product, an acknowledgment in the product documentation would be -* appreciated but is not required. -* 2. Altered source versions must be plainly marked as such, and must not be -* misrepresented as being the original software. -* 3. This notice may not be removed or altered from any source distribution. -**/ - -#ifndef LOVE_AUDIO_AUDIBLE_H -#define LOVE_AUDIO_AUDIBLE_H - -// LOVE -#include - -namespace love -{ -namespace audio -{ - class Source; - - class Audible : public Object - { - public: - - virtual ~Audible(){}; - virtual void play(Source * source) = 0; - virtual void update(Source * source) = 0; - virtual void stop(Source * source) = 0; - virtual void rewind(Source * source) = 0; - - }; // Audible - -} // audio -} // love - -#endif // LOVE_AUDIO_AUDIBLE_H \ No newline at end of file diff --git a/src/modules/audio/Audio.h b/src/modules/audio/Audio.h index 364f03191..b763b4bbc 100644 --- a/src/modules/audio/Audio.h +++ b/src/modules/audio/Audio.h @@ -23,11 +23,14 @@ #include #include "Source.h" -#include "Sound.h" -#include "Music.h" namespace love { +namespace sound +{ + class Decoder; + class SoundData; +} namespace audio { /** @@ -42,26 +45,9 @@ namespace audio **/ virtual ~Audio(){}; - /** - * Creates a new Sound with the specified SoundData. - * @param data The SoundData from which to create the sound. - * @return A new Sound if successful, zero otherwise. - **/ - virtual Sound * newSound(love::sound::SoundData * data) = 0; - - /** - * Creates a new Music (stream) using the specified SoundData. - * @param decoder The object to use to decode the sound stream. - **/ - virtual Music * newMusic(love::sound::Decoder * decoder) = 0; - - /** - * Creates a new Source. - * @returns A new Source. - **/ - virtual Source * newSource(Sound * sound) = 0; - virtual Source * newSource(Music * music) = 0; - + virtual Source * newSource(love::sound::Decoder * decoder) = 0; + virtual Source * newSource(love::sound::SoundData * soundData) = 0; + /** * Gets the current number of simulatenous playing sources. * @return The current number of simulatenous playing sources. @@ -80,26 +66,6 @@ namespace audio **/ virtual void play(Source * source) = 0; - /** - * Plays one Sound on the specified Source. We need separate - * Sound and Music play functions because Music must be cloned, - * whereas Sound needs not be. - * - * @param sound The Sound to play. - * @param source The Source on which to play the Sound. - **/ - virtual void play(Sound * sound) = 0; - - /** - * Plays one Music on the specified Source. We need separate - * Sound and Music play functions because Music must be cloned, - * whereas Sound needs not be. - * - * @param music The Music to play. - * @param source The Source on which to play the Music. - **/ - virtual void play(Music * music) = 0; - /** * Stops playback on the specified source. * @param source The source on which to stop the playback. diff --git a/src/modules/audio/Music.h b/src/modules/audio/Music.h deleted file mode 100644 index fdaeb90ec..000000000 --- a/src/modules/audio/Music.h +++ /dev/null @@ -1,63 +0,0 @@ -/** -* Copyright (c) 2006-2009 LOVE Development Team -* -* This software is provided 'as-is', without any express or implied -* warranty. In no event will the authors be held liable for any damages -* arising from the use of this software. -* -* Permission is granted to anyone to use this software for any purpose, -* including commercial applications, and to alter it and redistribute it -* freely, subject to the following restrictions: -* -* 1. The origin of this software must not be misrepresented; you must not -* claim that you wrote the original software. If you use this software -* in a product, an acknowledgment in the product documentation would be -* appreciated but is not required. -* 2. Altered source versions must be plainly marked as such, and must not be -* misrepresented as being the original software. -* 3. This notice may not be removed or altered from any source distribution. -**/ - -#ifndef LOVE_AUDIO_MUSIC_H -#define LOVE_AUDIO_MUSIC_H - -// LOVE -#include "Audible.h" -#include - -namespace love -{ -namespace audio -{ - /** - * A Music object represents a stream of sound samples which are gradually - * acquired somehow. Compare with Sounds, which have all the needed sound - * samples pre-decoded. - * - * Typically, you would want to use love::sound::Decoder to decode samples - * from some encoded format, like OGG or MP3, however, Music can come from - * other sources as well. - **/ - class Music : public Audible - { - public: - - /** - * Destructor. - **/ - virtual ~Music(){}; - - /** - * Creates a clone of the music stream. Music objects are gradually - * decoded, so if the client wants to play the same Music object, we can't - * use the same object. We must clone the entire stream. - * @return A clone of this object, but rewound to the start. - **/ - virtual Music * clone() = 0; - - }; // Music - -} // audio -} // love - -#endif // LOVE_AUDIO_MUSIC_H diff --git a/src/modules/audio/Sound.h b/src/modules/audio/Sound.h deleted file mode 100644 index 389fade89..000000000 --- a/src/modules/audio/Sound.h +++ /dev/null @@ -1,42 +0,0 @@ -/** -* Copyright (c) 2006-2009 LOVE Development Team -* -* This software is provided 'as-is', without any express or implied -* warranty. In no event will the authors be held liable for any damages -* arising from the use of this software. -* -* Permission is granted to anyone to use this software for any purpose, -* including commercial applications, and to alter it and redistribute it -* freely, subject to the following restrictions: -* -* 1. The origin of this software must not be misrepresented; you must not -* claim that you wrote the original software. If you use this software -* in a product, an acknowledgment in the product documentation would be -* appreciated but is not required. -* 2. Altered source versions must be plainly marked as such, and must not be -* misrepresented as being the original software. -* 3. This notice may not be removed or altered from any source distribution. -**/ - -#ifndef LOVE_AUDIO_SOUND_H -#define LOVE_AUDIO_SOUND_H - -// LOVE -#include -#include "Audible.h" - -namespace love -{ -namespace audio -{ - class Sound : public Audible - { - private: - public: - virtual ~Sound(){}; - }; // Sound - -} // audio -} // love - -#endif // LOVE_AUDIO_SOUND_H \ No newline at end of file diff --git a/src/modules/audio/Source.cpp b/src/modules/audio/Source.cpp index 9ec9a8ae1..cc36f3126 100644 --- a/src/modules/audio/Source.cpp +++ b/src/modules/audio/Source.cpp @@ -24,47 +24,32 @@ namespace love { namespace audio { - Source::Source() - : audible(0), looping(false) + Source::Source(Type type) + : type(type) { } Source::~Source() { - if(audible != 0) - { - audible->stop(this); - audible->release(); - } - } - - void Source::setAudible(Audible * audible) - { - // If this source already has an audible, remove it. - if(this->audible != 0) - { - this->audible->stop(this); - this->audible->release(); - } - - this->audible = audible; - audible->retain(); - } - - Audible * Source::getAudible() const - { - return audible; } - void Source::setLooping(bool looping) + bool Source::getConstant(const char * in, Type & out) { - this->looping = looping; + return types.find(in, out); } - bool Source::isLooping() const - { - return looping; + bool Source::getConstant(Type in, const char *& out) + { + return types.find(in, out); } + StringMap::Entry Source::typeEntries[] = + { + {"static", Source::TYPE_STATIC}, + {"stream", Source::TYPE_STREAM}, + }; + + StringMap Source::types(Source::typeEntries, sizeof(Source::typeEntries)); + } // audio } // love diff --git a/src/modules/audio/Source.h b/src/modules/audio/Source.h index 82a6dcd19..1f9d0263b 100644 --- a/src/modules/audio/Source.h +++ b/src/modules/audio/Source.h @@ -23,7 +23,7 @@ // LOVE #include -#include "Audible.h" +#include namespace love { @@ -31,14 +31,23 @@ namespace audio { class Source : public Object { - protected: - Audible * audible; - bool looping; public: - Source(); + + enum Type + { + TYPE_STATIC = 1, + TYPE_STREAM, + TYPE_MAX_ENUM + }; // Type + + protected: + Type type; + public: + + Source(Type type); virtual ~Source(); - void setAudible(Audible * audible); - Audible * getAudible() const; + + virtual Source * copy() = 0; virtual void play() = 0; virtual void stop() = 0; @@ -46,6 +55,7 @@ namespace audio virtual void resume() = 0; virtual void rewind() = 0; virtual bool isStopped() const = 0; + virtual bool isFinished() const = 0; virtual void update() = 0; virtual void setPitch(float pitch) = 0; @@ -62,8 +72,16 @@ namespace audio virtual void setDirection(float * v) = 0; virtual void getDirection(float * v) const = 0; - void setLooping(bool looping); - bool isLooping() const; + virtual void setLooping(bool looping) = 0; + virtual bool isLooping() const = 0; + + static bool getConstant(const char * in, Type & out); + static bool getConstant(Type in, const char *& out); + + private: + + static StringMap::Entry typeEntries[]; + static StringMap types; }; // Source diff --git a/src/modules/audio/null/Audio.cpp b/src/modules/audio/null/Audio.cpp index 57ccbf29d..c09c5fbc2 100644 --- a/src/modules/audio/null/Audio.cpp +++ b/src/modules/audio/null/Audio.cpp @@ -39,22 +39,12 @@ namespace null return "love.audio.null"; } - love::audio::Sound * Audio::newSound(love::sound::SoundData * data) - { - return new Sound(data); - } - - love::audio::Music * Audio::newMusic(love::sound::Decoder * decoder) - { - return new Music(decoder); - } - - love::audio::Source * Audio::newSource(love::audio::Sound * sound) + love::audio::Source * Audio::newSource(love::sound::Decoder * decoder) { return new Source(); } - love::audio::Source * Audio::newSource(love::audio::Music * music) + love::audio::Source * Audio::newSource(love::sound::SoundData * soundData) { return new Source(); } @@ -73,14 +63,6 @@ namespace null { } - void Audio::play(love::audio::Sound * sound) - { - } - - void Audio::play(love::audio::Music * music) - { - } - void Audio::play() { } diff --git a/src/modules/audio/null/Audio.h b/src/modules/audio/null/Audio.h index ff6bddd5f..2e3549ce7 100644 --- a/src/modules/audio/null/Audio.h +++ b/src/modules/audio/null/Audio.h @@ -24,8 +24,6 @@ // LOVE #include