Merge remote-tracking branch 'origin/12.0-development' into vulkan

This commit is contained in:
niki
2022-05-06 16:46:39 +02:00
112 changed files with 1615 additions and 1368 deletions
+50 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2015 LOVE Development Team
* Copyright (c) 2006-2022 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
@@ -20,10 +20,59 @@
// LOVE
#include "Stream.h"
#include "Data.h"
#include "data/ByteData.h"
#include "Exception.h"
namespace love
{
love::Type Stream::type("Stream", &Object::type);
Data *Stream::read(int64 size)
{
int64 max = LOVE_INT64_MAX;
int64 cur = 0;
if (isSeekable())
{
max = getSize();
cur = tell();
}
if (cur < 0)
cur = 0;
else if (cur > max)
cur = max;
if (cur + size > max)
size = max - cur;
StrongRef<data::ByteData> dst(new data::ByteData(size, false), Acquire::NORETAIN);
int64 bytesRead = read(dst->getData(), size);
if (bytesRead < 0 || (bytesRead == 0 && bytesRead != size))
throw love::Exception("Could not read from stream.");
if (bytesRead < size)
dst.set(new data::ByteData(dst->getData(), (size_t) bytesRead), Acquire::NORETAIN);
dst->retain();
return dst;
}
bool Stream::write(Data *src)
{
return write(src, 0, src->getSize());
}
bool Stream::write(Data *src, int64 offset, int64 size)
{
if (offset < 0 || size < 0 || offset + size > src->getSize())
throw love::Exception("Offset and size parameters do not fit within the given Data's size.");
return write((const uint8 *) src->getData() + offset, size);
}
} // love
+64 -13
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2015 LOVE Development Team
* Copyright (c) 2006-2022 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
@@ -24,41 +24,92 @@
// LOVE
#include <stddef.h>
#include "Object.h"
#include "int.h"
namespace love
{
class Data;
class Stream : public Object
{
public:
enum SeekOrigin
{
SEEKORIGIN_BEGIN,
SEEKORIGIN_CURRENT,
SEEKORIGIN_END,
SEEKORIGIN_MAX_ENUM
};
static love::Type type;
virtual ~Stream() {}
// getData and getSize are assumed to talk about
// the buffer
/**
* Creates a new copy of the Stream, with the same settings as the original.
* The seek position will be reset in the copy.
**/
virtual Stream *clone() = 0;
/**
* A callback, gets called when some Stream consumer exhausts the data
* Gets whether read() is supported for this Stream.
**/
virtual void fillBackBuffer() {}
virtual bool isReadable() const = 0;
/**
* Get the front buffer, Streams are supposed to be (at least) double-buffered
* Gets whether write() is supported for this Stream.
**/
virtual const void *getFrontBuffer() const = 0;
virtual bool isWritable() const = 0;
/**
* Get the size of any (and in particular the front) buffer
* Gets whether seek(), tell(), and getSize() are supported for this Stream.
**/
virtual size_t getSize() const = 0;
virtual bool isSeekable() const = 0;
/**
* Swap buffers. Returns true if there is new data in the front buffer,
* false otherwise.
* NOTE: If there is no back buffer ready, this call must be ignored
* Reads data into the destination buffer, and returns the number of bytes
* actually read.
**/
virtual bool swapBuffers() = 0;
virtual int64 read(void *dst, int64 size) = 0;
/**
* Reads data into a new Data object.
**/
virtual Data *read(int64 size);
/**
* Writes data from the source buffer into the Stream.
**/
virtual bool write(const void *src, int64 size) = 0;
/**
* Writes data from the source Data object into the Stream.
**/
virtual bool write(Data *src, int64 offset, int64 size);
bool write(Data *src);
/**
* Flushes all data written to the Stream.
**/
virtual bool flush() = 0;
/**
* Gets the total size of the Stream, if supported.
**/
virtual int64 getSize() = 0;
/**
* Sets the current position in the Stream, if supported.
**/
virtual bool seek(int64 pos, SeekOrigin origin = SEEKORIGIN_BEGIN) = 0;
/**
* Gets the current position in the Stream, if supported.
**/
virtual int64 tell() = 0;
}; // Stream
} // love
+1 -1
View File
@@ -35,7 +35,7 @@
#include <sys/types.h>
#include <unistd.h>
#include "physfs.h"
#include "libraries/physfs/physfs.h"
namespace love
{
+2
View File
@@ -38,6 +38,8 @@
#endif
#if defined(__ANDROID__)
# define LOVE_ANDROID 1
// Needed for ENet
# define HAS_SOCKLEN_T 1
#endif
#if defined(__APPLE__)
# include <TargetConditionals.h>
+13 -12
View File
@@ -24,6 +24,7 @@
#include <atomic>
#include <map>
#include <sstream>
namespace love
{
@@ -97,32 +98,32 @@ bool isDeprecationOutputEnabled()
std::string getDeprecationNotice(const DeprecationInfo &info, bool usewhere)
{
std::string notice;
std::stringstream notice;
if (usewhere)
notice += info.where;
notice << info.where;
notice += "Using deprecated ";
notice << "Using deprecated ";
if (info.apiType == API_FUNCTION)
notice += "function ";
notice << "function ";
else if (info.apiType == API_METHOD)
notice += "method ";
notice << "method ";
else if (info.apiType == API_CALLBACK)
notice += "callback ";
notice << "callback ";
else if (info.apiType == API_FIELD)
notice += "field ";
notice << "field ";
else if (info.apiType == API_CONSTANT)
notice += "constant ";
notice << "constant ";
notice += info.name;
notice << info.name;
if (info.type == DEPRECATED_REPLACED && !info.replacement.empty())
notice += " (replaced by " + info.replacement + ")";
notice << " (replaced by " << info.replacement << ")";
else if (info.type == DEPRECATED_RENAMED && !info.replacement.empty())
notice += " (renamed to " + info.replacement + ")";
notice << " (renamed to " << info.replacement << ")";
return notice;
return notice.str();
}
GetDeprecated::GetDeprecated()
+12
View File
@@ -240,11 +240,23 @@ const PixelFormatInfo &getPixelFormatInfo(PixelFormat format)
return formatInfo[format];
}
const char *getPixelFormatName(PixelFormat format)
{
const char *name = "unknown";
getConstant(format, name);
return name;
}
bool isPixelFormatCompressed(PixelFormat format)
{
return formatInfo[format].compressed;
}
bool isPixelFormatColor(PixelFormat format)
{
return formatInfo[format].color;
}
bool isPixelFormatDepthStencil(PixelFormat format)
{
const PixelFormatInfo &info = formatInfo[format];
+10
View File
@@ -157,11 +157,21 @@ bool getConstant(const char *in, PixelFormat &out);
const PixelFormatInfo &getPixelFormatInfo(PixelFormat format);
/**
* Gets the name of the specified pixel format.
**/
const char *getPixelFormatName(PixelFormat format);
/**
* Gets whether the specified pixel format is a compressed type.
**/
bool isPixelFormatCompressed(PixelFormat format);
/**
* Gets whether the specified pixel format is a color type.
**/
bool isPixelFormatColor(PixelFormat format);
/**
* Gets whether the specified pixel format is a depth or stencil type.
**/