Automated formatting fix

This commit is contained in:
Bart van Strien
2011-11-16 11:32:41 +01:00
parent fafe472595
commit 0aae9684b3
262 changed files with 16705 additions and 16503 deletions
+199 -199
View File
@@ -1,199 +1,199 @@
/**
* Copyright (c) 2006-2011 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"
namespace love
{
namespace sound
{
class Decoder;
class SoundData;
}
namespace audio
{
/**
* The Audio module is responsible for playing back raw sound samples.
**/
class Audio : public Module
{
public:
/**
* Destructor.
**/
virtual ~Audio(){};
virtual Source * newSource(love::sound::Decoder * decoder) = 0;
virtual Source * newSource(love::sound::SoundData * soundData) = 0;
/**
* Gets the current number of simultaneous playing sources.
* @return The current number of simultaneous playing sources.
**/
virtual int getNumSources() const = 0;
/**
* Gets the maximum supported number of simultaneous playing sources.
* @return The maximum supported number of simultaneous playing sources.
**/
virtual int getMaxSources() const = 0;
/**
* Play the specified Source.
* @param source The Source to play.
**/
virtual void play(Source * source) = 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;
/**
* Gets the position of the listener.
* @param v A float array of size 3 containing (x,y,z) in that order.
**/
virtual void getPosition(float * v) const = 0;
/**
* Sets the position of the listener.
* @param v A float array of size 3 containing [x,y,z] in that order.
**/
virtual void setPosition(float * v) = 0;
/**
* Gets the orientation of the listener.
* @param v A float array of size 6 containing [x,y,z] for the forward
* vector, followed by [x,y,z] for the up vector.
**/
virtual void getOrientation(float * v) const = 0;
/**
* Sets the orientation of the listener.
* @param v A float array of size 6 containing [x,y,z] for the forward
* vector, followed by [x,y,z] for the up vector.
**/
virtual void setOrientation(float * v) = 0;
/**
* Gets the velocity of the listener.
* @param v A float array of size 3 containing [x,y,z] in that order.
**/
virtual void getVelocity(float * v) const = 0;
/**
* Sets the velocity of the listener.
* @param v A float array of size 3 containing [x,y,z] in that order.
**/
virtual void setVelocity(float * v) = 0;
/**
* Begins recording audio input from the microphone.
**/
virtual void record() = 0;
/**
* Gets a section of recorded audio.
* Per OpenAL, the measurement begins from the start of the
* audio data in memory, which is after the last time this function
* was called. If this function has not been called yet this recording
* session, it just grabs from the beginning.
* @return All the recorded SoundData thus far.
**/
virtual love::sound::SoundData * getRecordedData() = 0;
/**
* Stops recording and, if passed true, returns all the recorded audio
* not already gotten by getRecordedData.
* @param returnData Whether to return recorded audio.
* @return if returnData, all the recorded audio yet to be gotten,
* otherwise NULL.
**/
virtual love::sound::SoundData * stopRecording(bool returnData) = 0;
/**
* Checks whether LOVE is able to record audio input.
* @return hasMic Whether LOVE has a microphone enabled.
**/
virtual bool canRecord() = 0;
}; // Audio
} // audio
} // love
#endif // LOVE_AUDIO_AUDIO_H
/**
* Copyright (c) 2006-2011 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"
namespace love
{
namespace sound
{
class Decoder;
class SoundData;
}
namespace audio
{
/**
* The Audio module is responsible for playing back raw sound samples.
**/
class Audio : public Module
{
public:
/**
* Destructor.
**/
virtual ~Audio(){};
virtual Source * newSource(love::sound::Decoder * decoder) = 0;
virtual Source * newSource(love::sound::SoundData * soundData) = 0;
/**
* Gets the current number of simultaneous playing sources.
* @return The current number of simultaneous playing sources.
**/
virtual int getNumSources() const = 0;
/**
* Gets the maximum supported number of simultaneous playing sources.
* @return The maximum supported number of simultaneous playing sources.
**/
virtual int getMaxSources() const = 0;
/**
* Play the specified Source.
* @param source The Source to play.
**/
virtual void play(Source * source) = 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;
/**
* Gets the position of the listener.
* @param v A float array of size 3 containing (x,y,z) in that order.
**/
virtual void getPosition(float * v) const = 0;
/**
* Sets the position of the listener.
* @param v A float array of size 3 containing [x,y,z] in that order.
**/
virtual void setPosition(float * v) = 0;
/**
* Gets the orientation of the listener.
* @param v A float array of size 6 containing [x,y,z] for the forward
* vector, followed by [x,y,z] for the up vector.
**/
virtual void getOrientation(float * v) const = 0;
/**
* Sets the orientation of the listener.
* @param v A float array of size 6 containing [x,y,z] for the forward
* vector, followed by [x,y,z] for the up vector.
**/
virtual void setOrientation(float * v) = 0;
/**
* Gets the velocity of the listener.
* @param v A float array of size 3 containing [x,y,z] in that order.
**/
virtual void getVelocity(float * v) const = 0;
/**
* Sets the velocity of the listener.
* @param v A float array of size 3 containing [x,y,z] in that order.
**/
virtual void setVelocity(float * v) = 0;
/**
* Begins recording audio input from the microphone.
**/
virtual void record() = 0;
/**
* Gets a section of recorded audio.
* Per OpenAL, the measurement begins from the start of the
* audio data in memory, which is after the last time this function
* was called. If this function has not been called yet this recording
* session, it just grabs from the beginning.
* @return All the recorded SoundData thus far.
**/
virtual love::sound::SoundData * getRecordedData() = 0;
/**
* Stops recording and, if passed true, returns all the recorded audio
* not already gotten by getRecordedData.
* @param returnData Whether to return recorded audio.
* @return if returnData, all the recorded audio yet to be gotten,
* otherwise NULL.
**/
virtual love::sound::SoundData * stopRecording(bool returnData) = 0;
/**
* Checks whether LOVE is able to record audio input.
* @return hasMic Whether LOVE has a microphone enabled.
**/
virtual bool canRecord() = 0;
}; // Audio
} // audio
} // love
#endif // LOVE_AUDIO_AUDIO_H
+73 -73
View File
@@ -1,73 +1,73 @@
/**
* Copyright (c) 2006-2011 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(Type type)
: type(type)
{
}
Source::~Source()
{
}
bool Source::getConstant(const char * in, Type & out)
{
return types.find(in, out);
}
bool Source::getConstant(Type in, const char *& out)
{
return types.find(in, out);
}
bool Source::getConstant(const char * in, Unit & out)
{
return units.find(in, out);
}
bool Source::getConstant(Unit in, const char *& out)
{
return units.find(in, out);
}
StringMap<Source::Type, Source::TYPE_MAX_ENUM>::Entry Source::typeEntries[] =
{
{"static", Source::TYPE_STATIC},
{"stream", Source::TYPE_STREAM},
};
StringMap<Source::Type, Source::TYPE_MAX_ENUM> Source::types(Source::typeEntries, sizeof(Source::typeEntries));
StringMap<Source::Unit, Source::UNIT_MAX_ENUM>::Entry Source::unitEntries[] =
{
{"seconds", Source::UNIT_SECONDS},
{"samples", Source::UNIT_SAMPLES},
};
StringMap<Source::Unit, Source::UNIT_MAX_ENUM> Source::units(Source::unitEntries, sizeof(Source::unitEntries));
} // audio
} // love
/**
* Copyright (c) 2006-2011 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(Type type)
: type(type)
{
}
Source::~Source()
{
}
bool Source::getConstant(const char * in, Type & out)
{
return types.find(in, out);
}
bool Source::getConstant(Type in, const char *& out)
{
return types.find(in, out);
}
bool Source::getConstant(const char * in, Unit & out)
{
return units.find(in, out);
}
bool Source::getConstant(Unit in, const char *& out)
{
return units.find(in, out);
}
StringMap<Source::Type, Source::TYPE_MAX_ENUM>::Entry Source::typeEntries[] =
{
{"static", Source::TYPE_STATIC},
{"stream", Source::TYPE_STREAM},
};
StringMap<Source::Type, Source::TYPE_MAX_ENUM> Source::types(Source::typeEntries, sizeof(Source::typeEntries));
StringMap<Source::Unit, Source::UNIT_MAX_ENUM>::Entry Source::unitEntries[] =
{
{"seconds", Source::UNIT_SECONDS},
{"samples", Source::UNIT_SAMPLES},
};
StringMap<Source::Unit, Source::UNIT_MAX_ENUM> Source::units(Source::unitEntries, sizeof(Source::unitEntries));
} // audio
} // love
+107 -107
View File
@@ -1,107 +1,107 @@
/**
* Copyright (c) 2006-2011 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 <common/StringMap.h>
namespace love
{
namespace audio
{
class Source : public Object
{
public:
enum Type
{
TYPE_STATIC = 1,
TYPE_STREAM,
TYPE_MAX_ENUM
}; // Type
enum Unit
{
UNIT_SECONDS = 1,
UNIT_SAMPLES,
UNIT_MAX_ENUM
};
protected:
Type type;
public:
Source(Type type);
virtual ~Source();
virtual Source * copy() = 0;
virtual void play() = 0;
virtual void stop() = 0;
virtual void pause() = 0;
virtual void resume() = 0;
virtual void rewind() = 0;
virtual bool isStopped() const = 0;
virtual bool isPaused() const = 0;
virtual bool isFinished() const = 0;
virtual bool update() = 0;
virtual void setPitch(float pitch) = 0;
virtual float getPitch() const = 0;
virtual void setVolume(float volume) = 0;
virtual float getVolume() const = 0;
virtual void seek(float offset, Unit unit) = 0;
virtual float tell(Unit unit) = 0;
// all float * v must be of size 3
virtual void setPosition(float * v) = 0;
virtual void getPosition(float * v) const = 0;
virtual void setVelocity(float * v) = 0;
virtual void getVelocity(float * v) const = 0;
virtual void setDirection(float * v) = 0;
virtual void getDirection(float * v) const = 0;
virtual void setLooping(bool looping) = 0;
virtual bool isLooping() const = 0;
virtual bool isStatic() const = 0;
static bool getConstant(const char * in, Type & out);
static bool getConstant(Type in, const char *& out);
static bool getConstant(const char * in, Unit & out);
static bool getConstant(Unit in, const char *& out);
private:
static StringMap<Type, TYPE_MAX_ENUM>::Entry typeEntries[];
static StringMap<Type, TYPE_MAX_ENUM> types;
static StringMap<Unit, UNIT_MAX_ENUM>::Entry unitEntries[];
static StringMap<Unit, UNIT_MAX_ENUM> units;
}; // Source
} // audio
} // love
#endif // LOVE_AUDIO_SOURCE_H
/**
* Copyright (c) 2006-2011 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 <common/StringMap.h>
namespace love
{
namespace audio
{
class Source : public Object
{
public:
enum Type
{
TYPE_STATIC = 1,
TYPE_STREAM,
TYPE_MAX_ENUM
}; // Type
enum Unit
{
UNIT_SECONDS = 1,
UNIT_SAMPLES,
UNIT_MAX_ENUM
};
protected:
Type type;
public:
Source(Type type);
virtual ~Source();
virtual Source * copy() = 0;
virtual void play() = 0;
virtual void stop() = 0;
virtual void pause() = 0;
virtual void resume() = 0;
virtual void rewind() = 0;
virtual bool isStopped() const = 0;
virtual bool isPaused() const = 0;
virtual bool isFinished() const = 0;
virtual bool update() = 0;
virtual void setPitch(float pitch) = 0;
virtual float getPitch() const = 0;
virtual void setVolume(float volume) = 0;
virtual float getVolume() const = 0;
virtual void seek(float offset, Unit unit) = 0;
virtual float tell(Unit unit) = 0;
// all float * v must be of size 3
virtual void setPosition(float * v) = 0;
virtual void getPosition(float * v) const = 0;
virtual void setVelocity(float * v) = 0;
virtual void getVelocity(float * v) const = 0;
virtual void setDirection(float * v) = 0;
virtual void getDirection(float * v) const = 0;
virtual void setLooping(bool looping) = 0;
virtual bool isLooping() const = 0;
virtual bool isStatic() const = 0;
static bool getConstant(const char * in, Type & out);
static bool getConstant(Type in, const char *& out);
static bool getConstant(const char * in, Unit & out);
static bool getConstant(Unit in, const char *& out);
private:
static StringMap<Type, TYPE_MAX_ENUM>::Entry typeEntries[];
static StringMap<Type, TYPE_MAX_ENUM> types;
static StringMap<Unit, UNIT_MAX_ENUM>::Entry unitEntries[];
static StringMap<Unit, UNIT_MAX_ENUM> units;
}; // Source
} // audio
} // love
#endif // LOVE_AUDIO_SOURCE_H
+7 -7
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -132,21 +132,21 @@ namespace null
void Audio::setVelocity(float *)
{
}
void Audio::record()
{
}
love::sound::SoundData * Audio::getRecordedData()
{
return NULL;
}
love::sound::SoundData * Audio::stopRecording(bool)
{
return NULL;
}
bool Audio::canRecord()
{
return false;
+4 -4
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -68,7 +68,7 @@ namespace null
void setOrientation(float * v);
void getVelocity(float * v) const;
void setVelocity(float * v);
void record();
love::sound::SoundData * getRecordedData();
love::sound::SoundData * stopRecording(bool returnData);
+2 -2
View File
@@ -101,11 +101,11 @@ namespace null
{
return volume;
}
void Source::seek(float, Source::Unit)
{
}
float Source::tell(Source::Unit)
{
return 0.0f;
+78 -78
View File
@@ -1,78 +1,78 @@
/**
* Copyright (c) 2006-2011 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;
bool looping;
public:
Source();
virtual ~Source();
virtual love::audio::Source * copy();
virtual void play();
virtual void stop();
virtual void pause();
virtual void resume();
virtual void rewind();
virtual bool isStopped() const;
virtual bool isPaused() const;
virtual bool isFinished() const;
virtual bool update();
virtual void setPitch(float pitch);
virtual float getPitch() const;
virtual void setVolume(float volume);
virtual float getVolume() const;
virtual void seek(float offset, Unit unit);
virtual float tell(Unit unit);
virtual void setPosition(float * v);
virtual void getPosition(float * v) const;
virtual void setVelocity(float * v);
virtual void getVelocity(float * v) const;
virtual void setDirection(float * v);
virtual void getDirection(float * v) const;
void setLooping(bool looping);
bool isLooping() const;
bool isStatic() const;
}; // Source
} // null
} // audio
} // love
#endif // LOVE_AUDIO_NULL_SOURCE_H
/**
* Copyright (c) 2006-2011 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;
bool looping;
public:
Source();
virtual ~Source();
virtual love::audio::Source * copy();
virtual void play();
virtual void stop();
virtual void pause();
virtual void resume();
virtual void rewind();
virtual bool isStopped() const;
virtual bool isPaused() const;
virtual bool isFinished() const;
virtual bool update();
virtual void setPitch(float pitch);
virtual float getPitch() const;
virtual void setVolume(float volume);
virtual float getVolume() const;
virtual void seek(float offset, Unit unit);
virtual float tell(Unit unit);
virtual void setPosition(float * v);
virtual void getPosition(float * v) const;
virtual void setVelocity(float * v);
virtual void getVelocity(float * v) const;
virtual void setDirection(float * v);
virtual void getDirection(float * v) const;
void setLooping(bool looping);
bool isLooping() const;
bool isStatic() const;
}; // Source
} // null
} // audio
} // love
#endif // LOVE_AUDIO_NULL_SOURCE_H
+33 -25
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -30,16 +30,18 @@ namespace audio
namespace openal
{
Audio::PoolThread::PoolThread(Pool* pool)
: pool(pool), finish(false) {
: pool(pool), finish(false)
{
}
void Audio::PoolThread::main()
{
while(true) {
while (true)
{
{
thread::Lock lock(mutex);
if (finish) {
if (finish)
{
return;
}
}
@@ -61,32 +63,35 @@ namespace openal
// Passing zero for default device.
device = alcOpenDevice(0);
if(device == 0)
if (device == 0)
throw love::Exception("Could not open device.");
context = alcCreateContext(device, 0);
if(context == 0)
if (context == 0)
throw love::Exception("Could not create context.");
alcMakeContextCurrent(context);
if(alcGetError(device) != ALC_NO_ERROR)
if (alcGetError(device) != ALC_NO_ERROR)
throw love::Exception("Could not make context current.");
/*std::string captureName(alcGetString(NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER));
const ALCchar * devices = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
while (*devices) {
while (*devices)
{
std::string device(devices);
devices += device.size() + 1;
if (device.find("Mic") != std::string::npos || device.find("mic") != std::string::npos) {
if (device.find("Mic") != std::string::npos || device.find("mic") != std::string::npos)
{
captureName = device;
}
}
capture = alcCaptureOpenDevice(captureName.c_str(), 8000, AL_FORMAT_MONO16, 262144); // about 32 seconds
if (!capture) {
if (!capture)
{
// We're not going to prevent LOVE from running without a microphone, but we should warn, at least
std::cerr << "Warning, couldn't open capture device! No audio input!" << std::endl;
}*/
@@ -105,7 +110,7 @@ namespace openal
delete poolThread;
delete pool;
alcMakeContextCurrent(0);
alcDestroyContext(context);
//if (capture) alcCaptureCloseDevice(capture);
@@ -167,7 +172,7 @@ namespace openal
{
source->resume();
}
void Audio::resume()
{
pool->resume();
@@ -224,16 +229,17 @@ namespace openal
{
alListenerfv(AL_VELOCITY, v);
}
void Audio::record()
{
if (!canRecord()) return;
alcCaptureStart(capture);
}
love::sound::SoundData * Audio::getRecordedData()
{
if (!canRecord()) return NULL;
if (!canRecord())
return NULL;
int samplerate = 8000;
ALCint samples;
alcGetIntegerv(capture, ALC_CAPTURE_SAMPLES, 4, &samples);
@@ -243,18 +249,20 @@ namespace openal
free(data);
return sd;
}
love::sound::SoundData * Audio::stopRecording(bool returnData)
{
if (!canRecord()) return NULL;
if (!canRecord())
return NULL;
love::sound::SoundData * sd = NULL;
if (returnData) {
if (returnData)
{
sd = getRecordedData();
}
alcCaptureStop(capture);
return sd;
}
bool Audio::canRecord()
{
return (capture != NULL);
+5 -5
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -57,7 +57,7 @@ namespace openal
// The OpenAL device.
ALCdevice * device;
// The OpenAL capture device (microphone).
ALCdevice * capture;
@@ -121,7 +121,7 @@ namespace openal
void setOrientation(float * v);
void getVelocity(float * v) const;
void setVelocity(float * v);
void record();
love::sound::SoundData * getRecordedData();
love::sound::SoundData * stopRecording(bool returnData);
+18 -18
View File
@@ -36,11 +36,11 @@ namespace openal
// Create the mutex.
mutex = new thread::Mutex();
if(alGetError() != AL_NO_ERROR)
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++)
for (int i = 0; i < NUM_SOURCES; i++)
available.push(sources[i]);
}
@@ -69,9 +69,9 @@ namespace openal
bool p = false;
{
thread::Lock lock(mutex);
for(std::map<Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
for (std::map<Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
{
if(i->first == s)
if (i->first == s)
p = true;
}
}
@@ -84,9 +84,9 @@ namespace openal
std::map<Source *, ALuint>::iterator i = playing.begin();
while(i != playing.end())
while (i != playing.end())
{
if(!i->first->update())
if (!i->first->update())
{
i->first->stopAtomic();
i->first->rewindAtomic();
@@ -118,10 +118,10 @@ namespace openal
bool alreadyPlaying = findSource(source, out);
if(!alreadyPlaying)
if (!alreadyPlaying)
{
// Try to play.
if(!available.empty())
if (!available.empty())
{
// Get the first available source.
out = available.front();
@@ -154,7 +154,7 @@ namespace openal
void Pool::stop()
{
thread::Lock lock(mutex);
for(std::map<Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
for (std::map<Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
{
i->first->stopAtomic();
i->first->release();
@@ -173,7 +173,7 @@ namespace openal
void Pool::pause()
{
thread::Lock lock(mutex);
for(std::map<Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
for (std::map<Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
i->first->pauseAtomic();
}
@@ -181,14 +181,14 @@ namespace openal
{
thread::Lock lock(mutex);
ALuint out;
if(findSource(source, out))
if (findSource(source, out))
source->pauseAtomic();
}
void Pool::resume()
{
thread::Lock lock(mutex);
for(std::map<Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
for (std::map<Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
i->first->resumeAtomic();
}
@@ -196,14 +196,14 @@ namespace openal
{
thread::Lock lock(mutex);
ALuint out;
if(findSource(source, out))
if (findSource(source, out))
source->resumeAtomic();
}
void Pool::rewind()
{
thread::Lock lock(mutex);
for(std::map<Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
for (std::map<Source *, ALuint>::iterator i = playing.begin(); i != playing.end(); i++)
i->first->rewindAtomic();
}
@@ -224,7 +224,7 @@ namespace openal
{
ALuint s = findi(source);
if(s != 0)
if (s != 0)
{
available.push(s);
playing.erase(source);
@@ -247,7 +247,7 @@ namespace openal
{
std::map<Source *, ALuint>::const_iterator i = playing.find((Source *)source);
if(i != playing.end())
if (i != playing.end())
return i->second;
return 0;
@@ -259,7 +259,7 @@ namespace openal
bool found = i != playing.end();
if(found)
if (found)
out = i->second;
return found;
@@ -269,7 +269,7 @@ namespace openal
{
std::map<Source *, ALuint>::iterator i = playing.find((Source *)source);
if(i != playing.end())
if (i != playing.end())
{
source->stopAtomic();
available.push(i->second);
+3 -3
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
+47 -40
View File
@@ -87,7 +87,7 @@ namespace openal
valid = pool->play(this, source);
if(valid)
if (valid)
reset(source);
}
@@ -117,7 +117,7 @@ namespace openal
bool Source::isStopped() const
{
if(valid)
if (valid)
{
ALenum state;
alGetSourcei(source, AL_SOURCE_STATE, &state);
@@ -129,7 +129,7 @@ namespace openal
bool Source::isPaused() const
{
if(valid)
if (valid)
{
ALenum state;
alGetSourcei(source, AL_SOURCE_STATE, &state);
@@ -161,7 +161,7 @@ namespace openal
alGetSourcei(source, AL_BUFFERS_PROCESSED, &processed);
while(processed--)
while (processed--)
{
ALuint buffer;
@@ -196,7 +196,7 @@ namespace openal
void Source::setPitch(float pitch)
{
if(valid)
if (valid)
alSourcef(source, AL_PITCH, pitch);
this->pitch = pitch;
@@ -204,7 +204,7 @@ namespace openal
float Source::getPitch() const
{
if(valid)
if (valid)
{
ALfloat f;
alGetSourcef(source, AL_PITCH, &f);
@@ -217,7 +217,7 @@ namespace openal
void Source::setVolume(float volume)
{
if(valid)
if (valid)
{
alSourcef(source, AL_GAIN, volume);
}
@@ -227,7 +227,7 @@ namespace openal
float Source::getVolume() const
{
if(valid)
if (valid)
{
ALfloat f;
alGetSourcef(source, AL_GAIN, &f);
@@ -237,14 +237,15 @@ namespace openal
// In case the Source isn't playing.
return volume;
}
void Source::seekAtomic(float offset, void * unit)
{
if (valid)
{
switch (*((Source::Unit*) unit)) {
case Source::UNIT_SAMPLES:
if (type == TYPE_STREAM) {
if (type == TYPE_STREAM)
{
offsetSamples = offset;
ALint buffer;
alGetSourcei(source, AL_BUFFER, &buffer);
@@ -253,13 +254,16 @@ namespace openal
offset /= freq;
offsetSeconds = offset;
decoder->seek(offset);
} else {
}
else
{
alSourcef(source, AL_SAMPLE_OFFSET, offset);
}
break;
case Source::UNIT_SECONDS:
case Source::UNIT_SECONDS:
default:
if (type == TYPE_STREAM) {
if (type == TYPE_STREAM)
{
offsetSeconds = offset;
decoder->seek(offset);
ALint buffer;
@@ -267,7 +271,9 @@ namespace openal
int freq;
alGetBufferi(buffer, AL_FREQUENCY, &freq);
offsetSamples = offset*freq;
} else {
}
else
{
alSourcef(source, AL_SEC_OFFSET, offset);
}
break;
@@ -290,7 +296,7 @@ namespace openal
{
return pool->seek(this, offset, &unit);
}
float Source::tellAtomic(void * unit) const
{
if (valid)
@@ -324,7 +330,7 @@ namespace openal
void Source::setPosition(float * v)
{
if(valid)
if (valid)
alSourcefv(source, AL_POSITION, v);
setFloatv(position, v);
@@ -332,7 +338,7 @@ namespace openal
void Source::getPosition(float * v) const
{
if(valid)
if (valid)
alGetSourcefv(source, AL_POSITION, v);
else
setFloatv(v, position);
@@ -340,7 +346,7 @@ namespace openal
void Source::setVelocity(float * v)
{
if(valid)
if (valid)
alSourcefv(source, AL_VELOCITY, v);
setFloatv(velocity, v);
@@ -348,7 +354,7 @@ namespace openal
void Source::getVelocity(float * v) const
{
if(valid)
if (valid)
alGetSourcefv(source, AL_VELOCITY, v);
else
setFloatv(v, velocity);
@@ -356,7 +362,7 @@ namespace openal
void Source::setDirection(float * v)
{
if(valid)
if (valid)
alSourcefv(source, AL_DIRECTION, v);
else
setFloatv(direction, v);
@@ -364,7 +370,7 @@ namespace openal
void Source::getDirection(float * v) const
{
if(valid)
if (valid)
alGetSourcefv(source, AL_DIRECTION, v);
else
setFloatv(v, direction);
@@ -372,7 +378,7 @@ namespace openal
void Source::setLooping(bool looping)
{
if(valid && type == TYPE_STATIC)
if (valid && type == TYPE_STATIC)
alSourcei(source, AL_LOOPING, looping ? AL_TRUE : AL_FALSE);
this->looping = looping;
@@ -385,23 +391,23 @@ namespace openal
void Source::playAtomic()
{
if(type == TYPE_STATIC)
if (type == TYPE_STATIC)
{
alSourcei(source, AL_BUFFER, buffers[0]);
}
else if(type == TYPE_STREAM)
else if (type == TYPE_STREAM)
{
int usedBuffers = 0;
for(unsigned int i = 0; i < MAX_BUFFERS; i++)
for (unsigned int i = 0; i < MAX_BUFFERS; i++)
{
streamAtomic(buffers[i], decoder);
++usedBuffers;
if(decoder->isFinished())
if (decoder->isFinished())
break;
}
if(usedBuffers > 0)
if (usedBuffers > 0)
alSourceQueueBuffers(source, usedBuffers, buffers);
}
@@ -418,13 +424,13 @@ namespace openal
void Source::stopAtomic()
{
if(valid)
if (valid)
{
if(type == TYPE_STATIC)
if (type == TYPE_STATIC)
{
alSourceStop(source);
}
else if(type == TYPE_STREAM)
else if (type == TYPE_STREAM)
{
alSourceStop(source);
int queued = 0;
@@ -444,7 +450,7 @@ namespace openal
void Source::pauseAtomic()
{
if(valid)
if (valid)
{
alSourcePause(source);
paused = true;
@@ -453,7 +459,7 @@ namespace openal
void Source::resumeAtomic()
{
if(valid && paused)
if (valid && paused)
{
alSourcePlay(source);
paused = false;
@@ -462,13 +468,13 @@ namespace openal
void Source::rewindAtomic()
{
if(valid && type == TYPE_STATIC)
if (valid && type == TYPE_STATIC)
{
alSourceRewind(source);
if (!paused)
alSourcePlay(source);
}
else if(valid && type == TYPE_STREAM)
else if (valid && type == TYPE_STREAM)
{
bool waspaused = paused;
decoder->rewind();
@@ -508,13 +514,13 @@ namespace openal
ALenum Source::getFormat(int channels, int bits) const
{
if(channels == 1 && bits == 8)
if (channels == 1 && bits == 8)
return AL_FORMAT_MONO8;
else if(channels == 1 && bits == 16)
else if (channels == 1 && bits == 16)
return AL_FORMAT_MONO16;
else if(channels == 2 && bits == 8)
else if (channels == 2 && bits == 8)
return AL_FORMAT_STEREO8;
else if(channels == 2 && bits == 16)
else if (channels == 2 && bits == 16)
return AL_FORMAT_STEREO16;
else
return 0;
@@ -527,10 +533,11 @@ namespace openal
int fmt = getFormat(d->getChannels(), d->getBits());
if(fmt != 0)
if (fmt != 0)
alBufferData(buffer, fmt, d->getBuffer(), decoded, d->getSampleRate());
if(decoder->isFinished() && isLooping()) {
if (decoder->isFinished() && isLooping())
{
int queued, processed;
alGetSourcei(source, AL_BUFFERS_QUEUED, &queued);
alGetSourcei(source, AL_BUFFERS_PROCESSED, &processed);
+1 -1
View File
@@ -63,7 +63,7 @@ namespace openal
float direction[3];
bool looping;
bool paused;
float offsetSamples;
float offsetSeconds;
+318 -315
View File
@@ -1,315 +1,318 @@
/**
* Copyright (c) 2006-2011 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 <scripts/audio.lua.h>
#include <common/runtime.h>
namespace love
{
namespace audio
{
static Audio * instance = 0;
int w_getNumSources(lua_State * L)
{
lua_pushinteger(L, instance->getNumSources());
return 1;
}
int w_newSource1(lua_State * L)
{
Source * t = 0;
if(luax_istype(L, 1, SOUND_SOUND_DATA_T))
t = instance->newSource(luax_totype<love::sound::SoundData>(L, 1, "SoundData", SOUND_SOUND_DATA_T));
else if(luax_istype(L, 1, SOUND_DECODER_T))
t = instance->newSource(luax_totype<love::sound::Decoder>(L, 1, "Decoder", SOUND_DECODER_T));
if(t)
{
luax_newtype(L, "Source", AUDIO_SOURCE_T, (void*)t);
return 1;
}
else
return luaL_error(L, "No matching overload");
return 0;
}
int w_play(lua_State * L)
{
Source * s = luax_checksource(L, 1);
instance->play(s);
return 0;
}
int w_stop(lua_State * L)
{
if(lua_gettop(L) == 0)
{
instance->stop();
}
else
{
Source * s = luax_checksource(L, 1);
s->stop();
}
return 0;
}
int w_pause(lua_State * L)
{
if(lua_gettop(L) == 0)
{
instance->pause();
}
else
{
Source * s = luax_checksource(L, 1);
s->pause();
}
return 0;
}
int w_resume(lua_State * L)
{
if(lua_gettop(L) == 0)
{
instance->resume();
}
else
{
Source * s = luax_checksource(L, 1);
s->resume();
}
return 0;
}
int w_rewind(lua_State * L)
{
if(lua_gettop(L) == 0)
{
instance->rewind();
}
else
{
Source * s = luax_checksource(L, 1);
s->rewind();
}
return 0;
}
int w_setVolume(lua_State * L)
{
float v = (float)luaL_checknumber(L, 1);
instance->setVolume(v);
return 0;
}
int w_getVolume(lua_State * L)
{
lua_pushnumber(L, instance->getVolume());
return 1;
}
int w_setPosition(lua_State * L)
{
float v[3];
v[0] = (float)luaL_checknumber(L, 1);
v[1] = (float)luaL_checknumber(L, 2);
v[2] = (float)luaL_checknumber(L, 3);
instance->setPosition(v);
return 0;
}
int w_getPosition(lua_State * L)
{
float v[3];
instance->getPosition(v);
lua_pushnumber(L, v[0]);
lua_pushnumber(L, v[1]);
lua_pushnumber(L, v[2]);
return 3;
}
int w_setOrientation(lua_State * L)
{
float v[6];
v[0] = (float)luaL_checknumber(L, 1);
v[1] = (float)luaL_checknumber(L, 2);
v[2] = (float)luaL_checknumber(L, 3);
v[3] = (float)luaL_checknumber(L, 4);
v[4] = (float)luaL_checknumber(L, 5);
v[5] = (float)luaL_checknumber(L, 6);
instance->setOrientation(v);
return 0;
}
int w_getOrientation(lua_State * L)
{
float v[6];
instance->getOrientation(v);
lua_pushnumber(L, v[0]);
lua_pushnumber(L, v[1]);
lua_pushnumber(L, v[2]);
lua_pushnumber(L, v[3]);
lua_pushnumber(L, v[4]);
lua_pushnumber(L, v[5]);
return 6;
}
int w_setVelocity(lua_State * L)
{
float v[3];
v[0] = (float)luaL_checknumber(L, 1);
v[1] = (float)luaL_checknumber(L, 2);
v[2] = (float)luaL_checknumber(L, 3);
instance->setVelocity(v);
return 0;
}
int w_getVelocity(lua_State * L)
{
float v[3];
instance->getVelocity(v);
lua_pushnumber(L, v[0]);
lua_pushnumber(L, v[1]);
lua_pushnumber(L, v[2]);
return 3;
}
int w_record(lua_State *)
{
instance->record();
return 0;
}
int w_getRecordedData(lua_State * L)
{
love::sound::SoundData * sd = instance->getRecordedData();
if (!sd) lua_pushnil(L);
else luax_newtype(L, "SoundData", SOUND_SOUND_DATA_T, (void*)sd);
return 1;
}
int w_stopRecording(lua_State * L)
{
if (luax_optboolean(L, 1, true)) {
love::sound::SoundData * sd = instance->stopRecording(true);
if (!sd) lua_pushnil(L);
else luax_newtype(L, "SoundData", SOUND_SOUND_DATA_T, (void*)sd);
return 1;
}
instance->stopRecording(false);
return 0;
}
int w_canRecord(lua_State * L) {
luax_pushboolean(L, instance->canRecord());
return 1;
}
// List of functions to wrap.
static const luaL_Reg functions[] = {
{ "getNumSources", w_getNumSources },
{ "newSource1", w_newSource1 },
{ "play", w_play },
{ "stop", w_stop },
{ "pause", w_pause },
{ "resume", w_resume },
{ "rewind", w_rewind },
{ "setVolume", w_setVolume },
{ "getVolume", w_getVolume },
{ "setPosition", w_setPosition },
{ "getPosition", w_getPosition },
{ "setOrientation", w_setOrientation },
{ "getOrientation", w_getOrientation },
{ "setVelocity", w_setVelocity },
{ "getVelocity", w_getVelocity },
/*{ "record", w_record },
{ "getRecordedData", w_getRecordedData },
{ "stopRecording", w_stopRecording },*/
{ 0, 0 }
};
static const lua_CFunction types[] = {
luaopen_source,
0
};
int luaopen_love_audio(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;
}
}
else
instance->retain();
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.");
WrappedModule w;
w.module = instance;
w.name = "audio";
w.flags = MODULE_T;
w.functions = functions;
w.types = types;
luax_register_module(L, w);
if (luaL_loadbuffer(L, (const char *)audio_lua, sizeof(audio_lua), "audio.lua") == 0)
lua_call(L, 0, 0);
return 0;
}
} // audio
} // love
/**
* Copyright (c) 2006-2011 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 <scripts/audio.lua.h>
#include <common/runtime.h>
namespace love
{
namespace audio
{
static Audio * instance = 0;
int w_getNumSources(lua_State * L)
{
lua_pushinteger(L, instance->getNumSources());
return 1;
}
int w_newSource1(lua_State * L)
{
Source * t = 0;
if (luax_istype(L, 1, SOUND_SOUND_DATA_T))
t = instance->newSource(luax_totype<love::sound::SoundData>(L, 1, "SoundData", SOUND_SOUND_DATA_T));
else if (luax_istype(L, 1, SOUND_DECODER_T))
t = instance->newSource(luax_totype<love::sound::Decoder>(L, 1, "Decoder", SOUND_DECODER_T));
if (t)
{
luax_newtype(L, "Source", AUDIO_SOURCE_T, (void*)t);
return 1;
}
else
return luaL_error(L, "No matching overload");
return 0;
}
int w_play(lua_State * L)
{
Source * s = luax_checksource(L, 1);
instance->play(s);
return 0;
}
int w_stop(lua_State * L)
{
if (lua_gettop(L) == 0)
{
instance->stop();
}
else
{
Source * s = luax_checksource(L, 1);
s->stop();
}
return 0;
}
int w_pause(lua_State * L)
{
if (lua_gettop(L) == 0)
{
instance->pause();
}
else
{
Source * s = luax_checksource(L, 1);
s->pause();
}
return 0;
}
int w_resume(lua_State * L)
{
if (lua_gettop(L) == 0)
{
instance->resume();
}
else
{
Source * s = luax_checksource(L, 1);
s->resume();
}
return 0;
}
int w_rewind(lua_State * L)
{
if (lua_gettop(L) == 0)
{
instance->rewind();
}
else
{
Source * s = luax_checksource(L, 1);
s->rewind();
}
return 0;
}
int w_setVolume(lua_State * L)
{
float v = (float)luaL_checknumber(L, 1);
instance->setVolume(v);
return 0;
}
int w_getVolume(lua_State * L)
{
lua_pushnumber(L, instance->getVolume());
return 1;
}
int w_setPosition(lua_State * L)
{
float v[3];
v[0] = (float)luaL_checknumber(L, 1);
v[1] = (float)luaL_checknumber(L, 2);
v[2] = (float)luaL_checknumber(L, 3);
instance->setPosition(v);
return 0;
}
int w_getPosition(lua_State * L)
{
float v[3];
instance->getPosition(v);
lua_pushnumber(L, v[0]);
lua_pushnumber(L, v[1]);
lua_pushnumber(L, v[2]);
return 3;
}
int w_setOrientation(lua_State * L)
{
float v[6];
v[0] = (float)luaL_checknumber(L, 1);
v[1] = (float)luaL_checknumber(L, 2);
v[2] = (float)luaL_checknumber(L, 3);
v[3] = (float)luaL_checknumber(L, 4);
v[4] = (float)luaL_checknumber(L, 5);
v[5] = (float)luaL_checknumber(L, 6);
instance->setOrientation(v);
return 0;
}
int w_getOrientation(lua_State * L)
{
float v[6];
instance->getOrientation(v);
lua_pushnumber(L, v[0]);
lua_pushnumber(L, v[1]);
lua_pushnumber(L, v[2]);
lua_pushnumber(L, v[3]);
lua_pushnumber(L, v[4]);
lua_pushnumber(L, v[5]);
return 6;
}
int w_setVelocity(lua_State * L)
{
float v[3];
v[0] = (float)luaL_checknumber(L, 1);
v[1] = (float)luaL_checknumber(L, 2);
v[2] = (float)luaL_checknumber(L, 3);
instance->setVelocity(v);
return 0;
}
int w_getVelocity(lua_State * L)
{
float v[3];
instance->getVelocity(v);
lua_pushnumber(L, v[0]);
lua_pushnumber(L, v[1]);
lua_pushnumber(L, v[2]);
return 3;
}
int w_record(lua_State *)
{
instance->record();
return 0;
}
int w_getRecordedData(lua_State * L)
{
love::sound::SoundData * sd = instance->getRecordedData();
if (!sd)
lua_pushnil(L);
else
luax_newtype(L, "SoundData", SOUND_SOUND_DATA_T, (void*)sd);
return 1;
}
int w_stopRecording(lua_State * L)
{
if (luax_optboolean(L, 1, true))
{
love::sound::SoundData * sd = instance->stopRecording(true);
if (!sd) lua_pushnil(L);
else luax_newtype(L, "SoundData", SOUND_SOUND_DATA_T, (void*)sd);
return 1;
}
instance->stopRecording(false);
return 0;
}
int w_canRecord(lua_State * L) {
luax_pushboolean(L, instance->canRecord());
return 1;
}
// List of functions to wrap.
static const luaL_Reg functions[] = {
{ "getNumSources", w_getNumSources },
{ "newSource1", w_newSource1 },
{ "play", w_play },
{ "stop", w_stop },
{ "pause", w_pause },
{ "resume", w_resume },
{ "rewind", w_rewind },
{ "setVolume", w_setVolume },
{ "getVolume", w_getVolume },
{ "setPosition", w_setPosition },
{ "getPosition", w_getPosition },
{ "setOrientation", w_setOrientation },
{ "getOrientation", w_getOrientation },
{ "setVelocity", w_setVelocity },
{ "getVelocity", w_getVelocity },
/*{ "record", w_record },
{ "getRecordedData", w_getRecordedData },
{ "stopRecording", w_stopRecording },*/
{ 0, 0 }
};
static const lua_CFunction types[] = {
luaopen_source,
0
};
int luaopen_love_audio(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;
}
}
else
instance->retain();
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.");
WrappedModule w;
w.module = instance;
w.name = "audio";
w.flags = MODULE_T;
w.functions = functions;
w.types = types;
luax_register_module(L, w);
if (luaL_loadbuffer(L, (const char *)audio_lua, sizeof(audio_lua), "audio.lua") == 0)
lua_call(L, 0, 0);
return 0;
}
} // audio
} // love
+58 -58
View File
@@ -1,58 +1,58 @@
/**
* Copyright (c) 2006-2011 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 <common/config.h>
#include <common/runtime.h>
#include "Audio.h"
#include "wrap_Source.h"
namespace love
{
namespace audio
{
int w_getNumSources(lua_State * L);
int w_newSource1(lua_State * L);
int w_play(lua_State * L);
int w_stop(lua_State * L);
int w_pause(lua_State * L);
int w_resume(lua_State * L);
int w_rewind(lua_State * L);
int w_setVolume(lua_State * L);
int w_getVolume(lua_State * L);
int w_setPosition(lua_State * L);
int w_getPosition(lua_State * L);
int w_setOrientation(lua_State * L);
int w_getOrientation(lua_State * L);
int w_setVelocity(lua_State * L);
int w_getVelocity(lua_State * L);
int w_record(lua_State * L);
int w_getRecordedData(lua_State * L);
int w_stopRecording(lua_State * L);
int w_canRecord(lua_State * L);
extern "C" LOVE_EXPORT int luaopen_love_audio(lua_State * L);
} // audio
} // love
#endif // LOVE_AUDIO_WRAP_AUDIO_H
/**
* Copyright (c) 2006-2011 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 <common/config.h>
#include <common/runtime.h>
#include "Audio.h"
#include "wrap_Source.h"
namespace love
{
namespace audio
{
int w_getNumSources(lua_State * L);
int w_newSource1(lua_State * L);
int w_play(lua_State * L);
int w_stop(lua_State * L);
int w_pause(lua_State * L);
int w_resume(lua_State * L);
int w_rewind(lua_State * L);
int w_setVolume(lua_State * L);
int w_getVolume(lua_State * L);
int w_setPosition(lua_State * L);
int w_getPosition(lua_State * L);
int w_setOrientation(lua_State * L);
int w_getOrientation(lua_State * L);
int w_setVelocity(lua_State * L);
int w_getVelocity(lua_State * L);
int w_record(lua_State * L);
int w_getRecordedData(lua_State * L);
int w_stopRecording(lua_State * L);
int w_canRecord(lua_State * L);
extern "C" LOVE_EXPORT int luaopen_love_audio(lua_State * L);
} // audio
} // love
#endif // LOVE_AUDIO_WRAP_AUDIO_H
+253 -253
View File
@@ -1,253 +1,253 @@
/**
* Copyright (c) 2006-2011 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", AUDIO_SOURCE_T);
}
int w_Source_play(lua_State * L)
{
Source * t = luax_checksource(L, 1);
t->play();
return 0;
}
int w_Source_stop(lua_State * L)
{
Source * t = luax_checksource(L, 1);
t->stop();
return 0;
}
int w_Source_pause(lua_State * L)
{
Source * t = luax_checksource(L, 1);
t->pause();
return 0;
}
int w_Source_resume(lua_State * L)
{
Source * t = luax_checksource(L, 1);
t->resume();
return 0;
}
int w_Source_rewind(lua_State * L)
{
Source * t = luax_checksource(L, 1);
t->rewind();
return 0;
}
int w_Source_setPitch(lua_State * L)
{
Source * t = luax_checksource(L, 1);
float p = (float)luaL_checknumber(L, 2);
t->setPitch(p);
return 0;
}
int w_Source_getPitch(lua_State * L)
{
Source * t = luax_checksource(L, 1);
lua_pushnumber(L, t->getPitch());
return 1;
}
int w_Source_setVolume(lua_State * L)
{
Source * t = luax_checksource(L, 1);
float p = (float)luaL_checknumber(L, 2);
t->setVolume(p);
return 0;
}
int w_Source_getVolume(lua_State * L)
{
Source * t = luax_checksource(L, 1);
lua_pushnumber(L, t->getVolume());
return 1;
}
int w_Source_seek(lua_State * L)
{
Source * t = luax_checksource(L, 1);
float offset = (float)luaL_checknumber(L, 2);
const char * unit = luaL_optstring(L, 3, "seconds");
Source::Unit u;
t->getConstant(unit, u);
t->seek(offset, u);
return 0;
}
int w_Source_tell(lua_State * L)
{
Source * t = luax_checksource(L, 1);
const char * unit = luaL_optstring(L, 2, "seconds");
Source::Unit u;
t->getConstant(unit, u);
lua_pushnumber(L, t->tell(u));
return 1;
}
int w_Source_setPosition(lua_State * L)
{
Source * t = luax_checksource(L, 1);
float v[3];
v[0] = (float)luaL_checknumber(L, 2);
v[1] = (float)luaL_checknumber(L, 3);
v[2] = (float)luaL_checknumber(L, 4);
t->setPosition(v);
return 0;
}
int w_Source_getPosition(lua_State * L)
{
Source * t = luax_checksource(L, 1);
float v[3];
t->getPosition(v);
lua_pushnumber(L, v[0]);
lua_pushnumber(L, v[1]);
lua_pushnumber(L, v[2]);
return 3;
}
int w_Source_setVelocity(lua_State * L)
{
Source * t = luax_checksource(L, 1);
float v[3];
v[0] = (float)luaL_checknumber(L, 2);
v[1] = (float)luaL_checknumber(L, 3);
v[2] = (float)luaL_checknumber(L, 4);
t->setVelocity(v);
return 0;
}
int w_Source_getVelocity(lua_State * L)
{
Source * t = luax_checksource(L, 1);
float v[3];
t->getVelocity(v);
lua_pushnumber(L, v[0]);
lua_pushnumber(L, v[1]);
lua_pushnumber(L, v[2]);
return 3;
}
int w_Source_setDirection(lua_State * L)
{
Source * t = luax_checksource(L, 1);
float v[3];
v[0] = (float)luaL_checknumber(L, 2);
v[1] = (float)luaL_checknumber(L, 3);
v[2] = (float)luaL_checknumber(L, 4);
t->setDirection(v);
return 0;
}
int w_Source_getDirection(lua_State * L)
{
Source * t = luax_checksource(L, 1);
float v[3];
t->getDirection(v);
lua_pushnumber(L, v[0]);
lua_pushnumber(L, v[1]);
lua_pushnumber(L, v[2]);
return 3;
}
int w_Source_setLooping(lua_State * L)
{
Source * t = luax_checksource(L, 1);
t->setLooping(luax_toboolean(L, 2));
return 0;
}
int w_Source_isLooping(lua_State * L)
{
Source * t = luax_checksource(L, 1);
luax_pushboolean(L, t->isLooping());
return 1;
}
int w_Source_isStopped(lua_State * L)
{
Source * t = luax_checksource(L, 1);
luax_pushboolean(L, t->isStopped());
return 1;
}
int w_Source_isPaused(lua_State * L)
{
Source * t = luax_checksource(L, 1);
luax_pushboolean(L, t->isPaused());
return 1;
}
int w_Source_isStatic(lua_State * L)
{
Source * t= luax_checksource(L, 1);
luax_pushboolean(L, t->isStatic());
return 1;
}
static const luaL_Reg functions[] = {
{ "play", w_Source_play },
{ "stop", w_Source_stop },
{ "pause", w_Source_pause },
{ "resume", w_Source_resume },
{ "rewind", w_Source_rewind },
{ "setPitch", w_Source_setPitch },
{ "getPitch", w_Source_getPitch },
{ "setVolume", w_Source_setVolume },
{ "getVolume", w_Source_getVolume },
{ "seek", w_Source_seek },
{ "tell", w_Source_tell },
{ "setPosition", w_Source_setPosition },
{ "getPosition", w_Source_getPosition },
{ "setVelocity", w_Source_setVelocity },
{ "getVelocity", w_Source_getVelocity },
{ "setDirection", w_Source_setDirection },
{ "getDirection", w_Source_getDirection },
{ "setLooping", w_Source_setLooping },
{ "isLooping", w_Source_isLooping },
{ "isStopped", w_Source_isStopped },
{ "isPaused", w_Source_isPaused },
{ "isStatic", w_Source_isStatic },
{ 0, 0 }
};
int luaopen_source(lua_State * L)
{
return luax_register_type(L, "Source", functions);
}
} // audio
} // love
/**
* Copyright (c) 2006-2011 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", AUDIO_SOURCE_T);
}
int w_Source_play(lua_State * L)
{
Source * t = luax_checksource(L, 1);
t->play();
return 0;
}
int w_Source_stop(lua_State * L)
{
Source * t = luax_checksource(L, 1);
t->stop();
return 0;
}
int w_Source_pause(lua_State * L)
{
Source * t = luax_checksource(L, 1);
t->pause();
return 0;
}
int w_Source_resume(lua_State * L)
{
Source * t = luax_checksource(L, 1);
t->resume();
return 0;
}
int w_Source_rewind(lua_State * L)
{
Source * t = luax_checksource(L, 1);
t->rewind();
return 0;
}
int w_Source_setPitch(lua_State * L)
{
Source * t = luax_checksource(L, 1);
float p = (float)luaL_checknumber(L, 2);
t->setPitch(p);
return 0;
}
int w_Source_getPitch(lua_State * L)
{
Source * t = luax_checksource(L, 1);
lua_pushnumber(L, t->getPitch());
return 1;
}
int w_Source_setVolume(lua_State * L)
{
Source * t = luax_checksource(L, 1);
float p = (float)luaL_checknumber(L, 2);
t->setVolume(p);
return 0;
}
int w_Source_getVolume(lua_State * L)
{
Source * t = luax_checksource(L, 1);
lua_pushnumber(L, t->getVolume());
return 1;
}
int w_Source_seek(lua_State * L)
{
Source * t = luax_checksource(L, 1);
float offset = (float)luaL_checknumber(L, 2);
const char * unit = luaL_optstring(L, 3, "seconds");
Source::Unit u;
t->getConstant(unit, u);
t->seek(offset, u);
return 0;
}
int w_Source_tell(lua_State * L)
{
Source * t = luax_checksource(L, 1);
const char * unit = luaL_optstring(L, 2, "seconds");
Source::Unit u;
t->getConstant(unit, u);
lua_pushnumber(L, t->tell(u));
return 1;
}
int w_Source_setPosition(lua_State * L)
{
Source * t = luax_checksource(L, 1);
float v[3];
v[0] = (float)luaL_checknumber(L, 2);
v[1] = (float)luaL_checknumber(L, 3);
v[2] = (float)luaL_checknumber(L, 4);
t->setPosition(v);
return 0;
}
int w_Source_getPosition(lua_State * L)
{
Source * t = luax_checksource(L, 1);
float v[3];
t->getPosition(v);
lua_pushnumber(L, v[0]);
lua_pushnumber(L, v[1]);
lua_pushnumber(L, v[2]);
return 3;
}
int w_Source_setVelocity(lua_State * L)
{
Source * t = luax_checksource(L, 1);
float v[3];
v[0] = (float)luaL_checknumber(L, 2);
v[1] = (float)luaL_checknumber(L, 3);
v[2] = (float)luaL_checknumber(L, 4);
t->setVelocity(v);
return 0;
}
int w_Source_getVelocity(lua_State * L)
{
Source * t = luax_checksource(L, 1);
float v[3];
t->getVelocity(v);
lua_pushnumber(L, v[0]);
lua_pushnumber(L, v[1]);
lua_pushnumber(L, v[2]);
return 3;
}
int w_Source_setDirection(lua_State * L)
{
Source * t = luax_checksource(L, 1);
float v[3];
v[0] = (float)luaL_checknumber(L, 2);
v[1] = (float)luaL_checknumber(L, 3);
v[2] = (float)luaL_checknumber(L, 4);
t->setDirection(v);
return 0;
}
int w_Source_getDirection(lua_State * L)
{
Source * t = luax_checksource(L, 1);
float v[3];
t->getDirection(v);
lua_pushnumber(L, v[0]);
lua_pushnumber(L, v[1]);
lua_pushnumber(L, v[2]);
return 3;
}
int w_Source_setLooping(lua_State * L)
{
Source * t = luax_checksource(L, 1);
t->setLooping(luax_toboolean(L, 2));
return 0;
}
int w_Source_isLooping(lua_State * L)
{
Source * t = luax_checksource(L, 1);
luax_pushboolean(L, t->isLooping());
return 1;
}
int w_Source_isStopped(lua_State * L)
{
Source * t = luax_checksource(L, 1);
luax_pushboolean(L, t->isStopped());
return 1;
}
int w_Source_isPaused(lua_State * L)
{
Source * t = luax_checksource(L, 1);
luax_pushboolean(L, t->isPaused());
return 1;
}
int w_Source_isStatic(lua_State * L)
{
Source * t= luax_checksource(L, 1);
luax_pushboolean(L, t->isStatic());
return 1;
}
static const luaL_Reg functions[] = {
{ "play", w_Source_play },
{ "stop", w_Source_stop },
{ "pause", w_Source_pause },
{ "resume", w_Source_resume },
{ "rewind", w_Source_rewind },
{ "setPitch", w_Source_setPitch },
{ "getPitch", w_Source_getPitch },
{ "setVolume", w_Source_setVolume },
{ "getVolume", w_Source_getVolume },
{ "seek", w_Source_seek },
{ "tell", w_Source_tell },
{ "setPosition", w_Source_setPosition },
{ "getPosition", w_Source_getPosition },
{ "setVelocity", w_Source_setVelocity },
{ "getVelocity", w_Source_getVelocity },
{ "setDirection", w_Source_setDirection },
{ "getDirection", w_Source_getDirection },
{ "setLooping", w_Source_setLooping },
{ "isLooping", w_Source_isLooping },
{ "isStopped", w_Source_isStopped },
{ "isPaused", w_Source_isPaused },
{ "isStatic", w_Source_isStatic },
{ 0, 0 }
};
int luaopen_source(lua_State * L)
{
return luax_register_type(L, "Source", functions);
}
} // audio
} // love
+59 -59
View File
@@ -1,59 +1,59 @@
/**
* Copyright (c) 2006-2011 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 w_Source_play(lua_State * L);
int w_Source_stop(lua_State * L);
int w_Source_pause(lua_State * L);
int w_Source_resume(lua_State * L);
int w_Source_rewind(lua_State * L);
int w_Source_setPitch(lua_State * L);
int w_Source_getPitch(lua_State * L);
int w_Source_setVolume(lua_State * L);
int w_Source_getVolume(lua_State * L);
int w_Source_seek(lua_State * L);
int w_Source_tell(lua_State * L);
int w_Source_setPosition(lua_State * L);
int w_Source_getPosition(lua_State * L);
int w_Source_setVelocity(lua_State * L);
int w_Source_getVelocity(lua_State * L);
int w_Source_setDirection(lua_State * L);
int w_Source_getDirection(lua_State * L);
int w_Source_setLooping(lua_State * L);
int w_Source_isLooping(lua_State * L);
int w_Source_isStopped(lua_State * L);
int w_Source_isPaused(lua_State * L);
int w_Source_isStatic(lua_State * L);
int luaopen_source(lua_State * L);
} // audio
} // love
#endif // LOVE_AUDIO_WRAP_SOURCE_H
/**
* Copyright (c) 2006-2011 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 w_Source_play(lua_State * L);
int w_Source_stop(lua_State * L);
int w_Source_pause(lua_State * L);
int w_Source_resume(lua_State * L);
int w_Source_rewind(lua_State * L);
int w_Source_setPitch(lua_State * L);
int w_Source_getPitch(lua_State * L);
int w_Source_setVolume(lua_State * L);
int w_Source_getVolume(lua_State * L);
int w_Source_seek(lua_State * L);
int w_Source_tell(lua_State * L);
int w_Source_setPosition(lua_State * L);
int w_Source_getPosition(lua_State * L);
int w_Source_setVelocity(lua_State * L);
int w_Source_getVelocity(lua_State * L);
int w_Source_setDirection(lua_State * L);
int w_Source_getDirection(lua_State * L);
int w_Source_setLooping(lua_State * L);
int w_Source_isLooping(lua_State * L);
int w_Source_isStopped(lua_State * L);
int w_Source_isPaused(lua_State * L);
int w_Source_isStatic(lua_State * L);
int luaopen_source(lua_State * L);
} // audio
} // love
#endif // LOVE_AUDIO_WRAP_SOURCE_H
+8 -5
View File
@@ -50,9 +50,9 @@ namespace sdl
SDL_EnableUNICODE(1);
while(SDL_PollEvent(&e))
while (SDL_PollEvent(&e))
{
if(convert(e, message))
if (convert(e, message))
return true;
}
@@ -77,7 +77,7 @@ namespace sdl
{
static SDL_Event e;
while(SDL_PollEvent(&e))
while (SDL_PollEvent(&e))
{
// Do nothing with 'e' ...
}
@@ -107,11 +107,14 @@ namespace sdl
m.joystick.index = e.jbutton.which;
return true;
case SDL_ACTIVEEVENT:
if (e.active.state & SDL_APPINPUTFOCUS) {
if (e.active.state & SDL_APPINPUTFOCUS)
{
m.type = Event::TYPE_FOCUS;
m.focus.f = (e.active.gain != 0);
return true;
} else break;
}
else
break;
case SDL_QUIT:
m.type = Event::TYPE_QUIT;
return true;
+10 -10
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -38,22 +38,22 @@ namespace sdl
class Event : public love::event::Event
{
public:
// Implements Module.
const char * getName() const;
Event();
/**
* Pumps the event queue. This function gathers all the pending input information
* 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();
/**
* Checks if there are messages in the queue.
*
* Checks if there are messages in the queue.
*
* @param message The next message in the queue, if the return value is true.
* @return True if there a message was found, false otherwise.
**/
@@ -68,9 +68,9 @@ namespace sdl
/**
* Push a message onto the event queue.
*
*
* @param message The message to push onto the queue.
* @return True on success, false if the queue was full.
* @return True on success, false if the queue was full.
**/
bool push(Message & message);
+233 -233
View File
@@ -1,233 +1,233 @@
/**
* Copyright (c) 2006-2011 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;
static bool to_message(lua_State * L, Event::Message & msg)
{
const char * str = luaL_checkstring(L, 1);
if(!Event::getConstant(str, msg.type))
return false;
switch(msg.type)
{
case Event::TYPE_KEY_PRESSED:
if(!Event::getConstant(luaL_checkstring(L, 2), msg.keyboard.k))
return false;
msg.keyboard.u = (unsigned short)luaL_optint(L, 3, 0);
return true;
case Event::TYPE_KEY_RELEASED:
if(!Event::getConstant(luaL_checkstring(L, 2), msg.keyboard.k))
return false;
return true;
case Event::TYPE_MOUSE_PRESSED:
case Event::TYPE_MOUSE_RELEASED:
if(!Event::getConstant(luaL_checkstring(L, 2), msg.mouse.b))
return false;
msg.mouse.x = luaL_checkint(L, 3);
msg.mouse.y = luaL_checkint(L, 4);
return true;
case Event::TYPE_JOYSTICK_PRESSED:
case Event::TYPE_JOYSTICK_RELEASED:
msg.joystick.index = luaL_checkint(L, 2);
msg.joystick.button = luaL_checkint(L, 3);
return true;
case Event::TYPE_FOCUS:
msg.focus.f = luax_toboolean(L, 2);
return true;
case Event::TYPE_QUIT:
return true;
default:
return false;
}
return false;
}
static int push_message(lua_State * L, const Event::Message & msg)
{
const char * str = 0;
if(!Event::getConstant(msg.type, str))
return 0;
lua_pushstring(L, str);
switch(msg.type)
{
case Event::TYPE_KEY_PRESSED:
if(!Event::getConstant(msg.keyboard.k, str))
return 0;
lua_pushstring(L, str);
lua_pushinteger(L, msg.keyboard.u);
return 3;
case Event::TYPE_KEY_RELEASED:
if(!Event::getConstant(msg.keyboard.k, str))
return 0;
lua_pushstring(L, str);
return 2;
case Event::TYPE_MOUSE_PRESSED:
case Event::TYPE_MOUSE_RELEASED:
if(!Event::getConstant(msg.mouse.b, str))
return 0;
lua_pushinteger(L, msg.mouse.x);
lua_pushinteger(L, msg.mouse.y);
lua_pushstring(L, str);
return 4;
case Event::TYPE_JOYSTICK_PRESSED:
case Event::TYPE_JOYSTICK_RELEASED:
lua_pushinteger(L, msg.joystick.index+1);
lua_pushinteger(L, msg.joystick.button+1);
return 3;
case Event::TYPE_FOCUS:
lua_pushboolean(L, msg.focus.f);
return 2;
case Event::TYPE_QUIT:
return 1;
default:
return 0;
}
return 0;
}
static int poll_i(lua_State * L)
{
static Event::Message m;
while(instance->poll(m))
{
int args = push_message(L, m);
if(args > 0)
return args;
}
// No pending events.
return 0;
}
int w_pump(lua_State *)
{
instance->pump();
return 0;
}
int w_poll(lua_State * L)
{
lua_pushcclosure(L, &poll_i, 0);
return 1;
}
int w_wait(lua_State * L)
{
static Event::Message m;
if(instance->wait(m))
{
return push_message(L, m);
}
return 0;
}
int w_push(lua_State * L)
{
static Event::Message m;
if(!to_message(L, m))
{
luax_pushboolean(L, false);
return 1;
}
luax_pushboolean(L, instance->push(m));
return 1;
}
int w_clear(lua_State *)
{
instance->clear();
return 0;
}
int w_quit(lua_State * L)
{
static Event::Message m;
m.type = Event::TYPE_QUIT;
luax_pushboolean(L, instance->push(m));
return 1;
}
// List of functions to wrap.
static const luaL_Reg functions[] = {
{ "pump", w_pump },
{ "poll", w_poll },
{ "wait", w_wait },
{ "push", w_push },
{ "clear", w_clear },
{ "quit", w_quit },
{ 0, 0 }
};
int luaopen_love_event(lua_State * L)
{
if(instance == 0)
{
try
{
instance = new Event();
}
catch(Exception & e)
{
return luaL_error(L, e.what());
}
}
else
instance->retain();
WrappedModule w;
w.module = instance;
w.name = "event";
w.flags = MODULE_T;
w.functions = functions;
w.types = 0;
return luax_register_module(L, w);
}
} // sdl
} // event
} // love
/**
* Copyright (c) 2006-2011 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;
static bool to_message(lua_State * L, Event::Message & msg)
{
const char * str = luaL_checkstring(L, 1);
if (!Event::getConstant(str, msg.type))
return false;
switch(msg.type)
{
case Event::TYPE_KEY_PRESSED:
if (!Event::getConstant(luaL_checkstring(L, 2), msg.keyboard.k))
return false;
msg.keyboard.u = (unsigned short)luaL_optint(L, 3, 0);
return true;
case Event::TYPE_KEY_RELEASED:
if (!Event::getConstant(luaL_checkstring(L, 2), msg.keyboard.k))
return false;
return true;
case Event::TYPE_MOUSE_PRESSED:
case Event::TYPE_MOUSE_RELEASED:
if (!Event::getConstant(luaL_checkstring(L, 2), msg.mouse.b))
return false;
msg.mouse.x = luaL_checkint(L, 3);
msg.mouse.y = luaL_checkint(L, 4);
return true;
case Event::TYPE_JOYSTICK_PRESSED:
case Event::TYPE_JOYSTICK_RELEASED:
msg.joystick.index = luaL_checkint(L, 2);
msg.joystick.button = luaL_checkint(L, 3);
return true;
case Event::TYPE_FOCUS:
msg.focus.f = luax_toboolean(L, 2);
return true;
case Event::TYPE_QUIT:
return true;
default:
return false;
}
return false;
}
static int push_message(lua_State * L, const Event::Message & msg)
{
const char * str = 0;
if (!Event::getConstant(msg.type, str))
return 0;
lua_pushstring(L, str);
switch(msg.type)
{
case Event::TYPE_KEY_PRESSED:
if (!Event::getConstant(msg.keyboard.k, str))
return 0;
lua_pushstring(L, str);
lua_pushinteger(L, msg.keyboard.u);
return 3;
case Event::TYPE_KEY_RELEASED:
if (!Event::getConstant(msg.keyboard.k, str))
return 0;
lua_pushstring(L, str);
return 2;
case Event::TYPE_MOUSE_PRESSED:
case Event::TYPE_MOUSE_RELEASED:
if (!Event::getConstant(msg.mouse.b, str))
return 0;
lua_pushinteger(L, msg.mouse.x);
lua_pushinteger(L, msg.mouse.y);
lua_pushstring(L, str);
return 4;
case Event::TYPE_JOYSTICK_PRESSED:
case Event::TYPE_JOYSTICK_RELEASED:
lua_pushinteger(L, msg.joystick.index+1);
lua_pushinteger(L, msg.joystick.button+1);
return 3;
case Event::TYPE_FOCUS:
lua_pushboolean(L, msg.focus.f);
return 2;
case Event::TYPE_QUIT:
return 1;
default:
return 0;
}
return 0;
}
static int poll_i(lua_State * L)
{
static Event::Message m;
while (instance->poll(m))
{
int args = push_message(L, m);
if (args > 0)
return args;
}
// No pending events.
return 0;
}
int w_pump(lua_State *)
{
instance->pump();
return 0;
}
int w_poll(lua_State * L)
{
lua_pushcclosure(L, &poll_i, 0);
return 1;
}
int w_wait(lua_State * L)
{
static Event::Message m;
if (instance->wait(m))
{
return push_message(L, m);
}
return 0;
}
int w_push(lua_State * L)
{
static Event::Message m;
if (!to_message(L, m))
{
luax_pushboolean(L, false);
return 1;
}
luax_pushboolean(L, instance->push(m));
return 1;
}
int w_clear(lua_State *)
{
instance->clear();
return 0;
}
int w_quit(lua_State * L)
{
static Event::Message m;
m.type = Event::TYPE_QUIT;
luax_pushboolean(L, instance->push(m));
return 1;
}
// List of functions to wrap.
static const luaL_Reg functions[] = {
{ "pump", w_pump },
{ "poll", w_poll },
{ "wait", w_wait },
{ "push", w_push },
{ "clear", w_clear },
{ "quit", w_quit },
{ 0, 0 }
};
int luaopen_love_event(lua_State * L)
{
if (instance == 0)
{
try
{
instance = new Event();
}
catch (Exception & e)
{
return luaL_error(L, e.what());
}
}
else
instance->retain();
WrappedModule w;
w.module = instance;
w.name = "event";
w.flags = MODULE_T;
w.functions = functions;
w.types = 0;
return luax_register_module(L, w);
}
} // sdl
} // event
} // love
+47 -47
View File
@@ -1,47 +1,47 @@
/**
* Copyright (c) 2006-2011 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 <common/config.h>
#include "Event.h"
namespace love
{
namespace event
{
namespace sdl
{
int w_pump(lua_State * L);
int w_poll(lua_State * L);
int w_wait(lua_State * L);
int w_push(lua_State * L);
int w_clear(lua_State * L);
int w_quit(lua_State * L);
extern "C" LOVE_EXPORT int luaopen_love_event(lua_State * L);
} // sdl
} // event
} // love
#endif // LOVE_EVENT_SDL_WRAP_EVENT_H
/**
* Copyright (c) 2006-2011 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 <common/config.h>
#include "Event.h"
namespace love
{
namespace event
{
namespace sdl
{
int w_pump(lua_State * L);
int w_poll(lua_State * L);
int w_wait(lua_State * L);
int w_push(lua_State * L);
int w_clear(lua_State * L);
int w_quit(lua_State * L);
extern "C" LOVE_EXPORT int luaopen_love_event(lua_State * L);
} // sdl
} // event
} // love
#endif // LOVE_EVENT_SDL_WRAP_EVENT_H
+4 -4
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -38,7 +38,7 @@ namespace filesystem
return modes.find(in, out);
}
StringMap<File::Mode, File::MODE_MAX_ENUM>::Entry File::modeEntries[] =
StringMap<File::Mode, File::MODE_MAX_ENUM>::Entry File::modeEntries[] =
{
{"c", File::CLOSED},
{"r", File::READ},
+15 -15
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -34,7 +34,7 @@ namespace love
namespace filesystem
{
/**
* A File interface, providing generic means of reading from and
* A File interface, providing generic means of reading from and
* writing to files.
**/
class File : public Object
@@ -65,7 +65,7 @@ namespace filesystem
/**
* Opens the file in a certain mode.
*
*
* @param mode READ, WRITE, APPEND.
* @return True if successful, false otherwise.
**/
@@ -73,21 +73,21 @@ namespace filesystem
/**
* 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.
**/
@@ -95,7 +95,7 @@ namespace filesystem
/**
* 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.
@@ -104,7 +104,7 @@ namespace filesystem
/**
* Writes data into the File.
*
*
* @param data The source buffer.
* @param size The size of the buffer.
* @return True of success, false otherwise.
@@ -113,7 +113,7 @@ namespace filesystem
/**
* 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.
@@ -122,28 +122,28 @@ namespace filesystem
/**
* 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.
* Gets the current mode of the File.
* @return The current mode of the File; CLOSED, READ, WRITE or APPEND.
**/
virtual Mode getMode() = 0;
+5 -5
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -30,7 +30,7 @@ namespace filesystem
FileData::FileData(int size, const std::string & filename)
: data(new char[size]), size(size), filename(filename)
{
if(filename.rfind('.') != std::string::npos)
if (filename.rfind('.') != std::string::npos)
extension = filename.substr(filename.rfind('.')+1);
}
@@ -69,7 +69,7 @@ namespace filesystem
return decoders.find(in, out);
}
StringMap<FileData::Decoder, FileData::DECODE_MAX_ENUM>::Entry FileData::decoderEntries[] =
StringMap<FileData::Decoder, FileData::DECODE_MAX_ENUM>::Entry FileData::decoderEntries[] =
{
{"file", FileData::FILE},
{"base64", FileData::BASE64},
+4 -4
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -27,7 +27,7 @@
#include <common/StringMap.h>
namespace love
{
{
namespace filesystem
{
class FileData : public Data
+24 -24
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -35,7 +35,7 @@ namespace physfs
{
extern bool hack_setupWriteDirectory();
File::File(std::string filename)
File::File(std::string filename)
: filename(filename), file(0), mode(filesystem::File::CLOSED)
{
}
@@ -45,22 +45,22 @@ namespace physfs
if (mode != CLOSED)
close();
}
bool File::open(Mode mode)
{
if(mode == CLOSED)
if (mode == CLOSED)
return true;
// File must exist if read mode.
if((mode == READ) && !PHYSFS_exists(filename.c_str()))
if ((mode == READ) && !PHYSFS_exists(filename.c_str()))
throw love::Exception("Could not open file %s. Does not exist.", filename.c_str());
// Check whether the write directory is set.
if((mode == APPEND || mode == WRITE) && (PHYSFS_getWriteDir() == 0) && !hack_setupWriteDirectory())
if ((mode == APPEND || mode == WRITE) && (PHYSFS_getWriteDir() == 0) && !hack_setupWriteDirectory())
throw love::Exception("Could not set write directory.");
// File already open?
if(file != 0)
if (file != 0)
return false;
this->mode = mode;
@@ -82,10 +82,10 @@ namespace physfs
return (file != 0);
}
bool File::close()
{
if(!PHYSFS_close(file))
if (!PHYSFS_close(file))
return false;
mode = CLOSED;
file = 0;
@@ -96,7 +96,7 @@ namespace physfs
{
// If the file is closed, open it to
// check the size.
if(file == 0)
if (file == 0)
{
open(READ);
unsigned int size = (unsigned int)PHYSFS_fileLength(file);
@@ -112,7 +112,7 @@ namespace physfs
{
bool isOpen = (file != 0);
if(!isOpen && !open(READ))
if (!isOpen && !open(READ))
throw love::Exception("Could not read file %s.", filename.c_str());
int max = (int)PHYSFS_fileLength(file);
@@ -123,7 +123,7 @@ namespace physfs
read(fileData->getData(), size);
if(!isOpen)
if (!isOpen)
close();
return fileData;
@@ -133,7 +133,7 @@ namespace physfs
{
bool isOpen = (file != 0);
if(!isOpen)
if (!isOpen)
open(READ);
int max = (int)PHYSFS_fileLength(file);
@@ -142,7 +142,7 @@ namespace physfs
int read = (int)PHYSFS_read(file, dst, 1, size);
if(!isOpen)
if (!isOpen)
close();
return read;
@@ -150,14 +150,14 @@ namespace physfs
bool File::write(const void * data, int size)
{
if(file == 0)
if (file == 0)
throw love::Exception("Could not write to file. File not open.");
// 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)
if (written != size)
return false;
return true;
@@ -187,14 +187,14 @@ namespace physfs
bool File::eof()
{
if(file == 0 || test_eof(this, file))
if (file == 0 || test_eof(this, file))
return true;
return false;
}
int File::tell()
{
if(file == 0)
if (file == 0)
return -1;
return (int)PHYSFS_tell(file);
@@ -202,10 +202,10 @@ namespace physfs
bool File::seek(int pos)
{
if(file == 0)
if (file == 0)
return false;
if(!PHYSFS_seek(file, (PHYSFS_uint64)pos))
if (!PHYSFS_seek(file, (PHYSFS_uint64)pos))
return false;
return true;
}
@@ -219,7 +219,7 @@ namespace physfs
{
std::string::size_type idx = filename.rfind('.');
if(idx != std::string::npos)
if (idx != std::string::npos)
return filename.substr(idx+1);
else
return std::string();
+4 -4
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -63,7 +63,7 @@ namespace physfs
File(std::string filename);
virtual ~File();
// Implements love::filesystem::File.
bool open(Mode mode);
bool close();
+59 -54
View File
@@ -40,7 +40,7 @@ namespace physfs
Filesystem::~Filesystem()
{
if(isInited)
if (isInited)
{
isInited = false;
PHYSFS_deinit();
@@ -54,7 +54,7 @@ namespace physfs
void Filesystem::init(const char * arg0)
{
if(!PHYSFS_init(arg0))
if (!PHYSFS_init(arg0))
throw Exception(PHYSFS_getLastError());
isInited = true;
}
@@ -76,7 +76,7 @@ namespace physfs
bool Filesystem::setIdentity( const char * ident )
{
if(!isInited)
if (!isInited)
return false;
// Store the save directory.
@@ -106,15 +106,15 @@ namespace physfs
bool Filesystem::setSource(const char * source)
{
if(!isInited)
if (!isInited)
return false;
// Check whether directory is already set.
if(!game_source.empty())
if (!game_source.empty())
return false;
// Add the directory.
if(!PHYSFS_addToSearchPath(source, 1))
if (!PHYSFS_addToSearchPath(source, 1))
return false;
// Save the game source.
@@ -125,16 +125,16 @@ namespace physfs
bool Filesystem::setupWriteDirectory()
{
if(!isInited)
if (!isInited)
return false;
// These must all be set.
if(save_identity.empty() || save_path_full.empty() || save_path_relative.empty())
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()))
if (!PHYSFS_setWriteDir(getAppdataDirectory()))
return false;
// Create the save folder. (We're now "at" %APPDATA%).
@@ -144,18 +144,18 @@ namespace physfs
else
success = mkdir(save_path_relative.c_str());
if(!success)
if (!success)
{
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()))
if (!PHYSFS_setWriteDir(save_path_full.c_str()))
return false;
// Add the directory. (Will not be readded if already present).
if(!PHYSFS_addToSearchPath(save_path_full.c_str(), 0))
if (!PHYSFS_addToSearchPath(save_path_full.c_str(), 0))
{
PHYSFS_setWriteDir(0); // Clear the write directory in case of error.
return false;
@@ -195,7 +195,7 @@ namespace physfs
const char * Filesystem::getWorkingDirectory()
{
if(cwd.empty())
if (cwd.empty())
{
#ifdef LOVE_WINDOWS
@@ -206,7 +206,7 @@ namespace physfs
#else
char * cwd_char = new char[LOVE_MAX_PATH];
if(getcwd(cwd_char, LOVE_MAX_PATH))
if (getcwd(cwd_char, LOVE_MAX_PATH))
cwd = cwd_char; // if getcwd fails, cwd_char (and thus cwd) will still be empty
delete [] cwd_char;
@@ -224,7 +224,7 @@ namespace physfs
const char * Filesystem::getAppdataDirectory()
{
#ifdef LOVE_WINDOWS
if(appdata.empty())
if (appdata.empty())
{
wchar_t * w_appdata = _wgetenv(TEXT("APPDATA"));
appdata = to_utf8(w_appdata);
@@ -232,7 +232,7 @@ namespace physfs
}
return appdata.c_str();
#elif defined(LOVE_MACOSX)
if(appdata.empty())
if (appdata.empty())
{
std::string udir = getUserDirectory();
udir.append("/Library/Application Support");
@@ -240,7 +240,7 @@ namespace physfs
}
return appdata.c_str();
#elif defined(LOVE_LINUX)
if(appdata.empty())
if (appdata.empty())
{
char * xdgdatahome = getenv("XDG_DATA_HOME");
if (!xdgdatahome)
@@ -262,14 +262,14 @@ namespace physfs
bool Filesystem::exists(const char * file)
{
if(PHYSFS_exists(file))
if (PHYSFS_exists(file))
return true;
return false;
}
bool Filesystem::isDirectory(const char * file)
{
if(PHYSFS_isDirectory(file))
if (PHYSFS_isDirectory(file))
return true;
return false;
}
@@ -281,20 +281,20 @@ namespace physfs
bool Filesystem::mkdir(const char * file)
{
if(PHYSFS_getWriteDir() == 0 && !setupWriteDirectory())
if (PHYSFS_getWriteDir() == 0 && !setupWriteDirectory())
return false;
if(!PHYSFS_mkdir(file))
if (!PHYSFS_mkdir(file))
return false;
return true;
}
bool Filesystem::remove(const char * file)
{
if(PHYSFS_getWriteDir() == 0 && !setupWriteDirectory())
if (PHYSFS_getWriteDir() == 0 && !setupWriteDirectory())
return false;
if(!PHYSFS_delete(file))
if (!PHYSFS_delete(file))
return false;
return true;
}
@@ -305,7 +305,7 @@ namespace physfs
// on-the-fly, or passed as a parameter.
File * file;
if(lua_isstring(L, 1))
if (lua_isstring(L, 1))
{
// Create the file.
file = newFile(lua_tostring(L, 1));
@@ -321,12 +321,12 @@ namespace physfs
Data * data = file->read(count);
// Error check.
if(data == 0)
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))
if (lua_isstring(L, 1))
file->release();
// Push the string.
@@ -349,10 +349,10 @@ namespace physfs
// We know for sure that we need a second parameter, so
// let's check that first.
if(lua_isnoneornil(L, 2))
if (lua_isnoneornil(L, 2))
return luaL_error(L, "Second argument needed.");
if(lua_isstring(L, 1))
if (lua_isstring(L, 1))
{
// Create the file.
file = newFile(lua_tostring(L, 1));
@@ -363,26 +363,31 @@ namespace physfs
// Get the current mode of the file.
File::Mode mode = file->getMode();
if(mode == File::CLOSED)
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))
if (!file->open((File::Mode)mode))
return luaL_error(L, "Could not open file.");
}
size_t length = 0;
const char * input;
if(lua_isstring(L, 2)) {
if (lua_isstring(L, 2))
{
input = lua_tolstring(L, 2, &length);
} else if (luax_istype(L, 2, DATA_T)) {
}
else if (luax_istype(L, 2, DATA_T))
{
love::Data * data = luax_totype<love::Data>(L, 2, "Data", DATA_T);
length = data->getSize();
input = (char *)data->getData();
} else {
}
else
{
return luaL_error(L, "Expected string or data for argument #2.");
}
@@ -394,14 +399,14 @@ namespace physfs
// Close and delete the file, if we created
// it in this function.
if(lua_isstring(L, 1))
if (lua_isstring(L, 1))
{
// Kill the file if "we" created it.
file->close();
file->release();
}
if(!success)
if (!success)
return luaL_error(L, "Data could not be written.");
lua_pushboolean(L, success);
@@ -412,12 +417,12 @@ namespace physfs
{
int n = lua_gettop(L);
if( n != 1 )
if ( n != 1 )
return luaL_error(L, "Function requires a single parameter.");
int type = lua_type(L, 1);
if(type != LUA_TSTRING)
if (type != LUA_TSTRING)
return luaL_error(L, "Function requires parameter of type string.");
const char * dir = lua_tostring(L, 1);
@@ -444,10 +449,10 @@ namespace physfs
{
File * file;
if(lua_isstring(L, 1))
if (lua_isstring(L, 1))
{
file = newFile(lua_tostring(L, 1));
if(!file->open(File::READ))
if (!file->open(File::READ))
return luaL_error(L, "Could not open file %s.\n", lua_tostring(L, 1));
lua_pop(L, 1);
@@ -458,7 +463,7 @@ namespace physfs
return luaL_error(L, "Expected filename.");
// Reset the file position.
if(!file->seek(0))
if (!file->seek(0))
return luaL_error(L, "File does not appear to be open.\n");
lua_pushcclosure(L, lines_i, 2);
@@ -480,34 +485,34 @@ namespace physfs
int newline = -1;
int totalread = 0;
while(!file->eof())
while (!file->eof())
{
int current = file->tell();
int read = file->read(buf, bufsize);
totalread += read;
if(read < 0)
if (read < 0)
return luaL_error(L, "Readline failed!");
for(int i = 0;i<read;i++)
for (int i = 0;i<read;i++)
{
if(buf[i] == '\n')
if (buf[i] == '\n')
{
newline = current+i;
break;
}
}
if(newline > 0)
if (newline > 0)
break;
}
// Special case for the last "line".
if(newline <= 0 && file->eof() && totalread > 0)
if (newline <= 0 && file->eof() && totalread > 0)
newline = pos + totalread;
// We've got a newline.
if(newline > 0)
if (newline > 0)
{
// Ok, we've got a line.
int linesize = (newline-pos);
@@ -517,10 +522,10 @@ namespace physfs
// Read it.
file->seek(pos);
if(file->read(str, linesize) == -1)
if (file->read(str, linesize) == -1)
return luaL_error(L, "Read error.");
if(str[linesize-1]=='\r')
if (str[linesize-1]=='\r')
linesize -= 1;
lua_pushlstring(L, str, linesize);
@@ -529,13 +534,13 @@ namespace physfs
delete[] str;
// Set the beginning of the next line.
if(!file->eof())
if (!file->eof())
file->seek(newline+1);
return 1;
}
if(close)
if (close)
{
file->close();
file->release();
@@ -550,13 +555,13 @@ namespace physfs
luax_assert_argc(L, 1, 1);
// Must be string.
if(!lua_isstring(L, -1))
if (!lua_isstring(L, -1))
return luaL_error(L, "The argument must be a string.");
std::string filename = lua_tostring(L, -1);
// The file must exist.
if(!exists(filename.c_str()))
if (!exists(filename.c_str()))
return luaL_error(L, "File %s does not exist.", filename.c_str());
// Create the file.
+16 -14
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -53,14 +53,14 @@ namespace physfs
File * file = luax_checkfile(L, 1);
File::Mode mode;
if(!File::getConstant(luaL_checkstring(L, 2), mode))
if (!File::getConstant(luaL_checkstring(L, 2), mode))
return luaL_error(L, "Incorrect file open mode: %s", luaL_checkstring(L, 2));
try
{
lua_pushboolean(L, file->open(mode) ? 1 : 0);
}
catch(Exception e)
catch (Exception e)
{
return luaL_error(L, e.what());
}
@@ -84,7 +84,7 @@ namespace physfs
{
d = file->read(luaL_optint(L, 2, file->getSize()));
}
catch(Exception e)
catch (Exception e)
{
return luaL_error(L, e.what());
}
@@ -107,18 +107,20 @@ namespace physfs
{
result = file->write(lua_tostring(L, 2), luaL_optint(L, 3, lua_objlen(L, 2)));
}
catch(Exception e)
catch (Exception e)
{
return luaL_error(L, e.what());
}
}
else if( luax_istype(L, 2, DATA_T)) {
else if ( luax_istype(L, 2, DATA_T))
{
try
{
love::Data * data = luax_totype<love::Data>(L, 2, "Data", DATA_T);
result = file->write(data, luaL_optint(L, 3, data->getSize()));
} catch(Exception e)
}
catch (Exception e)
{
return luaL_error(L, e.what());
}
@@ -159,7 +161,7 @@ namespace physfs
{
File * file;
if(luax_istype(L, 1, FILESYSTEM_FILE_T))
if (luax_istype(L, 1, FILESYSTEM_FILE_T))
{
file = luax_checktype<File>(L, 1, "File", FILESYSTEM_FILE_T);
lua_pushnumber(L, 0); // 0 = do not close.
@@ -168,14 +170,14 @@ namespace physfs
return luaL_error(L, "Expected file handle.");
// Reset the file position.
if(!file->seek(0))
if (!file->seek(0))
return luaL_error(L, "File does not appear to be open.\n");
lua_pushcclosure(L, Filesystem::lines_i, 2);
return 1;
}
static const luaL_Reg functions[] = {
static const luaL_Reg functions[] = {
{ "getSize", w_File_getSize },
{ "open", w_File_open },
{ "close", w_File_close },
@@ -192,7 +194,7 @@ namespace physfs
{
return luax_register_type(L, "File", functions);
}
} // physfs
} // filesystem
} // love
+3 -3
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -63,7 +63,7 @@ namespace physfs
{
return luax_register_type(L, "FileData", w_FileData_functions);
}
} // physfs
} // filesystem
} // love
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -31,7 +31,7 @@ namespace physfs
bool hack_setupWriteDirectory()
{
if(instance != 0)
if (instance != 0)
return instance->setupWriteDirectory();
return false;
}
@@ -44,7 +44,7 @@ namespace physfs
{
instance->init(arg0);
}
catch(Exception & e)
catch (Exception & e)
{
return luaL_error(L, e.what());
}
@@ -64,7 +64,7 @@ namespace physfs
{
const char * arg = luaL_checkstring(L, 1);
if(!instance->setIdentity(arg))
if (!instance->setIdentity(arg))
return luaL_error(L, "Could not set write directory.");
return 0;
@@ -74,7 +74,7 @@ namespace physfs
{
const char * arg = luaL_checkstring(L, 1);
if(!instance->setSource(arg))
if (!instance->setSource(arg))
return luaL_error(L, "Could not set source.");
return 0;
@@ -88,7 +88,7 @@ namespace physfs
{
t = instance->newFile(filename);
}
catch(Exception e)
catch (Exception e)
{
return luaL_error(L, e.what());
}
@@ -98,9 +98,9 @@ namespace physfs
int w_newFileData(lua_State * L)
{
if(!lua_isstring(L, 1))
if (!lua_isstring(L, 1))
return luaL_error(L, "String expected.");
if(!lua_isstring(L, 2))
if (!lua_isstring(L, 2))
return luaL_error(L, "String expected.");
size_t length = 0;
@@ -110,7 +110,7 @@ namespace physfs
FileData::Decoder decoder = FileData::FILE;
if(decstr)
if (decstr)
FileData::getConstant(decstr, decoder);
FileData * t = 0;
@@ -196,7 +196,7 @@ namespace physfs
{
return instance->read(L);
}
catch(Exception e)
catch (Exception e)
{
return luaL_error(L, e.what());
}
@@ -208,7 +208,7 @@ namespace physfs
{
return instance->write(L);
}
catch(Exception e)
catch (Exception e)
{
return luaL_error(L, e.what());
}
@@ -233,10 +233,12 @@ namespace physfs
int w_load(lua_State * L)
{
try {
try
{
return instance->load(L);
}
catch (love::Exception & e) {
catch (love::Exception & e)
{
return luaL_error(L, e.what());
}
}
@@ -255,16 +257,16 @@ namespace physfs
int size = tmp.size();
for(int i=0;i<size-4;i++)
for (int i=0;i<size-4;i++)
{
if(tmp[i] == '.')
if (tmp[i] == '.')
{
tmp[i] = '/';
}
}
// Check whether file exists.
if(instance->exists(tmp.c_str()))
if (instance->exists(tmp.c_str()))
{
lua_pop(L, 1);
lua_pushstring(L, tmp.c_str());
@@ -274,9 +276,9 @@ namespace physfs
tmp = filename;
size = tmp.size();
for(int i=0;i<size;i++)
for (int i=0;i<size;i++)
{
if(tmp[i] == '.')
if (tmp[i] == '.')
{
tmp[i] = '/';
}
@@ -285,7 +287,8 @@ namespace physfs
if (instance->isDirectory(tmp.c_str()))
{
tmp += "/init.lua";
if (instance->exists(tmp.c_str())) {
if (instance->exists(tmp.c_str()))
{
lua_pop(L, 1);
lua_pushstring(L, tmp.c_str());
// Ok, load it.
@@ -384,7 +387,7 @@ namespace physfs
int luaopen_love_filesystem(lua_State * L)
{
if(instance == 0)
if (instance == 0)
{
try
{
@@ -392,7 +395,7 @@ namespace physfs
love::luax_register_searcher(L, loader, 1);
love::luax_register_searcher(L, extloader, 2);
}
catch(Exception & e)
catch (Exception & e)
{
return luaL_error(L, e.what());
}
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
+3 -3
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
+3 -2
View File
@@ -30,7 +30,8 @@ namespace font
GlyphData::GlyphData(unsigned short glyph, GlyphMetrics glyphMetrics, GlyphData::Format f)
: glyph(glyph), metrics(glyphMetrics), data(0), format(f)
{
if (metrics.width && metrics.height) {
if (metrics.width && metrics.height)
{
switch (f) {
case GlyphData::FORMAT_LUMINANCE_ALPHA:
data = new unsigned char[metrics.width * metrics.height * 2];
@@ -116,6 +117,6 @@ namespace font
{
return format;
}
} // font
} // love
+10 -10
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -47,14 +47,14 @@ namespace font
**/
class GlyphData : public Data
{
public:
enum Format
{
FORMAT_LUMINANCE_ALPHA,
FORMAT_RGBA
};
GlyphData(unsigned short glyph, GlyphMetrics glyphMetrics, Format f);
virtual ~GlyphData();
@@ -106,22 +106,22 @@ namespace font
* Gets the max y value of the glyph.
**/
int getMaxY() const;
/**
* Gets the format of the glyph data.
**/
Format getFormat() const;
private:
// The glyph itself
unsigned short glyph;
// Glyph metrics
GlyphMetrics metrics;
// Glyph texture data
unsigned char * data;
// The format the data's in
Format format;
+10 -9
View File
@@ -72,7 +72,8 @@ namespace font
if (gm.width == 0) return g;
unsigned char * gd = (unsigned char*)g->getData();
love::image::pixel * pixels = (love::image::pixel *)(imageData->getData());
for (unsigned int i = 0; i < widths[glyph]*getHeight(); i++) {
for (unsigned int i = 0; i < widths[glyph]*getHeight(); i++)
{
love::image::pixel p = pixels[ positions[glyph] + (i % widths[glyph]) + (imageData->getWidth() * (i / widths[glyph])) ];
gd[i*4] = p.r;
gd[i*4+1] = p.g;
@@ -99,27 +100,27 @@ namespace font
unsigned int start = 0;
unsigned int end = 0;
for(unsigned int i = 0; i < length; ++i)
for (unsigned int i = 0; i < length; ++i)
{
if(i >= MAX_CHARS)
if (i >= MAX_CHARS)
break;
start = end;
// Finds out where the first character starts
while(start < imgw && equal(pixels[start], spacer))
while (start < imgw && equal(pixels[start], spacer))
++start;
if(i > 0)
if (i > 0)
spacing[glyphs[i - 1]] = (start > end) ? (start - end) : 0;
end = start;
// Find where glyph ends.
while(end < imgw && !equal(pixels[end], spacer))
while (end < imgw && !equal(pixels[end], spacer))
++end;
if(start >= end)
if (start >= end)
break;
unsigned c = glyphs[i];
@@ -129,9 +130,9 @@ namespace font
}
// Replace spacer color with an empty pixel
for(unsigned int i = 0; i < imgs; ++i)
for (unsigned int i = 0; i < imgs; ++i)
{
if(equal(pixels[i], spacer))
if (equal(pixels[i], spacer))
{
pixels[i].r = 0;
pixels[i].g = 0;
+7 -7
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -38,7 +38,7 @@ namespace font
private:
// Load all the glyph positions into memory
void load();
// The image data
love::image::ImageData * imageData;
// The glyphs in the font
@@ -51,7 +51,7 @@ namespace font
unsigned int * widths;
// The spacing of each glyph
unsigned int * spacing;
public:
ImageRasterizer(love::image::ImageData * imageData, unsigned short * glyphs, int length);
virtual ~ImageRasterizer();
@@ -60,9 +60,9 @@ namespace font
virtual int getLineHeight() const;
virtual GlyphData * getGlyphData(unsigned short glyph) const;
virtual int getNumGlyphs() const;
static const unsigned int MAX_CHARS = 256;
}; // ImageRasterizer
} // font
+3 -3
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
+5 -5
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -47,7 +47,7 @@ namespace font
{
protected:
FontMetrics metrics;
public:
virtual ~Rasterizer();
@@ -82,7 +82,7 @@ namespace font
* @param glyph The (UNICODE) glyph to get data for
**/
virtual GlyphData * getGlyphData(unsigned short glyph) const = 0;
/**
* Gets the number of glyphs the rasterizer has data for.
**/
+7 -6
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -31,7 +31,7 @@ namespace freetype
{
Font::Font()
{
if(FT_Init_FreeType(&library))
if (FT_Init_FreeType(&library))
throw love::Exception("TrueTypeFont Loading error: FT_Init_FreeType failed\n");
}
@@ -44,12 +44,13 @@ namespace freetype
{
return new TrueTypeRasterizer(library, data, size);
}
Rasterizer * Font::newRasterizer(love::image::ImageData * data, std::string glyphs)
{
int length = glyphs.size();
unsigned short * g = new unsigned short[length];
for (int i = 0; i < length; i++) {
for (int i = 0; i < length; i++)
{
g[i] = (unsigned char)glyphs[i];
}
Rasterizer * r = newRasterizer(data, g, length);
+6 -6
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -52,18 +52,18 @@ namespace freetype
public:
Font();
/**
* Destructor.
**/
virtual ~Font();
// Implements Font
Rasterizer * newRasterizer(Data * data, int size);
Rasterizer * newRasterizer(love::image::ImageData * data, std::string glyphs);
Rasterizer * newRasterizer(love::image::ImageData * data, unsigned short * glyphs, int length);
GlyphData * newGlyphData(Rasterizer * r, unsigned short glyph);
// Implement Module
const char * getName() const;
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -36,13 +36,13 @@ namespace freetype
{
data->retain();
if(FT_New_Memory_Face( library,
if (FT_New_Memory_Face( library,
(const FT_Byte *)data->getData(), /* first byte in memory */
data->getSize(), /* size in bytes */
0, /* face_index */
&face))
throw love::Exception("TrueTypeFont Loading error: FT_New_Face failed (there is probably a problem with your font file)\n");
FT_Set_Pixel_Sizes(face, size, size);
// Set global metrics
@@ -70,12 +70,12 @@ namespace freetype
FT_Glyph ftglyph;
// Initialize
if(FT_Load_Glyph(face, FT_Get_Char_Index(face, glyph), FT_LOAD_DEFAULT))
if (FT_Load_Glyph(face, FT_Get_Char_Index(face, glyph), FT_LOAD_DEFAULT))
throw love::Exception("TrueTypeFont Loading vm->error: FT_Load_Glyph failed\n");
if( FT_Get_Glyph(face->glyph, &ftglyph) )
if ( FT_Get_Glyph(face->glyph, &ftglyph) )
throw love::Exception("TrueTypeFont Loading vm->error: FT_Get_Glyph failed\n");
FT_Glyph_To_Bitmap(&ftglyph, FT_RENDER_MODE_NORMAL, 0, 1);
FT_BitmapGlyph bitmap_glyph = (FT_BitmapGlyph)ftglyph;
FT_Bitmap& bitmap = bitmap_glyph->bitmap; //just to make things easier
@@ -93,22 +93,22 @@ namespace freetype
int size = bitmap.rows*bitmap.width;
unsigned char * dst = (unsigned char *)glyphData->getData();
// Note that bitmap.buffer contains only luminosity. We copy that single value to
// our luminosity-alpha format.
for(int i = 0; i<size; i++)
// Note that bitmap.buffer contains only luminosity. We copy that single value to
// our luminosity-alpha format.
for (int i = 0; i<size; i++)
{
dst[2*i] = 255;
dst[2*i+1] = bitmap.buffer[i];
}
}
// Having copied the data over, we can destroy the glyph
FT_Done_Glyph(ftglyph);
// Return data
return glyphData;
}
int TrueTypeRasterizer::getNumGlyphs() const
{
return 256;
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -51,7 +51,7 @@ namespace freetype
// File data
Data * data;
public:
TrueTypeRasterizer(FT_Library library, Data * data, int size);
virtual ~TrueTypeRasterizer();
+110 -108
View File
@@ -1,108 +1,110 @@
/**
* Copyright (c) 2006-2011 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_Font.h"
#include "Font.h"
#include <font/wrap_GlyphData.h>
#include <font/wrap_Rasterizer.h>
#include "TrueTypeRasterizer.h"
namespace love
{
namespace font
{
namespace freetype
{
static Font * instance = 0;
int w_newRasterizer(lua_State * L)
{
Rasterizer * t = NULL;
if (luax_istype(L, 1, IMAGE_IMAGE_DATA_T)) {
love::image::ImageData * d = luax_checktype<love::image::ImageData>(L, 1, "ImageData", IMAGE_IMAGE_DATA_T);
const char * g = luaL_checkstring(L, 2);
std::string glyphs(g);
t = instance->newRasterizer(d, glyphs);
}
else if (luax_istype(L, 1, DATA_T)) {
Data * d = luax_checkdata(L, 1);
int size = luaL_checkint(L, 2);
t = instance->newRasterizer(d, size);
}
luax_newtype(L, "Rasterizer", FONT_RASTERIZER_T, t);
return 1;
}
int w_newGlyphData(lua_State * L)
{
Rasterizer * r = luax_checkrasterizer(L, 1);
unsigned short g = (unsigned short)luaL_checkint(L, 2);
GlyphData * t = instance->newGlyphData(r, g);
luax_newtype(L, "GlyphData", FONT_GLYPH_DATA_T, t);
return 1;
}
// List of functions to wrap.
static const luaL_Reg functions[] = {
{ "newRasterizer", w_newRasterizer },
{ "newGlyphData", w_newGlyphData },
{ 0, 0 }
};
static const lua_CFunction types[] = {
luaopen_glyphdata,
luaopen_rasterizer,
0
};
int luaopen_love_font(lua_State * L)
{
if(instance == 0)
{
try
{
instance = new Font();
}
catch(Exception & e)
{
return luaL_error(L, e.what());
}
}
else
instance->retain();
WrappedModule w;
w.module = instance;
w.name = "font";
w.flags = MODULE_T;
w.functions = functions;
w.types = types;
return luax_register_module(L, w);
}
} // freetype
} // font
} // love
/**
* Copyright (c) 2006-2011 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_Font.h"
#include "Font.h"
#include <font/wrap_GlyphData.h>
#include <font/wrap_Rasterizer.h>
#include "TrueTypeRasterizer.h"
namespace love
{
namespace font
{
namespace freetype
{
static Font * instance = 0;
int w_newRasterizer(lua_State * L)
{
Rasterizer * t = NULL;
if (luax_istype(L, 1, IMAGE_IMAGE_DATA_T))
{
love::image::ImageData * d = luax_checktype<love::image::ImageData>(L, 1, "ImageData", IMAGE_IMAGE_DATA_T);
const char * g = luaL_checkstring(L, 2);
std::string glyphs(g);
t = instance->newRasterizer(d, glyphs);
}
else if (luax_istype(L, 1, DATA_T))
{
Data * d = luax_checkdata(L, 1);
int size = luaL_checkint(L, 2);
t = instance->newRasterizer(d, size);
}
luax_newtype(L, "Rasterizer", FONT_RASTERIZER_T, t);
return 1;
}
int w_newGlyphData(lua_State * L)
{
Rasterizer * r = luax_checkrasterizer(L, 1);
unsigned short g = (unsigned short)luaL_checkint(L, 2);
GlyphData * t = instance->newGlyphData(r, g);
luax_newtype(L, "GlyphData", FONT_GLYPH_DATA_T, t);
return 1;
}
// List of functions to wrap.
static const luaL_Reg functions[] = {
{ "newRasterizer", w_newRasterizer },
{ "newGlyphData", w_newGlyphData },
{ 0, 0 }
};
static const lua_CFunction types[] = {
luaopen_glyphdata,
luaopen_rasterizer,
0
};
int luaopen_love_font(lua_State * L)
{
if (instance == 0)
{
try
{
instance = new Font();
}
catch (Exception & e)
{
return luaL_error(L, e.what());
}
}
else
instance->retain();
WrappedModule w;
w.module = instance;
w.name = "font";
w.flags = MODULE_T;
w.functions = functions;
w.types = types;
return luax_register_module(L, w);
}
} // freetype
} // font
} // love
+42 -42
View File
@@ -1,42 +1,42 @@
/**
* Copyright (c) 2006-2011 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_FONT_FREETYPE_WRAP_FONT_H
#define LOVE_FONT_FREETYPE_WRAP_FONT_H
// LOVE
#include <common/config.h>
#include <common/runtime.h>
namespace love
{
namespace font
{
namespace freetype
{
int w_newRasterizer(lua_State * L);
int w_newGlyphData(lua_State * L);
extern "C" LOVE_EXPORT int luaopen_love_font(lua_State * L);
} // freetype
} // font
} // love
#endif // LOVE_FONT_FREETYPE_WRAP_FONT_H
/**
* Copyright (c) 2006-2011 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_FONT_FREETYPE_WRAP_FONT_H
#define LOVE_FONT_FREETYPE_WRAP_FONT_H
// LOVE
#include <common/config.h>
#include <common/runtime.h>
namespace love
{
namespace font
{
namespace freetype
{
int w_newRasterizer(lua_State * L);
int w_newGlyphData(lua_State * L);
extern "C" LOVE_EXPORT int luaopen_love_font(lua_State * L);
} // freetype
} // font
} // love
#endif // LOVE_FONT_FREETYPE_WRAP_FONT_H
+44 -44
View File
@@ -1,44 +1,44 @@
/**
* Copyright (c) 2006-2011 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_GlyphData.h"
namespace love
{
namespace font
{
GlyphData * luax_checkglyphdata(lua_State * L, int idx)
{
return luax_checktype<GlyphData>(L, idx, "GlyphData", FONT_GLYPH_DATA_T);
}
static const luaL_Reg functions[] = {
{ "getPointer", w_Data_getPointer },
{ "getSize", w_Data_getSize },
{ 0, 0 }
};
int luaopen_glyphdata(lua_State * L)
{
return luax_register_type(L, "GlyphData", functions);
}
} // font
} // love
/**
* Copyright (c) 2006-2011 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_GlyphData.h"
namespace love
{
namespace font
{
GlyphData * luax_checkglyphdata(lua_State * L, int idx)
{
return luax_checktype<GlyphData>(L, idx, "GlyphData", FONT_GLYPH_DATA_T);
}
static const luaL_Reg functions[] = {
{ "getPointer", w_Data_getPointer },
{ "getSize", w_Data_getSize },
{ 0, 0 }
};
int luaopen_glyphdata(lua_State * L)
{
return luax_register_type(L, "GlyphData", functions);
}
} // font
} // love
+40 -40
View File
@@ -1,40 +1,40 @@
/**
* Copyright (c) 2006-2011 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_FONT_WRAP_GLYPH_DATA_H
#define LOVE_FONT_WRAP_GLYPH_DATA_H
// LOVE
#include <common/runtime.h>
#include <common/wrap_Data.h>
#include "GlyphData.h"
namespace love
{
namespace font
{
GlyphData * luax_checkglyphdata(lua_State * L, int idx);
int luaopen_glyphdata(lua_State * L);
} // font
} // love
#endif // LOVE_FONT_WRAP_GLYPH_DATA_H
/**
* Copyright (c) 2006-2011 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_FONT_WRAP_GLYPH_DATA_H
#define LOVE_FONT_WRAP_GLYPH_DATA_H
// LOVE
#include <common/runtime.h>
#include <common/wrap_Data.h>
#include "GlyphData.h"
namespace love
{
namespace font
{
GlyphData * luax_checkglyphdata(lua_State * L, int idx);
int luaopen_glyphdata(lua_State * L);
} // font
} // love
#endif // LOVE_FONT_WRAP_GLYPH_DATA_H
+44 -44
View File
@@ -1,44 +1,44 @@
/**
* Copyright (c) 2006-2011 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_Rasterizer.h"
#include <common/wrap_Data.h>
namespace love
{
namespace font
{
Rasterizer * luax_checkrasterizer(lua_State * L, int idx)
{
return luax_checktype<Rasterizer>(L, idx, "Rasterizer", FONT_RASTERIZER_T);
}
static const luaL_Reg functions[] = {
{ 0, 0 }
};
int luaopen_rasterizer(lua_State * L)
{
return luax_register_type(L, "Rasterizer", functions);
}
} // font
} // love
/**
* Copyright (c) 2006-2011 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_Rasterizer.h"
#include <common/wrap_Data.h>
namespace love
{
namespace font
{
Rasterizer * luax_checkrasterizer(lua_State * L, int idx)
{
return luax_checktype<Rasterizer>(L, idx, "Rasterizer", FONT_RASTERIZER_T);
}
static const luaL_Reg functions[] = {
{ 0, 0 }
};
int luaopen_rasterizer(lua_State * L)
{
return luax_register_type(L, "Rasterizer", functions);
}
} // font
} // love
+38 -38
View File
@@ -1,38 +1,38 @@
/**
* Copyright (c) 2006-2011 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_FONT_WRAP_RASTERIZER_H
#define LOVE_FONT_WRAP_RASTERIZER_H
// LOVE
#include <common/runtime.h>
#include "Rasterizer.h"
namespace love
{
namespace font
{
Rasterizer * luax_checkrasterizer(lua_State * L, int idx);
int luaopen_rasterizer(lua_State * L);
} // font
} // love
#endif // LOVE_FONT_WRAP_RASTERIZER_H
/**
* Copyright (c) 2006-2011 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_FONT_WRAP_RASTERIZER_H
#define LOVE_FONT_WRAP_RASTERIZER_H
// LOVE
#include <common/runtime.h>
#include "Rasterizer.h"
namespace love
{
namespace font
{
Rasterizer * luax_checkrasterizer(lua_State * L, int idx);
int luaopen_rasterizer(lua_State * L);
} // font
} // love
#endif // LOVE_FONT_WRAP_RASTERIZER_H
+33 -33
View File
@@ -1,33 +1,33 @@
/**
* Copyright (c) 2006-2011 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 "DrawQable.h"
namespace love
{
namespace graphics
{
DrawQable::~DrawQable()
{
}
} // graphics
} // love
/**
* Copyright (c) 2006-2011 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 "DrawQable.h"
namespace love
{
namespace graphics
{
DrawQable::~DrawQable()
{
}
} // graphics
} // love
+4 -4
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -43,7 +43,7 @@ namespace graphics
/**
* Draws the object with the specified transformation.
*
*
* @param quad The Quad to use to draw the object.
* @param x The position of the object along the x-axis.
* @param y The position of the object along the y-axis.
+33 -33
View File
@@ -1,33 +1,33 @@
/**
* Copyright (c) 2006-2011 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
/**
* Copyright (c) 2006-2011 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
+4 -4
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -43,7 +43,7 @@ namespace graphics
/**
* 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).
+14 -14
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -35,43 +35,43 @@ namespace graphics
Image::~Image()
{
}
bool Image::getConstant(const char * in, FilterMode & out)
{
return filterModes.find(in, out);
}
bool Image::getConstant(FilterMode in, const char *& out)
{
return filterModes.find(in, out);
}
bool Image::getConstant(const char * in, WrapMode & out)
{
return wrapModes.find(in, out);
}
bool Image::getConstant(WrapMode in, const char *& out)
{
return wrapModes.find(in, out);
}
StringMap<Image::FilterMode, Image::FILTER_MAX_ENUM>::Entry Image::filterModeEntries[] =
StringMap<Image::FilterMode, Image::FILTER_MAX_ENUM>::Entry Image::filterModeEntries[] =
{
{ "linear", Image::FILTER_LINEAR },
{ "nearest", Image::FILTER_NEAREST },
};
StringMap<Image::FilterMode, Image::FILTER_MAX_ENUM> Image::filterModes(Image::filterModeEntries, sizeof(Image::filterModeEntries));
StringMap<Image::WrapMode, Image::WRAP_MAX_ENUM>::Entry Image::wrapModeEntries[] =
StringMap<Image::WrapMode, Image::WRAP_MAX_ENUM>::Entry Image::wrapModeEntries[] =
{
{ "clamp", Image::WRAP_CLAMP },
{ "repeat", Image::WRAP_REPEAT },
};
StringMap<Image::WrapMode, Image::WRAP_MAX_ENUM> Image::wrapModes(Image::wrapModeEntries, sizeof(Image::wrapModeEntries));
} // graphics
} // love
+10 -10
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -30,14 +30,14 @@ namespace love
{
namespace graphics
{
class Image : public DrawQable, public Volatile
{
public:
enum WrapMode
{
WRAP_CLAMP = 1,
WRAP_CLAMP = 1,
WRAP_REPEAT,
WRAP_MAX_ENUM
};
@@ -64,21 +64,21 @@ namespace graphics
};
virtual ~Image();
static bool getConstant(const char * in, FilterMode & out);
static bool getConstant(FilterMode in, const char *& out);
static bool getConstant(const char * in, WrapMode & out);
static bool getConstant(WrapMode in, const char *& out);
private:
static StringMap<FilterMode, FILTER_MAX_ENUM>::Entry filterModeEntries[];
static StringMap<FilterMode, FILTER_MAX_ENUM> filterModes;
static StringMap<WrapMode, WRAP_MAX_ENUM>::Entry wrapModeEntries[];
static StringMap<WrapMode, WRAP_MAX_ENUM> wrapModes;
}; // Image
} // graphics
} // love
+36 -36
View File
@@ -1,36 +1,36 @@
/**
* Copyright (c) 2006-2011 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 "Quad.h"
namespace love
{
namespace graphics
{
Quad::Quad()
{
}
Quad::~Quad()
{
}
} // graphics
} // love
/**
* Copyright (c) 2006-2011 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 "Quad.h"
namespace love
{
namespace graphics
{
Quad::Quad()
{
}
Quad::~Quad()
{
}
} // graphics
} // love
+3 -3
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
+6 -6
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -37,7 +37,7 @@ namespace graphics
Volatile::~Volatile()
{
// Remove the pointer to this object.
all.remove(this);
all.remove(this);
}
bool Volatile::loadAll()
@@ -45,7 +45,7 @@ namespace graphics
bool success = true;
std::list<Volatile *>::iterator i = all.begin();
while( i != all.end() )
while ( i != all.end() )
{
success = success && (*i)->loadVolatile();
i++;
@@ -58,7 +58,7 @@ namespace graphics
{
std::list<Volatile *>::iterator i = all.begin();
while( i != all.end() )
while ( i != all.end() )
{
(*i)->unloadVolatile();
i++;
+6 -6
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -59,7 +59,7 @@ namespace graphics
/**
* 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;
@@ -70,11 +70,11 @@ namespace graphics
**/
virtual void unloadVolatile() = 0;
// Static:
// 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();
+20 -19
View File
@@ -29,8 +29,8 @@ namespace love
namespace graphics
{
namespace opengl
{
{
// strategy for fbo creation, interchangable at runtime:
// none, opengl >= 3.0, extensions
struct FramebufferStrategy {
@@ -159,20 +159,21 @@ namespace opengl
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer);
}
};
FramebufferStrategy* strategy = NULL;
FramebufferStrategy strategyNone;
FramebufferStrategyGL3 strategyGL3;
FramebufferStrategyEXT strategyEXT;
Canvas* Canvas::current = NULL;
static void loadStrategy()
{
if (!strategy) {
if (!strategy)
{
if (GLEE_VERSION_3_0 || GLEE_ARB_framebuffer_object)
strategy = &strategyGL3;
else if (GLEE_EXT_framebuffer_object && GLEE_EXT_packed_depth_stencil)
@@ -240,15 +241,15 @@ namespace opengl
glPushAttrib(GL_VIEWPORT_BIT | GL_TRANSFORM_BIT);
strategy->bindFBO(fbo);
glViewport(0, 0, width, height);
// Reset the projection matrix
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
// Set up orthographic view (no depth)
glOrtho(0.0, width, height, 0.0, -1.0, 1.0);
// Switch back to modelview matrix
glMatrixMode(GL_MODELVIEW);
@@ -293,7 +294,7 @@ namespace opengl
drawv(t, vertices);
}
void Canvas::drawq(love::graphics::Quad * quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
{
static Matrix t;
@@ -326,7 +327,7 @@ namespace opengl
memcpy(dst -= row, src += row, row);
love::image::ImageData* img = image->newImageData(width, height, (void*)screenshot);
delete[] screenshot;
delete[] pixels;
@@ -395,7 +396,7 @@ namespace opengl
clear(c);
return true;
}
void Canvas::unloadVolatile()
{
settings.filter = getFilter();
@@ -412,15 +413,15 @@ namespace opengl
{
return height;
}
void Canvas::drawv(const Matrix & t, const vertex * v) const
{
glPushMatrix();
glMultMatrixf((const GLfloat*)t.getElements());
glBindTexture(GL_TEXTURE_2D, img);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid*)&v[0].x);
@@ -428,7 +429,7 @@ namespace opengl
glDrawArrays(GL_QUADS, 0, 4);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glPopMatrix();
}
+2 -2
View File
@@ -61,7 +61,7 @@ namespace opengl
* @copydoc DrawQable::drawq()
**/
void drawq(love::graphics::Quad * quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const;
love::image::ImageData * getImageData(love::image::Image * image);
void setFilter(const Image::Filter &f);
@@ -94,7 +94,7 @@ namespace opengl
Image::Filter filter;
Image::Wrap wrap;
} settings;
void drawv(const Matrix & t, const vertex * v) const;
};
+42 -31
View File
@@ -54,7 +54,7 @@ namespace opengl
rasterizer->release();
unloadVolatile();
}
void Font::createTexture()
{
texture_x = texture_y = rowHeight = 0;
@@ -62,7 +62,7 @@ namespace opengl
glGenTextures(1, &t);
textures.push_back(t);
glBindTexture(GL_TEXTURE_2D, t);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
(filter.mag == Image::FILTER_LINEAR) ? GL_LINEAR : GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
@@ -70,22 +70,23 @@ namespace opengl
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
GLint format = (type == FONT_TRUETYPE ? GL_LUMINANCE_ALPHA : GL_RGBA);
glTexImage2D(GL_TEXTURE_2D,
0,
GL_RGBA,
(GLsizei)TEXTURE_WIDTH,
(GLsizei)TEXTURE_HEIGHT,
0,
format,
GL_UNSIGNED_BYTE,
glTexImage2D(GL_TEXTURE_2D,
0,
GL_RGBA,
(GLsizei)TEXTURE_WIDTH,
(GLsizei)TEXTURE_HEIGHT,
0,
format,
GL_UNSIGNED_BYTE,
NULL);
}
Font::Glyph * Font::addGlyph(int glyph)
{
Glyph * g = new Glyph;
g->list = glGenLists(1);
if (g->list == 0) { // opengl failed to generate the list
if (g->list == 0)
{ // opengl failed to generate the list
delete g;
return NULL;
}
@@ -93,18 +94,20 @@ namespace opengl
g->spacing = gd->getAdvance();
int w = gd->getWidth();
int h = gd->getHeight();
if (texture_x + w > TEXTURE_WIDTH) { // out of space - new row!
if (texture_x + w > TEXTURE_WIDTH)
{ // out of space - new row!
texture_x = 0;
texture_y += rowHeight;
rowHeight = 0;
}
if (texture_y + h > TEXTURE_HEIGHT) { // totally out of space - new texture!
if (texture_y + h > TEXTURE_HEIGHT)
{ // totally out of space - new texture!
createTexture();
}
GLuint t = textures.back();
glBindTexture(GL_TEXTURE_2D, t);
glTexSubImage2D(GL_TEXTURE_2D, 0, texture_x, texture_y, w, h, (type == FONT_TRUETYPE ? GL_LUMINANCE_ALPHA : GL_RGBA), GL_UNSIGNED_BYTE, gd->getData());
Quad::Viewport v;
v.x = (float) texture_x;
v.y = (float) texture_y;
@@ -112,12 +115,12 @@ namespace opengl
v.h = (float) h;
Quad * q = new Quad(v, (const float) TEXTURE_WIDTH, (const float) TEXTURE_HEIGHT);
const vertex * verts = q->getVertices();
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&verts[0].x);
glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&verts[0].s);
glNewList(g->list, GL_COMPILE);
glBindTexture(GL_TEXTURE_2D, t);
glPushMatrix();
@@ -125,16 +128,16 @@ namespace opengl
glDrawArrays(GL_QUADS, 0, 4);
glPopMatrix();
glEndList();
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
delete q;
delete gd;
texture_x += w;
rowHeight = std::max(rowHeight, h);
glyphs[glyph] = g;
return g;
}
@@ -156,9 +159,11 @@ namespace opengl
{
utf8::iterator<std::string::iterator> i (text.begin(), text.begin(), text.end());
utf8::iterator<std::string::iterator> end (text.end(), text.begin(), text.end());
while (i != end) {
while (i != end)
{
int g = *i++;
if (g == '\n') { // wrap newline, but do not print it
if (g == '\n')
{ // wrap newline, but do not print it
glTranslatef(-dx, floor(getHeight() * getLineHeight() + 0.5f), 0);
dx = 0.0f;
continue;
@@ -194,16 +199,17 @@ namespace opengl
int Font::getWidth(const std::string & line)
{
if(line.size() == 0) return 0;
if (line.size() == 0) return 0;
int temp = 0;
Glyph * g;
try
{
utf8::iterator<std::string::const_iterator> i (line.begin(), line.begin(), line.end());
utf8::iterator<std::string::const_iterator> end (line.end(), line.begin(), line.end());
while (i != end) {
while (i != end)
{
int c = *i++;
g = glyphs[c];
if (!g) g = addGlyph(c);
@@ -240,7 +246,8 @@ namespace opengl
//split text at newlines
istringstream iss( text );
string line;
while (getline(iss, line, '\n')) {
while (getline(iss, line, '\n'))
{
// split line into words
vector<string> words;
istringstream word_iss(line);
@@ -252,12 +259,14 @@ namespace opengl
float oldwidth = 0.0f;
ostringstream string_builder;
vector<string>::const_iterator word_iter;
for (word_iter = words.begin(); word_iter != words.end(); ++word_iter) {
for (word_iter = words.begin(); word_iter != words.end(); ++word_iter)
{
string word( *word_iter );
width += getWidth( word );
// on wordwrap, push line to line buffer and clear string builder
if (width >= wrap && oldwidth > 0) {
if (width >= wrap && oldwidth > 0)
{
int realw = width;
lines_to_draw.push_back( string_builder.str() );
string_builder.str( "" );
@@ -313,14 +322,16 @@ namespace opengl
// nuke everything from orbit
std::map<int, Glyph *>::iterator it = glyphs.begin();
Glyph * g;
while (it != glyphs.end()) {
while (it != glyphs.end())
{
g = it->second;
glDeleteLists(g->list, 1);
delete g;
glyphs.erase(it++);
}
std::vector<GLuint>::iterator iter = textures.begin();
while (iter != textures.end()) {
while (iter != textures.end())
{
glDeleteTextures(1, (GLuint*)&*iter);
iter++;
}
+8 -8
View File
@@ -42,20 +42,20 @@ namespace opengl
class Font : public Object, public Volatile
{
private:
enum FontType
{
FONT_TRUETYPE = 1,
FONT_IMAGE,
FONT_UNKNOWN
};
struct Glyph
{
GLuint list;
int spacing;
};
love::font::Rasterizer * rasterizer;
int height;
@@ -65,13 +65,13 @@ namespace opengl
std::map<int, Glyph *> glyphs; // maps glyphs to display lists
FontType type;
Image::Filter filter;
static const int TEXTURE_WIDTH = 512;
static const int TEXTURE_HEIGHT = 512;
int texture_x, texture_y;
int rowHeight;
void createTexture();
Glyph * addGlyph(int glyph);
@@ -166,10 +166,10 @@ namespace opengl
* Returns the spacing modifier.
**/
float getSpacing() const;
// Implements Volatile.
bool loadVolatile();
void unloadVolatile();
void unloadVolatile();
}; // Font
+70 -48
View File
@@ -48,13 +48,13 @@ namespace opengl
// Window should be centered.
SDL_putenv(const_cast<char *>("SDL_VIDEO_CENTERED=center"));
if(SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
throw Exception(SDL_GetError());
}
Graphics::~Graphics()
{
if(currentFont != 0)
if (currentFont != 0)
currentFont->release();
SDL_QuitSubSystem(SDL_INIT_VIDEO);
@@ -156,7 +156,7 @@ namespace opengl
// love.mouse.getX() < 800 when switching from 800x600 to a
// higher resolution)
SDL_QuitSubSystem(SDL_INIT_VIDEO);
if(SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
{
std::cout << "Could not init SDL_VIDEO: " << SDL_GetError() << std::endl;
return false;
@@ -173,7 +173,7 @@ namespace opengl
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 1);
// FSAA
if(fsaa > 0)
if (fsaa > 0)
{
SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 1 ) ;
SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, fsaa ) ;
@@ -183,14 +183,14 @@ namespace opengl
// Fullscreen?
Uint32 sdlflags = fullscreen ? (SDL_OPENGL | SDL_FULLSCREEN) : SDL_OPENGL;
if(!isCreated())
if (!isCreated())
setCaption("");
// Have SDL set the video mode.
if(SDL_SetVideoMode(width, height, 32, sdlflags ) == 0)
if (SDL_SetVideoMode(width, height, 32, sdlflags ) == 0)
{
bool failed = true;
if(fsaa > 0)
if (fsaa > 0)
{
// FSAA might have failed, disable it and try again
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
@@ -202,7 +202,7 @@ namespace opengl
failed = SDL_SetVideoMode(width, height, 32, sdlflags ) == 0;
}
}
if(failed)
if (failed)
{
std::cerr << "Could not set video mode: " << SDL_GetError() << std::endl;
return false;
@@ -258,7 +258,7 @@ namespace opengl
// Reset modelview matrix
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// Set pixel row alignment
glPixelStorei(GL_UNPACK_ALIGNMENT, 2);
@@ -275,12 +275,12 @@ namespace opengl
currentMode.vsync = (real_vsync != 0);
// Reload all volatile objects.
if(!Volatile::loadAll())
if (!Volatile::loadAll())
std::cerr << "Could not reload all volatile objects." << std::endl;
// Restore the display state.
restoreState(tempState);
// Get the maximum number of matrices
// subtract a few to give the engine some room.
glGetIntegerv(GL_MAX_MODELVIEW_STACK_DEPTH, &matrixLimit);
@@ -392,14 +392,14 @@ namespace opengl
{
SDL_Rect ** modes = SDL_ListModes(0, SDL_OPENGL | SDL_FULLSCREEN);
if(modes == (SDL_Rect **)0 || modes == (SDL_Rect **)-1)
if (modes == (SDL_Rect **)0 || modes == (SDL_Rect **)-1)
return 0;
int index = 1;
lua_newtable(L);
for(int i=0;modes[i];++i)
for (int i=0;modes[i];++i)
{
lua_pushinteger(L, index);
lua_newtable(L);
@@ -437,7 +437,7 @@ namespace opengl
int Graphics::getScissor(lua_State * L)
{
if(glIsEnabled(GL_SCISSOR_TEST) == GL_FALSE)
if (glIsEnabled(GL_SCISSOR_TEST) == GL_FALSE)
return 0;
GLint scissor[4];
@@ -478,13 +478,17 @@ namespace opengl
// Create the image.
Image * image = new Image(data);
bool success;
try {
try
{
success = image->load();
} catch (love::Exception & e) {
}
catch (love::Exception & e)
{
image->release();
throw love::Exception(e.what());
}
if (!success) {
if (!success)
{
image->release();
return 0;
}
@@ -509,7 +513,7 @@ namespace opengl
Font * font = new Font(r, filter);
// Load it and check for errors.
if(!font)
if (!font)
{
delete font;
return 0;
@@ -521,9 +525,12 @@ namespace opengl
SpriteBatch * Graphics::newSpriteBatch(Image * image, int size, int usage)
{
SpriteBatch * t = NULL;
try {
try
{
t = new SpriteBatch(image, size, usage);
} catch (love::Exception& e) {
}
catch (love::Exception& e)
{
if (t) delete t;
throw e;
}
@@ -584,9 +591,12 @@ namespace opengl
PixelEffect * Graphics::newPixelEffect(const std::string& code)
{
PixelEffect * effect = NULL;
try {
try
{
effect = new PixelEffect(code);
} catch (love::Exception& e) {
}
catch (love::Exception& e)
{
if (effect)
delete effect;
throw(e);
@@ -634,12 +644,12 @@ namespace opengl
void Graphics::setFont( Font * font )
{
if(currentFont != 0)
if (currentFont != 0)
currentFont->release();
currentFont = font;
if(font != 0)
if (font != 0)
currentFont->retain();
}
@@ -669,7 +679,7 @@ namespace opengl
void Graphics::setColorMode ( Graphics::ColorMode mode )
{
if(mode == COLOR_MODULATE)
if (mode == COLOR_MODULATE)
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
else // mode = COLOR_REPLACE
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
@@ -689,7 +699,7 @@ namespace opengl
if (equation == GL_FUNC_REVERSE_SUBTRACT) // && src == GL_SRC_ALPHA && dst == GL_ONE
return BLEND_SUBTRACTIVE;
else if(src == GL_SRC_ALPHA && dst == GL_ONE) // && equation == GL_FUNC_ADD
else if (src == GL_SRC_ALPHA && dst == GL_ONE) // && equation == GL_FUNC_ADD
return BLEND_ADDITIVE;
else if (src == GL_SRC_ALPHA && dst == GL_ONE_MINUS_SRC_ALPHA) // && equation == GL_FUNC_ADD
return BLEND_ALPHA;
@@ -697,7 +707,7 @@ namespace opengl
return BLEND_MULTIPLICATIVE;
else if (src == GL_ONE && dst == GL_ONE_MINUS_SRC_ALPHA) // && equation == GL_FUNC_ADD
return BLEND_PREMULTIPLIED;
return BLEND_MAX_ENUM; // Should never be reached.
}
@@ -706,7 +716,7 @@ namespace opengl
GLint mode;
glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &mode);
if(mode == GL_MODULATE)
if (mode == GL_MODULATE)
return COLOR_MODULATE;
else // // mode == GL_REPLACE
return COLOR_REPLACE;
@@ -727,7 +737,7 @@ namespace opengl
//// XXX: actually enables antialiasing for _all_ polygons.
//// may need investigation if wanted or not
//// maybe rename to something else?
//if(style == LINE_ROUGH)
//if (style == LINE_ROUGH)
// glDisable (GL_POLYGON_SMOOTH);
//else // type == LINE_SMOOTH
//{
@@ -741,7 +751,7 @@ namespace opengl
{
setLineWidth(width);
if(style == 0)
if (style == 0)
return;
setLineStyle(style);
}
@@ -755,7 +765,7 @@ namespace opengl
Graphics::LineStyle Graphics::getLineStyle()
{
//if(glIsEnabled(GL_POLYGON_SMOOTH) == GL_TRUE)
//if (glIsEnabled(GL_POLYGON_SMOOTH) == GL_TRUE)
// return LINE_SMOOTH;
//else
return LINE_ROUGH;
@@ -768,7 +778,7 @@ namespace opengl
void Graphics::setPointStyle( Graphics::PointStyle style )
{
if( style == POINT_SMOOTH )
if ( style == POINT_SMOOTH )
glEnable(GL_POINT_SMOOTH);
else // love::POINT_ROUGH
glDisable(GL_POINT_SMOOTH);
@@ -776,7 +786,7 @@ namespace opengl
void Graphics::setPoint( float size, Graphics::PointStyle style )
{
if( style == POINT_SMOOTH )
if ( style == POINT_SMOOTH )
glEnable(GL_POINT_SMOOTH);
else // POINT_ROUGH
glDisable(GL_POINT_SMOOTH);
@@ -793,7 +803,7 @@ namespace opengl
Graphics::PointStyle Graphics::getPointStyle()
{
if(glIsEnabled(GL_POINT_SMOOTH) == GL_TRUE)
if (glIsEnabled(GL_POINT_SMOOTH) == GL_TRUE)
return POINT_SMOOTH;
else
return POINT_ROUGH;
@@ -808,7 +818,7 @@ namespace opengl
void Graphics::print( const char * str, float x, float y , float angle, float sx, float sy, float ox, float oy, float kx, float ky)
{
if(currentFont != 0)
if (currentFont != 0)
{
std::string text(str);
currentFont->print(text, x, y, angle, sx, sy, ox, oy, kx, ky);
@@ -826,7 +836,8 @@ namespace opengl
// now for the actual printing
vector<string>::const_iterator line_iter, line_end = lines_to_draw.end();
for (line_iter = lines_to_draw.begin(); line_iter != line_end; ++line_iter) {
for (line_iter = lines_to_draw.begin(); line_iter != line_end; ++line_iter)
{
float width = static_cast<float>(currentFont->getWidth( *line_iter ));
switch (align) {
case ALIGN_RIGHT:
@@ -875,7 +886,8 @@ namespace opengl
d2 *= halfwidth;
// lines parallel -> assume intersection at displacement points
if (fabs(det_norm) <= .03) {
if (fabs(det_norm) <= .03)
{
vertices[pos] = q - d2;
vertices[pos + 1] = q + d2;
return;
@@ -903,7 +915,8 @@ namespace opengl
if (looping) q = Vector(coords[count-4], coords[count-3]);
else q = r * 2 - Vector(coords[2], coords[3]);
for (size_t i = 0; i+3 < count; i += 2) {
for (size_t i = 0; i+3 < count; i += 2)
{
p = q;
q = r;
r = Vector(coords[i+2], coords[i+3]);
@@ -946,12 +959,13 @@ namespace opengl
void Graphics::circle(DrawMode mode, float x, float y, float radius, int points)
{
float two_pi = static_cast<float>(LOVE_M_PI * 2);
if(points <= 0) points = 1;
if (points <= 0) points = 1;
float angle_shift = (two_pi / points);
float phi = .0f;
float *coords = new float[2 * (points + 1)];
for (int i = 0; i < points; ++i, phi += angle_shift) {
for (int i = 0; i < points; ++i, phi += angle_shift)
{
coords[2*i] = x + radius * cos(phi);
coords[2*i+1] = y + radius * sin(phi);
}
@@ -963,7 +977,7 @@ namespace opengl
delete[] coords;
}
void Graphics::arc(DrawMode mode, float x, float y, float radius, float angle1, float angle2, int points)
{
angle1 = fmod(angle1, 2.0f * (float)LOVE_M_PI);
@@ -974,23 +988,27 @@ namespace opengl
angle2 += (float)LOVE_M_PI * 2.0f;
if(points <= 0) points = 1;
if (points <= 0) points = 1;
float angle_shift = ((angle2 - angle1) / points);
float phi = angle1;
// GL_POLYGON can only fill-draw convex polygons, so we need to do stuff manually here
if (mode == DRAW_LINE) {
if (mode == DRAW_LINE)
{
float *coords = new float[(points + 3) * 2];
coords[0] = coords[2 * points + 4] = x;
coords[1] = coords[2 * points + 5] = y;
for (int i = 0; i <= points; ++i, phi += angle_shift) {
for (int i = 0; i <= points; ++i, phi += angle_shift)
{
coords[2 * (i+1)] = x + radius * cos(phi);
coords[2 * (i+1) + 1] = y - radius * sin(phi);
}
polyline(coords, (points + 3) * 2); // artifacts at sharp angles if set to looping
delete[] coords;
} else {
}
else
{
glDisable(GL_TEXTURE_2D);
glBegin(GL_TRIANGLE_FAN);
glVertex2f(x, y);
@@ -1009,9 +1027,12 @@ namespace opengl
{
// coords is an array of a closed loop of vertices, i.e.
// coords[count-2] = coords[0], coords[count-1] = coords[1]
if (mode == DRAW_LINE) {
if (mode == DRAW_LINE)
{
polyline(coords, count, true);
} else {
}
else
{
glDisable(GL_TEXTURE_2D);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, (const GLvoid*)coords);
@@ -1039,7 +1060,8 @@ namespace opengl
GLubyte *src = pixels - row, *dst = screenshot + size;
for (int i = 0; i < h; ++i) {
for (int i = 0; i < h; ++i)
{
memcpy(dst-=row, src+=row, row);
}
+1 -1
View File
@@ -498,7 +498,7 @@ namespace opengl
* @param points Number of points to use to draw the circle.
**/
void circle(DrawMode mode, float x, float y, float radius, int points = 10);
/**
* Draws an arc using the specified arguments.
* @param mode The mode of drawing (line/filled).
+7 -7
View File
@@ -53,7 +53,7 @@ namespace opengl
Image::~Image()
{
if(data != 0)
if (data != 0)
data->release();
unload();
}
@@ -262,7 +262,7 @@ namespace opengl
void Image::bind() const
{
if(texture != 0)
if (texture != 0)
glBindTexture(GL_TEXTURE_2D,texture);
}
@@ -293,12 +293,12 @@ namespace opengl
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
float p2width = next_p2(width);
float p2height = next_p2(height);
float s = width/p2width;
float t = height/p2height;
vertices[1].t = t;
vertices[2].t = t;
vertices[2].s = s;
@@ -313,7 +313,7 @@ namespace opengl
GL_RGBA,
GL_UNSIGNED_BYTE,
0);
glTexSubImage2D(GL_TEXTURE_2D,
0,
0,
@@ -339,7 +339,7 @@ namespace opengl
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,
@@ -361,7 +361,7 @@ namespace opengl
settings.filter = getFilter();
settings.wrap = getWrap();
// Delete the hardware texture.
if(texture != 0)
if (texture != 0)
{
glDeleteTextures(1, (GLuint*)&texture);
texture = 0;
+16 -16
View File
@@ -67,22 +67,22 @@ namespace opengl
ParticleSystem::~ParticleSystem()
{
if(this->sprite != 0)
if (this->sprite != 0)
this->sprite->release();
if(pStart != 0)
if (pStart != 0)
delete [] pStart;
}
void ParticleSystem::add()
{
if(isFull()) return;
if (isFull()) return;
float min,max;
min = particleLifeMin;
max = particleLifeMax;
if(min == max)
if (min == max)
pLast->life = min;
else
pLast->life = (rand() / (float(RAND_MAX)+1)) * (max - min) + min;
@@ -132,7 +132,7 @@ namespace opengl
void ParticleSystem::remove(particle * p)
{
if(!isEmpty())
if (!isEmpty())
{
*p = *(--pLast);
}
@@ -140,7 +140,7 @@ namespace opengl
void ParticleSystem::setSprite(Image * image)
{
if(sprite != 0)
if (sprite != 0)
sprite->release();
sprite = image;
@@ -170,7 +170,7 @@ namespace opengl
void ParticleSystem::setParticleLife(float min, float max)
{
particleLifeMin = min;
if(max == 0)
if (max == 0)
particleLifeMax = min;
else
particleLifeMax = max;
@@ -387,7 +387,7 @@ namespace opengl
void ParticleSystem::draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
{
if(sprite == 0) return; // just in case of failure
if (sprite == 0) return; // just in case of failure
glPushMatrix();
glPushAttrib(GL_CURRENT_BIT);
@@ -397,7 +397,7 @@ namespace opengl
glMultMatrixf((const GLfloat*)t.getElements());
particle * p = pStart;
while(p != pLast)
while (p != pLast)
{
glPushMatrix();
@@ -418,30 +418,30 @@ namespace opengl
particle * p = pStart;
// Make some more particles.
if(active)
if (active)
{
float rate = 1.0f / emissionRate; // the amount of time between each particle emit
emitCounter += dt;
while(emitCounter > rate)
while (emitCounter > rate)
{
add();
emitCounter -= rate;
}
/*int particles = (int)(emissionRate * dt);
for(int i = 0; i != particles; i++)
for (int i = 0; i != particles; i++)
add();*/
life -= dt;
if(lifetime != -1 && life < 0)
if (lifetime != -1 && life < 0)
stop();
}
while(p != pLast)
while (p != pLast)
{
// Decrease lifespan.
p->life -= dt;
if(p->life > 0)
if (p->life > 0)
{
// Temp variables.
@@ -509,7 +509,7 @@ namespace opengl
{
remove(p);
if(p >= pLast)
if (p >= pLast)
return;
} // else
} // while
+9 -9
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -143,7 +143,7 @@ namespace opengl
float spinStart;
float spinEnd;
float spinVariation;
// Offsets
float offsetX;
float offsetY;
@@ -339,14 +339,14 @@ namespace opengl
* @param color The color.
**/
void setColor(const Color& color);
/**
* Sets the particles' offsets for rotation.
* @param x The x offset.
* @param y The y offset.
**/
void setOffset(float x, float y);
/**
* Sets the color of the particles.
* @param newColors Array of colors
@@ -372,17 +372,17 @@ namespace opengl
* Returns the directional spread of the emitter (in degrees).
**/
float getSpread() const;
/**
* Returns the X offset of the particles.
**/
float getOffsetX() const;
/**
* Returns the Y offset of the particles.
**/
float getOffsetY() const;
/**
* Returns the amount of particles that are currently active in the system.
**/
+14 -7
View File
@@ -78,7 +78,8 @@ namespace opengl
GLuint shader = glCreateShader(GL_FRAGMENT_SHADER);
// should only fail if this is called between a glBegin()/glEnd() pair
if (shader == 0) {
if (shader == 0)
{
glDeleteProgram(_program);
throw love::Exception("Cannot create shader object.");
}
@@ -91,7 +92,8 @@ namespace opengl
GLint compile_ok;
glGetShaderiv(shader, GL_COMPILE_STATUS, &compile_ok);
if (GL_FALSE == compile_ok) {
if (GL_FALSE == compile_ok)
{
// get compiler error
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &strlen);
char *error_str = new char[strlen];
@@ -112,7 +114,8 @@ namespace opengl
glAttachShader(_program, shader);
glLinkProgram(_program);
glGetProgramiv(_program, GL_LINK_STATUS, &link_ok);
if (GL_FALSE == link_ok) {
if (GL_FALSE == link_ok)
{
// this should not happen if compiling is ok, but one can never be too careful
// get linker error
std::string tmp(getWarnings());
@@ -189,7 +192,8 @@ namespace opengl
TemporaryAttacher attacher(this);
GLint location = getUniformLocation(name);
if (size < 1 || size > 4) {
if (size < 1 || size > 4)
{
throw love::Exception("Invalid variable size: %d (expected 1-4).", size);
}
@@ -218,7 +222,8 @@ namespace opengl
TemporaryAttacher attacher(this);
GLint location = getUniformLocation(name);
if (size < 2 || size > 4) {
if (size < 2 || size > 4)
{
throw love::Exception("Invalid matrix size: %dx%d "
"(can only set 2x2, 3x3 or 4x4 matrices).", size,size);
}
@@ -283,7 +288,8 @@ namespace opengl
return it->second;
GLint location = glGetUniformLocation(_program, name.c_str());
if (location == -1) {
if (location == -1)
{
throw love::Exception(
"Cannot get location of shader variable `%s'.\n"
"A common error is to define but not use the variable.", name.c_str());
@@ -296,7 +302,8 @@ namespace opengl
void PixelEffect::checkSetUniformError()
{
GLenum error_code = glGetError();
if (GL_INVALID_OPERATION == error_code) {
if (GL_INVALID_OPERATION == error_code)
{
throw love::Exception(
"Invalid operation:\n"
"- Trying to send the wrong value type to shader variable, or\n"
+124 -123
View File
@@ -1,123 +1,124 @@
/**
* Copyright (c) 2006-2011 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 "Quad.h"
#include <common/Matrix.h>
// GLee
#include "GLee.h"
// STD
#include <cstring> // For memcpy
namespace love
{
namespace graphics
{
namespace opengl
{
Quad::Quad(const Viewport & v, float sw, float sh)
: sw(sw), sh(sh)
{
memset(vertices, 255, sizeof(vertex)*NUM_VERTICES);
refresh(v, sw, sh);
}
Quad::~Quad()
{
}
void Quad::refresh(const Viewport & v, float sw, float sh)
{
if (!GLEE_ARB_texture_non_power_of_two)
{
sw = next_p2(sw);
sh = next_p2(sh);
}
viewport = v;
vertices[0].x = 0;
vertices[0].y = 0;
vertices[1].x = 0;
vertices[1].y = v.h;
vertices[2].x = v.w;
vertices[2].y = v.h;
vertices[3].x = v.w;
vertices[3].y = 0;
vertices[0].s = v.x/sw;
vertices[0].t = v.y/sh;
vertices[1].s = v.x/sw;
vertices[1].t = (v.y+v.h)/sh;
vertices[2].s = (v.x+v.w)/sw;
vertices[2].t = (v.y+v.h)/sh;
vertices[3].s = (v.x+v.w)/sw;
vertices[3].t = v.y/sh;
}
void Quad::setViewport(const Quad::Viewport & v)
{
refresh(v, sw, sh);
}
Quad::Viewport Quad::getViewport() const
{
return viewport;
}
void Quad::flip(bool x, bool y)
{
vertex temp[4];
if (x)
{
memcpy(temp, vertices, sizeof(vertex)*NUM_VERTICES);
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)*NUM_VERTICES);
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;
}
}
void Quad::mirror(bool x, bool y)
{
for (size_t i = 0; i < NUM_VERTICES; ++i) {
if (x)
vertices[i].s = 1.0 - vertices[i].s;
if (y)
vertices[i].s = 1.0 - vertices[i].s;
}
}
const vertex * Quad::getVertices() const
{
return vertices;
}
} // opengl
} // graphics
} // love
/**
* Copyright (c) 2006-2011 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 "Quad.h"
#include <common/Matrix.h>
// GLee
#include "GLee.h"
// STD
#include <cstring> // For memcpy
namespace love
{
namespace graphics
{
namespace opengl
{
Quad::Quad(const Viewport & v, float sw, float sh)
: sw(sw), sh(sh)
{
memset(vertices, 255, sizeof(vertex)*NUM_VERTICES);
refresh(v, sw, sh);
}
Quad::~Quad()
{
}
void Quad::refresh(const Viewport & v, float sw, float sh)
{
if (!GLEE_ARB_texture_non_power_of_two)
{
sw = next_p2(sw);
sh = next_p2(sh);
}
viewport = v;
vertices[0].x = 0;
vertices[0].y = 0;
vertices[1].x = 0;
vertices[1].y = v.h;
vertices[2].x = v.w;
vertices[2].y = v.h;
vertices[3].x = v.w;
vertices[3].y = 0;
vertices[0].s = v.x/sw;
vertices[0].t = v.y/sh;
vertices[1].s = v.x/sw;
vertices[1].t = (v.y+v.h)/sh;
vertices[2].s = (v.x+v.w)/sw;
vertices[2].t = (v.y+v.h)/sh;
vertices[3].s = (v.x+v.w)/sw;
vertices[3].t = v.y/sh;
}
void Quad::setViewport(const Quad::Viewport & v)
{
refresh(v, sw, sh);
}
Quad::Viewport Quad::getViewport() const
{
return viewport;
}
void Quad::flip(bool x, bool y)
{
vertex temp[4];
if (x)
{
memcpy(temp, vertices, sizeof(vertex)*NUM_VERTICES);
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)*NUM_VERTICES);
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;
}
}
void Quad::mirror(bool x, bool y)
{
for (size_t i = 0; i < NUM_VERTICES; ++i)
{
if (x)
vertices[i].s = 1.0 - vertices[i].s;
if (y)
vertices[i].s = 1.0 - vertices[i].s;
}
}
const vertex * Quad::getVertices() const
{
return vertices;
}
} // opengl
} // graphics
} // love
+7 -7
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -102,7 +102,7 @@ namespace opengl
int SpriteBatch::add(float x, float y, float a, float sx, float sy, float ox, float oy, float kx, float ky, int index /*= -1*/)
{
// Only do this if there's a free slot.
if((index == -1 && next >= size) || index < -1 || index >= size)
if ((index == -1 && next >= size) || index < -1 || index >= size)
return -1;
// Needed for colors.
@@ -127,7 +127,7 @@ namespace opengl
int SpriteBatch::addq(Quad * quad, float x, float y, float a, float sx, float sy, float ox, float oy, float kx, float ky, int index /*= -1*/)
{
// Only do this if there's a free slot.
if((index == -1 && next >= size) || index < -1 || index >= next)
if ((index == -1 && next >= size) || index < -1 || index >= next)
return -1;
// Needed for colors.
@@ -178,7 +178,7 @@ namespace opengl
void SpriteBatch::setColor(const Color & color)
{
if(!this->color)
if (!this->color)
this->color = new Color(color);
else
*(this->color) = color;
@@ -218,7 +218,7 @@ namespace opengl
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, sizeof(vertex), array_buf->getPointer(vertex_offset));
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), array_buf->getPointer(texel_offset));
glDrawElements(GL_TRIANGLES, next*6, GL_UNSIGNED_SHORT, element_buf->getPointer(0));
+138 -138
View File
@@ -1,138 +1,138 @@
/**
* Copyright (c) 2006-2011 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 <common/StringMap.h>
#include <graphics/Drawable.h>
#include <graphics/Volatile.h>
#include <graphics/Color.h>
// OpenGL
#include "GLee.h"
#include <SDL/SDL_opengl.h>
namespace love
{
namespace graphics
{
namespace opengl
{
// Forward declarations.
class Image;
class Quad;
class VertexBuffer;
class SpriteBatch : public Drawable
{
private:
Image * image;
// Max number of sprites in the batch.
int size;
// The next free element.
int next;
vertex sprite[4];
// Current color. This color, if present, will be applied to the next
// added quad.
Color * color;
VertexBuffer *array_buf;
VertexBuffer *element_buf;
public:
enum UsageHint
{
USAGE_DYNAMIC = 1,
USAGE_STATIC,
USAGE_STREAM,
USAGE_MAX_ENUM
};
SpriteBatch(Image * image, int size, int usage);
virtual ~SpriteBatch();
int add(float x, float y, float a, float sx, float sy, float ox, float oy, float kx, float ky, int index = -1);
int addq(Quad * quad, float x, float y, float a, float sx, float sy, float ox, float oy, float kx, float ky, int index = -1);
void clear();
void * lock();
void unlock();
void setImage(Image * newimage);
/**
* Set the current color for this SpriteBatch. The geometry added
* after this call will use this color. Note that global color
* will not longer apply to the SpriteBatch if this is used.
*
* @param color The color to use for the following geometry.
*/
void setColor(const Color & color);
/**
* Disable per-quad colors for this SpriteBatch. The next call to
* draw will use the global color for all sprites.
*/
void setColor();
// Implements Drawable.
void draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const;
static bool getConstant(const char * in, UsageHint & out);
static bool getConstant(UsageHint in, const char *& out);
private:
void addv(const vertex * v, int index);
/**
* Set the color for vertices.
*
* @param v The vertices to set the color for. Must be an array of
* of size 4.
* @param color The color to assign to each vertex.
*/
void setColorv(vertex * v, const Color & color);
static StringMap<UsageHint, USAGE_MAX_ENUM>::Entry usageHintEntries[];
static StringMap<UsageHint, USAGE_MAX_ENUM> usageHints;
}; // SpriteBatch
} // opengl
} // graphics
} // love
#endif // LOVE_GRAPHICS_OPENGL_SPRITE_BATCH_H
/**
* Copyright (c) 2006-2011 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 <common/StringMap.h>
#include <graphics/Drawable.h>
#include <graphics/Volatile.h>
#include <graphics/Color.h>
// OpenGL
#include "GLee.h"
#include <SDL/SDL_opengl.h>
namespace love
{
namespace graphics
{
namespace opengl
{
// Forward declarations.
class Image;
class Quad;
class VertexBuffer;
class SpriteBatch : public Drawable
{
private:
Image * image;
// Max number of sprites in the batch.
int size;
// The next free element.
int next;
vertex sprite[4];
// Current color. This color, if present, will be applied to the next
// added quad.
Color * color;
VertexBuffer *array_buf;
VertexBuffer *element_buf;
public:
enum UsageHint
{
USAGE_DYNAMIC = 1,
USAGE_STATIC,
USAGE_STREAM,
USAGE_MAX_ENUM
};
SpriteBatch(Image * image, int size, int usage);
virtual ~SpriteBatch();
int add(float x, float y, float a, float sx, float sy, float ox, float oy, float kx, float ky, int index = -1);
int addq(Quad * quad, float x, float y, float a, float sx, float sy, float ox, float oy, float kx, float ky, int index = -1);
void clear();
void * lock();
void unlock();
void setImage(Image * newimage);
/**
* Set the current color for this SpriteBatch. The geometry added
* after this call will use this color. Note that global color
* will not longer apply to the SpriteBatch if this is used.
*
* @param color The color to use for the following geometry.
*/
void setColor(const Color & color);
/**
* Disable per-quad colors for this SpriteBatch. The next call to
* draw will use the global color for all sprites.
*/
void setColor();
// Implements Drawable.
void draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const;
static bool getConstant(const char * in, UsageHint & out);
static bool getConstant(UsageHint in, const char *& out);
private:
void addv(const vertex * v, int index);
/**
* Set the color for vertices.
*
* @param v The vertices to set the color for. Must be an array of
* of size 4.
* @param color The color to assign to each vertex.
*/
void setColorv(vertex * v, const Color & color);
static StringMap<UsageHint, USAGE_MAX_ENUM>::Entry usageHintEntries[];
static StringMap<UsageHint, USAGE_MAX_ENUM> usageHints;
}; // SpriteBatch
} // opengl
} // graphics
} // love
#endif // LOVE_GRAPHICS_OPENGL_SPRITE_BATCH_H
+6 -5
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -41,7 +41,8 @@ namespace opengl
// Try to create a VBO.
return new VBO(size, target, usage);
} catch (const love::Exception &e)
}
catch (const love::Exception &e)
{
(void)e;
@@ -196,7 +197,7 @@ namespace opengl
// Copy the old buffer only if 'restore' was requested.
const GLvoid *src = restore ? buffer_copy : 0;
// Note that if 'src' is '0', no data will be copied.
glBufferDataARB(getTarget(), getSize(), src, getUsage());
+271 -271
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -17,271 +17,271 @@
* 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 <graphics/Volatile.h>
// OpenGL
#include "GLee.h"
#include <SDL/SDL_opengl.h>
namespace love
{
namespace graphics
{
namespace opengl
{
/**
* VertexBuffer is an abstraction over VBOs (Vertex Buffer Objecys), which
* falls back to regular vertex arrays if VBOs are not supported.
*
* This allows code to take advantage of VBOs where available, but still
* work on older systems where it's *not* available. Everyone's happy.
*
* The class is (for now) meant for internal use.
*/
class VertexBuffer
{
public:
/**
* Create a new VertexBuffer (either a plain vertex array, or a VBO),
* based on what's supported on the system.
*
* If VBOs are not supported, a plain vertex array will automatically
* be created and returned instead.
*
* @param size The size of the VertexBuffer (in bytes).
* @param target GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER.
* @param usage GL_DYNAMIC_DRAW, etc.
* @return A new VertexBuffer.
*/
static VertexBuffer *Create(int size, GLenum target, GLenum usage);
/**
* Constructor.
*
* @param size The size of the VertexBuffer in bytes.
* @param target The target VertexBuffer object, e.g. GL_ARRAY_BUFFER.
* @param usage Usage hint, e.g. GL_DYNAMIC_DRAW.
*/
VertexBuffer(int size, GLenum target, GLenum usage);
/**
* Destructor. Does nothing, but must be declared virtual.
*/
virtual ~VertexBuffer();
/**
* Get the size of the VertexBuffer, in bytes.
*
* @return The size of the VertexBuffer.
*/
int getSize() const { return size; }
/**
* Get the target buffer object.
*
* @return The target buffer object, e.g. GL_ARRAY_BUFFER.
*/
GLenum getTarget() const { return target; }
/**
* Get the usage hint for this VertexBuffer.
*
* @return The usage hint, e.g. GL_DYNAMIC_DRAW.
*/
GLenum getUsage() const { return usage; }
/**
* Map the VertexBuffer to client memory.
*
* This can be faster for large changes to the buffer. For smaller
* changes, see fill().
*
* The VertexBuffer must be bound to use this function.
*
* @param access GL_READ_ONLY, GL_WRITE_ONLY, GL_READ_WRITE.
* @return A pointer to memory which represents the buffer.
*/
virtual void *map(GLenum access) = 0;
/**
* Unmap a previously mapped VertexBuffer. The buffer must be unmapped
* when used to draw elements.
*
* The VertexBuffer must be bound to use this function.
*/
virtual void unmap() = 0;
/**
* Bind the VertexBuffer to the specified target.
* (GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER).
*
* @param target GL_ARRAY_BUFFER or GL_ELEMENT_ARRAY_BUFFER.
*/
virtual void bind() = 0;
/**
* Unbind a prevously bound VertexBuffer.
*/
virtual void unbind() = 0;
/**
* Fill a portion of the buffer with data.
*
* The VertexBuffer must be bound to use this function.
*
* @param offset The offset in the VertexBuffer to store the data.
* @param size The size of the incoming data.
* @param data Pointer to memory to copy data from.
*/
virtual void fill(int offset, int size, const void *data) = 0;
/**
* Get a pointer which represents the specified byte offset.
*
* @param offset The byte offset. (0 is first byte).
* @return A pointer which represents the offset.
*/
virtual const void *getPointer(int offset) const = 0;
/**
* This helper class can bind a VertexArray temporarily, and
* automatically un-bind when it's destroyed.
*/
class Bind
{
public:
/**
* Bind a VertexBuffer.
*/
Bind(VertexBuffer &buf);
/**
* Unbinds a VertexBuffer.
*/
~Bind();
private:
// VertexBuffer to work on.
VertexBuffer &buf;
};
private:
// The size of the buffer, in bytes.
int size;
// The target buffer object. (GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER).
GLenum target;
// Usage hint. GL_[DYNAMIC, STATIC, STREAM]_DRAW.
GLenum usage;
};
/**
* Implementation of VertexBuffer which uses plain arrays to store the data.
*
* This implementation should be supported everywhere, and acts as a fallback
* on systems which do not support VBOs.
*/
class VertexArray : public VertexBuffer
{
public:
/**
* @copydoc VertexBuffer(int, GLenum, GLenum)
*/
VertexArray(int size, GLenum target, GLenum usage);
/**
* Frees the data we've allocated.
*/
virtual ~VertexArray();
// Implements VertexBuffer.
virtual void *map(GLenum access);
virtual void unmap();
virtual void bind();
virtual void unbind();
virtual void fill(int offset, int size, const void *data);
virtual const void *getPointer(int offset) const ;
private:
// Holds the data.
char *buf;
};
/**
* Vertex Buffer Object (VBO) implementation of VertexBuffer.
*
* This will be used on all systems that support it. It's in general
* faster than vertex arrays, but especially in use-cases where there
* is no need to update the data every frame.
*/
class VBO : public VertexBuffer, public Volatile
{
public:
/**
* @copydoc VertexBuffer(int, GLenum, GLenum)
*/
VBO(int size, GLenum target, GLenum usage);
/**
* Deletes the VBOs from OpenGL.
*/
virtual ~VBO();
// Implements VertexBuffer.
virtual void *map(GLenum access);
virtual void unmap();
virtual void bind();
virtual void unbind();
virtual void fill(int offset, int size, const void *data);
virtual const void *getPointer(int offset) const ;
// Implements Volatile.
bool loadVolatile();
void unloadVolatile();
private:
/**
* Creates the VBO, and optionally restores data we saved earlier.
*
* @param restore True to restore data previously saved with 'unload'.
* @return True on success, false otherwise.
*/
bool load(bool restore);
/**
* Optionally save the data in the VBO, then delete it.
*
* @param save True to save the data before deleting.
*/
void unload(bool save);
// The VBO identifier. Assigned by OpenGL.
GLuint vbo;
// *May* contain data saved by 'unload'.
char *buffer_copy;
// A pointer to mapped memory. Zero if memory is currently
// not mapped.
void *mapped;
};
} // opengl
} // graphics
} // love
#endif // LOVE_GRAPHICS_OPENGL_SPRITE_BATCH_H
#ifndef LOVE_GRAPHICS_OPENGL_VERTEX_BUFFER_H
#define LOVE_GRAPHICS_OPENGL_VERTEX_BUFFER_H
// LOVE
#include <graphics/Volatile.h>
// OpenGL
#include "GLee.h"
#include <SDL/SDL_opengl.h>
namespace love
{
namespace graphics
{
namespace opengl
{
/**
* VertexBuffer is an abstraction over VBOs (Vertex Buffer Objecys), which
* falls back to regular vertex arrays if VBOs are not supported.
*
* This allows code to take advantage of VBOs where available, but still
* work on older systems where it's *not* available. Everyone's happy.
*
* The class is (for now) meant for internal use.
*/
class VertexBuffer
{
public:
/**
* Create a new VertexBuffer (either a plain vertex array, or a VBO),
* based on what's supported on the system.
*
* If VBOs are not supported, a plain vertex array will automatically
* be created and returned instead.
*
* @param size The size of the VertexBuffer (in bytes).
* @param target GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER.
* @param usage GL_DYNAMIC_DRAW, etc.
* @return A new VertexBuffer.
*/
static VertexBuffer *Create(int size, GLenum target, GLenum usage);
/**
* Constructor.
*
* @param size The size of the VertexBuffer in bytes.
* @param target The target VertexBuffer object, e.g. GL_ARRAY_BUFFER.
* @param usage Usage hint, e.g. GL_DYNAMIC_DRAW.
*/
VertexBuffer(int size, GLenum target, GLenum usage);
/**
* Destructor. Does nothing, but must be declared virtual.
*/
virtual ~VertexBuffer();
/**
* Get the size of the VertexBuffer, in bytes.
*
* @return The size of the VertexBuffer.
*/
int getSize() const { return size; }
/**
* Get the target buffer object.
*
* @return The target buffer object, e.g. GL_ARRAY_BUFFER.
*/
GLenum getTarget() const { return target; }
/**
* Get the usage hint for this VertexBuffer.
*
* @return The usage hint, e.g. GL_DYNAMIC_DRAW.
*/
GLenum getUsage() const { return usage; }
/**
* Map the VertexBuffer to client memory.
*
* This can be faster for large changes to the buffer. For smaller
* changes, see fill().
*
* The VertexBuffer must be bound to use this function.
*
* @param access GL_READ_ONLY, GL_WRITE_ONLY, GL_READ_WRITE.
* @return A pointer to memory which represents the buffer.
*/
virtual void *map(GLenum access) = 0;
/**
* Unmap a previously mapped VertexBuffer. The buffer must be unmapped
* when used to draw elements.
*
* The VertexBuffer must be bound to use this function.
*/
virtual void unmap() = 0;
/**
* Bind the VertexBuffer to the specified target.
* (GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER).
*
* @param target GL_ARRAY_BUFFER or GL_ELEMENT_ARRAY_BUFFER.
*/
virtual void bind() = 0;
/**
* Unbind a prevously bound VertexBuffer.
*/
virtual void unbind() = 0;
/**
* Fill a portion of the buffer with data.
*
* The VertexBuffer must be bound to use this function.
*
* @param offset The offset in the VertexBuffer to store the data.
* @param size The size of the incoming data.
* @param data Pointer to memory to copy data from.
*/
virtual void fill(int offset, int size, const void *data) = 0;
/**
* Get a pointer which represents the specified byte offset.
*
* @param offset The byte offset. (0 is first byte).
* @return A pointer which represents the offset.
*/
virtual const void *getPointer(int offset) const = 0;
/**
* This helper class can bind a VertexArray temporarily, and
* automatically un-bind when it's destroyed.
*/
class Bind
{
public:
/**
* Bind a VertexBuffer.
*/
Bind(VertexBuffer &buf);
/**
* Unbinds a VertexBuffer.
*/
~Bind();
private:
// VertexBuffer to work on.
VertexBuffer &buf;
};
private:
// The size of the buffer, in bytes.
int size;
// The target buffer object. (GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER).
GLenum target;
// Usage hint. GL_[DYNAMIC, STATIC, STREAM]_DRAW.
GLenum usage;
};
/**
* Implementation of VertexBuffer which uses plain arrays to store the data.
*
* This implementation should be supported everywhere, and acts as a fallback
* on systems which do not support VBOs.
*/
class VertexArray : public VertexBuffer
{
public:
/**
* @copydoc VertexBuffer(int, GLenum, GLenum)
*/
VertexArray(int size, GLenum target, GLenum usage);
/**
* Frees the data we've allocated.
*/
virtual ~VertexArray();
// Implements VertexBuffer.
virtual void *map(GLenum access);
virtual void unmap();
virtual void bind();
virtual void unbind();
virtual void fill(int offset, int size, const void *data);
virtual const void *getPointer(int offset) const ;
private:
// Holds the data.
char *buf;
};
/**
* Vertex Buffer Object (VBO) implementation of VertexBuffer.
*
* This will be used on all systems that support it. It's in general
* faster than vertex arrays, but especially in use-cases where there
* is no need to update the data every frame.
*/
class VBO : public VertexBuffer, public Volatile
{
public:
/**
* @copydoc VertexBuffer(int, GLenum, GLenum)
*/
VBO(int size, GLenum target, GLenum usage);
/**
* Deletes the VBOs from OpenGL.
*/
virtual ~VBO();
// Implements VertexBuffer.
virtual void *map(GLenum access);
virtual void unmap();
virtual void bind();
virtual void unbind();
virtual void fill(int offset, int size, const void *data);
virtual const void *getPointer(int offset) const ;
// Implements Volatile.
bool loadVolatile();
void unloadVolatile();
private:
/**
* Creates the VBO, and optionally restores data we saved earlier.
*
* @param restore True to restore data previously saved with 'unload'.
* @return True on success, false otherwise.
*/
bool load(bool restore);
/**
* Optionally save the data in the VBO, then delete it.
*
* @param save True to save the data before deleting.
*/
void unload(bool save);
// The VBO identifier. Assigned by OpenGL.
GLuint vbo;
// *May* contain data saved by 'unload'.
char *buffer_copy;
// A pointer to mapped memory. Zero if memory is currently
// not mapped.
void *mapped;
};
} // opengl
} // graphics
} // love
#endif // LOVE_GRAPHICS_OPENGL_SPRITE_BATCH_H
+10 -4
View File
@@ -36,7 +36,8 @@ namespace opengl
{
// As startGrab() clears the framebuffer, better not allow
// grabbing inside another grabbing
if (Canvas::current != NULL) {
if (Canvas::current != NULL)
{
Canvas::bindDefaultCanvas();
return luaL_error(L, "Current render target not the default canvas!");
}
@@ -130,12 +131,15 @@ namespace opengl
{
Canvas * canvas = luax_checkcanvas(L, 1);
Color c;
if (lua_isnoneornil(L, 2)) {
if (lua_isnoneornil(L, 2))
{
c.r = 0;
c.g = 0;
c.b = 0;
c.a = 0;
} else if (lua_istable(L, 2)) {
}
else if (lua_istable(L, 2))
{
lua_pushinteger(L, 1);
lua_gettable(L, 2);
c.r = (unsigned char)luaL_checkint(L, -1);
@@ -149,7 +153,9 @@ namespace opengl
lua_gettable(L, 2);
c.g = (unsigned char)luaL_optint(L, -1, 255);
lua_pop(L, 4);
} else {
}
else
{
c.r = (unsigned char)luaL_checkint(L, 2);
c.g = (unsigned char)luaL_checkint(L, 3);
c.b = (unsigned char)luaL_checkint(L, 4);
+108 -108
View File
@@ -1,108 +1,108 @@
/**
* Copyright (c) 2006-2011 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
{
Font * luax_checkfont(lua_State * L, int idx)
{
return luax_checktype<Font>(L, idx, "Font", GRAPHICS_FONT_T);
}
int w_Font_getHeight(lua_State * L)
{
Font * t = luax_checkfont(L, 1);
lua_pushnumber(L, t->getHeight());
return 1;
}
int w_Font_getWidth(lua_State * L)
{
Font * t = luax_checkfont(L, 1);
const char * str = luaL_checkstring(L, 2);
try
{
lua_pushinteger(L, t->getWidth(str));
}
catch (love::Exception & e)
{
return luaL_error(L, e.what());
}
return 1;
}
int w_Font_getWrap(lua_State * L)
{
Font * t = luax_checkfont(L, 1);
const char * str = luaL_checkstring(L, 2);
float wrap = (float) luaL_checknumber(L, 3);
int max_width = 0, numlines = 0;
try
{
std::vector<std::string> lines = t->getWrap(str, wrap, &max_width);
numlines = lines.size();
}
catch (love::Exception & e)
{
return luaL_error(L, e.what());
}
lua_pushinteger(L, max_width);
lua_pushinteger(L, numlines);
return 2;
}
int w_Font_setLineHeight(lua_State * L)
{
Font * t = luax_checkfont(L, 1);
float h = (float)luaL_checknumber(L, 2);
t->setLineHeight(h);
return 0;
}
int w_Font_getLineHeight(lua_State * L)
{
Font * t = luax_checkfont(L, 1);
lua_pushnumber(L, t->getLineHeight());
return 1;
}
static const luaL_Reg functions[] = {
{ "getHeight", w_Font_getHeight },
{ "getWidth", w_Font_getWidth },
{ "getWrap", w_Font_getWrap },
{ "setLineHeight", w_Font_setLineHeight },
{ "getLineHeight", w_Font_getLineHeight },
{ 0, 0 }
};
int luaopen_font(lua_State * L)
{
return luax_register_type(L, "Font", functions);
}
} // opengl
} // graphics
} // love
/**
* Copyright (c) 2006-2011 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
{
Font * luax_checkfont(lua_State * L, int idx)
{
return luax_checktype<Font>(L, idx, "Font", GRAPHICS_FONT_T);
}
int w_Font_getHeight(lua_State * L)
{
Font * t = luax_checkfont(L, 1);
lua_pushnumber(L, t->getHeight());
return 1;
}
int w_Font_getWidth(lua_State * L)
{
Font * t = luax_checkfont(L, 1);
const char * str = luaL_checkstring(L, 2);
try
{
lua_pushinteger(L, t->getWidth(str));
}
catch (love::Exception & e)
{
return luaL_error(L, e.what());
}
return 1;
}
int w_Font_getWrap(lua_State * L)
{
Font * t = luax_checkfont(L, 1);
const char * str = luaL_checkstring(L, 2);
float wrap = (float) luaL_checknumber(L, 3);
int max_width = 0, numlines = 0;
try
{
std::vector<std::string> lines = t->getWrap(str, wrap, &max_width);
numlines = lines.size();
}
catch (love::Exception & e)
{
return luaL_error(L, e.what());
}
lua_pushinteger(L, max_width);
lua_pushinteger(L, numlines);
return 2;
}
int w_Font_setLineHeight(lua_State * L)
{
Font * t = luax_checkfont(L, 1);
float h = (float)luaL_checknumber(L, 2);
t->setLineHeight(h);
return 0;
}
int w_Font_getLineHeight(lua_State * L)
{
Font * t = luax_checkfont(L, 1);
lua_pushnumber(L, t->getLineHeight());
return 1;
}
static const luaL_Reg functions[] = {
{ "getHeight", w_Font_getHeight },
{ "getWidth", w_Font_getWidth },
{ "getWrap", w_Font_getWrap },
{ "setLineHeight", w_Font_setLineHeight },
{ "getLineHeight", w_Font_getLineHeight },
{ 0, 0 }
};
int luaopen_font(lua_State * L)
{
return luax_register_type(L, "Font", functions);
}
} // opengl
} // graphics
} // love
+46 -46
View File
@@ -1,46 +1,46 @@
/**
* Copyright (c) 2006-2011 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 w_Font_getHeight(lua_State * L);
int w_Font_getWidth(lua_State * L);
int w_Font_getWrap(lua_State * L);
int w_Font_setLineHeight(lua_State * L);
int w_Font_getLineHeight(lua_State * L);
int luaopen_font(lua_State * L);
} // opengl
} // graphics
} // love
#endif // LOVE_GRAPHICS_OPENGL_WRAP_FONT_H
/**
* Copyright (c) 2006-2011 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 w_Font_getHeight(lua_State * L);
int w_Font_getWidth(lua_State * L);
int w_Font_getWrap(lua_State * L);
int w_Font_setLineHeight(lua_State * L);
int w_Font_getLineHeight(lua_State * L);
int luaopen_font(lua_State * L);
} // opengl
} // graphics
} // love
#endif // LOVE_GRAPHICS_OPENGL_WRAP_FONT_H
+108 -68
View File
@@ -135,7 +135,7 @@ namespace opengl
int w_setScissor(lua_State * L)
{
if(lua_gettop(L) == 0)
if (lua_gettop(L) == 0)
{
instance->setScissor();
return 0;
@@ -170,7 +170,8 @@ namespace opengl
static int setStencil(lua_State * L, bool invert)
{
// no argument -> clear mask
if (lua_isnoneornil(L, 1)) {
if (lua_isnoneornil(L, 1))
{
instance->discardStencil();
return 0;
}
@@ -198,24 +199,27 @@ namespace opengl
int w_newImage(lua_State * L)
{
// Convert to File, if necessary.
if(lua_isstring(L, 1))
if (lua_isstring(L, 1))
luax_convobj(L, 1, "filesystem", "newFile");
// Convert to ImageData, if necessary.
if(luax_istype(L, 1, FILESYSTEM_FILE_T))
if (luax_istype(L, 1, FILESYSTEM_FILE_T))
luax_convobj(L, 1, "image", "newImageData");
love::image::ImageData * data = luax_checktype<love::image::ImageData>(L, 1, "ImageData", IMAGE_IMAGE_DATA_T);
// Create the image.
Image * image = 0;
try {
try
{
image = instance->newImage(data);
} catch (love::Exception & e) {
}
catch (love::Exception & e)
{
luaL_error(L, e.what());
}
if(image == 0)
if (image == 0)
return luaL_error(L, "Could not load image.");
@@ -247,16 +251,19 @@ namespace opengl
{
Data * font_data = NULL;
// Convert to File, if necessary.
if(lua_isstring(L, 1))
if (lua_isstring(L, 1))
luax_convobj(L, 1, "filesystem", "newFile");
// Convert to Data, if necessary.
if(luax_istype(L, 1, FILESYSTEM_FILE_T)) {
if (luax_istype(L, 1, FILESYSTEM_FILE_T))
{
love::filesystem::File * f = luax_checktype<love::filesystem::File>(L, 1, "File", FILESYSTEM_FILE_T);
try {
try
{
font_data = f->read();
}
catch (love::Exception & e) {
catch (love::Exception & e)
{
return luaL_error(L, e.what());
}
lua_remove(L, 1); // get rid of the file
@@ -265,7 +272,8 @@ namespace opengl
}
// Convert to Rasterizer, if necessary.
if(luax_istype(L, 1, DATA_T)) {
if (luax_istype(L, 1, DATA_T))
{
int idxs[] = {1, 2};
luax_convobj(L, idxs, 2, "font", "newRasterizer");
}
@@ -278,7 +286,7 @@ namespace opengl
// Create the font.
Font * font = instance->newFont(rasterizer);
if(font == 0)
if (font == 0)
return luaL_error(L, "Could not load font.");
// Push the type.
@@ -293,9 +301,10 @@ namespace opengl
Image::Filter img_filter;
// Convert to ImageData if necessary.
if(lua_isstring(L, 1) || luax_istype(L, 1, FILESYSTEM_FILE_T) || (luax_istype(L, 1, DATA_T) && !luax_istype(L, 1, IMAGE_IMAGE_DATA_T)))
if (lua_isstring(L, 1) || luax_istype(L, 1, FILESYSTEM_FILE_T) || (luax_istype(L, 1, DATA_T) && !luax_istype(L, 1, IMAGE_IMAGE_DATA_T)))
luax_convobj(L, 1, "image", "newImageData");
else if(luax_istype(L, 1, GRAPHICS_IMAGE_T)) {
else if (luax_istype(L, 1, GRAPHICS_IMAGE_T))
{
Image * i = luax_checktype<Image>(L, 1, "Image", GRAPHICS_IMAGE_T);
img_filter = i->getFilter();
love::image::ImageData * id = i->getData();
@@ -304,7 +313,8 @@ namespace opengl
}
// Convert to Rasterizer if necessary.
if(luax_istype(L, 1, IMAGE_IMAGE_DATA_T)) {
if (luax_istype(L, 1, IMAGE_IMAGE_DATA_T))
{
int idxs[] = {1, 2};
luax_convobj(L, idxs, 2, "font", "newRasterizer");
}
@@ -314,7 +324,7 @@ namespace opengl
// Create the font.
Font * font = instance->newFont(rasterizer, img_filter);
if(font == 0)
if (font == 0)
return luaL_error(L, "Could not load font.");
// Push the type.
@@ -334,9 +344,12 @@ namespace opengl
usage = SpriteBatch::USAGE_DYNAMIC;
}
SpriteBatch * t = NULL;
try {
try
{
t = instance->newSpriteBatch(image, size, usage);
} catch(love::Exception& e) {
}
catch (love::Exception& e)
{
return luaL_error(L, e.what());
}
luax_newtype(L, "SpriteBatch", GRAPHICS_SPRITE_BATCH_T, (void*)t);
@@ -360,9 +373,12 @@ namespace opengl
glGetError(); // clear opengl error flag
Canvas * canvas = NULL;
try {
try
{
canvas = instance->newCanvas(width, height);
} catch (Exception& e) {
}
catch (Exception& e)
{
return luaL_error(L, e.what());
}
@@ -378,7 +394,8 @@ namespace opengl
if (!PixelEffect::isSupported())
return luaL_error(L, "Sorry, your graphics card does not support pixel effects.");
try {
try
{
luaL_checkstring(L, 1);
luax_getfunction(L, "graphics", "_effectCodeToGLSL");
@@ -388,7 +405,9 @@ namespace opengl
const char* code = lua_tostring(L, -1);
PixelEffect * effect = instance->newPixelEffect(code);
luax_newtype(L, "PixelEffect", GRAPHICS_PIXELEFFECT_T, (void*)effect);
} catch (const love::Exception& e) {
}
catch (const love::Exception& e)
{
// memory is freed in Graphics::newPixelEffect
luax_getfunction(L, "graphics", "_transformGLSLErrorMessages");
lua_pushstring(L, e.what());
@@ -403,7 +422,8 @@ namespace opengl
int w_setColor(lua_State * L)
{
Color c;
if (lua_istable(L, 1)) {
if (lua_istable(L, 1))
{
lua_pushinteger(L, 1);
lua_gettable(L, -2);
c.r = (unsigned char)luaL_checkint(L, -1);
@@ -445,7 +465,8 @@ namespace opengl
int w_setBackgroundColor(lua_State * L)
{
Color c;
if (lua_istable(L, 1)) {
if (lua_istable(L, 1))
{
lua_pushinteger(L, 1);
lua_gettable(L, -2);
c.r = (unsigned char)luaL_checkint(L, -1);
@@ -494,21 +515,26 @@ namespace opengl
bool created = false;
// If the first parameter isn't a Font, create a new one
if (!luax_istype(L, 1, GRAPHICS_FONT_T)) {
if (!luax_istype(L, 1, GRAPHICS_FONT_T))
{
created = true;
lua_pushinteger(L, size); // push the size
lua_insert(L, 2); // move it to its proper place
// Convert to File, if necessary.
if(lua_isstring(L, 1))
if (lua_isstring(L, 1))
luax_convobj(L, 1, "filesystem", "newFile");
// Convert to Data, if necessary.
if(luax_istype(L, 1, FILESYSTEM_FILE_T)) {
if (luax_istype(L, 1, FILESYSTEM_FILE_T))
{
love::filesystem::File * f = luax_checktype<love::filesystem::File>(L, 1, "File", FILESYSTEM_FILE_T);
Data * d;
try {
try
{
d = f->read();
} catch (love::Exception & e) {
}
catch (love::Exception & e)
{
return luaL_error(L, e.what());
}
lua_remove(L, 1); // get rid of the file
@@ -517,7 +543,8 @@ namespace opengl
}
// Convert to Rasterizer, if necessary.
if(luax_istype(L, 1, DATA_T)) {
if (luax_istype(L, 1, DATA_T))
{
int idxs[] = {1, 2};
luax_convobj(L, idxs, 2, "font", "newRasterizer");
}
@@ -527,7 +554,7 @@ namespace opengl
// Create the font.
font = instance->newFont(rasterizer);
if(font == 0)
if (font == 0)
return luaL_error(L, "Could not load font.");
}
else font = luax_checktype<Font>(L, 1, "Font", GRAPHICS_FONT_T);
@@ -541,7 +568,7 @@ namespace opengl
{
Font * f = instance->getFont();
if(f == 0)
if (f == 0)
return 0;
f->retain();
@@ -553,7 +580,7 @@ namespace opengl
{
Graphics::BlendMode mode;
const char * str = luaL_checkstring(L, 1);
if(!Graphics::getConstant(str, mode))
if (!Graphics::getConstant(str, mode))
return luaL_error(L, "Invalid blend mode: %s", str);
instance->setBlendMode(mode);
@@ -564,7 +591,7 @@ namespace opengl
{
Graphics::ColorMode mode;
const char * str = luaL_checkstring(L, 1);
if(!Graphics::getConstant(str, mode))
if (!Graphics::getConstant(str, mode))
return luaL_error(L, "Invalid color mode: %s", str);
instance->setColorMode(mode);
@@ -594,7 +621,7 @@ namespace opengl
{
Graphics::BlendMode mode = instance->getBlendMode();
const char * str;
if(!Graphics::getConstant(mode, str))
if (!Graphics::getConstant(mode, str))
return luaL_error(L, "Invalid blend mode: %s", str);
lua_pushstring(L, str);
@@ -605,7 +632,7 @@ namespace opengl
{
Graphics::ColorMode mode = instance->getColorMode();
const char * str;
if(!Graphics::getConstant(mode, str))
if (!Graphics::getConstant(mode, str))
return luaL_error(L, "Invalid color mode: %s", str);
lua_pushstring(L, str);
@@ -635,7 +662,7 @@ namespace opengl
{
Graphics::LineStyle style;
const char * str = luaL_checkstring(L, 1);
if(!Graphics::getConstant(str, style))
if (!Graphics::getConstant(str, style))
return luaL_error(L, "Invalid line style: %s", str);
instance->setLineStyle(style);
@@ -648,10 +675,10 @@ namespace opengl
Graphics::LineStyle style = Graphics::LINE_SMOOTH;
if(lua_gettop(L) >= 2)
if (lua_gettop(L) >= 2)
{
const char * str = luaL_checkstring(L, 2);
if(!Graphics::getConstant(str, style))
if (!Graphics::getConstant(str, style))
return luaL_error(L, "Invalid line style: %s", str);
}
@@ -685,10 +712,10 @@ namespace opengl
{
Graphics::PointStyle style = Graphics::POINT_SMOOTH;
if(lua_gettop(L) >= 2)
if (lua_gettop(L) >= 2)
{
const char * str = luaL_checkstring(L, 1);
if(!Graphics::getConstant(str, style))
if (!Graphics::getConstant(str, style))
return luaL_error(L, "Invalid point style: %s", str);
}
@@ -702,7 +729,7 @@ namespace opengl
Graphics::PointStyle style;
const char * str = luaL_checkstring(L, 2);
if(!Graphics::getConstant(str, style))
if (!Graphics::getConstant(str, style))
return luaL_error(L, "Invalid point style: %s", str);
instance->setPoint(size, style);
@@ -738,7 +765,8 @@ namespace opengl
int w_setRenderTarget(lua_State * L)
{
// called with nil or none -> reset to default buffer
if (lua_isnoneornil(L,1)) {
if (lua_isnoneornil(L,1))
{
Canvas::bindDefaultCanvas();
return 0;
}
@@ -753,7 +781,8 @@ namespace opengl
int w_getRenderTarget(lua_State * L)
{
Canvas *canvas = Canvas::current;
if (canvas) {
if (canvas)
{
canvas->retain();
luax_newtype(L, "Canvas", GRAPHICS_CANVAS_T, (void*) canvas);
}
@@ -764,7 +793,8 @@ namespace opengl
int w_setPixelEffect(lua_State * L)
{
if (lua_isnoneornil(L,1)) {
if (lua_isnoneornil(L,1))
{
PixelEffect::detach();
return 0;
}
@@ -782,7 +812,7 @@ namespace opengl
for (unsigned int i = 1; i <= len; i++)
{
const char * str = luaL_checkstring(L, i);
if(!Graphics::getConstant(str, support))
if (!Graphics::getConstant(str, support))
supported = false;
switch(support)
{
@@ -915,10 +945,10 @@ namespace opengl
Graphics::AlignMode align = Graphics::ALIGN_LEFT;
if(lua_gettop(L) >= 5)
if (lua_gettop(L) >= 5)
{
const char * str = luaL_checkstring(L, 5);
if(!Graphics::getConstant(str, align))
if (!Graphics::getConstant(str, align))
return luaL_error(L, "Incorrect alignment: %s", str);
}
@@ -945,7 +975,8 @@ namespace opengl
{
int args = lua_gettop(L);
bool is_table = false;
if (args == 1 && lua_istable(L, 1)) {
if (args == 1 && lua_istable(L, 1))
{
args = lua_objlen(L, 1);
is_table = true;
}
@@ -955,14 +986,18 @@ namespace opengl
return luaL_error(L, "Need at least two vertices to draw a line");
float* coords = new float[args];
if (is_table) {
for (int i = 0; i < args; ++i) {
if (is_table)
{
for (int i = 0; i < args; ++i)
{
lua_pushnumber(L, i + 1);
lua_rawget(L, 1);
coords[i] = luax_tofloat(L, -1);
lua_pop(L, 1);
}
} else {
}
else
{
for (int i = 0; i < args; ++i)
coords[i] = luax_tofloat(L, i + 1);
}
@@ -977,7 +1012,7 @@ namespace opengl
{
Graphics::DrawMode mode;
const char * str = luaL_checkstring(L, 1);
if(!Graphics::getConstant(str, mode))
if (!Graphics::getConstant(str, mode))
return luaL_error(L, "Incorrect draw mode %s", str);
float x1 = (float)luaL_checknumber(L, 2);
@@ -994,7 +1029,7 @@ namespace opengl
{
Graphics::DrawMode mode;
const char * str = luaL_checkstring(L, 1);
if(!Graphics::getConstant(str, mode))
if (!Graphics::getConstant(str, mode))
return luaL_error(L, "Incorrect draw mode %s", str);
float x = (float)luaL_checknumber(L, 2);
@@ -1009,7 +1044,7 @@ namespace opengl
{
Graphics::DrawMode mode;
const char * str = luaL_checkstring(L, 1);
if(!Graphics::getConstant(str, mode))
if (!Graphics::getConstant(str, mode))
return luaL_error(L, "Incorrect draw mode %s", str);
float x1 = (float)luaL_checknumber(L, 2);
@@ -1028,7 +1063,7 @@ namespace opengl
{
Graphics::DrawMode mode;
const char * str = luaL_checkstring(L, 1);
if(!Graphics::getConstant(str, mode))
if (!Graphics::getConstant(str, mode))
return luaL_error(L, "Incorrect draw mode %s", str);
float x = (float)luaL_checknumber(L, 2);
@@ -1042,14 +1077,14 @@ namespace opengl
instance->circle(mode, x, y, radius, points);
return 0;
}
int w_arc(lua_State * L)
{
Graphics::DrawMode mode;
const char * str = luaL_checkstring(L, 1);
if(!Graphics::getConstant(str, mode))
if (!Graphics::getConstant(str, mode))
return luaL_error(L, "Incorrect draw mode %s", str);
float x = (float)luaL_checknumber(L, 2);
float y = (float)luaL_checknumber(L, 3);
float radius = (float)luaL_checknumber(L, 4);
@@ -1066,12 +1101,13 @@ namespace opengl
Graphics::DrawMode mode;
const char * str = luaL_checkstring(L, 1);
if(!Graphics::getConstant(str, mode))
if (!Graphics::getConstant(str, mode))
return luaL_error(L, "Invalid draw mode: %s", str);
bool is_table = false;
float* coords;
if (args == 1 && lua_istable(L, 2)) {
if (args == 1 && lua_istable(L, 2))
{
args = lua_objlen(L, 2);
is_table = true;
}
@@ -1083,14 +1119,18 @@ namespace opengl
// fetch coords
coords = new float[args + 2];
if (is_table) {
for (int i = 0; i < args; ++i) {
if (is_table)
{
for (int i = 0; i < args; ++i)
{
lua_pushnumber(L, i + 1);
lua_rawget(L, 2);
coords[i] = luax_tofloat(L, -1);
lua_pop(L, 1);
}
} else {
}
else
{
for (int i = 0; i < args; ++i)
coords[i] = luax_tofloat(L, i + 2);
}
@@ -1100,7 +1140,7 @@ namespace opengl
coords[args+1] = coords[1];
instance->polygon(mode, coords, args+2);
delete[] coords;
return 0;
}
@@ -1282,13 +1322,13 @@ namespace opengl
int luaopen_love_graphics(lua_State * L)
{
if(instance == 0)
if (instance == 0)
{
try
{
instance = new Graphics();
}
catch(Exception & e)
catch (Exception & e)
{
return luaL_error(L, e.what());
}
+121 -121
View File
@@ -1,121 +1,121 @@
/**
* Copyright (c) 2006-2011 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_Font.h"
#include "wrap_Image.h"
#include "wrap_Quad.h"
#include "wrap_SpriteBatch.h"
#include "wrap_ParticleSystem.h"
#include "wrap_Canvas.h"
#include "wrap_PixelEffect.h"
#include "Graphics.h"
namespace love
{
namespace graphics
{
namespace opengl
{
int w_checkMode(lua_State * L);
int w_setMode(lua_State * L);
int w_getMode(lua_State * L);
int w_toggleFullscreen(lua_State * L);
int w_reset(lua_State * L);
int w_clear(lua_State * L);
int w_present(lua_State * L);
int w_setIcon(lua_State * L);
int w_setCaption(lua_State * L);
int w_getCaption(lua_State * L);
int w_getWidth(lua_State * L);
int w_getHeight(lua_State * L);
int w_isCreated(lua_State * L);
int w_setScissor(lua_State * L);
int w_getScissor(lua_State * L);
int w_defineMask(lua_State * L);
int w_setMask(lua_State * L);
int w_newImage(lua_State * L);
int w_newQuad(lua_State * L);
int w_newFrame(lua_State * L);
int w_newFont1(lua_State * L);
int w_newImageFont(lua_State * L);
int w_newSpriteBatch(lua_State * L);
int w_newParticleSystem(lua_State * L);
int w_newCanvas(lua_State * L); // comments in function
int w_newPixelEffect(lua_State * L);
int w_setColor(lua_State * L);
int w_getColor(lua_State * L);
int w_setBackgroundColor(lua_State * L);
int w_getBackgroundColor(lua_State * L);
int w_setFont1(lua_State * L);
int w_getFont(lua_State * L);
int w_setBlendMode(lua_State * L);
int w_setColorMode(lua_State * L);
int w_setDefaultImageFilter(lua_State * L);
int w_getBlendMode(lua_State * L);
int w_getColorMode(lua_State * L);
int w_getDefaultImageFilter(lua_State * L);
int w_setLineWidth(lua_State * L);
int w_setLineStyle(lua_State * L);
int w_setLine(lua_State * L);
int w_setLineStipple(lua_State * L);
int w_getLineWidth(lua_State * L);
int w_getLineStyle(lua_State * L);
int w_getLineStipple(lua_State * L);
int w_setPointSize(lua_State * L);
int w_setPointStyle(lua_State * L);
int w_setPoint(lua_State * L);
int w_getPointSize(lua_State * L);
int w_getPointStyle(lua_State * L);
int w_getMaxPointSize(lua_State * L);
int w_newScreenshot(lua_State * L);
int w_setRenderTarget(lua_State * L);
int w_getRenderTarget(lua_State * L);
int w_setPixelEffect(lua_State * L);
int w_isSupported(lua_State * L);
int w_draw(lua_State * L);
int w_drawq(lua_State * L);
int w_drawTest(lua_State * L);
int w_print1(lua_State * L);
int w_printf1(lua_State * L);
int w_point(lua_State * L);
int w_line(lua_State * L);
int w_triangle(lua_State * L);
int w_rectangle(lua_State * L);
int w_quad(lua_State * L);
int w_circle(lua_State * L);
int w_arc(lua_State * L);
int w_push(lua_State * L);
int w_pop(lua_State * L);
int w_rotate(lua_State * L);
int w_scale(lua_State * L);
int w_translate(lua_State * L);
int w_shear(lua_State * L);
int w_hasFocus(lua_State * L);
extern "C" LOVE_EXPORT int luaopen_love_graphics(lua_State * L);
} // opengl
} // graphics
} // love
#endif // LOVE_GRAPHICS_OPENGL_WRAP_GRAPHICS_H
/**
* Copyright (c) 2006-2011 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_Font.h"
#include "wrap_Image.h"
#include "wrap_Quad.h"
#include "wrap_SpriteBatch.h"
#include "wrap_ParticleSystem.h"
#include "wrap_Canvas.h"
#include "wrap_PixelEffect.h"
#include "Graphics.h"
namespace love
{
namespace graphics
{
namespace opengl
{
int w_checkMode(lua_State * L);
int w_setMode(lua_State * L);
int w_getMode(lua_State * L);
int w_toggleFullscreen(lua_State * L);
int w_reset(lua_State * L);
int w_clear(lua_State * L);
int w_present(lua_State * L);
int w_setIcon(lua_State * L);
int w_setCaption(lua_State * L);
int w_getCaption(lua_State * L);
int w_getWidth(lua_State * L);
int w_getHeight(lua_State * L);
int w_isCreated(lua_State * L);
int w_setScissor(lua_State * L);
int w_getScissor(lua_State * L);
int w_defineMask(lua_State * L);
int w_setMask(lua_State * L);
int w_newImage(lua_State * L);
int w_newQuad(lua_State * L);
int w_newFrame(lua_State * L);
int w_newFont1(lua_State * L);
int w_newImageFont(lua_State * L);
int w_newSpriteBatch(lua_State * L);
int w_newParticleSystem(lua_State * L);
int w_newCanvas(lua_State * L); // comments in function
int w_newPixelEffect(lua_State * L);
int w_setColor(lua_State * L);
int w_getColor(lua_State * L);
int w_setBackgroundColor(lua_State * L);
int w_getBackgroundColor(lua_State * L);
int w_setFont1(lua_State * L);
int w_getFont(lua_State * L);
int w_setBlendMode(lua_State * L);
int w_setColorMode(lua_State * L);
int w_setDefaultImageFilter(lua_State * L);
int w_getBlendMode(lua_State * L);
int w_getColorMode(lua_State * L);
int w_getDefaultImageFilter(lua_State * L);
int w_setLineWidth(lua_State * L);
int w_setLineStyle(lua_State * L);
int w_setLine(lua_State * L);
int w_setLineStipple(lua_State * L);
int w_getLineWidth(lua_State * L);
int w_getLineStyle(lua_State * L);
int w_getLineStipple(lua_State * L);
int w_setPointSize(lua_State * L);
int w_setPointStyle(lua_State * L);
int w_setPoint(lua_State * L);
int w_getPointSize(lua_State * L);
int w_getPointStyle(lua_State * L);
int w_getMaxPointSize(lua_State * L);
int w_newScreenshot(lua_State * L);
int w_setRenderTarget(lua_State * L);
int w_getRenderTarget(lua_State * L);
int w_setPixelEffect(lua_State * L);
int w_isSupported(lua_State * L);
int w_draw(lua_State * L);
int w_drawq(lua_State * L);
int w_drawTest(lua_State * L);
int w_print1(lua_State * L);
int w_printf1(lua_State * L);
int w_point(lua_State * L);
int w_line(lua_State * L);
int w_triangle(lua_State * L);
int w_rectangle(lua_State * L);
int w_quad(lua_State * L);
int w_circle(lua_State * L);
int w_arc(lua_State * L);
int w_push(lua_State * L);
int w_pop(lua_State * L);
int w_rotate(lua_State * L);
int w_scale(lua_State * L);
int w_translate(lua_State * L);
int w_shear(lua_State * L);
int w_hasFocus(lua_State * L);
extern "C" LOVE_EXPORT int luaopen_love_graphics(lua_State * L);
} // opengl
} // graphics
} // love
#endif // LOVE_GRAPHICS_OPENGL_WRAP_GRAPHICS_H
+134 -134
View File
@@ -1,134 +1,134 @@
/**
* Copyright (c) 2006-2011 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", GRAPHICS_IMAGE_T);
}
int w_Image_getWidth(lua_State * L)
{
Image * t = luax_checkimage(L, 1);
lua_pushnumber(L, t->getWidth());
return 1;
}
int w_Image_getHeight(lua_State * L)
{
Image * t = luax_checkimage(L, 1);
lua_pushnumber(L, t->getHeight());
return 1;
}
int w_Image_setFilter(lua_State * L)
{
Image * t = luax_checkimage(L, 1);
Image::Filter f;
Image::FilterMode min;
Image::FilterMode mag;
const char * minstr = luaL_checkstring(L, 2);
const char * magstr = luaL_checkstring(L, 3);
if (!Image::getConstant(minstr, min))
return luaL_error(L, "Invalid filter mode: %s", minstr);
if (!Image::getConstant(magstr, mag))
return luaL_error(L, "Invalid filter mode: %s", magstr);
f.min = min;
f.mag = mag;
t->setFilter(f);
return 0;
}
int w_Image_getFilter(lua_State * L)
{
Image * t = luax_checkimage(L, 1);
Image::Filter f = t->getFilter();
Image::FilterMode min = f.min;
Image::FilterMode mag = f.mag;
const char * minstr;
const char * magstr;
Image::getConstant(min, minstr);
Image::getConstant(mag, magstr);
lua_pushstring(L, minstr);
lua_pushstring(L, magstr);
return 2;
}
int w_Image_setWrap(lua_State * L)
{
Image * i = luax_checkimage(L, 1);
Image::Wrap w;
Image::WrapMode s;
Image::WrapMode t;
const char * sstr = luaL_checkstring(L, 2);
const char * tstr = luaL_checkstring(L, 3);
if (!Image::getConstant(sstr, s))
return luaL_error(L, "Invalid wrap mode: %s", sstr);
if (!Image::getConstant(tstr, t))
return luaL_error(L, "Invalid wrap mode, %s", tstr);
w.s = s;
w.t = t;
i->setWrap(w);
return 0;
}
int w_Image_getWrap(lua_State * L)
{
Image * i = luax_checkimage(L, 1);
Image::Wrap w = i->getWrap();
Image::WrapMode s = w.s;
Image::WrapMode t = w.t;
const char * sstr;
const char * tstr;
Image::getConstant(s, sstr);
Image::getConstant(t, tstr);
lua_pushstring(L, sstr);
lua_pushstring(L, tstr);
return 2;
}
static const luaL_Reg functions[] = {
{ "getWidth", w_Image_getWidth },
{ "getHeight", w_Image_getHeight },
{ "setFilter", w_Image_setFilter },
{ "getFilter", w_Image_getFilter },
{ "setWrap", w_Image_setWrap },
{ "getWrap", w_Image_getWrap },
{ 0, 0 }
};
int luaopen_image(lua_State * L)
{
return luax_register_type(L, "Image", functions);
}
} // opengl
} // graphics
} // love
/**
* Copyright (c) 2006-2011 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", GRAPHICS_IMAGE_T);
}
int w_Image_getWidth(lua_State * L)
{
Image * t = luax_checkimage(L, 1);
lua_pushnumber(L, t->getWidth());
return 1;
}
int w_Image_getHeight(lua_State * L)
{
Image * t = luax_checkimage(L, 1);
lua_pushnumber(L, t->getHeight());
return 1;
}
int w_Image_setFilter(lua_State * L)
{
Image * t = luax_checkimage(L, 1);
Image::Filter f;
Image::FilterMode min;
Image::FilterMode mag;
const char * minstr = luaL_checkstring(L, 2);
const char * magstr = luaL_checkstring(L, 3);
if (!Image::getConstant(minstr, min))
return luaL_error(L, "Invalid filter mode: %s", minstr);
if (!Image::getConstant(magstr, mag))
return luaL_error(L, "Invalid filter mode: %s", magstr);
f.min = min;
f.mag = mag;
t->setFilter(f);
return 0;
}
int w_Image_getFilter(lua_State * L)
{
Image * t = luax_checkimage(L, 1);
Image::Filter f = t->getFilter();
Image::FilterMode min = f.min;
Image::FilterMode mag = f.mag;
const char * minstr;
const char * magstr;
Image::getConstant(min, minstr);
Image::getConstant(mag, magstr);
lua_pushstring(L, minstr);
lua_pushstring(L, magstr);
return 2;
}
int w_Image_setWrap(lua_State * L)
{
Image * i = luax_checkimage(L, 1);
Image::Wrap w;
Image::WrapMode s;
Image::WrapMode t;
const char * sstr = luaL_checkstring(L, 2);
const char * tstr = luaL_checkstring(L, 3);
if (!Image::getConstant(sstr, s))
return luaL_error(L, "Invalid wrap mode: %s", sstr);
if (!Image::getConstant(tstr, t))
return luaL_error(L, "Invalid wrap mode, %s", tstr);
w.s = s;
w.t = t;
i->setWrap(w);
return 0;
}
int w_Image_getWrap(lua_State * L)
{
Image * i = luax_checkimage(L, 1);
Image::Wrap w = i->getWrap();
Image::WrapMode s = w.s;
Image::WrapMode t = w.t;
const char * sstr;
const char * tstr;
Image::getConstant(s, sstr);
Image::getConstant(t, tstr);
lua_pushstring(L, sstr);
lua_pushstring(L, tstr);
return 2;
}
static const luaL_Reg functions[] = {
{ "getWidth", w_Image_getWidth },
{ "getHeight", w_Image_getHeight },
{ "setFilter", w_Image_setFilter },
{ "getFilter", w_Image_getFilter },
{ "setWrap", w_Image_setWrap },
{ "getWrap", w_Image_getWrap },
{ 0, 0 }
};
int luaopen_image(lua_State * L)
{
return luax_register_type(L, "Image", functions);
}
} // opengl
} // graphics
} // love
+44 -44
View File
@@ -1,44 +1,44 @@
/**
* Copyright (c) 2006-2011 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 w_Image_getWidth(lua_State * L);
int w_Image_getHeight(lua_State * L);
int w_Image_setFilter(lua_State * L);
int luaopen_image(lua_State * L);
} // opengl
} // graphics
} // love
#endif // LOVE_GRAPHICS_OPENGL_WRAP_IMAGE_H
/**
* Copyright (c) 2006-2011 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 w_Image_getWidth(lua_State * L);
int w_Image_getHeight(lua_State * L);
int w_Image_setFilter(lua_State * L);
int luaopen_image(lua_State * L);
} // opengl
} // graphics
} // love
#endif // LOVE_GRAPHICS_OPENGL_WRAP_IMAGE_H
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -151,9 +151,12 @@ namespace opengl
if (nSizes > 8)
return luaL_error(L, "At most eight (8) sizes may be used.");
if (nSizes == 1) {
if (nSizes == 1)
{
t->setSize(luax_checkfloat(L, 2));
} else {
}
else
{
std::vector<float> sizes(nSizes);
for (size_t i = 0; i < nSizes; ++i)
sizes[i] = luax_checkfloat(L, 1 + i + 1);
@@ -206,14 +209,18 @@ namespace opengl
if (nColors > 8)
return luaL_error(L, "At most eight (8) colors may be used.");
if (nColors == 1) {
if (nColors == 1)
{
t->setColor(Color(luaL_checkint(L,2),
luaL_checkint(L,3),
luaL_checkint(L,4),
luaL_checkint(L,5)));
} else {
}
else
{
std::vector<Color> colors(nColors);
for (size_t i = 0; i < nColors; ++i) {
for (size_t i = 0; i < nColors; ++i)
{
colors[i] = Color(luaL_checkint(L, 1 + i*4 + 1),
luaL_checkint(L, 1 + i*4 + 2),
luaL_checkint(L, 1 + i*4 + 3),
@@ -224,7 +231,7 @@ namespace opengl
return 0;
}
int w_ParticleSystem_setOffset(lua_State * L)
{
ParticleSystem * t = luax_checkparticlesystem(L, 1);
@@ -261,21 +268,21 @@ namespace opengl
lua_pushnumber(L, t->getSpread());
return 1;
}
int w_ParticleSystem_getOffsetX(lua_State * L)
{
ParticleSystem * t = luax_checkparticlesystem(L, 1);
lua_pushnumber(L, t->getOffsetX());
return 1;
}
int w_ParticleSystem_getOffsetY(lua_State * L)
{
ParticleSystem * t = luax_checkparticlesystem(L, 1);
lua_pushnumber(L, t->getOffsetY());
return 1;
}
int w_ParticleSystem_count(lua_State * L)
{
ParticleSystem * t = luax_checkparticlesystem(L, 1);
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -46,17 +46,22 @@ namespace opengl
static int _sendScalars(lua_State * L, PixelEffect * effect, const char * name, int count)
{
float * values = new float[count];
for (int i = 0; i < count; ++i) {
if (!lua_isnumber(L, 3 + i)) {
for (int i = 0; i < count; ++i)
{
if (!lua_isnumber(L, 3 + i))
{
delete[] values;
return luaL_typerror(L, 3 + i, "number");
}
values[i] = (float)lua_tonumber(L, 3 + i);
}
try {
try
{
effect->sendFloat(name, 1, values, count);
} catch(love::Exception& e) {
}
catch (love::Exception& e)
{
delete[] values;
return luaL_error(L, e.what());
}
@@ -70,12 +75,15 @@ namespace opengl
size_t dimension = lua_objlen(L, 3);
float * values = new float[count * dimension];
for (int i = 0; i < count; ++i) {
if (!lua_istable(L, 3 + i)) {
for (int i = 0; i < count; ++i)
{
if (!lua_istable(L, 3 + i))
{
delete[] values;
return luaL_typerror(L, 3 + i, "table");
}
if (lua_objlen(L, 3 + i) != dimension) {
if (lua_objlen(L, 3 + i) != dimension)
{
delete[] values;
return luaL_error(L, "Error in argument %d: Expected table size %d, got %d.",
3+i, dimension, lua_objlen(L, 3+i));
@@ -88,9 +96,12 @@ namespace opengl
lua_pop(L, dimension);
}
try {
try
{
effect->sendFloat(name, dimension, values, count);
} catch(love::Exception& e) {
}
catch (love::Exception& e)
{
delete[] values;
return luaL_error(L, e.what());
}
@@ -134,9 +145,11 @@ namespace opengl
count, count);
float * values = new float[dimension * dimension * count];
for (int i = 0; i < count; ++i) {
for (int i = 0; i < count; ++i)
{
lua_getfield(L, 3+i, "dimension");
if (lua_tointeger(L, -1) != dimension) {
if (lua_tointeger(L, -1) != dimension)
{
// You unlock this door with the key of imagination. Beyond it is
// another dimension: a dimension of sound, a dimension of sight,
// a dimension of mind. You're moving into a land of both shadow
@@ -156,9 +169,12 @@ namespace opengl
lua_pop(L, 1 + dimension);
}
try {
try
{
effect->sendMatrix(name, dimension, values, count);
} catch(love::Exception& e) {
}
catch (love::Exception& e)
{
delete[] values;
return luaL_error(L, e.what());
}
@@ -173,9 +189,12 @@ namespace opengl
const char* name = luaL_checkstring(L, 2);
Image* img = luax_checkimage(L, 3);
try {
try
{
effect->sendImage(name, *img);
} catch(love::Exception& e) {
}
catch (love::Exception& e)
{
luaL_error(L, e.what());
}
@@ -188,9 +207,12 @@ namespace opengl
const char* name = luaL_checkstring(L, 2);
Canvas* canvas = luax_checkcanvas(L, 3);
try {
try
{
effect->sendCanvas(name, *canvas);
} catch(love::Exception& e) {
}
catch (love::Exception& e)
{
luaL_error(L, e.what());
}
+79 -79
View File
@@ -1,79 +1,79 @@
/**
* Copyright (c) 2006-2011 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_Quad.h"
namespace love
{
namespace graphics
{
namespace opengl
{
Quad * luax_checkframe(lua_State * L, int idx)
{
return luax_checktype<Quad>(L, idx, "Quad", GRAPHICS_QUAD_T);
}
int w_Quad_flip(lua_State *L)
{
Quad * quad = luax_checktype<Quad>(L, 1, "Quad", GRAPHICS_QUAD_T);
quad->flip(luax_toboolean(L, 2), luax_toboolean(L, 3));
return 0;
}
int w_Quad_setViewport(lua_State * L)
{
Quad * quad = luax_checktype<Quad>(L, 1, "Quad", GRAPHICS_QUAD_T);
Quad::Viewport v;
v.x = (float) luaL_checknumber(L, 2);
v.y = (float) luaL_checknumber(L, 3);
v.w = (float) luaL_checknumber(L, 4);
v.h = (float) luaL_checknumber(L, 5);
quad->setViewport(v);
return 0;
}
int w_Quad_getViewport(lua_State * L)
{
Quad * quad = luax_checktype<Quad>(L, 1, "Quad", GRAPHICS_QUAD_T);
Quad::Viewport v = quad->getViewport();
lua_pushnumber(L, v.x);
lua_pushnumber(L, v.y);
lua_pushnumber(L, v.w);
lua_pushnumber(L, v.h);
return 4;
}
static const luaL_Reg w_Quad_functions[] = {
{ "flip", w_Quad_flip },
{ "setViewport", w_Quad_setViewport },
{ "getViewport", w_Quad_getViewport },
{ 0, 0 }
};
int luaopen_frame(lua_State * L)
{
return luax_register_type(L, "Quad", w_Quad_functions);
}
} // opengl
} // graphics
} // love
/**
* Copyright (c) 2006-2011 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_Quad.h"
namespace love
{
namespace graphics
{
namespace opengl
{
Quad * luax_checkframe(lua_State * L, int idx)
{
return luax_checktype<Quad>(L, idx, "Quad", GRAPHICS_QUAD_T);
}
int w_Quad_flip(lua_State *L)
{
Quad * quad = luax_checktype<Quad>(L, 1, "Quad", GRAPHICS_QUAD_T);
quad->flip(luax_toboolean(L, 2), luax_toboolean(L, 3));
return 0;
}
int w_Quad_setViewport(lua_State * L)
{
Quad * quad = luax_checktype<Quad>(L, 1, "Quad", GRAPHICS_QUAD_T);
Quad::Viewport v;
v.x = (float) luaL_checknumber(L, 2);
v.y = (float) luaL_checknumber(L, 3);
v.w = (float) luaL_checknumber(L, 4);
v.h = (float) luaL_checknumber(L, 5);
quad->setViewport(v);
return 0;
}
int w_Quad_getViewport(lua_State * L)
{
Quad * quad = luax_checktype<Quad>(L, 1, "Quad", GRAPHICS_QUAD_T);
Quad::Viewport v = quad->getViewport();
lua_pushnumber(L, v.x);
lua_pushnumber(L, v.y);
lua_pushnumber(L, v.w);
lua_pushnumber(L, v.h);
return 4;
}
static const luaL_Reg w_Quad_functions[] = {
{ "flip", w_Quad_flip },
{ "setViewport", w_Quad_setViewport },
{ "getViewport", w_Quad_getViewport },
{ 0, 0 }
};
int luaopen_frame(lua_State * L)
{
return luax_register_type(L, "Quad", w_Quad_functions);
}
} // opengl
} // graphics
} // love
+44 -44
View File
@@ -1,44 +1,44 @@
/**
* Copyright (c) 2006-2011 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_QUAD_H
#define LOVE_GRAPHICS_OPENGL_WRAP_QUAD_H
// LOVE
#include <common/runtime.h>
#include "Quad.h"
namespace love
{
namespace graphics
{
namespace opengl
{
Quad * luax_checkframe(lua_State * L, int idx);
int w_Quad_flip(lua_State *L);
int w_Quad_setViewport(lua_State * L);
int w_Quad_getViewport(lua_State * L);
int luaopen_frame(lua_State * L);
} // opengl
} // graphics
} // love
#endif // LOVE_GRAPHICS_OPENGL_WRAP_QUAD_H
/**
* Copyright (c) 2006-2011 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_QUAD_H
#define LOVE_GRAPHICS_OPENGL_WRAP_QUAD_H
// LOVE
#include <common/runtime.h>
#include "Quad.h"
namespace love
{
namespace graphics
{
namespace opengl
{
Quad * luax_checkframe(lua_State * L, int idx);
int w_Quad_flip(lua_State *L);
int w_Quad_setViewport(lua_State * L);
int w_Quad_getViewport(lua_State * L);
int luaopen_frame(lua_State * L);
} // opengl
} // graphics
} // love
#endif // LOVE_GRAPHICS_OPENGL_WRAP_QUAD_H
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -28,7 +28,7 @@ namespace opengl
{
SpriteBatch * luax_checkspritebatch(lua_State * L, int idx)
{
return luax_checktype<SpriteBatch>(L, idx, "SpriteBatch", GRAPHICS_SPRITE_BATCH_T);
return luax_checktype<SpriteBatch>(L, idx, "SpriteBatch", GRAPHICS_SPRITE_BATCH_T);
}
int w_SpriteBatch_add(lua_State * L)
+49 -49
View File
@@ -1,49 +1,49 @@
/**
* Copyright (c) 2006-2011 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 w_SpriteBatch_add(lua_State * L);
int w_SpriteBatch_addq(lua_State * L);
int w_SpriteBatch_set(lua_State * L);
int w_SpriteBatch_setq(lua_State * L);
int w_SpriteBatch_clear(lua_State * L);
int w_SpriteBatch_lock(lua_State * L);
int w_SpriteBatch_unlock(lua_State * L);
int w_SpriteBatch_setImage(lua_State * L);
int luaopen_spritebatch(lua_State * L);
} // opengl
} // graphics
} // love
#endif // LOVE_GRAPHICS_OPENGL_WRAP_SPRITE_BATCH_H
/**
* Copyright (c) 2006-2011 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 w_SpriteBatch_add(lua_State * L);
int w_SpriteBatch_addq(lua_State * L);
int w_SpriteBatch_set(lua_State * L);
int w_SpriteBatch_setq(lua_State * L);
int w_SpriteBatch_clear(lua_State * L);
int w_SpriteBatch_lock(lua_State * L);
int w_SpriteBatch_unlock(lua_State * L);
int w_SpriteBatch_setImage(lua_State * L);
int luaopen_spritebatch(lua_State * L);
} // opengl
} // graphics
} // love
#endif // LOVE_GRAPHICS_OPENGL_WRAP_SPRITE_BATCH_H
+8 -8
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -34,7 +34,7 @@ namespace image
/**
* This module is responsible for decoding files such as PNG, GIF, JPEG
* into raw pixel data. This module does not know how to draw images on
* screen; only love.graphics knows that.
* screen; only love.graphics knows that.
**/
class Image : public Module
{
@@ -46,19 +46,19 @@ namespace image
virtual ~Image(){};
/**
* Creates new ImageData from a file.
* Creates new ImageData from a file.
* @param file The file containing the encoded image data.
* @return The new ImageData.
**/
virtual ImageData * newImageData(love::filesystem::File * file) = 0;
/**
* Creates new ImageData from a raw Data.
* Creates new ImageData from a raw Data.
* @param data The object containing encoded pixel data.
* @return The new ImageData.
**/
virtual ImageData * newImageData(Data * data) = 0;
/**
* Creates empty ImageData with the given size.
* @param The width of the ImageData.
@@ -66,7 +66,7 @@ namespace image
* @return The new ImageData.
**/
virtual ImageData * newImageData(int width, int height) = 0;
/**
* Creates empty ImageData with the given size.
* @param The width of the ImageData.
+10 -10
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -29,11 +29,11 @@ namespace image
pixel * s = (pixel *)src->getData();
pixel * d = (pixel *)getData();
for(int i = 0; i < sh; i++)
for (int i = 0; i < sh; i++)
{
for(int j = 0; j < sw; j++)
for (int j = 0; j < sw; j++)
{
if(inside(dx+j, dy+i) && src->inside(sx+j, sy+i))
if (inside(dx+j, dy+i) && src->inside(sx+j, sy+i))
{
d[(dy+i)*getWidth() + (dx+j)] = s[(sy+i)*src->getWidth() + (sx+j)];
}
@@ -45,17 +45,17 @@ namespace image
{
return (x >= 0 && x < getWidth() && y >= 0 && y < getHeight());
}
bool ImageData::getConstant(const char * in, ImageData::Format & out)
{
return formats.find(in, out);
}
bool ImageData::getConstant(ImageData::Format in, const char *& out)
{
return formats.find(in, out);
}
StringMap<ImageData::Format, ImageData::FORMAT_MAX_ENUM>::Entry ImageData::formatEntries[] =
{
{"tga", ImageData::FORMAT_TGA},
@@ -64,7 +64,7 @@ namespace image
{"jpg", ImageData::FORMAT_JPG},
{"png", ImageData::FORMAT_PNG},
};
StringMap<ImageData::Format, ImageData::FORMAT_MAX_ENUM> ImageData::formats(ImageData::formatEntries, sizeof(ImageData::formatEntries));
} // image
+14 -14
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -26,23 +26,23 @@
#include <filesystem/File.h>
namespace love
{
{
namespace image
{
// Pixel format structure.
struct pixel
// Pixel format structure.
struct pixel
{
// Red, green, blue, alpha.
unsigned char r, g, b, a;
};
/**
* Represents raw pixel data.
* Represents raw pixel data.
**/
class ImageData : public Data
{
public:
enum Format
{
FORMAT_TGA = 1,
@@ -57,7 +57,7 @@ namespace image
* Destructor.
**/
virtual ~ImageData(){};
static bool getConstant(const char * in, Format & out);
static bool getConstant(Format in, const char *& out);
@@ -75,7 +75,7 @@ namespace image
/**
* Checks whether a position is inside this ImageData. Useful for checking bounds.
* @param x The position along the x-axis.
* @param x The position along the x-axis.
* @param y The position along the y-axis.
**/
bool inside(int x, int y) const;
@@ -94,7 +94,7 @@ namespace image
/**
* Sets the pixel at location (x,y). No effect if out of bounds.
* @param x The location along the x-axis.
* @param x The location along the x-axis.
* @param y The location along the y-axis.
* @param p The color to use for the given location.
**/
@@ -103,19 +103,19 @@ namespace image
/**
* Gets the pixel at location (x,y). Returns black (0,0,0,0) if out
* out of bounds.
* @param x The location along the x-axis.
* @param x The location along the x-axis.
* @param y The location along the y-axis.
* @return The color for the given location.
**/
virtual pixel getPixel(int x, int y) = 0;
/**
* Encodes raw pixel data into a given format.
* @param f The format to convert to.
* @return A pointer to the encoded image data.
**/
virtual void encode(love::filesystem::File * f, Format format) = 0;
private:
static StringMap<Format, FORMAT_MAX_ENUM>::Entry formatEntries[];
static StringMap<Format, FORMAT_MAX_ENUM> formats;
+10 -7
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -55,14 +55,17 @@ namespace devil
love::image::ImageData * Image::newImageData(Data * data)
{
try {
try
{
return new ImageData(data);
} catch (love::Exception & e) {
}
catch (love::Exception & e)
{
throw love::Exception(e.what());
}
}
love::image::ImageData * Image::newImageData(int width, int height)
{
return new ImageData(width, height);
+4 -4
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
@@ -39,7 +39,7 @@ namespace devil
// Implements Module.
const char * getName() const;
love::image::ImageData * newImageData(love::filesystem::File * file);
love::image::ImageData * newImageData(Data * data);
love::image::ImageData * newImageData(int width, int height);
+11 -11
View File
@@ -50,13 +50,13 @@ namespace devil
//bind it
ilBindImage(image);
while(ilGetError() != IL_NO_ERROR);
while (ilGetError() != IL_NO_ERROR);
//create and populate the image
bool success = (ilTexImage(width, height, 1, bpp, IL_RGBA, IL_UNSIGNED_BYTE, data) == IL_TRUE);
ILenum err = ilGetError();
while(ilGetError() != IL_NO_ERROR);
while (ilGetError() != IL_NO_ERROR);
if (!success)
{
@@ -110,7 +110,7 @@ namespace devil
ILboolean success = ilLoadL(IL_TYPE_UNKNOWN, (void*)data->getData(), data->getSize());
// Check for errors
if(!success)
if (!success)
{
throw love::Exception("Could not decode image!");
}
@@ -125,7 +125,7 @@ namespace devil
// This should always be four.
bpp = ilGetInteger(IL_IMAGE_BPP);
if(bpp != 4)
if (bpp != 4)
{
ilDeleteImages(1, &image);
std::cerr << "Bits per pixel != 4" << std::endl;
@@ -136,7 +136,7 @@ namespace devil
{
this->data = new unsigned char[width*height*bpp];
}
catch(std::bad_alloc)
catch (std::bad_alloc)
{
ilDeleteImages(1, &image);
throw love::Exception("Out of memory");
@@ -206,7 +206,7 @@ namespace devil
//int ty = y > height-1 ? height-1 : y; // not using these seems to not break anything
if (x > width-1 || y > height-1 || x < 0 || y < 0)
throw love::Exception("Attempt to set out-of-range pixel!");
pixel * pixels = (pixel *)getData();
pixels[y*width+x] = c;
}
@@ -218,7 +218,7 @@ namespace devil
//int ty = y > height-1 ? height-1 : y; // not using these seems to not break anything
if (x > width-1 || y > height-1 || x < 0 || y < 0)
throw love::Exception("Attempt to get out-of-range pixel!");
pixel * pixels = (pixel *)getData();
return pixels[y*width+x];
}
@@ -231,12 +231,12 @@ namespace devil
ilGenImages(1, &tempimage);
ilBindImage(tempimage);
while(ilGetError() != IL_NO_ERROR);
while (ilGetError() != IL_NO_ERROR);
bool success = ilTexImage(width, height, 1, bpp, IL_RGBA, IL_UNSIGNED_BYTE, this->data) == IL_TRUE;
ILenum err = ilGetError();
while(ilGetError() != IL_NO_ERROR);
while (ilGetError() != IL_NO_ERROR);
if (!success)
{
@@ -295,7 +295,7 @@ namespace devil
{
encoded_data = new ILubyte[size];
}
catch(std::bad_alloc)
catch (std::bad_alloc)
{
ilDeleteImages(1, &tempimage);
throw love::Exception("Out of memory");
+21 -12
View File
@@ -35,14 +35,17 @@ namespace image
{
// Case 1: Integers.
if(lua_isnumber(L, 1))
if (lua_isnumber(L, 1))
{
int w = luaL_checkint(L, 1);
int h = luaL_checkint(L, 2);
ImageData * t = 0;
try {
try
{
t = instance->newImageData(w, h);
} catch (love::Exception & e) {
}
catch (love::Exception & e)
{
return luaL_error(L, e.what());
}
luax_newtype(L, "ImageData", IMAGE_IMAGE_DATA_T, (void*)t);
@@ -50,13 +53,16 @@ namespace image
}
// Case 2: Data
if(luax_istype(L, 1, DATA_T))
if (luax_istype(L, 1, DATA_T))
{
Data * d = luax_checktype<Data>(L, 1, "Data", DATA_T);
ImageData * t = 0;
try {
try
{
t = instance->newImageData(d);
} catch (love::Exception & e) {
}
catch (love::Exception & e)
{
return luaL_error(L, e.what());
}
luax_newtype(L, "ImageData", IMAGE_IMAGE_DATA_T, (void*)t);
@@ -66,21 +72,24 @@ namespace image
// Case 3: String/File.
// Convert to File, if necessary.
if(lua_isstring(L, 1))
if (lua_isstring(L, 1))
luax_convobj(L, 1, "filesystem", "newFile");
love::filesystem::File * file = luax_checktype<love::filesystem::File>(L, 1, "File", FILESYSTEM_FILE_T);
ImageData * t = 0;
try {
try
{
t = instance->newImageData(file);
} catch (love::Exception & e) {
}
catch (love::Exception & e)
{
return luaL_error(L, e.what());
}
luax_newtype(L, "ImageData", IMAGE_IMAGE_DATA_T, (void*)t);
return 1;
}
// List of functions to wrap.
static const luaL_Reg functions[] = {
{ "newImageData", w_newImageData },
@@ -94,13 +103,13 @@ namespace image
int luaopen_love_image(lua_State * L)
{
if(instance == 0)
if (instance == 0)
{
try
{
instance = new love::image::devil::Image();
}
catch(Exception & e)
catch (Exception & e)
{
return luaL_error(L, e.what());
}
+3 -3
View File
@@ -1,14 +1,14 @@
/**
* Copyright (c) 2006-2011 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
+197 -194
View File
@@ -1,194 +1,197 @@
/**
* Copyright (c) 2006-2011 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_ImageData.h"
#include <common/wrap_Data.h>
#include <filesystem/File.h>
namespace love
{
namespace image
{
ImageData * luax_checkimagedata(lua_State * L, int idx)
{
return luax_checktype<ImageData>(L, idx, "ImageData", IMAGE_IMAGE_DATA_T);
}
int w_ImageData_getWidth(lua_State * L)
{
ImageData * t = luax_checkimagedata(L, 1);
lua_pushinteger(L, t->getWidth());
return 1;
}
int w_ImageData_getHeight(lua_State * L)
{
ImageData * t = luax_checkimagedata(L, 1);
lua_pushinteger(L, t->getHeight());
return 1;
}
int w_ImageData_getPixel(lua_State * L)
{
ImageData * t = luax_checkimagedata(L, 1);
int x = luaL_checkint(L, 2);
int y = luaL_checkint(L, 3);
pixel c;
try
{
c = t->getPixel(x, y);
}
catch (love::Exception *e)
{
return luaL_error(L, "%s", e->what());
}
lua_pushnumber(L, c.r);
lua_pushnumber(L, c.g);
lua_pushnumber(L, c.b);
lua_pushnumber(L, c.a);
return 4;
}
int w_ImageData_setPixel(lua_State * L)
{
ImageData * t = luax_checkimagedata(L, 1);
int x = luaL_checkint(L, 2);
int y = luaL_checkint(L, 3);
pixel c;
c.r = luaL_checkint(L, 4);
c.g = luaL_checkint(L, 5);
c.b = luaL_checkint(L, 6);
c.a = luaL_checkint(L, 7);
try
{
t->setPixel(x, y, c);
}
catch (love::Exception *e)
{
return luaL_error(L, "%s", e->what());
}
return 0;
}
int w_ImageData_mapPixel(lua_State * L)
{
ImageData * t = luax_checkimagedata(L, 1);
if(!lua_isfunction(L, 2))
return luaL_error(L, "Function expected");
int w = t->getWidth();
int h = t->getHeight();
for(int i = 0; i < w; i++)
{
for(int j = 0; j < h; j++)
{
lua_pushvalue(L, 2);
lua_pushnumber(L, i);
lua_pushnumber(L, j);
pixel c = t->getPixel(i, j);
lua_pushnumber(L, c.r);
lua_pushnumber(L, c.g);
lua_pushnumber(L, c.b);
lua_pushnumber(L, c.a);
lua_call(L, 6, 4);
c.r = luaL_optint(L, -4, 0);
c.g = luaL_optint(L, -3, 0);
c.b = luaL_optint(L, -2, 0);
c.a = luaL_optint(L, -1, 0);
t->setPixel(i, j, c);
lua_pop(L, 4);
}
}
return 0;
}
int w_ImageData_getString(lua_State * L)
{
ImageData * t = luax_checkimagedata(L, 1);
lua_pushlstring(L, (const char *)t->getData(), t->getSize());
return 1;
}
int w_ImageData_paste(lua_State * L)
{
ImageData * t = luax_checkimagedata(L, 1);
ImageData * src = luax_checkimagedata(L, 2);
int dx = luaL_checkint(L, 3);
int dy = luaL_checkint(L, 4);
int sx = luaL_optint(L, 5, 0);
int sy = luaL_optint(L, 6, 0);
int sw = luaL_optint(L, 7, src->getWidth());
int sh = luaL_optint(L, 8, src->getHeight());
t->paste((love::image::ImageData *)src, dx, dy, sx, sy, sw, sh);
return 0;
}
int w_ImageData_encode(lua_State * L)
{
ImageData * t = luax_checkimagedata(L, 1);
if(lua_isstring(L, 2))
luax_convobj(L, 2, "filesystem", "newFile");
love::filesystem::File * file = luax_checktype<love::filesystem::File>(L, 2, "File", FILESYSTEM_FILE_T);
const char * fmt;
if (lua_isnoneornil(L, 3)) {
fmt = file->getExtension().c_str();
} else {
fmt = luaL_checkstring(L, 3);
}
ImageData::Format format;
ImageData::getConstant(fmt, format);
try
{
t->encode(file, format);
}
catch (love::Exception & e)
{
return luaL_error(L, e.what());
}
return 0;
}
static const luaL_Reg functions[] = {
// Data
{ "getPointer", w_Data_getPointer },
{ "getSize", w_Data_getSize },
{ "getWidth", w_ImageData_getWidth },
{ "getHeight", w_ImageData_getHeight },
{ "getPixel", w_ImageData_getPixel },
{ "setPixel", w_ImageData_setPixel },
{ "mapPixel", w_ImageData_mapPixel },
{ "getString", w_ImageData_getString },
{ "paste", w_ImageData_paste },
{ "encode", w_ImageData_encode },
{ 0, 0 }
};
int luaopen_imagedata(lua_State * L)
{
return luax_register_type(L, "ImageData", functions);
}
} // image
} // love
/**
* Copyright (c) 2006-2011 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_ImageData.h"
#include <common/wrap_Data.h>
#include <filesystem/File.h>
namespace love
{
namespace image
{
ImageData * luax_checkimagedata(lua_State * L, int idx)
{
return luax_checktype<ImageData>(L, idx, "ImageData", IMAGE_IMAGE_DATA_T);
}
int w_ImageData_getWidth(lua_State * L)
{
ImageData * t = luax_checkimagedata(L, 1);
lua_pushinteger(L, t->getWidth());
return 1;
}
int w_ImageData_getHeight(lua_State * L)
{
ImageData * t = luax_checkimagedata(L, 1);
lua_pushinteger(L, t->getHeight());
return 1;
}
int w_ImageData_getPixel(lua_State * L)
{
ImageData * t = luax_checkimagedata(L, 1);
int x = luaL_checkint(L, 2);
int y = luaL_checkint(L, 3);
pixel c;
try
{
c = t->getPixel(x, y);
}
catch (love::Exception *e)
{
return luaL_error(L, "%s", e->what());
}
lua_pushnumber(L, c.r);
lua_pushnumber(L, c.g);
lua_pushnumber(L, c.b);
lua_pushnumber(L, c.a);
return 4;
}
int w_ImageData_setPixel(lua_State * L)
{
ImageData * t = luax_checkimagedata(L, 1);
int x = luaL_checkint(L, 2);
int y = luaL_checkint(L, 3);
pixel c;
c.r = luaL_checkint(L, 4);
c.g = luaL_checkint(L, 5);
c.b = luaL_checkint(L, 6);
c.a = luaL_checkint(L, 7);
try
{
t->setPixel(x, y, c);
}
catch (love::Exception *e)
{
return luaL_error(L, "%s", e->what());
}
return 0;
}
int w_ImageData_mapPixel(lua_State * L)
{
ImageData * t = luax_checkimagedata(L, 1);
if (!lua_isfunction(L, 2))
return luaL_error(L, "Function expected");
int w = t->getWidth();
int h = t->getHeight();
for (int i = 0; i < w; i++)
{
for (int j = 0; j < h; j++)
{
lua_pushvalue(L, 2);
lua_pushnumber(L, i);
lua_pushnumber(L, j);
pixel c = t->getPixel(i, j);
lua_pushnumber(L, c.r);
lua_pushnumber(L, c.g);
lua_pushnumber(L, c.b);
lua_pushnumber(L, c.a);
lua_call(L, 6, 4);
c.r = luaL_optint(L, -4, 0);
c.g = luaL_optint(L, -3, 0);
c.b = luaL_optint(L, -2, 0);
c.a = luaL_optint(L, -1, 0);
t->setPixel(i, j, c);
lua_pop(L, 4);
}
}
return 0;
}
int w_ImageData_getString(lua_State * L)
{
ImageData * t = luax_checkimagedata(L, 1);
lua_pushlstring(L, (const char *)t->getData(), t->getSize());
return 1;
}
int w_ImageData_paste(lua_State * L)
{
ImageData * t = luax_checkimagedata(L, 1);
ImageData * src = luax_checkimagedata(L, 2);
int dx = luaL_checkint(L, 3);
int dy = luaL_checkint(L, 4);
int sx = luaL_optint(L, 5, 0);
int sy = luaL_optint(L, 6, 0);
int sw = luaL_optint(L, 7, src->getWidth());
int sh = luaL_optint(L, 8, src->getHeight());
t->paste((love::image::ImageData *)src, dx, dy, sx, sy, sw, sh);
return 0;
}
int w_ImageData_encode(lua_State * L)
{
ImageData * t = luax_checkimagedata(L, 1);
if (lua_isstring(L, 2))
luax_convobj(L, 2, "filesystem", "newFile");
love::filesystem::File * file = luax_checktype<love::filesystem::File>(L, 2, "File", FILESYSTEM_FILE_T);
const char * fmt;
if (lua_isnoneornil(L, 3))
{
fmt = file->getExtension().c_str();
}
else
{
fmt = luaL_checkstring(L, 3);
}
ImageData::Format format;
ImageData::getConstant(fmt, format);
try
{
t->encode(file, format);
}
catch (love::Exception & e)
{
return luaL_error(L, e.what());
}
return 0;
}
static const luaL_Reg functions[] = {
// Data
{ "getPointer", w_Data_getPointer },
{ "getSize", w_Data_getSize },
{ "getWidth", w_ImageData_getWidth },
{ "getHeight", w_ImageData_getHeight },
{ "getPixel", w_ImageData_getPixel },
{ "setPixel", w_ImageData_setPixel },
{ "mapPixel", w_ImageData_mapPixel },
{ "getString", w_ImageData_getString },
{ "paste", w_ImageData_paste },
{ "encode", w_ImageData_encode },
{ 0, 0 }
};
int luaopen_imagedata(lua_State * L)
{
return luax_register_type(L, "ImageData", functions);
}
} // image
} // love
+46 -46
View File
@@ -1,46 +1,46 @@
/**
* Copyright (c) 2006-2011 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_IMAGE_WRAP_IMAGE_DATA_H
#define LOVE_IMAGE_WRAP_IMAGE_DATA_H
// LOVE
#include <common/runtime.h>
#include "ImageData.h"
namespace love
{
namespace image
{
ImageData * luax_checkimagedata(lua_State * L, int idx);
int w_ImageData_getWidth(lua_State * L);
int w_ImageData_getHeight(lua_State * L);
int w_ImageData_getPixel(lua_State * L);
int w_ImageData_setPixel(lua_State * L);
int w_ImageData_mapPixel(lua_State * L);
int w_ImageData_getString(lua_State * L);
int w_ImageData_paste(lua_State * L);
int w_ImageData_encode(lua_State * L);
int luaopen_imagedata(lua_State * L);
} // image
} // love
#endif // LOVE_IMAGE_WRAP_IMAGE_DATA_H
/**
* Copyright (c) 2006-2011 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_IMAGE_WRAP_IMAGE_DATA_H
#define LOVE_IMAGE_WRAP_IMAGE_DATA_H
// LOVE
#include <common/runtime.h>
#include "ImageData.h"
namespace love
{
namespace image
{
ImageData * luax_checkimagedata(lua_State * L, int idx);
int w_ImageData_getWidth(lua_State * L);
int w_ImageData_getHeight(lua_State * L);
int w_ImageData_getPixel(lua_State * L);
int w_ImageData_setPixel(lua_State * L);
int w_ImageData_mapPixel(lua_State * L);
int w_ImageData_getString(lua_State * L);
int w_ImageData_paste(lua_State * L);
int w_ImageData_encode(lua_State * L);
int luaopen_imagedata(lua_State * L);
} // image
} // love
#endif // LOVE_IMAGE_WRAP_IMAGE_DATA_H

Some files were not shown because too many files have changed in this diff Show More