Cleanup, C string -> std::string

This commit is contained in:
wheremyfoodat 2023-07-18 22:23:28 +03:00
parent 19a77c2a85
commit 77b0382d0c
3 changed files with 14 additions and 13 deletions

View file

@ -1,6 +1,7 @@
#pragma once
#include <array>
#include <span>
#include <string>
#include <optional>
#include "PICA/pica_vertex.hpp"
@ -11,6 +12,7 @@ enum class RendererType : s8 {
// Todo: Auto = -1,
Null = 0,
OpenGL = 1,
Vulkan = 2,
};
class GPU;
@ -36,7 +38,7 @@ class Renderer {
static constexpr u32 vertexBufferSize = 0x10000;
static std::optional<RendererType> typeFromString(std::string inString);
static const char* typeToString(RendererType rendererType);
static std::string typeToString(RendererType rendererType);
virtual void reset() = 0;
virtual void display() = 0; // Display the 3DS screen contents to the window

View file

@ -34,16 +34,14 @@ void EmulatorConfig::load(const std::filesystem::path& path) {
auto gpu = gpuResult.unwrap();
// Get renderer
auto rendererResult = toml::expect<std::string>(gpu, "Renderer");
if (rendererResult.is_ok()) {
auto rendererName = rendererResult.unwrap();
if (auto configRendererType = Renderer::typeFromString(rendererName); configRendererType.has_value()) {
rendererType = configRendererType.value();
} else {
Helpers::warn("Invalid renderer specified: %s\n", rendererName.c_str());
}
auto rendererName = toml::find_or<std::string>(gpu, "Renderer", "OpenGL");
auto configRendererType = Renderer::typeFromString(rendererName);
if (configRendererType.has_value()) {
rendererType = configRendererType.value();
} else {
Helpers::warn("Renderer not specified: %s\n", rendererResult.unwrap_err().c_str());
Helpers::warn("Invalid renderer specified: %s\n", rendererName.c_str());
rendererType = RendererType::OpenGL;
}
shaderJitEnabled = toml::find_or<toml::boolean>(gpu, "EnableShaderJIT", false);
@ -58,7 +56,7 @@ void EmulatorConfig::save(const std::filesystem::path& path) {
if (std::filesystem::exists(path, error)) {
try {
data = toml::parse<toml::preserve_comments>(path);
} catch (std::exception& ex) {
} catch (const std::exception& ex) {
Helpers::warn("Exception trying to parse config file. Exception: %s\n", ex.what());
return;
}
@ -69,8 +67,8 @@ void EmulatorConfig::save(const std::filesystem::path& path) {
printf("Saving new configuration file %s\n", path.string().c_str());
}
data["GPU"]["Renderer"] = Renderer::typeToString(rendererType);
data["GPU"]["EnableShaderJIT"] = shaderJitEnabled;
data["GPU"]["Renderer"] = Renderer::typeToString(rendererType);
std::ofstream file(path, std::ios::out);
file << data;

View file

@ -17,10 +17,11 @@ std::optional<RendererType> Renderer::typeFromString(std::string inString) {
return std::nullopt;
}
const char* Renderer::typeToString(RendererType rendererType) {
std::string Renderer::typeToString(RendererType rendererType) {
switch (rendererType) {
case RendererType::Null: return "null";
case RendererType::OpenGL: return "opengl";
case RendererType::Vulkan: return "vk";
default: return "Invalid";
}
}