Rework of ScriptResolver to binary handling. Now also serialises the type database to the stream, simplifying it's api.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-05-02 11:13:04 +02:00
parent 846580550a
commit bd77b58743
6 changed files with 221 additions and 37 deletions

View File

@@ -2,23 +2,30 @@
#define PKMNLIB_FILEBYTECODESTREAM_HPP
#include <angelscript.h>
#include <cstdio>
#include "IPkmnBinaryStream.hpp"
class FileByteCodeStream : public asIBinaryStream {
class FileByteCodeStream : public IPkmnBinaryStream {
private:
FILE* _file;
size_t _readPosition = 0;
public:
explicit FileByteCodeStream(FILE* file) : _file(file) {}
explicit FileByteCodeStream(FILE* file, size_t bound) : IPkmnBinaryStream(bound), _file(file) {}
int Write(const void* ptr, asUINT size) {
int Write(const void* ptr, asUINT size) override {
if (size == 0)
return 0;
return fwrite(ptr, size, 1, _file);
}
int Read(void* ptr, asUINT size) {
int Read(void* ptr, asUINT size) override {
if (size == 0)
return 0;
return fread(ptr, size, 1, _file);
if (_readPosition + size >= _angelScriptBound) {
size = _angelScriptBound - _readPosition;
}
auto diff = fread(ptr, size, 1, _file);
_readPosition += diff;
return diff;
}
};