From a1fe4cac9d88ef3fbfe66ff6bc5aa02fabc7f57e Mon Sep 17 00:00:00 2001 From: Robert Konrad Date: Sat, 9 Mar 2024 18:51:49 +0100 Subject: [PATCH] Fix compilation with latest Kinc --- Sources/Kore/Audio1/Sound.cpp | 2 +- Sources/Kore/Audio1/SoundStream.cpp | 2 +- Sources/Kore/Graphics1/Image.cpp | 6 +++--- Sources/Kore/Graphics4/Shader.cpp | 2 +- Sources/Kore/Graphics4/Shader.h | 2 +- Sources/Kore/IO/BufferReader.cpp | 16 +++++++++------- Sources/Kore/IO/BufferReader.h | 14 +++++++------- Sources/Kore/IO/FileReader.h | 8 ++++---- Sources/Kore/IO/FileReader.winrt.cpp | 10 +++++----- Sources/Kore/IO/Reader.h | 8 ++++---- 10 files changed, 36 insertions(+), 34 deletions(-) diff --git a/Sources/Kore/Audio1/Sound.cpp b/Sources/Kore/Audio1/Sound.cpp index 28d363f43..bd4c1982b 100644 --- a/Sources/Kore/Audio1/Sound.cpp +++ b/Sources/Kore/Audio1/Sound.cpp @@ -110,7 +110,7 @@ void Sound::load(Reader &file, const char *filename) { if (strncmp(&filename[filenameLength - 4], ".ogg", 4) == 0) { u8 *filedata = (u8 *)file.readAll(); - int samples = stb_vorbis_decode_memory(filedata, file.size(), &format.channels, &format.samplesPerSecond, (short **)&data); + int samples = stb_vorbis_decode_memory(filedata, (int)file.size(), &format.channels, &format.samplesPerSecond, (short **)&data); size = samples * 2 * format.channels; format.bitsPerSample = 16; length = samples / (float)format.samplesPerSecond; diff --git a/Sources/Kore/Audio1/SoundStream.cpp b/Sources/Kore/Audio1/SoundStream.cpp index 312d1d1f2..438d0eaf0 100644 --- a/Sources/Kore/Audio1/SoundStream.cpp +++ b/Sources/Kore/Audio1/SoundStream.cpp @@ -12,7 +12,7 @@ SoundStream::SoundStream(const char *filename, bool looping) : myLooping(looping buffer = new u8[file.size()]; u8 *filecontent = (u8 *)file.readAll(); memcpy(buffer, filecontent, file.size()); - vorbis = stb_vorbis_open_memory(buffer, file.size(), nullptr, nullptr); + vorbis = stb_vorbis_open_memory(buffer, (int)file.size(), nullptr, nullptr); if (vorbis != nullptr) { stb_vorbis_info info = stb_vorbis_get_info(vorbis); chans = info.channels; diff --git a/Sources/Kore/Graphics1/Image.cpp b/Sources/Kore/Graphics1/Image.cpp index f5babfccb..e9b15a22c 100644 --- a/Sources/Kore/Graphics1/Image.cpp +++ b/Sources/Kore/Graphics1/Image.cpp @@ -15,7 +15,7 @@ using namespace Kore; namespace { - static int read_callback(void *user_data, void *data, size_t size) { + static size_t read_callback(void *user_data, void *data, size_t size) { Kore::Reader *file = (Kore::Reader *)user_data; return file->read(data, (int)size); } @@ -25,12 +25,12 @@ namespace { return (size_t)file->size(); } - static int pos_callback(void *user_data) { + static size_t pos_callback(void *user_data) { Kore::Reader *file = (Kore::Reader *)user_data; return file->pos(); } - static void seek_callback(void *user_data, int pos) { + static void seek_callback(void *user_data, size_t pos) { Kore::Reader *file = (Kore::Reader *)user_data; file->seek(pos); } diff --git a/Sources/Kore/Graphics4/Shader.cpp b/Sources/Kore/Graphics4/Shader.cpp index 9ef578f5a..94800ee70 100644 --- a/Sources/Kore/Graphics4/Shader.cpp +++ b/Sources/Kore/Graphics4/Shader.cpp @@ -3,7 +3,7 @@ using namespace Kore; using namespace Kore::Graphics4; -Shader::Shader(void *data, int length, ShaderType type) { +Shader::Shader(void *data, size_t length, ShaderType type) { kinc_g4_shader_init(&kincShader, data, length, (kinc_g4_shader_type_t)type); } diff --git a/Sources/Kore/Graphics4/Shader.h b/Sources/Kore/Graphics4/Shader.h index 3eeb6166f..16ac45c2b 100644 --- a/Sources/Kore/Graphics4/Shader.h +++ b/Sources/Kore/Graphics4/Shader.h @@ -15,7 +15,7 @@ namespace Kore { class Shader { public: - Shader(void *data, int length, ShaderType type); + Shader(void *data, size_t length, ShaderType type); Shader(const char *source, ShaderType type); // Beware, this is not portable virtual ~Shader(); diff --git a/Sources/Kore/IO/BufferReader.cpp b/Sources/Kore/IO/BufferReader.cpp index 216079ce5..24eaa1000 100644 --- a/Sources/Kore/IO/BufferReader.cpp +++ b/Sources/Kore/IO/BufferReader.cpp @@ -4,15 +4,17 @@ #include namespace Kore { - BufferReader::BufferReader(void const *buffer, int size) : buffer((u8 *)buffer), bufferSize(size), position(0), readAllBuffer(nullptr) {} + BufferReader::BufferReader(void const *buffer, size_t size) : buffer((u8 *)buffer), bufferSize(size), position(0), readAllBuffer(nullptr) {} BufferReader::~BufferReader() { if (readAllBuffer != nullptr) free(readAllBuffer); } - int BufferReader::read(void *data, int size) { - int bytesAvailable = bufferSize - position; - if (size > bytesAvailable) size = bytesAvailable; + size_t BufferReader::read(void *data, size_t size) { + size_t bytesAvailable = bufferSize - position; + if (size > bytesAvailable) { + size = bytesAvailable; + } memcpy(data, buffer + position, size); position += size; return size; @@ -26,15 +28,15 @@ namespace Kore { return readAllBuffer; } - int BufferReader::size() { + size_t BufferReader::size() { return bufferSize; } - int BufferReader::pos() { + size_t BufferReader::pos() { return position; } - void BufferReader::seek(int pos) { + void BufferReader::seek(size_t pos) { position = pos < 0 ? 0 : (pos > bufferSize ? bufferSize : pos); } } diff --git a/Sources/Kore/IO/BufferReader.h b/Sources/Kore/IO/BufferReader.h index 22b9e290c..caa189a90 100644 --- a/Sources/Kore/IO/BufferReader.h +++ b/Sources/Kore/IO/BufferReader.h @@ -6,17 +6,17 @@ namespace Kore { class BufferReader : public Reader { u8 *buffer; - int bufferSize; - int position; + size_t bufferSize; + size_t position; void *readAllBuffer; public: - BufferReader(void const *buffer, int size); + BufferReader(void const *buffer, size_t size); virtual ~BufferReader(); - int read(void *data, int size) override; + size_t read(void *data, size_t size) override; void *readAll() override; - int size() override; - int pos() override; - void seek(int pos) override; + size_t size() override; + size_t pos() override; + void seek(size_t pos) override; }; } diff --git a/Sources/Kore/IO/FileReader.h b/Sources/Kore/IO/FileReader.h index 1525f2975..d50e49a45 100644 --- a/Sources/Kore/IO/FileReader.h +++ b/Sources/Kore/IO/FileReader.h @@ -14,11 +14,11 @@ namespace Kore { ~FileReader(); bool open(const char *filename, FileType type = Asset); void close(); - int read(void *data, int size) override; + size_t read(void *data, size_t size) override; void *readAll() override; - int size() override; - int pos() override; - void seek(int pos) override; + size_t size() override; + size_t pos() override; + void seek(size_t pos) override; kinc_file_reader_t reader; FileType type; diff --git a/Sources/Kore/IO/FileReader.winrt.cpp b/Sources/Kore/IO/FileReader.winrt.cpp index c76054888..e38d4c448 100644 --- a/Sources/Kore/IO/FileReader.winrt.cpp +++ b/Sources/Kore/IO/FileReader.winrt.cpp @@ -21,7 +21,7 @@ bool FileReader::open(const char *filename, FileType type) { return kinc_file_reader_open(&reader, filename, (int)type); } -int FileReader::read(void *data, int size) { +size_t FileReader::read(void *data, size_t size) { return kinc_file_reader_read(&reader, data, size); } @@ -34,7 +34,7 @@ void *FileReader::readAll() { return readdata; } -void FileReader::seek(int pos) { +void FileReader::seek(size_t pos) { kinc_file_reader_seek(&reader, pos); } @@ -48,10 +48,10 @@ FileReader::~FileReader() { close(); } -int FileReader::pos() { +size_t FileReader::pos() { return kinc_file_reader_pos(&reader); } -int FileReader::size() { - return (int)kinc_file_reader_size(&reader); +size_t FileReader::size() { + return kinc_file_reader_size(&reader); } diff --git a/Sources/Kore/IO/Reader.h b/Sources/Kore/IO/Reader.h index 387f75666..3ea690025 100644 --- a/Sources/Kore/IO/Reader.h +++ b/Sources/Kore/IO/Reader.h @@ -6,11 +6,11 @@ namespace Kore { class Reader { public: virtual ~Reader() {} - virtual int read(void *data, int size) = 0; + virtual size_t read(void *data, size_t size) = 0; virtual void *readAll() = 0; - virtual int size() = 0; - virtual int pos() = 0; - virtual void seek(int pos) = 0; + virtual size_t size() = 0; + virtual size_t pos() = 0; + virtual void seek(size_t pos) = 0; float readF32LE(); float readF32BE();