mirror of
https://github.com/libretro/bsnes-libretro.git
synced 2024-11-23 08:59:40 +00:00
82293c95ae
byuu says: Changelog: - (u)int(max,ptr) abbreviations removed; use _t suffix now [didn't feel like they were contributing enough to be worth it] - cleaned up nall::integer,natural,real functionality - toInteger, toNatural, toReal for parsing strings to numbers - fromInteger, fromNatural, fromReal for creating strings from numbers - (string,Markup::Node,SQL-based-classes)::(integer,natural,real) left unchanged - template<typename T> numeral(T value, long padding, char padchar) -> string for print() formatting - deduces integer,natural,real based on T ... cast the value if you want to override - there still exists binary,octal,hex,pointer for explicit print() formatting - lstring -> string_vector [but using lstring = string_vector; is declared] - would be nice to remove the using lstring eventually ... but that'd probably require 10,000 lines of changes >_> - format -> string_format [no using here; format was too ambiguous] - using integer = Integer<sizeof(int)*8>; and using natural = Natural<sizeof(uint)*8>; declared - for consistency with boolean. These three are meant for creating zero-initialized values implicitly (various uses) - R65816::io() -> idle() and SPC700::io() -> idle() [more clear; frees up struct IO {} io; naming] - SFC CPU, PPU, SMP use struct IO {} io; over struct (Status,Registers) {} (status,registers); now - still some CPU::Status status values ... they didn't really fit into IO functionality ... will have to think about this more - SFC CPU, PPU, SMP now use step() exclusively instead of addClocks() calling into step() - SFC CPU joypad1_bits, joypad2_bits were unused; killed them - SFC PPU CGRAM moved into PPU::Screen; since nothing else uses it - SFC PPU OAM moved into PPU::Object; since nothing else uses it - the raw uint8[544] array is gone. OAM::read() constructs values from the OAM::Object[512] table now - this avoids having to determine how we want to sub-divide the two OAM memory sections - this also eliminates the OAM::synchronize() functionality - probably more I'm forgetting The FPS fluctuations are driving me insane. This WIP went from 128fps to 137fps. Settled on 133.5fps for the final build. But nothing I changed should have affected performance at all. This level of fluctuation makes it damn near impossible to know whether I'm speeding things up or slowing things down with changes.
111 lines
3.0 KiB
C++
111 lines
3.0 KiB
C++
#pragma once
|
|
|
|
#include <nall/platform.hpp>
|
|
#include <nall/file.hpp>
|
|
#include <nall/string.hpp>
|
|
|
|
namespace nall {
|
|
namespace Configuration {
|
|
|
|
struct Node {
|
|
string name;
|
|
string desc;
|
|
enum class Type : uint { Null, Boolean, Integer, Natural, Double, String } type = Type::Null;
|
|
void* data = nullptr;
|
|
vector<Node> children;
|
|
|
|
explicit operator bool() const { return data; }
|
|
|
|
auto get() const -> string {
|
|
switch(type) {
|
|
case Type::Boolean: return {*(bool*)data};
|
|
case Type::Integer: return {*(int*)data};
|
|
case Type::Natural: return {*(uint*)data};
|
|
case Type::Double: return {*(double*)data};
|
|
case Type::String: return {*(string*)data};
|
|
}
|
|
return "";
|
|
}
|
|
|
|
auto set(const string& value) -> void {
|
|
switch(type) {
|
|
case Type::Boolean: *(bool*)data = (value != "false"); break;
|
|
case Type::Integer: *(int*)data = toInteger(value); break;
|
|
case Type::Natural: *(uint*)data = toNatural(value); break;
|
|
case Type::Double: *(double*)data = toReal(value); break;
|
|
case Type::String: *(string*)data = value; break;
|
|
}
|
|
}
|
|
|
|
auto assign() { type = Type::Null; data = nullptr; }
|
|
auto assign(bool& bind) { type = Type::Boolean; data = (void*)&bind; }
|
|
auto assign(int& bind) { type = Type::Integer; data = (void*)&bind; }
|
|
auto assign(uint& bind) { type = Type::Natural; data = (void*)&bind; }
|
|
auto assign(double& bind) { type = Type::Double; data = (void*)&bind; }
|
|
auto assign(string& bind) { type = Type::String; data = (void*)&bind; }
|
|
auto assign(const Node& node) { operator=(node); }
|
|
|
|
template<typename T> auto append(T& data, const string& name, const string& desc = "") -> void {
|
|
Node node;
|
|
node.assign(data);
|
|
node.name = name;
|
|
node.desc = desc;
|
|
children.append(node);
|
|
}
|
|
|
|
auto find(const string& path) -> maybe<Node&> {
|
|
auto p = path.split("/");
|
|
auto name = p.takeLeft();
|
|
for(auto& child : children) {
|
|
if(child.name == name) {
|
|
if(p.size() == 0) return child;
|
|
return child.find(p.merge("/"));
|
|
}
|
|
}
|
|
return nothing;
|
|
}
|
|
|
|
auto load(Markup::Node path) -> void {
|
|
for(auto& child : children) {
|
|
if(auto leaf = path[child.name]) {
|
|
if(child) child.set(leaf.text());
|
|
child.load(leaf);
|
|
}
|
|
}
|
|
}
|
|
|
|
auto save(file& fp, uint depth = 0) -> void {
|
|
for(auto& child : children) {
|
|
if(child.desc) {
|
|
for(auto n : range(depth)) fp.print(" ");
|
|
fp.print("//", child.desc, "\n");
|
|
}
|
|
for(auto n : range(depth)) fp.print(" ");
|
|
fp.print(child.name);
|
|
if(child) fp.print(": ", child.get());
|
|
fp.print("\n");
|
|
child.save(fp, depth + 1);
|
|
if(depth == 0) fp.print("\n");
|
|
}
|
|
}
|
|
};
|
|
|
|
struct Document : Node {
|
|
auto load(const string& filename) -> bool {
|
|
if(!file::exists(filename)) return false;
|
|
auto document = BML::unserialize(string::read(filename));
|
|
Node::load(document);
|
|
return true;
|
|
}
|
|
|
|
auto save(const string& filename) -> bool {
|
|
file fp(filename, file::mode::write);
|
|
if(!fp.open()) return false;
|
|
Node::save(fp);
|
|
return true;
|
|
}
|
|
};
|
|
|
|
}
|
|
}
|