Skip to content

Commit

Permalink
Fix compilation with latest Kinc
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Mar 9, 2024
1 parent 78e1ace commit a1fe4ca
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Sources/Kore/Audio1/Sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Sources/Kore/Audio1/SoundStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions Sources/Kore/Graphics1/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Kore/Graphics4/Shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Kore/Graphics4/Shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
16 changes: 9 additions & 7 deletions Sources/Kore/IO/BufferReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
#include <string.h>

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;
Expand All @@ -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);
}
}
14 changes: 7 additions & 7 deletions Sources/Kore/IO/BufferReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}
8 changes: 4 additions & 4 deletions Sources/Kore/IO/FileReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions Sources/Kore/IO/FileReader.winrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}
8 changes: 4 additions & 4 deletions Sources/Kore/IO/Reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit a1fe4ca

Please sign in to comment.