mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +02:00
Merged default into minor
--HG-- branch : minor
This commit is contained in:
@@ -37,6 +37,7 @@ Audio::PoolThread::PoolThread(Pool *pool)
|
||||
, finish(false)
|
||||
{
|
||||
mutex = thread::newMutex();
|
||||
threadName = "AudioPool";
|
||||
}
|
||||
|
||||
Audio::PoolThread::~PoolThread()
|
||||
|
||||
@@ -259,10 +259,7 @@ bool Source::update()
|
||||
|
||||
alGetSourcef(source, AL_SAMPLE_OFFSET, &curOffsetSamples);
|
||||
|
||||
ALint b;
|
||||
alGetSourcei(source, AL_BUFFER, &b);
|
||||
int freq;
|
||||
alGetBufferi(b, AL_FREQUENCY, &freq);
|
||||
int freq = decoder->getSampleRate();
|
||||
curOffsetSecs = curOffsetSamples / freq;
|
||||
|
||||
// Get a free buffer.
|
||||
@@ -338,11 +335,7 @@ void Source::seekAtomic(float offset, void *unit)
|
||||
if (type == TYPE_STREAM)
|
||||
{
|
||||
offsetSamples = offset;
|
||||
ALint buffer;
|
||||
alGetSourcei(source, AL_BUFFER, &buffer);
|
||||
int freq;
|
||||
alGetBufferi(buffer, AL_FREQUENCY, &freq);
|
||||
offset /= freq;
|
||||
offset /= decoder->getSampleRate();
|
||||
offsetSeconds = offset;
|
||||
decoder->seek(offset);
|
||||
}
|
||||
@@ -357,11 +350,7 @@ void Source::seekAtomic(float offset, void *unit)
|
||||
{
|
||||
offsetSeconds = offset;
|
||||
decoder->seek(offset);
|
||||
ALint buffer;
|
||||
alGetSourcei(source, AL_BUFFER, &buffer);
|
||||
int freq;
|
||||
alGetBufferi(buffer, AL_FREQUENCY, &freq);
|
||||
offsetSamples = offset*freq;
|
||||
offsetSamples = offset * decoder->getSampleRate();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -403,11 +392,7 @@ float Source::tellAtomic(void *unit) const
|
||||
default:
|
||||
{
|
||||
alGetSourcef(source, AL_SAMPLE_OFFSET, &offset);
|
||||
ALint buffer;
|
||||
alGetSourcei(source, AL_BUFFER, &buffer);
|
||||
int freq;
|
||||
alGetBufferi(buffer, AL_FREQUENCY, &freq);
|
||||
offset /= freq;
|
||||
offset /= decoder->getSampleRate();
|
||||
if (type == TYPE_STREAM) offset += offsetSeconds;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -270,10 +270,7 @@ Message *Event::convertJoystickEvent(const SDL_Event &e) const
|
||||
|
||||
arg1 = new Variant(JOYSTICK_JOYSTICK_ID, (void *) &proxy);
|
||||
arg2 = new Variant((double)(e.jaxis.axis+1));
|
||||
float value = e.jaxis.value / 32768.0f;
|
||||
if (fabsf(value) < 0.001f) value = 0.0f;
|
||||
if (value < -0.99f) value = -1.0f;
|
||||
if (value > 0.99f) value = 1.0f;
|
||||
float value = joystick::Joystick::clampval(e.jaxis.value / 32768.0f);
|
||||
arg3 = new Variant((double) value);
|
||||
msg = new Message("joystickaxis", arg1, arg2, arg3);
|
||||
arg1->release();
|
||||
@@ -332,10 +329,7 @@ Message *Event::convertJoystickEvent(const SDL_Event &e) const
|
||||
arg1 = new Variant(JOYSTICK_JOYSTICK_ID, (void *) &proxy);
|
||||
|
||||
arg2 = new Variant(txt, strlen(txt));
|
||||
float value = e.jaxis.value / 32768.0f;
|
||||
if (fabsf(value) < 0.001f) value = 0.0f;
|
||||
if (value < -0.99f) value = -1.0f;
|
||||
if (value > 0.99f) value = 1.0f;
|
||||
float value = joystick::Joystick::clampval(e.caxis.value / 32768.0f);
|
||||
arg3 = new Variant((double) value);
|
||||
msg = new Message("gamepadaxis", arg1, arg2, arg3);
|
||||
arg1->release();
|
||||
|
||||
@@ -80,7 +80,7 @@ private:
|
||||
static EnumMap<love::mouse::Mouse::Button, Uint8, love::mouse::Mouse::BUTTON_MAX_ENUM>::Entry buttonEntries[];
|
||||
static EnumMap<love::mouse::Mouse::Button, Uint8, love::mouse::Mouse::BUTTON_MAX_ENUM> buttons;
|
||||
|
||||
}; // System
|
||||
}; // Event
|
||||
|
||||
} // sdl
|
||||
} // event
|
||||
|
||||
@@ -276,8 +276,8 @@ void ParticleSystem::initParticle(Particle *p, float t)
|
||||
min = speedMin;
|
||||
max = speedMax;
|
||||
float speed = (float) rng.random(min, max);
|
||||
p->speed = love::Vector(cosf(p->direction), sinf(p->direction));
|
||||
p->speed *= speed;
|
||||
p->velocity = love::Vector(cosf(p->direction), sinf(p->direction));
|
||||
p->velocity *= speed;
|
||||
|
||||
p->linearAcceleration.x = (float) rng.random(linearAccelerationMin.x, linearAccelerationMax.x);
|
||||
p->linearAcceleration.y = (float) rng.random(linearAccelerationMin.y, linearAccelerationMax.y);
|
||||
@@ -302,7 +302,7 @@ void ParticleSystem::initParticle(Particle *p, float t)
|
||||
|
||||
p->angle = p->rotation;
|
||||
if (relativeRotation)
|
||||
p->angle += atan2f(p->speed.y, p->speed.x);
|
||||
p->angle += atan2f(p->velocity.y, p->velocity.x);
|
||||
|
||||
p->color = colors[0];
|
||||
}
|
||||
@@ -907,11 +907,11 @@ void ParticleSystem::update(float dt)
|
||||
// Resize tangential.
|
||||
tangential *= p->tangentialAcceleration;
|
||||
|
||||
// Update position.
|
||||
p->speed += (radial+tangential+p->linearAcceleration)*dt;
|
||||
// Update velocity.
|
||||
p->velocity += (radial + tangential + p->linearAcceleration) * dt;
|
||||
|
||||
// Modify position.
|
||||
ppos += p->speed * dt;
|
||||
ppos += p->velocity * dt;
|
||||
|
||||
p->position[0] = ppos.getX();
|
||||
p->position[1] = ppos.getY();
|
||||
@@ -924,7 +924,7 @@ void ParticleSystem::update(float dt)
|
||||
p->angle = p->rotation;
|
||||
|
||||
if (relativeRotation)
|
||||
p->angle += atan2f(p->speed.y, p->speed.x);
|
||||
p->angle += atan2f(p->velocity.y, p->velocity.x);
|
||||
|
||||
// Change size according to given intervals:
|
||||
// i = 0 1 2 3 n-1
|
||||
|
||||
@@ -516,7 +516,7 @@ protected:
|
||||
// Particles gravitate towards this point.
|
||||
love::Vector origin;
|
||||
|
||||
love::Vector speed;
|
||||
love::Vector velocity;
|
||||
love::Vector linearAcceleration;
|
||||
float radialAcceleration;
|
||||
float tangentialAcceleration;
|
||||
|
||||
@@ -186,8 +186,16 @@ void Shader::createProgram(const std::vector<GLuint> &shaderids)
|
||||
// Bind generic vertex attribute indices to names in the shader.
|
||||
for (int i = 0; i < int(OpenGL::ATTRIB_MAX_ENUM); i++)
|
||||
{
|
||||
OpenGL::VertexAttrib attrib = (OpenGL::VertexAttrib) i;
|
||||
|
||||
// FIXME: We skip this both because pseudo-instancing is temporarily
|
||||
// disabled (see graphics.lua), and because binding a non-existant
|
||||
// attribute name to a location causes a shader linker warning.
|
||||
if (attrib == OpenGL::ATTRIB_PSEUDO_INSTANCE_ID)
|
||||
continue;
|
||||
|
||||
const char *name = nullptr;
|
||||
if (attribNames.find((OpenGL::VertexAttrib) i, name))
|
||||
if (attribNames.find(attrib, name))
|
||||
glBindAttribLocation(program, i, (const GLchar *) name);
|
||||
}
|
||||
|
||||
@@ -247,7 +255,7 @@ void Shader::mapActiveUniforms()
|
||||
}
|
||||
|
||||
// If this is a built-in (LOVE-created) uniform, store the location.
|
||||
BuiltinExtern builtin;
|
||||
BuiltinUniform builtin;
|
||||
if (builtinNames.find(u.name.c_str(), builtin))
|
||||
builtinUniforms[int(builtin)] = u.location;
|
||||
|
||||
@@ -652,19 +660,36 @@ int Shader::getTextureUnit(const std::string &name)
|
||||
return texunit;
|
||||
}
|
||||
|
||||
Shader::UniformType Shader::getExternVariable(const std::string &name, int &components, int &count)
|
||||
{
|
||||
auto it = uniforms.find(name);
|
||||
|
||||
if (it == uniforms.end())
|
||||
{
|
||||
components = 0;
|
||||
count = 0;
|
||||
return UNIFORM_UNKNOWN;
|
||||
}
|
||||
|
||||
components = getUniformTypeSize(it->second.type);
|
||||
count = (int) it->second.count;
|
||||
|
||||
return it->second.baseType;
|
||||
}
|
||||
|
||||
bool Shader::hasVertexAttrib(OpenGL::VertexAttrib attrib) const
|
||||
{
|
||||
return vertexAttributes[int(attrib)] != -1;
|
||||
}
|
||||
|
||||
bool Shader::hasBuiltinExtern(BuiltinExtern builtin) const
|
||||
bool Shader::hasBuiltinUniform(BuiltinUniform builtin) const
|
||||
{
|
||||
return builtinUniforms[int(builtin)] != -1;
|
||||
}
|
||||
|
||||
bool Shader::sendBuiltinFloat(BuiltinExtern builtin, int size, const GLfloat *vec, int count)
|
||||
bool Shader::sendBuiltinFloat(BuiltinUniform builtin, int size, const GLfloat *vec, int count)
|
||||
{
|
||||
if (!hasBuiltinExtern(builtin))
|
||||
if (!hasBuiltinUniform(builtin))
|
||||
return false;
|
||||
|
||||
GLint location = builtinUniforms[int(builtin)];
|
||||
@@ -754,6 +779,16 @@ bool Shader::isSupported()
|
||||
return getGLSLVersion() >= "1.2";
|
||||
}
|
||||
|
||||
bool Shader::getConstant(const char *in, UniformType &out)
|
||||
{
|
||||
return uniformTypes.find(in, out);
|
||||
}
|
||||
|
||||
bool Shader::getConstant(UniformType in, const char *&out)
|
||||
{
|
||||
return uniformTypes.find(in, out);
|
||||
}
|
||||
|
||||
StringMap<Shader::ShaderType, Shader::TYPE_MAX_ENUM>::Entry Shader::typeNameEntries[] =
|
||||
{
|
||||
{"vertex", Shader::TYPE_VERTEX},
|
||||
@@ -762,6 +797,17 @@ StringMap<Shader::ShaderType, Shader::TYPE_MAX_ENUM>::Entry Shader::typeNameEntr
|
||||
|
||||
StringMap<Shader::ShaderType, Shader::TYPE_MAX_ENUM> Shader::typeNames(Shader::typeNameEntries, sizeof(Shader::typeNameEntries));
|
||||
|
||||
StringMap<Shader::UniformType, Shader::UNIFORM_MAX_ENUM>::Entry Shader::uniformTypeEntries[] =
|
||||
{
|
||||
{"float", Shader::UNIFORM_FLOAT},
|
||||
{"int", Shader::UNIFORM_INT},
|
||||
{"bool", Shader::UNIFORM_BOOL},
|
||||
{"image", Shader::UNIFORM_SAMPLER},
|
||||
{"unknown", Shader::UNIFORM_UNKNOWN},
|
||||
};
|
||||
|
||||
StringMap<Shader::UniformType, Shader::UNIFORM_MAX_ENUM> Shader::uniformTypes(Shader::uniformTypeEntries, sizeof(Shader::uniformTypeEntries));
|
||||
|
||||
StringMap<OpenGL::VertexAttrib, OpenGL::ATTRIB_MAX_ENUM>::Entry Shader::attribNameEntries[] =
|
||||
{
|
||||
{"love_PseudoInstanceID", OpenGL::ATTRIB_PSEUDO_INSTANCE_ID},
|
||||
@@ -769,12 +815,12 @@ StringMap<OpenGL::VertexAttrib, OpenGL::ATTRIB_MAX_ENUM>::Entry Shader::attribNa
|
||||
|
||||
StringMap<OpenGL::VertexAttrib, OpenGL::ATTRIB_MAX_ENUM> Shader::attribNames(Shader::attribNameEntries, sizeof(Shader::attribNameEntries));
|
||||
|
||||
StringMap<Shader::BuiltinExtern, Shader::BUILTIN_MAX_ENUM>::Entry Shader::builtinNameEntries[] =
|
||||
StringMap<Shader::BuiltinUniform, Shader::BUILTIN_MAX_ENUM>::Entry Shader::builtinNameEntries[] =
|
||||
{
|
||||
{"love_ScreenSize", Shader::BUILTIN_SCREEN_SIZE},
|
||||
};
|
||||
|
||||
StringMap<Shader::BuiltinExtern, Shader::BUILTIN_MAX_ENUM> Shader::builtinNames(Shader::builtinNameEntries, sizeof(Shader::builtinNameEntries));
|
||||
StringMap<Shader::BuiltinUniform, Shader::BUILTIN_MAX_ENUM> Shader::builtinNames(Shader::builtinNameEntries, sizeof(Shader::builtinNameEntries));
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
|
||||
@@ -56,13 +56,24 @@ public:
|
||||
TYPE_MAX_ENUM
|
||||
};
|
||||
|
||||
// Built-in extern (uniform) variables.
|
||||
enum BuiltinExtern
|
||||
// Built-in uniform (extern) variables.
|
||||
enum BuiltinUniform
|
||||
{
|
||||
BUILTIN_SCREEN_SIZE,
|
||||
BUILTIN_MAX_ENUM
|
||||
};
|
||||
|
||||
// Types of potential uniform (extern) variables used in love's shaders.
|
||||
enum UniformType
|
||||
{
|
||||
UNIFORM_FLOAT,
|
||||
UNIFORM_INT,
|
||||
UNIFORM_BOOL,
|
||||
UNIFORM_SAMPLER,
|
||||
UNIFORM_UNKNOWN,
|
||||
UNIFORM_MAX_ENUM
|
||||
};
|
||||
|
||||
// Type for a list of shader source codes in the form of sources[shadertype] = code
|
||||
typedef std::map<ShaderType, std::string> ShaderSources;
|
||||
|
||||
@@ -135,12 +146,25 @@ public:
|
||||
**/
|
||||
void sendTexture(const std::string &name, Texture *texture);
|
||||
|
||||
/**
|
||||
* Gets the type, number of components, and number of array elements of
|
||||
* an active 'extern' (uniform) variable in the shader. If a uniform
|
||||
* variable with the specified name doesn't exist, returns UNIFORM_UNKNOWN
|
||||
* and sets the 'components' and 'count' values to 0.
|
||||
*
|
||||
* @param name The name of the uniform variable in the source code.
|
||||
* @param[out] components Number of components of the variable (2 for vec2.)
|
||||
* @param[out] count Number of array elements, if the variable is an array.
|
||||
* @return The base type of the uniform variable.
|
||||
**/
|
||||
UniformType getExternVariable(const std::string &name, int &components, int &count);
|
||||
|
||||
/**
|
||||
* Internal use only.
|
||||
**/
|
||||
bool hasVertexAttrib(OpenGL::VertexAttrib attrib) const;
|
||||
bool hasBuiltinExtern(BuiltinExtern builtin) const;
|
||||
bool sendBuiltinFloat(BuiltinExtern builtin, int size, const GLfloat *m, int count);
|
||||
bool hasBuiltinUniform(BuiltinUniform builtin) const;
|
||||
bool sendBuiltinFloat(BuiltinUniform builtin, int size, const GLfloat *m, int count);
|
||||
void checkSetScreenParams();
|
||||
|
||||
const std::map<std::string, Object *> &getBoundRetainables() const;
|
||||
@@ -148,17 +172,10 @@ public:
|
||||
static std::string getGLSLVersion();
|
||||
static bool isSupported();
|
||||
|
||||
private:
|
||||
static bool getConstant(const char *in, UniformType &out);
|
||||
static bool getConstant(UniformType in, const char *&out);
|
||||
|
||||
// Types of potential uniform variables used in love's shaders.
|
||||
enum UniformType
|
||||
{
|
||||
UNIFORM_FLOAT,
|
||||
UNIFORM_INT,
|
||||
UNIFORM_BOOL,
|
||||
UNIFORM_SAMPLER,
|
||||
UNIFORM_UNKNOWN
|
||||
};
|
||||
private:
|
||||
|
||||
// Represents a single uniform/extern shader variable.
|
||||
struct Uniform
|
||||
@@ -227,13 +244,16 @@ private:
|
||||
static StringMap<ShaderType, TYPE_MAX_ENUM>::Entry typeNameEntries[];
|
||||
static StringMap<ShaderType, TYPE_MAX_ENUM> typeNames;
|
||||
|
||||
static StringMap<UniformType, UNIFORM_MAX_ENUM>::Entry uniformTypeEntries[];
|
||||
static StringMap<UniformType, UNIFORM_MAX_ENUM> uniformTypes;
|
||||
|
||||
// Names for the generic vertex attributes used by love.
|
||||
static StringMap<OpenGL::VertexAttrib, OpenGL::ATTRIB_MAX_ENUM>::Entry attribNameEntries[];
|
||||
static StringMap<OpenGL::VertexAttrib, OpenGL::ATTRIB_MAX_ENUM> attribNames;
|
||||
|
||||
// Names for the built-in uniform variables.
|
||||
static StringMap<BuiltinExtern, BUILTIN_MAX_ENUM>::Entry builtinNameEntries[];
|
||||
static StringMap<BuiltinExtern, BUILTIN_MAX_ENUM> builtinNames;
|
||||
static StringMap<BuiltinUniform, BUILTIN_MAX_ENUM>::Entry builtinNameEntries[];
|
||||
static StringMap<BuiltinUniform, BUILTIN_MAX_ENUM> builtinNames;
|
||||
};
|
||||
|
||||
} // opengl
|
||||
|
||||
@@ -111,7 +111,7 @@ int SpriteBatch::add(float x, float y, float a, float sx, float sy, float ox, fl
|
||||
memcpy(sprite, texture->getVertices(), sizeof(Vertex) * 4);
|
||||
|
||||
// Transform.
|
||||
static Matrix t;
|
||||
Matrix t;
|
||||
t.setTransformation(x, y, a, sx, sy, ox, oy, kx, ky);
|
||||
t.transform(sprite, sprite, 4);
|
||||
|
||||
@@ -138,7 +138,7 @@ int SpriteBatch::addq(Quad *quad, float x, float y, float a, float sx, float sy,
|
||||
// Needed for colors.
|
||||
memcpy(sprite, quad->getVertices(), sizeof(Vertex) * 4);
|
||||
|
||||
static Matrix t;
|
||||
Matrix t;
|
||||
t.setTransformation(x, y, a, sx, sy, ox, oy, kx, ky);
|
||||
t.transform(sprite, sprite, 4);
|
||||
|
||||
|
||||
@@ -346,6 +346,38 @@ int w_Shader_send(lua_State *L)
|
||||
return luaL_argerror(L, 3, "number, boolean, table, image, or canvas expected");
|
||||
}
|
||||
|
||||
int w_Shader_getExternVariable(lua_State *L)
|
||||
{
|
||||
Shader *shader = luax_checkshader(L, 1);
|
||||
const char *name = luaL_checkstring(L, 2);
|
||||
|
||||
int components = 0;
|
||||
int arrayelements = 0;
|
||||
Shader::UniformType type = Shader::UNIFORM_UNKNOWN;
|
||||
|
||||
type = shader->getExternVariable(name, components, arrayelements);
|
||||
|
||||
// Check if the variable exists (function will set components to 0 if not.)
|
||||
if (components > 0)
|
||||
{
|
||||
const char *tname = nullptr;
|
||||
if (!Shader::getConstant(type, tname))
|
||||
return luaL_error(L, "Unknown extern variable type name.");
|
||||
|
||||
lua_pushstring(L, tname);
|
||||
lua_pushinteger(L, components);
|
||||
lua_pushinteger(L, arrayelements);
|
||||
}
|
||||
else
|
||||
{
|
||||
lua_pushnil(L);
|
||||
lua_pushnil(L);
|
||||
lua_pushnil(L);
|
||||
}
|
||||
|
||||
return 3;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getWarnings", w_Shader_getWarnings },
|
||||
@@ -355,6 +387,7 @@ static const luaL_Reg functions[] =
|
||||
{ "sendMatrix", w_Shader_sendMatrix },
|
||||
{ "sendTexture", w_Shader_sendTexture },
|
||||
{ "send", w_Shader_send },
|
||||
{ "getExternVariable", w_Shader_getExternVariable },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ int w_Shader_sendFloat(lua_State *L);
|
||||
int w_Shader_sendMatrix(lua_State *L);
|
||||
int w_Shader_sendTexture(lua_State *L);
|
||||
int w_Shader_send(lua_State *L);
|
||||
int w_Shader_getExternVariable(lua_State *L);
|
||||
extern "C" int luaopen_shader(lua_State *L);
|
||||
|
||||
} // opengl
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace love
|
||||
namespace joystick
|
||||
{
|
||||
|
||||
float Joystick::clampval(float x) const
|
||||
float Joystick::clampval(float x)
|
||||
{
|
||||
if (fabsf(x) < 0.01)
|
||||
return 0.0f;
|
||||
|
||||
@@ -173,9 +173,7 @@ public:
|
||||
static bool getConstant(const char *in, InputType &out);
|
||||
static bool getConstant(InputType in, const char *&out);
|
||||
|
||||
protected:
|
||||
|
||||
float clampval(float x) const;
|
||||
static float clampval(float x);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
@@ -51,12 +51,11 @@ bool Keyboard::hasKeyRepeat() const
|
||||
|
||||
bool Keyboard::isDown(Key *keylist) const
|
||||
{
|
||||
const Uint8 *keystate = SDL_GetKeyboardState(0);
|
||||
std::map<Key, SDL_Keycode>::const_iterator it;
|
||||
const Uint8 *keystate = SDL_GetKeyboardState(nullptr);
|
||||
|
||||
for (Key key = *keylist; key != KEY_MAX_ENUM; key = *(++keylist))
|
||||
{
|
||||
it = keys.find(key);
|
||||
auto it = keys.find(key);
|
||||
if (it != keys.end() && keystate[SDL_GetScancodeFromKey(it->second)])
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -56,6 +56,8 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
// Whether holding down a key triggers repeated key press events.
|
||||
// The real implementation is in love::event::sdl::Event::Convert.
|
||||
bool key_repeat;
|
||||
|
||||
static std::map<Key, SDL_Keycode> createKeyMap();
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace love
|
||||
namespace keyboard
|
||||
{
|
||||
|
||||
static Keyboard *instance = 0;
|
||||
static Keyboard *instance = nullptr;
|
||||
|
||||
int w_setKeyRepeat(lua_State *L)
|
||||
{
|
||||
@@ -87,7 +87,7 @@ static const luaL_Reg functions[] =
|
||||
|
||||
extern "C" int luaopen_love_keyboard(lua_State *L)
|
||||
{
|
||||
if (instance == 0)
|
||||
if (instance == nullptr)
|
||||
{
|
||||
EXCEPT_GUARD(instance = new love::keyboard::sdl::Keyboard();)
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ void RandomGenerator::setSeed(RandomGenerator::Seed newseed)
|
||||
{
|
||||
// 0 xor 0 is still 0, so Xorshift can't generate new numbers.
|
||||
if (newseed.b64 == 0)
|
||||
throw love::Exception("Invalid random seed.");
|
||||
throw love::Exception("Random seed cannot be 0.");
|
||||
|
||||
seed = newseed;
|
||||
rng_state = seed;
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace sdl
|
||||
{
|
||||
|
||||
Cursor::Cursor(image::ImageData *data, int hotx, int hoty)
|
||||
: cursor(0)
|
||||
: cursor(nullptr)
|
||||
, type(CURSORTYPE_IMAGE)
|
||||
, systemType(CURSOR_MAX_ENUM)
|
||||
{
|
||||
@@ -63,7 +63,7 @@ Cursor::Cursor(image::ImageData *data, int hotx, int hoty)
|
||||
}
|
||||
|
||||
Cursor::Cursor(mouse::Cursor::SystemCursor cursortype)
|
||||
: cursor(0)
|
||||
: cursor(nullptr)
|
||||
, type(CURSORTYPE_SYSTEM)
|
||||
, systemType(cursortype)
|
||||
{
|
||||
|
||||
@@ -71,7 +71,7 @@ const char *Mouse::getName() const
|
||||
}
|
||||
|
||||
Mouse::Mouse()
|
||||
: curCursor(0)
|
||||
: curCursor(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ void Mouse::setVisible(bool visible)
|
||||
|
||||
bool Mouse::isDown(Button *buttonlist) const
|
||||
{
|
||||
Uint32 buttonstate = SDL_GetMouseState(0, 0);
|
||||
Uint32 buttonstate = SDL_GetMouseState(nullptr, nullptr);
|
||||
|
||||
for (Button button = *buttonlist; button != BUTTON_MAX_ENUM; button = *(++buttonlist))
|
||||
{
|
||||
|
||||
@@ -36,7 +36,7 @@ int w_Cursor_getType(lua_State *L)
|
||||
Cursor *cursor = luax_checkcursor(L, 1);
|
||||
|
||||
Cursor::CursorType ctype = cursor->getType();
|
||||
const char *typestr = 0;
|
||||
const char *typestr = nullptr;
|
||||
|
||||
if (ctype == Cursor::CURSORTYPE_IMAGE)
|
||||
mouse::Cursor::getConstant(ctype, typestr);
|
||||
|
||||
@@ -30,11 +30,11 @@ namespace love
|
||||
namespace mouse
|
||||
{
|
||||
|
||||
static Mouse *instance = 0;
|
||||
static Mouse *instance = nullptr;
|
||||
|
||||
int w_newCursor(lua_State *L)
|
||||
{
|
||||
Cursor *cursor = 0;
|
||||
Cursor *cursor = nullptr;
|
||||
|
||||
if (lua_isstring(L, 1) || luax_istype(L, 1, FILESYSTEM_FILE_T) || luax_istype(L, 1, FILESYSTEM_FILE_DATA_T))
|
||||
luax_convobj(L, 1, "image", "newImageData");
|
||||
@@ -212,7 +212,7 @@ static const lua_CFunction types[] =
|
||||
|
||||
extern "C" int luaopen_love_mouse(lua_State *L)
|
||||
{
|
||||
if (instance == 0)
|
||||
if (instance == nullptr)
|
||||
{
|
||||
EXCEPT_GUARD(instance = new love::mouse::sdl::Mouse();)
|
||||
}
|
||||
|
||||
@@ -133,12 +133,12 @@ int Physics::newPolygonShape(lua_State *L)
|
||||
int Physics::newChainShape(lua_State *L)
|
||||
{
|
||||
int argc = lua_gettop(L)-1; // first argument is looping
|
||||
if (argc % 2 != 0)
|
||||
return luaL_error(L, "Number of vertex components must be a multiple of two.");
|
||||
|
||||
int vcount = (int)argc/2;
|
||||
|
||||
b2ChainShape *s = new b2ChainShape();
|
||||
|
||||
bool loop = luax_toboolean(L, 1);
|
||||
|
||||
b2Vec2 *vecs = new b2Vec2[vcount];
|
||||
|
||||
for (int i = 0; i<vcount; i++)
|
||||
@@ -166,7 +166,6 @@ int Physics::newChainShape(lua_State *L)
|
||||
delete[] vecs;
|
||||
|
||||
ChainShape *c = new ChainShape(s);
|
||||
|
||||
luax_pushtype(L, "ChainShape", PHYSICS_CHAIN_SHAPE_T, c);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace love
|
||||
namespace system
|
||||
{
|
||||
|
||||
static System *instance = 0;
|
||||
static System *instance = nullptr;
|
||||
|
||||
int w_getOS(lua_State *L)
|
||||
{
|
||||
@@ -99,7 +99,7 @@ static const luaL_Reg functions[] =
|
||||
|
||||
extern "C" int luaopen_love_system(lua_State *L)
|
||||
{
|
||||
if (instance == 0)
|
||||
if (instance == nullptr)
|
||||
{
|
||||
instance = new love::system::sdl::System();
|
||||
}
|
||||
@@ -111,7 +111,7 @@ extern "C" int luaopen_love_system(lua_State *L)
|
||||
w.name = "system";
|
||||
w.flags = MODULE_T;
|
||||
w.functions = functions;
|
||||
w.types = 0;
|
||||
w.types = nullptr;
|
||||
|
||||
return luax_register_module(L, w);
|
||||
}
|
||||
|
||||
@@ -26,13 +26,14 @@
|
||||
#include <string>
|
||||
|
||||
// LOVE
|
||||
#include <common/Variant.h>
|
||||
#include <thread/threads.h>
|
||||
#include "common/Variant.h"
|
||||
#include "threads.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace thread
|
||||
{
|
||||
|
||||
class Channel : public love::Object
|
||||
{
|
||||
// FOR WRAPPER USE ONLY
|
||||
@@ -40,8 +41,10 @@ friend void retainVariant(Channel *, Variant *);
|
||||
friend void releaseVariant(Channel *, Variant *);
|
||||
|
||||
public:
|
||||
|
||||
Channel();
|
||||
~Channel();
|
||||
|
||||
static Channel *getChannel(const std::string &name);
|
||||
|
||||
unsigned long push(Variant *var);
|
||||
@@ -56,6 +59,7 @@ public:
|
||||
void release();
|
||||
|
||||
private:
|
||||
|
||||
Channel(const std::string &name);
|
||||
void lockMutex();
|
||||
void unlockMutex();
|
||||
@@ -68,7 +72,9 @@ private:
|
||||
|
||||
unsigned long sent;
|
||||
unsigned long received;
|
||||
|
||||
}; // Channel
|
||||
|
||||
} // thread
|
||||
} // love
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ LuaThread::LuaThread(const std::string &name, love::Data *code)
|
||||
, nargs(0)
|
||||
{
|
||||
code->retain();
|
||||
threadName = name;
|
||||
}
|
||||
|
||||
LuaThread::~LuaThread()
|
||||
|
||||
@@ -25,15 +25,16 @@
|
||||
#include <string>
|
||||
|
||||
// LOVE
|
||||
#include <common/Data.h>
|
||||
#include <common/Object.h>
|
||||
#include <common/Variant.h>
|
||||
#include <thread/threads.h>
|
||||
#include "common/Data.h"
|
||||
#include "common/Object.h"
|
||||
#include "common/Variant.h"
|
||||
#include "threads.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace thread
|
||||
{
|
||||
|
||||
class LuaThread : public love::Object, public Threadable
|
||||
{
|
||||
public:
|
||||
@@ -55,7 +56,9 @@ private:
|
||||
|
||||
Variant **args;
|
||||
int nargs;
|
||||
};
|
||||
|
||||
}; // LuaThread
|
||||
|
||||
} // thread
|
||||
} // love
|
||||
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
#define LOVE_THREAD_THREAD_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include <common/Object.h>
|
||||
#include "common/runtime.h"
|
||||
#include "common/Object.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
|
||||
@@ -51,7 +51,7 @@ bool Thread::start()
|
||||
return false;
|
||||
if (thread) // Clean old handle up
|
||||
SDL_WaitThread(thread, 0);
|
||||
thread = SDL_CreateThread(thread_runner, NULL, this);
|
||||
thread = SDL_CreateThread(thread_runner, t->getThreadName(), this);
|
||||
running = (thread != 0);
|
||||
return running;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#define LOVE_THREAD_SDL_THREAD_H
|
||||
|
||||
// LOVE
|
||||
#include <thread/Thread.h>
|
||||
#include "thread/Thread.h"
|
||||
#include "threads.h"
|
||||
|
||||
// SDL
|
||||
@@ -34,6 +34,7 @@ namespace thread
|
||||
{
|
||||
namespace sdl
|
||||
{
|
||||
|
||||
class Thread : public thread::Thread
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace thread
|
||||
{
|
||||
namespace sdl
|
||||
{
|
||||
|
||||
Mutex::Mutex()
|
||||
{
|
||||
mutex = SDL_CreateMutex();
|
||||
@@ -81,6 +82,11 @@ bool Conditional::wait(thread::Mutex *_mutex, int timeout)
|
||||
|
||||
} // sdl
|
||||
|
||||
|
||||
/**
|
||||
* Implementations of the functions declared in src/modules/threads.h.
|
||||
**/
|
||||
|
||||
thread::Mutex *newMutex()
|
||||
{
|
||||
return new sdl::Mutex();
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
#ifndef LOVE_THREAD_SDL_THREADS_H
|
||||
#define LOVE_THREAD_SDL_THREADS_H
|
||||
|
||||
#include <common/config.h>
|
||||
#include <thread/threads.h>
|
||||
#include "common/config.h"
|
||||
#include "thread/threads.h"
|
||||
|
||||
#include <SDL_thread.h>
|
||||
|
||||
@@ -32,11 +32,13 @@ namespace thread
|
||||
{
|
||||
namespace sdl
|
||||
{
|
||||
|
||||
class Conditional;
|
||||
|
||||
class Mutex : public thread::Mutex
|
||||
{
|
||||
public:
|
||||
|
||||
Mutex();
|
||||
~Mutex();
|
||||
|
||||
@@ -44,15 +46,18 @@ public:
|
||||
void unlock();
|
||||
|
||||
private:
|
||||
|
||||
SDL_mutex *mutex;
|
||||
Mutex(const Mutex&/* mutex*/) {}
|
||||
|
||||
friend class Conditional;
|
||||
};
|
||||
|
||||
}; // Mutex
|
||||
|
||||
class Conditional : public thread::Conditional
|
||||
{
|
||||
public:
|
||||
|
||||
Conditional();
|
||||
~Conditional();
|
||||
|
||||
@@ -61,8 +66,10 @@ public:
|
||||
bool wait(thread::Mutex *mutex, int timeout=-1);
|
||||
|
||||
private:
|
||||
|
||||
SDL_cond *cond;
|
||||
};
|
||||
|
||||
}; // Conditional
|
||||
|
||||
} // sdl
|
||||
} // thread
|
||||
|
||||
@@ -99,5 +99,10 @@ bool Threadable::isRunning() const
|
||||
return owner->isRunning();
|
||||
}
|
||||
|
||||
const char *Threadable::getThreadName() const
|
||||
{
|
||||
return threadName.empty() ? nullptr : threadName.c_str();
|
||||
}
|
||||
|
||||
} // thread
|
||||
} // love
|
||||
|
||||
@@ -21,9 +21,13 @@
|
||||
#ifndef LOVE_THREAD_THREADS_H
|
||||
#define LOVE_THREAD_THREADS_H
|
||||
|
||||
#include <common/config.h>
|
||||
// LOVE
|
||||
#include "common/config.h"
|
||||
#include "Thread.h"
|
||||
|
||||
// C++
|
||||
#include <string>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace thread
|
||||
@@ -83,9 +87,13 @@ public:
|
||||
bool start();
|
||||
void wait();
|
||||
bool isRunning() const;
|
||||
const char *getThreadName() const;
|
||||
|
||||
protected:
|
||||
|
||||
Thread *owner;
|
||||
std::string threadName;
|
||||
|
||||
};
|
||||
|
||||
Mutex *newMutex();
|
||||
|
||||
Reference in New Issue
Block a user