mirror of
https://github.com/love2d/love.git
synced 2026-08-15 07:41:11 +02:00
Initial Mercurial commit.
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* 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 <common/Object.h>
|
||||
|
||||
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
|
||||
@@ -0,0 +1,164 @@
|
||||
/**
|
||||
* 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 = 0; 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_AUDIO_H
|
||||
#define LOVE_AUDIO_AUDIO_H
|
||||
|
||||
#include <common/Module.h>
|
||||
#include "Source.h"
|
||||
#include "Sound.h"
|
||||
#include "Music.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
/**
|
||||
* The Audio module is responsible for playing back raw sound samples.
|
||||
**/
|
||||
class Audio : public Module
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
**/
|
||||
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() = 0;
|
||||
|
||||
/**
|
||||
* Gets the current number of simulatenous playing sources.
|
||||
* @return The current number of simulatenous playing sources.
|
||||
**/
|
||||
virtual int getNumSources() const = 0;
|
||||
|
||||
/**
|
||||
* Gets the maximum supported number of simulatenous playing sources.
|
||||
* @return The maximum supported number of simulatenous playing sources.
|
||||
**/
|
||||
virtual int getMaxSources() const = 0;
|
||||
|
||||
/**
|
||||
* Play the specified Source.
|
||||
* @param source The Source to play.
|
||||
**/
|
||||
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.
|
||||
**/
|
||||
virtual void stop(Source * source) = 0;
|
||||
|
||||
/**
|
||||
* Stops all playing audio.
|
||||
**/
|
||||
virtual void stop() = 0;
|
||||
|
||||
/**
|
||||
* Pauses playback on the specified source.
|
||||
* @param source The source on which to pause the playback.
|
||||
**/
|
||||
virtual void pause(Source * source) = 0;
|
||||
|
||||
/**
|
||||
* Pauses all audio.
|
||||
**/
|
||||
virtual void pause() = 0;
|
||||
|
||||
/**
|
||||
* Resumes playback on the specified source.
|
||||
* @param source The source on which to resume the playback.
|
||||
**/
|
||||
virtual void resume(Source * source) = 0;
|
||||
|
||||
/**
|
||||
* Resumes all audio.
|
||||
**/
|
||||
virtual void resume() = 0;
|
||||
|
||||
/**
|
||||
* Rewinds the specified source. Whatever is playing on this
|
||||
* source gets rewound to the start.
|
||||
* @param source The source to rewind.
|
||||
**/
|
||||
virtual void rewind(Source * source) = 0;
|
||||
|
||||
/**
|
||||
* Rewinds all playing audio.
|
||||
**/
|
||||
virtual void rewind() = 0;
|
||||
|
||||
/**
|
||||
* Sets the master volume, where 0.0f is min (off) and 1.0f is max.
|
||||
* @param volume The new master volume.
|
||||
**/
|
||||
virtual void setVolume(float volume) = 0;
|
||||
|
||||
/**
|
||||
* Gets the master volume.
|
||||
* @return The current master volume.
|
||||
**/
|
||||
virtual float getVolume() const = 0;
|
||||
|
||||
}; // Audio
|
||||
|
||||
} // audio
|
||||
} // love
|
||||
|
||||
#endif // LOVE_AUDIO_AUDIO_H
|
||||
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* 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 <sound/Decoder.h>
|
||||
|
||||
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
|
||||
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* 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 <sound/SoundData.h>
|
||||
#include "Audible.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
class Sound : public Audible
|
||||
{
|
||||
private:
|
||||
public:
|
||||
virtual ~Sound(){};
|
||||
}; // Sound
|
||||
|
||||
} // audio
|
||||
} // love
|
||||
|
||||
#endif // LOVE_AUDIO_SOUND_H
|
||||
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#include "Source.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
Source::Source()
|
||||
: audible(0)
|
||||
{
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
} // audio
|
||||
} // love
|
||||
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* 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_SOURCE_H
|
||||
#define LOVE_AUDIO_SOURCE_H
|
||||
|
||||
// LOVE
|
||||
#include <common/Object.h>
|
||||
#include "Audible.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
class Source : public Object
|
||||
{
|
||||
protected:
|
||||
Audible * audible;
|
||||
public:
|
||||
Source();
|
||||
virtual ~Source();
|
||||
void setAudible(Audible * audible);
|
||||
Audible * getAudible() const;
|
||||
|
||||
virtual void play() = 0;
|
||||
virtual void stop() = 0;
|
||||
virtual void pause() = 0;
|
||||
virtual void resume() = 0;
|
||||
virtual void rewind() = 0;
|
||||
virtual bool isFinished() const = 0;
|
||||
virtual void update() = 0;
|
||||
|
||||
virtual void setPitch(float pitch) = 0;
|
||||
virtual float getPitch() const = 0;
|
||||
|
||||
virtual void setVolume(float volume) = 0;
|
||||
virtual float getVolume() const = 0;
|
||||
|
||||
}; // Source
|
||||
|
||||
} // audio
|
||||
} // love
|
||||
|
||||
#endif // LOVE_AUDIO_SOURCE_H
|
||||
@@ -0,0 +1,127 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#include "Audio.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
namespace null
|
||||
{
|
||||
Audio::Audio()
|
||||
{
|
||||
}
|
||||
|
||||
Audio::~Audio()
|
||||
{
|
||||
}
|
||||
|
||||
const char * Audio::getName() const
|
||||
{
|
||||
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()
|
||||
{
|
||||
return new Source();
|
||||
}
|
||||
|
||||
int Audio::getNumSources() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Audio::getMaxSources() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Audio::play(love::audio::Source * source)
|
||||
{
|
||||
}
|
||||
|
||||
void Audio::play(love::audio::Sound * sound)
|
||||
{
|
||||
}
|
||||
|
||||
void Audio::play(love::audio::Music * music)
|
||||
{
|
||||
}
|
||||
|
||||
void Audio::play()
|
||||
{
|
||||
}
|
||||
|
||||
void Audio::stop(love::audio::Source * source)
|
||||
{
|
||||
}
|
||||
|
||||
void Audio::stop()
|
||||
{
|
||||
}
|
||||
|
||||
void Audio::pause(love::audio::Source * source)
|
||||
{
|
||||
}
|
||||
|
||||
void Audio::pause()
|
||||
{
|
||||
}
|
||||
|
||||
void Audio::resume(love::audio::Source * source)
|
||||
{
|
||||
}
|
||||
|
||||
void Audio::resume()
|
||||
{
|
||||
}
|
||||
|
||||
void Audio::rewind(love::audio::Source * source)
|
||||
{
|
||||
}
|
||||
|
||||
void Audio::rewind()
|
||||
{
|
||||
}
|
||||
|
||||
void Audio::setVolume(float volume)
|
||||
{
|
||||
this->volume = volume;
|
||||
}
|
||||
|
||||
float Audio::getVolume() const
|
||||
{
|
||||
return volume;
|
||||
}
|
||||
|
||||
} // null
|
||||
} // audio
|
||||
} // love
|
||||
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* 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_NULL_AUDIO_H
|
||||
#define LOVE_AUDIO_NULL_AUDIO_H
|
||||
|
||||
// LOVE
|
||||
#include <audio/Audio.h>
|
||||
|
||||
#include "Sound.h"
|
||||
#include "Music.h"
|
||||
#include "Source.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
namespace null
|
||||
{
|
||||
class Audio : public love::audio::Audio
|
||||
{
|
||||
private:
|
||||
float volume;
|
||||
public:
|
||||
|
||||
Audio();
|
||||
~Audio();
|
||||
|
||||
// Implements Module.
|
||||
const char * getName() const;
|
||||
|
||||
// Implements Audio.
|
||||
love::audio::Sound * newSound(love::sound::SoundData * data);
|
||||
love::audio::Music * newMusic(love::sound::Decoder * decoder);
|
||||
love::audio::Source * newSource();
|
||||
int getNumSources() const;
|
||||
int getMaxSources() const;
|
||||
void play(love::audio::Source * source);
|
||||
void play(love::audio::Sound * sound);
|
||||
void play(love::audio::Music * music);
|
||||
void play();
|
||||
void stop(love::audio::Source * source);
|
||||
void stop();
|
||||
void pause(love::audio::Source * source);
|
||||
void pause();
|
||||
void resume(love::audio::Source * source);
|
||||
void resume();
|
||||
void rewind(love::audio::Source * source);
|
||||
void rewind();
|
||||
void setVolume(float volume);
|
||||
float getVolume() const;
|
||||
|
||||
}; // Audio
|
||||
|
||||
} // null
|
||||
} // audio
|
||||
} // love
|
||||
|
||||
#endif // LOVE_AUDIO_NULL_AUDIO_H
|
||||
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#include "Music.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
namespace null
|
||||
{
|
||||
Music::Music(love::sound::Decoder * decoder)
|
||||
: decoder(decoder)
|
||||
{
|
||||
decoder->retain();
|
||||
}
|
||||
|
||||
Music::~Music()
|
||||
{
|
||||
decoder->release();
|
||||
}
|
||||
|
||||
love::audio::Music * Music::clone()
|
||||
{
|
||||
return new Music(decoder->clone());
|
||||
}
|
||||
|
||||
void Music::play(love::audio::Source * s)
|
||||
{
|
||||
}
|
||||
|
||||
void Music::update(love::audio::Source * s)
|
||||
{
|
||||
}
|
||||
|
||||
void Music::stop(love::audio::Source * s)
|
||||
{
|
||||
}
|
||||
|
||||
void Music::rewind(love::audio::Source * s)
|
||||
{
|
||||
}
|
||||
|
||||
} // null
|
||||
} // audio
|
||||
} // love
|
||||
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* 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_NULL_MUSIC_H
|
||||
#define LOVE_AUDIO_NULL_MUSIC_H
|
||||
|
||||
// LOVE
|
||||
#include <audio/Music.h>
|
||||
#include <sound/Decoder.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
namespace null
|
||||
{
|
||||
class Music : public love::audio::Music
|
||||
{
|
||||
private:
|
||||
love::sound::Decoder * decoder;
|
||||
public:
|
||||
Music(love::sound::Decoder * decoder);
|
||||
virtual ~Music();
|
||||
|
||||
// Implements Audible.
|
||||
void play(love::audio::Source * source);
|
||||
void update(love::audio::Source * source);
|
||||
void stop(love::audio::Source * source);
|
||||
void rewind(love::audio::Source * source);
|
||||
|
||||
// Implements Music.
|
||||
love::audio::Music * clone();
|
||||
|
||||
}; // Music
|
||||
|
||||
} // null
|
||||
} // audio
|
||||
} // love
|
||||
|
||||
#endif // LOVE_AUDIO_NULL_MUSIC_H
|
||||
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#include "Sound.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
namespace null
|
||||
{
|
||||
Sound::Sound(love::sound::SoundData * data)
|
||||
{
|
||||
}
|
||||
|
||||
Sound::~Sound()
|
||||
{
|
||||
}
|
||||
|
||||
void Sound::play(love::audio::Source * s)
|
||||
{
|
||||
}
|
||||
|
||||
void Sound::update(love::audio::Source * s)
|
||||
{
|
||||
}
|
||||
|
||||
void Sound::stop(love::audio::Source * s)
|
||||
{
|
||||
}
|
||||
|
||||
void Sound::rewind(love::audio::Source * s)
|
||||
{
|
||||
}
|
||||
|
||||
} // null
|
||||
} // audio
|
||||
} // love
|
||||
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* 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_NULL_SOUND_H
|
||||
#define LOVE_AUDIO_NULL_SOUND_H
|
||||
|
||||
// LOVE
|
||||
#include <sound/SoundData.h>
|
||||
#include <audio/Sound.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
namespace null
|
||||
{
|
||||
class Sound : public love::audio::Sound
|
||||
{
|
||||
private:
|
||||
|
||||
public:
|
||||
Sound(love::sound::SoundData * data);
|
||||
virtual ~Sound();
|
||||
|
||||
// Implements Audible.
|
||||
void play(love::audio::Source * s);
|
||||
void update(love::audio::Source * s);
|
||||
void stop(love::audio::Source * s);
|
||||
void rewind(love::audio::Source * s);
|
||||
|
||||
}; // Sound
|
||||
|
||||
} // null
|
||||
} // audio
|
||||
} // love
|
||||
|
||||
#endif // LOVE_AUDIO_NULL_SOUND_H
|
||||
@@ -0,0 +1,94 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#include "Source.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
namespace null
|
||||
{
|
||||
|
||||
Source::Source()
|
||||
{
|
||||
}
|
||||
|
||||
Source::Source(Audible * audible)
|
||||
{
|
||||
setAudible(audible);
|
||||
}
|
||||
|
||||
Source::~Source()
|
||||
{
|
||||
}
|
||||
|
||||
void Source::play()
|
||||
{
|
||||
}
|
||||
|
||||
void Source::stop()
|
||||
{
|
||||
}
|
||||
|
||||
void Source::pause()
|
||||
{
|
||||
}
|
||||
|
||||
void Source::resume()
|
||||
{
|
||||
}
|
||||
|
||||
void Source::rewind()
|
||||
{
|
||||
}
|
||||
|
||||
bool Source::isFinished() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void Source::update()
|
||||
{
|
||||
}
|
||||
|
||||
void Source::setPitch(float pitch)
|
||||
{
|
||||
this->pitch = pitch;
|
||||
}
|
||||
|
||||
float Source::getPitch() const
|
||||
{
|
||||
return pitch;
|
||||
}
|
||||
|
||||
void Source::setVolume(float volume)
|
||||
{
|
||||
this->volume = volume;
|
||||
}
|
||||
|
||||
float Source::getVolume() const
|
||||
{
|
||||
return volume;
|
||||
}
|
||||
|
||||
} // null
|
||||
} // audio
|
||||
} // love
|
||||
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* 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_NULL_SOURCE_H
|
||||
#define LOVE_AUDIO_NULL_SOURCE_H
|
||||
|
||||
// LOVE
|
||||
#include <common/Object.h>
|
||||
#include <audio/Source.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
namespace null
|
||||
{
|
||||
class Source : public love::audio::Source
|
||||
{
|
||||
private:
|
||||
|
||||
float pitch;
|
||||
float volume;
|
||||
|
||||
public:
|
||||
Source();
|
||||
Source(Audible * audible);
|
||||
virtual ~Source();
|
||||
|
||||
void play();
|
||||
void stop();
|
||||
void pause();
|
||||
void resume();
|
||||
void rewind();
|
||||
bool isFinished() const;
|
||||
void update();
|
||||
|
||||
void setPitch(float pitch);
|
||||
float getPitch() const;
|
||||
|
||||
void setVolume(float volume);
|
||||
float getVolume() const;
|
||||
|
||||
}; // Source
|
||||
|
||||
} // null
|
||||
} // audio
|
||||
} // love
|
||||
|
||||
#endif // LOVE_AUDIO_NULL_SOURCE_H
|
||||
@@ -0,0 +1,180 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#include "Audio.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
namespace openal
|
||||
{
|
||||
Audio::Audio()
|
||||
{
|
||||
// Passing zero for default device.
|
||||
device = alcOpenDevice(0);
|
||||
|
||||
if(device == 0)
|
||||
throw love::Exception("Could not open device.");
|
||||
|
||||
context = alcCreateContext(device, 0);
|
||||
|
||||
if(context == 0)
|
||||
throw love::Exception("Could not create context.");
|
||||
|
||||
alcMakeContextCurrent(context);
|
||||
|
||||
if(alcGetError(device) != ALC_NO_ERROR)
|
||||
throw love::Exception("Could not make context current.");
|
||||
|
||||
// pool must be allocated after AL context.
|
||||
pool = new Pool();
|
||||
|
||||
thread = SDL_CreateThread(Audio::run, (void*)this);
|
||||
}
|
||||
|
||||
Audio::~Audio()
|
||||
{
|
||||
SDL_KillThread(thread);
|
||||
|
||||
delete pool;
|
||||
|
||||
alcMakeContextCurrent(0);
|
||||
alcDestroyContext(context);
|
||||
alcCloseDevice(device);
|
||||
}
|
||||
|
||||
int Audio::run(void * d)
|
||||
{
|
||||
Audio * instance = (Audio*)d;
|
||||
|
||||
while(true)
|
||||
{
|
||||
instance->pool->update();
|
||||
SDL_Delay(10);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char * Audio::getName() const
|
||||
{
|
||||
return "love.audio.openal";
|
||||
}
|
||||
|
||||
love::audio::Sound * Audio::newSound(love::sound::SoundData * data)
|
||||
{
|
||||
return new Sound(pool, data);
|
||||
}
|
||||
|
||||
love::audio::Music * Audio::newMusic(love::sound::Decoder * decoder)
|
||||
{
|
||||
return new Music(pool, decoder);
|
||||
}
|
||||
|
||||
love::audio::Source * Audio::newSource()
|
||||
{
|
||||
return new Source(pool);
|
||||
}
|
||||
|
||||
int Audio::getNumSources() const
|
||||
{
|
||||
return pool->getNumSources();
|
||||
}
|
||||
|
||||
int Audio::getMaxSources() const
|
||||
{
|
||||
return pool->getMaxSources();
|
||||
}
|
||||
|
||||
void Audio::play(love::audio::Source * source)
|
||||
{
|
||||
source->play();
|
||||
}
|
||||
|
||||
void Audio::play(love::audio::Sound * sound)
|
||||
{
|
||||
Source * source = new Source(pool, sound);
|
||||
play(source);
|
||||
source->release();
|
||||
}
|
||||
|
||||
void Audio::play(love::audio::Music * music)
|
||||
{
|
||||
Source * source = new Source(pool, music->clone());
|
||||
play(source);
|
||||
source->release();
|
||||
}
|
||||
|
||||
void Audio::stop(love::audio::Source * source)
|
||||
{
|
||||
source->stop();
|
||||
}
|
||||
|
||||
void Audio::stop()
|
||||
{
|
||||
pool->stop();
|
||||
}
|
||||
|
||||
void Audio::pause(love::audio::Source * source)
|
||||
{
|
||||
source->pause();
|
||||
}
|
||||
|
||||
void Audio::pause()
|
||||
{
|
||||
pool->pause();
|
||||
}
|
||||
|
||||
void Audio::resume(love::audio::Source * source)
|
||||
{
|
||||
source->resume();
|
||||
}
|
||||
|
||||
void Audio::resume()
|
||||
{
|
||||
pool->resume();
|
||||
}
|
||||
|
||||
void Audio::rewind(love::audio::Source * source)
|
||||
{
|
||||
source->rewind();
|
||||
}
|
||||
|
||||
void Audio::rewind()
|
||||
{
|
||||
pool->rewind();
|
||||
}
|
||||
|
||||
void Audio::setVolume(float volume)
|
||||
{
|
||||
alListenerf(AL_GAIN, volume);
|
||||
}
|
||||
|
||||
float Audio::getVolume() const
|
||||
{
|
||||
ALfloat volume;
|
||||
alGetListenerf(AL_GAIN, &volume);
|
||||
return volume;
|
||||
}
|
||||
|
||||
} // openal
|
||||
} // audio
|
||||
} // love
|
||||
@@ -0,0 +1,106 @@
|
||||
/**
|
||||
* 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_OPENAL_AUDIO_H
|
||||
#define LOVE_AUDIO_OPENAL_AUDIO_H
|
||||
|
||||
// STD
|
||||
#include <queue>
|
||||
#include <map>
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
// SDL
|
||||
#include <SDL.h>
|
||||
|
||||
// OpenAL
|
||||
#include <AL/alc.h>
|
||||
#include <AL/al.h>
|
||||
|
||||
// LOVE
|
||||
#include <audio/Audio.h>
|
||||
#include <common/config.h>
|
||||
#include <common/constants.h>
|
||||
#include <sound/SoundData.h>
|
||||
|
||||
#include "Sound.h"
|
||||
#include "Music.h"
|
||||
#include "Source.h"
|
||||
#include "Pool.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
namespace openal
|
||||
{
|
||||
class Audio : public love::audio::Audio
|
||||
{
|
||||
private:
|
||||
|
||||
// The OpenAL device.
|
||||
ALCdevice * device;
|
||||
|
||||
// The OpenAL context.
|
||||
ALCcontext * context;
|
||||
|
||||
SDL_Thread * thread;
|
||||
|
||||
// The Pool.
|
||||
Pool * pool;
|
||||
|
||||
static int run(void * unused);
|
||||
|
||||
public:
|
||||
|
||||
Audio();
|
||||
~Audio();
|
||||
|
||||
// Implements Module.
|
||||
const char * getName() const;
|
||||
|
||||
// Implements Audio.
|
||||
love::audio::Sound * newSound(love::sound::SoundData * data);
|
||||
love::audio::Music * newMusic(love::sound::Decoder * decoder);
|
||||
love::audio::Source * newSource();
|
||||
int getNumSources() const;
|
||||
int getMaxSources() const;
|
||||
void play(love::audio::Source * source);
|
||||
void play(love::audio::Sound * sound);
|
||||
void play(love::audio::Music * music);
|
||||
void play();
|
||||
void stop(love::audio::Source * source);
|
||||
void stop();
|
||||
void pause(love::audio::Source * source);
|
||||
void pause();
|
||||
void resume(love::audio::Source * source);
|
||||
void resume();
|
||||
void rewind(love::audio::Source * source);
|
||||
void rewind();
|
||||
void setVolume(float volume);
|
||||
float getVolume() const;
|
||||
|
||||
}; // Audio
|
||||
|
||||
} // openal
|
||||
} // audio
|
||||
} // love
|
||||
|
||||
#endif // LOVE_AUDIO_OPENAL_AUDIO_H
|
||||
@@ -0,0 +1,136 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#include "Music.h"
|
||||
|
||||
// STD
|
||||
#include <iostream>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
namespace openal
|
||||
{
|
||||
Music::Music(Pool * pool, love::sound::Decoder * decoder)
|
||||
: pool(pool), decoder(decoder), source(0)
|
||||
{
|
||||
decoder->retain();
|
||||
alGenBuffers(NUM_BUFFERS, buffers);
|
||||
}
|
||||
|
||||
Music::~Music()
|
||||
{
|
||||
decoder->release();
|
||||
alDeleteBuffers(NUM_BUFFERS, buffers);
|
||||
}
|
||||
|
||||
love::audio::Music * Music::clone()
|
||||
{
|
||||
return new Music(pool, decoder->clone());
|
||||
}
|
||||
|
||||
void Music::play(love::audio::Source * s)
|
||||
{
|
||||
source = pool->find(s);
|
||||
|
||||
if(source)
|
||||
{
|
||||
for(int i = 0; i < NUM_BUFFERS; i++)
|
||||
{
|
||||
if(!stream(buffers[i]))
|
||||
{
|
||||
std::cout << "Could not stream music." << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
alSourceQueueBuffers(source, NUM_BUFFERS, buffers);
|
||||
}
|
||||
}
|
||||
|
||||
void Music::update(love::audio::Source * s)
|
||||
{
|
||||
if(source)
|
||||
{
|
||||
// Number of processed buffers.
|
||||
ALint processed;
|
||||
|
||||
alGetSourcei(source, AL_BUFFERS_PROCESSED, &processed);
|
||||
|
||||
while(processed--)
|
||||
{
|
||||
ALuint buffer;
|
||||
|
||||
// Get a free buffer.
|
||||
alSourceUnqueueBuffers(source, 1, &buffer);
|
||||
|
||||
if(stream(buffer))
|
||||
alSourceQueueBuffers(source, 1, &buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Music::stop(love::audio::Source * s)
|
||||
{
|
||||
if(source)
|
||||
{
|
||||
ALuint bufs[NUM_BUFFERS];
|
||||
alSourceStop(source);
|
||||
alSourceUnqueueBuffers(source, NUM_BUFFERS, bufs);
|
||||
source = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void Music::rewind(love::audio::Source * s)
|
||||
{
|
||||
// Stop source, unqueue buffers.
|
||||
stop(s);
|
||||
|
||||
// Rewind data pointer.
|
||||
decoder->rewind();
|
||||
|
||||
// Requeue buffers.
|
||||
play(s);
|
||||
}
|
||||
|
||||
bool Music::stream(ALuint buffer)
|
||||
{
|
||||
// Get more sound data.
|
||||
int decoded = decoder->decode();
|
||||
|
||||
int fmt = pool->getFormat(decoder->getChannels(), decoder->getBits());
|
||||
|
||||
if(fmt == 0)
|
||||
return false;
|
||||
|
||||
if(decoded > 0)
|
||||
{
|
||||
alBufferData(buffer, fmt, decoder->getBuffer(),
|
||||
decoder->getSize(), decoder->getSampleRate());
|
||||
return true;
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // openal
|
||||
} // audio
|
||||
} // love
|
||||
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* 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_OPENAL_MUSIC_H
|
||||
#define LOVE_AUDIO_OPENAL_MUSIC_H
|
||||
|
||||
// LOVE
|
||||
#include <audio/Music.h>
|
||||
#include <sound/Decoder.h>
|
||||
#include "Pool.h"
|
||||
|
||||
// OpenAL
|
||||
#include <AL/alc.h>
|
||||
#include <AL/al.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
namespace openal
|
||||
{
|
||||
|
||||
// Forward declarations.
|
||||
class Audio;
|
||||
|
||||
class Music : public love::audio::Music
|
||||
{
|
||||
private:
|
||||
static const unsigned int NUM_BUFFERS = 32;
|
||||
ALuint buffers[NUM_BUFFERS];
|
||||
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);
|
||||
void update(love::audio::Source * source);
|
||||
void stop(love::audio::Source * source);
|
||||
void rewind(love::audio::Source * source);
|
||||
|
||||
// Implements Music.
|
||||
love::audio::Music * clone();
|
||||
|
||||
private:
|
||||
bool stream(ALuint buffer);
|
||||
}; // Sound
|
||||
|
||||
} // openal
|
||||
} // audio
|
||||
} // love
|
||||
|
||||
#endif // LOVE_AUDIO_OPENAL_MUSIC_H
|
||||
@@ -0,0 +1,237 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#include "Pool.h"
|
||||
|
||||
#define MUTEX_ASSERT(fn, sval) \
|
||||
if(fn != sval) \
|
||||
{ \
|
||||
std::cout << "Mutex lock/unlock failure. " << SDL_GetError() << std::endl; \
|
||||
exit(-1); \
|
||||
} \
|
||||
|
||||
#define LOCK(m) MUTEX_ASSERT(SDL_mutexP(m), 0)
|
||||
#define UNLOCK(m) MUTEX_ASSERT(SDL_mutexV(m), 0);
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
namespace openal
|
||||
{
|
||||
Pool::Pool()
|
||||
{
|
||||
// Generate sources.
|
||||
alGenSources(NUM_SOURCES, sources);
|
||||
|
||||
// Create the mutex.
|
||||
mutex = SDL_CreateMutex();
|
||||
|
||||
if(alGetError() != AL_NO_ERROR)
|
||||
throw love::Exception("Could not generate sources.");
|
||||
|
||||
// Make all sources available initially.
|
||||
for(int i = 0; i < NUM_SOURCES; i++)
|
||||
available.push(sources[i]);
|
||||
}
|
||||
|
||||
Pool::~Pool()
|
||||
{
|
||||
SDL_DestroyMutex(mutex);
|
||||
|
||||
std::map<love::audio::Source *, ALuint>::iterator i = playing.begin();
|
||||
|
||||
while(i != playing.end())
|
||||
{
|
||||
i->first->stop();
|
||||
i->first->release();
|
||||
i++;
|
||||
}
|
||||
|
||||
// Free all sources.
|
||||
alDeleteSources(NUM_SOURCES, sources);
|
||||
}
|
||||
|
||||
ALenum Pool::getFormat(int channels, int bits) const
|
||||
{
|
||||
if(channels == 1 && bits == 8)
|
||||
return AL_FORMAT_MONO8;
|
||||
else if(channels == 1 && bits == 16)
|
||||
return AL_FORMAT_MONO16;
|
||||
else if(channels == 2 && bits == 8)
|
||||
return AL_FORMAT_STEREO8;
|
||||
else if(channels == 2 && bits == 16)
|
||||
return AL_FORMAT_STEREO16;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool Pool::isAvailable() const
|
||||
{
|
||||
bool has = false;
|
||||
LOCK(mutex);
|
||||
has = !available.empty();
|
||||
UNLOCK(mutex);
|
||||
return has;
|
||||
}
|
||||
|
||||
ALuint Pool::claim(love::audio::Source * source)
|
||||
{
|
||||
ALuint s = 0;
|
||||
LOCK(mutex);
|
||||
if(!available.empty())
|
||||
{
|
||||
// Get the first available source.
|
||||
s = available.front();
|
||||
|
||||
// Remove it.
|
||||
available.pop();
|
||||
|
||||
// Insert into map of playing sources.
|
||||
playing.insert(std::pair<love::audio::Source *, ALuint>(source, s));
|
||||
|
||||
// Retain the source.
|
||||
source->retain();
|
||||
}
|
||||
UNLOCK(mutex);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
void Pool::release(love::audio::Source * source)
|
||||
{
|
||||
LOCK(mutex);
|
||||
ALuint s = findi(source);
|
||||
|
||||
if(s != 0)
|
||||
{
|
||||
available.push(s);
|
||||
playing.erase(source);
|
||||
source->release();
|
||||
}
|
||||
UNLOCK(mutex);
|
||||
}
|
||||
|
||||
ALuint Pool::find(const love::audio::Source * source) const
|
||||
{
|
||||
ALuint r = 0;
|
||||
LOCK(mutex);
|
||||
r = findi(source);
|
||||
UNLOCK(mutex);
|
||||
return r;
|
||||
}
|
||||
|
||||
bool Pool::isPlaying(love::audio::Source * s)
|
||||
{
|
||||
bool p = false;
|
||||
LOCK(mutex);
|
||||
for(std::map<love::audio::Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
|
||||
{
|
||||
if(i->first == s)
|
||||
p = true;
|
||||
}
|
||||
UNLOCK(mutex);
|
||||
return p;
|
||||
}
|
||||
|
||||
void Pool::update()
|
||||
{
|
||||
LOCK(mutex);
|
||||
|
||||
std::map<love::audio::Source *, ALuint>::iterator i = playing.begin();
|
||||
|
||||
while(i != playing.end())
|
||||
{
|
||||
if(i->first->isFinished())
|
||||
{
|
||||
// Stop the source.
|
||||
i->first->stop();
|
||||
|
||||
// Make it available.
|
||||
available.push(i->second);
|
||||
|
||||
// Remove if from the playing list.
|
||||
playing.erase(i++);
|
||||
}
|
||||
else
|
||||
{
|
||||
i->first->update();
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
UNLOCK(mutex);
|
||||
}
|
||||
|
||||
int Pool::getNumSources() const
|
||||
{
|
||||
return playing.size();
|
||||
}
|
||||
|
||||
int Pool::getMaxSources() const
|
||||
{
|
||||
return NUM_SOURCES;
|
||||
}
|
||||
|
||||
void Pool::stop()
|
||||
{
|
||||
LOCK(mutex);
|
||||
for(std::map<love::audio::Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
|
||||
i->first->stop();
|
||||
UNLOCK(mutex);
|
||||
}
|
||||
|
||||
void Pool::pause()
|
||||
{
|
||||
LOCK(mutex);
|
||||
for(std::map<love::audio::Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
|
||||
i->first->pause();
|
||||
UNLOCK(mutex);
|
||||
}
|
||||
|
||||
void Pool::resume()
|
||||
{
|
||||
LOCK(mutex);
|
||||
for(std::map<love::audio::Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
|
||||
i->first->resume();
|
||||
UNLOCK(mutex);
|
||||
}
|
||||
|
||||
void Pool::rewind()
|
||||
{
|
||||
LOCK(mutex);
|
||||
for(std::map<love::audio::Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
|
||||
i->first->rewind();
|
||||
UNLOCK(mutex);
|
||||
}
|
||||
|
||||
ALuint Pool::findi(const love::audio::Source * source) const
|
||||
{
|
||||
std::map<love::audio::Source *, ALuint>::const_iterator i = playing.find((love::audio::Source *)source);
|
||||
|
||||
if(i != playing.end())
|
||||
return i->second;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // openal
|
||||
} // audio
|
||||
} // love
|
||||
@@ -0,0 +1,126 @@
|
||||
/**
|
||||
* 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_OPENAL_POOL_H
|
||||
#define LOVE_AUDIO_OPENAL_POOL_H
|
||||
|
||||
// STD
|
||||
#include <queue>
|
||||
#include <map>
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
// SDL
|
||||
#include <SDL.h>
|
||||
|
||||
// OpenAL
|
||||
#include <AL/alc.h>
|
||||
#include <AL/al.h>
|
||||
|
||||
// LOVE
|
||||
#include <audio/Source.h>
|
||||
#include <common/Exception.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
namespace openal
|
||||
{
|
||||
class Pool
|
||||
{
|
||||
private:
|
||||
|
||||
// Number of OpenAL sources.
|
||||
static const int NUM_SOURCES = 16;
|
||||
|
||||
// OpenAL sources
|
||||
ALuint sources[NUM_SOURCES];
|
||||
|
||||
// A queue of available sources.
|
||||
std::queue<ALuint> available;
|
||||
|
||||
// A map of playing sources.
|
||||
std::map<love::audio::Source *, ALuint> playing;
|
||||
|
||||
// Only one thread can access this object at the same time. This mutex will
|
||||
// make sure of that.
|
||||
SDL_mutex * mutex;
|
||||
|
||||
public:
|
||||
|
||||
Pool();
|
||||
~Pool();
|
||||
|
||||
/**
|
||||
* Gets the OpenAL format identifier based on number of
|
||||
* channels and bits.
|
||||
* @param channels Either 1 (mono) or 2 (stereo).
|
||||
* @param bits Either 8-bit samples, or 16-bit samples.
|
||||
* @return One of AL_FORMAT_*, or 0 if unsupported format.
|
||||
**/
|
||||
ALenum getFormat(int channels, int bits) const;
|
||||
|
||||
/**
|
||||
* Checks whether an OpenAL source is available.
|
||||
* @return True if at least one is available, false otherwise.
|
||||
**/
|
||||
bool isAvailable() const;
|
||||
|
||||
/**
|
||||
* Checks whether a Source is currently in the playing list.
|
||||
**/
|
||||
bool isPlaying(love::audio::Source * s);
|
||||
|
||||
/**
|
||||
* Returns an available OpenAL source identifier, or 0 if
|
||||
* none is available.
|
||||
* @return An OpenAL source ID, or 0 if unavailable.
|
||||
**/
|
||||
ALuint claim(love::audio::Source * source);
|
||||
|
||||
/**
|
||||
* Makes the specified OpenAL source available for use.
|
||||
* @param source The OpenAL source.
|
||||
**/
|
||||
void release(love::audio::Source * source);
|
||||
|
||||
ALuint find(const love::audio::Source * source) const;
|
||||
|
||||
void update();
|
||||
|
||||
int getNumSources() const;
|
||||
int getMaxSources() const;
|
||||
|
||||
void stop();
|
||||
void pause();
|
||||
void resume();
|
||||
void rewind();
|
||||
|
||||
private:
|
||||
|
||||
ALuint findi(const love::audio::Source * source) const;
|
||||
}; // Pool
|
||||
|
||||
} // openal
|
||||
} // audio
|
||||
} // love
|
||||
|
||||
#endif // LOVE_AUDIO_OPENAL_POOL_H
|
||||
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#include "Sound.h"
|
||||
|
||||
#include <common/Exception.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
namespace openal
|
||||
{
|
||||
Sound::Sound(Pool * pool, love::sound::SoundData * data)
|
||||
: pool(pool), buffer(0), source(source)
|
||||
{
|
||||
|
||||
// Generate the buffer.
|
||||
alGenBuffers(1, &buffer);
|
||||
|
||||
int fmt = pool->getFormat(data->getChannels(), data->getBits());
|
||||
|
||||
if(fmt == 0)
|
||||
throw love::Exception("Unsopported audio format.");
|
||||
|
||||
alBufferData(buffer, fmt, data->getData(), data->getSize(), data->getSampleRate());
|
||||
|
||||
// Note: we're done with the sound data
|
||||
// at this point. No need to retain.
|
||||
}
|
||||
|
||||
Sound::~Sound()
|
||||
{
|
||||
if(buffer)
|
||||
alDeleteBuffers(1, &buffer);
|
||||
}
|
||||
|
||||
void Sound::play(love::audio::Source * s)
|
||||
{
|
||||
// Set the buffer for the sound.
|
||||
source = pool->find(s);
|
||||
|
||||
if(source)
|
||||
alSourcei(source, AL_BUFFER, buffer);
|
||||
}
|
||||
|
||||
void Sound::update(love::audio::Source * s)
|
||||
{
|
||||
// No need.
|
||||
}
|
||||
|
||||
void Sound::stop(love::audio::Source * s)
|
||||
{
|
||||
// Also no need.
|
||||
}
|
||||
|
||||
void Sound::rewind(love::audio::Source * s)
|
||||
{
|
||||
if(source)
|
||||
alSourceRewind(source);
|
||||
}
|
||||
|
||||
} // openal
|
||||
} // audio
|
||||
} // love
|
||||
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* 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_OPENAL_SOUND_H
|
||||
#define LOVE_AUDIO_OPENAL_SOUND_H
|
||||
|
||||
// LOVE
|
||||
#include <sound/SoundData.h>
|
||||
#include <audio/Sound.h>
|
||||
#include "Pool.h"
|
||||
|
||||
// OpenAL
|
||||
#include <AL/alc.h>
|
||||
#include <AL/al.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
namespace openal
|
||||
{
|
||||
// Forward declarations.
|
||||
class Audio;
|
||||
|
||||
class Sound : public love::audio::Sound
|
||||
{
|
||||
private:
|
||||
|
||||
Pool * pool;
|
||||
|
||||
// Sounds only need one buffer.
|
||||
ALuint buffer;
|
||||
|
||||
ALuint source;
|
||||
|
||||
public:
|
||||
Sound(Pool * pool, love::sound::SoundData * data);
|
||||
virtual ~Sound();
|
||||
|
||||
// Implements Audible.
|
||||
void play(love::audio::Source * s);
|
||||
void update(love::audio::Source * s);
|
||||
void stop(love::audio::Source * s);
|
||||
void rewind(love::audio::Source * s);
|
||||
|
||||
}; // Sound
|
||||
|
||||
} // openal
|
||||
} // audio
|
||||
} // love
|
||||
|
||||
#endif // LOVE_AUDIO_OPENAL_SOUND_H
|
||||
@@ -0,0 +1,168 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#include "Source.h"
|
||||
|
||||
// STD
|
||||
#include <iostream>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
namespace openal
|
||||
{
|
||||
|
||||
Source::Source(Pool * pool)
|
||||
: pool(pool), source(0), pitch(1.0f), volume(1.0f)
|
||||
{
|
||||
}
|
||||
|
||||
Source::Source(Pool * pool, Audible * audible)
|
||||
: pool(pool), source(0), pitch(1.0f), volume(1.0f)
|
||||
{
|
||||
setAudible(audible);
|
||||
}
|
||||
|
||||
Source::~Source()
|
||||
{
|
||||
}
|
||||
|
||||
void Source::play()
|
||||
{
|
||||
if(source != 0)
|
||||
return; // Already playing.
|
||||
|
||||
if(pool->isAvailable())
|
||||
source = pool->claim(this);
|
||||
|
||||
if(source != 0)
|
||||
{
|
||||
audible->play(this);
|
||||
|
||||
// Set these properties. These may have changed while we've
|
||||
// been without an AL source.
|
||||
alSourcef(source, AL_PITCH, pitch);
|
||||
alSourcef(source, AL_GAIN, volume);
|
||||
|
||||
alSourcePlay(source);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Source::stop()
|
||||
{
|
||||
if(source)
|
||||
{
|
||||
alSourceStop(source);
|
||||
audible->stop(this);
|
||||
source = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void Source::pause()
|
||||
{
|
||||
if(source)
|
||||
{
|
||||
alSourcePause(source);
|
||||
}
|
||||
}
|
||||
|
||||
void Source::resume()
|
||||
{
|
||||
if(source)
|
||||
{
|
||||
alSourcePlay(source);
|
||||
}
|
||||
}
|
||||
|
||||
void Source::rewind()
|
||||
{
|
||||
if(audible != 0)
|
||||
audible->rewind(this);
|
||||
}
|
||||
|
||||
bool Source::isFinished() const
|
||||
{
|
||||
if(source)
|
||||
{
|
||||
ALenum state;
|
||||
alGetSourcei(source, AL_SOURCE_STATE, &state);
|
||||
return (state == AL_STOPPED);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Source::update()
|
||||
{
|
||||
if(audible != 0)
|
||||
audible->update(this);
|
||||
}
|
||||
|
||||
void Source::setPitch(float pitch)
|
||||
{
|
||||
if(source)
|
||||
{
|
||||
alSourcef(source, AL_PITCH, pitch);
|
||||
}
|
||||
|
||||
this->pitch = pitch;
|
||||
}
|
||||
|
||||
float Source::getPitch() const
|
||||
{
|
||||
if(source)
|
||||
{
|
||||
ALfloat f;
|
||||
alGetSourcef(source, AL_PITCH, &f);
|
||||
return f;
|
||||
}
|
||||
|
||||
// In case the Source isn't playing.
|
||||
return pitch;
|
||||
}
|
||||
|
||||
void Source::setVolume(float volume)
|
||||
{
|
||||
if(source)
|
||||
{
|
||||
alSourcef(source, AL_GAIN, volume);
|
||||
}
|
||||
|
||||
this->volume = volume;
|
||||
}
|
||||
|
||||
float Source::getVolume() const
|
||||
{
|
||||
if(source)
|
||||
{
|
||||
ALfloat f;
|
||||
alGetSourcef(source, AL_GAIN, &f);
|
||||
return f;
|
||||
}
|
||||
|
||||
// In case the Source isn't playing.
|
||||
return volume;
|
||||
}
|
||||
|
||||
} // openal
|
||||
} // audio
|
||||
} // love
|
||||
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* 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_OPENAL_SOURCE_H
|
||||
#define LOVE_AUDIO_OPENAL_SOURCE_H
|
||||
|
||||
// LOVE
|
||||
#include <common/Object.h>
|
||||
#include <audio/Source.h>
|
||||
#include "Pool.h"
|
||||
|
||||
// OpenAL
|
||||
#include <AL/alc.h>
|
||||
#include <AL/al.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
namespace openal
|
||||
{
|
||||
class Audio;
|
||||
|
||||
class Source : public love::audio::Source
|
||||
{
|
||||
private:
|
||||
|
||||
Pool * pool;
|
||||
ALuint source;
|
||||
|
||||
float pitch;
|
||||
float volume;
|
||||
|
||||
public:
|
||||
Source(Pool * pool);
|
||||
Source(Pool * pool, Audible * audible);
|
||||
virtual ~Source();
|
||||
|
||||
void play();
|
||||
void stop();
|
||||
void pause();
|
||||
void resume();
|
||||
void rewind();
|
||||
bool isFinished() const;
|
||||
void update();
|
||||
|
||||
void setPitch(float pitch);
|
||||
float getPitch() const;
|
||||
|
||||
void setVolume(float volume);
|
||||
float getVolume() const;
|
||||
|
||||
}; // Source
|
||||
|
||||
} // openal
|
||||
} // audio
|
||||
} // love
|
||||
|
||||
#endif // LOVE_AUDIO_OPENAL_SOURCE_H
|
||||
@@ -0,0 +1,196 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
// LOVE
|
||||
#include "wrap_Audio.h"
|
||||
|
||||
#include "openal/Audio.h"
|
||||
#include "null/Audio.h"
|
||||
|
||||
#include <sound/wrap_Decoder.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
static Audio * instance = 0;
|
||||
|
||||
int _wrap_getNumSources(lua_State * L)
|
||||
{
|
||||
lua_pushinteger(L, instance->getNumSources());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_newSound(lua_State * L)
|
||||
{
|
||||
// Convert to File, if necessary.
|
||||
if(lua_isstring(L, 1))
|
||||
luax_strtofile(L, 1);
|
||||
|
||||
// Convert to SoundData, if necessary.
|
||||
if(luax_istype(L, 1, LOVE_FILESYSTEM_FILE_BITS))
|
||||
luax_convobj(L, 1, "sound", "newSoundData");
|
||||
|
||||
love::sound::SoundData * data = luax_checktype<love::sound::SoundData>(L, 1, "SoundData", LOVE_SOUND_SOUND_DATA_BITS);
|
||||
Sound * t = instance->newSound(data);
|
||||
luax_newtype(L, "Sound", LOVE_AUDIO_SOUND_BITS, (void*)t);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int _wrap_newMusic(lua_State * L)
|
||||
{
|
||||
// Convert to Decoder, if necessary.
|
||||
if(!luax_istype(L, 1, LOVE_SOUND_DECODER_BITS))
|
||||
luax_convobj(L, 1, "sound", "newDecoder");
|
||||
|
||||
love::sound::Decoder * decoder = love::sound::luax_checkdecoder(L, 1);
|
||||
Music * t = instance->newMusic(decoder);
|
||||
luax_newtype(L, "Music", LOVE_AUDIO_MUSIC_BITS, (void*)t);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_newSource(lua_State * L)
|
||||
{
|
||||
Source * t = instance->newSource();
|
||||
luax_newtype(L, "Source", LOVE_AUDIO_SOURCE_BITS, (void*)t);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_play(lua_State * L)
|
||||
{
|
||||
int argn = lua_gettop(L);
|
||||
|
||||
if(luax_istype(L, 1, LOVE_AUDIO_SOUND_BITS))
|
||||
{
|
||||
Sound * s = luax_checksound(L, 1);
|
||||
instance->play(s);
|
||||
return 0;
|
||||
}
|
||||
else if(luax_istype(L, 1, LOVE_AUDIO_MUSIC_BITS))
|
||||
{
|
||||
Music * m = luax_checkmusic(L, 1);
|
||||
instance->play(m);
|
||||
return 0;
|
||||
}
|
||||
else if(luax_istype(L, 1, LOVE_AUDIO_SOURCE_BITS))
|
||||
{
|
||||
Source * s = luax_checksource(L, 1);
|
||||
instance->play(s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return luaL_error(L, "No matching overload");
|
||||
}
|
||||
|
||||
int _wrap_stop(lua_State * L)
|
||||
{
|
||||
Source * c = luax_checksource(L, 1);
|
||||
instance->stop(c);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_pause(lua_State * L)
|
||||
{
|
||||
Source * c = luax_checksource(L, 1);
|
||||
instance->pause(c);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_rewind(lua_State * L)
|
||||
{
|
||||
Source * c = luax_checksource(L, 1);
|
||||
instance->rewind(c);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_setVolume(lua_State * L)
|
||||
{
|
||||
float v = (float)luaL_checknumber(L, 1);
|
||||
instance->setVolume(v);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_getVolume(lua_State * L)
|
||||
{
|
||||
lua_pushnumber(L, instance->getVolume());
|
||||
return 1;
|
||||
}
|
||||
|
||||
// List of functions to wrap.
|
||||
static const luaL_Reg wrap_Audio_functions[] = {
|
||||
{ "getNumSources", _wrap_getNumSources },
|
||||
{ "newSound", _wrap_newSound },
|
||||
{ "newMusic", _wrap_newMusic },
|
||||
{ "newSource", _wrap_newSource },
|
||||
{ "play", _wrap_play },
|
||||
{ "stop", _wrap_stop },
|
||||
{ "pause", _wrap_pause },
|
||||
{ "rewind", _wrap_rewind },
|
||||
{ "setVolume", _wrap_setVolume },
|
||||
{ "getVolume", _wrap_getVolume },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
static const lua_CFunction wrap_Audio_types[] = {
|
||||
wrap_Source_open,
|
||||
wrap_Music_open,
|
||||
wrap_Sound_open,
|
||||
0
|
||||
};
|
||||
|
||||
int wrap_Audio_open(lua_State * L)
|
||||
{
|
||||
if(instance == 0)
|
||||
{
|
||||
// Try OpenAL first.
|
||||
try
|
||||
{
|
||||
instance = new love::audio::openal::Audio();
|
||||
}
|
||||
catch(love::Exception & e)
|
||||
{
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
if(instance == 0)
|
||||
{
|
||||
// Fall back to nullaudio.
|
||||
try
|
||||
{
|
||||
instance = new love::audio::null::Audio();
|
||||
}
|
||||
catch(love::Exception & e)
|
||||
{
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
if(instance == 0)
|
||||
return luaL_error(L, "Could not open any audio module.");
|
||||
|
||||
luax_register_gc(L, "love.audio", instance);
|
||||
|
||||
return luax_register_module(L, wrap_Audio_functions, wrap_Audio_types);
|
||||
}
|
||||
|
||||
} // audio
|
||||
} // love
|
||||
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* 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_WRAP_AUDIO_H
|
||||
#define LOVE_AUDIO_WRAP_AUDIO_H
|
||||
|
||||
// LOVE
|
||||
#include "Audio.h"
|
||||
#include "wrap_Sound.h"
|
||||
#include "wrap_Music.h"
|
||||
#include "wrap_Source.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
int _wrap_getNumSources(lua_State * L);
|
||||
int _wrap_newSound(lua_State * L);
|
||||
int _wrap_newMusic(lua_State * L);
|
||||
int _wrap_newSource(lua_State * L);
|
||||
int _wrap_play(lua_State * L);
|
||||
int _wrap_stop(lua_State * L);
|
||||
int _wrap_pause(lua_State * L);
|
||||
int _wrap_rewind(lua_State * L);
|
||||
int _wrap_setVolume(lua_State * L);
|
||||
int _wrap_getVolume(lua_State * L);
|
||||
int wrap_Audio_open(lua_State * L);
|
||||
|
||||
} // audio
|
||||
} // love
|
||||
|
||||
|
||||
#endif // LOVE_AUDIO_WRAP_AUDIO_H
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#include "wrap_Music.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
Music * luax_checkmusic(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<Music>(L, idx, "Music", LOVE_AUDIO_MUSIC_BITS);
|
||||
}
|
||||
|
||||
static const luaL_Reg wrap_Music_functions[] = {
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int wrap_Music_open(lua_State * L)
|
||||
{
|
||||
luax_register_type(L, "Music", wrap_Music_functions);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // audio
|
||||
} // love
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* 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_WRAP_MUSIC_H
|
||||
#define LOVE_AUDIO_WRAP_MUSIC_H
|
||||
|
||||
#include <common/runtime.h>
|
||||
#include "Music.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
Music * luax_checkmusic(lua_State * L, int idx);
|
||||
int wrap_Music_open(lua_State * L);
|
||||
|
||||
} // audio
|
||||
} // love
|
||||
|
||||
#endif // LOVE_AUDIO_WRAP_MUSIC_H
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#include "wrap_Sound.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
Sound * luax_checksound(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<Sound>(L, idx, "Sound", LOVE_AUDIO_SOUND_BITS);
|
||||
}
|
||||
|
||||
static const luaL_Reg wrap_Sound_functions[] = {
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int wrap_Sound_open(lua_State * L)
|
||||
{
|
||||
luax_register_type(L, "Sound", wrap_Sound_functions);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // audio
|
||||
} // love
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* 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_WRAP_SOUND_H
|
||||
#define LOVE_AUDIO_WRAP_SOUND_H
|
||||
|
||||
#include <common/runtime.h>
|
||||
#include "Sound.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
Sound * luax_checksound(lua_State * L, int idx);
|
||||
int wrap_Sound_open(lua_State * L);
|
||||
|
||||
} // audio
|
||||
} // love
|
||||
|
||||
#endif // LOVE_AUDIO_WRAP_SOUND_H
|
||||
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#include "wrap_Source.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
Source * luax_checksource(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<Source>(L, idx, "Source", LOVE_AUDIO_SOURCE_BITS);
|
||||
}
|
||||
|
||||
int _wrap_Source_setPitch(lua_State * L)
|
||||
{
|
||||
Source * t = luax_checksource(L, 1);
|
||||
float p = (float)luaL_checknumber(L, 2);
|
||||
t->setPitch(p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_Source_getPitch(lua_State * L)
|
||||
{
|
||||
Source * t = luax_checksource(L, 1);
|
||||
lua_pushnumber(L, t->getPitch());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_Source_setVolume(lua_State * L)
|
||||
{
|
||||
Source * t = luax_checksource(L, 1);
|
||||
float p = (float)luaL_checknumber(L, 2);
|
||||
t->setVolume(p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_Source_getVolume(lua_State * L)
|
||||
{
|
||||
Source * t = luax_checksource(L, 1);
|
||||
lua_pushnumber(L, t->getVolume());
|
||||
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 },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int wrap_Source_open(lua_State * L)
|
||||
{
|
||||
luax_register_type(L, "Source", wrap_Source_functions);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // audio
|
||||
} // love
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* 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_WRAP_SOURCE_H
|
||||
#define LOVE_AUDIO_WRAP_SOURCE_H
|
||||
|
||||
#include <common/runtime.h>
|
||||
#include "Source.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
Source * luax_checksource(lua_State * L, int idx);
|
||||
int _wrap_Source_setPitch(lua_State * L);
|
||||
int _wrap_Source_getPitch(lua_State * L);
|
||||
int _wrap_Source_setVolume(lua_State * L);
|
||||
int _wrap_Source_getVolume(lua_State * L);
|
||||
int wrap_Source_open(lua_State * L);
|
||||
|
||||
} // audio
|
||||
} // love
|
||||
|
||||
#endif // LOVE_AUDIO_WRAP_SOURCE_H
|
||||
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
* 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_EVENT_EVENT_H
|
||||
#define LOVE_EVENT_EVENT_H
|
||||
|
||||
// LOVE
|
||||
#include <common/Module.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace event
|
||||
{
|
||||
class Event : public Module
|
||||
{
|
||||
protected:
|
||||
virtual ~Event(){};
|
||||
public:
|
||||
|
||||
enum
|
||||
{
|
||||
EVENT_NOEVENT = 0,
|
||||
EVENT_ACTIVEEVENT,
|
||||
EVENT_KEYDOWN,
|
||||
EVENT_KEYUP,
|
||||
EVENT_MOUSEMOTION,
|
||||
EVENT_MOUSEBUTTONDOWN,
|
||||
EVENT_MOUSEBUTTONUP,
|
||||
EVENT_JOYAXISMOTION,
|
||||
EVENT_JOYBALLMOTION,
|
||||
EVENT_JOYHATMOTION,
|
||||
EVENT_JOYBUTTONDOWN,
|
||||
EVENT_JOYBUTTONUP,
|
||||
EVENT_QUIT,
|
||||
EVENT_SYSWMEVENT,
|
||||
EVENT_RESERVEDA,
|
||||
EVENT_RESERVEDB,
|
||||
EVENT_VIDEORESIZE,
|
||||
EVENT_VIDEOEXPOSE,
|
||||
EVENT_RESERVED2,
|
||||
EVENT_RESERVED3,
|
||||
EVENT_RESERVED4,
|
||||
EVENT_RESERVED5,
|
||||
EVENT_RESERVED6,
|
||||
EVENT_RESERVED7,
|
||||
EVENT_USEREVENT = 24,
|
||||
EVENT_NUMEVENTS = 32
|
||||
};
|
||||
|
||||
}; // Event
|
||||
|
||||
} // event
|
||||
} // love
|
||||
|
||||
#endif // LOVE_EVENT_EVENT_H
|
||||
@@ -0,0 +1,163 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#include "Event.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace event
|
||||
{
|
||||
namespace sdl
|
||||
{
|
||||
const char * Event::getName() const
|
||||
{
|
||||
return "love.event.sdl";
|
||||
}
|
||||
|
||||
void Event::pump()
|
||||
{
|
||||
SDL_PumpEvents();
|
||||
}
|
||||
|
||||
int Event::poll(lua_State * L)
|
||||
{
|
||||
lua_pushcclosure(L, &poll_i, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Event::wait(lua_State * L)
|
||||
{
|
||||
static SDL_Event e;
|
||||
SDL_WaitEvent(&e);
|
||||
return pushEvent(L, e);
|
||||
}
|
||||
|
||||
void Event::quit()
|
||||
{
|
||||
SDL_Event e;
|
||||
e.type = Event::EVENT_QUIT;
|
||||
SDL_PushEvent(&e);
|
||||
}
|
||||
|
||||
int Event::push(lua_State * L)
|
||||
{
|
||||
SDL_Event e;
|
||||
getEvent(L, e);
|
||||
SDL_PushEvent(&e);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Event::poll_i(lua_State * L)
|
||||
{
|
||||
SDL_EnableUNICODE(1);
|
||||
|
||||
// The union used to get SDL events.
|
||||
static SDL_Event e;
|
||||
|
||||
// Get ONE event.
|
||||
while(SDL_PollEvent(&e))
|
||||
{
|
||||
int args = Event::pushEvent(L, e);
|
||||
if(args > 0)
|
||||
return args;
|
||||
}
|
||||
|
||||
// No pending events.
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Event::pushEvent(lua_State * L, SDL_Event & e)
|
||||
{
|
||||
switch(e.type)
|
||||
{
|
||||
case SDL_KEYDOWN:
|
||||
lua_pushinteger(L, e.type);
|
||||
lua_pushinteger(L, e.key.keysym.sym);
|
||||
lua_pushinteger(L, e.key.keysym.unicode);
|
||||
return 3;
|
||||
case SDL_KEYUP:
|
||||
lua_pushinteger(L, e.type);
|
||||
lua_pushinteger(L, e.key.keysym.sym);
|
||||
return 2;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
lua_pushinteger(L, e.type);
|
||||
lua_pushinteger(L, e.button.x);
|
||||
lua_pushinteger(L, e.button.y);
|
||||
lua_pushinteger(L, e.button.button);
|
||||
return 4;
|
||||
case SDL_JOYBUTTONDOWN:
|
||||
case SDL_JOYBUTTONUP:
|
||||
lua_pushinteger(L, e.type);
|
||||
lua_pushinteger(L, e.jbutton.which);
|
||||
lua_pushinteger(L, e.jbutton.button);
|
||||
return 3;
|
||||
case SDL_QUIT:
|
||||
lua_pushinteger(L, e.type);
|
||||
return 1;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Event::getEvent(lua_State * L, SDL_Event & e)
|
||||
{
|
||||
int type = luaL_checkint(L, 1);
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case EVENT_KEYDOWN:
|
||||
e.type = type;
|
||||
e.key.keysym.sym = (SDLKey)luaL_checkint(L, 2);
|
||||
e.key.keysym.unicode = luaL_checkint(L, 3);
|
||||
return 3;
|
||||
case EVENT_KEYUP:
|
||||
e.type = type;
|
||||
e.key.keysym.sym = (SDLKey)luaL_checkint(L, 2);
|
||||
return 2;
|
||||
case EVENT_MOUSEBUTTONDOWN:
|
||||
case EVENT_MOUSEBUTTONUP:
|
||||
e.type = type;
|
||||
e.button.x = luaL_checkint(L, 2);
|
||||
e.button.y = luaL_checkint(L, 3);
|
||||
e.button.button = luaL_checkint(L, 4);
|
||||
return 4;
|
||||
case EVENT_JOYBUTTONDOWN:
|
||||
case EVENT_JOYBUTTONUP:
|
||||
e.type = type;
|
||||
e.jbutton.which = luaL_checkint(L, 2);
|
||||
e.jbutton.button = luaL_checkint(L, 3);
|
||||
return 3;
|
||||
case EVENT_QUIT:
|
||||
e.type = type;
|
||||
return 1;
|
||||
default:
|
||||
e.type = EVENT_NOEVENT;
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // sdl
|
||||
} // event
|
||||
} // love
|
||||
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
* 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_EVENT_SDL_EVENT_H
|
||||
#define LOVE_EVENT_SDL_EVENT_H
|
||||
|
||||
// LOVE
|
||||
#include <event/Event.h>
|
||||
#include <common/runtime.h>
|
||||
|
||||
// SDL
|
||||
#include <SDL.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace event
|
||||
{
|
||||
namespace sdl
|
||||
{
|
||||
class Event : public event::Event
|
||||
{
|
||||
public:
|
||||
|
||||
// Implements Module.
|
||||
const char * getName() const;
|
||||
|
||||
/**
|
||||
* Pumps the event queue. This function gathers all the pending input information
|
||||
* from devices and places it on the event queue. Normally not needed if you poll
|
||||
* for events.
|
||||
**/
|
||||
void pump();
|
||||
|
||||
/**
|
||||
* Returns an iterator function for iterating over pending events.
|
||||
**/
|
||||
int poll(lua_State * L);
|
||||
|
||||
/**
|
||||
* Waits for the next event (indefinitely). Useful for creating games where
|
||||
* the screen and game state only needs updating when the user interacts with
|
||||
* the window.
|
||||
**/
|
||||
int wait(lua_State * L);
|
||||
|
||||
/**
|
||||
* Push a quit event. Calling this does not mean the application
|
||||
* will exit immediately, it just means an quit event will be issued.
|
||||
* How to respond to the quit event is up the application.
|
||||
**/
|
||||
void quit();
|
||||
|
||||
/**
|
||||
* Pushes an event into the queue.
|
||||
**/
|
||||
int push(lua_State * L);
|
||||
|
||||
/**
|
||||
* The iterator function.
|
||||
**/
|
||||
static int poll_i(lua_State * L);
|
||||
|
||||
private:
|
||||
|
||||
static int pushEvent(lua_State * L, SDL_Event & e);
|
||||
static int getEvent(lua_State * L, SDL_Event & e);
|
||||
|
||||
}; // System
|
||||
|
||||
} // sdl
|
||||
} // event
|
||||
} // love
|
||||
|
||||
#endif // LOVE_EVENT_SDL_EVENT_H
|
||||
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#include "wrap_Event.h"
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
|
||||
// sdlevent
|
||||
#include "Event.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace event
|
||||
{
|
||||
namespace sdl
|
||||
{
|
||||
static Event * instance = 0;
|
||||
|
||||
int _wrap_pump(lua_State * L)
|
||||
{
|
||||
instance->pump();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_poll(lua_State * L)
|
||||
{
|
||||
return instance->poll(L);
|
||||
}
|
||||
|
||||
int _wrap_wait(lua_State * L)
|
||||
{
|
||||
return instance->wait(L);
|
||||
}
|
||||
|
||||
int _wrap_quit(lua_State * L)
|
||||
{
|
||||
instance->quit();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_push(lua_State * L)
|
||||
{
|
||||
return instance->push(L);
|
||||
}
|
||||
|
||||
// List of functions to wrap.
|
||||
static const luaL_Reg wrap_Event_functions[] = {
|
||||
{ "pump", _wrap_pump },
|
||||
{ "poll", _wrap_poll },
|
||||
{ "wait", _wrap_wait },
|
||||
{ "quit", _wrap_quit },
|
||||
{ "push", _wrap_push },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int wrap_Event_open(lua_State * L)
|
||||
{
|
||||
if(instance == 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
instance = new Event();
|
||||
}
|
||||
catch(Exception & e)
|
||||
{
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
}
|
||||
|
||||
luax_register_gc(L, "love.event", instance);
|
||||
|
||||
return luax_register_module(L, wrap_Event_functions, 0);
|
||||
}
|
||||
|
||||
} // sdl
|
||||
} // event
|
||||
} // love
|
||||
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* 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_EVENT_SDL_WRAP_EVENT_H
|
||||
#define LOVE_EVENT_SDL_WRAP_EVENT_H
|
||||
|
||||
// LOVE
|
||||
#include "Event.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace event
|
||||
{
|
||||
namespace sdl
|
||||
{
|
||||
int _wrap_pump(lua_State * L);
|
||||
int _wrap_poll(lua_State * L);
|
||||
int _wrap_wait(lua_State * L);
|
||||
int _wrap_quit(lua_State * L);
|
||||
int _wrap_push(lua_State * L);
|
||||
|
||||
int wrap_Event_open(lua_State * L);
|
||||
|
||||
} // sdl
|
||||
} // event
|
||||
} // love
|
||||
|
||||
#endif // LOVE_EVENT_SDL_WRAP_EVENT_H
|
||||
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#include "Event.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace event
|
||||
{
|
||||
namespace signal
|
||||
{
|
||||
|
||||
Event::Event()
|
||||
: signals(0)
|
||||
{
|
||||
cb = 0;
|
||||
}
|
||||
|
||||
Event::~Event()
|
||||
{
|
||||
::signal(signals, SIG_DFL);
|
||||
}
|
||||
|
||||
bool Event::registerSignal(int sgn)
|
||||
{
|
||||
signals |= sgn;
|
||||
return ::signal(sgn, (void (*)(int)) &handler) != SIG_ERR;
|
||||
}
|
||||
|
||||
void Event::setCallback(lua_State *L)
|
||||
{
|
||||
luax_assert_argc(L, 1, 1);
|
||||
luax_assert_function(L, -1);
|
||||
|
||||
if(cb != 0)
|
||||
{
|
||||
delete cb;
|
||||
cb = 0;
|
||||
}
|
||||
|
||||
cb = new Reference(L);
|
||||
}
|
||||
|
||||
void handler(int signal)
|
||||
{
|
||||
if (cb == 0)
|
||||
return;
|
||||
lua_State *L = cb->getL();
|
||||
cb->push();
|
||||
lua_pushnumber(L, signal);
|
||||
lua_call(L, 1, 0);
|
||||
}
|
||||
|
||||
const char * Event::getName() const
|
||||
{
|
||||
return "love.event.signal";
|
||||
}
|
||||
|
||||
} // signal
|
||||
} // event
|
||||
} // love
|
||||
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* 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_EVENT_SIGNAL_EVENT_H
|
||||
#define LOVE_EVENT_SIGNAL_EVENT_H
|
||||
|
||||
// LOVE
|
||||
#include <event/Event.h>
|
||||
#include <common/runtime.h>
|
||||
#include <common/Reference.h>
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace event
|
||||
{
|
||||
namespace signal
|
||||
{
|
||||
class Event : public event::Event
|
||||
{
|
||||
private:
|
||||
int signals;
|
||||
|
||||
public:
|
||||
Event();
|
||||
~Event();
|
||||
bool registerSignal(int sgn);
|
||||
void setCallback(lua_State *L);
|
||||
const char * getName() const;
|
||||
};
|
||||
|
||||
void handler(int signal);
|
||||
static Reference *cb;
|
||||
|
||||
} // signal
|
||||
} // event
|
||||
} // love
|
||||
|
||||
#endif // LOVE_EVENT_SIGNAL_EVENT_H
|
||||
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#include "wrap_Event.h"
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
|
||||
#include "Event.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace event
|
||||
{
|
||||
namespace signal
|
||||
{
|
||||
static Event * instance = 0;
|
||||
|
||||
int _wrap_registerSignal(lua_State *L)
|
||||
{
|
||||
luaL_argcheck(L, lua_isnumber(L, 1), 1, "Expected number");
|
||||
lua_pushboolean(L, instance->registerSignal(lua_tonumber(L, 1)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_setCallback(lua_State *L)
|
||||
{
|
||||
luaL_argcheck(L, lua_isfunction(L, 1), 1, "Expected function");
|
||||
instance->setCallback(L);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// List of functions to wrap.
|
||||
static const luaL_Reg wrap_Event_signal_functions[] = {
|
||||
{ "registerSignal", _wrap_registerSignal },
|
||||
{ "setCallback", _wrap_setCallback },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int wrap_Event_signal_open(lua_State * L)
|
||||
{
|
||||
if(instance == 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
instance = new Event();
|
||||
}
|
||||
catch(Exception & e)
|
||||
{
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
}
|
||||
|
||||
luax_register_gc(L, "love.event.signal", instance);
|
||||
|
||||
return luax_register_module(L, wrap_Event_signal_functions, 0);
|
||||
}
|
||||
|
||||
} // signal
|
||||
} // event
|
||||
} // love
|
||||
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* 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_EVENT_SIGNAL_WRAP_EVENT_H
|
||||
#define LOVE_EVENT_SIGNAL_WRAP_EVENT_H
|
||||
|
||||
// LOVE
|
||||
#include "Event.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace event
|
||||
{
|
||||
namespace signal
|
||||
{
|
||||
int _wrap_registerSignal(lua_State *L);
|
||||
int _wrap_setCallback(lua_State *L);
|
||||
|
||||
int wrap_Event_signal_open(lua_State * L);
|
||||
|
||||
} // sdl
|
||||
} // event
|
||||
} // love
|
||||
|
||||
#endif // LOVE_EVENT_SIGNAL_WRAP_EVENT_H
|
||||
@@ -0,0 +1,166 @@
|
||||
/**
|
||||
* 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_FILESYSTEM_FILE_H
|
||||
#define LOVE_FILESYSTEM_FILE_H
|
||||
|
||||
// STD
|
||||
#include <string>
|
||||
|
||||
// LOVE
|
||||
#include <common/Data.h>
|
||||
#include <common/Object.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace filesystem
|
||||
{
|
||||
/**
|
||||
* A File interface, providing generic means of reading from and
|
||||
* writing to files.
|
||||
**/
|
||||
class File : public Object
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* File open mode.
|
||||
**/
|
||||
enum Mode
|
||||
{
|
||||
CLOSED,
|
||||
READ,
|
||||
WRITE,
|
||||
APPEND,
|
||||
};
|
||||
|
||||
/**
|
||||
* Used to indicate ALL data in a file.
|
||||
**/
|
||||
static const int ALL = -1;
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
**/
|
||||
virtual ~File(){};
|
||||
|
||||
/**
|
||||
* Opens the file in a certain mode.
|
||||
*
|
||||
* @param mode READ, WRITE, APPEND.
|
||||
* @return True if successful, false otherwise.
|
||||
**/
|
||||
virtual bool open(Mode mode) = 0;
|
||||
|
||||
/**
|
||||
* Closes the file.
|
||||
*
|
||||
* @return True if successful, false otherwise.
|
||||
**/
|
||||
virtual bool close() = 0;
|
||||
|
||||
/**
|
||||
* Gets the size of the file.
|
||||
*
|
||||
* @return The size of the file.
|
||||
**/
|
||||
virtual unsigned int getSize() = 0;
|
||||
|
||||
/**
|
||||
* Reads data from the file and allocates a Data object.
|
||||
*
|
||||
* @param size The number of bytes to attempt reading, or -1 for EOF.
|
||||
* @return A newly allocated Data object.
|
||||
**/
|
||||
virtual Data * read(int size = ALL) = 0;
|
||||
|
||||
/**
|
||||
* Reads data into the destination buffer.
|
||||
*
|
||||
* @param dst The destination buffer.
|
||||
* @param size The number of bytes to attempt reading.
|
||||
* @return The number of bytes actually read.
|
||||
**/
|
||||
virtual int read(void * dst, int size) = 0;
|
||||
|
||||
/**
|
||||
* Writes data into the File.
|
||||
*
|
||||
* @param data The source buffer.
|
||||
* @param size The size of the buffer.
|
||||
* @return True of success, false otherwise.
|
||||
**/
|
||||
virtual bool write(const void * data, int size) = 0;
|
||||
|
||||
/**
|
||||
* Writes a Data object into the File.
|
||||
*
|
||||
* @param data The data object to write into the file.
|
||||
* @param size The number of bytes to attempt writing, or -1 for everything.
|
||||
* @return True of success, false otherwise.
|
||||
**/
|
||||
virtual bool write(const Data * data, int size = ALL) = 0;
|
||||
|
||||
/**
|
||||
* Checks whether we are currently at end-of-file.
|
||||
*
|
||||
* @return True if EOF, false otherwise.
|
||||
**/
|
||||
virtual bool eof() = 0;
|
||||
|
||||
/**
|
||||
* Gets the current position in the File.
|
||||
*
|
||||
* @return The current byte position in the File.
|
||||
**/
|
||||
virtual int tell() = 0;
|
||||
|
||||
/**
|
||||
* Seeks to a certain position in the File.
|
||||
*
|
||||
* @param pos The byte position in the file.
|
||||
* @return True on success, false otherwise.
|
||||
**/
|
||||
virtual bool seek(int pos) = 0;
|
||||
|
||||
/**
|
||||
* Gets the current mode of the File.
|
||||
* @return The current mode of the File; CLOSED, READ, WRITE or APPEND.
|
||||
**/
|
||||
virtual Mode getMode() = 0;
|
||||
|
||||
/**
|
||||
* Gets the filename for this File, or empty string if none.
|
||||
* @return The filename for this File.
|
||||
**/
|
||||
virtual std::string getFilename() const = 0;
|
||||
|
||||
/**
|
||||
* Gets the file extension for this File, or empty string if none.
|
||||
* @return The file extension for this File (without the dot).
|
||||
**/
|
||||
virtual std::string getExtension() const = 0;
|
||||
|
||||
}; // File
|
||||
|
||||
} // filesystem
|
||||
} // love
|
||||
|
||||
#endif // LOVE_FILESYSTEM_FILE_H
|
||||
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* 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_FILESYSTEM_FILE_DATA_H
|
||||
#define LOVE_FILESYSTEM_FILE_DATA_H
|
||||
|
||||
// LOVE
|
||||
#include <common/Data.h>
|
||||
|
||||
// STD
|
||||
#include <string>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace filesystem
|
||||
{
|
||||
class FileData : public Data
|
||||
{
|
||||
private:
|
||||
public:
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
**/
|
||||
virtual ~FileData(){};
|
||||
|
||||
/**
|
||||
* Gets a filename for this FileData.
|
||||
* @return The filename for this FileData, with extension.
|
||||
**/
|
||||
virtual const std::string & getFilename() const = 0;
|
||||
|
||||
/**
|
||||
* Gets the file extension for this FileData, or empty string if none.
|
||||
* @return The file extension for this FileData (without the dot).
|
||||
**/
|
||||
virtual const std::string & getExtension() const = 0;
|
||||
|
||||
}; // FileData
|
||||
|
||||
} // filesystem
|
||||
} // love
|
||||
|
||||
#endif // LOVE_FILESYSTEM_FILE_DATA_H
|
||||
@@ -0,0 +1,208 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#include "File.h"
|
||||
|
||||
// STD
|
||||
#include <string.h>
|
||||
|
||||
// LOVE
|
||||
#include "Filesystem.h"
|
||||
#include "FileData.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace filesystem
|
||||
{
|
||||
namespace physfs
|
||||
{
|
||||
extern bool hack_setupWriteDirectory();
|
||||
|
||||
File::File(std::string filename)
|
||||
: filename(filename), file(0), mode(filesystem::File::CLOSED)
|
||||
{
|
||||
}
|
||||
|
||||
File::~File()
|
||||
{
|
||||
}
|
||||
|
||||
bool File::open(Mode mode)
|
||||
{
|
||||
// Check whether the write directory is set.
|
||||
if((mode == APPEND || mode == WRITE) && (PHYSFS_getWriteDir() == 0))
|
||||
if(!hack_setupWriteDirectory())
|
||||
return false;
|
||||
|
||||
// File already open?
|
||||
if(file != 0)
|
||||
return false;
|
||||
|
||||
this->mode = mode;
|
||||
|
||||
switch(mode)
|
||||
{
|
||||
case READ:
|
||||
file = PHYSFS_openRead(filename.c_str());
|
||||
break;
|
||||
case APPEND:
|
||||
file = PHYSFS_openAppend(filename.c_str());
|
||||
break;
|
||||
case WRITE:
|
||||
file = PHYSFS_openWrite(filename.c_str());
|
||||
break;
|
||||
case CLOSED:
|
||||
// Heh. Case closed.
|
||||
return true;
|
||||
}
|
||||
|
||||
return (file != 0);
|
||||
}
|
||||
|
||||
bool File::close()
|
||||
{
|
||||
if(!PHYSFS_close(file))
|
||||
return false;
|
||||
mode = CLOSED;
|
||||
file = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned int File::getSize()
|
||||
{
|
||||
// If the file is closed, open it to
|
||||
// check the size.
|
||||
if(file == 0)
|
||||
{
|
||||
open(READ);
|
||||
unsigned int size = (unsigned int)PHYSFS_fileLength(file);
|
||||
close();
|
||||
return size;
|
||||
}
|
||||
|
||||
return (unsigned int)PHYSFS_fileLength(file);
|
||||
}
|
||||
|
||||
|
||||
Data * File::read(int size)
|
||||
{
|
||||
bool isOpen = (file != 0);
|
||||
|
||||
if(!isOpen)
|
||||
open(READ);
|
||||
|
||||
int max = (int)PHYSFS_fileLength(file);
|
||||
size = (size == ALL) ? max : size;
|
||||
size = (size > max) ? max : size;
|
||||
|
||||
FileData * fileData = new FileData(size, getFilename());
|
||||
|
||||
read(fileData->getData(), size);
|
||||
|
||||
if(!isOpen)
|
||||
close();
|
||||
|
||||
return fileData;
|
||||
}
|
||||
|
||||
int File::read(void * dst, int size)
|
||||
{
|
||||
bool isOpen = (file != 0);
|
||||
|
||||
if(!isOpen)
|
||||
open(READ);
|
||||
|
||||
int max = (int)PHYSFS_fileLength(file);
|
||||
size = (size == ALL) ? max : size;
|
||||
size = (size > max) ? max : size;
|
||||
|
||||
int read = (int)PHYSFS_read(file, dst, 1, size);
|
||||
|
||||
if(!isOpen)
|
||||
close();
|
||||
|
||||
return read;
|
||||
}
|
||||
|
||||
bool File::write(const void * data, int size)
|
||||
{
|
||||
// Try to write.
|
||||
int written = static_cast<int>(PHYSFS_write(file, data, 1, size));
|
||||
|
||||
// Check that correct amount of data was written.
|
||||
if(written != size)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool File::write(const Data * data, int size)
|
||||
{
|
||||
return write(data->getData(), (size == ALL) ? data->getSize() : size);
|
||||
}
|
||||
|
||||
bool File::eof()
|
||||
{
|
||||
if(file == 0 || PHYSFS_eof(file))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
int File::tell()
|
||||
{
|
||||
if(file == 0)
|
||||
return -1;
|
||||
|
||||
return (int)PHYSFS_tell(file);
|
||||
}
|
||||
|
||||
bool File::seek(int pos)
|
||||
{
|
||||
if(file == 0)
|
||||
return false;
|
||||
|
||||
if(!PHYSFS_seek(file, (PHYSFS_uint64)pos))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string File::getFilename() const
|
||||
{
|
||||
return filename;
|
||||
}
|
||||
|
||||
std::string File::getExtension() const
|
||||
{
|
||||
std::string::size_type idx = filename.rfind('.');
|
||||
|
||||
if(idx != std::string::npos)
|
||||
return filename.substr(idx+1);
|
||||
else
|
||||
return std::string();
|
||||
}
|
||||
|
||||
filesystem::File::Mode File::getMode()
|
||||
{
|
||||
return mode;
|
||||
}
|
||||
|
||||
} // physfs
|
||||
} // filesystem
|
||||
} // love
|
||||
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* 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_FILESYSTEM_PHYSFS_FILE_H
|
||||
#define LOVE_FILESYSTEM_PHYSFS_FILE_H
|
||||
|
||||
// LOVE
|
||||
#include <filesystem/File.h>
|
||||
|
||||
// PhysFS
|
||||
#include <physfs.h>
|
||||
|
||||
// STD
|
||||
#include <string>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace filesystem
|
||||
{
|
||||
namespace physfs
|
||||
{
|
||||
class File : public love::filesystem::File
|
||||
{
|
||||
private:
|
||||
|
||||
// filename
|
||||
std::string filename;
|
||||
|
||||
// PHYSFS File handle.
|
||||
PHYSFS_file * file;
|
||||
|
||||
// The current mode of the file.
|
||||
Mode mode;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructs an File with the given source and filename.
|
||||
* @param source The source from which to load the file. (Archive or directory)
|
||||
* @param filename The relative filepath of the file to load from the source.
|
||||
**/
|
||||
File(std::string filename);
|
||||
|
||||
virtual ~File();
|
||||
|
||||
// Implements love::filesystem::File.
|
||||
bool open(Mode mode);
|
||||
bool close();
|
||||
unsigned int getSize();
|
||||
Data * read(int size = ALL);
|
||||
int read(void * dst, int size);
|
||||
bool write(const void * data, int size);
|
||||
bool write(const Data * data, int size = ALL);
|
||||
bool eof();
|
||||
int tell();
|
||||
bool seek(int pos);
|
||||
Mode getMode();
|
||||
std::string getFilename() const;
|
||||
std::string getExtension() const;
|
||||
|
||||
}; // File
|
||||
|
||||
} // physfs
|
||||
} // filesystem
|
||||
} // love
|
||||
|
||||
#endif // LOVE_FILESYSTEM_PHYSFS_FILE_H
|
||||
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#include "FileData.h"
|
||||
|
||||
// STD
|
||||
#include <iostream>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace filesystem
|
||||
{
|
||||
namespace physfs
|
||||
{
|
||||
FileData::FileData(int size, const std::string & filename)
|
||||
: data(new char[size]), size(size), filename(filename)
|
||||
{
|
||||
if(filename.rfind('.') != std::string::npos)
|
||||
extension = filename.substr(filename.rfind('.')+1);
|
||||
}
|
||||
|
||||
FileData::~FileData()
|
||||
{
|
||||
delete [] data;
|
||||
}
|
||||
|
||||
void * FileData::getData() const
|
||||
{
|
||||
return (void*)data;
|
||||
}
|
||||
|
||||
int FileData::getSize() const
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
const std::string & FileData::getFilename() const
|
||||
{
|
||||
return filename;
|
||||
}
|
||||
|
||||
const std::string & FileData::getExtension() const
|
||||
{
|
||||
return extension;
|
||||
}
|
||||
|
||||
} // physfs
|
||||
} // filesystem
|
||||
} // love
|
||||
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* 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_FILESYSTEM_PHYSFS_FILE_DATA_H
|
||||
#define LOVE_FILESYSTEM_PHYSFS_FILE_DATA_H
|
||||
|
||||
// LOVE
|
||||
#include <filesystem/FileData.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace filesystem
|
||||
{
|
||||
namespace physfs
|
||||
{
|
||||
class FileData : public love::filesystem::FileData
|
||||
{
|
||||
private:
|
||||
|
||||
// The actual data.
|
||||
char * data;
|
||||
|
||||
// Size of the data.
|
||||
int size;
|
||||
|
||||
// The filename used for error purposes.
|
||||
std::string filename;
|
||||
|
||||
// The extension (without dot). Used to identify file type.
|
||||
std::string extension;
|
||||
|
||||
public:
|
||||
|
||||
FileData(int size, const std::string & filename);
|
||||
|
||||
virtual ~FileData();
|
||||
|
||||
// Implements Data.
|
||||
void * getData() const;
|
||||
int getSize() const;
|
||||
|
||||
const std::string & getFilename() const;
|
||||
const std::string & getExtension() const;
|
||||
|
||||
}; // FileData
|
||||
|
||||
} // physfs
|
||||
} // filesystem
|
||||
} // love
|
||||
|
||||
#endif // LOVE_FILESYSTEM_PHYSFS_FILE_DATA_H
|
||||
@@ -0,0 +1,497 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#include "Filesystem.h"
|
||||
|
||||
// Physfs
|
||||
#include <physfs.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace filesystem
|
||||
{
|
||||
namespace physfs
|
||||
{
|
||||
Filesystem::Filesystem()
|
||||
: open_count(0), buffer(0)
|
||||
{
|
||||
// TODO: love.exe << fail
|
||||
if(!PHYSFS_init("love.exe"))
|
||||
throw Exception(PHYSFS_getLastError());
|
||||
}
|
||||
|
||||
Filesystem::~Filesystem()
|
||||
{
|
||||
PHYSFS_deinit();
|
||||
}
|
||||
|
||||
const char * Filesystem::getName() const
|
||||
{
|
||||
return "love.filesystem.physfs";
|
||||
}
|
||||
|
||||
bool Filesystem::setIdentity( const char * ident )
|
||||
{
|
||||
// Check whether save directory is already set.
|
||||
if(!save_identity.empty() || PHYSFS_getWriteDir() != 0)
|
||||
return false;
|
||||
|
||||
// Store the save directory.
|
||||
save_identity = std::string(ident);
|
||||
|
||||
// Generate the relative path to the game save folder.
|
||||
save_path_relative = std::string(LOVE_APPDATA_FOLDER LOVE_PATH_SEPARATOR) + save_identity;
|
||||
|
||||
// Generate the full path to the game save folder.
|
||||
save_path_full = std::string(getAppdataDirectory()) + std::string(LOVE_PATH_SEPARATOR);
|
||||
save_path_full += save_path_relative;
|
||||
|
||||
std::cout << save_path_full << std::endl;
|
||||
|
||||
// We now have something like:
|
||||
// save_identity: game
|
||||
// save_path_relative: ./LOVE/game
|
||||
// save_path_full: C:\Documents and Settings\user\Application Data/LOVE/game
|
||||
|
||||
// Try to add the save directory to the search path.
|
||||
// (No error on fail, it means that the path doesn't exist).
|
||||
PHYSFS_addToSearchPath(save_path_full.c_str(), 1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Filesystem::setSource(const char * source)
|
||||
{
|
||||
// Check whether directory is already set.
|
||||
if(!game_source.empty())
|
||||
return false;
|
||||
|
||||
// Add the directory.
|
||||
if(!PHYSFS_addToSearchPath(source, 0))
|
||||
return false;
|
||||
|
||||
// Save the game source.
|
||||
game_source = std::string(source);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Filesystem::setupWriteDirectory()
|
||||
{
|
||||
// These must all be set.
|
||||
if(save_identity.empty() || save_path_full.empty() || save_path_relative.empty())
|
||||
return false;
|
||||
|
||||
// Set the appdata folder as writable directory.
|
||||
// (We must create the save folder before mounting it).
|
||||
if(!PHYSFS_setWriteDir(getAppdataDirectory()))
|
||||
return false;
|
||||
|
||||
// Create the save folder. (We're now "at" %APPDATA%).
|
||||
if(!mkdir(save_path_relative.c_str()))
|
||||
{
|
||||
PHYSFS_setWriteDir(0); // Clear the write directory in case of error.
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set the final write directory.
|
||||
if(!PHYSFS_setWriteDir(save_path_full.c_str()))
|
||||
return false;
|
||||
|
||||
// Add the directory. (Well not be readded if already present).
|
||||
if(!PHYSFS_addToSearchPath(save_path_full.c_str(), 1))
|
||||
{
|
||||
PHYSFS_setWriteDir(0); // Clear the write directory in case of error.
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
File * Filesystem::newFile(const char *filename)
|
||||
{
|
||||
return new File(filename);
|
||||
}
|
||||
|
||||
FileData * Filesystem::newFileData(void * data, int size, const char * filename)
|
||||
{
|
||||
FileData * fd = new FileData(size, std::string(filename));
|
||||
|
||||
// Copy the data into
|
||||
memcpy(fd->getData(), data, size);
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
const char * Filesystem::getWorkingDirectory()
|
||||
{
|
||||
#ifdef LOVE_WINDOWS
|
||||
_getcwd(cwdbuffer, _MAX_PATH);
|
||||
#else
|
||||
char * temp = getcwd(cwdbuffer, MAXPATHLEN);
|
||||
if(temp == 0)
|
||||
return 0;
|
||||
#endif
|
||||
return cwdbuffer;
|
||||
}
|
||||
|
||||
const char * Filesystem::getUserDirectory()
|
||||
{
|
||||
return PHYSFS_getUserDir();
|
||||
}
|
||||
|
||||
const char * Filesystem::getAppdataDirectory()
|
||||
{
|
||||
#ifdef LOVE_WINDOWS
|
||||
return getenv("APPDATA");
|
||||
#else
|
||||
return getUserDirectory();
|
||||
#endif
|
||||
}
|
||||
|
||||
const char * Filesystem::getSaveDirectory()
|
||||
{
|
||||
return save_path_full.c_str();
|
||||
}
|
||||
|
||||
bool Filesystem::exists(const char * file)
|
||||
{
|
||||
if(PHYSFS_exists(file))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Filesystem::isDirectory(const char * file)
|
||||
{
|
||||
if(PHYSFS_isDirectory(file))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Filesystem::isFile(const char * file)
|
||||
{
|
||||
return exists(file) && !isDirectory(file);
|
||||
}
|
||||
|
||||
bool Filesystem::mkdir(const char * file)
|
||||
{
|
||||
if(PHYSFS_getWriteDir() == 0 && !setupWriteDirectory())
|
||||
return false;
|
||||
|
||||
if(!PHYSFS_mkdir(file))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Filesystem::remove(const char * file)
|
||||
{
|
||||
if(PHYSFS_getWriteDir() == 0 && !setupWriteDirectory())
|
||||
return false;
|
||||
|
||||
if(!PHYSFS_delete(file))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
int Filesystem::read(lua_State * L)
|
||||
{
|
||||
// The file to read from. The file must either be created
|
||||
// on-the-fly, or passed as a parameter.
|
||||
File * file;
|
||||
|
||||
if(lua_isstring(L, 1))
|
||||
{
|
||||
// Create the file.
|
||||
file = newFile(lua_tostring(L, 1));
|
||||
file->open(File::READ);
|
||||
}
|
||||
else
|
||||
return luaL_error(L, "Expected filename.");
|
||||
|
||||
// Optionally, the caller can specify whether to read
|
||||
// the whole file, or just a part of it.
|
||||
int count = luaL_optint(L, 2, file->getSize());
|
||||
|
||||
// Read the data.
|
||||
Data * data = file->read(count);
|
||||
|
||||
// Error check.
|
||||
if(data == 0)
|
||||
return luaL_error(L, "File could not be read.");
|
||||
|
||||
// Close and delete the file, if we created it.
|
||||
// (I.e. if the first parameter is a string).
|
||||
if(lua_isstring(L, 1))
|
||||
file->release();
|
||||
|
||||
// Push the string.
|
||||
lua_pushlstring(L, (char*)data->getData(), data->getSize());
|
||||
|
||||
// Push the size.
|
||||
lua_pushinteger(L, data->getSize());
|
||||
|
||||
// Lua has a copy now, so we can free it.
|
||||
data->release();
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
int Filesystem::write(lua_State * L)
|
||||
{
|
||||
// The file to write to. The file must either be created
|
||||
// on-the-fly, or passed as a parameter.
|
||||
File * file;
|
||||
|
||||
// We know for sure that the second parameter must be a
|
||||
// a string, so let's check that first.
|
||||
if(!lua_isstring(L, 2))
|
||||
return luaL_error(L, "Second argument must be a string.");
|
||||
|
||||
// The third paramter must be a number to indicate the size of
|
||||
// the data.
|
||||
if(!lua_isnumber(L, 3))
|
||||
return luaL_error(L, "Third argument must be a number.");
|
||||
|
||||
if(lua_isstring(L, 1))
|
||||
{
|
||||
// Create the file.
|
||||
file = newFile(lua_tostring(L, 1));
|
||||
}
|
||||
else
|
||||
return luaL_error(L, "Expected filename.");
|
||||
|
||||
// Get the current mode of the file.
|
||||
File::Mode mode = file->getMode();
|
||||
|
||||
if(mode == File::CLOSED)
|
||||
{
|
||||
// It should be possible to use append mode, but
|
||||
// normal File::Mode::Write is the default.
|
||||
int mode = luaL_optint(L, 4, File::WRITE);
|
||||
|
||||
// Open the file.
|
||||
if(!file->open((File::Mode)mode))
|
||||
return luaL_error(L, "Could not open file.");
|
||||
}
|
||||
|
||||
size_t length = 0;
|
||||
const char * input = lua_tolstring(L, 2, &length);
|
||||
|
||||
// Get how much we should write. Length of string default.
|
||||
length = luaL_optint(L, 3, length);
|
||||
|
||||
// Write the data.
|
||||
bool success = file->write(input, length);
|
||||
|
||||
// Close and delete the file, if we created
|
||||
// it in this function.
|
||||
if(lua_isstring(L, 1))
|
||||
{
|
||||
// Kill the file if "we" created it.
|
||||
file->close();
|
||||
file->release();
|
||||
}
|
||||
|
||||
if(!success)
|
||||
return luaL_error(L, "Data could not be written.");
|
||||
|
||||
lua_pushboolean(L, success);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Filesystem::enumerate(lua_State * L)
|
||||
{
|
||||
int n = lua_gettop(L);
|
||||
|
||||
if( n != 1 )
|
||||
return luaL_error(L, "Function requires a single parameter.");
|
||||
|
||||
int type = lua_type(L, 1);
|
||||
|
||||
if(type != LUA_TSTRING)
|
||||
return luaL_error(L, "Function requires parameter of type string.");
|
||||
|
||||
const char * dir = lua_tostring(L, 1);
|
||||
char **rc = PHYSFS_enumerateFiles(dir);
|
||||
char **i;
|
||||
int index = 1;
|
||||
|
||||
lua_newtable(L);
|
||||
|
||||
for (i = rc; *i != 0; i++)
|
||||
{
|
||||
lua_pushinteger(L, index);
|
||||
lua_pushstring(L, *i);
|
||||
lua_settable(L, -3);
|
||||
index++;
|
||||
}
|
||||
|
||||
PHYSFS_freeList(rc);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Filesystem::lines(lua_State * L)
|
||||
{
|
||||
File * file;
|
||||
|
||||
if(lua_isstring(L, 1))
|
||||
{
|
||||
file = newFile(lua_tostring(L, 1));
|
||||
if(!file->open(File::READ))
|
||||
return luaL_error(L, "Could not open file %s.\n", lua_tostring(L, 1));
|
||||
lua_pop(L, 1);
|
||||
|
||||
luax_newtype(L, "File", LOVE_FILESYSTEM_FILE_BITS, file, false);
|
||||
lua_pushboolean(L, 1); // 1 = autoclose.
|
||||
}
|
||||
else
|
||||
return luaL_error(L, "Expected filename.");
|
||||
|
||||
// Reset the file position.
|
||||
if(!file->seek(0))
|
||||
return luaL_error(L, "File does not appear to be open.\n");
|
||||
|
||||
lua_pushcclosure(L, lines_i, 2);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Filesystem::lines_i(lua_State * L)
|
||||
{
|
||||
// We're using a 1k buffer.
|
||||
const static int bufsize = 8;
|
||||
static char buf[bufsize];
|
||||
|
||||
File * file = luax_checktype<File>(L, lua_upvalueindex(1), "File", LOVE_FILESYSTEM_FILE_BITS);
|
||||
int close = (int)lua_tointeger(L, lua_upvalueindex(2));
|
||||
|
||||
// Find the next newline.
|
||||
// pos must be at the start of the line we're trying to find.
|
||||
int pos = file->tell();
|
||||
int newline = -1;
|
||||
int totalread = 0;
|
||||
|
||||
while(!file->eof())
|
||||
{
|
||||
int current = file->tell();
|
||||
int read = file->read(buf, bufsize);
|
||||
totalread += read;
|
||||
|
||||
if(read < 0)
|
||||
return luaL_error(L, "Readline failed!");
|
||||
|
||||
for(int i = 0;i<read;i++)
|
||||
{
|
||||
if(buf[i] == '\n')
|
||||
{
|
||||
newline = current+i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(newline > 0)
|
||||
break;
|
||||
}
|
||||
|
||||
// Special case for the last "line".
|
||||
if(newline <= 0 && file->eof() && totalread > 0)
|
||||
newline = pos + totalread;
|
||||
|
||||
// We've got a newline.
|
||||
if(newline > 0)
|
||||
{
|
||||
// Ok, we've got a line.
|
||||
int linesize = (newline-pos);
|
||||
|
||||
// Allocate memory for the string.
|
||||
char * str = new char[linesize];
|
||||
|
||||
// Read it.
|
||||
file->seek(pos);
|
||||
if(file->read(str, linesize) == -1)
|
||||
return luaL_error(L, "Read error.");
|
||||
|
||||
if(str[linesize-1]=='\r')
|
||||
linesize -= 1;
|
||||
|
||||
lua_pushlstring(L, str, linesize);
|
||||
|
||||
// Free the memory. Lua has a copy now.
|
||||
delete[] str;
|
||||
|
||||
// Set the beginning of the next line.
|
||||
if(!file->eof())
|
||||
file->seek(newline+1);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(close)
|
||||
{
|
||||
file->close();
|
||||
file->release();
|
||||
}
|
||||
|
||||
// else: (newline <= 0)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Filesystem::load(lua_State * L)
|
||||
{
|
||||
// Need only one arg.
|
||||
luax_assert_argc(L, 1, 1);
|
||||
|
||||
// Must be string.
|
||||
if(!lua_isstring(L, -1))
|
||||
return luaL_error(L, "The argument must be a string.");
|
||||
|
||||
const char * filename = lua_tostring(L, -1);
|
||||
|
||||
// The file must exist.
|
||||
if(!exists(filename))
|
||||
return luaL_error(L, "File %s does not exist.", filename);
|
||||
|
||||
// Create the file.
|
||||
File * file = newFile(filename);
|
||||
file->open(File::READ);
|
||||
|
||||
// Get the data from the file.
|
||||
Data * data = file->read();
|
||||
|
||||
int status = luaL_loadbuffer(L, (const char *)data->getData(), data->getSize(), filename);
|
||||
|
||||
data->release();
|
||||
file->release();
|
||||
|
||||
// Load the chunk, but don't run it.
|
||||
switch (status)
|
||||
{
|
||||
case LUA_ERRMEM:
|
||||
return luaL_error(L, "Memory allocation error: %s\n", lua_tostring(L, -1));
|
||||
case LUA_ERRSYNTAX:
|
||||
return luaL_error(L, "Syntax error: %s\n", lua_tostring(L, -1));
|
||||
default: // success
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
} // physfs
|
||||
} // filesystem
|
||||
} // love
|
||||
@@ -0,0 +1,267 @@
|
||||
/**
|
||||
* 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_FILESYSTEM_PHYSFS_FILESYSTEM_H
|
||||
#define LOVE_FILESYSTEM_PHYSFS_FILESYSTEM_H
|
||||
|
||||
// STD
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
// LOVE
|
||||
#include <common/Module.h>
|
||||
#include <common/config.h>
|
||||
#include <common/constants.h>
|
||||
|
||||
// Module
|
||||
#include "File.h"
|
||||
#include "FileData.h"
|
||||
|
||||
// For great CWD. (Current Working Directory)
|
||||
// Using this instead of boost::filesystem which totally
|
||||
// cramped our style.
|
||||
#ifdef LOVE_WINDOWS
|
||||
# include <direct.h>
|
||||
#else
|
||||
# include <sys/param.h>
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
// In Windows, we would like to use "LOVE" as the
|
||||
// application folder, but in Linux, we like .love.
|
||||
#ifdef LOVE_WINDOWS
|
||||
# define LOVE_APPDATA_FOLDER "LOVE"
|
||||
# define LOVE_PATH_SEPARATOR "/"
|
||||
# define LOVE_MAX_PATH _MAX_PATH
|
||||
#else
|
||||
# define LOVE_APPDATA_FOLDER ".love"
|
||||
# define LOVE_PATH_SEPARATOR "/"
|
||||
# define LOVE_MAX_PATH MAXPATHLEN
|
||||
#endif
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace filesystem
|
||||
{
|
||||
namespace physfs
|
||||
{
|
||||
class Filesystem : public Module
|
||||
{
|
||||
private:
|
||||
|
||||
// Counts open files.
|
||||
int open_count;
|
||||
|
||||
// Pointer used for file reads.
|
||||
char * buffer;
|
||||
|
||||
// Buffer used for getcwd in Linux.
|
||||
char cwdbuffer[LOVE_MAX_PATH];
|
||||
|
||||
// This name will be used to create the folder
|
||||
// in the appdata/userdata folder.
|
||||
std::string save_identity;
|
||||
|
||||
// Full and relative paths of the game save folder.
|
||||
// (Relative to the %APPDATA% folder, meaning that the
|
||||
// relative string will look something like: ./LOVE/game)
|
||||
std::string save_path_relative, save_path_full;
|
||||
|
||||
// The full path to the source of the game.
|
||||
std::string game_source;
|
||||
|
||||
protected:
|
||||
|
||||
public:
|
||||
|
||||
Filesystem();
|
||||
~Filesystem();
|
||||
|
||||
const char * getName() const;
|
||||
|
||||
/**
|
||||
* This sets up the save directory. If the
|
||||
* it is already set up, nothing happens.
|
||||
* @return True on success, false otherwise.
|
||||
**/
|
||||
bool setupWriteDirectory();
|
||||
|
||||
/**
|
||||
* Sets the name of the save folder.
|
||||
* @param ident The name of the game. Will be used to
|
||||
* to create the folder in the LOVE data folder.
|
||||
**/
|
||||
bool setIdentity(const char * ident);
|
||||
|
||||
/**
|
||||
* Sets the path to the game source.
|
||||
* This can only be set once.
|
||||
* @param source Path to a directory or a .love-file.
|
||||
**/
|
||||
bool setSource(const char * source);
|
||||
|
||||
/**
|
||||
* Creates a new file.
|
||||
**/
|
||||
File * newFile(const char* filename);
|
||||
|
||||
/**
|
||||
* Creates a new FileData object. Data will be copied.
|
||||
* @param data Pointer to the data.
|
||||
* @param size The size of the data.
|
||||
* @param filename The full filename used to file type identification.
|
||||
**/
|
||||
FileData * newFileData(void * data, int size, const char * filename);
|
||||
|
||||
/**
|
||||
* Gets the current working directory.
|
||||
**/
|
||||
const char * getWorkingDirectory();
|
||||
|
||||
/**
|
||||
* Gets the user home directory.
|
||||
**/
|
||||
const char * getUserDirectory();
|
||||
|
||||
/**
|
||||
* Gets the APPDATA directory. On Windows, this is the folder
|
||||
* in the %APPDATA% enviroment variable. On Linux, this is the
|
||||
* user home folder.
|
||||
**/
|
||||
const char * getAppdataDirectory();
|
||||
|
||||
/**
|
||||
* Gets the full path of the save folder.
|
||||
**/
|
||||
const char * getSaveDirectory();
|
||||
|
||||
/**
|
||||
* Checks whether a file exists in the current search path
|
||||
* or not.
|
||||
* @param file The filename to check.
|
||||
**/
|
||||
bool exists(const char * file);
|
||||
|
||||
/**
|
||||
* Checks if an existing file really is a directory.
|
||||
* @param file The filename to check.
|
||||
**/
|
||||
bool isDirectory(const char * file);
|
||||
|
||||
/**
|
||||
* Checks if an existing file really is a file,
|
||||
* and not a directory.
|
||||
* @param file The filename to check.
|
||||
**/
|
||||
bool isFile(const char * file);
|
||||
|
||||
/**
|
||||
* Creates a directory. Write dir must be set.
|
||||
* @param file The directory to create.
|
||||
**/
|
||||
bool mkdir(const char * file);
|
||||
|
||||
/**
|
||||
* Removes a file (or directory).
|
||||
* @param file The file or directory to remove.
|
||||
**/
|
||||
bool remove(const char * file);
|
||||
|
||||
/**
|
||||
* Opens a file for reading or writing. (Depends
|
||||
* on the mode chosen at the time of creation).
|
||||
* @param file The file to open.
|
||||
* @param mode The mode to open the file in.
|
||||
**/
|
||||
bool open(File * file, File::Mode mode);
|
||||
|
||||
/**
|
||||
* Closes a file.
|
||||
* @param file The file to close.
|
||||
**/
|
||||
bool close(File * file);
|
||||
|
||||
/**
|
||||
* Reads count bytes from an open file.
|
||||
* The first parameter is either a File or
|
||||
* a string. An optional second parameter specified the
|
||||
* max number of bytes to read.
|
||||
**/
|
||||
int read(lua_State * L);
|
||||
|
||||
/**
|
||||
* Write the bytes in data to the file. File
|
||||
* must be opened for write.
|
||||
* The first parameter is either a File or
|
||||
* a string.
|
||||
**/
|
||||
int write(lua_State * L);
|
||||
|
||||
/**
|
||||
* Check if end-of-file is reached.
|
||||
* @return True if EOF, false otherwise.
|
||||
**/
|
||||
bool eof(File * file);
|
||||
|
||||
/**
|
||||
* Gets the current position in a file.
|
||||
* @param file An open File.
|
||||
**/
|
||||
int tell(File * file);
|
||||
|
||||
/**
|
||||
* Seek to a position within a file.
|
||||
* @param pos The position to seek to.
|
||||
**/
|
||||
bool seek(File * file, int pos);
|
||||
|
||||
/**
|
||||
* This "native" method returns a table of all
|
||||
* files in a given directory.
|
||||
**/
|
||||
int enumerate(lua_State * L);
|
||||
|
||||
/**
|
||||
* Returns an iterator which iterates over
|
||||
* lines in files.
|
||||
**/
|
||||
int lines(lua_State * L);
|
||||
|
||||
/**
|
||||
* The line iterator function.
|
||||
**/
|
||||
static int lines_i(lua_State * L);
|
||||
|
||||
/**
|
||||
* Loads a file without running it. The loaded
|
||||
* chunk is returned as a function.
|
||||
* @param filename The filename of the file to load.
|
||||
* @return A function.
|
||||
**/
|
||||
int load(lua_State * L);
|
||||
|
||||
}; // Filesystem
|
||||
|
||||
} // physfs
|
||||
} // filesystem
|
||||
} // love
|
||||
|
||||
#endif // LOVE_FILESYSTEM_PHYSFS_FILESYSTEM_H
|
||||
@@ -0,0 +1,225 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#include "wrap_File.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace filesystem
|
||||
{
|
||||
namespace physfs
|
||||
{
|
||||
File * luax_checkfile(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<File>(L, idx, "File", LOVE_FILESYSTEM_FILE_BITS);
|
||||
}
|
||||
|
||||
int _wrap_File_getSize(lua_State * L)
|
||||
{
|
||||
File * t = luax_checkfile(L, 1);
|
||||
lua_pushinteger(L, t->getSize());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_File_open(lua_State * L)
|
||||
{
|
||||
File * file = luax_checkfile(L, 1);
|
||||
int mode = luaL_optint(L, 2, File::READ);
|
||||
lua_pushboolean(L, file->open((File::Mode)mode) ? 1 : 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_File_close(lua_State * L)
|
||||
{
|
||||
File * file = luax_checkfile(L, 1);
|
||||
lua_pushboolean(L, file->close() ? 1 : 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_File_read(lua_State * L)
|
||||
{
|
||||
File * file = luax_checkfile(L, 1);
|
||||
Data * d = file->read(luaL_optint(L, 2, file->getSize()));
|
||||
lua_pushlstring(L, (const char*) d->getData(), d->getSize());
|
||||
lua_pushnumber(L, d->getSize());
|
||||
d->release();
|
||||
return 2;
|
||||
}
|
||||
|
||||
int _wrap_File_write(lua_State * L)
|
||||
{
|
||||
File * file = luax_checkfile(L, 1);
|
||||
bool result;
|
||||
if ( file->getMode() == File::CLOSED )
|
||||
return luaL_error(L, "File is not open.");
|
||||
if ( lua_isstring(L, 2) )
|
||||
result = file->write(lua_tostring(L, 2), luaL_optint(L, 3, lua_objlen(L, 2)));
|
||||
else
|
||||
return luaL_error(L, "String expected.");
|
||||
lua_pushboolean(L, result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_File_eof(lua_State * L)
|
||||
{
|
||||
File * file = luax_checkfile(L, 1);
|
||||
lua_pushboolean(L, file->eof() ? 1 : 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_File_tell(lua_State * L)
|
||||
{
|
||||
File * file = luax_checkfile(L, 1);
|
||||
lua_pushinteger(L, file->tell());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_File_seek(lua_State * L)
|
||||
{
|
||||
File * file = luax_checkfile(L, 1);
|
||||
int pos = luaL_checkinteger(L, 2);
|
||||
lua_pushboolean(L, file->seek(pos) ? 1 : 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
//yes, the following two are copy-pasted and slightly edited
|
||||
|
||||
int _wrap_File_lines(lua_State * L)
|
||||
{
|
||||
File * file;
|
||||
|
||||
if(luax_istype(L, 1, LOVE_FILESYSTEM_FILE_BITS))
|
||||
{
|
||||
file = luax_checktype<File>(L, 1, "File", LOVE_FILESYSTEM_FILE_BITS);
|
||||
lua_pushboolean(L, 0); // 0 = do not close.
|
||||
}
|
||||
else
|
||||
return luaL_error(L, "Expected file handle.");
|
||||
|
||||
// Reset the file position.
|
||||
if(!file->seek(0))
|
||||
return luaL_error(L, "File does not appear to be open.\n");
|
||||
|
||||
lua_pushcclosure(L, lines_i, 2);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int lines_i(lua_State * L)
|
||||
{
|
||||
// We're using a 1k buffer.
|
||||
const static int bufsize = 1024;
|
||||
static char buf[bufsize];
|
||||
|
||||
File * file = luax_checktype<File>(L, lua_upvalueindex(1), "File", LOVE_FILESYSTEM_FILE_BITS);
|
||||
int close = (int)lua_tointeger(L, lua_upvalueindex(2));
|
||||
|
||||
// Find the next newline.
|
||||
// pos must be at the start of the line we're trying to find.
|
||||
int pos = file->tell();
|
||||
int newline = -1;
|
||||
int totalread = 0;
|
||||
|
||||
while(!file->eof())
|
||||
{
|
||||
int current = file->tell();
|
||||
int read = file->read(buf, bufsize);
|
||||
totalread += read;
|
||||
|
||||
if(read < 0)
|
||||
return luaL_error(L, "Readline failed!");
|
||||
|
||||
for(int i = 0;i<read;i++)
|
||||
{
|
||||
if(buf[i] == '\n')
|
||||
{
|
||||
newline = current+i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(newline > 0)
|
||||
break;
|
||||
}
|
||||
|
||||
// Special case for the last "line".
|
||||
if(newline <= 0 && file->eof() && totalread > 0)
|
||||
newline = pos + totalread;
|
||||
|
||||
// We've got a newline.
|
||||
if(newline > 0)
|
||||
{
|
||||
// Ok, we've got a line.
|
||||
int linesize = (newline-pos);
|
||||
|
||||
// Allocate memory for the string.
|
||||
char * str = new char[linesize];
|
||||
|
||||
// Read it.
|
||||
file->seek(pos);
|
||||
if(file->read(str, linesize) == -1)
|
||||
return luaL_error(L, "Read error.");
|
||||
|
||||
if(str[linesize-1]=='\r')
|
||||
linesize -= 1;
|
||||
|
||||
lua_pushlstring(L, str, linesize);
|
||||
|
||||
// Free the memory. Lua has a copy now.
|
||||
delete[] str;
|
||||
|
||||
// Set the beginning of the next line.
|
||||
if(!file->eof())
|
||||
file->seek(newline+1);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(close)
|
||||
{
|
||||
file->close();
|
||||
file->release();
|
||||
}
|
||||
|
||||
// else: (newline <= 0)
|
||||
return 0;
|
||||
}
|
||||
|
||||
const luaL_Reg wrap_File_functions[] = {
|
||||
{ "getSize", _wrap_File_getSize },
|
||||
{ "open", _wrap_File_open },
|
||||
{ "close", _wrap_File_close },
|
||||
{ "read", _wrap_File_read },
|
||||
{ "write", _wrap_File_write },
|
||||
{ "eof", _wrap_File_eof },
|
||||
{ "tell", _wrap_File_tell },
|
||||
{ "seek", _wrap_File_seek },
|
||||
{ "lines", _wrap_File_lines },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int wrap_File_open(lua_State * L)
|
||||
{
|
||||
luax_register_type(L, "File", wrap_File_functions);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // physfs
|
||||
} // filesystem
|
||||
} // love
|
||||
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* 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_FILESYSTEM_PHYSFS_WRAP_FILE_H
|
||||
#define LOVE_FILESYSTEM_PHYSFS_WRAP_FILE_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "File.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace filesystem
|
||||
{
|
||||
namespace physfs
|
||||
{
|
||||
File * luax_checkfile(lua_State * L, int idx);
|
||||
int _wrap_File_getSize(lua_State * L);
|
||||
int _wrap_File_open(lua_State * L);
|
||||
int _wrap_File_close(lua_State * L);
|
||||
int _wrap_File_read(lua_State * L);
|
||||
int _wrap_File_write(lua_State * L);
|
||||
int _wrap_File_eof(lua_State * L);
|
||||
int _wrap_File_tell(lua_State * L);
|
||||
int _wrap_File_seek(lua_State * L);
|
||||
int _wrap_File_lines(lua_State * L);
|
||||
int lines_i(lua_State * L);
|
||||
int wrap_File_open(lua_State * L);
|
||||
} // physfs
|
||||
} // filesystem
|
||||
} // love
|
||||
|
||||
#endif // LOVE_FILESYSTEM_PHYSFS_WRAP_FILE_H
|
||||
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#include "wrap_FileData.h"
|
||||
|
||||
#include <common/wrap_Data.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace filesystem
|
||||
{
|
||||
namespace physfs
|
||||
{
|
||||
FileData * luax_checkfiledata(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<FileData>(L, idx, "FileData", LOVE_FILESYSTEM_FILE_DATA_BITS);
|
||||
}
|
||||
|
||||
int _wrap_FileData_getFilename(lua_State * L)
|
||||
{
|
||||
FileData * t = luax_checkfiledata(L, 1);
|
||||
lua_pushstring(L, t->getFilename().c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_FileData_getExtension(lua_State * L)
|
||||
{
|
||||
FileData * t = luax_checkfiledata(L, 1);
|
||||
lua_pushstring(L, t->getExtension().c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
const luaL_Reg wrap_FileData_functions[] = {
|
||||
|
||||
// Data
|
||||
{ "getPointer", _wrap_Data_getPointer },
|
||||
{ "getSize", _wrap_Data_getSize },
|
||||
|
||||
{ "getFilename", _wrap_FileData_getFilename },
|
||||
{ "getExtension", _wrap_FileData_getExtension },
|
||||
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int wrap_FileData_open(lua_State * L)
|
||||
{
|
||||
luax_register_type(L, "FileData", wrap_FileData_functions);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // physfs
|
||||
} // filesystem
|
||||
} // love
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* 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_FILESYSTEM_PHYSFS_WRAP_FILE_DATA_H
|
||||
#define LOVE_FILESYSTEM_PHYSFS_WRAP_FILE_DATA_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
|
||||
#include "FileData.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace filesystem
|
||||
{
|
||||
namespace physfs
|
||||
{
|
||||
FileData * luax_checkfiledata(lua_State * L, int idx);
|
||||
int _wrap_FileData_getFilename(lua_State * L);
|
||||
int _wrap_FileData_getExtension(lua_State * L);
|
||||
int wrap_FileData_open(lua_State * L);
|
||||
} // physfs
|
||||
} // filesystem
|
||||
} // love
|
||||
|
||||
#endif // LOVE_FILESYSTEM_PHYSFS_WRAP_FILE_DATA_H
|
||||
@@ -0,0 +1,252 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
// LOVE
|
||||
#include "wrap_Filesystem.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace filesystem
|
||||
{
|
||||
namespace physfs
|
||||
{
|
||||
static Filesystem * instance = 0;
|
||||
|
||||
bool hack_setupWriteDirectory()
|
||||
{
|
||||
if(instance != 0)
|
||||
return instance->setupWriteDirectory();
|
||||
return false;
|
||||
}
|
||||
|
||||
int _wrap_setIdentity(lua_State * L)
|
||||
{
|
||||
const char * arg = luaL_checkstring(L, 1);
|
||||
|
||||
if(!instance->setIdentity(arg))
|
||||
return luaL_error(L, "Could not set write directory.");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_setSource(lua_State * L)
|
||||
{
|
||||
const char * arg = luaL_checkstring(L, 1);
|
||||
|
||||
if(!instance->setSource(arg))
|
||||
return luaL_error(L, "Could not set source.");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_newFile(lua_State * L)
|
||||
{
|
||||
const char * filename = luaL_checkstring(L, 1);
|
||||
File * t = instance->newFile(filename);
|
||||
luax_newtype(L, "File", LOVE_FILESYSTEM_FILE_BITS, (void*)t);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_newFileData(lua_State * L)
|
||||
{
|
||||
if(!lua_isstring(L, 1))
|
||||
return luaL_error(L, "String expected.");
|
||||
if(!lua_isstring(L, 2))
|
||||
return luaL_error(L, "String expected.");
|
||||
|
||||
size_t length = 0;
|
||||
const char * str = lua_tolstring(L, 1, &length);
|
||||
const char * filename = lua_tostring(L, 2);
|
||||
|
||||
FileData * t = instance->newFileData((void*)str, (int)length, filename);
|
||||
|
||||
luax_newtype(L, "FileData", LOVE_FILESYSTEM_FILE_DATA_BITS, (void*)t);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_getWorkingDirectory(lua_State * L)
|
||||
{
|
||||
lua_pushstring(L, instance->getWorkingDirectory());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_getUserDirectory(lua_State * L)
|
||||
{
|
||||
lua_pushstring(L, instance->getUserDirectory());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_getAppdataDirectory(lua_State * L)
|
||||
{
|
||||
lua_pushstring(L, instance->getAppdataDirectory());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_getSaveDirectory(lua_State * L)
|
||||
{
|
||||
lua_pushstring(L, instance->getSaveDirectory());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_exists(lua_State * L)
|
||||
{
|
||||
const char * arg = luaL_checkstring(L, 1);
|
||||
lua_pushboolean(L, instance->exists(arg) ? 1 : 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_isDirectory(lua_State * L)
|
||||
{
|
||||
const char * arg = luaL_checkstring(L, 1);
|
||||
lua_pushboolean(L, instance->isDirectory(arg) ? 1 : 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_isFile(lua_State * L)
|
||||
{
|
||||
const char * arg = luaL_checkstring(L, 1);
|
||||
lua_pushboolean(L, instance->isFile(arg) ? 1 : 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_mkdir(lua_State * L)
|
||||
{
|
||||
const char * arg = luaL_checkstring(L, 1);
|
||||
lua_pushboolean(L, instance->mkdir(arg) ? 1 : 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_remove(lua_State * L)
|
||||
{
|
||||
const char * arg = luaL_checkstring(L, 1);
|
||||
lua_pushboolean(L, instance->remove(arg) ? 1 : 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_read(lua_State * L)
|
||||
{
|
||||
return instance->read(L);
|
||||
}
|
||||
|
||||
int _wrap_write(lua_State * L)
|
||||
{
|
||||
return instance->write(L);
|
||||
}
|
||||
|
||||
int _wrap_enumerate(lua_State * L)
|
||||
{
|
||||
return instance->enumerate(L);
|
||||
}
|
||||
|
||||
int _wrap_lines(lua_State * L)
|
||||
{
|
||||
return instance->lines(L);
|
||||
}
|
||||
|
||||
int _wrap_load(lua_State * L)
|
||||
{
|
||||
return instance->load(L);
|
||||
}
|
||||
|
||||
int loader(lua_State * L)
|
||||
{
|
||||
const char * filename = lua_tostring(L, -1);
|
||||
|
||||
std::string tmp(filename);
|
||||
|
||||
int size = tmp.size();
|
||||
|
||||
if(size <= 4 || strcmp(filename + (size-4), ".lua") != 0)
|
||||
tmp.append(".lua");
|
||||
|
||||
for(int i=0;i<size-4;i++)
|
||||
{
|
||||
if(tmp[i] == '.')
|
||||
{
|
||||
tmp[i] = '/';
|
||||
}
|
||||
}
|
||||
|
||||
// Check whether file exists.
|
||||
if(!instance->exists(tmp.c_str()))
|
||||
{
|
||||
lua_pushfstring(L, "\n\tno file \"%s\" in LOVE game directories.\n", tmp.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
lua_pop(L, 1);
|
||||
lua_pushstring(L, tmp.c_str());
|
||||
|
||||
// Ok, load it.
|
||||
return instance->load(L);
|
||||
}
|
||||
|
||||
// List of functions to wrap.
|
||||
const luaL_Reg wrap_Filesystem_functions[] = {
|
||||
{ "setIdentity", _wrap_setIdentity },
|
||||
{ "setSource", _wrap_setSource },
|
||||
{ "newFile", _wrap_newFile },
|
||||
{ "getWorkingDirectory", _wrap_getWorkingDirectory },
|
||||
{ "getUserDirectory", _wrap_getUserDirectory },
|
||||
{ "getAppdataDirectory", _wrap_getAppdataDirectory },
|
||||
{ "getSaveDirectory", _wrap_getSaveDirectory },
|
||||
{ "exists", _wrap_exists },
|
||||
{ "isDirectory", _wrap_isDirectory },
|
||||
{ "isFile", _wrap_isFile },
|
||||
{ "mkdir", _wrap_mkdir },
|
||||
{ "remove", _wrap_remove },
|
||||
{ "read", _wrap_read },
|
||||
{ "write", _wrap_write },
|
||||
{ "enumerate", _wrap_enumerate },
|
||||
{ "lines", _wrap_lines },
|
||||
{ "load", _wrap_load },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
const lua_CFunction wrap_Filesystem_types[] = {
|
||||
wrap_File_open,
|
||||
wrap_FileData_open,
|
||||
0
|
||||
};
|
||||
|
||||
int wrap_Filesystem_open(lua_State * L)
|
||||
{
|
||||
if(instance == 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
instance = new Filesystem();
|
||||
love::luax_register_searcher(L, loader);
|
||||
}
|
||||
catch(Exception & e)
|
||||
{
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
}
|
||||
|
||||
luax_register_gc(L, "love.filesystem", instance);
|
||||
|
||||
return luax_register_module(L, wrap_Filesystem_functions, wrap_Filesystem_types);
|
||||
}
|
||||
|
||||
} // physfs
|
||||
} // filesystem
|
||||
} // love
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* 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_FILESYSTEM_PHYSFS_WRAP_FILESYSTEM_H
|
||||
#define LOVE_FILESYSTEM_PHYSFS_WRAP_FILESYSTEM_H
|
||||
|
||||
// LOVE
|
||||
#include "Filesystem.h"
|
||||
#include "wrap_File.h"
|
||||
#include "wrap_FileData.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace filesystem
|
||||
{
|
||||
namespace physfs
|
||||
{
|
||||
bool hack_setupWriteDirectory();
|
||||
int _wrap_setIdentity(lua_State * L);
|
||||
int _wrap_setSource(lua_State * L);
|
||||
int _wrap_newFile(lua_State * L);
|
||||
int _wrap_newFileData(lua_State * L);
|
||||
int _wrap_getWorkingDirectory(lua_State * L);
|
||||
int _wrap_getUserDirectory(lua_State * L);
|
||||
int _wrap_getAppdataDirectory(lua_State * L);
|
||||
int _wrap_getSaveDirectory(lua_State * L);
|
||||
int _wrap_exists(lua_State * L);
|
||||
int _wrap_isDirectory(lua_State * L);
|
||||
int _wrap_isFile(lua_State * L);
|
||||
int _wrap_mkdir(lua_State * L);
|
||||
int _wrap_remove(lua_State * L);
|
||||
int _wrap_open(lua_State * L);
|
||||
int _wrap_close(lua_State * L);
|
||||
int _wrap_read(lua_State * L);
|
||||
int _wrap_write(lua_State * L);
|
||||
int _wrap_eof(lua_State * L);
|
||||
int _wrap_tell(lua_State * L);
|
||||
int _wrap_seek(lua_State * L);
|
||||
int _wrap_enumerate(lua_State * L);
|
||||
int _wrap_lines(lua_State * L);
|
||||
int _wrap_load(lua_State * L);
|
||||
int loader(lua_State * L);
|
||||
int wrap_Filesystem_open(lua_State * L);
|
||||
|
||||
} // physfs
|
||||
} // filesystem
|
||||
} // love
|
||||
|
||||
#endif // LOVE_FILESYSTEM_PHYSFS_WRAP_FILESYSTEM_H
|
||||
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#include "Drawable.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
|
||||
Drawable::~Drawable()
|
||||
{
|
||||
}
|
||||
|
||||
} // graphics
|
||||
} // love
|
||||
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* 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_GRAPHICS_DRAWABLE_H
|
||||
#define LOVE_GRAPHICS_DRAWABLE_H
|
||||
|
||||
// LOVE
|
||||
#include <common/Object.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
/**
|
||||
* A Drawable is anything that can be drawn on screen with a
|
||||
* position, scale and orientation.
|
||||
**/
|
||||
class Drawable : public Object
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
**/
|
||||
virtual ~Drawable();
|
||||
|
||||
/**
|
||||
* Draws the object with the specified transformation.
|
||||
*
|
||||
* @param x The position of the object along the x-axis.
|
||||
* @param y The position of the object along the y-axis.
|
||||
* @param angle The angle of the object (in radians).
|
||||
* @param sx The scale factor along the x-axis.
|
||||
* @param sy The scale factor along the y-axis.
|
||||
* @param ox The origin offset along the x-axis.
|
||||
* @param oy The origin offset along the y-axis.
|
||||
**/
|
||||
virtual void draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const = 0;
|
||||
};
|
||||
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_DRAWABLE_H
|
||||
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#include "Volatile.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
|
||||
// Static members.
|
||||
std::list<Volatile *> Volatile::all;
|
||||
|
||||
Volatile::Volatile()
|
||||
{
|
||||
// Insert this object into "all".
|
||||
all.push_back(this);
|
||||
}
|
||||
|
||||
Volatile::~Volatile()
|
||||
{
|
||||
// Remove the pointer to this object.
|
||||
all.remove(this);
|
||||
}
|
||||
|
||||
bool Volatile::loadAll()
|
||||
{
|
||||
bool success = true;
|
||||
std::list<Volatile *>::iterator i = all.begin();
|
||||
|
||||
while( i != all.end() )
|
||||
{
|
||||
success = success && (*i)->loadVolatile();
|
||||
i++;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
void Volatile::unloadAll()
|
||||
{
|
||||
std::list<Volatile *>::iterator i = all.begin();
|
||||
|
||||
while( i != all.end() )
|
||||
{
|
||||
(*i)->unloadVolatile();
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
} // graphics
|
||||
} // love
|
||||
@@ -0,0 +1,92 @@
|
||||
/**
|
||||
* 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_GRAPHICS_VOLATILE_H
|
||||
#define LOVE_GRAPHICS_VOLATILE_H
|
||||
|
||||
// STL
|
||||
#include <list>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
/**
|
||||
* This class is the superclass of all objects which must completely or
|
||||
* partially reload when the user changes the display resolution. All
|
||||
* volatile objects will be notified when the display mode changes.
|
||||
*
|
||||
* @author Anders Ruud
|
||||
**/
|
||||
class Volatile
|
||||
{
|
||||
private:
|
||||
|
||||
// A list of all Volatile object currently alive.
|
||||
static std::list<Volatile *> all;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor. Automatically adds \c this into the list
|
||||
* of volatile objects.
|
||||
**/
|
||||
Volatile();
|
||||
|
||||
/**
|
||||
* Destructor. Removes \c this from the list of volatile
|
||||
* objects.
|
||||
**/
|
||||
virtual ~Volatile();
|
||||
|
||||
/**
|
||||
* Loads the part(s) of the object which is destroyed when
|
||||
* the display mode is changed.
|
||||
*
|
||||
* @return True if successful, false on errors.
|
||||
**/
|
||||
virtual bool loadVolatile() = 0;
|
||||
|
||||
/**
|
||||
* Unloads the part(s) of the objects which would be destroyed
|
||||
* anyway when the display mode is changed.
|
||||
**/
|
||||
virtual void unloadVolatile() = 0;
|
||||
|
||||
// Static:
|
||||
|
||||
/**
|
||||
* Calls \c loadVolatile() on each element in the list of volatiles.
|
||||
*
|
||||
* @return True if all elements succeeded, false if one or more failed.
|
||||
**/
|
||||
static bool loadAll();
|
||||
|
||||
/**
|
||||
* Calls \c unloadVolatile() on each element in the list of volatiles.
|
||||
**/
|
||||
static void unloadAll();
|
||||
|
||||
}; // Volatile
|
||||
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_VOLATILE_H
|
||||
@@ -0,0 +1,235 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#include "Animation.h"
|
||||
|
||||
// STD
|
||||
#include <cmath>
|
||||
|
||||
// LOVE
|
||||
#include <common/constants.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
Animation::Animation(Image * image)
|
||||
: image(image), mode(1), current(0), playing(true),
|
||||
timeBuffer(0), direction(1), speed(1.0f)
|
||||
{
|
||||
image->retain();
|
||||
}
|
||||
|
||||
Animation::Animation(Image * image, float fw, float fh, float delay, int num)
|
||||
: image(image), mode(1), current(0), playing(true), timeBuffer(0), direction(1), speed(1.0f)
|
||||
{
|
||||
|
||||
image->retain();
|
||||
|
||||
// Generate frames.
|
||||
int w = (int)(image->getWidth()/fw);
|
||||
int h = (int)(image->getHeight()/fh);
|
||||
|
||||
int real_num = (num == 0) ? (w * h) : num;
|
||||
if(real_num > (w * h)) real_num = (w * h);
|
||||
|
||||
for(int i = 0;i<real_num;i++)
|
||||
{
|
||||
int x = (int)((i % w)*fw);
|
||||
int y = (int)((i/w)*fh);
|
||||
|
||||
addFrame((float)x, (float)y, fw, fh, delay);
|
||||
}
|
||||
}
|
||||
|
||||
Animation::~Animation()
|
||||
{
|
||||
if(image != 0)
|
||||
image->release();
|
||||
}
|
||||
|
||||
void Animation::addFrame(float x, float y, float w, float h, float delay)
|
||||
{
|
||||
// Add delay.
|
||||
delays.push_back(delay);
|
||||
|
||||
// Add frame.
|
||||
AnimationFrame f;
|
||||
f.x = x;
|
||||
f.y = y;
|
||||
f.w = w;
|
||||
f.h = h;
|
||||
f.postDelay = (int)delays.size() - 1;
|
||||
|
||||
frames.push_back(f);
|
||||
|
||||
if(frames.size() > 1)
|
||||
{
|
||||
frames.back().preDelay = frames[frames.size() - 2].postDelay;
|
||||
|
||||
// Update delay of first frame.
|
||||
frames.front().preDelay = frames.back().postDelay;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Animation::setMode(int mode)
|
||||
{
|
||||
this->mode = mode;
|
||||
}
|
||||
|
||||
void Animation::play()
|
||||
{
|
||||
playing = true;
|
||||
}
|
||||
|
||||
void Animation::stop()
|
||||
{
|
||||
playing = false;
|
||||
}
|
||||
|
||||
void Animation::reset()
|
||||
{
|
||||
current = 0;
|
||||
timeBuffer = 0;
|
||||
}
|
||||
|
||||
void Animation::seek(int frame)
|
||||
{
|
||||
if(frame >= 0 && frame < (int)frames.size())
|
||||
current = frame;
|
||||
}
|
||||
|
||||
int Animation::getCurrentFrame() const
|
||||
{
|
||||
return current;
|
||||
}
|
||||
|
||||
int Animation::getSize() const
|
||||
{
|
||||
return (int)frames.size();
|
||||
}
|
||||
|
||||
void Animation::setDelay(int frame, float delay)
|
||||
{
|
||||
if(frame >= 0 && frame < (int)frames.size())
|
||||
delays[frames[0].postDelay] = delay;
|
||||
}
|
||||
|
||||
void Animation::setSpeed(float speed)
|
||||
{
|
||||
this->speed = speed;
|
||||
}
|
||||
|
||||
float Animation::getSpeed() const
|
||||
{
|
||||
return speed;
|
||||
}
|
||||
|
||||
void Animation::update(float dt)
|
||||
{
|
||||
if(!playing)
|
||||
return;
|
||||
|
||||
if(frames.size() <= 0)
|
||||
return;
|
||||
|
||||
timeBuffer += (dt * speed);
|
||||
|
||||
int next;
|
||||
float d;
|
||||
|
||||
switch(mode)
|
||||
{
|
||||
case ANIMATION_LOOP:
|
||||
next = current;
|
||||
while(timeBuffer >= delays[frames[current].postDelay])
|
||||
{
|
||||
timeBuffer -= delays[frames[current].postDelay];
|
||||
if(++next >= (int)frames.size())
|
||||
next = 0;
|
||||
}
|
||||
current = next;
|
||||
break;
|
||||
case ANIMATION_PLAY_ONCE:
|
||||
next = current;
|
||||
while(timeBuffer >= delays[frames[current].postDelay])
|
||||
{
|
||||
timeBuffer -= delays[frames[current].postDelay];
|
||||
if(++next >= (int)frames.size())
|
||||
{
|
||||
next--;
|
||||
playing = false;
|
||||
timeBuffer = 0;
|
||||
}
|
||||
}
|
||||
current = next;
|
||||
break;
|
||||
case ANIMATION_BOUNCE:
|
||||
next = current;
|
||||
d = (direction == 1) ? delays[frames[next].postDelay] : delays[frames[next].preDelay];
|
||||
|
||||
while(timeBuffer >= d)
|
||||
{
|
||||
timeBuffer -= d;
|
||||
next += direction;
|
||||
if(next < 0 || next >= (int)frames.size())
|
||||
{
|
||||
direction *= -1;
|
||||
next += direction;
|
||||
}
|
||||
d = (direction == 1) ? delays[frames[next].postDelay] : delays[frames[next].preDelay];
|
||||
}
|
||||
current = next;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Animation::draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const
|
||||
{
|
||||
if(frames.size() <= 0)
|
||||
return;
|
||||
|
||||
const AnimationFrame & f = frames[current];
|
||||
image->draws(x, y, angle, sx, sy, ox, oy, f.x, f.y, f.w, f.h);
|
||||
}
|
||||
|
||||
float Animation::getWidth() const
|
||||
{
|
||||
if(frames.size() <= 0)
|
||||
return 0;
|
||||
|
||||
return frames[current].w;
|
||||
}
|
||||
|
||||
float Animation::getHeight() const
|
||||
{
|
||||
if(frames.size() <= 0)
|
||||
return 0;
|
||||
|
||||
return frames[current].h;
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
@@ -0,0 +1,172 @@
|
||||
/**
|
||||
* 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_OPENGL_ANIMATION_H
|
||||
#define LOVE_OPENGL_ANIMATION_H
|
||||
|
||||
// LOVE
|
||||
#include "../Drawable.h"
|
||||
#include "Image.h"
|
||||
|
||||
// STD
|
||||
#include <vector>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
// Represents a single frame.
|
||||
struct AnimationFrame
|
||||
{
|
||||
float x, y; // Top left corner of the frame.
|
||||
float w, h; // Size of the frame.
|
||||
int preDelay; // Delay to previous frame.
|
||||
int postDelay; // Delay to next frame.
|
||||
};
|
||||
|
||||
class Animation : public Drawable
|
||||
{
|
||||
private:
|
||||
|
||||
// The source of the animation.
|
||||
Image * image;
|
||||
|
||||
// Delays between frames.
|
||||
// delays[0] is the delay between frames[0] and frames[1].
|
||||
std::vector<float> delays;
|
||||
|
||||
// Holds all the frames.
|
||||
std::vector<AnimationFrame> frames;
|
||||
|
||||
// Animation mode.
|
||||
int mode;
|
||||
|
||||
// The current frame.
|
||||
int current;
|
||||
|
||||
// True if playing, false otherwise.
|
||||
bool playing;
|
||||
|
||||
// "Left over"-time.
|
||||
float timeBuffer;
|
||||
|
||||
// Used for bounce mode.
|
||||
int direction;
|
||||
|
||||
// Overall speed. (1 = normal).
|
||||
float speed;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates an Animation with no frames.
|
||||
* @param image The image to use as the source.
|
||||
**/
|
||||
Animation(Image * image);
|
||||
|
||||
/**
|
||||
* Creates an Animation with frames from top-left to bottom right.
|
||||
* @param image The image to use as the source.
|
||||
* @param fw The width of each frame.
|
||||
* @param fh The height of each frame.
|
||||
* @param delay The delay after each frame.
|
||||
* @param num The number of frames. (0 = all)
|
||||
**/
|
||||
Animation(Image * image, float fw, float fh, float delay, int num = 0);
|
||||
|
||||
virtual ~Animation();
|
||||
|
||||
/**
|
||||
* Adds a single frame.
|
||||
* @param x The top-left corner of the frame.
|
||||
* @param y The top-right corner of the frame.
|
||||
* @param w The width of the frame.
|
||||
* @param h The height of the frame.
|
||||
* @param delay The delay after the frame.
|
||||
**/
|
||||
void addFrame(float x, float y, float w, float h, float delay);
|
||||
|
||||
/**
|
||||
* Sets the current animation mode, and reset.
|
||||
**/
|
||||
void setMode(int mode);
|
||||
|
||||
/**
|
||||
* Causes the Animation to start playing.
|
||||
**/
|
||||
void play();
|
||||
|
||||
/**
|
||||
* Causes the Animation to stop.
|
||||
**/
|
||||
void stop();
|
||||
|
||||
/**
|
||||
* Resets the Animation.
|
||||
**/
|
||||
void reset();
|
||||
|
||||
/**
|
||||
* Resets timebuffers, and sets the current frame directly.
|
||||
**/
|
||||
void seek(int frame);
|
||||
|
||||
/**
|
||||
* Gets the current frame.
|
||||
**/
|
||||
int getCurrentFrame() const;
|
||||
|
||||
/**
|
||||
* Gets amount of frames.
|
||||
**/
|
||||
int getSize() const;
|
||||
|
||||
/**
|
||||
* Sets the delay after a frame.
|
||||
**/
|
||||
void setDelay(int frame, float delay);
|
||||
|
||||
/**
|
||||
* Sets the overall animation speed.
|
||||
**/
|
||||
void setSpeed(float speed);
|
||||
|
||||
/**
|
||||
* Gets the overall animation speed.
|
||||
**/
|
||||
float getSpeed() const;
|
||||
|
||||
void update(float dt);
|
||||
|
||||
void draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const;
|
||||
|
||||
float getWidth() const;
|
||||
|
||||
float getHeight() const;
|
||||
};
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_OPENGL_ANIMATION_H
|
||||
@@ -0,0 +1,85 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#include "Color.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
Color::Color()
|
||||
: red(255), green(255), blue(255), alpha(255)
|
||||
{
|
||||
}
|
||||
|
||||
Color::Color(int r, int g, int b, int a)
|
||||
: red(r), green(g), blue(b), alpha(a)
|
||||
{
|
||||
}
|
||||
|
||||
Color::~Color()
|
||||
{
|
||||
}
|
||||
|
||||
void Color::setRed(int red)
|
||||
{
|
||||
this->red = red;
|
||||
}
|
||||
|
||||
void Color::setGreen(int green)
|
||||
{
|
||||
this->green = green;
|
||||
}
|
||||
|
||||
void Color::setBlue(int blue)
|
||||
{
|
||||
this->blue = blue;
|
||||
}
|
||||
|
||||
void Color::setAlpha(int alpha)
|
||||
{
|
||||
this->alpha = alpha;
|
||||
}
|
||||
|
||||
int Color::getRed() const
|
||||
{
|
||||
return red;
|
||||
}
|
||||
|
||||
int Color::getGreen() const
|
||||
{
|
||||
return green;
|
||||
}
|
||||
|
||||
int Color::getBlue() const
|
||||
{
|
||||
return blue;
|
||||
}
|
||||
|
||||
int Color::getAlpha() const
|
||||
{
|
||||
return alpha;
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
@@ -0,0 +1,102 @@
|
||||
/**
|
||||
* 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_GRAPHICS_OPENGL_COLOR_H
|
||||
#define LOVE_GRAPHICS_OPENGL_COLOR_H
|
||||
|
||||
// LOVE
|
||||
#include <common/Object.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
/**
|
||||
* @author Michael Enger
|
||||
**/
|
||||
class Color : public Object
|
||||
{
|
||||
protected:
|
||||
|
||||
// Color components. (0-255)
|
||||
int red, green, blue, alpha;
|
||||
|
||||
public:
|
||||
|
||||
Color();
|
||||
|
||||
/**
|
||||
* Creates a new color with the specified component values.
|
||||
* Values must be unsigned bytes. (0-255).
|
||||
**/
|
||||
Color(int r, int g, int b, int a);
|
||||
|
||||
virtual ~Color();
|
||||
|
||||
/**
|
||||
* Sets the amount of red in the color.
|
||||
**/
|
||||
void setRed(int red);
|
||||
|
||||
/**
|
||||
* Sets the amount of green in the color.
|
||||
**/
|
||||
void setGreen(int green);
|
||||
|
||||
/**
|
||||
* Sets the amount of blue in the color.
|
||||
**/
|
||||
void setBlue(int blue);
|
||||
|
||||
/**
|
||||
* Sets the amount of alpha.
|
||||
**/
|
||||
void setAlpha(int alpha);
|
||||
|
||||
/**
|
||||
* Returns the amount of red in the color.
|
||||
**/
|
||||
int getRed() const;
|
||||
|
||||
/**
|
||||
* Returns the amount of green in the color.
|
||||
**/
|
||||
int getGreen() const;
|
||||
|
||||
/**
|
||||
* Returns the amount of blue in the color.
|
||||
**/
|
||||
int getBlue() const;
|
||||
|
||||
/**
|
||||
* Returns the amount of alpha.
|
||||
**/
|
||||
int getAlpha() const;
|
||||
|
||||
}; // Color
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_COLOR_H
|
||||
@@ -0,0 +1,94 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#include "Font.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
Font::Font(int size)
|
||||
: size(size), lineHeight(1), mSpacing(1)
|
||||
{
|
||||
for(unsigned int i = 0; i < MAX_CHARS; i++)
|
||||
{
|
||||
widths[i] = 0;
|
||||
spacing[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
Font::~Font()
|
||||
{
|
||||
}
|
||||
|
||||
float Font::getHeight() const
|
||||
{
|
||||
return (float)size;
|
||||
}
|
||||
|
||||
float Font::getWidth(const std::string & line) const
|
||||
{
|
||||
if(line.size() == 0) return 0;
|
||||
float temp = 0;
|
||||
|
||||
for(unsigned int i = 0; i < line.size() - 1; i++)
|
||||
{
|
||||
temp += widths[(int)line[i]] + (spacing[(int)line[i]] * mSpacing);
|
||||
}
|
||||
temp += widths[(int)line[line.size() - 1]]; // the last character's spacing isn't counted
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
float Font::getWidth(const char * line) const
|
||||
{
|
||||
return this->getWidth(std::string(line));
|
||||
}
|
||||
|
||||
float Font::getWidth(const char character) const
|
||||
{
|
||||
return (float)widths[(int)character];
|
||||
}
|
||||
|
||||
void Font::setLineHeight(float height)
|
||||
{
|
||||
this->lineHeight = height;
|
||||
}
|
||||
|
||||
float Font::getLineHeight() const
|
||||
{
|
||||
return lineHeight;
|
||||
}
|
||||
|
||||
void Font::setSpacing(float amount)
|
||||
{
|
||||
mSpacing = amount;
|
||||
}
|
||||
|
||||
float Font::getSpacing() const
|
||||
{
|
||||
return mSpacing;
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
@@ -0,0 +1,142 @@
|
||||
/**
|
||||
* 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_GRAPHICS_OPENGL_FONT_H
|
||||
#define LOVE_GRAPHICS_OPENGL_FONT_H
|
||||
|
||||
// LOVE
|
||||
#include <filesystem/File.h>
|
||||
#include <graphics/Volatile.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
class Font : public Object, public Volatile
|
||||
{
|
||||
protected:
|
||||
|
||||
love::filesystem::File * file;
|
||||
|
||||
int size;
|
||||
float lineHeight;
|
||||
float mSpacing; // modifies the spacing by multiplying it with this value
|
||||
|
||||
public:
|
||||
static const unsigned int MAX_CHARS = 256;
|
||||
// The widths of each character.
|
||||
int widths[MAX_CHARS];
|
||||
int spacing[MAX_CHARS];
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*
|
||||
* @param file The file containing the OpenGLFont data.
|
||||
* @param size The size of the OpenGLFont.
|
||||
**/
|
||||
Font(int size);
|
||||
|
||||
virtual ~Font();
|
||||
|
||||
virtual bool load() = 0;
|
||||
virtual void unload() = 0;
|
||||
|
||||
/**
|
||||
* Prints the text at the designated position.
|
||||
*
|
||||
* @param text A string.
|
||||
* @param x The x-coordinate.
|
||||
* @param y The y-coordinate.
|
||||
**/
|
||||
virtual void print(std::string text, float x, float y) const = 0;
|
||||
|
||||
/**
|
||||
* Prints the text at the designated position with rotation and scaling.
|
||||
*
|
||||
* @param text A string.
|
||||
* @param x The x-coordinate.
|
||||
* @param y The y-coordinate.
|
||||
* @param angle The amount of rotation.
|
||||
**/
|
||||
virtual void print(std::string text, float x, float y, float angle, float sx, float sy) const = 0;
|
||||
|
||||
/**
|
||||
* Prints the character at the designated position.
|
||||
*
|
||||
* @param character A character.
|
||||
* @param x The x-coordinate.
|
||||
* @param y The y-coordinate.
|
||||
**/
|
||||
virtual void print(char character, float x, float y) const = 0;
|
||||
|
||||
/**
|
||||
* Returns the height of the font.
|
||||
**/
|
||||
virtual float getHeight() const;
|
||||
|
||||
/**
|
||||
* Returns the width of the passed string.
|
||||
*
|
||||
* @param line A line of text.
|
||||
**/
|
||||
virtual float getWidth(const std::string & line) const;
|
||||
virtual float getWidth(const char * line) const;
|
||||
|
||||
/**
|
||||
* Returns the width of the passed character.
|
||||
*
|
||||
* @param character A character.
|
||||
**/
|
||||
virtual float getWidth(const char character) const;
|
||||
|
||||
/**
|
||||
* Sets the line height (which should be a number to multiply the font size by,
|
||||
* example: line height = 1.2 and size = 12 means that rendered line height = 12*1.2)
|
||||
* @param height The new line height.
|
||||
**/
|
||||
void setLineHeight(float height);
|
||||
|
||||
/**
|
||||
* Returns the line height.
|
||||
**/
|
||||
virtual float getLineHeight() const;
|
||||
|
||||
/**
|
||||
* Sets the spacing modifier (changes the spacing between the characters the
|
||||
* same way that the line height does [multiplication]).
|
||||
* Note: The spacing must be set BEFORE the font is loaded to have any effect.
|
||||
* @param amount The amount of modification.
|
||||
**/
|
||||
void setSpacing(float amount);
|
||||
|
||||
/**
|
||||
* Returns the spacing modifier.
|
||||
**/
|
||||
float getSpacing() const;
|
||||
|
||||
}; // Font
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_FONT_H
|
||||
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#include "Frame.h"
|
||||
#include <common/Matrix.h>
|
||||
|
||||
// STD
|
||||
#include <cstring> // For memcpy
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
Frame::Frame(int x, int y, int w, int h, int sw, int sh)
|
||||
{
|
||||
memset(vertices, 255, sizeof(vertex)*4);
|
||||
|
||||
vertices[0].x = 0; vertices[0].y = 0;
|
||||
vertices[1].x = 0; vertices[1].y = (float)h;
|
||||
vertices[2].x = (float)w; vertices[2].y = (float)h;
|
||||
vertices[3].x = (float)w; vertices[3].y = 0;
|
||||
|
||||
vertices[0].s = (float)x/(float)sw; vertices[0].t = (float)y/(float)sh;
|
||||
vertices[1].s = (float)x/(float)sw; vertices[1].t = (float)(y+h)/(float)sh;
|
||||
vertices[2].s = (float)(x+w)/(float)sw; vertices[2].t = (float)(y+h)/(float)sh;
|
||||
vertices[3].s = (float)(x+w)/(float)sw; vertices[3].t = (float)y/(float)sh;
|
||||
}
|
||||
|
||||
void Frame::flip(bool x, bool y)
|
||||
{
|
||||
vertex temp[4];
|
||||
if (x)
|
||||
{
|
||||
memcpy(temp, vertices, sizeof(vertex)*4);
|
||||
vertices[0].s = temp[3].s; vertices[0].t = temp[3].t;
|
||||
vertices[1].s = temp[2].s; vertices[1].t = temp[2].t;
|
||||
vertices[2].s = temp[1].s; vertices[2].t = temp[1].t;
|
||||
vertices[3].s = temp[0].s; vertices[3].t = temp[0].t;
|
||||
}
|
||||
if (y)
|
||||
{
|
||||
memcpy(temp, vertices, sizeof(vertex)*4);
|
||||
vertices[0].s = temp[1].s; vertices[0].t = temp[1].t;
|
||||
vertices[1].s = temp[0].s; vertices[1].t = temp[0].t;
|
||||
vertices[2].s = temp[3].s; vertices[2].t = temp[3].t;
|
||||
vertices[3].s = temp[2].s; vertices[3].t = temp[2].t;
|
||||
}
|
||||
}
|
||||
|
||||
const vertex * Frame::getVertices() const
|
||||
{
|
||||
return vertices;
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* 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_GRAPHICS_OPENGL_FRAME_H
|
||||
#define LOVE_GRAPHICS_OPENGL_FRAME_H
|
||||
|
||||
// LOVE
|
||||
#include <common/math.h>
|
||||
#include <graphics/Drawable.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
class Frame
|
||||
{
|
||||
private:
|
||||
vertex vertices[4];
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a new Frame of size (w,h), using (x,y) as the top-left
|
||||
* anchor point in the source image. The size of the source image is
|
||||
* is specified by (sw,sh).
|
||||
*
|
||||
* @param x Frame source position along the x-axis.
|
||||
* @param y Frame source position along the y-axis.
|
||||
* @param w Frame width.
|
||||
* @param h Frame width.
|
||||
* @param sw Width of the source image.
|
||||
* @param sh Height of the source image.
|
||||
**/
|
||||
Frame(int x, int y, int w, int h, int sw, int sh);
|
||||
|
||||
void flip(bool x, bool y);
|
||||
|
||||
/**
|
||||
* Gets a pointer to the vertices.
|
||||
**/
|
||||
const vertex * getVertices() const;
|
||||
};
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_FRAME_H
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,576 @@
|
||||
/**
|
||||
* 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_GRAPHICS_OPENGL_GRAPHICS_H
|
||||
#define LOVE_GRAPHICS_OPENGL_GRAPHICS_H
|
||||
|
||||
// STD
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
// SDL
|
||||
#include <SDL.h>
|
||||
#include "GLee.h"
|
||||
#include <SDL_opengl.h>
|
||||
|
||||
// LOVE
|
||||
#include <common/Module.h>
|
||||
#include "Image.h"
|
||||
#include "Animation.h"
|
||||
#include "Color.h"
|
||||
#include "TrueTypeFont.h"
|
||||
#include "ImageFont.h"
|
||||
#include "ParticleSystem.h"
|
||||
#include "SpriteBatch.h"
|
||||
#include "VertexBuffer.h"
|
||||
#include "Frame.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
struct DisplayMode
|
||||
{
|
||||
int width, height; // The size of the screen.
|
||||
int colorDepth; // The color depth of the display mode.
|
||||
bool fullscreen; // Fullscreen (true), or windowed (false).
|
||||
bool vsync; // Vsync enabled (true), or disabled (false).
|
||||
int fsaa; // 0 for no FSAA, otherwise 1, 2 or 4.
|
||||
};
|
||||
|
||||
// During display mode changing, certain
|
||||
// variables about the OpenGL context are
|
||||
// lost.
|
||||
struct DisplayState
|
||||
{
|
||||
// Colors.
|
||||
GLubyte color[4];
|
||||
GLubyte backgroundColor[4];
|
||||
|
||||
// Blend and color modes.
|
||||
int blendMode, colorMode;
|
||||
|
||||
// Line.
|
||||
float lineWidth;
|
||||
int lineStyle;
|
||||
bool stipple;
|
||||
int stippleRepeat;
|
||||
int stipplePattern;
|
||||
|
||||
// Point.
|
||||
float pointSize;
|
||||
int pointStyle;
|
||||
|
||||
// Scissor.
|
||||
bool scissor;
|
||||
GLint scissorBox[4];
|
||||
|
||||
// Default values.
|
||||
DisplayState()
|
||||
{
|
||||
color[0] = 255;
|
||||
color[1] = 255;
|
||||
color[2] = 255;
|
||||
color[3] = 255;
|
||||
backgroundColor[0] = 0;
|
||||
backgroundColor[1] = 0;
|
||||
backgroundColor[2] = 0;
|
||||
backgroundColor[3] = 255;
|
||||
blendMode = BLEND_NORMAL;
|
||||
colorMode = COLOR_NORMAL;
|
||||
lineWidth = 1.0f;
|
||||
lineStyle = LINE_SMOOTH;
|
||||
stipple = false;
|
||||
pointSize = 1.0f;
|
||||
pointStyle = POINT_SMOOTH;
|
||||
scissor = false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class Graphics : public Module
|
||||
{
|
||||
private:
|
||||
|
||||
Font * currentFont;
|
||||
DisplayMode currentMode;
|
||||
|
||||
public:
|
||||
Graphics();
|
||||
~Graphics();
|
||||
|
||||
// Implements Module.
|
||||
const char * getName() const;
|
||||
|
||||
/**
|
||||
* Checks whether a display mode is supported or not. Note
|
||||
* that fullscreen is assumed, because windowed modes are
|
||||
* generally supported regardless of size.
|
||||
* @param width The window width.
|
||||
* @param height The window height.
|
||||
**/
|
||||
bool checkMode(int width, int height, bool fullscreen);
|
||||
|
||||
|
||||
DisplayState saveState();
|
||||
|
||||
void restoreState(const DisplayState & s);
|
||||
|
||||
/**
|
||||
* Sets the current display mode.
|
||||
* @param width The window width.
|
||||
* @param height The window height.
|
||||
* @param fullscreen True if fullscreen, false otherwise.
|
||||
* @param vsync True if we should wait for vsync, false otherwise.
|
||||
* @param fsaa Number of full scene anti-aliasing buffer, or 0 for disabled.
|
||||
**/
|
||||
bool setMode(int width, int height, bool fullscreen, bool vsync, int fsaa);
|
||||
|
||||
/**
|
||||
* Toggles fullscreen. Note that this also needs to reload the
|
||||
* entire OpenGL context.
|
||||
**/
|
||||
bool toggleFullscreen();
|
||||
|
||||
/**
|
||||
* Resets the current color, background color,
|
||||
* line style, and so forth. (This will be called
|
||||
* when the game reloads.
|
||||
**/
|
||||
void reset();
|
||||
|
||||
/**
|
||||
* Clears the screen.
|
||||
**/
|
||||
void clear();
|
||||
|
||||
/**
|
||||
* Flips buffers. (Rendered geometry is
|
||||
* presented on screen).
|
||||
**/
|
||||
void present();
|
||||
|
||||
/**
|
||||
* Sets the windows caption.
|
||||
**/
|
||||
void setCaption(const char * caption);
|
||||
|
||||
int getCaption(lua_State * L);
|
||||
|
||||
/**
|
||||
* Gets the width of the current display mode.
|
||||
**/
|
||||
int getWidth();
|
||||
|
||||
/**
|
||||
* Gets the height of the current display mode.
|
||||
**/
|
||||
int getHeight();
|
||||
|
||||
/**
|
||||
* True if some display mode is set.
|
||||
**/
|
||||
bool isCreated();
|
||||
|
||||
/**
|
||||
* This native Lua function gets available modes
|
||||
* from SDL and returns them as a table on the following format:
|
||||
*
|
||||
* {
|
||||
* { width = 800, height = 600 },
|
||||
* { width = 1024, height = 768 },
|
||||
* ...
|
||||
* }
|
||||
*
|
||||
* Only fullscreen modes are returned here, as all
|
||||
* window sizes are supported (normally).
|
||||
**/
|
||||
int getModes(lua_State * L);
|
||||
|
||||
/**
|
||||
* Scissor defines a box such that everything outside that box is discared and not drawn.
|
||||
* Scissoring is automatically enabled.
|
||||
* @param x The x-coordinate of the top-left corner.
|
||||
* @param y The y-coordinate of the top-left corner.
|
||||
* @param width The width of the box.
|
||||
* @param height The height of the box.
|
||||
**/
|
||||
void setScissor(int x, int y, int width, int height);
|
||||
|
||||
/**
|
||||
* Clears any scissor that has been created.
|
||||
**/
|
||||
void setScissor();
|
||||
|
||||
/**
|
||||
* This native Lua function gets the current scissor box in the order of:
|
||||
* x, y, width, height
|
||||
**/
|
||||
int getScissor(lua_State * L);
|
||||
|
||||
/**
|
||||
* Creates a new Color object.
|
||||
**/
|
||||
Color * newColor( int r, int g, int b, int a );
|
||||
|
||||
/**
|
||||
* Creates an Image object with padding and/or optimization.
|
||||
**/
|
||||
Image * newImage(love::filesystem::File * file);
|
||||
Image * newImage(love::image::ImageData * data);
|
||||
|
||||
/**
|
||||
* Creates a Frame
|
||||
**/
|
||||
Frame * newFrame(int x, int y, int w, int h, int sw, int sh);
|
||||
|
||||
/**
|
||||
* Creates a Font object.
|
||||
**/
|
||||
Font * newFont(love::filesystem::File * file, int size = 12);
|
||||
|
||||
/**
|
||||
* Creates an ImageFont object.
|
||||
**/
|
||||
Font * newImageFont(Image * image, const char * glyphs, float spacing = 1);
|
||||
|
||||
/**
|
||||
* Creates an Animation object with no frames.
|
||||
**/
|
||||
Animation * newAnimation(Image * image);
|
||||
|
||||
/**
|
||||
* Creates an Animation object with generated frames in a grid.
|
||||
**/
|
||||
Animation * newAnimation(Image * image, float fw, float fh, float delay, int num = 0);
|
||||
|
||||
/**
|
||||
* Creates a ParticleSystem object with the specified buffer size and using the specified sprite.
|
||||
**/
|
||||
//pParticleSystem newParticleSystem(Image * image, unsigned int size);
|
||||
|
||||
/**
|
||||
* Creates a PointParticleSystem object with the specified buffer size and sprite.
|
||||
* @param mode This should be love::POINT_SPRITE.
|
||||
**/
|
||||
//pParticleSystem newParticleSystem(Image * image, unsigned int size, int mode);
|
||||
|
||||
SpriteBatch * newSpriteBatch(Image * image, int size, int usage);
|
||||
VertexBuffer * newVertexBuffer(Image * image, int size, int type, int usage);
|
||||
|
||||
/**
|
||||
* Sets the foreground color.
|
||||
**/
|
||||
void setColor(Color * color);
|
||||
|
||||
/**
|
||||
* Sets the foreground color.
|
||||
**/
|
||||
void setColor( int r, int g, int b, int a = 255);
|
||||
|
||||
/**
|
||||
* Gets current color.
|
||||
**/
|
||||
Color * getColor();
|
||||
|
||||
/**
|
||||
* Sets the background Color.
|
||||
**/
|
||||
void setBackgroundColor( Color * color );
|
||||
|
||||
/**
|
||||
* Sets the background Color.
|
||||
**/
|
||||
void setBackgroundColor( int r, int g, int b );
|
||||
|
||||
/**
|
||||
* Gets the current background color.
|
||||
**/
|
||||
Color * getBackgroundColor();
|
||||
|
||||
/**
|
||||
* Sets the current font.
|
||||
* @parm font A Font object.
|
||||
**/
|
||||
void setFont( Font * font );
|
||||
|
||||
/**
|
||||
* Sets a default font. The font is
|
||||
* loaded and sent to the GPU every time this is called,
|
||||
* so no over-using.
|
||||
* @param file File from which to load the font.
|
||||
* @param size The size of the font.
|
||||
**/
|
||||
void setFont( love::filesystem::File * file, int size = 12);
|
||||
|
||||
/**
|
||||
* Gets the current Font, or nil if none.
|
||||
**/
|
||||
Font * getFont();
|
||||
|
||||
/**
|
||||
* Sets the current blend mode.
|
||||
**/
|
||||
void setBlendMode( int mode );
|
||||
|
||||
/**
|
||||
* Sets the current color mode.
|
||||
**/
|
||||
void setColorMode ( int mode );
|
||||
|
||||
/**
|
||||
* Gets the current blend mode.
|
||||
**/
|
||||
int getBlendMode();
|
||||
|
||||
/**
|
||||
* Gets the current color mode.
|
||||
**/
|
||||
int getColorMode();
|
||||
|
||||
/**
|
||||
* Sets the line width.
|
||||
* @param width The new width of the line.
|
||||
**/
|
||||
void setLineWidth( float width );
|
||||
|
||||
/**
|
||||
* Sets the line style.
|
||||
* @param style LINE_ROUGH or LINE_SMOOTH.
|
||||
**/
|
||||
void setLineStyle( int style );
|
||||
|
||||
/**
|
||||
* Sets the type of line used to draw primitives.
|
||||
* A shorthand for setLineWidth and setLineStyle.
|
||||
**/
|
||||
void setLine( float width, int style = 0 );
|
||||
|
||||
/**
|
||||
* Disables line stippling.
|
||||
**/
|
||||
void setLineStipple();
|
||||
|
||||
/**
|
||||
* Sets a line stipple pattern.
|
||||
**/
|
||||
void setLineStipple(unsigned short pattern, int repeat = 1);
|
||||
|
||||
/**
|
||||
* Gets the line width.
|
||||
**/
|
||||
float getLineWidth();
|
||||
|
||||
/**
|
||||
* Gets the line style.
|
||||
**/
|
||||
int getLineStyle();
|
||||
|
||||
/**
|
||||
* Gets the line stipple pattern and repeat factor.
|
||||
* @return pattern The stipplie bit-pattern.
|
||||
* @return repeat The reapeat factor.
|
||||
**/
|
||||
int getLineStipple(lua_State * L);
|
||||
|
||||
/**
|
||||
* Sets the size of points.
|
||||
**/
|
||||
void setPointSize( float size );
|
||||
|
||||
/**
|
||||
* Sets the style of points.
|
||||
* @param style POINT_SMOOTH or POINT_ROUGH.
|
||||
**/
|
||||
void setPointStyle( int style );
|
||||
|
||||
/**
|
||||
* Shorthand for setPointSize and setPointStyle.
|
||||
**/
|
||||
void setPoint( float size, int style );
|
||||
|
||||
/**
|
||||
* Gets the point size.
|
||||
**/
|
||||
float getPointSize();
|
||||
|
||||
/**
|
||||
* Gets the point style.
|
||||
**/
|
||||
int getPointStyle();
|
||||
|
||||
/**
|
||||
* Gets the maximum point size supported.
|
||||
* This may vary from computer to computer.
|
||||
**/
|
||||
int getMaxPointSize();
|
||||
|
||||
/**
|
||||
* Draw text on screen at the specified coordiantes (automatically breaks \n characters).
|
||||
*
|
||||
* @param str A string of text.
|
||||
* @param x The x-coordiante.
|
||||
* @param y The y-coordiante.
|
||||
**/
|
||||
void print( const char * str, float x, float y );
|
||||
|
||||
/**
|
||||
* Draws text at the specified coordinates, with rotation.
|
||||
* @param x The x-coordinate.
|
||||
* @param y The y-coordinate.
|
||||
* @param angle The amount of rotation.
|
||||
**/
|
||||
void print( const char * str, float x, float y , float angle );
|
||||
|
||||
/**
|
||||
* Draws text at the specified coordinates, with rotation and
|
||||
* scaling.
|
||||
* @param x The x-coordinate.
|
||||
* @param y The y-coordinate.
|
||||
* @param angle The amount of rotation.
|
||||
* @param s The scale factor. (1 = normal).
|
||||
**/
|
||||
void print( const char * str, float x, float y , float angle, float s );
|
||||
|
||||
/**
|
||||
* Draws text at the specified coordinates, with rotation and
|
||||
* scaling along both axes.
|
||||
* @param x The x-coordinate.
|
||||
* @param y The y-coordinate.
|
||||
* @param angle The amount of rotation.
|
||||
* @param sx The scale factor along the x-axis. (1 = normal).
|
||||
* @param sy The scale factor along the y-axis. (1 = normal).
|
||||
**/
|
||||
void print( const char * str, float x, float y , float angle, float sx, float sy);
|
||||
|
||||
/**
|
||||
* Draw formatted text on screen at the specified coordinates.
|
||||
*
|
||||
* @param str A string of text.
|
||||
* @param x The x-coordinate.
|
||||
* @param y The y-coordinate.
|
||||
* @param wrap The maximum width of the text area.
|
||||
* @param align Where to align the text.
|
||||
**/
|
||||
void printf( const char * str, float x, float y, float wrap, int align = 0 );
|
||||
|
||||
/**
|
||||
* Draws an Image at the specified coordinates, with rotation and
|
||||
* scaling along both axes.
|
||||
* @param x The x-coordinate.
|
||||
* @param y The y-coordinate.
|
||||
* @param angle The amount of rotation.
|
||||
* @param sx The scale factor along the x-axis. (1 = normal).
|
||||
* @param sy The scale factor along the y-axis. (1 = normal).
|
||||
**/
|
||||
//void draw(Drawable * drawable, float x, float y, float angle, float sx, float sy);
|
||||
|
||||
/**
|
||||
* Draws a point at (x,y).
|
||||
* @param x Point along x-axis.
|
||||
* @param y Point along y-axis.
|
||||
**/
|
||||
void point( float x, float y );
|
||||
|
||||
/**
|
||||
* Draws a line from (x1,y1) to (x2,y2).
|
||||
* @param x1 First x-coordinate.
|
||||
* @param y1 First y-coordinate.
|
||||
* @param x2 Second x-coordinate.
|
||||
* @param y2 Second y-coordinate.
|
||||
**/
|
||||
void line( float x1, float y1, float x2, float y2 );
|
||||
|
||||
/**
|
||||
* Draws a triangle using the three coordinates passed.
|
||||
* @param type The type of drawing (line/filled).
|
||||
* @param x1 First x-coordinate.
|
||||
* @param y1 First y-coordinate.
|
||||
* @param x2 Second x-coordinate.
|
||||
* @param y2 Second y-coordinate.
|
||||
* @param x3 Third x-coordinate.
|
||||
* @param y3 Third y-coordinate.
|
||||
**/
|
||||
void triangle( int type, float x1, float y1, float x2, float y2, float x3, float y3 );
|
||||
|
||||
/**
|
||||
* Draws a rectangle.
|
||||
* @param x Position along x-axis for top-left corner.
|
||||
* @param y Position along y-axis for top-left corner.
|
||||
* @param w The width of the rectangle.
|
||||
* @param h The height of the rectangle.
|
||||
**/
|
||||
void rectangle( int type, float x, float y, float w, float h );
|
||||
|
||||
/**
|
||||
* Draws a quadrilateral using the four coordinates passed.
|
||||
* @param type The type of drawing (line/filled).
|
||||
* @param x1 First x-coordinate.
|
||||
* @param y1 First y-coordinate.
|
||||
* @param x2 Second x-coordinate.
|
||||
* @param y2 Second y-coordinate.
|
||||
* @param x3 Third x-coordinate.
|
||||
* @param y3 Third y-coordinate.
|
||||
* @param x4 Fourth x-coordinate.
|
||||
* @param y4 Fourth y-coordinate.
|
||||
**/
|
||||
void quad( int type, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4 );
|
||||
|
||||
/**
|
||||
* Draws a circle using the specified arguments.
|
||||
* @param type The type of drawing (line/filled).
|
||||
* @param x X-coordinate.
|
||||
* @param y Y-coordinate.
|
||||
* @param radius Radius of the circle.
|
||||
* @param points Amount of points to use to draw the circle.
|
||||
**/
|
||||
void circle( int type, float x, float y, float radius, int points = 10 );
|
||||
|
||||
/**
|
||||
* Draws a polygon with an arbitrary number of vertices.
|
||||
* @param type The type of drawing (line/filled).
|
||||
* @param ... Vertex components (x1, y1, x2, y2, etc).
|
||||
**/
|
||||
int polygon( lua_State * L );
|
||||
int polygong( lua_State * L );
|
||||
|
||||
/**
|
||||
* Creates a screenshot of the view and saves it to the default folder.
|
||||
* @param file The file to write the screenshot to.
|
||||
**/
|
||||
bool screenshot(love::filesystem::File * file);
|
||||
|
||||
void push();
|
||||
void pop();
|
||||
void rotate(float r);
|
||||
void scale(float x, float y = 1.0f);
|
||||
void translate(float x, float y);
|
||||
|
||||
void drawTest(Image * image, float x, float y, float a, float sx, float sy, float ox, float oy);
|
||||
|
||||
}; // Graphics
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_GRAPHICS_H
|
||||
@@ -0,0 +1,337 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#include "Image.h"
|
||||
|
||||
// STD
|
||||
#include <cstring> // For memcpy
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
Image::Image(love::image::ImageData * data)
|
||||
: width((float)(data->getWidth())), height((float)(data->getHeight())), texture(0)
|
||||
{
|
||||
data->retain();
|
||||
this->data = data;
|
||||
|
||||
memset(vertices, 255, sizeof(vertex)*4);
|
||||
|
||||
vertices[0].x = 0; vertices[0].y = 0;
|
||||
vertices[1].x = 0; vertices[1].y = height;
|
||||
vertices[2].x = width; vertices[2].y = height;
|
||||
vertices[3].x = width; vertices[3].y = 0;
|
||||
|
||||
vertices[0].s = 0; vertices[0].t = 0;
|
||||
vertices[1].s = 0; vertices[1].t = 1;
|
||||
vertices[2].s = 1; vertices[2].t = 1;
|
||||
vertices[3].s = 1; vertices[3].t = 0;
|
||||
|
||||
}
|
||||
|
||||
Image::~Image()
|
||||
{
|
||||
if(data != 0)
|
||||
data->release();
|
||||
unload();
|
||||
}
|
||||
|
||||
float Image::getWidth() const
|
||||
{
|
||||
return width;
|
||||
}
|
||||
|
||||
float Image::getHeight() const
|
||||
{
|
||||
return height;
|
||||
}
|
||||
|
||||
const vertex * Image::getVertices() const
|
||||
{
|
||||
return vertices;
|
||||
}
|
||||
|
||||
love::image::ImageData * Image::getData() const
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
void Image::getRectangleVertices(int x, int y, int w, int h, vertex * vertices) const
|
||||
{
|
||||
// Check upper.
|
||||
x = (x+w > (int)width) ? (int)width-w : x;
|
||||
y = (y+h > (int)height) ? (int)height-h : y;
|
||||
|
||||
// Check lower.
|
||||
x = (x < 0) ? 0 : x;
|
||||
y = (y < 0) ? 0 : y;
|
||||
|
||||
vertices[0].x = 0; vertices[0].y = 0;
|
||||
vertices[1].x = 0; vertices[1].y = (float)h;
|
||||
vertices[2].x = (float)w; vertices[2].y = (float)h;
|
||||
vertices[3].x = (float)w; vertices[3].y = 0;
|
||||
|
||||
float tx = (float)x/width;
|
||||
float ty = (float)y/height;
|
||||
float tw = (float)w/width;
|
||||
float th = (float)h/height;
|
||||
|
||||
vertices[0].s = tx; vertices[0].t = ty;
|
||||
vertices[1].s = tx; vertices[1].t = ty+th;
|
||||
vertices[2].s = tx+tw; vertices[2].t = ty+th;
|
||||
vertices[3].s = tx+tw; vertices[3].t = ty;
|
||||
}
|
||||
|
||||
void Image::draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const
|
||||
{
|
||||
static Matrix t;
|
||||
|
||||
t.setTransformation(x, y, angle, sx, sy, ox, oy);
|
||||
drawv(t, vertices);
|
||||
}
|
||||
|
||||
void Image::draws(float x, float y, float angle, float sx, float sy, float ox, float oy, float rx, float ry, float rw, float rh) const
|
||||
{
|
||||
static Matrix t;
|
||||
static vertex cache[4];
|
||||
|
||||
getRectangleVertices((int)rx, (int)ry, (int)rw, (int)rh, cache);
|
||||
t.setTransformation(x, y, angle, sx, sy, ox, oy);
|
||||
drawv(t, cache);
|
||||
}
|
||||
|
||||
void Image::draws(float x, float y, float angle, float sx, float sy, float ox, float oy, Frame * frame) const
|
||||
{
|
||||
static Matrix t;
|
||||
const vertex * v = frame->getVertices();
|
||||
|
||||
t.setTransformation(x, y, angle, sx, sy, ox, oy);
|
||||
drawv(t, v);
|
||||
}
|
||||
|
||||
void Image::setFilter(Image::Filter f)
|
||||
{
|
||||
GLint gmin, gmag;
|
||||
|
||||
switch(f.min)
|
||||
{
|
||||
case FILTER_LINEAR:
|
||||
gmin = GL_LINEAR;
|
||||
break;
|
||||
case FILTER_NEAREST:
|
||||
gmin = GL_NEAREST;
|
||||
break;
|
||||
}
|
||||
|
||||
switch(f.mag)
|
||||
{
|
||||
case FILTER_LINEAR:
|
||||
gmag = GL_LINEAR;
|
||||
break;
|
||||
case FILTER_NEAREST:
|
||||
gmag = GL_NEAREST;
|
||||
break;
|
||||
}
|
||||
|
||||
bind();
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gmin);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gmag);
|
||||
}
|
||||
|
||||
Image::Filter Image::getFilter() const
|
||||
{
|
||||
bind();
|
||||
|
||||
GLint gmin, gmag;
|
||||
|
||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, &gmin);
|
||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, &gmag);
|
||||
|
||||
Image::Filter f;
|
||||
|
||||
switch(gmin)
|
||||
{
|
||||
case GL_NEAREST:
|
||||
f.min = FILTER_NEAREST;
|
||||
break;
|
||||
case GL_LINEAR:
|
||||
default:
|
||||
f.min = FILTER_LINEAR;
|
||||
break;
|
||||
}
|
||||
|
||||
switch(gmin)
|
||||
{
|
||||
case GL_NEAREST:
|
||||
f.mag = FILTER_NEAREST;
|
||||
break;
|
||||
case GL_LINEAR:
|
||||
default:
|
||||
f.mag = FILTER_LINEAR;
|
||||
break;
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
void Image::setWrap(Image::Wrap w)
|
||||
{
|
||||
GLint gs, gt;
|
||||
|
||||
switch(w.s)
|
||||
{
|
||||
case WRAP_CLAMP:
|
||||
gs = GL_CLAMP;
|
||||
break;
|
||||
case WRAP_REPEAT:
|
||||
default:
|
||||
gs = GL_REPEAT;
|
||||
break;
|
||||
}
|
||||
|
||||
switch(w.t)
|
||||
{
|
||||
case WRAP_CLAMP:
|
||||
gt = GL_CLAMP;
|
||||
break;
|
||||
case WRAP_REPEAT:
|
||||
default:
|
||||
gt = GL_REPEAT;
|
||||
break;
|
||||
}
|
||||
|
||||
bind();
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, gs);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, gt);
|
||||
}
|
||||
|
||||
Image::Wrap Image::getWrap() const
|
||||
{
|
||||
bind();
|
||||
|
||||
GLint gs, gt;
|
||||
|
||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, &gs);
|
||||
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, >);
|
||||
|
||||
Wrap w;
|
||||
|
||||
switch(gs)
|
||||
{
|
||||
case GL_CLAMP:
|
||||
w.s = WRAP_CLAMP;
|
||||
break;
|
||||
case GL_REPEAT:
|
||||
default:
|
||||
w.s = WRAP_REPEAT;
|
||||
break;
|
||||
}
|
||||
|
||||
switch(gt)
|
||||
{
|
||||
case GL_CLAMP:
|
||||
w.t = WRAP_CLAMP;
|
||||
break;
|
||||
case GL_REPEAT:
|
||||
default:
|
||||
w.t = WRAP_REPEAT;
|
||||
break;
|
||||
}
|
||||
|
||||
return w;
|
||||
}
|
||||
|
||||
void Image::bind() const
|
||||
{
|
||||
if(texture != 0)
|
||||
glBindTexture(GL_TEXTURE_2D,texture);
|
||||
}
|
||||
|
||||
bool Image::load()
|
||||
{
|
||||
return loadVolatile();
|
||||
}
|
||||
|
||||
void Image::unload()
|
||||
{
|
||||
unloadVolatile();
|
||||
}
|
||||
|
||||
bool Image::loadVolatile()
|
||||
{
|
||||
glGenTextures(1,(GLuint*)&texture);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_RGBA8,
|
||||
(GLsizei)width,
|
||||
(GLsizei)height,
|
||||
0,
|
||||
GL_RGBA,
|
||||
GL_UNSIGNED_BYTE,
|
||||
data->getData());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Image::unloadVolatile()
|
||||
{
|
||||
// Delete the hardware texture.
|
||||
if(texture != 0)
|
||||
{
|
||||
glDeleteTextures(1, (GLuint*)&texture);
|
||||
texture = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void Image::drawv(const Matrix & t, const vertex * v) const
|
||||
{
|
||||
bind();
|
||||
|
||||
glPushMatrix();
|
||||
|
||||
glMultMatrixf((const GLfloat*)t.getElements());
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid*)&v[0].x);
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid*)&v[0].s);
|
||||
glDrawArrays(GL_QUADS, 0, 4);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
@@ -0,0 +1,157 @@
|
||||
/**
|
||||
* 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_GRAPHICS_OPENGL_IMAGE_H
|
||||
#define LOVE_GRAPHICS_OPENGL_IMAGE_H
|
||||
|
||||
// LOVE
|
||||
#include <common/config.h>
|
||||
#include <image/ImageData.h>
|
||||
#include <common/math.h>
|
||||
#include <graphics/Image.h>
|
||||
#include "Frame.h"
|
||||
#include <common/Matrix.h>
|
||||
#include <common/math.h>
|
||||
|
||||
// OpenGL
|
||||
#include <SDL/SDL_opengl.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
/**
|
||||
* A drawable image based on OpenGL-textures. This class takes ImageData
|
||||
* objects and create textures on the GPU for fast drawing.
|
||||
*
|
||||
* @author Anders Ruud
|
||||
**/
|
||||
class Image : public love::graphics::Image
|
||||
{
|
||||
private:
|
||||
|
||||
// The ImageData from which the texture is created.
|
||||
love::image::ImageData * data;
|
||||
|
||||
// Width and height of the hardware texture.
|
||||
float width, height;
|
||||
|
||||
// OpenGL texture identifier.
|
||||
GLuint texture;
|
||||
|
||||
// The source vertices of the image.
|
||||
vertex vertices[4];
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a new Image. Not that anything is ready to use
|
||||
* before load is called.
|
||||
*
|
||||
* @param file The file from which to load the image.
|
||||
**/
|
||||
Image(love::image::ImageData * data);
|
||||
|
||||
/**
|
||||
* Destructor. Deletes the hardware texture and other resources.
|
||||
**/
|
||||
virtual ~Image();
|
||||
|
||||
float getWidth() const;
|
||||
float getHeight() const;
|
||||
|
||||
const vertex * getVertices() const;
|
||||
|
||||
love::image::ImageData * getData() const;
|
||||
|
||||
/**
|
||||
* Generate vertices according to a subimage.
|
||||
*
|
||||
* Note: out-of-range values will be clamped.
|
||||
* Note: the vertex colors will not be changed.
|
||||
*
|
||||
* @param x The top-left corner of the subimage along the x-axis.
|
||||
* @param y The top-left corner of the subimage along the y-axis.
|
||||
* @param w The width of the subimage.
|
||||
* @param h The height of the subimage.
|
||||
* @param vertices A vertex array of size four.
|
||||
**/
|
||||
void getRectangleVertices(int x, int y, int w, int h, vertex * vertices) const;
|
||||
|
||||
/**
|
||||
* @copydoc Drawable::draw()
|
||||
**/
|
||||
void draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const;
|
||||
|
||||
/**
|
||||
* This function draws a section of the image.
|
||||
*
|
||||
* @copydetails Drawable::draw()
|
||||
* @param rx The upper-left corner of the source rectangle along the x-axis.
|
||||
* @param ry The upper-left corner of the source rectangle along the y-axis.
|
||||
* @param rw The width of the source rectangle.
|
||||
* @param rw The height of the source rectangle.
|
||||
**/
|
||||
void draws(float x, float y, float angle, float sx, float sy, float ox, float oy, float rx, float ry, float rw, float rh) const;
|
||||
|
||||
/**
|
||||
* This function draws a section of the image using a Frame object.
|
||||
*
|
||||
* @copydetails Image::draws()
|
||||
* @param frame Represents the region of the Image to draw.
|
||||
**/
|
||||
void draws(float x, float y, float angle, float sx, float sy, float ox, float oy, Frame * frame) const;
|
||||
|
||||
/**
|
||||
* Sets the filter mode.
|
||||
*
|
||||
* @param mode The filter mode.
|
||||
**/
|
||||
void setFilter(Image::Filter f);
|
||||
|
||||
Image::Filter getFilter() const;
|
||||
|
||||
void setWrap(Image::Wrap r);
|
||||
|
||||
Image::Wrap getWrap() const;
|
||||
|
||||
void bind() const;
|
||||
|
||||
bool load();
|
||||
void unload();
|
||||
|
||||
// Implements Volatile.
|
||||
bool loadVolatile();
|
||||
void unloadVolatile();
|
||||
|
||||
private:
|
||||
|
||||
void drawv(const Matrix & t, const vertex * v) const;
|
||||
|
||||
}; // Image
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_IMAGE_H
|
||||
@@ -0,0 +1,225 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#include "ImageFont.h"
|
||||
|
||||
#include <SDL_opengl.h>
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
ImageFont::ImageFont(Image * image, std::string glyphs)
|
||||
: Font(0), glyphs(glyphs), image(image)
|
||||
|
||||
{
|
||||
image->retain();
|
||||
}
|
||||
|
||||
ImageFont::~ImageFont()
|
||||
{
|
||||
unload();
|
||||
image->release();
|
||||
}
|
||||
|
||||
void ImageFont::print(string text, float x, float y) const
|
||||
{
|
||||
glPushMatrix();
|
||||
glTranslatef(x, y, 0.0f);
|
||||
GLuint OpenGLFont = list;
|
||||
glListBase(OpenGLFont);
|
||||
glCallLists((int)text.length(), GL_UNSIGNED_BYTE, text.c_str());
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
void ImageFont::print(std::string text, float x, float y, float angle, float sx, float sy) const
|
||||
{
|
||||
glPushMatrix();
|
||||
|
||||
glTranslatef(x, y, 0.0f);
|
||||
glRotatef(angle, 0, 0, 1.0f);
|
||||
glScalef(sx, sy, 1.0f);
|
||||
|
||||
GLuint OpenGLFont = list;
|
||||
glListBase(OpenGLFont);
|
||||
glCallLists((int)text.length(), GL_UNSIGNED_BYTE, text.c_str());
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
void ImageFont::print(char character, float x, float y) const
|
||||
{
|
||||
glPushMatrix();
|
||||
glTranslatef(x, y, 0.0f);
|
||||
GLuint OpenGLFont = list;
|
||||
glListBase(OpenGLFont);
|
||||
glCallList(list + (int)character);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
bool ImageFont::load()
|
||||
{
|
||||
return loadVolatile();
|
||||
}
|
||||
|
||||
void ImageFont::unload()
|
||||
{
|
||||
unloadVolatile();
|
||||
}
|
||||
|
||||
bool ImageFont::loadVolatile()
|
||||
{
|
||||
love::image::pixel * pixels = (love::image::pixel *)(image->getData()->getData());
|
||||
|
||||
// Reading texture data begins
|
||||
size = (int)image->getHeight();
|
||||
|
||||
for(unsigned int i = 0; i < MAX_CHARS; i++) positions[i] = -1;
|
||||
|
||||
love::image::pixel spacer = pixels[0];
|
||||
unsigned int current = 0;
|
||||
int width = 0;
|
||||
int space = 0;
|
||||
|
||||
// Finds out where the first character starts
|
||||
int firstchar = 0;
|
||||
for(int i = 0; i != (int)image->getWidth(); i++)
|
||||
{
|
||||
if(spacer.r == pixels[i].r && spacer.g == pixels[i].g && spacer.b == pixels[i].b && spacer.a == pixels[i].a)
|
||||
continue;
|
||||
else
|
||||
{
|
||||
firstchar = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = firstchar; i != (int)image->getWidth(); i++)
|
||||
{
|
||||
if(spacer.r == pixels[i].r && spacer.g == pixels[i].g && spacer.b == pixels[i].b && spacer.a == pixels[i].a)
|
||||
{
|
||||
if(width != 0) // this means we have found the end of our current character
|
||||
{
|
||||
if((unsigned int)glyphs[current] > MAX_CHARS)
|
||||
printf("Error reading texture font: Character '%c' is out of range.", glyphs[current]);
|
||||
else
|
||||
{
|
||||
widths[(int)glyphs[current]] = width - 1;
|
||||
positions[(int)glyphs[current]] = i - width;
|
||||
}
|
||||
|
||||
width = 0;
|
||||
//space++; // start counting the spacing
|
||||
}
|
||||
space++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(space != 0) // this means we have found the end of our spacing
|
||||
{
|
||||
if((unsigned int)spacing[current] > MAX_CHARS)
|
||||
printf("Error reading image font: Character '%c' is out of range.", glyphs[current]);
|
||||
else
|
||||
spacing[(int)glyphs[current]] = space;
|
||||
|
||||
current++;
|
||||
if(current == glyphs.size())
|
||||
i = (int)image->getWidth() - 1; // just to end it when the last character is found
|
||||
|
||||
space = 0;
|
||||
//width++; // start counting the width
|
||||
}
|
||||
width++;
|
||||
}
|
||||
}
|
||||
// Reading image data ends
|
||||
|
||||
// Replace spacer color with an empty pixel
|
||||
for(int i = 0; i < (int)(image->getWidth() * image->getHeight()); i++)
|
||||
{
|
||||
if(spacer.r == pixels[i].r && spacer.g == pixels[i].g && spacer.b == pixels[i].b && spacer.a == pixels[i].a)
|
||||
{
|
||||
pixels[i].r = 0;
|
||||
pixels[i].g = 0;
|
||||
pixels[i].b = 0;
|
||||
pixels[i].a = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Create display lists
|
||||
list = glGenLists(MAX_CHARS);
|
||||
|
||||
for(unsigned int i = 0; i < MAX_CHARS; i++)
|
||||
{
|
||||
glNewList(list + i, GL_COMPILE);
|
||||
|
||||
if(positions[i] != -1)
|
||||
{
|
||||
|
||||
float x = (float)positions[i] + 1;
|
||||
float y = 1.0;
|
||||
float w = (float)widths[i];
|
||||
float h = (float)size+1;
|
||||
|
||||
image->bind();
|
||||
|
||||
float xTex = x/(float)image->getWidth();
|
||||
float yTex = y/(float)image->getHeight();
|
||||
|
||||
float wTex = w/(float)image->getWidth();
|
||||
float hTex = h/(float)image->getHeight();
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(xTex,yTex); glVertex2f(0,0);
|
||||
glTexCoord2f(xTex,yTex+hTex); glVertex2f(0,h);
|
||||
glTexCoord2f(xTex+wTex,yTex+hTex); glVertex2f(w,h);
|
||||
glTexCoord2f(xTex+wTex,yTex); glVertex2f(w,0);
|
||||
glEnd();
|
||||
|
||||
glTranslatef((float)widths[i] + ((float)spacing[i] * mSpacing), 0, 0);
|
||||
}
|
||||
else
|
||||
glTranslatef((float)widths[(int)' '], 0, 0); // empty character are replaced with a whitespace
|
||||
|
||||
glEndList();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ImageFont::unloadVolatile()
|
||||
{
|
||||
glDeleteLists(list, MAX_CHARS);
|
||||
}
|
||||
|
||||
inline int ImageFont::next_p2(int num)
|
||||
{
|
||||
int powered = 2;
|
||||
while(powered < num) powered <<= 1;
|
||||
return powered;
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
@@ -0,0 +1,103 @@
|
||||
/**
|
||||
* 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_OPENGL_IMAGE_FONT_H
|
||||
#define LOVE_OPENGL_IMAGE_FONT_H
|
||||
|
||||
#include <image/ImageData.h>
|
||||
#include "Font.h"
|
||||
#include "Image.h"
|
||||
|
||||
// STD
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
/**
|
||||
* A class to handle OpenGL image fonts.
|
||||
*
|
||||
* @author Michael Enger
|
||||
* @date 2008-01-17
|
||||
**/
|
||||
class ImageFont : public Font
|
||||
{
|
||||
protected:
|
||||
|
||||
Image * image;
|
||||
|
||||
// List of glyphs.
|
||||
std::string glyphs;
|
||||
|
||||
// The position of each character.
|
||||
int positions[MAX_CHARS];
|
||||
|
||||
// OpenGL display lists.
|
||||
unsigned int list;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Default constructor.
|
||||
*
|
||||
* @param file The image file.
|
||||
* @param glyphs A list of the characters as they appear in the image.
|
||||
**/
|
||||
ImageFont(Image * image, std::string glyphs);
|
||||
|
||||
/**
|
||||
* Calls unload().
|
||||
**/
|
||||
virtual ~ImageFont();
|
||||
|
||||
|
||||
// From Font
|
||||
virtual void print(std::string text, float x, float y) const;
|
||||
virtual void print(std::string text, float x, float y, float angle, float sx, float sy) const;
|
||||
virtual void print(char character, float x, float y) const;
|
||||
|
||||
// From Resource.
|
||||
bool load();
|
||||
void unload();
|
||||
|
||||
// From Volatile.
|
||||
bool loadVolatile();
|
||||
void unloadVolatile();
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Returns the closest number to num which is a power of two.
|
||||
*
|
||||
* @param num The number to be 2powered.
|
||||
**/
|
||||
inline int next_p2(int num);
|
||||
|
||||
}; // ImageFont
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_OPENGL_IMAGE_FONT_H
|
||||
@@ -0,0 +1,497 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#include "ParticleSystem.h"
|
||||
|
||||
#include <SDL_opengl.h>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
float calculate_variation(float inner, float outer, float var)
|
||||
{
|
||||
float low = inner - (outer/2.0f)*var;
|
||||
float high = inner + (outer/2.0f)*var;
|
||||
float r = (rand() / (float(RAND_MAX)+1));
|
||||
return low*(1-r)+high*r;
|
||||
}
|
||||
|
||||
|
||||
ParticleSystem::ParticleSystem(Image * sprite, unsigned int buffer) : pStart(0), pLast(0), pEnd(0), active(true), emissionRate(0),
|
||||
emitCounter(0), lifetime(-1), life(0), particleLifeMin(0), particleLifeMax(0),
|
||||
direction(0), spread(0), relative(false), speedMin(0), speedMax(0), gravityMin(0),
|
||||
gravityMax(0), radialAccelerationMin(0), radialAccelerationMax(0),
|
||||
tangentialAccelerationMin(0), tangentialAccelerationMax(0),
|
||||
sizeStart(1), sizeEnd(1), sizeVariation(0), rotationMin(0), rotationMax(0),
|
||||
spinStart(0), spinEnd(0), spinVariation(0)
|
||||
{
|
||||
this->sprite = sprite;
|
||||
sprite->retain();
|
||||
colorStart = Color(255, 255, 255, 255);
|
||||
colorEnd = Color(255, 255, 255, 255);
|
||||
setBufferSize(buffer);
|
||||
}
|
||||
|
||||
ParticleSystem::~ParticleSystem()
|
||||
{
|
||||
if(this->sprite != 0)
|
||||
{
|
||||
this->sprite->release();
|
||||
this->sprite = 0;
|
||||
}
|
||||
|
||||
if(pStart != 0)
|
||||
delete [] pStart;
|
||||
}
|
||||
|
||||
void ParticleSystem::add()
|
||||
{
|
||||
if(isFull()) return;
|
||||
|
||||
float min,max;
|
||||
|
||||
min = particleLifeMin;
|
||||
max = particleLifeMax;
|
||||
if(min == max)
|
||||
pLast->life = min;
|
||||
else
|
||||
pLast->life = (rand() / (float(RAND_MAX)+1)) * (max - min) + min;
|
||||
pLast->lifetime = pLast->life;
|
||||
|
||||
pLast->position[0] = position.getX();
|
||||
pLast->position[1] = position.getY();
|
||||
|
||||
min = direction - spread/2.0f;
|
||||
max = direction + spread/2.0f;
|
||||
pLast->direction = (rand() / (float(RAND_MAX)+1)) * (max - min) + min;
|
||||
|
||||
min = speedMin;
|
||||
max = speedMax;
|
||||
float speed = (rand() / (float(RAND_MAX)+1)) * (max - min) + min;
|
||||
pLast->speed = love::Vector(cos(pLast->direction), sin(pLast->direction));
|
||||
pLast->speed *= speed;
|
||||
|
||||
min = gravityMin;
|
||||
max = gravityMax;
|
||||
pLast->gravity = (rand() / (float(RAND_MAX)+1)) * (max - min) + min;
|
||||
|
||||
min = radialAccelerationMin;
|
||||
max = radialAccelerationMax;
|
||||
pLast->radialAcceleration = (rand() / (float(RAND_MAX)+1)) * (max - min) + min;
|
||||
|
||||
min = tangentialAccelerationMin;
|
||||
max = tangentialAccelerationMax;
|
||||
pLast->tangentialAcceleration = (rand() / (float(RAND_MAX)+1)) * (max - min) + min;
|
||||
|
||||
pLast->sizeStart = calculate_variation(sizeStart, sizeEnd, sizeVariation);
|
||||
pLast->sizeEnd = calculate_variation(sizeEnd, sizeStart, sizeVariation);
|
||||
pLast->size = pLast->sizeStart;
|
||||
|
||||
min = rotationMin;
|
||||
max = rotationMax;
|
||||
pLast->spinStart = calculate_variation(spinStart, spinEnd, spinVariation);
|
||||
pLast->spinEnd = calculate_variation(spinEnd, spinStart, spinVariation);
|
||||
pLast->rotation = (rand() / (float(RAND_MAX)+1)) * (max - min) + min;;
|
||||
|
||||
pLast->color[0] = (float)colorStart.getRed() / 255;
|
||||
pLast->color[1] = (float)colorStart.getGreen() / 255;
|
||||
pLast->color[2] = (float)colorStart.getBlue() / 255;
|
||||
pLast->color[3] = (float)colorStart.getAlpha() / 255;
|
||||
|
||||
pLast++;
|
||||
}
|
||||
|
||||
void ParticleSystem::remove(particle * p)
|
||||
{
|
||||
if(!isEmpty())
|
||||
{
|
||||
*p = *(--pLast);
|
||||
}
|
||||
}
|
||||
|
||||
void ParticleSystem::setSprite(Image * image)
|
||||
{
|
||||
if(this->sprite != 0)
|
||||
{
|
||||
this->sprite->release();
|
||||
this->sprite = 0;
|
||||
}
|
||||
|
||||
this->sprite = image;
|
||||
}
|
||||
|
||||
void ParticleSystem::setBufferSize(unsigned int size)
|
||||
{
|
||||
// delete previous data
|
||||
delete [] pStart;
|
||||
|
||||
pLast = pStart = new particle[size];
|
||||
|
||||
pEnd = pStart + size;
|
||||
}
|
||||
|
||||
void ParticleSystem::setEmissionRate(int rate)
|
||||
{
|
||||
emissionRate = rate;
|
||||
}
|
||||
|
||||
void ParticleSystem::setLifetime(float life)
|
||||
{
|
||||
this->life = lifetime = life;
|
||||
}
|
||||
|
||||
void ParticleSystem::setParticleLife(float min, float max)
|
||||
{
|
||||
particleLifeMin = min;
|
||||
if(max == 0)
|
||||
particleLifeMax = min;
|
||||
else
|
||||
particleLifeMax = max;
|
||||
}
|
||||
|
||||
void ParticleSystem::setPosition(float x, float y)
|
||||
{
|
||||
position = love::Vector(x, y);
|
||||
}
|
||||
|
||||
void ParticleSystem::setDirection(float direction)
|
||||
{
|
||||
this->direction = direction * LOVE_M_TORAD;
|
||||
}
|
||||
|
||||
void ParticleSystem::setSpread(float spread)
|
||||
{
|
||||
this->spread = spread * LOVE_M_TORAD;
|
||||
}
|
||||
|
||||
void ParticleSystem::setRelativeDirection(bool relative)
|
||||
{
|
||||
this->relative = relative;
|
||||
}
|
||||
|
||||
void ParticleSystem::setSpeed(float speed)
|
||||
{
|
||||
speedMin = speedMax = speed;
|
||||
}
|
||||
|
||||
void ParticleSystem::setSpeed(float min, float max)
|
||||
{
|
||||
speedMin = min;
|
||||
speedMax = max;
|
||||
}
|
||||
|
||||
void ParticleSystem::setGravity(float gravity)
|
||||
{
|
||||
gravityMin = gravityMax = gravity;
|
||||
}
|
||||
|
||||
void ParticleSystem::setGravity(float min, float max)
|
||||
{
|
||||
gravityMin = min;
|
||||
gravityMax = max;
|
||||
}
|
||||
|
||||
void ParticleSystem::setRadialAcceleration(float acceleration)
|
||||
{
|
||||
radialAccelerationMin = radialAccelerationMax = acceleration;
|
||||
}
|
||||
|
||||
void ParticleSystem::setRadialAcceleration(float min, float max)
|
||||
{
|
||||
radialAccelerationMin = min;
|
||||
radialAccelerationMax = max;
|
||||
}
|
||||
|
||||
void ParticleSystem::setTangentialAcceleration(float acceleration)
|
||||
{
|
||||
tangentialAccelerationMin = tangentialAccelerationMax = acceleration;
|
||||
}
|
||||
|
||||
void ParticleSystem::setTangentialAcceleration(float min, float max)
|
||||
{
|
||||
tangentialAccelerationMin = min;
|
||||
tangentialAccelerationMax = max;
|
||||
}
|
||||
|
||||
void ParticleSystem::setSize(float size)
|
||||
{
|
||||
sizeStart = size;
|
||||
sizeEnd = size;
|
||||
}
|
||||
|
||||
void ParticleSystem::setSize(float start, float end)
|
||||
{
|
||||
sizeStart = start;
|
||||
sizeEnd = end;
|
||||
}
|
||||
|
||||
void ParticleSystem::setSize(float start, float end, float variation)
|
||||
{
|
||||
sizeStart = start;
|
||||
sizeEnd = end;
|
||||
sizeVariation = variation;
|
||||
}
|
||||
|
||||
void ParticleSystem::setSizeVariation(float variation)
|
||||
{
|
||||
sizeVariation = variation;
|
||||
}
|
||||
|
||||
void ParticleSystem::setRotation(float rotation)
|
||||
{
|
||||
rotationMin = rotationMax = rotation;
|
||||
}
|
||||
|
||||
void ParticleSystem::setRotation(float min, float max)
|
||||
{
|
||||
rotationMin = min;
|
||||
rotationMax = max;
|
||||
}
|
||||
|
||||
void ParticleSystem::setSpin(float spin)
|
||||
{
|
||||
spinStart = spin * LOVE_M_TORAD;
|
||||
spinEnd = spin * LOVE_M_TORAD;
|
||||
}
|
||||
|
||||
void ParticleSystem::setSpin(float start, float end)
|
||||
{
|
||||
spinStart = start * LOVE_M_TORAD;
|
||||
spinEnd = end * LOVE_M_TORAD;
|
||||
}
|
||||
|
||||
void ParticleSystem::setSpin(float start, float end, float variation)
|
||||
{
|
||||
spinStart = start * LOVE_M_TORAD;
|
||||
spinEnd = end * LOVE_M_TORAD;
|
||||
spinVariation = variation * LOVE_M_TORAD;
|
||||
}
|
||||
|
||||
void ParticleSystem::setSpinVariation(float variation)
|
||||
{
|
||||
spinVariation = variation * LOVE_M_TORAD;
|
||||
}
|
||||
|
||||
void ParticleSystem::setColor(Color * color)
|
||||
{
|
||||
colorStart = *color;
|
||||
colorEnd = *color;
|
||||
}
|
||||
|
||||
void ParticleSystem::setColor(Color * start, Color * end)
|
||||
{
|
||||
colorStart = *start;
|
||||
colorEnd = *end;
|
||||
}
|
||||
|
||||
float ParticleSystem::getX() const
|
||||
{
|
||||
return position.getX();
|
||||
}
|
||||
|
||||
float ParticleSystem::getY() const
|
||||
{
|
||||
return position.getY();
|
||||
}
|
||||
|
||||
float ParticleSystem::getDirection() const
|
||||
{
|
||||
return direction * LOVE_M_TODEG;
|
||||
}
|
||||
|
||||
float ParticleSystem::getSpread() const
|
||||
{
|
||||
return spread * LOVE_M_TODEG;
|
||||
}
|
||||
|
||||
int ParticleSystem::count() const
|
||||
{
|
||||
return (int)(pLast - pStart);
|
||||
}
|
||||
|
||||
void ParticleSystem::start()
|
||||
{
|
||||
active = true;
|
||||
}
|
||||
|
||||
void ParticleSystem::stop()
|
||||
{
|
||||
active = false;
|
||||
life = lifetime;
|
||||
emitCounter = 0;
|
||||
}
|
||||
|
||||
void ParticleSystem::pause()
|
||||
{
|
||||
active = false;
|
||||
}
|
||||
|
||||
void ParticleSystem::reset()
|
||||
{
|
||||
pLast = pStart;
|
||||
life = lifetime;
|
||||
emitCounter = 0;
|
||||
}
|
||||
|
||||
bool ParticleSystem::isActive() const
|
||||
{
|
||||
return active;
|
||||
}
|
||||
|
||||
bool ParticleSystem::isEmpty() const
|
||||
{
|
||||
return pStart == pLast;
|
||||
}
|
||||
|
||||
bool ParticleSystem::isFull() const
|
||||
{
|
||||
return pLast == pEnd;
|
||||
}
|
||||
|
||||
void ParticleSystem::draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const
|
||||
{
|
||||
if(sprite == 0) return; // just in case of failure
|
||||
|
||||
glPushMatrix();
|
||||
glPushAttrib(GL_CURRENT_BIT);
|
||||
|
||||
glTranslatef(x, y, 0);
|
||||
glRotatef(angle, 0, 0, 1.0f);
|
||||
glScalef(sx, sy, 1.0f);
|
||||
glTranslatef( ox, oy, 0);
|
||||
|
||||
particle * p = pStart;
|
||||
while(p != pLast)
|
||||
{
|
||||
glPushMatrix();
|
||||
|
||||
glColor4f(p->color[0],p->color[1],p->color[2],p->color[3]);
|
||||
glTranslatef(p->position[0],p->position[1],0.0f);
|
||||
glRotatef(p->rotation * 57.29578f, 0.0f, 0.0f, 1.0f); // rad * (180 / pi)
|
||||
glScalef(p->size,p->size,1.0f);
|
||||
sprite->draw(0,0, 0, 1, 1, 0, 0);
|
||||
|
||||
glPopMatrix();
|
||||
p++;
|
||||
}
|
||||
|
||||
glPopAttrib();
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
void ParticleSystem::update(float dt)
|
||||
{
|
||||
// Traverse all particles and update.
|
||||
particle * p = pStart;
|
||||
|
||||
// Make some more particles.
|
||||
if(active)
|
||||
{
|
||||
float rate = 1.0f / emissionRate; // the amount of time between each particle emit
|
||||
emitCounter += dt;
|
||||
while(emitCounter > rate)
|
||||
{
|
||||
add();
|
||||
emitCounter -= rate;
|
||||
}
|
||||
/*int particles = (int)(emissionRate * dt);
|
||||
for(int i = 0; i != particles; i++)
|
||||
add();*/
|
||||
|
||||
life -= dt;
|
||||
if(lifetime != -1 && life < 0)
|
||||
stop();
|
||||
}
|
||||
|
||||
while(p != pLast)
|
||||
{
|
||||
// Decrease lifespan.
|
||||
p->life -= dt;
|
||||
|
||||
if(p->life > 0)
|
||||
{
|
||||
|
||||
// Temp variables.
|
||||
love::Vector radial, tangential, gravity(0, p->gravity);
|
||||
love::Vector ppos(p->position[0], p->position[1]);
|
||||
|
||||
// Get vector from particle center to particle.
|
||||
radial = ppos - position;
|
||||
radial.normalize();
|
||||
tangential = radial;
|
||||
|
||||
// Resize radial acceleration.
|
||||
radial *= p->radialAcceleration;
|
||||
|
||||
// Calculate tangential acceleration.
|
||||
{
|
||||
float a = tangential.getX();
|
||||
tangential.setX(-tangential.getY());
|
||||
tangential.setY(a);
|
||||
}
|
||||
|
||||
// Resize tangential.
|
||||
tangential *= p->tangentialAcceleration;
|
||||
|
||||
// Update position.
|
||||
p->speed += (radial+tangential+gravity)*dt;
|
||||
|
||||
// Modify position.
|
||||
ppos += p->speed * dt;
|
||||
|
||||
p->position[0] = ppos.getX();
|
||||
p->position[1] = ppos.getY();
|
||||
|
||||
const float t = p->life / p->lifetime;
|
||||
|
||||
// Change size.
|
||||
p->size = p->sizeEnd - ((p->sizeEnd - p->sizeStart) * t);
|
||||
|
||||
// Rotate.
|
||||
p->rotation += (p->spinStart*(1-t) + p->spinEnd*t)*dt;
|
||||
|
||||
// Update color.
|
||||
p->color[0] = (float)(colorEnd.getRed()*(1.0f-t) + colorStart.getRed() * t)/255.0f;
|
||||
p->color[1] = (float)(colorEnd.getGreen()*(1.0f-t) + colorStart.getGreen() * t)/255.0f;
|
||||
p->color[2] = (float)(colorEnd.getBlue()*(1.0f-t) + colorStart.getBlue() * t)/255.0f;
|
||||
p->color[3] = (float)(colorEnd.getAlpha()*(1.0f-t) + colorStart.getAlpha() * t)/255.0f;
|
||||
|
||||
// Next particle.
|
||||
p++;
|
||||
}
|
||||
else
|
||||
{
|
||||
remove(p);
|
||||
|
||||
if(p >= pLast)
|
||||
return;
|
||||
} // else
|
||||
} // while
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
@@ -0,0 +1,432 @@
|
||||
/**
|
||||
* 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_GRAPHICS_OPENGL_PARTICLE_SYSTEM_H
|
||||
#define LOVE_GRAPHICS_OPENGL_PARTICLE_SYSTEM_H
|
||||
|
||||
// LOVE
|
||||
|
||||
#include <common/math.h>
|
||||
#include <common/Vector.h>
|
||||
#include <common/constants.h>
|
||||
#include <graphics/Drawable.h>
|
||||
|
||||
#include "Color.h"
|
||||
#include "Image.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
// Represents a single particle.
|
||||
struct particle
|
||||
{
|
||||
float lifetime;
|
||||
float life;
|
||||
|
||||
float position[2];
|
||||
float direction;
|
||||
|
||||
love::Vector speed;
|
||||
float gravity;
|
||||
float radialAcceleration;
|
||||
float tangentialAcceleration;
|
||||
|
||||
float size;
|
||||
float sizeStart;
|
||||
float sizeEnd;
|
||||
|
||||
float rotation;
|
||||
float spinStart;
|
||||
float spinEnd;
|
||||
|
||||
float color[4];
|
||||
};
|
||||
|
||||
/**
|
||||
* A class for creating, moving and drawing particles.
|
||||
* A big thanks to bobthebloke.org
|
||||
**/
|
||||
class ParticleSystem : public Drawable
|
||||
{
|
||||
protected:
|
||||
|
||||
// The max amount of particles.
|
||||
unsigned int bufferSize;
|
||||
|
||||
// Pointer to the first particle.
|
||||
particle * pStart;
|
||||
|
||||
// Pointer to the next available free space.
|
||||
particle * pLast;
|
||||
|
||||
// Pointer to the end of the memory allocation.
|
||||
particle * pEnd;
|
||||
|
||||
// The sprite to be drawn.
|
||||
Image * sprite;
|
||||
|
||||
// Whether the particle emitter is active.
|
||||
bool active;
|
||||
|
||||
// The emission rate (particles/sec).
|
||||
int emissionRate;
|
||||
|
||||
// Used to determine when a particle should be emitted.
|
||||
float emitCounter;
|
||||
|
||||
// The relative position of the particle emitter.
|
||||
love::Vector position;
|
||||
|
||||
// The lifetime of the particle emitter (-1 means infinite) and the life it has left.
|
||||
float lifetime;
|
||||
float life;
|
||||
|
||||
// The particle life.
|
||||
float particleLifeMin;
|
||||
float particleLifeMax;
|
||||
|
||||
// The direction (and spread) the particles will be emitted in. Measured in radians.
|
||||
float direction;
|
||||
float spread;
|
||||
|
||||
// Whether the direction should be relative to the emitter's movement.
|
||||
bool relative;
|
||||
|
||||
// The speed.
|
||||
float speedMin;
|
||||
float speedMax;
|
||||
|
||||
// Acceleration towards the bottom of the screen
|
||||
float gravityMin;
|
||||
float gravityMax;
|
||||
|
||||
// Acceleration towards the emitter's center
|
||||
float radialAccelerationMin;
|
||||
float radialAccelerationMax;
|
||||
|
||||
// Acceleration perpendicular to the particle's direction.
|
||||
float tangentialAccelerationMin;
|
||||
float tangentialAccelerationMax;
|
||||
|
||||
// Size.
|
||||
float sizeStart;
|
||||
float sizeEnd;
|
||||
float sizeVariation;
|
||||
|
||||
// Rotation
|
||||
float rotationMin;
|
||||
float rotationMax;
|
||||
|
||||
// Spin.
|
||||
float spinStart;
|
||||
float spinEnd;
|
||||
float spinVariation;
|
||||
|
||||
// Color.
|
||||
Color colorStart;
|
||||
Color colorEnd;
|
||||
|
||||
void add();
|
||||
void remove(particle * p);
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a particle system with the specified buffersize and sprite.
|
||||
**/
|
||||
ParticleSystem(Image * sprite, unsigned int buffer);
|
||||
|
||||
/**
|
||||
* Deletes any allocated memory.
|
||||
**/
|
||||
virtual ~ParticleSystem();
|
||||
|
||||
/**
|
||||
* Sets the sprite used in the particle system.
|
||||
* @param sprite The new sprite.
|
||||
**/
|
||||
void setSprite(Image * image);
|
||||
|
||||
/**
|
||||
* Clears the current buffer and allocates the appropriate amount of space for the buffer.
|
||||
* @param size The new buffer size.
|
||||
**/
|
||||
void setBufferSize(unsigned int size);
|
||||
|
||||
/**
|
||||
* Sets the emission rate.
|
||||
* @param rate The amount of particles per second.
|
||||
**/
|
||||
void setEmissionRate(int rate);
|
||||
|
||||
/**
|
||||
* Sets the lifetime of the particle emitter (-1 means eternal)
|
||||
* @param life The lifetime (in seconds).
|
||||
**/
|
||||
void setLifetime(float life);
|
||||
|
||||
/**
|
||||
* Sets the life range of the particles.
|
||||
* @param lifeMin The minimum life.
|
||||
* @param lifeMax The maximum life (if 0, then becomes the same as minimum life).
|
||||
**/
|
||||
void setParticleLife(float min, float max = 0);
|
||||
|
||||
/**
|
||||
* Sets the position of the center of the emitter and the direction (if set to relative).
|
||||
* Used to move the emitter without changing the position of already existing particles.
|
||||
* @param x The x-coordinate.
|
||||
* @param y The y-coordinate.
|
||||
**/
|
||||
void setPosition(float x, float y);
|
||||
|
||||
/**
|
||||
* Sets the direction and the spread of the particle emitter.
|
||||
* @param direction The direction (in degrees).
|
||||
**/
|
||||
void setDirection(float direction);
|
||||
|
||||
/**
|
||||
* Sets the spread of the particle emitter.
|
||||
* @param spread The spread (in degrees).
|
||||
**/
|
||||
void setSpread(float spread);
|
||||
|
||||
/**
|
||||
* Sets whether the direction should be relative to the particle emitters movement. Used in conjunction with setPosition.
|
||||
* @param relative Whether to have relative direction.
|
||||
**/
|
||||
void setRelativeDirection(bool relative);
|
||||
|
||||
/**
|
||||
* Sets the speed of the particles.
|
||||
* @param speed The speed.
|
||||
**/
|
||||
void setSpeed(float speed);
|
||||
|
||||
/**
|
||||
* Sets the speed of the particles.
|
||||
* @param min The minimum speed.
|
||||
* @param max The maximum speed.
|
||||
**/
|
||||
void setSpeed(float min, float max);
|
||||
|
||||
/**
|
||||
* Sets the gravity of the particles (the acceleration along the y-axis).
|
||||
* @param gravity The amount of gravity.
|
||||
**/
|
||||
void setGravity(float gravity);
|
||||
|
||||
/**
|
||||
* Sets the gravity of the particles (the acceleration along the y-axis).
|
||||
* @param min The minimum gravity.
|
||||
* @param max The maximum gravity.
|
||||
**/
|
||||
void setGravity(float min, float max);
|
||||
|
||||
/**
|
||||
* Sets the radial acceleration (the acceleration towards the particle emitter).
|
||||
* @param acceleration The amount of acceleration.
|
||||
**/
|
||||
void setRadialAcceleration(float acceleration);
|
||||
|
||||
/**
|
||||
* Sets the radial acceleration (the acceleration towards the particle emitter).
|
||||
* @param min The minimum acceleration.
|
||||
* @param max The maximum acceleration.
|
||||
**/
|
||||
void setRadialAcceleration(float min, float max);
|
||||
|
||||
/**
|
||||
* Sets the tangential acceleration (the acceleration perpendicular to the particle's direction).
|
||||
* @param acceleration The amount of acceleration.
|
||||
**/
|
||||
void setTangentialAcceleration(float acceleration);
|
||||
|
||||
/**
|
||||
* Sets the tangential acceleration (the acceleration perpendicular to the particle's direction).
|
||||
* @param min The minimum acceleration.
|
||||
* @param max The maximum acceleration.
|
||||
**/
|
||||
void setTangentialAcceleration(float min, float max);
|
||||
|
||||
/**
|
||||
* Sets the size of the sprite (1.0 being the default size).
|
||||
* @param size The size of the sprite.
|
||||
**/
|
||||
void setSize(float size);
|
||||
|
||||
/**
|
||||
* Sets the size of the sprite upon creation and upon death (1.0 being the default size).
|
||||
* @param start The size of the sprite upon creation
|
||||
* @param end The size of the sprite upon death.
|
||||
**/
|
||||
void setSize(float start, float end);
|
||||
|
||||
/**
|
||||
* Sets the size of the sprite upon creation and upon death (1.0 being the default size) and any variation.
|
||||
* @param start The size of the sprite upon creation
|
||||
* @param end The size of the sprite upon death.
|
||||
* @param variation The amount of variation on the starting size (0 being no variation and 1.0 a random size between start and end).
|
||||
**/
|
||||
void setSize(float start, float end, float variation);
|
||||
|
||||
/**
|
||||
* Sets the amount of variation to the sprite's beginning size (0 being no variation and 1.0 a random size between start and end).
|
||||
* @param variation The amount of variation.
|
||||
**/
|
||||
void setSizeVariation(float variation);
|
||||
|
||||
/**
|
||||
* Sets the amount of rotation a sprite starts out with.
|
||||
* @param rotation The amount of rotation.
|
||||
**/
|
||||
void setRotation(float rotation);
|
||||
|
||||
/**
|
||||
* Sets the amount of rotation a sprite starts out with (a random value between min and max).
|
||||
* @param min The minimum amount of rotation.
|
||||
* @param max The maximum amount of rotation.
|
||||
**/
|
||||
void setRotation(float min, float max);
|
||||
|
||||
/**
|
||||
* Sets the spin of the sprite.
|
||||
* @param spin The spin of the sprite (in degrees).
|
||||
**/
|
||||
void setSpin(float spin);
|
||||
|
||||
/**
|
||||
* Sets the spin of the sprite upon particle creation and death.
|
||||
* @param start The spin of the sprite upon creation (in degrees).
|
||||
* @param end The spin of the sprite upon death (in degrees).
|
||||
**/
|
||||
void setSpin(float start, float end);
|
||||
|
||||
/**
|
||||
* Sets the spin of the sprite upon particle creation and death and the variation.
|
||||
* @param start The spin of the sprite upon creation (in degrees).
|
||||
* @param end The spin of the sprite upon death (in degrees).
|
||||
* @param variation The variation of the start spin (0 being no variation and 1 beign a random spin between start and end).
|
||||
**/
|
||||
void setSpin(float start, float end, float variation);
|
||||
|
||||
/**
|
||||
* Sets the variation of the start spin (0 being no variation and 1 beign a random spin between start and end).
|
||||
* @param variation The variation in degrees.
|
||||
**/
|
||||
void setSpinVariation(float variation);
|
||||
|
||||
/**
|
||||
* Sets the color of the particles.
|
||||
* @param color The color.
|
||||
**/
|
||||
void setColor(Color * color);
|
||||
|
||||
/**
|
||||
* Sets the color of the particles.
|
||||
* @param start The color of the particle when created.
|
||||
* @param end The color of the particle upon death.
|
||||
**/
|
||||
void setColor(Color * start, Color * end);
|
||||
|
||||
/**
|
||||
* Returns the x-coordinate of the emitter's position.
|
||||
**/
|
||||
float getX() const;
|
||||
|
||||
/**
|
||||
* Returns the y-coordinate of the emitter's position.
|
||||
**/
|
||||
float getY() const;
|
||||
|
||||
/**
|
||||
* Returns the direction of the emitter (in degrees).
|
||||
**/
|
||||
float getDirection() const;
|
||||
|
||||
/**
|
||||
* Returns the directional spread of the emitter (in degrees).
|
||||
**/
|
||||
float getSpread() const;
|
||||
|
||||
/**
|
||||
* Returns the amount of particles that are currently active in the system.
|
||||
**/
|
||||
int count() const;
|
||||
|
||||
/**
|
||||
* Starts/resumes the particle emitter.
|
||||
**/
|
||||
void start();
|
||||
|
||||
/**
|
||||
* Stops the particle emitter and resets.
|
||||
**/
|
||||
void stop();
|
||||
|
||||
/**
|
||||
* Pauses the particle emitter.
|
||||
**/
|
||||
void pause();
|
||||
|
||||
/**
|
||||
* Resets the particle emitter.
|
||||
**/
|
||||
void reset();
|
||||
|
||||
/**
|
||||
* Returns whether the particle emitter is active.
|
||||
**/
|
||||
bool isActive() const;
|
||||
|
||||
/**
|
||||
* Returns whether the particle system is empty of particles or not.
|
||||
**/
|
||||
bool isEmpty() const;
|
||||
|
||||
/**
|
||||
* Returns whether the amount of particles has reached the buffer limit or not.
|
||||
**/
|
||||
bool isFull() const;
|
||||
|
||||
/**
|
||||
* Draws the particle emitter at the specified position.
|
||||
* @param x The x-coordinate.
|
||||
* @param y The y-coordinate.
|
||||
**/
|
||||
virtual void draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const;
|
||||
|
||||
/**
|
||||
* Updates the particle system.
|
||||
* @param dt Time since last update.
|
||||
**/
|
||||
void update(float dt);
|
||||
};
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_PARTICLE_SYSTEM_H
|
||||
@@ -0,0 +1,111 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#include "SpriteBatch.h"
|
||||
|
||||
// STD
|
||||
#include <iostream>
|
||||
|
||||
// LOVE
|
||||
#include "VertexBuffer.h"
|
||||
#include "Image.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
SpriteBatch::SpriteBatch(Image * image, int size, int usage)
|
||||
: size(size), next(0)
|
||||
{
|
||||
// Four vertices in one sprite.
|
||||
buffer = new VertexBuffer(image, size*6, TYPE_TRIANGLES, usage);
|
||||
}
|
||||
|
||||
SpriteBatch::~SpriteBatch()
|
||||
{
|
||||
buffer->release();
|
||||
}
|
||||
|
||||
void SpriteBatch::add(float x, float y, float a, float sx, float sy, float ox, float oy)
|
||||
{
|
||||
// Only do this if there's a free slot.
|
||||
if(next < size)
|
||||
{
|
||||
// Get a pointer to the correct insertion position.
|
||||
vertex * v = buffer->vertices + next*6;
|
||||
|
||||
// Fill vertices with ones (for white colors).
|
||||
memset(v, 0xff, sizeof(vertex)*6);
|
||||
|
||||
// Half-sizes.
|
||||
float w2 = buffer->image->getWidth()/2.0f;
|
||||
float h2 = buffer->image->getHeight()/2.0f;
|
||||
|
||||
// MASSIVE TODO: just copy vertices from image.
|
||||
|
||||
v[0].x = -w2; v[0].y = -h2;
|
||||
v[1].x = -w2; v[1].y = h2;
|
||||
v[2].x = w2; v[2].y = h2;
|
||||
v[3].x = w2; v[3].y = -h2;
|
||||
|
||||
v[0].s = 0; v[0].t = 0;
|
||||
v[1].s = 0; v[1].t = 1;
|
||||
v[2].s = 1; v[2].t = 1;
|
||||
v[3].s = 1; v[3].t = 0;
|
||||
|
||||
// Transform.
|
||||
Matrix t;
|
||||
t.translate(x, y);
|
||||
t.scale(sx, sy);
|
||||
t.rotate(a);
|
||||
t.transform(v, v, 4);
|
||||
|
||||
v[5] = v[3];
|
||||
v[4] = v[2];
|
||||
v[3] = v[0];
|
||||
|
||||
// Send the buffer to the GPU.
|
||||
buffer->update(next*6, 6);
|
||||
|
||||
// Increment counter.
|
||||
next++;
|
||||
}
|
||||
}
|
||||
|
||||
void SpriteBatch::clear()
|
||||
{
|
||||
// Reset the position of the next index.
|
||||
next = 0;
|
||||
|
||||
// Also reset the buffer.
|
||||
buffer->clear();
|
||||
}
|
||||
|
||||
void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const
|
||||
{
|
||||
// Let the buffer handle this.
|
||||
buffer->draw(x, y, angle, sx, sy, ox, oy);
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* 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_GRAPHICS_OPENGL_SPRITE_BATCH_H
|
||||
#define LOVE_GRAPHICS_OPENGL_SPRITE_BATCH_H
|
||||
|
||||
// C
|
||||
#include <cstring>
|
||||
|
||||
// LOVE
|
||||
#include <common/math.h>
|
||||
#include <common/Object.h>
|
||||
#include <common/Vector.h>
|
||||
#include <common/Matrix.h>
|
||||
#include <graphics/Drawable.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
// Forward declarations.
|
||||
class VertexBuffer;
|
||||
class Image;
|
||||
|
||||
class SpriteBatch : public Drawable
|
||||
{
|
||||
private:
|
||||
|
||||
// Max number of sprites in the batch.
|
||||
int size;
|
||||
|
||||
// The next free element.
|
||||
int next;
|
||||
|
||||
// Vertex Buffer.
|
||||
VertexBuffer * buffer;
|
||||
|
||||
public:
|
||||
|
||||
SpriteBatch(Image * image, int size, int usage);
|
||||
virtual ~SpriteBatch();
|
||||
|
||||
void add(float x, float y, float a, float sx, float sy, float ox, float oy);
|
||||
void clear();
|
||||
|
||||
// Implements Drawable.
|
||||
void draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const;
|
||||
|
||||
}; // SpriteBatch
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_SPRITE_BATCH_H
|
||||
@@ -0,0 +1,255 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#include "TrueTypeFont.h"
|
||||
|
||||
#include <SDL_opengl.h>
|
||||
|
||||
|
||||
#include <math.h>
|
||||
#include <iostream>
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
inline int TrueTypeFont::next_p2(int num)
|
||||
{
|
||||
int powered = 2;
|
||||
while(powered < num) powered <<= 1;
|
||||
return powered;
|
||||
}
|
||||
|
||||
inline void TrueTypeFont::pushScreenCoordinateMatrix()
|
||||
{
|
||||
glPushAttrib(GL_TRANSFORM_BIT);
|
||||
GLint viewport[4];
|
||||
glGetIntegerv(GL_VIEWPORT, viewport);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
gluOrtho2D(viewport[0],viewport[2],viewport[1],viewport[3]);
|
||||
glPopAttrib();
|
||||
}
|
||||
|
||||
inline void TrueTypeFont::popProjectionMatrix()
|
||||
{
|
||||
glPushAttrib(GL_TRANSFORM_BIT);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
glPopAttrib();
|
||||
}
|
||||
|
||||
void TrueTypeFont::createList(FT_Face face, unsigned short character)
|
||||
{
|
||||
if( FT_Load_Glyph(face, FT_Get_Char_Index(face, character), FT_LOAD_DEFAULT) )
|
||||
std::cerr << "TrueTypeFont Loading vm->error: FT_Load_Glyph failed." << std::endl;
|
||||
|
||||
FT_Glyph glyph;
|
||||
if( FT_Get_Glyph(face->glyph, &glyph) )
|
||||
std::cerr << "TrueTypeFont Loading vm->error: FT_Get_Glyph failed." << std::endl;
|
||||
|
||||
FT_Glyph_To_Bitmap(&glyph, FT_RENDER_MODE_NORMAL, 0, 1);
|
||||
FT_BitmapGlyph bitmap_glyph = (FT_BitmapGlyph)glyph;
|
||||
|
||||
FT_Bitmap& bitmap = bitmap_glyph->bitmap; //just to make things easier
|
||||
|
||||
widths[character] = face->glyph->advance.x >> 6;
|
||||
int w = next_p2(bitmap.width);
|
||||
int h = next_p2(bitmap.rows);
|
||||
|
||||
if(bitmap.rows > trueHeight)
|
||||
trueHeight = bitmap.rows;
|
||||
|
||||
GLubyte* expandedData = new GLubyte[ 2 * w * h];
|
||||
|
||||
for(int j = 0; j < h; j++) for(int i = 0; i < w; i++)
|
||||
{
|
||||
expandedData[2 * (i + j * w)] = MAX_CHARS-1;
|
||||
expandedData[2 * (i + j * w) + 1] = (i >= bitmap.width || j >= bitmap.rows) ? 0 : bitmap.buffer[i + bitmap.width * j];
|
||||
}
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, textures[character]);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
|
||||
// Rude adds:
|
||||
// (You're welcome, Mike.)
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, expandedData);
|
||||
|
||||
|
||||
|
||||
delete [] expandedData; //no longer needed
|
||||
|
||||
glNewList(list + character, GL_COMPILE);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, textures[character]);
|
||||
|
||||
glPushMatrix();
|
||||
|
||||
glTranslatef((float)bitmap_glyph->left, -(float)bitmap_glyph->top, 0);
|
||||
//glTranslatef(0, (float)bitmap_glyph->top-bitmap.rows, 0);
|
||||
|
||||
float x=(float)bitmap.width / (float)w,
|
||||
y=(float)bitmap.rows / (float)h;
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2d(0, 0); glVertex2f(0, 0);
|
||||
glTexCoord2d(0, y); glVertex2f(0, (float)bitmap.rows);
|
||||
glTexCoord2d(x, y); glVertex2f((float)bitmap.width, (float)bitmap.rows);
|
||||
glTexCoord2d(x, 0); glVertex2f((float)bitmap.width, 0);
|
||||
glEnd();
|
||||
glPopMatrix();
|
||||
glTranslatef((float)(face->glyph->advance.x >> 6) ,0,0);
|
||||
|
||||
glEndList();
|
||||
|
||||
FT_Done_Glyph(glyph);
|
||||
}
|
||||
|
||||
TrueTypeFont::TrueTypeFont(love::filesystem::File * file, int size)
|
||||
: Font(size), file(file), textures(0), list(0)
|
||||
{
|
||||
file->retain();
|
||||
}
|
||||
|
||||
TrueTypeFont::~TrueTypeFont()
|
||||
{
|
||||
unload();
|
||||
file->release();
|
||||
}
|
||||
|
||||
void TrueTypeFont::print(string text, float x, float y) const
|
||||
{
|
||||
glPushMatrix();
|
||||
glTranslatef(ceil(x), ceil(y), 0.0f); // + getHeight() to make the x,y coordiantes the top left corner
|
||||
GLuint TrueTypeFont = list;
|
||||
glListBase(TrueTypeFont);
|
||||
glCallLists((int)text.length(), GL_UNSIGNED_BYTE, text.c_str());
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
void TrueTypeFont::print(std::string text, float x, float y, float angle, float sx, float sy) const
|
||||
{
|
||||
glPushMatrix();
|
||||
|
||||
glTranslatef(ceil(x), ceil(y), 0.0f);
|
||||
glRotatef(angle, 0, 0, 1.0f);
|
||||
glScalef(sx, sy, 1.0f);
|
||||
|
||||
GLuint TrueTypeFont = list;
|
||||
glListBase(TrueTypeFont);
|
||||
glCallLists((int)text.length(), GL_UNSIGNED_BYTE, text.c_str());
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
void TrueTypeFont::print(char character, float x, float y) const
|
||||
{
|
||||
glPushMatrix();
|
||||
glTranslatef(ceil(x), ceil(y), 0.0f);
|
||||
GLuint TrueTypeFont = list;
|
||||
glListBase(TrueTypeFont);
|
||||
glCallList(list + (int)character);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
float TrueTypeFont::getHeight() const
|
||||
{
|
||||
return (float)trueHeight;
|
||||
}
|
||||
|
||||
float TrueTypeFont::getLineHeight() const
|
||||
{
|
||||
return Font::getLineHeight() * 1.25f;
|
||||
}
|
||||
|
||||
bool TrueTypeFont::load()
|
||||
{
|
||||
return loadVolatile();
|
||||
}
|
||||
|
||||
void TrueTypeFont::unload()
|
||||
{
|
||||
unloadVolatile();
|
||||
}
|
||||
|
||||
bool TrueTypeFont::loadVolatile()
|
||||
{
|
||||
Data * data = file->read();
|
||||
|
||||
trueHeight = size;
|
||||
|
||||
|
||||
textures = (unsigned int *)(new GLuint[MAX_CHARS]);
|
||||
for(unsigned int i = 0; i != MAX_CHARS; i++) widths[i] = 0;
|
||||
|
||||
FT_Library library;
|
||||
if( FT_Init_FreeType(&library) )
|
||||
std::cerr << "TrueTypeFont Loading error: FT_Init_FreeType failed." << std::endl;
|
||||
|
||||
FT_Face face;
|
||||
if( FT_New_Memory_Face( library,
|
||||
(const FT_Byte *)data->getData(), /* first byte in memory */
|
||||
data->getSize(), /* size in bytes */
|
||||
0, /* face_index */
|
||||
&face ))
|
||||
std::cerr << "TrueTypeFont Loading error: FT_New_Face failed (there is probably a problem with your font file)." << std::endl;
|
||||
//FT_Set_Char_Size(face, size << 6, size << 6, 96, 96);
|
||||
FT_Set_Pixel_Sizes(face, size, size);
|
||||
|
||||
list = glGenLists(MAX_CHARS);
|
||||
glGenTextures(MAX_CHARS, (GLuint*)textures);
|
||||
for(unsigned short i = 0; i < MAX_CHARS; i++)
|
||||
createList(face, i);
|
||||
|
||||
FT_Done_Face(face);
|
||||
FT_Done_FreeType(library); //all done
|
||||
|
||||
// Free data.
|
||||
data->release();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void TrueTypeFont::unloadVolatile()
|
||||
{
|
||||
if(list != 0)
|
||||
glDeleteLists(list, MAX_CHARS);
|
||||
if(textures != 0)
|
||||
glDeleteTextures(MAX_CHARS, (const GLuint*)textures);
|
||||
|
||||
// Cleanup plz.
|
||||
if(textures != 0)
|
||||
delete [] textures;
|
||||
textures = 0;
|
||||
list = 0;
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
@@ -0,0 +1,126 @@
|
||||
/**
|
||||
* 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_GRAPHICS_OPENGL_TRUETYPE_FONT_H
|
||||
#define LOVE_GRAPHICS_OPENGL_TRUETYPE_FONT_H
|
||||
|
||||
// Module
|
||||
#include "Font.h"
|
||||
|
||||
// FreeType2
|
||||
#include <ft2build.h>
|
||||
#include <freetype/freetype.h>
|
||||
#include <freetype/ftglyph.h>
|
||||
#include <freetype/ftoutln.h>
|
||||
#include <freetype/fttrigon.h>
|
||||
|
||||
// STD
|
||||
#include <string>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
/**
|
||||
* A class to handle TrueType fonts. Uses the library FreeType2
|
||||
* (available here: http://www.freetype.org/) and takes use of both
|
||||
* their local documentation and Sven's experience.
|
||||
*
|
||||
* @author Michael Enger (with great help from Sven C. Olsen)
|
||||
* @date 2007-01-15
|
||||
**/
|
||||
class TrueTypeFont : public Font
|
||||
{
|
||||
private:
|
||||
|
||||
love::filesystem::File * file;
|
||||
|
||||
protected:
|
||||
|
||||
unsigned int * textures;
|
||||
unsigned int list;
|
||||
int trueHeight; // the true height of the font
|
||||
|
||||
/**
|
||||
* Returns the closest number to num which is a power of two.
|
||||
*
|
||||
* @param num The number to be 2powered.
|
||||
**/
|
||||
inline int next_p2(int num);
|
||||
|
||||
/**
|
||||
* As stated by Sven: A fairly straight forward function that pushes a projection matrix that will make object world coordinates identical to window coordinates.
|
||||
**/
|
||||
inline void pushScreenCoordinateMatrix();
|
||||
|
||||
/**
|
||||
* Pops the projection matrix without changing the current MatrixMode.
|
||||
**/
|
||||
inline void popProjectionMatrix();
|
||||
|
||||
/**
|
||||
* Creates an OpenGL display list for the character (for speedy execution).
|
||||
*
|
||||
* @param face The FT_Face containing information about the character.
|
||||
* @param character The character in question.
|
||||
**/
|
||||
void createList(FT_Face face, unsigned short character);
|
||||
|
||||
public:
|
||||
/**
|
||||
* Default constructor.
|
||||
*
|
||||
* @param file The file containing the TrueTypeFont data.
|
||||
* @param size The size of the TrueTypeFont.
|
||||
**/
|
||||
TrueTypeFont(love::filesystem::File * file, int size);
|
||||
|
||||
/**
|
||||
* Calls unload().
|
||||
**/
|
||||
virtual ~TrueTypeFont();
|
||||
|
||||
|
||||
// From Font
|
||||
//virtual float getHeight() const;
|
||||
virtual void print(std::string text, float x, float y) const;
|
||||
virtual void print(std::string text, float x, float y, float angle, float sx, float sy) const;
|
||||
virtual void print(char character, float x, float y) const;
|
||||
virtual float getHeight() const;
|
||||
virtual float getLineHeight() const;
|
||||
|
||||
// From Resource.
|
||||
bool load();
|
||||
void unload();
|
||||
|
||||
// From Volatile.
|
||||
bool loadVolatile();
|
||||
void unloadVolatile();
|
||||
|
||||
}; // TrueTypeFont
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_TRUETYPE_FONT_H
|
||||
@@ -0,0 +1,188 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#include "VertexBuffer.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
VertexBuffer::VertexBuffer(Image * image, int size, int type, int usage)
|
||||
: size(size), next(0), image(image), vbo_buf(0), type(type), gl_type(0), usage(usage), gl_usage(0)
|
||||
{
|
||||
if(image != 0)
|
||||
image->retain();
|
||||
|
||||
vertices = new vertex[size];
|
||||
|
||||
// If VBOs aren't supported, then we must use vertex arrays.
|
||||
if(!GLEE_ARB_vertex_buffer_object)
|
||||
usage = USAGE_ARRAY;
|
||||
|
||||
// Find out which OpenGL VBO usage hint to use.
|
||||
gl_usage = (usage == USAGE_DYNAMIC) ? GL_DYNAMIC_DRAW : gl_usage;
|
||||
gl_usage = (usage == USAGE_STATIC) ? GL_STATIC_DRAW : gl_usage;
|
||||
gl_usage = (usage == USAGE_STREAM) ? GL_STREAM_DRAW : gl_usage;
|
||||
|
||||
setType(type);
|
||||
|
||||
if(useVBO())
|
||||
{
|
||||
glGenBuffers(1, &vbo_buf);
|
||||
if(vbo_buf != 0)
|
||||
{
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo_buf);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertex)*size, vertices, gl_usage);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
else // FAIL. Use vertex arrays instead.
|
||||
usage = USAGE_ARRAY;
|
||||
}
|
||||
}
|
||||
|
||||
VertexBuffer::~VertexBuffer()
|
||||
{
|
||||
if(image != 0)
|
||||
image->release();
|
||||
|
||||
delete [] vertices;
|
||||
|
||||
if(useVBO() && vbo_buf != 0)
|
||||
glDeleteBuffers(1, &vbo_buf);
|
||||
}
|
||||
|
||||
bool VertexBuffer::useVBO() const
|
||||
{
|
||||
return usage >= USAGE_DYNAMIC;
|
||||
}
|
||||
|
||||
void VertexBuffer::update(int pos, int size)
|
||||
{
|
||||
// Update VBO.
|
||||
if(useVBO())
|
||||
{
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo_buf);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, pos*sizeof(vertex), sizeof(vertex)*size, &vertices[pos]);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
// ... no need to update vertex arrays.
|
||||
|
||||
next += size;
|
||||
}
|
||||
|
||||
void VertexBuffer::setType(int type)
|
||||
{
|
||||
this->type = type;
|
||||
// Find out which OpenGL primitive type to use.
|
||||
gl_type = (type == TYPE_POINTS) ? GL_POINTS : gl_type;
|
||||
gl_type = (type == TYPE_LINES) ? GL_LINES : gl_type;
|
||||
gl_type = (type == TYPE_LINE_STRIP) ? GL_LINE_STRIP : gl_type;
|
||||
gl_type = (type == TYPE_TRIANGLES) ? GL_TRIANGLES : gl_type;
|
||||
gl_type = (type == TYPE_TRIANGLE_STRIP) ? GL_TRIANGLE_STRIP : gl_type;
|
||||
gl_type = (type == TYPE_TRIANGLE_FAN) ? GL_TRIANGLE_FAN : gl_type;
|
||||
}
|
||||
|
||||
int VertexBuffer::getType() const
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
void VertexBuffer::add(float x, float y, float s, float t, unsigned char r, unsigned char g, unsigned char b, unsigned char a)
|
||||
{
|
||||
// Only do this if there's a free slot.
|
||||
if(next < size)
|
||||
{
|
||||
vertex & e = vertices[next];
|
||||
|
||||
e.x = x;
|
||||
e.y = y;
|
||||
e.s = s;
|
||||
e.t = t;
|
||||
e.r = r;
|
||||
e.g = g;
|
||||
e.b = b;
|
||||
e.a = a;
|
||||
|
||||
update(next, 1);
|
||||
}
|
||||
}
|
||||
|
||||
void VertexBuffer::add(float x, float y, float s, float t)
|
||||
{
|
||||
add(x, y, s, y, 255, 255, 255, 255);
|
||||
}
|
||||
|
||||
void VertexBuffer::clear()
|
||||
{
|
||||
// Reset the position of the next index.
|
||||
next = 0;
|
||||
}
|
||||
|
||||
void VertexBuffer::draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const
|
||||
{
|
||||
glPushMatrix();
|
||||
glTranslatef(x, y, 0);
|
||||
|
||||
if(image == 0)
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
else
|
||||
image->bind();
|
||||
|
||||
// Enable vertex arrays.
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
|
||||
if(useVBO())
|
||||
{
|
||||
// Bind the VBO buffer.
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo_buf);
|
||||
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(vertex), (GLvoid*)0);
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid*)(sizeof(unsigned char)*4));
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid*)(sizeof(unsigned char)*4+sizeof(float)*2));
|
||||
glDrawArrays(gl_type, 0, next);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(vertex), (GLvoid*)&vertices[0].r);
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid*)&vertices[0].x);
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid*)&vertices[0].s);
|
||||
glDrawArrays(gl_type, 0, next);
|
||||
}
|
||||
|
||||
// Disable vertex arrays.
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
// Enable textures again.
|
||||
if(image == 0)
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
@@ -0,0 +1,98 @@
|
||||
/**
|
||||
* 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_GRAPHICS_OPENGL_VERTEX_BUFFER_H
|
||||
#define LOVE_GRAPHICS_OPENGL_VERTEX_BUFFER_H
|
||||
|
||||
// LOVE
|
||||
#include <common/constants.h>
|
||||
#include <common/math.h>
|
||||
#include <common/Object.h>
|
||||
#include <common/Vector.h>
|
||||
#include <common/Matrix.h>
|
||||
#include <graphics/Drawable.h>
|
||||
|
||||
// Module.
|
||||
#include "Image.h"
|
||||
|
||||
// OpenGL
|
||||
#include "GLee.h"
|
||||
#include <SDL/SDL_opengl.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
class VertexBuffer : public Drawable
|
||||
{
|
||||
friend class SpriteBatch;
|
||||
private:
|
||||
|
||||
vertex * vertices;
|
||||
|
||||
// Max number of vertices in the buffer.
|
||||
int size;
|
||||
|
||||
// The next free element.
|
||||
int next;
|
||||
|
||||
// The texture (optional).
|
||||
Image * image;
|
||||
|
||||
// Contains the vbo_buffer.
|
||||
GLuint vbo_buf;
|
||||
|
||||
// The uage hint for the vertex buffer.
|
||||
int usage;
|
||||
int gl_usage;
|
||||
|
||||
// The type of primitives we're drawing.
|
||||
int type;
|
||||
int gl_type;
|
||||
|
||||
private:
|
||||
|
||||
bool useVBO() const;
|
||||
void update(int pos, int size);
|
||||
|
||||
public:
|
||||
|
||||
VertexBuffer(Image * image, int size, int type, int usage);
|
||||
virtual ~VertexBuffer();
|
||||
|
||||
void setType(int type);
|
||||
int getType() const;
|
||||
|
||||
void add(float x, float y, float s, float t, unsigned char r, unsigned char g, unsigned char b, unsigned char a);
|
||||
void add(float x, float y, float s, float t);
|
||||
void clear();
|
||||
|
||||
// Implements Drawable.
|
||||
void draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const;
|
||||
|
||||
}; // VertexBuffer
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_VERTEX_BUFFER_H
|
||||
@@ -0,0 +1,161 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
// LOVE
|
||||
#include "wrap_Animation.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
Animation * luax_checkanimation(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<Animation>(L, idx, "Animation", LOVE_GRAPHICS_ANIMATION_BITS);
|
||||
}
|
||||
|
||||
int _wrap_Animation_addFrame(lua_State * L)
|
||||
{
|
||||
Animation * t = luax_checkanimation(L, 1);
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
float w = (float)luaL_checknumber(L, 4);
|
||||
float h = (float)luaL_checknumber(L, 5);
|
||||
float d = (float)luaL_checknumber(L, 6);
|
||||
t->addFrame(x, y, w, h, d);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_Animation_play(lua_State * L)
|
||||
{
|
||||
Animation * t = luax_checkanimation(L, 1);
|
||||
t->play();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_Animation_stop(lua_State * L)
|
||||
{
|
||||
Animation * t = luax_checkanimation(L, 1);
|
||||
t->stop();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_Animation_reset(lua_State * L)
|
||||
{
|
||||
Animation * t = luax_checkanimation(L, 1);
|
||||
t->reset();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_Animation_seek(lua_State * L)
|
||||
{
|
||||
Animation * t = luax_checkanimation(L, 1);
|
||||
int frame = luaL_checkint(L, 2);
|
||||
t->seek(frame);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_Animation_getCurrentFrame(lua_State * L)
|
||||
{
|
||||
Animation * t = luax_checkanimation(L, 1);
|
||||
lua_pushnumber(L, t->getCurrentFrame());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_Animation_getSize(lua_State * L)
|
||||
{
|
||||
Animation * t = luax_checkanimation(L, 1);
|
||||
lua_pushnumber(L, t->getSize());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_Animation_setDelay(lua_State * L)
|
||||
{
|
||||
Animation * t = luax_checkanimation(L, 1);
|
||||
int frame = luaL_checkint(L, 2);
|
||||
float delay = (float)luaL_checknumber(L, 3);
|
||||
t->setDelay(frame, delay);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_Animation_setSpeed(lua_State * L)
|
||||
{
|
||||
Animation * t = luax_checkanimation(L, 1);
|
||||
float speed = (float)luaL_checknumber(L, 2);
|
||||
t->setSpeed(speed);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_Animation_getSpeed(lua_State * L)
|
||||
{
|
||||
Animation * t = luax_checkanimation(L, 1);
|
||||
lua_pushnumber(L, t->getSpeed());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_Animation_update(lua_State * L)
|
||||
{
|
||||
Animation * t = luax_checkanimation(L, 1);
|
||||
float dt = (float)luaL_checknumber(L, 2);
|
||||
t->update(dt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_Animation_getWidth(lua_State * L)
|
||||
{
|
||||
Animation * t = luax_checkanimation(L, 1);
|
||||
lua_pushnumber(L, t->getWidth());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_Animation_getHeight(lua_State * L)
|
||||
{
|
||||
Animation * t = luax_checkanimation(L, 1);
|
||||
lua_pushnumber(L, t->getHeight());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg wrap_Animation_functions[] = {
|
||||
{ "addFrame", _wrap_Animation_addFrame },
|
||||
{ "play", _wrap_Animation_play },
|
||||
{ "stop", _wrap_Animation_stop },
|
||||
{ "reset", _wrap_Animation_reset },
|
||||
{ "seek", _wrap_Animation_seek },
|
||||
{ "getCurrentFrame", _wrap_Animation_getCurrentFrame },
|
||||
{ "getSize", _wrap_Animation_getSize },
|
||||
{ "setDelay", _wrap_Animation_setDelay },
|
||||
{ "setSpeed", _wrap_Animation_setSpeed },
|
||||
{ "getSpeed", _wrap_Animation_getSpeed },
|
||||
{ "update", _wrap_Animation_update },
|
||||
{ "getWidth", _wrap_Animation_getWidth },
|
||||
{ "getHeight", _wrap_Animation_getHeight },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int wrap_Animation_open(lua_State * L)
|
||||
{
|
||||
luax_register_type(L, "Animation", wrap_Animation_functions);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* 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_GRAPHICS_OPENGL_WRAP_ANIMATION_H
|
||||
#define LOVE_GRAPHICS_OPENGL_WRAP_ANIMATION_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "Animation.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
Animation * luax_checkanimation(lua_State * L, int idx);
|
||||
int _wrap_Animation_addFrame(lua_State * L);
|
||||
int _wrap_Animation_play(lua_State * L);
|
||||
int _wrap_Animation_stop(lua_State * L);
|
||||
int _wrap_Animation_reset(lua_State * L);
|
||||
int _wrap_Animation_seek(lua_State * L);
|
||||
int _wrap_Animation_getCurrentFrame(lua_State * L);
|
||||
int _wrap_Animation_getSize(lua_State * L);
|
||||
int _wrap_Animation_setDelay(lua_State * L);
|
||||
int _wrap_Animation_setSpeed(lua_State * L);
|
||||
int _wrap_Animation_getSpeed(lua_State * L);
|
||||
int _wrap_Animation_update(lua_State * L);
|
||||
int _wrap_Animation_getWidth(lua_State * L);
|
||||
int _wrap_Animation_getHeight(lua_State * L);
|
||||
int wrap_Animation_open(lua_State * L);
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_WRAP_ANIMATION_H
|
||||
@@ -0,0 +1,117 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
// LOVE
|
||||
#include "wrap_Color.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
// This macro makes checking for the correct type slightly more compact.
|
||||
Color * luax_checkcolor(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<Color>(L, idx, "Color", LOVE_GRAPHICS_COLOR_BITS);
|
||||
}
|
||||
|
||||
int _wrap_Color_setRed(lua_State * L)
|
||||
{
|
||||
Color * t = luax_checkcolor(L, 1);
|
||||
int arg = luaL_checkinteger(L, 2);
|
||||
t->setRed(arg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_Color_setGreen(lua_State * L)
|
||||
{
|
||||
Color * t = luax_checkcolor(L, 1);
|
||||
int arg = luaL_checkinteger(L, 2);
|
||||
t->setGreen(arg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_Color_setBlue(lua_State * L)
|
||||
{
|
||||
Color * t = luax_checkcolor(L, 1);
|
||||
int arg = luaL_checkinteger(L, 2);
|
||||
t->setBlue(arg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_Color_setAlpha(lua_State * L)
|
||||
{
|
||||
Color * t = luax_checkcolor(L, 1);
|
||||
int arg = luaL_checkinteger(L, 2);
|
||||
t->setAlpha(arg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_Color_getRed(lua_State * L)
|
||||
{
|
||||
Color * t = luax_checkcolor(L, 1);
|
||||
lua_pushinteger(L, t->getRed());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_Color_getGreen(lua_State * L)
|
||||
{
|
||||
Color * t = luax_checkcolor(L, 1);
|
||||
lua_pushinteger(L, t->getGreen());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_Color_getBlue(lua_State * L)
|
||||
{
|
||||
Color * t = luax_checkcolor(L, 1);
|
||||
lua_pushinteger(L, t->getBlue());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_Color_getAlpha(lua_State * L)
|
||||
{
|
||||
Color * t = luax_checkcolor(L, 1);
|
||||
lua_pushinteger(L, t->getAlpha());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg wrap_Color_functions[] = {
|
||||
{ "setRed", _wrap_Color_setRed },
|
||||
{ "setGreen", _wrap_Color_setGreen },
|
||||
{ "setBlue", _wrap_Color_setBlue },
|
||||
{ "setAlpha", _wrap_Color_setAlpha },
|
||||
{ "getRed", _wrap_Color_getRed },
|
||||
{ "getGreen", _wrap_Color_getGreen },
|
||||
{ "getBlue", _wrap_Color_getBlue },
|
||||
{ "getAlpha", _wrap_Color_getAlpha },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int wrap_Color_open(lua_State * L)
|
||||
{
|
||||
luax_register_type(L, "Color", wrap_Color_functions);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* 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_GRAPHICS_OPENGL_WRAP_COLOR_H
|
||||
#define LOVE_GRAPHICS_OPENGL_WRAP_COLOR_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "Color.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
Color * luax_checkcolor(lua_State * L, int idx);
|
||||
int _wrap_Color_setRed(lua_State * L);
|
||||
int _wrap_Color_setGreen(lua_State * L);
|
||||
int _wrap_Color_setBlue(lua_State * L);
|
||||
int _wrap_Color_setAlpha(lua_State * L);
|
||||
int _wrap_Color_getRed(lua_State * L);
|
||||
int _wrap_Color_getGreen(lua_State * L);
|
||||
int _wrap_Color_getBlue(lua_State * L);
|
||||
int _wrap_Color_getAlpha(lua_State * L);
|
||||
int wrap_Color_open(lua_State * L);
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_WRAP_COLOR_H
|
||||
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
// LOVE
|
||||
#include "wrap_Font.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
// This macro makes checking for the correct type slightly more compact.
|
||||
Font * luax_checkfont(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<Font>(L, idx, "Font", LOVE_GRAPHICS_FONT_BITS);
|
||||
}
|
||||
|
||||
int _wrap_Font_getHeight(lua_State * L)
|
||||
{
|
||||
Font * t = luax_checkfont(L, 1);
|
||||
lua_pushnumber(L, t->getHeight());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_Font_getWidth(lua_State * L)
|
||||
{
|
||||
Font * t = luax_checkfont(L, 1);
|
||||
const char * str = luaL_checkstring(L, 2);
|
||||
lua_pushnumber(L, t->getWidth(str));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_Font_setLineHeight(lua_State * L)
|
||||
{
|
||||
Font * t = luax_checkfont(L, 1);
|
||||
float h = (float)luaL_checknumber(L, 2);
|
||||
t->setLineHeight(h);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_Font_getLineHeight(lua_State * L)
|
||||
{
|
||||
Font * t = luax_checkfont(L, 1);
|
||||
lua_pushnumber(L, t->getLineHeight());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg wrap_Font_functions[] = {
|
||||
{ "getHeight", _wrap_Font_getHeight },
|
||||
{ "getWidth", _wrap_Font_getWidth },
|
||||
{ "setLineHeight", _wrap_Font_setLineHeight },
|
||||
{ "getLineHeight", _wrap_Font_getLineHeight },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int wrap_Font_open(lua_State * L)
|
||||
{
|
||||
luax_register_type(L, "Font", wrap_Font_functions);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* 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_GRAPHICS_OPENGL_WRAP_FONT_H
|
||||
#define LOVE_GRAPHICS_OPENGL_WRAP_FONT_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "Font.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
Font * luax_checkfont(lua_State * L, int idx);
|
||||
int _wrap_Font_getHeight(lua_State * L);
|
||||
int _wrap_Font_getWidth(lua_State * L);
|
||||
int _wrap_Font_setLineHeight(lua_State * L);
|
||||
int _wrap_Font_getLineHeight(lua_State * L);
|
||||
int wrap_Font_open(lua_State * L);
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_WRAP_FONT_H
|
||||
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
// LOVE
|
||||
#include "wrap_Frame.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
Frame * luax_checkframe(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<Frame>(L, idx, "Frame", LOVE_GRAPHICS_FRAME_BITS);
|
||||
}
|
||||
|
||||
int _wrap_Frame_flip(lua_State *L)
|
||||
{
|
||||
Frame *frame = luax_checktype<Frame>(L, 1, "Frame", LOVE_GRAPHICS_FRAME_BITS);
|
||||
frame->flip(luax_toboolean(L, 2), luax_toboolean(L, 3));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const luaL_Reg wrap_Frame_functions[] = {
|
||||
{ "flip", _wrap_Frame_flip },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int wrap_Frame_open(lua_State * L)
|
||||
{
|
||||
luax_register_type(L, "Frame", wrap_Frame_functions);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* 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_GRAPHICS_OPENGL_WRAP_FRAME_H
|
||||
#define LOVE_GRAPHICS_OPENGL_WRAP_FRAME_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "Frame.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
Frame * luax_checkframe(lua_State * L, int idx);
|
||||
int _wrap_Frame_flip(lua_State *L);
|
||||
int wrap_Frame_open(lua_State * L);
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_WRAP_FRAME_H
|
||||
@@ -0,0 +1,850 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
#include "wrap_Graphics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
static Graphics * instance = 0;
|
||||
|
||||
int _wrap_checkMode(lua_State * L)
|
||||
{
|
||||
int w = luaL_checkint(L, 1);
|
||||
int h = luaL_checkint(L, 2);
|
||||
bool fs = luax_toboolean(L, 3);
|
||||
luax_pushboolean(L, instance->checkMode(w, h, fs));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_setMode(lua_State * L)
|
||||
{
|
||||
int w = luaL_checkint(L, 1);
|
||||
int h = luaL_checkint(L, 2);
|
||||
bool fs = luax_optboolean(L, 3, false);
|
||||
bool vsync = luax_optboolean(L, 4, true);
|
||||
int fsaa = luaL_optint(L, 5, 0);
|
||||
luax_pushboolean(L, instance->setMode(w, h, fs, vsync, fsaa));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_toggleFullscreen(lua_State * L)
|
||||
{
|
||||
luax_pushboolean(L, instance->toggleFullscreen());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_reset(lua_State * L)
|
||||
{
|
||||
instance->reset();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_clear(lua_State * L)
|
||||
{
|
||||
instance->clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_present(lua_State * L)
|
||||
{
|
||||
instance->present();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_setCaption(lua_State * L)
|
||||
{
|
||||
const char * str = luaL_checkstring(L, 1);
|
||||
instance->setCaption(str);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_getCaption(lua_State * L)
|
||||
{
|
||||
return instance->getCaption(L);
|
||||
}
|
||||
|
||||
int _wrap_getWidth(lua_State * L)
|
||||
{
|
||||
lua_pushnumber(L, instance->getWidth());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_getHeight(lua_State * L)
|
||||
{
|
||||
lua_pushnumber(L, instance->getHeight());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_isCreated(lua_State * L)
|
||||
{
|
||||
luax_pushboolean(L, instance->isCreated());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_getModes(lua_State * L)
|
||||
{
|
||||
return instance->getModes(L);
|
||||
}
|
||||
|
||||
int _wrap_setScissor(lua_State * L)
|
||||
{
|
||||
if(lua_gettop(L) == 0)
|
||||
{
|
||||
instance->setScissor();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int x = luaL_checkint(L, 1);
|
||||
int y = luaL_checkint(L, 2);
|
||||
int w = luaL_checkint(L, 3);
|
||||
int h = luaL_checkint(L, 4);
|
||||
|
||||
instance->setScissor(x, y, w, h);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_getScissor(lua_State * L)
|
||||
{
|
||||
return instance->getScissor(L);
|
||||
}
|
||||
|
||||
int _wrap_newColor(lua_State * L)
|
||||
{
|
||||
int r = luaL_checkinteger(L, 1);
|
||||
int g = luaL_checkinteger(L, 2);
|
||||
int b = luaL_checkinteger(L, 3);
|
||||
int a = luaL_optint(L, 4, 255);
|
||||
|
||||
Color * t = instance->newColor(r, g, b, a);
|
||||
|
||||
luax_newtype(L, "Color", LOVE_GRAPHICS_COLOR_BITS, (void*)t);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_newImage(lua_State * L)
|
||||
{
|
||||
// Convert to File, if necessary.
|
||||
if(lua_isstring(L, 1))
|
||||
luax_strtofile(L, 1);
|
||||
|
||||
// Convert to ImageData, if necessary.
|
||||
if(luax_istype(L, 1, LOVE_FILESYSTEM_FILE_BITS))
|
||||
luax_convobj(L, 1, "image", "newImageData");
|
||||
|
||||
love::image::ImageData * data = luax_checktype<love::image::ImageData>(L, 1, "ImageData", LOVE_IMAGE_IMAGE_DATA_BITS);
|
||||
|
||||
// Create the image.
|
||||
Image * image = instance->newImage(data);
|
||||
|
||||
if(image == 0)
|
||||
return luaL_error(L, "Could not load image.");
|
||||
|
||||
|
||||
// Push the type.
|
||||
luax_newtype(L, "Image", LOVE_GRAPHICS_IMAGE_BITS, (void*)image);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_newFrame(lua_State * L)
|
||||
{
|
||||
int x = luaL_checkint(L, 1);
|
||||
int y = luaL_checkint(L, 2);
|
||||
int w = luaL_checkint(L, 3);
|
||||
int h = luaL_checkint(L, 4);
|
||||
int sw = luaL_checkint(L, 5);
|
||||
int sh = luaL_checkint(L, 6);
|
||||
|
||||
Frame * frame = instance->newFrame(x, y, w, h, sw, sh);
|
||||
|
||||
if (frame == 0)
|
||||
return luaL_error(L, "Could not create frame.");
|
||||
|
||||
luax_newtype(L, "Frame", LOVE_GRAPHICS_FRAME_BITS, (void*)frame);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_newAnimation(lua_State * L)
|
||||
{
|
||||
// If string -> file
|
||||
if(lua_isstring(L, 1))
|
||||
luax_strtofile(L, 1);
|
||||
|
||||
// file -> imagedata
|
||||
if(luax_istype(L, 1, LOVE_FILESYSTEM_FILE_BITS))
|
||||
luax_convobj(L, 1, "image", "newImageData");
|
||||
|
||||
// imagedata -> image
|
||||
if(luax_istype(L, 1, LOVE_IMAGE_IMAGE_DATA_BITS))
|
||||
luax_convobj(L, 1, "graphics", "newImage");
|
||||
|
||||
// Check the value.
|
||||
Image * image = luax_checktype<Image>(L, 1, "Image", LOVE_GRAPHICS_IMAGE_BITS);
|
||||
|
||||
Animation * animation = 0;
|
||||
|
||||
if(lua_gettop(L) == 1)
|
||||
{
|
||||
animation = instance->newAnimation(image);
|
||||
}
|
||||
else
|
||||
{
|
||||
float fw = (float)luaL_checknumber(L, 2);
|
||||
float fh = (float)luaL_checknumber(L, 3);
|
||||
float delay = (float)luaL_checknumber(L, 4);
|
||||
int num = luaL_optint(L, 5, 0);
|
||||
animation = instance->newAnimation(image, fw, fh, delay, num);
|
||||
}
|
||||
|
||||
if(animation == 0)
|
||||
return luaL_error(L, "Could not load the Animation");
|
||||
|
||||
luax_newtype(L, "Animation", LOVE_GRAPHICS_ANIMATION_BITS, (void*)animation);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_newFont(lua_State * L)
|
||||
{
|
||||
// Convert to File, if necessary.
|
||||
if(lua_isstring(L, 1))
|
||||
luax_strtofile(L, 1);
|
||||
|
||||
// Check the value.
|
||||
love::filesystem::File * file = luax_checktype<love::filesystem::File>(L, 1, "File", LOVE_FILESYSTEM_FILE_BITS);
|
||||
|
||||
// Second optional parameter can be a number:
|
||||
int size = luaL_optint(L, 2, 12);
|
||||
|
||||
Font * font = instance->newFont(file, size);
|
||||
|
||||
if(font == 0)
|
||||
return luaL_error(L, "Could not load the font");
|
||||
|
||||
luax_newtype(L, "Font", LOVE_GRAPHICS_FONT_BITS, (void*)font);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_newImageFont(lua_State * L)
|
||||
{
|
||||
// Convert to File, if necessary.
|
||||
if(lua_isstring(L, 1))
|
||||
luax_strtofile(L, 1);
|
||||
|
||||
// Convert to Image, if necessary.
|
||||
if(luax_istype(L, 1, LOVE_FILESYSTEM_FILE_BITS))
|
||||
luax_convobj(L, 1, "graphics", "newImage");
|
||||
|
||||
// Check the value.
|
||||
Image * image = luax_checktype<Image>(L, 1, "Image", LOVE_GRAPHICS_IMAGE_BITS);
|
||||
|
||||
const char * glyphs = luaL_checkstring(L, 2);
|
||||
|
||||
Font * font = instance->newImageFont(image, glyphs);
|
||||
|
||||
if(font == 0)
|
||||
return luaL_error(L, "Could not load the font");
|
||||
|
||||
luax_newtype(L, "Font", LOVE_GRAPHICS_FONT_BITS, (void*)font);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_newSpriteBatch(lua_State * L)
|
||||
{
|
||||
Image * image = luax_checktype<Image>(L, 1, "Image", LOVE_GRAPHICS_IMAGE_BITS);
|
||||
int size = luaL_optint(L, 2, 1000);
|
||||
int usage = luaL_optint(L, 3, USAGE_ARRAY);
|
||||
SpriteBatch * t = instance->newSpriteBatch(image, size, usage);
|
||||
luax_newtype(L, "SpriteBatch", LOVE_GRAPHICS_SPRITE_BATCH_BITS, (void*)t);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_newVertexBuffer(lua_State * L)
|
||||
{
|
||||
|
||||
Image * image;
|
||||
int type, usage, size;
|
||||
|
||||
if(luax_istype(L, 1, LOVE_GRAPHICS_IMAGE_BITS))
|
||||
{
|
||||
image = luax_checktype<Image>(L, 1, "Image", LOVE_GRAPHICS_IMAGE_BITS);
|
||||
size = luaL_optint(L, 2, 100);
|
||||
type = luaL_optint(L, 3, TYPE_TRIANGLES);
|
||||
usage = luaL_optint(L, 4, USAGE_ARRAY);
|
||||
}
|
||||
else if(lua_isnumber(L, 1))
|
||||
{
|
||||
image = 0;
|
||||
size = luaL_optint(L, 1, 100);
|
||||
type = luaL_optint(L, 2, TYPE_TRIANGLES);
|
||||
usage = luaL_optint(L, 3, USAGE_ARRAY);
|
||||
}
|
||||
else return luaL_error(L, "Expected type image or number");
|
||||
|
||||
VertexBuffer * t = instance->newVertexBuffer(image, size, type, usage);
|
||||
luax_newtype(L, "VertexBuffer", LOVE_GRAPHICS_VERTEX_BUFFER_BITS, (void*)t);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_setColor(lua_State * L)
|
||||
{
|
||||
if(luax_istype(L, 1, LOVE_GRAPHICS_COLOR_BITS))
|
||||
{
|
||||
Color * color = luax_checktype<Color>(L, 1, "Color", LOVE_GRAPHICS_COLOR_BITS);
|
||||
instance->setColor(color);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int r = luaL_checkint(L, 1);
|
||||
int g = luaL_checkint(L, 2);
|
||||
int b = luaL_checkint(L, 3);
|
||||
int a = luaL_optint(L, 4, 255);
|
||||
|
||||
instance->setColor(r, g, b, a);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_getColor(lua_State * L)
|
||||
{
|
||||
Color * color = instance->getColor();
|
||||
luax_newtype(L, "Color", LOVE_GRAPHICS_COLOR_BITS, (void*)color);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_setBackgroundColor(lua_State * L)
|
||||
{
|
||||
if(luax_istype(L, 1, LOVE_GRAPHICS_COLOR_BITS))
|
||||
{
|
||||
Color * color = luax_checktype<Color>(L, 1, "Color", LOVE_GRAPHICS_COLOR_BITS);
|
||||
instance->setBackgroundColor(color);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int r = luaL_checkint(L, 1);
|
||||
int g = luaL_checkint(L, 1);
|
||||
int b = luaL_checkint(L, 1);
|
||||
|
||||
instance->setBackgroundColor(r, g, b);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_getBackgroundColor(lua_State * L)
|
||||
{
|
||||
Color * color = instance->getBackgroundColor();
|
||||
luax_newtype(L, "Color", LOVE_GRAPHICS_COLOR_BITS, (void*)color);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_setFont(lua_State * L)
|
||||
{
|
||||
// The second parameter is an optional int.
|
||||
int size = luaL_optint(L, 2, 12);
|
||||
|
||||
// If the first parameter is a string, convert it to a file.
|
||||
if(lua_isstring(L, 1))
|
||||
luax_strtofile(L, 1);
|
||||
|
||||
// If the first parameter is a File, use another setFont function.
|
||||
if(luax_istype(L, 1, LOVE_FILESYSTEM_FILE_BITS))
|
||||
{
|
||||
love::filesystem::File * file = luax_checktype<love::filesystem::File>(L, 1, "File", LOVE_FILESYSTEM_FILE_BITS);
|
||||
instance->setFont(file, size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Font * font = luax_checktype<Font>(L, 1, "Font", LOVE_GRAPHICS_FONT_BITS);
|
||||
instance->setFont(font);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_getFont(lua_State * L)
|
||||
{
|
||||
Font * f = instance->getFont();
|
||||
|
||||
if(f == 0)
|
||||
return 0;
|
||||
|
||||
f->retain();
|
||||
luax_newtype(L, "Font", LOVE_GRAPHICS_FONT_BITS, (void*)f);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_setBlendMode(lua_State * L)
|
||||
{
|
||||
int mode = luaL_checkint(L, 1);
|
||||
instance->setBlendMode(mode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_setColorMode(lua_State * L)
|
||||
{
|
||||
int mode = luaL_checkint(L, 1);
|
||||
instance->setColorMode(mode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_getBlendMode(lua_State * L)
|
||||
{
|
||||
lua_pushinteger(L, instance->getBlendMode());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_getColorMode(lua_State * L)
|
||||
{
|
||||
lua_pushinteger(L, instance->getColorMode());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_setLineWidth(lua_State * L)
|
||||
{
|
||||
float width = (float)luaL_checknumber(L, 1);
|
||||
instance->setLineWidth(width);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_setLineStyle(lua_State * L)
|
||||
{
|
||||
int style = luaL_checkint(L, 1);
|
||||
instance->setLineStyle(style);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_setLine(lua_State * L)
|
||||
{
|
||||
float width = (float)luaL_checknumber(L, 1);
|
||||
int style = luaL_optint(L, 2, LINE_SMOOTH);
|
||||
instance->setLine(width, style);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_setLineStipple(lua_State * L)
|
||||
{
|
||||
if(lua_gettop(L) == 0)
|
||||
{
|
||||
instance->setLineStipple();
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned short pattern = (unsigned short)luaL_checkint(L, 1);
|
||||
int repeat = luaL_optint(L, 2, 1);
|
||||
instance->setLineStipple(pattern, repeat);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_getLineWidth(lua_State * L)
|
||||
{
|
||||
lua_pushnumber(L, instance->getLineWidth());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_getLineStyle(lua_State * L)
|
||||
{
|
||||
lua_pushinteger(L, instance->getLineStyle());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_getLineStipple(lua_State * L)
|
||||
{
|
||||
return instance->getLineStipple(L);
|
||||
}
|
||||
|
||||
int _wrap_setPointSize(lua_State * L)
|
||||
{
|
||||
float size = (float)luaL_checknumber(L, 1);
|
||||
instance->setPointSize(size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_setPointStyle(lua_State * L)
|
||||
{
|
||||
int style = luaL_checkint(L, 1);
|
||||
instance->setPointStyle(style);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_setPoint(lua_State * L)
|
||||
{
|
||||
float size = (float)luaL_checknumber(L, 1);
|
||||
int style = luaL_optint(L, 2, POINT_SMOOTH);
|
||||
instance->setPoint(size, style);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_getPointSize(lua_State * L)
|
||||
{
|
||||
lua_pushnumber(L, instance->getPointSize());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_getPointStyle(lua_State * L)
|
||||
{
|
||||
lua_pushinteger(L, instance->getPointStyle());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_getMaxPointSize(lua_State * L)
|
||||
{
|
||||
lua_pushnumber(L, instance->getMaxPointSize());
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws an Image at the specified coordinates, with rotation and
|
||||
* scaling along both axes.
|
||||
* @param x The x-coordinate.
|
||||
* @param y The y-coordinate.
|
||||
* @param angle The amount of rotation.
|
||||
* @param sx The scale factor along the x-axis. (1 = normal).
|
||||
* @param sy The scale factor along the y-axis. (1 = normal).
|
||||
* @param ox The offset along the x-axis.
|
||||
* @param oy The offset along the y-axis.
|
||||
**/
|
||||
int _wrap_draw(lua_State * L)
|
||||
{
|
||||
Drawable * drawable = luax_checktype<Drawable>(L, 1, "Drawable", LOVE_GRAPHICS_DRAWABLE_BITS);
|
||||
float x = (float)luaL_optnumber(L, 2, 0.0f);
|
||||
float y = (float)luaL_optnumber(L, 3, 0.0f);
|
||||
float angle = (float)luaL_optnumber(L, 4, 0.0f);
|
||||
float sx = (float)luaL_optnumber(L, 5, 1.0f);
|
||||
float sy = (float)luaL_optnumber(L, 6, sx);
|
||||
float ox = (float)luaL_optnumber(L, 7, 0);
|
||||
float oy = (float)luaL_optnumber(L, 8, 0);
|
||||
drawable->draw(x, y, angle, sx, sy, ox, oy);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws an Image at the specified coordinates, with rotation and
|
||||
* scaling along both axes.
|
||||
* @param x The x-coordinate.
|
||||
* @param y The y-coordinate.
|
||||
* @param angle The amount of rotation.
|
||||
* @param sx The scale factor along the x-axis. (1 = normal).
|
||||
* @param sy The scale factor along the y-axis. (1 = normal).
|
||||
* @param ox The offset along the x-axis.
|
||||
* @param oy The offset along the y-axis.
|
||||
* @param rx The upper-left corner of the source rectangle along the x-axis.
|
||||
* @param ry The upper-left corner of the source rectangle along the y-axis.
|
||||
* @param rw The width of the source rectangle.
|
||||
* @param rw The height of the source rectangle.
|
||||
**/
|
||||
int _wrap_draws(lua_State * L)
|
||||
{
|
||||
Image * image = luax_checktype<Image>(L, 1, "Image", LOVE_GRAPHICS_IMAGE_BITS);
|
||||
float x = (float)luaL_optnumber(L, 2, 0.0f);
|
||||
float y = (float)luaL_optnumber(L, 3, 0.0f);
|
||||
float angle = (float)luaL_optnumber(L, 4, 0.0f);
|
||||
float sx = (float)luaL_optnumber(L, 5, 1.0f);
|
||||
float sy = (float)luaL_optnumber(L, 6, sx);
|
||||
float ox = (float)luaL_optnumber(L, 7, 0);
|
||||
float oy = (float)luaL_optnumber(L, 8, 0);
|
||||
float rx = (float)luaL_optnumber(L, 9, 0);
|
||||
float ry = (float)luaL_optnumber(L, 10, 0);
|
||||
float rw = (float)luaL_optnumber(L, 11, image->getWidth());
|
||||
float rh = (float)luaL_optnumber(L, 12, image->getHeight());
|
||||
image->draws(x, y, angle, sx, sy, ox, oy, rx, ry, rw, rh);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_drawTest(lua_State * L)
|
||||
{
|
||||
Image * image = luax_checktype<Image>(L, 1, "Image", LOVE_GRAPHICS_IMAGE_BITS);
|
||||
float x = (float)luaL_optnumber(L, 2, 0.0f);
|
||||
float y = (float)luaL_optnumber(L, 3, 0.0f);
|
||||
float angle = (float)luaL_optnumber(L, 4, 0.0f);
|
||||
float sx = (float)luaL_optnumber(L, 5, 1.0f);
|
||||
float sy = (float)luaL_optnumber(L, 6, sx);
|
||||
float ox = (float)luaL_optnumber(L, 7, 0);
|
||||
float oy = (float)luaL_optnumber(L, 8, 0);
|
||||
instance->drawTest(image, x, y, angle, sx, sy, ox, oy);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_print(lua_State * L)
|
||||
{
|
||||
const char * str = luaL_checkstring(L, 1);
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
float angle = (float)luaL_optnumber(L, 4, 0.0f);
|
||||
float sx = (float)luaL_optnumber(L, 5, 1.0f);
|
||||
float sy = (float)luaL_optnumber(L, 6, sx);
|
||||
|
||||
switch(lua_gettop(L))
|
||||
{
|
||||
case 3:
|
||||
instance->print(str, x, y);
|
||||
break;
|
||||
case 4:
|
||||
instance->print(str, x, y, angle);
|
||||
break;
|
||||
case 5:
|
||||
instance->print(str, x, y, angle, sx);
|
||||
break;
|
||||
case 6:
|
||||
instance->print(str, x, y, angle, sx, sy);
|
||||
break;
|
||||
default:
|
||||
return luaL_error(L, "Incorrect number of parameters");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_printf(lua_State * L)
|
||||
{
|
||||
const char * str = luaL_checkstring(L, 1);
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
float wrap = (float)luaL_checknumber(L, 4);
|
||||
int align = luaL_optint(L, 5, 0);
|
||||
instance->printf(str, x, y, wrap, align);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_point(lua_State * L)
|
||||
{
|
||||
float x = (float)luaL_checknumber(L, 1);
|
||||
float y = (float)luaL_checknumber(L, 2);
|
||||
instance->point(x, y);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_line(lua_State * L)
|
||||
{
|
||||
float x1 = (float)luaL_checknumber(L, 1);
|
||||
float y1 = (float)luaL_checknumber(L, 2);
|
||||
float x2 = (float)luaL_checknumber(L, 3);
|
||||
float y2 = (float)luaL_checknumber(L, 4);
|
||||
instance->line(x1, y1, x2, y2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_triangle(lua_State * L)
|
||||
{
|
||||
int type = luaL_checkint(L, 1);
|
||||
float x1 = (float)luaL_checknumber(L, 2);
|
||||
float y1 = (float)luaL_checknumber(L, 3);
|
||||
float x2 = (float)luaL_checknumber(L, 4);
|
||||
float y2 = (float)luaL_checknumber(L, 5);
|
||||
float x3 = (float)luaL_checknumber(L, 6);
|
||||
float y3 = (float)luaL_checknumber(L, 7);
|
||||
instance->triangle(type, x1, y1, x2, y2, x3, y3);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_rectangle(lua_State * L)
|
||||
{
|
||||
int type = luaL_checkint(L, 1);
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
float w = (float)luaL_checknumber(L, 4);
|
||||
float h = (float)luaL_checknumber(L, 5);
|
||||
instance->rectangle(type, x, y, w, h);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_quad(lua_State * L)
|
||||
{
|
||||
int type = luaL_checkint(L, 1);
|
||||
float x1 = (float)luaL_checknumber(L, 2);
|
||||
float y1 = (float)luaL_checknumber(L, 3);
|
||||
float x2 = (float)luaL_checknumber(L, 4);
|
||||
float y2 = (float)luaL_checknumber(L, 5);
|
||||
float x3 = (float)luaL_checknumber(L, 6);
|
||||
float y3 = (float)luaL_checknumber(L, 7);
|
||||
float x4 = (float)luaL_checknumber(L, 6);
|
||||
float y4 = (float)luaL_checknumber(L, 7);
|
||||
instance->quad(type, x1, y1, x2, y2, x3, y3, x4, y4);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_circle(lua_State * L)
|
||||
{
|
||||
int type = luaL_checkint(L, 1);
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
float radius = (float)luaL_checknumber(L, 4);
|
||||
int points = luaL_optint(L, 5, 10);
|
||||
instance->circle(type, x, y, radius, points);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_polygon(lua_State * L)
|
||||
{
|
||||
return instance->polygon(L);
|
||||
}
|
||||
|
||||
int _wrap_push(lua_State * L)
|
||||
{
|
||||
instance->push();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_pop(lua_State * L)
|
||||
{
|
||||
instance->pop();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_rotate(lua_State * L)
|
||||
{
|
||||
float deg = (float)luaL_checknumber(L, 1);
|
||||
instance->rotate(deg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_scale(lua_State * L)
|
||||
{
|
||||
float sx = (float)luaL_optnumber(L, 1, 1.0f);
|
||||
float sy = (float)luaL_optnumber(L, 2, sx);
|
||||
instance->scale(sx, sy);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_translate(lua_State * L)
|
||||
{
|
||||
float x = (float)luaL_checknumber(L, 1);
|
||||
float y = (float)luaL_checknumber(L, 2);
|
||||
instance->translate(x, y);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// List of functions to wrap.
|
||||
static const luaL_Reg wrap_Graphics_functions[] = {
|
||||
{ "checkMode", _wrap_checkMode },
|
||||
{ "setMode", _wrap_setMode },
|
||||
{ "toggleFullscreen", _wrap_toggleFullscreen },
|
||||
{ "reset", _wrap_reset },
|
||||
{ "clear", _wrap_clear },
|
||||
{ "present", _wrap_present },
|
||||
|
||||
{ "newColor", _wrap_newColor },
|
||||
{ "newImage", _wrap_newImage },
|
||||
{ "newFrame", _wrap_newFrame },
|
||||
{ "newAnimation", _wrap_newAnimation },
|
||||
{ "newFont", _wrap_newFont },
|
||||
{ "newImageFont", _wrap_newImageFont },
|
||||
{ "newSpriteBatch", _wrap_newSpriteBatch },
|
||||
{ "newVertexBuffer", _wrap_newVertexBuffer },
|
||||
|
||||
{ "setColor", _wrap_setColor },
|
||||
{ "getColor", _wrap_getColor },
|
||||
{ "setBackgroundColor", _wrap_setBackgroundColor },
|
||||
{ "getBackgroundColor", _wrap_getBackgroundColor },
|
||||
|
||||
{ "setFont", _wrap_setFont },
|
||||
|
||||
{ "setBlendMode", _wrap_setBlendMode },
|
||||
{ "setColorMode", _wrap_setColorMode },
|
||||
{ "getBlendMode", _wrap_getBlendMode },
|
||||
{ "getColorMode", _wrap_getColorMode },
|
||||
{ "setLineWidth", _wrap_setLineWidth },
|
||||
{ "setLineStyle", _wrap_setLineStyle },
|
||||
{ "setLine", _wrap_setLine },
|
||||
{ "setLineStipple", _wrap_setLineStipple },
|
||||
{ "getLineWidth", _wrap_getLineWidth },
|
||||
{ "getLineStyle", _wrap_getLineStyle },
|
||||
{ "getLineStipple", _wrap_getLineStipple },
|
||||
{ "setPointSize", _wrap_setPointSize },
|
||||
{ "setPointStyle", _wrap_setPointStyle },
|
||||
{ "setPoint", _wrap_setPoint },
|
||||
{ "getPointSize", _wrap_getPointSize },
|
||||
{ "getPointStyle", _wrap_getPointStyle },
|
||||
{ "getMaxPointSize", _wrap_getMaxPointSize },
|
||||
|
||||
{ "draw", _wrap_draw },
|
||||
{ "draws", _wrap_draws },
|
||||
{ "drawTest", _wrap_drawTest },
|
||||
|
||||
{ "print", _wrap_print },
|
||||
{ "printf", _wrap_printf },
|
||||
|
||||
{ "setCaption", _wrap_setCaption },
|
||||
{ "getCaption", _wrap_getCaption },
|
||||
|
||||
{ "getWidth", _wrap_getWidth },
|
||||
{ "getHeight", _wrap_getHeight },
|
||||
|
||||
{ "isCreated", _wrap_isCreated },
|
||||
|
||||
{ "getModes", _wrap_getModes },
|
||||
|
||||
{ "setScissor", _wrap_setScissor },
|
||||
{ "getScissor", _wrap_getScissor },
|
||||
|
||||
{ "point", _wrap_point },
|
||||
{ "line", _wrap_line },
|
||||
{ "triangle", _wrap_triangle },
|
||||
{ "rectangle", _wrap_rectangle },
|
||||
{ "quad", _wrap_quad },
|
||||
{ "circle", _wrap_circle },
|
||||
|
||||
{ "polygon", _wrap_polygon },
|
||||
|
||||
{ "push", _wrap_push },
|
||||
{ "pop", _wrap_pop },
|
||||
{ "rotate", _wrap_rotate },
|
||||
{ "scale", _wrap_scale },
|
||||
{ "translate", _wrap_translate },
|
||||
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
// Types for this module.
|
||||
const lua_CFunction wrap_Graphics_types[] = {
|
||||
wrap_Color_open,
|
||||
wrap_Font_open,
|
||||
wrap_Image_open,
|
||||
wrap_Frame_open,
|
||||
wrap_Animation_open,
|
||||
wrap_ParticleSystem_open,
|
||||
wrap_SpriteBatch_open,
|
||||
wrap_VertexBuffer_open,
|
||||
0
|
||||
};
|
||||
|
||||
int wrap_Graphics_open(lua_State * L)
|
||||
{
|
||||
if(instance == 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
instance = new Graphics();
|
||||
}
|
||||
catch(Exception & e)
|
||||
{
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
}
|
||||
|
||||
luax_register_gc(L, "love.graphics", instance);
|
||||
|
||||
return luax_register_module(L, wrap_Graphics_functions, wrap_Graphics_types);
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
@@ -0,0 +1,107 @@
|
||||
/**
|
||||
* 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_GRAPHICS_OPENGL_WRAP_GRAPHICS_H
|
||||
#define LOVE_GRAPHICS_OPENGL_WRAP_GRAPHICS_H
|
||||
|
||||
// LOVE
|
||||
#include "wrap_Color.h"
|
||||
#include "wrap_Font.h"
|
||||
#include "wrap_Image.h"
|
||||
#include "wrap_Animation.h"
|
||||
#include "wrap_ParticleSystem.h"
|
||||
#include "wrap_SpriteBatch.h"
|
||||
#include "wrap_VertexBuffer.h"
|
||||
#include "wrap_Frame.h"
|
||||
#include "Graphics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
int _wrap_checkMode(lua_State * L);
|
||||
int _wrap_setMode(lua_State * L);
|
||||
int _wrap_toggleFullscreen(lua_State * L);
|
||||
int _wrap_reset(lua_State * L);
|
||||
int _wrap_clear(lua_State * L);
|
||||
int _wrap_present(lua_State * L);
|
||||
int _wrap_setCaption(lua_State * L);
|
||||
int _wrap_getCaption(lua_State * L);
|
||||
int _wrap_getWidth(lua_State * L);
|
||||
int _wrap_getHeight(lua_State * L);
|
||||
int _wrap_isCreated(lua_State * L);
|
||||
int _wrap_setScissor(lua_State * L);
|
||||
int _wrap_getScissor(lua_State * L);
|
||||
int _wrap_newColor(lua_State * L);
|
||||
int _wrap_newImage(lua_State * L);
|
||||
int _wrap_newFrame(lua_State * L);
|
||||
int _wrap_newAnimation(lua_State * L);
|
||||
int _wrap_newFont(lua_State * L);
|
||||
int _wrap_newImageFont(lua_State * L);
|
||||
int _wrap_newSpriteBatch(lua_State * L);
|
||||
int _wrap_newVertexBuffer(lua_State * L);
|
||||
int _wrap_setColor(lua_State * L);
|
||||
int _wrap_getColor(lua_State * L);
|
||||
int _wrap_setBackgroundColor(lua_State * L);
|
||||
int _wrap_getBackgroundColor(lua_State * L);
|
||||
int _wrap_setFont(lua_State * L);
|
||||
int _wrap_getFont(lua_State * L);
|
||||
int _wrap_setBlendMode(lua_State * L);
|
||||
int _wrap_setColorMode(lua_State * L);
|
||||
int _wrap_getBlendMode(lua_State * L);
|
||||
int _wrap_getColorMode(lua_State * L);
|
||||
int _wrap_setLineWidth(lua_State * L);
|
||||
int _wrap_setLineStyle(lua_State * L);
|
||||
int _wrap_setLine(lua_State * L);
|
||||
int _wrap_setLineStipple(lua_State * L);
|
||||
int _wrap_getLineWidth(lua_State * L);
|
||||
int _wrap_getLineStyle(lua_State * L);
|
||||
int _wrap_getLineStipple(lua_State * L);
|
||||
int _wrap_setPointSize(lua_State * L);
|
||||
int _wrap_setPointStyle(lua_State * L);
|
||||
int _wrap_setPoint(lua_State * L);
|
||||
int _wrap_getPointSize(lua_State * L);
|
||||
int _wrap_getPointStyle(lua_State * L);
|
||||
int _wrap_getMaxPointSize(lua_State * L);
|
||||
int _wrap_draw(lua_State * L);
|
||||
int _wrap_draws(lua_State * L);
|
||||
int _wrap_drawTest(lua_State * L);
|
||||
int _wrap_print(lua_State * L);
|
||||
int _wrap_printf(lua_State * L);
|
||||
int _wrap_point(lua_State * L);
|
||||
int _wrap_line(lua_State * L);
|
||||
int _wrap_triangle(lua_State * L);
|
||||
int _wrap_rectangle(lua_State * L);
|
||||
int _wrap_quad(lua_State * L);
|
||||
int _wrap_circle(lua_State * L);
|
||||
int _wrap_push(lua_State * L);
|
||||
int _wrap_pop(lua_State * L);
|
||||
int _wrap_rotate(lua_State * L);
|
||||
int _wrap_scale(lua_State * L);
|
||||
int _wrap_translate(lua_State * L);
|
||||
int wrap_Graphics_open(lua_State * L);
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_WRAP_GRAPHICS_H
|
||||
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
// LOVE
|
||||
#include "wrap_Image.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
Image * luax_checkimage(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<Image>(L, idx, "Image", LOVE_GRAPHICS_IMAGE_BITS);
|
||||
}
|
||||
|
||||
int _wrap_Image_getWidth(lua_State * L)
|
||||
{
|
||||
Image * t = luax_checkimage(L, 1);
|
||||
lua_pushnumber(L, t->getWidth());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_Image_getHeight(lua_State * L)
|
||||
{
|
||||
Image * t = luax_checkimage(L, 1);
|
||||
lua_pushnumber(L, t->getHeight());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_Image_setFilter(lua_State * L)
|
||||
{
|
||||
Image * t = luax_checkimage(L, 1);
|
||||
int min = luaL_checkint(L, 2);
|
||||
int mag = luaL_checkint(L, 3);
|
||||
t->setFilter(min, mag);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg wrap_Image_functions[] = {
|
||||
{ "getWidth", _wrap_Image_getWidth },
|
||||
{ "getHeight", _wrap_Image_getHeight },
|
||||
{ "setFilter", _wrap_Image_setFilter },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int wrap_Image_open(lua_State * L)
|
||||
{
|
||||
luax_register_type(L, "Image", wrap_Image_functions);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* 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_GRAPHICS_OPENGL_WRAP_IMAGE_H
|
||||
#define LOVE_GRAPHICS_OPENGL_WRAP_IMAGE_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "Image.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
Image * luax_checkimage(lua_State * L, int idx);
|
||||
int _wrap_Image_getWidth(lua_State * L);
|
||||
int _wrap_Image_getHeight(lua_State * L);
|
||||
int _wrap_Image_setFIlter(lua_State * L);
|
||||
int wrap_Image_open(lua_State * L);
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_WRAP_IMAGE_H
|
||||
@@ -0,0 +1,334 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#include "wrap_ParticleSystem.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
ParticleSystem * luax_checkparticlesystem(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<ParticleSystem>(L, idx, "ParticleSystem", LOVE_GRAPHICS_PARTICLE_SYSTEM_BITS);
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_setSprite(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
Image * i = luax_checkimage(L, 2);
|
||||
t->setSprite(i);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_setBufferSize(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
int arg1 = luaL_checkint(L, 2);
|
||||
t->setBufferSize((unsigned int)arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_setEmissionRate(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
int arg1 = luaL_checkint(L, 2);
|
||||
t->setEmissionRate((unsigned int)arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_setLifetime(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setLifetime(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_setParticleLife(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_checknumber(L, 3);
|
||||
t->setParticleLife(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_setPosition(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_checknumber(L, 3);
|
||||
t->setPosition(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_setDirection(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setDirection(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_setSpread(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setSpread(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_setRelativeDirection(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
bool arg1 = (bool)luax_toboolean(L, 2);
|
||||
t->setRelativeDirection(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_setSpeed(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_optnumber(L, 3, arg1);
|
||||
t->setSpeed(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_setGravity(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_optnumber(L, 3, arg1);
|
||||
t->setGravity(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_setRadialAcceleration(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_optnumber(L, 3, arg1);
|
||||
t->setRadialAcceleration(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_setTangentialAcceleration(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_optnumber(L, 3, arg1);
|
||||
t->setTangentialAcceleration(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_setSize(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_optnumber(L, 3, arg1);
|
||||
float arg3 = (float)luaL_optnumber(L, 3, 0);
|
||||
t->setSize(arg1, arg2, arg3);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_setSizeVariation(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setSizeVariation(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_setRotation(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_optnumber(L, 3, arg1);
|
||||
t->setRotation(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_setSpin(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_optnumber(L, 3, arg1);
|
||||
float arg3 = (float)luaL_optnumber(L, 3, 0);
|
||||
t->setSpin(arg1, arg2, arg3);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_setSpinVariation(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setSpinVariation(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_setColor(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
Color * start = luax_checkcolor(L, 2);
|
||||
Color * end = (lua_gettop(L) == 3) ? luax_checkcolor(L, 3) : start;
|
||||
t->setColor(start, end);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_getX(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
lua_pushnumber(L, t->getX());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_getY(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
lua_pushnumber(L, t->getY());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_getDirection(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
lua_pushnumber(L, t->getDirection());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_getSpread(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
lua_pushnumber(L, t->getSpread());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_count(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
lua_pushnumber(L, t->count());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_start(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
t->start();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_stop(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
t->stop();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_pause(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
t->pause();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_reset(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
t->reset();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_isActive(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
luax_pushboolean(L, t->isActive());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_isEmpty(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
luax_pushboolean(L, t->isEmpty());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_isFull(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
luax_pushboolean(L, t->isFull());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_ParticleSystem_update(lua_State * L)
|
||||
{
|
||||
ParticleSystem * t = luax_checkparticlesystem(L, 1);
|
||||
float dt = (float)luaL_checknumber(L, 2);
|
||||
t->update(dt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const luaL_Reg wrap_ParticleSystem_functions[] = {
|
||||
{ "setSprite", _wrap_ParticleSystem_setSprite },
|
||||
{ "setBufferSize", _wrap_ParticleSystem_setBufferSize },
|
||||
{ "setEmissionRate", _wrap_ParticleSystem_setEmissionRate },
|
||||
{ "setLifeTime", _wrap_ParticleSystem_setLifetime },
|
||||
{ "setParticleLife", _wrap_ParticleSystem_setParticleLife },
|
||||
{ "setPosition", _wrap_ParticleSystem_setPosition },
|
||||
{ "setDirection", _wrap_ParticleSystem_setDirection },
|
||||
{ "setSpread", _wrap_ParticleSystem_setSpread },
|
||||
{ "setRelativeDirection", _wrap_ParticleSystem_setRelativeDirection },
|
||||
{ "setSpeed", _wrap_ParticleSystem_setSpeed },
|
||||
{ "setGravity", _wrap_ParticleSystem_setGravity },
|
||||
{ "setRadialAcceleration", _wrap_ParticleSystem_setRadialAcceleration },
|
||||
{ "setTangentialAcceleration", _wrap_ParticleSystem_setTangentialAcceleration },
|
||||
{ "setSize", _wrap_ParticleSystem_setSize },
|
||||
{ "setSizeVariation", _wrap_ParticleSystem_setSizeVariation },
|
||||
{ "setRotation", _wrap_ParticleSystem_setRotation },
|
||||
{ "setSpin", _wrap_ParticleSystem_setSpin },
|
||||
{ "setSpinVariation", _wrap_ParticleSystem_setSpinVariation },
|
||||
{ "setColor", _wrap_ParticleSystem_setColor },
|
||||
{ "getX", _wrap_ParticleSystem_getX },
|
||||
{ "getY", _wrap_ParticleSystem_getY },
|
||||
{ "getDirection", _wrap_ParticleSystem_getDirection },
|
||||
{ "getSpread", _wrap_ParticleSystem_getSpread },
|
||||
{ "count", _wrap_ParticleSystem_count },
|
||||
{ "start", _wrap_ParticleSystem_start },
|
||||
{ "stop", _wrap_ParticleSystem_stop },
|
||||
{ "pause", _wrap_ParticleSystem_pause },
|
||||
{ "reset", _wrap_ParticleSystem_reset },
|
||||
{ "isActive", _wrap_ParticleSystem_isActive },
|
||||
{ "isEmpty", _wrap_ParticleSystem_isEmpty },
|
||||
{ "isFull", _wrap_ParticleSystem_isFull },
|
||||
{ "update", _wrap_ParticleSystem_update },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int wrap_ParticleSystem_open(lua_State * L)
|
||||
{
|
||||
luax_register_type(L, "ParticleSystem", wrap_ParticleSystem_functions);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* 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_GRAPHICS_OPENGL_WRAP_PARTICLE_SYSTEM_H
|
||||
#define LOVE_GRAPHICS_OPENGL_WRAP_PARTICLE_SYSTEM_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "wrap_Image.h"
|
||||
#include "wrap_Color.h"
|
||||
#include "ParticleSystem.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
ParticleSystem * luax_checkparticlesystem(lua_State * L, int idx);
|
||||
int _wrap_ParticleSystem_setSprite(lua_State * L);
|
||||
int _wrap_ParticleSystem_setBufferSize(lua_State * L);
|
||||
int _wrap_ParticleSystem_setEmissionRate(lua_State * L);
|
||||
int _wrap_ParticleSystem_setLifetime(lua_State * L);
|
||||
int _wrap_ParticleSystem_setParticleLife(lua_State * L);
|
||||
int _wrap_ParticleSystem_setPosition(lua_State * L);
|
||||
int _wrap_ParticleSystem_setDirection(lua_State * L);
|
||||
int _wrap_ParticleSystem_setSpread(lua_State * L);
|
||||
int _wrap_ParticleSystem_setRelativeDirection(lua_State * L);
|
||||
int _wrap_ParticleSystem_setSpeed(lua_State * L);
|
||||
int _wrap_ParticleSystem_setGravity(lua_State * L);
|
||||
int _wrap_ParticleSystem_setRadialAcceleration(lua_State * L);
|
||||
int _wrap_ParticleSystem_setTangentialAcceleration(lua_State * L);
|
||||
int _wrap_ParticleSystem_setSize(lua_State * L);
|
||||
int _wrap_ParticleSystem_setSizeVariation(lua_State * L);
|
||||
int _wrap_ParticleSystem_setRotation(lua_State * L);
|
||||
int _wrap_ParticleSystem_setSpin(lua_State * L);
|
||||
int _wrap_ParticleSystem_setSpinVariation(lua_State * L);
|
||||
int _wrap_ParticleSystem_setColor(lua_State * L);
|
||||
int _wrap_ParticleSystem_getX(lua_State * L);
|
||||
int _wrap_ParticleSystem_getY(lua_State * L);
|
||||
int _wrap_ParticleSystem_getDirection(lua_State * L);
|
||||
int _wrap_ParticleSystem_getSpread(lua_State * L);
|
||||
int _wrap_ParticleSystem_count(lua_State * L);
|
||||
int _wrap_ParticleSystem_start(lua_State * L);
|
||||
int _wrap_ParticleSystem_stop(lua_State * L);
|
||||
int _wrap_ParticleSystem_pause(lua_State * L);
|
||||
int _wrap_ParticleSystem_reset(lua_State * L);
|
||||
int _wrap_ParticleSystem_isActive(lua_State * L);
|
||||
int _wrap_ParticleSystem_isEmpty(lua_State * L);
|
||||
int _wrap_ParticleSystem_isFull(lua_State * L);
|
||||
int _wrap_ParticleSystem_update(lua_State * L);
|
||||
int wrap_ParticleSystem_open(lua_State * L);
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_WRAP_PARTICLE_SYSTEM_H
|
||||
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#include "wrap_SpriteBatch.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
SpriteBatch * luax_checkspritebatch(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<SpriteBatch>(L, idx, "SpriteBatch", LOVE_GRAPHICS_SPRITE_BATCH_BITS);
|
||||
}
|
||||
|
||||
int _wrap_SpriteBatch_add(lua_State * L)
|
||||
{
|
||||
SpriteBatch * t = luax_checkspritebatch(L, 1);
|
||||
float x = (float)luaL_optnumber(L, 2, 0.0f);
|
||||
float y = (float)luaL_optnumber(L, 3, 0.0f);
|
||||
float angle = (float)luaL_optnumber(L, 4, 0.0f);
|
||||
float sx = (float)luaL_optnumber(L, 5, 1.0f);
|
||||
float sy = (float)luaL_optnumber(L, 6, sx);
|
||||
float ox = (float)luaL_optnumber(L, 7, 0);
|
||||
float oy = (float)luaL_optnumber(L, 8, 0);
|
||||
t->add(x, y, angle, sx, sy, ox, oy);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_SpriteBatch_clear(lua_State * L)
|
||||
{
|
||||
SpriteBatch * t = luax_checkspritebatch(L, 1);
|
||||
t->clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const luaL_Reg wrap_SpriteBatch_functions[] = {
|
||||
{ "add", _wrap_SpriteBatch_add },
|
||||
{ "clear", _wrap_SpriteBatch_clear },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int wrap_SpriteBatch_open(lua_State * L)
|
||||
{
|
||||
luax_register_type(L, "SpriteBatch", wrap_SpriteBatch_functions);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* 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_GRAPHICS_OPENGL_WRAP_SPRITE_BATCH_H
|
||||
#define LOVE_GRAPHICS_OPENGL_WRAP_SPRITE_BATCH_H
|
||||
|
||||
#include <common/runtime.h>
|
||||
#include "SpriteBatch.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
SpriteBatch * luax_checkspritebatch(lua_State * L, int idx);
|
||||
int _wrap_SpriteBatch_add(lua_State * L);
|
||||
int _wrap_SpriteBatch_clear(lua_State * L);
|
||||
int wrap_SpriteBatch_open(lua_State * L);
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_GRAPHICS_OPENGL_WRAP_SPRITE_BATCH_H
|
||||
@@ -0,0 +1,87 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#include "wrap_VertexBuffer.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
VertexBuffer * luax_checkvertexbuffer(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<VertexBuffer>(L, idx, "VertexBuffer", LOVE_GRAPHICS_VERTEX_BUFFER_BITS);
|
||||
}
|
||||
|
||||
int _wrap_VertexBuffer_setType(lua_State * L)
|
||||
{
|
||||
VertexBuffer * t = luax_checkvertexbuffer(L, 1);
|
||||
int type = luaL_checkint(L, 2);
|
||||
t->setType(type);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_VertexBuffer_getType(lua_State * L)
|
||||
{
|
||||
VertexBuffer * t = luax_checkvertexbuffer(L, 1);
|
||||
lua_pushnumber(L, t->getType());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _wrap_VertexBuffer_add(lua_State * L)
|
||||
{
|
||||
VertexBuffer * vb = luax_checkvertexbuffer(L, 1);
|
||||
float x = (float)luaL_optnumber(L, 2, 0.0f);
|
||||
float y = (float)luaL_optnumber(L, 3, 0.0f);
|
||||
float s = (float)luaL_optnumber(L, 4, 0.0f);
|
||||
float t = (float)luaL_optnumber(L, 5, 0.0f);
|
||||
unsigned char r = (unsigned char)luaL_optnumber(L, 6, 255);
|
||||
unsigned char g = (unsigned char)luaL_optnumber(L, 7, 255);
|
||||
unsigned char b = (unsigned char)luaL_optnumber(L, 8, 255);
|
||||
unsigned char a = (unsigned char)luaL_optnumber(L, 9, 255);
|
||||
vb->add(x, y, s, t, r, g, b, a);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _wrap_VertexBuffer_clear(lua_State * L)
|
||||
{
|
||||
VertexBuffer * t = luax_checkvertexbuffer(L, 1);
|
||||
t->clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
const luaL_Reg wrap_VertexBuffer_functions[] = {
|
||||
{ "setType", _wrap_VertexBuffer_setType },
|
||||
{ "getType", _wrap_VertexBuffer_getType },
|
||||
{ "add", _wrap_VertexBuffer_add },
|
||||
{ "clear", _wrap_VertexBuffer_clear },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int wrap_VertexBuffer_open(lua_State * L)
|
||||
{
|
||||
luax_register_type(L, "VertexBuffer", wrap_VertexBuffer_functions);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user