mirror of
https://github.com/love2d/love.git
synced 2026-08-15 15:51:12 +02:00
Merge default into minor
--HG-- branch : minor
This commit is contained in:
@@ -104,10 +104,7 @@ Source::Source(Pool *pool, love::sound::SoundData *soundData)
|
||||
if (fmt == 0)
|
||||
throw InvalidFormatException(soundData->getChannels(), soundData->getBitDepth());
|
||||
|
||||
staticBuffer.set(new StaticDataBuffer(fmt, soundData->getData(), (ALsizei) soundData->getSize(), soundData->getSampleRate()));
|
||||
|
||||
// The buffer has a +2 retain count right now, but we want it to have +1.
|
||||
staticBuffer->release();
|
||||
staticBuffer.set(new StaticDataBuffer(fmt, soundData->getData(), (ALsizei) soundData->getSize(), sampleRate), Acquire::NORETAIN);
|
||||
|
||||
float z[3] = {0, 0, 0};
|
||||
|
||||
@@ -179,11 +176,7 @@ Source::Source(const Source &s)
|
||||
if (type == TYPE_STREAM)
|
||||
{
|
||||
if (s.decoder.get())
|
||||
{
|
||||
love::sound::Decoder *dec = s.decoder->clone();
|
||||
decoder.set(dec);
|
||||
dec->release();
|
||||
}
|
||||
decoder.set(s.decoder->clone(), Acquire::NORETAIN);
|
||||
|
||||
alGenBuffers(MAX_BUFFERS, streamBuffers);
|
||||
}
|
||||
|
||||
@@ -74,16 +74,14 @@ int w_wait(lua_State *L)
|
||||
|
||||
int w_push(lua_State *L)
|
||||
{
|
||||
Message *m = Message::fromLua(L, 1);
|
||||
StrongRef<Message> m(Message::fromLua(L, 1), Acquire::NORETAIN);
|
||||
|
||||
luax_pushboolean(L, m != nullptr);
|
||||
luax_pushboolean(L, m.get() != nullptr);
|
||||
|
||||
if (m == nullptr)
|
||||
if (m.get() == nullptr)
|
||||
return 1;
|
||||
|
||||
instance()->push(m);
|
||||
m->release();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -101,9 +99,8 @@ int w_quit(lua_State *L)
|
||||
if (Variant::fromLua(L, 1, &v))
|
||||
args.push_back(v);
|
||||
|
||||
Message *m = new Message("quit", args);
|
||||
StrongRef<Message> m(new Message("quit", args), Acquire::NORETAIN);
|
||||
instance()->push(m);
|
||||
m->release();
|
||||
|
||||
luax_pushboolean(L, true);
|
||||
return 1;
|
||||
|
||||
@@ -78,7 +78,7 @@ bool FileData::getConstant(const char *in, Decoder &out)
|
||||
return decoders.find(in, out);
|
||||
}
|
||||
|
||||
bool FileData::getConstant(Decoder in, const char *&out)
|
||||
bool FileData::getConstant(Decoder in, const char *&out)
|
||||
{
|
||||
return decoders.find(in, out);
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ public:
|
||||
const std::string &getExtension() const;
|
||||
|
||||
static bool getConstant(const char *in, Decoder &out);
|
||||
static bool getConstant(Decoder in, const char *&out);
|
||||
static bool getConstant(Decoder in, const char *&out);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
@@ -108,13 +108,13 @@ int w_File_isOpen(lua_State *L)
|
||||
int w_File_read(lua_State *L)
|
||||
{
|
||||
File *file = luax_checkfile(L, 1);
|
||||
Data *d = 0;
|
||||
StrongRef<Data> d = nullptr;
|
||||
|
||||
int64 size = (int64) luaL_optnumber(L, 2, (lua_Number) File::ALL);
|
||||
|
||||
try
|
||||
{
|
||||
d = file->read(size);
|
||||
d.set(file->read(size), Acquire::NORETAIN);
|
||||
}
|
||||
catch (love::Exception &e)
|
||||
{
|
||||
@@ -123,7 +123,6 @@ int w_File_read(lua_State *L)
|
||||
|
||||
lua_pushlstring(L, (const char *) d->getData(), d->getSize());
|
||||
lua_pushnumber(L, d->getSize());
|
||||
d->release();
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
||||
@@ -223,17 +223,16 @@ int w_newFileData(lua_State *L)
|
||||
{
|
||||
File *file = luax_checkfile(L, 1);
|
||||
|
||||
FileData *data = 0;
|
||||
StrongRef<FileData> data;
|
||||
try
|
||||
{
|
||||
data = file->read();
|
||||
data.set(file->read(), Acquire::NORETAIN);
|
||||
}
|
||||
catch (love::Exception &e)
|
||||
{
|
||||
return luax_ioError(L, "%s", e.what());
|
||||
}
|
||||
luax_pushtype(L, FILESYSTEM_FILE_DATA_ID, data);
|
||||
data->release();
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -198,12 +198,11 @@ void BMFontRasterizer::parseConfig(const std::string &configtext)
|
||||
if (!imagemodule)
|
||||
throw love::Exception("Image module not loaded!");
|
||||
|
||||
// Release these variables right away since StrongRef retains.
|
||||
StrongRef<FileData> data = filesystem->read(filename.c_str());
|
||||
data->release();
|
||||
// read() returns a retained ref already.
|
||||
StrongRef<FileData> data(filesystem->read(filename.c_str()), Acquire::NORETAIN);
|
||||
|
||||
images[pageindex].set(imagemodule->newImageData(data.get()));
|
||||
images[pageindex]->release();
|
||||
// Same with newImageData.
|
||||
images[pageindex].set(imagemodule->newImageData(data.get()), Acquire::NORETAIN);
|
||||
}
|
||||
}
|
||||
else if (tag == "char")
|
||||
|
||||
@@ -43,9 +43,7 @@ public:
|
||||
|
||||
Rasterizer *Font::newTrueTypeRasterizer(int size, TrueTypeRasterizer::Hinting hinting)
|
||||
{
|
||||
StrongRef<DefaultFontData> data(new DefaultFontData);
|
||||
data->release();
|
||||
|
||||
StrongRef<DefaultFontData> data(new DefaultFontData, Acquire::NORETAIN);
|
||||
return newTrueTypeRasterizer(data.get(), size, hinting);
|
||||
}
|
||||
|
||||
|
||||
@@ -40,18 +40,7 @@ GlyphData::GlyphData(uint32 glyph, GlyphMetrics glyphMetrics, GlyphData::Format
|
||||
, format(f)
|
||||
{
|
||||
if (metrics.width > 0 && metrics.height > 0)
|
||||
{
|
||||
switch (f)
|
||||
{
|
||||
case GlyphData::FORMAT_LUMINANCE_ALPHA:
|
||||
data = new unsigned char[metrics.width * metrics.height * 2];
|
||||
break;
|
||||
case GlyphData::FORMAT_RGBA:
|
||||
default:
|
||||
data = new unsigned char[metrics.width * metrics.height * 4];
|
||||
break;
|
||||
}
|
||||
}
|
||||
data = new uint8[metrics.width * metrics.height * getPixelSize()];
|
||||
}
|
||||
|
||||
GlyphData::~GlyphData()
|
||||
@@ -61,22 +50,30 @@ GlyphData::~GlyphData()
|
||||
|
||||
void *GlyphData::getData() const
|
||||
{
|
||||
return (void *) data;
|
||||
return data;
|
||||
}
|
||||
|
||||
size_t GlyphData::getPixelSize() const
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case FORMAT_LUMINANCE_ALPHA:
|
||||
return 2;
|
||||
case FORMAT_RGBA:
|
||||
default:
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
||||
void *GlyphData::getData(int x, int y) const
|
||||
{
|
||||
size_t offset = (y * getWidth() + x) * getPixelSize();
|
||||
return data + offset;
|
||||
}
|
||||
|
||||
size_t GlyphData::getSize() const
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case GlyphData::FORMAT_LUMINANCE_ALPHA:
|
||||
return size_t(getWidth() * getHeight() * 2);
|
||||
break;
|
||||
case GlyphData::FORMAT_RGBA:
|
||||
default:
|
||||
return size_t(getWidth() * getHeight() * 4);
|
||||
break;
|
||||
}
|
||||
|
||||
return size_t(getWidth() * getHeight()) * getPixelSize();
|
||||
}
|
||||
|
||||
int GlyphData::getHeight() const
|
||||
@@ -133,22 +130,22 @@ int GlyphData::getBearingY() const
|
||||
|
||||
int GlyphData::getMinX() const
|
||||
{
|
||||
return this->getBearingX();
|
||||
return getBearingX();
|
||||
}
|
||||
|
||||
int GlyphData::getMinY() const
|
||||
{
|
||||
return this->getHeight() - this->getBearingY();
|
||||
return getHeight() - getBearingY();
|
||||
}
|
||||
|
||||
int GlyphData::getMaxX() const
|
||||
{
|
||||
return this->getBearingX() + this->getWidth();
|
||||
return getBearingX() + getWidth();
|
||||
}
|
||||
|
||||
int GlyphData::getMaxY() const
|
||||
{
|
||||
return this->getBearingY();
|
||||
return getBearingY();
|
||||
}
|
||||
|
||||
GlyphData::Format GlyphData::getFormat() const
|
||||
@@ -168,8 +165,8 @@ bool GlyphData::getConstant(GlyphData::Format in, const char *&out)
|
||||
|
||||
StringMap<GlyphData::Format, GlyphData::FORMAT_MAX_ENUM>::Entry GlyphData::formatEntries[] =
|
||||
{
|
||||
{"luminancealpha", GlyphData::FORMAT_LUMINANCE_ALPHA},
|
||||
{"rgba", GlyphData::FORMAT_RGBA},
|
||||
{"luminancealpha", FORMAT_LUMINANCE_ALPHA},
|
||||
{"rgba", FORMAT_RGBA},
|
||||
};
|
||||
|
||||
StringMap<GlyphData::Format, GlyphData::FORMAT_MAX_ENUM> GlyphData::formats(GlyphData::formatEntries, sizeof(GlyphData::formatEntries));
|
||||
|
||||
@@ -69,6 +69,16 @@ public:
|
||||
void *getData() const;
|
||||
size_t getSize() const;
|
||||
|
||||
/**
|
||||
* Gets the data starting at a specific pixel in the glyph.
|
||||
**/
|
||||
void *getData(int x, int y) const;
|
||||
|
||||
/**
|
||||
* Gets the size in bytes of each pixel in the glyph.
|
||||
**/
|
||||
size_t getPixelSize() const;
|
||||
|
||||
/**
|
||||
* Gets the height of the glyph.
|
||||
**/
|
||||
@@ -141,7 +151,7 @@ private:
|
||||
GlyphMetrics metrics;
|
||||
|
||||
// Glyph texture data.
|
||||
unsigned char *data;
|
||||
uint8 *data;
|
||||
|
||||
// The format the data's in.
|
||||
Format format;
|
||||
|
||||
@@ -203,11 +203,10 @@ void Graphics::checkSetDefaultFont()
|
||||
if (!fontmodule)
|
||||
throw love::Exception("Font module has not been loaded.");
|
||||
|
||||
StrongRef<font::Rasterizer> r(fontmodule->newTrueTypeRasterizer(12, font::TrueTypeRasterizer::HINTING_NORMAL));
|
||||
r->release();
|
||||
auto hinting = font::TrueTypeRasterizer::HINTING_NORMAL;
|
||||
StrongRef<font::Rasterizer> r(fontmodule->newTrueTypeRasterizer(12, hinting), Acquire::NORETAIN);
|
||||
|
||||
defaultFont.set(newFont(r.get()));
|
||||
defaultFont->release();
|
||||
defaultFont.set(newFont(r.get()), Acquire::NORETAIN);
|
||||
}
|
||||
|
||||
states.back().font.set(defaultFont.get());
|
||||
|
||||
@@ -133,7 +133,11 @@ Image::Image(const std::vector<love::image::CompressedImageData *> &compressedda
|
||||
if (compresseddata[0]->getMipmapCount() == 1)
|
||||
this->flags.mipmaps = false;
|
||||
else
|
||||
throw love::Exception("Image cannot have mipmaps: compressed image data does not have all required mipmap levels.");
|
||||
{
|
||||
throw love::Exception("Image cannot have mipmaps: compressed image data does not have all required mipmap levels (expected %d, got %d)",
|
||||
getMipmapCount(width, height),
|
||||
compresseddata[0]->getMipmapCount());
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto &cd : compresseddata)
|
||||
|
||||
@@ -124,10 +124,7 @@ void ImageData::decode(love::filesystem::FileData *data)
|
||||
// The decoder *must* output a 32 bits-per-pixel image.
|
||||
if (decodedimage.size != decodedimage.width*decodedimage.height*sizeof(pixel))
|
||||
{
|
||||
if (decodeHandler)
|
||||
decodeHandler->free(decodedimage.data);
|
||||
else
|
||||
delete[] decodedimage.data;
|
||||
decoder->free(decodedimage.data);
|
||||
throw love::Exception("Could not convert image!");
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,12 @@ FormatHandler::DecodedImage STBHandler::decode(love::filesystem::FileData *data)
|
||||
&comp, 4);
|
||||
|
||||
if (img.data == nullptr || img.width <= 0 || img.height <= 0)
|
||||
throw love::Exception("Could not decode image with stb_image.");
|
||||
{
|
||||
const char *err = stbi_failure_reason();
|
||||
if (err == nullptr)
|
||||
err = "unknown error";
|
||||
throw love::Exception("Could not decode image with stb_image (%s).", err);
|
||||
}
|
||||
|
||||
img.size = img.width * img.height * 4;
|
||||
|
||||
|
||||
@@ -118,8 +118,8 @@ int w_Fixture_getBody(lua_State *L)
|
||||
int w_Fixture_getShape(lua_State *L)
|
||||
{
|
||||
Fixture *t = luax_checkfixture(L, 1);
|
||||
Shape *shape = t->getShape();
|
||||
if (shape == 0)
|
||||
StrongRef<Shape> shape(t->getShape(), Acquire::NORETAIN);
|
||||
if (shape.get() == nullptr)
|
||||
return 0;
|
||||
switch (shape->getType())
|
||||
{
|
||||
@@ -139,7 +139,6 @@ int w_Fixture_getShape(lua_State *L)
|
||||
luax_pushtype(L, PHYSICS_SHAPE_ID, shape);
|
||||
break;
|
||||
}
|
||||
shape->release();
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -58,12 +58,17 @@ Channel *Channel::getChannel(const std::string &name)
|
||||
if (!namedChannelMutex)
|
||||
namedChannelMutex = newMutex();
|
||||
|
||||
Lock l(namedChannelMutex);
|
||||
if (!namedChannels.count(name))
|
||||
namedChannels[name] = new Channel(name);
|
||||
else
|
||||
namedChannels[name]->retain();
|
||||
Lock lock(namedChannelMutex);
|
||||
|
||||
auto it = namedChannels.find(name);
|
||||
|
||||
if (it != namedChannels.end())
|
||||
{
|
||||
it->second->retain();
|
||||
return it->second;
|
||||
}
|
||||
|
||||
namedChannels[name] = new Channel(name);
|
||||
return namedChannels[name];
|
||||
}
|
||||
|
||||
@@ -92,7 +97,10 @@ Channel::~Channel()
|
||||
delete cond;
|
||||
|
||||
if (named)
|
||||
{
|
||||
Lock l(namedChannelMutex);
|
||||
namedChannels.erase(name);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned long Channel::push(const Variant &var)
|
||||
@@ -196,22 +204,5 @@ void Channel::unlockMutex()
|
||||
mutex->unlock();
|
||||
}
|
||||
|
||||
void Channel::retain()
|
||||
{
|
||||
EmptyLock l;
|
||||
if (named)
|
||||
l.setLock(namedChannelMutex);
|
||||
|
||||
Object::retain();
|
||||
}
|
||||
|
||||
void Channel::release()
|
||||
{
|
||||
EmptyLock l;
|
||||
if (named)
|
||||
l.setLock(namedChannelMutex);
|
||||
|
||||
Object::release();
|
||||
}
|
||||
} // thread
|
||||
} // love
|
||||
|
||||
@@ -54,9 +54,6 @@ public:
|
||||
int getCount();
|
||||
void clear();
|
||||
|
||||
void retain();
|
||||
void release();
|
||||
|
||||
private:
|
||||
|
||||
Channel(const std::string &name);
|
||||
|
||||
@@ -116,9 +116,8 @@ void LuaThread::onError()
|
||||
Variant(error.c_str(), error.length())
|
||||
};
|
||||
|
||||
event::Message *msg = new event::Message("threaderror", vargs);
|
||||
StrongRef<event::Message> msg(new event::Message("threaderror", vargs), Acquire::NORETAIN);
|
||||
eventmodule->push(msg);
|
||||
msg->release();
|
||||
}
|
||||
|
||||
} // thread
|
||||
|
||||
@@ -27,8 +27,7 @@ namespace thread
|
||||
|
||||
LuaThread *ThreadModule::newThread(const std::string &name, love::Data *data)
|
||||
{
|
||||
LuaThread *lt = new LuaThread(name, data);
|
||||
return lt;
|
||||
return new LuaThread(name, data);
|
||||
}
|
||||
|
||||
Channel *ThreadModule::newChannel()
|
||||
|
||||
@@ -64,8 +64,7 @@ VideoStream::VideoStream(love::filesystem::File *file)
|
||||
throw ex;
|
||||
}
|
||||
|
||||
frameSync = new DeltaSync();
|
||||
frameSync->release();
|
||||
frameSync.set(new DeltaSync(), Acquire::NORETAIN);
|
||||
}
|
||||
|
||||
VideoStream::~VideoStream()
|
||||
|
||||
Reference in New Issue
Block a user