mirror of
https://github.com/holub/mame
synced 2025-10-04 08:28:39 +03:00
Make JSON error checking a lot more verbose
This commit is contained in:
parent
50e3b68924
commit
1226b243a2
@ -3,7 +3,7 @@
|
||||
"targets": [
|
||||
{ "name": "temp",
|
||||
"mode": "guest",
|
||||
"bilinear": false
|
||||
"bilinear": true
|
||||
},
|
||||
{ "name": "screen",
|
||||
"mode": "native"
|
||||
|
@ -80,12 +80,6 @@
|
||||
{ "name": "screen",
|
||||
"mode": "native",
|
||||
"doublebuffer": true
|
||||
},
|
||||
{ "name": "bloom",
|
||||
"mode": "guest",
|
||||
"prescale": true,
|
||||
"doublebuffer": true,
|
||||
"pyramid": true
|
||||
}
|
||||
],
|
||||
"passes": [
|
||||
|
@ -3,7 +3,7 @@
|
||||
"targets": [
|
||||
{ "name": "temp",
|
||||
"mode": "guest",
|
||||
"bilinear": true
|
||||
"bilinear": false
|
||||
},
|
||||
{ "name": "screen",
|
||||
"mode": "native"
|
||||
|
@ -136,6 +136,7 @@ function osdmodulesbuild()
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/timeparameter.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/paramreader.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/paramuniform.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/paramuniformreader.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/shadermanager.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/slider.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/sliderreader.cpp",
|
||||
|
@ -27,20 +27,25 @@
|
||||
#include "suppressor.h"
|
||||
#include "suppressorreader.h"
|
||||
|
||||
bgfx_chain_entry* chain_entry_reader::read_from_value(const Value& value, osd_options& options, texture_manager& textures, target_manager& targets, effect_manager& effects, std::map<std::string, bgfx_slider*>& sliders, std::map<std::string, bgfx_parameter*>& params)
|
||||
bgfx_chain_entry* chain_entry_reader::read_from_value(const Value& value, std::string prefix, osd_options& options, texture_manager& textures, target_manager& targets, effect_manager& effects, std::map<std::string, bgfx_slider*>& sliders, std::map<std::string, bgfx_parameter*>& params)
|
||||
{
|
||||
validate_parameters(value);
|
||||
validate_parameters(value, prefix);
|
||||
|
||||
bgfx_effect* effect = effects.effect(value["effect"].GetString());
|
||||
std::string name = value["name"].GetString();
|
||||
|
||||
std::vector<bgfx_input_pair> inputs;
|
||||
if (value.HasMember("input"))
|
||||
{
|
||||
assert(value["input"].IsArray());
|
||||
READER_ASSERT(value["input"].IsArray(), (prefix + "Chain entry '" + name + "': value 'input' must be an array\n").c_str());
|
||||
const Value& input_array = value["input"];
|
||||
for (UINT32 i = 0; i < input_array.Size(); i++)
|
||||
{
|
||||
std::string sampler = input_array[i]["sampler"].GetString();
|
||||
READER_ASSERT(input_array[i].HasMember("sampler"), (prefix + "input[" + std::to_string(i) + ": Must have string value 'sampler' (what sampler are we binding to?)\n").c_str());
|
||||
READER_ASSERT(input_array[i]["sampler"].IsString(), (prefix + "input[" + std::to_string(i) + ": Value 'sampler' must be a string\n").c_str());
|
||||
READER_ASSERT(input_array[i].HasMember("texture"), (prefix + "input[" + std::to_string(i) + ": Must have string value 'texture' (what texture are we using?)\n").c_str());
|
||||
READER_ASSERT(input_array[i]["texture"].IsString(), (prefix + "input[" + std::to_string(i) + ": Value 'texture' must be a string\n").c_str());
|
||||
std::string sampler = input_array[i]["sampler"].GetString();
|
||||
std::string texture = input_array[i]["texture"].GetString();
|
||||
inputs.push_back(bgfx_input_pair(i, sampler, texture));
|
||||
}
|
||||
@ -49,28 +54,28 @@ bgfx_chain_entry* chain_entry_reader::read_from_value(const Value& value, osd_op
|
||||
std::vector<bgfx_entry_uniform*> uniforms;
|
||||
if (value.HasMember("uniforms"))
|
||||
{
|
||||
assert(value["uniforms"].IsArray());
|
||||
READER_ASSERT(value["uniforms"].IsArray(), (prefix + "Chain entry '" + name + "': value 'uniforms' must be an array\n").c_str());
|
||||
const Value& uniform_array = value["uniforms"];
|
||||
for (UINT32 i = 0; i < uniform_array.Size(); i++)
|
||||
{
|
||||
uniforms.push_back(entry_uniform_reader::read_from_value(uniform_array[i], effect, sliders, params));
|
||||
uniforms.push_back(entry_uniform_reader::read_from_value(uniform_array[i], prefix + "uniforms[" + std::to_string(i) + "]: ", effect, sliders, params));
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<bgfx_suppressor*> suppressors;
|
||||
if (value.HasMember("disablewhen"))
|
||||
{
|
||||
assert(value["disablewhen"].IsArray());
|
||||
READER_ASSERT(value["disablewhen"].IsArray(), (prefix + "Chain entry '" + name + "': value 'disablewhen' must be an array\n").c_str());
|
||||
const Value& suppressor_array = value["disablewhen"];
|
||||
for (UINT32 i = 0; i < suppressor_array.Size(); i++)
|
||||
{
|
||||
suppressors.push_back(suppressor_reader::read_from_value(suppressor_array[i], sliders));
|
||||
suppressors.push_back(suppressor_reader::read_from_value(suppressor_array[i], prefix, sliders));
|
||||
}
|
||||
}
|
||||
|
||||
if (value.HasMember("textures"))
|
||||
{
|
||||
assert(value["textures"].IsArray());
|
||||
READER_ASSERT(value["textures"].IsArray(), (prefix + "Chain entry '" + name + "': value 'textures' must be an array\n").c_str());
|
||||
const Value& texture_array = value["textures"];
|
||||
for (UINT32 i = 0; i < texture_array.Size(); i++)
|
||||
{
|
||||
@ -84,24 +89,20 @@ bgfx_chain_entry* chain_entry_reader::read_from_value(const Value& value, osd_op
|
||||
std::string output_name = value["output"].GetString();
|
||||
if (output_name != std::string("backbuffer"))
|
||||
{
|
||||
return new bgfx_chain_entry(value["name"].GetString(), effect, suppressors, inputs, uniforms, targets, output_name);
|
||||
return new bgfx_chain_entry(name, effect, suppressors, inputs, uniforms, targets, output_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new bgfx_chain_entry(value["name"].GetString(), effect, suppressors, inputs, uniforms, targets, "none");
|
||||
return new bgfx_chain_entry(name, effect, suppressors, inputs, uniforms, targets, "none");
|
||||
}
|
||||
}
|
||||
|
||||
void chain_entry_reader::validate_parameters(const Value& value)
|
||||
void chain_entry_reader::validate_parameters(const Value& value, std::string prefix)
|
||||
{
|
||||
assert(value.HasMember("effect"));
|
||||
assert(value["effect"].IsString());
|
||||
if (value.HasMember("name"))
|
||||
{
|
||||
assert(value["name"].IsString());
|
||||
}
|
||||
assert(value.HasMember("effect"));
|
||||
assert(value["effect"].IsString());
|
||||
assert(value.HasMember("output"));
|
||||
assert(value["output"].IsString());
|
||||
READER_ASSERT(value.HasMember("effect"), (prefix + "Must have string value 'effect' (what effect does this entry use?)\n").c_str());
|
||||
READER_ASSERT(value["effect"].IsString(), (prefix + "Value 'effect' must be a string\n").c_str());
|
||||
READER_ASSERT(value.HasMember("name"), (prefix + "Must have string value 'effect' (what effect does this entry use?)\n").c_str());
|
||||
READER_ASSERT(value["name"].IsString(), (prefix + "Value 'name' must be a string\n").c_str());
|
||||
READER_ASSERT(value.HasMember("output"), (prefix + "Must have string value 'output' (what target contains the result of this entry?)\n").c_str());
|
||||
READER_ASSERT(value["output"].IsString(), (prefix + "Value 'output' must be a string\n").c_str());
|
||||
}
|
||||
|
@ -26,10 +26,10 @@ class bgfx_parameter;
|
||||
class chain_entry_reader : public state_reader
|
||||
{
|
||||
public:
|
||||
static bgfx_chain_entry* read_from_value(const Value& value, osd_options& options, texture_manager& textures, target_manager& targets, effect_manager& effects, std::map<std::string, bgfx_slider*>& sliders, std::map<std::string, bgfx_parameter*>& params);
|
||||
static bgfx_chain_entry* read_from_value(const Value& value, std::string prefix, osd_options& options, texture_manager& textures, target_manager& targets, effect_manager& effects, std::map<std::string, bgfx_slider*>& sliders, std::map<std::string, bgfx_parameter*>& params);
|
||||
|
||||
private:
|
||||
static void validate_parameters(const Value& value);
|
||||
static void validate_parameters(const Value& value, std::string prefix);
|
||||
};
|
||||
|
||||
#endif // __DRAWBGFX_CHAIN_ENTRY_READER__
|
||||
|
@ -62,7 +62,7 @@ bgfx_chain* chain_manager::load_chain(std::string name, running_machine& machine
|
||||
|
||||
Document document;
|
||||
document.Parse<0>(data);
|
||||
bgfx_chain* chain = chain_reader::read_from_value(document, m_options, machine, window_index, m_textures, m_targets, m_effects, m_width, m_height);
|
||||
bgfx_chain* chain = chain_reader::read_from_value(document, name + ": ", m_options, machine, window_index, m_textures, m_targets, m_effects, m_width, m_height);
|
||||
|
||||
m_chains[name + std::to_string(window_index)] = chain;
|
||||
|
||||
|
@ -29,9 +29,9 @@ const chain_reader::string_to_enum chain_reader::STYLE_NAMES[chain_reader::STYLE
|
||||
{ "custom", TARGET_STYLE_CUSTOM }
|
||||
};
|
||||
|
||||
bgfx_chain* chain_reader::read_from_value(const Value& value, osd_options& options, running_machine& machine, uint32_t window_index, texture_manager& textures, target_manager& targets, effect_manager& effects, uint32_t screen_width, uint32_t screen_height)
|
||||
bgfx_chain* chain_reader::read_from_value(const Value& value, std::string prefix, osd_options& options, running_machine& machine, uint32_t window_index, texture_manager& textures, target_manager& targets, effect_manager& effects, uint32_t screen_width, uint32_t screen_height)
|
||||
{
|
||||
validate_parameters(value);
|
||||
validate_parameters(value, prefix);
|
||||
|
||||
std::string name = value["name"].GetString();
|
||||
std::string author = value["author"].GetString();
|
||||
@ -43,7 +43,7 @@ bgfx_chain* chain_reader::read_from_value(const Value& value, osd_options& optio
|
||||
const Value& slider_array = value["sliders"];
|
||||
for (UINT32 i = 0; i < slider_array.Size(); i++)
|
||||
{
|
||||
std::vector<bgfx_slider*> expanded_sliders = slider_reader::read_from_value(slider_array[i], machine, window_index);
|
||||
std::vector<bgfx_slider*> expanded_sliders = slider_reader::read_from_value(slider_array[i], prefix + "sliders[" + std::to_string(i) + "]: ", machine, window_index);
|
||||
for (bgfx_slider* slider : expanded_sliders)
|
||||
{
|
||||
sliders.push_back(slider);
|
||||
@ -62,10 +62,11 @@ bgfx_chain* chain_reader::read_from_value(const Value& value, osd_options& optio
|
||||
std::vector<bgfx_parameter*> parameters;
|
||||
if (value.HasMember("parameters"))
|
||||
{
|
||||
READER_ASSERT(value["parameters"].IsArray(), (prefix + "Value 'parameters' must be an array\n").c_str());
|
||||
const Value& param_array = value["parameters"];
|
||||
for (UINT32 i = 0; i < param_array.Size(); i++)
|
||||
{
|
||||
parameters.push_back(parameter_reader::read_from_value(param_array[i], window_index));
|
||||
parameters.push_back(parameter_reader::read_from_value(param_array[i], prefix + "parameters[" + std::to_string(i) + "]; ", window_index));
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,12 +80,20 @@ bgfx_chain* chain_reader::read_from_value(const Value& value, osd_options& optio
|
||||
// Create targets
|
||||
if (value.HasMember("targets"))
|
||||
{
|
||||
READER_ASSERT(value["targets"].IsArray(), (prefix + "Value 'targets' must be an array\n").c_str());
|
||||
const Value& target_array = value["targets"];
|
||||
// TODO: Move into its own reader
|
||||
for (UINT32 i = 0; i < target_array.Size(); i++)
|
||||
{
|
||||
assert(target_array[i].HasMember("name"));
|
||||
assert(target_array[i]["name"].IsString());
|
||||
READER_ASSERT(target_array[i].HasMember("name"), (prefix + "targets[" + std::to_string(i) + "]: Must have string value 'name'\n").c_str());
|
||||
READER_ASSERT(target_array[i]["name"].IsString(), (prefix + "targets[" + std::to_string(i) + "]: Value 'name' must be a string\n").c_str());
|
||||
READER_ASSERT(target_array[i].HasMember("mode"), (prefix + "targets[" + std::to_string(i) + "]: Must have string enum 'mode'\n").c_str());
|
||||
READER_ASSERT(target_array[i]["mode"].IsString(), (prefix + "targets[" + std::to_string(i) + "]: Value 'mode' must be a string (what screens does this apply to?)\n").c_str());
|
||||
READER_ASSERT(!target_array[i].HasMember("bilinear") || target_array[i]["bilinear"].IsBool(), (prefix + "targets[" + std::to_string(i) + "]: Value 'bilinear' must be a boolean\n").c_str());
|
||||
READER_ASSERT(!target_array[i].HasMember("doublebuffer") || target_array[i]["doublebuffer"].IsBool(), (prefix + "targets[" + std::to_string(i) + "]: Value 'doublebuffer' must be a boolean\n").c_str());
|
||||
READER_ASSERT(!target_array[i].HasMember("prescale") || target_array[i]["prescale"].IsBool(), (prefix + "targets[" + std::to_string(i) + "]: Value 'prescale' must be a boolean\n").c_str());
|
||||
|
||||
std::string target_name = target_array[i]["name"].GetString();
|
||||
uint32_t mode = uint32_t(get_enum_from_value(target_array[i], "mode", TARGET_STYLE_NATIVE, STYLE_NAMES, STYLE_COUNT));
|
||||
bool bilinear = get_bool(target_array[i], "bilinear", true);
|
||||
bool double_buffer = get_bool(target_array[i], "doublebuffer", true);
|
||||
@ -103,10 +112,10 @@ bgfx_chain* chain_reader::read_from_value(const Value& value, osd_options& optio
|
||||
height = screen_height;
|
||||
break;
|
||||
case TARGET_STYLE_CUSTOM:
|
||||
assert(target_array[i].HasMember("width"));
|
||||
assert(target_array[i]["width"].IsNumber());
|
||||
assert(target_array[i].HasMember("height"));
|
||||
assert(target_array[i]["height"].IsNumber());
|
||||
READER_ASSERT(target_array[i].HasMember("width"), (prefix + "Target '" + target_name + "': Must have numeric value 'width'\n").c_str());
|
||||
READER_ASSERT(target_array[i]["width"].IsNumber(), (prefix + "Target '" + target_name + "': Value 'width' must be a number\n").c_str());
|
||||
READER_ASSERT(target_array[i].HasMember("height"), (prefix + "Target '" + target_name + "': Must have numeric value 'height'\n").c_str());
|
||||
READER_ASSERT(target_array[i]["height"].IsNumber(), (prefix + "Target '" + target_name + "': Value 'height' must be a number\n").c_str());
|
||||
width = uint32_t(target_array[i]["width"].GetDouble());
|
||||
height = uint32_t(target_array[i]["height"].GetDouble());
|
||||
break;
|
||||
@ -120,7 +129,7 @@ bgfx_chain* chain_reader::read_from_value(const Value& value, osd_options& optio
|
||||
prescale_y = options.bgfx_prescale_y();
|
||||
}
|
||||
|
||||
targets.create_target(target_array[i]["name"].GetString(), bgfx::TextureFormat::RGBA8, width, height, prescale_x, prescale_y, mode, double_buffer, bilinear);
|
||||
targets.create_target(target_name, bgfx::TextureFormat::RGBA8, width, height, prescale_x, prescale_y, mode, double_buffer, bilinear);
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,7 +140,7 @@ bgfx_chain* chain_reader::read_from_value(const Value& value, osd_options& optio
|
||||
const Value& entry_array = value["passes"];
|
||||
for (UINT32 i = 0; i < entry_array.Size(); i++)
|
||||
{
|
||||
entries.push_back(chain_entry_reader::read_from_value(entry_array[i], options, textures, targets, effects, slider_map, param_map));
|
||||
entries.push_back(chain_entry_reader::read_from_value(entry_array[i], prefix + "passes[" + std::to_string(i) + "]: ", options, textures, targets, effects, slider_map, param_map));
|
||||
}
|
||||
}
|
||||
|
||||
@ -140,14 +149,14 @@ bgfx_chain* chain_reader::read_from_value(const Value& value, osd_options& optio
|
||||
return new bgfx_chain(name, author, sliders, parameters, entries, output);
|
||||
}
|
||||
|
||||
void chain_reader::validate_parameters(const Value& value)
|
||||
void chain_reader::validate_parameters(const Value& value, std::string prefix)
|
||||
{
|
||||
assert(value.HasMember("name"));
|
||||
assert(value["name"].IsString());
|
||||
assert(value.HasMember("author"));
|
||||
assert(value["author"].IsString());
|
||||
assert(value.HasMember("passes"));
|
||||
assert(value["passes"].IsArray());
|
||||
assert(value.HasMember("output"));
|
||||
assert(value["output"].IsString());
|
||||
READER_ASSERT(value.HasMember("name"), (prefix + "Must have string value 'name'\n").c_str());
|
||||
READER_ASSERT(value["name"].IsString(), (prefix + "Value 'name' must be a string\n").c_str());
|
||||
READER_ASSERT(value.HasMember("author"), (prefix + "Must have string value 'author'\n").c_str());
|
||||
READER_ASSERT(value["author"].IsString(), (prefix + "Value 'author' must be a string\n").c_str());
|
||||
READER_ASSERT(value.HasMember("passes"), (prefix + "Must have array value 'passes'\n").c_str());
|
||||
READER_ASSERT(value["passes"].IsArray(), (prefix + "Value 'passes' must be an array\n").c_str());
|
||||
READER_ASSERT(value.HasMember("output"), (prefix + "Must have string value 'output'\n").c_str());
|
||||
READER_ASSERT(value["output"].IsString(), (prefix + "Value 'output' must be a string\n").c_str());
|
||||
}
|
||||
|
@ -21,10 +21,10 @@ class effect_manager;
|
||||
class chain_reader : public state_reader
|
||||
{
|
||||
public:
|
||||
static bgfx_chain* read_from_value(const Value& value, osd_options& options, running_machine& machine, uint32_t window_index, texture_manager& textures, target_manager& targets, effect_manager& effects, uint32_t screen_width, uint32_t screen_height);
|
||||
static bgfx_chain* read_from_value(const Value& value, std::string prefix, osd_options& options, running_machine& machine, uint32_t window_index, texture_manager& textures, target_manager& targets, effect_manager& effects, uint32_t screen_width, uint32_t screen_height);
|
||||
|
||||
private:
|
||||
static void validate_parameters(const Value& value);
|
||||
static void validate_parameters(const Value& value, std::string prefix);
|
||||
|
||||
static const int STYLE_COUNT = 3;
|
||||
static const string_to_enum STYLE_NAMES[STYLE_COUNT];
|
||||
|
@ -46,12 +46,15 @@ bgfx_effect* effect_manager::effect(std::string name)
|
||||
|
||||
bgfx_effect* effect_manager::load_effect(std::string name)
|
||||
{
|
||||
std::string path = std::string(m_options.bgfx_path()) + "/effects/" + name + ".json";
|
||||
if (name.length() < 5 || (name.compare(name.length() - 5, 5, ".json") != 0)) {
|
||||
name = name + ".json";
|
||||
}
|
||||
std::string path = std::string(m_options.bgfx_path()) + "/effects/" + name;
|
||||
|
||||
bx::CrtFileReader reader;
|
||||
bx::open(&reader, path.c_str());
|
||||
|
||||
int32_t size = (uint32_t)bx::getSize(&reader);
|
||||
int32_t size (bx::getSize(&reader));
|
||||
|
||||
char* data = new char[size + 1];
|
||||
bx::read(&reader, reinterpret_cast<void*>(data), size);
|
||||
@ -60,7 +63,7 @@ bgfx_effect* effect_manager::load_effect(std::string name)
|
||||
|
||||
Document document;
|
||||
document.Parse<0>(data);
|
||||
bgfx_effect* effect = effect_reader::read_from_value(m_shaders, document);
|
||||
bgfx_effect* effect = effect_reader::read_from_value(document, "Effect '" + name + "': ", m_shaders);
|
||||
|
||||
m_effects[name] = effect;
|
||||
|
||||
|
@ -22,9 +22,9 @@
|
||||
|
||||
#include "effectreader.h"
|
||||
|
||||
bgfx_effect* effect_reader::read_from_value(shader_manager& shaders, const Value& value)
|
||||
bgfx_effect* effect_reader::read_from_value(const Value& value, std::string prefix, shader_manager& shaders)
|
||||
{
|
||||
validate_parameters(value);
|
||||
validate_parameters(value, prefix);
|
||||
|
||||
uint64_t blend = 0;
|
||||
if (value.HasMember("blend"))
|
||||
@ -59,22 +59,16 @@ bgfx_effect* effect_reader::read_from_value(shader_manager& shaders, const Value
|
||||
return new bgfx_effect(blend | depth | cull | write, vertex_shader, fragment_shader, uniforms);
|
||||
}
|
||||
|
||||
void effect_reader::validate_parameters(const Value& value)
|
||||
void effect_reader::validate_parameters(const Value& value, std::string prefix)
|
||||
{
|
||||
assert(value.HasMember("depth"));
|
||||
assert(value.HasMember("cull"));
|
||||
assert(value.HasMember("write"));
|
||||
assert(value.HasMember("vertex"));
|
||||
assert(value["vertex"].IsString());
|
||||
assert(value.HasMember("fragment") || value.HasMember("pixel"));
|
||||
if (value.HasMember("fragment"))
|
||||
{
|
||||
assert(value["fragment"].IsString());
|
||||
}
|
||||
if (value.HasMember("pixel"))
|
||||
{
|
||||
assert(value["pixel"].IsString());
|
||||
}
|
||||
assert(value.HasMember("uniforms"));
|
||||
assert(value["uniforms"].IsArray());
|
||||
READER_ASSERT(value.HasMember("depth"), (prefix + "Must have object value 'depth' (what are our Z-buffer settings?)\n").c_str());
|
||||
READER_ASSERT(value.HasMember("cull"), (prefix + "Must have object value 'cull' (do we cull triangles based on winding?)\n").c_str());
|
||||
READER_ASSERT(value.HasMember("write"), (prefix + "Must have object value 'write' (what are our color buffer write settings?)\n").c_str());
|
||||
READER_ASSERT(value.HasMember("vertex"), (prefix + "Must have string value 'vertex' (what is our vertex shader?)\n").c_str());
|
||||
READER_ASSERT(value["vertex"].IsString(), (prefix + "Value 'vertex' must be a string\n").c_str());
|
||||
READER_ASSERT(value.HasMember("fragment") || value.HasMember("pixel"), (prefix + "Must have string value named 'fragment' or 'pixel' (what is our fragment/pixel shader?)\n").c_str());
|
||||
READER_ASSERT(!value.HasMember("fragment") || value["fragment"].IsString(), (prefix + "Value 'fragment' must be a string\n").c_str());
|
||||
READER_ASSERT(!value.HasMember("pixel") || value["pixel"].IsString(), (prefix + "Value 'pixel' must be a string\n").c_str());
|
||||
READER_ASSERT(value.HasMember("uniforms"), (prefix + "Must have array value 'uniforms' (what are our shader's parameters?)\n").c_str());
|
||||
READER_ASSERT(value["uniforms"].IsArray(), (prefix + "Value 'uniforms' must be an array\n").c_str());
|
||||
}
|
||||
|
@ -11,6 +11,8 @@
|
||||
#ifndef __DRAWBGFX_EFFECT_READER__
|
||||
#define __DRAWBGFX_EFFECT_READER__
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "statereader.h"
|
||||
|
||||
class bgfx_effect;
|
||||
@ -19,10 +21,10 @@ class shader_manager;
|
||||
class effect_reader : public state_reader
|
||||
{
|
||||
public:
|
||||
static bgfx_effect* read_from_value(shader_manager& shaders, const Value& value);
|
||||
static bgfx_effect* read_from_value(const Value& value, std::string prefix, shader_manager& shaders);
|
||||
|
||||
private:
|
||||
static void validate_parameters(const Value& value);
|
||||
static void validate_parameters(const Value& value, std::string prefix);
|
||||
};
|
||||
|
||||
#endif // __DRAWBGFX_EFFECT_READER__
|
||||
|
@ -12,37 +12,36 @@
|
||||
#include "effect.h"
|
||||
#include "slideruniformreader.h"
|
||||
#include "valueuniformreader.h"
|
||||
#include "paramuniform.h"
|
||||
#include "paramuniformreader.h"
|
||||
#include "uniform.h"
|
||||
|
||||
bgfx_entry_uniform* entry_uniform_reader::read_from_value(const Value& value, bgfx_effect* effect, std::map<std::string, bgfx_slider*>& sliders, std::map<std::string, bgfx_parameter*>& params)
|
||||
bgfx_entry_uniform* entry_uniform_reader::read_from_value(const Value& value, std::string prefix, bgfx_effect* effect, std::map<std::string, bgfx_slider*>& sliders, std::map<std::string, bgfx_parameter*>& params)
|
||||
{
|
||||
validate_parameters(value);
|
||||
validate_parameters(value, prefix);
|
||||
|
||||
std::string name = value["uniform"].GetString();
|
||||
bgfx_uniform* uniform = effect->uniform(name);
|
||||
|
||||
|
||||
assert(uniform != nullptr);
|
||||
READER_ASSERT(uniform != nullptr, (prefix + "Uniform '" + name + " does not appear to exist\n").c_str());
|
||||
|
||||
if (value.HasMember("slider"))
|
||||
{
|
||||
return slider_uniform_reader::read_from_value(value, uniform, sliders);
|
||||
return slider_uniform_reader::read_from_value(value, prefix, uniform, sliders);
|
||||
}
|
||||
else if (value.HasMember("value"))
|
||||
{
|
||||
return value_uniform_reader::read_from_value(value, uniform);
|
||||
return value_uniform_reader::read_from_value(value, prefix, uniform);
|
||||
}
|
||||
else if (value.HasMember("parameter"))
|
||||
{
|
||||
return new bgfx_param_uniform(uniform, params[value["parameter"].GetString()]);
|
||||
return param_uniform_reader::read_from_value(value, prefix, uniform, params);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void entry_uniform_reader::validate_parameters(const Value& value)
|
||||
void entry_uniform_reader::validate_parameters(const Value& value, std::string prefix)
|
||||
{
|
||||
assert(value.HasMember("uniform"));
|
||||
assert(value["uniform"].IsString());
|
||||
READER_ASSERT(value.HasMember("uniform"), (prefix + "Must have string value 'uniform' (what uniform are we mapping?)\n").c_str());
|
||||
READER_ASSERT(value["uniform"].IsString(), (prefix + "Value 'effect' must be a string\n").c_str());
|
||||
}
|
||||
|
@ -24,10 +24,10 @@ class bgfx_parameter;
|
||||
class entry_uniform_reader : public state_reader
|
||||
{
|
||||
public:
|
||||
static bgfx_entry_uniform* read_from_value(const Value& value, bgfx_effect* effect, std::map<std::string, bgfx_slider*>& sliders, std::map<std::string, bgfx_parameter*>& params);
|
||||
static bgfx_entry_uniform* read_from_value(const Value& value, std::string prefix, bgfx_effect* effect, std::map<std::string, bgfx_slider*>& sliders, std::map<std::string, bgfx_parameter*>& params);
|
||||
|
||||
private:
|
||||
static void validate_parameters(const Value& value);
|
||||
static void validate_parameters(const Value& value, std::string prefix);
|
||||
};
|
||||
|
||||
#endif // __DRAWBGFX_ENTRY_UNIFORM_READER__
|
||||
|
@ -21,9 +21,9 @@ const parameter_reader::string_to_enum parameter_reader::TYPE_NAMES[parameter_re
|
||||
{ "time", bgfx_parameter::parameter_type::PARAM_TIME }
|
||||
};
|
||||
|
||||
bgfx_parameter* parameter_reader::read_from_value(const Value& value, uint32_t window_index)
|
||||
bgfx_parameter* parameter_reader::read_from_value(const Value& value, std::string prefix, uint32_t window_index)
|
||||
{
|
||||
validate_parameters(value);
|
||||
validate_parameters(value, prefix);
|
||||
|
||||
std::string name = value["name"].GetString();
|
||||
bgfx_parameter::parameter_type type = bgfx_parameter::parameter_type(get_enum_from_value(value, "type", bgfx_parameter::parameter_type::PARAM_FRAME, TYPE_NAMES, TYPE_COUNT));
|
||||
@ -50,18 +50,12 @@ bgfx_parameter* parameter_reader::read_from_value(const Value& value, uint32_t w
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void parameter_reader::validate_parameters(const Value& value)
|
||||
void parameter_reader::validate_parameters(const Value& value, std::string prefix)
|
||||
{
|
||||
assert(value.HasMember("name"));
|
||||
assert(value["name"].IsString());
|
||||
assert(value.HasMember("type"));
|
||||
assert(value["type"].IsString());
|
||||
if (value.HasMember("period"))
|
||||
{
|
||||
assert(value["period"].IsNumber());
|
||||
}
|
||||
if (value.HasMember("limit"))
|
||||
{
|
||||
assert(value["limit"].IsNumber());
|
||||
}
|
||||
READER_ASSERT(value.HasMember("name"), (prefix + "Must have string value 'name'\n").c_str());
|
||||
READER_ASSERT(value["name"].IsString(), (prefix + "Value 'name' must be a string\n").c_str());
|
||||
READER_ASSERT(value.HasMember("type"), (prefix + "Must have string value 'type'\n").c_str());
|
||||
READER_ASSERT(value["type"].IsString(), (prefix + "Value 'type' must be a string\n").c_str());
|
||||
READER_ASSERT(!value.HasMember("period") || value["period"].IsNumber(), (prefix + "Value 'period' must be numeric\n").c_str());
|
||||
READER_ASSERT(!value.HasMember("limit") || value["limit"].IsNumber(), (prefix + "Value 'period' must be numeric\n").c_str());
|
||||
}
|
||||
|
@ -18,10 +18,10 @@ class bgfx_parameter;
|
||||
class parameter_reader : public state_reader
|
||||
{
|
||||
public:
|
||||
static bgfx_parameter* read_from_value(const Value& value, uint32_t window_index);
|
||||
static bgfx_parameter* read_from_value(const Value& value, std::string prefix, uint32_t window_index);
|
||||
|
||||
private:
|
||||
static void validate_parameters(const Value& value);
|
||||
static void validate_parameters(const Value& value, std::string prefix);
|
||||
|
||||
static const int TYPE_COUNT = 3;
|
||||
static const string_to_enum TYPE_NAMES[TYPE_COUNT];
|
||||
|
28
src/osd/modules/render/bgfx/paramuniformreader.cpp
Normal file
28
src/osd/modules/render/bgfx/paramuniformreader.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:Ryan Holtz
|
||||
//====================================================================
|
||||
//
|
||||
// paramuniformreader.cpp - BGFX chain entry parameter mapper reader
|
||||
//
|
||||
//====================================================================
|
||||
|
||||
#include "paramuniformreader.h"
|
||||
|
||||
#include "entryuniform.h"
|
||||
#include "paramuniform.h"
|
||||
#include "parameter.h"
|
||||
|
||||
bgfx_entry_uniform* param_uniform_reader::read_from_value(const Value& value, std::string prefix, bgfx_uniform* uniform, std::map<std::string, bgfx_parameter*>& params)
|
||||
{
|
||||
validate_parameters(value, prefix);
|
||||
|
||||
std::string parameter = value["parameter"].GetString();
|
||||
|
||||
return new bgfx_param_uniform(uniform, params[parameter]);
|
||||
}
|
||||
|
||||
void param_uniform_reader::validate_parameters(const Value& value, std::string prefix)
|
||||
{
|
||||
READER_ASSERT(value.HasMember("parameter"), (prefix + "Must have string value 'parameter' (what parameter is being mapped?)\n").c_str());
|
||||
READER_ASSERT(value["parameter"].IsString(), (prefix + "Value 'parameter' must be a string\n").c_str());
|
||||
}
|
32
src/osd/modules/render/bgfx/paramuniformreader.h
Normal file
32
src/osd/modules/render/bgfx/paramuniformreader.h
Normal file
@ -0,0 +1,32 @@
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:Ryan Holtz
|
||||
//==================================================================
|
||||
//
|
||||
// paramuniformreader.h - BGFX chain entry parameter mapper reader
|
||||
//
|
||||
//==================================================================
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __DRAWBGFX_PARAM_UNIFORM_READER__
|
||||
#define __DRAWBGFX_PARAM_UNIFORM_READER__
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#include "statereader.h"
|
||||
|
||||
class bgfx_entry_uniform;
|
||||
class bgfx_uniform;
|
||||
class bgfx_parameter;
|
||||
|
||||
class param_uniform_reader : public state_reader
|
||||
{
|
||||
public:
|
||||
static bgfx_entry_uniform* read_from_value(const Value& value, std::string prefix, bgfx_uniform* uniform, std::map<std::string, bgfx_parameter*>& params);
|
||||
|
||||
private:
|
||||
static void validate_parameters(const Value& value, std::string prefix);
|
||||
};
|
||||
|
||||
#endif // __DRAWBGFX_PARAM_UNIFORM_READER__
|
@ -33,9 +33,9 @@ const slider_reader::string_to_enum slider_reader::SCREEN_NAMES[slider_reader::S
|
||||
{ "all", uint64_t(bgfx_slider::screen_type::SLIDER_SCREEN_TYPE_ANY) }
|
||||
};
|
||||
|
||||
std::vector<bgfx_slider*> slider_reader::read_from_value(const Value& value, running_machine& machine, uint32_t window_index)
|
||||
std::vector<bgfx_slider*> slider_reader::read_from_value(const Value& value, std::string prefix, running_machine& machine, uint32_t window_index)
|
||||
{
|
||||
validate_parameters(value);
|
||||
validate_parameters(value, prefix);
|
||||
|
||||
std::string name = value["name"].GetString();
|
||||
int step = value["step"].GetInt();
|
||||
@ -48,9 +48,11 @@ std::vector<bgfx_slider*> slider_reader::read_from_value(const Value& value, run
|
||||
std::vector<std::string> strings;
|
||||
if (value.HasMember("strings"))
|
||||
{
|
||||
READER_ASSERT(value["strings"].IsArray(), (prefix + "Slider '" + name + "': value 'strings' must be an array\n").c_str());
|
||||
const Value& string_array = value["strings"];
|
||||
for (UINT32 i = 0; i < string_array.Size(); i++)
|
||||
{
|
||||
READER_ASSERT(string_array[i].IsString(), (prefix + "Slider '" + name + "': strings[" + std::to_string(i) + "]: must be a string\n").c_str());
|
||||
strings.push_back(std::string(string_array[i].GetString()));
|
||||
}
|
||||
}
|
||||
@ -80,9 +82,12 @@ std::vector<bgfx_slider*> slider_reader::read_from_value(const Value& value, run
|
||||
int min[3];
|
||||
int defaults[3];
|
||||
int max[3];
|
||||
get_values(value, "min", min, slider_count);
|
||||
get_values(value, "default", defaults, slider_count);
|
||||
get_values(value, "max", max, slider_count);
|
||||
READER_ASSERT(value["min"].IsArray(), (prefix + "Slider '" + name + "': value 'min' must be an array\n").c_str());
|
||||
READER_ASSERT(value["default"].IsArray(), (prefix + "Slider '" + name + "': value 'default' must be an array\n").c_str());
|
||||
READER_ASSERT(value["max"].IsArray(), (prefix + "Slider '" + name + "': value 'max' must be an array\n").c_str());
|
||||
get_values(value, prefix + "Slider '" + name + "': 'min': ", "min", min, slider_count);
|
||||
get_values(value, prefix + "Slider '" + name + "': 'default': ", "default", defaults, slider_count);
|
||||
get_values(value, prefix + "Slider '" + name + "': 'max': ", "max", max, slider_count);
|
||||
for (int index = 0; index < slider_count; index++)
|
||||
{
|
||||
std::string desc;
|
||||
@ -115,36 +120,37 @@ std::vector<bgfx_slider*> slider_reader::read_from_value(const Value& value, run
|
||||
return sliders;
|
||||
}
|
||||
|
||||
void slider_reader::get_values(const Value& value, std::string name, int* values, const int count)
|
||||
void slider_reader::get_values(const Value& value, std::string prefix, std::string name, int* values, const int count)
|
||||
{
|
||||
const char* name_str = name.c_str();
|
||||
assert(value.HasMember(name_str));
|
||||
assert(value[name_str].IsArray());
|
||||
|
||||
const Value& value_array = value[name_str];
|
||||
for (UINT32 i = 0; i < value_array.Size() && i < count; i++)
|
||||
{
|
||||
READER_ASSERT(value_array[i].IsInt(), (prefix + "Entry " + std::to_string(i) + " must be an integer\n").c_str());
|
||||
values[i] = value_array[i].GetInt();
|
||||
}
|
||||
}
|
||||
|
||||
void slider_reader::validate_parameters(const Value& value)
|
||||
void slider_reader::validate_parameters(const Value& value, std::string prefix)
|
||||
{
|
||||
assert(value.HasMember("name"));
|
||||
assert(value["name"].IsString());
|
||||
assert(value.HasMember("min"));
|
||||
assert(value.HasMember("default"));
|
||||
assert(value.HasMember("max"));
|
||||
assert(value.HasMember("step"));
|
||||
assert(value["step"].IsInt());
|
||||
assert(value.HasMember("type"));
|
||||
assert(value["type"].IsString());
|
||||
assert(value.HasMember("screen"));
|
||||
assert(value["screen"].IsString());
|
||||
assert(value.HasMember("scale"));
|
||||
assert(value["scale"].IsFloat());
|
||||
assert(value.HasMember("format"));
|
||||
assert(value["format"].IsString());
|
||||
assert(value.HasMember("text"));
|
||||
assert(value["text"].IsString());
|
||||
READER_ASSERT(value.HasMember("name"), (prefix + "Must have string value 'name'\n").c_str());
|
||||
READER_ASSERT(value["name"].IsString(), (prefix + "Value 'name' must be a string\n").c_str());
|
||||
READER_ASSERT(value.HasMember("min"), (prefix + "Must have integer or array value 'min'\n").c_str());
|
||||
READER_ASSERT(value["min"].IsInt() || value["min"].IsArray(), (prefix + "Value 'min' must be an integer or an array the size of the corresponding slider type\n").c_str());
|
||||
READER_ASSERT(value.HasMember("default"), (prefix + "Must have integer or array value 'default'\n").c_str());
|
||||
READER_ASSERT(value["default"].IsInt() || value["default"].IsArray(), (prefix + "Value 'default' must be an integer or an array the size of the corresponding slider type\n").c_str());
|
||||
READER_ASSERT(value.HasMember("max"), (prefix + "Must have integer or array value 'max'\n").c_str());
|
||||
READER_ASSERT(value["max"].IsInt() || value["max"].IsArray(), (prefix + "Value 'max' must be an integer or an array the size of the corresponding slider type\n").c_str());
|
||||
READER_ASSERT(value.HasMember("step"), (prefix + "Must have integer value 'step'\n").c_str());
|
||||
READER_ASSERT(value["step"].IsInt(), (prefix + "Value 'step' must be an integer (how much does this slider increment by internally?)\n").c_str());
|
||||
READER_ASSERT(value.HasMember("type"), (prefix + "Must have string value 'type'\n").c_str());
|
||||
READER_ASSERT(value["type"].IsString(), (prefix + "Value 'type' must be a string (what type of slider is this? [int_enum, int, float])\n").c_str());
|
||||
READER_ASSERT(value.HasMember("screen"), (prefix + "Must have string value 'screen'\n").c_str());
|
||||
READER_ASSERT(value["screen"].IsString(), (prefix + "Value 'screen' must be a string (what type of output device does this slider apply to? [none, raster, vector, crt, lcd, non_vector, any])\n").c_str());
|
||||
READER_ASSERT(value.HasMember("scale"), (prefix + "Must have numeric value 'scale'\n").c_str());
|
||||
READER_ASSERT(value["scale"].IsNumber(), (prefix + "Value 'scale' must be a number (what do we multiply with to get 1.0?)").c_str());
|
||||
READER_ASSERT(value.HasMember("format"), (prefix + "Must have string value 'format'\n").c_str());
|
||||
READER_ASSERT(value["format"].IsString(), (prefix + "Value 'scale' must be a string (how would we display it in a printf?)").c_str());
|
||||
READER_ASSERT(value.HasMember("text"), (prefix + "Must have string value 'text'\n").c_str());
|
||||
READER_ASSERT(value["text"].IsString(), (prefix + "Value 'text' must be a string (how would you explain it?)").c_str());
|
||||
}
|
||||
|
@ -21,11 +21,11 @@ class running_machine;
|
||||
class slider_reader : public state_reader
|
||||
{
|
||||
public:
|
||||
static std::vector<bgfx_slider*> read_from_value(const Value& value, running_machine& machine, uint32_t window_index);
|
||||
static std::vector<bgfx_slider*> read_from_value(const Value& value, std::string prefix, running_machine& machine, uint32_t window_index);
|
||||
|
||||
private:
|
||||
static void get_values(const Value& value, std::string name, int* values, const int count);
|
||||
static void validate_parameters(const Value& value);
|
||||
static void get_values(const Value& value, std::string prefix, std::string name, int* values, const int count);
|
||||
static void validate_parameters(const Value& value, std::string prefix);
|
||||
|
||||
static const int TYPE_COUNT = 5;
|
||||
static const string_to_enum TYPE_NAMES[TYPE_COUNT];
|
||||
|
@ -14,9 +14,9 @@
|
||||
#include "entryuniform.h"
|
||||
#include "slider.h"
|
||||
|
||||
bgfx_entry_uniform* slider_uniform_reader::read_from_value(const Value& value, bgfx_uniform* uniform, std::map<std::string, bgfx_slider*>& sliders)
|
||||
bgfx_entry_uniform* slider_uniform_reader::read_from_value(const Value& value, std::string prefix, bgfx_uniform* uniform, std::map<std::string, bgfx_slider*>& sliders)
|
||||
{
|
||||
validate_parameters(value);
|
||||
validate_parameters(value, prefix);
|
||||
|
||||
std::string name = value["slider"].GetString();
|
||||
std::vector<bgfx_slider*> slider_list;
|
||||
@ -35,8 +35,8 @@ bgfx_entry_uniform* slider_uniform_reader::read_from_value(const Value& value, b
|
||||
return new bgfx_slider_uniform(uniform, slider_list);
|
||||
}
|
||||
|
||||
void slider_uniform_reader::validate_parameters(const Value& value)
|
||||
void slider_uniform_reader::validate_parameters(const Value& value, std::string prefix)
|
||||
{
|
||||
assert(value.HasMember("slider"));
|
||||
assert(value["slider"].IsString());
|
||||
READER_ASSERT(value.HasMember("slider"), (prefix + "Must have string value 'slider' (what slider are we getting the value of?)\n").c_str());
|
||||
READER_ASSERT(value["slider"].IsString(), (prefix + "Value 'slider' must be a string\n").c_str());
|
||||
}
|
||||
|
@ -23,10 +23,10 @@ class bgfx_slider;
|
||||
class slider_uniform_reader : public state_reader
|
||||
{
|
||||
public:
|
||||
static bgfx_entry_uniform* read_from_value(const Value& value, bgfx_uniform* uniform, std::map<std::string, bgfx_slider*>& sliders);
|
||||
static bgfx_entry_uniform* read_from_value(const Value& value, std::string prefix, bgfx_uniform* uniform, std::map<std::string, bgfx_slider*>& sliders);
|
||||
|
||||
private:
|
||||
static void validate_parameters(const Value& value);
|
||||
static void validate_parameters(const Value& value, std::string prefix);
|
||||
};
|
||||
|
||||
#endif // __DRAWBGFX_SLIDER_UNIFORM_READER__
|
||||
|
@ -35,6 +35,21 @@ protected:
|
||||
static uint64_t get_enum_from_value(const Value& value, std::string name, const uint64_t default_value, const string_to_enum* enums, const int count);
|
||||
static uint64_t get_param_from_string(std::string value, const string_to_enum* enums, const int count);
|
||||
|
||||
protected:
|
||||
static void READER_ASSERT(bool condition, const char* format, ...)
|
||||
{
|
||||
if (!condition)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
char buf[2048];
|
||||
vsnprintf(buf, 2048, format, ap);
|
||||
printf("%s\n", buf);
|
||||
fflush(stdout);
|
||||
fatalerror("%s", buf);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
static void get_vec_values(const Value& value_array, float* data, const unsigned int count);
|
||||
};
|
||||
|
@ -23,9 +23,9 @@ const suppressor_reader::string_to_enum suppressor_reader::COMBINE_NAMES[suppres
|
||||
{ "or", bgfx_suppressor::combine_mode::COMBINE_OR }
|
||||
};
|
||||
|
||||
bgfx_suppressor* suppressor_reader::read_from_value(const Value& value, std::map<std::string, bgfx_slider*>& sliders)
|
||||
bgfx_suppressor* suppressor_reader::read_from_value(const Value& value, std::string prefix, std::map<std::string, bgfx_slider*>& sliders)
|
||||
{
|
||||
validate_parameters(value);
|
||||
validate_parameters(value, prefix);
|
||||
|
||||
std::string name = value["name"].GetString();
|
||||
uint32_t condition = uint32_t(get_enum_from_value(value, "condition", bgfx_suppressor::condition_type::CONDITION_EQUAL, CONDITION_NAMES, CONDITION_COUNT));
|
||||
@ -56,13 +56,10 @@ bgfx_suppressor* suppressor_reader::read_from_value(const Value& value, std::map
|
||||
int values[4];
|
||||
if (slider_count > 1)
|
||||
{
|
||||
get_values(value, "value", values, slider_count);
|
||||
get_values(value, prefix, "value", values, slider_count);
|
||||
for (int index = 1; index < slider_count; index++)
|
||||
{
|
||||
std::string desc;
|
||||
char full_name[1024]; // arbitrary
|
||||
snprintf(full_name, 1024, "%s%d", name.c_str(), index);
|
||||
check_sliders.push_back(sliders[std::string(full_name)]);
|
||||
check_sliders.push_back(sliders[name + std::to_string(index)]);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -73,23 +70,21 @@ bgfx_suppressor* suppressor_reader::read_from_value(const Value& value, std::map
|
||||
return new bgfx_suppressor(check_sliders, condition, mode, values);
|
||||
}
|
||||
|
||||
void suppressor_reader::validate_parameters(const Value& value)
|
||||
void suppressor_reader::validate_parameters(const Value& value, std::string prefix)
|
||||
{
|
||||
assert(value.HasMember("name"));
|
||||
assert(value["name"].IsString());
|
||||
assert(value.HasMember("value"));
|
||||
assert(value["value"].IsNumber() || value["value"].IsArray());
|
||||
READER_ASSERT(value.HasMember("name"), (prefix + "Must have string value 'name'\n").c_str());
|
||||
READER_ASSERT(value["name"].IsString(), (prefix + "Value 'name' must be a string\n").c_str());
|
||||
READER_ASSERT(value.HasMember("value"), (prefix + "Must have numeric or array value 'value'\n").c_str());
|
||||
READER_ASSERT(value["value"].IsNumber() || value["value"].IsArray(), (prefix + "Value 'value' must be a number or array the size of the corresponding slider type\n").c_str());
|
||||
}
|
||||
|
||||
void suppressor_reader::get_values(const Value& value, std::string name, int* values, const int count)
|
||||
void suppressor_reader::get_values(const Value& value, std::string prefix, std::string name, int* values, const int count)
|
||||
{
|
||||
const char* name_str = name.c_str();
|
||||
assert(value.HasMember(name_str));
|
||||
assert(value[name_str].IsArray());
|
||||
|
||||
const Value& value_array = value[name_str];
|
||||
for (UINT32 i = 0; i < value_array.Size() && i < count; i++)
|
||||
{
|
||||
READER_ASSERT(value_array[i].IsInt(), (prefix + "value[" + std::to_string(i) + "] must be an integer\n").c_str());
|
||||
values[i] = value_array[i].GetInt();
|
||||
}
|
||||
}
|
||||
|
@ -22,12 +22,12 @@ class bgfx_slider;
|
||||
class suppressor_reader : public state_reader
|
||||
{
|
||||
public:
|
||||
static bgfx_suppressor* read_from_value(const Value& value, std::map<std::string, bgfx_slider*>& sliders);
|
||||
static bgfx_suppressor* read_from_value(const Value& value, std::string prefix, std::map<std::string, bgfx_slider*>& sliders);
|
||||
|
||||
private:
|
||||
static void get_values(const Value& value, std::string name, int* values, const int count);
|
||||
static void get_values(const Value& value, std::string prefix, std::string name, int* values, const int count);
|
||||
|
||||
static void validate_parameters(const Value& value);
|
||||
static void validate_parameters(const Value& value, std::string prefix);
|
||||
|
||||
static const int CONDITION_COUNT = 2;
|
||||
static const string_to_enum CONDITION_NAMES[CONDITION_COUNT];
|
||||
|
@ -11,9 +11,9 @@
|
||||
#include "entryuniform.h"
|
||||
#include "valueuniform.h"
|
||||
|
||||
bgfx_entry_uniform* value_uniform_reader::read_from_value(const Value& value, bgfx_uniform* uniform)
|
||||
bgfx_entry_uniform* value_uniform_reader::read_from_value(const Value& value, std::string prefix, bgfx_uniform* uniform)
|
||||
{
|
||||
validate_parameters(value);
|
||||
validate_parameters(value, prefix);
|
||||
|
||||
float values[4];
|
||||
int count = 1;
|
||||
@ -33,8 +33,8 @@ bgfx_entry_uniform* value_uniform_reader::read_from_value(const Value& value, bg
|
||||
return new bgfx_value_uniform(uniform, values, count);
|
||||
}
|
||||
|
||||
void value_uniform_reader::validate_parameters(const Value& value)
|
||||
void value_uniform_reader::validate_parameters(const Value& value, std::string prefix)
|
||||
{
|
||||
assert(value.HasMember("value"));
|
||||
assert(value["value"].IsArray() || value["value"].IsNumber());
|
||||
READER_ASSERT(value.HasMember("value"), (prefix + "Must have string value 'value' (what value is being assigned?)\n").c_str());
|
||||
READER_ASSERT(value["value"].IsArray() || value["value"].IsNumber(), (prefix + "Value 'value' must be numeric or an array\n").c_str());
|
||||
}
|
||||
|
@ -22,10 +22,10 @@ class bgfx_uniform;
|
||||
class value_uniform_reader : public state_reader
|
||||
{
|
||||
public:
|
||||
static bgfx_entry_uniform* read_from_value(const Value& value, bgfx_uniform* uniform);
|
||||
static bgfx_entry_uniform* read_from_value(const Value& value, std::string prefix, bgfx_uniform* uniform);
|
||||
|
||||
private:
|
||||
static void validate_parameters(const Value& value);
|
||||
static void validate_parameters(const Value& value, std::string prefix);
|
||||
};
|
||||
|
||||
#endif // __DRAWBGFX_VALUE_UNIFORM_READER__
|
||||
|
Loading…
Reference in New Issue
Block a user