summaryrefslogtreecommitdiffstats
path: root/src/Rml.cpp
diff options
context:
space:
mode:
authorLaG1924 <lag1924@gmail.com>2021-06-18 14:14:19 +0200
committerLaG1924 <lag1924@gmail.com>2021-06-18 16:52:47 +0200
commit8c033fff3d82d5f0e4c5d2eb3c5d10efc60ee851 (patch)
treee0f585207f4dde33999e73d3fbde65f0c76f8b16 /src/Rml.cpp
parentImplemented main menu in Rml and improved RmlUi support (diff)
downloadAltCraft-8c033fff3d82d5f0e4c5d2eb3c5d10efc60ee851.tar
AltCraft-8c033fff3d82d5f0e4c5d2eb3c5d10efc60ee851.tar.gz
AltCraft-8c033fff3d82d5f0e4c5d2eb3c5d10efc60ee851.tar.bz2
AltCraft-8c033fff3d82d5f0e4c5d2eb3c5d10efc60ee851.tar.lz
AltCraft-8c033fff3d82d5f0e4c5d2eb3c5d10efc60ee851.tar.xz
AltCraft-8c033fff3d82d5f0e4c5d2eb3c5d10efc60ee851.tar.zst
AltCraft-8c033fff3d82d5f0e4c5d2eb3c5d10efc60ee851.zip
Diffstat (limited to '')
-rw-r--r--src/Rml.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/Rml.cpp b/src/Rml.cpp
index abec7db..cbc795f 100644
--- a/src/Rml.cpp
+++ b/src/Rml.cpp
@@ -162,3 +162,49 @@ void RmlRenderInterface::Update(unsigned int windowWidth, unsigned int windowHei
AssetManager::GetAsset<AssetShader>("/altcraft/shaders/rmltex")->shader->SetUniform("fontTexture", 0);
glCheckError();
}
+
+Rml::FileHandle RmlFileInterface::Open(const Rml::String& path) {
+ Rml::FileHandle fileId = handles.rbegin() != handles.rend() ? handles.rbegin()->first + 1 : 1;
+ while (handles.find(fileId) != handles.end())
+ fileId++;
+
+ AssetHandle handle;
+ handle.fileName = path;
+ std::string assetName = path;
+ if (*assetName.begin() != '/')
+ assetName = "/" + assetName;
+ handle.assetPtr = AssetManager::GetAssetByAssetName(assetName);
+ handle.filePos = 0;
+
+ if (handle.assetPtr != nullptr)
+ handles.insert(std::make_pair(fileId, handle));
+ else
+ fileId = 0;
+ return fileId;
+}
+
+void RmlFileInterface::Close(Rml::FileHandle file) {
+ handles.erase(file);
+}
+
+size_t RmlFileInterface::Read(void* buffer, size_t size, Rml::FileHandle file) {
+ size_t readed = 0;
+ readed = _min(handles[file].assetPtr->data.size() - handles[file].filePos, size);
+ std::memcpy(buffer, handles[file].assetPtr->data.data() + handles[file].filePos, readed);
+ handles[file].filePos += readed;
+ return readed;
+}
+
+bool RmlFileInterface::Seek(Rml::FileHandle file, long offset, int origin) {
+ unsigned long long base = 0;
+ if (origin == SEEK_CUR)
+ base = handles[file].filePos;
+ else if (origin == SEEK_END)
+ base = handles[file].assetPtr->data.size();
+ handles[file].filePos = base + offset;
+ return true;
+}
+
+size_t RmlFileInterface::Tell(Rml::FileHandle file) {
+ return handles[file].filePos;
+}