Browse Source

Engine: Switch to ruc::File

master
Riyyi 2 years ago
parent
commit
f61f402116
  1. 8
      src/inferno/io/gltffile.cpp
  2. 4
      src/inferno/render/font.cpp
  3. 6
      src/inferno/render/shader.cpp
  4. 4
      src/inferno/script/luascript.cpp
  5. 15
      src/inferno/settings.cpp

8
src/inferno/io/gltffile.cpp

@ -2,9 +2,9 @@
#include <fstream> // std::ifstream
#include <ios> // std::ios
#include "ruc/file.h"
#include "ruc/meta/assert.h"
#include "inferno/io/file.h"
#include "inferno/io/gltffile.h"
#include "inferno/io/log.h"
#include "inferno/util/json.h"
@ -20,7 +20,7 @@ std::pair<std::shared_ptr<char[]>, std::shared_ptr<char[]>> GltfFile::read(const
return glb(path);
}
else if (extension.compare(".gltf") == 0) {
return { File::raw(path), nullptr };
return { ruc::File::raw(path), nullptr };
}
VERIFY(false, "GltfFile unknown file extension!");
@ -38,7 +38,7 @@ std::pair<std::shared_ptr<char[]>, std::shared_ptr<char[]>> GltfFile::glb(const
constexpr uint32_t json = 27; // Minimum valid glTF has an asset property with version specifier
// Get the actual length of the file
uint32_t length = static_cast<uint32_t>(File::length(path, glb));
uint32_t length = static_cast<uint32_t>(ruc::File::length(path, glb));
VERIFY(length > header + json, "GltfFile too small to be valid '{}'", path);
// Read header
@ -62,7 +62,7 @@ std::pair<std::shared_ptr<char[]>, std::shared_ptr<char[]>> GltfFile::glb(const
VERIFY(versionInt == 2, "Gltf unsupported version '{}'", versionInt);
uint32_t fileLengthInt = *reinterpret_cast<uint32_t*>(fileLength);
VERIFY(fileLengthInt == length, "Gltf file and reported byte size mismatch '{}' '{}'", length, fileLengthInt);
VERIFY(fileLengthInt == static_cast<uint32_t>(length), "Gltf file and reported byte size mismatch '{}' '{}'", length, fileLengthInt);
// Read JSON data
auto jsonChunk = readChunk(glb, header, 0x4e4f534a);

4
src/inferno/render/font.cpp

@ -2,9 +2,9 @@
#include <string> // std::getline, std::stoi
#include <utility> // std::move
#include "ruc/file.h"
#include "ruc/meta/assert.h"
#include "inferno/io/file.h"
#include "inferno/render/font.h"
#include "inferno/render/texture.h"
#include "inferno/util/integer.h"
@ -17,7 +17,7 @@ Font::Font(const std::string& name)
std::string path = name + ".fnt";
std::string image = name + ".png";
std::string font = File::read(path);
std::string font = ruc::File(path).data();
parseFont(font);
m_texture = std::make_shared<Texture>(image);

6
src/inferno/render/shader.cpp

@ -3,10 +3,10 @@
#include "glad/glad.h"
#include "glm/gtc/type_ptr.hpp" // glm::value_ptr
#include "ruc/file.h"
#include "ruc/meta/assert.h"
#include "inferno/core.h"
#include "inferno/io/file.h"
#include "inferno/io/log.h"
#include "inferno/render/shader.h"
@ -17,8 +17,8 @@ Shader::Shader(const std::string& name)
, m_id(0)
{
// Get file contents
std::string vertexSrc = File::read(name + ".vert");
std::string fragmentSrc = File::read(name + ".frag");
std::string vertexSrc = ruc::File(name + ".vert").data();
std::string fragmentSrc = ruc::File(name + ".frag").data();
// Compile shaders
uint32_t vertexID = compileShader(GL_VERTEX_SHADER, vertexSrc.c_str());

4
src/inferno/script/luascript.cpp

@ -1,10 +1,10 @@
#include "ruc/file.h"
#include "sol/unsafe_function_result.hpp"
#include "inferno/component/cameracomponent.h"
#include "inferno/component/spritecomponent.h"
#include "inferno/component/tagcomponent.h"
#include "inferno/component/transformcomponent.h"
#include "inferno/io/file.h"
#include "inferno/scene/scene.h"
#include "inferno/script/luascript.h"
#include "inferno/script/registration.h"
@ -63,7 +63,7 @@ void LuaScript::update(float deltaTime)
void LuaScript::loadScript()
{
std::string script = File::read(m_path);
std::string script = ruc::File(m_path).data();
auto result = m_state.script(script.c_str(),
[](lua_State*, sol::protected_function_result pfr) { return pfr; });
VERIFY(result.valid(), "LuaScript {}", ((sol::error)result).what());

15
src/inferno/settings.cpp

@ -1,9 +1,9 @@
#include <cstdint> // uint32_t
#include <string> // std::string
#include "ruc/file.h"
#include "ruc/json/json.h"
#include "inferno/io/file.h"
#include "inferno/io/log.h"
#include "inferno/settings.h"
#include "inferno/window.h"
@ -28,9 +28,9 @@ void Settings::destroy()
bool Settings::load()
{
ruc::Json object;
auto object = ruc::Json::parse(ruc::File(m_path).data());
if (!File::ioRead(&object, m_path)) {
if (object.type() != ruc::Json::Type::Object) {
warn() << "Settings invalid formatting, using default values";
return false;
}
@ -44,10 +44,11 @@ bool Settings::save()
{
ruc::Json object = m_properties;
if (!File::ioWrite(&object, m_path)) {
warn() << "Settings could not be saved";
return false;
}
auto file = ruc::File(m_path);
file.clear();
file.append(object.dump(1, '\t'));
file.append("\n");
file.flush();
info() << "Settings saved";
return true;

Loading…
Cancel
Save