bool ShadingEnviromentCompiler::readJSON(const jsonxx::Object& root) { BaseCompiler::readJSON(root); ShadingEnviroment shading; memset(&shading, 0x00, sizeof(shading)); //init shading variables float fogParams[] = {10, 40, 0, 0}; memcpy(shading.m_fog_params, fogParams, sizeof(fogParams)); vec3_make(shading.m_ambient_sky_color, 0.37f, 0.55f, 0.66f); shading.m_shadow_area_size = 30.0f; shading.m_shadow_far = 100; vec3_make(shading.m_shadow_params, 0.01f, 0.001f, 0.0f); if(root.has<jsonxx::Object>("fog")) { const jsonxx::Object& o = root.get<jsonxx::Object>("fog"); shading.m_fog_params[0] = json_to_float(o, "near", 10.0f); shading.m_fog_params[1] = json_to_float(o, "far", 40.0f); shading.m_fog_params[2] = json_to_float(o, "density", 0.0f); shading.m_fog_params[3] = json_to_float(o, "density", 0.0f); } json_to_floats(root, "ambient_sky_color", shading.m_ambient_sky_color, 3); json_to_floats(root, "ambient_ground_color", shading.m_ambient_ground_color, 3); if(root.has<jsonxx::Object>("shadow")) { const jsonxx::Object& o = root.get<jsonxx::Object>("shadow"); shading.m_shadow_area_size = json_to_float(o, "area", 1.0f); shading.m_shadow_far = json_to_float(o, "far", 1.0f); shading.m_shadow_params[0] = json_to_float(o, "offset", 1.0f); shading.m_shadow_params[1] = json_to_float(o, "bias", 1.0f); } if(root.has<jsonxx::Object>("color_grading")) { const jsonxx::Object& o = root.get<jsonxx::Object>("color_grading"); const jsonxx::Array& texturesValue = o.get<jsonxx::Array>("textures"); shading.m_num_colorgrading_textures = texturesValue.size(); for (uint32_t i=0; i<shading.m_num_colorgrading_textures; ++i) { const std::string& lutTexture = texturesValue.get<std::string>(i); shading.m_color_grading_texturenames[i] = stringid_caculate(lutTexture.c_str()); addDependency("color_grading_texture", name_to_file_path(lutTexture.c_str(), EngineNames::TEXTURE_3D)); } shading.m_colorgrading_index = json_to_int(o, "grading_index"); } return write_file(m_output, &shading, sizeof(shading)); }
static struct command_result *waitsendpay_error(struct command *cmd, const char *buf, const jsmntok_t *error, struct pay_command *pc) { const jsmntok_t *codetok, *scidtok, *dirtok; int code; attempt_failed_tok(pc, "waitsendpay", buf, error); codetok = json_get_member(buf, error, "code"); if (!json_to_int(buf, codetok, &code)) plugin_err("waitsendpay error gave no 'code'? '%.*s'", error->end - error->start, buf + error->start); /* FIXME: Handle PAY_UNPARSEABLE_ONION! */ /* Many error codes are final. */ if (code != PAY_TRY_OTHER_ROUTE) { return forward_error(cmd, buf, error, pc); } scidtok = json_delve(buf, error, ".data.erring_channel"); if (!scidtok) plugin_err("waitsendpay error no erring_channel '%.*s'", error->end - error->start, buf + error->start); dirtok = json_delve(buf, error, ".data.erring_direction"); if (!dirtok) plugin_err("waitsendpay error no erring_direction '%.*s'", error->end - error->start, buf + error->start); if (time_after(time_now(), pc->stoptime)) { return waitsendpay_expired(cmd, pc); } /* If failure is in routehint part, try next one */ if (channel_in_routehint(pc->current_routehint, buf, scidtok)) return next_routehint(cmd, pc); /* Otherwise, add erring channel to exclusion list. */ tal_arr_expand(&pc->excludes, tal_fmt(pc->excludes, "%.*s/%c", scidtok->end - scidtok->start, buf + scidtok->start, buf[dirtok->start])); /* Try again. */ return start_pay_attempt(cmd, pc, "Excluded channel %s", pc->excludes[tal_count(pc->excludes)-1]); }
struct svalue * json_to_value(json_object *ob) { enum json_type type = json_object_get_type(ob); switch (type) { case json_type_boolean: return json_to_boolean(ob); case json_type_double: return json_to_float(ob); case json_type_int: return json_to_int(ob); case json_type_string: return json_to_string(ob); case json_type_object: return json_to_mapping(ob); case json_type_array: return json_to_array(ob); case json_type_null: return json_to_null(ob); } return NULL; }