diff --git a/src/CRE/Glitter/curve.cpp b/src/CRE/Glitter/curve.cpp index 29388d16..de68ad87 100644 --- a/src/CRE/Glitter/curve.cpp +++ b/src/CRE/Glitter/curve.cpp @@ -11,12 +11,12 @@ namespace Glitter { const uint8_t step, size_t i, double_t t1, double_t t2, double_t t2_old, std::vector* keys_rev); - Curve::Key::Key() : type(), frame(), value(), tangent1(), tangent2(), random_range() { + Curve::Key::Key() : type(), frame(), value(), l_slope(), r_slope(), random_range() { } Curve::Key::Key(KeyType type, int32_t frame, - float_t value, float_t random_range) : tangent1(), tangent2() { + float_t value, float_t random_range) : l_slope(), r_slope() { this->type = type; this->frame = frame; this->value = value; @@ -24,21 +24,21 @@ namespace Glitter { } Curve::Key::Key(KeyType type, int32_t frame, float_t value, - float_t tangent1, float_t tangent2, float_t random_range) { + float_t l_slope, float_t r_slope, float_t random_range) { this->type = type; this->frame = frame; this->value = value; - this->tangent1 = tangent1; - this->tangent2 = tangent2; + this->l_slope = l_slope; + this->r_slope = r_slope; this->random_range = random_range; } - Curve::KeyRev::KeyRev() : type(), frame(), value(), tangent1(), tangent2(), random_range() { + Curve::KeyRev::KeyRev() : type(), frame(), value(), l_slope(), r_slope(), random_range() { } Curve::KeyRev::KeyRev(KeyType type, int32_t frame, - double_t value, double_t random_range) : tangent1(), tangent2() { + double_t value, double_t random_range) : l_slope(), r_slope() { this->type = type; this->frame = frame; this->value = value; @@ -46,12 +46,12 @@ namespace Glitter { } Curve::KeyRev::KeyRev(KeyType type, int32_t frame, double_t value, - double_t tangent1, double_t tangent2, double_t random_range) { + double_t l_slope, double_t r_slope, double_t random_range) { this->type = type; this->frame = frame; this->value = value; - this->tangent1 = tangent1; - this->tangent2 = tangent2; + this->l_slope = l_slope; + this->r_slope = r_slope; this->random_range = random_range; } @@ -171,7 +171,7 @@ namespace Glitter { float_t next_val = F2RandomizeKey(GLT_VAL, next, random); float_t curr_val = F2RandomizeKey(GLT_VAL, curr, random); return InterpolateHermite(F2RandomizeKey(GLT_VAL, curr, random), - next_val - curr_val, curr.tangent2, next.tangent1, + next_val - curr_val, curr.r_slope, next.l_slope, (float_t)curr.frame, (float_t)next.frame, frame); } @@ -211,8 +211,8 @@ namespace Glitter { const Curve::Key& src, bool baked_x = false, bool negate = false) { dst.type = src.type; dst.frame = src.frame; - dst.tangent1 = src.tangent1; - dst.tangent2 = src.tangent2; + dst.l_slope = src.l_slope; + dst.r_slope = src.r_slope; if (!baked_x) { dst.value = src.value; @@ -497,8 +497,8 @@ namespace Glitter { const Curve::KeyRev& src, bool baked_x = false, bool negate = false) { dst.type = src.type; dst.frame = src.frame; - dst.tangent1 = (float_t)src.tangent1; - dst.tangent2 = (float_t)src.tangent2; + dst.l_slope = (float_t)src.l_slope; + dst.r_slope = (float_t)src.r_slope; if (!baked_x) { dst.value = (float_t)src.value; @@ -598,7 +598,7 @@ namespace Glitter { } else if (curr_key->type == KEY_HERMITE) { val = InterpolateHermite(curr_key->value, next_key->value - curr_key->value, - curr_key->tangent2, next_key->tangent1, + curr_key->r_slope, next_key->l_slope, (double_t)curr_key->frame, (double_t)next_key->frame, (double_t)frame); rand_range = InterpolateHermite(curr_key->random_range, next_key->random_range - curr_key->random_range, 0.0, 0.0, @@ -716,7 +716,7 @@ namespace Glitter { float_t next_val = XRandomizeKey(next, random); float_t curr_val = XRandomizeKey(curr, random); return InterpolateHermite(XRandomizeKey(curr, random), - next_val - curr_val, curr.tangent2, next.tangent1, + next_val - curr_val, curr.r_slope, next.l_slope, (float_t)curr.frame, (float_t)next.frame, frame); } diff --git a/src/CRE/Glitter/effect_inst.cpp b/src/CRE/Glitter/effect_inst.cpp index bc073e5c..b66fff05 100644 --- a/src/CRE/Glitter/effect_inst.cpp +++ b/src/CRE/Glitter/effect_inst.cpp @@ -25,7 +25,7 @@ namespace Glitter { mat = mat4_identity; flags = (EffectInstFlag)0; random = 0; - req_frame = 0.0f; + frame_req = 0.0f; ext_color = 0.0f; ext_anim_scale = 0.0f; ext_scale = -1.0f; @@ -100,7 +100,7 @@ namespace Glitter { return bone_data->get_bone_node_index(BONE_KIND_CMN, bone_names[node]); } - EffectInstF2::ExtAnim::ExtAnim() : object_index(), mesh_index(), a3da_id(), object_is_hrc(), mesh_name() { + EffectInstF2::ExtAnim::ExtAnim() : object_index(), mesh_index(), scene_handle(), is_hrc(), mesh_name() { } @@ -111,8 +111,8 @@ namespace Glitter { void EffectInstF2::ExtAnim::Reset() { object_index = -1; mesh_index = -1; - a3da_id = -1; - object_is_hrc = false; + scene_handle = -1; + is_hrc = false; mesh_name = 0; mat = mat4_identity; translation = 0.0f; @@ -376,8 +376,6 @@ namespace Glitter { || (flags & EFFECT_INST_EXT_ANIM_SET_ONCE && flags & EFFECT_INST_EXT_ANIM_TRANS)) return; - int32_t chara_id; - if (flags & EFFECT_INST_EXT_ANIM_CHARA) { RobManagement* rob_man = get_rob_management(); if (!rob_man) @@ -414,25 +412,25 @@ namespace Glitter { } else if (flags & EFFECT_INST_EXT_ANIM_AUTH) { const mat4* obj_mat = 0; - if (ext_anim->a3da_id != -1) - obj_mat = auth_3d_id(ext_anim->a3da_id).get_auth_3d_object_mat( - ext_anim->object_index, ext_anim->object_is_hrc); + if (ext_anim->scene_handle != -1) + obj_mat = auth_3d_detail::get_object_matrix(ext_anim->scene_handle, + ext_anim->object_index, ext_anim->is_hrc); if (!obj_mat) { - ext_anim->a3da_id = auth_3d_data_get_auth_3d_id(ext_anim->object, - &ext_anim->object_index, &ext_anim->object_is_hrc); - if (ext_anim->a3da_id == -1) + ext_anim->scene_handle = auth_3d_detail::get_scene_object_index(ext_anim->object, + &ext_anim->object_index, &ext_anim->is_hrc); + if (ext_anim->scene_handle == -1) return; ext_anim->mesh_index = -1; - obj_mat = auth_3d_id(ext_anim->a3da_id).get_auth_3d_object_mat( - ext_anim->object_index, ext_anim->object_is_hrc); + obj_mat = auth_3d_detail::get_object_matrix(ext_anim->scene_handle, + ext_anim->object_index, ext_anim->is_hrc); if (!obj_mat) return; } mat4 mat = mat4_identity; - chara_id = auth_3d_id(ext_anim->a3da_id).get_chara_id(); + int32_t chara_id = auth_3d_detail::get_assign_rob_id(ext_anim->scene_handle); if (chara_id >= 0 && chara_id < ROB_ID_MAX) { RobManagement* rob_man = get_rob_management(); if (rob_man) { @@ -659,8 +657,8 @@ namespace Glitter { return ret; } - EffectInstX::ExtAnim::ExtAnim() : object_index(), mesh_index(), a3da_id(), - object_is_hrc(), file_name_hash(), object_hash(), instance_id(), mesh_name() { + EffectInstX::ExtAnim::ExtAnim() : object_index(), mesh_index(), scene_handle(), + is_hrc(), file_name_hash(), object_hash(), instance_id(), mesh_name() { } @@ -671,8 +669,8 @@ namespace Glitter { void EffectInstX::ExtAnim::Reset() { object_index = -1; mesh_index = -1; - a3da_id = -1; - object_is_hrc = false; + scene_handle = -1; + is_hrc = false; file_name_hash = hash_murmurhash_empty; object_hash = hash_murmurhash_empty; instance_id = 0; @@ -1113,27 +1111,26 @@ namespace Glitter { } else if (flags & EFFECT_INST_EXT_ANIM_AUTH) { const mat4* obj_mat = 0; - if (ext_anim->a3da_id != -1) - obj_mat = auth_3d_id(ext_anim->a3da_id).get_auth_3d_object_mat( - ext_anim->object_index, ext_anim->object_is_hrc); + if (ext_anim->scene_handle != -1) + obj_mat = auth_3d_detail::get_object_matrix(ext_anim->scene_handle, + ext_anim->object_index, ext_anim->is_hrc); if (!obj_mat) { - ext_anim->a3da_id = auth_3d_data_get_auth_3d_id( + ext_anim->scene_handle = auth_3d_detail::get_scene_object_index( ext_anim->file_name_hash, ext_anim->object_hash, - &ext_anim->object_index, &ext_anim->object_is_hrc, ext_anim->instance_id); - if (ext_anim->a3da_id == -1) + &ext_anim->object_index, &ext_anim->is_hrc, ext_anim->instance_id); + if (ext_anim->scene_handle == -1) return; ext_anim->mesh_index = -1; - obj_mat = auth_3d_id(ext_anim->a3da_id).get_auth_3d_object_mat( - ext_anim->object_index, ext_anim->object_is_hrc); + obj_mat = auth_3d_detail::get_object_matrix(ext_anim->scene_handle, + ext_anim->object_index, ext_anim->is_hrc); if (!obj_mat) return; } mat4 mat = mat4_identity; - - int32_t chara_id = auth_3d_id(ext_anim->a3da_id).get_chara_id(); + int32_t chara_id = auth_3d_detail::get_assign_rob_id(ext_anim->scene_handle); if (chara_id >= 0 && chara_id < ROB_ID_MAX) { RobManagement* rob_man = get_rob_management(); if (rob_man) { diff --git a/src/CRE/Glitter/file_reader.cpp b/src/CRE/Glitter/file_reader.cpp index 4578afe0..f33fd289 100644 --- a/src/CRE/Glitter/file_reader.cpp +++ b/src/CRE/Glitter/file_reader.cpp @@ -627,8 +627,8 @@ namespace Glitter { key.type = KEY_CONSTANT; key.frame = 0; key.value = 0.0f; - key.tangent1 = 0.0f; - key.tangent2 = 0.0f; + key.l_slope = 0.0f; + key.r_slope = 0.0f; key.random_range = 0.0f; std::vector& keys = c->keys; @@ -641,8 +641,8 @@ namespace Glitter { key.type = (KeyType)load_reverse_endianness_int16_t((void*)d); key.frame = load_reverse_endianness_int16_t((void*)(d + 2)); if (key.type == KEY_HERMITE) { - key.tangent1 = load_reverse_endianness_float_t((void*)(d + 4)); - key.tangent2 = load_reverse_endianness_float_t((void*)(d + 8)); + key.l_slope = load_reverse_endianness_float_t((void*)(d + 4)); + key.r_slope = load_reverse_endianness_float_t((void*)(d + 8)); key.min_value = load_reverse_endianness_float_t((void*)(d + 12)); key.max_value = load_reverse_endianness_float_t((void*)(d + 16)); keys.push_back(key); @@ -660,8 +660,8 @@ namespace Glitter { key.type = (KeyType)load_reverse_endianness_int16_t((void*)d); key.frame = load_reverse_endianness_int16_t((void*)(d + 2)); if (key.type == KEY_HERMITE) { - key.tangent1 = load_reverse_endianness_float_t((void*)(d + 4)); - key.tangent2 = load_reverse_endianness_float_t((void*)(d + 8)); + key.l_slope = load_reverse_endianness_float_t((void*)(d + 4)); + key.r_slope = load_reverse_endianness_float_t((void*)(d + 8)); key.value = load_reverse_endianness_float_t((void*)(d + 12)); keys.push_back(key); d += 16; @@ -678,8 +678,8 @@ namespace Glitter { key.type = (KeyType) * (int16_t*)d; key.frame = *(int16_t*)(d + 2); if (key.type == KEY_HERMITE) { - key.tangent1 = *(float_t*)(d + 4); - key.tangent2 = *(float_t*)(d + 8); + key.l_slope = *(float_t*)(d + 4); + key.r_slope = *(float_t*)(d + 8); key.min_value = *(float_t*)(d + 12); key.max_value = *(float_t*)(d + 16); keys.push_back(key); @@ -697,8 +697,8 @@ namespace Glitter { key.type = (KeyType) * (int16_t*)d; key.frame = *(int16_t*)(d + 2); if (key.type == KEY_HERMITE) { - key.tangent1 = *(float_t*)(d + 4); - key.tangent2 = *(float_t*)(d + 8); + key.l_slope = *(float_t*)(d + 4); + key.r_slope = *(float_t*)(d + 8); key.value = *(float_t*)(d + 12); keys.push_back(key); d += 16; @@ -717,8 +717,8 @@ namespace Glitter { key.type = (KeyType)load_reverse_endianness_int16_t((void*)d); key.frame = load_reverse_endianness_int16_t((void*)(d + 2)); if (key.type == KEY_HERMITE) { - key.tangent1 = load_reverse_endianness_float_t((void*)(d + 16)); - key.tangent2 = load_reverse_endianness_float_t((void*)(d + 20)); + key.l_slope = load_reverse_endianness_float_t((void*)(d + 16)); + key.r_slope = load_reverse_endianness_float_t((void*)(d + 20)); key.min_value = load_reverse_endianness_float_t((void*)(d + 24)); key.max_value = load_reverse_endianness_float_t((void*)(d + 28)); keys.push_back(key); @@ -736,8 +736,8 @@ namespace Glitter { key.type = (KeyType)load_reverse_endianness_int16_t((void*)d); key.frame = load_reverse_endianness_int16_t((void*)(d + 2)); if (key.type == KEY_HERMITE) { - key.tangent1 = load_reverse_endianness_float_t((void*)(d + 4)); - key.tangent2 = load_reverse_endianness_float_t((void*)(d + 8)); + key.l_slope = load_reverse_endianness_float_t((void*)(d + 4)); + key.r_slope = load_reverse_endianness_float_t((void*)(d + 8)); key.value = load_reverse_endianness_float_t((void*)(d + 12)); keys.push_back(key); d += 16; @@ -754,8 +754,8 @@ namespace Glitter { key.type = (KeyType) * (int16_t*)d; key.frame = *(int16_t*)(d + 2); if (key.type == KEY_HERMITE) { - key.tangent1 = *(float_t*)(d + 16); - key.tangent2 = *(float_t*)(d + 20); + key.l_slope = *(float_t*)(d + 16); + key.r_slope = *(float_t*)(d + 20); key.min_value = *(float_t*)(d + 24); key.max_value = *(float_t*)(d + 28); keys.push_back(key); @@ -773,8 +773,8 @@ namespace Glitter { key.type = (KeyType) * (int16_t*)d; key.frame = *(int16_t*)(d + 2); if (key.type == KEY_HERMITE) { - key.tangent1 = *(float_t*)(d + 4); - key.tangent2 = *(float_t*)(d + 8); + key.l_slope = *(float_t*)(d + 4); + key.r_slope = *(float_t*)(d + 8); key.value = *(float_t*)(d + 12); keys.push_back(key); d += 16; @@ -811,8 +811,8 @@ namespace Glitter { key.type = (KeyType)load_reverse_endianness_int16_t((void*)d); key.frame = load_reverse_endianness_int16_t((void*)(d + 2)); if (key.type == KEY_HERMITE) { - key.tangent1 = load_reverse_endianness_float_t((void*)(d + 4)); - key.tangent2 = load_reverse_endianness_float_t((void*)(d + 8)); + key.l_slope = load_reverse_endianness_float_t((void*)(d + 4)); + key.r_slope = load_reverse_endianness_float_t((void*)(d + 8)); key.random_range = load_reverse_endianness_float_t((void*)(d + 12)); key.value = load_reverse_endianness_float_t((void*)(d + 16)); keys.push_back(key); @@ -830,8 +830,8 @@ namespace Glitter { key.type = (KeyType)load_reverse_endianness_int16_t((void*)d); key.frame = load_reverse_endianness_int16_t((void*)(d + 2)); if (key.type == KEY_HERMITE) { - key.tangent1 = load_reverse_endianness_float_t((void*)(d + 4)); - key.tangent2 = load_reverse_endianness_float_t((void*)(d + 8)); + key.l_slope = load_reverse_endianness_float_t((void*)(d + 4)); + key.r_slope = load_reverse_endianness_float_t((void*)(d + 8)); key.value = load_reverse_endianness_float_t((void*)(d + 12)); keys.push_back(key); d += 16; @@ -848,8 +848,8 @@ namespace Glitter { key.type = (KeyType)load_reverse_endianness_int16_t((void*)d); key.frame = load_reverse_endianness_int16_t((void*)(d + 2)); if (key.type == KEY_HERMITE) { - key.tangent1 = load_reverse_endianness_float_t((void*)(d + 4)) * scale; - key.tangent2 = load_reverse_endianness_float_t((void*)(d + 8)) * scale; + key.l_slope = load_reverse_endianness_float_t((void*)(d + 4)) * scale; + key.r_slope = load_reverse_endianness_float_t((void*)(d + 8)) * scale; key.random_range = load_reverse_endianness_float_t((void*)(d + 12)) * scale; key.value = load_reverse_endianness_float_t((void*)(d + 16)) * scale; keys.push_back(key); @@ -867,8 +867,8 @@ namespace Glitter { key.type = (KeyType)load_reverse_endianness_int16_t((void*)d); key.frame = load_reverse_endianness_int16_t((void*)(d + 2)); if (key.type == KEY_HERMITE) { - key.tangent1 = load_reverse_endianness_float_t((void*)(d + 4)) * scale; - key.tangent2 = load_reverse_endianness_float_t((void*)(d + 8)) * scale; + key.l_slope = load_reverse_endianness_float_t((void*)(d + 4)) * scale; + key.r_slope = load_reverse_endianness_float_t((void*)(d + 8)) * scale; key.value = load_reverse_endianness_float_t((void*)(d + 12)) * scale; keys.push_back(key); d += 16; @@ -886,8 +886,8 @@ namespace Glitter { key.type = (KeyType) * (int16_t*)d; key.frame = *(int16_t*)(d + 2); if (key.type == KEY_HERMITE) { - key.tangent1 = *(float_t*)(d + 4); - key.tangent2 = *(float_t*)(d + 8); + key.l_slope = *(float_t*)(d + 4); + key.r_slope = *(float_t*)(d + 8); key.random_range = *(float_t*)(d + 12); key.value = *(float_t*)(d + 16); keys.push_back(key); @@ -905,8 +905,8 @@ namespace Glitter { key.type = (KeyType) * (int16_t*)d; key.frame = *(int16_t*)(d + 2); if (key.type == KEY_HERMITE) { - key.tangent1 = *(float_t*)(d + 4); - key.tangent2 = *(float_t*)(d + 8); + key.l_slope = *(float_t*)(d + 4); + key.r_slope = *(float_t*)(d + 8); key.value = *(float_t*)(d + 12); keys.push_back(key); d += 16; @@ -923,8 +923,8 @@ namespace Glitter { key.type = (KeyType) * (int16_t*)d; key.frame = *(int16_t*)(d + 2); if (key.type == KEY_HERMITE) { - key.tangent1 = *(float_t*)(d + 4) * scale; - key.tangent2 = *(float_t*)(d + 8) * scale; + key.l_slope = *(float_t*)(d + 4) * scale; + key.r_slope = *(float_t*)(d + 8) * scale; key.random_range = *(float_t*)(d + 12) * scale; key.value = *(float_t*)(d + 16) * scale; keys.push_back(key); @@ -942,8 +942,8 @@ namespace Glitter { key.type = (KeyType) * (int16_t*)d; key.frame = *(int16_t*)(d + 2); if (key.type == KEY_HERMITE) { - key.tangent1 = *(float_t*)(d + 4) * scale; - key.tangent2 = *(float_t*)(d + 8) * scale; + key.l_slope = *(float_t*)(d + 4) * scale; + key.r_slope = *(float_t*)(d + 8) * scale; key.value = *(float_t*)(d + 12) * scale; keys.push_back(key); d += 16; diff --git a/src/CRE/Glitter/file_writer.cpp b/src/CRE/Glitter/file_writer.cpp index 63297dc9..e5ccaeaa 100644 --- a/src/CRE/Glitter/file_writer.cpp +++ b/src/CRE/Glitter/file_writer.cpp @@ -159,8 +159,8 @@ namespace Glitter { store_reverse_endianness_int16_t((void*)d, (int16_t)i.type); store_reverse_endianness_int16_t((void*)(d + 2), (int16_t)i.frame); if (i.type == KEY_HERMITE) { - store_reverse_endianness_float_t((void*)(d + 4), i.tangent1); - store_reverse_endianness_float_t((void*)(d + 8), i.tangent2); + store_reverse_endianness_float_t((void*)(d + 4), i.l_slope); + store_reverse_endianness_float_t((void*)(d + 8), i.r_slope); store_reverse_endianness_float_t((void*)(d + 12), i.min_value); store_reverse_endianness_float_t((void*)(d + 16), i.max_value); d += 20; @@ -176,8 +176,8 @@ namespace Glitter { store_reverse_endianness_int16_t((void*)d, (int16_t)i.type); store_reverse_endianness_int16_t((void*)(d + 2), (int16_t)i.frame); if (i.type == KEY_HERMITE) { - store_reverse_endianness_float_t((void*)(d + 4), i.tangent1); - store_reverse_endianness_float_t((void*)(d + 8), i.tangent2); + store_reverse_endianness_float_t((void*)(d + 4), i.l_slope); + store_reverse_endianness_float_t((void*)(d + 8), i.r_slope); store_reverse_endianness_float_t((void*)(d + 12), i.value); d += 16; } @@ -192,8 +192,8 @@ namespace Glitter { *(int16_t*)d = (int16_t)i.type; *(int16_t*)(d + 2) = (int16_t)i.frame; if (i.type == KEY_HERMITE) { - *(float_t*)(d + 4) = i.tangent1; - *(float_t*)(d + 8) = i.tangent2; + *(float_t*)(d + 4) = i.l_slope; + *(float_t*)(d + 8) = i.r_slope; *(float_t*)(d + 12) = i.min_value; *(float_t*)(d + 16) = i.max_value; d += 20; @@ -209,8 +209,8 @@ namespace Glitter { *(int16_t*)d = (int16_t)i.type; *(int16_t*)(d + 2) = (int16_t)i.frame; if (i.type == KEY_HERMITE) { - *(float_t*)(d + 4) = i.tangent1; - *(float_t*)(d + 8) = i.tangent2; + *(float_t*)(d + 4) = i.l_slope; + *(float_t*)(d + 8) = i.r_slope; *(float_t*)(d + 12) = i.value; d += 16; } @@ -227,8 +227,8 @@ namespace Glitter { store_reverse_endianness_int16_t((void*)d, (int16_t)i.type); store_reverse_endianness_int16_t((void*)(d + 2), (int16_t)i.frame); if (i.type == KEY_HERMITE) { - store_reverse_endianness_float_t((void*)(d + 16), i.tangent1); - store_reverse_endianness_float_t((void*)(d + 20), i.tangent2); + store_reverse_endianness_float_t((void*)(d + 16), i.l_slope); + store_reverse_endianness_float_t((void*)(d + 20), i.r_slope); store_reverse_endianness_float_t((void*)(d + 24), i.min_value); store_reverse_endianness_float_t((void*)(d + 28), i.max_value); d += 32; @@ -244,8 +244,8 @@ namespace Glitter { store_reverse_endianness_int16_t((void*)d, (int16_t)i.type); store_reverse_endianness_int16_t((void*)(d + 2), (int16_t)i.frame); if (i.type == KEY_HERMITE) { - store_reverse_endianness_float_t((void*)(d + 4), i.tangent1); - store_reverse_endianness_float_t((void*)(d + 8), i.tangent2); + store_reverse_endianness_float_t((void*)(d + 4), i.l_slope); + store_reverse_endianness_float_t((void*)(d + 8), i.r_slope); store_reverse_endianness_float_t((void*)(d + 12), i.value); d += 16; } @@ -260,8 +260,8 @@ namespace Glitter { *(int16_t*)d = (int16_t)i.type; *(int16_t*)(d + 2) = (int16_t)i.frame; if (i.type == KEY_HERMITE) { - *(float_t*)(d + 16) = i.tangent1; - *(float_t*)(d + 20) = i.tangent2; + *(float_t*)(d + 16) = i.l_slope; + *(float_t*)(d + 20) = i.r_slope; *(float_t*)(d + 24) = i.min_value; *(float_t*)(d + 28) = i.max_value; d += 32; @@ -277,8 +277,8 @@ namespace Glitter { *(int16_t*)d = (int16_t)i.type; *(int16_t*)(d + 2) = (int16_t)i.frame; if (i.type == KEY_HERMITE) { - *(float_t*)(d + 4) = i.tangent1; - *(float_t*)(d + 8) = i.tangent2; + *(float_t*)(d + 4) = i.l_slope; + *(float_t*)(d + 8) = i.r_slope; *(float_t*)(d + 12) = i.value; d += 16; } @@ -313,8 +313,8 @@ namespace Glitter { store_reverse_endianness_int16_t((void*)d, (int16_t)i.type); store_reverse_endianness_int16_t((void*)(d + 2), (int16_t)i.frame); if (i.type == KEY_HERMITE) { - store_reverse_endianness_float_t((void*)(d + 4), i.tangent1); - store_reverse_endianness_float_t((void*)(d + 8), i.tangent2); + store_reverse_endianness_float_t((void*)(d + 4), i.l_slope); + store_reverse_endianness_float_t((void*)(d + 8), i.r_slope); store_reverse_endianness_float_t((void*)(d + 12), i.random_range); store_reverse_endianness_float_t((void*)(d + 16), i.value); d += 20; @@ -330,8 +330,8 @@ namespace Glitter { store_reverse_endianness_int16_t((void*)d, (int16_t)i.type); store_reverse_endianness_int16_t((void*)(d + 2), (int16_t)i.frame); if (i.type == KEY_HERMITE) { - store_reverse_endianness_float_t((void*)(d + 4), i.tangent1); - store_reverse_endianness_float_t((void*)(d + 8), i.tangent2); + store_reverse_endianness_float_t((void*)(d + 4), i.l_slope); + store_reverse_endianness_float_t((void*)(d + 8), i.r_slope); store_reverse_endianness_float_t((void*)(d + 12), i.value); d += 16; } @@ -346,8 +346,8 @@ namespace Glitter { *(int16_t*)d = (int16_t)i.type; *(int16_t*)(d + 2) = (int16_t)i.frame; if (i.type == KEY_HERMITE) { - *(float_t*)(d + 4) = i.tangent1; - *(float_t*)(d + 8) = i.tangent2; + *(float_t*)(d + 4) = i.l_slope; + *(float_t*)(d + 8) = i.r_slope; *(float_t*)(d + 12) = i.random_range; *(float_t*)(d + 16) = i.value; d += 20; @@ -363,8 +363,8 @@ namespace Glitter { *(int16_t*)d = (int16_t)i.type; *(int16_t*)(d + 2) = (int16_t)i.frame; if (i.type == KEY_HERMITE) { - *(float_t*)(d + 4) = i.tangent1; - *(float_t*)(d + 8) = i.tangent2; + *(float_t*)(d + 4) = i.l_slope; + *(float_t*)(d + 8) = i.r_slope; *(float_t*)(d + 12) = i.value; d += 16; } @@ -381,8 +381,8 @@ namespace Glitter { store_reverse_endianness_int16_t((void*)d, (int16_t)i.type); store_reverse_endianness_int16_t((void*)(d + 2), (int16_t)i.frame); if (i.type == KEY_HERMITE) { - store_reverse_endianness_float_t((void*)(d + 4), i.tangent1 * scale); - store_reverse_endianness_float_t((void*)(d + 8), i.tangent2 * scale); + store_reverse_endianness_float_t((void*)(d + 4), i.l_slope * scale); + store_reverse_endianness_float_t((void*)(d + 8), i.r_slope * scale); store_reverse_endianness_float_t((void*)(d + 12), i.random_range * scale); store_reverse_endianness_float_t((void*)(d + 16), i.value * scale); d += 20; @@ -398,8 +398,8 @@ namespace Glitter { store_reverse_endianness_int16_t((void*)d, (int16_t)i.type); store_reverse_endianness_int16_t((void*)(d + 2), (int16_t)i.frame); if (i.type == KEY_HERMITE) { - store_reverse_endianness_float_t((void*)(d + 4), i.tangent1 * scale); - store_reverse_endianness_float_t((void*)(d + 8), i.tangent2 * scale); + store_reverse_endianness_float_t((void*)(d + 4), i.l_slope * scale); + store_reverse_endianness_float_t((void*)(d + 8), i.r_slope * scale); store_reverse_endianness_float_t((void*)(d + 12), i.value * scale); d += 16; } @@ -414,8 +414,8 @@ namespace Glitter { *(int16_t*)d = (int16_t)i.type; *(int16_t*)(d + 2) = (int16_t)i.frame; if (i.type == KEY_HERMITE) { - *(float_t*)(d + 4) = i.tangent1 * scale; - *(float_t*)(d + 8) = i.tangent2 * scale; + *(float_t*)(d + 4) = i.l_slope * scale; + *(float_t*)(d + 8) = i.r_slope * scale; *(float_t*)(d + 12) = i.random_range * scale; *(float_t*)(d + 16) = i.value * scale; d += 20; @@ -431,8 +431,8 @@ namespace Glitter { *(int16_t*)d = (int16_t)i.type; *(int16_t*)(d + 2) = (int16_t)i.frame; if (i.type == KEY_HERMITE) { - *(float_t*)(d + 4) = i.tangent1 * scale; - *(float_t*)(d + 8) = i.tangent2 * scale; + *(float_t*)(d + 4) = i.l_slope * scale; + *(float_t*)(d + 8) = i.r_slope * scale; *(float_t*)(d + 12) = i.value * scale; d += 16; } diff --git a/src/CRE/Glitter/glitter.hpp b/src/CRE/Glitter/glitter.hpp index 581aa60c..7e0bf962 100644 --- a/src/CRE/Glitter/glitter.hpp +++ b/src/CRE/Glitter/glitter.hpp @@ -515,8 +515,8 @@ namespace Glitter { float_t value; float_t max_value; }; - float_t tangent1; - float_t tangent2; + float_t l_slope; + float_t r_slope; union { float_t random_range; float_t min_value; @@ -525,21 +525,21 @@ namespace Glitter { Key(); Key(KeyType type, int32_t frame, float_t value, float_t random_range); Key(KeyType type, int32_t frame, float_t value, - float_t tangent1, float_t tangent2, float_t random_range); + float_t l_slope, float_t r_slope, float_t random_range); }; struct KeyRev { KeyType type; int32_t frame; double_t value; - double_t tangent1; - double_t tangent2; + double_t l_slope; + double_t r_slope; double_t random_range; KeyRev(); KeyRev(KeyType type, int32_t frame, double_t value, double_t random_range); KeyRev(KeyType type, int32_t frame, double_t value, - double_t tangent1, double_t tangent2, double_t random_range); + double_t l_slope, double_t r_slope, double_t random_range); }; CurveType type; @@ -918,7 +918,7 @@ namespace Glitter { EffectInstFlag flags; size_t id; uint32_t random; - float_t req_frame; + float_t frame_req; vec4 ext_color; float_t ext_scale; vec3 ext_anim_scale; @@ -953,8 +953,8 @@ namespace Glitter { struct { int32_t object_index; int32_t mesh_index; - int32_t a3da_id; - bool object_is_hrc; + int32_t scene_handle; + bool is_hrc; object_info object; const char* mesh_name; }; @@ -1015,8 +1015,8 @@ namespace Glitter { struct { int32_t object_index; int32_t mesh_index; - int32_t a3da_id; - bool object_is_hrc; + int32_t scene_handle; + bool is_hrc; uint32_t file_name_hash; uint32_t object_hash; int32_t instance_id; @@ -1662,7 +1662,7 @@ namespace Glitter { bool SetExtColorByID(float_t r, float_t g, float_t b, float_t a, bool set, size_t id); void SetExtScale(float_t scale, size_t id); void SetFrameRate(FrameRateControl* frame_rate); - void SetReqFrame(size_t id, float_t req_frame); + void SetFrameReq(size_t id, float_t frame_req); }; class GltParticleManager : public app::Task { @@ -1739,7 +1739,7 @@ namespace Glitter { void SetSceneEffectExtColor(SceneCounter scene_counter, float_t r, float_t g, float_t b, float_t a, bool set, uint64_t effect_hash); void SetSceneEffectExtScale(SceneCounter scene_counter, float_t scale); - void SetSceneEffectReqFrame(SceneCounter scene_counter, float_t req_frame); + void SetSceneEffectFrameReq(SceneCounter scene_counter, float_t frame_req); void SetSceneFrameRate(SceneCounter scene_counter, FrameRateControl* frame_rate); void SetSceneName(uint64_t hash, const char* name); void SetPause(bool value); diff --git a/src/CRE/Glitter/particle_manager.cpp b/src/CRE/Glitter/particle_manager.cpp index 68036c87..462823aa 100644 --- a/src/CRE/Glitter/particle_manager.cpp +++ b/src/CRE/Glitter/particle_manager.cpp @@ -920,10 +920,10 @@ namespace Glitter { } } - void GltParticleManager::SetSceneEffectReqFrame(SceneCounter scene_counter, float_t req_frame) { + void GltParticleManager::SetSceneEffectFrameReq(SceneCounter scene_counter, float_t frame_req) { for (Scene*& i : scenes) if (i && i->counter.counter == scene_counter.counter) { - i->SetReqFrame(scene_counter.index, req_frame); + i->SetFrameReq(scene_counter.index, frame_req); break; } } diff --git a/src/CRE/Glitter/scene.cpp b/src/CRE/Glitter/scene.cpp index b5b3219a..ec928c40 100644 --- a/src/CRE/Glitter/scene.cpp +++ b/src/CRE/Glitter/scene.cpp @@ -138,10 +138,10 @@ namespace Glitter { if (!just_init) _delta_frame = delta_frame; - float_t req_frame = eff->req_frame; - eff->req_frame = 0.0f; + float_t frame_req = eff->frame_req; + eff->frame_req = 0.0f; - float_t remain_frame = req_frame - _delta_frame; + float_t remain_frame = frame_req - _delta_frame; while (true) { if (step || _delta_frame > 0.0f) { eff->CtrlFlags(_delta_frame); @@ -437,16 +437,16 @@ namespace Glitter { this->frame_rate = frame_rate; } - void Scene::SetReqFrame(size_t id, float_t req_frame) { + void Scene::SetFrameReq(size_t id, float_t frame_req) { if (!id) { for (SceneEffect& i : effects) if (i.disp && i.ptr) - i.ptr->req_frame = req_frame; + i.ptr->frame_req = frame_req; } else for (SceneEffect& i : effects) if (i.disp && i.ptr && i.ptr->id == id) { - i.ptr->req_frame = req_frame; + i.ptr->frame_req = frame_req; break; } } diff --git a/src/CRE/auth_2d.cpp b/src/CRE/auth_2d.cpp index c0a14351..c9bf73c5 100644 --- a/src/CRE/auth_2d.cpp +++ b/src/CRE/auth_2d.cpp @@ -6,6 +6,7 @@ #include #include #include "auth_2d.hpp" +#include "../KKdLib/prj/algorithm.hpp" #include "../KKdLib/farc.hpp" #include "../KKdLib/str_utils.hpp" #include "data.hpp" @@ -218,6 +219,164 @@ AetArgs& AetArgs::operator=(const AetArgs& other) { return *this; } +namespace aet { + // 0x14019CB90 + void IdHandle::M_put() { + data_struct* aft_data = &data_list[DATA_AFT]; + aet_database* aft_aet_db = &aft_data->data_ft.aet_db; + + if (M_args.id.id < 0) + M_handle = -1; + else { + M_handle = aet_manager_init_aet_object(M_args, aft_aet_db); + if (M_handle != -1) + aet_manager_set_obj_play(M_handle, 1); + } + } + + // 0x14019D540 + void IdHandle::remove() { + if (M_handle != -1) + aet_manager_free_aet_object(M_handle); + M_handle = -1; + } + + IdHandle::IdHandle(const IdHandle& other) : M_args(other.M_args), M_handle(other.M_handle) { + + } + + IdHandle::IdHandle() : M_handle(-1) { + + } + + IdHandle::~IdHandle() { + + } + + // 0x14019CC80 + IdHandle& IdHandle::assign(const AetArgs& in_args) { + remove(); + M_args = in_args; + return *this; + } + + // Missing + void IdHandle::restart() { + if (isValid() && getReady()) { + remove(); + M_put(); + } + } + + // 0x1401E5F10 + void IdHandle::put() { + remove(); + M_put(); + } + + // Inlined + void IdHandle::put_valid() { + if (isValid()) { + remove(); + M_put(); + } + } + + // Inlined + void IdHandle::destroy() { + remove(); + M_args = {}; + } + + // Missing + void IdHandle::setDisplay(bool flag) { + if (isValid()) + aet_manager_set_obj_visible(M_handle, flag); + } + + // Missing + void IdHandle::setPlay(bool flag) { + if (isValid()) + aet_manager_set_obj_play(M_handle, flag); + } + + // 0x1401D4F10 + bool IdHandle::getReady() { + data_struct* aft_data = &data_list[DATA_AFT]; + aet_database* aft_aet_db = &aft_data->data_ft.aet_db; + + return aet_manager_get_set_ready(M_args.id.id, aft_aet_db); + } + + // 0x14019CD00 + void SetHandle::destroy() { + free(); + M_set = -1; + M_spr_set = S_INVALID_SPR_SET; + } + + SetHandle::SetHandle() : M_set(-1), M_spr_set(S_INVALID_SPR_SET), M_is_requested(false) { + + } + + SetHandle::~SetHandle() { + + } + + // 0x14019CCB0 + SetHandle& SetHandle::assign(int32_t uid) { + destroy(); + + data_struct* aft_data = &data_list[DATA_AFT]; + aet_database* aft_aet_db = &aft_data->data_ft.aet_db; + + M_spr_set = S_INVALID_SPR_SET; + M_set = uid; + M_spr_set = aft_aet_db->get_aet_set_by_id(M_set)->sprite_set_id; + return *this; + } + + // 0x14019D5C0 + void SetHandle::request() { + if (!isValid()) + return; + + data_struct* aft_data = &data_list[DATA_AFT]; + aet_database* aft_aet_db = &aft_data->data_ft.aet_db; + SprDb* aft_spr_db = &aft_data->data_ft.spr_db; + + spr::request(M_spr_set, "", aft_data, aft_spr_db); + aet_manager_read_file(M_set, "", aft_data, aft_aet_db); + M_is_requested = true; + } + + // 0x14019D920 + bool SetHandle::wait() { + if (!isValid() || !M_is_requested) + return false; + + data_struct* aft_data = &data_list[DATA_AFT]; + aet_database* aft_aet_db = &aft_data->data_ft.aet_db; + SprDb* aft_spr_db = &aft_data->data_ft.spr_db; + + return spr::wait(M_spr_set, aft_spr_db) || aet_manager_load_file(M_set, aft_aet_db); + } + + // 0x14019CDA0 + void SetHandle::free() { + if (!isValid() || !M_is_requested) + return; + + data_struct* aft_data = &data_list[DATA_AFT]; + aet_database* aft_aet_db = &aft_data->data_ft.aet_db; + SprDb* aft_spr_db = &aft_data->data_ft.spr_db; + + aet_manager_unload_set(M_set, aft_aet_db); + spr::free(M_spr_set, aft_spr_db); + M_is_requested = false; + } +} + aet_layout_data::aet_layout_data() : width(), height() { mat = mat4_identity; opacity = 1.0f; @@ -1579,16 +1738,7 @@ void AetMgr::FreeAetObject(uint32_t id) { } void AetMgr::FreeAetObject(std::map::iterator it) { - auto i = free_objects.begin(); - auto i_end = free_objects.end(); - while (i != i_end) { - if (it == *i) { - free_objects.erase(i); - break; - } - i++; - } - + prj::find_and_erase(free_objects, it); free_objects.push_back(it); } diff --git a/src/CRE/auth_2d.hpp b/src/CRE/auth_2d.hpp index 88b56b7d..1a7a3d31 100644 --- a/src/CRE/auth_2d.hpp +++ b/src/CRE/auth_2d.hpp @@ -74,6 +74,59 @@ struct AetArgs { AetArgs& operator=(const AetArgs& other); }; +namespace aet { + class IdHandle { + private: + AetArgs M_args; + int32_t M_handle; + + void M_put(); + void remove(); + + public: + IdHandle(const IdHandle& other); + IdHandle(); + ~IdHandle(); + + inline bool isValid() { + return M_handle != -1; + } + + IdHandle& assign(const AetArgs& in_args); + void restart(); + void put(); + void put_valid(); + void destroy(); + void setDisplay(bool flag); + void setPlay(bool flag); + bool getReady(); + }; + + class SetHandle { + private: + int32_t M_set; + int32_t M_spr_set; + bool M_is_requested; + + void destroy(); + + static const uint32_t S_INVALID_SPR_SET = -1; + + public: + SetHandle(); + ~SetHandle(); + + inline bool isValid() { + return M_set != -1; + } + + SetHandle& assign(int32_t uid); + void request(); + bool wait(); + void free(); + }; +} + struct aet_layout_data { mat4 mat; vec3 position; diff --git a/src/CRE/auth_3d.cpp b/src/CRE/auth_3d.cpp index f470c5e6..b39efac8 100644 --- a/src/CRE/auth_3d.cpp +++ b/src/CRE/auth_3d.cpp @@ -12,9 +12,9 @@ #include "../KKdLib/hash.hpp" #include "../KKdLib/interpolation.hpp" #include "../KKdLib/msgpack.hpp" -#include "../KKdLib/sort.hpp" #include "../KKdLib/str_utils.hpp" #include "rob/rob.hpp" +#include "rob/motion.hpp" #include "app_system_detail.hpp" #include "clear_color.hpp" #include "data.hpp" @@ -44,1001 +44,35 @@ namespace auth_3d_detail { virtual float_t get_delta_frame() override; }; + + static void event_log(const char* fmt, ...); + static const char* get_ID_EVENT_TYPE(EVENT_TYPE type); + + template + size_t get_index_by_name(const T& in_c, const std::string& in_name); + + template + void list_load(T& in_c, const SceneFile& in_file, const U& in_a, Args... args); + + template + void list_store(const T& in_c, const SceneFile& in_file, U& in_a, Args... args); } -typedef a3da_ambient auth_3d_ambient_file; -typedef a3da_camera_auxiliary auth_3d_camera_auxiliary_file; -typedef a3da_camera_root auth_3d_camera_root_file; -typedef a3da_camera_root_view_point auth_3d_camera_root_view_point_file; -typedef a3da_chara auth_3d_chara_file; -typedef a3da_curve auth_3d_curve_file; -typedef a3da_dof auth_3d_dof_file; -typedef a3da_event auth_3d_event_file; -typedef a3da_fog auth_3d_fog_file; -typedef a3da_key auth_3d_key_file; -typedef a3da_light auth_3d_light_file; -typedef a3da_m_object_hrc auth_3d_m_object_hrc_file; -typedef a3da_object_instance auth_3d_object_instance_file; -typedef a3da_material_list auth_3d_material_list_file; -typedef a3da_model_transform auth_3d_model_transform_file; -typedef a3da_object auth_3d_object_file; -typedef a3da_object_hrc auth_3d_object_hrc_file; -typedef a3da_object_node auth_3d_object_node_file; -typedef a3da_object_texture_pattern auth_3d_object_texture_pattern_file; -typedef a3da_object_texture_transform auth_3d_object_texture_transform_file; -typedef a3da_play_control auth_3d_play_control_file; -typedef a3da_point auth_3d_point_file; -typedef a3da_post_process auth_3d_post_process_file; -typedef a3da_rgba auth_3d_rgba_file; -typedef a3da_vec3 auth_3d_vec3_file; +static void a3da_msgpack_read(const char* path, const char* file, a3d::Scene* auth_file); -static void a3da_msgpack_read(const char* path, const char* file, a3da* auth_file); +static void auth_3d_set_material_list(auth_3d_detail::Scene& in_scene, render_context* rctx); -static bool auth_3d_key_detect_fast_change(auth_3d_key* data, float_t frame, float_t threshold); -static kft3* auth_3d_key_find_keyframe(auth_3d_key* data, float_t frame); -static float_t auth_3d_key_interpolate_inner(auth_3d_key* data, float_t frame); -static float_t auth_3d_interpolate_value(auth_3d_key_type type, - float_t frame, kft3* curr_key, kft3* next_key); -static void auth_3d_key_load(auth_3d* auth, auth_3d_key* k, auth_3d_key_file* kf); -static void auth_3d_key_store(auth_3d* auth, auth_3d_key* k, auth_3d_key_file* kf); -static void auth_3d_rgba_load(auth_3d* auth, auth_3d_rgba* rgba, auth_3d_rgba_file* rgbaf); -static void auth_3d_rgba_store(auth_3d* auth, auth_3d_rgba* rgba, auth_3d_rgba_file* rgbaf); -static void auth_3d_vec3_load(auth_3d* auth, auth_3d_vec3* vec, auth_3d_vec3_file* vecf); -static void auth_3d_vec3_store(auth_3d* auth, auth_3d_vec3* vec, auth_3d_vec3_file* vecf); -static void auth_3d_model_transform_load(auth_3d* auth, auth_3d_model_transform* mt, auth_3d_model_transform_file* mtf); -static void auth_3d_model_transform_store(auth_3d* auth, auth_3d_model_transform* mt, auth_3d_model_transform_file* mtf); +namespace auth_3d_detail { + Auth3dManager* g_manager; + TaskAuth3d* task_auth_3d; +} -static int32_t auth_3d_get_auth_3d_object_index_by_object_info(auth_3d* auth, - object_info obj_info, int32_t object_instance); -static int32_t auth_3d_get_auth_3d_object_index_by_hash(auth_3d* auth, - uint32_t object_hash, int32_t object_instance); -static const mat4* auth_3d_get_auth_3d_object_mat(auth_3d* auth, size_t index); -static const mat4* auth_3d_get_auth_3d_object_hrc_bone_mats(auth_3d* auth, size_t index); -static int32_t auth_3d_get_auth_3d_object_hrc_index_by_object_info(auth_3d* auth, - object_info obj_info, int32_t object_instance = -1); -static int32_t auth_3d_get_auth_3d_object_hrc_index_by_hash(auth_3d* auth, - uint32_t object_hash, int32_t object_instance = -1); -static void auth_3d_read_file(auth_3d* auth, auth_3d_database* auth_3d_db); -static void auth_3d_read_file_modern(auth_3d* auth); -static void auth_3d_set_material_list(auth_3d* auth, render_context* rctx); - -static void auth_3d_ambient_load(auth_3d* auth, auth_3d_ambient* a, auth_3d_ambient_file* af); -static void auth_3d_ambient_set(auth_3d_ambient* a, render_context* rctx); -static void auth_3d_ambient_store(auth_3d* auth, auth_3d_ambient* a, auth_3d_ambient_file* af); -static void auth_3d_camera_auxiliary_load(auth_3d* auth, auth_3d_camera_auxiliary_file* caf); -static void auth_3d_camera_auxiliary_restore_prev_value(auth_3d_camera_auxiliary* ca, render_context* rctx); -static void auth_3d_camera_auxiliary_set(auth_3d_camera_auxiliary* ca, render_context* rctx); -static void auth_3d_camera_auxiliary_store(auth_3d* auth, auth_3d_camera_auxiliary_file* caf); -static float_t auth_3d_camera_root_calc_frame(auth_3d_camera_root* cr, float_t frame, render_context* rctx); -static void auth_3d_camera_root_load(auth_3d* auth, auth_3d_camera_root* cr, auth_3d_camera_root_file* crf); -static void auth_3d_camera_root_store(auth_3d* auth, auth_3d_camera_root* cr, auth_3d_camera_root_file* crf); -static void auth_3d_camera_root_view_point_load(auth_3d* auth, auth_3d_camera_root_view_point* crvp, - auth_3d_camera_root_view_point_file* crvpf); -static void auth_3d_camera_root_view_point_store(auth_3d* auth, auth_3d_camera_root_view_point* crvp, - auth_3d_camera_root_view_point_file* crvpf); -static void auth_3d_chara_disp(auth_3d_chara* c, auth_3d* auth, render_context* rctx); -static void auth_3d_chara_load(auth_3d* auth, auth_3d_chara* c, auth_3d_chara_file* cf); -static void auth_3d_chara_set(auth_3d_chara* c, auth_3d* auth, render_context* rctx); -static void auth_3d_chara_store(auth_3d* auth, auth_3d_chara* c, auth_3d_chara_file* cf); -static void auth_3d_curve_load(auth_3d* auth, auth_3d_curve* c, auth_3d_curve_file* cf); -static void auth_3d_curve_store(auth_3d* auth, auth_3d_curve* c, auth_3d_curve_file* cf); -static void auth_3d_dof_load(auth_3d* auth, auth_3d_dof* d, auth_3d_dof_file* df); -static void auth_3d_dof_restore_prev_value(auth_3d_dof* d, render_context* rctx); -static void auth_3d_dof_set(auth_3d_dof* d, render_context* rctx); -static void auth_3d_dof_store(auth_3d* auth, auth_3d_dof* d, auth_3d_dof_file* df); -static auth_3d_detail::Event* auth_3d_event_load(auth_3d* auth, auth_3d_event_file* ef); -static void auth_3d_event_store(auth_3d* auth, auth_3d_detail::Event* e, auth_3d_event_file* ef); -static const char* auth_3d_event_type_string(auth_3d_detail::Event::Type type); -static void auth_3d_fog_load(auth_3d* auth, auth_3d_fog* f, auth_3d_fog_file* ff); -static void auth_3d_fog_restore_prev_value(auth_3d_fog* f, render_context* rctx); -static void auth_3d_fog_set(auth_3d_fog* f, render_context* rctx); -static void auth_3d_fog_store(auth_3d* auth, auth_3d_fog* f, auth_3d_fog_file* ff); -static void auth_3d_light_load(auth_3d* auth, auth_3d_light* l, auth_3d_light_file* lf); -static void auth_3d_light_restore_prev_value(auth_3d_light* l, render_context* rctx); -static void auth_3d_light_set(auth_3d_light* l, render_context* rctx); -static void auth_3d_light_store(auth_3d* auth, auth_3d_light* l, auth_3d_light_file* lf); -static void auth_3d_m_object_hrc_disp(auth_3d_m_object_hrc* moh, auth_3d* auth, render_context* rctx); -static void auth_3d_m_object_hrc_get_mat(auth_3d_m_object_hrc* moh, mat4* mat); -static void auth_3d_m_object_hrc_load(auth_3d* auth, auth_3d_m_object_hrc* moh, - auth_3d_m_object_hrc_file* mohf, object_database* obj_db); -static void auth_3d_m_object_hrc_nodes_mat_mult(auth_3d_m_object_hrc* moh); -static void auth_3d_m_object_hrc_store(auth_3d* auth, auth_3d_m_object_hrc* moh, - auth_3d_m_object_hrc_file* mohf); -static void auth_3d_material_list_load(auth_3d* auth, auth_3d_material_list* ml, auth_3d_material_list_file* mlf); -static void auth_3d_material_list_store(auth_3d* auth, auth_3d_material_list* ml, auth_3d_material_list_file* mlf); -static void auth_3d_object_disp(auth_3d_object* o, auth_3d* auth, render_context* rctx); -static void auth_3d_object_load(auth_3d* auth, auth_3d_object* o, - auth_3d_object_file* of, object_database* obj_db, texture_database* tex_db); -static void auth_3d_object_store(auth_3d* auth, auth_3d_object* o, - auth_3d_object_file* of); -static void auth_3d_object_curve_load(auth_3d* auth, auth_3d_object_curve* oc, - std::string& name, float_t frame_offset); -static void auth_3d_object_curve_store(auth_3d* auth, auth_3d_object_curve* oc, - std::string& name, float_t& frame_offset); -static void auth_3d_object_hrc_disp(auth_3d_object_hrc* oh, auth_3d* auth, render_context* rctx); -static void auth_3d_object_hrc_load(auth_3d* auth, auth_3d_object_hrc* oh, - auth_3d_object_hrc_file* ohf, object_database* obj_db); -static void auth_3d_object_hrc_store(auth_3d* auth, auth_3d_object_hrc* oh, - auth_3d_object_hrc_file* ohf); -static bool auth_3d_object_hrc_replace_chara(auth_3d_object_hrc* oh, - CHARA_NUM src_chara, CHARA_NUM dst_chara, object_database* obj_db); -static void auth_3d_object_hrc_nodes_mat_mult(auth_3d_object_hrc* oh, const mat4* mat); -static void auth_3d_object_instance_load(auth_3d* auth, auth_3d_object_instance* oi, - auth_3d_object_instance_file* oif, auth_3d_m_object_hrc* moh, object_database* obj_db); -static void auth_3d_object_instance_store(auth_3d* auth, auth_3d_object_instance* oi, - auth_3d_object_instance_file* oif, auth_3d_m_object_hrc* moh); -static void auth_3d_object_model_transform_load(auth_3d* auth, - auth_3d_object_model_transform* omt, auth_3d_model_transform_file* mtf); -static void auth_3d_object_model_transform_store(auth_3d* auth, - auth_3d_object_model_transform* omt, auth_3d_model_transform_file* mtf); -static void auth_3d_object_node_load(auth_3d* auth, - auth_3d_object_node* on, auth_3d_object_node_file* onf); -static void auth_3d_object_node_store(auth_3d* auth, - auth_3d_object_node* on, auth_3d_object_node_file* onf); -static void auth_3d_object_texture_pattern_load(auth_3d* auth, auth_3d_object_texture_pattern* otp, - auth_3d_object_texture_pattern_file* otpf, texture_database* tex_db); -static void auth_3d_object_texture_pattern_store(auth_3d* auth, auth_3d_object_texture_pattern* otp, - auth_3d_object_texture_pattern_file* otpf); -static void auth_3d_object_texture_transform_load(auth_3d* auth, auth_3d_object_texture_transform* ott, - auth_3d_object_texture_transform_file* ottf, texture_database* tex_db); -static void auth_3d_object_texture_transform_store(auth_3d* auth, auth_3d_object_texture_transform* ott, - auth_3d_object_texture_transform_file* ottf); -static void auth_3d_play_control_load(auth_3d* auth, auth_3d_play_control_file* pcf); -static void auth_3d_play_control_store(auth_3d* auth, auth_3d_play_control_file* pcf); -static void auth_3d_point_disp(auth_3d_point* p, auth_3d* auth, render_context* rctx); -static void auth_3d_point_load(auth_3d* auth, auth_3d_point* p, auth_3d_point_file* pf); -static void auth_3d_point_store(auth_3d* auth, auth_3d_point* p, auth_3d_point_file* pf); -static void auth_3d_post_process_load(auth_3d* auth, auth_3d_post_process* pp, auth_3d_post_process_file* ppf); -static void auth_3d_post_process_restore_prev_value(auth_3d_post_process* pp, render_context* rctx); -static void auth_3d_post_process_set(auth_3d_post_process* pp, render_context* rctx); -static void auth_3d_post_process_store(auth_3d* auth, auth_3d_post_process* pp, auth_3d_post_process_file* ppf); - -static bool auth_3d_data_struct_init(auth_3d_data_struct* auth_3d_data, render_context* rctx); -static bool auth_3d_data_struct_check_category_loaded( - auth_3d_data_struct* auth_3d_data, const char* category_name); -static bool auth_3d_data_struct_check_category_loaded( - auth_3d_data_struct* auth_3d_data, uint32_t category_hash); -static bool auth_3d_data_struct_ctrl(auth_3d_data_struct* auth_3d_data, render_context* rctx); -static void auth_3d_data_struct_disp(auth_3d_data_struct* auth_3d_data, render_context* rctx); -static auth_3d_farc* auth_3d_data_struct_get_farc( - auth_3d_data_struct* auth_3d_data, const char* category_name); -static void auth_3d_data_struct_load_category(auth_3d_data_struct* auth_3d_data, - const char* category_name, const char* mdata_dir); -static void auth_3d_data_struct_load_category(auth_3d_data_struct* auth_3d_data, - void* data, const char* category_name, uint32_t category_hash); -static void auth_3d_data_struct_unload_category(auth_3d_data_struct* auth_3d_data, const char* category_name); -static void auth_3d_data_struct_unload_category( - auth_3d_data_struct* auth_3d_data, uint32_t category_hash); - -static void auth_3d_farc_load(auth_3d_farc* a3da_farc, const char* mdata_dir); -static void auth_3d_farc_load_modern(auth_3d_farc* a3da_farc, void* data); -static void auth_3d_farc_read_file(auth_3d_farc* a3da_farc, const char* mdata_dir); -static void auth_3d_farc_read_file_modern(auth_3d_farc* a3da_farc, void* data); -static bool auth_3d_farc_read_func(auth_3d_farc* a3da_farc, const void* data, size_t size); -static void auth_3d_farc_reset(auth_3d_farc* a3da_farc); -static void auth_3d_farc_unload(auth_3d_farc* a3da_farc); - -static void auth_3d_uid_file_load(auth_3d_uid_file* uid_file); -static void auth_3d_uid_file_modern_load(auth_3d_uid_file_modern* uid_file); -static void auth_3d_uid_file_load_file(auth_3d_uid_file* uid_file, auth_3d_database* auth_3d_db); -static void auth_3d_uid_file_modern_load_file(auth_3d_uid_file_modern* uid_file); -static void auth_3d_uid_file_unload(auth_3d_uid_file* uid_file); -static void auth_3d_uid_file_modern_unload(auth_3d_uid_file_modern* uid_file); -static void auth_3d_uid_file_unload_file(auth_3d_uid_file* uid_file); -static void auth_3d_uid_file_modern_unload_file(auth_3d_uid_file_modern* uid_file); - -static size_t auth_3d_time_event_radix_index_func_frame(auth_3d_time_event* data, size_t index); - -auth_3d_data_struct* auth_3d_data; -auth_3d_detail::TaskAuth3d* task_auth_3d; - -static int16_t auth_3d_load_counter; +static int16_t magic_number; +static const mat4 bad_matrix; static auth_3d_detail::FrameRateTimeStop frame_rate_time_stop; extern render_context* rctx_ptr; -auth_3d::auth_3d() : uid(), id(), mat(), enable(), camera_root_update(), visible(), repeat(), field_C(), ended(), -mirror(), once(), alpha(), rob_id(), chara_item(), shadow(), reflect(), pos(), frame_rate(), frame(), -req_frame(), max_frame(), frame_changed(), frame_offset(), last_frame(), paused(), event_time_next() { - hash = hash_murmurhash_empty; - src_chara = CN_MAX; - dst_chara = CN_MAX; - reset(); -} - -auth_3d::~auth_3d() { - reset(); -} - -void auth_3d::ctrl(render_context* rctx) { - parse(); - - if (state != 2 || !enable) - return; - - int32_t event_flags = 0; - bool set = false; - while (true) { - bool v40 = this->field_C; - if (frame_changed) { - frame_changed = false; - if (req_frame < frame) { - event_time_next = event_time.data(); - event_flags |= 0x02; - } - else - event_flags |= 0x04; - frame = req_frame; - field_C = true; - ended = false; - if (max_frame >= 0.0f && frame >= max_frame) - max_frame = -1.0f; - } - else if (!paused) { - event_flags |= 0x01; - frame += frame_rate->get_delta_frame(); - if (max_frame >= 0.0f && frame > max_frame) - frame = max_frame; - } - - float_t frame = this->frame; - for (auth_3d_point& i : point) - i.interpolate(frame); - - for (auth_3d_curve& i : curve) - i.interpolate(frame); - - for (auth_3d_chara& i : chara) - i.interpolate(frame); - - for (auth_3d_material_list& i : material_list) - i.interpolate(frame); - - for (auth_3d_object& i : object) - i.interpolate(frame); - - for (auth_3d_object*& i : object_list) - i->list_ctrl(&mat); - - for (auth_3d_object_hrc& i : object_hrc) - i.interpolate(frame); - - for (auth_3d_object_hrc*& i : object_hrc_list) - i->list_ctrl(&mat); - - for (auth_3d_m_object_hrc& i : m_object_hrc) - i.interpolate(frame); - - for (auth_3d_m_object_hrc*& i : m_object_hrc_list) - i->list_ctrl(&mat); - - for (auth_3d_ambient& i : ambient) { - i.interpolate(frame); - auth_3d_ambient_set(&i, rctx); - } - - for (auth_3d_light& i : light) { - i.interpolate(frame); - auth_3d_light_set(&i, rctx); - } - - for (auth_3d_fog& i : fog) { - i.interpolate(frame); - auth_3d_fog_set(&i, rctx); - } - - post_process.interpolate(frame); - auth_3d_post_process_set(&post_process, rctx); - - for (auth_3d_chara& i : chara) - auth_3d_chara_set(&i, this, rctx); - - auth_3d_time_event* i_event = event_time_next; - auth_3d_time_event* i_event_end = event_time.data() + event_time.size(); - for (; i_event != i_event_end && frame >= i_event->frame; i_event++) { - auth_3d_detail::Event* e = event[i_event->event_index]; - if (!i_event->type) { - printf_debug(" [%s]: [%s][%s]\n", - auth_3d_event_type_string(e->type), e->ref.c_str(), e->param1.c_str()); - e->Begin(this, event_flags, rctx); - e->active = true; - } - else if (i_event->type) { - printf_debug(" [%s]: [%s][%s]\n", - auth_3d_event_type_string(e->type), e->ref.c_str(), e->param1.c_str()); - if (e->active) { - e->active = false; - e->End(this, event_flags, rctx); - } - } - } - event_time_next = i_event; - - for (auth_3d_detail::Event*& i : event) - if (i->active) - i->Ctrl(this, event_flags, rctx); - - camera_auxiliary.interpolate(frame); - auth_3d_camera_auxiliary_set(&camera_auxiliary, rctx); - - if (camera_root_update) - for (auth_3d_camera_root& i : camera_root) { - i.interpolate(auth_3d_camera_root_calc_frame(&i, frame, rctx)); - - cam_struct cam; - - cam.interest = i.interest_value; - cam.view_point = i.view_point_value; - cam.fov = i.fov_value; - cam.roll = i.roll_value; - - if (mirror) { - cam.interest.x = -cam.interest.x; - cam.view_point.x = -cam.view_point.x; - cam.roll = -cam.roll; - } - - mat4_transform_point(&mat, &cam.interest, &cam.interest); - mat4_transform_point(&mat, &cam.view_point, &cam.view_point); - - cam.set(rctx->camera); - break; - } - - dof.interpolate(frame); - auth_3d_dof_set(&dof, rctx); - - if (field_C && v40 != field_C) - for (a3d::EventAdapter*& i : event_adapter) { - auth_3d_id id = get_id(); - i->OnCtrl(id); - } - - if (set || !repeat || last_frame > frame) - break; - - for (a3d::EventAdapter*& i : event_adapter) { - auth_3d_id id = get_id(); - i->OnRepeat(id); - } - - req_frame = frame - last_frame + frame_offset; - frame_changed = true; - set = true; - } - - for (a3d::EventAdapter*& i : event_adapter) { - auth_3d_id id = get_id(); - i->OnPostCtrl(id); - } - - bool ended = play_control.size <= frame; - if (ended && this->ended != ended) { - paused = true; - if (once) - enable = false; - - for (a3d::EventAdapter*& i : event_adapter) { - auth_3d_id id = get_id(); - i->OnEnded(id); - } - } - this->ended = ended; -} - -void auth_3d::disp(render_context* rctx) { - if (state != 2 || !enable) - return; - - if (pos) - debug_put_line_axis(mat); - - auth_3d_set_material_list(this, rctx); - extern bool reflect_full; - extern bool reflect_draw; - reflect_draw = reflect_full && reflect; - - for (auth_3d_point& i : point) - auth_3d_point_disp(&i, this, rctx); - - for (auth_3d_chara& i : chara) - auth_3d_chara_disp(&i, this, rctx); - - for (auth_3d_object*& i : object_list) - auth_3d_object_disp(i, this, rctx); - - for (auth_3d_object_hrc*& i : object_hrc_list) - auth_3d_object_hrc_disp(i, this, rctx); - - for (auth_3d_m_object_hrc*& i : m_object_hrc_list) - auth_3d_m_object_hrc_disp(i, this, rctx); - - for (auth_3d_detail::Event*& i : event) - if (i->active) - i->Disp(this, &mat, rctx); - - reflect_draw = false; - rctx->disp_manager->set_material_list(); -} - -auth_3d_id auth_3d::get_id() { - return auth_3d_id(id); -} - -void auth_3d::load(a3da* auth_file, - object_database* obj_db, texture_database* tex_db) { - if (!auth_file) - return; - - hash = hash_murmurhash_empty; - auth_3d_play_control_load(this, &auth_file->play_control); - - frame_offset = 0.0f; - max_frame = play_control.size; - last_frame = play_control.size; - - this->obj_db = obj_db; - this->tex_db = tex_db; - - auth_3d_camera_auxiliary_load(this, &auth_file->camera_auxiliary); - auth_3d_dof_load(this, &dof, &auth_file->dof); - auth_3d_post_process_load(this, &post_process, &auth_file->post_process); - - if (auth_file->ambient.size()) { - size_t ambient_index = 0; - ambient.resize(auth_file->ambient.size()); - for (auth_3d_ambient_file& i : auth_file->ambient) - auth_3d_ambient_load(this, &ambient[ambient_index++], &i); - } - - if (auth_file->auth_2d.size()) { - size_t auth_2d_index = 0; - auth_2d.resize(auth_file->auth_2d.size()); - for (std::string& i : auth_file->auth_2d) - auth_2d[auth_2d_index++].assign(i); - } - - if (auth_file->camera_root.size()) { - size_t camera_root_index = 0; - camera_root.resize(auth_file->camera_root.size()); - for (auth_3d_camera_root_file& i : auth_file->camera_root) - auth_3d_camera_root_load(this, &camera_root[camera_root_index++], &i); - } - - if (auth_file->chara.size()) { - size_t chara_index = 0; - chara.resize(auth_file->chara.size()); - for (auth_3d_chara_file& i : auth_file->chara) - auth_3d_chara_load(this, &chara[chara_index++], &i); - } - - if (auth_file->curve.size()) { - size_t curve_index = 0; - curve.resize(auth_file->curve.size()); - for (auth_3d_curve_file& i : auth_file->curve) - auth_3d_curve_load(this, &curve[curve_index++], &i); - } - - if (auth_file->event.size()) { - event.reserve(auth_file->event.size()); - for (auth_3d_event_file& i : auth_file->event) { - auth_3d_detail::Event* e = auth_3d_event_load(this, &i); - if (e) - event.push_back(e); - } - } - - if (auth_file->fog.size()) { - size_t fog_index = 0; - fog.resize(auth_file->fog.size()); - for (auth_3d_fog_file& i : auth_file->fog) - auth_3d_fog_load(this, &fog[fog_index++], &i); - } - - if (auth_file->light.size()) { - size_t light_index = 0; - light.resize(auth_file->light.size()); - for (auth_3d_light_file& i : auth_file->light) - auth_3d_light_load(this, &light[light_index++], &i); - } - - if (auth_file->m_object_hrc.size()) { - size_t m_object_hrc_index = 0; - m_object_hrc.resize(auth_file->m_object_hrc.size()); - for (auth_3d_m_object_hrc_file& i : auth_file->m_object_hrc) - auth_3d_m_object_hrc_load(this, &m_object_hrc[m_object_hrc_index++], &i, obj_db); - } - - if (auth_file->material_list.size()) { - size_t material_list_index = 0; - material_list.resize(auth_file->material_list.size()); - for (auth_3d_material_list_file& i : auth_file->material_list) - auth_3d_material_list_load(this, &material_list[material_list_index++], &i); - } - - if (auth_file->motion.size()) { - size_t motion_index = 0; - motion.resize(auth_file->motion.size()); - for (std::string& i : auth_file->motion) - motion[motion_index++].assign(i); - } - - if (auth_file->object.size()) { - size_t object_index = 0; - object.resize(auth_file->object.size()); - for (auth_3d_object_file& i : auth_file->object) - auth_3d_object_load(this, &object[object_index++], &i, obj_db, tex_db); - } - - if (auth_file->object_hrc.size()) { - size_t object_hrc_index = 0; - object_hrc.resize(auth_file->object_hrc.size()); - for (auth_3d_object_hrc_file& i : auth_file->object_hrc) - auth_3d_object_hrc_load(this, &object_hrc[object_hrc_index++], &i, obj_db); - - for (auth_3d_object_hrc& i : object_hrc) - auth_3d_object_hrc_replace_chara(&i, (CHARA_NUM)src_chara, (CHARA_NUM)dst_chara, obj_db); - } - - if (auth_file->point.size()) { - size_t point_index = 0; - point.resize(auth_file->point.size()); - for (auth_3d_point_file& i : auth_file->point) - auth_3d_point_load(this, &point[point_index++], &i); - } - - if (auth_file->m_object_hrc_list.size()) { - size_t m_object_hrc_list_index = 0; - m_object_hrc_list.resize(auth_file->m_object_hrc_list.size()); - for (std::string& i : auth_file->m_object_hrc_list) - for (auth_3d_m_object_hrc& j : m_object_hrc) - if (!i.compare(j.name)) { - m_object_hrc_list[m_object_hrc_list_index++] = &j; - break; - } - m_object_hrc_list.resize(m_object_hrc_list_index); - } - - if (auth_file->object_list.size()) { - size_t object_list_index = 0; - object_list.resize(auth_file->object_list.size()); - for (std::string& i : auth_file->object_list) - for (auth_3d_object& j : object) - if (!i.compare(j.name)) { - object_list[object_list_index++] = &j; - break; - } - object_list.resize(object_list_index); - } - - if (auth_file->object_hrc_list.size()) { - size_t object_hrc_list_index = 0; - object_hrc_list.resize(auth_file->object_hrc_list.size()); - for (std::string& i : auth_file->object_hrc_list) - for (auth_3d_object_hrc& j : object_hrc) - if (!i.compare(j.name)) { - object_hrc_list[object_hrc_list_index++] = &j; - break; - } - object_hrc_list.resize(object_hrc_list_index); - } - - if (object.size()) { - for (auth_3d_object& i : object) { - if (!i.parent_name.size()) - continue; - - if (i.parent_node.size()) - for (auth_3d_object_hrc& j : object_hrc) { - if (i.parent_name.compare(j.name)) - continue; - - int32_t node_index = j.get_node_index(i.parent_node.c_str()); - if (node_index > -1) { - j.children_object_parent_node.push_back(node_index); - j.children_object.push_back(&i); - } - break; - } - else - for (auth_3d_object& j : object) { - if (i.parent_name.compare(j.name)) - continue; - - j.children_object.push_back(&i); - break; - } - } - } - - if (object_hrc.size()) { - for (auth_3d_object_hrc& i : object_hrc) { - if (!i.parent_name.size()) - continue; - - if (i.parent_node.size()) - for (auth_3d_object_hrc& j : object_hrc) { - if (i.parent_name.compare(j.name)) - continue; - - int32_t node_index = j.get_node_index(i.parent_node.c_str()); - if (node_index > -1) { - j.children_object_hrc_parent_node.push_back(node_index); - j.children_object_hrc.push_back(&i); - } - break; - } - else - for (auth_3d_object& j : object) { - if (i.parent_name.compare(j.name)) - continue; - - j.children_object_hrc.push_back(&i); - break; - } - } - } - - if (event.size()) { - for (auth_3d_detail::Event*& i : event) - if (i) - i->Load(this); - - size_t event_index = 0; - event_time.clear(); - event_time.shrink_to_fit(); - event_time.reserve(event.size() * 2); - for (auth_3d_detail::Event*& i : event) { - event_time.push_back({ i->begin, 0, event_index }); - event_time.push_back({ i->end , 1, event_index }); - event_index++; - } - - radix_sort_custom(event_time.data(), event_time.size(), sizeof(auth_3d_time_event), - sizeof(float_t), (radix_index_func)auth_3d_time_event_radix_index_func_frame); - - event_time_next = event_time.data(); - } - - file_name.assign(auth_file->_file_name); -} - -void auth_3d::load_from_farc(struct farc* f, const char* file, - object_database* obj_db, texture_database* tex_db) { - farc_file* ff = f->read_file(file); - if (!ff) - return; - - const char* l_str = ff->name.c_str(); - const char* t = strrchr(l_str, '.'); - size_t l_len = ff->name.size(); - if (t) - l_len = t - l_str; - - uint32_t h = hash_murmurhash(l_str, l_len); - - a3da a; - a.read(ff->data, ff->size); - load(&a, obj_db, tex_db); -} - -void auth_3d::parse() { - if (state != 1) - return; - - if (hash == hash_murmurhash_empty) { - data_struct* aft_data = &data_list[DATA_AFT]; - auth_3d_database* aft_auth_3d_db = &aft_data->data_ft.auth_3d_db; - object_database* aft_obj_db = &aft_data->data_ft.obj_db; - texture_database* aft_tex_db = &aft_data->data_ft.tex_db; - - auth_3d_database_uid* db_uid = &aft_auth_3d_db->uid[uid]; - if (db_uid->enabled) { - auth_3d_uid_file* uid_file = &auth_3d_data->uid_files[uid]; - if (uid_file->uid == uid && uid_file->state == 1 && uid_file->farc->state == 2) { - state = 2; - farc_file* ff = uid_file->farc->farc->read_file(uid_file->file_name.c_str()); - if (ff) { - a3da a; - a.read(ff->data, ff->size); - - time_struct time; - load(&a, aft_obj_db, aft_tex_db); - time.calc_time(); - - for (a3d::EventAdapter*& i : event_adapter) { - auth_3d_id id = get_id(); - i->OnLoad(id); - } - - frame = 0.0f; - } - } - } - } - else { - auto elem = auth_3d_data->uid_files_modern.find(hash); - if (elem == auth_3d_data->uid_files_modern.end()) - return; - - auth_3d_uid_file_modern* uid_file = &elem->second; - if (uid_file->hash == hash && uid_file->state == 1 && uid_file->farc->state == 2) { - state = 2; - farc_file* ff = uid_file->farc->farc->read_file(uid_file->hash); - if (ff) { - a3da a; - a.read(ff->data, ff->size); - - a3da_msgpack_read("patch\\AFT\\auth_3d", a._file_name.c_str(), &a); - - const char* l_str = ff->name.c_str(); - const char* t = strrchr(l_str, '.'); - size_t l_len = ff->name.size(); - if (t) - l_len = t - l_str; - - uid_file->name.assign(ff->name.c_str(), l_len); - uid_file->file_name.assign(ff->name); - file_name.assign(ff->name); - - time_struct time; - load(&a, uid_file->obj_db, uid_file->tex_db); - time.calc_time(); - - hash = uid_file->hash; - - for (a3d::EventAdapter*& i : event_adapter) { - auth_3d_id id = get_id(); - i->OnLoad(id); - } - - frame = 0.0f; - } - } - } -} - -void auth_3d::reset() { - uid = -1; - id = -1; - mat = mat4_identity; - enable = false; - camera_root_update = true; - visible = true; - repeat = false; - field_C = false; - ended = false; - mirror = false; - once = false; - mat = mat4_identity; - alpha = 1.0f; - obj_flags = mdl::OBJ_ALPHA_ORDER_POST_GLITTER; - rob_id = ROB_ID_NULL; - chara_item = false; - shadow = false; - reflect = false; - src_chara = CN_MAX; - dst_chara = CN_MAX; - pos = 0; - frame_rate = get_sys_frame_rate(); - frame = 0.0f; - req_frame = 0.0f; - max_frame = -1.0f; - frame_changed = true; - frame_offset = 0.0f; - last_frame = 0.0f; - paused = true; - ambient.clear(); - ambient.shrink_to_fit(); - auth_2d.clear(); - auth_2d.shrink_to_fit(); - camera_auxiliary.reset(); - camera_root.clear(); - camera_root.shrink_to_fit(); - chara.clear(); - chara.shrink_to_fit(); - curve.clear(); - curve.shrink_to_fit(); - dof.reset(); - for (auth_3d_detail::Event*& i : event) - if (i) { - delete i; - i = 0; - } - event.clear(); - event.shrink_to_fit(); - event_time.clear(); - event_time.shrink_to_fit(); - event_time_next = 0; - fog.clear(); - fog.shrink_to_fit(); - light.clear(); - light.shrink_to_fit(); - m_object_hrc.clear(); - m_object_hrc.shrink_to_fit(); - m_object_hrc_list.clear(); - m_object_hrc_list.shrink_to_fit(); - material_list.clear(); - material_list.shrink_to_fit(); - motion.clear(); - motion.shrink_to_fit(); - object.clear(); - object.shrink_to_fit(); - object_hrc.clear(); - object_hrc.shrink_to_fit(); - object_hrc_list.clear(); - object_hrc_list.shrink_to_fit(); - object_list.clear(); - object_list.shrink_to_fit(); - play_control.reset(); - point.clear(); - point.shrink_to_fit(); - post_process.reset(); - state = 0; - event_adapter.clear(); - event_adapter.shrink_to_fit(); - hash = hash_murmurhash_empty; -} - -void auth_3d::store(a3da* auth_file) { - auth_3d_play_control_store(this, &auth_file->play_control); - - auth_3d_camera_auxiliary_store(this, &auth_file->camera_auxiliary); - auth_3d_dof_store(this, &dof, &auth_file->dof); - auth_3d_post_process_store(this, &post_process, &auth_file->post_process); - - if (ambient.size()) { - size_t ambient_index = 0; - auth_file->ambient.resize(auth_file->ambient.size()); - for (auth_3d_ambient& i : ambient) - auth_3d_ambient_store(this, &i, &auth_file->ambient[ambient_index++]); - } - - if (auth_2d.size()) { - size_t auth_2d_index = 0; - auth_file->auth_2d.resize(auth_2d.size()); - for (std::string& i : auth_2d) - auth_file->auth_2d[auth_2d_index++].assign(i); - } - - if (camera_root.size()) { - size_t camera_root_index = 0; - auth_file->camera_root.resize(camera_root.size()); - for (auth_3d_camera_root& i : camera_root) - auth_3d_camera_root_store(this, &i, &auth_file->camera_root[camera_root_index++]); - } - - if (chara.size()) { - size_t chara_index = 0; - auth_file->chara.resize(chara.size()); - for (auth_3d_chara& i : chara) - auth_3d_chara_store(this, &i, &auth_file->chara[chara_index++]); - } - - if (curve.size()) { - size_t curve_index = 0; - auth_file->curve.resize(curve.size()); - for (auth_3d_curve& i : curve) - auth_3d_curve_store(this, &i, &auth_file->curve[curve_index++]); - } - - if (event.size()) { - size_t event_index = 0; - auth_file->event.resize(event.size()); - for (auth_3d_detail::Event*& i : event) - auth_3d_event_store(this, i, &auth_file->event[event_index]); - } - - if (fog.size()) { - size_t fog_index = 0; - auth_file->fog.resize(fog.size()); - for (auth_3d_fog& i : fog) - auth_3d_fog_store(this, &i, &auth_file->fog[fog_index++]); - } - - if (light.size()) { - size_t light_index = 0; - auth_file->light.resize(light.size()); - for (auth_3d_light& i : light) - auth_3d_light_store(this, &i, &auth_file->light[light_index++]); - } - - if (m_object_hrc.size()) { - size_t m_object_hrc_index = 0; - auth_file->m_object_hrc.resize(m_object_hrc.size()); - for (auth_3d_m_object_hrc& i : m_object_hrc) - auth_3d_m_object_hrc_store(this, &i, &auth_file->m_object_hrc[m_object_hrc_index++]); - } - - if (material_list.size()) { - size_t material_list_index = 0; - auth_file->material_list.resize(material_list.size()); - for (auth_3d_material_list& i : material_list) - auth_3d_material_list_store(this, &i, &auth_file->material_list[material_list_index++]); - } - - if (motion.size()) { - size_t motion_index = 0; - auth_file->motion.resize(motion.size()); - for (std::string& i : motion) - auth_file->motion[motion_index++].assign(i); - } - - if (object.size()) { - size_t object_index = 0; - auth_file->object.resize(object.size()); - for (auth_3d_object& i : object) - auth_3d_object_store(this, &i, &auth_file->object[object_index++]); - } - - if (object_hrc.size()) { - size_t object_hrc_index = 0; - auth_file->object_hrc.resize(object_hrc.size()); - for (auth_3d_object_hrc& i : object_hrc) - auth_3d_object_hrc_store(this, &i, &auth_file->object_hrc[object_hrc_index++]); - } - - if (point.size()) { - size_t point_index = 0; - auth_file->point.resize(point.size()); - for (auth_3d_point& i : point) - auth_3d_point_store(this, &i, &auth_file->point[point_index++]); - } - - if (m_object_hrc_list.size()) { - size_t m_object_hrc_list_index = 0; - auth_file->m_object_hrc_list.resize(m_object_hrc_list.size()); - for (auth_3d_m_object_hrc*& i : m_object_hrc_list) - auth_file->m_object_hrc_list[m_object_hrc_list_index++].assign(i->name); - } - - if (object_list.size()) { - size_t object_list_index = 0; - auth_file->object_list.resize(object_list.size()); - for (auth_3d_object*& i : object_list) - auth_file->object_list[object_list_index++].assign(i->name); - } - - if (object_hrc_list.size()) { - size_t object_hrc_list_index = 0; - auth_file->object_hrc_list.resize(object_hrc_list.size()); - for (auth_3d_object_hrc*& i : object_hrc_list) - auth_file->object_hrc_list[object_hrc_list_index++].assign(i->name); - } -} - -void auth_3d::unload(render_context* rctx) { - auth_3d_camera_auxiliary_restore_prev_value(&camera_auxiliary, rctx); - for (auth_3d_light& i : light) - auth_3d_light_restore_prev_value(&i, rctx); - for (auth_3d_fog& i : fog) - auth_3d_fog_restore_prev_value(&i, rctx); - auth_3d_dof_restore_prev_value(&dof, rctx); - auth_3d_post_process_restore_prev_value(&post_process, rctx); - - if (state) - if (hash == hash_murmurhash_empty) { - data_struct* aft_data = &data_list[DATA_AFT]; - auth_3d_database* aft_auth_3d_db = &aft_data->data_ft.auth_3d_db; - - if (aft_auth_3d_db->uid[uid].enabled) { - auth_3d_uid_file* uid_file = &auth_3d_data->uid_files[uid]; - if (uid_file->uid == uid) - auth_3d_uid_file_unload(uid_file); - } - } - else { - auto elem = auth_3d_data->uid_files_modern.find(hash); - if (elem == auth_3d_data->uid_files_modern.end()) - return; - - auth_3d_uid_file_modern* uid_file = &elem->second; - if (uid_file->hash == hash) - auth_3d_uid_file_modern_unload(uid_file); - } - reset(); -} - namespace a3d { EventListener::EventListener() { @@ -1056,223 +90,1779 @@ namespace a3d { } - void EventAdapter::OnLoad(::auth_3d_id& id) { + void EventAdapter::loadFinished(auth_3d_detail::Handle& in_handle) { } - void EventAdapter::OnCtrl(::auth_3d_id& id) { + void EventAdapter::playStart(auth_3d_detail::Handle& in_handle) { } - void EventAdapter::OnEnded(::auth_3d_id& id) { + void EventAdapter::playFinished(auth_3d_detail::Handle& in_handle) { } - void EventAdapter::OnPostCtrl(::auth_3d_id& id) { + void EventAdapter::playLoopJumpAfter(auth_3d_detail::Handle& in_handle) { } - void EventAdapter::OnRepeat(::auth_3d_id& id) { + void EventAdapter::playLoopJumpBefore(auth_3d_detail::Handle& in_handle) { } } namespace auth_3d_detail { - Event::Event(a3da_event* e) { - active = false; - switch (e->type) { - case A3DA_EVENT_MISC: - default: - type = Event::Type::MISC; - case A3DA_EVENT_FILT: - type = Event::Type::FILT; - case A3DA_EVENT_FX: - type = Event::Type::FX; - case A3DA_EVENT_SND: - type = Event::Type::SND; - case A3DA_EVENT_MOT: - type = Event::Type::MOT; - case A3DA_EVENT_A2D: - type = Event::Type::A2D; - } - name.assign(e->name); - begin = e->begin; - end = e->end; - param1.assign(e->param1); - ref.assign(e->ref); - index = -1; + // 0x1401AF2F0 + const Fcurve::KeyData* Fcurve::KeyData::next() const { + return this + 1; } + // Missing + Fcurve::KeyData* Fcurve::KeyData::next() { + return this + 1; + } + + // 0x1401AF360 + const Fcurve::KeyData* Fcurve::KeyData::prev() const { + return this - 1; + } + + // Missing + Fcurve::KeyData* Fcurve::KeyData::prev() { + return this - 1; + } + + // 0x1401C1DF0 + float_t Fcurve::KeyData::S_calc(FC_TYPE in_type, float_t in_frame, + const Fcurve::KeyData* curr_key, const Fcurve::KeyData* next_key) { + switch (in_type) { + case FC_TYPE_LINEAR: + if (curr_key->frame < next_key->frame) + return interpolate_linear_value(curr_key->value, next_key->value, + curr_key->frame, next_key->frame, in_frame); + else + return curr_key->value; + case FC_TYPE_HERMITE: + if (curr_key->frame < next_key->frame) + return interpolate_chs_value(curr_key->value, next_key->value, + curr_key->r_slope, next_key->l_slope, + curr_key->frame, next_key->frame, in_frame); + else + return curr_key->value; + case FC_TYPE_NO_INTERPOLATION: + if (in_frame >= next_key->frame) + return next_key->value; + else + return curr_key->value; + default: + return 0.0f; + } + } + + // 0x1401BF960 + void Fcurve::M_init() { + m_max_frame = 0.0f; + m_ep_type_pre = EP_TYPE_CONSTANT; + m_ep_type_post = EP_TYPE_CONSTANT; + m_frame_delta = 0.0f; + m_value_delta = 0.0f; + m_key_data_list.clear(); + m_key_data_list.shrink_to_fit(); + m_key_data_size = 0; + m_key_data_ptr = 0; + + m_frame = 0.0f; + m_value = 0.0f; + } + + // 0x1401BF870 + float_t Fcurve::M_get(float_t in_frame) const { + const KeyData* first_key = m_key_data_ptr; + const KeyData* next_key = find_key_data(in_frame); + + if (next_key == first_key) + return first_key->value; + + const KeyData* prev_key = next_key->prev(); + if (next_key == &first_key[m_key_data_size]) + return prev_key->value; + + return KeyData::S_calc(m_type, in_frame, prev_key, next_key); + } + + // 0x1401C1B00 + void Fcurve::M_set_ep_type(EP_TYPE in_ep_type_pre, EP_TYPE in_ep_type_post) { + m_ep_type_pre = EP_TYPE_CONSTANT; + m_ep_type_post = EP_TYPE_CONSTANT; + m_frame_delta = m_max_frame; + m_value_delta = 0.0f; + + if (m_key_data_size) { + const KeyData* first_key = &m_key_data_ptr[0]; + const KeyData* last_key = &m_key_data_ptr[m_key_data_size - 1]; + if (first_key->frame < last_key->frame + && check_ep_range(0.0f, m_max_frame, first_key->frame, last_key->frame)) { + m_ep_type_pre = in_ep_type_pre; + m_ep_type_post = in_ep_type_post; + m_frame_delta = last_key->frame - first_key->frame; + m_value_delta = last_key->value - first_key->value; + } + } + } + + // 0x1401B3E60 + Fcurve::Fcurve() : m_type(), m_static_value(), m_max_frame(), + m_ep_type_pre(), m_ep_type_post(), m_frame_delta(), m_value_delta(), + m_key_data_list(), m_key_data_size(), m_key_data_ptr(), m_frame(), m_value() { + + } + + // Missing + Fcurve::Fcurve(float_t in_value) : m_type(FC_TYPE_STATIC_DATA), m_static_value(in_value), + m_max_frame(), m_ep_type_pre(), m_ep_type_post(), m_frame_delta(), m_value_delta(), + m_key_data_list(), m_key_data_size(), m_key_data_ptr(), m_frame(), m_value() { + + } + + // 0x1401B3DF0 + Fcurve::Fcurve(const Fcurve& other) : m_type(other.m_type), m_static_value(other.m_static_value), + m_max_frame(other.m_max_frame), m_ep_type_pre(other.m_ep_type_pre), m_ep_type_post(other.m_ep_type_post), + m_frame_delta(other.m_frame_delta), m_value_delta(other.m_value_delta), + m_key_data_list(other.m_key_data_list), m_key_data_size(other.m_key_data_size), + m_key_data_ptr(other.m_key_data_ptr), m_frame(other.m_frame), m_value(other.m_value) { + + } + + // Missing + Fcurve::~Fcurve() { + + } + + // 0x1401D6F80 + void Fcurve::init() { + m_type = FC_TYPE_STATIC_0; + m_static_value = 0.0f; + M_init(); + } + + // 0x1401D6F20 + void Fcurve::init(float_t in_value) { + m_type = FC_TYPE_STATIC_DATA; + m_static_value = in_value; + M_init(); + } + + // 0x1401D4230 + float_t Fcurve::get(float_t in_frame) { + if (m_type == FC_TYPE_STATIC_DATA) + return m_static_value; + else if (m_type < FC_TYPE_STATIC_DATA + || m_type > FC_TYPE_NO_INTERPOLATION || !m_key_data_size) + return 0.0f; + + const KeyData* first_key = &m_key_data_ptr[0]; + const KeyData* last_key = &m_key_data_ptr[m_key_data_size - 1]; + float_t first_frame = first_key->frame; + float_t last_frame = last_key->frame; + + float_t offset = 0.0f; + float_t frame = in_frame; + if (frame < first_frame) { + float_t delta_frame = first_frame - frame; + switch (m_ep_type_pre) { + case a3d::EP_TYPE_CONSTANT: + default: + m_frame = frame; + m_value = first_key->value; + return m_value; + case a3d::EP_TYPE_LINEAR: + m_frame = frame; + m_value = first_key->value + delta_frame * first_key->l_slope; + return m_value; + case a3d::EP_TYPE_CYCLE: + frame = last_frame - fmodf(delta_frame, m_frame_delta); + break; + case a3d::EP_TYPE_CYCLE_WITH_OFFSET: + offset = (prj::truncf(delta_frame / m_frame_delta) + 1.0f) * m_value_delta; + frame = last_frame - fmodf(delta_frame, m_frame_delta); + break; + } + } + else if (frame >= last_frame) { + float_t delta_frame = frame - last_frame; + switch (m_ep_type_post) { + case a3d::EP_TYPE_CONSTANT: + default: + m_frame = frame; + m_value = last_key->value; + return m_value; + case a3d::EP_TYPE_LINEAR: + m_frame = frame; + m_value = last_key->value - delta_frame * last_key->r_slope; + return m_value; + case a3d::EP_TYPE_CYCLE: + frame = first_frame + fmodf(delta_frame, m_frame_delta); + break; + case a3d::EP_TYPE_CYCLE_WITH_OFFSET: + offset = (prj::truncf(delta_frame / m_frame_delta) + 1.0f) * m_value_delta; + frame = first_frame + fmodf(delta_frame, m_frame_delta); + break; + } + } + + m_frame = frame; + m_value = M_get(frame) + offset; + return m_value; + } + + // Missing + float_t Fcurve::operator()(float_t in_frame) { + return get(in_frame); + } + + // 0x1401D3AB0 + const Fcurve::KeyData* Fcurve::find_key_data(float_t in_frame) const { + return std::upper_bound(m_key_data_ptr, m_key_data_ptr + m_key_data_size, + in_frame, [](float_t in_frame, const KeyData& key) { + return in_frame < key.frame; + }); + } + + // Missing + float_t Fcurve::get_size() const { + return m_max_frame; + } + + // 0x1401CBFF0 + bool Fcurve::check_discontinuity(float_t in_frame) const { + if (m_type < FC_TYPE_LINEAR || m_type > FC_TYPE_NO_INTERPOLATION) + return false; + + const float_t frame = clamp_def(in_frame, 0.0f, m_max_frame); + if (!m_key_data_size) + return false; + + const KeyData* key = find_key_data(frame); + if (key == m_key_data_ptr || key == &m_key_data_ptr[m_key_data_size]) + return false; + + return key->frame - key->prev()->frame < 2.0f; + } + + // 0x1401CC540 + bool Fcurve::check_threshold_discontinuity(float_t in_frame, float_t in_threshold) const { + if (m_type < FC_TYPE_LINEAR || m_type > FC_TYPE_NO_INTERPOLATION) + return false; + + const float_t frame = clamp_def(in_frame, 0.0f, m_max_frame); + if (!m_key_data_size) + return false; + + const KeyData* keys = m_key_data_ptr; + const KeyData* keys_end = &keys[m_key_data_size]; + const KeyData* key = find_key_data(frame); + if (key == keys || key == keys_end || key == keys->next()) + return false; + + const KeyData* next_key = key->next(); + if (next_key == keys_end) + return false; + + const KeyData* prev_key = key->prev(); + + const float_t frame_diff = key->frame - prev_key->frame; + if (frame_diff >= 2.0f || frame_diff <= 0.0f) + return false; + + if (fabsf(key->value - prev_key->value) <= in_threshold) + return false; + + const KeyData* prev2_key = prev_key->prev(); + while (prev_key->frame <= prev2_key->frame) + if (prev2_key == keys) + return false; + else + prev2_key = prev2_key->prev(); + + const KeyData* next_key_1 = next_key; + while (key->frame >= next_key->frame) + next_key_1 = next_key; + + // Intentional! Should be (V2 - V1) / (F2 - F1), but first parenthesis is missing + const float_t center_slope = key->value - prev_key->value / frame_diff; + + float_t left_slope; + float_t right_slope; + if (m_type != FC_TYPE_HERMITE) { + left_slope = (prev_key->value - prev2_key->value) / (prev_key->frame - prev2_key->frame); + right_slope = (next_key_1->value - key->value) / (next_key_1->frame - key->frame); + } + else { + if ((prev_key->frame - prev2_key->frame) >= 2.0f) { + float_t value; + if (prev2_key->frame < prev_key->frame) + value = interpolate_chs_value( + prev2_key->value, prev_key->value, prev2_key->r_slope, prev_key->l_slope, + prev_key->frame, prev2_key->frame, prev_key->frame - 1.0f); + else + value = prev2_key->value; + left_slope = prev_key->value - value; + } + else + left_slope = (prev_key->value - prev2_key->value) / (prev_key->frame - prev2_key->frame); + + if (next_key_1->frame - key->frame >= 2.0f) { + float_t value; + if (key->frame < next_key_1->frame) + value = interpolate_chs_value( + key->value, next_key_1->value, key->r_slope, next_key_1->l_slope, + key->frame, next_key_1->frame, key->frame + 1.0f); + else + value = key->value; + right_slope = value - key->value; + } + else + right_slope = (next_key_1->value - key->value) / (next_key_1->frame - key->frame); + } + + const float_t left_dot = left_slope * center_slope; + const float_t right_dot = right_slope * center_slope; + + const float_t abs_left_slope = fabsf(left_slope); + const float_t abs_center_slope = fabsf(center_slope); + const float_t abs_right_slope = fabsf(right_slope); + + bool left_small = abs_left_slope < abs_center_slope && abs_left_slope <= in_threshold; + bool right_small = abs_right_slope < abs_center_slope && abs_right_slope <= in_threshold; + return (left_dot <= 0.0f || left_small) + && (right_dot <= 0.0f || right_small); + } + + // 0x1401DB1A0 + bool Fcurve::load(const SceneFile& in_file, const a3d::Fcurve& in_fcv) { + m_max_frame = in_file.frame_max; + m_frame_delta = m_max_frame; + m_value_delta = 0.0f; + + switch (in_fcv.type) { + case a3d::FC_TYPE_STATIC_0: + m_type = FC_TYPE_STATIC_0; + m_static_value = 0.0f; + return true; + case a3d::FC_TYPE_STATIC_DATA: + m_type = in_fcv.value != 0.0f ? FC_TYPE_STATIC_DATA : FC_TYPE_STATIC_0; + m_static_value = in_fcv.value; + return true; + case a3d::FC_TYPE_LINEAR: + m_type = FC_TYPE_LINEAR; + break; + case a3d::FC_TYPE_HERMITE: + default: + m_type = FC_TYPE_HERMITE; + break; + case a3d::FC_TYPE_NO_INTERPOLATION: + m_type = FC_TYPE_NO_INTERPOLATION; + break; + } + + size_t key_data_size = in_fcv.keys.size(); + if (key_data_size > 1) { + m_key_data_list.assign(in_fcv.keys.begin(), in_fcv.keys.end()); + m_key_data_size = key_data_size; + m_key_data_ptr = m_key_data_list.data(); + + M_set_ep_type((EP_TYPE)in_fcv.ep_type_pre, (EP_TYPE)in_fcv.ep_type_post); + } + else if (key_data_size == 1) { + float_t value = in_fcv.keys.front().value; + m_type = value != 0.0f ? FC_TYPE_STATIC_DATA : FC_TYPE_STATIC_0; + m_static_value = value; + } + else { + m_type = FC_TYPE_STATIC_0; + m_static_value = 0.0f; + } + return true; + } + + // Added + void Fcurve::store(const SceneFile& in_file, a3d::Fcurve& out_fcv) const { + out_fcv.max_frame = in_file.frame_max; + + switch (m_type) { + case FC_TYPE_STATIC_0: + out_fcv.type = a3d::FC_TYPE_STATIC_0; + out_fcv.value = 0.0f; + return; + case FC_TYPE_STATIC_DATA: + out_fcv.type = m_static_value != 0.0f ? a3d::FC_TYPE_STATIC_DATA : a3d::FC_TYPE_STATIC_0; + out_fcv.value = m_static_value; + return; + case FC_TYPE_LINEAR: + out_fcv.type = a3d::FC_TYPE_LINEAR; + break; + case FC_TYPE_HERMITE: + default: + out_fcv.type = a3d::FC_TYPE_HERMITE; + break; + case FC_TYPE_NO_INTERPOLATION: + out_fcv.type = a3d::FC_TYPE_NO_INTERPOLATION; + break; + } + + size_t key_data_size = m_key_data_list.size(); + if (key_data_size > 1) { + out_fcv.keys.assign(m_key_data_list.begin(), m_key_data_list.end()); + + const KeyData* first_key = &m_key_data_ptr[0]; + const KeyData* last_key = &m_key_data_ptr[key_data_size - 1]; + if (first_key->frame < last_key->frame + && check_ep_range(0.0f, m_max_frame, first_key->frame, last_key->frame)) { + out_fcv.ep_type_pre = (a3d::EP_TYPE)m_ep_type_pre; + out_fcv.ep_type_post = (a3d::EP_TYPE)m_ep_type_post; + } + } + else if (key_data_size == 1) { + float_t value = m_key_data_list.front().value; + out_fcv.type = value != 0.0f ? a3d::FC_TYPE_STATIC_DATA : a3d::FC_TYPE_STATIC_0; + out_fcv.value = value; + } + else { + out_fcv.type = a3d::FC_TYPE_STATIC_0; + out_fcv.value = 0.0f; + } + } + + // 0x1401BBAB0 + Fcurve& Fcurve::operator=(const Fcurve& other) { + m_type = other.m_type; + m_static_value = other.m_static_value; + m_max_frame = other.m_max_frame; + m_ep_type_pre = other.m_ep_type_pre; + m_ep_type_post = other.m_ep_type_post; + m_frame_delta = other.m_frame_delta; + m_value_delta = other.m_value_delta; + m_key_data_list.assign(other.m_key_data_list.begin(), other.m_key_data_list.end()); + m_key_data_size = other.m_key_data_size; + m_key_data_ptr = m_key_data_list.data(); + return *this; + } + + // 0x1401AF540 + bool Fcurve::check_ep_range(float_t in_frame_begin, float_t in_frame_end, + float_t in_key_frame_begin, float_t in_key_frame_end) { + return in_key_frame_end > in_frame_begin && in_frame_end > in_key_frame_begin; + } + + // 0x1401B3D60 + Fcurve3f::Fcurve3f() : x(), y(), z() { + + } + + // Missing + Fcurve3f::Fcurve3f(float_t in_value) : x(in_value), y(in_value), z(in_value) { + + } + + // 0x1401B3C10 + Fcurve3f::Fcurve3f(const Fcurve3f& other) : x(other.x), y(other.y), z(other.z) { + + } + + // 0x1401B8850 + Fcurve3f::~Fcurve3f() { + + } + + // 0x1401D6E20 + void Fcurve3f::init() { + x.init(); + y.init(); + z.init(); + } + + // 0x1401D6D00 + void Fcurve3f::init(float_t in_value) { + x.init(in_value); + y.init(in_value); + z.init(in_value); + } + + // 0x1401D41B0 + vec3 Fcurve3f::get(float_t in_frame) { + vec3 value; + value.x = x.get(in_frame); + value.y = y.get(in_frame); + value.z = z.get(in_frame); + return value; + } + + // 0x1401DB050 + bool Fcurve3f::load(const SceneFile& in_file, const a3d::Fcurve3f& in_fcv3f) { + x.load(in_file, in_fcv3f.x); + y.load(in_file, in_fcv3f.y); + z.load(in_file, in_fcv3f.z); + return true; + } + + // Added + void Fcurve3f::store(const SceneFile& in_file, a3d::Fcurve3f& out_fcv3f) const { + x.store(in_file, out_fcv3f.x); + y.store(in_file, out_fcv3f.y); + z.store(in_file, out_fcv3f.z); + } + + // 0x1401BB970 + Fcurve3f& Fcurve3f::operator=(const Fcurve3f& other) { + x = other.x; + y = other.y; + z = other.z; + return *this; + } + + // 0x1401B4090 + FcurveColor4f::FcurveColor4f() : r(), g(), b(), a(), has_r(), has_g(), has_b(), has_a() { + + } + + // 0x1401B3E90 + FcurveColor4f::FcurveColor4f(const FcurveColor4f& other) : r(other.r), g(other.g), b(other.b), a(other.a), + has_r(other.has_r), has_g(other.has_g), has_b(other.has_g), has_a(other.has_g) { + + } + + // 0x1401B8900 + FcurveColor4f::~FcurveColor4f() { + + } + + // 0x1401D6FE0 + void FcurveColor4f::init() { + r.init(); + g.init(); + b.init(); + a.init(); + + has_r = false; + has_g = false; + has_b = false; + has_a = false; + } + + // 0x1401D4450 + vec4 FcurveColor4f::get(float_t in_frame) { + vec4 value; + value.x = r.get(in_frame); + value.y = g.get(in_frame); + value.z = b.get(in_frame); + value.w = a.get(in_frame); + return value; + } + + // 0x1401DB520 + bool FcurveColor4f::load(const SceneFile& in_file, const a3d::FcurveColor4f& in_fcv_col4f) { + if (in_fcv_col4f.has_r) { + r.load(in_file, in_fcv_col4f.r); + has_r = true; + } + + if (in_fcv_col4f.has_g) { + g.load(in_file, in_fcv_col4f.g); + has_g = true; + } + + if (in_fcv_col4f.has_b) { + b.load(in_file, in_fcv_col4f.b); + has_b = true; + } + + if (in_fcv_col4f.has_a) { + a.load(in_file, in_fcv_col4f.a); + has_a = true; + } + return has_r || has_g || has_b || has_a; + } + + // Added + void FcurveColor4f::store(const SceneFile& in_file, a3d::FcurveColor4f& out_fcv_col4f) const { + if (has_r) { + r.store(in_file, out_fcv_col4f.r); + out_fcv_col4f.has_r = true; + } + + if (has_g) { + g.store(in_file, out_fcv_col4f.g); + out_fcv_col4f.has_g = true; + } + + if (has_b) { + b.store(in_file, out_fcv_col4f.b); + out_fcv_col4f.has_b = true; + } + + if (has_a) { + a.store(in_file, out_fcv_col4f.a); + out_fcv_col4f.has_a = true; + } + } + + // 0x1401BBB20 + FcurveColor4f& FcurveColor4f::operator=(const FcurveColor4f& other) { + r = other.r; + g = other.g; + b = other.b; + a = other.a; + + has_r = other.has_r; + has_g = other.has_g; + has_b = other.has_b; + has_a = other.has_a; + return *this; + } + + // 0x1401B30B0 + Color::Color() : fcurve_color(), color(), has_color() { + + } + + // 0x1401B3050 + Color::Color(const Color& other) : fcurve_color(other.fcurve_color), color(other.color) { + has_color[0] = other.has_color[0]; + has_color[1] = other.has_color[1]; + has_color[2] = other.has_color[2]; + has_color[3] = other.has_color[3]; + } + + // 0x1401B85A0 + Color::~Color() { + init(); + } + + /// 0x1401D6CA0 + void Color::init() { + fcurve_color.init(); + + has_color[0] = true; + has_color[1] = true; + has_color[2] = true; + has_color[3] = true; + } + + // 0x1401D4070 + void Color::get(float_t in_frame) { + color = fcurve_color.get(in_frame); + + has_color[0] = fcurve_color.has_r; + has_color[1] = fcurve_color.has_b; // TYPO! + has_color[2] = fcurve_color.has_g; // TYPO! + has_color[3] = fcurve_color.has_a; + } + + // 0x1401DA200 + bool Color::load(const SceneFile& in_file, const a3d::FcurveColor4f& in_fcv_col4f) { + fcurve_color.load(in_file, in_fcv_col4f); + return true; + } + + // Added + void Color::store(const SceneFile& in_file, a3d::FcurveColor4f& out_fcv_col4f) const { + fcurve_color.store(in_file, out_fcv_col4f); + } + + // 0x1401BB740 + Color& Color::operator=(const Color& other) { + fcurve_color = other.fcurve_color; + color = other.color; + has_color[0] = other.has_color[0]; + has_color[1] = other.has_color[1]; + has_color[2] = other.has_color[2]; + has_color[3] = other.has_color[3]; + return *this; + } + + // 0x1401B4E10 + ModelTransform::ModelTransform() : matrix(), fcurve_scale(), fcurve_rotation(), + fcurve_translation(), fcurve_visibility(), scale(), rotation(), translation(), visibility() { + + } + + // 0x1401B4C50 + ModelTransform::ModelTransform(const ModelTransform& other) : matrix(other.matrix), + fcurve_scale(other.fcurve_scale), fcurve_rotation(other.fcurve_rotation), + fcurve_translation(other.fcurve_translation), fcurve_visibility(other.fcurve_visibility), + scale(other.scale), rotation(other.rotation), translation(other.translation), visibility(other.visibility) { + + } + + // 0x1401B8D50 + ModelTransform::~ModelTransform() { + + } + + // 0x1401D74B0 + void ModelTransform::init() { + matrix = mat4_identity; + + fcurve_scale.init(); + fcurve_rotation.init(); + fcurve_translation.init(); + fcurve_visibility.init(); + + scale = 0.0f; + rotation = 0.0f; + translation = 0.0f; + visibility = false; + } + + // 0x1401D8840 + void ModelTransform::init_static() { + matrix = mat4_identity; + + fcurve_scale.init(1.0f); + fcurve_rotation.init(0.0f); + fcurve_translation.init(0.0f); + fcurve_visibility.init(1.0f); + + scale = 1.0f; + rotation = 0.0f; + translation = 0.0f; + visibility = true; + } + + // 0x1401D4680 + void ModelTransform::get(float_t in_frame) { + scale = fcurve_scale.get(in_frame); + rotation = fcurve_rotation.get(in_frame); + translation = fcurve_translation.get(in_frame); + visibility = fcurve_visibility.get(in_frame) >= 0.999f; + if (visibility && (scale.x == 0.0f || scale.y == 0.0f || scale.z == 0.0f)) + visibility = false; + } + + // 0x1401E1CB0 + const mat4& ModelTransform::mul(const mat4& in_base_mat) { + matrix = in_base_mat; + mat4_mul_translate(&matrix, &translation, &matrix); + mat4_mul_rotate_zyx(&matrix, &rotation, &matrix); + mat4_scale_rot(&matrix, &scale, &matrix); + return matrix; + } + + // Inlined + inline const mat4& ModelTransform::get_matrix() { + return matrix; + } + + // 0x1401DCFB0 + bool ModelTransform::load(const SceneFile& in_file, const a3d::ModelTransform& in_mt) { + fcurve_rotation.load(in_file, in_mt.rotation); + fcurve_scale.load(in_file, in_mt.scale); + fcurve_translation.load(in_file, in_mt.translation); + fcurve_visibility.load(in_file, in_mt.visibility); + return true; + } + + // Added + void ModelTransform::store(const SceneFile& in_file, a3d::ModelTransform& out_mt) const { + fcurve_rotation.store(in_file, out_mt.rotation); + fcurve_scale.store(in_file, out_mt.scale); + fcurve_translation.store(in_file, out_mt.translation); + fcurve_visibility.store(in_file, out_mt.visibility); + } + + // 0x1401BC1F0 + ModelTransform& ModelTransform::operator=(const ModelTransform& other) { + matrix = other.matrix; + + fcurve_scale = other.fcurve_scale; + fcurve_rotation = other.fcurve_rotation; + fcurve_translation = other.fcurve_translation; + fcurve_visibility = other.fcurve_visibility; + + scale = other.scale; + rotation = other.rotation; + translation = other.translation; + visibility = other.visibility; + return *this; + } + + // MGF + Ambient::Ambient() : flag(), name(), light_diffuse(), rim_light_diffuse() { + + } + + // MGF + Ambient::Ambient(const Ambient& other) : flag(other.flag), name(other.name), + light_diffuse(other.light_diffuse), rim_light_diffuse(other.rim_light_diffuse) { + + } + + // MGF + Ambient::~Ambient() { + + } + + // MGF + void Ambient::init() { + flag = 0; + name.clear(); + name.shrink_to_fit(); + light_diffuse.init(); + rim_light_diffuse.init(); + } + + // MGF + void Ambient::get(float_t in_frame) { + if (has_light_diffuse()) + light_diffuse.get(in_frame); + + if (has_rim_light_diffuse()) + rim_light_diffuse.get(in_frame); + } + + // MGF + void Ambient::ctrl(render_context* rctx) { + + } + + // MGF + bool Ambient::load(const SceneFile& in_file, const a3d::Ambient& in_a) { + name.assign(in_a.name); + + if (in_a.flag & a3d::Ambient::FLAG_LIGHT_DIFFUSE) { + light_diffuse.load(in_file, in_a.light_diffuse); + flag |= FLAG_LIGHT_DIFFUSE; + } + + if (in_a.flag & a3d::Ambient::FLAG_RIM_LIGHT_DIFFUSE) { + rim_light_diffuse.load(in_file, in_a.rim_light_diffuse); + flag |= FLAG_RIM_LIGHT_DIFFUSE; + } + return true; + } + + // MGF, Added + void Ambient::store(const SceneFile& in_file, a3d::Ambient& out_a) const { + out_a.name.assign(name); + + if (flag & FLAG_LIGHT_DIFFUSE) { + light_diffuse.store(in_file, out_a.light_diffuse); + out_a.flag |= a3d::Ambient::FLAG_LIGHT_DIFFUSE; + } + + if (flag & FLAG_RIM_LIGHT_DIFFUSE) { + rim_light_diffuse.store(in_file, out_a.rim_light_diffuse); + out_a.flag |= a3d::Ambient::FLAG_RIM_LIGHT_DIFFUSE; + } + } + + // MGF + Ambient& Ambient::operator=(const Ambient& other) { + flag = other.flag; + name.assign(other.name); + light_diffuse = other.light_diffuse; + rim_light_diffuse = other.rim_light_diffuse; + return *this; + } + + // 0x1401B2790 + Auth2d::Auth2d() : name() { + + } + + // 0x1401B2750 + Auth2d::Auth2d(const Auth2d& other) : name(other.name) { + + } + + // 0x1401B7D80 + Auth2d::~Auth2d() { + + } + + // 0x1401D9960 + bool Auth2d::load(const SceneFile& in_file, const a3d::Auth2d& in_a2) { + name.assign(in_a2.name); + + if (!name.find("S_ADVPR0")) + name[7] = 'O'; + return true; + } + + // Added + void Auth2d::store(const SceneFile& in_file, a3d::Auth2d& out_a2) const { + out_a2.name.assign(name); + } + + // 0x1401BB350 + Auth2d& Auth2d::operator=(const Auth2d& other) { + name.assign(other.name); + return *this; + } + + // 0x1401B28C0 + CameraAuxiliary::CameraAuxiliary() : flag(), fcurve_exposure(), fcurve_exposure_rate(), + fcurve_gamma(), fcurve_gamma_rate(), fcurve_saturate(), fcurve_auto_exposure(), exposure(2.0f), + exposure_rate(1.0f), gamma(1.0f), gamma_rate(1.0f), saturate(1.0f), auto_exposure(1.0f) { + + } + + // Missing + CameraAuxiliary::CameraAuxiliary(const CameraAuxiliary& other) : flag(other.flag), + fcurve_exposure(other.fcurve_exposure), fcurve_exposure_rate(other.fcurve_exposure_rate), + fcurve_gamma(other.fcurve_gamma), fcurve_gamma_rate(other.fcurve_gamma_rate), + fcurve_saturate(other.fcurve_saturate), fcurve_auto_exposure(other.fcurve_auto_exposure), + exposure(other.exposure), exposure_rate(other.exposure_rate), gamma(other.gamma), + gamma_rate(other.gamma_rate), saturate(other.saturate), auto_exposure(other.auto_exposure) { + + } + + // 0x1401B8140 + CameraAuxiliary::~CameraAuxiliary() { + + } + + // 0x1401D69D0 + void CameraAuxiliary::init() { + flag = 0; + fcurve_exposure.init(); + fcurve_exposure_rate.init(); // F/F2/X/XHD + fcurve_gamma.init(); + fcurve_gamma_rate.init(); // F/F2/X/XHD + fcurve_saturate.init(); + fcurve_auto_exposure.init(); + } + + // 0x1401D3BD0 + void CameraAuxiliary::get(float_t in_frame) { + if (has_exposure()) + exposure = fcurve_exposure.get(in_frame); + if (has_exposure_rate()) // F/F2/X/XHD + exposure_rate = fcurve_exposure_rate.get(in_frame); + if (has_gamma()) + gamma = fcurve_gamma.get(in_frame); + if (has_gamma_rate()) // F/F2/X/XHD + gamma_rate = fcurve_gamma_rate.get(in_frame); + if (has_saturate()) + saturate = fcurve_saturate.get(in_frame); + if (has_auto_exposure()) + auto_exposure = fcurve_auto_exposure.get(in_frame); + } + + // 0x1401CE3E0 + void CameraAuxiliary::ctrl(Scene& in_scene, render_context* rctx) { + if (has_exposure()) + rctx->render.set_exposure(exposure); + if (has_gamma()) + rctx->render.set_gamma(gamma); + if (has_saturate()) + rctx->render.set_saturate_coeff(saturate, 0, false); + if (has_auto_exposure()) + rctx->render.set_auto_exposure(auto_exposure > 0.0f); + } + + // 0x1401CFDE0 + void CameraAuxiliary::dest(render_context* rctx) { + if (has_exposure()) + rctx->render.set_exposure(2.0f); + if (has_gamma()) + rctx->render.set_gamma(1.0f); + if (has_saturate()) + rctx->render.set_saturate_coeff(1.0f, 0, false); + if (has_auto_exposure()) + rctx->render.set_auto_exposure(true); + + init(); + } + + // 0x1401D9A60 + bool CameraAuxiliary::load(const SceneFile& in_file, const a3d::CameraAuxiliary& in_ca) { + if (in_ca.flag & a3d::CameraAuxiliary::FLAG_EXPOSURE) { + fcurve_exposure.load(in_file, in_ca.exposure); + flag |= FLAG_EXPOSURE; + } + + // F/F2/X/XHD + if (in_ca.flag & a3d::CameraAuxiliary::FLAG_EXPOSURE_RATE) { + fcurve_exposure_rate.load(in_file, in_ca.exposure_rate); + flag |= FLAG_EXPOSURE_RATE; + } + + if (in_ca.flag & a3d::CameraAuxiliary::FLAG_GAMMA) { + fcurve_gamma.load(in_file, in_ca.gamma); + flag |= FLAG_GAMMA; + } + + // F/F2/X/XHD + if (in_ca.flag & a3d::CameraAuxiliary::FLAG_GAMMA_RATE) { + fcurve_gamma_rate.load(in_file, in_ca.gamma_rate); + flag |= FLAG_GAMMA_RATE; + } + + if (in_ca.flag & a3d::CameraAuxiliary::FLAG_SATURATE) { + fcurve_saturate.load(in_file, in_ca.saturate); + flag |= FLAG_SATURATE; + } + + if (in_ca.flag & a3d::CameraAuxiliary::FLAG_AUTO_EXPOSURE) { + fcurve_auto_exposure.load(in_file, in_ca.auto_exposure); + flag |= FLAG_AUTO_EXPOSURE; + } + return true; + } + + // Added + void CameraAuxiliary::store(const SceneFile& in_file, a3d::CameraAuxiliary& out_ca) const { + if (flag & FLAG_EXPOSURE) { + fcurve_exposure.store(in_file, out_ca.exposure); + out_ca.flag |= a3d::CameraAuxiliary::FLAG_EXPOSURE; + } + + // F/F2/X/XHD + if (flag & FLAG_EXPOSURE_RATE) { + fcurve_exposure_rate.store(in_file, out_ca.exposure_rate); + out_ca.flag |= a3d::CameraAuxiliary::FLAG_EXPOSURE_RATE; + } + + if (flag & FLAG_GAMMA) { + fcurve_gamma.store(in_file, out_ca.gamma); + out_ca.flag |= a3d::CameraAuxiliary::FLAG_GAMMA; + } + + // F/F2/X/XHD + if (flag & FLAG_GAMMA_RATE) { + fcurve_gamma_rate.store(in_file, out_ca.gamma_rate); + out_ca.flag |= a3d::CameraAuxiliary::FLAG_GAMMA_RATE; + } + + if (flag & FLAG_SATURATE) { + fcurve_saturate.store(in_file, out_ca.saturate); + out_ca.flag |= a3d::CameraAuxiliary::FLAG_SATURATE; + } + + if (flag & FLAG_AUTO_EXPOSURE) { + fcurve_auto_exposure.store(in_file, out_ca.auto_exposure); + out_ca.flag |= a3d::CameraAuxiliary::FLAG_AUTO_EXPOSURE; + } + } + + // Missing + CameraAuxiliary& CameraAuxiliary::operator=(const CameraAuxiliary& other) { + flag = other.flag; + fcurve_exposure = other.fcurve_exposure; + fcurve_exposure_rate = other.fcurve_exposure_rate; // F/F2/X/XHD + fcurve_gamma = other.fcurve_gamma; + fcurve_gamma_rate = other.fcurve_gamma_rate; // F/F2/X/XHD + fcurve_saturate = other.fcurve_saturate; + fcurve_auto_exposure = other.fcurve_auto_exposure; + + exposure = other.exposure; + exposure_rate = other.exposure_rate; // F/F2/X/XHD + gamma = other.gamma; + gamma_rate = other.gamma_rate; // F/F2/X/XHD + saturate = other.saturate; + auto_exposure = other.auto_exposure; + return *this; + } + + // 0x1401B29E0 + CameraInterest::CameraInterest() : model_transform() { + init(); + } + + // 0x1401B29C0 + CameraInterest::CameraInterest(const CameraInterest& other) : model_transform(other.model_transform) { + + } + + // 0x1401B81E0 + CameraInterest::~CameraInterest() { + + } + + // Inlined + inline void CameraInterest::init() { + model_transform.init(); + } + + // 0x1401D9C90 + bool CameraInterest::load(const SceneFile& in_file, const a3d::CameraInterest& in_ci) { + model_transform.load(in_file, in_ci.model_transform); + return true; + } + + // Added + void CameraInterest::store(const SceneFile& in_file, a3d::CameraInterest& out_ci) const { + model_transform.store(in_file, out_ci.model_transform); + } + + // 0x1401BB380 + CameraInterest& CameraInterest::operator=(const CameraInterest& other) { + model_transform = other.model_transform; + return *this; + } + + // 0x1401B2CA0 + CameraViewPoint::CameraViewPoint() : model_transform(), roll(), has_fov(), fov_is_horizontal(), + fov(), aspect(), focal_length(), camera_aperture_w(), camera_aperture_h() { + init(); + } + + // 0x1401B2AA0 + CameraViewPoint::CameraViewPoint(const CameraViewPoint& other) : model_transform(other.model_transform), + roll(other.roll), has_fov(other.has_fov), fov_is_horizontal(other.fov_is_horizontal), + fov(other.fov), aspect(other.aspect), focal_length(other.focal_length), + camera_aperture_w(other.camera_aperture_w), camera_aperture_h(other.camera_aperture_h) { + + } + + // 0x1401B8370 + CameraViewPoint::~CameraViewPoint() { + + } + + // 0x1401D6B30 + void CameraViewPoint::init() { + model_transform.init(); + roll.init(); + has_fov = true; + fov.init(); + fov_is_horizontal = false; + aspect = 1.667f; + focal_length.init(); + camera_aperture_w = 1.0f; + camera_aperture_h = 1.0f; + } + + // 0x1401D9D90 + bool CameraViewPoint::load(const SceneFile& in_file, const a3d::CameraViewPoint& in_cvp) { + model_transform.load(in_file, in_cvp.model_transform); + roll.load(in_file, in_cvp.roll); + + if (in_cvp.has_fov) { + has_fov = true; + fov.load(in_file, in_cvp.fov); + fov_is_horizontal = in_cvp.fov_is_horizontal; + aspect = in_cvp.aspect; + } + else { + has_fov = false; + focal_length.load(in_file, in_cvp.focal_length); + camera_aperture_w = in_cvp.camera_aperture_w; + camera_aperture_h = in_cvp.camera_aperture_h; + } + return true; + } + + // 0x1401D6380 + float_t CameraViewPoint::get_v_fov(float_t in_frame) { + if (has_fov) { + float_t fov_value = fov.get(in_frame); + if (fov_is_horizontal) + fov_value = atanf(tanf(fov_value * 0.5f) / aspect) * 2.0f; + return fov_value; + } + else { + float_t half_cam_aper_h_mm = (camera_aperture_h * 25.4f) * 0.5f; + float_t focal_lenth_value = focal_length.get(in_frame); + return atanf(half_cam_aper_h_mm / focal_lenth_value) * 2.0f; + } + } + + // Added + void CameraViewPoint::store(const SceneFile& in_file, a3d::CameraViewPoint& out_cvp) const { + model_transform.store(in_file, out_cvp.model_transform); + roll.store(in_file, out_cvp.roll); + + if (has_fov) { + out_cvp.has_fov = true; + fov.store(in_file, out_cvp.fov); + out_cvp.fov_is_horizontal = fov_is_horizontal; + out_cvp.aspect = aspect; + } + else { + focal_length.store(in_file, out_cvp.focal_length); + out_cvp.camera_aperture_w = camera_aperture_w; + out_cvp.camera_aperture_h = camera_aperture_h; + } + } + + // 0x1401BB3F0 + CameraViewPoint& CameraViewPoint::operator=(const CameraViewPoint& other) { + model_transform = other.model_transform; + roll = other.roll; + has_fov = other.has_fov; + fov_is_horizontal = other.fov_is_horizontal; + fov = other.fov; + aspect = other.aspect; + focal_length = other.focal_length; + camera_aperture_w = other.camera_aperture_w; + camera_aperture_h = other.camera_aperture_h; + return *this; + } + + // 0x1401B2A60 + CameraRoot::CameraRoot() : model_transform(), interest(), view_point() { + + } + + // 0x1401B2A00 + CameraRoot::CameraRoot(const CameraRoot& other) : model_transform(other.model_transform), + interest(other.interest), view_point(other.view_point) { + + } + + // 0x1401B8240 + CameraRoot::~CameraRoot() { + + } + + // Inlined + inline void CameraRoot::init() { + model_transform.init(); + interest.init(); + view_point.init(); + } + + // 0x1401D3C70 + CameraParam CameraRoot::get(float_t in_frame, const Scene& in_scene, render_context* rctx) { + float_t frame = in_frame; + Fcurve3f& vp_translation = view_point.model_transform.fcurve_translation; + Fcurve3f& intr_translation = interest.model_transform.fcurve_translation; + if (vp_translation.x.check_threshold_discontinuity(frame) + || vp_translation.y.check_threshold_discontinuity(frame) + || vp_translation.z.check_threshold_discontinuity(frame) + || intr_translation.x.check_threshold_discontinuity(frame) + || intr_translation.y.check_threshold_discontinuity(frame) + || intr_translation.z.check_threshold_discontinuity(frame)) { + frame = prj::floorf(frame); + rctx->camera->set_fast_change(true); + } + else { + float_t frame_prev = frame - get_delta_frame(); + if (frame_prev > 0.0f && (int32_t)frame - (int32_t)frame_prev == 2) { + frame_prev = prj::ceilf(frame_prev); + if (vp_translation.x.check_threshold_discontinuity(frame_prev) + || vp_translation.y.check_threshold_discontinuity(frame_prev) + || vp_translation.z.check_threshold_discontinuity(frame_prev) + || intr_translation.x.check_threshold_discontinuity(frame_prev) + || intr_translation.y.check_threshold_discontinuity(frame_prev) + || intr_translation.z.check_threshold_discontinuity(frame_prev)) + rctx->camera->set_fast_change_hist0(true); + } + } + + CameraParam cam; + + model_transform.get(frame); + model_transform.mul(mat4_identity); + + const mat4& cr_mat = model_transform.get_matrix(); + + vec3 _view_point = vp_translation.get(frame); + mat4_transform_point(&cr_mat, &_view_point, &cam.view_point); + + vec3 _interest = intr_translation.get(frame); + mat4_transform_point(&cr_mat, &_interest, &cam.interest); + + cam.v_fov = view_point.get_v_fov(frame) * in_scene.M_fov_adjust; + cam.roll = view_point.roll.get(frame); + return cam; + } + + // 0x1401D9CA0 + bool CameraRoot::load(const SceneFile& in_file, const a3d::CameraRoot& in_cr) { + model_transform.load(in_file, in_cr.model_transform); + interest.load(in_file, in_cr.interest); + view_point.load(in_file, in_cr.view_point); + return true; + } + + // Added + void CameraRoot::store(const SceneFile& in_file, a3d::CameraRoot& out_cr) const { + model_transform.store(in_file, out_cr.model_transform); + interest.store(in_file, out_cr.interest); + view_point.store(in_file, out_cr.view_point); + } + + // 0x1401BB3A0 + CameraRoot& CameraRoot::operator=(const CameraRoot& other) { + model_transform = other.model_transform; + interest = other.interest; + view_point = other.view_point; + return *this; + } + + // 0x1401B3000 + Chara::Chara() : name(), model_transform(), rob_id(ROB_ID_NULL) { + + } + + // 0x1401B2F90 + Chara::Chara(const Chara& other) + : name(other.name), model_transform(other.model_transform), rob_id(other.rob_id) { + + } + + // 0x1401B8520 + Chara::~Chara() { + + } + + // 0x1401D4060 + void Chara::get(float_t in_frame) { + model_transform.get(in_frame); + } + + // 0x1401CE470 + void Chara::ctrl(Scene& in_scene) { + mat4 base_matrix = in_scene.get_base_matrix(); + + vec3 pos = model_transform.translation; + if (in_scene.get_reverse_side()) + pos.x = -pos.x; + mat4_transform_point(&base_matrix, &pos, &pos); + + RobAngle mt_yang; + mt_yang.set_rad(model_transform.rotation.y); + if (in_scene.get_reverse_side()) + mt_yang = -mt_yang; + + RobAngle base_yang; + base_yang.set_rad(atan2f(base_matrix.row2.x, base_matrix.row2.z)); + RobAngle yang = base_yang + mt_yang; + if (rob_id >= 0 && rob_id < ROB_ID_MAX) { + RobManagement* rob_man = get_rob_management(); + rob_man->set_rob_pos((ROB_ID)rob_id, pos); + rob_man->set_rob_yang((ROB_ID)rob_id, yang); + } + } + + // 0x1401D0380 + void Chara::disp(const Scene& in_scene, const mat4& in_base_mat, render_context* rctx) { + if (rob_id >= 0 && rob_id < ROB_ID_MAX) + get_rob_management()->set_disp_on((ROB_ID)rob_id, model_transform.visibility); + + if (in_scene.M_debug) { + model_transform.mul(in_scene.base_matrix); + debug_put_line_axis(model_transform.get_matrix()); + } + } + + // 0x1401E63E0 + void Chara::set_disp_freeze(bool in_value) const { + if (rob_id >= 0 && rob_id < ROB_ID_MAX) + get_rob_management()->set_disp_freeze((ROB_ID)rob_id, in_value); + } + + // 0x1401D8A70 + bool Chara::is_bind() const { + return rob_id >= 0 && rob_id < ROB_ID_MAX; + } + + // 0x1401DA100 + bool Chara::load(const SceneFile& in_file, const a3d::Chara& in_c) { + name.assign(in_c.name); + model_transform.load(in_file, in_c.model_transform); + return true; + } + + // Added + void Chara::store(const SceneFile& in_file, a3d::Chara& out_c) const { + out_c.name.assign(name); + model_transform.store(in_file, out_c.model_transform); + } + + // 0x1401BB6F0 + Chara& Chara::operator=(const Chara& other) { + name.assign(other.name); + model_transform = other.model_transform; + rob_id = other.rob_id; + return *this; + } + + // 0x1401B3180 + Curve::Curve() : curve(), name(), value() { + + } + + // 0x1401B30E0 + Curve::Curve(const Curve& other) : curve(other.curve), name(other.name), value(other.value) { + + } + + // 0x1401B85B0 + Curve::~Curve() { + + } + + // 0x1401D4140 + void Curve::get(float_t in_frame) { + value = curve.get(in_frame); + } + + // Inlined + inline Fcurve* Curve::M_get_fcurve() { + return &curve; + } + + // 0x1401DA230 + bool Curve::load(const SceneFile& in_file, const a3d::Curve& in_c) { + curve.load(in_file, in_c.fcurve); + name.assign(in_c.name); + return true; + } + + // Added + void Curve::store(const SceneFile& in_file, a3d::Curve& out_c) const { + curve.store(in_file, out_c.fcurve); + out_c.name.assign(name); + } + + // 0x1401BB7D0 + Curve& Curve::operator=(const Curve& other) { + curve = other.curve; + name.assign(other.name); + value = other.value; + return *this; + } + + // 0x1401B3220 + CurveWithOffset::CurveWithOffset() : fcurve_ptr(), offset(), value() { + init(); + } + + // 0x1401B31C0 + CurveWithOffset::CurveWithOffset(const CurveWithOffset& other) + : fcurve_ptr(other.fcurve_ptr), offset(other.offset), value(other.value) { + + } + + // 0x1401B8610 + CurveWithOffset::~CurveWithOffset() { + + } + + // 0x1401D6CD0 + void CurveWithOffset::init() { + fcurve_ptr = 0; + name.clear(); + name.shrink_to_fit(); + offset = 0.0f; + value = 0.0f; + } + + // Inlined + inline void CurveWithOffset::bind(Curve& in_c) { + fcurve_ptr = &in_c; + } + + // 0x1401D4160 + void CurveWithOffset::get(float_t in_frame) { + if (!fcurve_ptr) + return; + + float_t frame = in_frame; + if (offset != 0.0f) { + frame += offset; + if (frame >= fcurve_ptr->curve.m_max_frame) + frame -= fcurve_ptr->curve.m_max_frame; + } + value = fcurve_ptr->curve.get(frame); + } + + // Inlined + inline bool CurveWithOffset::is_valid() const { + return fcurve_ptr != 0; + } + + // 0x1401BB860 + CurveWithOffset& CurveWithOffset::operator=(const CurveWithOffset& other) { + fcurve_ptr = other.fcurve_ptr; + name.assign(other.name); + offset = other.offset; + value = other.value; + return *this; + } + + // 0x1401B32C0 + Dof::Dof() : has_dof() { + init(); + } + + // Missing + Dof::Dof(const Dof& other) : has_dof(other.has_dof), model_transform(other.model_transform) { + + } + + // 0x1401B86D0 + Dof::~Dof() { + + } + + // 0x1401D6CF0 + void Dof::init() { + has_dof = false; + model_transform.init(); + } + + // 0x1401D41A0 + void Dof::get(float_t in_frame) { + if (has_dof) + model_transform.get(in_frame); + } + + // 0x1401CE5F0 + void Dof::ctrl(render_context* rctx) { + if (!has_dof) + return; + + vec3 view_point; + rctx->camera->get_view_point(view_point); + + float_t focus = vec3::distance(model_transform.translation, view_point); + + rctx->render.set_dof_enable(fabsf(model_transform.rotation.z) > 0.000001f); + rctx->render.set_dof_data(focus, model_transform.scale.x, + model_transform.rotation.x, model_transform.rotation.y); + } + + // 0x1401CFE70 + void Dof::dest(render_context* rctx) { + if (has_dof) + rctx->render.set_dof_enable(false); + has_dof = false; + init(); + } + + // 0x1401DAFA0 + bool Dof::load(const SceneFile& in_file, const a3d::Dof& in_d) { + if (in_d.has_dof) { + model_transform.load(in_file, in_d.model_transform); + has_dof = true; + } + return true; + } + + // Added + void Dof::store(const SceneFile& in_file, a3d::Dof& out_d) const { + if (has_dof) { + model_transform.store(in_file, out_d.model_transform); + out_d.has_dof = true; + } + } + + // Missing + Dof& Dof::operator=(const Dof& other) { + has_dof = other.has_dof; + model_transform = other.model_transform; + return *this; + } + + // 0x1401B32E0 + Event::Event(const a3d::Event& in_e) { + active = false; + switch (in_e.type) { + case a3d::EVENT_MISC: + default: + type = EVENT_MISC; + break; + case a3d::EVENT_FLT: + type = EVENT_FLT; + break; + case a3d::EVENT_FX: + type = EVENT_FX; + break; + case a3d::EVENT_SND: + type = EVENT_SND; + break; + case a3d::EVENT_MOT: + type = EVENT_MOT; + break; + case a3d::EVENT_A2D: + type = EVENT_A2D; + break; + } + name.assign(in_e.name); + index = 0; + begin = in_e.begin; + end = in_e.end; + param1.assign(in_e.param1); + ref.assign(in_e.ref); + ref_index = -1; + } + + // 0x1401B8730 Event::~Event() { } - void Event::Load(auth_3d* auth) { + // 0x1401E5CD0 + void Event::resolve_relation(const Scene& in_scene) { } - void Event::Begin(auth_3d* auth, int32_t flags, render_context* rctx) { + // 0x1401D1E80 + void Event::entry(const Scene& in_scene, EventActionFlag in_eaf, render_context* rctx) { } - void Event::End(auth_3d* auth, int32_t flags, render_context* rctx) { + // 0x1401D3880 + void Event::exit(const Scene& in_scene, EventActionFlag in_eaf, render_context* rctx) { } - void Event::Ctrl(auth_3d* auth, int32_t flags, render_context* rctx) { + // 0x1401D14F0 + void Event::do_ctrl(const Scene& in_scene, EventActionFlag in_eaf, render_context* rctx) { } - void Event::Disp(auth_3d* auth, const mat4* mat, render_context* rctx) { + // 0x1401D1750 + void Event::do_disp(const Scene& in_scene, const mat4& in_mat, render_context* rctx) { } - void EventA2d::Aet::Free() { - if (id != -1) - aet_manager_free_aet_object(id); - id = -1; - } - - void EventA2d::Aet::Init() { - data_struct* aft_data = &data_list[DATA_AFT]; - aet_database* aft_aet_db = &aft_data->data_ft.aet_db; - - if (args.id.id < 0) - id = -1; - else { - id = aet_manager_init_aet_object(args, aft_aet_db); - if (id != -1) - aet_manager_set_obj_play(id, 1); - } - } - - EventA2d::Aet& EventA2d::Aet::SetArgs(const AetArgs& value) { - Free(); - args = value; - return *this; - } - - EventA2d::EventA2d(a3da_event* e) : Event(e) { + // Added + void Event::store(const SceneFile& in_file, a3d::Event& out_e) const { } + // 0x1401B3710 + EventA2d::EventA2d(const a3d::Event& in_e) : Event(in_e) { + + } + + // 0x1401B87C0 EventA2d::~EventA2d() { } - void EventA2d::Begin(auth_3d* auth, int32_t flags, render_context* rctx) { + // 0x1401D1E90 + void EventA2d::entry(const Scene& in_scene, EventActionFlag in_eaf, render_context* rctx) { + float_t frame = in_scene.get_frame(); + if (frame >= begin && frame < end) + M_a2d_handle.restart(); + } + + // 0x1401D3890 + void EventA2d::exit(const Scene& in_scene, EventActionFlag in_eaf, render_context* rctx) { } - void EventA2d::End(auth_3d* auth, int32_t flags, render_context* rctx) { + // 0x1401D1500 + void EventA2d::do_ctrl(const Scene& in_scene, EventActionFlag in_eaf, render_context* rctx) { } - void EventA2d::Ctrl(auth_3d* auth, int32_t flags, render_context* rctx) { + // 0x1401D1760 + void EventA2d::do_disp(const Scene& in_scene, const mat4& in_mat, render_context* rctx) { } - void EventA2d::Disp(auth_3d* auth, const mat4* mat, render_context* rctx) { - - } - - EventFX::EventFX(a3da_event* e) : Event(e) { + // 0x1401B3860 + EventFX::EventFX(const a3d::Event& in_e) : Event(in_e) { } + // 0x1401B87F0 EventFX::~EventFX() { } - void EventFX::Load(auth_3d* auth) { + // 0x1401E5CE0 + void EventFX::resolve_relation(const Scene& in_scene) { if (param1.compare("DOWN") && param1.compare("KABEHIT1") && param1.compare("PAPER1")) return; - index = -1; - for (auth_3d_point& i : auth->point) - if (!i.name.compare(ref)) { - index = &i - auth->point.data(); - break; - } + ref_index = in_scene.get_point_index(ref);; } - void EventFX::Begin(auth_3d* auth, int32_t flags, render_context* rctx) { - printf_debug(" [FX]: %s\n", param1.c_str()); + // 0x1401D1EF0 + void EventFX::entry(const Scene& in_scene, EventActionFlag in_eaf, render_context* rctx) { + event_log(" [FX]: %s\n", param1.c_str()); } - void EventFX::Ctrl(auth_3d* auth, int32_t flags, render_context* rctx) { - if (index >= auth->point.size() || auth->frame < begin || auth->frame >= end || param1.compare("PAPER1")) + // 0x1401D1510 + void EventFX::do_ctrl(const Scene& in_scene, EventActionFlag in_eaf, render_context* rctx) { + if (ref_index >= in_scene.point_list.size() || in_scene.M_frame < begin + || in_scene.M_frame >= end || param1.compare("PAPER1")) return; - auth_3d_point& point = auth->point[index]; - vec3 pos = point.model_transform.translation_value; - if (auth->mirror) + mat4 base_matrix = in_scene.get_base_matrix(); + + const Point& point = in_scene.point_list[ref_index]; + vec3 pos = point.model_transform.translation; + if (in_scene.get_reverse_side()) pos.x = -pos.x; + mat4_transform_point(&base_matrix, &pos, &pos); - mat4_transform_point(&auth->mat, &pos, &pos); particle_event_data event; event.type = 1.0f; - event.count = point.model_transform.scale_value.x * 100.0f; - event.size = point.model_transform.scale_value.z; + event.count = point.model_transform.scale.x * 100.0f; + event.size = point.model_transform.scale.z; event.pos = pos; - event.force = point.model_transform.scale_value.y; + event.force = point.model_transform.scale.y; effect_manager_event(EFFECT_PARTICLE, 1, &event); } - EventFXSmoothCut::EventFXSmoothCut(a3da_event* e) : Event(e), cam() { + // 0x1401B3890 + EventFXSmoothCut::EventFXSmoothCut(const a3d::Event& in_e) : Event(in_e), is_camera() { } + // 0x1401B8800 EventFXSmoothCut::~EventFXSmoothCut() { } - void EventFXSmoothCut::Load(auth_3d* auth) { + // 0x1401E5E10 + void EventFXSmoothCut::resolve_relation(const Scene& in_scene) { if (!ref.compare("CAM")) { - cam = true; + is_camera = true; return; } - index = -1; - for (auth_3d_point& i : auth->point) - if (!i.name.compare(ref)) { - index = &i - auth->point.data(); - break; - } + ref_index = in_scene.get_chara_index(ref); } - void EventFXSmoothCut::Begin(auth_3d* auth, int32_t flags, render_context* rctx) { - if (cam || !auth->chara.size() || index >= auth->chara.size()) + // 0x1401D1F10 + void EventFXSmoothCut::entry(const Scene& in_scene, EventActionFlag in_eaf, render_context* rctx) { + if (is_camera || !in_scene.chara_list.size() || ref_index >= in_scene.chara_list.size()) return; - ROB_ID rob_id = (ROB_ID)auth->chara[index].rob_id; - rob_chara* rob_chr = get_rob_management()->get_rob(rob_id); - if (rob_chr) - rob_chr->disp_pos_reset = true; + int32_t rob_id = in_scene.chara_list[ref_index].rob_id; + if (rob_id >= 0 && rob_id < ROB_ID_MAX) + get_rob_management()->reset_osage_pos((ROB_ID)rob_id); } - void EventFXSmoothCut::End(auth_3d* auth, int32_t flags, render_context* rctx) { + // 0x1401D38A0 + void EventFXSmoothCut::exit(const Scene& in_scene, EventActionFlag in_eaf, render_context* rctx) { } - void EventFXSmoothCut::Disp(auth_3d* auth, const mat4* mat, render_context* rctx) { + // 0x1401D1770 + void EventFXSmoothCut::do_disp(const Scene& in_scene, const mat4& in_mat, render_context* rctx) { } - EventFilterFade::EventFilterFade(a3da_event* e) : Event(e) { - type = Type::FADE_NONE; + // 0x1401B38C0 + EventFilterFade::EventFilterFade(const a3d::Event& in_e) : Event(in_e) { + fade_type = Type::FADE_NONE; } + // 0x1401B8810 EventFilterFade::~EventFilterFade() { } - void EventFilterFade::Begin(auth_3d* auth, int32_t flags, render_context* rctx) { + // 0x1401D1F90 + void EventFilterFade::entry(const Scene& in_scene, EventActionFlag in_eaf, render_context* rctx) { } - void EventFilterFade::End(auth_3d* auth, int32_t flags, render_context* rctx) { - switch (type) { + // 0x1401D38B0 + void EventFilterFade::exit(const Scene& in_scene, EventActionFlag in_eaf, render_context* rctx) { + switch (fade_type) { case EventFilterFade::Type::FADE_OUT: case EventFilterFade::Type::FADE_IN: break; @@ -1283,8 +1873,9 @@ namespace auth_3d_detail { rctx->render.reset_scene_fade(0); } - void EventFilterFade::Disp(auth_3d* auth, const mat4* mat, render_context* rctx) { - switch (type) { + // 0x1401D1780 + void EventFilterFade::do_disp(const Scene& in_scene, const mat4& in_mat, render_context* rctx) { + switch (fade_type) { case EventFilterFade::Type::FADE_OUT: case EventFilterFade::Type::FADE_IN: break; @@ -1292,11 +1883,11 @@ namespace auth_3d_detail { return; } - float_t t = (auth->frame - begin) / (end - begin); + float_t t = (in_scene.M_frame - begin) / (end - begin); vec4 value; - *(vec3*)&value = color; - if (type == EventFilterFade::Type::FADE_IN) + *(vec3*)&value = fade_color; + if (fade_type == EventFilterFade::Type::FADE_IN) value.w = t; else value.w = 1.0f - t; @@ -1304,85 +1895,140 @@ namespace auth_3d_detail { rctx->render.set_scene_fade(value, 0); } - EventFilterTimeStop::EventFilterTimeStop(a3da_event* e) : Event(e) { + // 0x1401B3AD0 + EventFilterTimeStop::EventFilterTimeStop(const a3d::Event& in_e) : Event(in_e) { } + // 0x1401B8820 EventFilterTimeStop::~EventFilterTimeStop() { } - void EventFilterTimeStop::Begin(auth_3d* auth, int32_t flags, render_context* rctx) { - for (auth_3d_chara& i : auth->chara) { - get_rob_management()->set_disp_freeze((ROB_ID)i.rob_id, true); - } + // 0x1401D1FA0 + void EventFilterTimeStop::entry(const Scene& in_scene, EventActionFlag in_eaf, render_context* rctx) { + for (const Chara& i : in_scene.chara_list) + i.set_disp_freeze(true); effect_manager_set_frame_rate_control(&frame_rate_time_stop); } - void EventFilterTimeStop::End(auth_3d* auth, int32_t flags, render_context* rctx) { - for (auth_3d_chara& i : auth->chara) { - get_rob_management()->set_disp_freeze((ROB_ID)i.rob_id, false); - } + // 0x1401D38E0 + void EventFilterTimeStop::exit(const Scene& in_scene, EventActionFlag in_eaf, render_context* rctx) { + for (const Chara& i : in_scene.chara_list) + i.set_disp_freeze(false); effect_manager_set_frame_rate_control(get_sys_frame_rate()); } - void EventFilterTimeStop::Disp(auth_3d* auth, const mat4* mat, render_context* rctx) { + // 0x1401D1830 + void EventFilterTimeStop::do_disp(const Scene& in_scene, const mat4& in_mat, render_context* rctx) { } - EventMot::EventMot(a3da_event* e) : Event(e) { + // 0x1401B3B00 + EventMot::EventMot(const a3d::Event& in_e) : Event(in_e) { } + // 0x1401B8830 EventMot::~EventMot() { } - void EventMot::Load(auth_3d* auth) { - index = -1; - for (auth_3d_chara& i : auth->chara) - if (!i.name.compare(ref)) { - index = &i - auth->chara.data(); - break; - } + // 0x1401E5EC0 + void EventMot::resolve_relation(const Scene& in_scene) { + ref_index = in_scene.get_chara_index(ref); } - void EventMot::Begin(auth_3d* auth, int32_t flags, render_context* rctx) { + // 0x1401D1FF0 + void EventMot::entry(const Scene& in_scene, EventActionFlag in_eaf, render_context* rctx) { + if (ref_index < 0 || ref_index >= in_scene.chara_list.size()) + return; + + const Chara& chara = in_scene.chara_list[ref_index]; + if (chara.rob_id < 0 || chara.rob_id >= ROB_ID_MAX) + return; + + data_struct* aft_data = &data_list[DATA_AFT]; + bone_database* aft_bone_data = &aft_data->data_ft.bone_data; + motion_database* aft_mot_db = &aft_data->data_ft.mot_db; + + mat4 base_matrix = in_scene.get_base_matrix(); + + vec3 pos = chara.model_transform.translation; + if (in_scene.get_reverse_side()) + pos.x = -pos.x; + mat4_transform_point(&base_matrix, &pos, &pos); + + RobAngle mt_yang; + mt_yang.set_rad(chara.model_transform.rotation.y); + if (in_scene.get_reverse_side()) + mt_yang = -mt_yang; + + RobAngle base_yang; + base_yang.set_rad(-atan2f(base_matrix.row2.x, base_matrix.row2.z)); + RobAngle yang = base_yang + mt_yang; + + RobInit rob_init; + rob_init.rob_type = ROB_TYPE_AUTH; + rob_init.mirror = in_scene.get_reverse_side(); + rob_init.pos = pos; + rob_init.yang = yang; + rob_init.energy = 200; + + ROB_ID rob_id = (ROB_ID)chara.rob_id; + RobManagement* rob_man = get_rob_management(); + rob_man->reset_rob(rob_id, rob_init, aft_bone_data, aft_mot_db); + rob_man->set_disp_on(rob_id, true); + + uint32_t motnum = aft_mot_db->get_motion_id(param1.c_str()); + if (motnum != -1 && motion_storage_check_mot_file_not_ready( + aft_mot_db->get_motion_set_id_by_motion_id(motnum))) + rob_man->set_motion(rob_id, motnum); + } + + // 0x1401D3940 + void EventMot::exit(const Scene& in_scene, EventActionFlag in_eaf, render_context* rctx) { } - void EventMot::End(auth_3d* auth, int32_t flags, render_context* rctx) { + // 0x1401D16F0 + void EventMot::do_ctrl(const Scene& in_scene, EventActionFlag in_eaf, render_context* rctx) { + float_t frame = in_scene.get_frame(); + if (begin <= frame && frame < end) { + int32_t rob_id = in_scene.chara_list[ref_index].rob_id; + get_rob_management()->set_mot_frame((ROB_ID)rob_id, frame); + } + } + + // 0x1401D1840 + void EventMot::do_disp(const Scene& in_scene, const mat4& in_mat, render_context* rctx) { } - void EventMot::Ctrl(auth_3d* auth, int32_t flags, render_context* rctx) { - - } - - void EventMot::Disp(auth_3d* auth, const mat4* mat, render_context* rctx) { - - } - - EventSnd::EventSnd(a3da_event* e) : Event(e) { - field_190 = param1.find("zz", 0, 2) == 0; + // 0x1401B3B30 + EventSnd::EventSnd(const a3d::Event& in_e) : Event(in_e) { + is_pseudo = param1.find("zz", 0, 2) == 0; } + // 0x1401B8840 EventSnd::~EventSnd() { } - void EventSnd::Load(auth_3d* auth) { + // 0x1401E5EF0 + void EventSnd::resolve_relation(const Scene& in_scene) { } - void EventSnd::Begin(auth_3d* auth, int32_t flags, render_context* rctx) { - float_t frame = auth->frame; - if (begin > frame || frame >= end || ((flags & 0x02) && fabsf(frame - begin) > 0.1f)) + // 0x1401B8840 + void EventSnd::entry(const Scene& in_scene, EventActionFlag in_eaf, render_context* rctx) { + float_t frame = in_scene.M_frame; + if (begin > frame || frame >= end || ((in_eaf & EAF_JUMP_BACKWARD) && fabsf(frame - begin) > 0.1f)) return; ROB_ID rob_id = ROB_ID_NULL; - if (auth->chara.size()) - rob_id = (ROB_ID)auth->chara.front().rob_id; + if (in_scene.chara_list.size()) + rob_id = (ROB_ID)in_scene.chara_list.front().rob_id; if (rob_id >= 0 && rob_id < ROB_ID_MAX) get_rob_management()->play_auth3d_sound(rob_id, param1.c_str()); @@ -1390,1704 +2036,5713 @@ namespace auth_3d_detail { sound_work_play_se(1, param1.c_str()); } - void EventSnd::End(auth_3d* auth, int32_t flags, render_context* rctx) { + // 0x1401D3950 + void EventSnd::exit(const Scene& in_scene, EventActionFlag in_eaf, render_context* rctx) { } - void EventSnd::Disp(auth_3d* auth, const mat4* mat, render_context* rctx) { + // 0x1401D1850 + void EventSnd::do_disp(const Scene& in_scene, const mat4& in_mat, render_context* rctx) { } -} + // 0x1401B4470 + Fog::Fog() : flag(), backup_flag(), id(), name(), fcurve_density(), fcurve_start(), fcurve_end(), + density(), start(), end(), color(), backup_density(), backup_start(), backup_end(), backup_color() { -auth_3d_key::auth_3d_key() : type(), value(), max_frame(), ep_type_pre(), ep_type_post(), -frame_delta(), value_delta(), length(), keys(), frame(), value_interp(), value_init() { - reset(); -} - -auth_3d_key::auth_3d_key(const auth_3d_key& k) : type(), value(), max_frame(), ep_type_pre(), -ep_type_post(), frame_delta(), value_delta(), length(), keys(), frame(), value_interp(), value_init() { - *this = k; -} - -auth_3d_key::~auth_3d_key() { - reset(); -} - -float_t auth_3d_key::interpolate(float_t frame) { - if (type == AUTH_3D_KEY_STATIC) - return value; - else if (type < AUTH_3D_KEY_STATIC || type > AUTH_3D_KEY_HOLD || !length) - return 0.0f; - - kft3* first_key = &keys[0]; - kft3* last_key = &keys[length - 1]; - float_t first_frame = first_key->frame; - float_t last_frame = last_key->frame; - - float_t offset = 0.0f; - if (frame < first_frame) { - float_t delta_frame = first_frame - frame; - switch (ep_type_pre) { - case A3DA_EP_NONE: - default: - this->frame = frame; - value_interp = first_key->value; - return value_interp; - case A3DA_EP_LINEAR: - this->frame = frame; - value_interp = first_key->value + delta_frame * first_key->tangent1; - return value_interp; - case A3DA_EP_CYCLE: - frame = last_frame - fmodf(delta_frame, frame_delta); - break; - case A3DA_EP_CYCLE_OFFSET: - offset = (prj::truncf(delta_frame / frame_delta) + 1.0f) * value_delta; - frame = last_frame - fmodf(delta_frame, frame_delta); - break; - } - } - else if (frame >= last_frame) { - float_t delta_frame = frame - last_frame; - switch (ep_type_post) { - case A3DA_EP_NONE: - default: - this->frame = frame; - value_interp = last_key->value; - return value_interp; - case A3DA_EP_LINEAR: - this->frame = frame; - value_interp = last_key->value - delta_frame * last_key->tangent2; - return value_interp; - case A3DA_EP_CYCLE: - frame = first_frame + fmodf(delta_frame, frame_delta); - break; - case A3DA_EP_CYCLE_OFFSET: - offset = (prj::truncf(delta_frame / frame_delta) + 1.0f) * value_delta; - frame = first_frame + fmodf(delta_frame, frame_delta); - break; - } } - this->frame = frame; - value_interp = auth_3d_key_interpolate_inner(this, frame) + offset; - return value_interp; -} + // 0x1401B41C0 + Fog::Fog(const Fog& other) : flag(other.flag), backup_flag(other.backup_flag), id(other.id), name(other.name), + fcurve_density(other.fcurve_density), fcurve_start(other.fcurve_start), fcurve_end(other.fcurve_end), + density(other.density), start(other.start), end(other.end), color(other.color), + backup_density(other.backup_density), backup_start(other.backup_start), + backup_end(other.backup_end), backup_color(other.backup_color) { -void auth_3d_key::reset() { - type = AUTH_3D_KEY_NONE; - value = 0.0f; - max_frame = 0.0f; - ep_type_pre = AUTH_3D_EP_NONE; - ep_type_post = AUTH_3D_EP_NONE; - frame_delta = 0.0f; - value_delta = 0.0f; - keys_vec.clear(); - keys_vec.shrink_to_fit(); - length = 0; - keys = 0; - frame = 0.0f; - value_interp = 0.0f; - value_init = 0.0f; -} - -auth_3d_key& auth_3d_key::operator=(const auth_3d_key& k) { - type = k.type; - value = k.value; - max_frame = k.max_frame; - ep_type_pre = k.ep_type_pre; - ep_type_post = k.ep_type_post; - frame_delta = k.frame_delta; - value_delta = k.value_delta; - keys_vec.assign(k.keys_vec.begin(), k.keys_vec.end()); - length = k.length; - keys = keys_vec.data(); - - frame = k.frame; - value_interp = k.value_interp; - value_init = k.value_init; - return *this; -} - -auth_3d_rgba::auth_3d_rgba() : flags(), value() { - reset(); -} - -auth_3d_rgba::~auth_3d_rgba() { - reset(); -} - -void auth_3d_rgba::interpolate(float_t frame){ - if (flags & AUTH_3D_RGBA_R) - value.x = r.interpolate(frame); - - if (flags & AUTH_3D_RGBA_G) - value.y = g.interpolate(frame); - - if (flags & AUTH_3D_RGBA_B) - value.z = b.interpolate(frame); - - if (flags & AUTH_3D_RGBA_A) - value.w = a.interpolate(frame); -} - -void auth_3d_rgba::reset() { - flags = (auth_3d_rgba_flags)0; - r.reset(); - g.reset(); - b.reset(); - a.reset(); - value = 0.0f; -} - -auth_3d_vec3::auth_3d_vec3() { - reset(); -} - -auth_3d_vec3::~auth_3d_vec3() { - reset(); -} - -vec3 auth_3d_vec3::interpolate(float_t frame) { - vec3 value; - value.x = x.interpolate(frame); - value.y = y.interpolate(frame); - value.z = z.interpolate(frame); - return value; -} - -void auth_3d_vec3::reset() { - x.reset(); - y.reset(); - z.reset(); -} - -auth_3d_model_transform::auth_3d_model_transform() : mat(), -scale_value(), rotation_value(), translation_value(), visible() { - reset(); -} - -auth_3d_model_transform::~auth_3d_model_transform() { - reset(); -} - -void auth_3d_model_transform::interpolate(float_t frame) { - scale_value = scale.interpolate(frame); - rotation_value = rotation.interpolate(frame); - translation_value = translation.interpolate(frame); - visible = visibility.interpolate(frame) >= 0.999f; - if (visible && (scale_value.x == 0.0f || scale_value.y == 0.0f || scale_value.z == 0.0f)) - visible = false; -} - -void auth_3d_model_transform::reset() { - mat = mat4_identity; - scale.reset(); - rotation.reset(); - translation.reset(); - visibility.reset(); - scale_value = 0.0f; - rotation_value = 0.0f; - translation_value = 0.0f; - visible = false; -} - -void auth_3d_model_transform::set_mat(const mat4* parent_mat) { - mat4 mat; - mat4_mul_translate(parent_mat, &translation_value, &mat); - mat4_mul_rotate_zyx(&mat, &rotation_value, &mat); - mat4_scale_rot(&mat, &scale_value, &this->mat); -} - -auth_3d_ambient::auth_3d_ambient() : flags() { - reset(); -} - -auth_3d_ambient::~auth_3d_ambient() { - reset(); -} - -void auth_3d_ambient::interpolate(float_t frame) { - if (flags & AUTH_3D_AMBIENT_LIGHT_DIFFUSE) - light_diffuse.interpolate(frame); - - if (flags & AUTH_3D_AMBIENT_LIGHT_DIFFUSE) - rim_light_diffuse.interpolate(frame); -} - -void auth_3d_ambient::reset() { - flags = (auth_3d_ambient_flags)0; - light_diffuse.reset(); - name.clear(); - name.shrink_to_fit(); - rim_light_diffuse.reset(); -} - -auth_3d_camera_auxiliary::auth_3d_camera_auxiliary() : flags(), auto_exposure_value(), -exposure_value(), exposure_rate_value(), gamma_value(), gamma_rate_value(), saturate_value() { - reset(); -} - -auth_3d_camera_auxiliary::~auth_3d_camera_auxiliary() { - reset(); -} - -void auth_3d_camera_auxiliary::interpolate(float_t frame) { - if (flags & AUTH_3D_CAMERA_AUXILIARY_AUTO_EXPOSURE) - auto_exposure_value = auto_exposure.interpolate(frame); - if (flags & AUTH_3D_CAMERA_AUXILIARY_EXPOSURE) - exposure_value = exposure.interpolate(frame); - if (flags & AUTH_3D_CAMERA_AUXILIARY_EXPOSURE_RATE) - exposure_rate_value = exposure_rate.interpolate(frame); - if (flags & AUTH_3D_CAMERA_AUXILIARY_GAMMA) - gamma_value = gamma.interpolate(frame); - if (flags & AUTH_3D_CAMERA_AUXILIARY_GAMMA_RATE) - gamma_rate_value = gamma_rate.interpolate(frame); - if (flags & AUTH_3D_CAMERA_AUXILIARY_SATURATE) - saturate_value = saturate.interpolate(frame); -} - -void auth_3d_camera_auxiliary::reset() { - flags = (auth_3d_camera_auxiliary_flags)0; - auto_exposure.reset(); - exposure.reset(); - exposure_rate.reset(); - gamma.reset(); - gamma_rate.reset(); - saturate.reset(); - auto_exposure_value = 1.0f; - exposure_value = 2.0f; - exposure_rate_value = 1.0f; - gamma_value = 1.0f; - gamma_rate_value = 1.0f; - saturate_value = 1.0f; -} - -auth_3d_camera_root::auth_3d_camera_root() : fov_value(), -interest_value(), roll_value(), view_point_value() { - reset(); -} - -void auth_3d_camera_root::interpolate(float_t frame) { - model_transform.interpolate(frame); - model_transform.set_mat(&mat4_identity); - - mat4& cr_mat = model_transform.mat; - - vec3 _view_point = view_point.model_transform.translation.interpolate(frame); - mat4_transform_point(&cr_mat, &_view_point, &view_point_value); - - vec3 _interest = interest.translation.interpolate(frame); - mat4_transform_point(&cr_mat, &_interest, &interest_value); - - float_t fov; - if (view_point.flags & AUTH_3D_CAMERA_ROOT_VIEW_POINT_FOV) { - fov = view_point.fov.interpolate(frame); - if (view_point.fov_is_horizontal) - fov = atanf(tanf(fov * 0.5f) / view_point.aspect) * 2.0f; - } - else { - float_t camera_aperture_h = view_point.camera_aperture_h; - float_t focal_lenth = view_point.focal_length.interpolate(frame); - fov = atanf((camera_aperture_h * 25.4f) * 0.5f / focal_lenth) * 2.0f; - } - fov_value = fov; - - if (view_point.flags & AUTH_3D_CAMERA_ROOT_VIEW_POINT_ROLL) - roll_value = view_point.roll.interpolate(frame); -} - -void auth_3d_camera_root::reset() { - interest.reset(); - model_transform.reset(); - view_point.reset(); - fov_value = 0.0f; - interest_value = 0.0f; - roll_value = 0.0f; - view_point_value = 0.0f; -} - -auth_3d_camera_root::~auth_3d_camera_root() { - reset(); -} - -auth_3d_camera_root_view_point::auth_3d_camera_root_view_point() : flags(), -aspect(), camera_aperture_h(), camera_aperture_w(), fov_is_horizontal() { - reset(); -} - -auth_3d_camera_root_view_point::~auth_3d_camera_root_view_point() { - reset(); -} - -void auth_3d_camera_root_view_point::reset() { - flags = (auth_3d_camera_root_view_point_flags)0; - aspect = 0.0f; - camera_aperture_h = 0.0f; - camera_aperture_w = 0.0f; - focal_length.reset(); - fov.reset(); - fov_is_horizontal = false; - model_transform.reset(); - roll.reset(); -} - -auth_3d_chara::auth_3d_chara() : rob_id() { - reset(); -} - -auth_3d_chara::~auth_3d_chara() { - reset(); -} - -void auth_3d_chara::interpolate(float_t frame) { - model_transform.interpolate(frame); -} - -void auth_3d_chara::reset() { - model_transform.reset(); - name.clear(); - name.shrink_to_fit(); - rob_id = ROB_ID_NULL; -} - -auth_3d_curve::auth_3d_curve() : value() { - reset(); -} - -auth_3d_curve::~auth_3d_curve() { - reset(); -} - -void auth_3d_curve::interpolate(float_t frame) { - value = curve.interpolate(frame); -} - -void auth_3d_curve::reset() { - curve.reset(); - name.clear(); - name.shrink_to_fit(); - value = 0.0f; -} - -auth_3d_dof::auth_3d_dof() : has_dof() { - reset(); -} - -auth_3d_dof::~auth_3d_dof() { - reset(); -} - -void auth_3d_dof::interpolate(float_t frame) { - if (!has_dof) - return; - - model_transform.interpolate(frame); -} - -void auth_3d_dof::reset() { - has_dof = false; - model_transform.reset(); -} - -auth_3d_fog::auth_3d_fog() : flags(), flags_init(), id(), density_value(), -end_value(), start_value(), density_init(), end_init(), start_init() { - reset(); -} - -auth_3d_fog::~auth_3d_fog() { - reset(); -} - -void auth_3d_fog::interpolate(float_t frame) { - if (flags & AUTH_3D_FOG_DENSITY) - density_value = density.interpolate(frame); - if (flags & AUTH_3D_FOG_START) - start_value = start.interpolate(frame); - if (flags & AUTH_3D_FOG_END) - end_value = end.interpolate(frame); - if (flags & AUTH_3D_FOG_COLOR) - color.interpolate(frame); -} - -void auth_3d_fog::reset() { - flags = (auth_3d_fog_flags)0; - flags_init = (auth_3d_fog_flags)0; - color.reset(); - density.reset(); - end.reset(); - id = (fog_id)0; - start.reset(); - - density_value = 0.0f; - end_value = 0.0f; - start_value = 0.0f; - - color_init = 0.0f; - density_init = 0.0f; - end_init = 0.0f; - start_init = 0.0f; -} - -auth_3d_light::auth_3d_light() : flags(), flags_init(), id(), cone_angle_value(), -constant_value(), drop_off_value(), far_value(), intensity_value(), linear_value(), -quadratic_value(), cone_angle_init(), constant_init(), drop_off_init(), -far_init(), intensity_init(), linear_init(), quadratic_init(), tone_curve_init() { - reset(); -} - -auth_3d_light::~auth_3d_light() { - reset(); -} - -void auth_3d_light::interpolate(float_t frame) { - if (flags & AUTH_3D_LIGHT_AMBIENT) - ambient.interpolate(frame); - if (flags & AUTH_3D_LIGHT_CONE_ANGLE) - cone_angle_value = cone_angle.interpolate(frame); - if (flags & AUTH_3D_LIGHT_CONSTANT) - constant_value = constant.interpolate(frame); - if (flags & AUTH_3D_LIGHT_DIFFUSE) - diffuse.interpolate(frame); - if (flags & AUTH_3D_LIGHT_DROP_OFF) - drop_off_value = drop_off.interpolate(frame); - if (flags & AUTH_3D_LIGHT_FAR) - far_value = _far.interpolate(frame); - if (flags & AUTH_3D_LIGHT_INTENSITY) - intensity_value = intensity.interpolate(frame); - if (flags & AUTH_3D_LIGHT_LINEAR) - linear_value = linear.interpolate(frame); - if (flags & AUTH_3D_LIGHT_POSITION) - position.interpolate(frame); - if (flags & AUTH_3D_LIGHT_QUADRATIC) - quadratic_value = quadratic.interpolate(frame); - if (flags & AUTH_3D_LIGHT_SPECULAR) - specular.interpolate(frame); - if (flags & AUTH_3D_LIGHT_SPOT_DIRECTION) - spot_direction.interpolate(frame); - if (flags & AUTH_3D_LIGHT_TONE_CURVE) - tone_curve.interpolate(frame); -} - -void auth_3d_light::reset() { - flags = (auth_3d_light_flags)0; - flags_init = (auth_3d_light_flags)0; - ambient.reset(); - cone_angle.reset(); - constant.reset(); - diffuse.reset(); - drop_off.reset(); - _far.reset(); - id = (light_id)0; - intensity.reset(); - linear.reset(); - position.reset(); - quadratic.reset(); - specular.reset(); - spot_direction.reset(); - tone_curve.reset(); - type.clear(); - type.shrink_to_fit(); - cone_angle_value = 0.0f; - constant_value = 0.0f; - drop_off_value = 0.0f; - far_value = 0.0f; - intensity_value = 0.0f; - linear_value = 0.0f; - quadratic_value = 0.0f; - ambient_init = 0.0f; - cone_angle_init = 0.0f; - constant_init = 0.0f; - diffuse_init = 0.0f; - drop_off_init = 0.0f; - far_init = 0.0f; - intensity_init = 0.0f; - linear_init = 0.0f; - quadratic_init = 0.0f; - specular_init = 0.0f; - tone_curve_init = {}; -} - -auth_3d_m_object_hrc::auth_3d_m_object_hrc() { - reset(); -} - -auth_3d_m_object_hrc::~auth_3d_m_object_hrc() { - reset(); -} - -void auth_3d_m_object_hrc::interpolate(float_t frame) { - model_transform.interpolate(frame); - for (auth_3d_object_instance& i : instance) - i.interpolate(frame); - for (auth_3d_object_node& i : node) - i.interpolate(frame); -} - -void auth_3d_m_object_hrc::list_ctrl(const mat4* parent_mat) { - //if (!model_transform.visible) - // return; - - auth_3d_object_node* node = this->node.data(); - - auth_3d_m_object_hrc_nodes_mat_mult(this); - - this->model_transform.mat_mult(parent_mat); - - mat4& mat = this->model_transform.mat; - - for (auth_3d_object_instance& i : this->instance) { - //if (!i.model_transform.visible) - // continue; - - i.model_transform.mat_mult(&mat); - int32_t* object_bone_indices = i.object_bone_indices.data(); - size_t object_bone_indices_count = i.object_bone_indices.size(); - mat4* mats = i.mats.data(); - for (size_t j = 0; j < object_bone_indices_count; j++) - mats[j] = node[object_bone_indices[j]].model_transform.mat; - } -} - -void auth_3d_m_object_hrc::reset() { - for (auth_3d_object_instance& i : instance) - i.reset(); - instance.clear(); - instance.shrink_to_fit(); - model_transform.reset(); - name.clear(); - name.shrink_to_fit(); - for (auth_3d_object_node& i : node) - i.reset(); - node.clear(); - node.shrink_to_fit(); -} - -auth_3d_material_list::auth_3d_material_list() : flags(), glow_intensity_value() { - reset(); -} - -auth_3d_material_list::~auth_3d_material_list() { - reset(); -} - -void auth_3d_material_list::interpolate(float_t frame) { - if (flags & AUTH_3D_MATERIAL_LIST_BLEND_COLOR) - blend_color.interpolate(frame); - if (flags & AUTH_3D_MATERIAL_LIST_GLOW_INTENSITY) - glow_intensity_value = glow_intensity.interpolate(frame); - if (flags & AUTH_3D_MATERIAL_LIST_EMISSION) - emission.interpolate(frame); -} - -void auth_3d_material_list::reset() { - flags = (auth_3d_material_list_flags)0; - blend_color.reset(); - glow_intensity.reset(); - emission.reset(); - name.clear(); - name.shrink_to_fit(); - glow_intensity_value = 0.0f; -} - -auth_3d_object::auth_3d_object() : object_info(), object_hash(), reflect(), refract() { - reset(); -} - -auth_3d_object::~auth_3d_object() { - reset(); -} - -void auth_3d_object::interpolate(float_t frame) { - model_transform.interpolate(frame); - pattern.interpolate(frame); - morph.interpolate(frame); - for (auth_3d_object_texture_pattern& i : texture_pattern) - i.interpolate(frame); - for (auth_3d_object_texture_transform& i : texture_transform) - i.interpolate(frame); -} - -void auth_3d_object::list_ctrl(const mat4* parent_mat) { - //if (!model_transform.visible) - // return; - - model_transform.set_mat(parent_mat); - - mat4& mat = model_transform.mat; - - for (auth_3d_object*& i : children_object) - i->list_ctrl(&mat); - for (auth_3d_object_hrc*& i : children_object_hrc) - i->list_ctrl(&mat); -} - -void auth_3d_object::reset() { - children_object.clear(); - children_object.shrink_to_fit(); - children_object_hrc.clear(); - children_object_hrc.shrink_to_fit(); - model_transform.reset(); - morph.reset(); - object_info = {}; - object_hash = (uint32_t)-1; - name.clear(); - name.shrink_to_fit(); - parent_name.clear(); - parent_name.shrink_to_fit(); - parent_node.clear(); - parent_node.shrink_to_fit(); - pattern.reset(); - reflect = false; - refract = false; - for (auth_3d_object_texture_pattern& i : texture_pattern) - i.reset(); - texture_pattern.clear(); - texture_pattern.shrink_to_fit(); - for (auth_3d_object_texture_transform& i : texture_transform) - i.reset(); - texture_transform.clear(); - texture_transform.shrink_to_fit(); - uid_name.clear(); - uid_name.shrink_to_fit(); -} - -auth_3d_object_curve::auth_3d_object_curve() : curve(), frame_offset(), value() { - reset(); -} - -auth_3d_object_curve::~auth_3d_object_curve() { - reset(); -} - -void auth_3d_object_curve::interpolate(float_t frame) { - auth_3d_curve* c = curve; - if (!c) - return; - - if (frame_offset != 0.0f) { - frame += frame_offset; - if (frame >= c->curve.max_frame) - frame -= c->curve.max_frame; - } - value = c->curve.interpolate(frame); -} - -void auth_3d_object_curve::reset() { - curve = 0; - name.clear(); - name.shrink_to_fit(); - frame_offset = 0.0f; - value = 0.0f; -} - -auth_3d_object_hrc::auth_3d_object_hrc() : object_info(), -object_hash(), reflect(), refract(), shadow() { - reset(); -} - -auth_3d_object_hrc::~auth_3d_object_hrc() { - reset(); -} - -int32_t auth_3d_object_hrc::get_node_index(const char* node) { - for (auth_3d_object_node& i : this->node) - if (!i.name.compare(node)) - return (int32_t)(&i - this->node.data()); - return -1; -} - -void auth_3d_object_hrc::interpolate(float_t frame) { - for (auth_3d_object_node& i : node) - i.interpolate(frame); -} - -void auth_3d_object_hrc::list_ctrl(const mat4* mat) { - //if (node.size() < 1 || !node.front().model_transform.visible) - // return; - - auth_3d_object_hrc_nodes_mat_mult(this, mat); - - auth_3d_object_node* node = this->node.data(); - - int32_t* children_object_parent_node = this->children_object_parent_node.data(); - auth_3d_object** children_object = this->children_object.data(); - size_t children_object_count = this->children_object.size(); - for (size_t i = 0; i < children_object_count; i++) - children_object[i]->list_ctrl( - &node[children_object_parent_node[i]].model_transform.mat); - - int32_t* children_object_hrc_parent_node = this->children_object_hrc_parent_node.data(); - auth_3d_object_hrc** children_object_hrc = this->children_object_hrc.data(); - size_t children_object_hrc_count = this->children_object_hrc.size(); - for (size_t i = 0; i < children_object_hrc_count; i++) - children_object_hrc[i]->list_ctrl( - &node[children_object_hrc_parent_node[i]].model_transform.mat); -} - -void auth_3d_object_hrc::reset() { - children_object.clear(); - children_object.shrink_to_fit(); - children_object_hrc.clear(); - children_object_hrc.shrink_to_fit(); - children_object_parent_node.clear(); - children_object_parent_node .shrink_to_fit(); - children_object_hrc_parent_node.clear(); - children_object_hrc_parent_node.shrink_to_fit(); - mats.clear(); - mats.shrink_to_fit(); - name.clear(); - name.shrink_to_fit(); - for (auth_3d_object_node& i : node) - i.reset(); - node.clear(); - node.shrink_to_fit(); - object_info = {}; - object_hash = (uint32_t)-1; - parent_name.clear(); - parent_name.shrink_to_fit(); - parent_node.clear(); - parent_node.shrink_to_fit(); - reflect = false; - refract = false; - shadow = false; - uid_name.clear(); - uid_name.shrink_to_fit(); -} - -auth_3d_object_instance::auth_3d_object_instance() : object_info(), object_hash(), shadow() { - reset(); -} - -auth_3d_object_instance::~auth_3d_object_instance() { - reset(); -} - -void auth_3d_object_instance::interpolate(float_t frame) { - model_transform.interpolate(frame); -} - -void auth_3d_object_instance::reset() { - mats.clear(); - mats.shrink_to_fit(); - model_transform.reset(); - name.clear(); - name.shrink_to_fit(); - object_bone_indices.clear(); - object_bone_indices.shrink_to_fit(); - object_info = {}; - object_hash = (uint32_t)-1; - shadow = false; - uid_name.clear(); - uid_name.shrink_to_fit(); -} - -auth_3d_object_model_transform::auth_3d_object_model_transform() : mat(), -mat_inner(), mat_rot(), translation_value(), rotation_value(), scale_value(), -visible(), frame(), has_rotation(), has_translation(), has_scale(), has_visibility() { - reset(); -} - -auth_3d_object_model_transform::~auth_3d_object_model_transform() { - reset(); -} - -void auth_3d_object_model_transform::interpolate(float_t frame) { - if (frame != this->frame || has_rotation) { - translation_value = translation.interpolate(frame); - rotation_value = rotation.interpolate(frame); - - if (has_scale) - scale_value = scale.interpolate(frame); - - if (has_visibility) - visible = visibility.interpolate(frame) >= 0.999f; - - mat4_rotate_zyx(&rotation_value, &mat_rot); - this->frame = frame; - has_rotation = false; - has_translation = false; } - if (has_translation && !has_rotation) - return; + // 0x1401B89B0 + Fog::~Fog() { - mat4 mat; - mat4_translate(&translation_value, &mat); - - mat4_mul(&mat_rot, &mat, &mat); - if (has_scale) - mat4_scale_rot(&mat, &scale_value, &mat); - mat_inner = mat; - has_translation = true; -} - -void auth_3d_object_model_transform::mat_mult(const mat4* mat) { - mat4_mul(&this->mat_inner, mat, &this->mat); -} - -void auth_3d_object_model_transform::reset() { - mat = mat4_identity; - mat_inner = mat4_identity; - mat_rot = mat4_identity; - translation.reset(); - rotation.reset(); - scale.reset(); - visibility.reset(); - translation_value = 0.0f; - rotation_value = 0.0f; - scale_value = 1.0f; - visible = true; - frame = -1.0f; - has_rotation = false; - has_translation = false; - has_scale = false; - has_visibility = false; -} - -auth_3d_object_node::auth_3d_object_node() : flags(), -bone_id(), joint_orient(), joint_orient_mat(), mat(), parent() { - reset(); -} - -auth_3d_object_node::~auth_3d_object_node() { - reset(); -} - -void auth_3d_object_node::interpolate(float_t frame) { - model_transform.interpolate(frame); -} - -void auth_3d_object_node::reset() { - flags = (auth_3d_object_node_flags)0; - bone_id = -1; - joint_orient = 0.0f; - joint_orient_mat = mat4_identity; - mat = 0; - model_transform.reset(); - name.clear(); - name.shrink_to_fit(); - parent = -1; -} - -auth_3d_object_texture_pattern::auth_3d_object_texture_pattern() : texture_id() { - reset(); -} - -auth_3d_object_texture_pattern::~auth_3d_object_texture_pattern() { - reset(); -} - -void auth_3d_object_texture_pattern::interpolate(float_t frame) { - pattern.interpolate(frame); -} - -void auth_3d_object_texture_pattern::reset() { - name.clear(); - name.shrink_to_fit(); - pattern.reset(); - texture_id = -1; -} - -auth_3d_object_texture_transform::auth_3d_object_texture_transform() : flags(), mat(), texture_id() { - reset(); -} - -auth_3d_object_texture_transform::~auth_3d_object_texture_transform() { - reset(); -} - -void auth_3d_object_texture_transform::interpolate(float_t frame) { - int32_t flags = this->flags; - - vec3 scale = 1.0f; - vec3 repeat = 1.0f; - vec3 rotate = 0.0f; - vec3 translate_frame = 0.0f; - - if (flags & AUTH_3D_OBJECT_TEXTURE_TRANSFORM_COVERAGE_U && this->coverage_u.max_frame > 0.0f) { - float_t coverage_u = this->coverage_u.interpolate(frame); - if (fabsf(coverage_u) > 0.000001f) - scale.x = 1.0f / coverage_u; } - if (flags & AUTH_3D_OBJECT_TEXTURE_TRANSFORM_COVERAGE_V && this->coverage_v.max_frame > 0.0f) { - float_t coverage_v = this->coverage_v.interpolate(frame); - if (fabsf(coverage_v) > 0.000001f) - scale.y = 1.0f / coverage_v; + // 0x1401D7150 + void Fog::init() { + id = -1; + flag = 0; + backup_flag = 0; + name.assign("(init)"); + + density = 0.0f; + start = 10.0f; + end = 100.0f; + + fcurve_density.init(); + fcurve_start.init(); + fcurve_end.init(); } - if (flags & AUTH_3D_OBJECT_TEXTURE_TRANSFORM_REPEAT_U && this->repeat_u.max_frame > 0.0f) { - float_t value = this->repeat_u.interpolate(frame); - if (fabsf(value) > 0.000001f) - repeat.x = value; - } - - if (flags & AUTH_3D_OBJECT_TEXTURE_TRANSFORM_REPEAT_V && this->repeat_v.max_frame > 0.0f) { - float_t value = this->repeat_v.interpolate(frame); - if (fabsf(value) > 0.000001f) - repeat.y = value; - } - - if (flags & AUTH_3D_OBJECT_TEXTURE_TRANSFORM_ROTATE_FRAME) - rotate.z = this->rotate_frame.interpolate(frame); - - if (flags & AUTH_3D_OBJECT_TEXTURE_TRANSFORM_ROTATE) - rotate.z += this->rotate.interpolate(frame); - - float_t translate_frame_u; - if (flags & AUTH_3D_OBJECT_TEXTURE_TRANSFORM_TRANSLATE_FRAME_U) - translate_frame_u = -this->translate_frame_u.interpolate(frame); - else - translate_frame_u = 0.0f; - - float_t offset_u; - if (flags & AUTH_3D_OBJECT_TEXTURE_TRANSFORM_OFFSET_U) - offset_u = this->offset_u.interpolate(frame); - else - offset_u = 0.0f; - - translate_frame.x = (translate_frame_u + offset_u) * repeat.x; - - float_t translate_frame_v; - if (flags & AUTH_3D_OBJECT_TEXTURE_TRANSFORM_TRANSLATE_FRAME_V) - translate_frame_v = -this->translate_frame_v.interpolate(frame); - else - translate_frame_v = 0.0f; - - float_t offset_v; - if (flags & AUTH_3D_OBJECT_TEXTURE_TRANSFORM_OFFSET_V) - offset_v = this->offset_v.interpolate(frame); - else - offset_v = 0.0f; - - translate_frame.y = (translate_frame_v + offset_v) * repeat.y; - - mat4 mat; - mat4_translate(&translate_frame, &mat); - mat4_scale_rot(&mat, &scale, &mat); - - mat4_mul_translate(&mat, 1.0f, 1.0f, 0.0f, &mat); - mat4_scale_rot(&mat, &repeat, &mat); - mat4_mul_translate(&mat, -1.0f, -1.0f, 0.0f, &mat); - - mat4_mul_translate(&mat, 0.5f, 0.5f, 0.0f, &mat); - mat4_mul_rotate_z(&mat, rotate.z, &mat); - mat4_mul_translate(&mat, -0.5f, -0.5f, 0.0f, &mat); - this->mat = mat; -} - -void auth_3d_object_texture_transform::reset() { - flags = (auth_3d_object_texture_transform_flags)0; - coverage_u.reset(); - coverage_v.reset(); - mat = mat4_identity; - name.clear(); - name.shrink_to_fit(); - offset_u.reset(); - offset_v.reset(); - repeat_u.reset(); - repeat_v.reset(); - rotate.reset(); - rotate_frame.reset(); - texture_id = -1; - translate_frame_u.reset(); - translate_frame_v.reset(); -} - -auth_3d_play_control::auth_3d_play_control() : flags(), -begin(), div(), fps(), offset(), size() { - reset(); -} - -auth_3d_play_control::~auth_3d_play_control() { - reset(); -} - -void auth_3d_play_control::reset() { - flags = (auth_3d_play_control_flags)0; - begin = 0.0f; - div = 0; - fps = 0.0f; - offset = 0.0f; - size = 0.0f; -} - -auth_3d_point::auth_3d_point() { - reset(); -} - -auth_3d_point::~auth_3d_point() { - reset(); -} - -void auth_3d_point::interpolate(float_t frame) { - model_transform.interpolate(frame); -} - -void auth_3d_point::reset() { - model_transform.reset(); - name.clear(); - name.shrink_to_fit(); -} - -auth_3d_post_process::auth_3d_post_process() : flags(), flags_init() { - reset(); -} - -auth_3d_post_process::~auth_3d_post_process() { - reset(); -} - -void auth_3d_post_process::interpolate(float_t frame) { - if (flags & AUTH_3D_POST_PROCESS_INTENSITY) - intensity.interpolate(frame); - if (flags & AUTH_3D_POST_PROCESS_LENS_FLARE) - lens_value.x = lens_flare.interpolate(frame); - if (flags & AUTH_3D_POST_PROCESS_LENS_SHAFT) - lens_value.y = lens_shaft.interpolate(frame); - if (flags & AUTH_3D_POST_PROCESS_LENS_GHOST) - lens_value.z = lens_ghost.interpolate(frame); - if (flags & AUTH_3D_POST_PROCESS_RADIUS) - radius.interpolate(frame); - if (flags & AUTH_3D_POST_PROCESS_SCENE_FADE) - scene_fade.interpolate(frame); -} - -void auth_3d_post_process::reset() { - flags = (auth_3d_post_process_flags)0; - flags_init = (auth_3d_post_process_flags)0; - intensity.reset(); - lens_flare.reset(); - lens_ghost.reset(); - lens_shaft.reset(); - radius.reset(); - scene_fade.reset(); - lens_value = 1.0f; - intensity_init = 0.0f; - lens_init = 1.0f; - radius_init = 0.0f; - scene_fade_init = 0.0f; -} - -auth_3d_farc::auth_3d_farc() : load_count(), name(), state(), farc(), data(), size() { - -} - -auth_3d_farc::~auth_3d_farc() { - delete farc; -} - -auth_3d_uid_file::auth_3d_uid_file() : load_count(), uid(), state(), name(), farc() { - -} - -auth_3d_uid_file::~auth_3d_uid_file() { - -} - -auth_3d_uid_file_modern::auth_3d_uid_file_modern() : load_count(), -state(), name(), farc(),data(), obj_db(), tex_db() { - hash = hash_murmurhash_empty; -} - -auth_3d_uid_file_modern::~auth_3d_uid_file_modern() { - -} - -auth_3d_id::auth_3d_id(uint32_t hash, void* data, object_database* obj_db, texture_database* tex_db) { - id = -1; - - int32_t index = 0; - while (auth_3d_data->data[index].uid != -1 || auth_3d_data->data[index].hash - != hash_murmurhash_empty && auth_3d_data->data[index].hash != -1) - if (++index >= AUTH_3D_DATA_COUNT) + // 0x1401CE730 + void Fog::ctrl(render_context* rctx) { + if (id < 0 || id > FOG_MAX) return; - auto elem = auth_3d_data->uid_files_modern.find(hash); - if (elem == auth_3d_data->uid_files_modern.end()) - elem = auth_3d_data->uid_files_modern.insert({ hash, {} }).first; + fog* data = &rctx->fog[id]; - auth_3d_uid_file_modern* uid_file = &elem->second; - uid_file->load_count = 0; - uid_file->hash = hash; - uid_file->file_name.clear(); - uid_file->file_name.shrink_to_fit(); - uid_file->state = 0; - uid_file->name.clear(); - uid_file->name.shrink_to_fit(); - uid_file->farc = 0; - uid_file->data = data; - uid_file->obj_db = obj_db; - uid_file->tex_db = tex_db; + if (has_start()) { + if (!(backup_flag & FLAG_START)) { + backup_start = data->get_start(); + backup_flag |= FLAG_START; + } - auth_3d_data->data[index].reset(); + data->set_start(start); + } - if (++auth_3d_load_counter < 0) - auth_3d_load_counter = 1; + if (has_end()) { + if (!(backup_flag & FLAG_END)) { + backup_end = data->get_end(); + backup_flag |= FLAG_END; + } - int32_t id = ((auth_3d_load_counter & 0x7FFF) << 16) | index & 0x7FFF; - auth_3d_data->data[index].hash = hash; - auth_3d_data->data[index].id = id; - auth_3d_data->loaded_ids.push_back(id); - this->id = id; -} + data->set_end(end); + } -auth_3d_id::auth_3d_id(int32_t uid, auth_3d_database* auth_3d_db) { - id = -1; + if (has_density()) { + if (!(backup_flag & FLAG_DENSITY)) { + backup_density = data->get_density(); + backup_flag |= FLAG_DENSITY; + } - if (uid >= auth_3d_db->uid.size() || !auth_3d_db->uid[uid].enabled) - return; + data->set_density(density); + } - int32_t index = 0; - while (auth_3d_data->data[index].uid != -1 || auth_3d_data->data[index].hash - != hash_murmurhash_empty && auth_3d_data->data[index].hash != -1) - if (++index >= AUTH_3D_DATA_COUNT) - return; + if (has_color()) { + if (!(backup_flag & FLAG_COLOR)) { + vec4 color; + data->get_color(color); + backup_color = color; + backup_flag |= FLAG_COLOR; + } - auth_3d_data->data[index].reset(); - - if (++auth_3d_load_counter < 0) - auth_3d_load_counter = 1; - - int32_t id = ((auth_3d_load_counter & 0x7FFF) << 16) | index & 0x7FFF; - auth_3d_data->data[index].uid = uid; - auth_3d_data->data[index].id = id; - auth_3d_data->loaded_ids.push_back(id); - this->id = id; -} - -void auth_3d_id::add_event_adapter(a3d::EventAdapter* value) { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id == id) - auth->event_adapter.push_back(value); - } -} - -bool auth_3d_id::check_not_empty() { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id == id) - return auth->id != -1; - } - return false; -} - -bool auth_3d_id::check_loading() { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id == id) - return auth->state == 1; - } - return false; -} - -bool auth_3d_id::check_loaded() { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id == id) - return auth->state == 2; - } - return true; -} - -auth_3d* auth_3d_id::get_auth_3d() { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id == id) - return auth; - } - return 0; -} - -const mat4* auth_3d_id::get_auth_3d_object_mat(size_t index, bool hrc) { - if (id < 0 || (id & 0x7FFF) >= AUTH_3D_DATA_COUNT) - return 0; - - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id != id || !auth->enable) - return 0; - - if (hrc) - return auth_3d_get_auth_3d_object_hrc_bone_mats(auth, index); - return auth_3d_get_auth_3d_object_mat(auth, index); -} - -auth_3d_chara* auth_3d_id::get_chara(size_t auth_chara_id) { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id == id) - if (auth_chara_id < auth->chara.size()) - return &auth->chara[auth_chara_id]; - } - return 0; -} - -size_t auth_3d_id::get_chara_count() { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id == id) - return auth->chara.size(); - } - return -1; -} - -int32_t auth_3d_id::get_chara_id() { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id == id) - return auth->rob_id; - } - return ROB_ID_NULL; -} - -bool auth_3d_id::get_enable() { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id == id) - return auth->enable; - } - return false; -} - -bool auth_3d_id::get_ended() { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id == id) - return auth->ended; - } - return true; -} - -float_t auth_3d_id::get_frame() { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id == id) - return auth->frame; - } - return 0.0f; -} - -float_t auth_3d_id::get_frame_offset() { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id == id) - return auth->frame_offset; - } - return 0.0f; -} - -float_t auth_3d_id::get_last_frame() { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id == id) - return auth->last_frame; - } - return 0.0f; -} - -bool auth_3d_id::get_mirror() { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id == id) - return auth->mirror; - } - return false; -} - -float_t auth_3d_id::get_play_control_begin() { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id == id) - return auth->play_control.begin; - } - return 0.0f; -} - -float_t auth_3d_id::get_play_control_size() { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id == id) - return auth->play_control.size; - } - return 0.0f; -} - -bool auth_3d_id::get_paused() { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id == id) - return auth->paused; - } - return false; -} - -bool auth_3d_id::get_repeat() { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id == id) - return auth->repeat; - } - return false; -} - -int32_t auth_3d_id::get_uid() { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id == id) - return auth->uid; - } - return -1; -} - -void auth_3d_id::read_file(auth_3d_database* auth_3d_db) { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth && auth->id == id) - auth_3d_read_file(auth, auth_3d_db); - } -} - -void auth_3d_id::read_file_modern() { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth && auth->id == id) - auth_3d_read_file_modern(auth); - } -} - -void auth_3d_id::set_alpha_obj_flags(float_t alpha, mdl::ObjFlags obj_flags) { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id == id) { - auth->alpha = alpha; - auth->obj_flags = obj_flags; + data->set_color(color.color); } } -} -void auth_3d_id::set_camera_root_update(bool value) { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id == id) - auth->camera_root_update = value; + // 0x1401CFEB0 + void Fog::dest(render_context* rctx) { + if (id < 0 || id >= FOG_MAX) + return; + + fog* data = &rctx->fog[id]; + if (backup_flag & FLAG_DENSITY) + data->set_density(backup_density); + if (backup_flag & FLAG_START) + data->set_start(backup_start); + if (backup_flag & FLAG_END) + data->set_end(backup_end); + if (backup_flag & FLAG_COLOR) + data->set_color(backup_color); + + init(); } -} -void auth_3d_id::set_chara_id(int32_t value) { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id == id) - auth->rob_id = value; + // 0x1401D4500 + void Fog::get(float_t in_frame) { + if (has_density()) + density = fcurve_density.get(in_frame); + if (has_start()) + start = fcurve_start.get(in_frame); + if (has_end()) + end = fcurve_end.get(in_frame); + if (has_color()) + color.get(in_frame); } -} -void auth_3d_id::set_chara_num(size_t auth_chara_id, int32_t index) { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id == id) - if (auth_chara_id < auth->chara.size()) - auth->chara[auth_chara_id].rob_id = index; + // 0x1401DBB20 + bool Fog::load(const SceneFile& in_file, const a3d::Fog& in_f) { + id = in_f.id; + name.assign(in_f.name); + + if (in_f.flag & a3d::Fog::FLAG_DENSITY) { + fcurve_density.load(in_file, in_f.density); + flag |= FLAG_DENSITY; + } + + if (in_f.flag & a3d::Fog::FLAG_START) { + fcurve_start.load(in_file, in_f.start); + flag |= FLAG_START; + } + + if (in_f.flag & a3d::Fog::FLAG_END) { + fcurve_end.load(in_file, in_f.end); + flag |= FLAG_END; + } + + if (in_f.flag & a3d::Fog::FLAG_COLOR) { + color.load(in_file, in_f.color); + flag |= FLAG_COLOR; + } + return true; } -} -void auth_3d_id::set_chara_item(bool value) { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id == id) - auth->chara_item = value; + // Added + void Fog::store(const SceneFile& in_file, a3d::Fog& out_f) const { + out_f.id = id; + out_f.name.assign(name); + + if (flag & FLAG_DENSITY) { + fcurve_density.store(in_file, out_f.density); + out_f.flag |= a3d::Fog::FLAG_DENSITY; + } + + if (flag & FLAG_START) { + fcurve_start.store(in_file, out_f.start); + out_f.flag |= a3d::Fog::FLAG_START; + } + + if (flag & FLAG_END) { + fcurve_end.store(in_file, out_f.end); + out_f.flag |= a3d::Fog::FLAG_END; + } + + if (flag & FLAG_COLOR) { + color.store(in_file, out_f.color); + out_f.flag |= a3d::Fog::FLAG_COLOR; + } } -} -void auth_3d_id::set_enable(bool value) { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id == id) - auth->enable = value; + // 0x1401BBD30 + Fog& Fog::operator=(const Fog& other) { + flag = other.flag; + backup_flag = other.backup_flag; + id = other.id; + name.assign(other.name); + + fcurve_density = other.fcurve_density; + fcurve_start = other.fcurve_start; + fcurve_end = other.fcurve_end; + + density = other.density; + start = other.start; + end = other.end; + + color = other.color; + + backup_density = other.backup_density; + backup_start = other.backup_start; + backup_end = other.backup_end; + backup_color = other.backup_color; + return *this; } -} -void auth_3d_id::set_frame_rate(FrameRateControl* value) { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id == id) - if (value) - auth->frame_rate = value; + // 0x1401B4730 + HierarchyObject::HierarchyObject() : node_list(), mats(), ex_node_mat(), name(), uid_name(), + obj_uid(), obj_hash(), is_reflect(), is_refract(), has_shadow(), parent_name(), parent_node(), + child_object_list(), child_object_list_parent_node(), + child_object_hrc_list(), child_object_hrc_list_parent_node() { + + } + + // 0x1401B45D0 + HierarchyObject::HierarchyObject(const HierarchyObject& other) : node_list(other.node_list), mats(other.mats), + ex_node_mat(other.ex_node_mat), name(other.name), uid_name(other.uid_name), obj_uid(other.obj_uid), + obj_hash(other.obj_hash), is_reflect(other.is_reflect), is_refract(other.is_refract), + has_shadow(other.has_shadow), parent_name(other.parent_name), parent_node(other.parent_node), + child_object_list(other.child_object_list), + child_object_list_parent_node(other.child_object_list_parent_node), + child_object_hrc_list(other.child_object_hrc_list), + child_object_hrc_list_parent_node(other.child_object_hrc_list_parent_node) { + + } + + // 0x1401B8A80 + HierarchyObject::~HierarchyObject() { + + } + + // 0x1401D72A0 + void HierarchyObject::init() { + name.clear(); + name.shrink_to_fit(); + uid_name.clear(); + uid_name.shrink_to_fit(); + + obj_uid = {}; + obj_hash = (uint32_t)-1; + is_reflect = false; + is_refract = false; + has_shadow = false; + + node_list.clear(); + node_list.shrink_to_fit(); + mats.clear(); + mats.shrink_to_fit(); + parent_name.clear(); + parent_name.shrink_to_fit(); + parent_node.clear(); + parent_node.shrink_to_fit(); + + child_object_list.clear(); + child_object_list.shrink_to_fit(); + child_object_list_parent_node.clear(); + child_object_list_parent_node.shrink_to_fit(); + + child_object_hrc_list.clear(); + child_object_hrc_list.shrink_to_fit(); + child_object_hrc_list_parent_node.clear(); + child_object_hrc_list_parent_node.shrink_to_fit(); + } + + // 0x1401D45A0 + void HierarchyObject::get(float_t in_frame) { + for (TransformNode& i : node_list) + i.get(in_frame); + } + + // 0x1401CE860 + void HierarchyObject::ctrl(const mat4& in_base_mat) { + //if (!node.front().motion_transform.visibility) + // return; + + calc_matrix_hierarchy(in_base_mat); + + TransformNode* node = node_list.data(); + + for (size_t i = 0; i < child_object_list.size(); i++) + child_object_list[i]->ctrl(node[child_object_list_parent_node[i]].motion_transform.matrix); + + for (size_t i = 0; i < child_object_hrc_list.size(); i++) + child_object_hrc_list[i]->ctrl( + node[child_object_hrc_list_parent_node[i]].motion_transform.matrix); + } + + // 0x1401D04A0 + void HierarchyObject::disp(Scene& in_scene, render_context* rctx) { + if (!in_scene.M_is_visible || !node_list.front().motion_transform.visibility) + return; + + mdl::DispManager& disp_manager = *rctx->disp_manager; + const object_database* obj_db = in_scene.obj_db; + const texture_database* tex_db = in_scene.tex_db; + + mdl::ObjFlags flag = mdl::OBJ_SSS; + if (in_scene.M_shadow | has_shadow) + enum_or(flag, mdl::OBJ_4 | mdl::OBJ_SHADOW); + if (is_reflect) + enum_or(flag, mdl::OBJ_NO_TRANSLUCENCY | mdl::OBJ_REFLECT); + if (is_refract) + enum_or(flag, mdl::OBJ_NO_TRANSLUCENCY | mdl::OBJ_REFRACT); + if (in_scene.trnsl < 1.0f) + enum_or(flag, in_scene.trnsl_state); + + disp_manager.set_obj_flags(flag); + disp_manager.set_shadow_group(SHADOW_GROUP_CHARA); + + mat4 mat = mat4_identity; + if (in_scene.M_assign_rob_id >= 0 && in_scene.M_assign_rob_id < ROB_ID_MAX) { + RobManagement* rob_man = get_rob_management(); + if (rob_man->is_init((ROB_ID)in_scene.M_assign_rob_id)) { + rob_chara* rob_chr = rob_man->get_rob((ROB_ID)in_scene.M_assign_rob_id); + mat4_mul(&rob_chr->rob_base.position.rob_mat, + in_scene.M_chara_item + ? &rob_chr->rob_base.adjust.item_mat + : &rob_chr->rob_base.adjust.mat, &mat); + if (in_scene.M_assign_rob_id) + disp_manager.set_shadow_group(SHADOW_GROUP_STAGE); + } + } + else if (flag & mdl::OBJ_SHADOW) { + disp_manager.set_shadow_group(SHADOW_GROUP_STAGE); + + const mat4& root_matrix = get_root_matrix(); + + Shadow* shad = shadow_ptr_get(); + if (shad) { + vec3 pos; + mat4_get_translation(&root_matrix, &pos); + pos.y -= 0.2f; + shad->positions[SHADOW_GROUP_STAGE].push_back(pos); + } + } + + if (mats.size()) + disp_manager.entry_obj_by_object_info_object_skin( + obj_uid, 0, 0, in_scene.trnsl, mats.data(), 0, 0, mat); + + disp_manager.set_obj_flags(); + disp_manager.set_shadow_group(SHADOW_GROUP_CHARA); + + for (Object*& i : child_object_list) + i->disp(in_scene, rctx); + + for (HierarchyObject*& i : child_object_hrc_list) + i->disp(in_scene, rctx); + } + + void HierarchyObject::add_child_object(int32_t in_index, Object* in_obj) { + child_object_list_parent_node.push_back(in_index); + child_object_list.push_back(in_obj); + } + + void HierarchyObject::add_child_object(int32_t in_index, HierarchyObject * in_obj) { + child_object_hrc_list_parent_node.push_back(in_index); + child_object_hrc_list.push_back(in_obj); + } + + // 0x1401CA530 + void HierarchyObject::assign_object_skin() { + const obj_skin* skin = objset_info_storage_get_obj_skin(obj_uid); + if (!skin) { + std::string error_str = sprintf_s_string("%s skin data is not found", uid_name.c_str()); + throw std::runtime_error(error_str.c_str()); + } + + size_t bone_num = 0; + for (TransformNode& i : node_list) { + if (!skin->num_bone) + continue; + + size_t num_bone = skin->num_bone; + for (size_t j = 0; j < num_bone; j++) + if (!i.name.compare(skin->bone_array[j].name)) { + i.node_index = skin->bone_array[j].id; + bone_num++; + break; + } + } + + if (!node_list.size() || !bone_num) { + std::string error_str = sprintf_s_string("%s skin data has no bone", uid_name.c_str()); + throw std::runtime_error(error_str.c_str()); + } + + if (ex_node_mat) { + for (TransformNode& i : node_list) + if (i.node_index >= 0 && (i.node_index & 0x8000)) + i.mat_ptr = &ex_node_mat[i.node_index & 0x7FFF]; + } + else { + if (bone_num != skin->num_bone) + throw std::runtime_error("bone_num mismatch"); + + mats.resize(bone_num); + for (TransformNode& i : node_list) + if (i.node_index >= 0 && !(i.node_index & 0x8000)) + i.mat_ptr = &mats[i.node_index]; + } + } + + // 0x1401CB190 + void HierarchyObject::calc_matrix_hierarchy(const mat4& in_base_mat) { + for (TransformNode& i : node_list) { + i.motion_transform.calc_matrix_local(); + + mat4 mat; + if (i.parent_id >= 0) + mat = node_list[i.parent_id].motion_transform.matrix; else - auth->frame_rate = get_sys_frame_rate(); - } -} + mat = in_base_mat; -void auth_3d_id::set_last_frame(float_t value) { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id == id) - auth->last_frame = value; - } -} - -void auth_3d_id::set_mat(const mat4& value) { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id == id) - auth->mat = value; - } -} - -void auth_3d_id::set_max_frame(float_t value) { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id == id) - auth->max_frame = value; - } -} - -void auth_3d_id::set_mirror(bool value) { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id == id) - auth->mirror = value; - } -} - -void auth_3d_id::set_paused(bool value) { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id == id) - auth->paused = value; - } -} - -void auth_3d_id::set_pos(int32_t value) { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id == id) - auth->pos = value; - } -} - -void auth_3d_id::set_reflect(bool value) { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id == id) - auth->reflect = value; - } -} - -void auth_3d_id::set_repeat(bool value) { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id == id) - auth->repeat = value; - } -} - -void auth_3d_id::set_req_frame(float_t value) { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id == id) { - auth->req_frame = value; - auth->frame_changed = true; + i.calc_matrix_local(mat); } } -} -void auth_3d_id::set_shadow(bool value) { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id == id) - auth->shadow = value; + // 0x1401E3510 + bool HierarchyObject::replace_chara(int32_t in_cn_src, int32_t in_cn_dst, const object_database* obj_db) { + if (in_cn_src < 0 || in_cn_src >= CN_MAX + || in_cn_dst < 0 || in_cn_dst >= CN_MAX || in_cn_src == in_cn_dst) + return false; + + std::string cn_src_str(get_char_id_str((CHARA_NUM)in_cn_src)); + std::string cn_dst_str(get_char_id_str((CHARA_NUM)in_cn_dst)); + + std::string uid_name(this->uid_name); + size_t pos = uid_name.find(cn_src_str); + if (pos != -1) + uid_name.assign(uid_name.replace(pos, cn_src_str.size(), cn_dst_str)); + + object_info obj_uid = obj_db->get_object_info(uid_name.c_str()); + if (obj_uid.not_null()) { + this->obj_uid = obj_uid; + this->uid_name.assign(uid_name); + return true; + } + return false; } -} -void auth_3d_id::set_src_dst_chara(int32_t src_chara, int32_t dst_chara) { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id == id) { - auth->src_chara = src_chara; - auth->dst_chara = dst_chara; + // 0x1401CC0B0 + void HierarchyObject::check_rob_chara(const std::string& in_name) { + static std::string chara_str("_CHARA"); + static std::string exchr_str("_EXCHR"); + + for (TransformNode& i : node_list) { + if (i.name.find(chara_str) == -1) { + if (i.name.find(exchr_str.c_str()) == -1) + continue; + + std::string chr = i.name.substr(i.name.find(exchr_str) + exchr_str.size()) + "____"; + if (in_name.size() && chr.find(in_name) == -1 || !in_name.size()) + i.motion_transform.init_static(); + } + else { + std::string chr = i.name.substr(i.name.find(chara_str) + chara_str.size()); + if (in_name.size() && chr.find(in_name) == -1) + i.motion_transform.init_static(); + } } } -} -void auth_3d_id::set_visibility(bool value) { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id == id) - auth->visible = value; + // 0x1401D5EB0 + const mat4& HierarchyObject::get_root_matrix() const { + for (const TransformNode& i : node_list) + if (i.mat_ptr) + return *i.mat_ptr; + + return node_list.front().motion_transform.matrix; } -} -void auth_3d_id::unload(render_context* rctx) { - if (id < 0 || (id & 0x7FFF) >= AUTH_3D_DATA_COUNT) - return; + // 0x1401D8D20 + void HierarchyObject::join(const HierarchyObject& in_other, float_t in_blend, float_t in_inv_blend) { + if (node_list.size() != in_other.node_list.size()) + return; - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (!auth || auth->id != id) - return; + for (size_t i = 0; i < node_list.size(); i++) + node_list[i].motion_transform.join( + in_other.node_list[i].motion_transform, in_blend, in_inv_blend); + } - for (auto i = auth_3d_data->loaded_ids.begin(); i != auth_3d_data->loaded_ids.end();) { - if (*i != id) { - i++; - continue; + // 0x1401D93B0 + void HierarchyObject::join_lock(const HierarchyObject& in_other, float_t in_blend, float_t in_inv_blend) { + if (node_list.size() != in_other.node_list.size()) + return; + + for (size_t i = 0; i < node_list.size(); i++) + node_list[i].motion_transform.join_lock( + in_other.node_list[i].motion_transform, in_blend, in_inv_blend); + } + + // 0x1401E1340 + void HierarchyObject::lock_set() { + for (TransformNode& i : node_list) + i.motion_transform.lock_set(); + } + + // 0x1401E5F30 + int32_t HierarchyObject::query_node_index(const char* in_name) const { + for (const TransformNode& i : node_list) + if (!i.name.compare(in_name)) + return (int32_t)(&i - node_list.data()); + return -1; + } + + // 0x1401E69E0 + void HierarchyObject::set_obj_uid(object_info objuid) { + if (objuid.not_null()) + obj_uid = objuid; + assign_object_skin(); + } + + // 0x1401DBED0 + bool HierarchyObject::load(const SceneFile& in_file, + const a3d::ObjectHrc& in_oh, const object_database* obj_db) { + name.assign(in_oh.name); + uid_name.assign(in_oh.uid_name); + + obj_uid = obj_db->get_object_info(uid_name.c_str()); + obj_hash = hash_string_murmurhash(uid_name); + + static std::string reflect_str = "_REFLECT"; + is_reflect = uid_name.find(reflect_str) != -1; + + static std::string refract_str = "_REFRACT"; + is_refract = uid_name.find(refract_str) != -1; + + has_shadow = in_oh.shadow; + + list_load(node_list, in_file, in_oh.node); + + parent_name.assign(in_oh.parent_name); + parent_node.assign(in_oh.parent_node); + + int32_t node_index = 0; + for (TransformNode& i : node_list) { + if (i.parent_id >= node_index) + throw std::range_error("parent_id is not less than child"); + node_index++; + } + return true; + } + + // Added + void HierarchyObject::store(const SceneFile& in_file, a3d::ObjectHrc& out_oh) const { + out_oh.name.assign(name); + out_oh.uid_name.assign(uid_name); + + out_oh.shadow = has_shadow; + + list_store(node_list, in_file, out_oh.node); + + out_oh.parent_name.assign(parent_name); + out_oh.parent_node.assign(parent_node); + } + + // 0x1401BBF50 + HierarchyObject& HierarchyObject::operator=(const HierarchyObject& other) { + node_list.assign(other.node_list.begin(), other.node_list.end()); + mats.assign(other.mats.begin(), other.mats.end()); + ex_node_mat = other.ex_node_mat; + name.assign(other.name); + uid_name.assign(other.uid_name); + obj_uid = other.obj_uid; + obj_hash = other.obj_hash; + is_reflect = other.is_reflect; + is_refract = other.is_refract; + has_shadow = other.has_shadow; + parent_name.assign(other.parent_name); + parent_node.assign(other.parent_node); + child_object_list.assign( + other.child_object_list.begin(), other.child_object_list.end()); + child_object_list_parent_node.assign( + other.child_object_list_parent_node.begin(), other.child_object_list_parent_node.end()); + child_object_hrc_list.assign( + other.child_object_hrc_list.begin(), other.child_object_hrc_list.end()); + child_object_hrc_list_parent_node.assign( + other.child_object_hrc_list_parent_node.begin(), other.child_object_hrc_list_parent_node.end()); + return *this; + } + + // 0x1401B4B20 + Light::Light() : flag(), backup_flag(), id(), name(), type(), position(), spot_direction(), + ambient(), diffuse(), specular(), tone_curve(), fcurve_constant(), fcurve_intensity(), fcurve_far(), + fcurve_linear(), fcurve_quadratic(), fcurve_drop_off(), fcurve_cone_angle(), constant(), intensity(), + far_(), linear(), quadratic(), drop_off(), cone_angle(), backup_ambient(), backup_diffuse(), + backup_specular(), backup_tone_curve(), backup_constant(), backup_intensity(), backup_far(), + backup_linear(), backup_quadratic(), backup_drop_off(), backup_cone_angle() { + + } + + // 0x1401B4840 + Light::Light(const Light& other) : flag(other.flag), backup_flag(other.backup_flag), id(other.id), + name(other.name), type(other.type), position(other.position), spot_direction(other.spot_direction), + ambient(other.ambient), diffuse(other.diffuse), specular(other.specular), tone_curve(other.tone_curve), + fcurve_constant(other.fcurve_constant), fcurve_intensity(other.fcurve_intensity), + fcurve_far(other.fcurve_far), fcurve_linear(other.fcurve_linear), fcurve_quadratic(other.fcurve_quadratic), + fcurve_drop_off(other.fcurve_drop_off), fcurve_cone_angle(other.fcurve_cone_angle), constant(other.constant), + intensity(other.intensity), far_(other.far_), linear(other.linear), quadratic(other.quadratic), + drop_off(other.drop_off), cone_angle(other.cone_angle), + backup_ambient(other.backup_ambient), backup_diffuse(other.backup_diffuse), + backup_specular(other.backup_specular), backup_tone_curve(other.backup_tone_curve), + backup_constant(other.backup_constant), backup_intensity(other.backup_intensity), + backup_far(other.backup_far), backup_linear(other.backup_linear), backup_quadratic(other.backup_quadratic), + backup_drop_off(other.backup_drop_off), backup_cone_angle(other.backup_cone_angle) { + + } + + // 0x1401B8C30 + Light::~Light() { + + } + + // 0x1401D7450 + void Light::init() { + id = -1; + flag = 0; + backup_flag = 0; + + name.assign("(init)"); + type.assign("(init)"); + + position.init(); + spot_direction.init(); + } + + // 0x1401CEA90 + void Light::ctrl(render_context* rctx) { + light_set* set = &rctx->light_set[LIGHT_SET_MAIN]; + + if (has_ambient()) { + if (!(backup_flag & FLAG_AMBIENT)) { + vec4 ambient; + set->lights[id].get_ambient(ambient); + backup_ambient = ambient; + backup_flag |= FLAG_AMBIENT; + } + + set->lights[id].set_ambient(ambient.color, ambient.has_color); } - i = auth_3d_data->loaded_ids.erase(i); - auth->unload(rctx); - break; + if (has_diffuse()) { + if (!(backup_flag & FLAG_DIFFUSE)) { + vec4 diffuse; + set->lights[id].get_diffuse(diffuse); + backup_diffuse = diffuse; + backup_flag |= FLAG_DIFFUSE; + } + + set->lights[id].set_diffuse(diffuse.color, diffuse.has_color); + } + + if (has_specular()) { + if (!(backup_flag & FLAG_SPECULAR)) { + vec4 specular; + set->lights[id].get_specular(specular); + backup_specular = specular; + backup_flag |= FLAG_SPECULAR; + } + + set->lights[id].set_specular(specular.color, specular.has_color); + } + + if (has_tone_curve()) { + if (!(backup_flag & FLAG_TONE_CURVE)) { + set->lights[id].get_tone_curve(backup_tone_curve); + backup_flag |= FLAG_TONE_CURVE; + } + + light_tone_curve curve; + curve.start_point = tone_curve.color.x; + curve.end_point = tone_curve.color.y; + curve.coefficient = tone_curve.color.z; + set->lights[id].set_tone_curve(curve); + } + + if (id >= 0 && id < LIGHT_MAX) { + light_data* data = &set->lights[id]; + data->set_position(position.translation); + data->set_spot_direction(spot_direction.translation); + } } -} -auth_3d_data_struct::auth_3d_data_struct() { + // 0x1401CFF60 + void Light::dest(render_context* rctx) { + light_set* set = &rctx->light_set[LIGHT_SET_MAIN]; -} + if (backup_flag & FLAG_AMBIENT) + set->lights[id].set_ambient(backup_ambient); + if (backup_flag & FLAG_DIFFUSE) + set->lights[id].set_diffuse(backup_diffuse); + if (backup_flag & FLAG_SPECULAR) + set->lights[id].set_specular(backup_specular); + if (backup_flag & FLAG_TONE_CURVE) + set->lights[id].set_tone_curve(backup_tone_curve); -auth_3d_data_struct::~auth_3d_data_struct() { + init(); + } + // 0x1401DCA70 + bool Light::load(const SceneFile& in_file, const a3d::Light& in_l) { + id = in_l.id; + name.assign(in_l.name); + type.assign(in_l.type); + + position.load(in_file, in_l.position); + spot_direction.load(in_file, in_l.spot_direction); + + if (in_l.flag & a3d::Light::FLAG_AMBIENT) { + ambient.load(in_file, in_l.ambient); + flag |= FLAG_AMBIENT; + } + + if (in_l.flag & a3d::Light::FLAG_DIFFUSE) { + diffuse.load(in_file, in_l.diffuse); + flag |= FLAG_DIFFUSE; + } + + if (in_l.flag & a3d::Light::FLAG_SPECULAR) { + specular.load(in_file, in_l.specular); + flag |= FLAG_SPECULAR; + } + + if (in_l.flag & a3d::Light::FLAG_TONE_CURVE) { + tone_curve.load(in_file, in_l.tone_curve); + flag |= FLAG_TONE_CURVE; + } + + /// XHD + if (in_l.flag & a3d::Light::FLAG_CONSTANT) { + fcurve_constant.load(in_file, in_l.constant); + flag |= FLAG_CONSTANT; + } + + /// XHD + if (in_l.flag & a3d::Light::FLAG_INTENSITY) { + fcurve_intensity.load(in_file, in_l.intensity); + flag |= FLAG_INTENSITY; + } + + /// XHD + if (in_l.flag & a3d::Light::FLAG_FAR) { + fcurve_far.load(in_file, in_l.far_); + flag |= FLAG_FAR; + } + + /// XHD + if (in_l.flag & a3d::Light::FLAG_LINEAR) { + fcurve_linear.load(in_file, in_l.linear); + flag |= FLAG_LINEAR; + } + + /// XHD + if (in_l.flag & a3d::Light::FLAG_QUADRATIC) { + fcurve_quadratic.load(in_file, in_l.quadratic); + flag |= FLAG_QUADRATIC; + } + + /// XHD + if (in_l.flag & a3d::Light::FLAG_DROP_OFF) { + fcurve_drop_off.load(in_file, in_l.drop_off); + flag |= FLAG_DROP_OFF; + } + + /// XHD + if (in_l.flag & a3d::Light::FLAG_CONE_ANGLE) { + fcurve_cone_angle.load(in_file, in_l.cone_angle); + flag |= FLAG_CONE_ANGLE; + } + return true; + } + + // Added + void Light::store(const SceneFile& in_file, a3d::Light& out_l) const { + out_l.id = id; + out_l.name.assign(name); + out_l.type.assign(type); + + position.store(in_file, out_l.position); + spot_direction.store(in_file, out_l.spot_direction); + + if (flag & FLAG_AMBIENT) { + ambient.store(in_file, out_l.ambient); + out_l.flag |= a3d::Light::FLAG_AMBIENT; + } + + if (flag & FLAG_DIFFUSE) { + diffuse.store(in_file, out_l.diffuse); + out_l.flag |= a3d::Light::FLAG_DIFFUSE; + } + + if (flag & FLAG_SPECULAR) { + specular.store(in_file, out_l.specular); + out_l.flag |= a3d::Light::FLAG_SPECULAR; + } + + if (flag & FLAG_TONE_CURVE) { + tone_curve.store(in_file, out_l.tone_curve); + out_l.flag |= a3d::Light::FLAG_TONE_CURVE; + } + + /// XHD + if (flag & FLAG_CONSTANT) { + fcurve_constant.store(in_file, out_l.constant); + out_l.flag |= a3d::Light::FLAG_CONSTANT; + } + + /// XHD + if (flag & FLAG_INTENSITY) { + fcurve_intensity.store(in_file, out_l.intensity); + out_l.flag |= a3d::Light::FLAG_INTENSITY; + } + + /// XHD + if (flag & FLAG_FAR) { + fcurve_far.store(in_file, out_l.far_); + out_l.flag |= a3d::Light::FLAG_FAR; + } + + /// XHD + if (flag & FLAG_LINEAR) { + fcurve_linear.store(in_file, out_l.linear); + out_l.flag |= a3d::Light::FLAG_LINEAR; + } + + /// XHD + if (flag & FLAG_QUADRATIC) { + fcurve_quadratic.store(in_file, out_l.quadratic); + out_l.flag |= a3d::Light::FLAG_QUADRATIC; + } + + /// XHD + if (flag & FLAG_DROP_OFF) { + fcurve_drop_off.store(in_file, out_l.drop_off); + out_l.flag |= a3d::Light::FLAG_DROP_OFF; + } + + /// XHD + if (flag & FLAG_CONE_ANGLE) { + fcurve_cone_angle.store(in_file, out_l.cone_angle); + out_l.flag |= a3d::Light::FLAG_CONE_ANGLE; + } + } + + // 0x1401D45F0 + void Light::get(float_t in_frame) { + position.get(in_frame); + spot_direction.get(in_frame); + + if (has_ambient()) + ambient.get(in_frame); + if (has_diffuse()) + diffuse.get(in_frame); + if (has_specular()) + specular.get(in_frame); + if (has_tone_curve()) + tone_curve.get(in_frame); + + /// XHD + if (has_constant()) + constant = fcurve_constant.get(in_frame); + if (has_intensity()) + intensity = fcurve_intensity.get(in_frame); + if (has_far()) + far_ = fcurve_far.get(in_frame); + if (has_linear()) + linear = fcurve_linear.get(in_frame); + if (has_quadratic()) + quadratic = fcurve_quadratic.get(in_frame); + if (has_drop_off()) + drop_off = fcurve_drop_off.get(in_frame); + if (has_cone_angle()) + cone_angle = fcurve_cone_angle.get(in_frame); + } + + // 0x1401BC060 + Light& Light::operator=(const Light& other) { + flag = other.flag; + backup_flag = other.backup_flag; + id = other.id; + name.assign(other.name); + type.assign(other.type); + + position = other.position; + spot_direction = other.spot_direction; + ambient = other.ambient; + diffuse = other.diffuse; + specular = other.specular; + tone_curve = other.tone_curve; + + /// XHD + fcurve_constant = other.fcurve_constant; + fcurve_intensity = other.fcurve_intensity; + fcurve_far = other.fcurve_far; + fcurve_linear = other.fcurve_linear; + fcurve_quadratic = other.fcurve_quadratic; + fcurve_drop_off = other.fcurve_drop_off; + fcurve_cone_angle = other.fcurve_cone_angle; + + /// XHD + constant = other.constant; + intensity = other.intensity; + far_ = other.far_; + linear = other.linear; + quadratic = other.quadratic; + drop_off = other.drop_off; + cone_angle = other.cone_angle; + + backup_ambient = other.backup_ambient; + backup_diffuse = other.backup_diffuse; + backup_specular = other.backup_specular; + backup_tone_curve = other.backup_tone_curve; + + /// XHD + backup_constant = other.backup_constant; + backup_intensity = other.backup_intensity; + backup_far = other.backup_far; + backup_linear = other.backup_linear; + backup_quadratic = other.backup_quadratic; + backup_drop_off = other.backup_drop_off; + backup_cone_angle = other.backup_cone_angle; + return *this; + } + + // X/XHD + MaterialList::MaterialList() : flag(), name(), hash(hash_murmurhash_empty), + emission(), blend_color(), fcurve_glow_intensity(), glow_intensity() { + + } + + // X/XHD + MaterialList::MaterialList(const MaterialList& other) : flag(other.flag), name(other.name), + hash(other.hash), emission(other.emission), blend_color(other.blend_color), + fcurve_glow_intensity(other.fcurve_glow_intensity), glow_intensity(other.glow_intensity) { + + } + + // X/XHD + MaterialList::~MaterialList() { + + } + + // X/XHD + void MaterialList::init() { + flag = 0; + name.clear(); + name.shrink_to_fit(); + hash = hash_murmurhash_empty; + + fcurve_glow_intensity.init(); + } + + // X/XHD + void MaterialList::get(float_t in_frame) { + if (has_emission()) + emission.get(in_frame); + if (has_blend_color()) + blend_color.get(in_frame); + if (has_glow_intensity()) + glow_intensity = fcurve_glow_intensity.get(in_frame); + } + + // X/XHD + bool MaterialList::load(const SceneFile& in_file, const a3d::MaterialList& in_ml) { + name.assign(in_ml.name); + hash = hash_string_murmurhash(name); + + if (in_ml.flag & a3d::MaterialList::FLAG_EMISSION) { + emission.load(in_file, in_ml.emission); + flag |= FLAG_EMISSION; + } + + if (in_ml.flag & a3d::MaterialList::FLAG_BLEND_COLOR) { + blend_color.load(in_file, in_ml.blend_color); + flag |= FLAG_BLEND_COLOR; + } + + if (in_ml.flag & a3d::MaterialList::FLAG_GLOW_INTENSITY) { + fcurve_glow_intensity.load(in_file, in_ml.glow_intensity); + flag |= FLAG_GLOW_INTENSITY; + } + return true; + } + + // X/XHD, Added + void MaterialList::store(const SceneFile& in_file, a3d::MaterialList& out_ml) const { + out_ml.name.assign(name); + + if (flag & FLAG_EMISSION) { + emission.store(in_file, out_ml.emission); + out_ml.flag |= a3d::MaterialList::FLAG_EMISSION; + } + + if (flag & FLAG_BLEND_COLOR) { + blend_color.store(in_file, out_ml.blend_color); + out_ml.flag |= a3d::MaterialList::FLAG_BLEND_COLOR; + } + + if (flag & FLAG_GLOW_INTENSITY) { + fcurve_glow_intensity.store(in_file, out_ml.glow_intensity); + out_ml.flag |= a3d::MaterialList::FLAG_GLOW_INTENSITY; + } + } + + // X/XHD + MaterialList& MaterialList::operator=(const MaterialList & other) { + flag = other.flag; + name.assign(other.name); + hash = other.hash; + + emission = other.emission; + blend_color = other.blend_color; + fcurve_glow_intensity = other.fcurve_glow_intensity; + + glow_intensity = other.glow_intensity; + return *this; + } + + // 0x1401B5100 + Motion::Motion() : name() { + + } + + // 0x1401B50C0 + Motion::Motion(const Motion& other) : name(other.name) { + + } + + // 0x1401B8DB0 + Motion::~Motion() { + + } + + // 0x1401DD2E0 + bool Motion::load(const SceneFile& in_file, const a3d::Motion& in_m) { + name.assign(in_m.name); + return true; + } + + // Added + void Motion::store(const SceneFile& in_file, a3d::Motion& out_m) const { + out_m.name.assign(name); + } + + // 0x1401BC3A0 + Motion& Motion::operator=(const Motion& other) { + name.assign(other.name); + return *this; + } + + // 0x1401B5550 + MotionTransform::MotionTransform() : matrix(), matrix_local(), fcurve_translation(), + fcurve_rotation(), fcurve_scale(), fcurve_visibility(), translation(0.0f), rotation(0.0f), scale(1.0f), + visibility(false), rot(), trans_lock(0.0f), rot_lock(), scale_lock(1.0f), frame(-1.0f), + update_rot(), matrix_local_ready(), has_scale(), has_visibility() { + matrix = mat4_identity; + matrix_local = mat4_identity; + rot = mat4_identity; + rot = mat4_identity; + } + + // 0x1401B5120 + MotionTransform::MotionTransform(const MotionTransform& other) : matrix(other.matrix), + matrix_local(other.matrix_local), fcurve_translation(other.fcurve_translation), + fcurve_rotation(other.fcurve_rotation), fcurve_scale(other.fcurve_scale), + fcurve_visibility(other.fcurve_visibility), translation(other.translation), + rotation(other.rotation), scale(other.scale), visibility(other.visibility), rot(other.rot), + trans_lock(other.trans_lock), rot_lock(other.rot_lock), scale_lock(other.scale_lock), + frame(other.frame), update_rot(other.update_rot), matrix_local_ready(other.matrix_local_ready), + has_scale(other.has_scale), has_visibility(other.has_visibility) { + + } + + // 0x1401B8DF0 + MotionTransform::~MotionTransform() { + + } + + // 0x1401D47F0 + void MotionTransform::get(float_t in_frame) { + if (frame != in_frame || update_rot) { + translation = fcurve_translation.get(in_frame); + rotation = fcurve_rotation.get(in_frame); + + if (has_scale) + scale = fcurve_scale.get(in_frame); + + if (has_visibility) + visibility = fcurve_visibility.get(in_frame) >= 0.999f; + + mat4_rotate_zyx(&rotation, &rot); + + frame = in_frame; + update_rot = false; + matrix_local_ready = false; + } + + if (matrix_local_ready && !update_rot) + return; + + } + + // 0x1401D7550 + void MotionTransform::init() { + matrix = mat4_identity; + matrix_local = mat4_identity; + + fcurve_translation.init(); + fcurve_rotation.init(); + fcurve_scale.init(); + fcurve_visibility.init(); + + rot = mat4_identity; + + frame = -1.0f; + update_rot = false; + matrix_local_ready = false; + has_scale = false; + has_visibility = false; + } + + // 0x1401D8900 + void MotionTransform::init_static() { + matrix = mat4_identity; + matrix_local = mat4_identity; + + fcurve_translation.init(0.0f); + fcurve_rotation.init(0.0f); + fcurve_scale.init(1.0f); + fcurve_visibility.init(1.0f); + + rot = mat4_identity; + + frame = -1.0f; + update_rot = false; + matrix_local_ready = false; + has_scale = false; + has_visibility = false; + } + + // 0x1401CADD0 + void MotionTransform::calc_matrix(const mat4& in_mat) { + mat4_mul(&matrix_local, &in_mat, &matrix); + } + + // 0x1401CB020 + void MotionTransform::calc_matrix_local() { + if (!matrix_local_ready || update_rot) { + mat4_translate(&translation, &matrix_local); + mat4_mul(&rot, &matrix_local, &matrix_local); + if (has_scale) + mat4_scale_rot(&matrix_local, &scale, &matrix_local); + matrix_local_ready = true; + } + } + + // 0x1401CC4A0 + void MotionTransform::check_scale() { + if (fcurve_scale.x.m_type == FC_TYPE_STATIC_DATA + && fabsf(1.0f - fcurve_scale.x.m_static_value) <= 0.000001f + && fcurve_scale.y.m_type == FC_TYPE_STATIC_DATA + && fabsf(1.0f - fcurve_scale.y.m_static_value) <= 0.000001f + && fcurve_scale.z.m_type == FC_TYPE_STATIC_DATA + && fabsf(1.0f - fcurve_scale.z.m_static_value) <= 0.000001f) { + has_scale = false; + scale = 1.0f; + } + else + has_scale = true; + } + + // 0x1401CC8C0 + void MotionTransform::check_visibility() { + if (fcurve_visibility.m_type == FC_TYPE_STATIC_DATA) { + has_visibility = false; + visibility = fcurve_visibility.m_static_value >= 0.999f; + } + else + has_visibility = true; + } + + // 0x1401D8E60 + void MotionTransform::join(const MotionTransform& in_mt1, + const MotionTransform& in_mt2, float_t in_inv_blend, float_t in_blend) { + translation = in_mt2.translation * in_blend + in_mt1.translation * in_inv_blend; + mat4_blend_rotation(&in_mt2.rot, &in_mt1.rot, &rot, in_blend); + if (has_scale) + scale = in_mt2.scale * in_blend + in_mt1.scale * in_inv_blend; + update_rot = true; + } + + // 0x1401D9020 + void MotionTransform::join( + const MotionTransform& in_mt1, float_t in_inv_blend, float_t in_blend) { + translation = in_mt1.translation * in_blend + translation * in_inv_blend; + mat4_blend_rotation(&rot, &in_mt1.rot, &rot, in_blend); + if (has_scale) + scale = in_mt1.scale * in_blend + scale * in_inv_blend; + update_rot = true; + } + + // 0x1401D94F0 + void MotionTransform::join_lock(const MotionTransform& in_mt1, + const MotionTransform& in_mt2, float_t in_inv_blend, float_t in_blend) { + translation = in_mt2.trans_lock * in_blend + in_mt1.translation * in_inv_blend; + mat4_blend_rotation(&in_mt2.rot_lock, &in_mt1.rot, &rot, in_blend); + if (has_scale) + scale = in_mt2.scale_lock * in_blend + in_mt1.scale * in_inv_blend; + update_rot = true; + } + + // 0x1401D96B0 + void MotionTransform::join_lock( + const MotionTransform& in_mt1, float_t in_inv_blend, float_t in_blend) { + translation = in_mt1.trans_lock * in_blend + translation * in_inv_blend; + mat4_blend_rotation(&in_mt1.rot_lock, &rot, &rot, in_blend); + if (has_scale) + scale = in_mt1.scale_lock * in_blend + scale * in_inv_blend; + update_rot = true; + } + + // 0x1401E1380 + void MotionTransform::lock_set() { + trans_lock = translation; + rot_lock = rot; + if (has_scale) + scale_lock = scale; + } + + // 0x1401C8FF0 + void MotionTransform::add( + const MotionTransform& in_mt1, const MotionTransform& in_mt2) { + translation = in_mt1.translation + in_mt2.translation; + mat4_mul(&in_mt2.rot, &in_mt1.rot, &rot); + if (has_scale) + scale = in_mt1.scale * in_mt2.scale; + update_rot = true; + } + + // 0x1401E7B00 + void MotionTransform::sub( + const MotionTransform& in_mt1, const MotionTransform& in_mt2) { + translation = in_mt1.translation - in_mt2.translation; + mat4_mul(&in_mt1.rot, &in_mt2.rot, &rot); + if (has_scale) + scale = in_mt1.scale / in_mt2.scale; + update_rot = true; + } + + // 0x1401DD3B0 + bool MotionTransform::load(const SceneFile& in_file, const a3d::ModelTransform& in_mt) { + fcurve_translation.load(in_file, in_mt.translation); + fcurve_rotation.load(in_file, in_mt.rotation); + fcurve_scale.load(in_file, in_mt.scale); + fcurve_visibility.load(in_file, in_mt.visibility); + + check_scale(); + check_visibility(); + return true; + } + + // Added + void MotionTransform::store(const SceneFile& in_file, a3d::ModelTransform& out_mt) const { + fcurve_translation.store(in_file, out_mt.translation); + fcurve_rotation.store(in_file, out_mt.rotation); + fcurve_scale.store(in_file, out_mt.scale); + fcurve_visibility.store(in_file, out_mt.visibility); + } + + // 0x1401BC3D0 + MotionTransform& MotionTransform::operator=(const MotionTransform& other) { + matrix = other.matrix; + matrix_local = other.matrix_local; + + fcurve_translation = other.fcurve_translation; + fcurve_rotation = other.fcurve_rotation; + fcurve_scale = other.fcurve_scale; + fcurve_visibility = other.fcurve_visibility; + + translation = other.translation; + rotation = other.rotation; + scale = other.scale; + visibility = other.visibility; + + rot = other.rot; + + trans_lock = other.trans_lock; + rot_lock = other.rot_lock; + scale_lock = other.scale_lock; + + frame = other.frame; + update_rot = other.update_rot; + matrix_local_ready = other.matrix_local_ready; + has_scale = other.has_scale; + has_visibility = other.has_visibility; + return *this; + } + + // 0x1401B5950 + MultiHierarchyObject::MultiHierarchyObject() : name(), motion_transform(), node_list(), instance_list() { + + } + + // 0x1401B58C0 + MultiHierarchyObject::MultiHierarchyObject(const MultiHierarchyObject& other) : name(other.name), + motion_transform(other.motion_transform), node_list(other.node_list), instance_list(other.instance_list) { + + } + + // 0x1401B8E50 + MultiHierarchyObject::~MultiHierarchyObject() { + + } + + // 0x1401D7620 + void MultiHierarchyObject::init() { + name.clear(); + name.shrink_to_fit(); + node_list.clear(); + node_list.shrink_to_fit(); + instance_list.clear(); + instance_list.shrink_to_fit(); + } + + // 0x1401D49B0 + void MultiHierarchyObject::get(float_t in_frame) { + motion_transform.get(in_frame); + motion_transform.calc_matrix_local(); + + for (ObjectInstance& i : instance_list) + i.get(in_frame); + for (TransformNode& i : node_list) + i.get(in_frame); + } + + // 0x1401CEC40 + void MultiHierarchyObject::ctrl(const mat4& in_base_mat) { + //if (!motion_transform.visibility) + // return; + + TransformNode* node = node_list.data(); + + calc_matrix_hierarchy(); + + motion_transform.calc_matrix(in_base_mat); + + mat4& mat = motion_transform.matrix; + + for (ObjectInstance& i : instance_list) { + //if (!i.motion_transform.visibility) + // continue; + + i.motion_transform.calc_matrix(mat); + int32_t* matrix_id = i.matrix_id.data(); + size_t matrix_id_count = i.matrix_id.size(); + mat4* mats = i.mats.data(); + for (size_t j = 0; j < matrix_id_count; j++) + mats[j] = node[matrix_id[j]].motion_transform.matrix; + } + } + + // 0x1401D0760 + void MultiHierarchyObject::disp(Scene& in_scene, render_context* rctx) { + if (!in_scene.M_is_visible || !motion_transform.visibility) + return; + + mdl::DispManager& disp_manager = *rctx->disp_manager; + + const mat4& root_matrix = get_root_matrix(); + + for (ObjectInstance& i : instance_list) { + if (!i.motion_transform.visibility) + continue; + + mdl::ObjFlags flag = mdl::OBJ_SSS; + SHADOW_GROUP shadow_group = SHADOW_GROUP_CHARA; + if (in_scene.M_shadow || i.shadow) { + enum_or(flag, mdl::OBJ_4 | mdl::OBJ_SHADOW); + shadow_group = SHADOW_GROUP_STAGE; + } + if (in_scene.trnsl < 1.0f) + enum_or(flag, in_scene.trnsl_state); + + disp_manager.set_obj_flags(flag); + disp_manager.set_shadow_group(shadow_group); + + Shadow* shad = shadow_ptr_get(); + if (shad && (flag & mdl::OBJ_SHADOW)) { + disp_manager.set_shadow_group(SHADOW_GROUP_STAGE); + + mat4 mat; + mat4_mul(&i.motion_transform.matrix, &root_matrix, &mat); + + vec3 pos; + mat4_get_translation(&mat, &pos); + pos.y -= 0.2f; + shad->positions[shadow_group].push_back(pos); + } + + if (i.mats.size()) + disp_manager.entry_obj_by_object_info_object_skin( + i.obj_uid, 0, 0, in_scene.trnsl, i.mats.data(), 0, 0, i.motion_transform.matrix); + } + + disp_manager.set_obj_flags(); + disp_manager.set_shadow_group(SHADOW_GROUP_CHARA); + } + + // 0x1401CAE40 + void MultiHierarchyObject::calc_matrix_hierarchy() { + TransformNode* node = node_list.data(); + + for (TransformNode& i : node_list) + if (i.parent_id >= 0) + i.motion_transform.calc_matrix(node[i.parent_id].motion_transform.matrix); + else + i.motion_transform.matrix = i.motion_transform.matrix_local; + } + + // 0x1401CB0A0 + void MultiHierarchyObject::calc_matrix_local() { + for (TransformNode& i : node_list) + i.motion_transform.calc_matrix_local(); + } + + // 0x1401D5F20 + const mat4& MultiHierarchyObject::get_root_matrix() const { + for (const TransformNode& i : node_list) + if (i.mat_ptr) + return *i.mat_ptr; + + return node_list.front().motion_transform.matrix; + } + + // 0x1401DD710 + bool MultiHierarchyObject::load(const SceneFile& in_file, + const a3d::MObjectHrc& in_moh, const object_database* obj_db) { + name.assign(in_moh.name); + motion_transform.load(in_file, in_moh.model_transform); + + list_load(node_list, in_file, in_moh.node); + list_load(instance_list, in_file, in_moh.instance, *this, obj_db); + + int32_t node_index = 0; + for (TransformNode& i : node_list) { + if (i.parent_id >= node_index) + throw std::range_error("parent_id is not less than child"); + node_index++; + } + return true; + } + + // Added + void MultiHierarchyObject::store(const SceneFile& in_file, a3d::MObjectHrc& out_moh) const { + out_moh.name.assign(name); + motion_transform.store(in_file, out_moh.model_transform); + + list_store(node_list, in_file, out_moh.node); + list_store(instance_list, in_file, out_moh.instance, *this); + } + + // 0x1401BC7F0 + MultiHierarchyObject& MultiHierarchyObject::operator=(const MultiHierarchyObject& other) { + name.assign(other.name); + motion_transform = other.motion_transform; + node_list.assign(other.node_list.begin(), other.node_list.end()); + instance_list.assign(other.instance_list.begin(), other.instance_list.end()); + return *this; + } + + // 0x1401B5BD0 + Object::Object() : model_transform(), index(), name(), uid_name(), parent_name(), parent_node(), + obj_pat(), obj_morph(), texture_list(), texture_transform_list(), child_object_list(), + child_object_hrc_list(), obj_uid(), obj_hash(hash_murmurhash_empty), is_reflect(), is_refract() { + + } + + // 0x1401B59C0 + Object::Object(const Object& other) : model_transform(other.model_transform), index(other.index), + name(other.name), uid_name(other.uid_name), parent_name(other.parent_name), parent_node(other.parent_node), + obj_pat(other.obj_pat), obj_morph(other.obj_morph), texture_list(other.texture_list), + texture_transform_list(other.texture_transform_list), child_object_list(other.child_object_list), + child_object_hrc_list(other.child_object_hrc_list), obj_uid(other.obj_uid), + obj_hash(other.obj_hash), is_reflect(other.is_reflect), is_refract(other.is_refract) { + + } + + // 0x1401B8F80 + Object::~Object() { + + } + + // 0x1401D76D0 + void Object::init() { + index = -1; + + name.clear(); + name.shrink_to_fit(); + uid_name.clear(); + uid_name.shrink_to_fit(); + parent_name.clear(); + parent_name.shrink_to_fit(); + parent_node.clear(); + parent_node.shrink_to_fit(); + + obj_pat.init(); + obj_morph.init(); + + texture_list.clear(); + texture_list.shrink_to_fit(); + texture_transform_list.clear(); + texture_transform_list.shrink_to_fit(); + child_object_list.clear(); + child_object_list.shrink_to_fit(); + child_object_hrc_list.clear(); + child_object_hrc_list.shrink_to_fit(); + + obj_uid = {}; + obj_hash = hash_murmurhash_empty; + is_reflect = false; + is_refract = false; + } + + // 0x1401D4A70 + void Object::get(float_t in_frame) { + model_transform.get(in_frame); + + obj_morph.get(in_frame); + obj_pat.get(in_frame); + + for (Texture& i : texture_list) + i.get(in_frame); + for (TextureTransform& i : texture_transform_list) + i.get(in_frame); + } + + // 0x1401CEE70 + void Object::ctrl(const mat4& in_base_mat) { + //if (!model_transform.visibility) + // return; + + model_transform.mul(in_base_mat); + + const mat4& mat = model_transform.get_matrix(); + + for (Object*& i : child_object_list) + i->ctrl(mat); + for (HierarchyObject*& i : child_object_hrc_list) + i->ctrl(mat); + } + + // 0x1401D0970 + void Object::disp(Scene& in_scene, render_context* rctx) { + if (!model_transform.visibility) + return; + + if (!in_scene.M_is_visible) { + if (in_scene.M_debug) + debug_put_line_axis(model_transform.get_matrix()); + + for (Object*& i : child_object_list) + i->disp(in_scene, rctx); + for (HierarchyObject*& i : child_object_hrc_list) + i->disp(in_scene, rctx); + return; + } + + mat4 matrix = model_transform.get_matrix(); + + mdl::DispManager& disp_manager = *rctx->disp_manager; + const object_database* obj_db = in_scene.obj_db; + const texture_database* tex_db = in_scene.tex_db; + + if (in_scene.M_assign_rob_id >= 0 && in_scene.M_assign_rob_id < ROB_ID_MAX) { + RobManagement* rob_man = get_rob_management(); + if (rob_man->is_init((ROB_ID)in_scene.M_assign_rob_id)) { + rob_chara* rob_chr = rob_man->get_rob((ROB_ID)in_scene.M_assign_rob_id); + mat4 m; + mat4_mul(&rob_chr->rob_base.position.rob_mat, + in_scene.M_chara_item + ? &rob_chr->rob_base.adjust.item_mat + : &rob_chr->rob_base.adjust.mat, &m); + mat4_mul(&matrix, &m, &matrix); + disp_manager.set_shadow_group(in_scene.M_assign_rob_id ? SHADOW_GROUP_STAGE : SHADOW_GROUP_CHARA); + } + } + + mdl::ObjFlags flag = (mdl::ObjFlags)0; + if (in_scene.M_shadow) + enum_or(flag, mdl::OBJ_4 | mdl::OBJ_SHADOW); + if (is_reflect) + enum_or(flag, mdl::OBJ_NO_TRANSLUCENCY | mdl::OBJ_REFLECT); + if (is_refract) + enum_or(flag, mdl::OBJ_NO_TRANSLUCENCY | mdl::OBJ_REFRACT); + + disp_manager.set_obj_flags(flag); + + char buf[0x80]; + int32_t tex_pat_count = 0; + TexChange tex_pat[TEXTURE_PATTERN_COUNT]; + + for (Texture& i : texture_list) { + if (!i.tex_pat.is_valid() || i.name.size() <= 3) + continue; + else if (tex_pat_count >= TEXTURE_PATTERN_COUNT) + break; + + sprintf_s(buf, sizeof(buf), "%.*s%03d", + (int32_t)(i.name.size() - 3), i.name.c_str(), (int32_t)prj::roundf(i.tex_pat.value)); + + tex_pat[tex_pat_count].org_texid = texture_id(0x00, i.tex_uid); + tex_pat[tex_pat_count].change_texid = texture_id(0x00, tex_db->get_texture_id(buf)); + tex_pat_count++; + } + + if (tex_pat_count) + disp_manager.set_texture_pattern(tex_pat_count, tex_pat); + + int32_t tex_trans_count = 0; + texture_transform_struct tex_trans[TEXTURE_TRANSFORM_COUNT]; + + for (TextureTransform& i : texture_transform_list) { + if (tex_trans_count >= TEXTURE_TRANSFORM_COUNT || i.tex_uid == -1 + || !texture_manager_get_texture(i.tex_uid)) + continue; + + tex_trans[tex_trans_count].texid = i.tex_uid; + tex_trans[tex_trans_count].mat = i.mat; + tex_trans_count++; + } + + if (tex_trans_count) + disp_manager.set_texture_transform(tex_trans_count, tex_trans); + + if (obj_morph.is_valid()) { + const char* uid_name = this->uid_name.c_str(); + size_t uid_name_length = this->uid_name.size(); + if (uid_name_length > 3) { + float_t morph = obj_morph.value; + int32_t morph_int = (int32_t)morph; + morph = fmodf(morph, 1.0f); + if (morph > 0.0f && morph < 1.0f) { + sprintf_s(buf, sizeof(buf), "%.*s%03d", + (int32_t)uid_name_length - 3, uid_name, morph_int + 1); + object_info morph_obj_uid = obj_db->get_object_info(buf); + if (morph_obj_uid.is_null()) + morph_obj_uid = obj_uid; + disp_manager.set_morph(morph_obj_uid, morph); + + sprintf_s(buf, sizeof(buf), "%.*s%03d", + (int32_t)uid_name_length - 3, uid_name, morph_int); + object_info obj_uid = obj_db->get_object_info(buf); + in_scene.M_put_obj(matrix, obj_uid, rctx); + disp_manager.set_morph({}, 0.0f); + } + else { + if (morph >= 1.0f) + morph_int++; + + sprintf_s(buf, sizeof(buf), "%.*s%03d", + (int32_t)uid_name_length - 3, uid_name, morph_int); + object_info obj_uid = obj_db->get_object_info(buf); + if (obj_uid.is_null()) + obj_uid = this->obj_uid; + in_scene.M_put_obj(matrix, obj_uid, rctx); + } + } + } + else if (obj_pat.is_valid()) { + const char* uid_name = this->uid_name.c_str(); + size_t uid_name_length = this->uid_name.size(); + if (uid_name_length > 3) { + float_t pat = prj::roundf(obj_pat.value); + int32_t pat_int = (int32_t)pat; + sprintf_s(buf, sizeof(buf), "%.*s%03d", + (int32_t)uid_name_length - 3, uid_name, pat_int); + object_info obj_uid = obj_db->get_object_info(buf); + in_scene.M_put_obj(matrix, obj_uid, rctx); + } + else + in_scene.M_put_obj(matrix, obj_uid, rctx); + } + else + in_scene.M_put_obj(matrix, obj_uid, rctx); + + disp_manager.set_texture_transform(); + disp_manager.set_texture_pattern(); + disp_manager.set_obj_flags(); + + if (in_scene.M_debug) + debug_put_line_axis(model_transform.get_matrix()); + + for (Object*& i : child_object_list) + i->disp(in_scene, rctx); + for (HierarchyObject*& i : child_object_hrc_list) + i->disp(in_scene, rctx); + } + + // 0x1401E3510 + bool Object::replace_chara(int32_t in_cn_src, int32_t in_cn_dst, const object_database* obj_db) { + if (in_cn_src < 0 || in_cn_src >= CN_MAX || in_cn_dst < 0 || in_cn_dst >= CN_MAX || in_cn_src == in_cn_dst) + return false; + + std::string cn_src_str(get_char_id_str((CHARA_NUM)in_cn_src)); + std::string cn_dst_str(get_char_id_str((CHARA_NUM)in_cn_dst)); + + std::string uid_name(this->uid_name); + size_t pos = uid_name.find(cn_src_str); + if (pos != -1) + uid_name.assign(uid_name.replace(pos, cn_src_str.size(), cn_dst_str)); + + object_info obj_uid = obj_db->get_object_info(uid_name.c_str()); + if (obj_uid.not_null()) { + this->obj_uid = obj_uid; + this->uid_name.assign(uid_name); + return true; + } + return false; + } + + // Added + void Object::prepare_morph(const object_database* obj_db) { + if (!obj_morph.is_valid()) + return; + + float_t min_value = FLT_MAX; + float_t max_value = -FLT_MAX; + + float_t first_frame = 0.0f; + float_t last_frame = obj_morph.fcurve_ptr->curve.m_max_frame; + for (float_t i = first_frame; i <= last_frame; i += 1.0f) { + obj_morph.get(i); + min_value = fminf(min_value, obj_morph.value); + max_value = fmaxf(max_value, obj_morph.value); + } + obj_morph.get(0.0f); + + int32_t min = (int32_t)prj::floorf(min_value); + int32_t max = (int32_t)prj::ceilf(max_value); + if (min >= max) + return; + + const char* uid_name = this->uid_name.c_str(); + int32_t uid_name_length = (int32_t)this->uid_name.size(); + + char buf[0x80]; + for (int32_t i = min; i < max; i++) { + sprintf_s(buf, sizeof(buf), "%.*s%03d", uid_name_length - 3, uid_name, i + 1); + object_info morph_obj_uid = obj_db->get_object_info(buf); + if (morph_obj_uid.is_null()) + morph_obj_uid = this->obj_uid; + + sprintf_s(buf, sizeof(buf), "%.*s%03d", uid_name_length - 3, uid_name, i); + object_info obj_uid = obj_db->get_object_info(buf); + + ::obj* obj = objset_info_storage_get_obj(obj_uid); + if (!obj) + continue; + + obj_mesh_vertex_buffer* obj_vert_buf = objset_info_storage_get_obj_mesh_vertex_buffer(obj_uid); + obj_mesh_index_buffer* obj_index_buf = objset_info_storage_get_obj_mesh_index_buffer(obj_uid); + + obj_mesh_vertex_buffer* obj_morph_vert_buf = 0; + if (morph_obj_uid.set_id != -1) + obj_morph_vert_buf = objset_info_storage_get_obj_mesh_vertex_buffer(morph_obj_uid); + + for (int32_t i = 0; i < obj->num_mesh; i++) { + const obj_mesh* mesh = &obj->mesh_array[i]; + for (int32_t j = 0; j < mesh->num_submesh; j++) { + const obj_sub_mesh* sub_mesh = &mesh->submesh_array[j]; + if (sub_mesh->attrib.m.cloth) + continue; + + obj_material_data* material = &obj->material_array[sub_mesh->material_index]; + + GLuint morph_vertex_buffer = 0; + size_t morph_vertex_buffer_offset = 0; + if (obj_morph_vert_buf) { + morph_vertex_buffer = obj_morph_vert_buf[i].get_buffer(); + morph_vertex_buffer_offset = obj_morph_vert_buf[i].get_offset(); + } + + GLuint index_buffer = 0; + if (obj_index_buf) + index_buffer = obj_index_buf[i].buffer; + + GLuint vertex_buffer = 0; + size_t vertex_buffer_offset = 0; + if (obj_vert_buf) { + vertex_buffer = obj_vert_buf[i].get_buffer(); + vertex_buffer_offset = obj_vert_buf[i].get_offset(); + } + + if (vertex_buffer && index_buffer && (!obj_morph_vert_buf || morph_vertex_buffer)) + rctx_ptr->disp_manager->add_vertex_array(mesh, sub_mesh, material, vertex_buffer, + vertex_buffer_offset, index_buffer, morph_vertex_buffer, morph_vertex_buffer_offset); + } + } + } + } + + // 0x1401DE5F0 + bool Object::load(const SceneFile& in_file, const a3d::Object& in_o, + const object_database* obj_db, const texture_database* tex_db) { + name.assign(in_o.name); + uid_name.assign(in_o.uid_name); + + obj_uid = obj_db->get_object_info(uid_name.c_str()); + obj_hash = hash_string_murmurhash(uid_name); + + static std::string reflect_str = "_REFLECT"; + is_reflect = uid_name.find(reflect_str) != -1; + + static std::string refract_str = "_REFRACT"; + is_refract = uid_name.find(refract_str) != -1; + + model_transform.load(in_file, in_o.model_transform); + + obj_morph.name.assign(in_o.morph); + obj_morph.offset = in_o.morph_offset; + + obj_pat.name.assign(in_o.pattern); + obj_pat.offset = in_o.pattern_offset; + + parent_name.assign(in_o.parent_name); + parent_node.assign(in_o.parent_node); + + list_load(texture_list, in_file, in_o.texture, tex_db); + list_load(texture_transform_list, in_file, in_o.texture_transform, tex_db); + return true; + } + + // Added + void Object::store(const SceneFile& in_file, a3d::Object& out_o) const { + out_o.name.assign(name); + out_o.uid_name.assign(uid_name); + + model_transform.store(in_file, out_o.model_transform); + + out_o.morph.assign(obj_morph.name); + out_o.morph_offset = obj_morph.offset; + + out_o.pattern.assign(obj_pat.name); + out_o.pattern_offset = obj_pat.offset; + + out_o.parent_name.assign(parent_name); + out_o.parent_node.assign(parent_node); + + list_store(texture_list, in_file, out_o.texture); + list_store(texture_transform_list, in_file, out_o.texture_transform); + } + + // 0x1401BC860 + Object& Object::operator=(const Object& other) { + model_transform = other.model_transform; + index = other.index; + name.assign(other.name); + uid_name.assign(other.uid_name); + parent_name.assign(other.parent_name); + parent_node.assign(other.parent_node); + obj_pat = other.obj_pat; + obj_morph = other.obj_morph; + texture_list.assign(other.texture_list.begin(), other.texture_list.end()); + texture_transform_list.assign(other.texture_transform_list.begin(), other.texture_transform_list.end()); + child_object_list.assign(other.child_object_list.begin(), other.child_object_list.end()); + child_object_hrc_list.assign(other.child_object_hrc_list.begin(), other.child_object_hrc_list.end()); + obj_uid = other.obj_uid; + obj_hash = other.obj_hash; + is_reflect = other.is_reflect; + is_refract = other.is_refract; + return *this; + } + + // 0x1401B5DE0 + ObjectInstance::ObjectInstance() : name(), uid_name(), obj_uid(), + obj_hash(hash_murmurhash_empty), shadow(), motion_transform(), matrix_id(), mats() { + + } + + // 0x1401B5D20 + ObjectInstance::ObjectInstance(const ObjectInstance& other) : name(other.name), + uid_name(other.uid_name), obj_uid(other.obj_uid), obj_hash(other.obj_hash), shadow(other.shadow), + motion_transform(other.motion_transform), matrix_id(other.matrix_id), mats(other.mats) { + + } + + // 0x1401B91E0 + ObjectInstance::~ObjectInstance() { + + } + + // Missing + void ObjectInstance::init() { + name.clear(); + name.shrink_to_fit(); + uid_name.clear(); + uid_name.shrink_to_fit(); + + obj_uid = {}; + obj_hash = (uint32_t)-1; + shadow = false; + + matrix_id.clear(); + matrix_id.shrink_to_fit(); + mats.clear(); + mats.shrink_to_fit(); + } + + // Inlined + inline void ObjectInstance::get(float_t in_frame) { + motion_transform.get(in_frame); + motion_transform.calc_matrix_local(); + } + + // Inlined + inline bool ObjectInstance::load(const SceneFile& in_file, const a3d::ObjectInstance& in_oi, + const MultiHierarchyObject& in_mho, const object_database* obj_db) { + name.assign(in_oi.name); + uid_name.assign(in_oi.uid_name); + + obj_uid = obj_db->get_object_info(uid_name.c_str()); + obj_hash = hash_string_murmurhash(uid_name); + + shadow = in_oi.shadow; + motion_transform.load(in_file, in_oi.model_transform); + + const obj_skin* skin = objset_info_storage_get_obj_skin(obj_uid); + if (!skin) { + std::string error_str = sprintf_s_string("%s skin data is not found", uid_name.c_str()); + throw std::runtime_error(error_str.c_str()); + } + + matrix_id.resize(skin->num_bone); + + size_t bone_num = 0; + for (size_t i = 0; i < in_mho.node_list.size(); i++) { + const TransformNode& node = in_mho.node_list[i]; + size_t num_bone = skin->num_bone; + for (size_t j = 0; j < num_bone; j++) + if (!node.name.compare(skin->bone_array[j].name)) { + int32_t node_index = skin->bone_array[j].id; + if (node_index & 0x8000) { + std::string error_str = sprintf_s_string( + "%s skin bone type is not normal bone", uid_name.c_str()); + throw std::runtime_error(error_str.c_str()); + } + + matrix_id[node_index] = (int32_t)i; + bone_num++; + break; + } + } + + if (!bone_num) { + std::string error_str = sprintf_s_string("%s skin data has no bone", uid_name.c_str()); + throw std::runtime_error(error_str.c_str()); + } + + if (bone_num != skin->num_bone) + throw std::range_error("bone_num mismatch"); + + mats.resize(bone_num); + return true; + } + + // Added + inline void ObjectInstance::store(const SceneFile& in_file, a3d::ObjectInstance& out_oi, + const MultiHierarchyObject& in_mho) const { + out_oi.name.assign(name); + out_oi.uid_name.assign(uid_name); + out_oi.shadow = shadow; + motion_transform.store(in_file, out_oi.model_transform); + } + + // 0x1401BCA10 + ObjectInstance& ObjectInstance::operator=(const ObjectInstance& other) { + name.assign(other.name); + uid_name.assign(other.uid_name); + obj_uid = other.obj_uid; + obj_hash = other.obj_hash; + shadow = other.shadow; + motion_transform = other.motion_transform; + matrix_id.assign(other.matrix_id.begin(), other.matrix_id.end()); + mats.assign(other.mats.begin(), other.mats.end()); + return *this; + } + + // Missing + PlayControl::PlayControl() : flag(), + begin(), div(), fps(), offset(), size() { + + } + + // Missing + PlayControl::PlayControl(const PlayControl& other) : flag(other.flag), + begin(other.begin), div(other.div), fps(other.fps), offset(other.offset), size(other.size) { + + } + + // Missing + PlayControl::~PlayControl() { + + } + + // 0x1401D78B0 + void PlayControl::init() { + flag = 0; + begin = 0.0f; + div = 0; // F2/X/XHD + fps = 0.0f; + offset = 0.0f; + size = 0.0f; + } + + // 0x1401DEE10 + bool PlayControl::load(const SceneFile& in_file, const a3d::PlayControl& in_pc) { + begin = in_pc.begin; + + // F2/X/XHD + if (in_pc.flag & a3d::PlayControl::FLAG_DIV) { + div = in_pc.div; + flag |= FLAG_DIV; + } + + fps = in_pc.fps; + + // F2/X/XHD + if (in_pc.flag & a3d::PlayControl::FLAG_OFFSET) { + offset = in_pc.offset; + flag |= FLAG_OFFSET; + } + + size = in_pc.size; + return true; + } + + // Added + void PlayControl::store(const SceneFile& in_file, a3d::PlayControl& out_pc) const { + out_pc.begin = begin; + + // F2/X/XHD + if (flag & FLAG_DIV) { + out_pc.div = div; + out_pc.flag |= a3d::PlayControl::FLAG_DIV; + } + + out_pc.fps = fps; + + // F2/X/XHD + if (flag & FLAG_OFFSET) { + out_pc.offset = offset; + out_pc.flag |= a3d::PlayControl::FLAG_OFFSET; + } + + out_pc.size = size; + } + + // Missing + PlayControl& PlayControl::operator=(const PlayControl& other) { + flag = other.flag; + begin = other.begin; + div = other.div; + fps = other.fps; + offset = other.offset; + size = other.size; + return *this; + } + + // 0x1401B5EE0 + Point::Point() : name(), model_transform() { + + } + + // 0x1401B5E80 + Point::Point(const Point& other) : name(other.name), model_transform(other.model_transform) { + + } + + // 0x1401B92D0 + Point::~Point() { + + } + + // 0x1401D4B20 + void Point::get(float_t in_frame) { + model_transform.get(in_frame); + } + + // 0x1401D1150 + void Point::disp(const Scene& in_scene, render_context* rctx) { + if (in_scene.M_debug) { + model_transform.mul(in_scene.base_matrix); + debug_put_line_axis(model_transform.get_matrix()); + } + } + + // 0x1401DEF50 + bool Point::load(const SceneFile& in_file, const a3d::Point& in_p) { + name.assign(in_p.name); + model_transform.load(in_file, in_p.model_transform); + return true; + } + + // Added + void Point::store(const SceneFile& in_file, a3d::Point& out_p) const { + out_p.name.assign(name); + model_transform.store(in_file, out_p.model_transform); + } + + // 0x1401BCAA0 + Point& Point::operator=(const Point& other) { + name.assign(other.name); + model_transform = other.model_transform; + return *this; + } + + // 0x1401B5F20 + PostProcess::PostProcess() : flag(), backup_flag(), + fcurve_lens_flare(), fcurve_lens_shaft(), fcurve_lens_ghost(), radius(), intensity(), + scene_fade(), backup_lens_flare(), backup_lens_shaft(), backup_lens_ghost(), backup_radius(), + backup_intensity(), backup_scene_fade(), lens_flare(), lens_shaft(), lens_ghost() { + + } + + // Missing + PostProcess::PostProcess(const PostProcess& other) : flag(other.flag), backup_flag(other.backup_flag), + fcurve_lens_flare(other.fcurve_lens_flare), fcurve_lens_shaft(other.fcurve_lens_shaft), + fcurve_lens_ghost(other.fcurve_lens_ghost), radius(other.radius), intensity(other.intensity), + scene_fade(other.scene_fade), backup_lens_flare(other.backup_lens_flare), + backup_lens_shaft(other.backup_lens_shaft), backup_lens_ghost(other.backup_lens_ghost), + backup_radius(other.backup_radius), backup_intensity(other.backup_intensity), + backup_scene_fade(other.backup_scene_fade), lens_flare(other.lens_flare), + lens_shaft(other.lens_shaft), lens_ghost(other.lens_ghost) { + + } + + // 0x1401B9350 + PostProcess::~PostProcess() { + + } + + // 0x1401D78C0 + void PostProcess::init() { + flag = 0; + backup_flag = 0; + + fcurve_lens_flare.init(); + fcurve_lens_shaft.init(); + fcurve_lens_ghost.init(); + } + + // 0x1401D4B30 + void PostProcess::get(float_t in_frame) { + if (has_lens_flare()) + lens_flare = fcurve_lens_flare.get(in_frame); + if (has_lens_shaft()) + lens_shaft = fcurve_lens_shaft.get(in_frame); + if (has_lens_ghost()) + lens_ghost = fcurve_lens_ghost.get(in_frame); + if (has_radius()) + radius.get(in_frame); + if (has_intensity()) + intensity.get(in_frame); + if (has_scene_fade()) + scene_fade.get(in_frame); + } + + // 0x1401CEF00 + void PostProcess::ctrl(Scene& in_scene, render_context* rctx) { + if (has_lens()) { + vec3 lens = rctx->render.get_lens(); + if (has_lens_flare()) { + if (!(backup_flag & FLAG_LENS_FLARE)) { + backup_lens_flare = lens.x; + backup_flag |= FLAG_LENS_FLARE; + } + lens.x = lens_flare; + } + + if (has_lens_shaft()) { + if (!(backup_flag & FLAG_LENS_SHAFT)) { + backup_lens_shaft = lens.y; + backup_flag |= FLAG_LENS_SHAFT; + } + lens.y = lens_shaft; + } + + if (has_lens_ghost()) { + if (!(backup_flag & FLAG_LENS_GHOST)) { + backup_lens_ghost = lens.z; + backup_flag |= FLAG_LENS_GHOST; + } + lens.z = lens_ghost; + } + rctx->render.set_lens(lens); + } + + if (has_radius()) { + if (!(backup_flag & FLAG_RADIUS)) { + *(vec3*)&backup_radius = rctx->render.get_radius(); + backup_flag |= FLAG_RADIUS; + } + + rctx->render.set_radius(*(vec3*)&radius.color); + } + + if (has_intensity()) { + if (!(backup_flag & FLAG_INTENSITY)) { + *(vec3*)&backup_intensity = rctx->render.get_intensity(); + backup_flag |= FLAG_INTENSITY; + } + + rctx->render.set_intensity(*(vec3*)&intensity.color); + } + + if (has_scene_fade()) { + if (!(backup_flag & FLAG_SCENE_FADE)) { + backup_scene_fade = rctx->render.get_scene_fade(); + backup_flag |= FLAG_SCENE_FADE; + } + + rctx->render.set_scene_fade(scene_fade.color, 0); + } + } + + // 0x1401D0050 + void PostProcess::dest(render_context* rctx) { + if (backup_flag & (FLAG_LENS_FLARE | FLAG_LENS_SHAFT | FLAG_LENS_GHOST)) { + vec3 value = rctx->render.get_lens(); + if (backup_flag & FLAG_LENS_FLARE) + value.x = backup_lens_flare; + if (backup_flag & FLAG_LENS_SHAFT) + value.y = backup_lens_shaft; + if (backup_flag & FLAG_LENS_GHOST) + value.z = backup_lens_ghost; + rctx->render.set_lens(value); + } + + if (backup_flag & FLAG_RADIUS) + rctx->render.set_radius(*(vec3*)&backup_radius); + if (backup_flag & FLAG_INTENSITY) + rctx->render.set_intensity(*(vec3*)&backup_intensity); + if (backup_flag & FLAG_SCENE_FADE) + rctx->render.set_scene_fade(backup_scene_fade, 0); + } + + // 0x1401DF050 + bool PostProcess::load(const SceneFile& in_file, const a3d::PostProcess& in_pp) { + if (in_pp.flag & a3d::PostProcess::FLAG_LENS_FLARE) { + fcurve_lens_flare.load(in_file, in_pp.lens_flare); + flag |= FLAG_LENS_FLARE; + } + + if (in_pp.flag & a3d::PostProcess::FLAG_LENS_SHAFT) { + fcurve_lens_shaft.load(in_file, in_pp.lens_shaft); + flag |= FLAG_LENS_SHAFT; + } + + if (in_pp.flag & a3d::PostProcess::FLAG_LENS_GHOST) { + fcurve_lens_ghost.load(in_file, in_pp.lens_ghost); + flag |= FLAG_LENS_GHOST; + } + + if (in_pp.flag & a3d::PostProcess::FLAG_RADIUS) { + radius.load(in_file, in_pp.radius); + flag |= FLAG_RADIUS; + } + + if (in_pp.flag & a3d::PostProcess::FLAG_INTENSITY) { + intensity.load(in_file, in_pp.intensity); + flag |= FLAG_INTENSITY; + } + + if (in_pp.flag & a3d::PostProcess::FLAG_SCENE_FADE) { + scene_fade.load(in_file, in_pp.scene_fade); + flag |= FLAG_SCENE_FADE; + } + return true; + } + + // Added + void PostProcess::store(const SceneFile& in_file, a3d::PostProcess& out_pp) const { + if (flag & FLAG_LENS_FLARE) { + fcurve_lens_flare.store(in_file, out_pp.lens_flare); + out_pp.flag |= a3d::PostProcess::FLAG_LENS_FLARE; + } + + if (flag & FLAG_LENS_SHAFT) { + fcurve_lens_shaft.store(in_file, out_pp.lens_shaft); + out_pp.flag |= a3d::PostProcess::FLAG_LENS_SHAFT; + } + + if (flag & FLAG_LENS_GHOST) { + fcurve_lens_ghost.store(in_file, out_pp.lens_ghost); + out_pp.flag |= a3d::PostProcess::FLAG_LENS_GHOST; + } + + if (flag & FLAG_RADIUS) { + radius.store(in_file, out_pp.radius); + out_pp.flag |= a3d::PostProcess::FLAG_RADIUS; + } + + if (flag & FLAG_INTENSITY) { + intensity.store(in_file, out_pp.intensity); + out_pp.flag |= a3d::PostProcess::FLAG_INTENSITY; + } + + if (flag & FLAG_SCENE_FADE) { + scene_fade.store(in_file, out_pp.scene_fade); + out_pp.flag |= a3d::PostProcess::FLAG_SCENE_FADE; + } + } + + // Missing + PostProcess& PostProcess::operator=(const PostProcess& other) { + flag = other.flag; + backup_flag = other.backup_flag; + fcurve_lens_flare = other.fcurve_lens_flare; + fcurve_lens_shaft = other.fcurve_lens_shaft; + fcurve_lens_ghost = other.fcurve_lens_ghost; + radius = other.radius; + intensity = other.intensity; + scene_fade = other.scene_fade; + backup_lens_flare = other.backup_lens_flare; + backup_lens_shaft = other.backup_lens_shaft; + backup_lens_ghost = other.backup_lens_ghost; + backup_radius = other.backup_radius; + backup_intensity = other.backup_intensity; + backup_scene_fade = other.backup_scene_fade; + lens_flare = other.lens_flare; + lens_shaft = other.lens_shaft; + lens_ghost = other.lens_ghost; + return *this; + } + + // 0x1401B6550 + Texture::Texture() : name(), tex_uid(-1), tex_pat() { + + } + + // 0x1401B64C0 + Texture::Texture(const Texture& other) + : name(other.name), tex_uid(other.tex_uid), tex_pat(other.tex_pat) { + + } + + // 0x1401B9BF0 + Texture::~Texture() { + + } + + // 0x1401D8420 + void Texture::init() { + name.clear(); + name.shrink_to_fit(); + tex_uid = -1; + tex_pat.init(); + } + + // 0x1401D4C00 + void Texture::get(float_t in_frame) { + tex_pat.get(in_frame); + } + + // 0x1401DFA50 + bool Texture::load(const SceneFile& in_file, + const a3d::Texture& in_t, const texture_database* tex_db) { + name.assign(in_t.name); + tex_uid = tex_db->get_texture_id(name.c_str()); + tex_pat.name.assign(in_t.pattern); + tex_pat.offset = in_t.pattern_offset; + return true; + } + + // Added + void Texture::store(const SceneFile& in_file, a3d::Texture& out_t) const { + out_t.name.assign(name); + out_t.pattern.assign(tex_pat.name); + out_t.pattern_offset = tex_pat.offset; + } + + // 0x1401BCBA0 + Texture& Texture::operator=(const Texture& other) { + name.assign(other.name); + tex_uid = other.tex_uid; + tex_pat = other.tex_pat; + return *this; + } + + // 0x1401B6C30 + TextureTransform::TextureTransform() : flag(), backup_flag(), name(), tex_uid(), fcurve_coverage_u(), + fcurve_coverage_v(), fcurve_repeat_u(), fcurve_repeat_v(), fcurve_translate_frame_u(), + fcurve_translate_frame_v(), fcurve_offset_u(), fcurve_offset_v(), fcurve_rotate_frame(), + fcurve_rotate(), mat(), scale(), repeat(), rotate(), translate_frame() { + } + + // 0x1401B65A0 + TextureTransform::TextureTransform(const TextureTransform& other) + : flag(other.flag), backup_flag(other.backup_flag), name(other.name), tex_uid(other.tex_uid), + fcurve_coverage_u(other.fcurve_coverage_u), fcurve_coverage_v(other.fcurve_coverage_v), + fcurve_repeat_u(other.fcurve_repeat_u), fcurve_repeat_v(other.fcurve_repeat_v), + fcurve_translate_frame_u(other.fcurve_translate_frame_u), + fcurve_translate_frame_v(other.fcurve_translate_frame_v), + fcurve_offset_u(other.fcurve_offset_u), fcurve_offset_v(other.fcurve_offset_v), + fcurve_rotate_frame(other.fcurve_rotate_frame), fcurve_rotate(other.fcurve_rotate), + mat(other.mat), scale(other.scale), repeat(other.repeat), rotate(other.rotate), + translate_frame(other.translate_frame) { + + } + + // 0x1401B9C50 + TextureTransform::~TextureTransform() { + + } + + // 0x1401D8460 + void TextureTransform::init() { + flag = 0; + tex_uid = -1; + name.clear(); + name.shrink_to_fit(); + + mat = mat4_identity; + + fcurve_coverage_u.init(); + fcurve_coverage_v.init(); + fcurve_repeat_u.init(); + fcurve_repeat_v.init(); + fcurve_translate_frame_u.init(); + fcurve_translate_frame_v.init(); + fcurve_offset_u.init(); + fcurve_offset_v.init(); + fcurve_rotate_frame.init(); + fcurve_rotate.init(); + } + + // 0x1401D4C10 + void TextureTransform::get(float_t in_frame) { + scale = 1.0f; + + if (has_coverage_u() && fcurve_coverage_u.m_max_frame > 0.0f) { + float_t coverage_u = fcurve_coverage_u.get(in_frame); + if (fabsf(coverage_u) > 0.000001f) + scale.x = 1.0f / coverage_u; + } + + if (has_coverage_v() && fcurve_coverage_v.m_max_frame > 0.0f) { + float_t coverage_v = fcurve_coverage_v.get(in_frame); + if (fabsf(coverage_v) > 0.000001f) + scale.y = 1.0f / coverage_v; + } + + repeat = 1.0f; + + if (has_repeat_u() && fcurve_repeat_u.m_max_frame > 0.0f) { + float_t value = fcurve_repeat_u.get(in_frame); + if (fabsf(value) > 0.000001f) + repeat.x = value; + } + + if (has_repeat_v() && fcurve_repeat_v.m_max_frame > 0.0f) { + float_t value = fcurve_repeat_v.get(in_frame); + if (fabsf(value) > 0.000001f) + repeat.y = value; + } + + float_t rotate_frame_value = 0.0f; + if (has_rotate_frame()) + rotate_frame_value = fcurve_rotate_frame.get(in_frame); + + float_t rotate_value = 0.0f; + if (has_rotate()) + rotate_value = fcurve_rotate.get(in_frame); + + rotate.z = rotate_frame_value + rotate_value; + + float_t translate_frame_u = 0.0f; + if (has_translate_frame_u()) + translate_frame_u = -fcurve_translate_frame_u.get(in_frame); + + float_t offset_u = 0.0f; + if (has_offset_u()) + offset_u = fcurve_offset_u.get(in_frame); + + translate_frame.x = (translate_frame_u + offset_u) * repeat.x; + + float_t translate_frame_v = 0.0f; + if (has_translate_frame_v()) + translate_frame_v = -fcurve_translate_frame_v.get(in_frame); + + float_t offset_v = 0.0f; + if (has_offset_v()) + offset_v = fcurve_offset_v.get(in_frame); + + translate_frame.y = (translate_frame_v + offset_v) * repeat.y; + + mul(); + } + + // 0x1401E1DB0 + void TextureTransform::mul() { + mat4_translate(&translate_frame, &mat); + mat4_scale_rot(&mat, &scale, &mat); + + mat4_mul_translate(&mat, 1.0f, 1.0f, 0.0f, &mat); + mat4_scale_rot(&mat, &repeat, &mat); + mat4_mul_translate(&mat, -1.0f, -1.0f, 0.0f, &mat); + + mat4_mul_translate(&mat, 0.5f, 0.5f, 0.0f, &mat); + mat4_mul_rotate_z(&mat, rotate.z, &mat); + mat4_mul_translate(&mat, -0.5f, -0.5f, 0.0f, &mat); + } + + // 0x1401DFCB0 + bool TextureTransform::load(const SceneFile& in_file, + const a3d::TextureTransform& in_tt, const texture_database* tex_db) { + name.assign(in_tt.name); + tex_uid = tex_db->get_texture_id(name.c_str()); + + if (in_tt.flag & a3d::TextureTransform::FLAG_COVERAGE_U) { + fcurve_coverage_u.load(in_file, in_tt.coverage_u); + flag |= FLAG_COVERAGE_U; + } + + if (in_tt.flag & a3d::TextureTransform::FLAG_COVERAGE_V) { + fcurve_coverage_v.load(in_file, in_tt.coverage_v); + flag |= FLAG_COVERAGE_V; + } + + if (in_tt.flag & a3d::TextureTransform::FLAG_REPEAT_U) { + fcurve_repeat_u.load(in_file, in_tt.repeat_u); + flag |= FLAG_REPEAT_U; + } + + if (in_tt.flag & a3d::TextureTransform::FLAG_REPEAT_V) { + fcurve_repeat_v.load(in_file, in_tt.repeat_v); + flag |= FLAG_REPEAT_V; + } + + if (in_tt.flag & a3d::TextureTransform::FLAG_ROTATE) { + fcurve_rotate.load(in_file, in_tt.rotate); + flag |= FLAG_ROTATE; + } + + if (in_tt.flag & a3d::TextureTransform::FLAG_ROTATE_FRAME) { + fcurve_rotate_frame.load(in_file, in_tt.rotate_frame); + flag |= FLAG_ROTATE_FRAME; + } + + if (in_tt.flag & a3d::TextureTransform::FLAG_OFFSET_U) { + fcurve_offset_u.load(in_file, in_tt.offset_u); + flag |= FLAG_OFFSET_U; + } + + if (in_tt.flag & a3d::TextureTransform::FLAG_OFFSET_V) { + fcurve_offset_v.load(in_file, in_tt.offset_v); + flag |= FLAG_OFFSET_V; + } + + if (in_tt.flag & a3d::TextureTransform::FLAG_TRANSLATE_FRAME_U) { + fcurve_translate_frame_u.load(in_file, in_tt.translate_frame_u); + flag |= FLAG_TRANSLATE_FRAME_U; + } + + if (in_tt.flag & a3d::TextureTransform::FLAG_TRANSLATE_FRAME_V) { + fcurve_translate_frame_v.load(in_file, in_tt.translate_frame_v); + flag |= FLAG_TRANSLATE_FRAME_V; + } + return true; + } + + // Added + void TextureTransform::store(const SceneFile& in_file, a3d::TextureTransform& out_tt) const { + out_tt.name.assign(name); + + if (flag & FLAG_COVERAGE_U) { + fcurve_coverage_u.store(in_file, out_tt.coverage_u); + out_tt.flag |= a3d::TextureTransform::FLAG_COVERAGE_U; + } + + if (flag & FLAG_COVERAGE_V) { + fcurve_coverage_v.store(in_file, out_tt.coverage_v); + out_tt.flag |= a3d::TextureTransform::FLAG_COVERAGE_V; + } + + if (flag & FLAG_REPEAT_U) { + fcurve_repeat_u.store(in_file, out_tt.repeat_u); + out_tt.flag |= a3d::TextureTransform::FLAG_REPEAT_U; + } + + if (flag & FLAG_REPEAT_V) { + fcurve_repeat_v.store(in_file, out_tt.repeat_v); + out_tt.flag |= a3d::TextureTransform::FLAG_REPEAT_V; + } + + if (flag & FLAG_ROTATE) { + fcurve_rotate.store(in_file, out_tt.rotate); + out_tt.flag |= a3d::TextureTransform::FLAG_ROTATE; + } + + if (flag & FLAG_ROTATE_FRAME) { + fcurve_rotate_frame.store(in_file, out_tt.rotate_frame); + out_tt.flag |= a3d::TextureTransform::FLAG_ROTATE_FRAME; + } + + if (flag & FLAG_OFFSET_U) { + fcurve_offset_u.store(in_file, out_tt.offset_u); + out_tt.flag |= a3d::TextureTransform::FLAG_OFFSET_U; + } + + if (flag & FLAG_OFFSET_V) { + fcurve_offset_v.store(in_file, out_tt.offset_v); + out_tt.flag |= a3d::TextureTransform::FLAG_OFFSET_V; + } + + if (flag & FLAG_TRANSLATE_FRAME_U) { + fcurve_translate_frame_u.store(in_file, out_tt.translate_frame_u); + out_tt.flag |= a3d::TextureTransform::FLAG_TRANSLATE_FRAME_U; + } + + if (flag & FLAG_TRANSLATE_FRAME_V) { + fcurve_translate_frame_v.store(in_file, out_tt.translate_frame_v); + out_tt.flag |= a3d::TextureTransform::FLAG_TRANSLATE_FRAME_V; + } + } + + // 0x1401BCC10 + TextureTransform& TextureTransform::operator=(const TextureTransform& other) { + flag = other.flag; + backup_flag = other.backup_flag; + name.assign(other.name); + tex_uid = other.tex_uid; + fcurve_coverage_u = other.fcurve_coverage_u; + fcurve_coverage_v = other.fcurve_coverage_v; + fcurve_repeat_u = other.fcurve_repeat_u; + fcurve_repeat_v = other.fcurve_repeat_v; + fcurve_translate_frame_u = other.fcurve_translate_frame_u; + fcurve_translate_frame_v = other.fcurve_translate_frame_v; + fcurve_offset_u = other.fcurve_offset_u; + fcurve_offset_v = other.fcurve_offset_v; + fcurve_rotate_frame = other.fcurve_rotate_frame; + fcurve_rotate = other.fcurve_rotate; + mat = other.mat; + scale = other.scale; + repeat = other.repeat; + rotate = other.rotate; + translate_frame = other.translate_frame; + return *this; + } + + // 0x1401B7080 + TransformNode::TransformNode() : flag(), name(), node_index(-1), parent_id(-1), + motion_transform(), mat_ptr(), joint_orient(), joint_orient_mat() { + + } + + // 0x1401B6F40 + TransformNode::TransformNode(const TransformNode& other) : flag(other.flag), name(other.name), + node_index(other.node_index), parent_id(other.parent_id), motion_transform(other.motion_transform), + mat_ptr(other.mat_ptr), joint_orient(other.joint_orient), joint_orient_mat(other.joint_orient_mat) { + + } + + // 0x1401B9E00 + TransformNode::~TransformNode() { + + } + + // Missing + void TransformNode::init() { + flag = 0; + name.clear(); + name.shrink_to_fit(); + node_index = -1; + parent_id = -1; + + mat_ptr = 0; + } + + // Inlined + inline void TransformNode::get(float_t in_frame) { + motion_transform.get(in_frame); + motion_transform.calc_matrix_local(); + } + + // 0x1401CAF10 + void TransformNode::calc_matrix_local(const mat4& in_base_mat) { + mat4 mat = in_base_mat; + mat4_mul(&joint_orient_mat, &mat, &mat); + motion_transform.calc_matrix(mat); + + if (mat_ptr) + *mat_ptr = motion_transform.matrix; + } + + // Inlined + inline bool TransformNode::load(const SceneFile& in_file, const a3d::ObjectNode& in_on) { + name.assign(in_on.name); + parent_id = in_on.parent; + motion_transform.load(in_file, in_on.model_transform); + + if (in_on.flag & a3d::ObjectNode::FLAG_JOINT_ORIENT) { + joint_orient = in_on.joint_orient; + mat4_rotate_zyx(&joint_orient, &joint_orient_mat); + flag |= FLAG_JOINT_ORIENT; + } + else { + joint_orient = 0.0f; + joint_orient_mat = mat4_identity; + } + return true; + } + + // Added + inline void TransformNode::store(const SceneFile& in_file, a3d::ObjectNode& out_on) const { + out_on.name.assign(name); + out_on.parent = parent_id; + motion_transform.store(in_file, out_on.model_transform); + + if (flag & FLAG_JOINT_ORIENT) { + out_on.joint_orient = joint_orient; + out_on.flag |= a3d::ObjectNode::FLAG_JOINT_ORIENT; + } + else + out_on.joint_orient = 0.0f; + } + + // 0x1401BD280 + TransformNode& TransformNode::operator=(const TransformNode& other) { + flag = other.flag; + name.assign(other.name); + node_index = other.node_index; + parent_id = other.parent_id; + motion_transform = other.motion_transform; + mat_ptr = other.mat_ptr; + joint_orient = other.joint_orient; + joint_orient_mat = other.joint_orient_mat; + return *this; + } + + // 0x1401B3250 + DB::DB() { + + } + + // 0x1401B8650 + DB::~DB() { + + } + + // 0x1401C1850 + void CategoryData::M_load_req(const char* in_mdata_dir) { + if (load_state != S_BEFORE_LOADING) { + load_state = S_DONE; + return; + } + + load_state = S_NOW_LOADING; + + if (in_mdata_dir && *in_mdata_dir) { + path.assign(in_mdata_dir); + path.append("rom/auth_3d/"); + } + else + path.assign("rom/auth_3d/"); + file.assign(category_name); + file.append(".farc"); + + if (file_handler.read_file(&data_list[DATA_AFT], + path.c_str(), file.c_str(), prj::MemCSystem)) + file_handler.set_callback_data(0, (PFNFILEHANDLERCALLBACK*)S_load_cb, this); + else + load_state = S_DONE; + } + + // Added + void CategoryData::M_load_req_modern(void* data) { + if (load_state != S_BEFORE_LOADING) { + load_state = S_DONE; + return; + } + + load_state = S_NOW_LOADING; + path.assign("root+/auth_3d/"); + file.assign(category_name); + file.append(".farc"); + + if (file_handler.read_file(data, path.c_str(), + hash_string_murmurhash(category_name), ".farc", prj::MemCSystem)) + file_handler.set_callback_data(0, (PFNFILEHANDLERCALLBACK*)S_load_cb, this); + else + load_state = S_DONE; + } + + // 0x1401BF7B0 + void CategoryData::M_free() { + if (load_state == S_NOW_LOADING) + file_handler.call_free_callback(); + else if (load_state == S_DONE) { + delete ar; + ar = 0; + file_handler.reset(); + } + + path.clear(); + path.shrink_to_fit(); + file.clear(); + file.shrink_to_fit(); + raw_data = 0; + raw_size = 0; + load_state = S_BEFORE_LOADING; + } + + // 0x1401C1EE0 + bool CategoryData::S_load_cb(CategoryData* data, const void* file_data, size_t file_size) { + if (data->load_state == S_NOW_LOADING) { + data->load_state = S_DONE; + data->raw_data = file_data; + data->raw_size = file_size; + } + + if (!data->ar) + data->ar = new farc; + + if (data->ar) { + data->ar->read(data->raw_data, data->raw_size, true); + return true; + } + return false; + } + + // 0x1401B2F20 + CategoryData::CategoryData() : ref_count(), load_state(), ar(), raw_data(), raw_size() { + + } + + // 0x1401B2E80 + CategoryData::CategoryData(const CategoryData& other) { + *this = other; + } + + // 0x1401B84C0 + CategoryData::~CategoryData() { + delete ar; + } + + // 0x1401E0F60 + void CategoryData::load_req(const char* in_mdata_dir) { + if (ref_count) + ref_count++; + else { + ref_count = 1; + M_load_req(in_mdata_dir); + } + } + + // Added + void CategoryData::load_req_modern(void* data) { + if (ref_count) + ref_count++; + else { + ref_count = 1; + M_load_req_modern(data); + } + } + + // 0x1401D3B10 + void CategoryData::free() { + if (--ref_count < 0) + ref_count = 0; + else if (!ref_count) + M_free(); + } + + // 0x1401D54C0 + std::tuple CategoryData::get_file(const std::string& in_name) { + if (ar) { + farc_file* ff = ar->read_file(in_name.c_str()); + if (ff) + return { ff->size, ff->data }; + } + return {}; + } + + // Added + std::tuple CategoryData::get_file(uint32_t in_hash) { + if (ar) { + farc_file* ff = ar->read_file(in_hash); + if (ff) + return { ff->size, ff->data, ff->name.c_str() }; + } + return {}; + } + + // 0x1401E0670 + inline bool CategoryData::load_is_done() const { + return load_state == S_DONE; + } + + // 0x1401BB670 + CategoryData& CategoryData::operator=(const CategoryData& other) { + ref_count = other.ref_count; + category_name.assign(other.category_name); + load_state = other.load_state; + path.assign(other.path); + file.assign(other.file); + file_handler = other.file_handler; + ar = other.ar ? new farc(*other.ar) : 0; + raw_data = other.raw_data; + raw_size = other.raw_size; + return *this; + } + + // 0x1401B63F0 + SceneFile::SceneFile() : frame_max(), raw_data(), raw_size(), has_raw(), prop_is_ready() { + + } + + // 0x1401B6320 + SceneFile::SceneFile(const SceneFile& other) { + *this = other; + } + + // 0x1401B9B20 + SceneFile::~SceneFile() { + + } + + // 0x1401DF370 + void SceneFile::load(const void* in_data, size_t in_size) { + frame_max = 0.0f; + raw_data = in_data; + raw_size = in_size; + has_raw = true; + + prop.read(in_data, in_size); + prop_is_ready = prop.ready; + } + + // 0x1401CD130 + void SceneFile::clear() { + frame_max = 0.0f; + raw_data = 0; + raw_size = 0; + has_raw = false; + prop = {}; + prop_is_ready = 0; + } + + // 0x1401BCAE0 + SceneFile& SceneFile::operator=(const SceneFile& other) { + frame_max = other.frame_max; + raw_data = other.raw_data; + raw_size = other.raw_size; + has_raw = other.has_raw; + prop = other.prop; + prop_is_ready = other.prop_is_ready; + return *this; + } + + // Inlined + void UidData::M_load_req(const auth_3d_database* auth_3d_db) { + load_state = S_DONE; + if (uid >= auth_3d_db->uid.size()) + return; + + const auth_3d_database_uid* db_uid = &auth_3d_db->uid[uid]; + + if (!db_uid->enabled) + return; + + name = db_uid->name.c_str(); + file_name.assign(db_uid->name); + file_name.append(".a3da"); + + category = g_manager->get_category_data(db_uid->category_name.c_str()); + if (category) { + ref_count = 1; + M_load_req_category(); + } + } + + // 0x1401C1A80 + void UidData::M_load_req_category() { + load_state = S_NOW_LOADING; + category->load_req(0); + } + + // 0x1401BF810 + void UidData::M_free() { + if (load_state == S_NOW_LOADING) + category->free(); + else if (load_state == S_DONE) { + file.clear(); + category->free(); + } + name = 0; + category = 0; + load_state = S_BEFORE_LOADING; + } + + // 0x1401C1710 + void UidData::M_load_is_done() { + if (load_state != S_NOW_LOADING || !category->load_is_done()) + return; + + std::string file_name(name); + file_name.append(".a3da"); + + size_t size; + const void* data; + std::tie(size, data) = category->get_file(file_name); + + time_struct time; + file.load(data, size); + time.calc_time(); + load_state = S_DONE; + } + + // 0x1401B7240 + UidData::UidData() : ref_count(), uid(), load_state(), name(), category() { + + } + + // 0x1401B71B0 + UidData::UidData(const UidData& other) { + *this = other; + } + + // 0x1401B9ED0 + UidData::~UidData() { + + } + + // 0x1401E1040 + void UidData::load_req(const auth_3d_database* auth_3d_db) { + if (ref_count) + ref_count++; + else if (load_state == S_BEFORE_LOADING) + M_load_req(auth_3d_db); + } + + // 0x1401D3B30 + void UidData::free() { + if (--ref_count < 0) + ref_count = 0; + else if (!ref_count) + M_free(); + } + + // 0x1401E06E0 + bool UidData::load_is_done() { + M_load_is_done(); + return load_state == S_DONE; + } + + // 0x1401BD3F0 + UidData& UidData::operator=(const UidData& other) { + ref_count = other.ref_count; + uid = other.uid; + file_name.assign(file_name); + load_state = other.load_state; + file = other.file; + name = other.name; + category = other.category; + return *this; + } + + // Added + void UidDataModern::M_load_req() { + load_state = S_DONE; + + category = g_manager->get_category_data_modern(hash); + if (category) { + file_name.assign(category->ar->get_file_name(hash)); + ref_count = 1; + M_load_req_category(); + } + } + + // Added + void UidDataModern::M_load_req_category() { + load_state = S_NOW_LOADING; + category->load_req(0); + } + + // Added + void UidDataModern::M_free() { + if (load_state == S_NOW_LOADING) + category->free(); + else if (load_state == S_DONE) { + file.clear(); + category->free(); + } + name.clear(); + name.shrink_to_fit(); + category = 0; + load_state = S_BEFORE_LOADING; + g_manager->uid_data_list_modern.erase(hash); + } + + // Added + void UidDataModern::M_load_is_done() { + if (load_state != S_NOW_LOADING || !category->load_is_done()) + return; + + size_t size; + const void* data; + const char* name; + std::tie(size, data, name) = category->get_file(hash); + + time_struct time; + file_name.assign(name); + file.load(data, size); + time.calc_time(); + load_state = S_DONE; + } + + // Added + UidDataModern::UidDataModern() : ref_count(), + load_state(), name(), category(), data(), obj_db(), tex_db() { + hash = hash_murmurhash_empty; + } + + // Added + UidDataModern::UidDataModern(const UidDataModern& other) { + *this = other; + } + + // Added + UidDataModern::~UidDataModern() { + + } + + // Added + void UidDataModern::load_req() { + if (ref_count) + ref_count++; + else if (load_state == S_BEFORE_LOADING) + M_load_req(); + } + + // Added + void UidDataModern::free() { + if (--ref_count < 0) + ref_count = 0; + else if (!ref_count) + M_free(); + } + + // Added + bool UidDataModern::load_is_done() { + M_load_is_done(); + return load_state == S_DONE; + } + + // Added + UidDataModern& UidDataModern::operator=(const UidDataModern& other) { + ref_count = other.ref_count; + hash = other.hash; + file_name.assign(file_name); + load_state = other.load_state; + file = other.file; + name.assign(name); + category = other.category; + data = other.data; + obj_db = other.obj_db; + tex_db = other.tex_db; + return *this; + } + + // 0x1401B60B0 + Scene::Scene() : M_uid(), my_handle(), M_is_enabled(), M_camera_is_enabled(), + M_is_visible(), M_is_looped(), M_is_start(), M_is_finished(), M_is_reverse_side(), + M_is_auto_disable(), trnsl(), trnsl_state(), M_is_attribute_wall(), M_assign_rob_id(), + M_ex_node_mat(), M_shadow(), M_chara_item(), M_reflect(), M_cn_src(), M_cn_dst(), + M_debug(), M_data(), M_frc(), M_frame(), frame_req(), frame_max(), is_requested_frame(), + M_frame_loop_begin(), M_frame_loop_end(), M_fov_adjust(), object_hrc_blend_list(), + object_hrc_blend(), now_pause(), event_time_unread_ptr() { + hash = hash_murmurhash_empty; + init(); + } + + // 0x1401B93F0 + Scene::~Scene() { + init(); + } + + // 0x1401D79C0 + void Scene::init() { + M_uid = -1; + my_handle = -1; + M_is_enabled = false; + M_camera_is_enabled = true; + M_is_visible = true; + M_is_looped = false; + M_is_start = false; + M_is_finished = false; + M_is_reverse_side = false; + M_is_auto_disable = false; + + base_matrix = mat4_identity; + trnsl = 1.0f; + trnsl_state = mdl::OBJ_ALPHA_ORDER_POST_GLITTER; + + M_is_attribute_wall = false; + + item_attr_map.clear(); + item_texchg_list.clear(); + item_texchg_list.shrink_to_fit(); + + M_assign_rob_id = ROB_ID_NULL; + M_ex_node_mat = 0; + M_obj_uid = {}; + + M_shadow = false; + M_chara_item = false; + M_reflect = false; + + M_cn_src = CN_MAX; + M_cn_dst = CN_MAX; + M_debug = 0; + M_data = 0; + + M_frc = get_sys_frame_rate(); + M_frame = 0.0f; + frame_req = 0.0f; + frame_max = -1.0f; + + is_requested_frame = true; + + M_frame_loop_begin = 0.0f; + M_frame_loop_end = 0.0f; + M_fov_adjust = 1.0f; + + object_hrc_blend_list = 0; + object_hrc_blend = 0.0f; + now_pause = true; + + for (Event*& i : event_list) + if (i) { + delete i; + i = 0; + } + + event_list.clear(); + event_list.shrink_to_fit(); + event_time_list.clear(); + event_time_list.shrink_to_fit(); + event_time_unread_ptr = event_time_list.begin(); + + play_control.init(); + + point_list.clear(); + point_list.shrink_to_fit(); + curve_list.clear(); + curve_list.shrink_to_fit(); + + camera_root_list.clear(); + camera_root_list.shrink_to_fit(); + camera_auxiliary.init(); + + light_list.clear(); + light_list.shrink_to_fit(); + + // MGF + ambient_list.clear(); + ambient_list.shrink_to_fit(); + + fog_list.clear(); + fog_list.shrink_to_fit(); + + post_process.init(); + dof.init(); + + chara_list.clear(); + chara_list.shrink_to_fit(); + motion_list.clear(); + motion_list.shrink_to_fit(); + + object_holder.clear(); + object_holder.shrink_to_fit(); + object_list.clear(); + object_list.shrink_to_fit(); + object_hrc_holder.clear(); + object_hrc_holder.shrink_to_fit(); + object_hrc_list.clear(); + object_hrc_list.shrink_to_fit(); + m_object_hrc_holder.clear(); + m_object_hrc_holder.shrink_to_fit(); + m_object_hrc_list.clear(); + m_object_hrc_list.shrink_to_fit(); + + adx_sound_list.clear(); + adx_sound_list.shrink_to_fit(); + + // X/XHD + material_list.clear(); + material_list.shrink_to_fit(); + + object_name_list.clear(); + object_name_list.shrink_to_fit(); + object_hrc_name_list.clear(); + object_hrc_name_list.shrink_to_fit(); + m_object_hrc_name_list.clear(); + m_object_hrc_name_list.shrink_to_fit(); + + auth_2d_list.clear(); + auth_2d_list.shrink_to_fit(); + + load_state = S_BEFORE_LOADING; + + my_event_listener.clear(); + my_event_listener.shrink_to_fit(); + + file_name.clear(); + file_name.shrink_to_fit(); + hash = hash_murmurhash_empty; + obj_db = 0; + tex_db = 0; + } + + // 0x1401D01C0 + void Scene::destroy(render_context* rctx) { + camera_auxiliary.dest(rctx); + + for (Light& i : light_list) + i.dest(rctx); + + for (Fog& i : fog_list) + i.dest(rctx); + + dof.dest(rctx); + post_process.dest(rctx); + + for (Event* i : event_list) + if (i->active) { + i->active = false; + i->exit(*this, EAF_DESTROY, rctx); + } + + if (load_state != S_BEFORE_LOADING) + if (hash == hash_murmurhash_empty) { + data_struct* aft_data = &data_list[DATA_AFT]; + auth_3d_database* aft_auth_3d_db = &aft_data->data_ft.auth_3d_db; + g_manager->uid_free(M_uid, aft_auth_3d_db); + } + else + g_manager->uid_free_modern(hash); + init(); + } + + // 0x1401D6310 + int32_t Scene::get_uid() const { + return M_uid; + } + + // 0x1401CF110 + void Scene::ctrl(render_context* rctx) { + M_load_exec(); + + if (load_state != S_DONE || !M_is_enabled) + return; + + EventActionFlag eaf = (EventActionFlag)0; + bool set = false; + while (true) { + bool is_start = M_is_start; + if (is_requested_frame) { + is_requested_frame = false; + if (frame_req < M_frame) { + event_time_unread_ptr = event_time_list.begin(); + enum_or(eaf, EAF_JUMP_BACKWARD); + } + else + enum_or(eaf, EAF_JUMP_FORWARD); + M_frame = frame_req; + M_is_start = true; + M_is_finished = false; + if (frame_max >= 0.0f && M_frame >= frame_max) + frame_max = -1.0f; + } + else if (!now_pause) { + enum_or(eaf, EAF_PASS); + M_frame += M_frc->get_delta_frame(); + if (frame_max >= 0.0f && M_frame > frame_max) + M_frame = frame_max; + } + + float_t frame = M_frame; + for (Point& i : point_list) + i.get(frame); + + for (Curve& i : curve_list) + i.get(frame); + + for (Chara& i : chara_list) + i.get(frame); + + for (Object& i : object_holder) + i.get(frame); + + for (Object*& i : object_list) + i->ctrl(base_matrix); + + for (HierarchyObject& i : object_hrc_holder) + i.get(frame); + + for (HierarchyObject*& i : object_hrc_list) + i->ctrl(base_matrix); + + for (MultiHierarchyObject& i : m_object_hrc_holder) + i.get(frame); + + for (MultiHierarchyObject*& i : m_object_hrc_list) + i->ctrl(base_matrix); + + // X/XHD + for (MaterialList& i : material_list) + i.get(frame); + + for (Light& i : light_list) { + i.get(frame); + i.ctrl(rctx); + } + + // MGF + for (Ambient& i : ambient_list) { + i.get(frame); + i.ctrl(rctx); + } + + for (Fog& i : fog_list) { + i.get(frame); + i.ctrl(rctx); + } + + post_process.get(frame); + post_process.ctrl(*this, rctx); + + for (Chara& i : chara_list) + i.ctrl(*this); + + auto i_event = event_time_unread_ptr; + auto i_event_end = event_time_list.end(); + for (; i_event != i_event_end && frame >= i_event->frame; i_event++) { + Event* e = event_list[i_event->event_index]; + if (!i_event->type) { + event_log(" [%s]: [%s][%s]\n", + get_ID_EVENT_TYPE(e->type), e->ref.c_str(), e->param1.c_str()); + e->entry(*this, eaf, rctx); + e->active = true; + } + else if (i_event->type) { + event_log(" [%s]: [%s][%s]\n", + get_ID_EVENT_TYPE(e->type), e->ref.c_str(), e->param1.c_str()); + if (e->active) { + e->active = false; + e->exit(*this, eaf, rctx); + } + } + } + event_time_unread_ptr = i_event; + + for (Event* i : event_list) + if (i->active) + i->do_ctrl(*this, eaf, rctx); + + camera_auxiliary.get(frame); + camera_auxiliary.ctrl(*this, rctx); + + if (M_camera_is_enabled) + for (CameraRoot& i : camera_root_list) { + CameraParam cam = i.get(frame, *this, rctx); + + if (M_is_reverse_side) { + cam.interest.x = -cam.interest.x; + cam.view_point.x = -cam.view_point.x; + cam.roll = -cam.roll; + } + + mat4_transform_point(&base_matrix, &cam.interest, &cam.interest); + mat4_transform_point(&base_matrix, &cam.view_point, &cam.view_point); + + cam.set(rctx->camera); + break; + } + + dof.get(frame); + dof.ctrl(rctx); + + if (M_is_start && is_start != M_is_start) + for (a3d::EventListener*& i : my_event_listener) { + Handle handle = to_handle(); + i->playStart(handle); + } + + if (set || !M_is_looped || M_frame_loop_end > frame) + break; + + for (a3d::EventListener*& i : my_event_listener) { + Handle handle = to_handle(); + i->playLoopJumpBefore(handle); + } + + frame_req = frame - M_frame_loop_end + M_frame_loop_begin; + is_requested_frame = true; + set = true; + } + + for (a3d::EventListener*& i : my_event_listener) { + Handle handle = to_handle(); + i->playLoopJumpAfter(handle); + } + + bool is_finished = play_control.size <= M_frame; + if (is_finished && M_is_finished != is_finished) { + now_pause = true; + if (M_is_auto_disable) + M_is_enabled = false; + + for (a3d::EventListener*& i : my_event_listener) { + Handle handle = to_handle(); + i->playFinished(handle); + } + } + M_is_finished = is_finished; + } + + // 0x1401D1230 + void Scene::disp(render_context* rctx) { + if (load_state != S_DONE || !M_is_enabled) + return; + + if (M_debug) + debug_put_line_axis(base_matrix); + + // X/XHD + auth_3d_set_material_list(*this, rctx); + extern bool reflect_full; + extern bool reflect_draw; + reflect_draw = reflect_full && M_reflect; + + for (Point& i : point_list) + i.disp(*this, rctx); + + for (Chara& i : chara_list) + i.disp(*this, base_matrix, rctx); + + for (Object*& i : object_list) + i->disp(*this, rctx); + + for (HierarchyObject*& i : object_hrc_list) + i->disp(*this, rctx); + + for (MultiHierarchyObject*& i : m_object_hrc_list) + i->disp(*this, rctx); + + for (Event* i : event_list) + if (i->active) + i->do_disp(*this, base_matrix, rctx); + + reflect_draw = false; + rctx->disp_manager->set_material_list(); + } + + // 0x1401E0FC0 + void Scene::load_req(const auth_3d_database* auth_3d_db) { + if (g_manager->uid_load_req(M_uid, auth_3d_db)) + load_state = S_NOW_LOADING; + } + + // Added + void Scene::load_req_modern() { + if (g_manager->uid_load_req_modern(hash)) + load_state = S_NOW_LOADING; + } + + // 0x1401C1AE0 + void Scene::M_put_obj(const mat4& in_mat, object_info in_id, render_context* rctx) const { + if (trnsl < 0.999f) + rctx->disp_manager->entry_obj_by_object_info(in_mat, in_id, trnsl); + else + rctx->disp_manager->entry_obj_by_object_info(in_mat, in_id); + } + + // 0x1401E06D0 + bool Scene::load_is_done() const { + return load_state == S_DONE; + } + + // 0x1401C92A0 + void Scene::add_event_listener(a3d::EventListener* in_evt_list) { + my_event_listener.push_back(in_evt_list); + } + + // 0x1401E3490 + void Scene::remove_event_listener(a3d::EventListener* in_evt_list) { + prj::find_and_erase(my_event_listener, in_evt_list); + } + + // 0x1401BF9C0 + void Scene::M_loadFromProperties(SceneFile& in_file, + const object_database* in_obj_db, const texture_database* in_tex_db) { + a3d::Scene& prop = in_file.prop; + + hash = hash_murmurhash_empty; + play_control.load(in_file, prop.play_control); + + in_file.frame_max = play_control.size; + frame_max = play_control.size; + + M_frame_loop_begin = 0.0f; + M_frame_loop_end = play_control.size; + + obj_db = in_obj_db; + tex_db = in_tex_db; + + list_load(point_list, in_file, prop.point); + list_load(curve_list, in_file, prop.curve); + list_load(camera_root_list, in_file, prop.camera_root); + + camera_auxiliary.load(in_file, prop.camera_auxiliary); + + list_load(light_list, in_file, prop.light); + + // MGF + list_load(ambient_list, in_file, prop.ambient); + + list_load(fog_list, in_file, prop.fog); + + post_process.load(in_file, prop.post_process); + dof.load(in_file, prop.dof); + + list_load(chara_list, in_file, prop.chara); + list_load(motion_list, in_file, prop.motion); + list_load(auth_2d_list, in_file, prop.auth_2d); + + list_load(object_holder, in_file, prop.object, obj_db, tex_db); + + size_t object_index = 0; + for (Object& i : object_holder) { + i.replace_chara(M_cn_src, M_cn_dst, obj_db); + i.index = object_index++; + } + + if (prop.object_list.size()) + object_name_list.assign(prop.object_list.begin(), prop.object_list.end()); + + for (Object& i : object_holder) { + if (i.obj_pat.name.size()) { + size_t index = get_curve_index(i.obj_pat.name); + if (index != -1) + i.obj_pat.bind(curve_list[index]); + } + + if (i.obj_morph.name.size()) { + size_t index = get_curve_index(i.obj_morph.name); + if (index != -1) + i.obj_morph.bind(curve_list[index]); + } + + for (Texture& j : i.texture_list) + if (j.tex_pat.name.size()) { + size_t index = get_curve_index(j.tex_pat.name); + if (index != -1) + j.tex_pat.bind(curve_list[index]); + } + + i.prepare_morph(obj_db); + } + + object_list.reserve(object_name_list.size()); + for (const std::string& i : object_name_list) + object_list.push_back(&object_holder[get_object_index(i)]); + + list_load(object_hrc_holder, in_file, prop.object_hrc, obj_db); + + for (HierarchyObject& i : object_hrc_holder) { + i.ex_node_mat = M_ex_node_mat; + bool v45 = i.replace_chara(M_cn_src, M_cn_dst, obj_db); + object_info obj_uid; + if (!v45 && !i.parent_name.size()) + obj_uid = M_obj_uid; + i.set_obj_uid(obj_uid); + } + + std::string chara_str; + if (M_assign_rob_id >= 0 || M_assign_rob_id < ROB_ID_MAX) { + std::string char_str = get_char_id_str(get_rob_management()->get_chara((ROB_ID)M_assign_rob_id)); + chara_str.assign("_" + char_str); + } + else + chara_str.assign("____"); + + for (HierarchyObject& i : object_hrc_holder) + i.check_rob_chara(chara_str); + + if (prop.object_hrc_list.size()) + object_hrc_name_list.assign(prop.object_hrc_list.begin(), prop.object_hrc_list.end()); + + object_hrc_list.reserve(object_hrc_name_list.size()); + for (const std::string& i : object_hrc_name_list) { + size_t index = get_object_hrc_index(i); + if (index != -1) + object_hrc_list.push_back(&object_hrc_holder[index]); + } + + list_load(m_object_hrc_holder, in_file, prop.m_object_hrc, obj_db); + + if (prop.m_object_hrc_list.size()) + m_object_hrc_name_list.assign(prop.m_object_hrc_list.begin(), prop.m_object_hrc_list.end()); + + m_object_hrc_list.reserve(m_object_hrc_name_list.size()); + for (const std::string& i : m_object_hrc_name_list) { + size_t index = get_m_object_hrc_index(i); + if (index != -1) + m_object_hrc_list.push_back(&m_object_hrc_holder[index]); + } + + if (object_holder.size()) { + for (Object& i : object_holder) { + if (!i.parent_name.size()) + continue; + + if (i.parent_node.size()) + for (HierarchyObject& j : object_hrc_holder) { + if (i.parent_name.compare(j.name)) + continue; + + int32_t node_index = j.query_node_index(i.parent_node.c_str()); + if (node_index >= 0) + j.add_child_object(node_index, &i); + break; + } + else + for (Object& j : object_holder) { + if (i.parent_name.compare(j.name)) + continue; + + j.child_object_list.push_back(&i); + break; + } + } + } + + if (object_hrc_holder.size()) { + for (HierarchyObject& i : object_hrc_holder) { + if (!i.parent_name.size()) + continue; + + if (i.parent_node.size()) + for (HierarchyObject& j : object_hrc_holder) { + if (i.parent_name.compare(j.name)) + continue; + + int32_t node_index = j.query_node_index(i.parent_node.c_str()); + if (node_index >= 0) + j.add_child_object(node_index, &i); + break; + } + else + for (Object& j : object_holder) { + if (i.parent_name.compare(j.name)) + continue; + + j.child_object_hrc_list.push_back(&i); + break; + } + } + } + + adx_sound_list.clear(); + + // X/XHD + list_load(material_list, in_file, prop.material_list); + + if (prop.event.size()) { + event_list.reserve(prop.event.size()); + + for (const a3d::Event& i : prop.event) { + Event* e = createEvent(in_file, i); + if (e) { + event_list.push_back(e); + + if (e->type == a3d::EVENT_SND) { + std::string param1(e->param1); + if (param1.find("_adx") == param1.size() - 4) + adx_sound_list.push_back(param1); + } + } + } + + if (adx_sound_list.size()) { + std::string path("rom/sound/voice/auth_voice/"); + path.append(adx_sound_list.front()); + path.append(".adx"); + sound_work_play_stream(2, path.c_str(), true); + } + + for (Event* i : event_list) + if (i) + i->resolve_relation(*this); + } + + event_time_list.clear(); + event_time_list.shrink_to_fit(); + + if (event_list.size()) { + size_t event_index = 0; + event_time_list.reserve(event_list.size() * 2); + for (Event* i : event_list) { + event_time_list.push_back({ i->begin, 0, event_index }); + event_time_list.push_back({ i->end , 1, event_index }); + event_index++; + } + + std::sort(event_time_list.begin(), event_time_list.end(), + [](const TimeEvent& left, const TimeEvent& right) { + return left.frame < right.frame; + }); + } + + event_time_unread_ptr = event_time_list.begin(); + + file_name.assign(prop._file_name); + } + + // Added + void Scene::M_storeToProperties(SceneFile& in_file) const { + a3d::Scene& prop = in_file.prop; + + play_control.store(in_file, prop.play_control); + + list_store(point_list, in_file, prop.point); + list_store(curve_list, in_file, prop.curve); + list_store(camera_root_list, in_file, prop.camera_root); + + camera_auxiliary.store(in_file, prop.camera_auxiliary); + + list_store(light_list, in_file, prop.light); + + // MGF + list_store(ambient_list, in_file, prop.ambient); + + list_store(fog_list, in_file, prop.fog); + + post_process.store(in_file, prop.post_process); + dof.store(in_file, prop.dof); + + list_store(chara_list, in_file, prop.chara); + list_store(motion_list, in_file, prop.motion); + list_store(auth_2d_list, in_file, prop.auth_2d); + + list_store(object_holder, in_file, prop.object); + + if (object_name_list.size()) + prop.object_list.assign(object_name_list.begin(), object_name_list.end()); + + list_store(object_hrc_holder, in_file, prop.object_hrc); + + if (object_hrc_name_list.size()) + prop.object_hrc_list.assign( + object_hrc_name_list.begin(), object_hrc_name_list.end()); + + list_store(m_object_hrc_holder, in_file, prop.m_object_hrc); + + if (m_object_hrc_name_list.size()) + prop.m_object_hrc_list.assign( + m_object_hrc_name_list.begin(), m_object_hrc_name_list.end()); + + // X/XHD + list_store(material_list, in_file, prop.material_list); + + if (event_list.size()) { + size_t event_index = 0; + prop.motion.resize(event_list.size()); + for (const Event* i : event_list) + i->store(in_file, prop.event[event_index++]); + } + } + + // 0x1401D8C10 + inline bool Scene::is_valid() const { + return my_handle != -1; + } + + // 0x1401E6730 + void Scene::set_frame_rate_control(FrameRateControl* in_value) { + if (in_value) + M_frc = in_value; + else + M_frc = get_sys_frame_rate(); + } + + // 0x1401D58D0 + float_t Scene::get_frame_speed() const { + return M_frc->get_delta_frame(); + } + + // 0x1401E67B0 + void Scene::set_frame_req(float_t in_frame) { + frame_req = in_frame; + is_requested_frame = true; + } + + void Scene::set_frame_max(float_t in_frame) { + frame_max = in_frame; + } + + float_t Scene::get_frame() const { + return M_frame; + } + + float_t Scene::get_frame_size() const { + return play_control.size; + } + + float_t Scene::get_frame_fps() const { + return play_control.fps; + } + + float_t Scene::get_frame_begin() const { + return play_control.begin; + } + + // 0x1401E6A50 + void Scene::set_pause(bool in_value) { + now_pause = in_value; + } + + // 0x1401D5DD0 + bool Scene::get_pause() const { + return now_pause; + } + + // 0x1401E6460 + void Scene::set_enabled(bool in_value) { + M_is_enabled = in_value; + } + + // 0x1401D55C0 + bool Scene::get_enabled() const { + return M_is_enabled; + } + + // 0x1401E6BC0 + void Scene::set_visible(bool in_value) { + M_is_visible = in_value; + } + + // 0x1401D64E0 + bool Scene::get_visible() const { + return M_is_visible; + } + + // 0x1401E6990 + void Scene::set_looped(bool in_value) { + M_is_looped = in_value; + } + + // 0x1401D59D0 + bool Scene::get_looped() const { + return M_is_looped; + } + + // 0x1401E65F0 + void Scene::set_frame_loop_begin(float_t in_frame) { + M_frame_loop_begin = in_frame; + } + + // 0x1401E6600 + void Scene::set_frame_loop_begin() { + M_frame_loop_begin = 0.0f; + } + + // 0x1401D5800 + float_t Scene::get_frame_loop_begin() const { + return M_frame_loop_begin; + } + + // 0x1401E6690 + void Scene::set_frame_loop_end(float_t in_frame) { + M_frame_loop_end = in_frame; + } + + // 0x1401E66A0 + void Scene::set_frame_loop_end() { + M_frame_loop_end = play_control.size; + } + + // 0x1401D5850 + float_t Scene::get_frame_loop_end() const { + return M_frame_loop_end; + } + + // 0x1401D8AF0 + bool Scene::is_finished() const { + return M_is_finished; + } + + // 0x1401E6AC0 + void Scene::set_reverse_side(bool in_value) { + M_is_reverse_side = in_value; + } + + // 0x1401D5EA0 + bool Scene::get_reverse_side() const { + return M_is_reverse_side; + } + + // 0x1401E6320 + void Scene::set_auto_disable(bool in_value) { + M_is_auto_disable = in_value; + } + + // 0x1401D51F0 + bool Scene::get_auto_disable() const { + return M_is_auto_disable; + } + + // 0x1401E6370 + void Scene::set_base_matrix(const mat4& in_value) { + base_matrix = in_value; + } + + // 0x1401D5280 + const mat4& Scene::get_base_matrix() const { + return base_matrix; + } + + // 0x1401E6B60 + void Scene::set_trnsl(float_t in_value, mdl::ObjFlags in_state) { + trnsl = in_value; + trnsl_state = in_state; + } + + // 0x1401D6110 + float_t Scene::get_trnsl() const { + return trnsl; + } + + // 0x1401E62D0 + void Scene::set_attribute_wall(bool in_value) { + M_is_attribute_wall = in_value; + } + + // 0x1401D50E0 + bool Scene::get_attribute_wall() const { + return M_is_attribute_wall; + } + + // 0x1401E6860 + void Scene::set_item_attr(uint32_t in_id, uint32_t in_attr) { + item_attr_map.insert({ in_id, in_attr }); + } + + // Missing + uint32_t Scene::get_item_attr(uint32_t in_id) const { + auto elem = item_attr_map.find(in_id); + if (elem != item_attr_map.end()) + return elem->second; + return 0; + } + + // 0x1401E68E0 + void Scene::set_item_texchange(const std::vector& in_list) { + item_texchg_list.assign(in_list.begin(), in_list.end()); + } + + // Missing + const std::vector& Scene::get_item_texchange() const { + return item_texchg_list; + } + + // 0x1401D5480 + inline size_t Scene::get_chara_size() const { + return chara_list.size(); + } + + // 0x1401D5400 + inline size_t Scene::get_chara_index(const std::string& in_name) const { + return get_index_by_name(chara_list, in_name); + } + + // 0x1401CBF60 + const std::string* Scene::chara_get_name(size_t in_index) const { + if (in_index < chara_list.size()) + return &chara_list[in_index].name; + return 0; + } + + // Inlined + void Scene::chara_bind_rob(size_t in_index, int32_t in_rob_id) { + if (in_index < chara_list.size() + && (in_rob_id == ROB_ID_NULL || in_rob_id == ROB_ID_1P || in_rob_id == ROB_ID_2P) + && chara_list[in_index].rob_id != in_rob_id) + chara_list[in_index].rob_id = in_rob_id; + } + + // 0x1401D5C80 + size_t Scene::get_object_size() const { + return object_holder.size(); + } + + // 0x1401D5AD0 + size_t Scene::get_object_index(const std::string& in_name) const { + return get_index_by_name(object_holder, in_name); + } + + // 0x1401D5AE0 + int32_t Scene::get_object_index(object_info in_obj_uid, int32_t in_instance) const { + if (in_instance >= 0) { + int32_t index = 0; + int32_t instance = 0; + for (auto i = object_holder.cbegin(); i != object_holder.cend(); i++, index++) + if (in_obj_uid == i->obj_uid) { + if (in_instance == instance) + return index; + instance++; + } + return -1; + } + + int32_t index = 0; + for (auto i = object_holder.cbegin(); i != object_holder.cend(); i++, index++) + if (in_obj_uid == i->obj_uid) + return index; + return -1; + } + + // Added + int32_t Scene::get_object_index(uint32_t in_obj_hash, int32_t in_instance) const { + if (in_instance >= 0) { + int32_t index = 0; + int32_t instance = 0; + for (auto i = object_holder.cbegin(); i != object_holder.cend(); i++, index++) + if (in_obj_hash == i->obj_hash) { + if (in_instance == instance) + return index; + instance++; + } + return -1; + } + + int32_t index = 0; + for (auto i = object_holder.cbegin(); i != object_holder.cend(); i++, index++) + if (in_obj_hash == i->obj_hash) + return index; + return -1; + } + + // Inlined + const std::string* Scene::object_get_name(size_t in_index) const { + if (in_index < object_holder.size()) + return &object_holder[in_index].name; + return 0; + } + + // 0x1401D5B70 + const mat4* Scene::get_object_matrix(size_t in_index) const { + if (in_index < object_holder.size()) + return &object_holder[in_index].model_transform.matrix; + return 0; + } + + // Inlined + const mat4* Scene::get_object_matrix(size_t in_index, bool in_is_hrc) const { + if (in_is_hrc) + return get_object_hrc_matrix(in_index); + return get_object_matrix(in_index); + } + + // Inlined + inline size_t Scene::get_object_hrc_size() const { + return object_hrc_holder.size(); + } + + // 0x0x1401D5CB0 + size_t Scene::get_object_hrc_index(const std::string& in_name) const { + return get_index_by_name(object_hrc_holder, in_name); + } + + // 0x1401D5CC0 + int32_t Scene::get_object_hrc_index(object_info in_obj_uid, int32_t in_instance) const { + if (in_instance >= 0) { + int32_t index = 0; + int32_t instance = 0; + for (auto i = object_hrc_holder.cbegin(); i != object_hrc_holder.cend(); i++, index++) + if (in_obj_uid == i->obj_uid) { + if (in_instance == instance) + return index; + instance++; + } + return -1; + } + + int32_t index = 0; + for (auto i = object_hrc_holder.cbegin(); i != object_hrc_holder.cend(); i++, index++) + if (in_obj_uid == i->obj_uid) + return index; + return -1; + } + + // Added + int32_t Scene::get_object_hrc_index(uint32_t in_obj_hash, int32_t in_instance) const { + if (in_instance >= 0) { + int32_t index = 0; + int32_t instance = 0; + for (auto i = object_hrc_holder.cbegin(); i != object_hrc_holder.cend(); i++, index++) + if (in_obj_hash == i->obj_hash) { + if (in_instance == instance) + return index; + instance++; + } + return -1; + } + + int32_t index = 0; + for (auto i = object_hrc_holder.cbegin(); i != object_hrc_holder.cend(); i++, index++) + if (in_obj_hash == i->obj_hash) + return index; + return -1; + } + + // Missing + const std::string* Scene::object_hrc_get_name(size_t in_index) const { + if (in_index < object_hrc_holder.size()) + return &object_hrc_holder[in_index].name; + return 0; + } + + // 0x1401D5D00 + const mat4* Scene::get_object_hrc_matrix(size_t in_index) const { + if (in_index < object_hrc_holder.size()) { + const HierarchyObject& hrc_obj = object_hrc_holder[in_index]; + if (hrc_obj.mats.size()) + return &hrc_obj.mats[0]; + } + return 0; + } + + // Inlined + inline size_t Scene::get_m_object_hrc_size() const { + return m_object_hrc_holder.size(); + } + + // 0x1401D5A70 + size_t Scene::get_m_object_hrc_index(const std::string& in_name) const { + return get_index_by_name(m_object_hrc_holder, in_name); + } + + // Missing + const std::string* Scene::m_object_hrc_get_name(size_t in_index) const { + if (in_index < m_object_hrc_holder.size()) + return &m_object_hrc_holder[in_index].name; + return 0; + } + + // 0x1401CB5C0 + void Scene::camera_set_enabled(bool in_value) { + M_camera_is_enabled = in_value; + } + + // 0x1401CB510 + bool Scene::camera_get_enabled() const { + return M_camera_is_enabled; + } + + // 0x1401CB610 + void Scene::camera_set_fov_adjust(float_t in_value) { + M_fov_adjust = in_value; + } + + // 0x1401CB570 + float_t Scene::camera_get_fov_adjust() const { + return M_fov_adjust; + } + + // 0x1401D5190 + size_t Scene::get_auth_2d_size() const { + return auth_2d_list.size(); + } + + // 0x1401D5140 + size_t Scene::get_auth_2d_index(const std::string& in_name) const { + return get_index_by_name(auth_2d_list, in_name); + } + + // 0x1401CA890 + const std::string* Scene::auth_2d_get_name(size_t in_index) const { + if (in_index < get_auth_2d_size()) + return &auth_2d_list[in_index].name; + return 0; + } + + // 0x1401D5DE0 + size_t Scene::get_point_index(const std::string& in_name) const { + return get_index_by_name(point_list, in_name); + } + + // 0x1401D54B0 + size_t Scene::get_curve_index(const std::string& in_name) const { + return get_index_by_name(curve_list, in_name); + } + + // Missing + void Scene::set_data(size_t in_value) { + M_data = in_value; + } + + // Missing + size_t Scene::get_data() const { + return M_data; + } + + // 0x1401E63D0 + void Scene::set_debug(uint32_t in_value) { + M_debug = in_value; + } + + // 0x1401D5570 + uint32_t Scene::get_debug() const { + return M_debug; + } + + // 0x1401CA880 + void Scene::assign_rob_id(int32_t in_value) { + M_assign_rob_id = in_value; + } + + // 0x1401D5090 + int32_t Scene::get_assign_rob_id() const { + return M_assign_rob_id; + } + + // 0x1401E6A00 + void Scene::set_obj_uid(object_info in_value) { + M_obj_uid = in_value; + } + + // 0x1401E6B10 + void Scene::set_shadow(bool in_value) { + M_shadow = in_value; + } + + // 0x1401D8B00 + bool Scene::is_shadow() const { + return M_shadow; + } + + // 0x1401E3B70 + void Scene::replace_chara(int32_t in_cn_src, int32_t in_cn_dst) { + M_cn_src = in_cn_src; + M_cn_dst = in_cn_dst; + } + + // 0x1401E64D0 + void Scene::set_frame_object_hrc(float_t in_frame) { + M_is_start = true; + now_pause = true; + M_is_finished = !(in_frame < play_control.size); + M_frame = in_frame; + + if (frame_max >= 0.0f && frame_max <= in_frame) + frame_max = -1.0f; + } + + // 0x1401E68F0 + void Scene::set_object_hrc_blend(const Scene * in_scene, float_t in_value) { + if (in_scene && object_hrc_list.size() + && object_hrc_list.size() == in_scene->object_hrc_list.size()) { + object_hrc_blend_list = &in_scene->object_hrc_list; + object_hrc_blend = in_value; + } + else { + object_hrc_blend_list = 0; + object_hrc_blend = 0.0f; + } + } + + // Inlined + inline void Scene::calc_matrix_hierarchy(const mat4& in_value) { + base_matrix = in_value; + calc_matrix_hierarchy_mul(); + } + + // 0x1401CB250 + void Scene::calc_matrix_hierarchy_get() { + if (M_ex_node_mat) + for (HierarchyObject*& i : object_hrc_list) + i->calc_matrix_hierarchy(base_matrix); + } + + // 0x1401CB2B0 + void Scene::calc_matrix_hierarchy_mul() { + if (M_ex_node_mat) + for (HierarchyObject*& i : object_hrc_list) + i->calc_matrix_hierarchy(base_matrix); + } + + // 0x1401D91C0 + void Scene::join() { + if (!M_ex_node_mat || !object_hrc_blend_list + || object_hrc_list.size() != object_hrc_blend_list->size()) + return; + + float_t blend = object_hrc_blend; + float_t inv_blend = 1.0f - object_hrc_blend; + for (size_t i = 0; i < object_hrc_list.size(); i++) + object_hrc_list[i]->join(*(*object_hrc_blend_list)[i], blend, inv_blend); + } + + // 0x1401D9850 + void Scene::join_lock() { + if (!M_ex_node_mat || !object_hrc_blend_list + || object_hrc_list.size() != object_hrc_blend_list->size()) + return; + + float_t blend = object_hrc_blend; + float_t inv_blend = 1.0f - object_hrc_blend; + for (size_t i = 0; i < object_hrc_list.size(); i++) + object_hrc_list[i]->join_lock(*(*object_hrc_blend_list)[i], blend, inv_blend); + } + + // 0x1401E64B0 + void Scene::set_ex_node_mat(mat4* in_value) { + M_ex_node_mat = in_value; + } + + // 0x1401D8AA0 + bool Scene::is_ex_node_mat() const { + return M_ex_node_mat; + } + + // 0x1401E1280 + void Scene::lock_list_set() { + for (HierarchyObject*& i : object_hrc_list) + i->lock_set(); + } + + // Added + void Scene::set_chara_item(bool in_value) { + M_chara_item = in_value; + } + + // Added + bool Scene::get_chara_item() const { + return M_chara_item; + } + + // Added + void Scene::set_reflect(bool in_value) { + M_reflect = in_value; + } + + // Added + bool Scene::get_reflect() const { + return M_reflect; + } + + // 0x1401B27B0 + Auth3dManager::Auth3dManager() { + + } + + // 0x1401B7DC0 + Auth3dManager::~Auth3dManager() { + + } + + // Inlined + inline UidData* Auth3dManager::get_uid_data(int32_t in_uid, const auth_3d_database* auth_3d_db) { + if (in_uid >= auth_3d_db->uid.size()) + return 0; + + const auth_3d_database_uid* db_uid = &auth_3d_db->uid[in_uid]; + if (db_uid && db_uid->enabled) { + UidData* uid_data = &uid_data_list[in_uid]; + if (uid_data->uid == in_uid) + return uid_data; + } + return 0; + } + + // Added + inline UidDataModern* Auth3dManager::get_uid_data_modern(uint32_t hash) { + auto elem = uid_data_list_modern.find(hash); + if (elem == uid_data_list_modern.end()) + return 0; + + UidDataModern* uid_data = &elem->second; + if (uid_data->hash == hash) + return uid_data; + return 0; + } + + // 0x1401CBA80 + void Auth3dManager::category_free(const char* in_name) { + if (!in_name) + return; + + CategoryData* category_data = get_category_data(in_name); + if (category_data) + category_data->free(); + } + + // Added + void Auth3dManager::category_free(uint32_t in_hash) { + if (!in_hash || in_hash == hash_murmurhash_empty) + return; + + auto elem = category_data_list_modern.find(in_hash); + if (elem != category_data_list_modern.end()) { + elem->second.free(); + if (elem->second.ref_count <= 0) + category_data_list_modern.erase(elem); + } + } + + // 0x1401CBDF0 + bool Auth3dManager::category_load_is_done(const char* in_name) { + if (!in_name) + return true; + + CategoryData* category_data = get_category_data(in_name); + if (category_data) + return category_data->load_is_done(); + return true; + } + + // Added + bool Auth3dManager::category_load_is_done(uint32_t in_hash) { + if (!in_hash || in_hash == hash_murmurhash_empty) + return true; + + auto elem = category_data_list_modern.find(in_hash); + if (elem != category_data_list_modern.end()) + return elem->second.load_is_done(); + return true; + } + + // 0x1401CBE30 + void Auth3dManager::category_load_req(const char* in_name, const char* in_mdata_dir) { + if (!in_name) + return; + + CategoryData* category_data = get_category_data(in_name); + if (category_data) + category_data->load_req(in_mdata_dir); + } + + // Added + void Auth3dManager::category_load_req(void* data, const char* in_name, uint32_t in_hash) { + if (!in_hash || in_hash == hash_murmurhash_empty) + return; + + auto elem = category_data_list_modern.find(in_hash); + if (elem == category_data_list_modern.end()) { + elem = category_data_list_modern.insert({ in_hash, {} }).first; + CategoryData* category_data = &elem->second; + category_data->category_name.assign(in_name); + } + + CategoryData* category_data = &elem->second; + if (category_data) + category_data->load_req_modern(data); + } + + // 0x1401D5B20 + const mat4* Auth3dManager::get_object_matrix(int32_t in_handle, size_t in_index, bool in_is_hrc) const { + const Scene* scene = get_work_enabled(in_handle); + if (scene) + return scene->get_object_matrix(in_index, in_is_hrc); + return 0; + } + + // 0x1401D5A80 + const char* Auth3dManager::get_name_uid(int32_t in_uid, const auth_3d_database* auth_3d_db) const { + if (in_uid >= auth_3d_db->uid.size()) + return 0; + + const auth_3d_database_uid* db_uid = &auth_3d_db->uid[in_uid]; + if (db_uid && db_uid->enabled) + return db_uid->name.c_str(); + return 0; + } + + // Added + Scene* Auth3dManager::get_scene(int32_t in_uid) { + for (int32_t& i : handle_list) { + Scene* scene = get_work(i); + if (scene && scene->M_uid == in_uid) + return scene; + } + return 0; + } + + // Added + Scene* Auth3dManager::get_scene(uint32_t hash) { + for (int32_t& i : handle_list) { + Scene* scene = get_work(i); + if (scene && scene->hash == hash) + return scene; + } + return 0; + } + + // 0x1401D5FA0 + int32_t Auth3dManager::get_scene_object_index(object_info in_obj_uid, + int32_t* out_index, bool* out_is_hrc, int32_t in_instance) { + for (const int32_t handle : handle_list) { + Scene* scene = get_work_enabled(handle); + if (!scene) + continue; + + int32_t obj_hrc_index = scene->get_object_hrc_index(in_obj_uid, in_instance); + if (obj_hrc_index >= 0) { + if (out_index) + *out_index = obj_hrc_index; + if (out_is_hrc) + *out_is_hrc = true; + return handle; + } + + int32_t obj_index = scene->get_object_index(in_obj_uid, in_instance); + if (obj_index >= 0) { + if (out_index) + *out_index = obj_index; + if (out_is_hrc) + *out_is_hrc = false; + return handle; + } + } + return -1; + } + + // Added + int32_t Auth3dManager::get_scene_object_index(uint32_t in_file_name_hash, uint32_t in_obj_hash, + int32_t* out_index, bool* out_is_hrc, int32_t in_instance) { + for (int32_t& i : g_manager->handle_list) { + Scene* scene = get_work_enabled(i); + if (!scene) + continue; + + bool ret = false; + if (in_file_name_hash != hash_murmurhash_empty) { + if (scene->hash != in_file_name_hash) + continue; + ret = true; + } + + int32_t obj_index = scene->get_object_index(in_obj_hash, in_instance); + if (obj_index >= 0) { + if (out_index) + *out_index = obj_index; + if (out_is_hrc) + *out_is_hrc = false; + return i; + } + + int32_t obj_hrc_index = scene->get_object_hrc_index(in_obj_hash, in_instance); + if (obj_hrc_index >= 0) { + if (out_index) + *out_index = obj_hrc_index; + if (out_is_hrc) + *out_is_hrc = true; + return i; + } + + if (ret) + return -1; + } + return -1; + } + + // 0x1401E7DE0 + bool Auth3dManager::uid_load_req(int32_t in_uid, const auth_3d_database* auth_3d_db) { + UidData* uid_data = get_uid_data(in_uid, auth_3d_db); + if (uid_data) { + uid_data->load_req(auth_3d_db); + return true; + } + return false; + } + + // Added + bool Auth3dManager::uid_load_req_modern(uint32_t hash) { + UidDataModern* uid_data = get_uid_data_modern(hash); + if (uid_data) { + uid_data->load_req(); + return true; + } + return false; + } + + // Inlined + void Auth3dManager::uid_free(int32_t in_uid, const auth_3d_database* auth_3d_db) { + UidData* uid_data = get_uid_data(in_uid, auth_3d_db); + if (uid_data) + uid_data->free(); + } + + // Added + void Auth3dManager::uid_free_modern(uint32_t hash) { + UidDataModern* uid_data = get_uid_data_modern(hash); + if (uid_data) + uid_data->free(); + } + + // 0x1401D6910 + bool Auth3dManager::init() { + handle_list.clear(); + handle_list.shrink_to_fit(); + for (int32_t i = 0; i < AUTH_3D_DATA_COUNT; i++) + scene_buffer[i].init(); + return true; + } + + // 0x1401CE370 + bool Auth3dManager::ctrl() { + for (const int32_t handle : handle_list) { + Scene* scene = get_work(handle); + if (scene) + scene->ctrl(rctx_ptr); + } + return false; + } + + // 0x1401D0310 + void Auth3dManager::disp() { + for (const int32_t handle : handle_list) { + Scene* scene = get_work(handle); + if (scene) + scene->disp(rctx_ptr); + } + } + + // Missing + inline const Scene* Auth3dManager::M_get_work(int32_t in_handle) const { + if (in_handle >= 0) { + size_t idx = in_handle & 0x7FFF; + if (idx < AUTH_3D_DATA_COUNT) + return &scene_buffer[idx]; + } + return 0; + } + + // 0x1401BF8F0 + inline Scene* Auth3dManager::M_get_work(int32_t in_handle) { + if (in_handle >= 0) { + size_t idx = in_handle & 0x7FFF; + if (idx < AUTH_3D_DATA_COUNT) + return &scene_buffer[idx]; + } + return 0; + } + + // Missing + inline const Scene* Auth3dManager::get_work(int32_t in_handle) const { + const Scene* scene = M_get_work(in_handle); + if (scene && scene->my_handle == in_handle) + return scene; + return 0; + } + + // 0x1401D64F0 + inline Scene* Auth3dManager::get_work(int32_t in_handle) { + Scene* scene = M_get_work(in_handle); + if (scene && scene->my_handle == in_handle) + return scene; + return 0; + } + + // Missing + inline const Scene* Auth3dManager::get_work_enabled(int32_t in_handle) const { + const Scene* scene = M_get_work(in_handle); + if (scene && scene->my_handle == in_handle && scene->M_is_enabled) + return scene; + return 0; + } + + // Inlined + inline Scene* Auth3dManager::get_work_enabled(int32_t in_handle) { + Scene* scene = M_get_work(in_handle); + if (scene && scene->my_handle == in_handle && scene->M_is_enabled) + return scene; + return 0; + } + + // 0x1401D6580 + int32_t Auth3dManager::create(int32_t uid, const auth_3d_database* auth_3d_db) { + if (uid >= auth_3d_db->uid.size() || !auth_3d_db->uid[uid].enabled) + return -1; + + int32_t index = 0; + while (scene_buffer[index].is_valid() || scene_buffer[index].hash + != hash_murmurhash_empty && scene_buffer[index].hash != -1) + if (++index >= AUTH_3D_DATA_COUNT) + return -1; + + scene_buffer[index].init(); + + if (++magic_number < 0) + magic_number = 1; + + int32_t handle = ((magic_number & 0x7FFF) << 16) | index & 0x7FFF; + scene_buffer[index].M_uid = uid; + scene_buffer[index].my_handle = handle; + handle_list.push_back(handle); + return handle; + } + + // Added + int32_t Auth3dManager::create(uint32_t hash, void* data, + const object_database* obj_db, const texture_database* tex_db) { + int32_t index = 0; + while (scene_buffer[index].is_valid() || scene_buffer[index].hash + != hash_murmurhash_empty && scene_buffer[index].hash != -1) + if (++index >= AUTH_3D_DATA_COUNT) + return -1; + + auto elem = uid_data_list_modern.find(hash); + if (elem == uid_data_list_modern.end()) + elem = uid_data_list_modern.insert({ hash, {} }).first; + + UidDataModern* uid_data = &elem->second; + uid_data->ref_count = 0; + uid_data->hash = hash; + uid_data->file_name.clear(); + uid_data->file_name.shrink_to_fit(); + uid_data->load_state = S_BEFORE_LOADING; + uid_data->name.clear(); + uid_data->name.shrink_to_fit(); + uid_data->category = 0; + uid_data->data = data; + uid_data->obj_db = obj_db; + uid_data->tex_db = tex_db; + + scene_buffer[index].init(); + + if (++magic_number < 0) + magic_number = 1; + + int32_t handle = ((magic_number & 0x7FFF) << 16) | index & 0x7FFF; + scene_buffer[index].hash = hash; + scene_buffer[index].my_handle = handle; + handle_list.push_back(handle); + return handle; + } + + // 0x1401D6710 + void Auth3dManager::destroy(int32_t in_handle, render_context* rctx) { + Scene* scene = get_work(in_handle); + if (scene && prj::find_and_erase(handle_list, in_handle)) + scene->destroy(rctx); + } + + // 0x1401D4FD0 + int32_t Auth3dManager::get_assign_rob_id(int32_t in_handle) const { + const Scene* scene = get_work(in_handle); + if (scene) + return scene->get_assign_rob_id(); + return ROB_ID_NULL; + } + + // 0x1401D5290 + CategoryData* Auth3dManager::get_category_data(const char* in_name) { + if (!in_name || !category_data_list.size()) + return 0; + + uint64_t name_hash = hash_utf8_xxh3_64bits(in_name); + for (CategoryData& i : category_data_list) + if (hash_string_xxh3_64bits(i.category_name) == name_hash) + return &i; + return 0; + } + + // Added + CategoryData* Auth3dManager::get_category_data_modern(uint32_t in_hash) { + for (auto& i : g_manager->category_data_list_modern) + if (i.second.ar && i.second.ar->has_file(in_hash)) + return &i.second; + return 0; + } + + // 0x1401C1ED0 + Handle Handle::S_init(int32_t in_handle) { + return Handle(in_handle); + } + + // Missing + int32_t Handle::get() { + return m_handle; + } + + // 0x1401CDC80 + Handle Handle::create(int32_t uid, const auth_3d_database* auth_3d_db) { + return Handle(g_manager->create(uid, auth_3d_db)); + } + + // Added + Handle Handle::create(uint32_t hash, void* data, + const object_database* obj_db, const texture_database* tex_db) { + return Handle(g_manager->create(hash, data, obj_db, tex_db)); + } + + // 0x1401D0190 + void Handle::destroy(render_context* rctx) { + g_manager->destroy(m_handle, rctx); + m_handle = -1; + } + + // 0x1401D8BC0 + bool Handle::is_valid() const { + const Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->is_valid(); + return false; + } + + void Handle::set_invalid() { + // NOT IMPL! + } + + // 0x1401D62D0 + int32_t Handle::get_uid() const { + const Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->get_uid(); + return -1; + } + + // 0x1401C9230 + void Handle::add_event_listener(a3d::EventListener* in_evt_list) { + Scene* scene = g_manager->get_work(m_handle); + if (scene) + scene->add_event_listener(in_evt_list); + } + + // 0x1401E3420 + void Handle::remove_event_listener(a3d::EventListener* in_evt_list) { + Scene* scene = g_manager->get_work(m_handle); + if (scene) + scene->remove_event_listener(in_evt_list); + } + + // 0x1401E0F80 + void Handle::load_req(const auth_3d_database* auth_3d_db) { + Scene* scene = g_manager->get_work(m_handle); + if (scene) + scene->load_req(auth_3d_db); + } + + // Added + void Handle::load_req_modern() { + Scene* scene = g_manager->get_work(m_handle); + if (scene) + scene->load_req_modern(); + } + + // 0x1401E0680 + bool Handle::load_is_done() const { + const Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->load_is_done(); + return true; + } + + // 0x1401E6760 + void Handle::set_frame_req(float_t in_frame) { + Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->set_frame_req(in_frame); + } + + // 0x1401E6520 + void Handle::set_frame_max(float_t in_frame) { + Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->set_frame_max(in_frame); + } + + // 0x1401D56C0 + float_t Handle::get_frame() const { + const Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->get_frame(); + return 0.0f; + } + + // 0x1401D5860 + float_t Handle::get_frame_size() const { + const Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->get_frame_size(); + return 0.0f; + } + + // 0x1401D5760 + float_t Handle::get_frame_fps() const { + const Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->get_frame_fps(); + return 60.0f; + } + + // 0x1401D5710 + float_t Handle::get_frame_begin() const { + const Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->get_frame_begin(); + return 0.0f; + } + + // 0x1401E66C0 + void Handle::set_frame_rate_control(FrameRateControl* in_value) { + Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->set_frame_rate_control(in_value); + } + + // 0x1401E6A10 + void Handle::set_pause(bool in_value) { + Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->set_pause(in_value); + } + + // 0x1401D5D90 + bool Handle::get_pause() const { + const Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->get_pause(); + return false; + } + + // 0x1401E6420 + void Handle::set_enabled(bool in_value) { + Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->set_enabled(in_value); + } + + // 0x1401D5580 + bool Handle::get_enabled() const { + const Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->get_enabled(); + return false; + } + + // 0x1401E6950 + void Handle::set_looped(bool in_value) { + Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->set_looped(in_value); + } + + // 0x1401D5990 + bool Handle::get_looped() const { + const Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->get_looped(); + return false; + } + + // 0x1401E65B0 + void Handle::set_frame_loop_begin() { + Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->set_frame_loop_begin(); + } + + // 0x1401E6570 + void Handle::set_frame_loop_begin(float_t in_frame) { + Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->set_frame_loop_begin(in_frame); + } + + // 0x1401D57C0 + float_t Handle::get_frame_loop_begin() const { + const Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->get_frame_loop_begin(); + return 0.0f; + } + + // 0x1401E6650 + void Handle::set_frame_loop_end() { + Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->set_frame_loop_end(); + } + + // 0x1401E6610 + void Handle::set_frame_loop_end(float_t in_frame) { + Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->set_frame_loop_end(in_frame); + } + + // 0x1401D5810 + float_t Handle::get_frame_loop_end() const { + const Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->get_frame_loop_end(); + return 0.0f; + } + + // 0x1401D8AB0 + bool Handle::is_finished() const { + const Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->is_finished(); + return false; + } + + // 0x1401E62E0 + void Handle::set_auto_disable(bool in_value) { + Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->set_auto_disable(in_value); + } + + // 0x1401D51B0 + bool Handle::get_auto_disable() const { + const Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->get_auto_disable(); + return false; + } + + // 0x1401E6330 + void Handle::set_base_matrix(const mat4& in_value) { + Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->set_base_matrix(in_value); + } + + // 0x1401D5200 + const mat4& Handle::get_base_matrix() const { + const Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->get_base_matrix(); + return bad_matrix; + } + + // 0x1401E6A80 + void Handle::set_reverse_side(bool in_value) { + Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->set_reverse_side(in_value); + } + + // 0x1401D5E60 + bool Handle::get_reverse_side() const { + const Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->get_reverse_side(); + return false; + } + + // 0x1401D5410 + size_t Handle::get_chara_size() const { + const Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->get_chara_size(); + return 0; + } + + // 0x1401D53C0 + size_t Handle::get_chara_index(const std::string& in_name) const { + const Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->get_chara_index(in_name); + return 0; + } + + // Missing + const std::string* Handle::chara_get_name(size_t in_index) const { + const Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->chara_get_name(in_index); + return 0; + } + + // 0x1401CBEC0 + void Handle::chara_bind_rob(size_t in_index, int32_t in_rob_id) { + Scene* scene = g_manager->get_work(m_handle); + if (scene) + scene->chara_bind_rob(in_index, in_rob_id); + } + + // 0x1401D5C10 + size_t Handle::get_object_size() const { + const Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->get_object_size(); + return 0; + } + + // Missing + size_t Handle::get_object_index(const std::string& in_name) const { + const Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->get_object_index(in_name); + return -1; + } + + // 0x1401E1FC0 + const std::string* Handle::object_get_name(size_t in_index) const { + const Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->object_get_name(in_index); + return 0; + } + + // Missing + const mat4* Handle::get_object_matrix(size_t in_index) const { + const Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->get_object_matrix(in_index); + return 0; + } + + // 0x1401E6B80 + void Handle::set_visible(bool in_value) { + Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->set_visible(in_value); + } + + // 0x1401D64A0 + bool Handle::get_visible() const { + const Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->get_visible(); + return false; + } + + // 0x1401E6B20 + void Handle::set_trnsl(float_t in_value, mdl::ObjFlags in_state) { + Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->set_trnsl(in_value, in_state); + } + + // 0x1401D60D0 + float_t Handle::get_trnsl() const { + const Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->get_trnsl(); + return 1.0f; + } + + // 0x1401E6290 + void Handle::set_attribute_wall(bool in_value) { + Scene* scene = g_manager->get_work(m_handle); + if (scene) + scene->set_attribute_wall(in_value); + } + + // 01401D50A0 + bool Handle::get_attribute_wall() const { + const Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->get_attribute_wall(); + return false; + } + + // 0x1401E67E0 + void Handle::set_item_attr(uint32_t in_id, uint32_t in_attr) { + Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->set_item_attr(in_id, in_attr); + } + + // 0x1401E68A0 + void Handle::set_item_texchange(const std::vector& in_list) { + Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->set_item_texchange(in_list); + } + + // 0x1401CB580 + void Handle::camera_set_enabled(bool in_value) { + Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->camera_set_enabled(in_value); + } + + // 0x1401CB4D0 + bool Handle::camera_get_enabled() const { + const Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->camera_get_enabled(); + return false; + } + + // 0x1401CB5D0 + void Handle::camera_set_fov_adjust(float_t in_value) { + Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->camera_set_fov_adjust(in_value); + } + + // 0x1401CB520 + float_t Handle::camera_get_fov_adjust() const { + const Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->camera_get_fov_adjust(); + return 1.0f; + } + + // 0x1401D5140 + size_t Handle::get_auth_2d_size() const { + const Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->get_auth_2d_size(); + return 0; + } + + // 0x1401D50F0 + size_t Handle::get_auth_2d_index(const std::string& in_name) const { + const Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->get_auth_2d_index(in_name); + return -1; + } + + const std::string* Handle::auth_2d_get_name(size_t in_index) const { + const Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->auth_2d_get_name(in_index); + return 0; + } + + // Missing + void Handle::set_data(size_t in_value) { + Scene* scene = g_manager->get_work(m_handle); + if (scene) + scene->set_data(in_value); + } + + // Missing + size_t Handle::get_data() const { + const Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->get_data(); + return 0; + } + + // 0x1401E6390 + void Handle::set_debug(uint32_t in_debug) { + Scene* scene = g_manager->get_work(m_handle); + if (scene) + scene->set_debug(in_debug); + } + + // 0x1401D5530 + uint32_t Handle::get_debug() const { + const Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->get_debug(); + return 0; + } + + // 0x1401CA840 + void Handle::assign_rob_id(int32_t in_value) { + Scene* scene = g_manager->get_work(m_handle); + if (scene) + scene->assign_rob_id(in_value); + } + + // 0x1401D5050 + int32_t Handle::get_assign_rob_id() const { + const Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->get_assign_rob_id(); + return ROB_ID_NULL; + } + + // 0x1401E69A0 + void Handle::set_obj_uid(object_info in_value) { + Scene* scene = g_manager->get_work(m_handle); + if (scene) + return set_obj_uid(in_value); + } + + // 0x1401E6AD0 + void Handle::set_shadow(bool in_value) { + Scene* scene = g_manager->get_work(m_handle); + if (scene) + scene->set_shadow(in_value); + } + + // Missing + bool Handle::is_shadow() const { + const Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->is_shadow(); + return false; + } + + // 0x1401E34C0 + void Handle::replace_chara(int32_t in_cn_src, int32_t in_cn_dst) { + Scene* scene = g_manager->get_work(m_handle); + if (scene) + scene->replace_chara(in_cn_src, in_cn_dst); + } + + // 0x1401CAD50 + void Handle::set_frame_object_hrc(float_t in_frame) { + Scene* scene = g_manager->get_work(m_handle); + if (scene) + scene->set_frame_object_hrc(in_frame); + } + + // 0x1401CB0F0 + void Handle::calc_matrix_hierarchy(const mat4& in_value) { + Scene* scene = g_manager->get_work(m_handle); + if (scene) + scene->calc_matrix_hierarchy(in_value); + } + + // 0x1401D8C40 + void Handle::join(int32_t in_handle, float_t in_blend) { + Scene* scene = g_manager->get_work(m_handle); + if (scene) { + Scene* other_scene = g_manager->get_work(in_handle); + if (other_scene && scene->object_hrc_list.size() + && scene->object_hrc_list.size() == other_scene->object_hrc_list.size()) { + scene->object_hrc_blend_list = &other_scene->object_hrc_list; + scene->object_hrc_blend = in_blend; + scene->join(); + } + else { + scene->object_hrc_blend_list = 0; + scene->object_hrc_blend = 0.0f; + scene->join(); + } + } + } + + // 0x1401D92D + void Handle::join_lock(int32_t in_handle, float_t in_blend) { + Scene* scene = g_manager->get_work(m_handle); + if (scene) { + Scene* other_scene = g_manager->get_work(in_handle); + if (other_scene && scene->object_hrc_list.size() + && scene->object_hrc_list.size() == other_scene->object_hrc_list.size()) { + scene->object_hrc_blend_list = &other_scene->object_hrc_list; + scene->object_hrc_blend = in_blend; + scene->join_lock(); + } + else { + scene->object_hrc_blend_list = 0; + scene->object_hrc_blend = 0.0f; + scene->join_lock(); + } + } + } + + // 0x1401E6470 + void Handle::set_ex_node_mat(mat4* in_value) { + Scene* scene = g_manager->get_work(m_handle); + if (scene) + scene->set_ex_node_mat(in_value); + } + + // Missing + bool Handle::is_ex_node_mat() const { + const Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->is_ex_node_mat(); + return false; + } + + // 0x1401E12C0 + void Handle::lock_set() { + Scene* scene = g_manager->get_work(m_handle); + if (scene) + scene->lock_list_set(); + } + + // Added + void Handle::set_chara_item(bool in_value) { + Scene* scene = g_manager->get_work(m_handle); + if (scene) + scene->set_chara_item(in_value); + } + + // Added + bool Handle::get_chara_item() const { + const Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->get_chara_item(); + return false; + } + + // Added + void Handle::set_reflect(bool in_value) { + Scene* scene = g_manager->get_work(m_handle); + if (scene) + scene->set_reflect(in_value); + } + + // Added + bool Handle::get_reflect() const { + const Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene->get_reflect(); + return false; + } + + // Added + Scene* Handle::get_scene() { + Scene* scene = g_manager->get_work(m_handle); + if (scene) + return scene; + return 0; + } + + // 0x1401C15B0 + void Scene::M_load_exec() { + if (load_state != S_NOW_LOADING) + return; + + if (hash == hash_murmurhash_empty) { + data_struct* aft_data = &data_list[DATA_AFT]; + auth_3d_database* aft_auth_3d_db = &aft_data->data_ft.auth_3d_db; + object_database* aft_obj_db = &aft_data->data_ft.obj_db; + texture_database* aft_tex_db = &aft_data->data_ft.tex_db; + + UidData* uid_data = g_manager->get_uid_data(M_uid, aft_auth_3d_db); + if (uid_data && uid_data->load_is_done()) { + load_state = S_DONE; + + time_struct time; + M_loadFromProperties(uid_data->file, aft_obj_db, aft_tex_db); + time.calc_time(); + + for (a3d::EventListener*& i : my_event_listener) { + Handle handle = to_handle(); + i->loadFinished(handle); + } + + M_frame = 0.0f; + } + } + else { + UidDataModern* uid_data = g_manager->get_uid_data_modern(hash); + if (uid_data && uid_data->load_is_done()) { + load_state = S_DONE; + + a3da_msgpack_read("patch\\AFT\\auth_3d", uid_data->file_name.c_str(), &uid_data->file.prop); + + const char* l_str = uid_data->file_name.c_str(); + const char* t = strrchr(l_str, '.'); + size_t l_len = uid_data->file_name.size(); + if (t) + l_len = t - l_str; + + uid_data->name.assign(uid_data->file_name.c_str(), l_len); + uid_data->file_name.assign(uid_data->file_name); + file_name.assign(uid_data->file_name); + + time_struct time; + M_loadFromProperties(uid_data->file, uid_data->obj_db, uid_data->tex_db); + time.calc_time(); + + hash = uid_data->hash; + + for (a3d::EventListener*& i : my_event_listener) { + Handle handle = to_handle(); + i->loadFinished(handle); + } + + M_frame = 0.0f; + } + } + } + + //Inlined + Handle Scene::to_handle() { + return Handle::S_init(my_handle); + } + + // 0x1401CBAB0 + void category_free(const char* in_name) { + g_manager->category_free(in_name); + } + + // Added + void category_free(uint32_t in_hash) { + g_manager->category_free(in_hash); + } + + // 0x1401CBE20 + bool category_load_is_done(const char* in_name) { + return g_manager->category_load_is_done(in_name); + } + + // Added + bool category_load_is_done(uint32_t in_hash) { + return g_manager->category_load_is_done(in_hash); + } + + // 0x1401CBE60 + void category_load_req(const char* in_name) { + g_manager->category_load_req(in_name, 0); + } + + // 0x1401CBE30 + void category_load_req(const char* in_name, const char* in_mdata_dir) { + g_manager->category_load_req(in_name, in_mdata_dir); + } + + // Added + void category_load_req(void* data, const char* in_name, uint32_t in_hash) { + g_manager->category_load_req(data, in_name, in_hash); + } + + // 0x1401CDCA0 + Event* createEvent(const SceneFile& in_file, const a3d::Event& in_e) { + switch (in_e.type) { + case a3d::EVENT_MISC: + default: + return new Event(in_e); + case a3d::EVENT_FLT: + return createEventFilter(in_file, in_e); + case a3d::EVENT_FX: + return createEventFX(in_file, in_e); + case a3d::EVENT_SND: + return new EventSnd(in_e); + case a3d::EVENT_MOT: + return new EventMot(in_e); + case a3d::EVENT_A2D: + return new EventA2d(in_e); + } + } + + // 0x1401CDE30 + Event* createEventFX(const SceneFile& in_file, const a3d::Event& in_e) { + if (!in_e.param1.compare("SMOOTH")) + return new EventFXSmoothCut(in_e); + return new EventFX(in_e); + } + + // 0x1401CDFF0 + Event* createEventFilter(const SceneFile& in_file, const a3d::Event& in_e) { + if (!in_e.param1.compare("WHITEIN") || !in_e.param1.compare("WHITEOUT") + || !in_e.param1.compare("FADEIN") || !in_e.param1.compare("FADEOUT")) + return new EventFilterFade(in_e); + else if (!in_e.param1.compare("TIMESTOP")) + return new EventFilterTimeStop(in_e); + return new Event(in_e); + } + + // 0x1401D5BC0 + const mat4* get_object_matrix(int32_t in_handle, size_t in_index, bool in_is_hrc) { + return g_manager->get_object_matrix(in_handle, in_index, in_is_hrc); + } + + // 0x1401D5010 + int32_t get_assign_rob_id(int32_t in_handle) { + return g_manager->get_assign_rob_id(in_handle); + } + + // Added + Scene* get_scene(int32_t in_uid) { + return g_manager->get_scene(in_uid); + } + + // Added + Scene* get_scene(uint32_t hash) { + return g_manager->get_scene(hash); + } + + // 0x1401D6090 + int32_t get_scene_object_index(object_info in_obj_uid, + int32_t* out_index, bool* out_is_hrc, int32_t in_instance) { + return g_manager->get_scene_object_index(in_obj_uid, out_index, out_is_hrc, in_instance); + } + + // Added + int32_t get_scene_object_index(uint32_t in_file_name_hash, uint32_t in_obj_hash, + int32_t* out_index, bool* out_is_hrc, int32_t in_instance) { + return g_manager->get_scene_object_index(in_file_name_hash, in_obj_hash, out_index, out_is_hrc, in_instance); + } + + // 0x1401E7E90 + const char* get_name_uid(int32_t in_uid, const auth_3d_database* auth_3d_db) { + return g_manager->get_name_uid(in_uid, auth_3d_db); + } } void auth_3d_data_init() { - if (!auth_3d_data) - auth_3d_data = new auth_3d_data_struct; -} - -bool auth_3d_data_check_category_loaded(const char* category_name) { - return auth_3d_data_struct_check_category_loaded(auth_3d_data, category_name); -} - -bool auth_3d_data_check_category_loaded(uint32_t category_hash) { - return auth_3d_data_struct_check_category_loaded(auth_3d_data, category_hash); -} - -auth_3d* auth_3d_data_get_auth_3d(uint32_t hash) { - for (int32_t& i : auth_3d_data->loaded_ids) { - if (i < 0 || (i & 0x7FFF) >= AUTH_3D_DATA_COUNT) - continue; - - auth_3d* auth = &auth_3d_data->data[i & 0x7FFF]; - if (auth->hash == hash) - return auth; - } - return 0; -} - -auth_3d* auth_3d_data_get_auth_3d(int32_t uid) { - for (int32_t& i : auth_3d_data->loaded_ids) { - if (i < 0 || (i & 0x7FFF) >= AUTH_3D_DATA_COUNT) - continue; - - auth_3d* auth = &auth_3d_data->data[i & 0x7FFF]; - if (auth->uid == uid) - return auth; - } - return 0; -} - -int32_t auth_3d_data_get_auth_3d_id(const char* object_name) { - for (int32_t& i : auth_3d_data->loaded_ids) { - if (i < 0 || (i & 0x7FFF) >= AUTH_3D_DATA_COUNT) - continue; - - auth_3d* auth = &auth_3d_data->data[i & 0x7FFF]; - if (auth->id != i || !auth->enable) - continue; - - for (auth_3d_object_hrc& j : auth->object_hrc) - if (!j.name.compare(object_name)) - return i; - - for (auth_3d_object& j : auth->object) - if (!j.name.compare(object_name)) - return i; - } - return -1; -} - -int32_t auth_3d_data_get_auth_3d_id(object_info obj_info, - int32_t* object_index, bool* hrc, int32_t object_instance) { - for (int32_t& i : auth_3d_data->loaded_ids) { - if (i < 0 || (i & 0x7FFF) >= AUTH_3D_DATA_COUNT) - continue; - - auth_3d* auth = &auth_3d_data->data[i & 0x7FFF]; - if (auth->id != i || !auth->enable) - continue; - - int32_t obj_hrc_index = auth_3d_get_auth_3d_object_hrc_index_by_object_info( - auth, obj_info, object_instance); - if (obj_hrc_index >= 0) { - if (object_index) - *object_index = obj_hrc_index; - if (hrc) - *hrc = true; - return i; - } - - int32_t obj_index = auth_3d_get_auth_3d_object_index_by_object_info( - auth, obj_info, object_instance); - if (obj_index >= 0) { - if (object_index) - *object_index = obj_index; - if (hrc) - *hrc = false; - return i; - } - } - return -1; -} - -int32_t auth_3d_data_get_auth_3d_id(uint32_t file_name_hash, uint32_t object_hash, - int32_t* object_index, bool* hrc, int32_t object_instance) { - for (int32_t& i : auth_3d_data->loaded_ids) { - if (i < 0 || (i & 0x7FFF) >= AUTH_3D_DATA_COUNT) - continue; - - auth_3d* auth = &auth_3d_data->data[i & 0x7FFF]; - if (auth->id != i || !auth->enable) - continue; - - bool ret = false; - if (file_name_hash != hash_murmurhash_empty) { - if (auth->hash != file_name_hash) - continue; - ret = true; - } - - int32_t obj_index = auth_3d_get_auth_3d_object_index_by_hash( - auth, object_hash, object_instance); - if (obj_index >= 0) { - if (object_index) - *object_index = obj_index; - if (hrc) - *hrc = false; - return i; - } - - int32_t obj_hrc_index = auth_3d_get_auth_3d_object_hrc_index_by_hash( - auth, object_hash, object_instance); - if (obj_hrc_index >= 0) { - if (object_index) - *object_index = obj_hrc_index; - if (hrc) - *hrc = true; - return i; - } - - if (ret) - return -1; - } - return -1; + if (!auth_3d_detail::g_manager) + auth_3d_detail::g_manager = new auth_3d_detail::Auth3dManager; } +// 0x140248480 void auth_3d_data_get_obj_sets_from_category(std::string& name, std::vector& obj_sets, - auth_3d_database* auth_3d_db, object_database* obj_db) { + const auth_3d_database* auth_3d_db, const object_database* obj_db) { obj_sets.clear(); - std::vector uid; - auth_3d_db->get_category_uids(name.c_str(), uid); - for (int32_t& i : uid) { - const char* uid_name = auth_3d_data_get_uid_name(i, auth_3d_db); + std::vector uids; + auth_3d_db->get_category_uids(name.c_str(), uids); + for (int32_t& i : uids) { + const char* uid_name = auth_3d_detail::get_name_uid(i, auth_3d_db); if (!uid_name) continue; @@ -3122,7 +7777,7 @@ void auth_3d_data_get_obj_sets_from_category(std::string& name, std::vector auth_3d_db->uid.size()) - return 0; - - auth_3d_database_uid* db_uid = &auth_3d_db->uid[uid]; - if (db_uid->enabled) - return db_uid->name.c_str(); - return 0; -} - -void auth_3d_data_load_auth_3d_db(auth_3d_database* auth_3d_db) { - auth_3d_data->farcs.clear(); - auth_3d_data->farcs.resize(auth_3d_db->category.size()); +void auth_3d_data_load_auth_3d_db(const auth_3d_database* auth_3d_db) { + auth_3d_detail::g_manager->category_data_list.clear(); + auth_3d_detail::g_manager->category_data_list.resize(auth_3d_db->category.size()); size_t cat_index = 0; - for (auth_3d_farc& i : auth_3d_data->farcs) - i.name.assign(auth_3d_db->category[cat_index++].name); + for (auth_3d_detail::CategoryData& i : auth_3d_detail::g_manager->category_data_list) + i.category_name.assign(auth_3d_db->category[cat_index++].name); - auth_3d_data->uid_files.clear(); - auth_3d_data->uid_files.resize(auth_3d_db->uid.size()); + auth_3d_detail::g_manager->uid_data_list.clear(); + auth_3d_detail::g_manager->uid_data_list.resize(auth_3d_db->uid.size()); size_t uid_index = 0; - for (auth_3d_uid_file& i : auth_3d_data->uid_files) + for (auth_3d_detail::UidData& i : auth_3d_detail::g_manager->uid_data_list) i.uid = (int32_t)(uid_index++); } -void auth_3d_data_load_category(const char* category_name, const char* mdata_dir) { - auth_3d_data_struct_load_category(auth_3d_data, category_name, mdata_dir); -} - -void auth_3d_data_load_category(void* data, const char* category_name, uint32_t category_hash) { - auth_3d_data_struct_load_category(auth_3d_data, data, category_name, category_hash); -} - -void auth_3d_data_unload_category(const char* category_name) { - auth_3d_data_struct_unload_category(auth_3d_data, category_name); -} - -void auth_3d_data_unload_category(uint32_t category_hash) { - auth_3d_data_struct_unload_category(auth_3d_data, category_hash); -} - void auth_3d_data_free() { - if (auth_3d_data) { - delete auth_3d_data; - auth_3d_data = 0; + if (auth_3d_detail::g_manager) { + delete auth_3d_detail::g_manager; + auth_3d_detail::g_manager = 0; } } void task_auth_3d_init() { - if (!task_auth_3d) - task_auth_3d = new auth_3d_detail::TaskAuth3d; + if (!auth_3d_detail::task_auth_3d) + auth_3d_detail::task_auth_3d = new auth_3d_detail::TaskAuth3d; } bool task_auth_3d_open() { - return task_auth_3d->open("AUTH_3D"); + return auth_3d_detail::task_auth_3d->open("AUTH_3D"); } bool task_auth_3d_check_alive() { - return task_auth_3d->check_alive(); + return auth_3d_detail::task_auth_3d->check_alive(); } bool task_auth_3d_close() { - return task_auth_3d->close(); + return auth_3d_detail::task_auth_3d->close(); } void task_auth_3d_free() { - if (task_auth_3d) { - delete task_auth_3d; - task_auth_3d = 0; + if (auth_3d_detail::task_auth_3d) { + delete auth_3d_detail::task_auth_3d; + auth_3d_detail::task_auth_3d = 0; } } @@ -3229,15 +7858,15 @@ namespace auth_3d_detail { } bool TaskAuth3d::init() { - return auth_3d_data_struct_init(auth_3d_data, rctx_ptr); + return g_manager->init(); } bool TaskAuth3d::ctrl() { - return auth_3d_data_struct_ctrl(auth_3d_data, rctx_ptr); + return g_manager->ctrl(); } void TaskAuth3d::disp() { - auth_3d_data_struct_disp(auth_3d_data, rctx_ptr); + g_manager->disp(); } FrameRateTimeStop::FrameRateTimeStop() { @@ -3251,26 +7880,85 @@ namespace auth_3d_detail { float_t FrameRateTimeStop::get_delta_frame() { return 0.0f; } + + // 0x1401D3860 + static void event_log(const char* fmt, ...) { +#ifdef DEBUG + va_list args; + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); +#endif + } + + // 0x1401D4F30 + static const char* get_ID_EVENT_TYPE(EVENT_TYPE type) { + switch (type) { + case EVENT_MISC: + return "MISC"; + case EVENT_FLT: + return "FLT"; + case EVENT_FX: + return "FX"; + case EVENT_SND: + return "SND"; + case EVENT_MOT: + return "MOT"; + case EVENT_A2D: + return "A2D"; + default: + return "(unknown)"; + } + } + + template + size_t get_index_by_name(const T& in_c, const std::string& in_name) { + size_t index = 0; + for (auto i = in_c.cbegin(); i != in_c.cend(); i++, index++) + if (!i->name.compare(in_name)) + return index; + return -1; + } + + template + void list_load(T& in_c, const SceneFile& in_file, const U& in_a, Args... args) { + if (in_a.size()) { + size_t index = 0; + in_c.resize(in_a.size()); + for (size_t i = 0; i < in_a.size(); i++) + in_c[i].load(in_file, in_a[i], args...); + } + } + + template + void list_store(const T& in_c, const SceneFile& in_file, U& out_a, Args... args) { + if (in_c.size()) { + size_t index = 0; + out_a.resize(in_c.size()); + for (size_t i = 0; i < in_c.size(); i++) + in_c[i].store(in_file, out_a[i], args...); + } + } } -static bool a3da_msgpack_read_key(a3da_key& key, msgpack* msg) { +static bool a3da_msgpack_read_key(a3d::Fcurve& key, msgpack* msg) { if (msg->read_bool("remove")) { key = {}; return false; } if (msg->read_bool("ignore_tangents") && key.keys.size()) { - float_t ep_pre_val = key.keys.front().tangent1; - float_t ep_post_val = key.keys.back().tangent2; + float_t ep_pre_val = key.keys.front().l_slope; + float_t ep_post_val = key.keys.back().r_slope; for (kft3& i : key.keys) { - i.tangent1 = 0.0f; - i.tangent2 = 0.0f; + i.l_slope = 0.0f; + i.r_slope = 0.0f; } - if (key.ep_type_pre == A3DA_EP_LINEAR) - key.keys.front().tangent1 = ep_pre_val; - if (key.ep_type_post == A3DA_EP_LINEAR) - key.keys.back().tangent2 = ep_post_val; + if (key.ep_type_pre == a3d::EP_TYPE_LINEAR) + key.keys.front().l_slope = ep_pre_val; + if (key.ep_type_post == a3d::EP_TYPE_LINEAR) + key.keys.back().r_slope = ep_post_val; } msgpack* max_frame = msg->read("max_frame"); @@ -3279,25 +7967,25 @@ static bool a3da_msgpack_read_key(a3da_key& key, msgpack* msg) { msgpack* change_type = msg->read("change_type"); if (change_type) { - a3da_key_type type = (a3da_key_type)change_type->read_int32_t(); + a3d::FC_TYPE type = (a3d::FC_TYPE)change_type->read_int32_t(); switch (type) { - case A3DA_KEY_NONE: + case a3d::FC_TYPE_STATIC_0: key.keys.clear(); - key.type = A3DA_KEY_NONE; + key.type = a3d::FC_TYPE_STATIC_0; key.value = 0.0f; return true; - case A3DA_KEY_STATIC: + case a3d::FC_TYPE_STATIC_DATA: key.keys.clear(); - key.type = A3DA_KEY_STATIC; + key.type = a3d::FC_TYPE_STATIC_DATA; key.value = msg->read_float_t("value"); return true; - case A3DA_KEY_LINEAR: - case A3DA_KEY_HERMITE: - case A3DA_KEY_HOLD: + case a3d::FC_TYPE_LINEAR: + case a3d::FC_TYPE_HERMITE: + case a3d::FC_TYPE_NO_INTERPOLATION: switch (key.type) { - case A3DA_KEY_LINEAR: - case A3DA_KEY_HERMITE: - case A3DA_KEY_HOLD: + case a3d::FC_TYPE_LINEAR: + case a3d::FC_TYPE_HERMITE: + case a3d::FC_TYPE_NO_INTERPOLATION: key.type = type; break; } @@ -3331,15 +8019,15 @@ static bool a3da_msgpack_read_key(a3da_key& key, msgpack* msg) { case 3: { k.frame = (*ptr)[0].read_float_t(); k.value = (*ptr)[1].read_float_t(); - float_t tangent = (*ptr)[2].read_float_t(); - k.tangent1 = tangent; - k.tangent2 = tangent; + float_t slope = (*ptr)[2].read_float_t(); + k.l_slope = slope; + k.r_slope = slope; } break; case 4: k.frame = (*ptr)[0].read_float_t(); k.value = (*ptr)[1].read_float_t(); - k.tangent1 = (*ptr)[2].read_float_t(); - k.tangent2 = (*ptr)[3].read_float_t(); + k.l_slope = (*ptr)[2].read_float_t(); + k.r_slope = (*ptr)[3].read_float_t(); break; } key.keys.push_back(k); @@ -3348,7 +8036,7 @@ static bool a3da_msgpack_read_key(a3da_key& key, msgpack* msg) { return true; } -static bool a3da_msgpack_read_vec3(a3da_vec3& vec, msgpack* msg) { +static bool a3da_msgpack_read_vec3(a3d::Fcurve3f& vec, msgpack* msg) { if (msg->read_bool("remove")) { vec = {}; return false; @@ -3368,77 +8056,81 @@ static bool a3da_msgpack_read_vec3(a3da_vec3& vec, msgpack* msg) { return true; } -static bool a3da_msgpack_read_rgba(a3da_rgba& rgba, msgpack* msg) { +static bool a3da_msgpack_read_rgba(a3d::FcurveColor4f& col4, msgpack* msg) { if (msg->read_bool("remove")) { - rgba = {}; + col4 = {}; return false; } msgpack* rgb = msg->read_map("rgb"); if (rgb) { - a3da_key rgb_key = rgba.r; + a3d::Fcurve rgb_key = col4.r; if (a3da_msgpack_read_key(rgb_key, rgb)) { - rgba.r = rgb_key; - rgba.g = rgb_key; - rgba.b = rgb_key; - enum_or(rgba.flags, A3DA_RGBA_R | A3DA_RGBA_G | A3DA_RGBA_B); + col4.r = rgb_key; + col4.g = rgb_key; + col4.b = rgb_key; + col4.has_r = true; + col4.has_g = true; + col4.has_b = true; } else { - rgba.r = {}; - rgba.g = {}; - rgba.b = {}; - enum_and(rgba.flags, ~(A3DA_RGBA_R | A3DA_RGBA_G | A3DA_RGBA_B)); + col4.r = {}; + col4.g = {}; + col4.b = {}; + col4.has_r = false; + col4.has_g = false; + col4.has_b = false; } } msgpack* r = msg->read_map("r"); if (r) { - enum_or(rgba.flags, A3DA_RGBA_R); - if (!a3da_msgpack_read_key(rgba.r, r)) { - rgba.r = {}; - enum_and(rgba.flags, ~A3DA_RGBA_R); + col4.has_r = true; + if (!a3da_msgpack_read_key(col4.r, r)) { + col4.r = {}; + col4.has_r = false; } } msgpack* g = msg->read_map("g"); if (g) { - enum_or(rgba.flags, A3DA_RGBA_G); - if (!a3da_msgpack_read_key(rgba.g, g)) { - rgba.g = {}; - enum_and(rgba.flags, ~A3DA_RGBA_G); + col4.has_g = true; + if (!a3da_msgpack_read_key(col4.g, g)) { + col4.g = {}; + col4.has_g = false; } } msgpack* b = msg->read_map("b"); if (b) { - enum_or(rgba.flags, A3DA_RGBA_B); - if (!a3da_msgpack_read_key(rgba.b, b)) { - rgba.b = {}; - enum_and(rgba.flags, ~A3DA_RGBA_B); + col4.has_b = true; + if (!a3da_msgpack_read_key(col4.b, b)) { + col4.b = {}; + col4.has_b = false; } } msgpack* a = msg->read_map("a"); if (a) { - enum_or(rgba.flags, A3DA_RGBA_A); - if (!a3da_msgpack_read_key(rgba.a, a)) { - rgba.a = {}; - enum_and(rgba.flags, ~A3DA_RGBA_A); + col4.has_a = true; + if (!a3da_msgpack_read_key(col4.a, a)) { + col4.a = {}; + col4.has_a = false; } } return true; } -static bool a3da_msgpack_read_model_transform(a3da_model_transform& mt, msgpack* msg) { +static bool a3da_msgpack_read_model_transform(a3d::ModelTransform& mt, msgpack* msg) { if (msg->read_bool("remove")) { mt = {}; - mt.scale.x.type = A3DA_KEY_STATIC; + mt.scale.x.type = a3d::FC_TYPE_STATIC_DATA; mt.scale.x.value = 1.0f; - mt.scale.y.type = A3DA_KEY_STATIC; + mt.scale.y.type = a3d::FC_TYPE_STATIC_DATA; mt.scale.y.value = 1.0f; - mt.scale.z.type = A3DA_KEY_STATIC; + mt.scale.z.type = a3d::FC_TYPE_STATIC_DATA; mt.scale.z.value = 1.0f; - mt.visibility.type = A3DA_KEY_STATIC; + mt.visibility.type = a3d::FC_TYPE_STATIC_DATA; mt.visibility.value = 1.0f; return false; } @@ -3454,24 +8146,24 @@ static bool a3da_msgpack_read_model_transform(a3da_model_transform& mt, msgpack* msgpack* scale = msg->read_map("scale"); if (scale && !a3da_msgpack_read_vec3(mt.scale, scale)) { mt.scale = {}; - mt.scale.x.type = A3DA_KEY_STATIC; + mt.scale.x.type = a3d::FC_TYPE_STATIC_DATA; mt.scale.x.value = 1.0f; - mt.scale.y.type = A3DA_KEY_STATIC; + mt.scale.y.type = a3d::FC_TYPE_STATIC_DATA; mt.scale.y.value = 1.0f; - mt.scale.z.type = A3DA_KEY_STATIC; + mt.scale.z.type = a3d::FC_TYPE_STATIC_DATA; mt.scale.z.value = 1.0f; } msgpack* visibility = msg->read_map("visibility"); if (visibility && !a3da_msgpack_read_key(mt.visibility, visibility)) { mt.visibility = {}; - mt.visibility.type = A3DA_KEY_STATIC; + mt.visibility.type = a3d::FC_TYPE_STATIC_DATA; mt.visibility.value = 1.0f; } return true; } -static void a3da_msgpack_read(const char* path, const char* file, a3da* auth_file) { +static void a3da_msgpack_read(const char* path, const char* file, a3d::Scene* auth_file) { if (!path_check_directory_exists(path)) return; @@ -3508,13 +8200,13 @@ static void a3da_msgpack_read(const char* path, const char* file, a3da* auth_fil std::string name = curve.read_string("name"); uint32_t name_hash = hash_string_murmurhash(name); - for (a3da_curve& j : auth_file->curve) { + for (a3d::Curve& j : auth_file->curve) { if (name_hash != hash_string_murmurhash(j.name)) continue; msgpack* cv = curve.read_map("cv"); if (cv) - a3da_msgpack_read_key(j.curve, cv); + a3da_msgpack_read_key(j.fcurve, cv); break; } } @@ -3529,7 +8221,7 @@ static void a3da_msgpack_read(const char* path, const char* file, a3da* auth_fil std::string name = m_objhrc.read_string("name"); uint32_t name_hash = hash_string_murmurhash(name); - for (a3da_m_object_hrc& j : auth_file->m_object_hrc) { + for (a3d::MObjectHrc& j : auth_file->m_object_hrc) { if (name_hash != hash_string_murmurhash(j.name)) continue; @@ -3549,6 +8241,7 @@ static void a3da_msgpack_read(const char* path, const char* file, a3da* auth_fil } } + // X/XHD msgpack* material_lists = msg.read_array("material_list"); if (material_lists) { msgpack_array* ptr = material_lists->data.arr; @@ -3576,19 +8269,19 @@ static void a3da_msgpack_read(const char* path, const char* file, a3da* auth_fil msgpack* blend_color = material_list.read_map("blend_color"); if (blend_color) { - enum_or(j->flags, A3DA_MATERIAL_LIST_BLEND_COLOR); + j->flag |= a3d::MaterialList::FLAG_BLEND_COLOR; if (!a3da_msgpack_read_rgba(j->blend_color, blend_color)) - enum_and(j->flags, ~A3DA_MATERIAL_LIST_BLEND_COLOR); + j->flag &= ~a3d::MaterialList::FLAG_BLEND_COLOR; } msgpack* emission = material_list.read_map("emission"); if (emission) { - enum_or(j->flags, A3DA_MATERIAL_LIST_EMISSION); + j->flag |= a3d::MaterialList::FLAG_EMISSION; if (!a3da_msgpack_read_rgba(j->emission, emission)) - enum_and(j->flags, ~A3DA_MATERIAL_LIST_EMISSION); + j->flag &= ~a3d::MaterialList::FLAG_EMISSION; } - if (!j->flags) + if (!j->flag) auth_file->material_list.erase(j); break; } @@ -3625,7 +8318,7 @@ static void a3da_msgpack_read(const char* path, const char* file, a3da* auth_fil remove_parent_name.push_back(j->name); - for (a3da_object_node& k : j->node) + for (a3d::ObjectNode& k : j->node) remove_parent_node.push_back(k.name); auth_file->object_hrc.erase(j); @@ -3716,7 +8409,7 @@ static void a3da_msgpack_read(const char* path, const char* file, a3da* auth_fil if (remove_parent_name_hash == hash_string_murmurhash(k->parent_name)) { remove_parent_name.push_back(k->name); - for (a3da_object_node& l : k->node) + for (a3d::ObjectNode& l : k->node) remove_parent_node.push_back(l.name); auth_file->object_hrc.erase(k); break; @@ -3745,7 +8438,7 @@ static void a3da_msgpack_read(const char* path, const char* file, a3da* auth_fil if (remove_parent_node_hash == hash_string_murmurhash(k->parent_node)) { remove_parent_node.push_back(k->name); - for (a3da_object_node& l : k->node) + for (a3d::ObjectNode& l : k->node) remove_parent_node.push_back(l.name); auth_file->object_hrc.erase(k); break; @@ -3757,440 +8450,54 @@ static void a3da_msgpack_read(const char* path, const char* file, a3da* auth_fil }; } -static bool auth_3d_key_detect_fast_change(auth_3d_key* data, float_t frame, float_t threshold) { - if (data->type < AUTH_3D_KEY_LINEAR || data->type > AUTH_3D_KEY_HOLD) - return false; - - frame = clamp_def(frame, 0.0f, data->max_frame); - size_t length = data->length; - if (!length) - return false; - - const kft3* keys = data->keys; - const kft3* key = auth_3d_key_find_keyframe(data, frame); - if (key == keys || key == &keys[length] || key == &keys[1]) - return false; - - const kft3* next_key = &key[1]; - if (next_key == &keys[length]) - return false; - - const kft3* prev_key = &key[-1]; - float_t frame_diff = key->frame - prev_key->frame; - if (frame_diff >= 2.0 || frame_diff <= 0.0) - return false; - - if (fabsf(key->value - prev_key->value) <= threshold) - return false; - - const kft3* prev2_key = &prev_key[-1]; - for (; prev_key->frame <= prev2_key->frame; prev2_key = &prev2_key[-1]) - if (prev2_key != keys) - return false; - - float_t v23 = key->value - prev_key->value / frame_diff; - float_t v25; - float_t v30; - if (data->type != AUTH_3D_KEY_HERMITE) { - v25 = (prev_key->value - prev2_key->value) / (prev_key->frame - prev2_key->frame); - v30 = (next_key->value - key->value) / (next_key->frame - key->frame); - } - else { - if (prev_key->frame - prev2_key->frame >= 2.0f) { - float_t value; - if (prev2_key->frame < prev_key->frame) - value = interpolate_chs_value(prev2_key->value, prev_key->value, - prev2_key->tangent2, prev_key->tangent1, - prev_key->frame, prev2_key->frame, prev_key->frame - 1.0f); - else - value = prev2_key->value; - v25 = prev_key->value - value; - } - else - v25 = (prev_key->value - prev2_key->value) / (prev_key->frame - prev2_key->frame); - - if (next_key->frame - key->frame >= 2.0f) { - float_t value; - if (key->frame < next_key->frame) - value = interpolate_chs_value(key->value, next_key->value, - key->tangent2, next_key->tangent1, - key->frame, next_key->frame, key->frame + 1.0f); - else - value = key->value; - v30 = value - key->value; - } - else - v30 = (next_key->value - key->value) / (next_key->frame - key->frame); - } - - float_t v33 = v25 * v23; - float_t v34 = v30 * v23; - const float_t v25_abs = fabsf(v25); - const float_t v23_abs = fabsf(v23); - const float_t v30_abs = fabsf(v30); - return (v33 <= 0.0f || (v25_abs < v23_abs && v25_abs <= threshold)) - && (v34 <= 0.0f || (v30_abs < v23_abs && v30_abs <= threshold)); -} - -static float_t auth_3d_interpolate_value(auth_3d_key_type type, - float_t frame, kft3* curr_key, kft3* next_key) { - switch (type) { - case AUTH_3D_KEY_LINEAR: - if (curr_key->frame < next_key->frame) - return interpolate_linear_value(curr_key->value, next_key->value, - curr_key->frame, next_key->frame, frame); - else - return curr_key->value; - case AUTH_3D_KEY_HERMITE: - if (curr_key->frame < next_key->frame) - return interpolate_chs_value(curr_key->value, next_key->value, - curr_key->tangent2, next_key->tangent1, - curr_key->frame, next_key->frame, frame); - else - return curr_key->value; - case AUTH_3D_KEY_HOLD: - if (frame >= next_key->frame) - return next_key->value; - else - return curr_key->value; - default: - return 0.0f; - } -} - -static kft3* auth_3d_key_find_keyframe(auth_3d_key* data, float_t frame) { - kft3* key = data->keys; - size_t length = data->length; - size_t temp; - while (length > 0) - if (key[temp = length / 2].frame > frame) - length = temp; - else { - key += temp + 1; - length -= temp + 1; - } - return key; -} - -static float_t auth_3d_key_interpolate_inner(auth_3d_key* data, float_t frame) { - kft3* first_key = data->keys; - kft3* key = auth_3d_key_find_keyframe(data, frame); - - if (key == first_key) - return first_key->value; - else if (key == &first_key[data->length]) - return key[-1].value; - else - return auth_3d_interpolate_value(data->type, frame, key - 1, key); -} - -static void auth_3d_key_load(auth_3d* auth, auth_3d_key* k, auth_3d_key_file* kf) { - k->max_frame = auth->max_frame; - k->frame_delta = k->max_frame; - k->value_delta = 0.0f; - - switch (kf->type) { - case A3DA_KEY_NONE: - k->type = AUTH_3D_KEY_NONE; - k->value = 0.0f; - return; - case A3DA_KEY_STATIC: - k->type = kf->value != 0.0f ? AUTH_3D_KEY_STATIC : AUTH_3D_KEY_NONE; - k->value = kf->value; - return; - case A3DA_KEY_LINEAR: - k->type = AUTH_3D_KEY_LINEAR; - break; - case A3DA_KEY_HERMITE: - default: - k->type = AUTH_3D_KEY_HERMITE; - break; - case A3DA_KEY_HOLD: - k->type = AUTH_3D_KEY_HOLD; - break; - } - - size_t length = kf->keys.size(); - if (length > 1) { - k->keys_vec.assign(kf->keys.begin(), kf->keys.end()); - k->length = length; - k->keys = k->keys_vec.data(); - - kft3* first_key = &k->keys[0]; - kft3* last_key = &k->keys[length - 1]; - if (first_key->frame < last_key->frame - && last_key->frame > 0.0f && k->max_frame > first_key->frame) { - k->ep_type_pre = (auth_3d_ep_type)kf->ep_type_pre; - k->ep_type_post = (auth_3d_ep_type)kf->ep_type_post; - k->frame_delta = last_key->frame - first_key->frame; - k->value_delta = last_key->value - first_key->value; - } - } - else if (length == 1) { - float_t value = kf->keys.front().value; - k->type = value != 0.0f ? AUTH_3D_KEY_STATIC : AUTH_3D_KEY_NONE; - k->value = value; - } - else { - k->type = AUTH_3D_KEY_NONE; - k->value = 0.0f; - } -} - -static void auth_3d_key_store(auth_3d* auth, auth_3d_key* k, auth_3d_key_file* kf) { - kf->max_frame = auth->max_frame; - - switch (k->type) { - case AUTH_3D_KEY_NONE : - kf->type = A3DA_KEY_NONE; - kf->value = 0.0f; - return; - case AUTH_3D_KEY_STATIC : - kf->type = k->value != 0.0f ? A3DA_KEY_STATIC : A3DA_KEY_NONE; - kf->value = k->value; - return; - case AUTH_3D_KEY_LINEAR : - kf->type = A3DA_KEY_LINEAR; - break; - case AUTH_3D_KEY_HERMITE: - default: - kf->type = A3DA_KEY_HERMITE; - break; - case AUTH_3D_KEY_HOLD : - kf->type = A3DA_KEY_HOLD; - break; - } - - size_t length = k->keys_vec.size(); - if (length > 1) { - kf->keys.assign(k->keys_vec.begin(), k->keys_vec.end()); - - kft3* first_key = &k->keys[0]; - kft3* last_key = &k->keys[length - 1]; - if (first_key->frame < last_key->frame - && last_key->frame > 0.0f && k->max_frame > first_key->frame) { - kf->ep_type_pre = (a3da_ep_type)k->ep_type_pre; - kf->ep_type_post = (a3da_ep_type)k->ep_type_post; - } - } - else if (length == 1) { - float_t value = k->keys_vec.front().value; - kf->type = value != 0.0f ? A3DA_KEY_STATIC : A3DA_KEY_NONE; - kf->value = value; - } - else { - kf->type = A3DA_KEY_NONE; - kf->value = 0.0f; - } -} - -static void auth_3d_rgba_load(auth_3d* auth, auth_3d_rgba* rgba, auth_3d_rgba_file* rgbaf) { - if (rgbaf->flags & A3DA_RGBA_R) { - auth_3d_key_load(auth, &rgba->r, &rgbaf->r); - enum_or(rgba->flags, AUTH_3D_RGBA_R); - } - - if (rgbaf->flags & A3DA_RGBA_G) { - auth_3d_key_load(auth, &rgba->g, &rgbaf->g); - enum_or(rgba->flags, AUTH_3D_RGBA_G); - } - - if (rgbaf->flags & A3DA_RGBA_B) { - auth_3d_key_load(auth, &rgba->b, &rgbaf->b); - enum_or(rgba->flags, AUTH_3D_RGBA_B); - } - - if (rgbaf->flags & A3DA_RGBA_A) { - auth_3d_key_load(auth, &rgba->a, &rgbaf->a); - enum_or(rgba->flags, AUTH_3D_RGBA_A); - } -} - -static void auth_3d_rgba_store(auth_3d* auth, auth_3d_rgba* rgba, auth_3d_rgba_file* rgbaf) { - if (rgba->flags & AUTH_3D_RGBA_R) { - auth_3d_key_store(auth, &rgba->r, &rgbaf->r); - enum_or(rgbaf->flags, A3DA_RGBA_R); - } - - if (rgba->flags & AUTH_3D_RGBA_G) { - auth_3d_key_store(auth, &rgba->g, &rgbaf->g); - enum_or(rgbaf->flags, A3DA_RGBA_G); - } - - if (rgba->flags & AUTH_3D_RGBA_B) { - auth_3d_key_store(auth, &rgba->b, &rgbaf->b); - enum_or(rgbaf->flags, A3DA_RGBA_B); - } - - if (rgba->flags & AUTH_3D_RGBA_A) { - auth_3d_key_store(auth, &rgba->a, &rgbaf->a); - enum_or(rgbaf->flags, A3DA_RGBA_A); - } -} - -static void auth_3d_vec3_load(auth_3d* auth, auth_3d_vec3* vec, auth_3d_vec3_file* vecf) { - auth_3d_key_load(auth, &vec->x, &vecf->x); - auth_3d_key_load(auth, &vec->y, &vecf->y); - auth_3d_key_load(auth, &vec->z, &vecf->z); -} - -static void auth_3d_vec3_store(auth_3d* auth, auth_3d_vec3* vec, auth_3d_vec3_file* vecf) { - auth_3d_key_store(auth, &vec->x, &vecf->x); - auth_3d_key_store(auth, &vec->y, &vecf->y); - auth_3d_key_store(auth, &vec->z, &vecf->z); -} - -static void auth_3d_model_transform_load(auth_3d* auth, auth_3d_model_transform* mt, auth_3d_model_transform_file* mtf) { - auth_3d_vec3_load(auth, &mt->rotation, &mtf->rotation); - auth_3d_vec3_load(auth, &mt->scale, &mtf->scale); - auth_3d_vec3_load(auth, &mt->translation, &mtf->translation); - auth_3d_key_load(auth, &mt->visibility, &mtf->visibility); -} - -static void auth_3d_model_transform_store(auth_3d* auth, auth_3d_model_transform* mt, auth_3d_model_transform_file* mtf) { - auth_3d_vec3_store(auth, &mt->rotation, &mtf->rotation); - auth_3d_vec3_store(auth, &mt->scale, &mtf->scale); - auth_3d_vec3_store(auth, &mt->translation, &mtf->translation); - auth_3d_key_store(auth, &mt->visibility, &mtf->visibility); -} - -static int32_t auth_3d_get_auth_3d_object_index_by_object_info(auth_3d* auth, - object_info obj_info, int32_t object_instance) { - int32_t obj_instance = 0; - for (auth_3d_object& i : auth->object) - if (obj_info == i.object_info) { - if (obj_instance == object_instance) - return (int32_t)(&i - auth->object.data()); - obj_instance++; - } - return -1; -} - -static int32_t auth_3d_get_auth_3d_object_index_by_hash(auth_3d* auth, - uint32_t object_hash, int32_t object_instance) { - int32_t obj_instance = 0; - for (auth_3d_object& i : auth->object) - if (object_hash == i.object_hash) { - if (obj_instance == object_instance) - return (int32_t)(&i - auth->object.data()); - obj_instance++; - } - return -1; -} - -static const mat4* auth_3d_get_auth_3d_object_mat(auth_3d* auth, size_t index) { - if (index >= auth->object.size()) - return 0; - return &auth->object[index].model_transform.mat; -} - -static const mat4* auth_3d_get_auth_3d_object_hrc_bone_mats(auth_3d* auth, size_t index) { - if (index >= auth->object_hrc.size() || auth->object_hrc[index].mats.size() < 1) - return 0; - return auth->object_hrc[index].mats.data(); -} - -static int32_t auth_3d_get_auth_3d_object_hrc_index_by_object_info(auth_3d* auth, - object_info obj_info, int32_t object_instance) { - if (object_instance < 0) { - for (auth_3d_object_hrc& i : auth->object_hrc) - if (obj_info == i.object_info) - return (int32_t)(&i - auth->object_hrc.data()); - } - else { - int32_t obj_instance = 0; - for (auth_3d_object_hrc& i : auth->object_hrc) - if (obj_info == i.object_info) { - if (obj_instance == object_instance) - return (int32_t)(&i - auth->object_hrc.data()); - obj_instance++; - } - } - return -1; -} - -static int32_t auth_3d_get_auth_3d_object_hrc_index_by_hash(auth_3d* auth, - uint32_t object_hash, int32_t instance) { - if (instance < 0) { - for (auth_3d_object_hrc& i : auth->object_hrc) - if (object_hash == i.object_hash) - return (int32_t)(&i - auth->object_hrc.data()); - } - else { - int32_t obj_instance = 0; - for (auth_3d_object_hrc& i : auth->object_hrc) - if (object_hash == i.object_hash) { - if (obj_instance == instance) - return (int32_t)(&i - auth->object_hrc.data()); - obj_instance++; - } - } - return -1; -} - -static void auth_3d_read_file(auth_3d* auth, auth_3d_database* auth_3d_db) { - if (auth->uid >= auth_3d_db->uid.size()) - return; - - auth_3d_database_uid* db_uid = &auth_3d_db->uid[auth->uid]; - if (db_uid->enabled) { - auth_3d_uid_file* uid_file = &auth_3d_data->uid_files[auth->uid]; - if (uid_file->uid == auth->uid) { - auth_3d_uid_file_load_file(uid_file, auth_3d_db); - auth->state = 1; - } - } -} - -static void auth_3d_read_file_modern(auth_3d* auth) { - auto elem = auth_3d_data->uid_files_modern.find(auth->hash); - if (elem == auth_3d_data->uid_files_modern.end()) - return; - - auth_3d_uid_file_modern* uid_file = &elem->second; - if (uid_file->hash == auth->hash) { - auth_3d_uid_file_modern_load_file(uid_file); - auth->state = 1; - } -} - -static void auth_3d_set_material_list(auth_3d* auth, render_context* rctx) { +static void auth_3d_set_material_list(auth_3d_detail::Scene& in_scene, render_context* rctx) { mdl::DispManager& disp_manager = *rctx->disp_manager; int32_t mat_list_count = 0; material_list_struct mat_list[MATERIAL_LIST_COUNT]; - for (auth_3d_material_list& i : auth->material_list) { - if (!i.blend_color.flags && !i.emission.flags) + for (auth_3d_detail::MaterialList& i : in_scene.material_list) { + + if (!(i.blend_color.has_color[0] || i.blend_color.has_color[1] + || i.blend_color.has_color[2] || i.blend_color.has_color[3]) + && !(i.emission.has_color[0] || i.emission.has_color[1] + || i.emission.has_color[2] || i.emission.has_color[3])) continue; - if (i.blend_color.flags) { - vec4& blend_color = mat_list[mat_list_count].blend_color; - vec4u8& has_blend_color = mat_list[mat_list_count].has_blend_color; - - blend_color = i.blend_color.value; - has_blend_color.x = !!(i.blend_color.flags & AUTH_3D_RGBA_R); - has_blend_color.y = !!(i.blend_color.flags & AUTH_3D_RGBA_B); - has_blend_color.z = !!(i.blend_color.flags & AUTH_3D_RGBA_G); - has_blend_color.w = !!(i.blend_color.flags & AUTH_3D_RGBA_A); + vec4& blend_color = mat_list[mat_list_count].blend_color; + bool* has_blend_color = mat_list[mat_list_count].has_blend_color; + if (i.blend_color.has_color[0] || i.blend_color.has_color[1] + || i.blend_color.has_color[2] || i.blend_color.has_color[3]) { + blend_color = i.blend_color.color; + has_blend_color[0] = i.blend_color.has_color[0]; + has_blend_color[1] = i.blend_color.has_color[1]; + has_blend_color[2] = i.blend_color.has_color[2]; + has_blend_color[3] = i.blend_color.has_color[3]; } else { - mat_list[mat_list_count].blend_color = {}; - mat_list[mat_list_count].has_blend_color = {}; + blend_color = 0.0f; + has_blend_color[0] = false; + has_blend_color[1] = false; + has_blend_color[2] = false; + has_blend_color[3] = false; } - if (i.emission.flags) { - vec4& emission = mat_list[mat_list_count].emission; - vec4u8& has_emission = mat_list[mat_list_count].has_emission; + vec4& emission = mat_list[mat_list_count].emission; + bool* has_emission = mat_list[mat_list_count].has_emission; + if (i.emission.has_color[0] || i.emission.has_color[1] + || i.emission.has_color[2] || i.emission.has_color[3]) { - emission = i.emission.value; - has_emission.x = !!(i.emission.flags & AUTH_3D_RGBA_R); - has_emission.y = !!(i.emission.flags & AUTH_3D_RGBA_B); - has_emission.z = !!(i.emission.flags & AUTH_3D_RGBA_G); - has_emission.w = !!(i.emission.flags & AUTH_3D_RGBA_A); + emission = i.emission.color; + has_emission[0] = i.emission.has_color[0]; + has_emission[1] = i.emission.has_color[1]; + has_emission[2] = i.emission.has_color[2]; + has_emission[3] = i.emission.has_color[3]; } else { - mat_list[mat_list_count].emission = {}; - mat_list[mat_list_count].has_emission = {}; + emission = 0.0f; + has_emission[0] = false; + has_emission[1] = false; + has_emission[2] = false; + has_emission[3] = false; } mat_list[mat_list_count].hash = i.hash; @@ -4199,3531 +8506,3 @@ static void auth_3d_set_material_list(auth_3d* auth, render_context* rctx) { disp_manager.set_material_list(mat_list_count, mat_list); } - -static void auth_3d_ambient_load(auth_3d* auth, auth_3d_ambient* a, auth_3d_ambient_file* af) { - if (af->flags & A3DA_AMBIENT_LIGHT_DIFFUSE) { - auth_3d_rgba_load(auth, &a->light_diffuse, &af->light_diffuse); - enum_or(a->flags, AUTH_3D_AMBIENT_LIGHT_DIFFUSE); - } - - a->name.assign(af->name); - - if (af->flags & A3DA_AMBIENT_LIGHT_DIFFUSE) { - auth_3d_rgba_load(auth, &a->rim_light_diffuse, &af->rim_light_diffuse); - enum_or(a->flags, AUTH_3D_AMBIENT_LIGHT_DIFFUSE); - } -} - -static void auth_3d_ambient_set(auth_3d_ambient* a, render_context* rctx) { - -} - -static void auth_3d_ambient_store(auth_3d* auth, auth_3d_ambient* a, auth_3d_ambient_file* af) { - if (a->flags & AUTH_3D_AMBIENT_LIGHT_DIFFUSE) { - auth_3d_rgba_store(auth, &a->light_diffuse, &af->light_diffuse); - enum_or(af->flags, A3DA_AMBIENT_LIGHT_DIFFUSE); - } - - af->name.assign(a->name); - - if (a->flags & AUTH_3D_AMBIENT_LIGHT_DIFFUSE) { - auth_3d_rgba_store(auth, &a->rim_light_diffuse, &af->rim_light_diffuse); - enum_or(af->flags, A3DA_AMBIENT_LIGHT_DIFFUSE); - } -} - -static void auth_3d_camera_auxiliary_load(auth_3d* auth, auth_3d_camera_auxiliary_file* caf) { - auth_3d_camera_auxiliary* ca = &auth->camera_auxiliary; - - if (caf->flags & A3DA_CAMERA_AUXILIARY_AUTO_EXPOSURE) { - auth_3d_key_load(auth, &ca->auto_exposure, &caf->auto_exposure); - enum_or(ca->flags, AUTH_3D_CAMERA_AUXILIARY_AUTO_EXPOSURE); - } - - if (caf->flags & A3DA_CAMERA_AUXILIARY_EXPOSURE) { - auth_3d_key_load(auth, &ca->exposure, &caf->exposure); - enum_or(ca->flags, AUTH_3D_CAMERA_AUXILIARY_EXPOSURE); - } - - if (caf->flags & A3DA_CAMERA_AUXILIARY_EXPOSURE_RATE) { - auth_3d_key_load(auth, &ca->exposure_rate, &caf->exposure_rate); - enum_or(ca->flags, AUTH_3D_CAMERA_AUXILIARY_EXPOSURE_RATE); - } - - if (caf->flags & A3DA_CAMERA_AUXILIARY_GAMMA) { - auth_3d_key_load(auth, &ca->gamma, &caf->gamma); - enum_or(ca->flags, AUTH_3D_CAMERA_AUXILIARY_GAMMA); - } - - if (caf->flags & A3DA_CAMERA_AUXILIARY_GAMMA_RATE) { - auth_3d_key_load(auth, &ca->gamma_rate, &caf->gamma_rate); - enum_or(ca->flags, AUTH_3D_CAMERA_AUXILIARY_GAMMA_RATE); - } - - if (caf->flags & A3DA_CAMERA_AUXILIARY_SATURATE) { - auth_3d_key_load(auth, &ca->saturate, &caf->saturate); - enum_or(ca->flags, AUTH_3D_CAMERA_AUXILIARY_SATURATE); - } -} - -static void auth_3d_camera_auxiliary_restore_prev_value(auth_3d_camera_auxiliary* ca, render_context* rctx) { - if (ca->flags & AUTH_3D_CAMERA_AUXILIARY_AUTO_EXPOSURE) - rctx->render.set_auto_exposure(true); - if (ca->flags & AUTH_3D_CAMERA_AUXILIARY_EXPOSURE) - rctx->render.set_exposure(2.0); - if (ca->flags & AUTH_3D_CAMERA_AUXILIARY_GAMMA) - rctx->render.set_gamma(1.0); - if (ca->flags & AUTH_3D_CAMERA_AUXILIARY_GAMMA_RATE) - rctx->render.set_gamma_rate(1.0); - if (ca->flags & AUTH_3D_CAMERA_AUXILIARY_SATURATE) - rctx->render.set_saturate_coeff(1.0, 0, false); -} - -static void auth_3d_camera_auxiliary_set(auth_3d_camera_auxiliary* ca, render_context* rctx) { - if (ca->flags & AUTH_3D_CAMERA_AUXILIARY_AUTO_EXPOSURE) - rctx->render.set_auto_exposure(ca->auto_exposure_value > 0.0f); - if (ca->flags & AUTH_3D_CAMERA_AUXILIARY_EXPOSURE) - rctx->render.set_exposure(ca->exposure_value); - if (ca->flags & AUTH_3D_CAMERA_AUXILIARY_GAMMA) - rctx->render.set_gamma(ca->gamma_value); - if (ca->flags & AUTH_3D_CAMERA_AUXILIARY_GAMMA_RATE) - rctx->render.set_gamma_rate(ca->gamma_rate_value); - if (ca->flags & AUTH_3D_CAMERA_AUXILIARY_SATURATE) - rctx->render.set_saturate_coeff(ca->saturate_value, 0, false); -} - -static void auth_3d_camera_auxiliary_store(auth_3d* auth, auth_3d_camera_auxiliary_file* caf) { - auth_3d_camera_auxiliary* ca = &auth->camera_auxiliary; - - if (ca->flags & AUTH_3D_CAMERA_AUXILIARY_AUTO_EXPOSURE) { - auth_3d_key_store(auth, &ca->auto_exposure, &caf->auto_exposure); - enum_or(caf->flags, A3DA_CAMERA_AUXILIARY_AUTO_EXPOSURE); - } - - if (ca->flags & AUTH_3D_CAMERA_AUXILIARY_EXPOSURE) { - auth_3d_key_store(auth, &ca->exposure, &caf->exposure); - enum_or(caf->flags, A3DA_CAMERA_AUXILIARY_EXPOSURE); - } - - if (ca->flags & AUTH_3D_CAMERA_AUXILIARY_EXPOSURE_RATE) { - auth_3d_key_store(auth, &ca->exposure_rate, &caf->exposure_rate); - enum_or(caf->flags, A3DA_CAMERA_AUXILIARY_EXPOSURE_RATE); - } - - if (ca->flags & AUTH_3D_CAMERA_AUXILIARY_GAMMA) { - auth_3d_key_store(auth, &ca->gamma, &caf->gamma); - enum_or(caf->flags, A3DA_CAMERA_AUXILIARY_GAMMA); - } - - if (ca->flags & AUTH_3D_CAMERA_AUXILIARY_GAMMA_RATE) { - auth_3d_key_store(auth, &ca->gamma_rate, &caf->gamma_rate); - enum_or(caf->flags, A3DA_CAMERA_AUXILIARY_GAMMA_RATE); - } - - if (ca->flags & AUTH_3D_CAMERA_AUXILIARY_SATURATE) { - auth_3d_key_store(auth, &ca->saturate, &caf->saturate); - enum_or(caf->flags, A3DA_CAMERA_AUXILIARY_SATURATE); - } -} - -static float_t auth_3d_camera_root_calc_frame(auth_3d_camera_root* cr, float_t frame, render_context* rctx) { - if (auth_3d_key_detect_fast_change(&cr->view_point.model_transform.translation.x, frame, 0.3f) - || auth_3d_key_detect_fast_change(&cr->view_point.model_transform.translation.y, frame, 0.3f) - || auth_3d_key_detect_fast_change(&cr->view_point.model_transform.translation.z, frame, 0.3f) - || auth_3d_key_detect_fast_change(&cr->interest.translation.x, frame, 0.3f) - || auth_3d_key_detect_fast_change(&cr->interest.translation.y, frame, 0.3f) - || auth_3d_key_detect_fast_change(&cr->interest.translation.z, frame, 0.3f)) { - frame = prj::floorf(frame); - rctx->camera->set_fast_change(true); - } - else { - float_t frame_prev = frame - get_delta_frame(); - if (frame_prev > 0.0f && (int32_t)frame - (int32_t)frame_prev == 2) { - frame_prev = prj::ceilf(frame_prev); - if (auth_3d_key_detect_fast_change(&cr->view_point.model_transform.translation.x, frame_prev, 0.3f) - || auth_3d_key_detect_fast_change(&cr->view_point.model_transform.translation.y, frame_prev, 0.3f) - || auth_3d_key_detect_fast_change(&cr->view_point.model_transform.translation.z, frame_prev, 0.3f) - || auth_3d_key_detect_fast_change(&cr->interest.translation.x, frame_prev, 0.3f) - || auth_3d_key_detect_fast_change(&cr->interest.translation.y, frame_prev, 0.3f) - || auth_3d_key_detect_fast_change(&cr->interest.translation.z, frame_prev, 0.3f)) - rctx->camera->set_fast_change_hist0(true); - } - } - return frame; -} - -static void auth_3d_camera_root_load(auth_3d* auth, auth_3d_camera_root* cr, auth_3d_camera_root_file* crf) { - auth_3d_model_transform_load(auth, &cr->interest, &crf->interest); - auth_3d_model_transform_load(auth, &cr->model_transform, &crf->model_transform); - auth_3d_camera_root_view_point_load(auth, &cr->view_point, &crf->view_point); -} - -static void auth_3d_camera_root_store(auth_3d* auth, auth_3d_camera_root* cr, auth_3d_camera_root_file* crf) { - auth_3d_model_transform_store(auth, &cr->interest, &crf->interest); - auth_3d_model_transform_store(auth, &cr->model_transform, &crf->model_transform); - auth_3d_camera_root_view_point_store(auth, &cr->view_point, &crf->view_point); -} - -static void auth_3d_camera_root_view_point_load(auth_3d* auth, auth_3d_camera_root_view_point* crvp, - auth_3d_camera_root_view_point_file* crvpf) { - crvp->aspect = crvpf->aspect; - - if (crvpf->flags & A3DA_CAMERA_ROOT_VIEW_POINT_FOV) { - auth_3d_key_load(auth, &crvp->fov, &crvpf->fov); - crvp->fov_is_horizontal = crvpf->fov_is_horizontal; - enum_or(crvp->flags, AUTH_3D_CAMERA_ROOT_VIEW_POINT_FOV); - } - else { - crvp->camera_aperture_h = crvpf->camera_aperture_h; - crvp->camera_aperture_w = crvpf->camera_aperture_w; - auth_3d_key_load(auth, &crvp->focal_length, &crvpf->focal_length); - } - - auth_3d_model_transform_load(auth, &crvp->model_transform, &crvpf->model_transform); - - if (crvpf->flags & A3DA_CAMERA_ROOT_VIEW_POINT_ROLL) { - auth_3d_key_load(auth, &crvp->roll, &crvpf->roll); - enum_or(crvp->flags, AUTH_3D_CAMERA_ROOT_VIEW_POINT_ROLL); - } -} - -static void auth_3d_camera_root_view_point_store(auth_3d* auth, auth_3d_camera_root_view_point* crvp, - auth_3d_camera_root_view_point_file* crvpf) { - -} - -static void auth_3d_chara_disp(auth_3d_chara* c, auth_3d* auth, render_context* rctx) { - if (c->rob_id >= 0 && c->rob_id <= ROB_ID_MAX) - get_rob_management()->set_disp_on((ROB_ID)c->rob_id, c->model_transform.visible); - - if (auth->pos) { - c->model_transform.set_mat(&auth->mat); - debug_put_line_axis(c->model_transform.mat); - } -} - -static void auth_3d_chara_load(auth_3d* auth, auth_3d_chara* c, auth_3d_chara_file* cf) { - auth_3d_model_transform_load(auth, &c->model_transform, &cf->model_transform); - c->name.assign(cf->name); -} - -static void auth_3d_chara_set(auth_3d_chara* c, auth_3d* auth, render_context* rctx) { - mat4 mat = auth->mat; - - vec3 pos = c->model_transform.translation_value; - if (auth->mirror) - pos.x = -pos.x; - mat4_transform_point(&mat, &pos, &pos); - - RobAngle chr_ang; - chr_ang.set_rad(c->model_transform.rotation_value.y); - if (auth->mirror) - chr_ang = -chr_ang; - - RobAngle ang; - ang.set_rad(atan2f(mat.row2.x, mat.row2.z)); - ang += chr_ang; - if (c->rob_id >= 0 && c->rob_id < ROB_ID_MAX) { - RobManagement* rob_man = get_rob_management(); - rob_man->set_rob_pos((ROB_ID)c->rob_id, pos); - rob_man->set_rob_yang((ROB_ID)c->rob_id, ang); - } -} - -static void auth_3d_chara_store(auth_3d* auth, auth_3d_chara* c, auth_3d_chara_file* cf) { - auth_3d_model_transform_store(auth, &c->model_transform, &cf->model_transform); - cf->name.assign(c->name); -} - -static void auth_3d_curve_load(auth_3d* auth, auth_3d_curve* c, auth_3d_curve_file* cf) { - auth_3d_key_load(auth, &c->curve, &cf->curve); - c->name.assign(cf->name); -} - -static void auth_3d_curve_store(auth_3d* auth, auth_3d_curve* c, auth_3d_curve_file* cf) { - auth_3d_key_store(auth, &c->curve, &cf->curve); - cf->name.assign(c->name); -} - -static void auth_3d_dof_load(auth_3d* auth, auth_3d_dof* d, auth_3d_dof_file* df) { - if (df->has_dof) { - auth_3d_model_transform_load(auth, &d->model_transform, &df->model_transform); - d->has_dof = true; - } -} - -static void auth_3d_dof_restore_prev_value(auth_3d_dof* d, render_context* rctx) { - if (!d->has_dof) - return; - - rctx->render.set_dof_enable(false); -} - -static void auth_3d_dof_set(auth_3d_dof* d, render_context* rctx) { - if (!d->has_dof) - return; - - vec3 view_point; - rctx->camera->get_view_point(view_point); - - float_t focus = vec3::distance(d->model_transform.translation_value, view_point); - - rctx->render.set_dof_enable(fabsf(d->model_transform.rotation_value.z) > 0.000001f); - rctx->render.set_dof_data(focus, d->model_transform.scale_value.x, - d->model_transform.rotation_value.x, d->model_transform.rotation_value.y); -} - -static void auth_3d_dof_store(auth_3d* auth, auth_3d_dof* d, auth_3d_dof_file* df) { - if (d->has_dof) { - auth_3d_model_transform_store(auth, &d->model_transform, &df->model_transform); - df->has_dof = true; - } -} - -static auth_3d_detail::Event* auth_3d_event_load(auth_3d* auth, auth_3d_event_file* ef) { - auth_3d_detail::Event* e = 0; - switch (ef->type) { - case A3DA_EVENT_MISC: - default: - e = new auth_3d_detail::Event(ef); - break; - case A3DA_EVENT_FILT: { - if (!ef->param1.compare("WHITEIN") || !ef->param1.compare("WHITEOUT") - || !ef->param1.compare("FADEIN") || !ef->param1.compare("FADEOUT")) - e = new auth_3d_detail::EventFilterFade(ef); - else if (!ef->param1.compare("TIMESTOP")) - e = new auth_3d_detail::EventFilterTimeStop(ef); - else - e = new auth_3d_detail::Event(ef); - break; - } - case A3DA_EVENT_FX: - if (!ef->param1.compare("SMOOTH")) - e = new auth_3d_detail::EventFXSmoothCut(ef); - else - e = new auth_3d_detail::EventFX(ef); - break; - case A3DA_EVENT_SND: - e = new auth_3d_detail::EventSnd(ef); - break; - case A3DA_EVENT_MOT: - e = new auth_3d_detail::EventMot(ef); - break; - case A3DA_EVENT_A2D: - e = new auth_3d_detail::EventA2d(ef); - break; - } - return e; -} - -static void auth_3d_event_store(auth_3d* auth, auth_3d_detail::Event* e, auth_3d_event_file* ef) { - -} - -static const char* auth_3d_event_type_string(auth_3d_detail::Event::Type type) { - switch (type) { - case auth_3d_detail::Event::Type::MISC: - return "MISC"; - case auth_3d_detail::Event::Type::FILT: - return "FLT"; - case auth_3d_detail::Event::Type::FX: - return "FX"; - case auth_3d_detail::Event::Type::SND: - return "SND"; - case auth_3d_detail::Event::Type::MOT: - return "MOT"; - case auth_3d_detail::Event::Type::A2D: - return "A2D"; - default: - return "(unknown)"; - } -} - -static void auth_3d_fog_load(auth_3d* auth, auth_3d_fog* f, auth_3d_fog_file* ff) { - if (ff->flags & A3DA_FOG_COLOR) { - auth_3d_rgba_load(auth, &f->color, &ff->color); - enum_or(f->flags, AUTH_3D_FOG_COLOR); - } - - if (ff->flags & A3DA_FOG_DENSITY) { - auth_3d_key_load(auth, &f->density, &ff->density); - enum_or(f->flags, AUTH_3D_FOG_DENSITY); - } - - if (ff->flags & A3DA_FOG_END) { - auth_3d_key_load(auth, &f->end, &ff->end); - enum_or(f->flags, AUTH_3D_FOG_END); - } - - f->id = ff->id; - - if (ff->flags & A3DA_FOG_START) { - auth_3d_key_load(auth, &f->start, &ff->start); - enum_or(f->flags, AUTH_3D_FOG_START); - } -} - -static void auth_3d_fog_restore_prev_value(auth_3d_fog* f, render_context* rctx) { - fog_id id = f->id; - if (id < FOG_DEPTH || id > FOG_BUMP) - return; - - fog* data = &rctx->fog[id]; - if (f->flags_init & AUTH_3D_FOG_COLOR) - data->set_color(f->color_init); - - if (f->flags_init & AUTH_3D_FOG_DENSITY) - data->set_density(f->density_value); - - if (f->flags_init & AUTH_3D_FOG_END) - data->set_end(f->end_value); - - if (f->flags_init & AUTH_3D_FOG_START) - data->set_start(f->start_value); -} - -static void auth_3d_fog_set(auth_3d_fog* f, render_context* rctx) { - fog_id id = f->id; - if (id < FOG_DEPTH || id > FOG_BUMP) - return; - - fog* data = &rctx->fog[id]; - if (f->flags & AUTH_3D_FOG_COLOR) { - if (!(f->flags_init & AUTH_3D_FOG_COLOR)) { - vec4 color_init; - data->get_color(color_init); - f->color_init = color_init; - enum_or(f->flags_init, AUTH_3D_FOG_COLOR); - } - - data->set_color(f->color.value); - } - - if (f->flags & AUTH_3D_FOG_DENSITY) { - if (!(f->flags_init & AUTH_3D_FOG_DENSITY)) { - f->density_init = data->get_density(); - enum_or(f->flags_init, AUTH_3D_FOG_DENSITY); - } - - data->set_density(f->density_value); - } - - if (f->flags & AUTH_3D_FOG_END) { - if (!(f->flags_init & AUTH_3D_FOG_END)) { - f->end_init = data->get_end(); - enum_or(f->flags_init, AUTH_3D_FOG_END); - } - - data->set_end(f->end_value); - } - - if (f->flags & AUTH_3D_FOG_START) { - if (!(f->flags_init & AUTH_3D_FOG_START)) { - f->start_init = data->get_start(); - enum_or(f->flags_init, AUTH_3D_FOG_START); - } - - data->set_start(f->start_value); - } -} - -static void auth_3d_fog_store(auth_3d* auth, auth_3d_fog* f, auth_3d_fog_file* ff) { - if (f->flags & AUTH_3D_FOG_COLOR) { - auth_3d_rgba_store(auth, &f->color, &ff->color); - enum_or(ff->flags, A3DA_FOG_COLOR); - } - - if (f->flags & AUTH_3D_FOG_DENSITY) { - auth_3d_key_store(auth, &f->density, &ff->density); - enum_or(ff->flags, A3DA_FOG_DENSITY); - } - - if (f->flags & AUTH_3D_FOG_END) { - auth_3d_key_store(auth, &f->end, &ff->end); - enum_or(ff->flags, A3DA_FOG_END); - } - - ff->id = f->id; - - if (f->flags & AUTH_3D_FOG_START) { - auth_3d_key_store(auth, &f->start, &ff->start); - enum_or(ff->flags, A3DA_FOG_START); - } -} - -static void auth_3d_light_load(auth_3d* auth, auth_3d_light* l, auth_3d_light_file* lf) { - if (lf->flags & A3DA_LIGHT_AMBIENT) { - auth_3d_rgba_load(auth, &l->ambient, &lf->ambient); - enum_or(l->flags, AUTH_3D_LIGHT_AMBIENT); - } - - if (lf->flags & A3DA_LIGHT_CONE_ANGLE) { - auth_3d_key_load(auth, &l->cone_angle, &lf->cone_angle); - enum_or(l->flags, AUTH_3D_LIGHT_CONE_ANGLE); - } - - if (lf->flags & A3DA_LIGHT_CONSTANT) { - auth_3d_key_load(auth, &l->constant, &lf->constant); - enum_or(l->flags, AUTH_3D_LIGHT_CONSTANT); - } - - if (lf->flags & A3DA_LIGHT_DIFFUSE) { - auth_3d_rgba_load(auth, &l->diffuse, &lf->diffuse); - enum_or(l->flags, AUTH_3D_LIGHT_DIFFUSE); - } - - if (lf->flags & A3DA_LIGHT_DROP_OFF) { - auth_3d_key_load(auth, &l->drop_off, &lf->drop_off); - enum_or(l->flags, AUTH_3D_LIGHT_DROP_OFF); - } - - if (lf->flags & A3DA_LIGHT_FAR) { - auth_3d_key_load(auth, &l->_far, &lf->_far); - enum_or(l->flags, AUTH_3D_LIGHT_FAR); - } - - l->id = lf->id; - - if (lf->flags & A3DA_LIGHT_INTENSITY) { - auth_3d_key_load(auth, &l->intensity, &lf->intensity); - enum_or(l->flags, AUTH_3D_LIGHT_INTENSITY); - } - - if (lf->flags & A3DA_LIGHT_LINEAR) { - auth_3d_key_load(auth, &l->linear, &lf->linear); - enum_or(l->flags, AUTH_3D_LIGHT_LINEAR); - } - - if (lf->flags & A3DA_LIGHT_POSITION) { - auth_3d_model_transform_load(auth, &l->position, &lf->position); - enum_or(l->flags, AUTH_3D_LIGHT_POSITION); - } - - if (lf->flags & A3DA_LIGHT_QUADRATIC) { - auth_3d_key_load(auth, &l->quadratic, &lf->quadratic); - enum_or(l->flags, AUTH_3D_LIGHT_QUADRATIC); - } - - if (lf->flags & A3DA_LIGHT_SPECULAR) { - auth_3d_rgba_load(auth, &l->specular, &lf->specular); - enum_or(l->flags, AUTH_3D_LIGHT_SPECULAR); - } - - if (lf->flags & A3DA_LIGHT_SPOT_DIRECTION) { - auth_3d_model_transform_load(auth, &l->spot_direction, &lf->spot_direction); - enum_or(l->flags, AUTH_3D_LIGHT_SPOT_DIRECTION); - } - - if (lf->flags & A3DA_LIGHT_TONE_CURVE) { - auth_3d_rgba_load(auth, &l->tone_curve, &lf->tone_curve); - enum_or(l->flags, AUTH_3D_LIGHT_TONE_CURVE); - } - - l->type.assign(lf->type); -} - -static void auth_3d_light_restore_prev_value(auth_3d_light* l, render_context* rctx) { - light_set* set = &rctx->light_set[LIGHT_SET_MAIN]; - - light_id id = l->id; - if (id < LIGHT_CHARA || id > LIGHT_PROJECTION) - return; - - light_data* data = &set->lights[id]; - if (l->flags_init & AUTH_3D_LIGHT_AMBIENT) - data->set_ambient(l->ambient_init); - - if (l->flags_init & AUTH_3D_LIGHT_DIFFUSE) - data->set_diffuse(l->diffuse_init); - - if (l->flags_init & AUTH_3D_LIGHT_SPECULAR) - data->set_specular(l->specular_init); - - if (l->flags_init & AUTH_3D_LIGHT_TONE_CURVE) - data->set_tone_curve(l->tone_curve_init); -} - -static void auth_3d_light_set(auth_3d_light* l, render_context* rctx) { - light_set* set = &rctx->light_set[LIGHT_SET_MAIN]; - - light_id id = l->id; - if (id < LIGHT_CHARA || id > LIGHT_PROJECTION) - return; - - light_data* data = &set->lights[id]; - if (l->flags & AUTH_3D_LIGHT_AMBIENT) { - if (!(l->flags_init & AUTH_3D_LIGHT_AMBIENT)) { - vec4 ambient_init; - data->get_ambient(ambient_init); - l->ambient_init = ambient_init; - enum_or(l->flags_init, AUTH_3D_LIGHT_AMBIENT); - } - - bool set[4]; - set[0] = !!(l->ambient.flags & AUTH_3D_RGBA_R); - set[1] = !!(l->ambient.flags & AUTH_3D_RGBA_G); - set[2] = !!(l->ambient.flags & AUTH_3D_RGBA_B); - set[3] = !!(l->ambient.flags & AUTH_3D_RGBA_A); - data->set_ambient(l->ambient.value, set); - } - - if (l->flags & AUTH_3D_LIGHT_DIFFUSE) { - if (!(l->flags_init & AUTH_3D_LIGHT_DIFFUSE)) { - vec4 diffuse_init; - data->get_diffuse(diffuse_init); - l->diffuse_init = diffuse_init; - enum_or(l->flags_init, AUTH_3D_LIGHT_DIFFUSE); - } - - bool set[4]; - set[0] = !!(l->diffuse.flags & AUTH_3D_RGBA_R); - set[1] = !!(l->diffuse.flags & AUTH_3D_RGBA_G); - set[2] = !!(l->diffuse.flags & AUTH_3D_RGBA_B); - set[3] = !!(l->diffuse.flags & AUTH_3D_RGBA_A); - data->set_diffuse(l->diffuse.value, set); - } - - if (l->flags & AUTH_3D_LIGHT_POSITION) - data->set_position(l->position.translation_value); - - if (l->flags & AUTH_3D_LIGHT_SPECULAR) { - if (!(l->flags_init & AUTH_3D_LIGHT_SPECULAR)) { - vec4 specular_init; - data->get_specular(specular_init); - l->specular_init = specular_init; - enum_or(l->flags_init, AUTH_3D_LIGHT_SPECULAR); - } - - bool set[4]; - set[0] = !!(l->specular.flags & AUTH_3D_RGBA_R); - set[1] = !!(l->specular.flags & AUTH_3D_RGBA_G); - set[2] = !!(l->specular.flags & AUTH_3D_RGBA_B); - set[3] = !!(l->specular.flags & AUTH_3D_RGBA_A); - data->set_specular(l->specular.value, set); - } - - if (l->flags & AUTH_3D_LIGHT_SPOT_DIRECTION) - data->set_spot_direction(l->spot_direction.translation_value); - - if (l->flags & AUTH_3D_LIGHT_TONE_CURVE) { - if (!(l->flags_init & AUTH_3D_LIGHT_TONE_CURVE)) { - data->get_tone_curve(l->tone_curve_init); - enum_or(l->flags_init, AUTH_3D_LIGHT_TONE_CURVE); - } - - light_tone_curve tone_curve; - tone_curve.start_point = l->tone_curve.value.x; - tone_curve.end_point = l->tone_curve.value.y; - tone_curve.coefficient = l->tone_curve.value.z; - data->set_tone_curve(tone_curve); - } -} - -static void auth_3d_light_store(auth_3d* auth, auth_3d_light* l, auth_3d_light_file* lf) { - if (l->flags & AUTH_3D_LIGHT_AMBIENT) { - auth_3d_rgba_store(auth, &l->ambient, &lf->ambient); - enum_or(lf->flags, A3DA_LIGHT_AMBIENT); - } - - if (l->flags & AUTH_3D_LIGHT_CONE_ANGLE) { - auth_3d_key_store(auth, &l->cone_angle, &lf->cone_angle); - enum_or(lf->flags, A3DA_LIGHT_CONE_ANGLE); - } - - if (l->flags & AUTH_3D_LIGHT_CONSTANT) { - auth_3d_key_store(auth, &l->constant, &lf->constant); - enum_or(lf->flags, A3DA_LIGHT_CONSTANT); - } - - if (l->flags & AUTH_3D_LIGHT_DIFFUSE) { - auth_3d_rgba_store(auth, &l->diffuse, &lf->diffuse); - enum_or(lf->flags, A3DA_LIGHT_DIFFUSE); - } - - if (l->flags & AUTH_3D_LIGHT_DROP_OFF) { - auth_3d_key_store(auth, &l->drop_off, &lf->drop_off); - enum_or(lf->flags, A3DA_LIGHT_DROP_OFF); - } - - if (l->flags & AUTH_3D_LIGHT_FAR) { - auth_3d_key_store(auth, &l->_far, &lf->_far); - enum_or(lf->flags, A3DA_LIGHT_FAR); - } - - lf->id = l->id; - - if (l->flags & AUTH_3D_LIGHT_INTENSITY) { - auth_3d_key_store(auth, &l->intensity, &lf->intensity); - enum_or(lf->flags, A3DA_LIGHT_INTENSITY); - } - - if (l->flags & AUTH_3D_LIGHT_LINEAR) { - auth_3d_key_store(auth, &l->linear, &lf->linear); - enum_or(lf->flags, A3DA_LIGHT_LINEAR); - } - - if (l->flags & AUTH_3D_LIGHT_POSITION) { - auth_3d_model_transform_store(auth, &l->position, &lf->position); - enum_or(lf->flags, A3DA_LIGHT_POSITION); - } - - if (l->flags & AUTH_3D_LIGHT_QUADRATIC) { - auth_3d_key_store(auth, &l->quadratic, &lf->quadratic); - enum_or(lf->flags, A3DA_LIGHT_QUADRATIC); - } - - if (l->flags & AUTH_3D_LIGHT_SPECULAR) { - auth_3d_rgba_store(auth, &l->specular, &lf->specular); - enum_or(lf->flags, A3DA_LIGHT_SPECULAR); - } - - if (l->flags & AUTH_3D_LIGHT_SPOT_DIRECTION) { - auth_3d_model_transform_store(auth, &l->spot_direction, &lf->spot_direction); - enum_or(lf->flags, A3DA_LIGHT_SPOT_DIRECTION); - } - - if (l->flags & AUTH_3D_LIGHT_TONE_CURVE) { - auth_3d_rgba_store(auth, &l->tone_curve, &lf->tone_curve); - enum_or(lf->flags, A3DA_LIGHT_TONE_CURVE); - } - - lf->type.assign(l->type); -} - -static void auth_3d_m_object_hrc_get_mat(auth_3d_m_object_hrc* moh, mat4* mat) { - for (auth_3d_object_node& i : moh->node) - if (i.mat) { - *mat = *i.mat; - return; - } - - *mat = moh->node.front().model_transform.mat; -} - -static void auth_3d_m_object_hrc_disp(auth_3d_m_object_hrc* moh, auth_3d* auth, render_context* rctx) { - if (!auth->visible || !moh->model_transform.visible) - return; - - mdl::DispManager& disp_manager = *rctx->disp_manager; - - for (auth_3d_object_instance& i : moh->instance) { - if (!i.model_transform.visible) - continue; - - mdl::ObjFlags flags = mdl::OBJ_SSS; - SHADOW_GROUP shadow_group = SHADOW_GROUP_CHARA; - if (auth->shadow || i.shadow) { - enum_or(flags, mdl::OBJ_4 | mdl::OBJ_SHADOW); - shadow_group = SHADOW_GROUP_STAGE; - } - if (auth->alpha < 1.0f) - enum_or(flags, auth->obj_flags); - - disp_manager.set_obj_flags(flags); - disp_manager.set_shadow_group(shadow_group); - - Shadow* shad = shadow_ptr_get(); - if (shad && (flags & mdl::OBJ_SHADOW)) { - disp_manager.set_shadow_group(SHADOW_GROUP_STAGE); - - mat4* m = &moh->model_transform.mat; - for (auth_3d_object_node& j : moh->node) - if (j.mat) { - m = j.mat; - break; - } - - mat4 mat = i.model_transform.mat; - mat4_mul(&mat, m, &mat); - - vec3 pos; - mat4_get_translation(&mat, &pos); - pos.y -= 0.2f; - shad->positions[shadow_group].push_back(pos); - } - - if (i.mats.size()) - disp_manager.entry_obj_by_object_info_object_skin( - i.object_info, 0, 0, auth->alpha, i.mats.data(), 0, 0, i.model_transform.mat); - } - - disp_manager.set_obj_flags(); - disp_manager.set_shadow_group(SHADOW_GROUP_CHARA); -} - -static void auth_3d_m_object_hrc_load(auth_3d* auth, auth_3d_m_object_hrc* moh, - auth_3d_m_object_hrc_file* mohf, object_database* obj_db) { - size_t node_index = 0; - moh->node.resize(mohf->node.size()); - for (auth_3d_object_node_file& i : mohf->node) - auth_3d_object_node_load(auth, - &moh->node[node_index++], &i); - - auth_3d_object_model_transform_load(auth, &moh->model_transform, &mohf->model_transform); - moh->name.assign(mohf->name); - - size_t instance_index = 0; - moh->instance.resize(mohf->instance.size()); - for (auth_3d_object_instance_file& i : mohf->instance) - auth_3d_object_instance_load(auth, - &moh->instance[instance_index++], &i, moh, obj_db); -} - -static void auth_3d_m_object_hrc_nodes_mat_mult(auth_3d_m_object_hrc* moh) { - auth_3d_object_node* node = moh->node.data(); - - for (auth_3d_object_node& i : moh->node) - if (i.parent >= 0) - i.model_transform.mat_mult(&node[i.parent].model_transform.mat); - else - i.model_transform.mat = i.model_transform.mat_inner; -} - -static void auth_3d_m_object_hrc_store(auth_3d* auth, auth_3d_m_object_hrc* moh, - auth_3d_m_object_hrc_file* mohf) { - size_t node_index = 0; - mohf->node.resize(moh->node.size()); - for (auth_3d_object_node& i : moh->node) - auth_3d_object_node_store(auth, - &i, &mohf->node[node_index++]); - - auth_3d_object_model_transform_store(auth, &moh->model_transform, &mohf->model_transform); - mohf->name.assign(moh->name); - - size_t instance_index = 0; - mohf->instance.resize(moh->instance.size()); - for (auth_3d_object_instance& i : moh->instance) - auth_3d_object_instance_store(auth, - &i, &mohf->instance[instance_index++], moh); -} - -static void auth_3d_material_list_load(auth_3d* auth, auth_3d_material_list* ml, auth_3d_material_list_file* mlf) { - //int32_t ident[24] = {}; - if (mlf->flags & A3DA_MATERIAL_LIST_BLEND_COLOR) { - auth_3d_rgba_load(auth, &ml->blend_color, &mlf->blend_color); - enum_or(ml->flags, AUTH_3D_MATERIAL_LIST_BLEND_COLOR); - - /*auth_3d_key& r = ml->blend_color.r; - auth_3d_key& g = ml->blend_color.g; - auth_3d_key& b = ml->blend_color.b; - auth_3d_key& a = ml->blend_color.a; - - switch (r.type) { - case AUTH_3D_KEY_NONE: - case AUTH_3D_KEY_STATIC: - switch (g.type) { - case AUTH_3D_KEY_NONE: - case AUTH_3D_KEY_STATIC: - case AUTH_3D_KEY_LINEAR: - case AUTH_3D_KEY_HERMITE: - case AUTH_3D_KEY_HOLD: - ident[0] = 1; - ident[6] = 1; - break; - } - break; - case AUTH_3D_KEY_LINEAR: - case AUTH_3D_KEY_HERMITE: - case AUTH_3D_KEY_HOLD: - switch (g.type) { - case AUTH_3D_KEY_NONE: - case AUTH_3D_KEY_STATIC: - ident[0] = 1; - ident[6] = 1; - break; - case AUTH_3D_KEY_LINEAR: - case AUTH_3D_KEY_HERMITE: - case AUTH_3D_KEY_HOLD: - if (r.length == g.length) { - ident[0] = 1; - - kft3* keys1 = r.keys; - kft3* keys2 = g.keys; - size_t length = r.length; - for (size_t i = 0; i < length; i++) - if (*(uint32_t*)&keys1[i].frame != *(uint32_t*)&keys2[i].frame) { - ident[0] = 0; - break; - } - - if (ident[0]) { - ident[6] = 1; - - for (size_t i = 0; i < length; i++) - if (*(uint64_t*)&keys1[i].tangent1 != *(uint64_t*)&keys2[i].tangent1) { - ident[6] = 0; - break; - } - } - } - else if (r.length > g.length) { - if (g.type == AUTH_3D_KEY_LINEAR) { - kft3* keys1 = r.keys; - kft3* keys2 = g.keys; - size_t keys1_length = r.length; - size_t keys2_length = g.length; - - for (size_t i = 0; i < keys1_length; i++) { - float_t frame = keys1[i].frame; - bool found = false; - for (size_t j = 0; j < keys2_length && i < keys1_length; j++) - if (frame == keys2[j].frame) { - found = true; - break; - } - - if (!found) - if (frame <= keys2[0].frame || frame >= keys2[keys2_length - 1].frame) { - ident[0] = 1; - ident[6] = 1; - } - else - for (size_t j = 0; j + 1 < keys2_length && i < keys1_length; j++) - if (frame >= keys2[j].frame && keys2[j + 1].frame) { - if (*(uint32_t*)&keys2[j].value == *(uint32_t*)&keys2[j + 1].value) { - ident[0] = 1; - ident[6] = 1; - } - break; - } - } - } - } - else if (r.length < g.length) { - if (r.type == AUTH_3D_KEY_LINEAR) { - kft3* keys1 = g.keys; - kft3* keys2 = r.keys; - size_t keys1_length = g.length; - size_t keys2_length = r.length; - - for (size_t i = 0; i < keys1_length; i++) { - float_t frame = keys1[i].frame; - bool found = false; - for (size_t j = 0; j < keys2_length && i < keys1_length; j++) - if (frame == keys2[j].frame) { - found = true; - break; - } - - if (!found) - if (frame <= keys2[0].frame || frame >= keys2[keys2_length - 1].frame) { - ident[0] = 1; - ident[6] = 1; - } - else - for (size_t j = 0; j + 1 < keys2_length && i < keys1_length; j++) - if (frame >= keys2[j].frame && keys2[j + 1].frame) { - if (*(uint32_t*)&keys2[j].value == *(uint32_t*)&keys2[j + 1].value) { - ident[0] = 1; - ident[6] = 1; - } - break; - } - } - } - } - break; - } - break; - } - - switch (r.type) { - case AUTH_3D_KEY_NONE: - case AUTH_3D_KEY_STATIC: - switch (b.type) { - case AUTH_3D_KEY_NONE: - case AUTH_3D_KEY_STATIC: - case AUTH_3D_KEY_LINEAR: - case AUTH_3D_KEY_HERMITE: - case AUTH_3D_KEY_HOLD: - ident[1] = 1; - ident[7] = 1; - break; - } - break; - case AUTH_3D_KEY_LINEAR: - case AUTH_3D_KEY_HERMITE: - case AUTH_3D_KEY_HOLD: - switch (b.type) { - case AUTH_3D_KEY_NONE: - case AUTH_3D_KEY_STATIC: - ident[1] = 1; - ident[7] = 1; - break; - case AUTH_3D_KEY_LINEAR: - case AUTH_3D_KEY_HERMITE: - case AUTH_3D_KEY_HOLD: - if (r.length == b.length) { - ident[1] = 1; - - kft3* keys1 = r.keys; - kft3* keys2 = b.keys; - size_t length = r.length; - for (size_t i = 0; i < length; i++) - if (*(uint32_t*)&keys1[i].frame != *(uint32_t*)&keys2[i].frame) { - ident[1] = 0; - break; - } - - if (ident[1]) { - ident[7] = 1; - - for (size_t i = 0; i < length; i++) - if (*(uint64_t*)&keys1[i].tangent1 != *(uint64_t*)&keys2[i].tangent1) { - ident[7] = 0; - break; - } - } - } - else if (r.length > b.length) { - if (b.type == AUTH_3D_KEY_LINEAR) { - kft3* keys1 = r.keys; - kft3* keys2 = b.keys; - size_t keys1_length = r.length; - size_t keys2_length = b.length; - - for (size_t i = 0; i < keys1_length; i++) { - float_t frame = keys1[i].frame; - bool found = false; - for (size_t j = 0; j < keys2_length && i < keys1_length; j++) - if (frame == keys2[j].frame) { - found = true; - break; - } - - if (!found) - if (frame <= keys2[0].frame || frame >= keys2[keys2_length - 1].frame) { - ident[1] = 1; - ident[7] = 1; - } - else - for (size_t j = 0; j + 1 < keys2_length && i < keys1_length; j++) - if (frame >= keys2[j].frame && keys2[j + 1].frame) { - if (*(uint32_t*)&keys2[j].value == *(uint32_t*)&keys2[j + 1].value) { - ident[1] = 1; - ident[7] = 1; - } - break; - } - } - } - } - else if (r.length < b.length) { - if (r.type == AUTH_3D_KEY_LINEAR) { - kft3* keys1 = b.keys; - kft3* keys2 = r.keys; - size_t keys1_length = b.length; - size_t keys2_length = r.length; - - for (size_t i = 0; i < keys1_length; i++) { - float_t frame = keys1[i].frame; - bool found = false; - for (size_t j = 0; j < keys2_length && i < keys1_length; j++) - if (frame == keys2[j].frame) { - found = true; - break; - } - - if (!found) - if (frame <= keys2[0].frame || frame >= keys2[keys2_length - 1].frame) { - ident[1] = 1; - ident[7] = 1; - } - else - for (size_t j = 0; j + 1 < keys2_length && i < keys1_length; j++) - if (frame >= keys2[j].frame && keys2[j + 1].frame) { - if (*(uint32_t*)&keys2[j].value == *(uint32_t*)&keys2[j + 1].value) { - ident[1] = 1; - ident[7] = 1; - } - break; - } - } - } - } - break; - } - break; - } - - switch (r.type) { - case AUTH_3D_KEY_NONE: - case AUTH_3D_KEY_STATIC: - switch (a.type) { - case AUTH_3D_KEY_NONE: - case AUTH_3D_KEY_STATIC: - case AUTH_3D_KEY_LINEAR: - case AUTH_3D_KEY_HERMITE: - case AUTH_3D_KEY_HOLD: - ident[2] = 1; - ident[8] = 1; - break; - } - break; - case AUTH_3D_KEY_LINEAR: - case AUTH_3D_KEY_HERMITE: - case AUTH_3D_KEY_HOLD: - switch (a.type) { - case AUTH_3D_KEY_NONE: - case AUTH_3D_KEY_STATIC: - ident[2] = 1; - ident[8] = 1; - break; - case AUTH_3D_KEY_LINEAR: - case AUTH_3D_KEY_HERMITE: - case AUTH_3D_KEY_HOLD: - if (r.length == a.length) { - ident[2] = 1; - - kft3* keys1 = r.keys; - kft3* keys2 = a.keys; - size_t length = r.length; - for (size_t i = 0; i < length; i++) - if (*(uint32_t*)&keys1[i].frame != *(uint32_t*)&keys2[i].frame) { - ident[2] = 0; - break; - } - - if (ident[2]) { - ident[8] = 1; - - for (size_t i = 0; i < length; i++) - if (*(uint64_t*)&keys1[i].tangent1 != *(uint64_t*)&keys2[i].tangent1) { - ident[8] = 0; - break; - } - } - } - else if (r.length > a.length) { - if (a.type == AUTH_3D_KEY_LINEAR) { - kft3* keys1 = r.keys; - kft3* keys2 = a.keys; - size_t keys1_length = r.length; - size_t keys2_length = a.length; - - for (size_t i = 0; i < keys1_length; i++) { - float_t frame = keys1[i].frame; - bool found = false; - for (size_t j = 0; j < keys2_length && i < keys1_length; j++) - if (frame == keys2[j].frame) { - found = true; - break; - } - - if (!found) - if (frame <= keys2[0].frame || frame >= keys2[keys2_length - 1].frame) { - ident[2] = 1; - ident[8] = 1; - } - else - for (size_t j = 0; j + 1 < keys2_length && i < keys1_length; j++) - if (frame >= keys2[j].frame && keys2[j + 1].frame) { - if (*(uint32_t*)&keys2[j].value == *(uint32_t*)&keys2[j + 1].value) { - ident[2] = 1; - ident[8] = 1; - } - break; - } - } - } - } - else if (r.length < a.length) { - if (r.type == AUTH_3D_KEY_LINEAR) { - kft3* keys1 = a.keys; - kft3* keys2 = r.keys; - size_t keys1_length = a.length; - size_t keys2_length = r.length; - - for (size_t i = 0; i < keys1_length; i++) { - float_t frame = keys1[i].frame; - bool found = false; - for (size_t j = 0; j < keys2_length && i < keys1_length; j++) - if (frame == keys2[j].frame) { - found = true; - break; - } - - if (!found) - if (frame <= keys2[0].frame || frame >= keys2[keys2_length - 1].frame) { - ident[2] = 1; - ident[8] = 1; - } - else - for (size_t j = 0; j + 1 < keys2_length && i < keys1_length; j++) - if (frame >= keys2[j].frame && keys2[j + 1].frame) { - if (*(uint32_t*)&keys2[j].value == *(uint32_t*)&keys2[j + 1].value) { - ident[2] = 1; - ident[8] = 1; - } - break; - } - } - } - } - break; - } - break; - } - - switch (g.type) { - case AUTH_3D_KEY_NONE: - case AUTH_3D_KEY_STATIC: - switch (b.type) { - case AUTH_3D_KEY_NONE: - case AUTH_3D_KEY_STATIC: - case AUTH_3D_KEY_LINEAR: - case AUTH_3D_KEY_HERMITE: - case AUTH_3D_KEY_HOLD: - ident[3] = 1; - ident[9] = 1; - break; - } - break; - case AUTH_3D_KEY_LINEAR: - case AUTH_3D_KEY_HERMITE: - case AUTH_3D_KEY_HOLD: - switch (b.type) { - case AUTH_3D_KEY_NONE: - case AUTH_3D_KEY_STATIC: - ident[3] = 1; - ident[9] = 1; - break; - case AUTH_3D_KEY_LINEAR: - case AUTH_3D_KEY_HERMITE: - case AUTH_3D_KEY_HOLD: - if (g.length == b.length) { - ident[3] = 1; - - kft3* keys1 = g.keys; - kft3* keys2 = b.keys; - size_t length = g.length; - for (size_t i = 0; i < length; i++) - if (*(uint32_t*)&keys1[i].frame != *(uint32_t*)&keys2[i].frame) { - ident[3] = 0; - break; - } - - if (ident[3]) { - ident[9] = 1; - - for (size_t i = 0; i < length; i++) - if (*(uint64_t*)&keys1[i].tangent1 != *(uint64_t*)&keys2[i].tangent1) { - ident[9] = 0; - break; - } - } - } - else if (g.length > b.length) { - if (b.type == AUTH_3D_KEY_LINEAR) { - kft3* keys1 = g.keys; - kft3* keys2 = b.keys; - size_t keys1_length = g.length; - size_t keys2_length = b.length; - - for (size_t i = 0; i < keys1_length; i++) { - float_t frame = keys1[i].frame; - bool found = false; - for (size_t j = 0; j < keys2_length && i < keys1_length; j++) - if (frame == keys2[j].frame) { - found = true; - break; - } - - if (!found) - if (frame <= keys2[0].frame || frame >= keys2[keys2_length - 1].frame) { - ident[3] = 1; - ident[9] = 1; - } - else - for (size_t j = 0; j + 1 < keys2_length && i < keys1_length; j++) - if (frame >= keys2[j].frame && keys2[j + 1].frame) { - if (*(uint32_t*)&keys2[j].value == *(uint32_t*)&keys2[j + 1].value) { - ident[3] = 1; - ident[9] = 1; - } - break; - } - } - } - } - else if (g.length < b.length) { - if (g.type == AUTH_3D_KEY_LINEAR) { - kft3* keys1 = b.keys; - kft3* keys2 = g.keys; - size_t keys1_length = b.length; - size_t keys2_length = g.length; - - for (size_t i = 0; i < keys1_length; i++) { - float_t frame = keys1[i].frame; - bool found = false; - for (size_t j = 0; j < keys2_length && i < keys1_length; j++) - if (frame == keys2[j].frame) { - found = true; - break; - } - - if (!found) - if (frame <= keys2[0].frame || frame >= keys2[keys2_length - 1].frame) { - ident[3] = 1; - ident[9] = 1; - } - else - for (size_t j = 0; j + 1 < keys2_length && i < keys1_length; j++) - if (frame >= keys2[j].frame && keys2[j + 1].frame) { - if (*(uint32_t*)&keys2[j].value == *(uint32_t*)&keys2[j + 1].value) { - ident[3] = 1; - ident[9] = 1; - } - break; - } - } - } - } - break; - } - break; - } - - switch (g.type) { - case AUTH_3D_KEY_NONE: - case AUTH_3D_KEY_STATIC: - switch (a.type) { - case AUTH_3D_KEY_NONE: - case AUTH_3D_KEY_STATIC: - case AUTH_3D_KEY_LINEAR: - case AUTH_3D_KEY_HERMITE: - case AUTH_3D_KEY_HOLD: - ident[4] = 1; - ident[10] = 1; - break; - } - break; - case AUTH_3D_KEY_LINEAR: - case AUTH_3D_KEY_HERMITE: - case AUTH_3D_KEY_HOLD: - switch (a.type) { - case AUTH_3D_KEY_NONE: - case AUTH_3D_KEY_STATIC: - ident[4] = 1; - ident[10] = 1; - break; - case AUTH_3D_KEY_LINEAR: - case AUTH_3D_KEY_HERMITE: - case AUTH_3D_KEY_HOLD: - if (g.length == a.length) { - ident[4] = 1; - - kft3* keys1 = g.keys; - kft3* keys2 = a.keys; - size_t length = g.length; - for (size_t i = 0; i < length; i++) - if (*(uint32_t*)&keys1[i].frame != *(uint32_t*)&keys2[i].frame) { - ident[4] = 0; - break; - } - - if (ident[4]) { - ident[10] = 1; - - for (size_t i = 0; i < length; i++) - if (*(uint64_t*)&keys1[i].tangent1 != *(uint64_t*)&keys2[i].tangent1) { - ident[10] = 0; - break; - } - } - } - else if (g.length > a.length) { - if (a.type == AUTH_3D_KEY_LINEAR) { - kft3* keys1 = g.keys; - kft3* keys2 = a.keys; - size_t keys1_length = g.length; - size_t keys2_length = a.length; - - for (size_t i = 0; i < keys1_length; i++) { - float_t frame = keys1[i].frame; - bool found = false; - for (size_t j = 0; j < keys2_length && i < keys1_length; j++) - if (frame == keys2[j].frame) { - found = true; - break; - } - - if (!found) - if (frame <= keys2[0].frame || frame >= keys2[keys2_length - 1].frame) { - ident[4] = 1; - ident[10] = 1; - } - else - for (size_t j = 0; j + 1 < keys2_length && i < keys1_length; j++) - if (frame >= keys2[j].frame && keys2[j + 1].frame) { - if (*(uint32_t*)&keys2[j].value == *(uint32_t*)&keys2[j + 1].value) { - ident[4] = 1; - ident[10] = 1; - } - break; - } - } - } - } - else if (g.length < a.length) { - if (g.type == AUTH_3D_KEY_LINEAR) { - kft3* keys1 = a.keys; - kft3* keys2 = g.keys; - size_t keys1_length = a.length; - size_t keys2_length = g.length; - - for (size_t i = 0; i < keys1_length; i++) { - float_t frame = keys1[i].frame; - bool found = false; - for (size_t j = 0; j < keys2_length && i < keys1_length; j++) - if (frame == keys2[j].frame) { - found = true; - break; - } - - if (!found) - if (frame <= keys2[0].frame || frame >= keys2[keys2_length - 1].frame) { - ident[4] = 1; - ident[10] = 1; - } - else - for (size_t j = 0; j + 1 < keys2_length && i < keys1_length; j++) - if (frame >= keys2[j].frame && keys2[j + 1].frame) { - if (*(uint32_t*)&keys2[j].value == *(uint32_t*)&keys2[j + 1].value) { - ident[4] = 1; - ident[10] = 1; - } - break; - } - } - } - } - break; - } - break; - } - - switch (b.type) { - case AUTH_3D_KEY_NONE: - case AUTH_3D_KEY_STATIC: - switch (a.type) { - case AUTH_3D_KEY_NONE: - case AUTH_3D_KEY_STATIC: - case AUTH_3D_KEY_LINEAR: - case AUTH_3D_KEY_HERMITE: - case AUTH_3D_KEY_HOLD: - ident[5] = 1; - ident[11] = 1; - break; - } - break; - case AUTH_3D_KEY_LINEAR: - case AUTH_3D_KEY_HERMITE: - case AUTH_3D_KEY_HOLD: - switch (a.type) { - case AUTH_3D_KEY_NONE: - case AUTH_3D_KEY_STATIC: - ident[5] = 1; - ident[11] = 1; - break; - case AUTH_3D_KEY_LINEAR: - case AUTH_3D_KEY_HERMITE: - case AUTH_3D_KEY_HOLD: - if (b.length == a.length) { - ident[5] = 1; - - kft3* keys1 = b.keys; - kft3* keys2 = a.keys; - size_t length = b.length; - for (size_t i = 0; i < length; i++) - if (*(uint32_t*)&keys1[i].frame != *(uint32_t*)&keys2[i].frame) { - ident[5] = 0; - break; - } - - if (ident[5]) { - ident[11] = 1; - - for (size_t i = 0; i < length; i++) - if (*(uint64_t*)&keys1[i].tangent1 != *(uint64_t*)&keys2[i].tangent1) { - ident[11] = 0; - break; - } - } - } - else if (b.length > a.length) { - if (a.type == AUTH_3D_KEY_LINEAR) { - kft3* keys1 = b.keys; - kft3* keys2 = a.keys; - size_t keys1_length = b.length; - size_t keys2_length = a.length; - - for (size_t i = 0; i < keys1_length; i++) { - float_t frame = keys1[i].frame; - bool found = false; - for (size_t j = 0; j < keys2_length && i < keys1_length; j++) - if (frame == keys2[j].frame) { - found = true; - break; - } - - if (!found) - if (frame <= keys2[0].frame || frame >= keys2[keys2_length - 1].frame) { - ident[5] = 1; - ident[11] = 1; - } - else - for (size_t j = 0; j + 1 < keys2_length && i < keys1_length; j++) - if (frame >= keys2[j].frame && keys2[j + 1].frame) { - if (*(uint32_t*)&keys2[j].value == *(uint32_t*)&keys2[j + 1].value) { - ident[5] = 1; - ident[11] = 1; - } - break; - } - } - } - } - else if (b.length < a.length) { - if (b.type == AUTH_3D_KEY_LINEAR) { - kft3* keys1 = a.keys; - kft3* keys2 = b.keys; - size_t keys1_length = a.length; - size_t keys2_length = b.length; - - for (size_t i = 0; i < keys1_length; i++) { - float_t frame = keys1[i].frame; - bool found = false; - for (size_t j = 0; j < keys2_length && i < keys1_length; j++) - if (frame == keys2[j].frame) { - found = true; - break; - } - - if (!found) - if (frame <= keys2[0].frame || frame >= keys2[keys2_length - 1].frame) { - ident[5] = 1; - ident[11] = 1; - } - else - for (size_t j = 0; j + 1 < keys2_length && i < keys1_length; j++) - if (frame >= keys2[j].frame && keys2[j + 1].frame) { - if (*(uint32_t*)&keys2[j].value == *(uint32_t*)&keys2[j + 1].value) { - ident[5] = 1; - ident[11] = 1; - } - break; - } - } - } - } - break; - } - break; - }*/ - } - - if (mlf->flags & A3DA_MATERIAL_LIST_GLOW_INTENSITY) { - auth_3d_key_load(auth, &ml->glow_intensity, &mlf->glow_intensity); - enum_or(ml->flags, AUTH_3D_MATERIAL_LIST_GLOW_INTENSITY); - } - - if (mlf->flags & A3DA_MATERIAL_LIST_EMISSION) { - auth_3d_rgba_load(auth, &ml->emission, &mlf->emission); - enum_or(ml->flags, AUTH_3D_MATERIAL_LIST_EMISSION); - - /*auth_3d_key& r = ml->emission.r; - auth_3d_key& g = ml->emission.g; - auth_3d_key& b = ml->emission.b; - auth_3d_key& a = ml->emission.a; - - switch (r.type) { - case AUTH_3D_KEY_NONE: - case AUTH_3D_KEY_STATIC: - switch (g.type) { - case AUTH_3D_KEY_NONE: - case AUTH_3D_KEY_STATIC: - case AUTH_3D_KEY_LINEAR: - case AUTH_3D_KEY_HERMITE: - case AUTH_3D_KEY_HOLD: - ident[12] = 1; - ident[18] = 1; - break; - } - break; - case AUTH_3D_KEY_LINEAR: - case AUTH_3D_KEY_HERMITE: - case AUTH_3D_KEY_HOLD: - switch (g.type) { - case AUTH_3D_KEY_NONE: - case AUTH_3D_KEY_STATIC: - ident[12] = 1; - ident[18] = 1; - break; - case AUTH_3D_KEY_LINEAR: - case AUTH_3D_KEY_HERMITE: - case AUTH_3D_KEY_HOLD: - if (r.length == g.length) { - ident[12] = 1; - - kft3* keys1 = r.keys; - kft3* keys2 = g.keys; - size_t length = r.length; - for (size_t i = 0; i < length; i++) - if (*(uint32_t*)&keys1[i].frame != *(uint32_t*)&keys2[i].frame) { - ident[12] = 0; - break; - } - - if (ident[12]) { - ident[18] = 1; - - for (size_t i = 0; i < length; i++) - if (*(uint64_t*)&keys1[i].tangent1 != *(uint64_t*)&keys2[i].tangent1) { - ident[18] = 0; - break; - } - } - } - else if (b.length > a.length) { - if (a.type == AUTH_3D_KEY_LINEAR) { - kft3* keys1 = b.keys; - kft3* keys2 = a.keys; - size_t keys1_length = b.length; - size_t keys2_length = a.length; - - for (size_t i = 0; i < keys1_length; i++) { - float_t frame = keys1[i].frame; - bool found = false; - for (size_t j = 0; j < keys2_length && i < keys1_length; j++) - if (frame == keys2[j].frame) { - found = true; - break; - } - - if (!found) - if (frame <= keys2[0].frame || frame >= keys2[keys2_length - 1].frame) { - ident[12] = 1; - ident[18] = 1; - } - else - for (size_t j = 0; j + 1 < keys2_length && i < keys1_length; j++) - if (frame >= keys2[j].frame && keys2[j + 1].frame) { - if (*(uint32_t*)&keys2[j].value == *(uint32_t*)&keys2[j + 1].value) { - ident[12] = 1; - ident[18] = 1; - } - break; - } - } - } - } - else if (b.length < a.length) { - if (b.type == AUTH_3D_KEY_LINEAR) { - kft3* keys1 = a.keys; - kft3* keys2 = b.keys; - size_t keys1_length = a.length; - size_t keys2_length = b.length; - - for (size_t i = 0; i < keys1_length; i++) { - float_t frame = keys1[i].frame; - bool found = false; - for (size_t j = 0; j < keys2_length && i < keys1_length; j++) - if (frame == keys2[j].frame) { - found = true; - break; - } - - if (!found) - if (frame <= keys2[0].frame || frame >= keys2[keys2_length - 1].frame) { - ident[12] = 1; - ident[18] = 1; - } - else - for (size_t j = 0; j + 1 < keys2_length && i < keys1_length; j++) - if (frame >= keys2[j].frame && keys2[j + 1].frame) { - if (*(uint32_t*)&keys2[j].value == *(uint32_t*)&keys2[j + 1].value) { - ident[12] = 1; - ident[18] = 1; - } - break; - } - } - } - } - break; - } - break; - } - - switch (r.type) { - case AUTH_3D_KEY_NONE: - case AUTH_3D_KEY_STATIC: - switch (b.type) { - case AUTH_3D_KEY_NONE: - case AUTH_3D_KEY_STATIC: - case AUTH_3D_KEY_LINEAR: - case AUTH_3D_KEY_HERMITE: - case AUTH_3D_KEY_HOLD: - ident[13] = 1; - ident[19] = 1; - break; - } - break; - case AUTH_3D_KEY_LINEAR: - case AUTH_3D_KEY_HERMITE: - case AUTH_3D_KEY_HOLD: - switch (b.type) { - case AUTH_3D_KEY_NONE: - case AUTH_3D_KEY_STATIC: - ident[13] = 1; - ident[19] = 1; - break; - case AUTH_3D_KEY_LINEAR: - case AUTH_3D_KEY_HERMITE: - case AUTH_3D_KEY_HOLD: - if (r.length == b.length) { - ident[13] = 1; - - kft3* keys1 = r.keys; - kft3* keys2 = b.keys; - size_t length = r.length; - for (size_t i = 0; i < length; i++) - if (*(uint32_t*)&keys1[i].frame != *(uint32_t*)&keys2[i].frame) { - ident[13] = 0; - break; - } - - if (ident[13]) { - ident[19] = 1; - - for (size_t i = 0; i < length; i++) - if (*(uint64_t*)&keys1[i].tangent1 != *(uint64_t*)&keys2[i].tangent1) { - ident[19] = 0; - break; - } - } - } - else if (r.length > b.length) { - if (b.type == AUTH_3D_KEY_LINEAR) { - kft3* keys1 = r.keys; - kft3* keys2 = b.keys; - size_t keys1_length = r.length; - size_t keys2_length = b.length; - - for (size_t i = 0; i < keys1_length; i++) { - float_t frame = keys1[i].frame; - bool found = false; - for (size_t j = 0; j < keys2_length && i < keys1_length; j++) - if (frame == keys2[j].frame) { - found = true; - break; - } - - if (!found) - if (frame <= keys2[0].frame || frame >= keys2[keys2_length - 1].frame) { - ident[13] = 1; - ident[19] = 1; - } - else - for (size_t j = 0; j + 1 < keys2_length && i < keys1_length; j++) - if (frame >= keys2[j].frame && keys2[j + 1].frame) { - if (*(uint32_t*)&keys2[j].value == *(uint32_t*)&keys2[j + 1].value) { - ident[13] = 1; - ident[19] = 1; - } - break; - } - } - } - } - else if (r.length < b.length) { - if (r.type == AUTH_3D_KEY_LINEAR) { - kft3* keys1 = b.keys; - kft3* keys2 = r.keys; - size_t keys1_length = b.length; - size_t keys2_length = r.length; - - for (size_t i = 0; i < keys1_length; i++) { - float_t frame = keys1[i].frame; - bool found = false; - for (size_t j = 0; j < keys2_length && i < keys1_length; j++) - if (frame == keys2[j].frame) { - found = true; - break; - } - - if (!found) - if (frame <= keys2[0].frame || frame >= keys2[keys2_length - 1].frame) { - ident[13] = 1; - ident[19] = 1; - } - else - for (size_t j = 0; j + 1 < keys2_length && i < keys1_length; j++) - if (frame >= keys2[j].frame && keys2[j + 1].frame) { - if (*(uint32_t*)&keys2[j].value == *(uint32_t*)&keys2[j + 1].value) { - ident[13] = 1; - ident[19] = 1; - } - break; - } - } - } - } - break; - } - break; - } - - switch (r.type) { - case AUTH_3D_KEY_NONE: - case AUTH_3D_KEY_STATIC: - switch (a.type) { - case AUTH_3D_KEY_NONE: - case AUTH_3D_KEY_STATIC: - case AUTH_3D_KEY_LINEAR: - case AUTH_3D_KEY_HERMITE: - case AUTH_3D_KEY_HOLD: - ident[14] = 1; - ident[20] = 1; - break; - } - break; - case AUTH_3D_KEY_LINEAR: - case AUTH_3D_KEY_HERMITE: - case AUTH_3D_KEY_HOLD: - switch (a.type) { - case AUTH_3D_KEY_NONE: - case AUTH_3D_KEY_STATIC: - ident[14] = 1; - ident[20] = 1; - break; - case AUTH_3D_KEY_LINEAR: - case AUTH_3D_KEY_HERMITE: - case AUTH_3D_KEY_HOLD: - if (r.length == a.length) { - ident[14] = 1; - - kft3* keys1 = r.keys; - kft3* keys2 = a.keys; - size_t length = r.length; - for (size_t i = 0; i < length; i++) - if (*(uint32_t*)&keys1[i].frame != *(uint32_t*)&keys2[i].frame) { - ident[14] = 0; - break; - } - - if (ident[14]) { - ident[20] = 1; - - for (size_t i = 0; i < length; i++) - if (*(uint64_t*)&keys1[i].tangent1 != *(uint64_t*)&keys2[i].tangent1) { - ident[20] = 0; - break; - } - } - } - else if (r.length > a.length) { - if (a.type == AUTH_3D_KEY_LINEAR) { - kft3* keys1 = r.keys; - kft3* keys2 = a.keys; - size_t keys1_length = r.length; - size_t keys2_length = a.length; - - for (size_t i = 0; i < keys1_length; i++) { - float_t frame = keys1[i].frame; - bool found = false; - for (size_t j = 0; j < keys2_length && i < keys1_length; j++) - if (frame == keys2[j].frame) { - found = true; - break; - } - - if (!found) - if (frame <= keys2[0].frame || frame >= keys2[keys2_length - 1].frame) { - ident[14] = 1; - ident[20] = 1; - } - else - for (size_t j = 0; j + 1 < keys2_length && i < keys1_length; j++) - if (frame >= keys2[j].frame && keys2[j + 1].frame) { - if (*(uint32_t*)&keys2[j].value == *(uint32_t*)&keys2[j + 1].value) { - ident[14] = 1; - ident[20] = 1; - } - break; - } - } - } - } - else if (r.length < a.length) { - if (b.type == AUTH_3D_KEY_LINEAR) { - kft3* keys1 = a.keys; - kft3* keys2 = r.keys; - size_t keys1_length = a.length; - size_t keys2_length = r.length; - - for (size_t i = 0; i < keys1_length; i++) { - float_t frame = keys1[i].frame; - bool found = false; - for (size_t j = 0; j < keys2_length && i < keys1_length; j++) - if (frame == keys2[j].frame) { - found = true; - break; - } - - if (!found) - if (frame <= keys2[0].frame || frame >= keys2[keys2_length - 1].frame) { - ident[14] = 1; - ident[20] = 1; - } - else - for (size_t j = 0; j + 1 < keys2_length && i < keys1_length; j++) - if (frame >= keys2[j].frame && keys2[j + 1].frame) { - if (*(uint32_t*)&keys2[j].value == *(uint32_t*)&keys2[j + 1].value) { - ident[14] = 1; - ident[20] = 1; - } - break; - } - } - } - } - break; - } - break; - } - - switch (g.type) { - case AUTH_3D_KEY_NONE: - case AUTH_3D_KEY_STATIC: - switch (b.type) { - case AUTH_3D_KEY_NONE: - case AUTH_3D_KEY_STATIC: - ident[15] = 1; - ident[21] = 1; - break; - } - break; - case AUTH_3D_KEY_LINEAR: - case AUTH_3D_KEY_HERMITE: - case AUTH_3D_KEY_HOLD: - switch (b.type) { - case AUTH_3D_KEY_NONE: - case AUTH_3D_KEY_STATIC: - ident[15] = 1; - ident[21] = 1; - break; - case AUTH_3D_KEY_LINEAR: - case AUTH_3D_KEY_HERMITE: - case AUTH_3D_KEY_HOLD: - if (g.length == b.length) { - ident[15] = 1; - - kft3* keys1 = g.keys; - kft3* keys2 = b.keys; - size_t length = g.length; - for (size_t i = 0; i < length; i++) - if (*(uint32_t*)&keys1[i].frame != *(uint32_t*)&keys2[i].frame) { - ident[15] = 0; - break; - } - - if (ident[15]) { - ident[21] = 1; - - for (size_t i = 0; i < length; i++) - if (*(uint64_t*)&keys1[i].tangent1 != *(uint64_t*)&keys2[i].tangent1) { - ident[21] = 0; - break; - } - } - } - else if (g.length > b.length) { - if (b.type == AUTH_3D_KEY_LINEAR) { - kft3* keys1 = g.keys; - kft3* keys2 = b.keys; - size_t keys1_length = g.length; - size_t keys2_length = b.length; - - for (size_t i = 0; i < keys1_length; i++) { - float_t frame = keys1[i].frame; - bool found = false; - for (size_t j = 0; j < keys2_length && i < keys1_length; j++) - if (frame == keys2[j].frame) { - found = true; - break; - } - - if (!found) - if (frame <= keys2[0].frame || frame >= keys2[keys2_length - 1].frame) { - ident[15] = 1; - ident[21] = 1; - } - else - for (size_t j = 0; j + 1 < keys2_length && i < keys1_length; j++) - if (frame >= keys2[j].frame && keys2[j + 1].frame) { - if (*(uint32_t*)&keys2[j].value == *(uint32_t*)&keys2[j + 1].value) { - ident[15] = 1; - ident[21] = 1; - } - break; - } - } - } - } - else if (g.length < b.length) { - if (g.type == AUTH_3D_KEY_LINEAR) { - kft3* keys1 = b.keys; - kft3* keys2 = g.keys; - size_t keys1_length = b.length; - size_t keys2_length = g.length; - - for (size_t i = 0; i < keys1_length; i++) { - float_t frame = keys1[i].frame; - bool found = false; - for (size_t j = 0; j < keys2_length && i < keys1_length; j++) - if (frame == keys2[j].frame) { - found = true; - break; - } - - if (!found) - if (frame <= keys2[0].frame || frame >= keys2[keys2_length - 1].frame) { - ident[15] = 1; - ident[21] = 1; - } - else - for (size_t j = 0; j + 1 < keys2_length && i < keys1_length; j++) - if (frame >= keys2[j].frame && keys2[j + 1].frame) { - if (*(uint32_t*)&keys2[j].value == *(uint32_t*)&keys2[j + 1].value) { - ident[15] = 1; - ident[21] = 1; - } - break; - } - } - } - } - break; - } - break; - } - - switch (g.type) { - case AUTH_3D_KEY_NONE: - case AUTH_3D_KEY_STATIC: - switch (a.type) { - case AUTH_3D_KEY_NONE: - case AUTH_3D_KEY_STATIC: - ident[16] = 1; - ident[22] = 1; - break; - } - break; - case AUTH_3D_KEY_LINEAR: - case AUTH_3D_KEY_HERMITE: - case AUTH_3D_KEY_HOLD: - switch (a.type) { - case AUTH_3D_KEY_NONE: - case AUTH_3D_KEY_STATIC: - ident[16] = 1; - ident[22] = 1; - break; - case AUTH_3D_KEY_LINEAR: - case AUTH_3D_KEY_HERMITE: - case AUTH_3D_KEY_HOLD: - if (g.length == a.length) { - ident[16] = 1; - - kft3* keys1 = g.keys; - kft3* keys2 = a.keys; - size_t length = g.length; - for (size_t i = 0; i < length; i++) - if (*(uint32_t*)&keys1[i].frame != *(uint32_t*)&keys2[i].frame) { - ident[16] = 0; - break; - } - - if (ident[16]) { - ident[22] = 1; - - for (size_t i = 0; i < length; i++) - if (*(uint64_t*)&keys1[i].tangent1 != *(uint64_t*)&keys2[i].tangent1) { - ident[22] = 0; - break; - } - } - } - else if (g.length > a.length) { - if (a.type == AUTH_3D_KEY_LINEAR) { - kft3* keys1 = g.keys; - kft3* keys2 = a.keys; - size_t keys1_length = g.length; - size_t keys2_length = a.length; - - for (size_t i = 0; i < keys1_length; i++) { - float_t frame = keys1[i].frame; - bool found = false; - for (size_t j = 0; j < keys2_length && i < keys1_length; j++) - if (frame == keys2[j].frame) { - found = true; - break; - } - - if (!found) - if (frame <= keys2[0].frame || frame >= keys2[keys2_length - 1].frame) { - ident[16] = 1; - ident[22] = 1; - } - else - for (size_t j = 0; j + 1 < keys2_length && i < keys1_length; j++) - if (frame >= keys2[j].frame && keys2[j + 1].frame) { - if (*(uint32_t*)&keys2[j].value == *(uint32_t*)&keys2[j + 1].value) { - ident[16] = 1; - ident[22] = 1; - } - break; - } - } - } - } - else if (g.length < a.length) { - if (g.type == AUTH_3D_KEY_LINEAR) { - kft3* keys1 = a.keys; - kft3* keys2 = g.keys; - size_t keys1_length = a.length; - size_t keys2_length = g.length; - - for (size_t i = 0; i < keys1_length; i++) { - float_t frame = keys1[i].frame; - bool found = false; - for (size_t j = 0; j < keys2_length && i < keys1_length; j++) - if (frame == keys2[j].frame) { - found = true; - break; - } - - if (!found) - if (frame <= keys2[0].frame || frame >= keys2[keys2_length - 1].frame) { - ident[16] = 1; - ident[22] = 1; - } - else - for (size_t j = 0; j + 1 < keys2_length && i < keys1_length; j++) - if (frame >= keys2[j].frame && keys2[j + 1].frame) { - if (*(uint32_t*)&keys2[j].value == *(uint32_t*)&keys2[j + 1].value) { - ident[16] = 1; - ident[22] = 1; - } - break; - } - } - } - } - break; - } - break; - } - - switch (b.type) { - case AUTH_3D_KEY_NONE: - case AUTH_3D_KEY_STATIC: - switch (a.type) { - case AUTH_3D_KEY_NONE: - case AUTH_3D_KEY_STATIC: - case AUTH_3D_KEY_LINEAR: - case AUTH_3D_KEY_HERMITE: - case AUTH_3D_KEY_HOLD: - ident[17] = 1; - ident[23] = 1; - break; - } - break; - case AUTH_3D_KEY_LINEAR: - case AUTH_3D_KEY_HERMITE: - case AUTH_3D_KEY_HOLD: - switch (a.type) { - case AUTH_3D_KEY_NONE: - case AUTH_3D_KEY_STATIC: - ident[17] = 1; - ident[23] = 1; - break; - case AUTH_3D_KEY_LINEAR: - case AUTH_3D_KEY_HERMITE: - case AUTH_3D_KEY_HOLD: - if (b.length == a.length) { - ident[17] = 1; - - kft3* keys1 = b.keys; - kft3* keys2 = a.keys; - size_t length = b.length; - for (size_t i = 0; i < length; i++) - if (*(uint32_t*)&keys1[i].frame != *(uint32_t*)&keys2[i].frame) { - ident[17] = 0; - break; - } - - if (ident[17]) { - ident[23] = 1; - - for (size_t i = 0; i < length; i++) - if (*(uint64_t*)&keys1[i].tangent1 != *(uint64_t*)&keys2[i].tangent1) { - ident[23] = 0; - break; - } - } - } - else if (b.length > a.length) { - if (a.type == AUTH_3D_KEY_LINEAR) { - kft3* keys1 = b.keys; - kft3* keys2 = a.keys; - size_t keys1_length = b.length; - size_t keys2_length = a.length; - - for (size_t i = 0; i < keys1_length; i++) { - float_t frame = keys1[i].frame; - bool found = false; - for (size_t j = 0; j < keys2_length && i < keys1_length; j++) - if (frame == keys2[j].frame) { - found = true; - break; - } - - if (!found) - if (frame <= keys2[0].frame || frame >= keys2[keys2_length - 1].frame) { - ident[17] = 1; - ident[23] = 1; - } - else - for (size_t j = 0; j + 1 < keys2_length && i < keys1_length; j++) - if (frame >= keys2[j].frame && keys2[j + 1].frame) { - if (*(uint32_t*)&keys2[j].value == *(uint32_t*)&keys2[j + 1].value) { - ident[17] = 1; - ident[23] = 1; - } - break; - } - } - } - } - else if (b.length < a.length) { - if (b.type == AUTH_3D_KEY_LINEAR) { - kft3* keys1 = a.keys; - kft3* keys2 = b.keys; - size_t keys1_length = a.length; - size_t keys2_length = b.length; - - for (size_t i = 0; i < keys1_length; i++) { - float_t frame = keys1[i].frame; - bool found = false; - for (size_t j = 0; j < keys2_length && i < keys1_length; j++) - if (frame == keys2[j].frame) { - found = true; - break; - } - - if (!found) - if (frame <= keys2[0].frame || frame >= keys2[keys2_length - 1].frame) { - ident[17] = 1; - ident[23] = 1; - } - else - for (size_t j = 0; j + 1 < keys2_length && i < keys1_length; j++) - if (frame >= keys2[j].frame && keys2[j + 1].frame) { - if (*(uint32_t*)&keys2[j].value == *(uint32_t*)&keys2[j + 1].value) { - ident[17] = 1; - ident[23] = 1; - } - break; - } - } - } - } - break; - } - break; - }*/ - } - - /*OutputDebugStringA(auth->file_name.c_str()); - OutputDebugStringA("\n"); - OutputDebugStringA(mlf->name.c_str()); - OutputDebugStringA("\n"); - - if (ml->flags & AUTH_3D_MATERIAL_LIST_BLEND_COLOR) { - if ((ident[0] || ident[1] || ident[2] || ident[4] || ident[5] || ident[6]) - && (!ident[0] || !ident[1] || !ident[2] || !ident[4] || !ident[5] || !ident[6])) - OutputDebugStringA("A\n"); - if (!(ident[0] || ident[1] || ident[2] || ident[3] || ident[4] || ident[5])) - OutputDebugStringA("B\n"); - if (ident[0] || ident[1] || ident[2] || ident[3] || ident[4] || ident[5]) { - if ((ident[6] || ident[7] || ident[8] || ident[9] || ident[10] || ident[11]) - && (!ident[6] || !ident[7] || !ident[8] || !ident[9] || !ident[10] || !ident[11])) - OutputDebugStringA("C\n"); - if (!(ident[6] || ident[7] || ident[8] || ident[9] || ident[10] || ident[11])) - OutputDebugStringA("D\n"); - } - } - - if (ml->flags & AUTH_3D_MATERIAL_LIST_EMISSION) { - if ((ident[12] || ident[13] || ident[14] || ident[15] || ident[16] || ident[17]) - && (!ident[12] || !ident[13] || !ident[14] || !ident[15] || !ident[16] || !ident[17])) - OutputDebugStringA("E\n"); - if (!(ident[12] || ident[13] || ident[14] || ident[15] || ident[16] || ident[17])) - OutputDebugStringA("F\n"); - if (ident[12] || ident[13] || ident[14] || ident[15] || ident[16] || ident[17]) { - if ((ident[18] || ident[19] || ident[20] || ident[21] || ident[22] || ident[23]) - && (!ident[18] || !ident[19] || !ident[20] || !ident[21] || !ident[22] || !ident[23])) - OutputDebugStringA("G\n"); - if (!(ident[18] || ident[19] || ident[20] || ident[21] || ident[22] || ident[23])) - OutputDebugStringA("H\n"); - } - }*/ - - ml->name.assign(mlf->name); - ml->hash = hash_string_murmurhash(ml->name); - - /*char buf[0x200]; - sprintf_s(buf, sizeof(buf), "\n%d %d %d %d %d %d %d %d %d %d %d %d\n" - "%d %d %d %d %d %d %d %d %d %d %d %d\n\n", - ident[0], ident[1], ident[2], - ident[3], ident[4], ident[5], - ident[6], ident[7], ident[8], - ident[9], ident[10], ident[11], - ident[12], ident[13], ident[14], - ident[15], ident[16], ident[17], - ident[18], ident[19], ident[20], - ident[21], ident[22], ident[23]); - OutputDebugStringA(buf);*/ -} - -static void auth_3d_material_list_store(auth_3d* auth, auth_3d_material_list* ml, auth_3d_material_list_file* mlf) { - if (ml->flags & AUTH_3D_MATERIAL_LIST_BLEND_COLOR) { - auth_3d_rgba_store(auth, &ml->blend_color, &mlf->blend_color); - enum_or(mlf->flags, A3DA_MATERIAL_LIST_BLEND_COLOR); - } - - if (ml->flags & AUTH_3D_MATERIAL_LIST_GLOW_INTENSITY) { - auth_3d_key_store(auth, &ml->glow_intensity, &mlf->glow_intensity); - enum_or(mlf->flags, A3DA_MATERIAL_LIST_GLOW_INTENSITY); - } - - if (ml->flags & AUTH_3D_MATERIAL_LIST_EMISSION) { - auth_3d_rgba_store(auth, &ml->emission, &mlf->emission); - enum_or(mlf->flags, A3DA_MATERIAL_LIST_EMISSION); - } - - mlf->name.assign(ml->name); -} - -static void auth_3d_object_disp(auth_3d_object* o, auth_3d* auth, render_context* rctx) { - if (!o->model_transform.visible) - return; - - if (!auth->visible) { - if (auth->pos) - debug_put_line_axis(o->model_transform.mat); - - for (auth_3d_object*& i : o->children_object) - auth_3d_object_disp(i, auth, rctx); - for (auth_3d_object_hrc*& i : o->children_object_hrc) - auth_3d_object_hrc_disp(i, auth, rctx); - return; - } - - mat4 mat = o->model_transform.mat; - - mdl::DispManager& disp_manager = *rctx->disp_manager; - object_database* obj_db = auth->obj_db; - texture_database* tex_db = auth->tex_db; - - if (auth->rob_id >= 0 && auth->rob_id < ROB_ID_MAX) { - RobManagement* rob_man = get_rob_management(); - if (rob_man->is_init((ROB_ID)auth->rob_id)) { - rob_chara* rob_chr = rob_man->get_rob((ROB_ID)auth->rob_id); - mat4 m; - mat4_mul(&rob_chr->rob_base.position.rob_mat, - auth->chara_item - ? &rob_chr->rob_base.adjust.item_mat - : &rob_chr->rob_base.adjust.mat, &m); - mat4_mul(&mat, &m, &mat); - disp_manager.set_shadow_group(auth->rob_id ? SHADOW_GROUP_STAGE : SHADOW_GROUP_CHARA); - } - } - - mdl::ObjFlags flags = (mdl::ObjFlags)0; - if (auth->shadow) - enum_or(flags, mdl::OBJ_4 | mdl::OBJ_SHADOW); - if (o->reflect) - enum_or(flags, mdl::OBJ_NO_TRANSLUCENCY | mdl::OBJ_REFLECT); - if (o->refract) - enum_or(flags, mdl::OBJ_NO_TRANSLUCENCY | mdl::OBJ_REFRACT); - - disp_manager.set_obj_flags(flags); - - char buf[0x80]; - int32_t tex_pat_count = 0; - TexChange tex_pat[TEXTURE_PATTERN_COUNT]; - - for (auth_3d_object_texture_pattern& i : o->texture_pattern) { - if (!i.pattern.curve || i.name.size() <= 3) - continue; - else if (tex_pat_count >= TEXTURE_PATTERN_COUNT) - break; - - sprintf_s(buf, sizeof(buf), "%.*s%03d", - (int32_t)(i.name.size() - 3), i.name.c_str(), (int32_t)prj::roundf(i.pattern.value)); - - tex_pat[tex_pat_count].org_texid = texture_id(0x00, i.texture_id); - tex_pat[tex_pat_count].change_texid = texture_id(0x00, tex_db->get_texture_id(buf)); - tex_pat_count++; - } - - if (tex_pat_count) - disp_manager.set_texture_pattern(tex_pat_count, tex_pat); - - int32_t tex_trans_count = 0; - texture_transform_struct tex_trans[TEXTURE_TRANSFORM_COUNT]; - - for (auth_3d_object_texture_transform& i : o->texture_transform) { - if (tex_trans_count >= TEXTURE_TRANSFORM_COUNT || i.texture_id == -1 - || !texture_manager_get_texture(i.texture_id)) - continue; - - tex_trans[tex_trans_count].texid = i.texture_id; - tex_trans[tex_trans_count].mat = i.mat; - tex_trans_count++; - } - - if (tex_trans_count) - disp_manager.set_texture_transform(tex_trans_count, tex_trans); - - const char* uid_name = o->uid_name.c_str(); - int32_t uid_name_length = (int32_t)o->uid_name.size(); - - if (uid_name_length <= 3) - disp_manager.entry_obj_by_object_info(mat, o->object_info); - else if (o->morph.curve) { - float_t morph = o->morph.value; - int32_t morph_int = (int32_t)morph; - morph = fmodf(morph, 1.0f); - if (morph > 0.0f && morph < 1.0f) { - sprintf_s(buf, sizeof(buf), "%.*s%03d", uid_name_length - 3, uid_name, morph_int + 1); - object_info morph_obj_info = obj_db->get_object_info(buf); - if (morph_obj_info.is_null()) - morph_obj_info = o->object_info; - disp_manager.set_morph(morph_obj_info, morph); - - sprintf_s(buf, sizeof(buf), "%.*s%03d", uid_name_length - 3, uid_name, morph_int); - object_info obj_info = obj_db->get_object_info(buf); - if (auth->alpha < 0.999f) - disp_manager.entry_obj_by_object_info(mat, obj_info, auth->alpha); - else - disp_manager.entry_obj_by_object_info(mat, obj_info); - disp_manager.set_morph({}, 0.0f); - } - else { - if (morph >= 1.0f) - morph_int++; - - sprintf_s(buf, sizeof(buf), "%.*s%03d", uid_name_length - 3, uid_name, morph_int); - object_info obj_info = obj_db->get_object_info(buf); - if (obj_info.is_null()) - obj_info = o->object_info; - disp_manager.entry_obj_by_object_info(mat, obj_info); - } - } - else if (o->pattern.curve) { - sprintf_s(buf, sizeof(buf), "%.*s%03d", - uid_name_length - 3, uid_name, (int32_t)prj::roundf(o->pattern.value)); - object_info obj_info = obj_db->get_object_info(buf); - disp_manager.entry_obj_by_object_info(mat, obj_info); - } - else - disp_manager.entry_obj_by_object_info(mat, o->object_info); - - disp_manager.set_texture_transform(); - disp_manager.set_texture_pattern(); - disp_manager.set_obj_flags(); - - if (auth->pos) - debug_put_line_axis(o->model_transform.mat); - - for (auth_3d_object*& i : o->children_object) - auth_3d_object_disp(i, auth, rctx); - for (auth_3d_object_hrc*& i : o->children_object_hrc) - auth_3d_object_hrc_disp(i, auth, rctx); -} - -static void auth_3d_object_load(auth_3d* auth, auth_3d_object* o, - auth_3d_object_file* of, object_database* obj_db, texture_database* tex_db) { - auth_3d_model_transform_load(auth, &o->model_transform, &of->model_transform); - auth_3d_object_curve_load(auth, &o->morph, of->morph, of->morph_offset); - o->name.assign(of->name); - o->parent_name.assign(of->parent_name); - o->parent_node.assign(of->parent_node); - auth_3d_object_curve_load(auth, &o->pattern, of->pattern, of->pattern_offset); - - size_t texture_pattern_index = 0; - o->texture_pattern.resize(of->texture_pattern.size()); - for (auth_3d_object_texture_pattern_file& i : of->texture_pattern) - auth_3d_object_texture_pattern_load(auth, - &o->texture_pattern[texture_pattern_index++], &i, tex_db); - - size_t texture_transform_index = 0; - o->texture_transform.resize(of->texture_transform.size()); - for (auth_3d_object_texture_transform_file& i : of->texture_transform) - auth_3d_object_texture_transform_load(auth, - &o->texture_transform[texture_transform_index++], &i, tex_db); - - o->uid_name.assign(of->uid_name); - - o->reflect = strstr(o->uid_name.c_str(), "_REFLECT") ? true : false; - o->refract = strstr(o->uid_name.c_str(), "_REFRACT") ? true : false; - - o->object_info = obj_db->get_object_info(o->uid_name.c_str()); - o->object_hash = hash_string_murmurhash(o->uid_name); - - if (!of->morph.size() || !o->morph.curve || o->morph.curve->curve.keys_vec.size() < 2) - return; - - auth_3d_object_curve* oc = &o->morph; - - float_t min_value = FLT_MAX; - float_t max_value = -FLT_MAX; - - float_t first_frame = oc->curve->curve.keys_vec.front().frame; - float_t last_frame = oc->curve->curve.keys_vec.back().frame; - for (float_t i = first_frame; i <= last_frame; i += 1.0f) { - oc->interpolate(i); - min_value = fminf(min_value, oc->value); - max_value = fmaxf(max_value, oc->value); - } - oc->interpolate(0.0f); - - int32_t min = (int32_t)prj::floorf(min_value); - int32_t max = (int32_t)prj::ceilf(max_value); - if (min >= max) - return; - - const char* uid_name = o->uid_name.c_str(); - int32_t uid_name_length = (int32_t)o->uid_name.size(); - - char buf[0x80]; - for (int32_t i = min; i < max; i++) { - sprintf_s(buf, sizeof(buf), "%.*s%03d", uid_name_length - 3, uid_name, i + 1); - object_info morph_obj_info = obj_db->get_object_info(buf); - if (morph_obj_info.is_null()) - morph_obj_info = o->object_info; - - sprintf_s(buf, sizeof(buf), "%.*s%03d", uid_name_length - 3, uid_name, i); - object_info obj_info = obj_db->get_object_info(buf); - - ::obj* obj = objset_info_storage_get_obj(obj_info); - if (!obj) - continue; - - obj_mesh_vertex_buffer* obj_vert_buf = objset_info_storage_get_obj_mesh_vertex_buffer(obj_info); - obj_mesh_index_buffer* obj_index_buf = objset_info_storage_get_obj_mesh_index_buffer(obj_info); - - obj_mesh_vertex_buffer* obj_morph_vert_buf = 0; - if (morph_obj_info.set_id != -1) - obj_morph_vert_buf = objset_info_storage_get_obj_mesh_vertex_buffer(morph_obj_info); - - for (int32_t i = 0; i < obj->num_mesh; i++) { - const obj_mesh* mesh = &obj->mesh_array[i]; - for (int32_t j = 0; j < mesh->num_submesh; j++) { - const obj_sub_mesh* sub_mesh = &mesh->submesh_array[j]; - if (sub_mesh->attrib.m.cloth) - continue; - - obj_material_data* material = &obj->material_array[sub_mesh->material_index]; - - GLuint morph_vertex_buffer = 0; - size_t morph_vertex_buffer_offset = 0; - if (obj_morph_vert_buf) { - morph_vertex_buffer = obj_morph_vert_buf[i].get_buffer(); - morph_vertex_buffer_offset = obj_morph_vert_buf[i].get_offset(); - } - - GLuint index_buffer = 0; - if (obj_index_buf) - index_buffer = obj_index_buf[i].buffer; - - GLuint vertex_buffer = 0; - size_t vertex_buffer_offset = 0; - if (obj_vert_buf) { - vertex_buffer = obj_vert_buf[i].get_buffer(); - vertex_buffer_offset = obj_vert_buf[i].get_offset(); - } - - if (vertex_buffer && index_buffer && (!obj_morph_vert_buf || morph_vertex_buffer)) - rctx_ptr->disp_manager->add_vertex_array(mesh, sub_mesh, material, vertex_buffer, - vertex_buffer_offset, index_buffer, morph_vertex_buffer, morph_vertex_buffer_offset); - } - } - } -} - -static void auth_3d_object_store(auth_3d* auth, auth_3d_object* o, - auth_3d_object_file* of) { - auth_3d_model_transform_store(auth, &o->model_transform, &of->model_transform); - auth_3d_object_curve_store(auth, &o->morph, of->morph, of->morph_offset); - of->name.assign(o->name); - of->parent_name.assign(o->parent_name); - of->parent_node.assign(o->parent_node); - auth_3d_object_curve_store(auth, &o->pattern, of->pattern, of->pattern_offset); - - size_t texture_pattern_index = 0; - of->texture_pattern.resize(o->texture_pattern.size()); - for (auth_3d_object_texture_pattern& i : o->texture_pattern) - auth_3d_object_texture_pattern_store(auth, - &i, &of->texture_pattern[texture_pattern_index++]); - - size_t texture_transform_index = 0; - of->texture_transform.resize(o->texture_transform.size()); - for (auth_3d_object_texture_transform& i : o->texture_transform) - auth_3d_object_texture_transform_store(auth, - &i, &of->texture_transform[texture_transform_index++]); - - of->uid_name.assign(o->uid_name); -} - -static void auth_3d_object_curve_load(auth_3d* auth, auth_3d_object_curve* oc, - std::string& name, float_t frame_offset) { - if (!name.size()) - return; - - oc->curve = 0; - oc->name.assign(name); - oc->frame_offset = 0.0f; - oc->value = 0.0f; - - for (auth_3d_curve& i : auth->curve) - if (!oc->name.compare(i.name)) { - oc->curve = &i; - oc->frame_offset = frame_offset; - break; - } -} - -static void auth_3d_object_curve_store(auth_3d* auth, auth_3d_object_curve* oc, - std::string& name, float_t& frame_offset) { - name.assign(oc->name); - frame_offset = oc->frame_offset; -} - -static void auth_3d_object_hrc_disp(auth_3d_object_hrc* oh, auth_3d* auth, render_context* rctx) { - if (!auth->visible || !oh->node.front().model_transform.visible) - return; - - mdl::DispManager& disp_manager = *rctx->disp_manager; - object_database* obj_db = auth->obj_db; - texture_database* tex_db = auth->tex_db; - - mdl::ObjFlags flags = mdl::OBJ_SSS; - if (auth->shadow | oh->shadow) - enum_or(flags, mdl::OBJ_4 | mdl::OBJ_SHADOW); - if (oh->reflect) - enum_or(flags, mdl::OBJ_NO_TRANSLUCENCY | mdl::OBJ_REFLECT); - if (oh->refract) - enum_or(flags, mdl::OBJ_NO_TRANSLUCENCY | mdl::OBJ_REFRACT); - if (auth->alpha < 1.0f) - enum_or(flags, auth->obj_flags); - - disp_manager.set_obj_flags(flags); - disp_manager.set_shadow_group(SHADOW_GROUP_CHARA); - - mat4 mat = mat4_identity; - if (auth->rob_id >= 0 && auth->rob_id < ROB_ID_MAX) { - RobManagement* rob_man = get_rob_management(); - if (rob_man->is_init((ROB_ID)auth->rob_id)) { - rob_chara* rob_chr = rob_man->get_rob((ROB_ID)auth->rob_id); - mat4_mul(&rob_chr->rob_base.position.rob_mat, - auth->chara_item - ? &rob_chr->rob_base.adjust.item_mat - : &rob_chr->rob_base.adjust.mat, &mat); - if (auth->rob_id) - disp_manager.set_shadow_group(SHADOW_GROUP_STAGE); - } - } - else if (flags & mdl::OBJ_SHADOW) { - disp_manager.set_shadow_group(SHADOW_GROUP_STAGE); - - mat4 mat = oh->node.front().model_transform.mat; - for (auth_3d_object_node& i : oh->node) - if (i.mat) { - mat = *i.mat; - break; - } - - Shadow* shad = shadow_ptr_get(); - if (shad) { - vec3 pos; - mat4_get_translation(&mat, &pos); - pos.y -= 0.2f; - shad->positions[SHADOW_GROUP_STAGE].push_back(pos); - } - } - - if (oh->mats.size()) - disp_manager.entry_obj_by_object_info_object_skin( - oh->object_info, 0, 0, auth->alpha, oh->mats.data(), 0, 0, mat); - - disp_manager.set_obj_flags(); - disp_manager.set_shadow_group(SHADOW_GROUP_CHARA); - - for (auth_3d_object*& i : oh->children_object) - auth_3d_object_disp(i, auth, rctx); - - for (auth_3d_object_hrc*& i : oh->children_object_hrc) - auth_3d_object_hrc_disp(i, auth, rctx); -} - -static void auth_3d_object_hrc_load(auth_3d* auth, auth_3d_object_hrc* oh, - auth_3d_object_hrc_file* ohf, object_database* obj_db) { - oh->name.assign(ohf->name); - - size_t node_index = 0; - oh->node.resize(ohf->node.size()); - for (auth_3d_object_node_file& i : ohf->node) - auth_3d_object_node_load(auth, - &oh->node[node_index++], &i); - - oh->parent_name.assign(ohf->parent_name); - oh->parent_node.assign(ohf->parent_node); - oh->shadow = ohf->shadow; - oh->uid_name.assign(ohf->uid_name); - - oh->reflect = strstr(oh->uid_name.c_str(), "_REFLECT") ? true : false; - oh->refract = strstr(oh->uid_name.c_str(), "_REFRACT") ? true : false; - - oh->object_info = obj_db->get_object_info(oh->uid_name.c_str()); - oh->object_hash = hash_string_murmurhash(oh->uid_name); - - obj_skin* skin = objset_info_storage_get_obj_skin(oh->object_info); - if (!skin) - return; - - oh->mats.resize(skin->num_bone); - mat4* mats = oh->mats.data(); - - for (auth_3d_object_node& i : oh->node) { - i.bone_id = -1; - uint64_t name_hash = hash_string_xxh3_64bits(i.name); - for (int32_t j = 0; j < skin->num_bone; j++) - if (hash_utf8_xxh3_64bits(skin->bone_array[j].name) == name_hash) { - i.bone_id = skin->bone_array[j].id; - break; - } - - if (i.bone_id > -1 && !(i.bone_id & 0x8000)) - i.mat = &mats[i.bone_id]; - } -} - -static void auth_3d_object_hrc_store(auth_3d* auth, auth_3d_object_hrc* oh, - auth_3d_object_hrc_file* ohf) { - ohf->name.assign(oh->name); - - size_t node_index = 0; - ohf->node.resize(oh->node.size()); - for (auth_3d_object_node& i : oh->node) - auth_3d_object_node_store(auth, - &i, &ohf->node[node_index++]); - - ohf->parent_name.assign(oh->parent_name); - ohf->parent_node.assign(oh->parent_node); - ohf->shadow = oh->shadow; - ohf->uid_name.assign(oh->uid_name); -} - -static bool auth_3d_object_hrc_replace_chara(auth_3d_object_hrc* oh, - CHARA_NUM src_chara, CHARA_NUM dst_chara, object_database* obj_db) { - if (src_chara < 0 || src_chara >= CN_MAX || dst_chara < 0 || dst_chara >= CN_MAX || src_chara == dst_chara) - return false; - - std::string src_chara_str = get_char_id_str(src_chara); - std::string dst_chara_str = get_char_id_str(dst_chara); - - std::string uid_name = oh->uid_name; - size_t pos = uid_name.find(src_chara_str); - if (pos != -1) - uid_name.assign(uid_name.replace(pos, src_chara_str.size(), dst_chara_str)); - - object_info obj_info = obj_db->get_object_info(uid_name.c_str()); - if (obj_info.not_null()) { - oh->object_info = obj_info; - return true; - } - return false; -} - -static void auth_3d_object_hrc_nodes_mat_mult(auth_3d_object_hrc* oh, const mat4* mat) { - for (auth_3d_object_node& i : oh->node) { - mat4 m; - if (i.parent >= 0) - m = oh->node[i.parent].model_transform.mat; - else - m = *mat; - - mat4_mul(&i.joint_orient_mat, &m, &m); - i.model_transform.mat_mult(&m); - - if (i.mat) - *i.mat = i.model_transform.mat; - } -} - -static void auth_3d_object_instance_load(auth_3d* auth, auth_3d_object_instance* oi, - auth_3d_object_instance_file* oif, auth_3d_m_object_hrc* moh, object_database* obj_db) { - auth_3d_object_model_transform_load(auth, &oi->model_transform, &oif->model_transform); - oi->name.assign(oif->name); - oi->shadow = oif->shadow; - oi->uid_name.assign(oif->uid_name); - - oi->object_info = obj_db->get_object_info(oi->uid_name.c_str()); - oi->object_hash = hash_string_murmurhash(oi->uid_name); - - obj_skin* skin = objset_info_storage_get_obj_skin(oi->object_info); - if (!skin) - return; - - oi->object_bone_indices.resize(skin->num_bone); - int32_t* object_bone_indices = oi->object_bone_indices.data(); - - oi->mats.resize(skin->num_bone); - mat4* mats = oi->mats.data(); - - for (int32_t i = 0; i < skin->num_bone; i++) { - uint64_t name_hash = hash_utf8_xxh3_64bits(skin->bone_array[i].name); - for (auth_3d_object_node& j : moh->node) - if (hash_string_xxh3_64bits(j.name) == name_hash) { - int32_t bone_id = skin->bone_array[i].id; - if (!(bone_id & 0x8000)) - object_bone_indices[bone_id] = (int32_t)(&j - moh->node.data()); - break; - } - } -} - -static void auth_3d_object_instance_store(auth_3d* auth, auth_3d_object_instance* oi, - auth_3d_object_instance_file* oif, auth_3d_m_object_hrc* moh) { - auth_3d_object_model_transform_store(auth, &oi->model_transform, &oif->model_transform); - oif->name.assign(oi->name); - oif->shadow = oi->shadow; - oif->uid_name.assign(oi->uid_name); -} - -static void auth_3d_object_model_transform_load(auth_3d* auth, - auth_3d_object_model_transform* omt, auth_3d_model_transform_file* mtf) { - omt->mat = mat4_identity; - omt->mat_inner = mat4_identity; - omt->mat_rot = mat4_identity; - omt->translation_value = 0.0f; - omt->rotation_value = 0.0f; - omt->scale_value = 1.0f; - omt->visible = false; - omt->frame = -1.0f; - omt->has_rotation = false; - omt->has_translation = false; - omt->has_scale = false; - omt->has_visibility = false; - - auth_3d_vec3_load(auth, &omt->translation, &mtf->translation); - auth_3d_vec3_load(auth, &omt->rotation, &mtf->rotation); - auth_3d_vec3_load(auth, &omt->scale, &mtf->scale); - auth_3d_key_load(auth, &omt->visibility, &mtf->visibility); - - if (omt->scale.x.type == AUTH_3D_KEY_STATIC && fabsf(1.0f - omt->scale.x.value) <= 0.000001f - && omt->scale.y.type == AUTH_3D_KEY_STATIC && fabsf(1.0f - omt->scale.y.value) <= 0.000001f - && omt->scale.z.type == AUTH_3D_KEY_STATIC && fabsf(1.0f - omt->scale.z.value) <= 0.000001f) { - omt->has_scale = false; - omt->scale_value = 1.0f; - } - else - omt->has_scale = true; - - if (omt->visibility.type == AUTH_3D_KEY_STATIC) { - omt->has_visibility = false; - omt->visible = omt->visibility.value >= 0.999f; - } - else - omt->has_visibility = true; -} - -static void auth_3d_object_model_transform_store(auth_3d* auth, - auth_3d_object_model_transform* omt, auth_3d_model_transform_file* mtf) { - auth_3d_vec3_store(auth, &omt->translation, &mtf->translation); - auth_3d_vec3_store(auth, &omt->rotation, &mtf->rotation); - auth_3d_vec3_store(auth, &omt->scale, &mtf->scale); - auth_3d_key_store(auth, &omt->visibility, &mtf->visibility); -} - -static void auth_3d_object_node_load(auth_3d* auth, - auth_3d_object_node* on, auth_3d_object_node_file* onf) { - if (onf->flags & A3DA_OBJECT_NODE_JOINT_ORIENT) { - on->joint_orient = onf->joint_orient; - mat4_rotate_zyx(&on->joint_orient, &on->joint_orient_mat); - enum_or(on->flags, AUTH_3D_OBJECT_NODE_JOINT_ORIENT); - } - else { - on->joint_orient = 0.0f; - on->joint_orient_mat = mat4_identity; - } - - auth_3d_object_model_transform_load(auth, &on->model_transform, &onf->model_transform); - on->name.assign(onf->name); - on->parent = onf->parent; -} - -static void auth_3d_object_node_store(auth_3d* auth, - auth_3d_object_node* on, auth_3d_object_node_file* onf) { - if (on->flags & AUTH_3D_OBJECT_NODE_JOINT_ORIENT) { - onf->joint_orient = on->joint_orient; - enum_or(onf->flags, A3DA_OBJECT_NODE_JOINT_ORIENT); - } - else - onf->joint_orient = 0.0f; - - auth_3d_object_model_transform_store(auth, &on->model_transform, &onf->model_transform); - onf->name.assign(on->name); - onf->parent = on->parent; -} - -static void auth_3d_object_texture_pattern_load(auth_3d* auth, auth_3d_object_texture_pattern* otp, - auth_3d_object_texture_pattern_file* otpf, texture_database* tex_db) { - otp->name.assign(otpf->name); - auth_3d_object_curve_load(auth, &otp->pattern, otpf->pattern, otpf->pattern_offset); - otp->texture_id = tex_db->get_texture_id(otp->name.c_str()); -} - -static void auth_3d_object_texture_pattern_store(auth_3d* auth, auth_3d_object_texture_pattern* otp, - auth_3d_object_texture_pattern_file* otpf) { - otpf->name.assign(otp->name); - auth_3d_object_curve_store(auth, &otp->pattern, otpf->pattern, otpf->pattern_offset); -} - -static void auth_3d_object_texture_transform_load(auth_3d* auth, auth_3d_object_texture_transform* ott, - auth_3d_object_texture_transform_file* ottf, texture_database* tex_db) { - if (ottf->flags & A3DA_OBJECT_TEXTURE_TRANSFORM_COVERAGE_U) { - auth_3d_key_load(auth, &ott->coverage_u, &ottf->coverage_u); - enum_or(ott->flags, AUTH_3D_OBJECT_TEXTURE_TRANSFORM_COVERAGE_U); - } - - if (ottf->flags & A3DA_OBJECT_TEXTURE_TRANSFORM_COVERAGE_V) { - auth_3d_key_load(auth, &ott->coverage_v, &ottf->coverage_v); - enum_or(ott->flags, AUTH_3D_OBJECT_TEXTURE_TRANSFORM_COVERAGE_V); - } - - ott->name.assign(ottf->name); - - if (ottf->flags & A3DA_OBJECT_TEXTURE_TRANSFORM_OFFSET_U) { - auth_3d_key_load(auth, &ott->offset_u, &ottf->offset_u); - enum_or(ott->flags, AUTH_3D_OBJECT_TEXTURE_TRANSFORM_OFFSET_U); - } - - if (ottf->flags & A3DA_OBJECT_TEXTURE_TRANSFORM_OFFSET_V) { - auth_3d_key_load(auth, &ott->offset_v, &ottf->offset_v); - enum_or(ott->flags, AUTH_3D_OBJECT_TEXTURE_TRANSFORM_OFFSET_V); - } - - if (ottf->flags & A3DA_OBJECT_TEXTURE_TRANSFORM_REPEAT_U) { - auth_3d_key_load(auth, &ott->repeat_u, &ottf->repeat_u); - enum_or(ott->flags, AUTH_3D_OBJECT_TEXTURE_TRANSFORM_REPEAT_U); - } - - if (ottf->flags & A3DA_OBJECT_TEXTURE_TRANSFORM_REPEAT_V) { - auth_3d_key_load(auth, &ott->repeat_v, &ottf->repeat_v); - enum_or(ott->flags, AUTH_3D_OBJECT_TEXTURE_TRANSFORM_REPEAT_V); - } - - if (ottf->flags & A3DA_OBJECT_TEXTURE_TRANSFORM_ROTATE) { - auth_3d_key_load(auth, &ott->rotate, &ottf->rotate); - enum_or(ott->flags, AUTH_3D_OBJECT_TEXTURE_TRANSFORM_ROTATE); - } - - if (ottf->flags & A3DA_OBJECT_TEXTURE_TRANSFORM_ROTATE_FRAME) { - auth_3d_key_load(auth, &ott->rotate_frame, &ottf->rotate_frame); - enum_or(ott->flags, AUTH_3D_OBJECT_TEXTURE_TRANSFORM_ROTATE_FRAME); - } - - if (ottf->flags & A3DA_OBJECT_TEXTURE_TRANSFORM_TRANSLATE_FRAME_U) { - auth_3d_key_load(auth, &ott->translate_frame_u, &ottf->translate_frame_u); - enum_or(ott->flags, AUTH_3D_OBJECT_TEXTURE_TRANSFORM_TRANSLATE_FRAME_U); - } - - if (ottf->flags & A3DA_OBJECT_TEXTURE_TRANSFORM_TRANSLATE_FRAME_V) { - auth_3d_key_load(auth, &ott->translate_frame_v, &ottf->translate_frame_v); - enum_or(ott->flags, AUTH_3D_OBJECT_TEXTURE_TRANSFORM_TRANSLATE_FRAME_V); - } - - ott->texture_id = tex_db->get_texture_id(ott->name.c_str()); -} - -static void auth_3d_object_texture_transform_store(auth_3d* auth, auth_3d_object_texture_transform* ott, - auth_3d_object_texture_transform_file* ottf) { - if (ott->flags & AUTH_3D_OBJECT_TEXTURE_TRANSFORM_COVERAGE_U) { - auth_3d_key_store(auth, &ott->coverage_u, &ottf->coverage_u); - enum_or(ottf->flags, A3DA_OBJECT_TEXTURE_TRANSFORM_COVERAGE_U); - } - - if (ott->flags & AUTH_3D_OBJECT_TEXTURE_TRANSFORM_COVERAGE_V) { - auth_3d_key_store(auth, &ott->coverage_v, &ottf->coverage_v); - enum_or(ottf->flags, A3DA_OBJECT_TEXTURE_TRANSFORM_COVERAGE_V); - } - - ottf->name.assign(ott->name); - - if (ott->flags & AUTH_3D_OBJECT_TEXTURE_TRANSFORM_OFFSET_U) { - auth_3d_key_store(auth, &ott->offset_u, &ottf->offset_u); - enum_or(ottf->flags, A3DA_OBJECT_TEXTURE_TRANSFORM_OFFSET_U); - } - - if (ott->flags & AUTH_3D_OBJECT_TEXTURE_TRANSFORM_OFFSET_V) { - auth_3d_key_store(auth, &ott->offset_v, &ottf->offset_v); - enum_or(ottf->flags, A3DA_OBJECT_TEXTURE_TRANSFORM_OFFSET_V); - } - - if (ott->flags & AUTH_3D_OBJECT_TEXTURE_TRANSFORM_REPEAT_U) { - auth_3d_key_store(auth, &ott->repeat_u, &ottf->repeat_u); - enum_or(ottf->flags, A3DA_OBJECT_TEXTURE_TRANSFORM_REPEAT_U); - } - - if (ott->flags & AUTH_3D_OBJECT_TEXTURE_TRANSFORM_REPEAT_V) { - auth_3d_key_store(auth, &ott->repeat_v, &ottf->repeat_v); - enum_or(ottf->flags, A3DA_OBJECT_TEXTURE_TRANSFORM_REPEAT_V); - } - - if (ott->flags & AUTH_3D_OBJECT_TEXTURE_TRANSFORM_ROTATE) { - auth_3d_key_store(auth, &ott->rotate, &ottf->rotate); - enum_or(ottf->flags, A3DA_OBJECT_TEXTURE_TRANSFORM_ROTATE); - } - - if (ott->flags & AUTH_3D_OBJECT_TEXTURE_TRANSFORM_ROTATE_FRAME) { - auth_3d_key_store(auth, &ott->rotate_frame, &ottf->rotate_frame); - enum_or(ottf->flags, A3DA_OBJECT_TEXTURE_TRANSFORM_ROTATE_FRAME); - } - - if (ott->flags & AUTH_3D_OBJECT_TEXTURE_TRANSFORM_TRANSLATE_FRAME_U) { - auth_3d_key_store(auth, &ott->translate_frame_u, &ottf->translate_frame_u); - enum_or(ottf->flags, A3DA_OBJECT_TEXTURE_TRANSFORM_TRANSLATE_FRAME_U); - } - - if (ott->flags & AUTH_3D_OBJECT_TEXTURE_TRANSFORM_TRANSLATE_FRAME_V) { - auth_3d_key_store(auth, &ott->translate_frame_v, &ottf->translate_frame_v); - enum_or(ottf->flags, A3DA_OBJECT_TEXTURE_TRANSFORM_TRANSLATE_FRAME_V); - } -} - -static void auth_3d_play_control_load(auth_3d* auth, auth_3d_play_control_file* pcf) { - auth_3d_play_control* pc = &auth->play_control; - - pc->begin = pcf->begin; - - if (pcf->flags & A3DA_PLAY_CONTROL_DIV) { - pc->div = pcf->div; - enum_or(pc->flags, AUTH_3D_PLAY_CONTROL_DIV); - } - - pc->fps = pcf->fps; - - if (pcf->flags & A3DA_PLAY_CONTROL_OFFSET) { - pc->div = pcf->div; - enum_or(pc->flags, AUTH_3D_PLAY_CONTROL_OFFSET); - } - - pc->size = pcf->size; -} - -static void auth_3d_play_control_store(auth_3d* auth, auth_3d_play_control_file* pcf) { - auth_3d_play_control* pc = &auth->play_control; - - pcf->begin = pc->begin; - - if (pc->flags & AUTH_3D_PLAY_CONTROL_DIV) { - pcf->div = pc->div; - enum_or(pcf->flags, A3DA_PLAY_CONTROL_DIV); - } - - pcf->fps = pc->fps; - - if (pc->flags & AUTH_3D_PLAY_CONTROL_OFFSET) { - pcf->div = pc->div; - enum_or(pcf->flags, A3DA_PLAY_CONTROL_OFFSET); - } - - pcf->size = pc->size; -} - -static void auth_3d_point_disp(auth_3d_point* p, auth_3d* auth, render_context* rctx) { - if (auth->pos) { - p->model_transform.set_mat(&auth->mat); - debug_put_line_axis(p->model_transform.mat); - } -} - -static void auth_3d_point_load(auth_3d* auth, auth_3d_point* p, auth_3d_point_file* pf) { - auth_3d_model_transform_load(auth, &p->model_transform, &pf->model_transform); - p->name.assign(pf->name); -} - -static void auth_3d_point_store(auth_3d* auth, auth_3d_point* p, auth_3d_point_file* pf) { - auth_3d_model_transform_store(auth, &p->model_transform, &pf->model_transform); - pf->name.assign(p->name); -} - -static void auth_3d_post_process_load(auth_3d* auth, auth_3d_post_process* pp, auth_3d_post_process_file* ppf) { - if (ppf->flags & A3DA_POST_PROCESS_INTENSITY) { - auth_3d_rgba_load(auth, &pp->intensity, &ppf->intensity); - enum_or(pp->flags, AUTH_3D_POST_PROCESS_INTENSITY); - } - - if (ppf->flags & A3DA_POST_PROCESS_LENS_FLARE) { - auth_3d_key_load(auth, &pp->lens_flare, &ppf->lens_flare); - enum_or(pp->flags, AUTH_3D_POST_PROCESS_LENS_FLARE); - } - - if (ppf->flags & A3DA_POST_PROCESS_LENS_GHOST) { - auth_3d_key_load(auth, &pp->lens_ghost, &ppf->lens_ghost); - enum_or(pp->flags, AUTH_3D_POST_PROCESS_LENS_GHOST); - } - - if (ppf->flags & A3DA_POST_PROCESS_LENS_SHAFT) { - auth_3d_key_load(auth, &pp->lens_shaft, &ppf->lens_shaft); - enum_or(pp->flags, AUTH_3D_POST_PROCESS_LENS_SHAFT); - } - - if (ppf->flags & A3DA_POST_PROCESS_RADIUS) { - auth_3d_rgba_load(auth, &pp->radius, &ppf->radius); - enum_or(pp->flags, AUTH_3D_POST_PROCESS_RADIUS); - } - - if (ppf->flags & A3DA_POST_PROCESS_SCENE_FADE) { - auth_3d_rgba_load(auth, &pp->scene_fade, &ppf->scene_fade); - enum_or(pp->flags, AUTH_3D_POST_PROCESS_SCENE_FADE); - } -} - -static void auth_3d_post_process_restore_prev_value(auth_3d_post_process* pp, render_context* rctx) { - if (pp->flags_init & AUTH_3D_POST_PROCESS_INTENSITY) - rctx->render.set_intensity(pp->intensity_init); - - if (pp->flags_init & (AUTH_3D_POST_PROCESS_LENS_FLARE - | AUTH_3D_POST_PROCESS_LENS_GHOST | AUTH_3D_POST_PROCESS_LENS_SHAFT)) { - vec3 value = rctx->render.get_lens(); - if (pp->flags_init & AUTH_3D_POST_PROCESS_LENS_FLARE) - value.x = pp->lens_init.x; - if (pp->flags_init & AUTH_3D_POST_PROCESS_LENS_SHAFT) - value.y = pp->lens_init.y; - if (pp->flags_init & AUTH_3D_POST_PROCESS_LENS_GHOST) - value.z = pp->lens_init.z; - rctx->render.set_lens(value); - } - - if (pp->flags_init & AUTH_3D_POST_PROCESS_RADIUS) - rctx->render.set_radius(pp->radius_init); - - if (pp->flags_init & AUTH_3D_POST_PROCESS_SCENE_FADE) - rctx->render.set_scene_fade(pp->scene_fade_init, 0); -} - -static void auth_3d_post_process_set(auth_3d_post_process* pp, render_context* rctx) { - if (pp->flags & AUTH_3D_POST_PROCESS_INTENSITY) { - if (!(pp->flags_init & AUTH_3D_POST_PROCESS_INTENSITY)) { - pp->intensity_init = rctx->render.get_intensity(); - enum_or(pp->flags_init, AUTH_3D_POST_PROCESS_INTENSITY); - } - - rctx->render.set_intensity(*(vec3*)&pp->intensity.value); - } - - if (pp->flags & (AUTH_3D_POST_PROCESS_LENS_GHOST - | AUTH_3D_POST_PROCESS_LENS_SHAFT | AUTH_3D_POST_PROCESS_LENS_FLARE)) { - vec3 value = rctx->render.get_lens(); - if (pp->flags & AUTH_3D_POST_PROCESS_LENS_FLARE) { - if (!(pp->flags_init & AUTH_3D_POST_PROCESS_LENS_FLARE)) - pp->lens_init.x = value.x; - value.x = pp->lens_value.x; - } - - if (pp->flags & AUTH_3D_POST_PROCESS_LENS_SHAFT) { - if (!(pp->flags_init & AUTH_3D_POST_PROCESS_LENS_SHAFT)) - pp->lens_init.y = value.y; - value.y = pp->lens_value.y; - } - - if (pp->flags & AUTH_3D_POST_PROCESS_LENS_GHOST) { - if (!(pp->flags_init & AUTH_3D_POST_PROCESS_LENS_GHOST)) - pp->lens_init.z = value.z; - value.z = pp->lens_value.z; - } - rctx->render.set_lens(value); - } - - if (pp->flags & AUTH_3D_POST_PROCESS_RADIUS) { - if (!(pp->flags_init & AUTH_3D_POST_PROCESS_RADIUS)) { - pp->radius_init = rctx->render.get_radius(); - enum_or(pp->flags_init, AUTH_3D_POST_PROCESS_RADIUS); - } - - rctx->render.set_radius(*(vec3*)&pp->radius.value); - } - - if (pp->flags & AUTH_3D_POST_PROCESS_SCENE_FADE) { - if (!(pp->flags_init & AUTH_3D_POST_PROCESS_SCENE_FADE)) { - pp->scene_fade_init = rctx->render.get_scene_fade(); - enum_or(pp->flags_init, AUTH_3D_POST_PROCESS_SCENE_FADE); - } - - rctx->render.set_scene_fade(pp->scene_fade.value, 0); - } -} - -static void auth_3d_post_process_store(auth_3d* auth, auth_3d_post_process* pp, auth_3d_post_process_file* ppf) { - if (pp->flags & AUTH_3D_POST_PROCESS_INTENSITY) { - auth_3d_rgba_store(auth, &pp->intensity, &ppf->intensity); - enum_or(ppf->flags, A3DA_POST_PROCESS_INTENSITY); - } - - if (pp->flags & AUTH_3D_POST_PROCESS_LENS_FLARE) { - auth_3d_key_store(auth, &pp->lens_flare, &ppf->lens_flare); - enum_or(ppf->flags, A3DA_POST_PROCESS_LENS_FLARE); - } - - if (pp->flags & AUTH_3D_POST_PROCESS_LENS_GHOST) { - auth_3d_key_store(auth, &pp->lens_ghost, &ppf->lens_ghost); - enum_or(ppf->flags, A3DA_POST_PROCESS_LENS_GHOST); - } - - if (pp->flags & AUTH_3D_POST_PROCESS_LENS_SHAFT) { - auth_3d_key_store(auth, &pp->lens_shaft, &ppf->lens_shaft); - enum_or(ppf->flags, A3DA_POST_PROCESS_LENS_SHAFT); - } - - if (pp->flags & AUTH_3D_POST_PROCESS_RADIUS) { - auth_3d_rgba_store(auth, &pp->radius, &ppf->radius); - enum_or(ppf->flags, A3DA_POST_PROCESS_RADIUS); - } - - if (pp->flags & AUTH_3D_POST_PROCESS_SCENE_FADE) { - auth_3d_rgba_store(auth, &pp->scene_fade, &ppf->scene_fade); - enum_or(ppf->flags, A3DA_POST_PROCESS_SCENE_FADE); - } -} - -static bool auth_3d_data_struct_init(auth_3d_data_struct* auth_3d_data, render_context* rctx) { - auth_3d_data->loaded_ids.clear(); - auth_3d_data->loaded_ids.shrink_to_fit(); - for (int32_t i = 0; i < AUTH_3D_DATA_COUNT; i++) - auth_3d_data->data[i].reset(); - return true; -} - -static bool auth_3d_data_struct_check_category_loaded( - auth_3d_data_struct* auth_3d_data, const char* category_name) { - if (category_name) { - auth_3d_farc* a3da_farc = auth_3d_data_struct_get_farc(auth_3d_data, category_name); - if (a3da_farc) - return a3da_farc->state == 2; - } - return true; -} - -static bool auth_3d_data_struct_check_category_loaded( - auth_3d_data_struct* auth_3d_data, uint32_t category_hash) { - if (!category_hash || category_hash == hash_murmurhash_empty) - return true; - - auto elem = auth_3d_data->farcs_modern.find(category_hash); - if (elem != auth_3d_data->farcs_modern.end()) - return elem->second.state == 2; - return true; -} - -static bool auth_3d_data_struct_ctrl(auth_3d_data_struct* auth_3d_data, render_context* rctx) { - for (int32_t& i : auth_3d_data->loaded_ids) - if (i >= 0 && (i & 0x7FFF) < AUTH_3D_DATA_COUNT) { - auth_3d* auth = &auth_3d_data->data[i & 0x7FFF]; - if (auth && auth->id == i) - auth->ctrl(rctx); - } - return false; -} - -static void auth_3d_data_struct_disp(auth_3d_data_struct* auth_3d_data, render_context* rctx) { - for (int32_t& i : auth_3d_data->loaded_ids) - if (i >= 0 && (i & 0x7FFF) < AUTH_3D_DATA_COUNT) { - auth_3d* auth = &auth_3d_data->data[i & 0x7FFF]; - if (auth && auth->id == i) - auth->disp(rctx); - } -} - -static auth_3d_farc* auth_3d_data_struct_get_farc( - auth_3d_data_struct* auth_3d_data, const char* category_name) { - if (!category_name || !auth_3d_data->farcs.size()) - return 0; - - uint64_t name_hash = hash_utf8_xxh3_64bits(category_name); - for (auth_3d_farc& i : auth_3d_data->farcs) - if (hash_string_xxh3_64bits(i.name) == name_hash) - return &i; - return 0; -} - -static void auth_3d_data_struct_load_category(auth_3d_data_struct* auth_3d_data, - const char* category_name, const char* mdata_dir) { - if (!category_name) - return; - - auth_3d_farc* a3da_farc = auth_3d_data_struct_get_farc(auth_3d_data, category_name); - if (a3da_farc) - auth_3d_farc_load(a3da_farc, mdata_dir); -} - -static void auth_3d_data_struct_load_category(auth_3d_data_struct* auth_3d_data, - void* data, const char* category_name, uint32_t category_hash) { - if (!category_hash || category_hash == hash_murmurhash_empty) - return; - - auto elem = auth_3d_data->farcs_modern.find(category_hash); - if (elem == auth_3d_data->farcs_modern.end()) { - elem = auth_3d_data->farcs_modern.insert({ category_hash, {} }).first; - auth_3d_farc* a3da_farc = &elem->second; - a3da_farc->name.assign(category_name); - } - - auth_3d_farc* a3da_farc = &elem->second; - if (a3da_farc) - auth_3d_farc_load_modern(a3da_farc, data); -} - -static void auth_3d_data_struct_unload_category( - auth_3d_data_struct* auth_3d_data, const char* category_name) { - if (!category_name) - return; - - auth_3d_farc* a3da_farc = auth_3d_data_struct_get_farc(auth_3d_data, category_name); - if (a3da_farc) - auth_3d_farc_unload(a3da_farc); -} - -static void auth_3d_data_struct_unload_category( - auth_3d_data_struct* auth_3d_data, uint32_t category_hash) { - if (!category_hash || category_hash == hash_murmurhash_empty) - return; - - auto elem = auth_3d_data->farcs_modern.find(category_hash); - if (elem == auth_3d_data->farcs_modern.end()) - return; - - auth_3d_farc_unload(&elem->second); - if (elem->second.load_count <= 0) - auth_3d_data->farcs_modern.erase(elem); -} - -static void auth_3d_farc_load(auth_3d_farc* a3da_farc, const char* mdata_dir) { - if (a3da_farc->load_count) { - a3da_farc->load_count++; - return; - } - - a3da_farc->load_count = 1; - auth_3d_farc_read_file(a3da_farc, mdata_dir); -} - -static void auth_3d_farc_load_modern(auth_3d_farc* a3da_farc, void* data) { - if (a3da_farc->load_count) { - a3da_farc->load_count++; - return; - } - - a3da_farc->load_count = 1; - auth_3d_farc_read_file_modern(a3da_farc, data); -} - -static void auth_3d_farc_read_file(auth_3d_farc* a3da_farc, const char* mdata_dir) { - if (a3da_farc->state) { - a3da_farc->state = 2; - return; - } - - a3da_farc->state = 1; - - if (mdata_dir && *mdata_dir) { - a3da_farc->path.assign(mdata_dir); - a3da_farc->path.append("rom/auth_3d/"); - } - else - a3da_farc->path.assign("rom/auth_3d/"); - a3da_farc->file.assign(a3da_farc->name); - a3da_farc->file.append(".farc"); - - if (a3da_farc->file_handler.read_file(&data_list[DATA_AFT], - a3da_farc->path.c_str(), a3da_farc->file.c_str(), prj::MemCSystem)) - a3da_farc->file_handler.set_callback_data(0, - (PFNFILEHANDLERCALLBACK*)auth_3d_farc_read_func, a3da_farc); - else - a3da_farc->state = 2; -} - -static void auth_3d_farc_read_file_modern(auth_3d_farc* a3da_farc, void* data) { - if (a3da_farc->state) { - a3da_farc->state = 2; - return; - } - - a3da_farc->state = 1; - a3da_farc->path.assign("root+/auth_3d/"); - a3da_farc->file.assign(a3da_farc->name); - a3da_farc->file.append(".farc"); - - if (a3da_farc->file_handler.read_file(data, a3da_farc->path.c_str(), - hash_string_murmurhash(a3da_farc->name), ".farc", prj::MemCSystem)) - a3da_farc->file_handler.set_callback_data(0, - (PFNFILEHANDLERCALLBACK*)auth_3d_farc_read_func, a3da_farc); - else - a3da_farc->state = 2; -} - -static bool auth_3d_farc_read_func(auth_3d_farc* a3da_farc, const void* data, size_t size) { - if (a3da_farc->state == 1) { - a3da_farc->state = 2; - a3da_farc->data = data; - a3da_farc->size = size; - } - - if (!a3da_farc->farc) - a3da_farc->farc = new farc; - if (!a3da_farc->farc) - return false; - - a3da_farc->farc->read(a3da_farc->data, a3da_farc->size, true); - return true; -} - -static void auth_3d_farc_reset(auth_3d_farc* a3da_farc) { - if (a3da_farc->state == 1) - a3da_farc->file_handler.call_free_callback(); - else if (a3da_farc->state == 2) { - delete a3da_farc->farc; - a3da_farc->farc = 0; - a3da_farc->file_handler.reset(); - } - - a3da_farc->path.clear(); - a3da_farc->path.shrink_to_fit(); - a3da_farc->file.clear(); - a3da_farc->file.shrink_to_fit(); - a3da_farc->data = 0; - a3da_farc->size = 0; - a3da_farc->state = 0; -} - -static void auth_3d_farc_unload(auth_3d_farc* a3da_farc) { - if (--a3da_farc->load_count < 0) - a3da_farc->load_count = 0; - else if (!a3da_farc->load_count) - auth_3d_farc_reset(a3da_farc); -} - -static void auth_3d_uid_file_load(auth_3d_uid_file* uid_file) { - uid_file->state = 1; - auth_3d_farc_load(uid_file->farc, 0); -} - -static void auth_3d_uid_file_modern_load(auth_3d_uid_file_modern* uid_file) { - uid_file->state = 1; - auth_3d_farc_load(uid_file->farc, 0); -} - -static void auth_3d_uid_file_load_file(auth_3d_uid_file* uid_file, auth_3d_database* auth_3d_db) { - if (uid_file->load_count) - uid_file->load_count++; - else if (uid_file->state) - return; - - uid_file->state = 2; - if (uid_file->uid >= auth_3d_db->uid.size()) - return; - - auth_3d_database_uid* db_uid = &auth_3d_db->uid[uid_file->uid]; - - if (!db_uid->enabled) - return; - - uid_file->name = db_uid->name.c_str(); - uid_file->file_name.assign(db_uid->name); - uid_file->file_name.append(".a3da"); - auth_3d_farc* farc = auth_3d_data_struct_get_farc(auth_3d_data, db_uid->category.c_str()); - uid_file->farc = farc; - if (farc) { - uid_file->load_count = 1; - auth_3d_uid_file_load(uid_file); - } -} - -static void auth_3d_uid_file_modern_load_file(auth_3d_uid_file_modern* uid_file) { - if (uid_file->load_count) - uid_file->load_count++; - else if (uid_file->state) - return; - - uid_file->state = 2; - - auth_3d_farc* farc = 0; - for (auto& i : auth_3d_data->farcs_modern) - if (i.second.farc && i.second.farc->has_file(uid_file->hash)) { - farc = &i.second; - break; - } - - if (!farc) - return; - - uid_file->file_name.assign(farc->farc->get_file_name(uid_file->hash)); - - uid_file->farc = farc; - if (farc) { - uid_file->load_count = 1; - auth_3d_uid_file_modern_load(uid_file); - } -} - -static void auth_3d_uid_file_unload(auth_3d_uid_file* uid_file) { - if (--uid_file->load_count < 0) - uid_file->load_count = 0; - else if (!uid_file->load_count) - auth_3d_uid_file_unload_file(uid_file); -} - -static void auth_3d_uid_file_modern_unload(auth_3d_uid_file_modern* uid_file) { - if (--uid_file->load_count < 0) - uid_file->load_count = 0; - else if (!uid_file->load_count) - auth_3d_uid_file_modern_unload_file(uid_file); -} - -static void auth_3d_uid_file_unload_file(auth_3d_uid_file* uid_file) { - if (uid_file->state == 1 || uid_file->state == 2) - auth_3d_farc_unload(uid_file->farc); - uid_file->name = 0; - uid_file->farc = 0; - uid_file->state = 0; -} - -static void auth_3d_uid_file_modern_unload_file(auth_3d_uid_file_modern* uid_file) { - if (uid_file->state == 1 || uid_file->state == 2) - auth_3d_farc_unload(uid_file->farc); - uid_file->name.clear(); - uid_file->name.shrink_to_fit(); - uid_file->farc = 0; - uid_file->state = 0; - auth_3d_data->uid_files_modern.erase(uid_file->hash); -} - -static size_t auth_3d_time_event_radix_index_func_frame(auth_3d_time_event* data, size_t index) { - return *(uint32_t*)&data[index].frame; -} diff --git a/src/CRE/auth_3d.hpp b/src/CRE/auth_3d.hpp index d54e6dfa..ddc8a90d 100644 --- a/src/CRE/auth_3d.hpp +++ b/src/CRE/auth_3d.hpp @@ -6,6 +6,7 @@ #pragma once #include +#include #include #include "../KKdLib/default.hpp" #include "../KKdLib/database/auth_3d.hpp" @@ -16,174 +17,105 @@ #include "prj/memory_manager.hpp" #include "auth_2d.hpp" #include "frame_rate_control.hpp" -#include "render_context.hpp" -enum auth_3d_ambient_flags { - AUTH_3D_AMBIENT_LIGHT_DIFFUSE = 0x01, - AUTH_3D_AMBIENT_RIM_LIGHT_DIFFUSE = 0x02, +#define AUTH_3D_DATA_COUNT 0x100 + +namespace auth_3d_detail { + enum EventActionFlag { + EAF_PASS = 0x0001, + EAF_JUMP_BACKWARD = 0x0002, + EAF_JUMP_FORWARD = 0x0004, + EAF_DESTROY = 0x8000, + }; + + enum EVENT_TYPE { + EVENT_MISC = 0, + EVENT_FLT, + EVENT_FX, + EVENT_SND, + EVENT_MOT, + EVENT_A2D, + }; + + // Pre/Post Infinity + enum EP_TYPE { + EP_TYPE_CONSTANT = 0, + EP_TYPE_LINEAR, + EP_TYPE_CYCLE, + EP_TYPE_CYCLE_WITH_OFFSET, + }; + + enum FC_TYPE { + FC_TYPE_STATIC_0 = 0, + FC_TYPE_STATIC_DATA, + FC_TYPE_LINEAR, + FC_TYPE_HERMITE, + FC_TYPE_NO_INTERPOLATION, + }; + + enum LoadState { + S_BEFORE_LOADING = 0, + S_NOW_LOADING, + S_DONE, + }; }; -enum auth_3d_camera_auxiliary_flags { - AUTH_3D_CAMERA_AUXILIARY_AUTO_EXPOSURE = 0x01, - AUTH_3D_CAMERA_AUXILIARY_EXPOSURE = 0x02, - AUTH_3D_CAMERA_AUXILIARY_EXPOSURE_RATE = 0x04, - AUTH_3D_CAMERA_AUXILIARY_GAMMA = 0x08, - AUTH_3D_CAMERA_AUXILIARY_GAMMA_RATE = 0x10, - AUTH_3D_CAMERA_AUXILIARY_SATURATE = 0x20, +namespace mdl { + enum ObjFlags : uint32_t; +} + +struct CameraParam; + +struct farc; +struct render_context; + +namespace auth_3d_detail { + class Ambient; + class CameraAuxiliary; + class CameraRoot; + class CameraViewPoint; + class Chara; + class Color; + class Curve; + class CurveWithOffset; + class DB; + class Dof; + class Event; + class Fog; + class Fcurve; + class Fcurve3f; + class FcurveColor4f; + class Handle; + class HierarchyObject; + class Light; + class MaterialList; + class ModelTransform; + class Motion; + class MotionTransform; + class MultiHierarchyObject; + class Object; + class ObjectInstance; + class PlayControl; + class Point; + class PostProcess; + class Scene; + class SceneFile; + class Texture; + class TextureTransform; + class TransformNode; }; -enum auth_3d_camera_root_view_point_flags { - AUTH_3D_CAMERA_ROOT_VIEW_POINT_FOV = 0x01, - AUTH_3D_CAMERA_ROOT_VIEW_POINT_ROLL = 0x02, -}; - -enum auth_3d_compress_f16 { - AUTH_3D_COMPRESS_F32F32F32F32 = 0, - AUTH_3D_COMPRESS_I16F16F32F32 = 1, - AUTH_3D_COMPRESS_I16F16F16F16 = 2, -}; - -enum auth_3d_ep_type { - AUTH_3D_EP_NONE = 0, - AUTH_3D_EP_LINEAR = 1, - AUTH_3D_EP_CYCLE = 2, - AUTH_3D_EP_CYCLE_OFFSET = 3, -}; // Pre/Post Infinity - -enum auth_3d_fog_flags { - AUTH_3D_FOG_COLOR = 0x01, - AUTH_3D_FOG_DENSITY = 0x02, - AUTH_3D_FOG_END = 0x04, - AUTH_3D_FOG_START = 0x08, -}; - -enum auth_3d_format { - AUTH_3D_FORMAT_DT = 0, - AUTH_3D_FORMAT_F = 1, - AUTH_3D_FORMAT_FT = 2, - AUTH_3D_FORMAT_F2 = 3, - AUTH_3D_FORMAT_MGF = 4, - AUTH_3D_FORMAT_X = 5, - AUTH_3D_FORMAT_XHD = 6, -}; - -enum auth_3d_key_flags { - AUTH_3D_KEY_BIN_OFFSET = 0x01, -}; - -enum auth_3d_key_type { - AUTH_3D_KEY_NONE = 0, - AUTH_3D_KEY_STATIC = 1, - AUTH_3D_KEY_LINEAR = 2, - AUTH_3D_KEY_HERMITE = 3, - AUTH_3D_KEY_HOLD = 4, -}; - -enum auth_3d_light_flags { - AUTH_3D_LIGHT_AMBIENT = 0x0001, - AUTH_3D_LIGHT_CONE_ANGLE = 0x0002, - AUTH_3D_LIGHT_CONSTANT = 0x0004, - AUTH_3D_LIGHT_DIFFUSE = 0x0008, - AUTH_3D_LIGHT_DROP_OFF = 0x0010, - AUTH_3D_LIGHT_FAR = 0x0020, - AUTH_3D_LIGHT_INTENSITY = 0x0040, - AUTH_3D_LIGHT_LINEAR = 0x0080, - AUTH_3D_LIGHT_POSITION = 0x0100, - AUTH_3D_LIGHT_QUADRATIC = 0x0200, - AUTH_3D_LIGHT_SPECULAR = 0x0400, - AUTH_3D_LIGHT_SPOT_DIRECTION = 0x0800, - AUTH_3D_LIGHT_TONE_CURVE = 0x1000, -}; - -enum auth_3d_material_list_flags { - AUTH_3D_MATERIAL_LIST_BLEND_COLOR = 0x01, - AUTH_3D_MATERIAL_LIST_GLOW_INTENSITY = 0x02, - AUTH_3D_MATERIAL_LIST_EMISSION = 0x04, -}; - -enum auth_3d_model_transform_flags { - AUTH_3D_MODEL_TRANSFORM_BIN_OFFSET = 0x01, -}; - -enum auth_3d_object_node_flags { - AUTH_3D_OBJECT_NODE_JOINT_ORIENT = 0x01, -}; - -enum auth_3d_object_texture_transform_flags { - AUTH_3D_OBJECT_TEXTURE_TRANSFORM_COVERAGE_U = 0x001, - AUTH_3D_OBJECT_TEXTURE_TRANSFORM_COVERAGE_V = 0x002, - AUTH_3D_OBJECT_TEXTURE_TRANSFORM_OFFSET_U = 0x004, - AUTH_3D_OBJECT_TEXTURE_TRANSFORM_OFFSET_V = 0x008, - AUTH_3D_OBJECT_TEXTURE_TRANSFORM_REPEAT_U = 0x010, - AUTH_3D_OBJECT_TEXTURE_TRANSFORM_REPEAT_V = 0x020, - AUTH_3D_OBJECT_TEXTURE_TRANSFORM_ROTATE = 0x040, - AUTH_3D_OBJECT_TEXTURE_TRANSFORM_ROTATE_FRAME = 0x080, - AUTH_3D_OBJECT_TEXTURE_TRANSFORM_TRANSLATE_FRAME_U = 0x100, - AUTH_3D_OBJECT_TEXTURE_TRANSFORM_TRANSLATE_FRAME_V = 0x200, -}; - -enum auth_3d_play_control_flags { - AUTH_3D_PLAY_CONTROL_DIV = 0x01, - AUTH_3D_PLAY_CONTROL_OFFSET = 0x02, -}; - -enum auth_3d_post_process_flags { - AUTH_3D_POST_PROCESS_INTENSITY = 0x01, - AUTH_3D_POST_PROCESS_LENS_FLARE = 0x02, - AUTH_3D_POST_PROCESS_LENS_GHOST = 0x04, - AUTH_3D_POST_PROCESS_LENS_SHAFT = 0x08, - AUTH_3D_POST_PROCESS_RADIUS = 0x10, - AUTH_3D_POST_PROCESS_SCENE_FADE = 0x20, -}; - -enum auth_3d_rgba_flags { - AUTH_3D_RGBA_R = 0x01, - AUTH_3D_RGBA_G = 0x02, - AUTH_3D_RGBA_B = 0x04, - AUTH_3D_RGBA_A = 0x08, -}; - -struct auth_3d; -struct auth_3d_ambient; -struct auth_3d_camera_auxiliary; -struct auth_3d_camera_root; -struct auth_3d_camera_root_view_point; -struct auth_3d_chara; -struct auth_3d_curve; -struct auth_3d_dof; -struct auth_3d_event; -struct auth_3d_fog; -struct auth_3d_key; -struct auth_3d_light; -struct auth_3d_m_object_hrc; -struct auth_3d_material_list; -struct auth_3d_model_transform; -struct auth_3d_object; -struct auth_3d_object_curve; -struct auth_3d_object_hrc; -struct auth_3d_object_instance; -struct auth_3d_object_model_transform; -struct auth_3d_object_node; -struct auth_3d_object_texture_pattern; -struct auth_3d_object_texture_transform; -struct auth_3d_play_control; -struct auth_3d_point; -struct auth_3d_post_process; -struct auth_3d_rgba; -struct auth_3d_vec3; -struct auth_3d_id; - namespace a3d { class EventListener { public: EventListener(); virtual ~EventListener(); - virtual void OnLoad(auth_3d_id& id) = 0; - virtual void OnCtrl(auth_3d_id& id) = 0; - virtual void OnEnded(auth_3d_id& id) = 0; - virtual void OnPostCtrl(auth_3d_id& id) = 0; - virtual void OnRepeat(auth_3d_id& id) = 0; + virtual void loadFinished(auth_3d_detail::Handle& in_handle) = 0; + virtual void playStart(auth_3d_detail::Handle& in_handle) = 0; + virtual void playFinished(auth_3d_detail::Handle& in_handle) = 0; + virtual void playLoopJumpAfter(auth_3d_detail::Handle& in_handle) = 0; + virtual void playLoopJumpBefore(auth_3d_detail::Handle& in_handle) = 0; }; class EventAdapter : public EventListener { @@ -191,887 +123,1857 @@ namespace a3d { EventAdapter(); virtual ~EventAdapter() override; - virtual void OnLoad(auth_3d_id& id) override; - virtual void OnCtrl(auth_3d_id& id) override; - virtual void OnEnded(auth_3d_id& id) override; - virtual void OnPostCtrl(auth_3d_id& id) override; - virtual void OnRepeat(auth_3d_id& id) override; + virtual void loadFinished(auth_3d_detail::Handle& in_handle) override; + virtual void playStart(auth_3d_detail::Handle& in_handle) override; + virtual void playFinished(auth_3d_detail::Handle& in_handle) override; + virtual void playLoopJumpAfter(auth_3d_detail::Handle& in_handle) override; + virtual void playLoopJumpBefore(auth_3d_detail::Handle& in_handle) override; }; } namespace auth_3d_detail { - class Event { + class Fcurve { public: - enum Type { - MISC = 0x00, - FILT = 0x01, - FX = 0x02, - SND = 0x03, - MOT = 0x04, - A2D = 0x05, + struct KeyData { + float_t frame; + float_t value; + float_t l_slope; + float_t r_slope; + + const KeyData* next() const; + KeyData* next(); + const KeyData* prev() const; + KeyData* prev(); + + static float_t S_calc(FC_TYPE in_type, float_t in_frame, + const KeyData* curr_key, const KeyData* next_key); + + inline KeyData() : frame(), value(), l_slope(), r_slope() {} + inline KeyData(float_t in_frame) + : frame(in_frame), value(), l_slope(), r_slope() {} + inline KeyData(float_t in_frame, float_t in_value) + : frame(in_frame), value(in_value), l_slope(), r_slope() {} + inline KeyData(float_t in_frame, float_t in_value, float_t in_slope) + : frame(in_frame), value(in_value), l_slope(in_slope), r_slope(in_slope) {} + inline KeyData(float_t in_frame, float_t in_value, float_t in_l_slope, float_t in_r_slope) + : frame(in_frame), value(in_value), l_slope(in_l_slope), r_slope(in_r_slope) {} + inline KeyData(const kft3& other) + : frame(other.frame), value(other.value), l_slope(other.l_slope), r_slope(other.r_slope) {} + + inline operator kft3() const { + return { frame, value, l_slope, r_slope }; + } }; - bool active; - Type type; + FC_TYPE m_type; + float_t m_static_value; + float_t m_max_frame; + EP_TYPE m_ep_type_pre; + EP_TYPE m_ep_type_post; + float_t m_frame_delta; + float_t m_value_delta; + std::vector m_key_data_list; + size_t m_key_data_size; + const KeyData* m_key_data_ptr; + + // Added + float_t m_frame; + float_t m_value; + + private: + void M_init(); + float_t M_get(float_t in_frame) const; + void M_set_ep_type(EP_TYPE in_ep_type_pre, EP_TYPE in_ep_type_post); + + public: + Fcurve(); + Fcurve(float_t in_value); + Fcurve(const Fcurve& other); + ~Fcurve(); + + void init(); + void init(float_t in_value); + float_t get(float_t in_frame); + float_t operator()(float_t in_frame); + const KeyData* find_key_data(float_t in_frame) const; + float_t get_size() const; + bool check_discontinuity(float_t in_frame) const; + bool check_threshold_discontinuity(float_t in_frame, float_t in_threshold = 0.3f) const; + + bool load(const SceneFile& in_file, const a3d::Fcurve& in_fcv); + void store(const SceneFile& in_file, a3d::Fcurve& out_fcv) const; // Added + + static bool check_ep_range(float_t in_frame_begin, float_t in_frame_end, + float_t in_key_frame_begin, float_t in_key_frame_end); + + Fcurve& operator=(const Fcurve& other); + }; + + class Fcurve3f { + public: + Fcurve x; + Fcurve y; + Fcurve z; + + Fcurve3f(); + Fcurve3f(float_t in_value); + Fcurve3f(const Fcurve3f& other); + ~Fcurve3f(); + + void init(); + void init(float_t in_value); + vec3 get(float_t in_frame); + + bool load(const SceneFile& in_file, const a3d::Fcurve3f& in_fcv3f); + void store(const SceneFile& in_file, a3d::Fcurve3f& out_fcv3f) const; // Added + + Fcurve3f& operator=(const Fcurve3f& other); + }; + + class FcurveColor4f { + public: + Fcurve r; + Fcurve g; + Fcurve b; + Fcurve a; + bool has_r; + bool has_g; + bool has_b; + bool has_a; + + FcurveColor4f(); + FcurveColor4f(const FcurveColor4f& other); + ~FcurveColor4f(); + + void init(); + vec4 get(float_t in_frame); + + bool load(const SceneFile& in_file, const a3d::FcurveColor4f& in_fcv_col4f); + void store(const SceneFile& in_file, a3d::FcurveColor4f& out_fcv_col4f) const; // Added + + FcurveColor4f& operator=(const FcurveColor4f& other); + }; + + class Color { + public: + FcurveColor4f fcurve_color; + vec4 color; + bool has_color[4]; + + Color(); + Color(const Color& other); + ~Color(); + + void init(); + void get(float_t in_frame); + + bool load(const SceneFile& in_file, const a3d::FcurveColor4f& in_fcv_col4f); + void store(const SceneFile& in_file, a3d::FcurveColor4f& out_fcv_col4f) const; // Added + + Color& operator=(const Color& other); + }; + + class ModelTransform { + public: + mat4 matrix; + Fcurve3f fcurve_scale; + Fcurve3f fcurve_rotation; + Fcurve3f fcurve_translation; + Fcurve fcurve_visibility; + + vec3 scale; + vec3 rotation; + vec3 translation; + bool visibility; + + ModelTransform(); + ModelTransform(const ModelTransform& other); + ~ModelTransform(); + + void init(); + void init_static(); + void get(float_t in_frame); + const mat4& mul(const mat4& in_base_mat); + const mat4& get_matrix(); + + bool load(const SceneFile& in_file, const a3d::ModelTransform& in_mt); + void store(const SceneFile& in_file, a3d::ModelTransform& out_mt) const; // Added + + ModelTransform& operator=(const ModelTransform& other); + }; + + // MGF + class Ambient { + public: + enum { + FLAG_LIGHT_DIFFUSE = 0x01, + FLAG_RIM_LIGHT_DIFFUSE = 0x02, + }; + + uint32_t flag; std::string name; + Color light_diffuse; + Color rim_light_diffuse; + + Ambient(); + Ambient(const Ambient& other); + ~Ambient(); + + void init(); + bool has_light_diffuse() const; + bool has_rim_light_diffuse() const; + void get(float_t in_frame); + void ctrl(render_context* rctx); + + bool load(const SceneFile& in_file, const a3d::Ambient& in_a); + void store(const SceneFile& in_file, a3d::Ambient& out_a) const; // Added + + Ambient& operator=(const Ambient& other); + }; + + class Auth2d { + public: + std::string name; + + Auth2d(); + Auth2d(const Auth2d& other); + ~Auth2d(); + + bool load(const SceneFile& in_file, const a3d::Auth2d& in_a2); + void store(const SceneFile& in_file, a3d::Auth2d& out_a2) const; // Added + + Auth2d& operator=(const Auth2d& other); + }; + + class CameraAuxiliary { + public: + enum { + FLAG_EXPOSURE = 0x01, + FLAG_EXPOSURE_RATE = 0x02, // F/F2/X/XHD + FLAG_GAMMA = 0x04, + FLAG_GAMMA_RATE = 0x08, // F/F2/X/XHD + FLAG_SATURATE = 0x10, + FLAG_AUTO_EXPOSURE = 0x20, + }; + + uint32_t flag; + Fcurve fcurve_exposure; + Fcurve fcurve_exposure_rate; // F/F2/X/XHD + Fcurve fcurve_gamma; + Fcurve fcurve_gamma_rate; // F/F2/X/XHD + Fcurve fcurve_saturate; + Fcurve fcurve_auto_exposure; + + float_t exposure; + float_t exposure_rate; // F/F2/X/XHD + float_t gamma; + float_t gamma_rate; // F/F2/X/XHD + float_t saturate; + float_t auto_exposure; + + CameraAuxiliary(); + CameraAuxiliary(const CameraAuxiliary& other); + ~CameraAuxiliary(); + + void init(); + bool has_exposure() const; + bool has_exposure_rate() const; // F/F2/X/XHD + bool has_gamma() const; + bool has_gamma_rate() const; // F/F2/X/XHD + bool has_saturate() const; + bool has_auto_exposure() const; + void get(float_t in_frame); + void ctrl(Scene& in_scene, render_context* rctx); + void dest(render_context* rctx); + + bool load(const SceneFile& in_file, const a3d::CameraAuxiliary& in_ca); + void store(const SceneFile& in_file, a3d::CameraAuxiliary& out_ca) const; // Added + + CameraAuxiliary& operator=(const CameraAuxiliary& other); + }; + + class CameraInterest { + public: + ModelTransform model_transform; + + CameraInterest(); + CameraInterest(const CameraInterest& other); + ~CameraInterest(); + + void init(); + + bool load(const SceneFile& in_file, const a3d::CameraInterest& in_ci); + void store(const SceneFile& in_file, a3d::CameraInterest& in_ci) const; // Added + + CameraInterest& operator=(const CameraInterest& other); + }; + + class CameraViewPoint { + public: + ModelTransform model_transform; + Fcurve roll; + bool has_fov; + bool fov_is_horizontal; + Fcurve fov; + float_t aspect; + Fcurve focal_length; + float_t camera_aperture_w; + float_t camera_aperture_h; + + CameraViewPoint(); + CameraViewPoint(const CameraViewPoint& other); + ~CameraViewPoint(); + + void init(); + float_t get_v_fov(float_t in_frame); + + bool load(const SceneFile& in_file, const a3d::CameraViewPoint& in_cvp); + void store(const SceneFile& in_file, a3d::CameraViewPoint& out_cvp) const; // Added + + CameraViewPoint& operator=(const CameraViewPoint& other); + }; + + class CameraRoot { + public: + ModelTransform model_transform; + CameraInterest interest; + CameraViewPoint view_point; + + CameraRoot(); + CameraRoot(const CameraRoot& other); + ~CameraRoot(); + + void init(); + CameraParam get(float_t in_frame, const Scene& in_scene, render_context* rctx); + + bool load(const SceneFile& in_file, const a3d::CameraRoot& in_cr); + void store(const SceneFile& in_file, a3d::CameraRoot& out_cr) const; // Added + + CameraRoot& operator=(const CameraRoot& other); + + }; + + class Chara { + public: + std::string name; + ModelTransform model_transform; + int32_t rob_id; + + Chara(); + Chara(const Chara& other); + ~Chara(); + + void get(float_t in_frame); + void ctrl(Scene& in_scene); + void disp(const Scene& in_scene, const mat4& in_base_mat, render_context* rctx); + + void set_disp_freeze(bool in_value) const; + bool is_bind() const; + + bool load(const SceneFile& in_file, const a3d::Chara& in_c); + void store(const SceneFile& in_file, a3d::Chara& out_c) const; // Added + + Chara& operator=(const Chara& other); + }; + + class Curve { + public: + Fcurve curve; + std::string name; + float_t value; + + Curve(); + Curve(const Curve& other); + ~Curve(); + + void get(float_t in_frame); + Fcurve* M_get_fcurve(); + + bool load(const SceneFile& in_file, const a3d::Curve& in_c); + void store(const SceneFile& in_file, a3d::Curve& out_c) const; // Added + + Curve& operator=(const Curve& other); + }; + + class CurveWithOffset { + public: + Curve* fcurve_ptr; + std::string name; + float_t offset; + float_t value; + + CurveWithOffset(); + CurveWithOffset(const CurveWithOffset& other); + ~CurveWithOffset(); + + void init(); + void bind(Curve& in_c); + void get(float_t in_frame); + bool is_valid() const; + + CurveWithOffset& operator=(const CurveWithOffset& other); + }; + + class Dof { + public: + bool has_dof; + ModelTransform model_transform; + + Dof(); + Dof(const Dof& other); + ~Dof(); + + void init(); + void get(float_t in_frame); + void ctrl(render_context* rctx); + void dest(render_context* rctx); + + bool load(const SceneFile& in_file, const a3d::Dof& in_d); + void store(const SceneFile& in_file, a3d::Dof& out_d) const; // Added + + Dof& operator=(const Dof& other); + }; + + class Event { + public: + bool active; + EVENT_TYPE type; + std::string name; + size_t index; float_t begin; float_t end; std::string param1; std::string ref; - size_t index; + size_t ref_index; - Event(a3da_event* e); + Event(const a3d::Event& in_e); virtual ~Event(); - virtual void Load(auth_3d* auth); - virtual void Begin(auth_3d* auth, int32_t flags, render_context* rctx); - virtual void End(auth_3d* auth, int32_t flags, render_context* rctx); - virtual void Ctrl(auth_3d* auth, int32_t flags, render_context* rctx); - virtual void Disp(auth_3d* auth, const mat4* mat, render_context* rctx); + virtual void resolve_relation(const Scene& in_scene); + virtual void entry(const Scene& in_scene, EventActionFlag in_eaf, render_context* rctx); + virtual void exit(const Scene& in_scene, EventActionFlag in_eaf, render_context* rctx); + virtual void do_ctrl(const Scene& in_scene, EventActionFlag in_eaf, render_context* rctx); + virtual void do_disp(const Scene& in_scene, const mat4& in_mat, render_context* rctx); + + void store(const SceneFile& in_file, a3d::Event& out_e) const; // Added }; - struct EventA2d : public Event { + class EventA2d : public Event { public: - struct Aet { - AetArgs args; - int32_t id; + aet::IdHandle M_a2d_handle; - inline Aet() { - id = -1; - } - - void Free(); - void Init(); - EventA2d::Aet& SetArgs(const AetArgs& value); - }; - - Aet aet_args; - - EventA2d(a3da_event* e); + EventA2d(const a3d::Event& in_e); virtual ~EventA2d() override; - virtual void Begin(auth_3d* auth, int32_t flags, render_context* rctx) override; - virtual void End(auth_3d* auth, int32_t flags, render_context* rctx) override; - virtual void Ctrl(auth_3d* auth, int32_t flags, render_context* rctx) override; - virtual void Disp(auth_3d* auth, const mat4* mat, render_context* rctx) override; + virtual void entry(const Scene& in_scene, EventActionFlag in_eaf, render_context* rctx) override; + virtual void exit(const Scene& in_scene, EventActionFlag in_eaf, render_context* rctx) override; + virtual void do_ctrl(const Scene& in_scene, EventActionFlag in_eaf, render_context* rctx) override; + virtual void do_disp(const Scene& in_scene, const mat4& in_mat, render_context* rctx) override; }; - struct EventFX : public Event { + class EventFX : public Event { public: - EventFX(a3da_event* e); + EventFX(const a3d::Event& in_e); virtual ~EventFX() override; - virtual void Load(auth_3d* auth) override; - virtual void Begin(auth_3d* auth, int32_t flags, render_context* rctx) override; - virtual void Ctrl(auth_3d* auth, int32_t flags, render_context* rctx) override; + virtual void resolve_relation(const Scene& in_scene) override; + virtual void entry(const Scene& in_scene, EventActionFlag in_eaf, render_context* rctx) override; + virtual void do_ctrl(const Scene& in_scene, EventActionFlag in_eaf, render_context* rctx) override; }; - struct EventFXSmoothCut : public Event { + class EventFXSmoothCut : public Event { public: - bool cam; + bool is_camera; - EventFXSmoothCut(a3da_event* e); + EventFXSmoothCut(const a3d::Event& in_e); virtual ~EventFXSmoothCut() override; - virtual void Load(auth_3d* auth) override; - virtual void Begin(auth_3d* auth, int32_t flags, render_context* rctx) override; - virtual void End(auth_3d* auth, int32_t flags, render_context* rctx) override; - virtual void Disp(auth_3d* auth, const mat4* mat, render_context* rctx) override; + virtual void resolve_relation(const Scene& in_scene); + virtual void entry(const Scene& in_scene, EventActionFlag in_eaf, render_context* rctx) override; + virtual void exit(const Scene& in_scene, EventActionFlag in_eaf, render_context* rctx) override; + virtual void do_disp(const Scene& in_scene, const mat4& in_mat, render_context* rctx) override; }; - struct EventFilterFade : public Event { + class EventFilterFade : public Event { public: enum Type { FADE_NONE = -1, - FADE_OUT = 0, - FADE_IN = 1, + FADE_OUT = 0, + FADE_IN = 1, }; - Type type; - vec3 color; + Type fade_type; + vec3 fade_color; - EventFilterFade(a3da_event* e); + EventFilterFade(const a3d::Event& in_e); virtual ~EventFilterFade() override; - virtual void Begin(auth_3d* auth, int32_t flags, render_context* rctx) override; - virtual void End(auth_3d* auth, int32_t flags, render_context* rctx) override; - virtual void Disp(auth_3d* auth, const mat4* mat, render_context* rctx) override; + virtual void entry(const Scene& in_scene, EventActionFlag in_eaf, render_context* rctx) override; + virtual void exit(const Scene& in_scene, EventActionFlag in_eaf, render_context* rctx) override; + virtual void do_disp(const Scene& in_scene, const mat4& in_mat, render_context* rctx) override; }; - struct EventFilterTimeStop : public Event { + class EventFilterTimeStop : public Event { public: - EventFilterTimeStop(a3da_event* e); + EventFilterTimeStop(const a3d::Event& in_e); virtual ~EventFilterTimeStop() override; - virtual void Begin(auth_3d* auth, int32_t flags, render_context* rctx) override; - virtual void End(auth_3d* auth, int32_t flags, render_context* rctx) override; - virtual void Disp(auth_3d* auth, const mat4* mat, render_context* rctx) override; + virtual void entry(const Scene& in_scene, EventActionFlag in_eaf, render_context* rctx) override; + virtual void exit(const Scene& in_scene, EventActionFlag in_eaf, render_context* rctx) override; + virtual void do_disp(const Scene& in_scene, const mat4& in_mat, render_context* rctx) override; }; - struct EventMot : public Event { + class EventMot : public Event { public: - EventMot(a3da_event* e); + EventMot(const a3d::Event& in_e); virtual ~EventMot() override; - virtual void Load(auth_3d* auth) override; - virtual void Begin(auth_3d* auth, int32_t flags, render_context* rctx) override; - virtual void End(auth_3d* auth, int32_t flags, render_context* rctx) override; - virtual void Ctrl(auth_3d* auth, int32_t flags, render_context* rctx) override; - virtual void Disp(auth_3d* auth, const mat4* mat, render_context* rctx) override; + virtual void resolve_relation(const Scene& in_scene) override; + virtual void entry(const Scene& in_scene, EventActionFlag in_eaf, render_context* rctx) override; + virtual void exit(const Scene& in_scene, EventActionFlag in_eaf, render_context* rctx) override; + virtual void do_ctrl(const Scene& in_scene, EventActionFlag in_eaf, render_context* rctx) override; + virtual void do_disp(const Scene& in_scene, const mat4& in_mat, render_context* rctx) override; }; - struct EventSnd : public Event { + class EventSnd : public Event { public: - bool field_190; + bool is_pseudo; - EventSnd(a3da_event* e); + EventSnd(const a3d::Event& in_e); virtual ~EventSnd() override; - virtual void Load(auth_3d* auth) override; - virtual void Begin(auth_3d* auth, int32_t flags, render_context* rctx) override; - virtual void End(auth_3d* auth, int32_t flags, render_context* rctx) override; - virtual void Disp(auth_3d* auth, const mat4* mat, render_context* rctx) override; + virtual void resolve_relation(const Scene& in_scene); + virtual void entry(const Scene& in_scene, EventActionFlag in_eaf, render_context* rctx) override; + virtual void exit(const Scene& in_scene, EventActionFlag in_eaf, render_context* rctx) override; + virtual void do_disp(const Scene& in_scene, const mat4& in_mat, render_context* rctx) override; + }; + + class Fog { + public: + enum { + FLAG_DENSITY = 0x01, + FLAG_START = 0x02, + FLAG_END = 0x04, + FLAG_COLOR = 0x08, + }; + + uint32_t flag; + uint32_t backup_flag; + int32_t id; + std::string name; + + Fcurve fcurve_density; + Fcurve fcurve_start; + Fcurve fcurve_end; + + float_t density; + float_t start; + float_t end; + + Color color; + + float_t backup_density; + float_t backup_start; + float_t backup_end; + vec4 backup_color; + + Fog(); + Fog(const Fog& other); + ~Fog(); + + void init(); + void ctrl(render_context* rctx); + void dest(render_context* rctx); + bool has_density() const; + bool has_start() const; + bool has_end() const; + bool has_color() const; + void get(float_t in_frame); + + bool load(const SceneFile& in_file, const a3d::Fog& in_f); + void store(const SceneFile& in_file, a3d::Fog& out_f) const; // Added + + Fog& operator=(const Fog& other); + }; + + class HierarchyObject { + public: + std::vector node_list; + prj::sys_vector mats; + mat4* ex_node_mat; + std::string name; + std::string uid_name; + object_info obj_uid; + uint32_t obj_hash; + bool is_reflect; + bool is_refract; + bool has_shadow; + std::string parent_name; + std::string parent_node; + std::vector child_object_list; + std::vector child_object_list_parent_node; + std::vector child_object_hrc_list; + std::vector child_object_hrc_list_parent_node; + + HierarchyObject(); + HierarchyObject(const HierarchyObject& other); + ~HierarchyObject(); + + void init(); + void get(float_t in_frame); + void ctrl(const mat4& in_base_mat); + void disp(Scene& in_scene, render_context* rctx); + + void add_child_object(int32_t in_index, Object* in_obj); + void add_child_object(int32_t in_index, HierarchyObject* in_obj); + void assign_object_skin(); + void calc_matrix_hierarchy(const mat4& in_base_mat); + bool replace_chara(int32_t in_cn_src, int32_t in_cn_dst, const object_database* obj_db); + void check_rob_chara(const std::string& in_name); + const mat4& get_root_matrix() const; + void join(const HierarchyObject& in_other, float_t in_blend, float_t in_inv_blend); + void join_lock(const HierarchyObject& in_other, float_t in_blend, float_t in_inv_blend); + void lock_set(); + int32_t query_node_index(const char* in_name) const; + void set_obj_uid(object_info objuid); + + bool load(const SceneFile& in_file, + const a3d::ObjectHrc& in_oh, const object_database* obj_db); + void store(const SceneFile& in_file, a3d::ObjectHrc& out_oh) const; // Added + + HierarchyObject& operator=(const HierarchyObject& other); + }; + + class Light { + public: + enum { + FLAG_AMBIENT = 0x001, + FLAG_DIFFUSE = 0x002, + FLAG_SPECULAR = 0x004, + FLAG_TONE_CURVE = 0x008, + + // XHD + FLAG_CONSTANT = 0x010, + FLAG_INTENSITY = 0x020, + FLAG_FAR = 0x040, + FLAG_LINEAR = 0x080, + FLAG_QUADRATIC = 0x100, + FLAG_DROP_OFF = 0x200, + FLAG_CONE_ANGLE = 0x400, + }; + + uint32_t flag; + uint32_t backup_flag; + int32_t id; + std::string name; + std::string type; + + ModelTransform position; + ModelTransform spot_direction; + Color ambient; + Color diffuse; + Color specular; + Color tone_curve; + + // XHD + Fcurve fcurve_constant; + Fcurve fcurve_intensity; + Fcurve fcurve_far; + Fcurve fcurve_linear; + Fcurve fcurve_quadratic; + Fcurve fcurve_drop_off; + Fcurve fcurve_cone_angle; + + // XHD + float_t constant; + float_t intensity; + float_t far_; // MS... + float_t linear; + float_t quadratic; + float_t drop_off; + float_t cone_angle; + + vec4 backup_ambient; + vec4 backup_diffuse; + vec4 backup_specular; + light_tone_curve backup_tone_curve; + + // XHD + float_t backup_constant; + float_t backup_intensity; + float_t backup_far; + float_t backup_linear; + float_t backup_quadratic; + float_t backup_drop_off; + float_t backup_cone_angle; + + Light(); + Light(const Light& other); + ~Light(); + + void init(); + void ctrl(render_context* rctx); + void dest(render_context* rctx); + bool has_ambient() const; + bool has_diffuse() const; + bool has_specular() const; + bool has_tone_curve() const; + bool has_constant() const; // XHD + bool has_intensity() const; // XHD + bool has_far() const; // XHD + bool has_linear() const; // XHD + bool has_quadratic() const; // XHD + bool has_drop_off() const; // XHD + bool has_cone_angle() const; // XHD + void get(float_t in_frame); + + bool load(const SceneFile& in_file, const a3d::Light& in_l); + void store(const SceneFile& in_file, a3d::Light& out_l) const; // Added + + Light& operator=(const Light& other); + }; + + // X/XHD + class MaterialList { + public: + enum { + FLAG_EMISSION = 0x01, + FLAG_BLEND_COLOR = 0x02, + FLAG_GLOW_INTENSITY = 0x04, + }; + + uint32_t flag; + std::string name; + uint32_t hash; + + Color emission; + Color blend_color; + Fcurve fcurve_glow_intensity; + + float_t glow_intensity; + + MaterialList(); + MaterialList(const MaterialList& other); + ~MaterialList(); + + void init(); + bool has_emission() const; + bool has_blend_color() const; + bool has_glow_intensity() const; + void get(float_t in_frame); + + bool load(const SceneFile& in_file, const a3d::MaterialList& in_ml); + void store(const SceneFile& in_file, a3d::MaterialList& out_ml) const; // Added + + MaterialList& operator=(const MaterialList& other); + }; + + class Motion { + public: + std::string name; + + Motion(); + Motion(const Motion& other); + ~Motion(); + + bool load(const SceneFile& in_file, const a3d::Motion& in_m); + void store(const SceneFile& in_file, a3d::Motion& out_m) const; // Added + + Motion& operator=(const Motion& other); + }; + + class MotionTransform { + public: + mat4 matrix; + mat4 matrix_local; + + Fcurve3f fcurve_translation; + Fcurve3f fcurve_rotation; + Fcurve3f fcurve_scale; + Fcurve fcurve_visibility; + + vec3 translation; + vec3 rotation; + vec3 scale; + bool visibility; + + mat4 rot; + + vec3 trans_lock; + mat4 rot_lock; + vec3 scale_lock; + + float_t frame; + bool update_rot; + bool matrix_local_ready; + bool has_scale; + bool has_visibility; + + MotionTransform(); + MotionTransform(const MotionTransform& other); + ~MotionTransform(); + + void init(); + void init_static(); + void get(float_t in_frame); + + void calc_matrix(const mat4& in_mat); + void calc_matrix_local(); + + void check_scale(); + void check_visibility(); + + void join(const MotionTransform& in_mt1, + const MotionTransform& in_mt2, float_t in_inv_blend, float_t in_blend); + void join( + const MotionTransform& in_other, float_t in_inv_blend, float_t in_blend); + void join_lock(const MotionTransform& in_mt1, + const MotionTransform& in_mt2, float_t in_inv_blend, float_t in_blend); + void join_lock( + const MotionTransform& in_other, float_t in_inv_blend, float_t in_blend); + + void lock_set(); + + void add(const MotionTransform& in_mt1, const MotionTransform& in_mt2); + void sub(const MotionTransform& in_mt1, const MotionTransform& in_mt2); + + bool load(const SceneFile& in_file, const a3d::ModelTransform& in_mt); + void store(const SceneFile& in_file, a3d::ModelTransform& out_mt) const; // Added + + MotionTransform& operator=(const MotionTransform& other); + }; + + class MultiHierarchyObject { + public: + std::string name; + MotionTransform motion_transform; + std::vector node_list; + std::vector instance_list; + + MultiHierarchyObject(); + MultiHierarchyObject(const MultiHierarchyObject& other); + ~MultiHierarchyObject(); + + void init(); + void get(float_t in_frame); + void ctrl(const mat4& in_base_mat); + void disp(Scene& in_scene, render_context* rctx); + + void calc_matrix_hierarchy(); + void calc_matrix_local(); + const mat4& get_root_matrix() const; + + bool load(const SceneFile& in_file, const a3d::MObjectHrc& in_moh, + const object_database* obj_db); + void store(const SceneFile& in_file, a3d::MObjectHrc& out_moh) const; // Added + + MultiHierarchyObject& operator=(const MultiHierarchyObject& other); + }; + + class Object { + public: + ModelTransform model_transform; + size_t index; + std::string name; + std::string uid_name; + std::string parent_name; + std::string parent_node; + CurveWithOffset obj_pat; + CurveWithOffset obj_morph; + std::vector texture_list; + std::vector texture_transform_list; + std::vector child_object_list; + std::vector child_object_hrc_list; + object_info obj_uid; + uint32_t obj_hash; + bool is_reflect; + bool is_refract; + + Object(); + Object(const Object& other); + ~Object(); + + void init(); + void get(float_t in_frame); + void ctrl(const mat4& in_base_mat); + void disp(Scene& in_scene, render_context* rctx); + + bool replace_chara(int32_t in_cn_src, int32_t in_cn_dst, const object_database* obj_db); + void prepare_morph(const object_database* obj_db); // Added + + bool load(const SceneFile& in_file, const a3d::Object& in_o, + const object_database* obj_db, const texture_database* tex_db); + void store(const SceneFile& in_file, a3d::Object& out_o) const; // Added + + Object& operator=(const Object& other); + }; + + class ObjectInstance { + public: + std::string name; + std::string uid_name; + object_info obj_uid; + uint32_t obj_hash; + bool shadow; + MotionTransform motion_transform; + std::vector matrix_id; + prj::sys_vector mats; + + ObjectInstance(); + ObjectInstance(const ObjectInstance& other); + ~ObjectInstance(); + + void init(); + void get(float_t in_frame); + + bool load(const SceneFile& in_file, const a3d::ObjectInstance& in_oi, + const MultiHierarchyObject& in_moh, const object_database* obj_db); + void store(const SceneFile& in_file, a3d::ObjectInstance& out_oi, + const MultiHierarchyObject& in_moh) const; // Added + + ObjectInstance& operator=(const ObjectInstance& other); + }; + + class PlayControl { + public: + enum { + FLAG_DIV = 0x01, // F2/X/XHD + FLAG_OFFSET = 0x02, + }; + + uint32_t flag; + float_t begin; + int32_t div; // F2/X/XHD + float_t fps; + float_t offset; // F2/X/XHD + float_t size; + + PlayControl(); + PlayControl(const PlayControl& other); + ~PlayControl(); + + void init(); + + bool load(const SceneFile& in_file, const a3d::PlayControl& in_pc); + void store(const SceneFile& in_file, a3d::PlayControl& out_pc) const; // Added + + PlayControl& operator=(const PlayControl& other); + }; + + class Point { + public: + std::string name; + ModelTransform model_transform; + + Point(); + Point(const Point& other); + ~Point(); + + void get(float_t frame); + void disp(const Scene& in_scene, render_context* rctx); + + bool load(const SceneFile& in_file, const a3d::Point& in_p); + void store(const SceneFile& in_file, a3d::Point& out_p) const; // Added + + Point& operator=(const Point& other); + }; + + class PostProcess { + public: + enum { + FLAG_LENS_FLARE = 0x01, + FLAG_LENS_SHAFT = 0x02, + FLAG_LENS_GHOST = 0x04, + FLAG_RADIUS = 0x08, + FLAG_INTENSITY = 0x10, + FLAG_SCENE_FADE = 0x20, + }; + + uint32_t flag; + uint32_t backup_flag; + Fcurve fcurve_lens_flare; + Fcurve fcurve_lens_shaft; + Fcurve fcurve_lens_ghost; + Color radius; + Color intensity; + Color scene_fade; + + float_t backup_lens_flare; + float_t backup_lens_shaft; + float_t backup_lens_ghost; + vec4 backup_radius; + vec4 backup_intensity; + vec4 backup_scene_fade; + + float_t lens_flare; + float_t lens_shaft; + float_t lens_ghost; + + PostProcess(); + PostProcess(const PostProcess& other); + ~PostProcess(); + + void init(); + bool has_lens() const; + bool has_lens_flare() const; + bool has_lens_shaft() const; + bool has_lens_ghost() const; + bool has_radius() const; + bool has_intensity() const; + bool has_scene_fade() const; + void get(float_t in_frame); + void ctrl(Scene& in_scene, render_context* rctx); + void dest(render_context* rctx); + + bool load(const SceneFile& in_file, const a3d::PostProcess& in_pp); + void store(const SceneFile& in_file, a3d::PostProcess& out_pp) const; // Added + + PostProcess& operator=(const PostProcess& other); + }; + + class Texture { + public: + std::string name; + uint32_t tex_uid; + CurveWithOffset tex_pat; + + Texture(); + Texture(const Texture& other); + ~Texture(); + + void init(); + void get(float_t in_frame); + + bool load(const SceneFile& in_file, + const a3d::Texture& in_t, const texture_database* tex_db); + void store(const SceneFile& in_file, a3d::Texture& out_t) const; // Added + + Texture& operator=(const Texture& other); + }; + + class TextureTransform { + public: + enum { + FLAG_COVERAGE_U = 0x001, + FLAG_COVERAGE_V = 0x002, + FLAG_REPEAT_U = 0x004, + FLAG_REPEAT_V = 0x008, + FLAG_TRANSLATE_FRAME_U = 0x010, + FLAG_TRANSLATE_FRAME_V = 0x020, + FLAG_OFFSET_U = 0x040, + FLAG_OFFSET_V = 0x080, + FLAG_ROTATE_FRAME = 0x100, + FLAG_ROTATE = 0x200, + }; + + uint32_t flag; + uint32_t backup_flag; + std::string name; + uint32_t tex_uid; + + Fcurve fcurve_coverage_u; + Fcurve fcurve_coverage_v; + Fcurve fcurve_repeat_u; + Fcurve fcurve_repeat_v; + Fcurve fcurve_translate_frame_u; + Fcurve fcurve_translate_frame_v; + Fcurve fcurve_offset_u; + Fcurve fcurve_offset_v; + Fcurve fcurve_rotate_frame; + Fcurve fcurve_rotate; + + mat4 mat; + vec3 scale; + vec3 repeat; + vec3 rotate; + vec3 translate_frame; + + TextureTransform(); + TextureTransform(const TextureTransform& other); + ~TextureTransform(); + + void init(); + bool has_coverage_u() const; + bool has_coverage_v() const; + bool has_repeat_u() const; + bool has_repeat_v() const; + bool has_translate_frame_u() const; + bool has_translate_frame_v() const; + bool has_offset_u() const; + bool has_offset_v() const; + bool has_rotate_frame() const; + bool has_rotate() const; + void get(float_t frame); + void mul(); + + bool load(const SceneFile& in_file, + const a3d::TextureTransform& in_tt, const texture_database* tex_db); + void store(const SceneFile& in_file, a3d::TextureTransform& out_tt) const; // Added + + TextureTransform& operator=(const TextureTransform& other); + }; + + struct TimeEvent { + float_t frame; + int32_t type; + size_t event_index; + }; + + class TransformNode { + public: + enum { + FLAG_JOINT_ORIENT = 0x01, + }; + + uint32_t flag; + std::string name; + int32_t node_index; + int32_t parent_id; + MotionTransform motion_transform; + mat4* mat_ptr; + vec3 joint_orient; + mat4 joint_orient_mat; + + TransformNode(); + TransformNode(const TransformNode& other); + ~TransformNode(); + + void init(); + void get(float_t in_frame); + + void calc_matrix_local(const mat4& in_base_mat); + + bool load(const SceneFile& in_file, const a3d::ObjectNode& in_on); + void store(const SceneFile& in_file, a3d::ObjectNode& out_on) const; // Added + + TransformNode& operator=(const TransformNode& other); }; } -struct auth_3d_key { - auth_3d_key_type type; - float_t value; - float_t max_frame; - auth_3d_ep_type ep_type_pre; - auth_3d_ep_type ep_type_post; - float_t frame_delta; - float_t value_delta; - std::vector keys_vec; - size_t length; - kft3* keys; - - float_t frame; - float_t value_interp; - float_t value_init; - - auth_3d_key(); - auth_3d_key(const auth_3d_key& k); - ~auth_3d_key(); - - float_t interpolate(float_t frame); - void reset(); - - auth_3d_key& operator=(const auth_3d_key& k); -}; - -struct auth_3d_rgba { - auth_3d_rgba_flags flags; - auth_3d_key r; - auth_3d_key g; - auth_3d_key b; - auth_3d_key a; - - vec4 value; - - auth_3d_rgba(); - ~auth_3d_rgba(); - - void interpolate(float_t frame); - void reset(); -}; - -struct auth_3d_vec3 { - auth_3d_key x; - auth_3d_key y; - auth_3d_key z; - - auth_3d_vec3(); - ~auth_3d_vec3(); - - vec3 interpolate(float_t frame); - void reset(); -}; - -struct auth_3d_model_transform { - mat4 mat; - auth_3d_vec3 scale; - auth_3d_vec3 rotation; - auth_3d_vec3 translation; - auth_3d_key visibility; - - vec3 scale_value; - vec3 rotation_value; - vec3 translation_value; - bool visible; - - auth_3d_model_transform(); - ~auth_3d_model_transform(); - - void interpolate(float_t frame); - void reset(); - void set_mat(const mat4* parent_mat); -}; - -struct auth_3d_ambient { - auth_3d_ambient_flags flags; - auth_3d_rgba light_diffuse; - std::string name; - auth_3d_rgba rim_light_diffuse; - - auth_3d_ambient(); - ~auth_3d_ambient(); - - void interpolate(float_t frame); - void reset(); -}; - -struct auth_3d_camera_auxiliary { - auth_3d_camera_auxiliary_flags flags; - auth_3d_key auto_exposure; - auth_3d_key exposure; - auth_3d_key exposure_rate; - auth_3d_key gamma; - auth_3d_key gamma_rate; - auth_3d_key saturate; - - float_t auto_exposure_value; - float_t exposure_value; - float_t exposure_rate_value; - float_t gamma_value; - float_t gamma_rate_value; - float_t saturate_value; - - auth_3d_camera_auxiliary(); - ~auth_3d_camera_auxiliary(); - - void interpolate(float_t frame); - void reset(); -}; - -struct auth_3d_camera_root_view_point { - auth_3d_camera_root_view_point_flags flags; - float_t aspect; - float_t camera_aperture_h; - float_t camera_aperture_w; - auth_3d_key focal_length; - auth_3d_key fov; - bool fov_is_horizontal; - auth_3d_model_transform model_transform; - auth_3d_key roll; - - auth_3d_camera_root_view_point(); - ~auth_3d_camera_root_view_point(); - - void reset(); -}; - -struct auth_3d_camera_root { - auth_3d_model_transform interest; - auth_3d_model_transform model_transform; - auth_3d_camera_root_view_point view_point; - - float_t fov_value; - vec3 interest_value; - float_t roll_value; - vec3 view_point_value; - - auth_3d_camera_root(); - ~auth_3d_camera_root(); - - void interpolate(float_t frame); - void reset(); -}; - -struct auth_3d_chara { - auth_3d_model_transform model_transform; - std::string name; - int32_t rob_id; - - auth_3d_chara(); - ~auth_3d_chara(); - - void interpolate(float_t frame); - void reset(); -}; - -struct auth_3d_curve { - auth_3d_key curve; - std::string name; - float_t value; - - auth_3d_curve(); - ~auth_3d_curve(); - - void interpolate(float_t frame); - void reset(); -}; - -struct auth_3d_dof { - bool has_dof; - auth_3d_model_transform model_transform; - - auth_3d_dof(); - ~auth_3d_dof(); - - void interpolate(float_t frame); - void reset(); -}; - -struct auth_3d_fog { - auth_3d_fog_flags flags; - auth_3d_fog_flags flags_init; - auth_3d_rgba color; - auth_3d_key density; - auth_3d_key end; - fog_id id; - auth_3d_key start; - - float_t density_value; - float_t end_value; - float_t start_value; - - vec4 color_init; - float_t density_init; - float_t end_init; - float_t start_init; - - auth_3d_fog(); - ~auth_3d_fog(); - - void interpolate(float_t frame); - void reset(); -}; - -struct auth_3d_light { - auth_3d_light_flags flags; - auth_3d_light_flags flags_init; - auth_3d_rgba ambient; - auth_3d_key cone_angle; - auth_3d_key constant; - auth_3d_rgba diffuse; - auth_3d_key drop_off; - auth_3d_key _far; - light_id id; - auth_3d_key intensity; - auth_3d_key linear; - auth_3d_model_transform position; - auth_3d_key quadratic; - auth_3d_rgba specular; - auth_3d_model_transform spot_direction; - auth_3d_rgba tone_curve; - std::string type; - - float_t cone_angle_value; - float_t constant_value; - float_t drop_off_value; - float_t far_value; - float_t intensity_value; - float_t linear_value; - float_t quadratic_value; - - vec4 ambient_init; - float_t cone_angle_init; - float_t constant_init; - vec4 diffuse_init; - float_t drop_off_init; - float_t far_init; - float_t intensity_init; - float_t linear_init; - float_t quadratic_init; - vec4 specular_init; - light_tone_curve tone_curve_init; - - auth_3d_light(); - ~auth_3d_light(); - - void interpolate(float_t frame); - void reset(); -}; - -struct auth_3d_object_model_transform { - mat4 mat; - mat4 mat_inner; - mat4 mat_rot; - auth_3d_vec3 translation; - auth_3d_vec3 rotation; - auth_3d_vec3 scale; - auth_3d_key visibility; - - vec3 translation_value; - vec3 rotation_value; - vec3 scale_value; - bool visible; - float_t frame; - bool has_rotation; - bool has_translation; - bool has_scale; - bool has_visibility; - - auth_3d_object_model_transform(); - ~auth_3d_object_model_transform(); - - void interpolate(float_t frame); - void mat_mult(const mat4* mat); - void reset(); -}; - -struct auth_3d_m_object_hrc { - std::vector instance; - auth_3d_object_model_transform model_transform; - std::string name; - std::vector node; - - auth_3d_m_object_hrc(); - ~auth_3d_m_object_hrc(); - - void interpolate(float_t frame); - void list_ctrl(const mat4* parent_mat); - void reset(); -}; - -struct auth_3d_material_list { - auth_3d_material_list_flags flags; - auth_3d_rgba blend_color; - auth_3d_key glow_intensity; - auth_3d_rgba emission; - std::string name; - uint32_t hash; - - float_t glow_intensity_value; - - auth_3d_material_list(); - ~auth_3d_material_list(); - - void interpolate(float_t frame); - void reset(); -}; - -struct auth_3d_object_curve { - auth_3d_curve* curve; - std::string name; - float_t frame_offset; - float_t value; - - auth_3d_object_curve(); - ~auth_3d_object_curve(); - - void interpolate(float_t frame); - void reset(); -}; - -struct auth_3d_object { - std::vector children_object; - std::vector children_object_hrc; - auth_3d_model_transform model_transform; - auth_3d_object_curve morph; - object_info object_info; - uint32_t object_hash; - std::string name; - std::string parent_name; - std::string parent_node; - auth_3d_object_curve pattern; - bool reflect; - bool refract; - std::vector texture_pattern; - std::vector texture_transform; - std::string uid_name; - - auth_3d_object(); - ~auth_3d_object(); - - void interpolate(float_t frame); - void list_ctrl(const mat4* parent_mat); - void reset(); -}; - -struct auth_3d_object_hrc { - std::vector children_object; - std::vector children_object_hrc; - std::vector children_object_parent_node; - std::vector children_object_hrc_parent_node; - prj::sys_vector mats; - std::string name; - std::vector node; - object_info object_info; - uint32_t object_hash; - std::string parent_name; - std::string parent_node; - bool reflect; - bool refract; - bool shadow; - std::string uid_name; - - auth_3d_object_hrc(); - ~auth_3d_object_hrc(); - - int32_t get_node_index(const char* node); - void interpolate(float_t frame); - void list_ctrl(const mat4* parent_mat); - void reset(); -}; - -struct auth_3d_object_instance { - prj::sys_vector mats; - auth_3d_object_model_transform model_transform; - std::string name; - std::vector object_bone_indices; - object_info object_info; - uint32_t object_hash; - bool shadow; - std::string uid_name; - - auth_3d_object_instance(); - ~auth_3d_object_instance(); - - void interpolate(float_t frame); - void reset(); -}; - -struct auth_3d_object_node { - auth_3d_object_node_flags flags; - int32_t bone_id; - vec3 joint_orient; - mat4 joint_orient_mat; - mat4* mat; - auth_3d_object_model_transform model_transform; - std::string name; - int32_t parent; - - auth_3d_object_node(); - ~auth_3d_object_node(); - - void interpolate(float_t frame); - void reset(); -}; - -struct auth_3d_object_texture_pattern { - std::string name; - auth_3d_object_curve pattern; - int32_t texture_id; - - auth_3d_object_texture_pattern(); - ~auth_3d_object_texture_pattern(); - - void interpolate(float_t frame); - void reset(); -}; - -struct auth_3d_object_texture_transform { - auth_3d_object_texture_transform_flags flags; - auth_3d_key coverage_u; - auth_3d_key coverage_v; - mat4 mat; - std::string name; - auth_3d_key offset_u; - auth_3d_key offset_v; - auth_3d_key repeat_u; - auth_3d_key repeat_v; - auth_3d_key rotate; - auth_3d_key rotate_frame; - int32_t texture_id; - auth_3d_key translate_frame_u; - auth_3d_key translate_frame_v; - - auth_3d_object_texture_transform(); - ~auth_3d_object_texture_transform(); - - void interpolate(float_t frame); - void reset(); -}; - -struct auth_3d_play_control { - auth_3d_play_control_flags flags; - float_t begin; - int32_t div; - float_t fps; - float_t offset; - float_t size; - - auth_3d_play_control(); - ~auth_3d_play_control(); - - void reset(); -}; - -struct auth_3d_point { - auth_3d_model_transform model_transform; - std::string name; - - auth_3d_point(); - ~auth_3d_point(); - - void interpolate(float_t frame); - void reset(); -}; - -struct auth_3d_post_process { - auth_3d_post_process_flags flags; - auth_3d_post_process_flags flags_init; - auth_3d_rgba intensity; - auth_3d_key lens_flare; - auth_3d_key lens_ghost; - auth_3d_key lens_shaft; - auth_3d_rgba radius; - auth_3d_rgba scene_fade; - - vec3 lens_value; - - vec3 intensity_init; - vec3 lens_init; - vec3 radius_init; - vec4 scene_fade_init; - - auth_3d_post_process(); - ~auth_3d_post_process(); - - void interpolate(float_t frame); - void reset(); -}; - -struct auth_3d_time_event { - float_t frame; - int32_t type; - size_t event_index; -}; - -struct auth_3d_id { - int32_t id; - - inline auth_3d_id() { - id = -1; +namespace auth_3d_detail { + class DB { + public: + + DB(); + ~DB(); + }; + + class CategoryData { + public: + int32_t ref_count; + std::string category_name; + LoadState load_state; + std::string path; + std::string file; + p_file_handler file_handler; + farc* ar; + const void* raw_data; + size_t raw_size; + + private: + void M_load_req(const char* in_mdata_dir); + void M_load_req_modern(void* data); // Added + void M_free(); + + static bool S_load_cb(CategoryData* data, const void* file_data, size_t file_size); + + public: + CategoryData(); + CategoryData(const CategoryData& other); + ~CategoryData(); + + void load_req(const char* in_mdata_dir); + void load_req_modern(void* data); // Added + void free(); + std::tuple get_file(const std::string& in_name); + std::tuple get_file(uint32_t in_hash); // Added + bool load_is_done() const; + + CategoryData& operator=(const CategoryData& other); + }; + + class SceneFile { + public: + float_t frame_max; + const void* raw_data; + size_t raw_size; + bool has_raw; + a3d::Scene prop; + bool prop_is_ready; + + SceneFile(); + SceneFile(const SceneFile& other); + ~SceneFile(); + + void load(const void* in_data, size_t in_size); + void clear(); + + SceneFile& operator=(const SceneFile& other); + }; + + class UidData { + public: + int32_t ref_count; + int32_t uid; + std::string file_name; + LoadState load_state; + SceneFile file; + const char* name; + CategoryData* category; + + private: + void M_load_req(const auth_3d_database* auth_3d_db); + void M_load_req_category(); + void M_free(); + void M_load_is_done(); + + public: + UidData(); + UidData(const UidData& other); + ~UidData(); + + void load_req(const auth_3d_database* auth_3d_db); + void free(); + bool load_is_done(); + + UidData& operator=(const UidData& other); + }; + + // Added + class UidDataModern { + public: + int32_t ref_count; + uint32_t hash; + std::string file_name; + LoadState load_state; + SceneFile file; + std::string name; + CategoryData* category; + void* data; + const object_database* obj_db; + const texture_database* tex_db; + + private: + void M_load_req(); + void M_load_req_category(); + void M_free(); + void M_load_is_done(); + + public: + UidDataModern(); + UidDataModern(const UidDataModern& other); + ~UidDataModern(); + + void load_req(); + void free(); + bool load_is_done(); + + UidDataModern& operator=(const UidDataModern& other); + }; + + struct ItemTexChange { + uint32_t org_texid; + uint32_t change_texid; + + inline ItemTexChange() : org_texid(-1), change_texid(-1) { + + } + + inline ItemTexChange(uint32_t in_org_texid, uint32_t in_change_texid) + : org_texid(in_org_texid), change_texid(in_change_texid) { + + } + }; + + class Scene { + public: + int32_t M_uid; + int32_t my_handle; + bool M_is_enabled; + bool M_camera_is_enabled; + bool M_is_visible; + bool M_is_looped; + bool M_is_start; + bool M_is_finished; + bool M_is_reverse_side; + bool M_is_auto_disable; + mat4 base_matrix; + float_t trnsl; + mdl::ObjFlags trnsl_state; + bool M_is_attribute_wall; + std::map item_attr_map; + std::vector item_texchg_list; + int32_t M_assign_rob_id; + object_info M_obj_uid; + mat4* M_ex_node_mat; + bool M_shadow; + bool M_chara_item; // Added + bool M_reflect; // Added + int32_t M_cn_src; + int32_t M_cn_dst; + uint32_t M_debug; + uint64_t M_data; + FrameRateControl* M_frc; + float_t M_frame; + float_t frame_req; + float_t frame_max; + bool is_requested_frame; + float_t M_frame_loop_begin; + float_t M_frame_loop_end; + float_t M_fov_adjust; + const std::vector* object_hrc_blend_list; + float_t object_hrc_blend; + bool now_pause; + + std::vector event_list; + std::vector event_time_list; + std::vector::iterator event_time_unread_ptr; + PlayControl play_control; + std::vector point_list; + std::vector curve_list; + std::vector camera_root_list; + CameraAuxiliary camera_auxiliary; + std::vector light_list; + std::vector ambient_list; // MGF + std::vector fog_list; + PostProcess post_process; + Dof dof; + std::vector chara_list; + std::vector motion_list; + std::vector object_holder; + std::vector object_list; + std::vector object_hrc_holder; + std::vector object_hrc_list; + std::vector m_object_hrc_holder; + std::vector m_object_hrc_list; + std::vector adx_sound_list; + std::vector material_list; // X + std::vector object_name_list; + std::vector object_hrc_name_list; + std::vector m_object_hrc_name_list; + std::vector auth_2d_list; + LoadState load_state; + std::vector my_event_listener; + + std::string file_name; + uint32_t hash; + const object_database* obj_db; + const texture_database* tex_db; + + private: + void M_load_exec(); + + public: + Handle to_handle(); + + Scene(); + ~Scene(); + + void init(); + void destroy(render_context* rctx); + int32_t get_uid() const; + void ctrl(render_context* rctx); + void disp(render_context* rctx); + void load_req(const auth_3d_database* auth_3d_db); + void load_req_modern(); // Added + void M_put_obj(const mat4& in_mat, object_info in_id, render_context* rctx) const; + bool load_is_done() const; + void add_event_listener(a3d::EventListener* in_evt_list); + void remove_event_listener(a3d::EventListener* in_evt_list); + void M_loadFromProperties(SceneFile& in_file, + const object_database* in_obj_db, const texture_database* in_tex_db); + void M_storeToProperties(SceneFile& in_file) const; // Added + bool is_valid() const; + void set_frame_rate_control(FrameRateControl* in_value); + float_t get_frame_speed() const; + void set_frame_req(float_t in_frame); + void set_frame_max(float_t in_frame); + float_t get_frame() const; + float_t get_frame_size() const; + float_t get_frame_fps() const; + float_t get_frame_begin() const; + void set_pause(bool in_value); + bool get_pause() const; + void set_enabled(bool in_value); + bool get_enabled() const; + void set_visible(bool in_value); + bool get_visible() const; + void set_looped(bool in_value); + bool get_looped() const; + void set_frame_loop_begin(float_t in_frame); + void set_frame_loop_begin(); + float_t get_frame_loop_begin() const; + void set_frame_loop_end(float_t in_frame); + void set_frame_loop_end(); + float_t get_frame_loop_end() const; + bool is_finished() const; + void set_reverse_side(bool in_value); + bool get_reverse_side() const; + void set_auto_disable(bool in_value); + bool get_auto_disable() const; + void set_base_matrix(const mat4& in_value); + const mat4& get_base_matrix() const; + void set_trnsl(float_t in_value, mdl::ObjFlags in_state); + float_t get_trnsl() const; + void set_attribute_wall(bool in_value); + bool get_attribute_wall() const; + void set_item_attr(uint32_t in_id, uint32_t in_attr); + uint32_t get_item_attr(uint32_t in_id) const; + void set_item_texchange(const std::vector& in_list); + const std::vector& get_item_texchange() const; + size_t get_chara_size() const; + size_t get_chara_index(const std::string& in_name) const; + const std::string* chara_get_name(size_t in_index) const; + void chara_bind_rob(size_t in_index, int32_t in_rob_id); + size_t get_object_size() const; + size_t get_object_index(const std::string& in_name) const; + int32_t get_object_index(object_info in_obj_uid, int32_t in_instance = -1) const; + int32_t get_object_index(uint32_t in_obj_hash, int32_t in_instance = -1) const; + const std::string* object_get_name(size_t in_index) const; + const mat4* get_object_matrix(size_t in_index) const; + const mat4* get_object_matrix(size_t in_index, bool in_is_hrc) const; + size_t get_object_hrc_size() const; + size_t get_object_hrc_index(const std::string& in_name) const; + int32_t get_object_hrc_index(object_info in_obj_uid, int32_t instance = -1) const; + int32_t get_object_hrc_index(uint32_t in_obj_hash, int32_t instance = -1) const; // Added + const std::string* object_hrc_get_name(size_t in_index) const; + const mat4* get_object_hrc_matrix(size_t in_index) const; + size_t get_m_object_hrc_size() const; + size_t get_m_object_hrc_index(const std::string& in_name) const; + const std::string* m_object_hrc_get_name(size_t in_index) const; + void camera_set_enabled(bool in_value); + bool camera_get_enabled() const; + void camera_set_fov_adjust(float_t in_value); + float_t camera_get_fov_adjust() const; + size_t get_auth_2d_size() const; + size_t get_auth_2d_index(const std::string& in_name) const; + const std::string* auth_2d_get_name(size_t in_index) const; + size_t get_point_index(const std::string& in_name) const; + size_t get_curve_index(const std::string& in_name) const; + void set_data(size_t); + size_t get_data() const; + void set_debug(uint32_t in_value); + uint32_t get_debug() const; + void assign_rob_id(int32_t in_value); + int32_t get_assign_rob_id() const; + void set_obj_uid(object_info in_value); + void set_shadow(bool in_value); + bool is_shadow() const; + void replace_chara(int32_t in_cn_src, int32_t in_cn_dst); + void set_frame_object_hrc(float_t in_frame); + void set_object_hrc_blend(const Scene* in_scene, float_t in_value); + void calc_matrix_hierarchy(const mat4& in_value); + void calc_matrix_hierarchy_get(); + void calc_matrix_hierarchy_mul(); + void join(); + void join_lock(); + void set_ex_node_mat(mat4* in_value); + bool is_ex_node_mat() const; + void lock_list_set(); + void set_chara_item(bool in_value); // Added + bool get_chara_item() const; // Added + void set_reflect(bool in_value); // Added + bool get_reflect() const; // Added + }; + + struct Auth3dManager { + DB db; + + std::vector category_data_list; + std::unordered_map category_data_list_modern; + std::vector uid_data_list; + std::unordered_map uid_data_list_modern; + std::vector handle_list; + Scene scene_buffer[AUTH_3D_DATA_COUNT]; + + Auth3dManager(); + ~Auth3dManager(); + + UidData* get_uid_data(int32_t in_uid, const auth_3d_database* auth_3d_db); + UidDataModern* get_uid_data_modern(uint32_t hash); // Added + CategoryData* get_category_data(const char* in_name); + CategoryData* get_category_data_modern(uint32_t in_hash); // Added + void category_free(const char* in_name); + void category_free(uint32_t in_hash); // Added + bool category_load_is_done(const char* in_name); + bool category_load_is_done(uint32_t in_hash); // Added + void category_load_req(const char* in_name, const char* in_mdata_dir); + void category_load_req(void* data, const char* in_name, uint32_t in_hash); // Added + const mat4* get_object_matrix(int32_t in_handle, size_t in_index, bool in_is_hrc) const; + const char* get_name_uid(int32_t in_uid, const auth_3d_database* auth_3d_db) const; + Scene* get_scene(int32_t in_uid); // Added + Scene* get_scene(uint32_t hash); // Added + int32_t get_scene_object_index(object_info in_obj_uid, + int32_t* out_index, bool* out_is_hrc, int32_t in_instance = -1); + int32_t get_scene_object_index(uint32_t in_file_name_hash, uint32_t in_obj_hash, + int32_t* out_index, bool* out_is_hrc, int32_t in_instance = -1); // Added + bool uid_load_req(int32_t in_uid, const auth_3d_database* auth_3d_db); + bool uid_load_req_modern(uint32_t hash); // Added + void uid_free(int32_t in_uid, const auth_3d_database* auth_3d_db); + void uid_free_modern(uint32_t hash); // Added + bool init(); + bool ctrl(); + void disp(); + const Scene* M_get_work(int32_t in_handle) const; + Scene* M_get_work(int32_t in_handle); + const Scene* get_work(int32_t in_handle) const; + Scene* get_work(int32_t in_handle); + const Scene* get_work_enabled(int32_t in_handle) const; + Scene* get_work_enabled(int32_t in_handle); + //void dump_scene_buffer(); + int32_t create(int32_t uid, const auth_3d_database* auth_3d_db); + int32_t create(uint32_t hash, void* data, + const object_database* obj_db, const texture_database* tex_db); // Added + void destroy(int32_t in_handle, render_context* rctx); + int32_t get_assign_rob_id(int32_t in_handle) const; + }; + + class Handle { + private: + int32_t m_handle; + + Handle(int32_t in_handle) : m_handle(in_handle) { + + } + + public: + inline Handle() : m_handle(-1) { + + } + + inline ~Handle() { + + } + + constexpr bool operator==(const Handle& other) const; + constexpr bool operator<(const Handle& other) const; + + static Handle S_init(int32_t in_handle); + + int32_t get(); + static Handle create(int32_t uid, const auth_3d_database* auth_3d_db); + static Handle create(uint32_t hash, void* data, + const object_database* obj_db, const texture_database* tex_db); // Added + void destroy(render_context* rctx); + bool is_valid() const; + void set_invalid(); + int32_t get_uid() const; + void add_event_listener(a3d::EventListener* in_value); + void remove_event_listener(a3d::EventListener* in_value); + void load_req(const auth_3d_database* auth_3d_db); + void load_req_modern(); // Added + bool load_is_done() const; + void set_frame_req(float_t in_frame); + void set_frame_max(float_t in_frame); + float_t get_frame() const; + float_t get_frame_size() const; + float_t get_frame_fps() const; + float_t get_frame_begin() const; + void set_frame_rate_control(FrameRateControl* in_value); + void set_pause(bool in_value); + bool get_pause() const; + void set_enabled(bool in_value); + bool get_enabled() const; + void set_looped(bool in_value); + bool get_looped() const; + void set_frame_loop_begin(); + void set_frame_loop_begin(float_t in_frame); + float_t get_frame_loop_begin() const; + void set_frame_loop_end(); + void set_frame_loop_end(float_t in_frame); + float_t get_frame_loop_end() const; + bool is_finished() const; + void set_auto_disable(bool in_value); + bool get_auto_disable() const; + void set_base_matrix(const mat4& in_value); + const mat4& get_base_matrix() const; + void set_reverse_side(bool in_value); + bool get_reverse_side() const; + size_t get_chara_size() const; + size_t get_chara_index(const std::string& in_name) const; + const std::string* chara_get_name(size_t in_index) const; + void chara_bind_rob(size_t in_index, int32_t in_rob_id); + size_t get_object_size() const; + size_t get_object_index(const std::string& in_name) const; + const std::string* object_get_name(size_t in_index) const; + const mat4* get_object_matrix(size_t in_index) const; + void set_visible(bool in_value); + bool get_visible() const; + void set_trnsl(float_t in_value, mdl::ObjFlags in_state); + float_t get_trnsl() const; + void set_attribute_wall(bool in_value); + bool get_attribute_wall() const; + void set_item_attr(uint32_t in_id, uint32_t in_attr); + void set_item_texchange(const std::vector& in_list); + void camera_set_enabled(bool in_value); + bool camera_get_enabled() const; + void camera_set_fov_adjust(float_t in_value); + float_t camera_get_fov_adjust() const; + size_t get_auth_2d_size() const; + size_t get_auth_2d_index(const std::string& in_name) const; + const std::string* auth_2d_get_name(size_t in_index) const; + void set_data(size_t in_value); + size_t get_data() const; + void set_debug(uint32_t in_value); + uint32_t get_debug() const; + void assign_rob_id(int32_t in_value); + int32_t get_assign_rob_id() const; + void set_obj_uid(object_info in_value); + void set_shadow(bool in_value); + bool is_shadow() const; + void replace_chara(int32_t in_cn_src, int32_t in_cn_dst); + void set_frame_object_hrc(float_t in_frame); + void calc_matrix_hierarchy(const mat4& in_value); + void join(int32_t in_handle, float_t in_blend); + void join_lock(int32_t in_handle, float_t in_blend); + void set_ex_node_mat(mat4* in_value); + bool is_ex_node_mat() const; + void lock_set(); + void set_chara_item(bool in_value); // Added + bool get_chara_item() const; // Added + void set_reflect(bool in_value); // Added + bool get_reflect() const; // Added + + Scene* get_scene(); + }; + + inline constexpr bool Handle::operator==(const Handle& other) const { + return m_handle == other.m_handle; } - inline auth_3d_id(int32_t id) { - this->id = id; + inline constexpr bool Handle::operator<(const Handle& other) const { + return m_handle < other.m_handle; } - inline bool is_null() { - return id == -1; + constexpr bool operator!=(const Handle& left, const Handle& right) { + return !(left == right); } - inline bool not_null() { - return id != -1; + constexpr bool operator>(const Handle& left, const Handle& right) { + return right < left; } - auth_3d_id(uint32_t hash, void* data, object_database* obj_db, texture_database* tex_db); - auth_3d_id(int32_t uid, auth_3d_database* auth_3d_db); - void add_event_adapter(a3d::EventAdapter* value); - bool check_not_empty(); - bool check_loading(); - bool check_loaded(); - auth_3d* get_auth_3d(); - const mat4* get_auth_3d_object_mat(size_t index, bool hrc); - auth_3d_chara* get_chara(size_t auth_chara_id); - size_t get_chara_count(); - int32_t get_chara_id(); - bool get_enable(); - bool get_ended(); - float_t get_frame(); - float_t get_frame_offset(); - float_t get_last_frame(); - bool get_mirror(); - bool get_paused(); - float_t get_play_control_begin(); - float_t get_play_control_size(); - bool get_repeat(); - int32_t get_uid(); - void read_file(auth_3d_database* auth_3d_db); - void read_file_modern(); - void set_alpha_obj_flags(float_t alpha, mdl::ObjFlags obj_flags); - void set_camera_root_update(bool value); - void set_chara_id(int32_t value); - void set_chara_num(size_t auth_chara_id, int32_t index); - void set_chara_item(bool value); - void set_enable(bool value); - void set_frame_rate(FrameRateControl* value); - void set_last_frame(float_t value); - void set_mat(const mat4& value); - void set_max_frame(float_t value); - void set_mirror(bool value); - void set_paused(bool value); - void set_pos(int32_t value); - void set_reflect(bool value); - void set_repeat(bool value); - void set_req_frame(float_t value); - void set_shadow(bool value); - void set_src_dst_chara(int32_t src_chara, int32_t dst_chara); - void set_visibility(bool value); - void unload(render_context* rctx); -}; + constexpr bool operator<=(const Handle& left, const Handle& right) { + return !(right < left); + } -constexpr bool operator==(const auth_3d_id& left, const auth_3d_id& right) { - return left.id == right.id; + constexpr bool operator>=(const Handle& left, const Handle& right) { + return !(left < right); + } + + extern Auth3dManager* g_manager; + + extern void category_free(const char* in_name); + extern void category_free(uint32_t in_hash); // Added + extern bool category_load_is_done(const char* in_name); + extern bool category_load_is_done(uint32_t in_hash); // Added + extern void category_load_req(const char* in_name); + extern void category_load_req(const char* in_name, const char* in_mdata_dir); + extern void category_load_req(void* data, const char* in_name, uint32_t in_hash); // Added + extern Event* createEvent(const SceneFile& in_file, const a3d::Event& in_e); + extern Event* createEventFX(const SceneFile& in_file, const a3d::Event& in_e); + extern Event* createEventFilter(const SceneFile& in_file, const a3d::Event& in_e); + extern const char* get_name_uid(int32_t in_uid, const auth_3d_database* auth_3d_db); + extern const mat4* get_object_matrix(int32_t in_handle, size_t in_index, bool in_is_hrc); + extern int32_t get_assign_rob_id(int32_t in_handle); + extern Scene* get_scene(int32_t in_uid); // Added + extern Scene* get_scene(uint32_t hash); // Added + extern int32_t get_scene_object_index(object_info in_obj_uid, + int32_t* out_index, bool* out_is_hrc, int32_t in_instance = -1); + extern int32_t get_scene_object_index(uint32_t in_file_name_hash, uint32_t in_obj_hash, + int32_t* out_index, bool* out_is_hrc, int32_t in_instance = -1); // Added + + // MGF + inline bool Ambient::has_light_diffuse() const { + return flag & FLAG_LIGHT_DIFFUSE; + } + + // MGF + inline bool Ambient::has_rim_light_diffuse() const { + return flag & FLAG_RIM_LIGHT_DIFFUSE; + } + + inline bool CameraAuxiliary::has_exposure() const { + return flag & FLAG_EXPOSURE; + } + + // F/F2/X/XHD + inline bool CameraAuxiliary::has_exposure_rate() const { + return flag & FLAG_EXPOSURE_RATE; + } + + inline bool CameraAuxiliary::has_gamma() const { + return flag & FLAG_GAMMA; + } + + // F/F2/X/XHD + inline bool CameraAuxiliary::has_gamma_rate() const { + return flag & FLAG_GAMMA_RATE; + } + + inline bool CameraAuxiliary::has_saturate() const { + return flag & FLAG_SATURATE; + } + + inline bool CameraAuxiliary::has_auto_exposure() const { + return flag & FLAG_AUTO_EXPOSURE; + } + + inline bool Fog::has_density() const { + return flag & FLAG_DENSITY; + } + + inline bool Fog::has_start() const { + return flag & FLAG_START; + } + + inline bool Fog::has_end() const { + return flag & FLAG_END; + } + + inline bool Fog::has_color() const { + return flag & FLAG_COLOR; + } + + inline bool Light::has_ambient() const { + return flag & FLAG_AMBIENT; + } + + inline bool Light::has_diffuse() const { + return flag & FLAG_DIFFUSE; + } + + inline bool Light::has_specular() const { + return flag & FLAG_SPECULAR; + } + + inline bool Light::has_tone_curve() const { + return flag & FLAG_TONE_CURVE; + } + + // XHD + inline bool Light::has_constant() const { + return flag & FLAG_CONSTANT; + } + + // XHD + inline bool Light::has_intensity() const { + return flag & FLAG_INTENSITY; + } + + // XHD + inline bool Light::has_far() const { + return flag & FLAG_FAR; + } + + // XHD + inline bool Light::has_linear() const { + return flag & FLAG_LINEAR; + } + + // XHD + inline bool Light::has_quadratic() const { + return flag & FLAG_QUADRATIC; + } + + // XHD + inline bool Light::has_drop_off() const { + return flag & FLAG_DROP_OFF; + } + + // XHD + inline bool Light::has_cone_angle() const { + return flag & FLAG_CONE_ANGLE; + } + + // XHD + inline bool MaterialList::has_emission() const { + return flag & FLAG_EMISSION; + } + + // XHD + inline bool MaterialList::has_blend_color() const { + return flag & FLAG_BLEND_COLOR; + } + + // XHD + inline bool MaterialList::has_glow_intensity() const { + return flag & FLAG_GLOW_INTENSITY; + } + + inline bool PostProcess::has_lens() const { + return flag & (FLAG_LENS_GHOST | FLAG_LENS_SHAFT | FLAG_LENS_FLARE); + } + + inline bool PostProcess::has_lens_flare() const { + return flag & FLAG_LENS_FLARE; + } + + inline bool PostProcess::has_lens_shaft() const { + return flag & FLAG_LENS_SHAFT; + } + + inline bool PostProcess::has_lens_ghost() const { + return flag & FLAG_LENS_GHOST; + } + + inline bool PostProcess::has_radius() const { + return flag & FLAG_RADIUS; + } + + inline bool PostProcess::has_intensity() const { + return flag & FLAG_INTENSITY; + } + + inline bool PostProcess::has_scene_fade() const { + return flag & FLAG_SCENE_FADE; + } + + inline bool TextureTransform::has_coverage_u() const { + return flag & FLAG_COVERAGE_U; + } + + inline bool TextureTransform::has_coverage_v() const { + return flag & FLAG_COVERAGE_V; + } + + inline bool TextureTransform::has_repeat_u() const { + return flag & FLAG_REPEAT_U; + } + + inline bool TextureTransform::has_repeat_v() const { + return flag & FLAG_REPEAT_V; + } + + inline bool TextureTransform::has_translate_frame_u() const { + return flag & FLAG_TRANSLATE_FRAME_U; + } + + inline bool TextureTransform::has_translate_frame_v() const { + return flag & FLAG_TRANSLATE_FRAME_V; + } + + inline bool TextureTransform::has_offset_u() const { + return flag & FLAG_OFFSET_U; + } + + inline bool TextureTransform::has_offset_v() const { + return flag & FLAG_OFFSET_V; + } + + inline bool TextureTransform::has_rotate_frame() const { + return flag & FLAG_ROTATE_FRAME; + } + + inline bool TextureTransform::has_rotate() const { + return flag & FLAG_ROTATE; + } } -constexpr bool operator!=(const auth_3d_id& left, const auth_3d_id& right) { - return !(left == right); -} - -constexpr bool operator<(const auth_3d_id& left, const auth_3d_id& right) { - return left.id < right.id; -} - -constexpr bool operator>(const auth_3d_id& left, const auth_3d_id& right) { - return right < left; -} - -constexpr bool operator<=(const auth_3d_id& left, const auth_3d_id& right) { - return !(right < left); -} - -constexpr bool operator>=(const auth_3d_id& left, const auth_3d_id& right) { - return !(left < right); -} - -struct auth_3d { - int32_t uid; - int32_t id; - bool enable; - bool camera_root_update; - bool visible; - bool repeat; - bool field_C; - bool ended; - bool mirror; - bool once; - mat4 mat; - float_t alpha; - mdl::ObjFlags obj_flags; - int32_t rob_id; - bool chara_item; - bool shadow; - bool reflect; - int32_t src_chara; - int32_t dst_chara; - int32_t pos; - FrameRateControl* frame_rate; - float_t frame; - float_t req_frame; - float_t max_frame; - bool frame_changed; - float_t frame_offset; - float_t last_frame; - bool paused; - - std::vector ambient; - std::vector auth_2d; - auth_3d_camera_auxiliary camera_auxiliary; - std::vector camera_root; - std::vector chara; - std::vector curve; - auth_3d_dof dof; - std::vector event; - std::vector event_adapter; - std::vector event_time; - auth_3d_time_event* event_time_next; - std::vector fog; - std::vector light; - std::vector m_object_hrc; - std::vector m_object_hrc_list; - std::vector material_list; - std::vector motion; - std::vector object; - std::vector object_hrc; - std::vector object_hrc_list; - std::vector object_list; - auth_3d_play_control play_control; - std::vector point; - auth_3d_post_process post_process; - int32_t state; - - std::string file_name; - uint32_t hash; - object_database* obj_db; - texture_database* tex_db; - - auth_3d(); - ~auth_3d(); - - void ctrl(render_context* rctx); - void disp(render_context* rctx); - auth_3d_id get_id(); - void load(a3da* auth_file, - object_database* obj_db, texture_database* tex_db); - void load_from_farc(struct farc* f, const char* file, - object_database* obj_db, texture_database* tex_db); - void parse(); - void reset(); - void store(a3da* auth_file); - void unload(render_context* rctx); -}; - -#define AUTH_3D_DATA_COUNT 0x100 - -struct auth_3d_farc { - int32_t load_count; - std::string name; - int32_t state; - std::string path; - std::string file; - p_file_handler file_handler; - struct farc* farc; - const void* data; - size_t size; - - auth_3d_farc(); - ~auth_3d_farc(); -}; - -struct auth_3d_uid_file { - int32_t load_count; - int32_t uid; - std::string file_name; - int32_t state; - const char* name; - auth_3d_farc* farc; - - auth_3d_uid_file(); - ~auth_3d_uid_file(); -}; - -struct auth_3d_uid_file_modern { - int32_t load_count; - uint32_t hash; - std::string file_name; - int32_t state; - std::string name; - auth_3d_farc* farc; - void* data; - object_database* obj_db; - texture_database* tex_db; - - auth_3d_uid_file_modern(); - ~auth_3d_uid_file_modern(); -}; - -struct auth_3d_data_struct { - std::vector farcs; - std::map farcs_modern; - std::vector uid_files; - std::map uid_files_modern; - std::vector loaded_ids; - auth_3d data[AUTH_3D_DATA_COUNT]; - - auth_3d_data_struct(); - ~auth_3d_data_struct(); -}; - -extern auth_3d_data_struct* auth_3d_data; - extern void auth_3d_data_init(); -extern bool auth_3d_data_check_category_loaded(const char* category_name); -extern bool auth_3d_data_check_category_loaded(uint32_t category_hash); -extern auth_3d* auth_3d_data_get_auth_3d(uint32_t hash); -extern auth_3d* auth_3d_data_get_auth_3d(int32_t uid); -extern int32_t auth_3d_data_get_auth_3d_id(const char* object_name); -extern int32_t auth_3d_data_get_auth_3d_id(object_info obj_info, - int32_t* object_index, bool* hrc, int32_t object_instance = -1); -extern int32_t auth_3d_data_get_auth_3d_id(uint32_t file_name_hash, uint32_t object_hash, - int32_t* object_index, bool* hrc, int32_t object_instance = -1); void auth_3d_data_get_obj_sets_from_category(std::string& name, std::vector& obj_sets, - auth_3d_database* auth_3d_db, object_database* obj_db); -extern const char* auth_3d_data_get_uid_name(int32_t uid, auth_3d_database* auth_3d_db); -extern void auth_3d_data_load_auth_3d_db(auth_3d_database* auth_3d_db); -extern void auth_3d_data_load_category(const char* category_name, const char* mdata_dir = 0); -extern void auth_3d_data_load_category(void* data, const char* category_name, uint32_t category_hash); -extern void auth_3d_data_unload_category(const char* category_name); -extern void auth_3d_data_unload_category(uint32_t category_hash); + const auth_3d_database* auth_3d_db, const object_database* obj_db); +extern void auth_3d_data_load_auth_3d_db(const auth_3d_database* auth_3d_db); extern void auth_3d_data_free(); extern void task_auth_3d_init(); diff --git a/src/CRE/camera.cpp b/src/CRE/camera.cpp index 88dfca86..c4844944 100644 --- a/src/CRE/camera.cpp +++ b/src/CRE/camera.cpp @@ -379,30 +379,30 @@ static void camera_calculate_view(camera* c) { } } -cam_struct::cam_struct() { - use_up = false; - view_point = { 0.0f, 1.0f, 6.0f }; - interest = { 0.0f, 1.0f, 0.0f }; - fov = (float_t)(32.2673416137695 * DEG_TO_RAD); - roll = 0.0f; - up = { 0.0f, 1.0f, 0.0f }; - min_distance = 0.05f; -} - -void cam_struct::get(camera* cam) { +void CameraParam::get(camera* cam) { cam->get_view_point(view_point); cam->get_interest(interest); - fov = (float_t)cam->get_fov() * DEG_TO_RAD_FLOAT; + v_fov = (float_t)cam->get_fov() * DEG_TO_RAD_FLOAT; roll = (float_t)cam->get_roll() * DEG_TO_RAD_FLOAT; } -void cam_struct::set(camera* cam) { +void CameraParam::init() { + use_up = false; + view_point = { 0.0f, 1.0f, 6.0f }; + interest = { 0.0f, 1.0f, 0.0f }; + v_fov = (float_t)(32.2673416137695 * DEG_TO_RAD); + roll = 0.0f; + up = { 0.0f, 1.0f, 0.0f }; + clip_near = 0.05f; +} + +void CameraParam::set(camera* cam) { cam->set_view_point(view_point); cam->set_interest(interest); - cam->set_fov(fov * RAD_TO_DEG_FLOAT); + cam->set_fov(v_fov * RAD_TO_DEG_FLOAT); cam->set_roll(roll * RAD_TO_DEG_FLOAT); cam->set_up(use_up, up); - cam->set_min_distance(min_distance); + cam->set_min_distance(clip_near); } cam_data::cam_data() : view_point(0.0f, 0.0f, 1.0f), interest(), up(0.0f, 1.0f, 0.0f), diff --git a/src/CRE/camera.hpp b/src/CRE/camera.hpp index 774180b0..5bc4dc15 100644 --- a/src/CRE/camera.hpp +++ b/src/CRE/camera.hpp @@ -101,17 +101,22 @@ struct camera { void update_data(); }; -struct cam_struct { +struct CameraParam { bool use_up; vec3 view_point; vec3 interest; - float_t fov; + float_t v_fov; float_t roll; vec3 up; - float_t min_distance; + float_t clip_near; + + inline CameraParam() : use_up(), view_point(), + interest(), v_fov(), roll(), up(), clip_near() { + init(); + } - cam_struct(); void get(camera* cam); + void init(); void set(camera* cam); }; diff --git a/src/CRE/effect.cpp b/src/CRE/effect.cpp index c0962b4c..658c0b24 100644 --- a/src/CRE/effect.cpp +++ b/src/CRE/effect.cpp @@ -143,7 +143,7 @@ public: struct struc_621 { uint32_t stage_hash; // Added int32_t stage_index; - std::vector auth_3d_ids; + std::vector auth_3d_ids; struc_621(); ~struc_621(); @@ -152,8 +152,8 @@ struct struc_621 { struct EffectAuth3d { size_t count; size_t max_count; - auth_3d_id* auth_3d_ids_ptr; - auth_3d_id auth_3d_ids[TASK_STAGE_STAGE_COUNT]; + auth_3d_detail::Handle* auth_3d_ids_ptr; + auth_3d_detail::Handle auth_3d_ids[TASK_STAGE_STAGE_COUNT]; EffectAuth3d(); }; @@ -193,7 +193,7 @@ public: virtual void reset() override; void reset_data(); - void set_visibility(bool value); + void set_visible(bool value); }; struct EffectFogAnim { @@ -1934,8 +1934,6 @@ struc_621::~struc_621() { EffectAuth3d::EffectAuth3d() : auth_3d_ids() { count = 0; max_count = TASK_STAGE_STAGE_COUNT; - for (auth_3d_id& i : auth_3d_ids) - i = -1; auth_3d_ids_ptr = auth_3d_ids; } @@ -1957,15 +1955,15 @@ bool TaskEffectAuth3D::init() { if (stage.count) { for (int32_t i = 0; i < stage.count; i++) - if (!stage.auth_3d_ids_ptr[i].check_loaded()) + if (!stage.auth_3d_ids_ptr[i].load_is_done()) return false; } for (int32_t i = 0; i < stage.count; i++) { - auth_3d_id& id = stage.auth_3d_ids_ptr[i]; - id.set_repeat(true); - id.set_paused(false); - id.set_enable(true); + auth_3d_detail::Handle& id = stage.auth_3d_ids_ptr[i]; + id.set_looped(true); + id.set_pause(false); + id.set_enabled(true); } //if (field_158) @@ -2031,12 +2029,12 @@ void TaskEffectAuth3D::set_stage_hashes(const std::vector& stage_hashe if (stage.count == stage.max_count) break; - auth_3d_id id = auth_3d_id(j, data, obj_db, tex_db); - if (!id.check_not_empty()) + auth_3d_detail::Handle id = auth_3d_detail::Handle::create(j, data, obj_db, tex_db); + if (!id.is_valid()) break; - id.read_file_modern(); - id.set_visibility(false); + id.load_req_modern(); + id.set_visible(false); if (stage.count + 1 <= stage.max_count) stage.auth_3d_ids_ptr[stage.count++] = id; v30.auth_3d_ids.push_back(id); @@ -2066,12 +2064,12 @@ void TaskEffectAuth3D::set_stage_indices(const std::vector& stage_indic if (stage.count == stage.max_count) break; - auth_3d_id id = auth_3d_id(j, aft_auth_3d_db); - if (!id.check_not_empty()) + auth_3d_detail::Handle id = auth_3d_detail::Handle::create(j, aft_auth_3d_db); + if (!id.is_valid()) break; - id.read_file(aft_auth_3d_db); - id.set_visibility(false); + id.load_req(aft_auth_3d_db); + id.set_visible(false); if (stage.count + 1 <= stage.max_count) stage.auth_3d_ids_ptr[stage.count++] = id; v30.auth_3d_ids.push_back(id); @@ -2084,14 +2082,14 @@ void TaskEffectAuth3D::set_stage_indices(const std::vector& stage_indic void TaskEffectAuth3D::set_frame(int32_t value) { double_t frame = (double_t)value; for (int32_t i = 0; i < stage.count; i++) { - auth_3d_id& id = stage.auth_3d_ids_ptr[i]; - float_t play_control_size = id.get_play_control_size(); - float_t req_frame; - if (play_control_size != 0.0f) - req_frame = (float_t)fmod(frame, play_control_size); + auth_3d_detail::Handle& id = stage.auth_3d_ids_ptr[i]; + float_t frame_size = id.get_frame_size(); + float_t frame_req; + if (frame_size != 0.0f) + frame_req = (float_t)fmod(frame, frame_size); else - req_frame = 0.0f; - id.set_req_frame(req_frame); + frame_req = 0.0f; + id.set_frame_req(frame_req); } } @@ -2099,40 +2097,40 @@ void TaskEffectAuth3D::set_current_stage_hash(uint32_t value) { if (current_stage_hash == value) return; - set_visibility(false); + set_visible(false); current_stage_hash = value; - set_visibility(enable); + set_visible(enable); } void TaskEffectAuth3D::set_current_stage_index(int32_t value) { if (current_stage_index == value) return; - set_visibility(false); + set_visible(false); current_stage_index = value; - set_visibility(enable); + set_visible(enable); } void TaskEffectAuth3D::set_frame_rate_control(FrameRateControl* value) { for (int32_t i = 0; i < stage.count; i++) { - auth_3d_id& id = stage.auth_3d_ids_ptr[i]; - id.set_frame_rate(value); + auth_3d_detail::Handle& id = stage.auth_3d_ids_ptr[i]; + id.set_frame_rate_control(value); } } void TaskEffectAuth3D::reset() { for (int32_t i = 0; i < stage.count; i++) { - auth_3d_id& id = stage.auth_3d_ids_ptr[i]; - id.set_enable(true); - id.set_paused(false); - id.set_req_frame(0.0f); + auth_3d_detail::Handle& id = stage.auth_3d_ids_ptr[i]; + id.set_enabled(true); + id.set_pause(false); + id.set_frame_req(0.0f); } } void TaskEffectAuth3D::reset_data() { for (int32_t i = 0; i < stage.count; i++) { - auth_3d_id& id = stage.auth_3d_ids_ptr[i]; - id.unload(rctx_ptr); + auth_3d_detail::Handle& id = stage.auth_3d_ids_ptr[i]; + id.destroy(rctx_ptr); } stage.count = 0; enable = false; @@ -2147,14 +2145,14 @@ void TaskEffectAuth3D::reset_data() { frame = -1.0f; } -void TaskEffectAuth3D::set_visibility(bool value) { +void TaskEffectAuth3D::set_visible(bool value) { if (current_stage_index != -1) for (struc_621& i : field_120) { if (i.stage_index != current_stage_index) continue; - for (auth_3d_id& j : i.auth_3d_ids) - j.set_visibility(value); + for (auth_3d_detail::Handle& j : i.auth_3d_ids) + j.set_visible(value); break; } else if (current_stage_hash != -1 && current_stage_hash @@ -2163,15 +2161,15 @@ void TaskEffectAuth3D::set_visibility(bool value) { if (i.stage_hash != current_stage_hash) continue; - for (auth_3d_id& j : i.auth_3d_ids) - j.set_visibility(value); + for (auth_3d_detail::Handle& j : i.auth_3d_ids) + j.set_visible(value); break; } } void TaskEffectAuth3D::set_enable(bool value) { enable = value; - set_visibility(value); + set_visible(value); } EffectFogAnim::EffectFogAnim() : field_0(), field_4(), field_8(), field_C(), @@ -5709,7 +5707,7 @@ void EffectManager::set_stage_hashes(const std::vector& stage_hashes) obj_set_ids.push_back(j); } - prj::sort_unique(obj_set_ids); + prj::sort_and_erase_non_unique(obj_set_ids); for (uint32_t i : obj_set_ids) objset_info_storage_load_set_hash(data, i); @@ -5745,7 +5743,7 @@ void EffectManager::set_stage_indices(const std::vector& stage_indices) obj_set_ids.push_back(j); } - prj::sort_unique(obj_set_ids); + prj::sort_and_erase_non_unique(obj_set_ids); for (uint32_t i : obj_set_ids) objset_info_storage_load_set(aft_data, aft_obj_db, i); diff --git a/src/CRE/mdl/disp_manager.cpp b/src/CRE/mdl/disp_manager.cpp index 5c6613b9..8426540d 100644 --- a/src/CRE/mdl/disp_manager.cpp +++ b/src/CRE/mdl/disp_manager.cpp @@ -45,10 +45,17 @@ material_list_struct::material_list_struct() : blend_color(), has_blend_color(), hash = (uint32_t)-1; } -material_list_struct::material_list_struct(uint32_t hash, vec4& blend_color, - vec4u8& has_blend_color, vec4& emission, vec4u8& has_emission) : hash(hash), blend_color(blend_color), - has_blend_color(has_blend_color), emission(emission), has_emission(has_emission) { - +material_list_struct::material_list_struct(uint32_t in_hash, const vec4& in_blend_color, + const bool in_has_blend_color[4], const vec4& in_emission, const bool in_has_emission[4]) + : hash(in_hash), blend_color(in_blend_color), emission(in_emission) { + has_blend_color[0] = in_has_blend_color[0]; + has_blend_color[1] = in_has_blend_color[1]; + has_blend_color[2] = in_has_blend_color[2]; + has_blend_color[3] = in_has_blend_color[3]; + has_emission[0] = in_has_emission[0]; + has_emission[1] = in_has_emission[1]; + has_emission[2] = in_has_emission[2]; + has_emission[3] = in_has_emission[3]; } TexChange::TexChange() { @@ -2381,22 +2388,22 @@ namespace mdl { if (mat_list) { bool has_blend_color = false; - if (mat_list->has_blend_color.x) { + if (mat_list->has_blend_color[0]) { _blend_color.x = mat_list->blend_color.x; has_blend_color = true; } - if (mat_list->has_blend_color.y) { + if (mat_list->has_blend_color[1]) { _blend_color.y = mat_list->blend_color.y; has_blend_color = true; } - if (mat_list->has_blend_color.z) { + if (mat_list->has_blend_color[2]) { _blend_color.z = mat_list->blend_color.z; has_blend_color = true; } - if (mat_list->has_blend_color.w) { + if (mat_list->has_blend_color[3]) { _blend_color.w = mat_list->blend_color.w; has_blend_color = true; } @@ -2409,22 +2416,22 @@ namespace mdl { } bool has_emission = false; - if (mat_list->has_emission.x) { + if (mat_list->has_emission[0]) { _emission.x = mat_list->emission.x; has_emission = true; } - if (mat_list->has_emission.y) { + if (mat_list->has_emission[1]) { _emission.y = mat_list->emission.y; has_emission = true; } - if (mat_list->has_emission.z) { + if (mat_list->has_emission[2]) { _emission.z = mat_list->emission.z; has_emission = true; } - if (mat_list->has_emission.w) { + if (mat_list->has_emission[3]) { _emission.w = mat_list->emission.w; has_emission = true; } diff --git a/src/CRE/mdl/disp_manager.hpp b/src/CRE/mdl/disp_manager.hpp index a6faa1d1..89b12518 100644 --- a/src/CRE/mdl/disp_manager.hpp +++ b/src/CRE/mdl/disp_manager.hpp @@ -31,13 +31,13 @@ struct RobSkinCol { struct material_list_struct { uint32_t hash; vec4 blend_color; - vec4u8 has_blend_color; + bool has_blend_color[4]; vec4 emission; - vec4u8 has_emission; + bool has_emission[4]; material_list_struct(); - material_list_struct(uint32_t hash, vec4& blend_color, - vec4u8& has_blend_color, vec4& emission, vec4u8& has_emission); + material_list_struct(uint32_t in_hash, const vec4& in_blend_color, + const bool in_has_blend_color[4], const vec4& in_emission, const bool in_has_emission[4]); }; struct TexChange { diff --git a/src/CRE/ogg_vorbis.cpp b/src/CRE/ogg_vorbis.cpp index b30bc4b0..0c13105d 100644 --- a/src/CRE/ogg_vorbis.cpp +++ b/src/CRE/ogg_vorbis.cpp @@ -4,6 +4,7 @@ */ #include "ogg_vorbis.hpp" +#include "../KKdLib/prj/algorithm.hpp" #include "../KKdLib/str_utils.hpp" #include "../KKdLib/vec.hpp" #include "data.hpp" @@ -641,14 +642,7 @@ p_OggFileHandler::~p_OggFileHandler() { ptr = 0; } - std::list& list = ogg_file_handler_storage_ptr->list; - for (auto i = list.begin(); i != list.end();) - if (*i == this) { - list.erase(i); - break; - } - else - i++; + prj::find_and_erase(ogg_file_handler_storage_ptr->list, this); } int32_t p_OggFileHandler::GetChannelPairsCount() { diff --git a/src/CRE/rob/rob.cpp b/src/CRE/rob/rob.cpp index af058348..b19094b2 100644 --- a/src/CRE/rob/rob.cpp +++ b/src/CRE/rob/rob.cpp @@ -3930,7 +3930,7 @@ void rob_chara::rob_motion_modifier_ctrl() { rob_chara_bone_data_set_right_hand_scale(bone_data, right_hand_scale); } -bool rob_chara::replace_rob_motion(uint32_t motnum, float_t frame, +bool rob_chara::replace_rob_motion(uint32_t motnum, float_t frame, float_t blend_duration, bool blend, bool set_motion_reset_data, MotionBlendType blend_type, const bone_database* bone_data, const motion_database* mot_db) { if (!blend && rob_base.robmot.num == motnum) @@ -5825,7 +5825,7 @@ bool RobManagement::get_colli_check_on() const { return colli_check_on; } -// 0x140531F50 +// 0x140531F50 bool RobManagement::get_disp_on(ROB_ID id) const { if (is_init(id)) return rob_impl[id].check_disp(); @@ -6260,7 +6260,7 @@ void OpdChecker::sub_140471020() { SetIndexSize(++index, (int32_t)osage_play_data_database->map.size()); } - prj::sort_unique(objects); + prj::sort_and_erase_non_unique(objects); SetState(3); //if (!v63) @@ -11149,7 +11149,7 @@ void opd_make_start_get_motion_ids(std::vector& motion_ids) { opd_motion_ids++; }*/ motion_ids.push_back(195); // CMN_MRA00_13_01 - prj::sort_unique(motion_ids); + prj::sort_and_erase_non_unique(motion_ids); } void opd_make_stop() { @@ -17159,7 +17159,7 @@ void OsagePlayDataManager::LoadOpdFileList() { data_struct* aft_data = &data_list[DATA_AFT]; motion_database* aft_mot_db = &aft_data->data_ft.mot_db; - prj::sort_unique(req_data); + prj::sort_and_erase_non_unique(req_data); auto i_begin = req_data.begin(); auto i_end = req_data.end(); @@ -17762,7 +17762,7 @@ void OpdMakeManager::CharaData::Reset() { void OpdMakeManager::CharaData::SortUnique() { for (int32_t i = 0; i < CN_MAX; i++) for (int32_t j = 0; j < ROB_ITEM_EQUIP_SUB_ID_MAX; j++) { - prj::sort_unique(chara_costumes[i].items[j]); + prj::sort_and_erase_non_unique(chara_costumes[i].items[j]); count += chara_costumes[i].items[j].size(); } @@ -17832,7 +17832,7 @@ bool OpdMakeManager::ctrl() { motion_set_ids.push_back(set_id); } - prj::sort_unique(motion_set_ids); + prj::sort_and_erase_non_unique(motion_set_ids); for (uint32_t& i : motion_set_ids) { motion_set_load_motion(i, "", aft_mot_db); @@ -18969,7 +18969,7 @@ void PvOsageManager::SetPvSetMotion(const std::vector& set_m } void PvOsageManager::sub_1404F77E0() { - prj::sort_unique(pv_set_motion); + prj::sort_and_erase_non_unique(pv_set_motion); pv_data_set_motion* i_begin = pv_set_motion.data(); pv_data_set_motion* i_end = pv_set_motion.data() + pv_set_motion.size(); diff --git a/src/CRE/rob/skin_param.cpp b/src/CRE/rob/skin_param.cpp index 06ff1ae6..7bb0181f 100644 --- a/src/CRE/rob/skin_param.cpp +++ b/src/CRE/rob/skin_param.cpp @@ -581,7 +581,7 @@ key_val* skin_param_storage_get_key_val(object_info obj_uid) { void skin_param_storage_load(std::vector& obj_infos, void* data, const object_database* obj_db) { - prj::sort_unique(obj_infos); + prj::sort_and_erase_non_unique(obj_infos); for (const object_info& i : obj_infos) { if (i.is_null()) continue; diff --git a/src/CRE/sprite.cpp b/src/CRE/sprite.cpp index 57482267..e6bdfabd 100644 --- a/src/CRE/sprite.cpp +++ b/src/CRE/sprite.cpp @@ -36,7 +36,7 @@ public: SPRSET(uint32_t in_id); virtual ~SPRSET(); - + void request(const char* fname, const std::string mdata_dir, void* data); void requestModern(uint32_t sethash, void* data); // Added bool wait(); @@ -126,7 +126,7 @@ namespace spr { void Clear(); void Update(); }; - + struct SprArgsDraw { int32_t num_texture; int32_t blend; @@ -1483,7 +1483,7 @@ namespace spr { SprMgr::sprmgr().request(spr_db->getSetIdFromUid(setid), spr_db->getSetFileFromUid(setid), mdata_dir, data); } - + // Added void requestModern(const std::vector& sethashes, void* data, SprDb* spr_db) { for (uint32_t sethash : sethashes) diff --git a/src/CRE/stage.cpp b/src/CRE/stage.cpp index d70aaf52..293b3e36 100644 --- a/src/CRE/stage.cpp +++ b/src/CRE/stage.cpp @@ -663,8 +663,8 @@ static void stage_free(stage* s) { light_chara_ambient = false; if (s->auth_3d_loaded) { - auth_3d_data_unload_category(s->stage_data->auth_3d_name.c_str()); - auth_3d_data_unload_category(s->stage_data->name.c_str()); + auth_3d_detail::category_free(s->stage_data->auth_3d_name.c_str()); + auth_3d_detail::category_free(s->stage_data->name.c_str()); s->auth_3d_loaded = false; } @@ -694,15 +694,15 @@ static void stage_load(stage* s) { object_database* aft_obj_db = &aft_data->data_ft.obj_db; objset_info_storage_load_set(aft_data, aft_obj_db, s->stage_data->object_set_id); - auth_3d_data_load_category(s->stage_data->name.c_str()); - auth_3d_data_load_category(s->stage_data->auth_3d_name.c_str()); + auth_3d_detail::category_load_req(s->stage_data->name.c_str()); + auth_3d_detail::category_load_req(s->stage_data->auth_3d_name.c_str()); s->auth_3d_loaded = true; s->state = 4; } else if (s->state == 4) { if (objset_info_storage_load_obj_set_check_not_read(s->stage_data->object_set_id) - || !auth_3d_data_check_category_loaded(s->stage_data->name.c_str()) - || !auth_3d_data_check_category_loaded(s->stage_data->auth_3d_name.c_str())) + || !auth_3d_detail::category_load_is_done(s->stage_data->name.c_str()) + || !auth_3d_detail::category_load_is_done(s->stage_data->auth_3d_name.c_str())) return; if (s->stage_data->render_texture != -1) diff --git a/src/CRE/stage_modern.cpp b/src/CRE/stage_modern.cpp index b70cb141..80f16e8f 100644 --- a/src/CRE/stage_modern.cpp +++ b/src/CRE/stage_modern.cpp @@ -581,7 +581,7 @@ static void stage_modern_free(stage_modern* s) { light_chara_ambient = false; if (s->auth_3d_loaded) { - auth_3d_data_unload_category(s->stage_data->auth_3d_name_hash); + auth_3d_detail::category_free(s->stage_data->auth_3d_name_hash); s->auth_3d_loaded = false; } @@ -608,14 +608,14 @@ static void stage_modern_load(stage_modern* s, void* data, object_database* obj_ else if (s->state == 3) { objset_info_storage_load_set_hash(data, s->stage_data->hash); - auth_3d_data_load_category(data, s->stage_data->auth_3d_name.c_str(), + auth_3d_detail::category_load_req(data, s->stage_data->auth_3d_name.c_str(), s->stage_data->auth_3d_name_hash); s->auth_3d_loaded = true; s->state = 4; } else if (s->state == 4) { if (objset_info_storage_load_obj_set_check_not_read(s->stage_data->hash, obj_db, tex_db) - || !auth_3d_data_check_category_loaded(s->stage_data->auth_3d_name_hash)) + || !auth_3d_detail::category_load_is_done(s->stage_data->auth_3d_name_hash)) return; if (s->stage_data->render_texture != -1 && s->stage_data->render_texture != hash_murmurhash_empty) diff --git a/src/KKdLib/a3da.cpp b/src/KKdLib/a3da.cpp index e9016d72..afed47dd 100644 --- a/src/KKdLib/a3da.cpp +++ b/src/KKdLib/a3da.cpp @@ -14,3232 +14,3276 @@ #include "str_utils.hpp" #include -struct a3da_vec3_header { - uint32_t x; - uint32_t y; - uint32_t z; -}; - -struct a3da_model_transform_header { - a3da_vec3_header scale; - a3da_vec3_header rotation; - a3da_vec3_header translation; - uint32_t visibility; -}; - -struct a3dc_header { - uint32_t binary_length; - uint32_t binary_offset; - uint32_t string_length; - uint32_t string_offset; -}; - -struct a3dc_key_header { - a3da_key_type type : 8; - a3da_ep_type ep_type_pre : 4; - a3da_ep_type ep_type_post : 4; - uint32_t padding : 16; - float_t value; - float_t max_frame; - uint32_t length; -}; - -static void a3da_read_inner(a3da* a, stream& s); -static void a3da_write_inner(a3da* a, stream& s); -static void a3da_read_text(a3da* a, void* data, size_t size); -static void a3da_write_text(a3da* a, void** data, size_t* size, bool a3dc); -static void a3da_read_data(a3da* a, void* data, size_t size); -static void a3da_write_data(a3da* a, void** data, size_t* size); -static void a3da_get_time_stamp(char* buf, size_t buf_size); -static bool key_val_read(key_val* kv, - const char* key, a3da_key& value); -static void key_val_out_write(key_val_out* kv, stream& s, - const char* key, a3da_key& value, bool write_true = false); -static bool key_val_read_raw_data(key_val* kv, - a3da_key& value); -static void key_val_out_write_raw_data(key_val_out* kv, stream& s, - a3da_key& value); -static bool key_val_read(key_val* kv, - const char* key, a3da_model_transform& value); -static void key_val_out_write(key_val_out* kv, stream& s, - const char* key, a3da_model_transform& value, int32_t write_mask = 0x1F); -static bool key_val_read(key_val* kv, - const char* key, a3da_rgba& value); -static void key_val_out_write(key_val_out* kv, stream& s, - const char* key, a3da_rgba& value); -static bool key_val_read(key_val* kv, - const char* key, a3da_vec3& value); -static void key_val_out_write(key_val_out* kv, stream& s, - const char* key, a3da_vec3& value); -static void a3dc_read_a3da_key(void* data, size_t size, a3da_key* value); -static void a3dc_write_a3da_key(stream& s, a3da_key& value); -static void a3dc_read_a3da_key_f16(void* data, size_t size, a3da_key* value, a3da_compress_f16 f16); -static void a3dc_write_a3da_key_f16(stream& s, a3da_key& value, a3da_compress_f16 f16); -static void a3dc_read_a3da_model_transform(void* data, size_t size, - a3da_model_transform* value, a3da_compress_f16 f16); -static void a3dc_write_a3da_model_transform(stream& s, - a3da_model_transform& value, a3da_compress_f16 f16); -static void a3dc_write_a3da_model_transform_offset(stream& s, - a3da_model_transform& value); -static void a3dc_write_a3da_model_transform_offset_data(stream& s, - a3da_model_transform& value); -static void a3dc_read_a3da_rgba(void* data, size_t size, a3da_rgba* value); -static void a3dc_write_a3da_rgba(stream& s, a3da_rgba& value); -static void a3dc_read_a3da_vec3(void* data, size_t size, a3da_vec3* value); -static void a3dc_write_a3da_vec3(stream& s, a3da_vec3& value); -static void a3dc_read_a3da_vec3_f16(void* data, size_t size, a3da_vec3* value, a3da_compress_f16 f16); -static void a3dc_write_a3da_vec3_f16(stream& s, a3da_vec3& value, a3da_compress_f16 f16); +namespace a3d { + struct a3da_vec3_header { + uint32_t x; + uint32_t y; + uint32_t z; + }; + + struct a3da_model_transform_header { + a3da_vec3_header scale; + a3da_vec3_header rotation; + a3da_vec3_header translation; + uint32_t visibility; + }; + + struct a3dc_header { + uint32_t binary_length; + uint32_t binary_offset; + uint32_t string_length; + uint32_t string_offset; + }; + + struct a3dc_key_header { + FC_TYPE type : 8; + EP_TYPE ep_type_pre : 4; + EP_TYPE ep_type_post : 4; + uint32_t padding : 16; + float_t value; + float_t max_frame; + uint32_t length; + }; + + static void a3da_read_inner(Scene* sc, stream& s); + static void a3da_write_inner(Scene* sc, stream& s); + static void a3da_read_text(Scene* sc, void* data, size_t size); + static void a3da_write_text(Scene* sc, void** data, size_t* size, bool a3dc); + static void a3da_read_data(Scene* sc, void* data, size_t size); + static void a3da_write_data(Scene* sc, void** data, size_t* size); + static void a3da_get_time_stamp(char* buf, size_t buf_size); + static bool key_val_read(key_val* kv, + const char* key, Fcurve& value); + static void key_val_out_write(key_val_out* kv, stream& s, + const char* key, Fcurve& value, bool write_true = false); + static bool key_val_read_raw_data(key_val* kv, + Fcurve& value); + static void key_val_out_write_raw_data(key_val_out* kv, stream& s, + Fcurve& value); + static bool key_val_read(key_val* kv, + const char* key, ModelTransform& value); + static void key_val_out_write(key_val_out* kv, stream& s, + const char* key, ModelTransform& value, int32_t write_mask = 0x1F); + static bool key_val_read(key_val* kv, + const char* key, FcurveColor4f& value); + static void key_val_out_write(key_val_out* kv, stream& s, + const char* key, FcurveColor4f& value); + static bool key_val_read(key_val* kv, + const char* key, Fcurve3f& value); + static void key_val_out_write(key_val_out* kv, stream& s, + const char* key, Fcurve3f& value); + static void a3dc_read_a3da_key(void* data, size_t size, Fcurve* value); + static void a3dc_write_a3da_key(stream& s, Fcurve& value); + static void a3dc_read_a3da_key_f16(void* data, size_t size, Fcurve* value, COMPRESS_TYPE f16); + static void a3dc_write_a3da_key_f16(stream& s, Fcurve& value, COMPRESS_TYPE f16); + static void a3dc_read_a3da_model_transform(void* data, size_t size, + ModelTransform* value, COMPRESS_TYPE f16); + static void a3dc_write_a3da_model_transform(stream& s, + ModelTransform& value, COMPRESS_TYPE f16); + static void a3dc_write_a3da_model_transform_offset(stream& s, + ModelTransform& value); + static void a3dc_write_a3da_model_transform_offset_data(stream& s, + ModelTransform& value); + static void a3dc_read_a3da_rgba(void* data, size_t size, FcurveColor4f* value); + static void a3dc_write_a3da_rgba(stream& s, FcurveColor4f& value); + static void a3dc_read_a3da_vec3(void* data, size_t size, Fcurve3f* value); + static void a3dc_write_a3da_vec3(stream& s, Fcurve3f& value); + static void a3dc_read_a3da_vec3_f16(void* data, size_t size, Fcurve3f* value, COMPRESS_TYPE f16); + static void a3dc_write_a3da_vec3_f16(stream& s, Fcurve3f& value, COMPRESS_TYPE f16); -static void a3da_key_make_raw_data_binary(a3da_key* value); -static void a3da_model_transform_make_raw_data_binary(a3da_model_transform* value); -static void a3da_rgba_make_raw_data_binary(a3da_rgba* value); -static void a3da_vec3_make_raw_data_binary(a3da_vec3* value); + static void a3da_key_make_raw_data_binary(Fcurve* value); + static void a3da_model_transform_make_raw_data_binary(ModelTransform* value); + static void a3da_rgba_make_raw_data_binary(FcurveColor4f* value); + static void a3da_vec3_make_raw_data_binary(Fcurve3f* value); -a3da_key::a3da_key() : flags(), bin_offset(), type(), ep_type_pre(), ep_type_post(), max_frame(), -raw_data(), raw_data_binary(), raw_data_value_list_size(), raw_data_value_list_offset(), value() { -} + Fcurve::Fcurve() : flag(), bin_offset(), type(), ep_type_pre(), ep_type_post(), max_frame(), + raw_data(), raw_data_binary(), raw_data_value_list_size(), raw_data_value_list_offset(), value() { + } -a3da_key::~a3da_key() { + Fcurve::~Fcurve() { -} + } -a3da_key& a3da_key::operator=(const a3da_key& k) { - flags = k.flags; - bin_offset = k.bin_offset; - type = k.type; - ep_type_pre = k.ep_type_pre; - ep_type_post = k.ep_type_post; - keys.assign(k.keys.begin(), k.keys.end()); - max_frame = k.max_frame; - raw_data = k.raw_data; - raw_data_binary = k.raw_data_binary; - raw_data_value_list_size = k.raw_data_value_list_size; - raw_data_value_list_offset = k.raw_data_value_list_offset; - value = k.value; - return *this; -} + Fcurve& Fcurve::operator=(const Fcurve& other) { + flag = other.flag; + bin_offset = other.bin_offset; + type = other.type; + ep_type_pre = other.ep_type_pre; + ep_type_post = other.ep_type_post; + keys.assign(other.keys.begin(), other.keys.end()); + max_frame = other.max_frame; + raw_data = other.raw_data; + raw_data_binary = other.raw_data_binary; + raw_data_value_list_size = other.raw_data_value_list_size; + raw_data_value_list_offset = other.raw_data_value_list_offset; + value = other.value; + return *this; + } -a3da_rgba::a3da_rgba() : flags() { + Fcurve3f::Fcurve3f() { -} + } -a3da_rgba::~a3da_rgba() { + Fcurve3f::~Fcurve3f() { -} + } -a3da_vec3::a3da_vec3() { + FcurveColor4f::FcurveColor4f() : has_r(), has_g(), has_b(), has_a() { -} + } -a3da_vec3::~a3da_vec3() { + FcurveColor4f::~FcurveColor4f() { -} + } -a3da_model_transform::a3da_model_transform() : bin_offset(), flags() { + ModelTransform::ModelTransform() : bin_offset(), flag() { -} + } -a3da_model_transform::~a3da_model_transform() { + ModelTransform::~ModelTransform() { -} + } -a3da_ambient::a3da_ambient() : flags() { + // MGF + Ambient::Ambient() : flag() { -} + } -a3da_ambient::~a3da_ambient() { + // MGF + Ambient::~Ambient() { -} + } -a3da_camera_auxiliary::a3da_camera_auxiliary() : flags() { + Auth2d::Auth2d() { -} + } -a3da_camera_auxiliary::~a3da_camera_auxiliary() { + Auth2d::~Auth2d() { -} + } -a3da_camera_root_view_point::a3da_camera_root_view_point() : aspect(), -camera_aperture_w(), camera_aperture_h(), flags(), fov_is_horizontal() { + CameraAuxiliary::CameraAuxiliary() : flag() { -} + } -a3da_camera_root_view_point::~a3da_camera_root_view_point() { + CameraAuxiliary::~CameraAuxiliary() { -} + } -a3da_camera_root::a3da_camera_root() { + CameraInterest::CameraInterest() { -} + } -a3da_camera_root::~a3da_camera_root() { + CameraInterest::~CameraInterest() { -} + } -a3da_chara::a3da_chara() { + CameraViewPoint::CameraViewPoint() : fov_is_horizontal(), + has_fov(), aspect(), camera_aperture_w(), camera_aperture_h() { -} + } -a3da_chara::~a3da_chara() { + CameraViewPoint::~CameraViewPoint() { -} + } -a3da_curve::a3da_curve() { + CameraRoot::CameraRoot() { -} + } -a3da_curve::~a3da_curve() { + CameraRoot::~CameraRoot() { -} + } -a3da_dof::a3da_dof() : has_dof() { + Chara::Chara() { -} + } -a3da_dof::~a3da_dof() { + Chara::~Chara() { -} + } -a3da_event::a3da_event() : begin(), clip_begin(), -clip_end(), end(), time_ref_scale(), type() { + Curve::Curve() { -} + } -a3da_event::~a3da_event() { + Curve::~Curve() { -} + } -a3da_fog::a3da_fog() : flags(), id() { + Dof::Dof() : has_dof() { -} + } -a3da_fog::~a3da_fog() { + Dof::~Dof() { -} + } -a3da_light::a3da_light() : flags(), id() { + Event::Event() : begin(), clip_begin(), + clip_end(), end(), time_ref_scale(), type() { -} + } -a3da_light::~a3da_light() { + Event::~Event() { -} + } -a3da_m_object_hrc::a3da_m_object_hrc() { + Fog::Fog() : flag(), id(-1), name("(init)") { -} + } -a3da_m_object_hrc::~a3da_m_object_hrc() { + Fog::~Fog() { -} + } -a3da_material_list::a3da_material_list() : flags() { + Light::Light() : flag(), id(-1), name("(init)"), type("(init)") { -} + } -a3da_material_list::~a3da_material_list() { + Light::~Light() { -} + } -a3da_object::a3da_object() : morph_offset(), pattern_offset() { + MObjectHrc::MObjectHrc() { -} + } -a3da_object::~a3da_object() { + MObjectHrc::~MObjectHrc() { -} + } -a3da_object_hrc::a3da_object_hrc() : shadow() { + // X/HD + MaterialList::MaterialList() : flag() { -} + } -a3da_object_hrc::~a3da_object_hrc() { + // X/HD + MaterialList::~MaterialList() { -} + } -a3da_object_instance::a3da_object_instance() : shadow() { + Motion::Motion() { -} + } -a3da_object_instance::~a3da_object_instance() { + Motion::~Motion() { -} + } -a3da_object_node::a3da_object_node() : flags(), joint_orient(), parent() { + Object::Object() : morph_offset(), pattern_offset() { -} + } -a3da_object_node::~a3da_object_node() { + Object::~Object() { -} + } -a3da_object_texture_pattern::a3da_object_texture_pattern() : pattern_offset() { + ObjectHrc::ObjectHrc() : shadow() { -} + } -a3da_object_texture_pattern::~a3da_object_texture_pattern() { + ObjectHrc::~ObjectHrc() { -} + } -a3da_object_texture_transform::a3da_object_texture_transform() : flags() { + ObjectInstance::ObjectInstance() : shadow() { -} + } -a3da_object_texture_transform::~a3da_object_texture_transform() { + ObjectInstance::~ObjectInstance() { -} + } -a3da_play_control::a3da_play_control() : begin(), div(), flags(), fps(), offset(), size() { + ObjectNode::ObjectNode() : flag(), parent(), joint_orient() { -} + } -a3da_play_control::~a3da_play_control() { + ObjectNode::~ObjectNode() { -} + } -a3da_point::a3da_point() { + PlayControl::PlayControl() : flag(), begin(), div(), fps(), offset(), size() { -} + } -a3da_point::~a3da_point() { + PlayControl::~PlayControl() { -} + } -a3da_post_process::a3da_post_process() : flags() { + Point::Point() { -} + } -a3da_post_process::~a3da_post_process() { + Point::~Point() { -} + } -a3da::a3da() : ready(), compressed(), format(), _compress_f16(), -_file_name(), _property_version(), _converter_version() { + PostProcess::PostProcess() : flag() { -} + } -a3da::~a3da() { + PostProcess::~PostProcess() { -} + } -void a3da::read(const char* path) { - if (!path) - return; + Texture::Texture() : pattern_offset() { - char* path_a3da = str_utils_add(path, (char*)".a3da"); - if (!path_a3da) - return; + } + + Texture::~Texture() { + + } + + TextureTransform::TextureTransform() : flag() { + + } + + TextureTransform::~TextureTransform() { + + } + + Scene::Scene() : ready(), compressed(), format(), _compress_f16(), + _file_name(), _property_version(), _converter_version() { + + } + + Scene::~Scene() { + + } + + void Scene::read(const char* path) { + if (!path) + return; + + char* path_a3da = str_utils_add(path, (char*)".a3da"); + if (!path_a3da) + return; + + if (path_check_file_exists(path_a3da)) { + file_stream s; + s.open(path_a3da, "rb"); + if (s.check_not_null()) + a3da_read_inner(this, s); + } + free_def(path_a3da); + } + + void Scene::read(const wchar_t* path) { + if (!path) + return; + + wchar_t* path_a3da = str_utils_add(path, (wchar_t*)L".a3da"); + if (!path_a3da) + return; + + if (path_check_file_exists(path_a3da)) { + file_stream s; + s.open(path_a3da, L"rb"); + if (s.check_not_null()) + a3da_read_inner(this, s); + } + free_def(path_a3da); + } + + void Scene::read(const void* data, size_t size) { + if (!data || !size) + return; + + memory_stream s; + s.open(data, size); + a3da_read_inner(this, s); + } + + void Scene::write(const char* path) { + if (!path || !ready) + return; + + char* path_a3da = str_utils_add(path, ".a3da"); + if (!path_a3da) + return; - if (path_check_file_exists(path_a3da)) { file_stream s; - s.open(path_a3da, "rb"); + s.open(path_a3da, "wb"); if (s.check_not_null()) - a3da_read_inner(this, s); + a3da_write_inner(this, s); + free_def(path_a3da); } - free_def(path_a3da); -} -void a3da::read(const wchar_t* path) { - if (!path) - return; + void Scene::write(const wchar_t* path) { + if (!path || !ready) + return; - wchar_t* path_a3da = str_utils_add(path, (wchar_t*)L".a3da"); - if (!path_a3da) - return; + wchar_t* path_a3da = str_utils_add(path, L".a3da"); + if (!path_a3da) + return; - if (path_check_file_exists(path_a3da)) { file_stream s; - s.open(path_a3da, L"rb"); + s.open(path_a3da, L"wb"); if (s.check_not_null()) - a3da_read_inner(this, s); + a3da_write_inner(this, s); + free_def(path_a3da); } - free_def(path_a3da); -} -void a3da::read(const void* data, size_t size) { - if (!data || !size) - return; + void Scene::write(void** data, size_t* size) { + if (!data || !size || !ready) + return; - memory_stream s; - s.open(data, size); - a3da_read_inner(this, s); -} - -void a3da::write(const char* path) { - if (!path || !ready) - return; - - char* path_a3da = str_utils_add(path, ".a3da"); - if (!path_a3da) - return; - - file_stream s; - s.open(path_a3da, "wb"); - if (s.check_not_null()) + memory_stream s; a3da_write_inner(this, s); - free_def(path_a3da); -} - -void a3da::write(const wchar_t* path) { - if (!path || !ready) - return; - - wchar_t* path_a3da = str_utils_add(path, L".a3da"); - if (!path_a3da) - return; - - file_stream s; - s.open(path_a3da, L"wb"); - if (s.check_not_null()) - a3da_write_inner(this, s); - free_def(path_a3da); -} - -void a3da::write(void** data, size_t* size) { - if (!data || !size || !ready) - return; - - memory_stream s; - a3da_write_inner(this, s); - s.copy(data, size); -} - -bool a3da::load_file(void* data, const char* dir, const char* file, uint32_t hash) { - size_t file_len = utf8_length(file); - - const char* t = strrchr(file, '.'); - if (t) - file_len = t - file; - - std::string path(dir); - path.append(file, file_len); - - a3da* a = (a3da*)data; - a->read(path.c_str()); - - return a->ready; -} - -static void a3da_read_inner(a3da* a, stream& s) { - a3dc_header header = {}; - - a->format = A3DA_FORMAT_F; - uint32_t signature = s.read_uint32_t(); - s.set_position(0x00, SEEK_SET); - - memory_stream _s; - if (signature == reverse_endianness_int32_t('A3DA')) { - f2_struct st; - st.read(s); - _s.open(st.data); - a->format = A3DA_FORMAT_F2; - } - else { - size_t length = s.length; - void* data = force_malloc(length); - s.read(data, length); - _s.open(data, length); - free_def(data); + s.copy(data, size); } - void* a3da_data; + bool Scene::load_file(void* data, const char* dir, const char* file, uint32_t hash) { + size_t file_len = utf8_length(file); - signature = _s.read_uint32_t(); - if (signature != reverse_endianness_int32_t('#A3D')) - return; + const char* t = strrchr(file, '.'); + if (t) + file_len = t - file; - signature = _s.read_uint32_t(); - if ((signature & 0xFF) == 'A') { - header.string_offset = 0x10; - header.string_length = (int32_t)(_s.length - 0x10); - } - else if ((signature & 0xFF) == 'C') { - _s.set_position(0x10, SEEK_SET); - _s.read_int32_t(); - _s.read_int32_t(); - uint32_t sub_headers_offset = _s.read_uint32_t_reverse_endianness(true); - uint16_t sub_headers_count = _s.read_uint16_t_reverse_endianness(true); - uint16_t sub_headers_stride = _s.read_uint16_t_reverse_endianness(true); + std::string path(dir); + path.append(file, file_len); - if (sub_headers_count != 0x02) - return; + Scene* sc = (Scene*)data; + sc->read(path.c_str()); - _s.set_position(sub_headers_offset, SEEK_SET); - if (_s.read_int32_t() != 0x50) - return; - header.string_offset = _s.read_uint32_t_reverse_endianness(true); - header.string_length = _s.read_uint32_t_reverse_endianness(true); - - _s.set_position((int64_t)sub_headers_offset + sub_headers_stride, SEEK_SET); - if (_s.read_int32_t() != 0x4C42) - return; - header.binary_offset = _s.read_uint32_t_reverse_endianness(true); - header.binary_length = _s.read_uint32_t_reverse_endianness(true); - } - else - return; - - _s.set_position(header.string_offset, SEEK_SET); - a3da_data = force_malloc(header.string_length + 1LL); - _s.read(a3da_data, header.string_length); - ((uint8_t*)a3da_data)[header.string_length] = 0; - a3da_read_text(a, a3da_data, header.string_length); - free_def(a3da_data); - - if (signature == reverse_endianness_int32_t('C___')) { - a->compressed = true; - _s.set_position(header.binary_offset, SEEK_SET); - void* a3dc_data = force_malloc(header.binary_length); - _s.read(a3dc_data, header.binary_length); - a3da_read_data(a, a3dc_data, header.binary_length); - free_def(a3dc_data); - } - a->ready = true; -} - -static void a3da_write_inner(a3da* a, stream& s) { - bool a3dc = a->compressed || a->format > A3DA_FORMAT_AFT && a->format != A3DA_FORMAT_AFT_X_PACK; - - if (a->format <= A3DA_FORMAT_AFT || a->format == A3DA_FORMAT_AFT_X_PACK) - a->_compress_f16 = A3DA_COMPRESS_F32F32F32F32; - - void* a3dc_data = 0; - size_t a3dc_data_length = 0; - if (a3dc) - a3da_write_data(a, &a3dc_data, &a3dc_data_length); - - void* a3da_data = 0; - size_t a3da_data_length = 0; - a3da_write_text(a, &a3da_data, &a3da_data_length, a3dc); - - memory_stream s_a3da; - stream& _s = s; - if (a->format > A3DA_FORMAT_AFT && a->format != A3DA_FORMAT_AFT_X_PACK) { - s_a3da.open(); - _s = s_a3da; + return sc->ready; } - if (a3dc) { + static void a3da_read_inner(Scene* sc, stream& s) { a3dc_header header = {}; - header.string_offset = (uint32_t)0x40; - header.string_length = (uint32_t)a3da_data_length; - header.binary_offset = (uint32_t)(0x40 + align_val(a3da_data_length, 0x20)); - header.binary_length = (uint32_t)a3dc_data_length; - - _s.write("#A3DC__________\n", 16); - _s.write_int32_t(0x2000); - _s.write_int32_t(0x00); - _s.write_uint32_t_reverse_endianness(0x20, true); - _s.write_uint16_t_reverse_endianness(0x02, true); - _s.write_uint16_t_reverse_endianness(0x10, true); - _s.write_char('P'); - _s.align_write(0x04); - _s.write_uint32_t_reverse_endianness(header.string_offset, true); - _s.write_uint32_t_reverse_endianness(header.string_length, true); - _s.write_uint32_t_reverse_endianness(0x01, true); - _s.write_char('B'); - _s.write_char('L'); - _s.align_write(0x04); - _s.write_uint32_t_reverse_endianness(header.binary_offset, true); - _s.write_uint32_t_reverse_endianness(header.binary_length, true); - _s.write_uint32_t_reverse_endianness(0x20, true); - _s.write(a3da_data, a3da_data_length); - _s.align_write(0x20); - _s.write(a3dc_data, a3dc_data_length); - free_def(a3dc_data); - } - else - _s.write(a3da_data, a3da_data_length); - free_def(a3da_data); - - if (a->format > A3DA_FORMAT_AFT && a->format != A3DA_FORMAT_AFT_X_PACK) { - f2_struct st; - s_a3da.align_write(0x10); - s_a3da.copy(st.data); - s_a3da.close(); - - new (&st.header) f2_header('A3DA'); - st.header.inner_signature = a->format == A3DA_FORMAT_XHD ? 0x00131010 : 0x01131010; - - st.write(s, true, a->format == A3DA_FORMAT_X || a->format == A3DA_FORMAT_XHD); - } -} - -static void a3da_read_text(a3da* a, void* data, size_t size) { - key_val kv; - kv.parse((uint8_t*)data, size); - - if (kv.open_scope("_")) { - int32_t compress_f16; - if (kv.read("compress_f16", compress_f16)) - a->_compress_f16 = (a3da_compress_f16)compress_f16; - kv.read("converter.version", a->_converter_version); - kv.read("file_name", a->_file_name); - kv.read("property.version", a->_property_version); - - kv.close_scope(); - } - - if (kv.open_scope("camera_auxiliary")) { - a3da_camera_auxiliary* ca = &a->camera_auxiliary; - - if (key_val_read(&kv, "auto_exposure", ca->auto_exposure)) - enum_or(ca->flags, A3DA_CAMERA_AUXILIARY_AUTO_EXPOSURE); - if (key_val_read(&kv, "exposure", ca->exposure)) - enum_or(ca->flags, A3DA_CAMERA_AUXILIARY_EXPOSURE); - if (key_val_read(&kv, "exposure_rate", ca->exposure_rate)) - enum_or(ca->flags, A3DA_CAMERA_AUXILIARY_EXPOSURE_RATE); - if (key_val_read(&kv, "gamma", ca->gamma)) - enum_or(ca->flags, A3DA_CAMERA_AUXILIARY_GAMMA); - if (key_val_read(&kv, "gamma_rate", ca->gamma_rate)) - enum_or(ca->flags, A3DA_CAMERA_AUXILIARY_GAMMA_RATE); - if (key_val_read(&kv, "saturate", ca->saturate)) - enum_or(ca->flags, A3DA_CAMERA_AUXILIARY_SATURATE); - - if (ca->flags & (A3DA_CAMERA_AUXILIARY_EXPOSURE_RATE | A3DA_CAMERA_AUXILIARY_GAMMA_RATE)) - if (a->format < A3DA_FORMAT_F || a->format == A3DA_FORMAT_AFT) - a->format = A3DA_FORMAT_F; - - kv.close_scope(); - } - - if (kv.open_scope("play_control")) { - a3da_play_control* pc = &a->play_control; - - kv.read("begin", pc->begin); - if (kv.read("div", pc->div)) - enum_or(pc->flags, A3DA_PLAY_CONTROL_DIV); - kv.read("fps", pc->fps); - if (kv.read("offset", pc->offset)) - enum_or(pc->flags, A3DA_PLAY_CONTROL_OFFSET); - kv.read("size", pc->size); - - kv.close_scope(); - } - - if (kv.open_scope("post_process")) { - a3da_post_process* pp = &a->post_process; - - if (key_val_read(&kv, "Diffuse", pp->intensity)) - enum_or(pp->flags, A3DA_POST_PROCESS_INTENSITY); - if (key_val_read(&kv, "lens_flare", pp->lens_flare)) - enum_or(pp->flags, A3DA_POST_PROCESS_LENS_FLARE); - if (key_val_read(&kv, "lens_ghost", pp->lens_ghost)) - enum_or(pp->flags, A3DA_POST_PROCESS_LENS_GHOST); - if (key_val_read(&kv, "lens_shaft", pp->lens_shaft)) - enum_or(pp->flags, A3DA_POST_PROCESS_LENS_SHAFT); - if (key_val_read(&kv, "Ambient", pp->radius)) - enum_or(pp->flags, A3DA_POST_PROCESS_RADIUS); - if (key_val_read(&kv, "Specular", pp->scene_fade)) - enum_or(pp->flags, A3DA_POST_PROCESS_SCENE_FADE); - - kv.close_scope(); - } - - if (kv.open_scope("dof")) { - a3da_dof* d = &a->dof; - - d->has_dof = key_val_read(&kv, "", d->model_transform); - - kv.close_scope(); - } - - int32_t count; - if (kv.read("ambient", "length", count)) { - a->ambient.resize(count); - a3da_ambient* va = a->ambient.data(); - for (int32_t i = 0; i < count; i++) { - if (!kv.open_scope_fmt(i)) - continue; - - a3da_ambient* a = &va[i]; - if (key_val_read(&kv, "light.Diffuse", a->light_diffuse)) - enum_or(a->flags, A3DA_AMBIENT_LIGHT_DIFFUSE); - kv.read("name", a->name); - if (key_val_read(&kv, "rim.light.Diffuse", a->rim_light_diffuse)) - enum_or(a->flags, A3DA_AMBIENT_RIM_LIGHT_DIFFUSE); - - kv.close_scope(); - } - kv.close_scope(); - } - - if (kv.read("auth_2d", "length", count)) { - a->auth_2d.resize(count); - std::string* va2 = a->auth_2d.data(); - for (int32_t i = 0; i < count; i++) { - if (!kv.open_scope_fmt(i)) - continue; - - kv.read(va2[i]); - kv.close_scope(); - } - kv.close_scope(); - } - - if (kv.read("camera_root", "length", count)) { - a->camera_root.resize(count); - a3da_camera_root* vcr = a->camera_root.data(); - for (int32_t i = 0; i < count; i++) { - if (!kv.open_scope_fmt(i)) - continue; - - a3da_camera_root* cr = &vcr[i]; - key_val_read(&kv, "interest", cr->interest); - key_val_read(&kv, "", cr->model_transform); - - a3da_camera_root_view_point* vp = &cr->view_point; - - if (!kv.open_scope("view_point")) { - kv.close_scope(); - continue; - } - - kv.read("aspect", vp->aspect); - - if (kv.has_key("fov_is_horizontal")) { - key_val_read(&kv, "fov", vp->fov); - kv.read("fov_is_horizontal", vp->fov_is_horizontal); - enum_or(vp->flags, A3DA_CAMERA_ROOT_VIEW_POINT_FOV); - } - else { - kv.read("camera_aperture_h", vp->camera_aperture_h); - kv.read("camera_aperture_w", vp->camera_aperture_w); - key_val_read(&kv, "focal_length", vp->focal_length); - } - key_val_read(&kv, "", vp->model_transform); - if (key_val_read(&kv, "roll", vp->roll)) - enum_or(vp->flags, A3DA_CAMERA_ROOT_VIEW_POINT_ROLL); - - kv.close_scope(); - kv.close_scope(); - } - kv.close_scope(); - } - - if (kv.read("chara", "length", count)) { - a->chara.resize(count); - a3da_chara* vc = a->chara.data(); - for (int32_t i = 0; i < count; i++) { - if (!kv.open_scope_fmt(i)) - continue; - - a3da_chara* c = &vc[i]; - key_val_read(&kv, "", c->model_transform); - kv.read("name", c->name); - - kv.close_scope(); - } - kv.close_scope(); - } - - if (kv.read("curve", "length", count)) { - a->curve.resize(count); - a3da_curve* vc = a->curve.data(); - for (int32_t i = 0; i < count; i++) { - if (!kv.open_scope_fmt(i)) - continue; - - a3da_curve* c = &vc[i]; - key_val_read(&kv, "cv", c->curve); - kv.read("name", c->name); - - kv.close_scope(); - } - kv.close_scope(); - } - - if (kv.read("event", "length", count)) { - a->event.resize(count); - a3da_event* ve = a->event.data(); - for (int32_t i = 0; i < count; i++) { - if (!kv.open_scope_fmt(i)) - continue; - - a3da_event* e = &ve[i]; - kv.read("begin", e->begin); - kv.read("clip_begin", e->clip_begin); - kv.read("clip_end", e->clip_end); - kv.read("end", e->end); - kv.read("name", e->name); - kv.read("param1", e->param1); - kv.read("ref", e->ref); - kv.read("time_ref_scale", e->time_ref_scale); - - int32_t type; - if (kv.read("type", type)) - e->type = (a3da_event_type)type; - - kv.close_scope(); - } - kv.close_scope(); - } - - if (kv.read("fog", "length", count)) { - a->fog.resize(count); - a3da_fog* vf = a->fog.data(); - for (int32_t i = 0; i < count; i++) { - if (!kv.open_scope_fmt(i)) - continue; - - a3da_fog* f = &vf[i]; - if (key_val_read(&kv, "Diffuse", f->color)) - enum_or(f->flags, A3DA_FOG_COLOR); - if (key_val_read(&kv, "density", f->density)) - enum_or(f->flags, A3DA_FOG_DENSITY); - if (key_val_read(&kv, "end", f->end)) - enum_or(f->flags, A3DA_FOG_END); - - int32_t id; - if (kv.read("id", id)) - f->id = (fog_id)id; - - std::string name; - if (kv.read("name", name)) { - if (!name.compare("Z")) - f->id = FOG_DEPTH; - else if (!name.compare("Height")) - f->id = FOG_HEIGHT; - } - - if (key_val_read(&kv, "start", f->start)) - enum_or(f->flags, A3DA_FOG_START); - - kv.close_scope(); - } - kv.close_scope(); - } - - if (kv.read("light", "length", count)) { - a->light.resize(count); - a3da_light* vl = a->light.data(); - for (int32_t i = 0; i < count; i++) { - if (!kv.open_scope_fmt(i)) - continue; - - a3da_light* l = &vl[i]; - if (key_val_read(&kv, "Ambient", l->ambient)) - enum_or(l->flags, A3DA_LIGHT_AMBIENT); - if (key_val_read(&kv, "ConeAngle", l->cone_angle)) - enum_or(l->flags, A3DA_LIGHT_CONE_ANGLE); - if (key_val_read(&kv, "CONSTANT", l->constant)) - enum_or(l->flags, A3DA_LIGHT_CONSTANT); - if (key_val_read(&kv, "Diffuse", l->diffuse)) - enum_or(l->flags, A3DA_LIGHT_DIFFUSE); - if (key_val_read(&kv, "DropOff", l->drop_off)) - enum_or(l->flags, A3DA_LIGHT_DROP_OFF); - if (key_val_read(&kv, "FAR", l->_far)) - enum_or(l->flags, A3DA_LIGHT_FAR); - - int32_t id; - if (kv.read("id", id)) - l->id = (light_id)id; - - if (key_val_read(&kv, "Intensity", l->intensity)) - enum_or(l->flags, A3DA_LIGHT_INTENSITY); - if (key_val_read(&kv, "LINEAR", l->linear)) - enum_or(l->flags, A3DA_LIGHT_LINEAR); - if (key_val_read(&kv, "position", l->position)) - enum_or(l->flags, A3DA_LIGHT_POSITION); - if (key_val_read(&kv, "QUADRATIC", l->quadratic)) - enum_or(l->flags, A3DA_LIGHT_QUADRATIC); - if (key_val_read(&kv, "Specular", l->specular)) - enum_or(l->flags, A3DA_LIGHT_SPECULAR); - if (key_val_read(&kv, "spot_direction", l->spot_direction)) - enum_or(l->flags, A3DA_LIGHT_SPOT_DIRECTION); - if (key_val_read(&kv, "Incandescence", l->tone_curve)) - enum_or(l->flags, A3DA_LIGHT_TONE_CURVE); - kv.read("type", l->type); - - kv.close_scope(); - } - kv.close_scope(); - } - - if (kv.read("m_objhrc", "length", count)) { - a->m_object_hrc.resize(count); - a3da_m_object_hrc* vmoh = a->m_object_hrc.data(); - for (int32_t i = 0; i < count; i++) { - if (!kv.open_scope_fmt(i)) - continue; - - a3da_m_object_hrc* moh = &vmoh[i]; - int32_t count; - if (kv.read("instance", "length", count)) { - moh->instance.resize(count); - a3da_object_instance* voi = moh->instance.data(); - for (int32_t j = 0; j < count; j++) { - if (!kv.open_scope_fmt(j)) - continue; - - a3da_object_instance* oi = &voi[j]; - key_val_read(&kv, "", oi->model_transform); - kv.read("name", oi->name); - kv.read("shadow", oi->shadow); - kv.read("uid_name", oi->uid_name); - - kv.close_scope(); - } - kv.close_scope(); - } - - key_val_read(&kv, "", moh->model_transform); - kv.read("name", moh->name); - - if (kv.read("node", "length", count)) { - moh->node.resize(count); - a3da_object_node* von = moh->node.data(); - for (int32_t j = 0; j < count; j++) { - if (!kv.open_scope_fmt(j)) - continue; - - a3da_object_node* on = &von[j]; - if (kv.read("joint_orient", on->joint_orient)) - enum_or(on->flags, A3DA_OBJECT_NODE_JOINT_ORIENT); - key_val_read(&kv, "", on->model_transform); - kv.read("name", on->name); - kv.read("parent", on->parent); - - kv.close_scope(); - } - kv.close_scope(); - } - - kv.close_scope(); - } - kv.close_scope(); - } - - if (kv.read("m_objhrc_list", "length", count)) { - a->m_object_hrc_list.resize(count); - std::string* vmohl = a->m_object_hrc_list.data(); - for (int32_t i = 0; i < count; i++) { - if (!kv.open_scope_fmt(i)) - continue; - - kv.read(vmohl[i]); - kv.close_scope(); - } - kv.close_scope(); - } - - if (kv.read("material_list", "length", count)) { - a->material_list.resize(count); - a3da_material_list* vml = a->material_list.data(); - for (int32_t i = 0; i < count; i++) { - if (!kv.open_scope_fmt(i)) - continue; - - a3da_material_list* ml = &vml[i]; - if (key_val_read(&kv, "blend_color", ml->blend_color)) - enum_or(ml->flags, A3DA_MATERIAL_LIST_BLEND_COLOR); - if (key_val_read(&kv, "glow_intensity", ml->glow_intensity)) - enum_or(ml->flags, A3DA_MATERIAL_LIST_GLOW_INTENSITY); - if (key_val_read(&kv, "incandescence", ml->emission)) - enum_or(ml->flags, A3DA_MATERIAL_LIST_EMISSION); - kv.read("name", ml->name); - - kv.close_scope(); - } - kv.close_scope(); - } - - if (kv.read("motion", "length", count)) { - a->motion.resize(count); - std::string* vm = a->motion.data(); - for (int32_t i = 0; i < count; i++) { - if (!kv.open_scope_fmt(i)) - continue; - - kv.read(vm[i]); - kv.close_scope(); - } - kv.close_scope(); - } - - if (kv.read("object", "length", count)) { - a->object.resize(count); - a3da_object* vo = a->object.data(); - for (int32_t i = 0; i < count; i++) { - if (!kv.open_scope_fmt(i)) - continue; - - a3da_object* o = &vo[i]; - key_val_read(&kv, "", o->model_transform); - if (kv.read("morph", o->morph)) - kv.read("morph_offset", o->morph_offset); - kv.read("name", o->name); - kv.read("parent_name", o->parent_name); - kv.read("parent_node", o->parent_node); - if (kv.read("pat", o->pattern)) - kv.read("pat_offset", o->pattern_offset); - - int32_t count; - if (kv.read("tex_pat", "length", count)) { - o->texture_pattern.resize(count); - a3da_object_texture_pattern* votp = o->texture_pattern.data(); - for (int32_t j = 0; j < count; j++) { - if (!kv.open_scope_fmt(j)) - continue; - - a3da_object_texture_pattern* otp = &votp[j]; - kv.read("name", otp->name); - if (kv.read("pat", otp->pattern)) - kv.read("pat_offset", otp->pattern_offset); - - kv.close_scope(); - } - kv.close_scope(); - } - - if (kv.read("tex_transform", "length", count)) { - o->texture_transform.resize(count); - a3da_object_texture_transform* vott = o->texture_transform.data(); - for (int32_t j = 0; j < count; j++) { - if (!kv.open_scope_fmt(j)) - continue; - - a3da_object_texture_transform* ott = &vott[j]; - if (key_val_read(&kv, "coverageU", ott->coverage_u)) - enum_or(ott->flags, A3DA_OBJECT_TEXTURE_TRANSFORM_COVERAGE_U); - if (key_val_read(&kv, "coverageV", ott->coverage_v)) - enum_or(ott->flags, A3DA_OBJECT_TEXTURE_TRANSFORM_COVERAGE_V); - kv.read("name", ott->name); - if (key_val_read(&kv, "offsetU", ott->offset_u)) - enum_or(ott->flags, A3DA_OBJECT_TEXTURE_TRANSFORM_OFFSET_U); - if (key_val_read(&kv, "offsetV", ott->offset_v)) - enum_or(ott->flags, A3DA_OBJECT_TEXTURE_TRANSFORM_OFFSET_V); - if (key_val_read(&kv, "repeatU", ott->repeat_u)) - enum_or(ott->flags, A3DA_OBJECT_TEXTURE_TRANSFORM_REPEAT_U); - if (key_val_read(&kv, "repeatV", ott->repeat_v)) - enum_or(ott->flags, A3DA_OBJECT_TEXTURE_TRANSFORM_REPEAT_V); - if (key_val_read(&kv, "rotate", ott->rotate)) - enum_or(ott->flags, A3DA_OBJECT_TEXTURE_TRANSFORM_ROTATE); - if (key_val_read(&kv, "rotateFrame", ott->rotate_frame)) - enum_or(ott->flags, A3DA_OBJECT_TEXTURE_TRANSFORM_ROTATE_FRAME); - if (key_val_read(&kv, "translateFrameU", ott->translate_frame_u)) - enum_or(ott->flags, A3DA_OBJECT_TEXTURE_TRANSFORM_TRANSLATE_FRAME_U); - if (key_val_read(&kv, "translateFrameV", ott->translate_frame_v)) - enum_or(ott->flags, A3DA_OBJECT_TEXTURE_TRANSFORM_TRANSLATE_FRAME_V); - - kv.close_scope(); - } - kv.close_scope(); - } - - kv.read("uid_name", o->uid_name); - - kv.close_scope(); - } - kv.close_scope(); - } - - if (kv.read("object_list", "length", count)) { - a->object_list.resize(count); - std::string* vol = a->object_list.data(); - for (int32_t i = 0; i < count; i++) { - if (!kv.open_scope_fmt(i)) - continue; - - kv.read(vol[i]); - kv.close_scope(); - } - kv.close_scope(); - } - - if (kv.read("objhrc", "length", count)) { - a->object_hrc.resize(count); - a3da_object_hrc* voh = a->object_hrc.data(); - for (int32_t i = 0; i < count; i++) { - if (!kv.open_scope_fmt(i)) - continue; - - a3da_object_hrc* oh = &voh[i]; - kv.read("name", oh->name); - - int32_t count; - if (kv.read("node", "length", count)) { - oh->node.resize(count); - a3da_object_node* vohn = oh->node.data(); - for (int32_t j = 0; j < count; j++) { - if (!kv.open_scope_fmt(j)) - continue; - - a3da_object_node* ohn = &vohn[j]; - if (kv.read("joint_orient", ohn->joint_orient)) - enum_or(ohn->flags, A3DA_OBJECT_NODE_JOINT_ORIENT); - key_val_read(&kv, "", ohn->model_transform); - kv.read("name", ohn->name); - kv.read("parent", ohn->parent); - - kv.close_scope(); - } - kv.close_scope(); - } - - kv.read("parent_name", oh->parent_name); - kv.read("parent_node", oh->parent_node); - kv.read("shadow", oh->shadow); - kv.read("uid_name", oh->uid_name); - - kv.close_scope(); - } - kv.close_scope(); - } - - if (kv.read("objhrc_list", "length", count)) { - a->object_hrc_list.resize(count); - std::string* vohl = a->object_hrc_list.data(); - for (int32_t i = 0; i < count; i++) { - if (!kv.open_scope_fmt(i)) - continue; - - kv.read(vohl[i]); - kv.close_scope(); - } - kv.close_scope(); - } - - if (kv.read("point", "length", count)) { - a->point.resize(count); - a3da_point* vp = a->point.data(); - for (int32_t i = 0; i < count; i++) { - if (!kv.open_scope_fmt(i)) - continue; - - a3da_point* p = &vp[i]; - key_val_read(&kv, "", p->model_transform); - kv.read("name", p->name); - - kv.close_scope(); - } - kv.close_scope(); - } -} - -static void a3da_write_text(a3da* a, void** data, size_t* size, bool a3dc) { - char a3da_timestamp[0x100]; - a3da_get_time_stamp(a3da_timestamp, 0x100); - - memory_stream s; - s.open(); - - if (a3dc) { - if (a->_compress_f16 != A3DA_COMPRESS_F32F32F32F32) - s.write("#-compress_f16\n", 15); - } - else - s.write("#A3DA__________\n", 16); - - s.write_utf8_string(a3da_timestamp); - - key_val_out kv; - - { - kv.open_scope("_"); - - if (a3dc && a->format > A3DA_FORMAT_AFT && a->format != A3DA_FORMAT_AFT_X_PACK) - kv.write(s, "compress_f16", a->_compress_f16); - kv.write(s, "converter.version", a->_converter_version); - kv.write(s, "file_name", a->_file_name); - kv.write(s, "property.version", a->_property_version); - - kv.close_scope(); - } - - if (a->ambient.size() && a->format == A3DA_FORMAT_MGF) { - kv.open_scope("ambient"); - - int32_t count = (int32_t)a->ambient.size(); - a3da_ambient* va = a->ambient.data(); - - std::vector sort_index; - key_val_out::get_lexicographic_order(sort_index, count); - int32_t* sort_index_data = sort_index.data(); - for (int32_t i = 0; i < count; i++) { - kv.open_scope_fmt(sort_index_data[i]); - - a3da_ambient* a = &va[sort_index_data[i]]; - if (a->flags & A3DA_AMBIENT_LIGHT_DIFFUSE) - key_val_out_write(&kv, s, "light.Diffuse", a->light_diffuse); - kv.write(s, "name", a->name); - if (a->flags & A3DA_AMBIENT_RIM_LIGHT_DIFFUSE) - key_val_out_write(&kv, s, "rimlight.Diffuse", a->rim_light_diffuse); - - kv.close_scope(); - } - - kv.write(s, "length", count); - kv.close_scope(); - } - - if (a->auth_2d.size()) { - kv.open_scope("auth_2d"); - - int32_t count = (int32_t)a->auth_2d.size(); - std::string* va2 = a->auth_2d.data(); - - std::vector sort_index; - key_val_out::get_lexicographic_order(sort_index, count); - int32_t* sort_index_data = sort_index.data(); - for (int32_t i = 0; i < count; i++) { - kv.open_scope_fmt(sort_index_data[i]); - kv.write(s, "name", va2[sort_index_data[i]]); - kv.close_scope(); - } - - kv.write(s, "length", count); - kv.close_scope(); - } - - if (a->camera_auxiliary.flags) { - kv.open_scope("camera_auxiliary"); - - a3da_camera_auxiliary* ca = &a->camera_auxiliary; - if (a->format == A3DA_FORMAT_F || a->format > A3DA_FORMAT_AFT && a->format != A3DA_FORMAT_AFT_X_PACK) { - if (ca->flags & A3DA_CAMERA_AUXILIARY_EXPOSURE_RATE) - key_val_out_write(&kv, s, "exposure_rate", ca->exposure_rate, true); - if (ca->flags & A3DA_CAMERA_AUXILIARY_GAMMA_RATE) - key_val_out_write(&kv, s, "gamma_rate", ca->gamma_rate, true); - if (ca->flags & A3DA_CAMERA_AUXILIARY_SATURATE) - key_val_out_write(&kv, s, "saturate", ca->saturate, true); + sc->format = FORMAT_F; + uint32_t signature = s.read_uint32_t(); + s.set_position(0x00, SEEK_SET); + + memory_stream _s; + if (signature == reverse_endianness_int32_t('A3DA')) { + f2_struct st; + st.read(s); + _s.open(st.data); + sc->format = FORMAT_F2; } else { - if (ca->flags & A3DA_CAMERA_AUXILIARY_AUTO_EXPOSURE) - key_val_out_write(&kv, s, "auto_exposure", ca->auto_exposure, true); - if (ca->flags & A3DA_CAMERA_AUXILIARY_EXPOSURE) - key_val_out_write(&kv, s, "exposure", ca->exposure, true); - if (ca->flags & A3DA_CAMERA_AUXILIARY_GAMMA) - key_val_out_write(&kv, s, "gamma", ca->gamma, true); - if (ca->flags & A3DA_CAMERA_AUXILIARY_SATURATE) - key_val_out_write(&kv, s, "saturate", ca->saturate, true); + size_t length = s.length; + void* data = force_malloc(length); + s.read(data, length); + _s.open(data, length); + free_def(data); } - kv.close_scope(); + void* a3da_data; + + signature = _s.read_uint32_t(); + if (signature != reverse_endianness_int32_t('#A3D')) + return; + + signature = _s.read_uint32_t(); + if ((signature & 0xFF) == 'A') { + header.string_offset = 0x10; + header.string_length = (int32_t)(_s.length - 0x10); + } + else if ((signature & 0xFF) == 'C') { + _s.set_position(0x10, SEEK_SET); + _s.read_int32_t(); + _s.read_int32_t(); + uint32_t sub_headers_offset = _s.read_uint32_t_reverse_endianness(true); + uint16_t sub_headers_count = _s.read_uint16_t_reverse_endianness(true); + uint16_t sub_headers_stride = _s.read_uint16_t_reverse_endianness(true); + + if (sub_headers_count != 0x02) + return; + + _s.set_position(sub_headers_offset, SEEK_SET); + if (_s.read_int32_t() != 0x50) + return; + header.string_offset = _s.read_uint32_t_reverse_endianness(true); + header.string_length = _s.read_uint32_t_reverse_endianness(true); + + _s.set_position((int64_t)sub_headers_offset + sub_headers_stride, SEEK_SET); + if (_s.read_int32_t() != 0x4C42) + return; + header.binary_offset = _s.read_uint32_t_reverse_endianness(true); + header.binary_length = _s.read_uint32_t_reverse_endianness(true); + } + else + return; + + _s.set_position(header.string_offset, SEEK_SET); + a3da_data = force_malloc(header.string_length + 1LL); + _s.read(a3da_data, header.string_length); + ((uint8_t*)a3da_data)[header.string_length] = 0; + a3da_read_text(sc, a3da_data, header.string_length); + free_def(a3da_data); + + if (signature == reverse_endianness_int32_t('C___')) { + sc->compressed = true; + _s.set_position(header.binary_offset, SEEK_SET); + void* a3dc_data = force_malloc(header.binary_length); + _s.read(a3dc_data, header.binary_length); + a3da_read_data(sc, a3dc_data, header.binary_length); + free_def(a3dc_data); + } + sc->ready = true; } - if (a->camera_root.size() > 0) { - kv.open_scope("camera_root"); + static void a3da_write_inner(Scene* sc, stream& s) { + bool a3dc = sc->compressed || sc->format > FORMAT_AFT && sc->format != FORMAT_AFT_X_PACK; - int32_t count = (int32_t)a->camera_root.size(); - a3da_camera_root* vcr = a->camera_root.data(); + if (sc->format <= FORMAT_AFT || sc->format == FORMAT_AFT_X_PACK) + sc->_compress_f16 = COMPRESS_F32F32F32F32; - std::vector sort_index; - key_val_out::get_lexicographic_order(sort_index, count); - int32_t* sort_index_data = sort_index.data(); - for (int32_t i = 0; i < count; i++) { - kv.open_scope_fmt(sort_index_data[i]); + void* a3dc_data = 0; + size_t a3dc_data_length = 0; + if (a3dc) + a3da_write_data(sc, &a3dc_data, &a3dc_data_length); - a3da_camera_root* cr = &vcr[sort_index_data[i]]; - key_val_out_write(&kv, s, "interest", cr->interest, 0x1F); - key_val_out_write(&kv, s, "", cr->model_transform, 0x1E); + void* a3da_data = 0; + size_t a3da_data_length = 0; + a3da_write_text(sc, &a3da_data, &a3da_data_length, a3dc); - { - kv.open_scope("view_point"); + memory_stream s_a3da; + stream& _s = s; + if (sc->format > FORMAT_AFT && sc->format != FORMAT_AFT_X_PACK) { + s_a3da.open(); + _s = s_a3da; + } - a3da_camera_root_view_point* vp = &cr->view_point; - kv.write(s, "aspect", vp->aspect); - if (vp->flags & A3DA_CAMERA_ROOT_VIEW_POINT_FOV) { - key_val_out_write(&kv, s, "fov", vp->fov); - kv.write(s, "fov_is_horizontal", vp->fov_is_horizontal); + if (a3dc) { + a3dc_header header = {}; + + header.string_offset = (uint32_t)0x40; + header.string_length = (uint32_t)a3da_data_length; + header.binary_offset = (uint32_t)(0x40 + align_val(a3da_data_length, 0x20)); + header.binary_length = (uint32_t)a3dc_data_length; + + _s.write("#A3DC__________\n", 16); + _s.write_int32_t(0x2000); + _s.write_int32_t(0x00); + _s.write_uint32_t_reverse_endianness(0x20, true); + _s.write_uint16_t_reverse_endianness(0x02, true); + _s.write_uint16_t_reverse_endianness(0x10, true); + _s.write_char('P'); + _s.align_write(0x04); + _s.write_uint32_t_reverse_endianness(header.string_offset, true); + _s.write_uint32_t_reverse_endianness(header.string_length, true); + _s.write_uint32_t_reverse_endianness(0x01, true); + _s.write_char('B'); + _s.write_char('L'); + _s.align_write(0x04); + _s.write_uint32_t_reverse_endianness(header.binary_offset, true); + _s.write_uint32_t_reverse_endianness(header.binary_length, true); + _s.write_uint32_t_reverse_endianness(0x20, true); + _s.write(a3da_data, a3da_data_length); + _s.align_write(0x20); + _s.write(a3dc_data, a3dc_data_length); + free_def(a3dc_data); + } + else + _s.write(a3da_data, a3da_data_length); + free_def(a3da_data); + + if (sc->format > FORMAT_AFT && sc->format != FORMAT_AFT_X_PACK) { + f2_struct st; + s_a3da.align_write(0x10); + s_a3da.copy(st.data); + s_a3da.close(); + + new (&st.header) f2_header('A3DA'); + st.header.inner_signature = sc->format == FORMAT_XHD ? 0x00131010 : 0x01131010; + + st.write(s, true, sc->format == FORMAT_X || sc->format == FORMAT_XHD); + } + } + + static void a3da_read_text(Scene* sc, void* data, size_t size) { + key_val kv; + kv.parse((uint8_t*)data, size); + + if (kv.open_scope("_")) { + int32_t compress_f16; + if (kv.read("compress_f16", compress_f16)) + sc->_compress_f16 = (COMPRESS_TYPE)compress_f16; + kv.read("converter.version", sc->_converter_version); + kv.read("file_name", sc->_file_name); + kv.read("property.version", sc->_property_version); + + kv.close_scope(); + } + + if (kv.open_scope("camera_auxiliary")) { + CameraAuxiliary* ca = &sc->camera_auxiliary; + + if (key_val_read(&kv, "exposure", ca->exposure)) + ca->flag |= CameraAuxiliary::FLAG_EXPOSURE; + if (key_val_read(&kv, "exposure_rate", ca->exposure_rate)) // F/F2/X + ca->flag |= CameraAuxiliary::FLAG_EXPOSURE_RATE; + if (key_val_read(&kv, "gamma", ca->gamma)) + ca->flag |= CameraAuxiliary::FLAG_GAMMA; + if (key_val_read(&kv, "gamma_rate", ca->gamma_rate)) // F/F2/X + ca->flag |= CameraAuxiliary::FLAG_GAMMA_RATE; + if (key_val_read(&kv, "saturate", ca->saturate)) + ca->flag |= CameraAuxiliary::FLAG_SATURATE; + if (key_val_read(&kv, "auto_exposure", ca->auto_exposure)) + ca->flag |= CameraAuxiliary::FLAG_AUTO_EXPOSURE; + + if (ca->flag & (CameraAuxiliary::FLAG_EXPOSURE_RATE | CameraAuxiliary::FLAG_GAMMA_RATE)) + if (sc->format < FORMAT_F || sc->format == FORMAT_AFT) + sc->format = FORMAT_F; + + kv.close_scope(); + } + + if (kv.open_scope("play_control")) { + PlayControl* pc = &sc->play_control; + + kv.read("begin", pc->begin); + if (kv.read("div", pc->div)) + pc->flag |= PlayControl::FLAG_DIV; + kv.read("fps", pc->fps); + if (kv.read("offset", pc->offset)) + pc->flag |= PlayControl::FLAG_OFFSET; + kv.read("size", pc->size); + + kv.close_scope(); + } + + if (kv.open_scope("post_process")) { + PostProcess* pp = &sc->post_process; + + if (key_val_read(&kv, "lens_flare", pp->lens_flare)) + pp->flag |= PostProcess::FLAG_LENS_FLARE; + if (key_val_read(&kv, "lens_shaft", pp->lens_shaft)) + pp->flag |= PostProcess::FLAG_LENS_SHAFT; + if (key_val_read(&kv, "lens_ghost", pp->lens_ghost)) + pp->flag |= PostProcess::FLAG_LENS_GHOST; + if (key_val_read(&kv, "Ambient", pp->radius)) + pp->flag |= PostProcess::FLAG_RADIUS; + if (key_val_read(&kv, "Diffuse", pp->intensity)) + pp->flag |= PostProcess::FLAG_INTENSITY; + if (key_val_read(&kv, "Specular", pp->scene_fade)) + pp->flag |= PostProcess::FLAG_SCENE_FADE; + + kv.close_scope(); + } + + if (kv.open_scope("dof")) { + Dof* d = &sc->dof; + + d->has_dof = key_val_read(&kv, "", d->model_transform); + + kv.close_scope(); + } + + int32_t count; + + // MGF + if (kv.read("ambient", "length", count)) { + sc->ambient.resize(count); + Ambient* va = sc->ambient.data(); + for (int32_t i = 0; i < count; i++) { + if (!kv.open_scope_fmt(i)) + continue; + + Ambient* sc = &va[i]; + if (key_val_read(&kv, "light.Diffuse", sc->light_diffuse)) + sc->flag |= Ambient::FLAG_LIGHT_DIFFUSE; + kv.read("name", sc->name); + if (key_val_read(&kv, "rim.light.Diffuse", sc->rim_light_diffuse)) + sc->flag |= Ambient::FLAG_RIM_LIGHT_DIFFUSE; + + kv.close_scope(); + } + kv.close_scope(); + } + + if (kv.read("auth_2d", "length", count)) { + sc->auth_2d.resize(count); + Auth2d* va2 = sc->auth_2d.data(); + for (int32_t i = 0; i < count; i++) { + if (!kv.open_scope_fmt(i)) + continue; + + Auth2d* a2 = &va2[i]; + kv.read(a2->name); + kv.close_scope(); + } + kv.close_scope(); + } + + if (kv.read("camera_root", "length", count)) { + sc->camera_root.resize(count); + CameraRoot* vcr = sc->camera_root.data(); + for (int32_t i = 0; i < count; i++) { + if (!kv.open_scope_fmt(i)) + continue; + + CameraRoot* cr = &vcr[i]; + key_val_read(&kv, "", cr->model_transform); + + CameraInterest* intr = &cr->interest; + key_val_read(&kv, "interest", intr->model_transform); + + CameraViewPoint* vp = &cr->view_point; + if (!kv.open_scope("view_point")) { + kv.close_scope(); + continue; + } + + key_val_read(&kv, "", vp->model_transform); + key_val_read(&kv, "roll", vp->roll); + + if (kv.has_key("fov_is_horizontal")) { + vp->has_fov = true; + key_val_read(&kv, "fov", vp->fov); + kv.read("fov_is_horizontal", vp->fov_is_horizontal); + kv.read("aspect", vp->aspect); } else { - kv.write(s, "camera_aperture_h", vp->camera_aperture_h); - kv.write(s, "camera_aperture_w", vp->camera_aperture_w); - key_val_out_write(&kv, s, "focal_length", vp->focal_length); + key_val_read(&kv, "focal_length", vp->focal_length); + kv.read("camera_aperture_w", vp->camera_aperture_w); + kv.read("camera_aperture_h", vp->camera_aperture_h); } - key_val_out_write(&kv, s, "", vp->model_transform, 0x10); - if (vp->flags & A3DA_CAMERA_ROOT_VIEW_POINT_ROLL) - key_val_out_write(&kv, s, "roll", vp->roll); - key_val_out_write(&kv, s, "", vp->model_transform, 0x0F); + + kv.close_scope(); + kv.close_scope(); + } + kv.close_scope(); + } + + if (kv.read("chara", "length", count)) { + sc->chara.resize(count); + Chara* vc = sc->chara.data(); + for (int32_t i = 0; i < count; i++) { + if (!kv.open_scope_fmt(i)) + continue; + + Chara* c = &vc[i]; + key_val_read(&kv, "", c->model_transform); + kv.read("name", c->name); + + kv.close_scope(); + } + kv.close_scope(); + } + + if (kv.read("curve", "length", count)) { + sc->curve.resize(count); + Curve* vc = sc->curve.data(); + for (int32_t i = 0; i < count; i++) { + if (!kv.open_scope_fmt(i)) + continue; + + Curve* c = &vc[i]; + key_val_read(&kv, "cv", c->fcurve); + kv.read("name", c->name); + + kv.close_scope(); + } + kv.close_scope(); + } + + if (kv.read("event", "length", count)) { + sc->event.resize(count); + Event* ve = sc->event.data(); + for (int32_t i = 0; i < count; i++) { + if (!kv.open_scope_fmt(i)) + continue; + + Event* e = &ve[i]; + kv.read("begin", e->begin); + kv.read("clip_begin", e->clip_begin); + kv.read("clip_end", e->clip_end); + kv.read("end", e->end); + kv.read("name", e->name); + kv.read("param1", e->param1); + kv.read("ref", e->ref); + kv.read("time_ref_scale", e->time_ref_scale); + + int32_t type; + if (kv.read("type", type)) + e->type = (EVENT_TYPE)type; + + kv.close_scope(); + } + kv.close_scope(); + } + + if (kv.read("fog", "length", count)) { + sc->fog.resize(count); + Fog* vf = sc->fog.data(); + for (int32_t i = 0; i < count; i++) { + if (!kv.open_scope_fmt(i)) + continue; + + Fog* f = &vf[i]; + + int32_t id; + if (kv.read("id", id)) + f->id = id; + + if (kv.read("name", f->name)) { + if (!f->name.compare("Z")) + f->id = FOG_DEPTH; + else if (!f->name.compare("Height")) + f->id = FOG_HEIGHT; + } + + if (key_val_read(&kv, "density", f->density)) + f->flag |= Fog::FLAG_DENSITY; + if (key_val_read(&kv, "end", f->end)) + f->flag |= Fog::FLAG_END; + if (key_val_read(&kv, "start", f->start)) + f->flag |= Fog::FLAG_START; + if (key_val_read(&kv, "Diffuse", f->color)) + f->flag |= Fog::FLAG_COLOR; + + kv.close_scope(); + } + kv.close_scope(); + } + + if (kv.read("light", "length", count)) { + sc->light.resize(count); + Light* vl = sc->light.data(); + for (int32_t i = 0; i < count; i++) { + if (!kv.open_scope_fmt(i)) + continue; + + Light* l = &vl[i]; + int32_t id; + if (kv.read("id", id)) + l->id = id; + + kv.read("name", l->name); + kv.read("type", l->type); + + key_val_read(&kv, "position", l->position); + key_val_read(&kv, "spot_direction", l->spot_direction); + + if (key_val_read(&kv, "Ambient", l->ambient)) + l->flag |= Light::FLAG_AMBIENT; + if (key_val_read(&kv, "Diffuse", l->diffuse)) + l->flag |= Light::FLAG_DIFFUSE; + if (key_val_read(&kv, "Specular", l->specular)) + l->flag |= Light::FLAG_SPECULAR; + if (key_val_read(&kv, "Incandescence", l->tone_curve)) + l->flag |= Light::FLAG_TONE_CURVE; + + // XHD + if (key_val_read(&kv, "CONSTANT", l->constant)) + l->flag |= Light::FLAG_CONSTANT; + if (key_val_read(&kv, "Intensity", l->intensity)) + l->flag |= Light::FLAG_INTENSITY; + if (key_val_read(&kv, "FAR", l->far_)) + l->flag |= Light::FLAG_FAR; + if (key_val_read(&kv, "LINEAR", l->linear)) + l->flag |= Light::FLAG_LINEAR; + if (key_val_read(&kv, "QUADRATIC", l->quadratic)) + l->flag |= Light::FLAG_QUADRATIC; + if (key_val_read(&kv, "DropOff", l->drop_off)) + l->flag |= Light::FLAG_DROP_OFF; + if (key_val_read(&kv, "ConeAngle", l->cone_angle)) + l->flag |= Light::FLAG_CONE_ANGLE; + + kv.close_scope(); + } + kv.close_scope(); + } + + if (kv.read("m_objhrc", "length", count)) { + sc->m_object_hrc.resize(count); + MObjectHrc* vmoh = sc->m_object_hrc.data(); + for (int32_t i = 0; i < count; i++) { + if (!kv.open_scope_fmt(i)) + continue; + + MObjectHrc* moh = &vmoh[i]; + int32_t count; + if (kv.read("instance", "length", count)) { + moh->instance.resize(count); + ObjectInstance* voi = moh->instance.data(); + for (int32_t j = 0; j < count; j++) { + if (!kv.open_scope_fmt(j)) + continue; + + ObjectInstance* oi = &voi[j]; + kv.read("name", oi->name); + kv.read("uid_name", oi->uid_name); + kv.read("shadow", oi->shadow); + key_val_read(&kv, "", oi->model_transform); + + kv.close_scope(); + } + kv.close_scope(); + } + + key_val_read(&kv, "", moh->model_transform); + kv.read("name", moh->name); + + if (kv.read("node", "length", count)) { + moh->node.resize(count); + ObjectNode* von = moh->node.data(); + for (int32_t j = 0; j < count; j++) { + if (!kv.open_scope_fmt(j)) + continue; + + ObjectNode* on = &von[j]; + kv.read("name", on->name); + kv.read("parent", on->parent); + key_val_read(&kv, "", on->model_transform); + if (kv.read("joint_orient", on->joint_orient)) + on->flag |= ObjectNode::FLAG_JOINT_ORIENT; + + kv.close_scope(); + } + kv.close_scope(); + } + + kv.close_scope(); + } + kv.close_scope(); + } + + if (kv.read("m_objhrc_list", "length", count)) { + sc->m_object_hrc_list.resize(count); + std::string* vmohl = sc->m_object_hrc_list.data(); + for (int32_t i = 0; i < count; i++) { + if (!kv.open_scope_fmt(i)) + continue; + + kv.read(vmohl[i]); + kv.close_scope(); + } + kv.close_scope(); + } + + // X/XHD + if (kv.read("material_list", "length", count)) { + sc->material_list.resize(count); + MaterialList* vml = sc->material_list.data(); + for (int32_t i = 0; i < count; i++) { + if (!kv.open_scope_fmt(i)) + continue; + + MaterialList* ml = &vml[i]; + kv.read("name", ml->name); + + if (key_val_read(&kv, "incandescence", ml->emission)) + ml->flag |= MaterialList::FLAG_EMISSION; + if (key_val_read(&kv, "blend_color", ml->blend_color)) + ml->flag |= MaterialList::FLAG_BLEND_COLOR; + if (key_val_read(&kv, "glow_intensity", ml->glow_intensity)) + ml->flag |= MaterialList::FLAG_GLOW_INTENSITY; + kv.close_scope(); + } + kv.close_scope(); + } + + if (kv.read("motion", "length", count)) { + sc->motion.resize(count); + Motion* vm = sc->motion.data(); + for (int32_t i = 0; i < count; i++) { + if (!kv.open_scope_fmt(i)) + continue; + + Motion* m = &vm[i]; + kv.read(m->name); + kv.close_scope(); + } + kv.close_scope(); + } + + if (kv.read("object", "length", count)) { + sc->object.resize(count); + Object* vo = sc->object.data(); + for (int32_t i = 0; i < count; i++) { + if (!kv.open_scope_fmt(i)) + continue; + + Object* o = &vo[i]; + kv.read("name", o->name); + kv.read("uid_name", o->uid_name); + key_val_read(&kv, "", o->model_transform); + if (kv.read("morph", o->morph)) + kv.read("morph_offset", o->morph_offset); + if (kv.read("pat", o->pattern)) + kv.read("pat_offset", o->pattern_offset); + kv.read("parent_name", o->parent_name); + kv.read("parent_node", o->parent_node); + + int32_t count; + if (kv.read("tex_pat", "length", count)) { + o->texture.resize(count); + Texture* votp = o->texture.data(); + for (int32_t j = 0; j < count; j++) { + if (!kv.open_scope_fmt(j)) + continue; + + Texture* otp = &votp[j]; + kv.read("name", otp->name); + if (kv.read("pat", otp->pattern)) + kv.read("pat_offset", otp->pattern_offset); + + kv.close_scope(); + } + kv.close_scope(); + } + + if (kv.read("tex_transform", "length", count)) { + o->texture_transform.resize(count); + TextureTransform* vott = o->texture_transform.data(); + for (int32_t j = 0; j < count; j++) { + if (!kv.open_scope_fmt(j)) + continue; + + TextureTransform* ott = &vott[j]; + kv.read("name", ott->name); + + if (key_val_read(&kv, "coverageU", ott->coverage_u)) + ott->flag |= TextureTransform::FLAG_COVERAGE_U; + if (key_val_read(&kv, "coverageV", ott->coverage_v)) + ott->flag |= TextureTransform::FLAG_COVERAGE_V; + if (key_val_read(&kv, "repeatU", ott->repeat_u)) + ott->flag |= TextureTransform::FLAG_REPEAT_U; + if (key_val_read(&kv, "repeatV", ott->repeat_v)) + ott->flag |= TextureTransform::FLAG_REPEAT_V; + if (key_val_read(&kv, "rotate", ott->rotate)) + ott->flag |= TextureTransform::FLAG_ROTATE; + if (key_val_read(&kv, "rotateFrame", ott->rotate_frame)) + ott->flag |= TextureTransform::FLAG_ROTATE_FRAME; + if (key_val_read(&kv, "offsetU", ott->offset_u)) + ott->flag |= TextureTransform::FLAG_OFFSET_U; + if (key_val_read(&kv, "offsetV", ott->offset_v)) + ott->flag |= TextureTransform::FLAG_OFFSET_V; + if (key_val_read(&kv, "translateFrameU", ott->translate_frame_u)) + ott->flag |= TextureTransform::FLAG_TRANSLATE_FRAME_U; + if (key_val_read(&kv, "translateFrameV", ott->translate_frame_v)) + ott->flag |= TextureTransform::FLAG_TRANSLATE_FRAME_V; + + kv.close_scope(); + } + kv.close_scope(); + } + + kv.close_scope(); + } + kv.close_scope(); + } + + if (kv.read("object_list", "length", count)) { + sc->object_list.resize(count); + std::string* vol = sc->object_list.data(); + for (int32_t i = 0; i < count; i++) { + if (!kv.open_scope_fmt(i)) + continue; + + kv.read(vol[i]); + kv.close_scope(); + } + kv.close_scope(); + } + + if (kv.read("objhrc", "length", count)) { + sc->object_hrc.resize(count); + ObjectHrc* voh = sc->object_hrc.data(); + for (int32_t i = 0; i < count; i++) { + if (!kv.open_scope_fmt(i)) + continue; + + ObjectHrc* oh = &voh[i]; + kv.read("name", oh->name); + kv.read("uid_name", oh->uid_name); + + kv.read("shadow", oh->shadow); + + int32_t count; + if (kv.read("node", "length", count)) { + oh->node.resize(count); + ObjectNode* vohn = oh->node.data(); + for (int32_t j = 0; j < count; j++) { + if (!kv.open_scope_fmt(j)) + continue; + + ObjectNode* ohn = &vohn[j]; + kv.read("name", ohn->name); + kv.read("parent", ohn->parent); + key_val_read(&kv, "", ohn->model_transform); + if (kv.read("joint_orient", ohn->joint_orient)) + ohn->flag |= ObjectNode::FLAG_JOINT_ORIENT; + + kv.close_scope(); + } + kv.close_scope(); + } + + kv.read("parent_name", oh->parent_name); + kv.read("parent_node", oh->parent_node); + + kv.close_scope(); + } + kv.close_scope(); + } + + if (kv.read("objhrc_list", "length", count)) { + sc->object_hrc_list.resize(count); + std::string* vohl = sc->object_hrc_list.data(); + for (int32_t i = 0; i < count; i++) { + if (!kv.open_scope_fmt(i)) + continue; + + kv.read(vohl[i]); + kv.close_scope(); + } + kv.close_scope(); + } + + if (kv.read("point", "length", count)) { + sc->point.resize(count); + Point* vp = sc->point.data(); + for (int32_t i = 0; i < count; i++) { + if (!kv.open_scope_fmt(i)) + continue; + + Point* p = &vp[i]; + key_val_read(&kv, "", p->model_transform); + kv.read("name", p->name); + + kv.close_scope(); + } + kv.close_scope(); + } + } + + static void a3da_write_text(Scene* sc, void** data, size_t* size, bool a3dc) { + char a3da_timestamp[0x100]; + a3da_get_time_stamp(a3da_timestamp, 0x100); + + memory_stream s; + s.open(); + + if (a3dc) { + if (sc->_compress_f16 != COMPRESS_F32F32F32F32) + s.write("#-compress_f16\n", 15); + } + else + s.write("#A3DA__________\n", 16); + + s.write_utf8_string(a3da_timestamp); + + key_val_out kv; + + { + kv.open_scope("_"); + + if (a3dc && sc->format > FORMAT_AFT && sc->format != FORMAT_AFT_X_PACK) + kv.write(s, "compress_f16", sc->_compress_f16); + kv.write(s, "converter.version", sc->_converter_version); + kv.write(s, "file_name", sc->_file_name); + kv.write(s, "property.version", sc->_property_version); + + kv.close_scope(); + } + + // MGF + if (sc->ambient.size() && sc->format == FORMAT_MGF) { + kv.open_scope("ambient"); + + int32_t count = (int32_t)sc->ambient.size(); + Ambient* va = sc->ambient.data(); + + std::vector sort_index; + key_val_out::get_lexicographic_order(sort_index, count); + int32_t* sort_index_data = sort_index.data(); + for (int32_t i = 0; i < count; i++) { + kv.open_scope_fmt(sort_index_data[i]); + + Ambient* sc = &va[sort_index_data[i]]; + if (sc->flag & Ambient::FLAG_LIGHT_DIFFUSE) + key_val_out_write(&kv, s, "light.Diffuse", sc->light_diffuse); + kv.write(s, "name", sc->name); + if (sc->flag & Ambient::FLAG_RIM_LIGHT_DIFFUSE) + key_val_out_write(&kv, s, "rimlight.Diffuse", sc->rim_light_diffuse); kv.close_scope(); } - key_val_out_write(&kv, s, "", cr->model_transform, 0x01); - + kv.write(s, "length", count); kv.close_scope(); } - kv.write(s, "length", count); - kv.close_scope(); - } + if (sc->auth_2d.size()) { + kv.open_scope("auth_2d"); - if (a->chara.size() > 0) { - kv.open_scope("chara"); + int32_t count = (int32_t)sc->auth_2d.size(); + Auth2d* va2 = sc->auth_2d.data(); - int32_t count = (int32_t)a->chara.size(); - a3da_chara* vc = a->chara.data(); - - std::vector sort_index; - key_val_out::get_lexicographic_order(sort_index, count); - int32_t* sort_index_data = sort_index.data(); - for (int32_t i = 0; i < count; i++) { - kv.open_scope_fmt(sort_index_data[i]); - - a3da_chara* c = &vc[sort_index_data[i]]; - kv.write(s, "name", c->name); - key_val_out_write(&kv, s, "", c->model_transform); + std::vector sort_index; + key_val_out::get_lexicographic_order(sort_index, count); + int32_t* sort_index_data = sort_index.data(); + for (int32_t i = 0; i < count; i++) { + kv.open_scope_fmt(sort_index_data[i]); + Auth2d* a2 = &va2[sort_index_data[i]]; + kv.write(s, "name", a2->name); + kv.close_scope(); + } + kv.write(s, "length", count); kv.close_scope(); } - kv.write(s, "length", count); - kv.close_scope(); - } + if (sc->camera_auxiliary.flag) { + kv.open_scope("camera_auxiliary"); - if (a->format == A3DA_FORMAT_AFT_X_PACK && (a->curve.size() > 0 || a->material_list.size() > 0)) { - kv.open_scope("curve"); - - int32_t curve_count = (int32_t)a->curve.size(); - int32_t mat_list_count = (int32_t)a->material_list.size(); - a3da_curve* vc = a->curve.data(); - a3da_material_list* vml = a->material_list.data(); - - std::vector sort_index; - key_val_out::get_lexicographic_order(sort_index, curve_count + mat_list_count); - int32_t* sort_index_data = sort_index.data(); - for (int32_t i = 0; i < curve_count + mat_list_count; i++) { - kv.open_scope_fmt(sort_index_data[i]); - - if (sort_index_data[i] < curve_count) { - a3da_curve* c = &vc[sort_index_data[i]]; - key_val_out_write(&kv, s, "cv", c->curve); - kv.write(s, "name", c->name); + CameraAuxiliary* ca = &sc->camera_auxiliary; + if (sc->format == FORMAT_F || sc->format > FORMAT_AFT && sc->format != FORMAT_AFT_X_PACK) { + // F/F2/X + if (ca->flag & CameraAuxiliary::FLAG_EXPOSURE_RATE) + key_val_out_write(&kv, s, "exposure_rate", ca->exposure_rate, true); + if (ca->flag & CameraAuxiliary::FLAG_GAMMA_RATE) + key_val_out_write(&kv, s, "gamma_rate", ca->gamma_rate, true); + if (ca->flag & CameraAuxiliary::FLAG_SATURATE) + key_val_out_write(&kv, s, "saturate", ca->saturate, true); } else { - a3da_material_list* ml = &vml[sort_index_data[i] - curve_count]; - kv.open_scope("ml"); - kv.write(s, "true"); - if (ml->flags & A3DA_MATERIAL_LIST_BLEND_COLOR) - key_val_out_write(&kv, s, "blend_color", ml->blend_color); - if (ml->flags & A3DA_MATERIAL_LIST_EMISSION) - key_val_out_write(&kv, s, "emission", ml->emission); - kv.close_scope(); - kv.write(s, "name", ml->name); + if (ca->flag & CameraAuxiliary::FLAG_AUTO_EXPOSURE) + key_val_out_write(&kv, s, "auto_exposure", ca->auto_exposure, true); + if (ca->flag & CameraAuxiliary::FLAG_EXPOSURE) + key_val_out_write(&kv, s, "exposure", ca->exposure, true); + if (ca->flag & CameraAuxiliary::FLAG_GAMMA) + key_val_out_write(&kv, s, "gamma", ca->gamma, true); + if (ca->flag & CameraAuxiliary::FLAG_SATURATE) + key_val_out_write(&kv, s, "saturate", ca->saturate, true); } kv.close_scope(); } - kv.write(s, "length", curve_count + mat_list_count); - kv.close_scope(); - } - else if (a->curve.size() > 0) { - kv.open_scope("curve"); + if (sc->camera_root.size() > 0) { + kv.open_scope("camera_root"); - int32_t count = (int32_t)a->curve.size(); - a3da_curve* vc = a->curve.data(); + int32_t count = (int32_t)sc->camera_root.size(); + CameraRoot* vcr = sc->camera_root.data(); - std::vector sort_index; - key_val_out::get_lexicographic_order(sort_index, count); - int32_t* sort_index_data = sort_index.data(); - for (int32_t i = 0; i < count; i++) { - kv.open_scope_fmt(sort_index_data[i]); + std::vector sort_index; + key_val_out::get_lexicographic_order(sort_index, count); + int32_t* sort_index_data = sort_index.data(); + for (int32_t i = 0; i < count; i++) { + kv.open_scope_fmt(sort_index_data[i]); - a3da_curve* c = &vc[sort_index_data[i]]; - key_val_out_write(&kv, s, "cv", c->curve); - kv.write(s, "name", c->name); + CameraRoot* cr = &vcr[sort_index_data[i]]; + CameraInterest* intr = &cr->interest; + key_val_out_write(&kv, s, "interest", intr->model_transform, 0x1F); - kv.close_scope(); - } + key_val_out_write(&kv, s, "", cr->model_transform, 0x1E); - kv.write(s, "length", count); - kv.close_scope(); - } + { + kv.open_scope("view_point"); - if (a->dof.has_dof && (a->format == A3DA_FORMAT_AFT || a->format == A3DA_FORMAT_AFT_X_PACK)) { - kv.open_scope("dof"); - - a3da_dof* d = &a->dof; - kv.write(s, "name", "DOF"); - key_val_out_write(&kv, s, "", d->model_transform); - - kv.close_scope(); - } - - if (a->event.size() > 0) { - kv.open_scope("event"); - - int32_t count = (int32_t)a->event.size(); - a3da_event* ve = a->event.data(); - - std::vector sort_index; - key_val_out::get_lexicographic_order(sort_index, count); - int32_t* sort_index_data = sort_index.data(); - for (int32_t i = 0; i < count; i++) { - kv.open_scope_fmt(sort_index_data[i]); - - a3da_event* e = &ve[sort_index_data[i]]; - kv.write(s, "begin", e->begin); - kv.write(s, "clip_begin", e->clip_begin); - kv.write(s, "clip_en", e->clip_end); - kv.write(s, "end", e->end); - kv.write(s, "name", e->name); - kv.write(s, "param1", e->param1); - kv.write(s, "ref", e->ref); - kv.write(s, "time_ref_scale", e->time_ref_scale); - kv.write(s, "type", e->type); - - kv.close_scope(); - } - - kv.write(s, "length", count); - kv.close_scope(); - } - - if (a->fog.size() > 0) { - kv.open_scope("fog"); - - int32_t count = (int32_t)a->fog.size(); - a3da_fog* vf = a->fog.data(); - - std::vector sort_index; - key_val_out::get_lexicographic_order(sort_index, count); - int32_t* sort_index_data = sort_index.data(); - for (int32_t i = 0; i < count; i++) { - kv.open_scope_fmt(sort_index_data[i]); - - a3da_fog* f = &vf[sort_index_data[i]]; - if (f->flags & A3DA_FOG_COLOR) - key_val_out_write(&kv, s, "Diffuse", f->color); - if (f->flags & A3DA_FOG_DENSITY) - key_val_out_write(&kv, s, "density", f->density, true); - if (f->flags & A3DA_FOG_END) - key_val_out_write(&kv, s, "end", f->end, true); - kv.write(s, "id", f->id); - if (f->flags & A3DA_FOG_START) - key_val_out_write(&kv, s, "start", f->start, true); - - kv.close_scope(); - } - - kv.write(s, "length", count); - kv.close_scope(); - } - - if (a->light.size() > 0) { - kv.open_scope("light"); - - bool xhd = a->format == A3DA_FORMAT_XHD; - - int32_t count = (int32_t)a->light.size(); - a3da_light* vl = a->light.data(); - - std::vector sort_index; - key_val_out::get_lexicographic_order(sort_index, count); - int32_t* sort_index_data = sort_index.data(); - for (int32_t i = 0; i < count; i++) { - kv.open_scope_fmt(sort_index_data[i]); - - a3da_light* l = &vl[sort_index_data[i]]; - if (l->flags & A3DA_LIGHT_AMBIENT) - key_val_out_write(&kv, s, "Ambient", l->ambient); - if (l->flags & A3DA_LIGHT_CONSTANT && xhd) - key_val_out_write(&kv, s, "CONSTANT", l->constant, true); - if (l->flags & A3DA_LIGHT_CONE_ANGLE && xhd) - key_val_out_write(&kv, s, "ConeAngle", l->cone_angle, true); - if (l->flags & A3DA_LIGHT_DIFFUSE) - key_val_out_write(&kv, s, "Diffuse", l->diffuse); - if (l->flags & A3DA_LIGHT_DROP_OFF && xhd) - key_val_out_write(&kv, s, "DropOff", l->drop_off, true); - if (l->flags & A3DA_LIGHT_FAR && xhd) - key_val_out_write(&kv, s, "FAR", l->_far, true); - if (l->flags & A3DA_LIGHT_TONE_CURVE) - key_val_out_write(&kv, s, "Incandescence", l->tone_curve); - if (l->flags & A3DA_LIGHT_INTENSITY && xhd) - key_val_out_write(&kv, s, "Intensity", l->intensity, true); - if (l->flags & A3DA_LIGHT_LINEAR && xhd) - key_val_out_write(&kv, s, "LINEAR", l->linear, true); - if (l->flags & A3DA_LIGHT_QUADRATIC && xhd) - key_val_out_write(&kv, s, "QUADRATIC", l->quadratic, true); - if (l->flags & A3DA_LIGHT_SPECULAR) - key_val_out_write(&kv, s, "Specular", l->specular); - kv.write(s, "id", l->id); - const char* name = "none"; - switch (l->id) { - case LIGHT_CHARA: - name = "Char"; - break; - case LIGHT_STAGE: - name = "Stage"; - break; - case LIGHT_SUN: - name = "Sun"; - break; - case LIGHT_REFLECT: - name = "Reflect"; - break; - case LIGHT_CHARA_COLOR: - name = "CharColor"; - break; - case LIGHT_TONE_CURVE: - name = "ToneCurve"; - break; - } - kv.write(s, "name", name); - if (l->flags & A3DA_LIGHT_POSITION) - key_val_out_write(&kv, s, "position", l->position); - if (l->flags & A3DA_LIGHT_SPOT_DIRECTION) - key_val_out_write(&kv, s, "spot_direction", l->spot_direction); - kv.write(s, "type", l->type); - - kv.close_scope(); - } - - kv.write(s, "length", count); - kv.close_scope(); - } - - if (a->m_object_hrc.size() > 0) { - kv.open_scope("m_objhrc"); - - int32_t count = (int32_t)a->m_object_hrc.size(); - a3da_m_object_hrc* vmoh = a->m_object_hrc.data(); - - std::vector sort_index; - key_val_out::get_lexicographic_order(sort_index, count); - int32_t* sort_index_data = sort_index.data(); - for (int32_t i = 0; i < count; i++) { - kv.open_scope_fmt(sort_index_data[i]); - - a3da_m_object_hrc* moh = &vmoh[sort_index_data[i]]; - if (moh->instance.size()) { - kv.open_scope("instance"); - - int32_t count = (int32_t)moh->instance.size(); - a3da_object_instance* voi = moh->instance.data(); - - std::vector sort_index; - key_val_out::get_lexicographic_order(sort_index, count); - int32_t* sort_index_data = sort_index.data(); - for (int32_t j = 0; j < count; j++) { - kv.open_scope_fmt(sort_index_data[j]); - - a3da_object_instance* oi = &voi[sort_index_data[j]]; - key_val_out_write(&kv, s, "", oi->model_transform, 0x10); - kv.write(s, "name", oi->name); - key_val_out_write(&kv, s, "", oi->model_transform, 0x0C); - kv.write(s, "shadow", oi->shadow); - key_val_out_write(&kv, s, "", oi->model_transform, 0x02); - kv.write(s, "uid_name", oi->uid_name); - key_val_out_write(&kv, s, "", oi->model_transform, 0x01); + CameraViewPoint* vp = &cr->view_point; + if (vp->has_fov) { + kv.write(s, "aspect", vp->aspect); + key_val_out_write(&kv, s, "fov", vp->fov); + kv.write(s, "fov_is_horizontal", vp->fov_is_horizontal); + } + else { + kv.write(s, "camera_aperture_h", vp->camera_aperture_h); + kv.write(s, "camera_aperture_w", vp->camera_aperture_w); + key_val_out_write(&kv, s, "focal_length", vp->focal_length); + } + key_val_out_write(&kv, s, "", vp->model_transform, 0x10); + key_val_out_write(&kv, s, "roll", vp->roll); + key_val_out_write(&kv, s, "", vp->model_transform, 0x0F); kv.close_scope(); } - kv.write(s, "length", count); + key_val_out_write(&kv, s, "", cr->model_transform, 0x01); + kv.close_scope(); } - key_val_out_write(&kv, s, "", moh->model_transform, 0x10); - kv.write(s, "name", moh->name); + kv.write(s, "length", count); + kv.close_scope(); + } - if (moh->node.size()) { - kv.open_scope("node"); + if (sc->chara.size() > 0) { + kv.open_scope("chara"); - int32_t count = (int32_t)moh->node.size(); - a3da_object_node* von = moh->node.data(); + int32_t count = (int32_t)sc->chara.size(); + Chara* vc = sc->chara.data(); - std::vector sort_index; - key_val_out::get_lexicographic_order(sort_index, count); - int32_t* sort_index_data = sort_index.data(); - for (int32_t j = 0; j < count; j++) { - kv.open_scope_fmt(sort_index_data[j]); + std::vector sort_index; + key_val_out::get_lexicographic_order(sort_index, count); + int32_t* sort_index_data = sort_index.data(); + for (int32_t i = 0; i < count; i++) { + kv.open_scope_fmt(sort_index_data[i]); - a3da_object_node* on = &von[sort_index_data[j]]; - key_val_out_write(&kv, s, "", on->model_transform, 0x10); - if (on->flags & A3DA_OBJECT_NODE_JOINT_ORIENT) - kv.write(s, "joint_orient", on->joint_orient); - kv.write(s, "name", on->name); - kv.write(s, "parent", on->parent); - key_val_out_write(&kv, s, "", on->model_transform, 0x0F); + Chara* c = &vc[sort_index_data[i]]; + kv.write(s, "name", c->name); + key_val_out_write(&kv, s, "", c->model_transform); + kv.close_scope(); + } + + kv.write(s, "length", count); + kv.close_scope(); + } + + // X/XHD + if (sc->format == FORMAT_AFT_X_PACK && (sc->curve.size() > 0 || sc->material_list.size() > 0)) { + kv.open_scope("curve"); + + int32_t curve_count = (int32_t)sc->curve.size(); + int32_t mat_list_count = (int32_t)sc->material_list.size(); + Curve* vc = sc->curve.data(); + MaterialList* vml = sc->material_list.data(); + + std::vector sort_index; + key_val_out::get_lexicographic_order(sort_index, curve_count + mat_list_count); + int32_t* sort_index_data = sort_index.data(); + for (int32_t i = 0; i < curve_count + mat_list_count; i++) { + kv.open_scope_fmt(sort_index_data[i]); + + if (sort_index_data[i] < curve_count) { + Curve* c = &vc[sort_index_data[i]]; + key_val_out_write(&kv, s, "cv", c->fcurve); + kv.write(s, "name", c->name); + } + else { + MaterialList* ml = &vml[sort_index_data[i] - curve_count]; + kv.open_scope("ml"); + kv.write(s, "true"); + if (ml->flag & MaterialList::FLAG_BLEND_COLOR) + key_val_out_write(&kv, s, "blend_color", ml->blend_color); + if (ml->flag & MaterialList::FLAG_EMISSION) + key_val_out_write(&kv, s, "emission", ml->emission); kv.close_scope(); + kv.write(s, "name", ml->name); } - kv.write(s, "length", count); kv.close_scope(); } - key_val_out_write(&kv, s, "", moh->model_transform, 0x0F); - + kv.write(s, "length", curve_count + mat_list_count); kv.close_scope(); } + else if (sc->curve.size() > 0) { + kv.open_scope("curve"); - kv.write(s, "length", count); - kv.close_scope(); - } + int32_t count = (int32_t)sc->curve.size(); + Curve* vc = sc->curve.data(); - if (a->m_object_hrc_list.size()) { - kv.open_scope("m_objhrc_list"); + std::vector sort_index; + key_val_out::get_lexicographic_order(sort_index, count); + int32_t* sort_index_data = sort_index.data(); + for (int32_t i = 0; i < count; i++) { + kv.open_scope_fmt(sort_index_data[i]); - int32_t count = (int32_t)a->m_object_hrc_list.size(); - std::string* vmohl = a->m_object_hrc_list.data(); + Curve* c = &vc[sort_index_data[i]]; + key_val_out_write(&kv, s, "cv", c->fcurve); + kv.write(s, "name", c->name); - std::vector sort_index; - key_val_out::get_lexicographic_order(sort_index, count); - int32_t* sort_index_data = sort_index.data(); - for (int32_t i = 0; i < count; i++) { - kv.open_scope_fmt(sort_index_data[i]); - kv.write(s, vmohl[sort_index_data[i]]); - kv.close_scope(); - } - - kv.write(s, "length", count); - kv.close_scope(); - } - - if (a->material_list.size() > 0 && (a->format == A3DA_FORMAT_X || a->format == A3DA_FORMAT_XHD)) { - kv.open_scope("material_list"); - - int32_t count = (int32_t)a->material_list.size(); - a3da_material_list* vml = a->material_list.data(); - - std::vector sort_index; - key_val_out::get_lexicographic_order(sort_index, count); - int32_t* sort_index_data = sort_index.data(); - for (int32_t i = 0; i < count; i++) { - kv.open_scope_fmt(sort_index_data[i]); - - a3da_material_list* ml = &vml[sort_index_data[i]]; - if (ml->flags & A3DA_MATERIAL_LIST_BLEND_COLOR) - key_val_out_write(&kv, s, "blend_color", ml->blend_color); - if (ml->flags & A3DA_MATERIAL_LIST_GLOW_INTENSITY) - key_val_out_write(&kv, s, "glow_intensity", ml->glow_intensity, true); - kv.write(s, "hash_name", hash_string_murmurhash(ml->name)); - if (ml->flags & A3DA_MATERIAL_LIST_EMISSION) - key_val_out_write(&kv, s, "incandescence", ml->emission); - kv.write(s, "name", ml->name); - - kv.close_scope(); - } - - kv.write(s, "length", count); - kv.close_scope(); - } - - if (a->motion.size()) { - kv.open_scope("motion"); - - int32_t count = (int32_t)a->motion.size(); - std::string* vm = a->motion.data(); - - std::vector sort_index; - key_val_out::get_lexicographic_order(sort_index, count); - int32_t* sort_index_data = sort_index.data(); - for (int32_t i = 0; i < count; i++) { - kv.open_scope_fmt(sort_index_data[i]); - kv.write(s, "name", vm[sort_index_data[i]]); - kv.close_scope(); - } - - kv.write(s, "length", count); - kv.close_scope(); - } - - if (a->object.size() > 0) { - kv.open_scope("object"); - - int32_t count = (int32_t)a->object.size(); - a3da_object* vo = a->object.data(); - - std::vector sort_index; - key_val_out::get_lexicographic_order(sort_index, count); - int32_t* sort_index_data = sort_index.data(); - for (int32_t i = 0; i < count; i++) { - kv.open_scope_fmt(sort_index_data[i]); - - a3da_object* o = &vo[sort_index_data[i]]; - key_val_out_write(&kv, s, "", o->model_transform, 0x10); - if (o->morph.size()) { - kv.write(s, "morph", o->morph); - kv.write(s, "morph_offset", o->morph_offset); + kv.close_scope(); } - kv.write(s, "name", o->name); - if (o->parent_name.size()) - kv.write(s, "parent_name", o->parent_name); - if (o->parent_node.size()) - kv.write(s, "parent_node", o->parent_node); - if (o->pattern.size()) { - kv.write(s, "pat", o->pattern); - kv.write(s, "pat_offset", o->pattern_offset); + + kv.write(s, "length", count); + kv.close_scope(); + } + + if (sc->dof.has_dof && (sc->format == FORMAT_AFT || sc->format == FORMAT_AFT_X_PACK)) { + kv.open_scope("dof"); + + Dof* d = &sc->dof; + kv.write(s, "name", "DOF"); + key_val_out_write(&kv, s, "", d->model_transform); + + kv.close_scope(); + } + + if (sc->event.size() > 0) { + kv.open_scope("event"); + + int32_t count = (int32_t)sc->event.size(); + Event* ve = sc->event.data(); + + std::vector sort_index; + key_val_out::get_lexicographic_order(sort_index, count); + int32_t* sort_index_data = sort_index.data(); + for (int32_t i = 0; i < count; i++) { + kv.open_scope_fmt(sort_index_data[i]); + + Event* e = &ve[sort_index_data[i]]; + kv.write(s, "begin", e->begin); + kv.write(s, "clip_begin", e->clip_begin); + kv.write(s, "clip_en", e->clip_end); + kv.write(s, "end", e->end); + kv.write(s, "name", e->name); + kv.write(s, "param1", e->param1); + kv.write(s, "ref", e->ref); + kv.write(s, "time_ref_scale", e->time_ref_scale); + kv.write(s, "type", e->type); + + kv.close_scope(); } - key_val_out_write(&kv, s, "", o->model_transform, 0x0C); - if (o->texture_pattern.size()) { - kv.open_scope("tex_pat"); + kv.write(s, "length", count); + kv.close_scope(); + } - int32_t count = (int32_t)o->texture_pattern.size(); - a3da_object_texture_pattern* votp = o->texture_pattern.data(); + if (sc->fog.size() > 0) { + kv.open_scope("fog"); - std::vector sort_index; - key_val_out::get_lexicographic_order(sort_index, count); - int32_t* sort_index_data = sort_index.data(); - for (int32_t j = 0; j < count; j++) { - kv.open_scope_fmt(sort_index_data[j]); + int32_t count = (int32_t)sc->fog.size(); + Fog* vf = sc->fog.data(); - a3da_object_texture_pattern* otp = &votp[sort_index_data[j]]; - kv.write(s, "name", otp->name); - if (otp->pattern.size()) { - kv.write(s, "pat", otp->pattern); - kv.write(s, "pat_offset", otp->pattern_offset); + std::vector sort_index; + key_val_out::get_lexicographic_order(sort_index, count); + int32_t* sort_index_data = sort_index.data(); + for (int32_t i = 0; i < count; i++) { + kv.open_scope_fmt(sort_index_data[i]); + + Fog* f = &vf[sort_index_data[i]]; + if (f->flag & Fog::FLAG_COLOR) + key_val_out_write(&kv, s, "Diffuse", f->color); + if (f->flag & Fog::FLAG_DENSITY) + key_val_out_write(&kv, s, "density", f->density, true); + if (f->flag & Fog::FLAG_END) + key_val_out_write(&kv, s, "end", f->end, true); + kv.write(s, "id", f->id); + if (f->flag & Fog::FLAG_START) + key_val_out_write(&kv, s, "start", f->start, true); + + kv.close_scope(); + } + + kv.write(s, "length", count); + kv.close_scope(); + } + + if (sc->light.size() > 0) { + kv.open_scope("light"); + + bool xhd = sc->format == FORMAT_XHD; + + int32_t count = (int32_t)sc->light.size(); + Light* vl = sc->light.data(); + + std::vector sort_index; + key_val_out::get_lexicographic_order(sort_index, count); + int32_t* sort_index_data = sort_index.data(); + for (int32_t i = 0; i < count; i++) { + kv.open_scope_fmt(sort_index_data[i]); + + Light* l = &vl[sort_index_data[i]]; + if (l->flag & Light::FLAG_AMBIENT) + key_val_out_write(&kv, s, "Ambient", l->ambient); + if (l->flag & Light::FLAG_CONSTANT && xhd) // XHD + key_val_out_write(&kv, s, "CONSTANT", l->constant, true); + if (l->flag & Light::FLAG_CONE_ANGLE && xhd) // XHD + key_val_out_write(&kv, s, "ConeAngle", l->cone_angle, true); + if (l->flag & Light::FLAG_DIFFUSE) + key_val_out_write(&kv, s, "Diffuse", l->diffuse); + if (l->flag & Light::FLAG_DROP_OFF && xhd) // XHD + key_val_out_write(&kv, s, "DropOff", l->drop_off, true); + if (l->flag & Light::FLAG_FAR && xhd) // XHD + key_val_out_write(&kv, s, "FAR", l->far_, true); + if (l->flag & Light::FLAG_TONE_CURVE) + key_val_out_write(&kv, s, "Incandescence", l->tone_curve); + if (l->flag & Light::FLAG_INTENSITY && xhd) // XHD + key_val_out_write(&kv, s, "Intensity", l->intensity, true); + if (l->flag & Light::FLAG_LINEAR && xhd) // XHD + key_val_out_write(&kv, s, "LINEAR", l->linear, true); + if (l->flag & Light::FLAG_QUADRATIC && xhd) // XHD + key_val_out_write(&kv, s, "QUADRATIC", l->quadratic, true); + if (l->flag & Light::FLAG_SPECULAR) + key_val_out_write(&kv, s, "Specular", l->specular); + kv.write(s, "id", l->id); + const char* name = "none"; + switch (l->id) { + case LIGHT_CHARA: + name = "Char"; + break; + case LIGHT_STAGE: + name = "Stage"; + break; + case LIGHT_SUN: + name = "Sun"; + break; + case LIGHT_REFLECT: + name = "Reflect"; + break; + case LIGHT_CHARA_COLOR: + name = "CharColor"; + break; + case LIGHT_TONE_CURVE: + name = "ToneCurve"; + break; + } + kv.write(s, "name", name); + if (l->position.flag) + key_val_out_write(&kv, s, "position", l->position); + if (l->spot_direction.flag) + key_val_out_write(&kv, s, "spot_direction", l->spot_direction); + kv.write(s, "type", l->type); + + kv.close_scope(); + } + + kv.write(s, "length", count); + kv.close_scope(); + } + + if (sc->m_object_hrc.size() > 0) { + kv.open_scope("m_objhrc"); + + int32_t count = (int32_t)sc->m_object_hrc.size(); + MObjectHrc* vmoh = sc->m_object_hrc.data(); + + std::vector sort_index; + key_val_out::get_lexicographic_order(sort_index, count); + int32_t* sort_index_data = sort_index.data(); + for (int32_t i = 0; i < count; i++) { + kv.open_scope_fmt(sort_index_data[i]); + + MObjectHrc* moh = &vmoh[sort_index_data[i]]; + if (moh->instance.size()) { + kv.open_scope("instance"); + + int32_t count = (int32_t)moh->instance.size(); + ObjectInstance* voi = moh->instance.data(); + + std::vector sort_index; + key_val_out::get_lexicographic_order(sort_index, count); + int32_t* sort_index_data = sort_index.data(); + for (int32_t j = 0; j < count; j++) { + kv.open_scope_fmt(sort_index_data[j]); + + ObjectInstance* oi = &voi[sort_index_data[j]]; + key_val_out_write(&kv, s, "", oi->model_transform, 0x10); + kv.write(s, "name", oi->name); + key_val_out_write(&kv, s, "", oi->model_transform, 0x0C); + kv.write(s, "shadow", oi->shadow); + key_val_out_write(&kv, s, "", oi->model_transform, 0x02); + kv.write(s, "uid_name", oi->uid_name); + key_val_out_write(&kv, s, "", oi->model_transform, 0x01); + + kv.close_scope(); } + kv.write(s, "length", count); kv.close_scope(); } - kv.write(s, "length", count); - kv.close_scope(); - } + key_val_out_write(&kv, s, "", moh->model_transform, 0x10); + kv.write(s, "name", moh->name); - if (o->texture_transform.size()) { - kv.open_scope("tex_transform"); + if (moh->node.size()) { + kv.open_scope("node"); - int32_t count = (int32_t)o->texture_transform.size(); - a3da_object_texture_transform* vott = o->texture_transform.data(); + int32_t count = (int32_t)moh->node.size(); + ObjectNode* von = moh->node.data(); - std::vector sort_index; - key_val_out::get_lexicographic_order(sort_index, count); - int32_t* sort_index_data = sort_index.data(); - for (int32_t j = 0; j < count; j++) { - kv.open_scope_fmt(sort_index_data[j]); + std::vector sort_index; + key_val_out::get_lexicographic_order(sort_index, count); + int32_t* sort_index_data = sort_index.data(); + for (int32_t j = 0; j < count; j++) { + kv.open_scope_fmt(sort_index_data[j]); - a3da_object_texture_transform* ott = &vott[sort_index_data[j]]; - if (ott->flags & A3DA_OBJECT_TEXTURE_TRANSFORM_COVERAGE_U) - key_val_out_write(&kv, s, "coverageU", ott->coverage_u, true); - if (ott->flags & A3DA_OBJECT_TEXTURE_TRANSFORM_COVERAGE_V) - key_val_out_write(&kv, s, "coverageV", ott->coverage_v, true); - kv.write(s, "name", ott->name); - if (ott->flags & A3DA_OBJECT_TEXTURE_TRANSFORM_OFFSET_U) - key_val_out_write(&kv, s, "offsetU", ott->offset_u, true); - if (ott->flags & A3DA_OBJECT_TEXTURE_TRANSFORM_OFFSET_V) - key_val_out_write(&kv, s, "offsetV", ott->offset_v, true); - if (ott->flags & A3DA_OBJECT_TEXTURE_TRANSFORM_REPEAT_U) - key_val_out_write(&kv, s, "repeatU", ott->repeat_u, true); - if (ott->flags & A3DA_OBJECT_TEXTURE_TRANSFORM_REPEAT_V) - key_val_out_write(&kv, s, "repeatV", ott->repeat_v, true); - if (ott->flags & A3DA_OBJECT_TEXTURE_TRANSFORM_ROTATE) - key_val_out_write(&kv, s, "rotate", ott->rotate, true); - if (ott->flags & A3DA_OBJECT_TEXTURE_TRANSFORM_ROTATE_FRAME) - key_val_out_write(&kv, s, "rotateFrame", ott->rotate_frame, true); - if (ott->flags & A3DA_OBJECT_TEXTURE_TRANSFORM_TRANSLATE_FRAME_U) - key_val_out_write(&kv, s, "translateFrameU", ott->translate_frame_u, true); - if (ott->flags & A3DA_OBJECT_TEXTURE_TRANSFORM_TRANSLATE_FRAME_V) - key_val_out_write(&kv, s, "translateFrameV", ott->translate_frame_v, true); + ObjectNode* on = &von[sort_index_data[j]]; + key_val_out_write(&kv, s, "", on->model_transform, 0x10); + if (on->flag & ObjectNode::FLAG_JOINT_ORIENT) + kv.write(s, "joint_orient", on->joint_orient); + kv.write(s, "name", on->name); + kv.write(s, "parent", on->parent); + key_val_out_write(&kv, s, "", on->model_transform, 0x0F); + kv.close_scope(); + } + + kv.write(s, "length", count); kv.close_scope(); } - kv.write(s, "length", count); + key_val_out_write(&kv, s, "", moh->model_transform, 0x0F); + kv.close_scope(); } - key_val_out_write(&kv, s, "", o->model_transform, 0x02); - kv.write(s, "uid_name", o->uid_name); - key_val_out_write(&kv, s, "", o->model_transform, 0x01); - + kv.write(s, "length", count); kv.close_scope(); } - kv.write(s, "length", count); - kv.close_scope(); - } + if (sc->m_object_hrc_list.size()) { + kv.open_scope("m_objhrc_list"); - if (a->object_list.size()) { - kv.open_scope("object_list"); + int32_t count = (int32_t)sc->m_object_hrc_list.size(); + std::string* vmohl = sc->m_object_hrc_list.data(); - int32_t count = (int32_t)a->object_list.size(); - std::string* vol = a->object_list.data(); + std::vector sort_index; + key_val_out::get_lexicographic_order(sort_index, count); + int32_t* sort_index_data = sort_index.data(); + for (int32_t i = 0; i < count; i++) { + kv.open_scope_fmt(sort_index_data[i]); + kv.write(s, vmohl[sort_index_data[i]]); + kv.close_scope(); + } - std::vector sort_index; - key_val_out::get_lexicographic_order(sort_index, count); - int32_t* sort_index_data = sort_index.data(); - for (int32_t i = 0; i < count; i++) { - kv.open_scope_fmt(sort_index_data[i]); - kv.write(s, vol[sort_index_data[i]]); + kv.write(s, "length", count); kv.close_scope(); } - kv.write(s, "length", count); - kv.close_scope(); - } + // X/XHD + if (sc->material_list.size() > 0 && (sc->format == FORMAT_X || sc->format == FORMAT_XHD)) { + kv.open_scope("material_list"); - if (a->object_hrc.size() > 0) { - kv.open_scope("objhrc"); + int32_t count = (int32_t)sc->material_list.size(); + MaterialList* vml = sc->material_list.data(); - int32_t count = (int32_t)a->object_hrc.size(); - a3da_object_hrc* voh = a->object_hrc.data(); + std::vector sort_index; + key_val_out::get_lexicographic_order(sort_index, count); + int32_t* sort_index_data = sort_index.data(); + for (int32_t i = 0; i < count; i++) { + kv.open_scope_fmt(sort_index_data[i]); - std::vector sort_index; - key_val_out::get_lexicographic_order(sort_index, count); - int32_t* sort_index_data = sort_index.data(); - for (int32_t i = 0; i < count; i++) { - kv.open_scope_fmt(sort_index_data[i]); + MaterialList* ml = &vml[sort_index_data[i]]; + if (ml->flag & MaterialList::FLAG_BLEND_COLOR) + key_val_out_write(&kv, s, "blend_color", ml->blend_color); + if (ml->flag & MaterialList::FLAG_GLOW_INTENSITY) + key_val_out_write(&kv, s, "glow_intensity", ml->glow_intensity, true); + kv.write(s, "hash_name", hash_string_murmurhash(ml->name)); + if (ml->flag & MaterialList::FLAG_EMISSION) + key_val_out_write(&kv, s, "incandescence", ml->emission); + kv.write(s, "name", ml->name); - a3da_object_hrc* oh = &voh[sort_index_data[i]]; - kv.write(s, "name", oh->name); + kv.close_scope(); + } - if (oh->node.size()) { - kv.open_scope("node"); + kv.write(s, "length", count); + kv.close_scope(); + } - int32_t count = (int32_t)oh->node.size(); - a3da_object_node* vohn = oh->node.data(); + if (sc->motion.size()) { + kv.open_scope("motion"); - std::vector sort_index; - key_val_out::get_lexicographic_order(sort_index, count); - int32_t* sort_index_data = sort_index.data(); - for (int32_t j = 0; j < count; j++) { - kv.open_scope_fmt(sort_index_data[j]); + int32_t count = (int32_t)sc->motion.size(); + Motion* vm = sc->motion.data(); - a3da_object_node* ohn = &vohn[sort_index_data[j]]; - key_val_out_write(&kv, s, "", ohn->model_transform, 0x10); - if (ohn->flags & A3DA_OBJECT_NODE_JOINT_ORIENT) - kv.write(s, "joint_orient", ohn->joint_orient); - kv.write(s, "name", ohn->name); - kv.write(s, "parent", ohn->parent); - key_val_out_write(&kv, s, "", ohn->model_transform, 0x0F); + std::vector sort_index; + key_val_out::get_lexicographic_order(sort_index, count); + int32_t* sort_index_data = sort_index.data(); + for (int32_t i = 0; i < count; i++) { + kv.open_scope_fmt(sort_index_data[i]); + Motion* m = &vm[sort_index_data[i]]; + kv.write(s, "name", m->name); + kv.close_scope(); + } + kv.write(s, "length", count); + kv.close_scope(); + } + + if (sc->object.size() > 0) { + kv.open_scope("object"); + + int32_t count = (int32_t)sc->object.size(); + Object* vo = sc->object.data(); + + std::vector sort_index; + key_val_out::get_lexicographic_order(sort_index, count); + int32_t* sort_index_data = sort_index.data(); + for (int32_t i = 0; i < count; i++) { + kv.open_scope_fmt(sort_index_data[i]); + + Object* o = &vo[sort_index_data[i]]; + key_val_out_write(&kv, s, "", o->model_transform, 0x10); + if (o->morph.size()) { + kv.write(s, "morph", o->morph); + kv.write(s, "morph_offset", o->morph_offset); + } + kv.write(s, "name", o->name); + if (o->parent_name.size()) + kv.write(s, "parent_name", o->parent_name); + if (o->parent_node.size()) + kv.write(s, "parent_node", o->parent_node); + if (o->pattern.size()) { + kv.write(s, "pat", o->pattern); + kv.write(s, "pat_offset", o->pattern_offset); + } + key_val_out_write(&kv, s, "", o->model_transform, 0x0C); + + if (o->texture.size()) { + kv.open_scope("tex_pat"); + + int32_t count = (int32_t)o->texture.size(); + Texture* votp = o->texture.data(); + + std::vector sort_index; + key_val_out::get_lexicographic_order(sort_index, count); + int32_t* sort_index_data = sort_index.data(); + for (int32_t j = 0; j < count; j++) { + kv.open_scope_fmt(sort_index_data[j]); + + Texture* otp = &votp[sort_index_data[j]]; + kv.write(s, "name", otp->name); + if (otp->pattern.size()) { + kv.write(s, "pat", otp->pattern); + kv.write(s, "pat_offset", otp->pattern_offset); + } + + kv.close_scope(); + } + + kv.write(s, "length", count); kv.close_scope(); } - kv.write(s, "length", count); + if (o->texture_transform.size()) { + kv.open_scope("tex_transform"); + + int32_t count = (int32_t)o->texture_transform.size(); + TextureTransform* vott = o->texture_transform.data(); + + std::vector sort_index; + key_val_out::get_lexicographic_order(sort_index, count); + int32_t* sort_index_data = sort_index.data(); + for (int32_t j = 0; j < count; j++) { + kv.open_scope_fmt(sort_index_data[j]); + + TextureTransform* ott = &vott[sort_index_data[j]]; + if (ott->flag & TextureTransform::FLAG_COVERAGE_U) + key_val_out_write(&kv, s, "coverageU", ott->coverage_u, true); + if (ott->flag & TextureTransform::FLAG_COVERAGE_V) + key_val_out_write(&kv, s, "coverageV", ott->coverage_v, true); + kv.write(s, "name", ott->name); + if (ott->flag & TextureTransform::FLAG_OFFSET_U) + key_val_out_write(&kv, s, "offsetU", ott->offset_u, true); + if (ott->flag & TextureTransform::FLAG_OFFSET_V) + key_val_out_write(&kv, s, "offsetV", ott->offset_v, true); + if (ott->flag & TextureTransform::FLAG_REPEAT_U) + key_val_out_write(&kv, s, "repeatU", ott->repeat_u, true); + if (ott->flag & TextureTransform::FLAG_REPEAT_V) + key_val_out_write(&kv, s, "repeatV", ott->repeat_v, true); + if (ott->flag & TextureTransform::FLAG_ROTATE) + key_val_out_write(&kv, s, "rotate", ott->rotate, true); + if (ott->flag & TextureTransform::FLAG_ROTATE_FRAME) + key_val_out_write(&kv, s, "rotateFrame", ott->rotate_frame, true); + if (ott->flag & TextureTransform::FLAG_TRANSLATE_FRAME_U) + key_val_out_write(&kv, s, "translateFrameU", ott->translate_frame_u, true); + if (ott->flag & TextureTransform::FLAG_TRANSLATE_FRAME_V) + key_val_out_write(&kv, s, "translateFrameV", ott->translate_frame_v, true); + + kv.close_scope(); + } + + kv.write(s, "length", count); + kv.close_scope(); + } + + key_val_out_write(&kv, s, "", o->model_transform, 0x02); + kv.write(s, "uid_name", o->uid_name); + key_val_out_write(&kv, s, "", o->model_transform, 0x01); + kv.close_scope(); } - if (oh->parent_name.size()) - kv.write(s, "parent_name", oh->parent_name); - if (oh->parent_node.size()) - kv.write(s, "parent_node", oh->parent_node); - kv.write(s, "shadow", oh->shadow); - kv.write(s, "uid_name", oh->uid_name); - + kv.write(s, "length", count); kv.close_scope(); } - kv.write(s, "length", count); - kv.close_scope(); - } + if (sc->object_list.size()) { + kv.open_scope("object_list"); - if (a->object_hrc_list.size()) { - kv.open_scope("objhrc_list"); + int32_t count = (int32_t)sc->object_list.size(); + std::string* vol = sc->object_list.data(); - int32_t count = (int32_t)a->object_hrc_list.size(); - std::string* vohl = a->object_hrc_list.data(); + std::vector sort_index; + key_val_out::get_lexicographic_order(sort_index, count); + int32_t* sort_index_data = sort_index.data(); + for (int32_t i = 0; i < count; i++) { + kv.open_scope_fmt(sort_index_data[i]); + kv.write(s, vol[sort_index_data[i]]); + kv.close_scope(); + } - std::vector sort_index; - key_val_out::get_lexicographic_order(sort_index, count); - int32_t* sort_index_data = sort_index.data(); - for (int32_t i = 0; i < count; i++) { - kv.open_scope_fmt(sort_index_data[i]); - kv.write(s, vohl[sort_index_data[i]]); + kv.write(s, "length", count); kv.close_scope(); } - kv.write(s, "length", count); - kv.close_scope(); - } + if (sc->object_hrc.size() > 0) { + kv.open_scope("objhrc"); - { - kv.open_scope("play_control"); + int32_t count = (int32_t)sc->object_hrc.size(); + ObjectHrc* voh = sc->object_hrc.data(); - a3da_play_control* pc = &a->play_control; - kv.write(s, "begin", pc->begin); - if (pc->flags & A3DA_PLAY_CONTROL_DIV && a->format > A3DA_FORMAT_AFT && a->format != A3DA_FORMAT_AFT_X_PACK) - kv.write(s, "div", pc->div); - kv.write(s, "fps", pc->fps); - if (pc->flags & A3DA_PLAY_CONTROL_OFFSET) { - if (a->format > A3DA_FORMAT_AFT && a->format != A3DA_FORMAT_AFT_X_PACK) { - kv.write(s, "offset", pc->offset); - kv.write(s, "size", pc->size); + std::vector sort_index; + key_val_out::get_lexicographic_order(sort_index, count); + int32_t* sort_index_data = sort_index.data(); + for (int32_t i = 0; i < count; i++) { + kv.open_scope_fmt(sort_index_data[i]); + + ObjectHrc* oh = &voh[sort_index_data[i]]; + kv.write(s, "name", oh->name); + + if (oh->node.size()) { + kv.open_scope("node"); + + int32_t count = (int32_t)oh->node.size(); + ObjectNode* vohn = oh->node.data(); + + std::vector sort_index; + key_val_out::get_lexicographic_order(sort_index, count); + int32_t* sort_index_data = sort_index.data(); + for (int32_t j = 0; j < count; j++) { + kv.open_scope_fmt(sort_index_data[j]); + + ObjectNode* ohn = &vohn[sort_index_data[j]]; + key_val_out_write(&kv, s, "", ohn->model_transform, 0x10); + if (ohn->flag & ObjectNode::FLAG_JOINT_ORIENT) + kv.write(s, "joint_orient", ohn->joint_orient); + kv.write(s, "name", ohn->name); + kv.write(s, "parent", ohn->parent); + key_val_out_write(&kv, s, "", ohn->model_transform, 0x0F); + + kv.close_scope(); + } + + kv.write(s, "length", count); + kv.close_scope(); + } + + if (oh->parent_name.size()) + kv.write(s, "parent_name", oh->parent_name); + if (oh->parent_node.size()) + kv.write(s, "parent_node", oh->parent_node); + kv.write(s, "shadow", oh->shadow); + kv.write(s, "uid_name", oh->uid_name); + + kv.close_scope(); + } + + kv.write(s, "length", count); + kv.close_scope(); + } + + if (sc->object_hrc_list.size()) { + kv.open_scope("objhrc_list"); + + int32_t count = (int32_t)sc->object_hrc_list.size(); + std::string* vohl = sc->object_hrc_list.data(); + + std::vector sort_index; + key_val_out::get_lexicographic_order(sort_index, count); + int32_t* sort_index_data = sort_index.data(); + for (int32_t i = 0; i < count; i++) { + kv.open_scope_fmt(sort_index_data[i]); + kv.write(s, vohl[sort_index_data[i]]); + kv.close_scope(); + } + + kv.write(s, "length", count); + kv.close_scope(); + } + + { + kv.open_scope("play_control"); + + PlayControl* pc = &sc->play_control; + kv.write(s, "begin", pc->begin); + if (pc->flag & PlayControl::FLAG_DIV && sc->format > FORMAT_AFT + && sc->format != FORMAT_AFT_X_PACK) + kv.write(s, "div", pc->div); + kv.write(s, "fps", pc->fps); + if (pc->flag & PlayControl::FLAG_OFFSET) { + if (sc->format > FORMAT_AFT && sc->format != FORMAT_AFT_X_PACK) { + kv.write(s, "offset", pc->offset); + kv.write(s, "size", pc->size); + } + else + kv.write(s, "size", pc->size + pc->offset); } else - kv.write(s, "size", pc->size + pc->offset); - } - else - kv.write(s, "size", pc->size); - - kv.close_scope(); - } - - if (a->post_process.flags) { - kv.open_scope("post_process"); - - a3da_post_process* pp = &a->post_process; - if (a->post_process.flags & A3DA_POST_PROCESS_RADIUS) - key_val_out_write(&kv, s, "Ambient", pp->radius); - if (a->post_process.flags & A3DA_POST_PROCESS_INTENSITY) - key_val_out_write(&kv, s, "Diffuse", pp->intensity); - if (a->post_process.flags & A3DA_POST_PROCESS_SCENE_FADE) - key_val_out_write(&kv, s, "Specular", pp->scene_fade); - if (a->post_process.flags & A3DA_POST_PROCESS_LENS_FLARE) - key_val_out_write(&kv, s, "lens_flare", pp->lens_flare, true); - if (a->post_process.flags & A3DA_POST_PROCESS_LENS_GHOST) - key_val_out_write(&kv, s, "lens_ghost", pp->lens_ghost, true); - if (a->post_process.flags & A3DA_POST_PROCESS_LENS_SHAFT) - key_val_out_write(&kv, s, "lens_shaft", pp->lens_shaft, true); - - kv.close_scope(); - } - - if (a->point.size() > 0) { - kv.open_scope("point"); - - int32_t count = (int32_t)a->point.size(); - a3da_point* vp = a->point.data(); - - std::vector sort_index; - key_val_out::get_lexicographic_order(sort_index, count); - int32_t* sort_index_data = sort_index.data(); - for (int32_t i = 0; i < count; i++) { - kv.open_scope_fmt(sort_index_data[i]); - - a3da_point* p = &vp[sort_index_data[i]]; - kv.write(s, p->name); - key_val_out_write(&kv, s, "", p->model_transform); + kv.write(s, "size", pc->size); kv.close_scope(); } - kv.write(s, "length", count); - kv.close_scope(); - } + if (sc->post_process.flag) { + kv.open_scope("post_process"); - s.copy(data, size); -} + PostProcess* pp = &sc->post_process; + if (sc->post_process.flag & PostProcess::FLAG_RADIUS) + key_val_out_write(&kv, s, "Ambient", pp->radius); + if (sc->post_process.flag & PostProcess::FLAG_INTENSITY) + key_val_out_write(&kv, s, "Diffuse", pp->intensity); + if (sc->post_process.flag & PostProcess::FLAG_SCENE_FADE) + key_val_out_write(&kv, s, "Specular", pp->scene_fade); + if (sc->post_process.flag & PostProcess::FLAG_LENS_FLARE) + key_val_out_write(&kv, s, "lens_flare", pp->lens_flare, true); + if (sc->post_process.flag & PostProcess::FLAG_LENS_GHOST) + key_val_out_write(&kv, s, "lens_ghost", pp->lens_ghost, true); + if (sc->post_process.flag & PostProcess::FLAG_LENS_SHAFT) + key_val_out_write(&kv, s, "lens_shaft", pp->lens_shaft, true); -static void a3da_read_data(a3da* a, void* data, size_t size) { - a3da_compress_f16& _compress_f16 = a->_compress_f16; - - for (a3da_ambient& i : a->ambient) { - if (i.flags & A3DA_AMBIENT_LIGHT_DIFFUSE) - a3dc_read_a3da_rgba(data, size, &i.light_diffuse); - if (i.flags & A3DA_AMBIENT_RIM_LIGHT_DIFFUSE) - a3dc_read_a3da_rgba(data, size, &i.rim_light_diffuse); - } - - if (a->camera_auxiliary.flags) { - a3da_camera_auxiliary* ca = &a->camera_auxiliary; - - if (ca->flags & A3DA_CAMERA_AUXILIARY_AUTO_EXPOSURE) - a3dc_read_a3da_key(data, size, &ca->auto_exposure); - if (ca->flags & A3DA_CAMERA_AUXILIARY_EXPOSURE) - a3dc_read_a3da_key(data, size, &ca->exposure); - if (ca->flags & A3DA_CAMERA_AUXILIARY_EXPOSURE_RATE) - a3dc_read_a3da_key(data, size, &ca->exposure_rate); - if (ca->flags & A3DA_CAMERA_AUXILIARY_GAMMA) - a3dc_read_a3da_key(data, size, &ca->gamma); - if (ca->flags & A3DA_CAMERA_AUXILIARY_GAMMA_RATE) - a3dc_read_a3da_key(data, size, &ca->gamma_rate); - if (ca->flags & A3DA_CAMERA_AUXILIARY_SATURATE) - a3dc_read_a3da_key(data, size, &ca->saturate); - } - - for (a3da_camera_root& i : a->camera_root) { - a3dc_read_a3da_model_transform(data, size, &i.interest, _compress_f16); - a3dc_read_a3da_model_transform(data, size, &i.model_transform, _compress_f16); - - a3da_camera_root_view_point* vp = &i.view_point; - - if (vp->flags & A3DA_CAMERA_ROOT_VIEW_POINT_FOV) - a3dc_read_a3da_key(data, size, &vp->fov); - else - a3dc_read_a3da_key(data, size, &vp->focal_length); - a3dc_read_a3da_model_transform(data, size, &vp->model_transform, _compress_f16); - if (vp->flags & A3DA_CAMERA_ROOT_VIEW_POINT_ROLL) - a3dc_read_a3da_key(data, size, &vp->roll); - } - - for (a3da_chara& i : a->chara) - a3dc_read_a3da_model_transform(data, size, &i.model_transform, _compress_f16); - - for (a3da_curve& i : a->curve) - a3dc_read_a3da_key(data, size, &i.curve); - - if (a->dof.has_dof) { - a3da_dof* d = &a->dof; - - a3dc_read_a3da_model_transform(data, size, &d->model_transform, _compress_f16); - } - - for (a3da_fog& i : a->fog) { - if (i.flags & A3DA_FOG_COLOR) - a3dc_read_a3da_rgba(data, size, &i.color); - if (i.flags & A3DA_FOG_DENSITY) - a3dc_read_a3da_key(data, size, &i.density); - if (i.flags & A3DA_FOG_END) - a3dc_read_a3da_key(data, size, &i.end); - if (i.flags & A3DA_FOG_START) - a3dc_read_a3da_key(data, size, &i.start); - } - - for (a3da_light& i : a->light) { - if (i.flags & A3DA_LIGHT_AMBIENT) - a3dc_read_a3da_rgba(data, size, &i.ambient); - if (i.flags & A3DA_LIGHT_CONE_ANGLE) - a3dc_read_a3da_key(data, size, &i.cone_angle); - if (i.flags & A3DA_LIGHT_CONSTANT) - a3dc_read_a3da_key(data, size, &i.constant); - if (i.flags & A3DA_LIGHT_DIFFUSE) - a3dc_read_a3da_rgba(data, size, &i.diffuse); - if (i.flags & A3DA_LIGHT_DROP_OFF) - a3dc_read_a3da_key(data, size, &i.drop_off); - if (i.flags & A3DA_LIGHT_FAR) - a3dc_read_a3da_key(data, size, &i._far); - if (i.flags & A3DA_LIGHT_INTENSITY) - a3dc_read_a3da_key(data, size, &i.intensity); - if (i.flags & A3DA_LIGHT_LINEAR) - a3dc_read_a3da_key(data, size, &i.linear); - if (i.flags & A3DA_LIGHT_POSITION) - a3dc_read_a3da_model_transform(data, size, &i.position, _compress_f16); - if (i.flags & A3DA_LIGHT_QUADRATIC) - a3dc_read_a3da_key(data, size, &i.quadratic); - if (i.flags & A3DA_LIGHT_SPECULAR) - a3dc_read_a3da_rgba(data, size, &i.specular); - if (i.flags & A3DA_LIGHT_SPOT_DIRECTION) - a3dc_read_a3da_model_transform(data, size, &i.spot_direction, _compress_f16); - if (i.flags & A3DA_LIGHT_TONE_CURVE) - a3dc_read_a3da_rgba(data, size, &i.tone_curve); - } - - for (a3da_m_object_hrc& i : a->m_object_hrc) { - for (a3da_object_instance& j : i.instance) - a3dc_read_a3da_model_transform(data, size, &j.model_transform, _compress_f16); - - a3dc_read_a3da_model_transform(data, size, &i.model_transform, _compress_f16); - - for (a3da_object_node& j : i.node) - a3dc_read_a3da_model_transform(data, size, &j.model_transform, _compress_f16); - } - - for (a3da_material_list& i : a->material_list) { - if (i.flags & A3DA_MATERIAL_LIST_BLEND_COLOR) - a3dc_read_a3da_rgba(data, size, &i.blend_color); - if (i.flags & A3DA_MATERIAL_LIST_GLOW_INTENSITY) - a3dc_read_a3da_key(data, size, &i.glow_intensity); - if (i.flags & A3DA_MATERIAL_LIST_EMISSION) - a3dc_read_a3da_rgba(data, size, &i.emission); - } - - for (a3da_object& i : a->object) { - a3dc_read_a3da_model_transform(data, size, &i.model_transform, _compress_f16); - - for (a3da_object_texture_transform& j : i.texture_transform) { - if (j.flags & A3DA_OBJECT_TEXTURE_TRANSFORM_COVERAGE_U) - a3dc_read_a3da_key(data, size, &j.coverage_u); - if (j.flags & A3DA_OBJECT_TEXTURE_TRANSFORM_COVERAGE_V) - a3dc_read_a3da_key(data, size, &j.coverage_v); - if (j.flags & A3DA_OBJECT_TEXTURE_TRANSFORM_OFFSET_U) - a3dc_read_a3da_key(data, size, &j.offset_u); - if (j.flags & A3DA_OBJECT_TEXTURE_TRANSFORM_OFFSET_V) - a3dc_read_a3da_key(data, size, &j.offset_v); - if (j.flags & A3DA_OBJECT_TEXTURE_TRANSFORM_REPEAT_U) - a3dc_read_a3da_key(data, size, &j.repeat_u); - if (j.flags & A3DA_OBJECT_TEXTURE_TRANSFORM_REPEAT_V) - a3dc_read_a3da_key(data, size, &j.repeat_v); - if (j.flags & A3DA_OBJECT_TEXTURE_TRANSFORM_ROTATE) - a3dc_read_a3da_key(data, size, &j.rotate); - if (j.flags & A3DA_OBJECT_TEXTURE_TRANSFORM_ROTATE_FRAME) - a3dc_read_a3da_key(data, size, &j.rotate_frame); - if (j.flags & A3DA_OBJECT_TEXTURE_TRANSFORM_TRANSLATE_FRAME_U) - a3dc_read_a3da_key(data, size, &j.translate_frame_u); - if (j.flags & A3DA_OBJECT_TEXTURE_TRANSFORM_TRANSLATE_FRAME_V) - a3dc_read_a3da_key(data, size, &j.translate_frame_v); + kv.close_scope(); } - } - for (a3da_object_hrc& i : a->object_hrc) - for (a3da_object_node& j : i.node) - a3dc_read_a3da_model_transform(data, size, &j.model_transform, _compress_f16); + if (sc->point.size() > 0) { + kv.open_scope("point"); - for (a3da_point& i : a->point) - a3dc_read_a3da_model_transform(data, size, &i.model_transform, _compress_f16); + int32_t count = (int32_t)sc->point.size(); + Point* vp = sc->point.data(); - if (a->post_process.flags) { - a3da_post_process* pp = &a->post_process; + std::vector sort_index; + key_val_out::get_lexicographic_order(sort_index, count); + int32_t* sort_index_data = sort_index.data(); + for (int32_t i = 0; i < count; i++) { + kv.open_scope_fmt(sort_index_data[i]); - if (pp->flags & A3DA_POST_PROCESS_INTENSITY) - a3dc_read_a3da_rgba(data, size, &pp->intensity); - if (pp->flags & A3DA_POST_PROCESS_LENS_FLARE) - a3dc_read_a3da_key(data, size, &pp->lens_flare); - if (pp->flags & A3DA_POST_PROCESS_LENS_GHOST) - a3dc_read_a3da_key(data, size, &pp->lens_ghost); - if (pp->flags & A3DA_POST_PROCESS_LENS_SHAFT) - a3dc_read_a3da_key(data, size, &pp->lens_shaft); - if (pp->flags & A3DA_POST_PROCESS_RADIUS) - a3dc_read_a3da_rgba(data, size, &pp->radius); - if (pp->flags & A3DA_POST_PROCESS_SCENE_FADE) - a3dc_read_a3da_rgba(data, size, &pp->scene_fade); - } -} + Point* p = &vp[sort_index_data[i]]; + kv.write(s, p->name); + key_val_out_write(&kv, s, "", p->model_transform); -static void a3da_write_data(a3da* a, void** data, size_t* size) { - a3da_compress_f16& _compress_f16 = a->_compress_f16; - - memory_stream s; - s.open(); - - bool aft_rgba = a->format == A3DA_FORMAT_AFT || a->format == A3DA_FORMAT_AFT_X_PACK; - bool x_pack = a->format == A3DA_FORMAT_AFT_X_PACK; - - for (a3da_camera_root& i : a->camera_root) { - a3dc_write_a3da_model_transform_offset(s, i.model_transform); - a3dc_write_a3da_model_transform_offset(s, i.view_point.model_transform); - a3dc_write_a3da_model_transform_offset(s, i.interest); - } - - for (a3da_chara& i : a->chara) - a3dc_write_a3da_model_transform_offset(s, i.model_transform); - - for (a3da_light& i : a->light) { - if (i.flags & A3DA_LIGHT_POSITION) - a3dc_write_a3da_model_transform_offset(s, i.position); - if (i.flags & A3DA_LIGHT_SPOT_DIRECTION) - a3dc_write_a3da_model_transform_offset(s, i.spot_direction); - } - - for (a3da_m_object_hrc& i : a->m_object_hrc) { - a3dc_write_a3da_model_transform_offset(s, i.model_transform); - - for (a3da_object_node& j : i.node) - a3dc_write_a3da_model_transform_offset(s, j.model_transform); - - for (a3da_object_instance& j : i.instance) - a3dc_write_a3da_model_transform_offset(s, j.model_transform); - } - - for (a3da_object& i : a->object) - a3dc_write_a3da_model_transform_offset(s, i.model_transform); - - for (a3da_object_hrc& i : a->object_hrc) - for (a3da_object_node& j : i.node) - a3dc_write_a3da_model_transform_offset(s, j.model_transform); - - for (a3da_point& i : a->point) - a3dc_write_a3da_model_transform_offset(s, i.model_transform); - - for (a3da_ambient& i : a->ambient) { - if ((i.flags & A3DA_AMBIENT_LIGHT_DIFFUSE) && !aft_rgba) - a3dc_write_a3da_rgba(s, i.light_diffuse); - if ((i.flags & A3DA_AMBIENT_RIM_LIGHT_DIFFUSE) && !aft_rgba) - a3dc_write_a3da_rgba(s, i.rim_light_diffuse); - } - - if (a->camera_auxiliary.flags) { - a3da_camera_auxiliary* ca = &a->camera_auxiliary; - - if (ca->flags & A3DA_CAMERA_AUXILIARY_AUTO_EXPOSURE) - a3dc_write_a3da_key(s, ca->auto_exposure); - if (ca->flags & A3DA_CAMERA_AUXILIARY_EXPOSURE) - a3dc_write_a3da_key(s, ca->exposure); - if (ca->flags & A3DA_CAMERA_AUXILIARY_EXPOSURE_RATE) - a3dc_write_a3da_key(s, ca->exposure_rate); - if (ca->flags & A3DA_CAMERA_AUXILIARY_GAMMA) - a3dc_write_a3da_key(s, ca->gamma); - if (ca->flags & A3DA_CAMERA_AUXILIARY_GAMMA_RATE) - a3dc_write_a3da_key(s, ca->gamma_rate); - if (ca->flags & A3DA_CAMERA_AUXILIARY_SATURATE) - a3dc_write_a3da_key(s, ca->saturate); - } - - for (a3da_camera_root& i : a->camera_root) { - a3dc_write_a3da_model_transform(s, i.model_transform, _compress_f16); - - a3da_camera_root_view_point* vp = &i.view_point; - - a3dc_write_a3da_model_transform(s, vp->model_transform, _compress_f16); - if (vp->flags & A3DA_CAMERA_ROOT_VIEW_POINT_ROLL) - a3dc_write_a3da_key(s, vp->roll); - if (vp->flags & A3DA_CAMERA_ROOT_VIEW_POINT_FOV) - a3dc_write_a3da_key(s, vp->fov); - else - a3dc_write_a3da_key(s, vp->focal_length); - a3dc_write_a3da_model_transform(s, i.interest, _compress_f16); - } - - for (a3da_chara& i : a->chara) - a3dc_write_a3da_model_transform(s, i.model_transform, _compress_f16); - - for (a3da_curve& i : a->curve) - a3dc_write_a3da_key(s, i.curve); - - if (a->dof.has_dof && a->format == A3DA_FORMAT_AFT_X_PACK) { - a3da_dof* d = &a->dof; - a3da_model_transform_make_raw_data_binary(&d->model_transform); - a3dc_write_a3da_model_transform(s, d->model_transform, _compress_f16); - } - - for (a3da_light& i : a->light) { - if (i.flags & A3DA_LIGHT_POSITION) - a3dc_write_a3da_model_transform(s, i.position, _compress_f16); - if (i.flags & A3DA_LIGHT_SPOT_DIRECTION) - a3dc_write_a3da_model_transform(s, i.spot_direction, _compress_f16); - if (x_pack) { - if (i.flags & A3DA_LIGHT_AMBIENT) { - a3da_rgba_make_raw_data_binary(&i.ambient); - a3dc_write_a3da_rgba(s, i.ambient); - } - if (i.flags & A3DA_LIGHT_DIFFUSE) { - a3da_rgba_make_raw_data_binary(&i.diffuse); - a3dc_write_a3da_rgba(s, i.diffuse); - } - if (i.flags & A3DA_LIGHT_SPECULAR) { - a3da_rgba_make_raw_data_binary(&i.specular); - a3dc_write_a3da_rgba(s, i.specular); - } - if (i.flags & A3DA_LIGHT_TONE_CURVE) { - a3da_rgba_make_raw_data_binary(&i.tone_curve); - a3dc_write_a3da_rgba(s, i.tone_curve); - } - } - else if (!aft_rgba) { - if (i.flags & A3DA_LIGHT_AMBIENT) - a3dc_write_a3da_rgba(s, i.ambient); - if (i.flags & A3DA_LIGHT_DIFFUSE) - a3dc_write_a3da_rgba(s, i.diffuse); - if (i.flags & A3DA_LIGHT_SPECULAR) - a3dc_write_a3da_rgba(s, i.specular); - if (i.flags & A3DA_LIGHT_TONE_CURVE) - a3dc_write_a3da_rgba(s, i.tone_curve); - } - if (a->format == A3DA_FORMAT_XHD) { - if (i.flags & A3DA_LIGHT_INTENSITY) - a3dc_write_a3da_key(s, i.intensity); - if (i.flags & A3DA_LIGHT_FAR) - a3dc_write_a3da_key(s, i._far); - if (i.flags & A3DA_LIGHT_CONSTANT) - a3dc_write_a3da_key(s, i.constant); - if (i.flags & A3DA_LIGHT_LINEAR) - a3dc_write_a3da_key(s, i.linear); - if (i.flags & A3DA_LIGHT_QUADRATIC) - a3dc_write_a3da_key(s, i.quadratic); - if (i.flags & A3DA_LIGHT_DROP_OFF) - a3dc_write_a3da_key(s, i.drop_off); - if (i.flags & A3DA_LIGHT_CONE_ANGLE) - a3dc_write_a3da_key(s, i.cone_angle); - } - } - - for (a3da_fog& i : a->fog) { - if (i.flags & A3DA_FOG_DENSITY) - a3dc_write_a3da_key(s, i.density); - if (i.flags & A3DA_FOG_END) - a3dc_write_a3da_key(s, i.end); - if (i.flags & A3DA_FOG_START) - a3dc_write_a3da_key(s, i.start); - if (x_pack) { - if (i.flags & A3DA_FOG_COLOR) { - a3da_rgba_make_raw_data_binary(&i.color); - a3dc_write_a3da_rgba(s, i.color); - } - } - else if (!aft_rgba) { - if (i.flags & A3DA_FOG_COLOR) - a3dc_write_a3da_rgba(s, i.color); - } - } - - for (a3da_m_object_hrc& i : a->m_object_hrc) { - a3dc_write_a3da_model_transform(s, i.model_transform, _compress_f16); - - for (a3da_object_node& j : i.node) - a3dc_write_a3da_model_transform(s, j.model_transform, _compress_f16); - - for (a3da_object_instance& j : i.instance) - a3dc_write_a3da_model_transform(s, j.model_transform, _compress_f16); - } - - if (a->format == A3DA_FORMAT_X || a->format == A3DA_FORMAT_XHD) - for (a3da_material_list& i : a->material_list) { - if (i.flags & A3DA_MATERIAL_LIST_GLOW_INTENSITY) - a3dc_write_a3da_key(s, i.glow_intensity); - if (i.flags & A3DA_MATERIAL_LIST_BLEND_COLOR) - a3dc_write_a3da_rgba(s, i.blend_color); - if (i.flags & A3DA_MATERIAL_LIST_EMISSION) - a3dc_write_a3da_rgba(s, i.emission); - } - else if (a->format == A3DA_FORMAT_AFT_X_PACK) - for (a3da_material_list& i : a->material_list) { - if (i.flags & A3DA_MATERIAL_LIST_BLEND_COLOR) { - a3da_rgba_make_raw_data_binary(&i.blend_color); - a3dc_write_a3da_rgba(s, i.blend_color); + kv.close_scope(); } - if (i.flags & A3DA_MATERIAL_LIST_EMISSION) { - a3da_rgba_make_raw_data_binary(&i.emission); - a3dc_write_a3da_rgba(s, i.emission); + kv.write(s, "length", count); + kv.close_scope(); + } + + s.copy(data, size); + } + + static void a3da_read_data(Scene* sc, void* data, size_t size) { + COMPRESS_TYPE& _compress_f16 = sc->_compress_f16; + + // MGF + for (Ambient& i : sc->ambient) { + if (i.flag & Ambient::FLAG_LIGHT_DIFFUSE) + a3dc_read_a3da_rgba(data, size, &i.light_diffuse); + if (i.flag & Ambient::FLAG_RIM_LIGHT_DIFFUSE) + a3dc_read_a3da_rgba(data, size, &i.rim_light_diffuse); + } + + if (sc->camera_auxiliary.flag) { + CameraAuxiliary* ca = &sc->camera_auxiliary; + + if (ca->flag & CameraAuxiliary::FLAG_EXPOSURE) + a3dc_read_a3da_key(data, size, &ca->exposure); + if (ca->flag & CameraAuxiliary::FLAG_EXPOSURE_RATE) // F/F2/X + a3dc_read_a3da_key(data, size, &ca->exposure_rate); + if (ca->flag & CameraAuxiliary::FLAG_GAMMA) + a3dc_read_a3da_key(data, size, &ca->gamma); + if (ca->flag & CameraAuxiliary::FLAG_GAMMA_RATE) // F/F2/X + a3dc_read_a3da_key(data, size, &ca->gamma_rate); + if (ca->flag & CameraAuxiliary::FLAG_SATURATE) + a3dc_read_a3da_key(data, size, &ca->saturate); + if (ca->flag & CameraAuxiliary::FLAG_AUTO_EXPOSURE) + a3dc_read_a3da_key(data, size, &ca->auto_exposure); + } + + for (CameraRoot& i : sc->camera_root) { + a3dc_read_a3da_model_transform(data, size, &i.model_transform, _compress_f16); + + CameraInterest& intr = i.interest; + a3dc_read_a3da_model_transform(data, size, &intr.model_transform, _compress_f16); + + CameraViewPoint& vp = i.view_point; + a3dc_read_a3da_model_transform(data, size, &vp.model_transform, _compress_f16); + a3dc_read_a3da_key(data, size, &vp.roll); + + if (vp.has_fov) + a3dc_read_a3da_key(data, size, &vp.fov); + else + a3dc_read_a3da_key(data, size, &vp.focal_length); + } + + for (Chara& i : sc->chara) + a3dc_read_a3da_model_transform(data, size, &i.model_transform, _compress_f16); + + for (Curve& i : sc->curve) + a3dc_read_a3da_key(data, size, &i.fcurve); + + if (sc->dof.has_dof) { + Dof* d = &sc->dof; + + a3dc_read_a3da_model_transform(data, size, &d->model_transform, _compress_f16); + } + + for (Fog& i : sc->fog) { + if (i.flag & Fog::FLAG_DENSITY) + a3dc_read_a3da_key(data, size, &i.density); + if (i.flag & Fog::FLAG_START) + a3dc_read_a3da_key(data, size, &i.start); + if (i.flag & Fog::FLAG_END) + a3dc_read_a3da_key(data, size, &i.end); + if (i.flag & Fog::FLAG_COLOR) + a3dc_read_a3da_rgba(data, size, &i.color); + } + + for (Light& i : sc->light) { + if (i.position.flag) + a3dc_read_a3da_model_transform(data, size, &i.position, _compress_f16); + if (i.spot_direction.flag) + a3dc_read_a3da_model_transform(data, size, &i.spot_direction, _compress_f16); + if (i.flag & Light::FLAG_AMBIENT) + a3dc_read_a3da_rgba(data, size, &i.ambient); + if (i.flag & Light::FLAG_DIFFUSE) + a3dc_read_a3da_rgba(data, size, &i.diffuse); + if (i.flag & Light::FLAG_SPECULAR) + a3dc_read_a3da_rgba(data, size, &i.specular); + if (i.flag & Light::FLAG_TONE_CURVE) + a3dc_read_a3da_rgba(data, size, &i.tone_curve); + + // XHD + if (i.flag & Light::FLAG_CONSTANT) + a3dc_read_a3da_key(data, size, &i.constant); + if (i.flag & Light::FLAG_INTENSITY) + a3dc_read_a3da_key(data, size, &i.intensity); + if (i.flag & Light::FLAG_FAR) + a3dc_read_a3da_key(data, size, &i.far_); + if (i.flag & Light::FLAG_LINEAR) + a3dc_read_a3da_key(data, size, &i.linear); + if (i.flag & Light::FLAG_QUADRATIC) + a3dc_read_a3da_key(data, size, &i.quadratic); + if (i.flag & Light::FLAG_DROP_OFF) + a3dc_read_a3da_key(data, size, &i.drop_off); + if (i.flag & Light::FLAG_CONE_ANGLE) + a3dc_read_a3da_key(data, size, &i.cone_angle); + } + + for (MObjectHrc& i : sc->m_object_hrc) { + for (ObjectInstance& j : i.instance) + a3dc_read_a3da_model_transform(data, size, &j.model_transform, _compress_f16); + + a3dc_read_a3da_model_transform(data, size, &i.model_transform, _compress_f16); + + for (ObjectNode& j : i.node) + a3dc_read_a3da_model_transform(data, size, &j.model_transform, _compress_f16); + } + + // X/XHD + for (MaterialList& i : sc->material_list) { + if (i.flag & MaterialList::FLAG_EMISSION) + a3dc_read_a3da_rgba(data, size, &i.emission); + if (i.flag & MaterialList::FLAG_BLEND_COLOR) + a3dc_read_a3da_rgba(data, size, &i.blend_color); + if (i.flag & MaterialList::FLAG_GLOW_INTENSITY) + a3dc_read_a3da_key(data, size, &i.glow_intensity); + } + + for (Object& i : sc->object) { + a3dc_read_a3da_model_transform(data, size, &i.model_transform, _compress_f16); + + for (TextureTransform& j : i.texture_transform) { + if (j.flag & TextureTransform::FLAG_COVERAGE_U) + a3dc_read_a3da_key(data, size, &j.coverage_u); + if (j.flag & TextureTransform::FLAG_COVERAGE_V) + a3dc_read_a3da_key(data, size, &j.coverage_v); + if (j.flag & TextureTransform::FLAG_REPEAT_U) + a3dc_read_a3da_key(data, size, &j.repeat_u); + if (j.flag & TextureTransform::FLAG_REPEAT_V) + a3dc_read_a3da_key(data, size, &j.repeat_v); + if (j.flag & TextureTransform::FLAG_ROTATE) + a3dc_read_a3da_key(data, size, &j.rotate); + if (j.flag & TextureTransform::FLAG_ROTATE_FRAME) + a3dc_read_a3da_key(data, size, &j.rotate_frame); + if (j.flag & TextureTransform::FLAG_OFFSET_U) + a3dc_read_a3da_key(data, size, &j.offset_u); + if (j.flag & TextureTransform::FLAG_OFFSET_V) + a3dc_read_a3da_key(data, size, &j.offset_v); + if (j.flag & TextureTransform::FLAG_TRANSLATE_FRAME_U) + a3dc_read_a3da_key(data, size, &j.translate_frame_u); + if (j.flag & TextureTransform::FLAG_TRANSLATE_FRAME_V) + a3dc_read_a3da_key(data, size, &j.translate_frame_v); } } - for (a3da_object& i : a->object) { - a3dc_write_a3da_model_transform(s, i.model_transform, _compress_f16); + for (ObjectHrc& i : sc->object_hrc) + for (ObjectNode& j : i.node) + a3dc_read_a3da_model_transform(data, size, &j.model_transform, _compress_f16); - for (a3da_object_texture_transform& j : i.texture_transform) { - if (j.flags & A3DA_OBJECT_TEXTURE_TRANSFORM_COVERAGE_U) - a3dc_write_a3da_key(s, j.coverage_u); - if (j.flags & A3DA_OBJECT_TEXTURE_TRANSFORM_COVERAGE_V) - a3dc_write_a3da_key(s, j.coverage_v); - if (j.flags & A3DA_OBJECT_TEXTURE_TRANSFORM_REPEAT_U) - a3dc_write_a3da_key(s, j.repeat_u); - if (j.flags & A3DA_OBJECT_TEXTURE_TRANSFORM_REPEAT_V) - a3dc_write_a3da_key(s, j.repeat_v); - if (j.flags & A3DA_OBJECT_TEXTURE_TRANSFORM_OFFSET_U) - a3dc_write_a3da_key(s, j.offset_u); - if (j.flags & A3DA_OBJECT_TEXTURE_TRANSFORM_OFFSET_V) - a3dc_write_a3da_key(s, j.offset_v); - if (j.flags & A3DA_OBJECT_TEXTURE_TRANSFORM_ROTATE) - a3dc_write_a3da_key(s, j.rotate); - if (j.flags & A3DA_OBJECT_TEXTURE_TRANSFORM_ROTATE_FRAME) - a3dc_write_a3da_key(s, j.rotate_frame); - if (j.flags & A3DA_OBJECT_TEXTURE_TRANSFORM_TRANSLATE_FRAME_U) - a3dc_write_a3da_key(s, j.translate_frame_u); - if (j.flags & A3DA_OBJECT_TEXTURE_TRANSFORM_TRANSLATE_FRAME_V) - a3dc_write_a3da_key(s, j.translate_frame_v); + for (Point& i : sc->point) + a3dc_read_a3da_model_transform(data, size, &i.model_transform, _compress_f16); + + if (sc->post_process.flag) { + PostProcess* pp = &sc->post_process; + + if (pp->flag & PostProcess::FLAG_LENS_FLARE) + a3dc_read_a3da_key(data, size, &pp->lens_flare); + if (pp->flag & PostProcess::FLAG_LENS_SHAFT) + a3dc_read_a3da_key(data, size, &pp->lens_shaft); + if (pp->flag & PostProcess::FLAG_LENS_GHOST) + a3dc_read_a3da_key(data, size, &pp->lens_ghost); + if (pp->flag & PostProcess::FLAG_RADIUS) + a3dc_read_a3da_rgba(data, size, &pp->radius); + if (pp->flag & PostProcess::FLAG_INTENSITY) + a3dc_read_a3da_rgba(data, size, &pp->intensity); + if (pp->flag & PostProcess::FLAG_SCENE_FADE) + a3dc_read_a3da_rgba(data, size, &pp->scene_fade); } } - for (a3da_object_hrc& i : a->object_hrc) - for (a3da_object_node& j : i.node) - a3dc_write_a3da_model_transform(s, j.model_transform, _compress_f16); + static void a3da_write_data(Scene* sc, void** data, size_t* size) { + COMPRESS_TYPE& _compress_f16 = sc->_compress_f16; - for (a3da_point& i : a->point) - a3dc_write_a3da_model_transform(s, i.model_transform, _compress_f16); + memory_stream s; + s.open(); - if (a->post_process.flags) { - a3da_post_process* pp = &a->post_process; + bool aft_rgba = sc->format == FORMAT_AFT || sc->format == FORMAT_AFT_X_PACK; + bool x_pack = sc->format == FORMAT_AFT_X_PACK; - if (pp->flags & A3DA_POST_PROCESS_LENS_FLARE) - a3dc_write_a3da_key(s, pp->lens_flare); - if (pp->flags & A3DA_POST_PROCESS_LENS_GHOST) - a3dc_write_a3da_key(s, pp->lens_ghost); - if (pp->flags & A3DA_POST_PROCESS_LENS_SHAFT) - a3dc_write_a3da_key(s, pp->lens_shaft); - if (x_pack) { - if (pp->flags & A3DA_POST_PROCESS_INTENSITY) { - a3da_rgba_make_raw_data_binary(&pp->intensity); - a3dc_write_a3da_rgba(s, pp->intensity); + for (CameraRoot& i : sc->camera_root) { + a3dc_write_a3da_model_transform_offset(s, i.model_transform); + a3dc_write_a3da_model_transform_offset(s, i.view_point.model_transform); + a3dc_write_a3da_model_transform_offset(s, i.interest.model_transform); + } + + for (Chara& i : sc->chara) + a3dc_write_a3da_model_transform_offset(s, i.model_transform); + + for (Light& i : sc->light) { + if (i.position.flag) + a3dc_write_a3da_model_transform_offset(s, i.position); + if (i.spot_direction.flag) + a3dc_write_a3da_model_transform_offset(s, i.spot_direction); + } + + for (MObjectHrc& i : sc->m_object_hrc) { + a3dc_write_a3da_model_transform_offset(s, i.model_transform); + + for (ObjectNode& j : i.node) + a3dc_write_a3da_model_transform_offset(s, j.model_transform); + + for (ObjectInstance& j : i.instance) + a3dc_write_a3da_model_transform_offset(s, j.model_transform); + } + + for (Object& i : sc->object) + a3dc_write_a3da_model_transform_offset(s, i.model_transform); + + for (ObjectHrc& i : sc->object_hrc) + for (ObjectNode& j : i.node) + a3dc_write_a3da_model_transform_offset(s, j.model_transform); + + for (Point& i : sc->point) + a3dc_write_a3da_model_transform_offset(s, i.model_transform); + + // MGF + for (Ambient& i : sc->ambient) { + if ((i.flag & Ambient::FLAG_LIGHT_DIFFUSE) && !aft_rgba) + a3dc_write_a3da_rgba(s, i.light_diffuse); + if ((i.flag & Ambient::FLAG_RIM_LIGHT_DIFFUSE) && !aft_rgba) + a3dc_write_a3da_rgba(s, i.rim_light_diffuse); + } + + if (sc->camera_auxiliary.flag) { + CameraAuxiliary* ca = &sc->camera_auxiliary; + + if (ca->flag & CameraAuxiliary::FLAG_EXPOSURE) + a3dc_write_a3da_key(s, ca->exposure); + if (ca->flag & CameraAuxiliary::FLAG_EXPOSURE_RATE) // F/F2/X + a3dc_write_a3da_key(s, ca->exposure_rate); + if (ca->flag & CameraAuxiliary::FLAG_GAMMA) + a3dc_write_a3da_key(s, ca->gamma); + if (ca->flag & CameraAuxiliary::FLAG_GAMMA_RATE) // F/F2/X + a3dc_write_a3da_key(s, ca->gamma_rate); + if (ca->flag & CameraAuxiliary::FLAG_SATURATE) + a3dc_write_a3da_key(s, ca->saturate); + if (ca->flag & CameraAuxiliary::FLAG_AUTO_EXPOSURE) + a3dc_write_a3da_key(s, ca->auto_exposure); + } + + for (CameraRoot& i : sc->camera_root) { + a3dc_write_a3da_model_transform(s, i.model_transform, _compress_f16); + + CameraInterest& intr = i.interest; + CameraViewPoint& vp = i.view_point; + + a3dc_write_a3da_model_transform(s, vp.model_transform, _compress_f16); + a3dc_write_a3da_key(s, vp.roll); + + if (vp.has_fov) + a3dc_write_a3da_key(s, vp.fov); + else + a3dc_write_a3da_key(s, vp.focal_length); + + a3dc_write_a3da_model_transform(s, intr.model_transform, _compress_f16); + } + + for (Chara& i : sc->chara) + a3dc_write_a3da_model_transform(s, i.model_transform, _compress_f16); + + for (Curve& i : sc->curve) + a3dc_write_a3da_key(s, i.fcurve); + + if (sc->dof.has_dof && sc->format == FORMAT_AFT_X_PACK) { + Dof* d = &sc->dof; + a3da_model_transform_make_raw_data_binary(&d->model_transform); + a3dc_write_a3da_model_transform(s, d->model_transform, _compress_f16); + } + + for (Light& i : sc->light) { + if (i.position.flag) + a3dc_write_a3da_model_transform(s, i.position, _compress_f16); + if (i.spot_direction.flag) + a3dc_write_a3da_model_transform(s, i.spot_direction, _compress_f16); + if (x_pack) { + if (i.flag & Light::FLAG_AMBIENT) { + a3da_rgba_make_raw_data_binary(&i.ambient); + a3dc_write_a3da_rgba(s, i.ambient); + } + if (i.flag & Light::FLAG_DIFFUSE) { + a3da_rgba_make_raw_data_binary(&i.diffuse); + a3dc_write_a3da_rgba(s, i.diffuse); + } + if (i.flag & Light::FLAG_SPECULAR) { + a3da_rgba_make_raw_data_binary(&i.specular); + a3dc_write_a3da_rgba(s, i.specular); + } + if (i.flag & Light::FLAG_TONE_CURVE) { + a3da_rgba_make_raw_data_binary(&i.tone_curve); + a3dc_write_a3da_rgba(s, i.tone_curve); + } } - if (pp->flags & A3DA_POST_PROCESS_RADIUS) { - a3da_rgba_make_raw_data_binary(&pp->radius); - a3dc_write_a3da_rgba(s, pp->radius); + else if (!aft_rgba) { + if (i.flag & Light::FLAG_AMBIENT) + a3dc_write_a3da_rgba(s, i.ambient); + if (i.flag & Light::FLAG_DIFFUSE) + a3dc_write_a3da_rgba(s, i.diffuse); + if (i.flag & Light::FLAG_SPECULAR) + a3dc_write_a3da_rgba(s, i.specular); + if (i.flag & Light::FLAG_TONE_CURVE) + a3dc_write_a3da_rgba(s, i.tone_curve); } - if (pp->flags & A3DA_POST_PROCESS_SCENE_FADE) { - a3da_rgba_make_raw_data_binary(&pp->scene_fade); - a3dc_write_a3da_rgba(s, pp->scene_fade); + + // XHD + if (sc->format == FORMAT_XHD) { + if (i.flag & Light::FLAG_INTENSITY) + a3dc_write_a3da_key(s, i.intensity); + if (i.flag & Light::FLAG_FAR) + a3dc_write_a3da_key(s, i.far_); + if (i.flag & Light::FLAG_CONSTANT) + a3dc_write_a3da_key(s, i.constant); + if (i.flag & Light::FLAG_LINEAR) + a3dc_write_a3da_key(s, i.linear); + if (i.flag & Light::FLAG_QUADRATIC) + a3dc_write_a3da_key(s, i.quadratic); + if (i.flag & Light::FLAG_DROP_OFF) + a3dc_write_a3da_key(s, i.drop_off); + if (i.flag & Light::FLAG_CONE_ANGLE) + a3dc_write_a3da_key(s, i.cone_angle); } } - else if (!aft_rgba) { - if (pp->flags & A3DA_POST_PROCESS_INTENSITY) - a3dc_write_a3da_rgba(s, pp->intensity); - if (pp->flags & A3DA_POST_PROCESS_RADIUS) - a3dc_write_a3da_rgba(s, pp->radius); - if (pp->flags & A3DA_POST_PROCESS_SCENE_FADE) - a3dc_write_a3da_rgba(s, pp->scene_fade); + + for (Fog& i : sc->fog) { + if (i.flag & Fog::FLAG_DENSITY) + a3dc_write_a3da_key(s, i.density); + if (i.flag & Fog::FLAG_END) + a3dc_write_a3da_key(s, i.end); + if (i.flag & Fog::FLAG_START) + a3dc_write_a3da_key(s, i.start); + if (x_pack) { + if (i.flag & Fog::FLAG_COLOR) { + a3da_rgba_make_raw_data_binary(&i.color); + a3dc_write_a3da_rgba(s, i.color); + } + } + else if (!aft_rgba) { + if (i.flag & Fog::FLAG_COLOR) + a3dc_write_a3da_rgba(s, i.color); + } } + + for (MObjectHrc& i : sc->m_object_hrc) { + a3dc_write_a3da_model_transform(s, i.model_transform, _compress_f16); + + for (ObjectNode& j : i.node) + a3dc_write_a3da_model_transform(s, j.model_transform, _compress_f16); + + for (ObjectInstance& j : i.instance) + a3dc_write_a3da_model_transform(s, j.model_transform, _compress_f16); + } + + // X/XHD + if (sc->format == FORMAT_X || sc->format == FORMAT_XHD) + for (MaterialList& i : sc->material_list) { + if (i.flag & MaterialList::FLAG_GLOW_INTENSITY) + a3dc_write_a3da_key(s, i.glow_intensity); + if (i.flag & MaterialList::FLAG_BLEND_COLOR) + a3dc_write_a3da_rgba(s, i.blend_color); + if (i.flag & MaterialList::FLAG_EMISSION) + a3dc_write_a3da_rgba(s, i.emission); + } + else if (sc->format == FORMAT_AFT_X_PACK) + for (MaterialList& i : sc->material_list) { + if (i.flag & MaterialList::FLAG_BLEND_COLOR) { + a3da_rgba_make_raw_data_binary(&i.blend_color); + a3dc_write_a3da_rgba(s, i.blend_color); + } + + if (i.flag & MaterialList::FLAG_EMISSION) { + a3da_rgba_make_raw_data_binary(&i.emission); + a3dc_write_a3da_rgba(s, i.emission); + } + } + + for (Object& i : sc->object) { + a3dc_write_a3da_model_transform(s, i.model_transform, _compress_f16); + + for (TextureTransform& j : i.texture_transform) { + if (j.flag & TextureTransform::FLAG_COVERAGE_U) + a3dc_write_a3da_key(s, j.coverage_u); + if (j.flag & TextureTransform::FLAG_COVERAGE_V) + a3dc_write_a3da_key(s, j.coverage_v); + if (j.flag & TextureTransform::FLAG_REPEAT_U) + a3dc_write_a3da_key(s, j.repeat_u); + if (j.flag & TextureTransform::FLAG_REPEAT_V) + a3dc_write_a3da_key(s, j.repeat_v); + if (j.flag & TextureTransform::FLAG_OFFSET_U) + a3dc_write_a3da_key(s, j.offset_u); + if (j.flag & TextureTransform::FLAG_OFFSET_V) + a3dc_write_a3da_key(s, j.offset_v); + if (j.flag & TextureTransform::FLAG_ROTATE) + a3dc_write_a3da_key(s, j.rotate); + if (j.flag & TextureTransform::FLAG_ROTATE_FRAME) + a3dc_write_a3da_key(s, j.rotate_frame); + if (j.flag & TextureTransform::FLAG_TRANSLATE_FRAME_U) + a3dc_write_a3da_key(s, j.translate_frame_u); + if (j.flag & TextureTransform::FLAG_TRANSLATE_FRAME_V) + a3dc_write_a3da_key(s, j.translate_frame_v); + } + } + + for (ObjectHrc& i : sc->object_hrc) + for (ObjectNode& j : i.node) + a3dc_write_a3da_model_transform(s, j.model_transform, _compress_f16); + + for (Point& i : sc->point) + a3dc_write_a3da_model_transform(s, i.model_transform, _compress_f16); + + if (sc->post_process.flag) { + PostProcess* pp = &sc->post_process; + + if (pp->flag & PostProcess::FLAG_LENS_FLARE) + a3dc_write_a3da_key(s, pp->lens_flare); + if (pp->flag & PostProcess::FLAG_LENS_SHAFT) + a3dc_write_a3da_key(s, pp->lens_shaft); + if (pp->flag & PostProcess::FLAG_LENS_GHOST) + a3dc_write_a3da_key(s, pp->lens_ghost); + if (x_pack) { + if (pp->flag & PostProcess::FLAG_RADIUS) { + a3da_rgba_make_raw_data_binary(&pp->radius); + a3dc_write_a3da_rgba(s, pp->radius); + } + if (pp->flag & PostProcess::FLAG_INTENSITY) { + a3da_rgba_make_raw_data_binary(&pp->intensity); + a3dc_write_a3da_rgba(s, pp->intensity); + } + if (pp->flag & PostProcess::FLAG_SCENE_FADE) { + a3da_rgba_make_raw_data_binary(&pp->scene_fade); + a3dc_write_a3da_rgba(s, pp->scene_fade); + } + } + else if (!aft_rgba) { + if (pp->flag & PostProcess::FLAG_RADIUS) + a3dc_write_a3da_rgba(s, pp->radius); + if (pp->flag & PostProcess::FLAG_INTENSITY) + a3dc_write_a3da_rgba(s, pp->intensity); + if (pp->flag & PostProcess::FLAG_SCENE_FADE) + a3dc_write_a3da_rgba(s, pp->scene_fade); + } + } + + for (CameraRoot& i : sc->camera_root) { + CameraInterest& intr = i.interest; + CameraViewPoint& vp = i.view_point; + a3dc_write_a3da_model_transform_offset_data(s, i.model_transform); + a3dc_write_a3da_model_transform_offset_data(s, vp.model_transform); + a3dc_write_a3da_model_transform_offset_data(s, intr.model_transform); + } + + for (Chara& i : sc->chara) + a3dc_write_a3da_model_transform_offset_data(s, i.model_transform); + + for (Light& i : sc->light) { + if (i.position.flag) + a3dc_write_a3da_model_transform_offset_data(s, i.position); + if (i.spot_direction.flag) + a3dc_write_a3da_model_transform_offset_data(s, i.spot_direction); + } + + for (MObjectHrc& i : sc->m_object_hrc) { + a3dc_write_a3da_model_transform_offset_data(s, i.model_transform); + + for (ObjectNode& j : i.node) + a3dc_write_a3da_model_transform_offset_data(s, j.model_transform); + + for (ObjectInstance& j : i.instance) + a3dc_write_a3da_model_transform_offset_data(s, j.model_transform); + } + + for (Object& i : sc->object) + a3dc_write_a3da_model_transform_offset_data(s, i.model_transform); + + for (ObjectHrc& i : sc->object_hrc) + for (ObjectNode& j : i.node) + a3dc_write_a3da_model_transform_offset_data(s, j.model_transform); + + for (Point& i : sc->point) + a3dc_write_a3da_model_transform_offset_data(s, i.model_transform); + + s.align_write(0x10); + s.copy(data, size); } - for (a3da_camera_root& i : a->camera_root) { - a3da_camera_root_view_point* vp = &i.view_point; - a3dc_write_a3da_model_transform_offset_data(s, i.model_transform); - a3dc_write_a3da_model_transform_offset_data(s, vp->model_transform); - a3dc_write_a3da_model_transform_offset_data(s, i.interest); + static void a3da_get_time_stamp(char* buf, size_t buf_size) { + time_t time_now; + struct tm tm; + time(&time_now); + gmtime_s(&tm, &time_now); + + const char* day_of_week[] = { + "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", + }; + + const char* month[] = { + "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", + }; + + sprintf_s(buf, buf_size, "#%s %s %02d %02d:%02d:%02d %04d\n", + day_of_week[tm.tm_wday], month[tm.tm_mon], + tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, 1900 + tm.tm_year); } - for (a3da_chara& i : a->chara) - a3dc_write_a3da_model_transform_offset_data(s, i.model_transform); - - for (a3da_light& i : a->light) { - if (i.flags & A3DA_LIGHT_POSITION) - a3dc_write_a3da_model_transform_offset_data(s, i.position); - if (i.flags & A3DA_LIGHT_SPOT_DIRECTION) - a3dc_write_a3da_model_transform_offset_data(s, i.spot_direction); - } - - for (a3da_m_object_hrc& i : a->m_object_hrc) { - a3dc_write_a3da_model_transform_offset_data(s, i.model_transform); - - for (a3da_object_node& j : i.node) - a3dc_write_a3da_model_transform_offset_data(s, j.model_transform); - - for (a3da_object_instance& j : i.instance) - a3dc_write_a3da_model_transform_offset_data(s, j.model_transform); - } - - for (a3da_object& i : a->object) - a3dc_write_a3da_model_transform_offset_data(s, i.model_transform); - - for (a3da_object_hrc& i : a->object_hrc) - for (a3da_object_node& j : i.node) - a3dc_write_a3da_model_transform_offset_data(s, j.model_transform); - - for (a3da_point& i : a->point) - a3dc_write_a3da_model_transform_offset_data(s, i.model_transform); - - s.align_write(0x10); - s.copy(data, size); -} - -static void a3da_get_time_stamp(char* buf, size_t buf_size) { - time_t time_now; - struct tm tm; - time(&time_now); - gmtime_s(&tm, &time_now); - - const char* day_of_week[] = { - "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", - }; - - const char* month[] = { - "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", - }; - - sprintf_s(buf, buf_size, "#%s %s %02d %02d:%02d:%02d %04d\n", - day_of_week[tm.tm_wday], month[tm.tm_mon], - tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, 1900 + tm.tm_year); -} - -static bool key_val_read(key_val* kv, - const char* key, a3da_key& value) { - if (!kv->open_scope(key)) - return false; - else if (kv->read("bin_offset", value.bin_offset)) { - value.flags = A3DA_KEY_BIN_OFFSET; - kv->close_scope(); - return true; - } - - int32_t type; - if (!kv->read("type", type)) { - kv->close_scope(); - return false; - } - value.type = (a3da_key_type)type; - - if (value.type == A3DA_KEY_NONE) { - kv->close_scope(); - return true; - } - else if (value.type == A3DA_KEY_STATIC) { - kv->read("value", value.value); - kv->close_scope(); - return true; - } - - int32_t ep_type_post; - if (kv->read("ep_type_post", ep_type_post)) - value.ep_type_post = (a3da_ep_type)ep_type_post; - - int32_t ep_type_pre; - if (kv->read("ep_type_pre", ep_type_pre)) - value.ep_type_pre = (a3da_ep_type)ep_type_pre; - - kv->read("max", value.max_frame); - - if (key_val_read_raw_data(kv, value)) { - kv->close_scope(); - return true; - } - - int32_t length; - if (!kv->read("key", "length", length)) { - kv->close_scope(); - return false; - } - - int32_t act_length = length; - value.keys.resize(length); - kft3* keys = value.keys.data(); - - for (int32_t i = 0, j = 0; i < length; i++) { - if (!kv->open_scope_fmt(i)) - continue; - - const char* data; - int32_t type; - if (!kv->read("data", data) || !kv->read("type", type)) { + static bool key_val_read(key_val* kv, + const char* key, Fcurve& value) { + if (!kv->open_scope(key)) + return false; + else if (kv->read("bin_offset", value.bin_offset)) { + value.flag = Fcurve::BIN_OFFSET; kv->close_scope(); - continue; + return true; } - switch (type) { - case KEY_FRAME_TYPE_0: { - float_t f; - if (sscanf_s(data, "%g", &f) == 1) - keys[j++] = { f, 0.0f, 0.0f, 0.0f }; - } break; - case KEY_FRAME_TYPE_1: { - float_t f; - float_t v; - if (sscanf_s(data, "(%g,%g)", &f, &v) == 2) - keys[j++] = { f, v, 0.0f, 0.0f }; - } break; - case KEY_FRAME_TYPE_2: { - float_t f; - float_t v; - float_t t; - if (sscanf_s(data, "(%g,%g,%g)", &f, &v, &t) == 3) - keys[j++] = { f, v, t, t }; - } break; - case KEY_FRAME_TYPE_3: { - float_t f; - float_t v; - float_t t1; - float_t t2; - if (sscanf_s(data, "(%g,%g,%g,%g)", &f, &v, &t1, &t2) == 4) - keys[j++] = { f, v, t1, t2 }; - } break; - default: - keys[j++] = {}; - break; + int32_t type; + if (!kv->read("type", type)) { + kv->close_scope(); + return false; + } + value.type = (FC_TYPE)type; + + if (value.type == FC_TYPE_STATIC_0) { + kv->close_scope(); + return true; + } + else if (value.type == FC_TYPE_STATIC_DATA) { + kv->read("value", value.value); + kv->close_scope(); + return true; } - kv->close_scope(); - } - value.keys.resize(act_length); + int32_t ep_type_post; + if (kv->read("ep_type_post", ep_type_post)) + value.ep_type_post = (EP_TYPE)ep_type_post; - kv->close_scope(); - kv->close_scope(); - return true; -} + int32_t ep_type_pre; + if (kv->read("ep_type_pre", ep_type_pre)) + value.ep_type_pre = (EP_TYPE)ep_type_pre; -static void key_val_out_write(key_val_out* kv, stream& s, - const char* key, a3da_key& value, bool write_true) { - kv->open_scope(key); + kv->read("max", value.max_frame); - if (write_true) - kv->write(s, "true"); - - if (value.flags & A3DA_KEY_BIN_OFFSET) { - kv->write(s, "bin_offset", value.bin_offset); - value.flags, ~A3DA_KEY_BIN_OFFSET; - value.bin_offset = 0; - kv->close_scope(); - return; - } - - if (value.type == A3DA_KEY_NONE) { - kv->write(s, "type", 0); - kv->close_scope(); - return; - } - else if (value.type == A3DA_KEY_STATIC) { - kv->write(s, "type", 1); - kv->write(s, "value", value.value); - kv->close_scope(); - return; - } - - if (value.ep_type_post != A3DA_EP_NONE) - kv->write(s, "ep_type_post", value.ep_type_post); - if (value.ep_type_pre != A3DA_EP_NONE) - kv->write(s, "ep_type_pre", value.ep_type_pre); - - if (value.raw_data) { - key_val_out_write_raw_data(kv, s, value); - kv->close_scope(); - return; - } - - kv->open_scope("key"); - - int32_t length = (int32_t)value.keys.size(); - - std::vector sort_index; - key_val_out::get_lexicographic_order(sort_index, length); - int32_t* sort_index_data = sort_index.data(); - for (int32_t i = 0; i < length; i++) { - kv->open_scope_fmt(sort_index_data[i]); - - kft3 k = value.keys[sort_index_data[i]]; - kf_type kt = KEY_FRAME_TYPE_3; - kft_check(&k, kt, &k, &kt); - - char data_buf[0x200]; - switch (kt) { - case KEY_FRAME_TYPE_0: - sprintf_s(data_buf, sizeof(data_buf), "%g", - k.frame); - break; - case KEY_FRAME_TYPE_1: - sprintf_s(data_buf, sizeof(data_buf), "(%g,%g)", - k.frame, k.value); - break; - case KEY_FRAME_TYPE_2: - sprintf_s(data_buf, sizeof(data_buf), "(%g,%g,%g)", - k.frame, k.value, k.tangent1); - break; - case KEY_FRAME_TYPE_3: - sprintf_s(data_buf, sizeof(data_buf), "(%g,%g,%g,%g)", - k.frame, k.value, k.tangent1, k.tangent2); - break; + if (key_val_read_raw_data(kv, value)) { + kv->close_scope(); + return true; } - kv->write(s, "data", data_buf); - kv->write(s, "type", kt); + int32_t length; + if (!kv->read("key", "length", length)) { + kv->close_scope(); + return false; + } + + int32_t act_length = length; + value.keys.resize(length); + kft3* keys = value.keys.data(); + + for (int32_t i = 0, j = 0; i < length; i++) { + if (!kv->open_scope_fmt(i)) + continue; + + const char* data; + int32_t type; + if (!kv->read("data", data) || !kv->read("type", type)) { + kv->close_scope(); + continue; + } + + switch (type) { + case KEY_FRAME_TYPE_0: { + float_t f; + if (sscanf_s(data, "%g", &f) == 1) + keys[j++] = { f, 0.0f, 0.0f, 0.0f }; + } break; + case KEY_FRAME_TYPE_1: { + float_t f; + float_t v; + if (sscanf_s(data, "(%g,%g)", &f, &v) == 2) + keys[j++] = { f, v, 0.0f, 0.0f }; + } break; + case KEY_FRAME_TYPE_2: { + float_t f; + float_t v; + float_t t; + if (sscanf_s(data, "(%g,%g,%g)", &f, &v, &t) == 3) + keys[j++] = { f, v, t, t }; + } break; + case KEY_FRAME_TYPE_3: { + float_t f; + float_t v; + float_t t1; + float_t t2; + if (sscanf_s(data, "(%g,%g,%g,%g)", &f, &v, &t1, &t2) == 4) + keys[j++] = { f, v, t1, t2 }; + } break; + default: + keys[j++] = {}; + break; + } + + kv->close_scope(); + } + value.keys.resize(act_length); + + kv->close_scope(); + kv->close_scope(); + return true; + } + + static void key_val_out_write(key_val_out* kv, stream& s, + const char* key, Fcurve& value, bool write_true) { + kv->open_scope(key); + + if (write_true) + kv->write(s, "true"); + + if (value.flag & Fcurve::BIN_OFFSET) { + kv->write(s, "bin_offset", value.bin_offset); + value.flag &= ~Fcurve::BIN_OFFSET; + value.bin_offset = 0; + kv->close_scope(); + return; + } + + if (value.type == FC_TYPE_STATIC_0) { + kv->write(s, "type", 0); + kv->close_scope(); + return; + } + else if (value.type == FC_TYPE_STATIC_DATA) { + kv->write(s, "type", 1); + kv->write(s, "value", value.value); + kv->close_scope(); + return; + } + + if (value.ep_type_post != EP_TYPE_CONSTANT) + kv->write(s, "ep_type_post", value.ep_type_post); + if (value.ep_type_pre != EP_TYPE_CONSTANT) + kv->write(s, "ep_type_pre", value.ep_type_pre); + + if (value.raw_data) { + key_val_out_write_raw_data(kv, s, value); + kv->close_scope(); + return; + } + + kv->open_scope("key"); + + int32_t length = (int32_t)value.keys.size(); + + std::vector sort_index; + key_val_out::get_lexicographic_order(sort_index, length); + int32_t* sort_index_data = sort_index.data(); + for (int32_t i = 0; i < length; i++) { + kv->open_scope_fmt(sort_index_data[i]); + + kft3 k = value.keys[sort_index_data[i]]; + kf_type kt = KEY_FRAME_TYPE_3; + kft_check(&k, kt, &k, &kt); + + char data_buf[0x200]; + switch (kt) { + case KEY_FRAME_TYPE_0: + sprintf_s(data_buf, sizeof(data_buf), "%g", + k.frame); + break; + case KEY_FRAME_TYPE_1: + sprintf_s(data_buf, sizeof(data_buf), "(%g,%g)", + k.frame, k.value); + break; + case KEY_FRAME_TYPE_2: + sprintf_s(data_buf, sizeof(data_buf), "(%g,%g,%g)", + k.frame, k.value, k.l_slope); + break; + case KEY_FRAME_TYPE_3: + sprintf_s(data_buf, sizeof(data_buf), "(%g,%g,%g,%g)", + k.frame, k.value, k.l_slope, k.r_slope); + break; + } + + kv->write(s, "data", data_buf); + kv->write(s, "type", kt); + + kv->close_scope(); + } + + kv->write(s, "length", length); + + kv->close_scope(); + + kv->write(s, "max", value.max_frame); + kv->write(s, "type", value.type); kv->close_scope(); } - kv->write(s, "length", length); - - kv->close_scope(); - - kv->write(s, "max", value.max_frame); - kv->write(s, "type", value.type); - - kv->close_scope(); -} - -static bool key_val_read_raw_data(key_val* kv, - a3da_key& value) { - int32_t key_type; - if (!kv->read("raw_data_key_type", key_type)) - return false; - - const char* value_type; - kv->read("raw_data.value_type", value_type); - if (str_utils_compare(value_type, "float")) - return false; - - int32_t value_list_size; - kv->read("raw_data.value_list_size", value_list_size); - - int32_t value_list_offset; - if (kv->read("raw_data.value_list_offset", value_list_offset)) { - if (key_type != 3) + static bool key_val_read_raw_data(key_val* kv, + Fcurve& value) { + int32_t key_type; + if (!kv->read("raw_data_key_type", key_type)) return false; + const char* value_type; + kv->read("raw_data.value_type", value_type); + if (str_utils_compare(value_type, "float")) + return false; + + int32_t value_list_size; + kv->read("raw_data.value_list_size", value_list_size); + + int32_t value_list_offset; + if (kv->read("raw_data.value_list_offset", value_list_offset)) { + if (key_type != 3) + return false; + + value.raw_data = true; + value.raw_data_binary = true; + value.raw_data_value_list_size = value_list_size; + value.raw_data_value_list_offset = value_list_offset; + return true; + } + + const char* value_list; + if (!kv->read("raw_data.value_list", value_list)) + return false; + + const char* s = value_list; + size_t c = 1; + while (s = strchr(s, ',')) { + s++; + c++; + } + + if (c != value_list_size) + return false; + + char b[0x200]; + float_t* fs = force_malloc(c); + s = value_list; + for (size_t i = 0; i < c; i++) { + const char* t = s; + s = strchr(s, ','); + + size_t length = s ? s++ - t : utf8_length(t); + memcpy_s(b, sizeof(b) - 1, t, length); + b[length] = 0; + fs[i] = (float_t)atof(b); + } + + switch (key_type) { + case 0: { + value.keys.resize(c); + kft3* keys = value.keys.data(); + for (size_t i = 0; i < c; i++, fs++) + keys[i] = { fs[0], 0.0f, 0.0f, 0.0f }; + fs -= c; + } break; + case 1: { + c /= 2; + value.keys.resize(c); + kft3* keys = value.keys.data(); + for (size_t i = 0; i < c; i++, fs += 2) + keys[i] = { fs[0], fs[1], 0.0f, 0.0f }; + fs -= c * 2; + } break; + case 2: { + c /= 3; + value.keys.resize(c); + kft3* keys = value.keys.data(); + for (size_t i = 0; i < c; i++, fs += 3) + keys[i] = { fs[0], fs[1], fs[2], fs[2] }; + fs -= c * 3; + } break; + case 3: { + c /= 4; + value.keys.resize(c); + kft3* keys = value.keys.data(); + for (size_t i = 0; i < c; i++, fs += 4) + keys[i] = { fs[0], fs[1], fs[2], fs[3] }; + fs -= c * 4; + } break; + default: + free_def(fs); + return false; + } + free_def(fs); + value.raw_data = true; - value.raw_data_binary = true; - value.raw_data_value_list_size = value_list_size; - value.raw_data_value_list_offset = value_list_offset; return true; } - const char* value_list; - if (!kv->read("raw_data.value_list", value_list)) - return false; + static void key_val_out_write_raw_data(key_val_out* kv, stream& s, + Fcurve& value) { + kv->write(s, "max", value.max_frame); - const char* s = value_list; - size_t c = 1; - while (s = strchr(s, ',')) { - s++; - c++; - } + int32_t length = (int32_t)value.keys.size(); + if (value.raw_data_binary) { + kv->write(s, "raw_data.value_list_offset", + value.raw_data_value_list_offset); + kv->write(s, "raw_data.value_list_size", + value.raw_data_value_list_size); + kv->write(s, "raw_data.value_type", "float"); + kv->write(s, "raw_data_key_type", 3); + kv->write(s, "type", value.type); + return; + } - if (c != value_list_size) - return false; - - char b[0x200]; - float_t* fs = force_malloc(c); - s = value_list; - for (size_t i = 0; i < c; i++) { - const char* t = s; - s = strchr(s, ','); - - size_t length = s ? s++ - t : utf8_length(t); - memcpy_s(b, sizeof(b) - 1, t, length); - b[length] = 0; - fs[i] = (float_t)atof(b); - } - - switch (key_type) { - case 0: { - value.keys.resize(c); kft3* keys = value.keys.data(); - for (size_t i = 0; i < c; i++, fs++) - keys[i] = { fs[0], 0.0f, 0.0f, 0.0f }; - fs -= c; - } break; - case 1: { - c /= 2; - value.keys.resize(c); - kft3* keys = value.keys.data(); - for (size_t i = 0; i < c; i++, fs += 2) - keys[i] = { fs[0], fs[1], 0.0f, 0.0f }; - fs -= c * 2; - } break; - case 2: { - c /= 3; - value.keys.resize(c); - kft3* keys = value.keys.data(); - for (size_t i = 0; i < c; i++, fs += 3) - keys[i] = { fs[0], fs[1], fs[2], fs[2] }; - fs -= c * 3; - } break; - case 3: { - c /= 4; - value.keys.resize(c); - kft3* keys = value.keys.data(); - for (size_t i = 0; i < c; i++, fs += 4) - keys[i] = { fs[0], fs[1], fs[2], fs[3] }; - fs -= c * 4; - } break; - default: - free_def(fs); - return false; - } - free_def(fs); - value.raw_data = true; - return true; -} + kf_type key_type = KEY_FRAME_TYPE_0; + for (int32_t i = 0; i < length; i++) { + kft3 k = keys[i]; + kf_type kt = KEY_FRAME_TYPE_3; + kft_check(&k, kt, &k, &kt); + if (key_type < kt) + key_type = kt; + if (key_type == KEY_FRAME_TYPE_3) + break; + } -static void key_val_out_write_raw_data(key_val_out* kv, stream& s, - a3da_key& value) { - kv->write(s, "max", value.max_frame); + s.write_string(*kv->curr_scope); + s.write_char('.'); + s.write_utf8_string("raw_data.value_list"); + s.write_char('='); - int32_t length = (int32_t)value.keys.size(); - if (value.raw_data_binary) { - kv->write(s, "raw_data.value_list_offset", - value.raw_data_value_list_offset); - kv->write(s, "raw_data.value_list_size", - value.raw_data_value_list_size); - kv->write(s, "raw_data.value_type", "float"); - kv->write(s, "raw_data_key_type", 3); - kv->write(s, "type", value.type); - return; - } - - kft3* keys = value.keys.data(); - - kf_type key_type = KEY_FRAME_TYPE_0; - for (int32_t i = 0; i < length; i++) { - kft3 k = keys[i]; - kf_type kt = KEY_FRAME_TYPE_3; - kft_check(&k, kt, &k, &kt); - if (key_type < kt) - key_type = kt; - if (key_type == KEY_FRAME_TYPE_3) + char data_buf[0x200]; + switch (key_type) { + case KEY_FRAME_TYPE_0: + for (int32_t i = 0; i < length; i++) { + kft3 k = keys[i]; + sprintf_s(data_buf, sizeof(data_buf), "%g", + k.frame); + s.write_utf8_string(data_buf); + if (i + 1 < length) + s.write_char(','); + } break; + case KEY_FRAME_TYPE_1: + for (int32_t i = 0; i < length; i++) { + kft3 k = keys[i]; + sprintf_s(data_buf, sizeof(data_buf), "%g,%g", + k.frame, k.value); + s.write_utf8_string(data_buf); + if (i + 1 < length) + s.write_char(','); + } + break; + case KEY_FRAME_TYPE_2: + for (int32_t i = 0; i < length; i++) { + kft3 k = keys[i]; + sprintf_s(data_buf, sizeof(data_buf), "%g,%g,%g", + k.frame, k.value, k.l_slope); + s.write_utf8_string(data_buf); + if (i + 1 < length) + s.write_char(','); + } + break; + case KEY_FRAME_TYPE_3: + for (int32_t i = 0; i < length; i++) { + kft3 k = keys[i]; + sprintf_s(data_buf, sizeof(data_buf), "%g,%g,%g,%g", + k.frame, k.value, k.l_slope, k.r_slope); + s.write_utf8_string(data_buf); + if (i + 1 < length) + s.write_char(','); + } + break; + } + s.write_char('\n'); + + kv->write(s, "raw_data.value_list_size", + (int32_t)(length * ((size_t)key_type + 1))); + kv->write(s, "raw_data.value_type", "float"); + kv->write(s, "raw_data_key_type", key_type); + kv->write(s, "type", value.type); } - s.write_string(*kv->curr_scope); - s.write_char('.'); - s.write_utf8_string("raw_data.value_list"); - s.write_char('='); + static bool key_val_read(key_val* kv, + const char* key, ModelTransform& value) { + if (!kv->open_scope(key)) + return false; + else if (kv->read("model_transform.bin_offset", value.bin_offset)) { + value.flag = ModelTransform::BIN_OFFSET; + kv->close_scope(); + return true; + } - char data_buf[0x200]; - switch (key_type) { - case KEY_FRAME_TYPE_0: - for (int32_t i = 0; i < length; i++) { - kft3 k = keys[i]; - sprintf_s(data_buf, sizeof(data_buf), "%g", - k.frame); - s.write_utf8_string(data_buf); - if (i + 1 < length) - s.write_char(','); - } - break; - case KEY_FRAME_TYPE_1: - for (int32_t i = 0; i < length; i++) { - kft3 k = keys[i]; - sprintf_s(data_buf, sizeof(data_buf), "%g,%g", - k.frame, k.value); - s.write_utf8_string(data_buf); - if (i + 1 < length) - s.write_char(','); - } - break; - case KEY_FRAME_TYPE_2: - for (int32_t i = 0; i < length; i++) { - kft3 k = keys[i]; - sprintf_s(data_buf, sizeof(data_buf), "%g,%g,%g", - k.frame, k.value, k.tangent1); - s.write_utf8_string(data_buf); - if (i + 1 < length) - s.write_char(','); - } - break; - case KEY_FRAME_TYPE_3: - for (int32_t i = 0; i < length; i++) { - kft3 k = keys[i]; - sprintf_s(data_buf, sizeof(data_buf), "%g,%g,%g,%g", - k.frame, k.value, k.tangent1, k.tangent2); - s.write_utf8_string(data_buf); - if (i + 1 < length) - s.write_char(','); - } - break; - } - s.write_char('\n'); + key_val_read(kv, "rot", value.rotation); + key_val_read(kv, "scale", value.scale); + key_val_read(kv, "trans", value.translation); + key_val_read(kv, "visibility", value.visibility); - kv->write(s, "raw_data.value_list_size", - (int32_t)(length * ((size_t)key_type + 1))); - kv->write(s, "raw_data.value_type", "float"); - kv->write(s, "raw_data_key_type", key_type); - kv->write(s, "type", value.type); -} - -static bool key_val_read(key_val* kv, - const char* key, a3da_model_transform& value) { - if (!kv->open_scope(key)) - return false; - else if (kv->read("model_transform.bin_offset", value.bin_offset)) { - value.flags = A3DA_MODEL_TRANSFORM_BIN_OFFSET; kv->close_scope(); return true; } - key_val_read(kv, "rot", value.rotation); - key_val_read(kv, "scale", value.scale); - key_val_read(kv, "trans", value.translation); - key_val_read(kv, "visibility", value.visibility); + static void key_val_out_write(key_val_out* kv, stream& s, + const char* key, ModelTransform& value, int32_t write_mask) { + kv->open_scope(key); - kv->close_scope(); - return true; -} - -static void key_val_out_write(key_val_out* kv, stream& s, - const char* key, a3da_model_transform& value, int32_t write_mask) { - kv->open_scope(key); - - if (value.flags & A3DA_MODEL_TRANSFORM_BIN_OFFSET) { - if (write_mask & 0x10) { - kv->write(s, "model_transform.bin_offset", value.bin_offset); - } - if (write_mask & 0x01) - if (value.flags & A3DA_MODEL_TRANSFORM_BIN_OFFSET) { - value.flags, ~A3DA_MODEL_TRANSFORM_BIN_OFFSET; - value.bin_offset = 0; + if (value.flag & ModelTransform::BIN_OFFSET) { + if (write_mask & 0x10) { + kv->write(s, "model_transform.bin_offset", value.bin_offset); } - } - else { - if (write_mask & 0x08) - key_val_out_write(kv, s, "rot", value.rotation); - if (write_mask & 0x04) - key_val_out_write(kv, s, "scale", value.scale); - if (write_mask & 0x02) - key_val_out_write(kv, s, "trans", value.translation); - if (write_mask & 0x01) - key_val_out_write(kv, s, "visibility", value.visibility); + if (write_mask & 0x01) + if (value.flag & ModelTransform::BIN_OFFSET) { + value.flag &= ~ModelTransform::BIN_OFFSET; + value.bin_offset = 0; + } + } + else { + if (write_mask & 0x08) + key_val_out_write(kv, s, "rot", value.rotation); + if (write_mask & 0x04) + key_val_out_write(kv, s, "scale", value.scale); + if (write_mask & 0x02) + key_val_out_write(kv, s, "trans", value.translation); + if (write_mask & 0x01) + key_val_out_write(kv, s, "visibility", value.visibility); + } + + kv->close_scope(); } - kv->close_scope(); -} + static bool key_val_read(key_val* kv, + const char* key, FcurveColor4f& value) { + if (!kv->open_scope(key)) + return false; -static bool key_val_read(key_val* kv, - const char* key, a3da_rgba& value) { - if (!kv->open_scope(key)) - return false; + value.has_r = key_val_read(kv, "r", value.r); + value.has_g = key_val_read(kv, "g", value.g); + value.has_b = key_val_read(kv, "b", value.b); + value.has_a = key_val_read(kv, "a", value.a); - if (key_val_read(kv, "r", value.r)) - enum_or(value.flags, A3DA_RGBA_R); - if (key_val_read(kv, "g", value.g)) - enum_or(value.flags, A3DA_RGBA_G); - if (key_val_read(kv, "b", value.b)) - enum_or(value.flags, A3DA_RGBA_B); - if (key_val_read(kv, "a", value.a)) - enum_or(value.flags, A3DA_RGBA_A); + kv->close_scope(); + return true; + } - kv->close_scope(); - return true; -} - -static void key_val_out_write(key_val_out* kv, stream& s, - const char* key, a3da_rgba& value) { - if (!value.flags) - return; - - kv->open_scope(key); - - kv->write(s, "true"); - - if (value.flags & A3DA_RGBA_A) - key_val_out_write(kv, s, "a", value.a); - if (value.flags & A3DA_RGBA_B) - key_val_out_write(kv, s, "b", value.b); - if (value.flags & A3DA_RGBA_G) - key_val_out_write(kv, s, "g", value.g); - if (value.flags & A3DA_RGBA_R) - key_val_out_write(kv, s, "r", value.r); - - kv->close_scope(); -} - -static bool key_val_read(key_val* kv, - const char* key, a3da_vec3& value) { - if (!kv->open_scope(key)) - return false; - - key_val_read(kv, "x", value.x); - key_val_read(kv, "y", value.y); - key_val_read(kv, "z", value.z); - - kv->close_scope(); - return true; -} - -static void key_val_out_write(key_val_out* kv, stream& s, - const char* key, a3da_vec3& value) { - kv->open_scope(key); - - key_val_out_write(kv, s, "x", value.x); - key_val_out_write(kv, s, "y", value.y); - key_val_out_write(kv, s, "z", value.z); - - kv->close_scope(); -} - -inline static void a3dc_read_a3da_key(void* data, size_t size, a3da_key* value) { - a3dc_read_a3da_key_f16(data, size, value, A3DA_COMPRESS_F32F32F32F32); -} - -inline static void a3dc_write_a3da_key(stream& s, a3da_key& value) { - a3dc_write_a3da_key_f16(s, value, A3DA_COMPRESS_F32F32F32F32); -} - -static void a3dc_read_a3da_key_f16(void* data, size_t size, a3da_key* value, a3da_compress_f16 f16) { - if (value->raw_data) { - if (!value->raw_data_binary) + static void key_val_out_write(key_val_out* kv, stream& s, + const char* key, FcurveColor4f& value) { + if (!value.has_r && !value.has_g && !value.has_b && !value.has_a) return; - size_t _d = (size_t)data + value->raw_data_value_list_offset; - value->raw_data_value_list_offset = 0; + kv->open_scope(key); + + kv->write(s, "true"); + + if (value.has_a) + key_val_out_write(kv, s, "a", value.a); + if (value.has_b) + key_val_out_write(kv, s, "b", value.b); + if (value.has_g) + key_val_out_write(kv, s, "g", value.g); + if (value.has_r) + key_val_out_write(kv, s, "r", value.r); + + kv->close_scope(); + } + + static bool key_val_read(key_val* kv, + const char* key, Fcurve3f& value) { + if (!kv->open_scope(key)) + return false; + + key_val_read(kv, "x", value.x); + key_val_read(kv, "y", value.y); + key_val_read(kv, "z", value.z); + + kv->close_scope(); + return true; + } + + static void key_val_out_write(key_val_out* kv, stream& s, + const char* key, Fcurve3f& value) { + kv->open_scope(key); + + key_val_out_write(kv, s, "x", value.x); + key_val_out_write(kv, s, "y", value.y); + key_val_out_write(kv, s, "z", value.z); + + kv->close_scope(); + } + + inline static void a3dc_read_a3da_key(void* data, size_t size, Fcurve* value) { + a3dc_read_a3da_key_f16(data, size, value, COMPRESS_F32F32F32F32); + } + + inline static void a3dc_write_a3da_key(stream& s, Fcurve& value) { + a3dc_write_a3da_key_f16(s, value, COMPRESS_F32F32F32F32); + } + + static void a3dc_read_a3da_key_f16(void* data, size_t size, Fcurve* value, COMPRESS_TYPE f16) { + if (value->raw_data) { + if (!value->raw_data_binary) + return; + + size_t _d = (size_t)data + value->raw_data_value_list_offset; + value->raw_data_value_list_offset = 0; + + int32_t len = value->raw_data_value_list_size / 4; + value->keys.resize(len); + kft3* keys = value->keys.data(); + for (int32_t i = 0; i < len; i++) { + kft3& k = keys[i]; + k.frame = *(float_t*)_d; + k.value = *(float_t*)(_d + 4); + k.l_slope = *(float_t*)(_d + 8); + k.r_slope = *(float_t*)(_d + 12); + _d += 16; + } + return; + } + else if (!(value->flag & Fcurve::BIN_OFFSET)) + return; + + a3dc_key_header* head = (a3dc_key_header*)((size_t)data + value->bin_offset); + value->flag &= ~Fcurve::BIN_OFFSET; + value->bin_offset = 0; + + size_t d = (size_t)head + sizeof(a3dc_key_header); + + if (head->type == FC_TYPE_STATIC_0) { + value->type = head->type; + return; + } + else if (head->type == FC_TYPE_STATIC_DATA) { + value->type = head->type; + value->value = head->value; + return; + } + + value->type = head->type; + value->ep_type_pre = head->ep_type_pre; + value->ep_type_post = head->ep_type_post; + value->max_frame = head->max_frame; + uint32_t len = head->length; - int32_t len = value->raw_data_value_list_size / 4; value->keys.resize(len); kft3* keys = value->keys.data(); - for (int32_t i = 0; i < len; i++) { - kft3& k = keys[i]; - k.frame = *(float_t*)_d; - k.value = *(float_t*)(_d + 4); - k.tangent1 = *(float_t*)(_d + 8); - k.tangent2 = *(float_t*)(_d + 12); - _d += 16; + switch (f16) { + case COMPRESS_F32F32F32F32: + default: + for (uint32_t i = 0; i < len; i++) { + kft3& k = keys[i]; + k.frame = *(float_t*)d; + k.value = *(float_t*)(d + 4); + k.l_slope = *(float_t*)(d + 8); + k.r_slope = *(float_t*)(d + 12); + d += 16; + } + break; + case COMPRESS_I16F16F32F32: + for (uint32_t i = 0; i < len; i++) { + kft3& k = keys[i]; + k.frame = (float_t)*(int16_t*)d; + k.value = half_to_float(*(half_t*)(d + 2)); + k.l_slope = *(float_t*)(d + 4); + k.r_slope = *(float_t*)(d + 8); + d += 12; + } + break; + case COMPRESS_I16F16F16F16: + for (uint32_t i = 0; i < len; i++) { + kft3& k = keys[i]; + k.frame = (float_t)*(int16_t*)d; + k.value = half_to_float(*(half_t*)(d + 2)); + k.l_slope = half_to_float(*(half_t*)(d + 4)); + k.r_slope = half_to_float(*(half_t*)(d + 6)); + d += 8; + } + break; } - return; - } - else if (!(value->flags & A3DA_KEY_BIN_OFFSET)) - return; - - a3dc_key_header* head = (a3dc_key_header*)((size_t)data + value->bin_offset); - enum_and(value->flags, ~A3DA_KEY_BIN_OFFSET); - value->bin_offset = 0; - - size_t d = (size_t)head + sizeof(a3dc_key_header); - - if (head->type == A3DA_KEY_NONE) { - value->type = head->type; - return; - } - else if (head->type == A3DA_KEY_STATIC) { - value->type = head->type; - value->value = head->value; - return; } - value->type = head->type; - value->ep_type_pre = head->ep_type_pre; - value->ep_type_post = head->ep_type_post; - value->max_frame = head->max_frame; - uint32_t len = head->length; + static void a3dc_write_a3da_key_f16(stream& s, Fcurve& value, COMPRESS_TYPE f16) { + if (value.raw_data) { + if (value.type == FC_TYPE_STATIC_0 || value.type == FC_TYPE_STATIC_DATA) { + value.raw_data = false; + value.raw_data_binary = false; + return; + } + else if (value.keys.size() < 1) { + value.raw_data = false; + value.raw_data_binary = false; + value.type = FC_TYPE_STATIC_0; + value.keys.resize(0); + return; + } + else if (value.keys.size() == 1) { + value.raw_data = false; + value.raw_data_binary = false; + value.type = FC_TYPE_STATIC_DATA; + value.value = value.keys[0].value; + value.keys.resize(0); + return; + } + } - value->keys.resize(len); - kft3* keys = value->keys.data(); - switch (f16) { - case A3DA_COMPRESS_F32F32F32F32: - default: - for (uint32_t i = 0; i < len; i++) { - kft3& k = keys[i]; - k.frame = *(float_t*)d; - k.value = *(float_t*)(d + 4); - k.tangent1 = *(float_t*)(d + 8); - k.tangent2 = *(float_t*)(d + 12); - d += 16; - } - break; - case A3DA_COMPRESS_I16F16F32F32: - for (uint32_t i = 0; i < len; i++) { - kft3& k = keys[i]; - k.frame = (float_t)*(int16_t*)d; - k.value = half_to_float(*(half_t*)(d + 2)); - k.tangent1 = *(float_t*)(d + 4); - k.tangent2 = *(float_t*)(d + 8); - d += 12; - } - break; - case A3DA_COMPRESS_I16F16F16F16: - for (uint32_t i = 0; i < len; i++) { - kft3& k = keys[i]; - k.frame = (float_t)*(int16_t*)d; - k.value = half_to_float(*(half_t*)(d + 2)); - k.tangent1 = half_to_float(*(half_t*)(d + 4)); - k.tangent2 = half_to_float(*(half_t*)(d + 6)); - d += 8; - } - break; - } -} + if (value.raw_data) { + if (!value.raw_data_binary) + return; -static void a3dc_write_a3da_key_f16(stream& s, a3da_key& value, a3da_compress_f16 f16) { - if (value.raw_data) { - if (value.type == A3DA_KEY_NONE || value.type == A3DA_KEY_STATIC) { - value.raw_data = false; - value.raw_data_binary = false; + value.raw_data_value_list_offset = (int32_t)s.get_position(); + + int32_t len = (int32_t)value.keys.size(); + kft3* keys = value.keys.data(); + value.raw_data_value_list_size = len * 4; + for (int32_t i = 0; i < len; i++) { + kft3* k = &keys[i]; + s.write_float_t(k->frame); + s.write_float_t(k->value); + s.write_float_t(k->l_slope); + s.write_float_t(k->r_slope); + } return; } - else if (value.keys.size() < 1) { - value.raw_data = false; - value.raw_data_binary = false; - value.type = A3DA_KEY_NONE; - value.keys.resize(0); + + value.bin_offset = (int32_t)s.get_position(); + value.flag |= Fcurve::BIN_OFFSET; + + if (value.type == FC_TYPE_STATIC_0) { + s.write_int32_t(FC_TYPE_STATIC_0); + s.write_float_t(0.0f); return; } - else if (value.keys.size() == 1) { - value.raw_data = false; - value.raw_data_binary = false; - value.type = A3DA_KEY_STATIC; - value.value = value.keys[0].value; - value.keys.resize(0); + else if (value.type == FC_TYPE_STATIC_DATA) { + s.write_int32_t(FC_TYPE_STATIC_DATA); + s.write_float_t(value.value); return; } - } - if (value.raw_data) { - if (!value.raw_data_binary) - return; - - value.raw_data_value_list_offset = (int32_t)s.get_position(); - - int32_t len = (int32_t)value.keys.size(); + uint32_t len = (uint32_t)value.keys.size(); kft3* keys = value.keys.data(); - value.raw_data_value_list_size = len * 4; - for (int32_t i = 0; i < len; i++) { - kft3* k = &keys[i]; - s.write_float_t(k->frame); - s.write_float_t(k->value); - s.write_float_t(k->tangent1); - s.write_float_t(k->tangent2); + + a3dc_key_header head = {}; + head.type = value.type; + head.ep_type_pre = value.ep_type_pre; + head.ep_type_post = value.ep_type_post; + head.max_frame = value.max_frame; + head.length = len; + s.write_data(head); + + switch (f16) { + case COMPRESS_F32F32F32F32: + default: + for (uint32_t i = 0; i < len; i++) { + kft3* k = &keys[i]; + s.write_float_t(k->frame); + s.write_float_t(k->value); + s.write_float_t(k->l_slope); + s.write_float_t(k->r_slope); + } + break; + case COMPRESS_I16F16F32F32: + for (uint32_t i = 0; i < len; i++) { + kft3* k = &keys[i]; + s.write_int16_t((int16_t)prj::roundf(k->frame)); + s.write_half_t(float_to_half(k->value)); + s.write_float_t(k->l_slope); + s.write_float_t(k->r_slope); + } + break; + case COMPRESS_I16F16F16F16: + for (uint32_t i = 0; i < len; i++) { + kft3* k = &keys[i]; + s.write_int16_t((int16_t)prj::roundf(k->frame)); + s.write_half_t(float_to_half(k->value)); + s.write_half_t(float_to_half(k->l_slope)); + s.write_half_t(float_to_half(k->r_slope)); + } + break; } - return; } - value.bin_offset = (int32_t)s.get_position(); - enum_or(value.flags, A3DA_KEY_BIN_OFFSET); + static void a3dc_read_a3da_model_transform(void* data, size_t size, + ModelTransform* value, COMPRESS_TYPE f16) { + if (!(value->flag & ModelTransform::BIN_OFFSET)) + return; - if (value.type == A3DA_KEY_NONE) { - s.write_int32_t(A3DA_KEY_NONE); - s.write_float_t(0.0f); - return; - } - else if (value.type == A3DA_KEY_STATIC) { - s.write_int32_t(A3DA_KEY_STATIC); - s.write_float_t(value.value); - return; + a3da_model_transform_header* head = (a3da_model_transform_header*)((size_t)data + value->bin_offset); + value->flag &= ~ModelTransform::BIN_OFFSET; + value->bin_offset = 0; + + value->scale.x.bin_offset = head->scale.x; + value->scale.x.flag |= Fcurve::BIN_OFFSET; + value->scale.y.bin_offset = head->scale.y; + value->scale.y.flag |= Fcurve::BIN_OFFSET; + value->scale.z.bin_offset = head->scale.z; + value->scale.z.flag |= Fcurve::BIN_OFFSET; + value->rotation.x.bin_offset = head->rotation.x; + value->rotation.x.flag |= Fcurve::BIN_OFFSET; + value->rotation.y.bin_offset = head->rotation.y; + value->rotation.y.flag |= Fcurve::BIN_OFFSET; + value->rotation.z.bin_offset = head->rotation.z; + value->rotation.z.flag |= Fcurve::BIN_OFFSET; + value->translation.x.bin_offset = head->translation.x; + value->translation.x.flag |= Fcurve::BIN_OFFSET; + value->translation.y.bin_offset = head->translation.y; + value->translation.y.flag |= Fcurve::BIN_OFFSET; + value->translation.z.bin_offset = head->translation.z; + value->translation.z.flag |= Fcurve::BIN_OFFSET; + value->visibility.bin_offset = head->visibility; + value->visibility.flag |= Fcurve::BIN_OFFSET; + + a3dc_read_a3da_vec3(data, size, &value->scale); + a3dc_read_a3da_vec3_f16(data, size, &value->rotation, f16); + a3dc_read_a3da_vec3(data, size, &value->translation); + a3dc_read_a3da_key(data, size, &value->visibility); } - uint32_t len = (uint32_t)value.keys.size(); - kft3* keys = value.keys.data(); + static void a3dc_write_a3da_model_transform(stream& s, + ModelTransform& value, COMPRESS_TYPE f16) { + a3dc_write_a3da_vec3(s, value.scale); + a3dc_write_a3da_vec3_f16(s, value.rotation, f16); + a3dc_write_a3da_vec3(s, value.translation); + a3dc_write_a3da_key(s, value.visibility); + } - a3dc_key_header head = {}; - head.type = value.type; - head.ep_type_pre = value.ep_type_pre; - head.ep_type_post = value.ep_type_post; - head.max_frame = value.max_frame; - head.length = len; - s.write_data(head); + static void a3dc_write_a3da_model_transform_offset(stream& s, + ModelTransform& value) { + value.bin_offset = (int32_t)s.get_position(); + value.flag |= ModelTransform::BIN_OFFSET; + s.write(0x30); + } - switch (f16) { - case A3DA_COMPRESS_F32F32F32F32: - default: - for (uint32_t i = 0; i < len; i++) { - kft3* k = &keys[i]; - s.write_float_t(k->frame); - s.write_float_t(k->value); - s.write_float_t(k->tangent1); - s.write_float_t(k->tangent2); - } - break; - case A3DA_COMPRESS_I16F16F32F32: - for (uint32_t i = 0; i < len; i++) { - kft3* k = &keys[i]; - s.write_int16_t((int16_t)prj::roundf(k->frame)); - s.write_half_t(float_to_half(k->value)); - s.write_float_t(k->tangent1); - s.write_float_t(k->tangent2); - } - break; - case A3DA_COMPRESS_I16F16F16F16: - for (uint32_t i = 0; i < len; i++) { - kft3* k = &keys[i]; - s.write_int16_t((int16_t)prj::roundf(k->frame)); - s.write_half_t(float_to_half(k->value)); - s.write_half_t(float_to_half(k->tangent1)); - s.write_half_t(float_to_half(k->tangent2)); - } - break; + static void a3dc_write_a3da_model_transform_offset_data(stream& s, + ModelTransform& value) { + s.position_push(value.bin_offset, SEEK_SET); + s.write_uint32_t(value.scale.x.bin_offset); + value.scale.x.flag &= ~Fcurve::BIN_OFFSET; + value.scale.x.bin_offset = 0; + s.write_uint32_t(value.scale.y.bin_offset); + value.scale.y.flag &= ~Fcurve::BIN_OFFSET; + value.scale.y.bin_offset = 0; + s.write_uint32_t(value.scale.z.bin_offset); + value.scale.z.flag &= ~Fcurve::BIN_OFFSET; + value.scale.z.bin_offset = 0; + s.write_uint32_t(value.rotation.x.bin_offset); + value.rotation.x.flag &= ~Fcurve::BIN_OFFSET; + value.rotation.x.bin_offset = 0; + s.write_uint32_t(value.rotation.y.bin_offset); + value.rotation.y.flag &= ~Fcurve::BIN_OFFSET; + value.rotation.y.bin_offset = 0; + s.write_uint32_t(value.rotation.z.bin_offset); + value.rotation.z.flag &= ~Fcurve::BIN_OFFSET; + value.rotation.z.bin_offset = 0; + s.write_uint32_t(value.translation.x.bin_offset); + value.translation.x.flag &= ~Fcurve::BIN_OFFSET; + value.translation.x.bin_offset = 0; + s.write_uint32_t(value.translation.y.bin_offset); + value.translation.y.flag &= ~Fcurve::BIN_OFFSET; + value.translation.y.bin_offset = 0; + s.write_uint32_t(value.translation.z.bin_offset); + value.translation.z.flag &= ~Fcurve::BIN_OFFSET; + value.translation.z.bin_offset = 0; + s.write_uint32_t(value.visibility.bin_offset); + value.visibility.flag &= ~Fcurve::BIN_OFFSET; + value.visibility.bin_offset = 0; + s.position_pop(); + } + + static void a3dc_read_a3da_rgba(void* data, size_t size, FcurveColor4f* value) { + if (value->has_r) + a3dc_read_a3da_key(data, size, &value->r); + if (value->has_g) + a3dc_read_a3da_key(data, size, &value->g); + if (value->has_b) + a3dc_read_a3da_key(data, size, &value->b); + if (value->has_a) + a3dc_read_a3da_key(data, size, &value->a); + } + + static void a3dc_write_a3da_rgba(stream& s, FcurveColor4f& value) { + if (value.has_r) + a3dc_write_a3da_key(s, value.r); + if (value.has_g) + a3dc_write_a3da_key(s, value.g); + if (value.has_b) + a3dc_write_a3da_key(s, value.b); + if (value.has_a) + a3dc_write_a3da_key(s, value.a); + } + + static void a3dc_read_a3da_vec3(void* data, size_t size, Fcurve3f* value) { + a3dc_read_a3da_key(data, size, &value->x); + a3dc_read_a3da_key(data, size, &value->y); + a3dc_read_a3da_key(data, size, &value->z); + } + + static void a3dc_write_a3da_vec3(stream& s, Fcurve3f& value) { + a3dc_write_a3da_key(s, value.x); + a3dc_write_a3da_key(s, value.y); + a3dc_write_a3da_key(s, value.z); + } + + static void a3dc_read_a3da_vec3_f16(void* data, size_t size, Fcurve3f* value, COMPRESS_TYPE f16) { + a3dc_read_a3da_key_f16(data, size, &value->x, f16); + a3dc_read_a3da_key_f16(data, size, &value->y, f16); + a3dc_read_a3da_key_f16(data, size, &value->z, f16); + } + + static void a3dc_write_a3da_vec3_f16(stream& s, Fcurve3f& value, COMPRESS_TYPE f16) { + a3dc_write_a3da_key_f16(s, value.x, f16); + a3dc_write_a3da_key_f16(s, value.y, f16); + a3dc_write_a3da_key_f16(s, value.z, f16); + } + + inline static void a3da_key_make_raw_data_binary(Fcurve* value) { + value->raw_data = true; + value->raw_data_binary = true; + } + + inline static void a3da_model_transform_make_raw_data_binary(ModelTransform* value) { + a3da_vec3_make_raw_data_binary(&value->rotation); + a3da_vec3_make_raw_data_binary(&value->scale); + a3da_vec3_make_raw_data_binary(&value->translation); + a3da_key_make_raw_data_binary(&value->visibility); + } + + inline static void a3da_rgba_make_raw_data_binary(FcurveColor4f* value) { + if (value->has_r) + a3da_key_make_raw_data_binary(&value->r); + if (value->has_g) + a3da_key_make_raw_data_binary(&value->g); + if (value->has_b) + a3da_key_make_raw_data_binary(&value->b); + if (value->has_a) + a3da_key_make_raw_data_binary(&value->a); + } + + inline static void a3da_vec3_make_raw_data_binary(Fcurve3f* value) { + a3da_key_make_raw_data_binary(&value->x); + a3da_key_make_raw_data_binary(&value->y); + a3da_key_make_raw_data_binary(&value->z); } } - -static void a3dc_read_a3da_model_transform(void* data, size_t size, - a3da_model_transform* value, a3da_compress_f16 f16) { - if (!(value->flags & A3DA_MODEL_TRANSFORM_BIN_OFFSET)) - return; - - a3da_model_transform_header* head = (a3da_model_transform_header*)((size_t)data + value->bin_offset); - enum_and(value->flags, ~A3DA_MODEL_TRANSFORM_BIN_OFFSET); - value->bin_offset = 0; - - value->scale.x.bin_offset = head->scale.x; - enum_or(value->scale.x.flags, A3DA_KEY_BIN_OFFSET); - value->scale.y.bin_offset = head->scale.y; - enum_or(value->scale.y.flags, A3DA_KEY_BIN_OFFSET); - value->scale.z.bin_offset = head->scale.z; - enum_or(value->scale.z.flags, A3DA_KEY_BIN_OFFSET); - value->rotation.x.bin_offset = head->rotation.x; - enum_or(value->rotation.x.flags, A3DA_KEY_BIN_OFFSET); - value->rotation.y.bin_offset = head->rotation.y; - enum_or(value->rotation.y.flags, A3DA_KEY_BIN_OFFSET); - value->rotation.z.bin_offset = head->rotation.z; - enum_or(value->rotation.z.flags, A3DA_KEY_BIN_OFFSET); - value->translation.x.bin_offset = head->translation.x; - enum_or(value->translation.x.flags, A3DA_KEY_BIN_OFFSET); - value->translation.y.bin_offset = head->translation.y; - enum_or(value->translation.y.flags, A3DA_KEY_BIN_OFFSET); - value->translation.z.bin_offset = head->translation.z; - enum_or(value->translation.z.flags, A3DA_KEY_BIN_OFFSET); - value->visibility.bin_offset = head->visibility; - enum_or(value->visibility.flags, A3DA_KEY_BIN_OFFSET); - - a3dc_read_a3da_vec3(data, size, &value->scale); - a3dc_read_a3da_vec3_f16(data, size, &value->rotation, f16); - a3dc_read_a3da_vec3(data, size, &value->translation); - a3dc_read_a3da_key(data, size, &value->visibility); -} - -static void a3dc_write_a3da_model_transform(stream& s, - a3da_model_transform& value, a3da_compress_f16 f16) { - a3dc_write_a3da_vec3(s, value.scale); - a3dc_write_a3da_vec3_f16(s, value.rotation, f16); - a3dc_write_a3da_vec3(s, value.translation); - a3dc_write_a3da_key(s, value.visibility); -} - -static void a3dc_write_a3da_model_transform_offset(stream& s, - a3da_model_transform& value) { - value.bin_offset = (int32_t)s.get_position(); - enum_or(value.flags, A3DA_MODEL_TRANSFORM_BIN_OFFSET); - s.write(0x30); -} - -static void a3dc_write_a3da_model_transform_offset_data(stream& s, - a3da_model_transform& value) { - s.position_push(value.bin_offset, SEEK_SET); - s.write_uint32_t(value.scale.x.bin_offset); - enum_and(value.scale.x.flags, ~A3DA_KEY_BIN_OFFSET); - value.scale.x.bin_offset = 0; - s.write_uint32_t(value.scale.y.bin_offset); - enum_and(value.scale.y.flags, ~A3DA_KEY_BIN_OFFSET); - value.scale.y.bin_offset = 0; - s.write_uint32_t(value.scale.z.bin_offset); - enum_and(value.scale.z.flags, ~A3DA_KEY_BIN_OFFSET); - value.scale.z.bin_offset = 0; - s.write_uint32_t(value.rotation.x.bin_offset); - enum_and(value.rotation.x.flags, ~A3DA_KEY_BIN_OFFSET); - value.rotation.x.bin_offset = 0; - s.write_uint32_t(value.rotation.y.bin_offset); - enum_and(value.rotation.y.flags, ~A3DA_KEY_BIN_OFFSET); - value.rotation.y.bin_offset = 0; - s.write_uint32_t(value.rotation.z.bin_offset); - enum_and(value.rotation.z.flags, ~A3DA_KEY_BIN_OFFSET); - value.rotation.z.bin_offset = 0; - s.write_uint32_t(value.translation.x.bin_offset); - enum_and(value.translation.x.flags, ~A3DA_KEY_BIN_OFFSET); - value.translation.x.bin_offset = 0; - s.write_uint32_t(value.translation.y.bin_offset); - enum_and(value.translation.y.flags, ~A3DA_KEY_BIN_OFFSET); - value.translation.y.bin_offset = 0; - s.write_uint32_t(value.translation.z.bin_offset); - enum_and(value.translation.z.flags, ~A3DA_KEY_BIN_OFFSET); - value.translation.z.bin_offset = 0; - s.write_uint32_t(value.visibility.bin_offset); - enum_and(value.visibility.flags, ~A3DA_KEY_BIN_OFFSET); - value.visibility.bin_offset = 0; - s.position_pop(); -} - -static void a3dc_read_a3da_rgba(void* data, size_t size, a3da_rgba* value) { - if (!value->flags) - return; - - if (value->flags & A3DA_RGBA_R) - a3dc_read_a3da_key(data, size, &value->r); - if (value->flags & A3DA_RGBA_G) - a3dc_read_a3da_key(data, size, &value->g); - if (value->flags & A3DA_RGBA_B) - a3dc_read_a3da_key(data, size, &value->b); - if (value->flags & A3DA_RGBA_A) - a3dc_read_a3da_key(data, size, &value->a); -} - -static void a3dc_write_a3da_rgba(stream& s, a3da_rgba& value) { - if (!value.flags) - return; - - if (value.flags & A3DA_RGBA_R) - a3dc_write_a3da_key(s, value.r); - if (value.flags & A3DA_RGBA_G) - a3dc_write_a3da_key(s, value.g); - if (value.flags & A3DA_RGBA_B) - a3dc_write_a3da_key(s, value.b); - if (value.flags & A3DA_RGBA_A) - a3dc_write_a3da_key(s, value.a); -} - -static void a3dc_read_a3da_vec3(void* data, size_t size, a3da_vec3* value) { - a3dc_read_a3da_key(data, size, &value->x); - a3dc_read_a3da_key(data, size, &value->y); - a3dc_read_a3da_key(data, size, &value->z); -} - -static void a3dc_write_a3da_vec3(stream& s, a3da_vec3& value) { - a3dc_write_a3da_key(s, value.x); - a3dc_write_a3da_key(s, value.y); - a3dc_write_a3da_key(s, value.z); -} - -static void a3dc_read_a3da_vec3_f16(void* data, size_t size, a3da_vec3* value, a3da_compress_f16 f16) { - a3dc_read_a3da_key_f16(data, size, &value->x, f16); - a3dc_read_a3da_key_f16(data, size, &value->y, f16); - a3dc_read_a3da_key_f16(data, size, &value->z, f16); -} - -static void a3dc_write_a3da_vec3_f16(stream& s, a3da_vec3& value, a3da_compress_f16 f16) { - a3dc_write_a3da_key_f16(s, value.x, f16); - a3dc_write_a3da_key_f16(s, value.y, f16); - a3dc_write_a3da_key_f16(s, value.z, f16); -} - -inline static void a3da_key_make_raw_data_binary(a3da_key* value) { - value->raw_data = true; - value->raw_data_binary = true; -} - -inline static void a3da_model_transform_make_raw_data_binary(a3da_model_transform* value) { - a3da_vec3_make_raw_data_binary(&value->rotation); - a3da_vec3_make_raw_data_binary(&value->scale); - a3da_vec3_make_raw_data_binary(&value->translation); - a3da_key_make_raw_data_binary(&value->visibility); -} - -inline static void a3da_rgba_make_raw_data_binary(a3da_rgba* value) { - if (value->flags & A3DA_RGBA_R) - a3da_key_make_raw_data_binary(&value->r); - - if (value->flags & A3DA_RGBA_G) - a3da_key_make_raw_data_binary(&value->g); - - if (value->flags & A3DA_RGBA_B) - a3da_key_make_raw_data_binary(&value->b); - - if (value->flags & A3DA_RGBA_A) - a3da_key_make_raw_data_binary(&value->a); -} - -inline static void a3da_vec3_make_raw_data_binary(a3da_vec3* value) { - a3da_key_make_raw_data_binary(&value->x); - a3da_key_make_raw_data_binary(&value->y); - a3da_key_make_raw_data_binary(&value->z); -} diff --git a/src/KKdLib/a3da.hpp b/src/KKdLib/a3da.hpp index f8bb431c..02322ebb 100644 --- a/src/KKdLib/a3da.hpp +++ b/src/KKdLib/a3da.hpp @@ -13,511 +13,534 @@ #include "kf.hpp" #include "vec.hpp" -enum a3da_ambient_flags { - A3DA_AMBIENT_LIGHT_DIFFUSE = 0x01, - A3DA_AMBIENT_RIM_LIGHT_DIFFUSE = 0x02, -}; - -enum a3da_camera_auxiliary_flags { - A3DA_CAMERA_AUXILIARY_AUTO_EXPOSURE = 0x01, - A3DA_CAMERA_AUXILIARY_EXPOSURE = 0x02, - A3DA_CAMERA_AUXILIARY_EXPOSURE_RATE = 0x04, - A3DA_CAMERA_AUXILIARY_GAMMA = 0x08, - A3DA_CAMERA_AUXILIARY_GAMMA_RATE = 0x10, - A3DA_CAMERA_AUXILIARY_SATURATE = 0x20, -}; - -enum a3da_camera_root_view_point_flags { - A3DA_CAMERA_ROOT_VIEW_POINT_FOV = 0x01, - A3DA_CAMERA_ROOT_VIEW_POINT_ROLL = 0x02, -}; - -enum a3da_compress_f16 { - A3DA_COMPRESS_F32F32F32F32 = 0, - A3DA_COMPRESS_I16F16F32F32 = 1, - A3DA_COMPRESS_I16F16F16F16 = 2, -}; - -enum a3da_ep_type { - A3DA_EP_NONE = 0, - A3DA_EP_LINEAR = 1, - A3DA_EP_CYCLE = 2, - A3DA_EP_CYCLE_OFFSET = 3, -}; // Pre/Post Infinity - -enum a3da_event_type { - A3DA_EVENT_MISC = 0x00, - A3DA_EVENT_FILT = 0x01, - A3DA_EVENT_FX = 0x02, - A3DA_EVENT_SND = 0x03, - A3DA_EVENT_MOT = 0x04, - A3DA_EVENT_A2D = 0x05, -}; - -enum a3da_fog_flags { - A3DA_FOG_COLOR = 0x01, - A3DA_FOG_DENSITY = 0x02, - A3DA_FOG_END = 0x04, - A3DA_FOG_START = 0x08, -}; - -enum a3da_format { - A3DA_FORMAT_DT = 0, - A3DA_FORMAT_F, - A3DA_FORMAT_AFT, - A3DA_FORMAT_F2, - A3DA_FORMAT_MGF, - A3DA_FORMAT_X, - A3DA_FORMAT_XHD, - A3DA_FORMAT_AFT_X_PACK, -}; - -enum a3da_key_flags { - A3DA_KEY_BIN_OFFSET = 0x01, -}; - -enum a3da_key_type { - A3DA_KEY_NONE = 0, - A3DA_KEY_STATIC = 1, - A3DA_KEY_LINEAR = 2, - A3DA_KEY_HERMITE = 3, - A3DA_KEY_HOLD = 4, -}; - -enum a3da_light_flags { - A3DA_LIGHT_AMBIENT = 0x0001, - A3DA_LIGHT_CONE_ANGLE = 0x0002, - A3DA_LIGHT_CONSTANT = 0x0004, - A3DA_LIGHT_DIFFUSE = 0x0008, - A3DA_LIGHT_DROP_OFF = 0x0010, - A3DA_LIGHT_FAR = 0x0020, - A3DA_LIGHT_INTENSITY = 0x0040, - A3DA_LIGHT_LINEAR = 0x0080, - A3DA_LIGHT_POSITION = 0x0100, - A3DA_LIGHT_QUADRATIC = 0x0200, - A3DA_LIGHT_SPECULAR = 0x0400, - A3DA_LIGHT_SPOT_DIRECTION = 0x0800, - A3DA_LIGHT_TONE_CURVE = 0x1000, -}; - -enum a3da_material_list_flags { - A3DA_MATERIAL_LIST_BLEND_COLOR = 0x01, - A3DA_MATERIAL_LIST_GLOW_INTENSITY = 0x02, - A3DA_MATERIAL_LIST_EMISSION = 0x04, -}; - -enum a3da_model_transform_flags { - A3DA_MODEL_TRANSFORM_BIN_OFFSET = 0x01, -}; - -enum a3da_object_node_flags { - A3DA_OBJECT_NODE_JOINT_ORIENT = 0x01, -}; - -enum a3da_object_texture_transform_flags { - A3DA_OBJECT_TEXTURE_TRANSFORM_COVERAGE_U = 0x001, - A3DA_OBJECT_TEXTURE_TRANSFORM_COVERAGE_V = 0x002, - A3DA_OBJECT_TEXTURE_TRANSFORM_OFFSET_U = 0x004, - A3DA_OBJECT_TEXTURE_TRANSFORM_OFFSET_V = 0x008, - A3DA_OBJECT_TEXTURE_TRANSFORM_REPEAT_U = 0x010, - A3DA_OBJECT_TEXTURE_TRANSFORM_REPEAT_V = 0x020, - A3DA_OBJECT_TEXTURE_TRANSFORM_ROTATE = 0x040, - A3DA_OBJECT_TEXTURE_TRANSFORM_ROTATE_FRAME = 0x080, - A3DA_OBJECT_TEXTURE_TRANSFORM_TRANSLATE_FRAME_U = 0x100, - A3DA_OBJECT_TEXTURE_TRANSFORM_TRANSLATE_FRAME_V = 0x200, -}; - -enum a3da_play_control_flags { - A3DA_PLAY_CONTROL_DIV = 0x01, - A3DA_PLAY_CONTROL_OFFSET = 0x02, -}; - -enum a3da_post_process_flags { - A3DA_POST_PROCESS_INTENSITY = 0x01, - A3DA_POST_PROCESS_LENS_FLARE = 0x02, - A3DA_POST_PROCESS_LENS_GHOST = 0x04, - A3DA_POST_PROCESS_LENS_SHAFT = 0x08, - A3DA_POST_PROCESS_RADIUS = 0x10, - A3DA_POST_PROCESS_SCENE_FADE = 0x20, -}; - -enum a3da_rgba_flags { - A3DA_RGBA_R = 0x01, - A3DA_RGBA_G = 0x02, - A3DA_RGBA_B = 0x04, - A3DA_RGBA_A = 0x08, -}; - -struct a3da_ambient; -struct a3da_camera_auxiliary; -struct a3da_camera_root; -struct a3da_camera_root_view_point; -struct a3da_chara; -struct a3da_curve; -struct a3da_dof; -struct a3da_event; -struct a3da_fog; -struct a3da_key; -struct a3da_light; -struct a3da_m_object_hrc; -struct a3da_material_list; -struct a3da_model_transform; -struct a3da_object; -struct a3da_object_hrc; -struct a3da_object_instance; -struct a3da_object_node; -struct a3da_object_texture_pattern; -struct a3da_object_texture_transform; -struct a3da_play_control; -struct a3da_point; -struct a3da_post_process; -struct a3da_rgba; -struct a3da_vec3; - -struct a3da_key { - a3da_key_flags flags; - int32_t bin_offset; - a3da_key_type type; - a3da_ep_type ep_type_pre; - a3da_ep_type ep_type_post; - std::vector keys; - float_t max_frame; - bool raw_data; - bool raw_data_binary; - int32_t raw_data_value_list_size; - int32_t raw_data_value_list_offset; - float_t value; - - a3da_key(); - ~a3da_key(); - - a3da_key& operator=(const a3da_key& k); -}; - -struct a3da_rgba { - a3da_rgba_flags flags; - a3da_key r; - a3da_key g; - a3da_key b; - a3da_key a; - - a3da_rgba(); - ~a3da_rgba(); -}; - -struct a3da_vec3 { - a3da_key x; - a3da_key y; - a3da_key z; - - a3da_vec3(); - ~a3da_vec3(); -}; - -struct a3da_model_transform { - a3da_model_transform_flags flags; - int32_t bin_offset; - a3da_vec3 rotation; - a3da_vec3 scale; - a3da_vec3 translation; - a3da_key visibility; - - a3da_model_transform(); - ~a3da_model_transform(); -}; - -struct a3da_ambient { - a3da_ambient_flags flags; - a3da_rgba light_diffuse; - std::string name; - a3da_rgba rim_light_diffuse; - - a3da_ambient(); - ~a3da_ambient(); -}; - -struct a3da_camera_auxiliary { - a3da_camera_auxiliary_flags flags; - a3da_key auto_exposure; - a3da_key exposure; - a3da_key exposure_rate; - a3da_key gamma; - a3da_key gamma_rate; - a3da_key saturate; - - a3da_camera_auxiliary(); - ~a3da_camera_auxiliary(); -}; - -struct a3da_camera_root_view_point { - a3da_camera_root_view_point_flags flags; - float_t aspect; - float_t camera_aperture_h; - float_t camera_aperture_w; - a3da_key focal_length; - a3da_key fov; - bool fov_is_horizontal; - a3da_model_transform model_transform; - a3da_key roll; - - a3da_camera_root_view_point(); - ~a3da_camera_root_view_point(); -}; - -struct a3da_camera_root { - a3da_model_transform interest; - a3da_model_transform model_transform; - a3da_camera_root_view_point view_point; - - a3da_camera_root(); - ~a3da_camera_root(); -}; - -struct a3da_chara { - a3da_model_transform model_transform; - std::string name; - - a3da_chara(); - ~a3da_chara(); -}; - -struct a3da_curve { - a3da_key curve; - std::string name; - - a3da_curve(); - ~a3da_curve(); -}; - -struct a3da_dof { - bool has_dof; - a3da_model_transform model_transform; - - a3da_dof(); - ~a3da_dof(); -}; - -struct a3da_event { - float_t begin; - float_t clip_begin; - float_t clip_end; - float_t end; - std::string name; - std::string param1; - std::string ref; - float_t time_ref_scale; - a3da_event_type type; - - a3da_event(); - ~a3da_event(); -}; - -struct a3da_fog { - a3da_fog_flags flags; - a3da_rgba color; - a3da_key density; - a3da_key end; - fog_id id; - a3da_key start; - - a3da_fog(); - ~a3da_fog(); -}; - -struct a3da_light { - a3da_light_flags flags; - a3da_rgba ambient; - a3da_key cone_angle; - a3da_key constant; - a3da_rgba diffuse; - a3da_key drop_off; - a3da_key _far; - light_id id; - a3da_key intensity; - a3da_key linear; - a3da_model_transform position; - a3da_key quadratic; - a3da_rgba specular; - a3da_model_transform spot_direction; - a3da_rgba tone_curve; - std::string type; - - a3da_light(); - ~a3da_light(); -}; - -struct a3da_m_object_hrc { - std::vector instance; - a3da_model_transform model_transform; - std::string name; - std::vector node; - - a3da_m_object_hrc(); - ~a3da_m_object_hrc(); -}; - -struct a3da_material_list { - a3da_material_list_flags flags; - a3da_rgba blend_color; - a3da_key glow_intensity; - a3da_rgba emission; - std::string name; - - a3da_material_list(); - ~a3da_material_list(); -}; - -struct a3da_object { - a3da_model_transform model_transform; - std::string morph; - float_t morph_offset; - std::string name; - std::string parent_name; - std::string parent_node; - std::string pattern; - float_t pattern_offset; - std::vector texture_pattern; - std::vector texture_transform; - std::string uid_name; - - a3da_object(); - ~a3da_object(); -}; - -struct a3da_object_hrc { - std::string name; - std::vector node; - std::string parent_name; - std::string parent_node; - bool shadow; - std::string uid_name; - - a3da_object_hrc(); - ~a3da_object_hrc(); -}; - -struct a3da_object_instance { - a3da_model_transform model_transform; - std::string name; - bool shadow; - std::string uid_name; - - a3da_object_instance(); - ~a3da_object_instance(); -}; - -struct a3da_object_node { - a3da_object_node_flags flags; - vec3 joint_orient; - a3da_model_transform model_transform; - std::string name; - int32_t parent; - - a3da_object_node(); - ~a3da_object_node(); -}; - -struct a3da_object_texture_pattern { - std::string name; - std::string pattern; - float_t pattern_offset; - - a3da_object_texture_pattern(); - ~a3da_object_texture_pattern(); -}; - -struct a3da_object_texture_transform { - a3da_object_texture_transform_flags flags; - a3da_key coverage_u; - a3da_key coverage_v; - std::string name; - a3da_key offset_u; - a3da_key offset_v; - a3da_key repeat_u; - a3da_key repeat_v; - a3da_key rotate; - a3da_key rotate_frame; - a3da_key translate_frame_u; - a3da_key translate_frame_v; - - a3da_object_texture_transform(); - ~a3da_object_texture_transform(); -}; - -struct a3da_play_control { - a3da_play_control_flags flags; - float_t begin; - int32_t div; - float_t fps; - float_t offset; - float_t size; - - a3da_play_control(); - ~a3da_play_control(); -}; - -struct a3da_point { - a3da_model_transform model_transform; - std::string name; - - a3da_point(); - ~a3da_point(); -}; - -struct a3da_post_process { - a3da_post_process_flags flags; - a3da_rgba intensity; - a3da_key lens_flare; - a3da_key lens_ghost; - a3da_key lens_shaft; - a3da_rgba radius; - a3da_rgba scene_fade; - - a3da_post_process(); - ~a3da_post_process(); -}; - -struct a3da { - bool ready; - bool compressed; - a3da_format format; - - a3da_compress_f16 _compress_f16; - std::string _file_name; - std::string _property_version; - std::string _converter_version; - - std::vector ambient; - std::vector auth_2d; - a3da_camera_auxiliary camera_auxiliary; - std::vector camera_root; - std::vector chara; - std::vector curve; - a3da_dof dof; - std::vector event; - std::vector fog; - std::vector light; - std::vector m_object_hrc; - std::vector m_object_hrc_list; - std::vector material_list; - std::vector motion; - std::vector object; - std::vector object_hrc; - std::vector object_hrc_list; - std::vector object_list; - a3da_play_control play_control; - std::vector point; - a3da_post_process post_process; - - a3da(); - ~a3da(); - - void read(const char* path); - void read(const wchar_t* path); - void read(const void* data, size_t size); - void write(const char* path); - void write(const wchar_t* path); - void write(void** data, size_t* size); - - static bool load_file(void* data, const char* dir, const char* file, uint32_t hash); -}; +namespace a3d { + enum COMPRESS_TYPE { + COMPRESS_F32F32F32F32 = 0, + COMPRESS_I16F16F32F32, + COMPRESS_I16F16F16F16, + }; + + enum EVENT_TYPE { + EVENT_MISC = 0, + EVENT_FLT, + EVENT_FX, + EVENT_SND, + EVENT_MOT, + EVENT_A2D, + }; + + // Pre/Post Infinity + enum EP_TYPE { + EP_TYPE_CONSTANT = 0, + EP_TYPE_LINEAR, + EP_TYPE_CYCLE, + EP_TYPE_CYCLE_WITH_OFFSET, + }; + + enum FORMAT { + FORMAT_DT = 0, + FORMAT_F, + FORMAT_AFT, + FORMAT_F2, + FORMAT_MGF, + FORMAT_X, + FORMAT_XHD, + FORMAT_AFT_X_PACK, + }; + + enum FC_TYPE { + FC_TYPE_STATIC_0 = 0, + FC_TYPE_STATIC_DATA, + FC_TYPE_LINEAR, + FC_TYPE_HERMITE, + FC_TYPE_NO_INTERPOLATION, + }; + + struct Ambient; + struct CameraAuxiliary; + struct CameraInterest; + struct CameraRoot; + struct CameraViewPoint; + struct Chara; + struct Curve; + struct Dof; + struct Event; + struct Fcurve; + struct Fcurve3f; + struct FcurveColor4f; + struct Fog; + struct Light; + struct MObjectHrc; + struct MaterialList; + struct ModelTransform; + struct Object; + struct ObjectHrc; + struct ObjectInstance; + struct ObjectNode; + struct Texture; + struct TextureTransform; + struct PlayControl; + struct Point; + struct PostProcess; + + struct Fcurve { + enum { + BIN_OFFSET = 0x01, + }; + + uint32_t flag; + int32_t bin_offset; + FC_TYPE type; + EP_TYPE ep_type_pre; + EP_TYPE ep_type_post; + std::vector keys; + float_t max_frame; + bool raw_data; + bool raw_data_binary; + int32_t raw_data_value_list_size; + int32_t raw_data_value_list_offset; + float_t value; + + Fcurve(); + ~Fcurve(); + + Fcurve& operator=(const Fcurve& other); + }; + + struct Fcurve3f { + Fcurve x; + Fcurve y; + Fcurve z; + + Fcurve3f(); + ~Fcurve3f(); + }; + + struct FcurveColor4f { + Fcurve r; + Fcurve g; + Fcurve b; + Fcurve a; + bool has_r; + bool has_g; + bool has_b; + bool has_a; + + FcurveColor4f(); + ~FcurveColor4f(); + }; + + struct ModelTransform { + enum { + BIN_OFFSET = 0x01, + }; + + uint32_t flag; + int32_t bin_offset; + Fcurve3f rotation; + Fcurve3f scale; + Fcurve3f translation; + Fcurve visibility; + + ModelTransform(); + ~ModelTransform(); + }; + + // MGF + struct Ambient { + enum { + FLAG_LIGHT_DIFFUSE = 0x01, + FLAG_RIM_LIGHT_DIFFUSE = 0x02, + }; + + uint32_t flag; + FcurveColor4f light_diffuse; + std::string name; + FcurveColor4f rim_light_diffuse; + + Ambient(); + ~Ambient(); + }; + + struct Auth2d { + std::string name; + + Auth2d(); + ~Auth2d(); + }; + + struct CameraAuxiliary { + enum { + FLAG_EXPOSURE = 0x01, + FLAG_EXPOSURE_RATE = 0x02, // F/F2/X + FLAG_GAMMA = 0x04, + FLAG_GAMMA_RATE = 0x08, // F/F2/X + FLAG_SATURATE = 0x10, + FLAG_AUTO_EXPOSURE = 0x20, + }; + + uint32_t flag; + Fcurve auto_exposure; + Fcurve exposure; + Fcurve exposure_rate; // F/F2/X + Fcurve gamma; + Fcurve gamma_rate; // F/F2/X + Fcurve saturate; + + CameraAuxiliary(); + ~CameraAuxiliary(); + }; + + struct CameraInterest { + ModelTransform model_transform; + + CameraInterest(); + ~CameraInterest(); + }; + + struct CameraViewPoint { + ModelTransform model_transform; + Fcurve roll; + bool has_fov; + bool fov_is_horizontal; + Fcurve fov; + float_t aspect; + Fcurve focal_length; + float_t camera_aperture_w; + float_t camera_aperture_h; + + CameraViewPoint(); + ~CameraViewPoint(); + }; + + struct CameraRoot { + ModelTransform model_transform; + CameraInterest interest; + CameraViewPoint view_point; + + CameraRoot(); + ~CameraRoot(); + }; + + struct Chara { + ModelTransform model_transform; + std::string name; + + Chara(); + ~Chara(); + }; + + struct Curve { + Fcurve fcurve; + std::string name; + + Curve(); + ~Curve(); + }; + + struct Dof { + bool has_dof; + ModelTransform model_transform; + + Dof(); + ~Dof(); + }; + + struct Event { + float_t begin; + float_t clip_begin; + float_t clip_end; + float_t end; + std::string name; + std::string param1; + std::string ref; + float_t time_ref_scale; + EVENT_TYPE type; + + Event(); + ~Event(); + }; + + struct Fog { + enum { + FLAG_DENSITY = 0x01, + FLAG_START = 0x02, + FLAG_END = 0x04, + FLAG_COLOR = 0x08, + }; + + uint32_t flag; + int32_t id; + std::string name; + Fcurve density; + Fcurve start; + Fcurve end; + FcurveColor4f color; + + Fog(); + ~Fog(); + }; + + struct Light { + enum { + FLAG_AMBIENT = 0x001, + FLAG_DIFFUSE = 0x002, + FLAG_SPECULAR = 0x004, + FLAG_TONE_CURVE = 0x008, + + // XHD + FLAG_CONSTANT = 0x010, + FLAG_INTENSITY = 0x020, + FLAG_FAR = 0x040, + FLAG_LINEAR = 0x080, + FLAG_QUADRATIC = 0x100, + FLAG_DROP_OFF = 0x200, + FLAG_CONE_ANGLE = 0x400, + }; + + uint32_t flag; + int32_t id; + std::string name; + std::string type; + + ModelTransform position; + ModelTransform spot_direction; + FcurveColor4f ambient; + FcurveColor4f diffuse; + FcurveColor4f specular; + FcurveColor4f tone_curve; + + // XHD + Fcurve constant; + Fcurve intensity; + Fcurve far_; // MS... + Fcurve linear; + Fcurve quadratic; + Fcurve drop_off; + Fcurve cone_angle; + + Light(); + ~Light(); + }; + + struct MObjectHrc { + std::vector instance; + ModelTransform model_transform; + std::string name; + std::vector node; + + MObjectHrc(); + ~MObjectHrc(); + }; + + // X + struct MaterialList { + enum { + FLAG_EMISSION = 0x01, + FLAG_BLEND_COLOR = 0x02, + FLAG_GLOW_INTENSITY = 0x04, + }; + + uint32_t flag; + std::string name; + FcurveColor4f emission; + FcurveColor4f blend_color; + Fcurve glow_intensity; + + MaterialList(); + ~MaterialList(); + }; + + struct Motion { + std::string name; + + Motion(); + ~Motion(); + }; + + struct Object { + std::string name; + std::string uid_name; + ModelTransform model_transform; + std::string morph; + float_t morph_offset; + std::string pattern; + float_t pattern_offset; + std::string parent_name; + std::string parent_node; + std::vector texture; + std::vector texture_transform; + + Object(); + ~Object(); + }; + + struct ObjectHrc { + std::string name; + std::vector node; + std::string parent_name; + std::string parent_node; + bool shadow; + std::string uid_name; + + ObjectHrc(); + ~ObjectHrc(); + }; + + struct ObjectInstance { + std::string name; + std::string uid_name; + bool shadow; + ModelTransform model_transform; + + ObjectInstance(); + ~ObjectInstance(); + }; + + struct ObjectNode { + enum { + FLAG_JOINT_ORIENT = 0x01, + }; + + uint32_t flag; + std::string name; + int32_t parent; + ModelTransform model_transform; + vec3 joint_orient; + + ObjectNode(); + ~ObjectNode(); + }; + + struct PlayControl { + enum { + FLAG_DIV = 0x01, // F2/X + FLAG_OFFSET = 0x02, + }; + + uint32_t flag; + float_t begin; + int32_t div; // F2/X + float_t fps; + float_t offset; // F2/X/XHD + float_t size; + + PlayControl(); + ~PlayControl(); + }; + + struct Point { + ModelTransform model_transform; + std::string name; + + Point(); + ~Point(); + }; + + struct PostProcess { + enum { + FLAG_LENS_FLARE = 0x01, + FLAG_LENS_SHAFT = 0x02, + FLAG_LENS_GHOST = 0x04, + FLAG_RADIUS = 0x08, + FLAG_INTENSITY = 0x10, + FLAG_SCENE_FADE = 0x20, + }; + + uint32_t flag; + FcurveColor4f intensity; + Fcurve lens_flare; + Fcurve lens_shaft; + Fcurve lens_ghost; + FcurveColor4f radius; + FcurveColor4f scene_fade; + + PostProcess(); + ~PostProcess(); + }; + + struct Texture { + std::string name; + std::string pattern; + float_t pattern_offset; + + Texture(); + ~Texture(); + }; + + struct TextureTransform { + enum { + FLAG_COVERAGE_U = 0x001, + FLAG_COVERAGE_V = 0x002, + FLAG_REPEAT_U = 0x004, + FLAG_REPEAT_V = 0x008, + FLAG_TRANSLATE_FRAME_U = 0x010, + FLAG_TRANSLATE_FRAME_V = 0x020, + FLAG_OFFSET_U = 0x040, + FLAG_OFFSET_V = 0x080, + FLAG_ROTATE_FRAME = 0x100, + FLAG_ROTATE = 0x200, + }; + + uint32_t flag; + std::string name; + Fcurve coverage_u; + Fcurve coverage_v; + Fcurve repeat_u; + Fcurve repeat_v; + Fcurve translate_frame_u; + Fcurve translate_frame_v; + Fcurve offset_u; + Fcurve offset_v; + Fcurve rotate_frame; + Fcurve rotate; + + TextureTransform(); + ~TextureTransform(); + }; + + struct Scene { + bool ready; + bool compressed; + FORMAT format; + + COMPRESS_TYPE _compress_f16; + std::string _file_name; + std::string _property_version; + std::string _converter_version; + + std::vector ambient; // MGF + std::vector auth_2d; + CameraAuxiliary camera_auxiliary; + std::vector camera_root; + std::vector chara; + std::vector curve; + Dof dof; + std::vector event; + std::vector fog; + std::vector light; + std::vector m_object_hrc; + std::vector m_object_hrc_list; + std::vector material_list; // X + std::vector motion; + std::vector object; + std::vector object_list; + std::vector object_hrc; + std::vector object_hrc_list; + PlayControl play_control; + std::vector point; + PostProcess post_process; + + Scene(); + ~Scene(); + + void read(const char* path); + void read(const wchar_t* path); + void read(const void* data, size_t size); + void write(const char* path); + void write(const wchar_t* path); + void write(void** data, size_t* size); + + static bool load_file(void* data, const char* dir, const char* file, uint32_t hash); + }; +} diff --git a/src/KKdLib/database/auth_3d.cpp b/src/KKdLib/database/auth_3d.cpp index 34286aa1..7c92af88 100644 --- a/src/KKdLib/database/auth_3d.cpp +++ b/src/KKdLib/database/auth_3d.cpp @@ -23,7 +23,7 @@ static void auth_3d_database_file_write_inner(auth_3d_database_file* auth_3d_db_ static void auth_3d_database_file_read_text(auth_3d_database_file* auth_3d_db_file, void* data, size_t size); static void auth_3d_database_file_write_text(auth_3d_database_file* auth_3d_db_file, void** data, size_t* size); -auth_3d_database_uid::auth_3d_database_uid() : enabled(), org_uid(), size() { +auth_3d_database_uid::auth_3d_database_uid() : enabled(), frame_size(), org_uid() { category_hash = hash_murmurhash_empty; name_hash = hash_murmurhash_empty; } @@ -32,7 +32,7 @@ auth_3d_database_uid::~auth_3d_database_uid() { } -auth_3d_database_uid_file::auth_3d_database_uid_file() : flags(), org_uid(), size() { +auth_3d_database_uid_file::auth_3d_database_uid_file() : flag(), frame_size(), org_uid() { } @@ -197,8 +197,8 @@ void auth_3d_database::update() { for (auth_3d_database_uid& i : uid) uid_names.push_back(i.name_hash, &i); - category_names.sort_unique(); - uid_names.sort_unique(); + category_names.sort_and_erase_non_unique(); + uid_names.sort_and_erase_non_unique(); } int32_t auth_3d_database::get_category_index(const char* name) const { @@ -281,7 +281,7 @@ static void auth_3d_database_load_uids(auth_3d_database* auth_3d_db, int32_t org_uid; if (!mdata) org_uid = (int32_t)i; - else if (uid_file->flags & AUTH_3D_DATABASE_UID_ORG_UID) + else if (uid_file->flag & auth_3d_database_uid_file::FLAG_ORG_UID) org_uid = uid_file->org_uid; else org_uid = (int32_t)(uid_count + i); @@ -296,29 +296,29 @@ static void auth_3d_database_load_uids(auth_3d_database* auth_3d_db, uid->name.assign(uid_file->value.substr(2, uid_file->value.size() - 2)); uid->name_hash = hash_string_murmurhash(uid->name); - uid->category.assign(uid_file->category); - uid->category_hash = hash_string_murmurhash(uid->category); + uid->category_name.assign(uid_file->category_name); + uid->category_hash = hash_string_murmurhash(uid->category_name); } if (uid->enabled) { - uid_file->category.assign(uid->category); + uid_file->category_name.assign(uid->category_name); - if (uid->category.size() > 0) + if (uid->category_name.size() > 0) for (auth_3d_database_category& j : category) - if (!uid->category.compare(j.name)) { + if (!uid->category_name.compare(j.name)) { j.uid.push_back(org_uid); break; } } - if (uid_file->flags & AUTH_3D_DATABASE_UID_SIZE) - uid->size = uid_file->size; + if (uid_file->flag & auth_3d_database_uid_file::FLAG_FRAME_SIZE) + uid->frame_size = uid_file->frame_size; else - uid->size = -1.0f; + uid->frame_size = -1.0f; } for (auth_3d_database_category& i : category) - prj::sort_unique(i.uid); + prj::sort_and_erase_non_unique(i.uid); } static void auth_3d_database_file_read_inner(auth_3d_database_file* auth_3d_db_file, stream& s) { @@ -383,11 +383,11 @@ static void auth_3d_database_file_read_text(auth_3d_database_file* auth_3d_db_fi continue; auth_3d_database_uid_file* u = &vu[i]; - kv.read("category", u->category); + kv.read("category", u->category_name); if (kv.read("org_uid", u->org_uid)) - enum_or(u->flags, AUTH_3D_DATABASE_UID_ORG_UID); - if (kv.read("size", u->size)) - enum_or(u->flags, AUTH_3D_DATABASE_UID_SIZE); + u->flag |= auth_3d_database_uid_file::FLAG_ORG_UID; + if (kv.read("size", u->frame_size)) + u->flag |= auth_3d_database_uid_file::FLAG_FRAME_SIZE; kv.read("value", u->value); kv.close_scope(); @@ -439,15 +439,15 @@ static void auth_3d_database_file_write_text(auth_3d_database_file* auth_3d_db_f auth_3d_database_uid_file* u = &vu[sort_index_data[i]]; - kv.write(s, "category", u->category); - if ((int32_t)(u->flags & AUTH_3D_DATABASE_UID_ORG_UID)) + kv.write(s, "category", u->category_name); + if (u->flag & auth_3d_database_uid_file::FLAG_ORG_UID) kv.write(s, "org_uid", u->org_uid); - if ((int32_t)(u->flags & AUTH_3D_DATABASE_UID_SIZE)) - kv.write(s, "size", u->size); + if (u->flag & auth_3d_database_uid_file::FLAG_FRAME_SIZE) + kv.write(s, "size", u->frame_size); kv.write(s, "value", u->value); - if ((int32_t)(u->flags & AUTH_3D_DATABASE_UID_ORG_UID) && u->org_uid > uid_max) - uid_max = u->org_uid; + if (u->flag & auth_3d_database_uid_file::FLAG_ORG_UID) + uid_max = max_def(uid_max, u->org_uid); kv.close_scope(); } diff --git a/src/KKdLib/database/auth_3d.hpp b/src/KKdLib/database/auth_3d.hpp index 3181d7ec..29ab9981 100644 --- a/src/KKdLib/database/auth_3d.hpp +++ b/src/KKdLib/database/auth_3d.hpp @@ -10,29 +10,29 @@ #include "../default.hpp" #include "../prj/vector_pair.hpp" -enum auth_3d_database_uid_flags { - AUTH_3D_DATABASE_UID_ORG_UID = 0x01, - AUTH_3D_DATABASE_UID_SIZE = 0x02, -}; - struct auth_3d_database_uid { bool enabled; - std::string category; + std::string category_name; uint32_t category_hash; + float_t frame_size; std::string name; uint32_t name_hash; int32_t org_uid; - float_t size; auth_3d_database_uid(); ~auth_3d_database_uid(); }; struct auth_3d_database_uid_file { - auth_3d_database_uid_flags flags; - std::string category; + enum { + FLAG_FRAME_SIZE = 0x01, + FLAG_ORG_UID = 0x02, + }; + + uint32_t flag; + std::string category_name; + float_t frame_size; int32_t org_uid; - float_t size; std::string value; auth_3d_database_uid_file(); diff --git a/src/KKdLib/database/bone.cpp b/src/KKdLib/database/bone.cpp index b59f1a74..aa3a68b0 100644 --- a/src/KKdLib/database/bone.cpp +++ b/src/KKdLib/database/bone.cpp @@ -261,12 +261,12 @@ void bone_database::update() { for (std::string& j : i.bone_node_name) i.bone_node_name_map.push_back(hash_string_murmurhash(j), &j); - i.body_type_map.sort_unique(); - i.bone_name_map.sort_unique(); - i.bone_node_name_map.sort_unique(); + i.body_type_map.sort_and_erase_non_unique(); + i.bone_name_map.sort_and_erase_non_unique(); + i.bone_node_name_map.sort_and_erase_non_unique(); } - bonedata_map.sort_unique(); + bonedata_map.sort_and_erase_non_unique(); } const BoneData* bone_database::get_bone_data(const char* kind_name) const { diff --git a/src/KKdLib/database/motion.cpp b/src/KKdLib/database/motion.cpp index e2a64c38..07e2a81e 100644 --- a/src/KKdLib/database/motion.cpp +++ b/src/KKdLib/database/motion.cpp @@ -272,12 +272,12 @@ void motion_database::update() { } } - motion_set_ids.sort_unique(); - motion_set_names.sort_unique(); - motion_set_motion_ids.sort_unique(); - motion_set_motion_names.sort_unique(); - motion_ids.sort_unique(); - motion_names.sort_unique(); + motion_set_ids.sort_and_erase_non_unique(); + motion_set_names.sort_and_erase_non_unique(); + motion_set_motion_ids.sort_and_erase_non_unique(); + motion_set_motion_names.sort_and_erase_non_unique(); + motion_ids.sort_and_erase_non_unique(); + motion_names.sort_and_erase_non_unique(); } const motion_set_info* motion_database::get_motion_set_by_id(uint32_t id) const { diff --git a/src/KKdLib/database/object.cpp b/src/KKdLib/database/object.cpp index 5603cecd..3df577a1 100644 --- a/src/KKdLib/database/object.cpp +++ b/src/KKdLib/database/object.cpp @@ -370,16 +370,16 @@ void object_database::update() { } } - obj_set_ids.sort_unique(); - obj_set_murmurhashes.sort_unique(); - obj_set_names.sort_unique(); - obj_infos.sort_unique(); - obj_fnv1a64m_hashes.sort_unique(); - obj_fnv1a64m_hashes_upper.sort_unique(); - obj_murmurhashes.sort_unique(); - obj_info_fnv1a64m_hashes.sort_unique(); - obj_info_fnv1a64m_hashes_upper.sort_unique(); - obj_info_murmurhashes.sort_unique(); + obj_set_ids.sort_and_erase_non_unique(); + obj_set_murmurhashes.sort_and_erase_non_unique(); + obj_set_names.sort_and_erase_non_unique(); + obj_infos.sort_and_erase_non_unique(); + obj_fnv1a64m_hashes.sort_and_erase_non_unique(); + obj_fnv1a64m_hashes_upper.sort_and_erase_non_unique(); + obj_murmurhashes.sort_and_erase_non_unique(); + obj_info_fnv1a64m_hashes.sort_and_erase_non_unique(); + obj_info_fnv1a64m_hashes_upper.sort_and_erase_non_unique(); + obj_info_murmurhashes.sort_and_erase_non_unique(); } const object_set_info* object_database::get_object_set_info(const char* name) const { diff --git a/src/KKdLib/database/stage.cpp b/src/KKdLib/database/stage.cpp index 138a11fc..1edfcbc3 100644 --- a/src/KKdLib/database/stage.cpp +++ b/src/KKdLib/database/stage.cpp @@ -427,8 +427,8 @@ void stage_database::update() { for (stage_data_modern& i : stage_modern) stage_modern_names.push_back(i.hash, &i); - stage_data_names.sort_unique(); - stage_modern_names.sort_unique(); + stage_data_names.sort_and_erase_non_unique(); + stage_modern_names.sort_and_erase_non_unique(); } const ::stage_data* stage_database::get_stage_data(int32_t stage_index) const { diff --git a/src/KKdLib/database/texture.cpp b/src/KKdLib/database/texture.cpp index d4738602..07dfadfc 100644 --- a/src/KKdLib/database/texture.cpp +++ b/src/KKdLib/database/texture.cpp @@ -299,8 +299,8 @@ void texture_database::update() { texture_murmurhashes.push_back(i.name_hash, &i); } - texture_ids.sort_unique(); - texture_murmurhashes.sort_unique(); + texture_ids.sort_and_erase_non_unique(); + texture_murmurhashes.sort_and_erase_non_unique(); } uint32_t texture_database::get_texture_id(const char* name) const { diff --git a/src/KKdLib/interpolation.cpp b/src/KKdLib/interpolation.cpp index fbe65242..4e54ba07 100644 --- a/src/KKdLib/interpolation.cpp +++ b/src/KKdLib/interpolation.cpp @@ -422,12 +422,12 @@ int32_t interpolate_chs_reverse_sequence(const std::vector& values_src, for (size_t i = 0; i < length - 3; i++) if (*(uint32_t*)&keys[i + 0].value == *(uint32_t*)&keys[i + 1].value && *(uint32_t*)&keys[i + 1].value == *(uint32_t*)&keys[i + 2].value - && *(uint32_t*)&keys[i + 0].tangent2 == 0 - && *(uint32_t*)&keys[i + 1].tangent1 == 0 - && *(uint32_t*)&keys[i + 1].tangent2 == 0 - && *(uint32_t*)&keys[i + 2].tangent1 == 0) { + && *(uint32_t*)&keys[i + 0].r_slope == 0 + && *(uint32_t*)&keys[i + 1].l_slope == 0 + && *(uint32_t*)&keys[i + 1].r_slope == 0 + && *(uint32_t*)&keys[i + 2].l_slope == 0) { keys[i + 1].frame = keys[i + 2].frame; - keys[i + 1].tangent2 = keys[i + 2].tangent2; + keys[i + 1].r_slope = keys[i + 2].r_slope; values.erase(values.begin() + (i + 2)); keys = values.data(); length = values.size(); @@ -439,11 +439,11 @@ int32_t interpolate_chs_reverse_sequence(const std::vector& values_src, if (values.size() >= 2) { kft3* keys = values.data(); if (*(uint32_t*)&keys[0].value == *(uint32_t*)&keys[1].value - && *(uint32_t*)&keys[0].tangent1 == 0 - && *(uint32_t*)&keys[0].tangent2 == 0 - && *(uint32_t*)&keys[1].tangent1 == 0) { + && *(uint32_t*)&keys[0].l_slope == 0 + && *(uint32_t*)&keys[0].r_slope == 0 + && *(uint32_t*)&keys[1].l_slope == 0) { keys[0].frame = keys[1].frame; - keys[0].tangent2 = keys[1].tangent2; + keys[0].r_slope = keys[1].r_slope; values.erase(values.begin() + 1); } } @@ -452,9 +452,9 @@ int32_t interpolate_chs_reverse_sequence(const std::vector& values_src, kft3* keys = values.data(); size_t length = values.size(); if (*(uint32_t*)&keys[length - 2].value == *(uint32_t*)&keys[length - 1].value - && *(uint32_t*)&keys[length - 2].tangent2 == 0 - && *(uint32_t*)&keys[length - 1].tangent1 == 0 - && *(uint32_t*)&keys[length - 1].tangent2 == 0) { + && *(uint32_t*)&keys[length - 2].r_slope == 0 + && *(uint32_t*)&keys[length - 1].l_slope == 0 + && *(uint32_t*)&keys[length - 1].r_slope == 0) { values.erase(values.begin() + (length - 1)); } } @@ -490,8 +490,8 @@ int32_t interpolate_chs_reverse_sequence(const std::vector& values_src, } for (kft3& i : values) { - i.tangent1 = 0.0f; - i.tangent2 = 0.0f; + i.l_slope = 0.0f; + i.r_slope = 0.0f; } return 2; } diff --git a/src/KKdLib/kf.cpp b/src/KKdLib/kf.cpp index 0f58210f..0b1e50c3 100644 --- a/src/KKdLib/kf.cpp +++ b/src/KKdLib/kf.cpp @@ -29,11 +29,11 @@ void kft_check(void* src_key, kf_type src_type, void* dst_key, kf_type* dst_type } break; case KEY_FRAME_TYPE_2: { kft2* sk = (kft2*)src_key; - if (*(uint32_t*)&sk->tangent != 0) { + if (*(uint32_t*)&sk->slope != 0) { kft2* dk = (kft2*)dst_key; dk->frame = sk->frame; dk->value = sk->value; - dk->tangent = sk->tangent; + dk->slope = sk->slope; *dst_type = KEY_FRAME_TYPE_2; } else if (*(uint32_t*)&sk->value != 0) { @@ -50,19 +50,19 @@ void kft_check(void* src_key, kf_type src_type, void* dst_key, kf_type* dst_type } break; case KEY_FRAME_TYPE_3: { kft3* sk = (kft3*)src_key; - if (*(uint32_t*)&sk->tangent1 != *(uint32_t*)&sk->tangent2) { + if (*(uint32_t*)&sk->l_slope != *(uint32_t*)&sk->r_slope) { kft3* dk = (kft3*)dst_key; dk->frame = sk->frame; dk->value = sk->value; - dk->tangent1 = sk->tangent1; - dk->tangent2 = sk->tangent2; + dk->l_slope = sk->l_slope; + dk->r_slope = sk->r_slope; *dst_type = KEY_FRAME_TYPE_3; } - else if (*(uint32_t*)&sk->tangent1 != 0) { + else if (*(uint32_t*)&sk->l_slope != 0) { kft2* dk = (kft2*)dst_key; dk->frame = sk->frame; dk->value = sk->value; - dk->tangent = sk->tangent1; + dk->slope = sk->l_slope; *dst_type = KEY_FRAME_TYPE_2; } else if (*(uint32_t*)&sk->value != 0) { diff --git a/src/KKdLib/kf.hpp b/src/KKdLib/kf.hpp index e66658de..98179e25 100644 --- a/src/KKdLib/kf.hpp +++ b/src/KKdLib/kf.hpp @@ -26,14 +26,14 @@ struct kft1 { struct kft2 { float_t frame; float_t value; - float_t tangent; + float_t slope; }; struct kft3 { float_t frame; float_t value; - float_t tangent1; - float_t tangent2; + float_t l_slope; + float_t r_slope; }; extern void kft_check(void* src_key, kf_type src_type, void* dst_key, kf_type* dst_type); diff --git a/src/KKdLib/mot.cpp b/src/KKdLib/mot.cpp index 2c546049..2ec78de3 100644 --- a/src/KKdLib/mot.cpp +++ b/src/KKdLib/mot.cpp @@ -569,7 +569,7 @@ mot_key_set_type mot_set::fit_keys_into_curve(std::vector& values_src, break; if (arr != values.data() + count) - return MOT_KEY_SET_HERMITE_TANGENT; + return MOT_KEY_SET_HERMITE_SLOPE; float_t* arr_src = values.data(); float_t* arr_dst = values.data(); @@ -660,19 +660,19 @@ static void mot_classic_read_inner(mot_set* ms, prj::shared_ptrvalues[0] = s.read_float_t(); } else { - bool has_tangents = key_set->type != MOT_KEY_SET_HERMITE; + bool has_slopes = key_set->type != MOT_KEY_SET_HERMITE; uint16_t keys_count = s.read_uint16_t(); key_set->keys_count = keys_count; uint16_t* frames = alloc->allocate(keys_count); - float_t* values = alloc->allocate(has_tangents ? keys_count * 2ULL : keys_count); + float_t* values = alloc->allocate(has_slopes ? keys_count * 2ULL : keys_count); key_set->frames = frames; key_set->values = values; s.read(frames, sizeof(uint16_t) * keys_count); s.align_read(0x04); - if (!has_tangents) + if (!has_slopes) s.read(values, sizeof(float_t) * keys_count); else s.read(values, sizeof(float_t) * keys_count * 2ULL); @@ -730,7 +730,7 @@ static void mot_classic_write_inner(mot_set* ms, stream& s) { s.write_float_t(key_set->values[0]); } else if (key_set->type != MOT_KEY_SET_NONE) { - bool has_tangents = key_set->type != MOT_KEY_SET_HERMITE; + bool has_slopes = key_set->type != MOT_KEY_SET_HERMITE; uint16_t keys_count = key_set->keys_count; s.write_uint16_t(keys_count); @@ -739,7 +739,7 @@ static void mot_classic_write_inner(mot_set* ms, stream& s) { s.align_write(0x04); float_t* values = key_set->values; - if (!has_tangents) + if (!has_slopes) s.write(values, sizeof(float_t) * keys_count); else s.write(values, sizeof(float_t) * keys_count * 2ULL); @@ -872,7 +872,7 @@ static void mot_modern_read_inner(mot_set* ms, prj::shared_ptrvalues[0] = s.read_float_t(); } else { - bool has_tangents = key_set->type != MOT_KEY_SET_HERMITE; + bool has_slopes = key_set->type != MOT_KEY_SET_HERMITE; uint16_t keys_count = s_motc.read_uint16_t_reverse_endianness(); mot_key_set_data_type data_type = (mot_key_set_data_type)s_motc.read_uint16_t_reverse_endianness(); @@ -880,12 +880,12 @@ static void mot_modern_read_inner(mot_set* ms, prj::shared_ptrdata_type = data_type; int16_t* frames = alloc->allocate(keys_count); - float_t* values = alloc->allocate(has_tangents ? keys_count * 2ULL : keys_count); + float_t* values = alloc->allocate(has_slopes ? keys_count * 2ULL : keys_count); key_set->frames = (uint16_t*)frames; key_set->values = values; - uint8_t step = has_tangents ? 2 : 1; - if (has_tangents) { + uint8_t step = has_slopes ? 2 : 1; + if (has_slopes) { float_t* values = &key_set->values[1]; for (int32_t k = 0; k < keys_count; k++, values += step) *values = s_motc.read_float_t_reverse_endianness(); @@ -977,8 +977,8 @@ static void mot_modern_write_inner(mot_set* ms, stream& s) { } } else if (key_set->type != MOT_KEY_SET_NONE) { - bool has_tangents = key_set->type != MOT_KEY_SET_HERMITE; - if (has_tangents) + bool has_slopes = key_set->type != MOT_KEY_SET_HERMITE; + if (has_slopes) ee = { o, 1, 4, 1 }; else ee = { o, 1, 3, 1 }; @@ -986,7 +986,7 @@ static void mot_modern_write_inner(mot_set* ms, stream& s) { uint16_t keys_count = key_set->keys_count; mot_key_set_data_type data_type = key_set->data_type; o = 4; - if (has_tangents) + if (has_slopes) o += keys_count * 4; if (data_type == MOT_KEY_SET_DATA_F16) @@ -998,7 +998,7 @@ static void mot_modern_write_inner(mot_set* ms, stream& s) { ee.size = o; ee.append(0, 2, ENRS_WORD); - if (has_tangents) + if (has_slopes) ee.append(0, keys_count, ENRS_DWORD); if (data_type == MOT_KEY_SET_DATA_F16) { ee.append(0, keys_count, ENRS_WORD); @@ -1090,14 +1090,14 @@ static void mot_modern_write_inner(mot_set* ms, stream& s) { s.write_float_t_reverse_endianness(key_set->values[0]); } else if (key_set->type != MOT_KEY_SET_NONE) { - bool has_tangents = key_set->type != MOT_KEY_SET_HERMITE; + bool has_slopes = key_set->type != MOT_KEY_SET_HERMITE; uint16_t keys_count = key_set->keys_count; mot_key_set_data_type data_type = key_set->data_type; s_motc.write_uint16_t_reverse_endianness(keys_count); s_motc.write_uint16_t_reverse_endianness((uint16_t)data_type); - uint8_t step = has_tangents ? 2 : 1; - if (has_tangents) { + uint8_t step = has_slopes ? 2 : 1; + if (has_slopes) { float_t* values = &key_set->values[1]; for (int32_t k = 0; k < keys_count; k++, values += step) s_motc.write_float_t_reverse_endianness(*values); @@ -1263,7 +1263,7 @@ static void mot_data_move_data(mot_data* mot_dst, const mot_data* mot_src, key_set_dst->frames = alloc->allocate(key_set_src->frames, keys_count); key_set_dst->values = alloc->allocate(key_set_src->values, keys_count); break; - case MOT_KEY_SET_HERMITE_TANGENT: + case MOT_KEY_SET_HERMITE_SLOPE: key_set_dst->frames = alloc->allocate(key_set_src->frames, keys_count); key_set_dst->values = alloc->allocate(key_set_src->values, keys_count * 2ULL); break; diff --git a/src/KKdLib/mot.hpp b/src/KKdLib/mot.hpp index cd9f86ea..4db49569 100644 --- a/src/KKdLib/mot.hpp +++ b/src/KKdLib/mot.hpp @@ -13,10 +13,10 @@ #include "vec.hpp" enum mot_key_set_type { - MOT_KEY_SET_NONE = 0x00, - MOT_KEY_SET_STATIC = 0x01, - MOT_KEY_SET_HERMITE = 0x02, - MOT_KEY_SET_HERMITE_TANGENT = 0x03, + MOT_KEY_SET_NONE = 0x00, + MOT_KEY_SET_STATIC = 0x01, + MOT_KEY_SET_HERMITE = 0x02, + MOT_KEY_SET_HERMITE_SLOPE = 0x03, }; enum mot_key_set_data_type { diff --git a/src/KKdLib/obj.cpp b/src/KKdLib/obj.cpp index 506e3a46..5ef6c249 100644 --- a/src/KKdLib/obj.cpp +++ b/src/KKdLib/obj.cpp @@ -2482,7 +2482,7 @@ static void obj_classic_write_skin(obj_skin* sk, stream& s, int64_t base_offset) s.position_pop(); exh.osage_root_offset = obj_skin_strings_get_string_offset(strings, - string_offsets, ex->osage_root); + string_offsets, ex->osage_root); s.position_push(exh.osage_joint_offset, SEEK_SET); for (int32_t i = 0; i < ex->nb_jointX; i++) { diff --git a/src/KKdLib/prj/algorithm.hpp b/src/KKdLib/prj/algorithm.hpp index 1c577407..60907ed2 100644 --- a/src/KKdLib/prj/algorithm.hpp +++ b/src/KKdLib/prj/algorithm.hpp @@ -12,40 +12,52 @@ #include namespace prj { - template - bool find(std::vector& vec, const T& value) { - auto begin = vec.begin(); - auto end = vec.end(); - for (auto i = begin; i != end; i++) - if (*i == value) - return true; + template + inline bool find(T& in_c, const U& in_v) { + auto elem = std::find(in_c.begin(), in_c.end(), in_v); + return elem != in_c.end(); + } + + template + inline bool find(T& in_c, const U&& in_v) { + auto elem = std::find(in_c.begin(), in_c.end(), in_v); + return elem != in_c.end(); + } + + template + inline bool find_and_erase(T& in_c, const U& in_v) { + auto elem = std::find(in_c.begin(), in_c.end(), in_v); + if (elem != in_c.end()) { + in_c.erase(elem); + return true; + } + return false; + } + + template + inline bool find_and_erase(T& in_c, const U&& in_v) { + auto elem = std::find(in_c.begin(), in_c.end(), in_v); + if (elem != in_c.end()) { + in_c.erase(elem); + return true; + } return false; } template - bool find(std::vector& vec, const T&& value) { - auto begin = vec.begin(); - auto end = vec.end(); - for (auto i = begin; i != end; i++) - if (*i == value) - return true; - return false; + inline void sort(T& in_c) { + std::sort(in_c.begin(), in_c.end()); } template - inline void sort(std::vector& vec) { - std::sort(vec.begin(), vec.end()); + inline void unique_and_erase(T& in_c) { + auto last = std::unique(in_c.begin(), in_c.end()); + in_c.erase(last, in_c.end()); } template - void unique(std::vector& vec) { - auto last = std::unique(vec.begin(), vec.end()); - vec.erase(last, vec.end()); - } - - template - inline void sort_unique(std::vector& vec) { - sort(vec); - unique(vec); + inline void sort_and_erase_non_unique(T& in_c) { + sort(in_c); + unique_and_erase(in_c); } } diff --git a/src/KKdLib/prj/bit_array.hpp b/src/KKdLib/prj/bit_array.hpp index c878ce23..72121eab 100644 --- a/src/KKdLib/prj/bit_array.hpp +++ b/src/KKdLib/prj/bit_array.hpp @@ -73,7 +73,7 @@ namespace prj { uint32_t* M_data() { return M_core.M_pool; } - + const uint32_t* M_data() const { return M_core.M_pool; } @@ -180,7 +180,7 @@ namespace prj { return false; return true; } - + void operator&=(const BitArrayBase& right) { for (size_t i = 0; i < num_blocks(); i++) M_data()[i] &= right.M_data()[i]; diff --git a/src/KKdLib/prj/string_on_array.hpp b/src/KKdLib/prj/string_on_array.hpp index 3aa8343e..563efc78 100644 --- a/src/KKdLib/prj/string_on_array.hpp +++ b/src/KKdLib/prj/string_on_array.hpp @@ -191,7 +191,7 @@ namespace prj { return assign(ptr, npos); } - + template __declspec(noinline) PodStringOnArray& assign(const PodStringOnArray<_Elem, _Traits, len, unk, rhs_fill_null>& rhs) { if (c_str() == rhs.c_str()) diff --git a/src/KKdLib/prj/vector_pair.hpp b/src/KKdLib/prj/vector_pair.hpp index b4842af2..1c2271ea 100644 --- a/src/KKdLib/prj/vector_pair.hpp +++ b/src/KKdLib/prj/vector_pair.hpp @@ -48,14 +48,14 @@ namespace prj { }); } - void unique() { + void erase_non_unique() { auto last = std::unique(this->begin(), this->end()); this->erase(last, this->end()); } - inline void sort_unique() { + inline void sort_and_erase_non_unique() { sort(); - unique(); + erase_non_unique(); } inline typename auto find(const T& key) { diff --git a/src/ReDIVA/app.cpp b/src/ReDIVA/app.cpp index 66733757..f70549c1 100644 --- a/src/ReDIVA/app.cpp +++ b/src/ReDIVA/app.cpp @@ -2204,7 +2204,7 @@ static int32_t app_create_logical_device() { std::vector unique_queue_families; unique_queue_families.insert(unique_queue_families.end(), indices.first); unique_queue_families.insert(unique_queue_families.end(), indices.second); - prj::sort_unique(unique_queue_families); + prj::sort_and_erase_non_unique(unique_queue_families); std::vector queue_create_infos; queue_create_infos.reserve(unique_queue_families.size()); diff --git a/src/ReDIVA/data_edit/face_anim.cpp b/src/ReDIVA/data_edit/face_anim.cpp index b7cf0c2e..192f7353 100644 --- a/src/ReDIVA/data_edit/face_anim.cpp +++ b/src/ReDIVA/data_edit/face_anim.cpp @@ -26,257 +26,250 @@ FaceAnim::Auth3D::~Auth3D() { } -inline static void set_data(auth_3d_key& key, const float_t value) { - key.reset(); - key.type = value != 0.0f && value != -0.0f ? AUTH_3D_KEY_STATIC : AUTH_3D_KEY_NONE; - key.value = value; -} - -inline static void set_data(auth_3d_object_model_transform& mt, const vec3 translation, +inline static void set_data(auth_3d_detail::MotionTransform& mt, const vec3 translation, const vec3 rotation, const vec3 scale = 1.0f, const float_t visibility = 1.0f) { - set_data(mt.translation.x, translation.x); - set_data(mt.translation.y, translation.y); - set_data(mt.translation.z, translation.z); - set_data(mt.rotation.x, rotation.x); - set_data(mt.rotation.y, rotation.y); - set_data(mt.rotation.z, rotation.z); - set_data(mt.scale.x, scale.x); - set_data(mt.scale.y, scale.y); - set_data(mt.scale.z, scale.z); - set_data(mt.visibility, visibility); + mt.fcurve_translation.x.init(translation.x); + mt.fcurve_translation.y.init(translation.y); + mt.fcurve_translation.z.init(translation.z); + mt.fcurve_rotation.x.init(rotation.x); + mt.fcurve_rotation.y.init(rotation.y); + mt.fcurve_rotation.z.init(rotation.z); + mt.fcurve_scale.x.init(scale.x); + mt.fcurve_scale.y.init(scale.y); + mt.fcurve_scale.z.init(scale.z); + mt.fcurve_visibility.init(visibility); } void FaceAnim::Auth3D::patch() { - ::auth_3d* auth = id.get_auth_3d(); - auth_3d_object_hrc* objhrc = &auth->object_hrc[0]; - auth_3d_object_node* nodes = objhrc->node.data(); + auth_3d_detail::Scene* scene = id.get_scene(); + auth_3d_detail::HierarchyObject* objhrc = scene->object_hrc_list[0]; + auth_3d_detail::TransformNode* node_list = objhrc->node_list.data(); - set_data(nodes[ 0].model_transform, + set_data(node_list[ 0].motion_transform, vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // OBJHRC_EFFCHRPV826MIK001_MOB - set_data(nodes[ 1].model_transform, + set_data(node_list[ 1].motion_transform, vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // gblctr - set_data(nodes[ 2].model_transform, + set_data(node_list[ 2].motion_transform, vec3(0.0f, 1.055f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // n_hara - set_data(nodes[ 3].model_transform, + set_data(node_list[ 3].motion_transform, vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // n_hara_y - set_data(nodes[ 4].model_transform, + set_data(node_list[ 4].motion_transform, vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_hara_wj - set_data(nodes[ 5].model_transform, + set_data(node_list[ 5].motion_transform, vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 1.570796f, 0.0f)); // n_kosi - set_data(nodes[ 6].model_transform, + set_data(node_list[ 6].motion_transform, vec3(0.0f, 0.11f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_mune_wj - set_data(nodes[ 7].model_transform, + set_data(node_list[ 7].motion_transform, vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, -1.570796f, 0.0f)); // n_mune_kl - set_data(nodes[ 8].model_transform, + set_data(node_list[ 8].motion_transform, vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_mune_b_wj - set_data(nodes[ 9].model_transform, + set_data(node_list[ 9].motion_transform, vec3(0.0f, 0.145f, -0.044f), vec3(0.0f, 0.0f, 0.0f)); // j_kubi_wj - set_data(nodes[10].model_transform, + set_data(node_list[10].motion_transform, vec3(0.0f, 0.079f, 0.004f), vec3(1.570796f, 0.0f, 0.0f)); // n_kao - set_data(nodes[11].model_transform, + set_data(node_list[11].motion_transform, vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_kao_wj - set_data(nodes[12].model_transform, + set_data(node_list[12].motion_transform, vec3(0.111f, -0.062f, -0.18f), vec3(0.0f, -1.570796f, 1.221731f)); // j_hair_twin_l_000_wj - set_data(nodes[13].model_transform, + set_data(node_list[13].motion_transform, vec3(0.222f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_hair_twin_l_001_wj - set_data(nodes[14].model_transform, + set_data(node_list[14].motion_transform, vec3(0.222f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_hair_twin_l_002_wj - set_data(nodes[15].model_transform, + set_data(node_list[15].motion_transform, vec3(0.222f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_hair_twin_l_003_wj - set_data(nodes[16].model_transform, + set_data(node_list[16].motion_transform, vec3(0.222f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_hair_twin_l_004_wj - set_data(nodes[17].model_transform, + set_data(node_list[17].motion_transform, vec3(0.222f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_hair_twin_l_005_wj - set_data(nodes[18].model_transform, + set_data(node_list[18].motion_transform, vec3(-0.111f, -0.062f, -0.18f), vec3(0.0f, -1.570796f, -1.221731f)); // j_hair_twin_r_000_wj - set_data(nodes[19].model_transform, + set_data(node_list[19].motion_transform, vec3(0.222f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_hair_twin_r_001_wj - set_data(nodes[20].model_transform, + set_data(node_list[20].motion_transform, vec3(0.222f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_hair_twin_r_002_wj - set_data(nodes[21].model_transform, + set_data(node_list[21].motion_transform, vec3(0.222f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_hair_twin_r_003_wj - set_data(nodes[22].model_transform, + set_data(node_list[22].motion_transform, vec3(0.222f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_hair_twin_r_004_wj - set_data(nodes[23].model_transform, + set_data(node_list[23].motion_transform, vec3(0.222f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_hair_twin_r_005_wj - /*set_data(nodes[24].model_transform, + /*set_data(node_list[24].motion_transform, vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_kao_normal_wj - set_data(nodes[25].model_transform, + set_data(node_list[25].motion_transform, vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_kao_close_wj - set_data(nodes[26].model_transform, + set_data(node_list[26].motion_transform, vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_kao_smile_wj - set_data(nodes[27].model_transform, + set_data(node_list[27].motion_transform, vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_kao_close_half_wj - set_data(nodes[28].model_transform, + set_data(node_list[28].motion_transform, vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_kao_smile_half_wj - set_data(nodes[29].model_transform, + set_data(node_list[29].motion_transform, vec3(0.0148f, -0.0018f, 0.079f), vec3(0.0f, 0.0f, 0.0f)); // j_kuti_l_wj - set_data(nodes[30].model_transform, + set_data(node_list[30].motion_transform, vec3(0.0f, 0.00048f, 0.088f), vec3(0.0f, 0.0f, 0.0f)); // j_kuti_u_wj - set_data(nodes[31].model_transform, + set_data(node_list[31].motion_transform, vec3(0.0f, -0.00672f, 0.082f), vec3(0.0f, 0.0f, 0.0f)); // j_kuti_d_wj - set_data(nodes[32].model_transform, + set_data(node_list[32].motion_transform, vec3(-0.0148f, -0.0018f, 0.079f), vec3(0.0f, 0.0f, 0.0f)); // j_kuti_r_wj - set_data(nodes[33].model_transform, + set_data(node_list[33].motion_transform, vec3(-0.027f, 0.061f, 0.015f), vec3(-1.570796f, 0.0f, 0.0f)); // j_eye_r_wj - set_data(nodes[34].model_transform, + set_data(node_list[34].motion_transform, vec3(0.027f, 0.061f, 0.015f), vec3(-1.570796f, 0.0f, 0.0f)); // j_eye_l_wj*/ - set_data(nodes[35].model_transform, + set_data(node_list[35].motion_transform, vec3(0.02f, 0.129f, -0.053f), vec3(1.570796f, 0.0f, 1.570796f)); // n_waki_l - set_data(nodes[36].model_transform, + set_data(node_list[36].motion_transform, vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_waki_l_wj - set_data(nodes[37].model_transform, + set_data(node_list[37].motion_transform, vec3(-0.01f, 0.0f, 0.083f), vec3(-0.037163f, -1.081817f, -3.108780f)); // n_kata_l - set_data(nodes[38].model_transform, + set_data(node_list[38].motion_transform, vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_kata_l_wj - set_data(nodes[39].model_transform, + set_data(node_list[39].motion_transform, vec3(0.208f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_ude_l_wj - set_data(nodes[40].model_transform, + set_data(node_list[40].motion_transform, vec3(0.21f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_te_l_wj - set_data(nodes[41].model_transform, + set_data(node_list[41].motion_transform, vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_te_sizen2_l_wj - set_data(nodes[42].model_transform, + set_data(node_list[42].motion_transform, vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_te_close_l_wj - set_data(nodes[43].model_transform, + set_data(node_list[43].motion_transform, vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_te_reset_l_wj - set_data(nodes[44].model_transform, + set_data(node_list[44].motion_transform, vec3(-0.02f, 0.129f, -0.053f), vec3(1.570796f, 0.0f, 1.570796f)); // n_waki_r - set_data(nodes[45].model_transform, + set_data(node_list[45].motion_transform, vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_waki_r_wj - set_data(nodes[46].model_transform, + set_data(node_list[46].motion_transform, vec3(-0.01f, 0.0f, -0.083f), vec3(0.037163f, 1.081817f, -3.108780f)); // n_kata_r - set_data(nodes[47].model_transform, + set_data(node_list[47].motion_transform, vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_kata_r_wj - set_data(nodes[48].model_transform, + set_data(node_list[48].motion_transform, vec3(0.208f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_ude_r_wj - set_data(nodes[49].model_transform, + set_data(node_list[49].motion_transform, vec3(0.21f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_te_r_wj - set_data(nodes[50].model_transform, + set_data(node_list[50].motion_transform, vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_te_sizen2_r_wj - set_data(nodes[51].model_transform, + set_data(node_list[51].motion_transform, vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_te_close_r_wj - set_data(nodes[52].model_transform, + set_data(node_list[52].motion_transform, vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_te_reset_r_wj - set_data(nodes[53].model_transform, + set_data(node_list[53].motion_transform, vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_te_one_r_wj - set_data(nodes[54].model_transform, + set_data(node_list[54].motion_transform, vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_kosi_wj - set_data(nodes[55].model_transform, + set_data(node_list[55].motion_transform, vec3(0.046f, -0.15f, 0.065f), vec3(0.0f, 0.0f, -1.570796f)); // n_momo_l - set_data(nodes[56].model_transform, + set_data(node_list[56].motion_transform, vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_momo_l_wj - set_data(nodes[57].model_transform, + set_data(node_list[57].motion_transform, vec3(0.39f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_sune_l_wj - set_data(nodes[58].model_transform, + set_data(node_list[58].motion_transform, vec3(0.38f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_asi_l_wj - set_data(nodes[59].model_transform, + set_data(node_list[59].motion_transform, vec3(0.046f, -0.15f, -0.065f), vec3(0.0f, 0.0f, -1.570796f)); // n_momo_r - set_data(nodes[60].model_transform, + set_data(node_list[60].motion_transform, vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_momo_r_wj - set_data(nodes[61].model_transform, + set_data(node_list[61].motion_transform, vec3(0.39f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_sune_r_wj - set_data(nodes[62].model_transform, + set_data(node_list[62].motion_transform, vec3(0.38f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f)); // j_asi_r_wj - set_data(nodes[63].model_transform, + set_data(node_list[63].motion_transform, vec3(-0.060104f, -0.052047f, 0.0f), vec3(0.0f, 0.0f, -1.762782f)); // j_cloth_skirt_f_000_wj - set_data(nodes[64].model_transform, + set_data(node_list[64].motion_transform, vec3(-0.042834f, -0.052048f, 0.05915f), vec3(-0.368869f, -0.220518f, -1.784135f)); // j_cloth_skirt_l_02_000_wj - set_data(nodes[65].model_transform, + set_data(node_list[65].motion_transform, vec3(-0.013f, -0.052048f, 0.109621f), vec3(-1.710423f, -0.331613f, -1.588249f)); // j_cloth_skirt_l_04_000_wj - set_data(nodes[66].model_transform, + set_data(node_list[66].motion_transform, vec3(0.0927504f, -0.052048f, 0.08239f), vec3(-2.356194f, -0.314159f, -1.308997f)); // j_cloth_skirt_l_06_000_wj - set_data(nodes[67].model_transform, + set_data(node_list[67].motion_transform, vec3(-0.042834f, -0.052048f, -0.05915f), vec3(0.368869f, 0.220518f, -1.784135f)); // j_cloth_skirt_r_02_000_wj - set_data(nodes[68].model_transform, + set_data(node_list[68].motion_transform, vec3(0.013f, -0.052048f, -0.10962f), vec3(1.710423f, 0.331613f, -1.588249f)); // j_cloth_skirt_r_04_000_wj - set_data(nodes[69].model_transform, + set_data(node_list[69].motion_transform, vec3(0.09275f, -0.052048f, -0.08239f), vec3(2.356194f, 0.314159f, -1.308997f)); // j_cloth_skirt_r_06_000_wj - set_data(nodes[70].model_transform, + set_data(node_list[70].motion_transform, vec3(0.118331f, -0.052048f, 0.0f), vec3(-3.141592f, 0.0f, -1.186823f)); // j_cloth_skirt_b_000_wj - objhrc->interpolate(0.0f); + objhrc->get(0.0f); } void FaceAnim::Auth3D::reset() { - auth_3d_data_unload_category(category.hash_murmurhash); - id.unload(rctx_ptr); + auth_3d_detail::category_free(category.hash_murmurhash); + id.destroy(rctx_ptr); objset_info_storage_unload_set(object_set.hash_murmurhash); category.clear(); file.clear(); object_set.clear(); - id = -1; obj_db.clear(); tex_db.clear(); @@ -316,43 +309,44 @@ bool FaceAnim::ctrl() { auth_3d.file.assign("EFFCHRPV826MIK001"); auth_3d.object_set.assign("EFFCHRPV826MIK001"); - auth_3d_data_load_category(x_data, auth_3d.category.c_str(), auth_3d.category.hash_murmurhash); + auth_3d_detail::category_load_req(x_data, auth_3d.category.c_str(), auth_3d.category.hash_murmurhash); objset_info_storage_load_set_hash(x_data, auth_3d.object_set.hash_murmurhash); state = 2; } break; case 2: { - if (!auth_3d_data_check_category_loaded(auth_3d.category.hash_murmurhash) + if (!auth_3d_detail::category_load_is_done(auth_3d.category.hash_murmurhash) || (objset_info_storage_get_objset_info(auth_3d.object_set.hash_murmurhash) && objset_info_storage_load_obj_set_check_not_read( auth_3d.object_set.hash_murmurhash, &auth_3d.obj_db, &auth_3d.tex_db))) break; - auth_3d.id = auth_3d_id(auth_3d.file.hash_murmurhash, x_data, &auth_3d.obj_db, &auth_3d.tex_db); - auth_3d.id.read_file_modern(); + auth_3d.id = auth_3d_detail::Handle::create(auth_3d.file.hash_murmurhash, + x_data, &auth_3d.obj_db, &auth_3d.tex_db); + auth_3d.id.load_req_modern(); state = 3; } break; case 3: { - if (!auth_3d.id.check_not_empty() || !auth_3d.id.check_loaded()) + if (!auth_3d.id.is_valid() || !auth_3d.id.load_is_done()) break; - auth_3d.id.set_enable(true); - auth_3d.id.set_paused(false); - auth_3d.id.set_repeat(false); - auth_3d.id.set_req_frame(0.0f); - auth_3d.id.set_visibility(true); + auth_3d.id.set_enabled(true); + auth_3d.id.set_pause(false); + auth_3d.id.set_looped(false); + auth_3d.id.set_frame_req(0.0f); + auth_3d.id.set_visible(true); auth_3d.patch(); frame = 5000; - frame_max = (int32_t)auth_3d.id.get_last_frame(); + frame_max = (int32_t)auth_3d.id.get_frame_size(); ogg_path.assign("H:\\C\\Documents\\A\\pv826\\lipsync\\01_rin.ogg"); //sound_work_play_stream(0, ogg_path.c_str(), (float_t)((double_t)frame / 60.0)); state = 4; } break; case 4: { - auth_3d.id.set_req_frame((float_t)frame); + auth_3d.id.set_frame_req((float_t)frame); if (!play && sound_play) { sound_work_release_stream(0); @@ -400,7 +394,7 @@ void FaceAnim::window() { ImGuiWindowFlags window_flags = 0; window_flags |= ImGuiWindowFlags_NoResize; - focus = false; + reset_focus(); bool open = true; if (!ImGui::Begin("Face Anim", &open, window_flags)) { ImGui::End(); @@ -415,6 +409,8 @@ void FaceAnim::window() { play ^= true; ImGui::Text("% 5d/% 5d", frame, frame_max); + + set_focus(ImGui::IsWindowFocused()); ImGui::End(); } diff --git a/src/ReDIVA/data_edit/face_anim.hpp b/src/ReDIVA/data_edit/face_anim.hpp index 828155d2..50beac9b 100644 --- a/src/ReDIVA/data_edit/face_anim.hpp +++ b/src/ReDIVA/data_edit/face_anim.hpp @@ -19,7 +19,7 @@ public: string_hash category; string_hash file; string_hash object_set; - auth_3d_id id; + auth_3d_detail::Handle id; object_database obj_db; texture_database tex_db; diff --git a/src/ReDIVA/data_edit/glitter_editor.cpp b/src/ReDIVA/data_edit/glitter_editor.cpp index c432768e..ac9ecbb4 100644 --- a/src/ReDIVA/data_edit/glitter_editor.cpp +++ b/src/ReDIVA/data_edit/glitter_editor.cpp @@ -5310,7 +5310,7 @@ static void glitter_editor_curve_editor_property_window(GlitterEditor* glt_edt) break; case Glitter::KEY_HERMITE: value = Glitter::Curve::InterpolateHermite( - c->value, n->value - c->value, c->tangent2, n->tangent1, + c->value, n->value - c->value, c->r_slope, n->l_slope, (double_t)c->frame, (double_t)n->frame, (double_t)crv_edt->frame); break; } @@ -5356,20 +5356,20 @@ static void glitter_editor_curve_editor_property_window(GlitterEditor* glt_edt) ImGui::DisableElementPop(key_random_range); if (n && c->type == Glitter::KEY_HERMITE) { - float_t tangent2 = (float_t)(c->tangent2 * scale); - if (ImGui::ColumnDragFloat("Tangent 1", - &tangent2, 0.0001f, -FLT_MAX, FLT_MAX, "%g", + float_t r_slope = (float_t)(c->r_slope * scale); + if (ImGui::ColumnDragFloat("R Slope", + &r_slope, 0.0001f, -FLT_MAX, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat)) { - c->tangent2 = tangent2 * inv_scale; + c->r_slope = r_slope * inv_scale; changed = true; } key_edit |= ImGui::IsItemFocused(); - float_t tangent1 = (float_t)(n->tangent1 * scale); - if (ImGui::ColumnDragFloat("Tangent 2", - &tangent1, 0.0001f, -FLT_MAX, FLT_MAX, "%g", + float_t l_slope = (float_t)(n->l_slope * scale); + if (ImGui::ColumnDragFloat("L Slope", + &l_slope, 0.0001f, -FLT_MAX, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat)) { - n->tangent1 = tangent1 * inv_scale; + n->l_slope = l_slope * inv_scale; changed = true; } key_edit |= ImGui::IsItemFocused(); @@ -5892,11 +5892,11 @@ static void glitter_editor_curve_editor_window(GlitterEditor* glt_edt) { case Glitter::KEY_HERMITE: { int32_t df = n->frame - c->frame; int32_t _df = key.frame - c->frame; - std::vector v_arr = interpolate_chs(c->value, n->value, c->tangent2, n->tangent1, 0, df); + std::vector v_arr = interpolate_chs(c->value, n->value, c->r_slope, n->l_slope, 0, df); key.value = v_arr[_df]; key.random_range = lerp_def(c->random_range, n->random_range, (double_t)_df / (double_t)df); - interpolate_chs_reverse(v_arr.data(), v_arr.size(), c->tangent2, key.tangent1, 0, _df); - interpolate_chs_reverse(v_arr.data(), v_arr.size(), key.tangent2, n->tangent1, _df, df); + interpolate_chs_reverse(v_arr.data(), v_arr.size(), c->r_slope, key.l_slope, 0, _df); + interpolate_chs_reverse(v_arr.data(), v_arr.size(), key.r_slope, n->l_slope, _df, df); } break; } keys->insert(keys->begin() + ++pos, key); @@ -5939,18 +5939,18 @@ static void glitter_editor_curve_editor_window(GlitterEditor* glt_edt) { int32_t df_n = n->frame - i->frame; std::vector v_arr_c = interpolate_chs(c->value, - i->value, c->tangent2, i->tangent1, 0, df_c); + i->value, c->r_slope, i->l_slope, 0, df_c); std::vector v_arr_n = i->type == Glitter::KEY_HERMITE - ? interpolate_chs(i->value, n->value, i->tangent2, n->tangent1, 0, df_n) + ? interpolate_chs(i->value, n->value, i->r_slope, n->l_slope, 0, df_n) : interpolate_linear(i->value, n->value, 0, df_n); size_t v_length = v_arr_c.size() + v_arr_n.size() - 1; double_t* v_arr = new double_t[v_length]; memmove(v_arr, v_arr_c.data(), (v_arr_c.size() - 1) * sizeof(*v_arr)); memmove(v_arr + (v_arr_c.size() - 1), v_arr_n.data(), v_arr_n.size() * sizeof(*v_arr)); - interpolate_chs_reverse(v_arr, v_length, c->tangent2, - n->tangent1, 0, (size_t)n->frame - c->frame); + interpolate_chs_reverse(v_arr, v_length, c->r_slope, + n->l_slope, 0, (size_t)n->frame - c->frame); delete[] v_arr; } keys->erase(keys->begin() + (i - i_begin)); @@ -6524,70 +6524,70 @@ static void glitter_editor_curve_editor_window(GlitterEditor* glt_edt) { } if (i - i_begin > 0 && (i - 1)->type == Glitter::KEY_HERMITE) { - double_t tangent1 = i->tangent1; + double_t l_slope = i->l_slope; ImVec2 circle_pos; circle_pos.x = x - 25.0f; circle_pos.y = y - base_line + convert_value_to_height(crv_edt, - (float_t)tangent1, canvas_pos.y, canvas_size.y, min, max); + (float_t)l_slope, canvas_pos.y, canvas_size.y, min, max); draw_list->AddLine({ x, y }, circle_pos, default_color, 1.5f); if ((circle_pos.x >= p3.x - 10.0f && circle_pos.x <= p3.x + canvas_size.x + 10.0f) && (circle_pos.y >= p3.y - 10.0f && circle_pos.y <= p3.y + canvas_size.y + 10.0f)) { ImGui::SetCursorScreenPos({ circle_pos.x - 7.5f, circle_pos.y - 7.5f }); - ImGui::InvisibleButton("tan1", { 15.0f, 15.0f }, 0); + ImGui::InvisibleButton("l slope", { 15.0f, 15.0f }, 0); - ImU32 tangent1_color; + ImU32 l_slope_color; if (can_drag && ImGui::IsItemActive()) { if (ImGui::IsMouseDragging(ImGuiMouseButton_Left)) { - i->tangent1 = convert_height_to_value(crv_edt, + i->l_slope = convert_height_to_value(crv_edt, circle_pos.y + io.MouseDelta.y - y + base_line, canvas_pos.y, canvas_size.y, min, max); - if (i->tangent1 != tangent1) + if (i->l_slope != l_slope) changed = true; } holding_tan = true; - tangent1_color = selected_color; + l_slope_color = selected_color; } else - tangent1_color = default_color; + l_slope_color = default_color; draw_list->AddCircleFilled(circle_pos, - crv_edt->key_radius_in, tangent1_color, 12); + crv_edt->key_radius_in, l_slope_color, 12); } } if (i_end - i > 1 && i->type == Glitter::KEY_HERMITE) { - double_t tangent2 = i->tangent2; + double_t r_slope = i->r_slope; ImVec2 circle_pos; circle_pos.x = x + 25.0f; circle_pos.y = y - base_line + convert_value_to_height(crv_edt, - (float_t)tangent2, canvas_pos.y, canvas_size.y, min, max); + (float_t)r_slope, canvas_pos.y, canvas_size.y, min, max); draw_list->AddLine({ x, y }, circle_pos, default_color, 1.5f); if ((circle_pos.x >= p3.x - 10.0f && circle_pos.x <= p3.x + canvas_size.x + 10.0f) && (circle_pos.y >= p3.y - 10.0f && circle_pos.y <= p3.y + canvas_size.y + 10.0f)) { ImGui::SetCursorScreenPos({ circle_pos.x - 7.5f, circle_pos.y - 7.5f }); - ImGui::InvisibleButton("tan2", { 15.0f, 15.0f }, 0); + ImGui::InvisibleButton("r slope", { 15.0f, 15.0f }, 0); - ImU32 tangent2_color; + ImU32 r_slope_color; if (can_drag && ImGui::IsItemActive()) { if (ImGui::IsMouseDragging(ImGuiMouseButton_Left)) { - i->tangent2 = convert_height_to_value(crv_edt, + i->r_slope = convert_height_to_value(crv_edt, circle_pos.y + io.MouseDelta.y - y + base_line, canvas_pos.y, canvas_size.y, min, max); - if (i->tangent2 != tangent2) + if (i->r_slope != r_slope) changed = true; } holding_tan = true; - tangent2_color = selected_color; + r_slope_color = selected_color; } else - tangent2_color = default_color; + r_slope_color = default_color; draw_list->AddCircleFilled(circle_pos, - crv_edt->key_radius_in, tangent2_color, 12); + crv_edt->key_radius_in, r_slope_color, 12); } } @@ -6813,7 +6813,7 @@ static void glitter_editor_curve_editor_window_draw(GlitterEditor* glt_edt, cons break; case Glitter::KEY_HERMITE: value = Glitter::Curve::InterpolateHermite(c_value_vec, n_value_vec - c_value_vec, - vec3((float_t)c->tangent2), vec3((float_t)n->tangent1), + vec3((float_t)c->r_slope), vec3((float_t)n->l_slope), vec3((float_t)c->frame), vec3((float_t)n->frame), vec3((float_t)start_time)); break; } @@ -6862,7 +6862,7 @@ static void glitter_editor_curve_editor_window_draw(GlitterEditor* glt_edt, cons break; case Glitter::KEY_HERMITE: value = Glitter::Curve::InterpolateHermite(c_value_vec, n_value_vec - c_value_vec, - vec3((float_t)c->tangent2), vec3((float_t)n->tangent1), + vec3((float_t)c->r_slope), vec3((float_t)n->l_slope), vec3((float_t)c->frame), vec3((float_t)n->frame), vec3((float_t)end_time)); break; } @@ -6948,8 +6948,8 @@ static void glitter_editor_curve_editor_window_draw(GlitterEditor* glt_edt, cons case Glitter::KEY_HERMITE: { const float_t c_frame = (float_t)c->frame; const float_t n_frame = (float_t)n->frame; - const float_t c_tangent2 = (float_t)c->tangent2; - const float_t n_tangent1 = (float_t)n->tangent1; + const float_t c_r_slope = (float_t)c->r_slope; + const float_t n_l_slope = (float_t)n->l_slope; const vec3 c_frame_vec = c_frame; const vec3 n_frame_vec = n_frame; @@ -6957,8 +6957,8 @@ static void glitter_editor_curve_editor_window_draw(GlitterEditor* glt_edt, cons (float_t)c_value, (float_t)(c_value - c_random_range) }; const vec3 n_value_vec = { (float_t)(n_value + n_random_range), (float_t)n_value, (float_t)(n_value - n_random_range) }; - const vec3 c_tangent2_vec = c_tangent2; - const vec3 n_tangent1_vec = n_tangent1; + const vec3 c_r_slope_vec = c_r_slope; + const vec3 n_l_slope_vec = n_l_slope; const int32_t frame_width_int = (int32_t)prj::roundf(frame_width); for (int32_t j = c->frame; j < n->frame; j++) { if (j < start_time) @@ -6971,7 +6971,7 @@ static void glitter_editor_curve_editor_window_draw(GlitterEditor* glt_edt, cons const vec3 frame_vec = frame; const vec3 value = Glitter::Curve::InterpolateHermite(c_value_vec, n_value_vec - c_value_vec, - c_tangent2_vec, n_tangent1_vec, c_frame_vec, n_frame_vec, frame_vec); + c_r_slope_vec, n_l_slope_vec, c_frame_vec, n_frame_vec, frame_vec); const vec3 random = !random_range_mult ? random_range : glt_type_ft ? (random_range * value) : (random_range * value * 0.01f); @@ -7019,7 +7019,7 @@ static void glitter_editor_curve_editor_window_draw(GlitterEditor* glt_edt, cons break; case Glitter::KEY_HERMITE: value = Glitter::Curve::InterpolateHermite(c_value, n_value - c_value, - (double_t)c->tangent2, (double_t)n->tangent1, + (double_t)c->r_slope, (double_t)n->l_slope, (double_t)c->frame, (double_t)n->frame, (double_t)start_time); break; } @@ -7062,7 +7062,7 @@ static void glitter_editor_curve_editor_window_draw(GlitterEditor* glt_edt, cons break; case Glitter::KEY_HERMITE: value = Glitter::Curve::InterpolateHermite(c_value, n_value - c_value, - (double_t)c->tangent2, (double_t)n->tangent1, + (double_t)c->r_slope, (double_t)n->l_slope, (double_t)c->frame, (double_t)n->frame, (double_t)end_time); break; } @@ -7142,11 +7142,11 @@ static void glitter_editor_curve_editor_window_draw(GlitterEditor* glt_edt, cons else if (c->type == Glitter::KEY_HERMITE) { const double_t c_frame = (double_t)c->frame; const double_t n_frame = (double_t)n->frame; - const double_t c_tangent2 = c->tangent2; - const double_t n_tangent1 = n->tangent1; + const double_t c_r_slope = c->r_slope; + const double_t n_l_slope = n->l_slope; double_t value = Glitter::Curve::InterpolateHermite(c_value, n_value - c_value, - c_tangent2, n_tangent1, + c_r_slope, n_l_slope, c_frame, n_frame, (double_t)max_def(c->frame, start_time)); float_t x = canvas_pos.x + (float_t)(max_def(c->frame, start_time) - base_start_time) * frame_width; @@ -7164,7 +7164,7 @@ static void glitter_editor_curve_editor_window_draw(GlitterEditor* glt_edt, cons for (int32_t k = 0; k < frame_width_int; k++) { const double_t value = Glitter::Curve::InterpolateHermite(c_value, n_value - c_value, - c_tangent2, n_tangent1, c_frame, n_frame, (double_t)j + (double_t)k / frame_width); + c_r_slope, n_l_slope, c_frame, n_frame, (double_t)j + (double_t)k / frame_width); float_t x = canvas_pos.x + (float_t)(j - base_start_time) * frame_width + (float_t)k; diff --git a/src/ReDIVA/data_process/a3da_to_dft_dsc.cpp b/src/ReDIVA/data_process/a3da_to_dft_dsc.cpp index e33c1fbc..fe2c1544 100644 --- a/src/ReDIVA/data_process/a3da_to_dft_dsc.cpp +++ b/src/ReDIVA/data_process/a3da_to_dft_dsc.cpp @@ -28,42 +28,44 @@ dft_dsc_data::~dft_dsc_data() { } static bool a3da_to_dof_data(const char* a3da_path, dft_dsc_data& data) { - a3da cam_a3da_file; - a3da::load_file(&cam_a3da_file, "DOF\\auth_3d\\", a3da_path, 0); + auth_3d_detail::SceneFile file; + a3d::Scene::load_file(&file.prop, "DOF\\auth_3d\\", a3da_path, 0); - if (!cam_a3da_file.dof.has_dof) { + if (!file.prop.dof.has_dof) { data.frames = 0; return false; } - auth_3d cam_a3da; - cam_a3da.load(&cam_a3da_file, 0, 0); + auth_3d_detail::Scene scene; + scene.M_loadFromProperties(file, 0, 0); - data.frames = (int32_t)cam_a3da.play_control.size; + data.frames = (int32_t)scene.play_control.size; data.dof.data.reserve(data.frames + 1ULL); data.dof_index.reserve(data.frames); data.dof.data.push_back({ (dof_flags)0, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }); - auth_3d_camera_root* cr = &cam_a3da.camera_root[0]; + auth_3d_detail::CameraRoot& cr = scene.camera_root_list[0]; for (int32_t i = 0; i < data.frames; i++) { - cam_a3da.dof.model_transform.interpolate((float_t)i); - bool enable = fabsf(cam_a3da.dof.model_transform.rotation_value.z) > 0.000001f; + cr.view_point.model_transform.get((float_t)i); + scene.dof.get((float_t)i); + bool enable = fabsf(scene.dof.model_transform.rotation.z) > 0.000001f; if (!enable) { data.dof_index.push_back(0); continue; } - float_t focus = vec3::distance(cam_a3da.dof.model_transform.translation_value, cr->view_point_value); + float_t focus = vec3::distance(scene.dof.model_transform.translation, + cr.view_point.model_transform.translation); dof_data d; d.flags = (dof_flags)(DOF_QUALITY | DOF_RATIO | DOF_FUZZING_RANGE | DOF_FOCUS_RANGE | DOF_FOCUS); d.focus = focus; - d.focus_range = cam_a3da.dof.model_transform.scale_value.x; - d.fuzzing_range = cam_a3da.dof.model_transform.rotation_value.x; - d.ratio = cam_a3da.dof.model_transform.rotation_value.y; + d.focus_range = scene.dof.model_transform.scale.x; + d.fuzzing_range = scene.dof.model_transform.rotation.x; + d.ratio = scene.dof.model_transform.rotation.y; d.quality = 1.0f; bool found = false; diff --git a/src/ReDIVA/data_process/effchrpv_auth_3d_to_mot.cpp b/src/ReDIVA/data_process/effchrpv_auth_3d_to_mot.cpp index 88cd2b2f..32f09787 100644 --- a/src/ReDIVA/data_process/effchrpv_auth_3d_to_mot.cpp +++ b/src/ReDIVA/data_process/effchrpv_auth_3d_to_mot.cpp @@ -10,6 +10,7 @@ #include "../../CRE/rob/rob.hpp" #include "../../CRE/auth_3d.hpp" #include "../../CRE/data.hpp" +#include "../../CRE/debug_print.hpp" struct auth_3d_to_mot_keys { std::vector x; @@ -21,7 +22,7 @@ struct auth_3d_to_mot_keys { }; struct auth_3d_to_mot_data { - auth_3d_id id; + auth_3d_detail::Handle id; int32_t gblctr; int32_t n_hara; int32_t n_hara_y; @@ -59,10 +60,10 @@ struct auth_3d_to_mot_data { std::map bone_keys; std::map sec_bone_keys; - auth_3d_to_mot_data(auth_3d_id id); + auth_3d_to_mot_data(auth_3d_detail::Handle id); ~auth_3d_to_mot_data(); - void get_bone_indices(const auth_3d_object_hrc* oh); + void get_bone_indices(const auth_3d_detail::HierarchyObject* ho); }; struct mot_data_bake; @@ -103,7 +104,7 @@ struct effchrpv_auth_3d_to_mot { const ROB_ID* rob_ids; std::unordered_map auth_3d_mot_names; - std::map auth_3d_mot_ids; + std::map auth_3d_mot_ids; std::vector rob_mot_ids; std::map auth_3d_rob_mot_ids; @@ -129,7 +130,7 @@ struct effchrpv_auth_3d_to_mot { effchrpv_auth_3d_to_mot(); ~effchrpv_auth_3d_to_mot(); - void add_chara_effect_auth_3d(uint32_t hash, int32_t id); + void add_chara_effect_auth_3d(uint32_t hash, auth_3d_detail::Handle handle); void add_file_name(const std::string& file, const std::string& category); void disp(); void get_body_anim(int32_t frame, bool add_keys); @@ -154,8 +155,8 @@ void effchrpv_auth_3d_to_mot_init(int32_t pv_id, const ROB_ID* rob_ids) { effchr_a2m->bake.pv_id = pv_id; } -void effchrpv_auth_3d_to_mot_add_chara_effect_auth_3d(uint32_t hash, int32_t id) { - effchr_a2m->add_chara_effect_auth_3d(hash, id); +void effchrpv_auth_3d_to_mot_add_chara_effect_auth_3d(uint32_t hash, auth_3d_detail::Handle handle) { + effchr_a2m->add_chara_effect_auth_3d(hash, handle); } void effchrpv_auth_3d_to_mot_add_file_name(const std::string& file, const std::string& category) { @@ -204,8 +205,8 @@ auth_3d_to_mot_keys::~auth_3d_to_mot_keys() { } -auth_3d_to_mot_data::auth_3d_to_mot_data(auth_3d_id id) : id(id), gblctr(-1), n_hara(-1), n_hara_y(-1), -j_hara_wj(-1), n_kosi(-1), j_mune_wj(-1), n_mune_kl(-1), j_mune_b_wj(-1), j_kubi_wj(-1), +auth_3d_to_mot_data::auth_3d_to_mot_data(auth_3d_detail::Handle id) : id(id), gblctr(-1), n_hara(-1), +n_hara_y(-1), j_hara_wj(-1), n_kosi(-1), j_mune_wj(-1), n_mune_kl(-1), j_mune_b_wj(-1), j_kubi_wj(-1), n_kao(-1), j_kao_wj(-1), j_eye_r_wj(-1), j_eye_l_wj(-1), n_waki_l(-1), j_waki_l_wj(-1), n_kata_l(-1), j_kata_l_wj(-1), j_ude_l_wj(-1), j_te_l_wj(-1), n_waki_r(-1), j_waki_r_wj(-1), n_kata_r(-1), j_kata_r_wj(-1), j_ude_r_wj(-1), j_te_r_wj(-1), @@ -217,49 +218,41 @@ auth_3d_to_mot_data::~auth_3d_to_mot_data() { } -static int32_t get_bone_index(const auth_3d_object_hrc* oh, const char* name) { - uint32_t name_hash = hash_utf8_murmurhash(name); - for (const auth_3d_object_node& i : oh->node) - if (hash_string_murmurhash(i.name) == name_hash) - return (int32_t)(&i - oh->node.data()); - return -1; -} - -void auth_3d_to_mot_data::get_bone_indices(const auth_3d_object_hrc* oh) { - gblctr = get_bone_index(oh, "gblctr"); - n_hara = get_bone_index(oh, "n_hara"); - n_hara_y = get_bone_index(oh, "n_hara_y"); - j_hara_wj = get_bone_index(oh, "j_hara_wj"); - n_kosi = get_bone_index(oh, "n_kosi"); - j_mune_wj = get_bone_index(oh, "j_mune_wj"); - n_mune_kl = get_bone_index(oh, "n_mune_kl"); - j_mune_b_wj = get_bone_index(oh, "j_mune_b_wj"); - j_kubi_wj = get_bone_index(oh, "j_kubi_wj"); - n_kao = get_bone_index(oh, "n_kao"); - j_kao_wj = get_bone_index(oh, "j_kao_wj"); - j_eye_r_wj = get_bone_index(oh, "j_eye_r_wj"); - j_eye_l_wj = get_bone_index(oh, "j_eye_l_wj"); - n_waki_l = get_bone_index(oh, "n_waki_l"); - j_waki_l_wj = get_bone_index(oh, "j_waki_l_wj"); - n_kata_l = get_bone_index(oh, "n_kata_l"); - j_kata_l_wj = get_bone_index(oh, "j_kata_l_wj"); - j_ude_l_wj = get_bone_index(oh, "j_ude_l_wj"); - j_te_l_wj = get_bone_index(oh, "j_te_l_wj"); - n_waki_r = get_bone_index(oh, "n_waki_r"); - j_waki_r_wj = get_bone_index(oh, "j_waki_r_wj"); - n_kata_r = get_bone_index(oh, "n_kata_r"); - j_kata_r_wj = get_bone_index(oh, "j_kata_r_wj"); - j_ude_r_wj = get_bone_index(oh, "j_ude_r_wj"); - j_te_r_wj = get_bone_index(oh, "j_te_r_wj"); - j_kosi_wj = get_bone_index(oh, "j_kosi_wj"); - n_momo_l = get_bone_index(oh, "n_momo_l"); - j_momo_l_wj = get_bone_index(oh, "j_momo_l_wj"); - j_sune_l_wj = get_bone_index(oh, "j_sune_l_wj"); - j_asi_l_wj = get_bone_index(oh, "j_asi_l_wj"); - n_momo_r = get_bone_index(oh, "n_momo_r"); - j_momo_r_wj = get_bone_index(oh, "j_momo_r_wj"); - j_sune_r_wj = get_bone_index(oh, "j_sune_r_wj"); - j_asi_r_wj = get_bone_index(oh, "j_asi_r_wj"); +void auth_3d_to_mot_data::get_bone_indices(const auth_3d_detail::HierarchyObject* ho) { + gblctr = ho->query_node_index("gblctr"); + n_hara = ho->query_node_index("n_hara"); + n_hara_y = ho->query_node_index("n_hara_y"); + j_hara_wj = ho->query_node_index("j_hara_wj"); + n_kosi = ho->query_node_index("n_kosi"); + j_mune_wj = ho->query_node_index("j_mune_wj"); + n_mune_kl = ho->query_node_index("n_mune_kl"); + j_mune_b_wj = ho->query_node_index("j_mune_b_wj"); + j_kubi_wj = ho->query_node_index("j_kubi_wj"); + n_kao = ho->query_node_index("n_kao"); + j_kao_wj = ho->query_node_index("j_kao_wj"); + j_eye_r_wj = ho->query_node_index("j_eye_r_wj"); + j_eye_l_wj = ho->query_node_index("j_eye_l_wj"); + n_waki_l = ho->query_node_index("n_waki_l"); + j_waki_l_wj = ho->query_node_index("j_waki_l_wj"); + n_kata_l = ho->query_node_index("n_kata_l"); + j_kata_l_wj = ho->query_node_index("j_kata_l_wj"); + j_ude_l_wj = ho->query_node_index("j_ude_l_wj"); + j_te_l_wj = ho->query_node_index("j_te_l_wj"); + n_waki_r = ho->query_node_index("n_waki_r"); + j_waki_r_wj = ho->query_node_index("j_waki_r_wj"); + n_kata_r = ho->query_node_index("n_kata_r"); + j_kata_r_wj = ho->query_node_index("j_kata_r_wj"); + j_ude_r_wj = ho->query_node_index("j_ude_r_wj"); + j_te_r_wj = ho->query_node_index("j_te_r_wj"); + j_kosi_wj = ho->query_node_index("j_kosi_wj"); + n_momo_l = ho->query_node_index("n_momo_l"); + j_momo_l_wj = ho->query_node_index("j_momo_l_wj"); + j_sune_l_wj = ho->query_node_index("j_sune_l_wj"); + j_asi_l_wj = ho->query_node_index("j_asi_l_wj"); + n_momo_r = ho->query_node_index("n_momo_r"); + j_momo_r_wj = ho->query_node_index("j_momo_r_wj"); + j_sune_r_wj = ho->query_node_index("j_sune_r_wj"); + j_asi_r_wj = ho->query_node_index("j_asi_r_wj"); } mot_data_bake::mot_data_bake() : pv_id(), threads_count(4), set_info(), @@ -371,8 +364,8 @@ effchrpv_auth_3d_to_mot::~effchrpv_auth_3d_to_mot() { } -void effchrpv_auth_3d_to_mot::add_chara_effect_auth_3d(uint32_t hash, int32_t id) { - auth_3d_mot_ids.insert({ hash, id }); +void effchrpv_auth_3d_to_mot::add_chara_effect_auth_3d(uint32_t hash, auth_3d_detail::Handle handle) { + auth_3d_mot_ids.insert({ hash, handle }); } void effchrpv_auth_3d_to_mot::add_file_name(const std::string& file, const std::string& category) { @@ -381,17 +374,17 @@ void effchrpv_auth_3d_to_mot::add_file_name(const std::string& file, const std:: void effchrpv_auth_3d_to_mot::disp() { /*for (auto& i : auth_3d_rob_mot_ids) { - rob_chara* rob_chr = rob_chara_array_get(rob_ids[i.first]); + rob_chara* impl = get_rob_management()->get_rob(rob_ids[i.first]); auth_3d_to_mot_data& a2m = i.second; - auth_3d* auth = a2m.id.get_auth_3d(); - auth_3d_object_hrc* oh = &auth->object_hrc[0]; + auth_3d_detail::Scene* scene = a2m.id.get_scene(); + auth_3d_detail::HierarchyObject* ho = &scene->object_hrc[0]; mat4 mat; - mat = oh->node[a2m.j_mune_wj].model_transform.mat; + mat = ho->node_list[a2m.j_mune_wj].motion_transform.matrix; mat4_scale_rot(&mat, 0.1f, &mat); debug_put_line_axis(mat); - mat = oh->node[a2m.j_kao_wj].model_transform.mat; + mat = ho->node_list[a2m.j_kao_wj].motion_transform.matrix; mat4_scale_rot(&mat, 0.1f, &mat); debug_put_line_axis(mat); }*/ @@ -535,7 +528,7 @@ static void set_bone_key_set_ik_target_data(auth_3d_to_mot_data& a2m, const mat4 blk, curr_block_id, motion_body_type, fck, data, 2); } -static void set_bone_key_set_arm_ik_target_data(auth_3d_to_mot_data& a2m, auth_3d_object_hrc* oh, +static void set_bone_key_set_arm_ik_target_data(auth_3d_to_mot_data& a2m, auth_3d_detail::HierarchyObject* ho, const mat4& kata_mat, const mat4& ude_mat, const mat4& te_mat, const vec3 c_kata_rotation, RobBlock* block_top, FcurveKey* fck, bool add_keys, BONE_BLK tl_up_kata_index, BONE_BLK c_kata_index, @@ -579,22 +572,22 @@ void effchrpv_auth_3d_to_mot::get_body_anim(int32_t frame, bool add_keys) { static bool disable_cl_momo_rot[3] = { false, false, true }; for (auto& i : auth_3d_rob_mot_ids) { - rob_chara* rob_chr = get_rob_management()->get_rob(rob_ids[i.first]); + rob_chara* impl = get_rob_management()->get_rob(rob_ids[i.first]); auth_3d_to_mot_data& a2m = i.second; - auth_3d* auth = a2m.id.get_auth_3d(); - auth_3d_object_hrc* oh = &auth->object_hrc[0]; + auth_3d_detail::Scene* scene = a2m.id.get_scene(); + auth_3d_detail::HierarchyObject* ho = &scene->object_hrc_holder[0]; - float_t auth_frame = auth->frame; - bool auth_frame_changed = auth->frame_changed; - bool auth_paused = auth->paused; - auth->frame = (float_t)frame; - auth->frame_changed = false; - auth->paused = true; - auth->ctrl(rctx_ptr); + float_t auth_frame = scene->M_frame; + bool auth_is_requested_frame = scene->is_requested_frame; + bool auth_paused = scene->now_pause; + scene->M_frame = (float_t)frame; + scene->is_requested_frame = false; + scene->now_pause = true; + scene->ctrl(rctx_ptr); - rob_chr->set_disp_flag(oh->node[0].model_transform.visible); + impl->set_disp_flag(ho->node_list[0].motion_transform.visibility); - motion_blend_mot* mot = rob_chr->bone_data->motion_loaded.front(); + motion_blend_mot* mot = impl->bone_data->motion_loaded.front(); RobBlock* block_top = mot->bone_data.block_vec.data(); FcurveKey* fck = mot->mot_key_data.mot.fck_ptr; int32_t curr_block_id = 0; @@ -602,44 +595,44 @@ void effchrpv_auth_3d_to_mot::get_body_anim(int32_t frame, bool add_keys) { vec3 data[2]; data[0] = 0.0f; - data[1] = oh->node[a2m.gblctr].model_transform.rotation_value; + data[1] = ho->node_list[a2m.gblctr].motion_transform.rotation; set_bone_key_set_global_data(a2m.bone_keys, a2m.sec_bone_keys, add_keys, mot, fck, data, 2); - data[0] = oh->node[a2m.gblctr].model_transform.translation_value; - data[0] += oh->node[a2m.n_hara].model_transform.translation_value; - data[1] = oh->node[a2m.n_hara].model_transform.rotation_value; + data[0] = ho->node_list[a2m.gblctr].motion_transform.translation; + data[0] += ho->node_list[a2m.n_hara].motion_transform.translation; + data[1] = ho->node_list[a2m.n_hara].motion_transform.rotation; set_bone_key_set_data(block_top, a2m.bone_keys, a2m.sec_bone_keys, add_keys, BLK_N_HARA_CP, curr_block_id, motion_body_type, fck, data, 2); - data[0] = oh->node[a2m.n_hara_y].model_transform.rotation_value; + data[0] = ho->node_list[a2m.n_hara_y].motion_transform.rotation; set_bone_key_set_data(block_top, a2m.bone_keys, a2m.sec_bone_keys, add_keys, BLK_KG_HARA_Y, curr_block_id, motion_body_type, fck, data); - data[0] = oh->node[a2m.j_hara_wj].model_transform.rotation_value; + data[0] = ho->node_list[a2m.j_hara_wj].motion_transform.rotation; set_bone_key_set_data(block_top, a2m.bone_keys, a2m.sec_bone_keys, add_keys, BLK_KL_HARA_XZ, curr_block_id, motion_body_type, fck, data); - data[0] = oh->node[a2m.n_kosi].model_transform.rotation_value; + data[0] = ho->node_list[a2m.n_kosi].motion_transform.rotation; set_bone_key_set_data(block_top, a2m.bone_keys, a2m.sec_bone_keys, add_keys, BLK_N_HARA, curr_block_id, motion_body_type, fck, data); /*data[0] = { 0.0f, 0.945f, 0.0f }; - mat4_transform_point(&oh->node[a2m.j_mune_wj].model_transform.mat, &data[0], &data[0]); + mat4_transform_point(&ho->node_list[a2m.j_mune_wj].motion_transform.matrix, &data[0], &data[0]); data[1] = 0.0f; set_bone_key_set_data(block_top, a2m.bone_keys, a2m.sec_bone_keys, add_keys, BLK_CL_MUNE, curr_block_id, motion_body_type, fck, data, 2);*/ - set_bone_key_set_ik_target_data(a2m, oh->node[a2m.j_mune_wj].model_transform.mat, - oh->node[a2m.j_mune_wj].model_transform.rotation_value, block_top, fck, add_keys, + set_bone_key_set_ik_target_data(a2m, ho->node_list[a2m.j_mune_wj].motion_transform.matrix, + ho->node_list[a2m.j_mune_wj].motion_transform.rotation, block_top, fck, add_keys, BLK_CL_MUNE, curr_block_id, motion_body_type, { 0.0f, 0.945f, 0.0f }, n_mune_b_src, n_mune_b_dst, disable_cl_mune_rot); - data[0] = oh->node[a2m.j_mune_b_wj].model_transform.rotation_value; + data[0] = ho->node_list[a2m.j_mune_b_wj].motion_transform.rotation; set_bone_key_set_data(block_top, a2m.bone_keys, a2m.sec_bone_keys, add_keys, BLK_KL_MUNE_B_WJ, curr_block_id, motion_body_type, fck, data); - data[0] = oh->node[a2m.j_kubi_wj].model_transform.rotation_value; + data[0] = ho->node_list[a2m.j_kubi_wj].motion_transform.rotation; set_bone_key_set_data(block_top, a2m.bone_keys, a2m.sec_bone_keys, add_keys, BLK_KL_KUBI, curr_block_id, motion_body_type, fck, data); @@ -648,21 +641,21 @@ void effchrpv_auth_3d_to_mot::get_body_anim(int32_t frame, bool add_keys) { BLK_N_KAO, curr_block_id, motion_body_type, fck, data); /*data[0] = { 0.0f, 0.34f, 0.0f }; - mat4_transform_point(&oh->node[a2m.j_kao_wj].model_transform.mat, &data[0], &data[0]); - data[1] = oh->node[a2m.j_kao_wj].model_transform.rotation_value; + mat4_transform_point(&ho->node_list[a2m.j_kao_wj].motion_transform.matrix, &data[0], &data[0]); + data[1] = ho->node_list[a2m.j_kao_wj].motion_transform.rotation; //data[1].x = -data[1].x; //data[1].z = -data[1].z; //data[1] = 0.0f; set_bone_key_set_data(block_top, a2m.bone_keys, a2m.sec_bone_keys, add_keys, BLK_CL_KAO, curr_block_id, motion_body_type, fck, data, 2);*/ - set_bone_key_set_ik_target_data(a2m, oh->node[a2m.j_kao_wj].model_transform.mat, - oh->node[a2m.j_kao_wj].model_transform.rotation_value, block_top, fck, add_keys, + set_bone_key_set_ik_target_data(a2m, ho->node_list[a2m.j_kao_wj].motion_transform.matrix, + ho->node_list[a2m.j_kao_wj].motion_transform.rotation, block_top, fck, add_keys, BLK_CL_KAO, curr_block_id, motion_body_type, { 0.0f, 0.34f, 0.0f }, n_kao_src, n_kao_dst, disable_cl_kao_rot); if (a2m.j_eye_r_wj != -1) { - data[0] = oh->node[a2m.j_eye_r_wj].model_transform.rotation_value; + data[0] = ho->node_list[a2m.j_eye_r_wj].motion_transform.rotation; data[0].x += (float_t)(M_PI / 2.0); data[0].y = -data[0].z; data[0].z = 0.0f; @@ -671,7 +664,7 @@ void effchrpv_auth_3d_to_mot::get_body_anim(int32_t frame, bool add_keys) { } if (a2m.j_eye_l_wj != -1) { - data[0] = oh->node[a2m.j_eye_l_wj].model_transform.rotation_value; + data[0] = ho->node_list[a2m.j_eye_l_wj].motion_transform.rotation; data[0].x += (float_t)(M_PI / 2.0); data[0].y = -data[0].z; data[0].z = 0.0f; @@ -679,91 +672,91 @@ void effchrpv_auth_3d_to_mot::get_body_anim(int32_t frame, bool add_keys) { BLK_KL_EYE_L, curr_block_id, motion_body_type, fck, data); } - data[0] = oh->node[a2m.n_waki_l].model_transform.rotation_value; + data[0] = ho->node_list[a2m.n_waki_l].motion_transform.rotation; set_bone_key_set_data(block_top, a2m.bone_keys, a2m.sec_bone_keys, add_keys, BLK_N_WAKI_L, curr_block_id, motion_body_type, fck, data); - data[0] = oh->node[a2m.j_waki_l_wj].model_transform.rotation_value; + data[0] = ho->node_list[a2m.j_waki_l_wj].motion_transform.rotation; set_bone_key_set_data(block_top, a2m.bone_keys, a2m.sec_bone_keys, add_keys, BLK_KL_WAKI_L_WJ, curr_block_id, motion_body_type, fck, data); - set_bone_key_set_arm_ik_target_data(a2m, oh, - oh->node[a2m.j_kata_l_wj].model_transform.mat, - oh->node[a2m.j_ude_l_wj].model_transform.mat, - oh->node[a2m.j_te_l_wj].model_transform.mat, + set_bone_key_set_arm_ik_target_data(a2m, ho, + ho->node_list[a2m.j_kata_l_wj].motion_transform.matrix, + ho->node_list[a2m.j_ude_l_wj].motion_transform.matrix, + ho->node_list[a2m.j_te_l_wj].motion_transform.matrix, { -(float_t)(M_PI / 2.0), -(float_t)(M_PI / 2.0), -(float_t)(M_PI / 2.0) }, block_top, fck, add_keys, BLK_TL_UP_KATA_L, BLK_C_KATA_L, curr_block_id, motion_body_type); - data[0] = oh->node[a2m.j_te_l_wj].model_transform.rotation_value; + data[0] = ho->node_list[a2m.j_te_l_wj].motion_transform.rotation; set_bone_key_set_data(block_top, a2m.bone_keys, a2m.sec_bone_keys, add_keys, BLK_KL_TE_L_WJ, curr_block_id, motion_body_type, fck, data); - data[0] = oh->node[a2m.n_waki_r].model_transform.rotation_value; + data[0] = ho->node_list[a2m.n_waki_r].motion_transform.rotation; set_bone_key_set_data(block_top, a2m.bone_keys, a2m.sec_bone_keys, add_keys, BLK_N_WAKI_R, curr_block_id, motion_body_type, fck, data); - data[0] = oh->node[a2m.j_waki_r_wj].model_transform.rotation_value; + data[0] = ho->node_list[a2m.j_waki_r_wj].motion_transform.rotation; set_bone_key_set_data(block_top, a2m.bone_keys, a2m.sec_bone_keys, add_keys, BLK_KL_WAKI_R_WJ, curr_block_id, motion_body_type, fck, data); - set_bone_key_set_arm_ik_target_data(a2m, oh, - oh->node[a2m.j_kata_r_wj].model_transform.mat, - oh->node[a2m.j_ude_r_wj].model_transform.mat, - oh->node[a2m.j_te_r_wj].model_transform.mat, + set_bone_key_set_arm_ik_target_data(a2m, ho, + ho->node_list[a2m.j_kata_r_wj].motion_transform.matrix, + ho->node_list[a2m.j_ude_r_wj].motion_transform.matrix, + ho->node_list[a2m.j_te_r_wj].motion_transform.matrix, { -(float_t)(M_PI / 2.0), (float_t)(M_PI / 2.0), (float_t)(M_PI / 2.0) }, block_top, fck, add_keys, BLK_TL_UP_KATA_R, BLK_C_KATA_R, curr_block_id, motion_body_type); - data[0] = oh->node[a2m.j_te_r_wj].model_transform.rotation_value; + data[0] = ho->node_list[a2m.j_te_r_wj].motion_transform.rotation; set_bone_key_set_data(block_top, a2m.bone_keys, a2m.sec_bone_keys, add_keys, BLK_KL_TE_R_WJ, curr_block_id, motion_body_type, fck, data); - data[0] = oh->node[a2m.j_kosi_wj].model_transform.rotation_value; + data[0] = ho->node_list[a2m.j_kosi_wj].motion_transform.rotation; set_bone_key_set_data(block_top, a2m.bone_keys, a2m.sec_bone_keys, add_keys, BLK_KL_KOSI_XZ, curr_block_id, motion_body_type, fck, data); - /*mat4_get_translation(&oh->node[a2m.j_asi_l_wj].model_transform.mat, &data[0]); + /*mat4_get_translation(&ho->node_list[a2m.j_asi_l_wj].motion_transform.matrix, &data[0]); data[0].y -= 0.033f; if (data[0].y < 0.103f) data[0].y = 0.103f; - data[1] = oh->node[a2m.j_momo_l_wj].model_transform.rotation_value; + data[1] = ho->node_list[a2m.j_momo_l_wj].motion_transform.rotation; data[1].z -= (float_t)(M_PI / 2.0); set_bone_key_set_data(block_top, a2m.bone_keys, a2m.sec_bone_keys, add_keys, BLK_CL_MOMO_L, curr_block_id, motion_body_type, fck, data, 2);*/ - mat4_get_translation(&oh->node[a2m.j_asi_l_wj].model_transform.mat, &data[0]); + mat4_get_translation(&ho->node_list[a2m.j_asi_l_wj].motion_transform.matrix, &data[0]); data[0].y -= 0.033f; if (data[0].y < 0.103f) data[0].y = 0.103f; - set_bone_key_set_ik_target_data(a2m, oh->node[a2m.j_momo_l_wj].model_transform.mat, - oh->node[a2m.j_momo_l_wj].model_transform.rotation_value, block_top, fck, add_keys, + set_bone_key_set_ik_target_data(a2m, ho->node_list[a2m.j_momo_l_wj].motion_transform.matrix, + ho->node_list[a2m.j_momo_l_wj].motion_transform.rotation, block_top, fck, add_keys, BLK_CL_MOMO_L, curr_block_id, motion_body_type, data[0], n_momo_l_src, cl_momo_l_dst, disable_cl_momo_rot, false); - /*mat4_get_translation(&oh->node[a2m.j_asi_r_wj].model_transform.mat, &data[0]); + /*mat4_get_translation(&ho->node_list[a2m.j_asi_r_wj].motion_transform.matrix, &data[0]); data[0].y -= 0.033f; if (data[0].y < 0.103f) data[0].y = 0.103f; - data[1] = oh->node[a2m.j_momo_r_wj].model_transform.rotation_value; + data[1] = ho->node_list[a2m.j_momo_r_wj].motion_transform.rotation; data[1].z -= (float_t)(M_PI / 2.0); set_bone_key_set_data(block_top, a2m.bone_keys, a2m.sec_bone_keys, add_keys, BLK_CL_MOMO_R, curr_block_id, motion_body_type, fck, data, 2);*/ - mat4_get_translation(&oh->node[a2m.j_asi_r_wj].model_transform.mat, &data[0]); + mat4_get_translation(&ho->node_list[a2m.j_asi_r_wj].motion_transform.matrix, &data[0]); data[0].y -= 0.033f; if (data[0].y < 0.103f) data[0].y = 0.103f; - set_bone_key_set_ik_target_data(a2m, oh->node[a2m.j_momo_r_wj].model_transform.mat, - oh->node[a2m.j_momo_r_wj].model_transform.rotation_value, block_top, fck, add_keys, + set_bone_key_set_ik_target_data(a2m, ho->node_list[a2m.j_momo_r_wj].motion_transform.matrix, + ho->node_list[a2m.j_momo_r_wj].motion_transform.rotation, block_top, fck, add_keys, BLK_CL_MOMO_R, curr_block_id, motion_body_type, data[0], n_momo_r_src, cl_momo_r_dst, disable_cl_momo_rot, false); - data[0] = oh->node[a2m.j_asi_l_wj].model_transform.rotation_value; + data[0] = ho->node_list[a2m.j_asi_l_wj].motion_transform.rotation; set_bone_key_set_data(block_top, a2m.bone_keys, a2m.sec_bone_keys, add_keys, BLK_KL_ASI_L_WJ_CO, curr_block_id, motion_body_type, fck, data); - data[0] = oh->node[a2m.j_asi_r_wj].model_transform.rotation_value; + data[0] = ho->node_list[a2m.j_asi_r_wj].motion_transform.rotation; set_bone_key_set_data(block_top, a2m.bone_keys, a2m.sec_bone_keys, add_keys, BLK_KL_ASI_R_WJ_CO, curr_block_id, motion_body_type, fck, data); @@ -775,18 +768,18 @@ void effchrpv_auth_3d_to_mot::get_body_anim(int32_t frame, bool add_keys) { set_bone_key_set_data(block_top, a2m.bone_keys, a2m.sec_bone_keys, add_keys, BLK_N_KUBI_WJ_EX, curr_block_id, motion_body_type, fck, data); - //auth->frame = auth_frame; - //auth->frame_changed = auth_frame_changed; - //auth->paused = auth_paused; + //scene->M_frame = auth_frame; + //scene->is_requested_frame = auth_is_requested_frame; + //scene->now_pause = auth_now_pause; } } void effchrpv_auth_3d_to_mot::get_hand_anim(int32_t frame) { for (auto& i : auth_3d_rob_mot_ids) { - rob_chara* rob_chr = get_rob_management()->get_rob(rob_ids[i.first]); + rob_chara* impl = get_rob_management()->get_rob(rob_ids[i.first]); auth_3d_to_mot_data& a2m = i.second; - rob_chara_bone_data* rob_bone_data = rob_chr->bone_data; + rob_chara_bone_data* rob_bone_data = impl->bone_data; BONE_KIND kind = rob_bone_data->kind; motion_blend_mot* mot = rob_bone_data->motion_loaded.front(); @@ -829,11 +822,11 @@ void effchrpv_auth_3d_to_mot::load(int32_t frame) { char buf[0x100]; sprintf_s(buf, sizeof(buf), "PV826_OST_P%d_00", i + 1); uint32_t motion_id = aft_mot_db->get_motion_id(buf); - rob_chara* rob_chr = get_rob_management()->get_rob(rob_ids[i]); - rob_chr->replace_rob_motion(motion_id, 0.0f, + rob_chara* impl = get_rob_management()->get_rob(rob_ids[i]); + impl->replace_rob_motion(motion_id, 0.0f, 0.0f, false, false, MOTION_BLEND_CROSS, aft_bone_data, aft_mot_db); - rob_chr->set_motion_reset_data(motion_id, 0.0f); - rob_chr->set_motion_skin_param(motion_id, 0.0f); + impl->set_motion_reset_data(motion_id, 0.0f); + impl->set_motion_skin_param(motion_id, 0.0f); sprintf_s(buf, sizeof(buf), "A3D_EFFCHRPV%03dMIK%03d", pv_id, i); uint32_t hash = hash_utf8_murmurhash(buf); @@ -847,18 +840,18 @@ void effchrpv_auth_3d_to_mot::load(int32_t frame) { for (auto& i : auth_3d_rob_mot_ids) { auth_3d_to_mot_data& a2m = i.second; - auth_3d* auth = a2m.id.get_auth_3d(); - a2m.get_bone_indices(&auth->object_hrc[0]); + auth_3d_detail::Scene* scene = a2m.id.get_scene(); + a2m.get_bone_indices(&scene->object_hrc_holder[0]); } for (auto& i : auth_3d_mot_ids) { - auth_3d_id& id = i.second; - id.set_repeat(false); - id.set_camera_root_update(false); - id.set_enable(true); - id.set_paused(false); - id.set_visibility(true); - id.set_req_frame(0.0f); + auth_3d_detail::Handle& id = i.second; + id.set_looped(false); + id.camera_set_enabled(false); + id.set_enabled(true); + id.set_pause(false); + id.set_visible(true); + id.set_frame_req(0.0f); } auto round_mat = [](mat4& mat) { @@ -1022,7 +1015,7 @@ static mot_key_set_type mot_write_motion_fit_keys_into_curve(mot_data_bake* bake memcpy(frames, _frames.data(), sizeof(uint16_t) * keys_count); memcpy(values, _values.data(), sizeof(float_t) * keys_count); break; - case MOT_KEY_SET_HERMITE_TANGENT: + case MOT_KEY_SET_HERMITE_SLOPE: keys_count = _frames.size(); { std::unique_lock u_lock(*bake->alloc_mutex); diff --git a/src/ReDIVA/data_process/effchrpv_auth_3d_to_mot.hpp b/src/ReDIVA/data_process/effchrpv_auth_3d_to_mot.hpp index 801a5aee..b943afb9 100644 --- a/src/ReDIVA/data_process/effchrpv_auth_3d_to_mot.hpp +++ b/src/ReDIVA/data_process/effchrpv_auth_3d_to_mot.hpp @@ -8,8 +8,12 @@ #include "../../KKdLib/default.hpp" #include +namespace auth_3d_detail { + class Handle; +} + extern void effchrpv_auth_3d_to_mot_init(int32_t pv_id, const enum ROB_ID* rob_ids); -extern void effchrpv_auth_3d_to_mot_add_chara_effect_auth_3d(uint32_t hash, int32_t id); +extern void effchrpv_auth_3d_to_mot_add_chara_effect_auth_3d(uint32_t hash, auth_3d_detail::Handle handle); extern void effchrpv_auth_3d_to_mot_add_file_name(const std::string& file, const std::string& category); extern void effchrpv_auth_3d_to_mot_disp(); extern void effchrpv_auth_3d_to_mot_get_body_anim(int32_t frame, bool add_keys); diff --git a/src/ReDIVA/data_test/auth_2d_test.cpp b/src/ReDIVA/data_test/auth_2d_test.cpp index 50e87828..cc660a9e 100644 --- a/src/ReDIVA/data_test/auth_2d_test.cpp +++ b/src/ReDIVA/data_test/auth_2d_test.cpp @@ -119,7 +119,7 @@ bool DtmAet::ctrl() { comp_layers.clear(); aet_manager_get_scene_comp_layer_names(comp_layers, aet_id, aft_aet_db); - prj::sort_unique(comp_layers); + prj::sort_and_erase_non_unique(comp_layers); auto i = comp_layers.begin(); auto i_end = comp_layers.end(); diff --git a/src/ReDIVA/data_test/auth_3d_test.cpp b/src/ReDIVA/data_test/auth_3d_test.cpp index 002d331f..39fc8a26 100644 --- a/src/ReDIVA/data_test/auth_3d_test.cpp +++ b/src/ReDIVA/data_test/auth_3d_test.cpp @@ -291,7 +291,7 @@ public: static void CategoryCharaMenuInit(dw::Button* button, dw::Menu*& menu, std::vector& items, dw::SelectionListener* selection_listener); - static void LeftRightReverseCallback(bool value); + static void ReverseSideCallback(bool value); static void PosCallback(bool value); static void RepeatCallback(bool value); }; @@ -505,21 +505,21 @@ Auth3dTestTask::DataEventListener::~DataEventListener() { } -void Auth3dTestTask::DataEventListener::OnLoad(::auth_3d_id& id) { - size_t chara_count = id.get_chara_count(); - if (chara_count) - { - chara_count = min_def(chara_count, 2); - for (size_t i = 0; i < chara_count; i++) { - auth_3d_chara* chara = id.get_chara(i); - if (chara) { - CHARA_NUM chara_index = get_chara_num_from_char_id(chara->name.c_str()); +void Auth3dTestTask::DataEventListener::loadFinished(auth_3d_detail::Handle& in_handle) { + size_t chara_size = in_handle.get_chara_size(); + if (chara_size) { + chara_size = min_def(chara_size, 2); + + for (size_t i = 0; i < chara_size; i++) { + const std::string* name = in_handle.chara_get_name(i); + if (name) { + CHARA_NUM chara_index = get_chara_num_from_char_id(name->c_str()); if (chara_index != CN_MAX) { auth_3d_test_task->data_event_listener.data.chara_num[i ? 1 : 0] = chara_index; auth_3d_test_task->data_event_listener.data.field_C = true; - id.set_chara_num(i, i ? 1 : 0); + in_handle.chara_bind_rob(i, i ? ROB_ID_2P : ROB_ID_1P); auth_3d_test_window->rob_window->chara_list[i]->SetItemIndex(chara_index); - auth_3d_test_task->DispAuth3dChara(id); + auth_3d_test_task->DispAuth3dChara(in_handle); } } } @@ -530,14 +530,11 @@ void Auth3dTestTask::DataEventListener::OnLoad(::auth_3d_id& id) { //auth_3d_test_task->LoadTransValue(); //auth_3d_test_task->LoadRotYValue(); auth_3d_test_window->frame_slider->SetValue(0.0f); - auth_3d_test_window->SetMaxFrame(id.get_play_control_size()); + auth_3d_test_window->SetMaxFrame(in_handle.get_frame_size()); } -void Auth3dTestTask::DataEventListener::OnPostCtrl(::auth_3d_id& id) { - if (auth_3d_test_task->aet.id != -1) { - auth_3d_test_task->aet.Free(); - auth_3d_test_task->aet.Init(); - } +void Auth3dTestTask::DataEventListener::playLoopJumpAfter(auth_3d_detail::Handle& in_handle) { + auth_3d_test_task->aet_id_handle.put(); } Auth3dTestTask::Auth3dTestTask::Window::Window() { @@ -555,7 +552,7 @@ Auth3dTestTask::Auth3dTestTask() { auth_3d_id = {}; auth_3d_uid = -1; repeat = true; - mirror = false; + reverse_side = false; pos = false; snap_shot = false; snap_shot_state = 0; @@ -593,7 +590,7 @@ bool Auth3dTestTask::init() { auth_3d_id = {}; auth_3d_uid = -1; repeat = true; - mirror = false; + reverse_side = false; pos = false; snap_shot = false; snap_shot_state = 0; @@ -604,7 +601,7 @@ bool Auth3dTestTask::init() { effcmn_obj_set = aft_obj_db->get_object_set_id("EFFCMN"); aet_state = 1; aet_id = -1; - aet.Free(); + aet_id_handle.destroy(); plane_above_floor = false; stg_auth_display = true; stg_display = true; @@ -637,9 +634,8 @@ bool Auth3dTestTask::init() { bool Auth3dTestTask::ctrl() { const InputState* input_state = input_state_get(0); - if (auth_3d_test_task->auth_3d_id.check_not_empty() && input_state->CheckTapped(INPUT_BUTTON_0)) - auth_3d_test_task->auth_3d_id.set_paused( - !auth_3d_test_task->auth_3d_id.get_paused()); + if (auth_3d_test_task->auth_3d_id.is_valid() && input_state->CheckTapped(INPUT_BUTTON_0)) + auth_3d_test_task->auth_3d_id.set_pause(!auth_3d_test_task->auth_3d_id.get_pause()); SetStage(); SetAuth3dId(); @@ -649,19 +645,19 @@ bool Auth3dTestTask::ctrl() { if (effcmn_obj_set_state == 1 && !objset_info_storage_load_obj_set_check_not_read(effcmn_obj_set)) effcmn_obj_set_state = 4; - if (state == 1 && auth_3d_id.check_loaded()) + if (state == 1 && auth_3d_id.load_is_done()) state = 2; if (state == 2 && data_event_listener.data.state == 4 && !data_event_listener.data.field_C) { - auth_3d_id.set_enable(true); - auth_3d_id.set_paused(false); - auth_3d_id.set_repeat(auth_3d_test_task->repeat); - auth_3d_id.set_mirror(auth_3d_test_task->mirror); - auth_3d_id.set_pos(auth_3d_test_task->pos); + auth_3d_id.set_enabled(true); + auth_3d_id.set_pause(false); + auth_3d_id.set_looped(auth_3d_test_task->repeat); + auth_3d_id.set_reverse_side(auth_3d_test_task->reverse_side); + auth_3d_id.set_debug(auth_3d_test_task->pos ? 1 : 0); state = 4; } - if (auth_3d_id.check_not_empty()) { + if (auth_3d_id.is_valid()) { float_t frame = auth_3d_id.get_frame(); if (auth_3d_test_window) { auth_3d_test_window->frame_slider->SetValue(frame); @@ -675,7 +671,7 @@ bool Auth3dTestTask::ctrl() { mat4 mat; mat4_translate(&trans_value, &mat); mat4_mul_rotate_y(&mat, rot_y_value * DEG_TO_RAD_FLOAT, &mat); - auth_3d_id.set_mat(mat); + auth_3d_id.set_base_matrix(mat); if (!snap_shot_state && ::snap_shot && snap_shot) snap_shot_state = 1; @@ -690,7 +686,7 @@ bool Auth3dTestTask::ctrl() { data_struct* aft_data = &data_list[DATA_AFT]; auth_3d_database* aft_auth_3d_db = &aft_data->data_ft.auth_3d_db; - const char* name = auth_3d_data_get_uid_name(auth_3d_id.get_uid(), aft_auth_3d_db); + const char* name = auth_3d_detail::get_name_uid(auth_3d_id.get_uid(), aft_auth_3d_db); std::string path(get_dev_ram_ss_dir()); path.append("/"); @@ -698,7 +694,7 @@ bool Auth3dTestTask::ctrl() { //screen_shot_impl_ptr->capture_window_frame(path, auth_3d_id.get_frame()); - if (auth_3d_id.get_ended()) + if (auth_3d_id.is_finished()) snap_shot_state = 2; } } @@ -708,8 +704,8 @@ bool Auth3dTestTask::ctrl() { } bool Auth3dTestTask::dest() { - aet.Free(); - auth_3d_id.unload(rctx_ptr); + aet_id_handle.destroy(); + auth_3d_id.destroy(rctx_ptr); objset_info_storage_unload_set(effcmn_obj_set); task_stage_close(); data_event_listener.data.dest(); @@ -717,7 +713,7 @@ bool Auth3dTestTask::dest() { clear_color = color_black; shadow_ptr_get()->self_shadow = true; if (category.size()) - auth_3d_data_unload_category(category.c_str()); + auth_3d_detail::category_free(category.c_str()); category.clear(); category.shrink_to_fit(); load_category.clear(); @@ -734,9 +730,9 @@ void Auth3dTestTask::disp() { debug_put_plane_zx(vec3(0.0f, 0.25f, 0.0f), 20.0f, 20.0f); } -void Auth3dTestTask::DispAuth3dChara(::auth_3d_id& id) { +void Auth3dTestTask::DispAuth3dChara(auth_3d_detail::Handle& in_handle) { RobManagement* rob_man = get_rob_management(); - id.get_uid(); // ??? + in_handle.get_uid(); // ??? RobDisp* rob_disp = rob_man->get_rob_robdisp_work(ROB_ID_1P); if (!rob_disp) return; @@ -746,7 +742,7 @@ void Auth3dTestTask::DispAuth3dChara(::auth_3d_id& id) { } void Auth3dTestTask::DispChara() { - if (auth_3d_id.check_not_empty()) + if (auth_3d_id.is_valid()) Auth3dTestTask::DispAuth3dChara(auth_3d_id); } @@ -757,18 +753,18 @@ void Auth3dTestTask::SetAuth3dId() { if (load_category.compare(category)) { if (category.size()) { - auth_3d_data_unload_category(category.c_str()); + auth_3d_detail::category_free(category.c_str()); for (uint32_t& i : obj_sets) objset_info_storage_unload_set(i); obj_sets.clear(); } - auth_3d_data_load_category(load_category.c_str()); + auth_3d_detail::category_load_req(load_category.c_str()); category.assign(load_category); if (window.obj_link) load_state = 1; } - if (!auth_3d_data_check_category_loaded(category.c_str())) + if (!auth_3d_detail::category_load_is_done(category.c_str())) return; if (load_state == 1) { @@ -799,12 +795,12 @@ void Auth3dTestTask::SetAuth3dId() { data_event_listener.data.sub_140249A40(false); data_event_listener.data.sub_140249A40(true); - auth_3d_id.unload(rctx_ptr); - auth_3d_id = ::auth_3d_id(auth_3d_uid, aft_auth_3d_db); - if (auth_3d_id.check_not_empty()) { - auth_3d_id.set_enable(false); - auth_3d_id.add_event_adapter(&data_event_listener); - auth_3d_id.read_file(aft_auth_3d_db); + auth_3d_id.destroy(rctx_ptr); + auth_3d_id = auth_3d_detail::Handle::create(auth_3d_uid, aft_auth_3d_db); + if (auth_3d_id.is_valid()) { + auth_3d_id.set_enabled(false); + auth_3d_id.add_event_listener(&data_event_listener); + auth_3d_id.load_req(aft_auth_3d_db); state = 1; } auth_3d_uid = -1; @@ -837,7 +833,7 @@ void Auth3dTestTask::SetStage() { auth_3d_database* aft_auth_3d_db = &aft_data->data_ft.auth_3d_db; stage_database* aft_stage_data = &aft_data->data_ft.stage_data; - const char* name = auth_3d_data_get_uid_name(auth_3d_uid, aft_auth_3d_db); + const char* name = auth_3d_detail::get_name_uid(auth_3d_uid, aft_auth_3d_db); size_t name_length = utf8_length(name); if (name && name_length >= 3) { size_t v5 = name_length - 2; @@ -980,7 +976,7 @@ void Auth3dTestRobWindow::SelectionListDispStyle::Callback(dw::SelectionListener auth_3d_test_task->data_event_listener.data.cos_id[chara_id] = cos; int32_t uid = auth_3d_test_task->auth_3d_id.get_uid(); - auth_3d_test_task->auth_3d_id.unload(rctx_ptr); + auth_3d_test_task->auth_3d_id.destroy(rctx_ptr); auth_3d_test_task->SetAuth3dUid(uid); } } @@ -1253,10 +1249,10 @@ void Auth3dTestWindow::SelectionSliderFrame::Callback(dw::SelectionListener::Cal dw::Slider* slider = dynamic_cast(data->widget); if (slider) { Auth3dTestWindow* test_window = dynamic_cast(slider->parent_shell); - if (test_window && auth_3d_test_task->auth_3d_id.check_not_empty()) { - auth_3d_test_task->auth_3d_id.set_paused(true); + if (test_window && auth_3d_test_task->auth_3d_id.is_valid()) { + auth_3d_test_task->auth_3d_id.set_pause(true); test_window->UpdatePlayButton(); - auth_3d_test_task->auth_3d_id.set_req_frame(slider->GetValue()); + auth_3d_test_task->auth_3d_id.set_frame_req(slider->GetValue()); } } } @@ -1301,8 +1297,8 @@ void Auth3dTestWindow::SelectionButtonPlay::Callback(dw::SelectionListener::Call dw::Button* button = dynamic_cast(data->widget); if (button) { Auth3dTestWindow* test_window = dynamic_cast(button->parent_shell); - if (test_window && auth_3d_test_task->auth_3d_id.check_not_empty()) { - auth_3d_test_task->auth_3d_id.set_paused(!auth_3d_test_task->auth_3d_id.get_paused()); + if (test_window && auth_3d_test_task->auth_3d_id.is_valid()) { + auth_3d_test_task->auth_3d_id.set_pause(!auth_3d_test_task->auth_3d_id.get_pause()); test_window->UpdatePlayButton(); } } @@ -1317,16 +1313,16 @@ Auth3dTestWindow::SelectionButtonBegin::~SelectionButtonBegin() { } void Auth3dTestWindow::SelectionButtonBegin::Callback(dw::SelectionListener::CallbackData* data) { - if (!auth_3d_test_task->auth_3d_id.check_not_empty()) + if (!auth_3d_test_task->auth_3d_id.is_valid()) return; dw::Button* button = dynamic_cast(data->widget); if (button) { Auth3dTestWindow* test_window = dynamic_cast(button->parent_shell); - if (test_window && auth_3d_test_task->auth_3d_id.check_not_empty()) { - auth_3d_test_task->auth_3d_id.set_paused(false); + if (test_window && auth_3d_test_task->auth_3d_id.is_valid()) { + auth_3d_test_task->auth_3d_id.set_pause(false); test_window->UpdatePlayButton(); - auth_3d_test_task->auth_3d_id.set_req_frame(0.0f); + auth_3d_test_task->auth_3d_id.set_frame_req(0.0f); if (::snap_shot) { auth_3d_test_task->snap_shot = true; sub_140194880(0); @@ -1344,17 +1340,17 @@ Auth3dTestWindow::SelectionButtonEnd::~SelectionButtonEnd() { } void Auth3dTestWindow::SelectionButtonEnd::Callback(dw::SelectionListener::CallbackData* data) { - if (!auth_3d_test_task->auth_3d_id.check_not_empty()) + if (!auth_3d_test_task->auth_3d_id.is_valid()) return; dw::Button* button = dynamic_cast(data->widget); if (button) { Auth3dTestWindow* test_window = dynamic_cast(button->parent_shell); - if (test_window && auth_3d_test_task->auth_3d_id.check_not_empty()) { - auth_3d_test_task->auth_3d_id.set_paused(false); + if (test_window && auth_3d_test_task->auth_3d_id.is_valid()) { + auth_3d_test_task->auth_3d_id.set_pause(false); test_window->UpdatePlayButton(); - auth_3d_test_task->auth_3d_id.set_req_frame( - auth_3d_test_task->auth_3d_id.get_play_control_size()); + auth_3d_test_task->auth_3d_id.set_frame_req( + auth_3d_test_task->auth_3d_id.get_frame_size()); } } } @@ -1442,7 +1438,7 @@ Auth3dTestWindow::SelectionButtonCamReset::~SelectionButtonCamReset() { } void Auth3dTestWindow::SelectionButtonCamReset::Callback(dw::SelectionListener::CallbackData* data) { - cam_struct cam; + CameraParam cam; cam.set(rctx_ptr->camera); } @@ -1463,7 +1459,7 @@ Auth3dTestWindow::Auth3dTestWindow() { const char* nage_text; const char* obj_link_text; - const char* mirror_text; + const char* reverse_side_text; const char* snap_shot_text; const char* self_shadow_off_text; const char* black_mask_text; @@ -1471,7 +1467,7 @@ Auth3dTestWindow::Auth3dTestWindow() { if (dw::translate) { nage_text = u8"NAGE▽"; obj_link_text = u8"OBJ Link"; - mirror_text = u8"Mirror"; + reverse_side_text = u8"Reverse Side"; snap_shot_text = u8"ss capture"; self_shadow_off_text = u8"Self Shadow Off"; black_mask_text = u8"Black Mask"; @@ -1480,7 +1476,7 @@ Auth3dTestWindow::Auth3dTestWindow() { else { nage_text = u8"投▽"; obj_link_text = u8"OBJ連動"; - mirror_text = u8"左右逆"; + reverse_side_text = u8"左右逆"; snap_shot_text = u8"ss画撮"; self_shadow_off_text = u8"セルフ影OFF"; black_mask_text = u8"黒mask"; @@ -1595,9 +1591,9 @@ Auth3dTestWindow::Auth3dTestWindow() { repeat->AddSelectionListener(&repeat_listener); mirror = new dw::Button(this, dw::CHECKBOX); - mirror->SetText(mirror_text); - mirror->SetValue(auth_3d_test_task->mirror); - mirror_listener.callback = Auth3dTestWindow::LeftRightReverseCallback; + mirror->SetText(reverse_side_text); + mirror->SetValue(auth_3d_test_task->reverse_side); + mirror_listener.callback = Auth3dTestWindow::ReverseSideCallback; mirror->AddSelectionListener(&mirror_listener); dw::Composite* v79 = new dw::Composite(this); @@ -1729,8 +1725,8 @@ void Auth3dTestWindow::SetAuth3dCategoryIndex(size_t index) { void Auth3dTestWindow::SetAuth3dIndex(size_t index) { id_list->SetItemIndex(index); - if (auth_3d_test_task->auth_3d_id.check_not_empty()) { - auth_3d_test_task->auth_3d_id.set_paused(true); + if (auth_3d_test_task->auth_3d_id.is_valid()) { + auth_3d_test_task->auth_3d_id.set_pause(true); UpdatePlayButton(); } @@ -1755,8 +1751,8 @@ void Auth3dTestWindow::SetMaxFrame(float_t max_frame) { } void Auth3dTestWindow::UpdatePlayButton() { - if (auth_3d_test_task->auth_3d_id.check_not_empty()) - play->SetText(auth_3d_test_task->auth_3d_id.get_paused() ? " > " : "||"); + if (auth_3d_test_task->auth_3d_id.is_valid()) + play->SetText(auth_3d_test_task->auth_3d_id.get_pause() ? " > " : "||"); } void Auth3dTestWindow::CategoryCharaMenuInit(dw::Button* button, dw::Menu*& menu, @@ -1779,24 +1775,24 @@ void Auth3dTestWindow::CategoryCharaMenuInit(dw::Button* button, dw::Menu*& menu button->SetParentMenu(menu);*/ } -void Auth3dTestWindow::LeftRightReverseCallback(bool value) { - auth_3d_test_task->mirror = value; - if (auth_3d_test_task->auth_3d_id.check_not_empty()) { - auth_3d_test_task->auth_3d_id.set_req_frame(0.0f); - auth_3d_test_task->auth_3d_id.set_mirror(value); +void Auth3dTestWindow::ReverseSideCallback(bool value) { + auth_3d_test_task->reverse_side = value; + if (auth_3d_test_task->auth_3d_id.is_valid()) { + auth_3d_test_task->auth_3d_id.set_frame_req(0.0f); + auth_3d_test_task->auth_3d_id.set_reverse_side(value); } } void Auth3dTestWindow::PosCallback(bool value) { auth_3d_test_task->pos = value; - if (auth_3d_test_task->auth_3d_id.check_not_empty()) - auth_3d_test_task->auth_3d_id.set_pos(value); + if (auth_3d_test_task->auth_3d_id.is_valid()) + auth_3d_test_task->auth_3d_id.set_debug(value ? 1 : 0); } void Auth3dTestWindow::RepeatCallback(bool value) { auth_3d_test_task->repeat = value; - if (auth_3d_test_task->auth_3d_id.check_not_empty()) - auth_3d_test_task->auth_3d_id.set_repeat(value); + if (auth_3d_test_task->auth_3d_id.is_valid()) + auth_3d_test_task->auth_3d_id.set_looped(value); } SelectionButtonBool::SelectionButtonBool() { diff --git a/src/ReDIVA/data_test/auth_3d_test.hpp b/src/ReDIVA/data_test/auth_3d_test.hpp index 2b6091c9..add910ea 100644 --- a/src/ReDIVA/data_test/auth_3d_test.hpp +++ b/src/ReDIVA/data_test/auth_3d_test.hpp @@ -46,8 +46,8 @@ public: DataEventListener(); virtual ~DataEventListener() override; - virtual void OnLoad(::auth_3d_id& id) override; - virtual void OnPostCtrl(::auth_3d_id& id) override; + virtual void loadFinished(auth_3d_detail::Handle& in_handle) override; + virtual void playLoopJumpAfter(auth_3d_detail::Handle& in_handle) override; } data_event_listener; int32_t field_1C0; @@ -56,10 +56,10 @@ public: int32_t field_1CC; bool field_1D0; int32_t state; - ::auth_3d_id auth_3d_id; + auth_3d_detail::Handle auth_3d_id; int32_t auth_3d_uid; bool repeat; - bool mirror; + bool reverse_side; bool pos; bool snap_shot; int32_t snap_shot_state; @@ -69,9 +69,10 @@ public: bool stage_link_change; int32_t effcmn_obj_set_state; uint32_t effcmn_obj_set; + std::vector aet_set_handle; int32_t aet_state; int32_t aet_id; - auth_3d_detail::EventA2d::Aet aet; + aet::IdHandle aet_id_handle; bool plane_above_floor; bool stg_auth_display; bool stg_display; @@ -103,7 +104,7 @@ public: virtual bool dest() override; virtual void disp() override; - void DispAuth3dChara(::auth_3d_id& id); + void DispAuth3dChara(auth_3d_detail::Handle& in_handle); void DispChara(); void SetAuth3dId(); void SetAuth3dUid(int32_t value); diff --git a/src/ReDIVA/data_test/motion_test.cpp b/src/ReDIVA/data_test/motion_test.cpp index 4678aa4d..2689bfb5 100644 --- a/src/ReDIVA/data_test/motion_test.cpp +++ b/src/ReDIVA/data_test/motion_test.cpp @@ -614,16 +614,16 @@ bool DataTestMot::ctrl() { if (data.reset_cam) { data.reset_cam = false; - cam_struct cam; + CameraParam cam; if (data.field_A9) { cam.view_point = { -3.79f, 0.71f, 1.0f }; cam.interest = { 0.0f, 0.96f, 0.0f }; - cam.fov = 0.57268613576889f; + cam.v_fov = 0.57268613576889f; } else { cam.view_point = { 0.0f, 1.0f, 3.45f }; cam.interest = { 0.0f, 1.0f, 0.0f }; - cam.fov = 0.563171327114105f; + cam.v_fov = 0.563171327114105f; } cam.set(rctx_ptr->camera); } @@ -730,7 +730,7 @@ bool DataTestMotA3d::ctrl() { break; for (std::string& i : categories) - auth_3d_data_load_category(i.c_str()); + auth_3d_detail::category_load_req(i.c_str()); state = 4; } break; @@ -738,7 +738,7 @@ bool DataTestMotA3d::ctrl() { bool wait_load = false; for (std::string& i : categories) - if (!auth_3d_data_check_category_loaded(i.c_str())) + if (!auth_3d_detail::category_load_is_done(i.c_str())) wait_load |= true; if (wait_load) @@ -747,23 +747,23 @@ bool DataTestMotA3d::ctrl() { data_struct* aft_data = &data_list[DATA_AFT]; auth_3d_database* aft_auth_3d_db = &aft_data->data_ft.auth_3d_db; - for (auth_3d_id& i : auth_3d_ids) - i.read_file(aft_auth_3d_db); + for (auth_3d_detail::Handle& i : auth_3d_ids) + i.load_req(aft_auth_3d_db); state = 5; } break; case 5: { bool wait_load = false; - for (auth_3d_id& i : auth_3d_ids) - if (!i.check_loaded()) + for (auth_3d_detail::Handle& i : auth_3d_ids) + if (!i.load_is_done()) wait_load |= true; if (wait_load) break; - for (auth_3d_id& i : auth_3d_ids) - i.set_enable(true); + for (auth_3d_detail::Handle& i : auth_3d_ids) + i.set_enabled(true); state = 1; } break; @@ -833,12 +833,12 @@ void DataTestMotA3d::LoadAuth3d(std::string&& name) { if (uid == -1) return; - auth_3d_id id = auth_3d_id(uid, aft_auth_3d_db); - if (!id.check_not_empty()) + auth_3d_detail::Handle id = auth_3d_detail::Handle::create(uid, aft_auth_3d_db); + if (!id.is_valid()) return; - id.set_enable(false); - id.set_repeat(true); + id.set_enabled(false); + id.set_looped(true); auth_3d_ids.push_back(id); @@ -851,19 +851,19 @@ void DataTestMotA3d::LoadAuth3d(std::string&& name) { camera = false; } - std::string category(aft_auth_3d_db->uid[uid].category.c_str()); + std::string category(aft_auth_3d_db->uid[uid].category_name.c_str()); categories.push_back(category); auth_3d_data_get_obj_sets_from_category(category, obj_sets, aft_auth_3d_db, aft_obj_db); } void DataTestMotA3d::Reset() { for (std::string& i : categories) - auth_3d_data_unload_category(i.c_str()); + auth_3d_detail::category_free(i.c_str()); categories.clear(); - for (auth_3d_id& i : auth_3d_ids) - i.unload(rctx_ptr); + for (auth_3d_detail::Handle& i : auth_3d_ids) + i.destroy(rctx_ptr); auth_3d_ids.clear(); @@ -889,8 +889,8 @@ void DataTestMotA3d::Sync1pFrame() { if (get_pause()) frame -= dtm_mot_array[ROB_ID_1P].GetStep(); - for (auth_3d_id& i : auth_3d_ids) - i.set_req_frame(frame); + for (auth_3d_detail::Handle& i : auth_3d_ids) + i.set_frame_req(frame); } DtmMot::DtmMot() : rob_man(), motion(), assign(), rot(), pre_offset(), post_offset(), div(), @@ -1262,7 +1262,7 @@ bool DtmMot::ctrl() { if (rob_man->get_disp_on(rctrl) != display) rob_man->set_disp_on(rctrl, display); - rob_chr->rob_info_ctrl(); + rob_chr->ctrl_rob_info_main(); while (set_motion_index < set_motion.size()) { if (set_motion.data()[set_motion_index].motnum != uid) { @@ -3050,7 +3050,7 @@ static void motion_test_objset_load() { motion_test_objset.push_back(hnd_itm.obj_right.set_id); } - prj::sort_unique(motion_test_objset); + prj::sort_and_erase_non_unique(motion_test_objset); data_struct* aft_data = &data_list[DATA_AFT]; object_database* aft_obj_db = &aft_data->data_ft.obj_db; diff --git a/src/ReDIVA/data_test/motion_test.hpp b/src/ReDIVA/data_test/motion_test.hpp index 169a6159..d2425992 100644 --- a/src/ReDIVA/data_test/motion_test.hpp +++ b/src/ReDIVA/data_test/motion_test.hpp @@ -80,7 +80,7 @@ public: int32_t state; std::string auth_3d; std::vector categories; - std::vector auth_3d_ids; + std::vector auth_3d_ids; std::vector obj_sets; bool camera; diff --git a/src/ReDIVA/data_test/opd_test.cpp b/src/ReDIVA/data_test/opd_test.cpp index a5a8e6f5..960b5f04 100644 --- a/src/ReDIVA/data_test/opd_test.cpp +++ b/src/ReDIVA/data_test/opd_test.cpp @@ -217,7 +217,7 @@ void TaskDataTestOpd::BeginDataCreation() { opd_make_start_get_motion_ids(motion_ids); motion_ids.push_back(195); // CMN_MRA00_13_01 - prj::sort_unique(motion_ids); + prj::sort_and_erase_non_unique(motion_ids); OpdMakeManagerArgs args; args.motion_ids = &motion_ids; @@ -648,7 +648,7 @@ static void task_data_test_opd_dw_add_module() { data.modules.push_back(i.first); } break; } - prj::sort_unique(data.modules); + prj::sort_and_erase_non_unique(data.modules); } static void task_data_test_opd_dw_add_modules() { diff --git a/src/ReDIVA/data_test/rob_osage_test.cpp b/src/ReDIVA/data_test/rob_osage_test.cpp index 9efaeab9..ac01324e 100644 --- a/src/ReDIVA/data_test/rob_osage_test.cpp +++ b/src/ReDIVA/data_test/rob_osage_test.cpp @@ -2546,17 +2546,7 @@ void RobOsageTestDw::Collision::Init(dw::Composite* parent) { void RobOsageTestDw::Collision::Update() { if (element_comp) { - Composite* parent_comp = element_comp->parent_comp; - auto i_begin = parent_comp->controls.begin(); - auto i_end = parent_comp->controls.end(); - for (auto i = i_begin; i != i_end; ) - if (*i == element_comp) { - parent_comp->controls.erase(i); - break; - } - else - i++; - + prj::find_and_erase(element_comp->parent_comp->controls, element_comp); element_comp->Free(); element_comp = 0; } diff --git a/src/ReDIVA/data_view/auth_3d.cpp b/src/ReDIVA/data_view/auth_3d.cpp index b14c2b74..1260d41c 100644 --- a/src/ReDIVA/data_view/auth_3d.cpp +++ b/src/ReDIVA/data_view/auth_3d.cpp @@ -42,31 +42,38 @@ static const char* auth_3d_light_name[] = { DataViewAuth3D data_view_auth_3d; -static void data_view_auth_3d_window_auth_3d_key(auth_3d_key* k, const char* format, bool offset); -static void data_view_auth_3d_window_auth_3d_rgba(auth_3d_rgba* rgba, const char* format); -static void data_view_auth_3d_window_auth_3d_vec3(auth_3d_vec3* vec, const char* format); -static void data_view_auth_3d_window_auth_3d_model_transform(auth_3d_model_transform* mt); +static void data_view_auth_3d_window_auth_3d_fcurve( + const auth_3d_detail::Fcurve* fcv, const char* format, bool offset); +static void data_view_auth_3d_window_auth_3d_fcurve3f( + const auth_3d_detail::Fcurve3f* fcv3f, const char* format); +static void data_view_auth_3d_window_auth_3d_fcurve_color4f( + const auth_3d_detail::FcurveColor4f* fcv_col4f, const char* format); +static void data_view_auth_3d_window_auth_3d_model_transform( + const auth_3d_detail::ModelTransform* mt); -static void data_view_auth_3d_window_auth_3d_ambient(auth_3d_ambient* a); -static void data_view_auth_3d_window_auth_3d_camera_auxiliary(auth_3d_camera_auxiliary* ca); -static void data_view_auth_3d_window_auth_3d_camera_root(auth_3d_camera_root* cr, size_t index); -static void data_view_auth_3d_window_auth_3d_chara(auth_3d_chara* c); -static void data_view_auth_3d_window_auth_3d_curve(auth_3d_curve* c); -static void data_view_auth_3d_window_auth_3d_dof(auth_3d_dof* d); -static void data_view_auth_3d_window_auth_3d_fog(auth_3d_fog* f); -static void data_view_auth_3d_window_auth_3d_light(auth_3d_light* l); -static void data_view_auth_3d_window_auth_3d_m_object_hrc(auth_3d_m_object_hrc* moh); -static void data_view_auth_3d_window_auth_3d_material_list(auth_3d_material_list* ml); -static void data_view_auth_3d_window_auth_3d_object(auth_3d_object* o); -static void data_view_auth_3d_window_auth_3d_object_curve(auth_3d_object_curve* oc, const char* format); -static void data_view_auth_3d_window_auth_3d_object_hrc(auth_3d_object_hrc* oh); -static void data_view_auth_3d_window_auth_3d_object_instance(auth_3d_object_instance* oi); -static void data_view_auth_3d_window_auth_3d_object_model_transform(auth_3d_object_model_transform* omt); -static void data_view_auth_3d_window_auth_3d_object_node(auth_3d_object_node* on); -static void data_view_auth_3d_window_auth_3d_object_texture_pattern(auth_3d_object_texture_pattern* otp); -static void data_view_auth_3d_window_auth_3d_object_texture_transform(auth_3d_object_texture_transform* ott); -static void data_view_auth_3d_window_auth_3d_point(auth_3d_point* p); -static void data_view_auth_3d_window_auth_3d_post_process(auth_3d_post_process* pp); +static void data_view_auth_3d_window_auth_3d_ambient(auth_3d_detail::Ambient* a); +static void data_view_auth_3d_window_auth_3d_auth_2d(auth_3d_detail::Auth2d* a2); +static void data_view_auth_3d_window_auth_3d_camera_auxiliary(auth_3d_detail::CameraAuxiliary* ca); +static void data_view_auth_3d_window_auth_3d_camera_root(auth_3d_detail::CameraRoot* cr, size_t index); +static void data_view_auth_3d_window_auth_3d_chara(auth_3d_detail::Chara* c); +static void data_view_auth_3d_window_auth_3d_curve(auth_3d_detail::Curve* c); +static void data_view_auth_3d_window_auth_3d_curve_with_offset( + auth_3d_detail::CurveWithOffset* oc, const char* format); +static void data_view_auth_3d_window_auth_3d_dof(auth_3d_detail::Dof* d); +static void data_view_auth_3d_window_auth_3d_fog(auth_3d_detail::Fog* f); +static void data_view_auth_3d_window_auth_3d_light(auth_3d_detail::Light* l); +static void data_view_auth_3d_window_auth_3d_m_object_hrc(auth_3d_detail::MultiHierarchyObject* moh); +static void data_view_auth_3d_window_auth_3d_material_list(auth_3d_detail::MaterialList* ml); +static void data_view_auth_3d_window_auth_3d_motion(auth_3d_detail::Motion* m); +static void data_view_auth_3d_window_auth_3d_object(auth_3d_detail::Object* o); +static void data_view_auth_3d_window_auth_3d_object_hrc(auth_3d_detail::HierarchyObject* ho); +static void data_view_auth_3d_window_auth_3d_object_instance(auth_3d_detail::ObjectInstance* oi); +static void data_view_auth_3d_window_auth_3d_motion_transform(auth_3d_detail::MotionTransform* mt); +static void data_view_auth_3d_window_auth_3d_object_node(auth_3d_detail::TransformNode* tn); +static void data_view_auth_3d_window_auth_3d_texture(auth_3d_detail::Texture* t); +static void data_view_auth_3d_window_auth_3d_texture_transform(auth_3d_detail::TextureTransform* tt); +static void data_view_auth_3d_window_auth_3d_point(auth_3d_detail::Point* p); +static void data_view_auth_3d_window_auth_3d_post_process(auth_3d_detail::PostProcess* pp); void data_view_auth_3d_init() { data_view_auth_3d.open("DATA_VIEW_AUTH_3D", app::TASK_PRIO_LOW); @@ -128,12 +135,12 @@ void DataViewAuth3D::window() { char buf[0x200]; for (size_t i = 0; i < AUTH_3D_DATA_COUNT; i++) { - auth_3d* auth = &auth_3d_data->data[i]; - if (auth->id == -1) + auth_3d_detail::Scene* scene = &auth_3d_detail::g_manager->scene_buffer[i]; + if (scene->my_handle == -1) continue; - size_t str_len = min_def(sizeof(buf) - 1, auth->file_name.size()); - memcpy(buf, auth->file_name.c_str(), str_len); + size_t str_len = min_def(sizeof(buf) - 1, scene->file_name.size()); + memcpy(buf, scene->file_name.c_str(), str_len); buf[str_len] = 0; if (str_len >= 5 && !memcmp(&buf[str_len - 5], ".a3da", 6)) @@ -141,14 +148,14 @@ void DataViewAuth3D::window() { tree_node_flags = tree_node_base_flags; - bool visible = auth->enable && auth->visible; - if (!visible) + bool visibility = scene->M_is_enabled && scene->M_is_visible; + if (!visibility) ImGui::PushStyleColor(ImGuiCol_Text, 0xFF888888); - ImGui::PushID(auth->id); - if (!ImGui::TreeNodeEx(auth, tree_node_flags, - "ID: %5d; Frame: %5d; File: %s", auth->id & 0x7FFF, (int32_t)prj::roundf(auth->frame), buf)) { + ImGui::PushID(scene->my_handle); + if (!ImGui::TreeNodeEx(scene, tree_node_flags, "ID: %5d; Frame: %5d; File: %s", + scene->my_handle & 0x7FFF, (int32_t)prj::roundf(scene->M_frame), buf)) { ImGui::PopID(); - if (!visible) + if (!visibility) ImGui::PopStyleColor(); continue; } @@ -156,118 +163,121 @@ void DataViewAuth3D::window() { tree_node_flags = tree_node_base_flags; tree_node_flags |= ImGuiTreeNodeFlags_DefaultOpen; - if (auth->rob_id != ROB_ID_NULL) - ImGui::Text("Chara: %d", auth->rob_id + 1); + int32_t rob_id = scene->get_assign_rob_id(); + if (rob_id != ROB_ID_NULL) + ImGui::Text("Chara: %d", rob_id + 1); else ImGui::Text("Chara: None"); - if (auth->src_chara != auth->dst_chara) + if (scene->M_cn_src != scene->M_cn_dst) ImGui::Text("Chara Replace: %s/%s", - get_char_id_str((CHARA_NUM)auth->src_chara), - get_char_id_str((CHARA_NUM)auth->dst_chara)); + get_char_id_str((CHARA_NUM)scene->M_cn_src), + get_char_id_str((CHARA_NUM)scene->M_cn_dst)); - if (auth->ambient.size() > 0 + // MGF + if (scene->ambient_list.size() > 0 && ImGui::TreeNodeEx("Ambient", tree_node_flags)) { - for (auth_3d_ambient& l : auth->ambient) + for (auth_3d_detail::Ambient& l : scene->ambient_list) data_view_auth_3d_window_auth_3d_ambient(&l); ImGui::TreePop(); } - if (auth->auth_2d.size() > 0 + if (scene->auth_2d_list.size() > 0 && ImGui::TreeNodeEx("Auth 2D", tree_node_flags)) { - for (std::string& l : auth->auth_2d) - ImGui::Text("%s", l.c_str()); + for (auth_3d_detail::Auth2d& l : scene->auth_2d_list) + data_view_auth_3d_window_auth_3d_auth_2d(&l); ImGui::TreePop(); } - data_view_auth_3d_window_auth_3d_camera_auxiliary(&auth->camera_auxiliary); + data_view_auth_3d_window_auth_3d_camera_auxiliary(&scene->camera_auxiliary); - if (auth->camera_root.size() > 1 + if (scene->camera_root_list.size() > 1 && ImGui::TreeNodeEx("Camera Root", tree_node_flags)) { - for (auth_3d_camera_root& l : auth->camera_root) - data_view_auth_3d_window_auth_3d_camera_root(&l, &l - auth->camera_root.data()); + for (auth_3d_detail::CameraRoot& l : scene->camera_root_list) + data_view_auth_3d_window_auth_3d_camera_root(&l, &l - scene->camera_root_list.data()); ImGui::TreePop(); } - else if (auth->camera_root.size() == 1) - data_view_auth_3d_window_auth_3d_camera_root(&auth->camera_root[0], -1); + else if (scene->camera_root_list.size() == 1) + data_view_auth_3d_window_auth_3d_camera_root(&scene->camera_root_list[0], -1); - if (auth->chara.size() > 0 + if (scene->chara_list.size() > 0 && ImGui::TreeNodeEx("Chara", tree_node_flags)) { - for (auth_3d_chara& l : auth->chara) + for (auth_3d_detail::Chara& l : scene->chara_list) data_view_auth_3d_window_auth_3d_chara(&l); ImGui::TreePop(); } - if (auth->curve.size() > 0 + if (scene->curve_list.size() > 0 && ImGui::TreeNodeEx("Curve", tree_node_flags)) { - for (auth_3d_curve& l : auth->curve) + for (auth_3d_detail::Curve& l : scene->curve_list) data_view_auth_3d_window_auth_3d_curve(&l); ImGui::TreePop(); } - data_view_auth_3d_window_auth_3d_dof(&auth->dof); + data_view_auth_3d_window_auth_3d_dof(&scene->dof); - if (auth->fog.size() > 0 + if (scene->fog_list.size() > 0 && ImGui::TreeNodeEx("Fog", tree_node_flags)) { - for (auth_3d_fog& l : auth->fog) + for (auth_3d_detail::Fog& l : scene->fog_list) data_view_auth_3d_window_auth_3d_fog(&l); ImGui::TreePop(); } - if (auth->light.size() > 0 + if (scene->light_list.size() > 0 && ImGui::TreeNodeEx("Light", tree_node_flags)) { - for (auth_3d_light& l : auth->light) + for (auth_3d_detail::Light& l : scene->light_list) data_view_auth_3d_window_auth_3d_light(&l); ImGui::TreePop(); } - if (auth->m_object_hrc_list.size() > 0 + if (scene->m_object_hrc_list.size() > 0 && ImGui::TreeNodeEx("M Object HRC", tree_node_flags)) { - for (auth_3d_m_object_hrc*& l : auth->m_object_hrc_list) + for (auth_3d_detail::MultiHierarchyObject*& l : scene->m_object_hrc_list) data_view_auth_3d_window_auth_3d_m_object_hrc(l); ImGui::TreePop(); } - if (auth->material_list.size() > 0 + // X/XHD + if (scene->material_list.size() > 0 && ImGui::TreeNodeEx("Material List", tree_node_flags)) { - for (auth_3d_material_list& l : auth->material_list) + for (auth_3d_detail::MaterialList& l : scene->material_list) data_view_auth_3d_window_auth_3d_material_list(&l); ImGui::TreePop(); } - if (auth->motion.size() > 0 + if (scene->motion_list.size() > 0 && ImGui::TreeNodeEx("Motion", tree_node_flags)) { - for (std::string& l : auth->motion) - ImGui::Text("%s", l.c_str()); + for (auth_3d_detail::Motion& l : scene->motion_list) + data_view_auth_3d_window_auth_3d_motion(&l); ImGui::TreePop(); } - if (auth->object_list.size() > 0 + if (scene->object_list.size() > 0 && ImGui::TreeNodeEx("Object", tree_node_flags)) { - for (auth_3d_object*& l : auth->object_list) + for (auth_3d_detail::Object*& l : scene->object_list) data_view_auth_3d_window_auth_3d_object(l); ImGui::TreePop(); } - if (auth->object_hrc_list.size() > 0 + if (scene->object_hrc_list.size() > 0 && ImGui::TreeNodeEx("Object HRC", tree_node_flags)) { - for (auth_3d_object_hrc*& l : auth->object_hrc_list) + for (auth_3d_detail::HierarchyObject*& l : scene->object_hrc_list) data_view_auth_3d_window_auth_3d_object_hrc(l); ImGui::TreePop(); } - if (auth->point.size() > 0 + if (scene->point_list.size() > 0 && ImGui::TreeNodeEx("Point", tree_node_flags)) { - for (auth_3d_point& l : auth->point) + for (auth_3d_detail::Point& l : scene->point_list) data_view_auth_3d_window_auth_3d_point(&l); ImGui::TreePop(); } - data_view_auth_3d_window_auth_3d_post_process(&auth->post_process); + data_view_auth_3d_window_auth_3d_post_process(&scene->post_process); ImGui::TreePop(); ImGui::PopID(); - if (!visible) + if (!visibility) ImGui::PopStyleColor(); } @@ -275,8 +285,9 @@ void DataViewAuth3D::window() { ImGui::End(); } -static void data_view_auth_3d_window_auth_3d_key(auth_3d_key* k, const char* format, bool offset) { - if (!k) +static void data_view_auth_3d_window_auth_3d_fcurve( + const auth_3d_detail::Fcurve* fcv, const char* format, bool offset) { + if (!fcv) return; if (offset) { @@ -292,50 +303,53 @@ static void data_view_auth_3d_window_auth_3d_key(auth_3d_key* k, const char* for ImGui::SameLine(); } - switch (k->type) { - case A3DA_KEY_NONE: + switch (fcv->m_type) { + case auth_3d_detail::FC_TYPE_STATIC_0: default: ImGui::Text("V: %#.6g", 0.0f); break; - case A3DA_KEY_STATIC: - ImGui::Text("V: %#.6g", k->value); + case auth_3d_detail::FC_TYPE_STATIC_DATA: + ImGui::Text("V: %#.6g", fcv->m_static_value); break; - case A3DA_KEY_LINEAR: - case A3DA_KEY_HERMITE: - case A3DA_KEY_HOLD: - ImGui::Text("F: %5g; V: %#.6g", k->frame, k->value_interp); + case auth_3d_detail::FC_TYPE_LINEAR: + case auth_3d_detail::FC_TYPE_HERMITE: + case auth_3d_detail::FC_TYPE_NO_INTERPOLATION: + ImGui::Text("F: %5g; V: %#.6g", fcv->m_frame, fcv->m_value); break; } } -static void data_view_auth_3d_window_auth_3d_rgba(auth_3d_rgba* rgba, const char* format) { - if (!rgba || !rgba->flags || !format) - return; - - ImGui::Text(format); - if (rgba->flags & A3DA_RGBA_R) - data_view_auth_3d_window_auth_3d_key(&rgba->r, "R:", true); - if (rgba->flags & A3DA_RGBA_G) - data_view_auth_3d_window_auth_3d_key(&rgba->g, "G:", true); - if (rgba->flags & A3DA_RGBA_B) - data_view_auth_3d_window_auth_3d_key(&rgba->b, "B:", true); - if (rgba->flags & A3DA_RGBA_A) - data_view_auth_3d_window_auth_3d_key(&rgba->a, "A:", true); -} - -static void data_view_auth_3d_window_auth_3d_vec3(auth_3d_vec3* vec, const char* format) { - if (!vec || !format) +static void data_view_auth_3d_window_auth_3d_fcurve3f( + const auth_3d_detail::Fcurve3f* fcv3f, const char* format) { + if (!fcv3f || !format) return; ImGui::Text(format); ImGui::PushStyleColor(ImGuiCol_WindowBg, 0xFF404040); - data_view_auth_3d_window_auth_3d_key(&vec->x, "X:", true); - data_view_auth_3d_window_auth_3d_key(&vec->y, "Y:", true); - data_view_auth_3d_window_auth_3d_key(&vec->z, "Z:", true); + data_view_auth_3d_window_auth_3d_fcurve(&fcv3f->x, "X:", true); + data_view_auth_3d_window_auth_3d_fcurve(&fcv3f->y, "Y:", true); + data_view_auth_3d_window_auth_3d_fcurve(&fcv3f->z, "Z:", true); ImGui::PopStyleColor(); } -static void data_view_auth_3d_window_auth_3d_model_transform(auth_3d_model_transform* mt) { +static void data_view_auth_3d_window_auth_3d_fcurve_color4f( + const auth_3d_detail::FcurveColor4f* fcv_col4f, const char* format) { + if (!fcv_col4f || !(fcv_col4f->has_r || fcv_col4f->has_g || fcv_col4f->has_b || fcv_col4f->has_a) || !format) + return; + + ImGui::Text(format); + if (fcv_col4f->has_r) + data_view_auth_3d_window_auth_3d_fcurve(&fcv_col4f->r, "R:", true); + if (fcv_col4f->has_g) + data_view_auth_3d_window_auth_3d_fcurve(&fcv_col4f->g, "G:", true); + if (fcv_col4f->has_b) + data_view_auth_3d_window_auth_3d_fcurve(&fcv_col4f->b, "B:", true); + if (fcv_col4f->has_a) + data_view_auth_3d_window_auth_3d_fcurve(&fcv_col4f->a, "A:", true); +} + +static void data_view_auth_3d_window_auth_3d_model_transform( + const auth_3d_detail::ModelTransform* mt) { if (!mt) return; @@ -347,17 +361,18 @@ static void data_view_auth_3d_window_auth_3d_model_transform(auth_3d_model_trans if (!ImGui::TreeNodeEx(mt, tree_node_flags, "Model Transform")) return; - data_view_auth_3d_window_auth_3d_vec3(&mt->translation, "Translation"); - data_view_auth_3d_window_auth_3d_vec3(&mt->rotation, "Rotation"); - data_view_auth_3d_window_auth_3d_vec3(&mt->scale, "Scale"); + data_view_auth_3d_window_auth_3d_fcurve3f(&mt->fcurve_translation, "Translation"); + data_view_auth_3d_window_auth_3d_fcurve3f(&mt->fcurve_rotation, "Rotation"); + data_view_auth_3d_window_auth_3d_fcurve3f(&mt->fcurve_scale, "Scale"); ImGui::Text("Visibility"); - data_view_auth_3d_window_auth_3d_key(&mt->visibility, 0, true); + data_view_auth_3d_window_auth_3d_fcurve(&mt->fcurve_visibility, 0, true); ImGui::TreePop(); } -static void data_view_auth_3d_window_auth_3d_ambient(auth_3d_ambient* a) { - if (!a || !a->flags) +// MGF +static void data_view_auth_3d_window_auth_3d_ambient(auth_3d_detail::Ambient* a) { + if (!a || !a->flag) return; ImGuiTreeNodeFlags tree_node_flags = 0; @@ -368,15 +383,30 @@ static void data_view_auth_3d_window_auth_3d_ambient(auth_3d_ambient* a) { if (!ImGui::TreeNodeEx(a, tree_node_flags, a->name.c_str())) return; - if (a->flags & A3DA_AMBIENT_LIGHT_DIFFUSE) - data_view_auth_3d_window_auth_3d_rgba(&a->light_diffuse, "Light Diffuse"); - if (a->flags & A3DA_AMBIENT_RIM_LIGHT_DIFFUSE) - data_view_auth_3d_window_auth_3d_rgba(&a->rim_light_diffuse, "Rim Light Diffuse"); + if (a->has_light_diffuse()) + data_view_auth_3d_window_auth_3d_fcurve_color4f(&a->light_diffuse.fcurve_color, "Light Diffuse"); + if (a->has_rim_light_diffuse()) + data_view_auth_3d_window_auth_3d_fcurve_color4f(&a->rim_light_diffuse.fcurve_color, "Rim Light Diffuse"); ImGui::TreePop(); } -static void data_view_auth_3d_window_auth_3d_camera_auxiliary(auth_3d_camera_auxiliary* ca) { - if (!ca || !ca->flags) +static void data_view_auth_3d_window_auth_3d_auth_2d(auth_3d_detail::Auth2d* a2) { + if (!a2) + return; + + ImGuiTreeNodeFlags tree_node_flags = 0; + tree_node_flags |= ImGuiTreeNodeFlags_OpenOnDoubleClick; + tree_node_flags |= ImGuiTreeNodeFlags_OpenOnArrow; + tree_node_flags |= ImGuiTreeNodeFlags_SpanAvailWidth; + + if (!ImGui::TreeNodeEx(a2, tree_node_flags, a2->name.c_str())) + return; + + ImGui::TreePop(); +} + +static void data_view_auth_3d_window_auth_3d_camera_auxiliary(auth_3d_detail::CameraAuxiliary* ca) { + if (!ca || !ca->flag) return; ImGuiTreeNodeFlags tree_node_flags = 0; @@ -388,34 +418,41 @@ static void data_view_auth_3d_window_auth_3d_camera_auxiliary(auth_3d_camera_aux if (!ImGui::TreeNodeEx(ca, tree_node_flags, "Camera Auxiliary")) return; - if (ca->flags & AUTH_3D_CAMERA_AUXILIARY_AUTO_EXPOSURE) { - ImGui::Text("Auto Exposure"); - data_view_auth_3d_window_auth_3d_key(&ca->auto_exposure, 0, true); - } - if (ca->flags & AUTH_3D_CAMERA_AUXILIARY_EXPOSURE) { + if (ca->has_exposure()) { ImGui::Text("Exposure"); - data_view_auth_3d_window_auth_3d_key(&ca->exposure, 0, true); + data_view_auth_3d_window_auth_3d_fcurve(&ca->fcurve_exposure, 0, true); } - if (ca->flags & AUTH_3D_CAMERA_AUXILIARY_EXPOSURE_RATE) { + + // F/F2?X/XHD + if (ca->has_exposure_rate()) { ImGui::Text("Exposure Rate"); - data_view_auth_3d_window_auth_3d_key(&ca->exposure_rate, 0, true); + data_view_auth_3d_window_auth_3d_fcurve(&ca->fcurve_exposure_rate, 0, true); } - if (ca->flags & AUTH_3D_CAMERA_AUXILIARY_GAMMA) { + + if (ca->has_gamma()) { ImGui::Text("Gamma"); - data_view_auth_3d_window_auth_3d_key(&ca->gamma, 0, true); + data_view_auth_3d_window_auth_3d_fcurve(&ca->fcurve_gamma, 0, true); } - if (ca->flags & AUTH_3D_CAMERA_AUXILIARY_GAMMA_RATE) { + + // F/F2?X/XHD + if (ca->has_gamma_rate()) { ImGui::Text("Gamma Rate"); - data_view_auth_3d_window_auth_3d_key(&ca->gamma_rate, 0, true); + data_view_auth_3d_window_auth_3d_fcurve(&ca->fcurve_gamma_rate, 0, true); } - if (ca->flags & AUTH_3D_CAMERA_AUXILIARY_SATURATE) { + + if (ca->has_saturate()) { ImGui::Text("Saturate"); - data_view_auth_3d_window_auth_3d_key(&ca->saturate, 0, true); + data_view_auth_3d_window_auth_3d_fcurve(&ca->fcurve_saturate, 0, true); + } + + if (ca->has_auto_exposure()) { + ImGui::Text("Auto Exposure"); + data_view_auth_3d_window_auth_3d_fcurve(&ca->fcurve_auto_exposure, 0, true); } ImGui::TreePop(); } -static void data_view_auth_3d_window_auth_3d_camera_root(auth_3d_camera_root* cr, size_t index) { +static void data_view_auth_3d_window_auth_3d_camera_root(auth_3d_detail::CameraRoot* cr, size_t index) { if (!cr) return; @@ -430,38 +467,38 @@ static void data_view_auth_3d_window_auth_3d_camera_root(auth_3d_camera_root* cr index == -1 ? "Camera Root" : "%d", (int32_t)index)) return; - data_view_auth_3d_window_auth_3d_vec3(&cr->interest.translation, "Interest"); data_view_auth_3d_window_auth_3d_model_transform(&cr->model_transform); - auth_3d_camera_root_view_point* vp = &cr->view_point; - data_view_auth_3d_window_auth_3d_vec3(&vp->model_transform.translation, "View Point"); + auth_3d_detail::CameraInterest* intr = &cr->interest; + data_view_auth_3d_window_auth_3d_fcurve3f(&intr->model_transform.fcurve_translation, "Interest"); - ImGui::Text("Aspect"); - ImGui::Text(" %#.6g", vp->aspect); + auth_3d_detail::CameraViewPoint* vp = &cr->view_point; + data_view_auth_3d_window_auth_3d_fcurve3f(&vp->model_transform.fcurve_translation, "View Point"); - if (vp->flags & AUTH_3D_CAMERA_ROOT_VIEW_POINT_FOV) { + ImGui::Text("Roll"); + data_view_auth_3d_window_auth_3d_fcurve(&vp->roll, 0, true); + + if (vp->has_fov) { ImGui::Text(vp->fov_is_horizontal ? "FOV Horizontal" : "FOV"); - data_view_auth_3d_window_auth_3d_key(&vp->fov, 0, true); + data_view_auth_3d_window_auth_3d_fcurve(&vp->fov, 0, true); + + ImGui::Text("Aspect"); + ImGui::Text(" %#.6g", vp->aspect); } else { + ImGui::Text("Focal Length"); + data_view_auth_3d_window_auth_3d_fcurve(&vp->focal_length, 0, true); + ImGui::Text("Camera Aperture Width"); ImGui::Text(" %#.6g", vp->camera_aperture_w); ImGui::Text("Camera Aperture Height"); ImGui::Text(" %#.6g", vp->camera_aperture_h); - - ImGui::Text("Focal Length"); - data_view_auth_3d_window_auth_3d_key(&vp->focal_length, 0, true); - } - - if (vp->flags & AUTH_3D_CAMERA_ROOT_VIEW_POINT_ROLL) { - ImGui::Text("Roll"); - data_view_auth_3d_window_auth_3d_key(&vp->roll, 0, true); } ImGui::TreePop(); } -static void data_view_auth_3d_window_auth_3d_chara(auth_3d_chara* c) { +static void data_view_auth_3d_window_auth_3d_chara(auth_3d_detail::Chara* c) { if (!c) return; @@ -477,7 +514,7 @@ static void data_view_auth_3d_window_auth_3d_chara(auth_3d_chara* c) { ImGui::TreePop(); } -static void data_view_auth_3d_window_auth_3d_curve(auth_3d_curve* c) { +static void data_view_auth_3d_window_auth_3d_curve(auth_3d_detail::Curve* c) { if (!c) return; @@ -489,11 +526,29 @@ static void data_view_auth_3d_window_auth_3d_curve(auth_3d_curve* c) { if (!ImGui::TreeNodeEx(c, tree_node_flags, c->name.c_str())) return; - data_view_auth_3d_window_auth_3d_key(&c->curve, 0, false); + data_view_auth_3d_window_auth_3d_fcurve(&c->curve, 0, false); ImGui::TreePop(); } -static void data_view_auth_3d_window_auth_3d_dof(auth_3d_dof* d) { +static void data_view_auth_3d_window_auth_3d_curve_with_offset( + auth_3d_detail::CurveWithOffset* oc, const char* format) { + if (!oc || !oc->fcurve_ptr || !format) + return; + + ImGuiTreeNodeFlags tree_node_flags = 0; + tree_node_flags |= ImGuiTreeNodeFlags_DefaultOpen; + tree_node_flags |= ImGuiTreeNodeFlags_OpenOnDoubleClick; + tree_node_flags |= ImGuiTreeNodeFlags_OpenOnArrow; + tree_node_flags |= ImGuiTreeNodeFlags_SpanAvailWidth; + + if (!ImGui::TreeNodeEx(oc, tree_node_flags, format)) + return; + + data_view_auth_3d_window_auth_3d_curve(oc->fcurve_ptr); + ImGui::TreePop(); +} + +static void data_view_auth_3d_window_auth_3d_dof(auth_3d_detail::Dof* d) { if (!d || !d->has_dof) return; @@ -503,7 +558,7 @@ static void data_view_auth_3d_window_auth_3d_dof(auth_3d_dof* d) { tree_node_flags |= ImGuiTreeNodeFlags_OpenOnArrow; tree_node_flags |= ImGuiTreeNodeFlags_SpanAvailWidth; - bool enable = fabsf(d->model_transform.rotation_value.z) > 0.000001f; + bool enable = fabsf(d->model_transform.rotation.z) > 0.000001f; if (!enable) ImGui::PushStyleColor(ImGuiCol_Text, 0xFF888888); if (!ImGui::TreeNodeEx(d, tree_node_flags, "DOF")) { @@ -512,35 +567,35 @@ static void data_view_auth_3d_window_auth_3d_dof(auth_3d_dof* d) { return; } - auth_3d_model_transform* mt = &d->model_transform; + auth_3d_detail::ModelTransform* mt = &d->model_transform; - data_view_auth_3d_window_auth_3d_vec3(&mt->translation, "Position"); + data_view_auth_3d_window_auth_3d_fcurve3f(&mt->fcurve_translation, "Position"); ImGui::Text("Focus Range"); - data_view_auth_3d_window_auth_3d_key(&mt->scale.x, 0, true); + data_view_auth_3d_window_auth_3d_fcurve(&mt->fcurve_scale.x, 0, true); ImGui::Text("??? (Scale Y)"); - data_view_auth_3d_window_auth_3d_key(&mt->scale.y, 0, true); + data_view_auth_3d_window_auth_3d_fcurve(&mt->fcurve_scale.y, 0, true); ImGui::Text("??? (Scale Z)"); - data_view_auth_3d_window_auth_3d_key(&mt->scale.z, 0, true); + data_view_auth_3d_window_auth_3d_fcurve(&mt->fcurve_scale.z, 0, true); ImGui::Text("Fuzzing Range"); - data_view_auth_3d_window_auth_3d_key(&mt->rotation.x, 0, true); + data_view_auth_3d_window_auth_3d_fcurve(&mt->fcurve_rotation.x, 0, true); ImGui::Text("Ratio"); - data_view_auth_3d_window_auth_3d_key(&mt->rotation.y, 0, true); + data_view_auth_3d_window_auth_3d_fcurve(&mt->fcurve_rotation.y, 0, true); ImGui::Text("Enable"); - data_view_auth_3d_window_auth_3d_key(&mt->rotation.z, 0, true); + data_view_auth_3d_window_auth_3d_fcurve(&mt->fcurve_rotation.z, 0, true); ImGui::TreePop(); if (!enable) ImGui::PopStyleColor(); } -static void data_view_auth_3d_window_auth_3d_fog(auth_3d_fog* f) { - if (!f || !f->flags) +static void data_view_auth_3d_window_auth_3d_fog(auth_3d_detail::Fog* f) { + if (!f || !f->flag) return; ImGuiTreeNodeFlags tree_node_flags = 0; @@ -551,28 +606,28 @@ static void data_view_auth_3d_window_auth_3d_fog(auth_3d_fog* f) { if (!ImGui::TreeNodeEx(f, tree_node_flags, auth_3d_fog_name[f->id])) return; - if (f->flags & AUTH_3D_FOG_COLOR) - data_view_auth_3d_window_auth_3d_rgba(&f->color, "Color"); - - if (f->flags & AUTH_3D_FOG_DENSITY) { + if (f->flag & auth_3d_detail::Fog::FLAG_DENSITY) { ImGui::Text("Density"); - data_view_auth_3d_window_auth_3d_key(&f->density, 0, true); + data_view_auth_3d_window_auth_3d_fcurve(&f->fcurve_density, 0, true); } - if (f->flags & AUTH_3D_FOG_END) { - ImGui::Text("End"); - data_view_auth_3d_window_auth_3d_key(&f->end, 0, true); - } - - if (f->flags & AUTH_3D_FOG_START) { + if (f->flag & auth_3d_detail::Fog::FLAG_START) { ImGui::Text("Start"); - data_view_auth_3d_window_auth_3d_key(&f->start, 0, true); + data_view_auth_3d_window_auth_3d_fcurve(&f->fcurve_start, 0, true); } + + if (f->flag & auth_3d_detail::Fog::FLAG_END) { + ImGui::Text("End"); + data_view_auth_3d_window_auth_3d_fcurve(&f->fcurve_end, 0, true); + } + + if (f->flag & auth_3d_detail::Fog::FLAG_COLOR) + data_view_auth_3d_window_auth_3d_fcurve_color4f(&f->color.fcurve_color, "Color"); ImGui::TreePop(); } -static void data_view_auth_3d_window_auth_3d_light(auth_3d_light* l) { - if (!l || !l->flags) +static void data_view_auth_3d_window_auth_3d_light(auth_3d_detail::Light* l) { + if (!l || !l->flag) return; ImGuiTreeNodeFlags tree_node_flags = 0; @@ -583,62 +638,67 @@ static void data_view_auth_3d_window_auth_3d_light(auth_3d_light* l) { if (!ImGui::TreeNodeEx(l, tree_node_flags, auth_3d_light_name[l->id])) return; - if (l->flags & AUTH_3D_LIGHT_AMBIENT) - data_view_auth_3d_window_auth_3d_rgba(&l->ambient, "Ambient"); + data_view_auth_3d_window_auth_3d_fcurve3f(&l->position.fcurve_translation, "Position"); + data_view_auth_3d_window_auth_3d_fcurve3f(&l->spot_direction.fcurve_translation, "Spot Direction"); - if (l->flags & AUTH_3D_LIGHT_CONE_ANGLE) { - ImGui::Text("Cone Angle"); - data_view_auth_3d_window_auth_3d_key(&l->cone_angle, 0, true); - } + if (l->flag & auth_3d_detail::Light::FLAG_DIFFUSE) + data_view_auth_3d_window_auth_3d_fcurve_color4f(&l->diffuse.fcurve_color, "Diffuse"); - if (l->flags & AUTH_3D_LIGHT_CONSTANT) { + if (l->flag & auth_3d_detail::Light::FLAG_AMBIENT) + data_view_auth_3d_window_auth_3d_fcurve_color4f(&l->ambient.fcurve_color, "Ambient"); + + if (l->flag & auth_3d_detail::Light::FLAG_SPECULAR) + data_view_auth_3d_window_auth_3d_fcurve_color4f(&l->specular.fcurve_color, "Specular"); + + if (l->flag & auth_3d_detail::Light::FLAG_TONE_CURVE) + data_view_auth_3d_window_auth_3d_fcurve_color4f(&l->tone_curve.fcurve_color, "Tone Curve"); + + // XHD + if (l->flag & auth_3d_detail::Light::FLAG_CONSTANT) { ImGui::Text("Constant"); - data_view_auth_3d_window_auth_3d_key(&l->constant, 0, true); + data_view_auth_3d_window_auth_3d_fcurve(&l->fcurve_constant, 0, true); } - if (l->flags & AUTH_3D_LIGHT_DIFFUSE) - data_view_auth_3d_window_auth_3d_rgba(&l->diffuse, "Diffuse"); - - if (l->flags & AUTH_3D_LIGHT_DROP_OFF) { - ImGui::Text("Drop Off"); - data_view_auth_3d_window_auth_3d_key(&l->drop_off, 0, true); - } - - if (l->flags & AUTH_3D_LIGHT_FAR) { - ImGui::Text("Far"); - data_view_auth_3d_window_auth_3d_key(&l->_far, 0, true); - } - - if (l->flags & AUTH_3D_LIGHT_INTENSITY) { + // XHD + if (l->flag & auth_3d_detail::Light::FLAG_INTENSITY) { ImGui::Text("Intensity"); - data_view_auth_3d_window_auth_3d_key(&l->intensity, 0, true); + data_view_auth_3d_window_auth_3d_fcurve(&l->fcurve_intensity, 0, true); } - if (l->flags & AUTH_3D_LIGHT_LINEAR) { + // XHD + if (l->flag & auth_3d_detail::Light::FLAG_FAR) { + ImGui::Text("Far"); + data_view_auth_3d_window_auth_3d_fcurve(&l->fcurve_far, 0, true); + } + + // XHD + if (l->flag & auth_3d_detail::Light::FLAG_LINEAR) { ImGui::Text("Linear"); - data_view_auth_3d_window_auth_3d_key(&l->linear, 0, true); + data_view_auth_3d_window_auth_3d_fcurve(&l->fcurve_linear, 0, true); } - if (l->flags & AUTH_3D_LIGHT_POSITION) - data_view_auth_3d_window_auth_3d_vec3(&l->position.translation, "Position"); - - if (l->flags & AUTH_3D_LIGHT_QUADRATIC) { + // XHD + if (l->flag & auth_3d_detail::Light::FLAG_QUADRATIC) { ImGui::Text("Quadratic"); - data_view_auth_3d_window_auth_3d_key(&l->quadratic, 0, true); + data_view_auth_3d_window_auth_3d_fcurve(&l->fcurve_quadratic, 0, true); } - if (l->flags & AUTH_3D_LIGHT_SPECULAR) - data_view_auth_3d_window_auth_3d_rgba(&l->specular, "Specular"); + // XHD + if (l->flag & auth_3d_detail::Light::FLAG_DROP_OFF) { + ImGui::Text("Drop Off"); + data_view_auth_3d_window_auth_3d_fcurve(&l->fcurve_drop_off, 0, true); + } - if (l->flags & AUTH_3D_LIGHT_SPOT_DIRECTION) - data_view_auth_3d_window_auth_3d_vec3(&l->spot_direction.translation, "Spot Direction"); + // XHD + if (l->flag & auth_3d_detail::Light::FLAG_CONE_ANGLE) { + ImGui::Text("Cone Angle"); + data_view_auth_3d_window_auth_3d_fcurve(&l->fcurve_cone_angle, 0, true); + } - if (l->flags & AUTH_3D_LIGHT_TONE_CURVE) - data_view_auth_3d_window_auth_3d_rgba(&l->tone_curve, "Tone Curve"); ImGui::TreePop(); } -static void data_view_auth_3d_window_auth_3d_m_object_hrc(auth_3d_m_object_hrc* moh) { +static void data_view_auth_3d_window_auth_3d_m_object_hrc(auth_3d_detail::MultiHierarchyObject* moh) { if (!moh) return; @@ -647,39 +707,40 @@ static void data_view_auth_3d_window_auth_3d_m_object_hrc(auth_3d_m_object_hrc* tree_node_flags |= ImGuiTreeNodeFlags_OpenOnArrow; tree_node_flags |= ImGuiTreeNodeFlags_SpanAvailWidth; - bool visible = moh->model_transform.visible; - if (!visible) + bool visibility = moh->motion_transform.visibility; + if (!visibility) ImGui::PushStyleColor(ImGuiCol_Text, 0xFF888888); if (!ImGui::TreeNodeEx(moh, tree_node_flags, moh->name.c_str())) { - if (!visible) + if (!visibility) ImGui::PopStyleColor(); return; } - if (moh->instance.size() > 0 + data_view_auth_3d_window_auth_3d_motion_transform(&moh->motion_transform); + + if (moh->instance_list.size() > 0 && ImGui::TreeNodeEx("Instance", tree_node_flags)) { - for (auth_3d_object_instance& i : moh->instance) + for (auth_3d_detail::ObjectInstance& i : moh->instance_list) data_view_auth_3d_window_auth_3d_object_instance(&i); ImGui::TreePop(); } - data_view_auth_3d_window_auth_3d_object_model_transform(&moh->model_transform); - - if (moh->node.size() > 0 + if (moh->node_list.size() > 0 && ImGui::TreeNodeEx("Node", tree_node_flags)) { - for (auth_3d_object_node& i : moh->node) + for (auth_3d_detail::TransformNode& i : moh->node_list) data_view_auth_3d_window_auth_3d_object_node(&i); ImGui::TreePop(); } ImGui::TreePop(); - if (!visible) + if (!visibility) ImGui::PopStyleColor(); } -static void data_view_auth_3d_window_auth_3d_material_list(auth_3d_material_list* ml) { - if (!ml || !ml->flags) +// X/XHD +static void data_view_auth_3d_window_auth_3d_material_list(auth_3d_detail::MaterialList* ml) { + if (!ml || !ml->flag) return; ImGuiTreeNodeFlags tree_node_flags = 0; @@ -690,20 +751,36 @@ static void data_view_auth_3d_window_auth_3d_material_list(auth_3d_material_list if (!ImGui::TreeNodeEx(ml, tree_node_flags, ml->name.c_str())) return; - if (ml->flags & AUTH_3D_MATERIAL_LIST_BLEND_COLOR) - data_view_auth_3d_window_auth_3d_rgba(&ml->blend_color, "Blend Color"); + if (ml->flag & auth_3d_detail::MaterialList::FLAG_EMISSION) + data_view_auth_3d_window_auth_3d_fcurve_color4f(&ml->emission.fcurve_color, "Emission"); - if (ml->flags & AUTH_3D_MATERIAL_LIST_GLOW_INTENSITY) { + if (ml->flag & auth_3d_detail::MaterialList::FLAG_BLEND_COLOR) + data_view_auth_3d_window_auth_3d_fcurve_color4f(&ml->blend_color.fcurve_color, "Blend Color"); + + if (ml->flag & auth_3d_detail::MaterialList::FLAG_GLOW_INTENSITY) { ImGui::Text("Glow Intensity"); - data_view_auth_3d_window_auth_3d_key(&ml->glow_intensity, 0, false); + data_view_auth_3d_window_auth_3d_fcurve(&ml->fcurve_glow_intensity, 0, false); } - if (ml->flags & AUTH_3D_MATERIAL_LIST_EMISSION) - data_view_auth_3d_window_auth_3d_rgba(&ml->emission, "Emission"); ImGui::TreePop(); } -static void data_view_auth_3d_window_auth_3d_object(auth_3d_object* o) { +static void data_view_auth_3d_window_auth_3d_motion(auth_3d_detail::Motion* m) { + if (!m) + return; + + ImGuiTreeNodeFlags tree_node_flags = 0; + tree_node_flags |= ImGuiTreeNodeFlags_OpenOnDoubleClick; + tree_node_flags |= ImGuiTreeNodeFlags_OpenOnArrow; + tree_node_flags |= ImGuiTreeNodeFlags_SpanAvailWidth; + + if (!ImGui::TreeNodeEx(m, tree_node_flags, m->name.c_str())) + return; + + ImGui::TreePop(); +} + +static void data_view_auth_3d_window_auth_3d_object(auth_3d_detail::Object* o) { if (!o) return; @@ -719,47 +796,47 @@ static void data_view_auth_3d_window_auth_3d_object(auth_3d_object* o) { while (s = strchr(name = s, '|')) s++; - bool visible = o->model_transform.visible; - if (!visible) + bool visibility = o->model_transform.visibility; + if (!visibility) ImGui::PushStyleColor(ImGuiCol_Text, 0xFF888888); tree_node_flags = tree_node_base_flags; if (!ImGui::TreeNodeEx(o, tree_node_flags, name)) { - if (!visible) + if (!visibility) ImGui::PopStyleColor(); return; } data_view_auth_3d_window_auth_3d_model_transform(&o->model_transform); - data_view_auth_3d_window_auth_3d_object_curve(&o->morph, "Morph"); - data_view_auth_3d_window_auth_3d_object_curve(&o->pattern, "Pattern"); + data_view_auth_3d_window_auth_3d_curve_with_offset(&o->obj_morph, "Morph"); + data_view_auth_3d_window_auth_3d_curve_with_offset(&o->obj_pat, "Pattern"); tree_node_flags = tree_node_base_flags; - if (o->texture_pattern.size() > 0 - && ImGui::TreeNodeEx("Texture Pattern", tree_node_flags)) { - for (auth_3d_object_texture_pattern& i : o->texture_pattern) - data_view_auth_3d_window_auth_3d_object_texture_pattern(&i); + if (o->texture_list.size() > 0 + && ImGui::TreeNodeEx("Texture", tree_node_flags)) { + for (auth_3d_detail::Texture& i : o->texture_list) + data_view_auth_3d_window_auth_3d_texture(&i); ImGui::TreePop(); } tree_node_flags = tree_node_base_flags; - if (o->texture_transform.size() > 0 + if (o->texture_transform_list.size() > 0 && ImGui::TreeNodeEx("Texture Transform", tree_node_flags)) { - for (auth_3d_object_texture_transform& i : o->texture_transform) - data_view_auth_3d_window_auth_3d_object_texture_transform(&i); + for (auth_3d_detail::TextureTransform& i : o->texture_transform_list) + data_view_auth_3d_window_auth_3d_texture_transform(&i); ImGui::TreePop(); } tree_node_flags = tree_node_base_flags; tree_node_flags |= ImGuiTreeNodeFlags_DefaultOpen; - if (o->children_object.size() > 0 - && ImGui::TreeNodeEx("Children Object", tree_node_flags)) { - for (auth_3d_object*& i : o->children_object) + if (o->child_object_list.size() > 0 + && ImGui::TreeNodeEx("Child Object List", tree_node_flags)) { + for (auth_3d_detail::Object*& i : o->child_object_list) data_view_auth_3d_window_auth_3d_object(i); ImGui::TreePop(); } @@ -767,37 +844,20 @@ static void data_view_auth_3d_window_auth_3d_object(auth_3d_object* o) { tree_node_flags = tree_node_base_flags; tree_node_flags |= ImGuiTreeNodeFlags_DefaultOpen; - if (o->children_object_hrc.size() > 0 - && ImGui::TreeNodeEx("Children Object HRC", tree_node_flags)) { - for (auth_3d_object_hrc*& i : o->children_object_hrc) + if (o->child_object_hrc_list.size() > 0 + && ImGui::TreeNodeEx("Child Object HRC List", tree_node_flags)) { + for (auth_3d_detail::HierarchyObject*& i : o->child_object_hrc_list) data_view_auth_3d_window_auth_3d_object_hrc(i); ImGui::TreePop(); } ImGui::TreePop(); - if (!visible) + if (!visibility) ImGui::PopStyleColor(); } -static void data_view_auth_3d_window_auth_3d_object_curve(auth_3d_object_curve* oc, const char* format) { - if (!oc || !oc->curve || !format) - return; - - ImGuiTreeNodeFlags tree_node_flags = 0; - tree_node_flags |= ImGuiTreeNodeFlags_DefaultOpen; - tree_node_flags |= ImGuiTreeNodeFlags_OpenOnDoubleClick; - tree_node_flags |= ImGuiTreeNodeFlags_OpenOnArrow; - tree_node_flags |= ImGuiTreeNodeFlags_SpanAvailWidth; - - if (!ImGui::TreeNodeEx(oc, tree_node_flags, format)) - return; - - data_view_auth_3d_window_auth_3d_curve(oc->curve); - ImGui::TreePop(); -} - -static void data_view_auth_3d_window_auth_3d_object_hrc(auth_3d_object_hrc* oh) { - if (!oh) +static void data_view_auth_3d_window_auth_3d_object_hrc(auth_3d_detail::HierarchyObject* ho) { + if (!ho) return; ImGuiTreeNodeFlags tree_node_base_flags = 0; @@ -807,28 +867,28 @@ static void data_view_auth_3d_window_auth_3d_object_hrc(auth_3d_object_hrc* oh) ImGuiTreeNodeFlags tree_node_flags; - const char* s = oh->name.c_str(); + const char* s = ho->name.c_str(); const char* name = s; while (s = strchr(name = s, '|')) s++; - bool visible = oh->node[0].model_transform.visible; - if (!visible) + bool visibility = ho->node_list[0].motion_transform.visibility; + if (!visibility) ImGui::PushStyleColor(ImGuiCol_Text, 0xFF888888); tree_node_flags = tree_node_base_flags; - if (!ImGui::TreeNodeEx(oh, tree_node_flags, name)) { - if (!visible) + if (!ImGui::TreeNodeEx(ho, tree_node_flags, name)) { + if (!visibility) ImGui::PopStyleColor(); return; } tree_node_flags = tree_node_base_flags; - if (oh->node.size() > 0 + if (ho->node_list.size() > 0 && ImGui::TreeNodeEx("Node", tree_node_flags)) { - for (auth_3d_object_node& i : oh->node) + for (auth_3d_detail::TransformNode& i : ho->node_list) data_view_auth_3d_window_auth_3d_object_node(&i); ImGui::TreePop(); } @@ -836,9 +896,9 @@ static void data_view_auth_3d_window_auth_3d_object_hrc(auth_3d_object_hrc* oh) tree_node_flags = tree_node_base_flags; tree_node_flags |= ImGuiTreeNodeFlags_DefaultOpen; - if (oh->children_object.size() > 0 - && ImGui::TreeNodeEx("Children Object", tree_node_flags)) { - for (auth_3d_object*& i : oh->children_object) + if (ho->child_object_list.size() > 0 + && ImGui::TreeNodeEx("Child Object List", tree_node_flags)) { + for (auth_3d_detail::Object*& i : ho->child_object_list) data_view_auth_3d_window_auth_3d_object(i); ImGui::TreePop(); } @@ -846,19 +906,19 @@ static void data_view_auth_3d_window_auth_3d_object_hrc(auth_3d_object_hrc* oh) tree_node_flags = tree_node_base_flags; tree_node_flags |= ImGuiTreeNodeFlags_DefaultOpen; - if (oh->children_object_hrc.size() > 0 - && ImGui::TreeNodeEx("Children Object HRC", tree_node_flags)) { - for (auth_3d_object_hrc*& i : oh->children_object_hrc) + if (ho->child_object_hrc_list.size() > 0 + && ImGui::TreeNodeEx("Child Object HRC List", tree_node_flags)) { + for (auth_3d_detail::HierarchyObject*& i : ho->child_object_hrc_list) data_view_auth_3d_window_auth_3d_object_hrc(i); ImGui::TreePop(); } ImGui::TreePop(); - if (!visible) + if (!visibility) ImGui::PopStyleColor(); } -static void data_view_auth_3d_window_auth_3d_object_instance(auth_3d_object_instance* oi) { +static void data_view_auth_3d_window_auth_3d_object_instance(auth_3d_detail::ObjectInstance* oi) { if (!oi) return; @@ -867,17 +927,17 @@ static void data_view_auth_3d_window_auth_3d_object_instance(auth_3d_object_inst tree_node_flags |= ImGuiTreeNodeFlags_OpenOnArrow; tree_node_flags |= ImGuiTreeNodeFlags_SpanAvailWidth; - bool visible = oi->model_transform.visible; - if (!visible) + bool visibility = oi->motion_transform.visibility; + if (!visibility) ImGui::PushStyleColor(ImGuiCol_Text, 0xFF888888); if (!ImGui::TreeNodeEx(oi, tree_node_flags, oi->name.c_str())) { - if (!visible) + if (!visibility) ImGui::PopStyleColor(); return; } - data_view_auth_3d_window_auth_3d_object_model_transform(&oi->model_transform); + data_view_auth_3d_window_auth_3d_motion_transform(&oi->motion_transform); if (oi->shadow) ImGui::Text("Shadow: True"); @@ -885,12 +945,12 @@ static void data_view_auth_3d_window_auth_3d_object_instance(auth_3d_object_inst ImGui::Text("UID Name: %s", oi->uid_name.c_str()); ImGui::TreePop(); - if (!visible) + if (!visibility) ImGui::PopStyleColor(); } -static void data_view_auth_3d_window_auth_3d_object_model_transform(auth_3d_object_model_transform* omt) { - if (!omt) +static void data_view_auth_3d_window_auth_3d_motion_transform(auth_3d_detail::MotionTransform* mt) { + if (!mt) return; ImGuiTreeNodeFlags tree_node_flags = 0; @@ -898,22 +958,22 @@ static void data_view_auth_3d_window_auth_3d_object_model_transform(auth_3d_obje tree_node_flags |= ImGuiTreeNodeFlags_OpenOnArrow; tree_node_flags |= ImGuiTreeNodeFlags_SpanAvailWidth; - if (!ImGui::TreeNodeEx(omt, tree_node_flags, "Model Transform")) + if (!ImGui::TreeNodeEx(mt, tree_node_flags, "Model Transform")) return; - ImGui::Text("Frame: %5f", omt->frame); + ImGui::Text("Frame: %5f", mt->frame); - data_view_auth_3d_window_auth_3d_vec3(&omt->translation, "Translation"); - data_view_auth_3d_window_auth_3d_vec3(&omt->rotation, "Rotation"); - data_view_auth_3d_window_auth_3d_vec3(&omt->scale, "Scale"); + data_view_auth_3d_window_auth_3d_fcurve3f(&mt->fcurve_translation, "Translation"); + data_view_auth_3d_window_auth_3d_fcurve3f(&mt->fcurve_rotation, "Rotation"); + data_view_auth_3d_window_auth_3d_fcurve3f(&mt->fcurve_scale, "Scale"); ImGui::Text("Visibility"); - data_view_auth_3d_window_auth_3d_key(&omt->visibility, 0, true); + data_view_auth_3d_window_auth_3d_fcurve(&mt->fcurve_visibility, 0, true); ImGui::TreePop(); } -static void data_view_auth_3d_window_auth_3d_object_node(auth_3d_object_node* on) { - if (!on) +static void data_view_auth_3d_window_auth_3d_object_node(auth_3d_detail::TransformNode* tn) { + if (!tn) return; ImGuiTreeNodeFlags tree_node_flags = 0; @@ -921,31 +981,31 @@ static void data_view_auth_3d_window_auth_3d_object_node(auth_3d_object_node* on tree_node_flags |= ImGuiTreeNodeFlags_OpenOnArrow; tree_node_flags |= ImGuiTreeNodeFlags_SpanAvailWidth; - if (!ImGui::TreeNodeEx(on, tree_node_flags, on->name.c_str())) + if (!ImGui::TreeNodeEx(tn, tree_node_flags, tn->name.c_str())) return; - data_view_auth_3d_window_auth_3d_object_model_transform(&on->model_transform); + data_view_auth_3d_window_auth_3d_motion_transform(&tn->motion_transform); - if (on->flags & AUTH_3D_OBJECT_NODE_JOINT_ORIENT) { + if (tn->flag & auth_3d_detail::TransformNode::FLAG_JOINT_ORIENT) { ImGui::Text("Joint Orient "); - ImGui::Text(" X: %#.6g", on->joint_orient.x); - ImGui::Text(" Y: %#.6g", on->joint_orient.y); - ImGui::Text(" Z: %#.6g", on->joint_orient.z); + ImGui::Text(" X: %#.6g", tn->joint_orient.x); + ImGui::Text(" Y: %#.6g", tn->joint_orient.y); + ImGui::Text(" Z: %#.6g", tn->joint_orient.z); } - ImGui::Text("Parent: %d", on->parent); + ImGui::Text("Parent ID: %d", tn->parent_id); ImGui::TreePop(); } -static void data_view_auth_3d_window_auth_3d_object_texture_pattern(auth_3d_object_texture_pattern* otp) { - if (!otp) +static void data_view_auth_3d_window_auth_3d_texture(auth_3d_detail::Texture* t) { + if (!t) return; - data_view_auth_3d_window_auth_3d_object_curve(&otp->pattern, otp->name.c_str()); + data_view_auth_3d_window_auth_3d_curve_with_offset(&t->tex_pat, t->name.c_str()); } -static void data_view_auth_3d_window_auth_3d_object_texture_transform(auth_3d_object_texture_transform* ott) { - if (!ott || !ott->flags) +static void data_view_auth_3d_window_auth_3d_texture_transform(auth_3d_detail::TextureTransform* tt) { + if (!tt || !tt->flag) return; ImGuiTreeNodeFlags tree_node_flags = 0; @@ -953,33 +1013,33 @@ static void data_view_auth_3d_window_auth_3d_object_texture_transform(auth_3d_ob tree_node_flags |= ImGuiTreeNodeFlags_OpenOnArrow; tree_node_flags |= ImGuiTreeNodeFlags_SpanAvailWidth; - if (!ImGui::TreeNodeEx(ott, tree_node_flags, ott->name.c_str())) + if (!ImGui::TreeNodeEx(tt, tree_node_flags, tt->name.c_str())) return; - if (ott->flags & AUTH_3D_OBJECT_TEXTURE_TRANSFORM_COVERAGE_U) - data_view_auth_3d_window_auth_3d_key(&ott->coverage_u, "Coverage U:", false); - if (ott->flags & AUTH_3D_OBJECT_TEXTURE_TRANSFORM_COVERAGE_V) - data_view_auth_3d_window_auth_3d_key(&ott->coverage_v, "Coverage V:", false); - if (ott->flags & AUTH_3D_OBJECT_TEXTURE_TRANSFORM_OFFSET_U) - data_view_auth_3d_window_auth_3d_key(&ott->offset_u, "Offset U:", false); - if (ott->flags & AUTH_3D_OBJECT_TEXTURE_TRANSFORM_OFFSET_V) - data_view_auth_3d_window_auth_3d_key(&ott->offset_v, "Offset V:", false); - if (ott->flags & AUTH_3D_OBJECT_TEXTURE_TRANSFORM_REPEAT_U) - data_view_auth_3d_window_auth_3d_key(&ott->repeat_u, "Repeat U:", false); - if (ott->flags & AUTH_3D_OBJECT_TEXTURE_TRANSFORM_REPEAT_V) - data_view_auth_3d_window_auth_3d_key(&ott->repeat_v, "Repeat V:", false); - if (ott->flags & AUTH_3D_OBJECT_TEXTURE_TRANSFORM_ROTATE) - data_view_auth_3d_window_auth_3d_key(&ott->rotate, "Rotate:", false); - if (ott->flags & AUTH_3D_OBJECT_TEXTURE_TRANSFORM_ROTATE_FRAME) - data_view_auth_3d_window_auth_3d_key(&ott->rotate_frame, "Rotate Frame:", false); - if (ott->flags & AUTH_3D_OBJECT_TEXTURE_TRANSFORM_TRANSLATE_FRAME_U) - data_view_auth_3d_window_auth_3d_key(&ott->translate_frame_u, "Translate Frame U:", false); - if (ott->flags & AUTH_3D_OBJECT_TEXTURE_TRANSFORM_TRANSLATE_FRAME_V) - data_view_auth_3d_window_auth_3d_key(&ott->translate_frame_v, "Translate Frame V:", false); + if (tt->has_coverage_u()) + data_view_auth_3d_window_auth_3d_fcurve(&tt->fcurve_coverage_u, "Coverage U:", false); + if (tt->has_coverage_v()) + data_view_auth_3d_window_auth_3d_fcurve(&tt->fcurve_coverage_v, "Coverage V:", false); + if (tt->has_repeat_u()) + data_view_auth_3d_window_auth_3d_fcurve(&tt->fcurve_repeat_u, "Repeat U:", false); + if (tt->has_repeat_v()) + data_view_auth_3d_window_auth_3d_fcurve(&tt->fcurve_repeat_v, "Repeat V:", false); + if (tt->has_translate_frame_u()) + data_view_auth_3d_window_auth_3d_fcurve(&tt->fcurve_translate_frame_u, "Translate Frame U:", false); + if (tt->has_translate_frame_v()) + data_view_auth_3d_window_auth_3d_fcurve(&tt->fcurve_translate_frame_v, "Translate Frame V:", false); + if (tt->has_offset_u()) + data_view_auth_3d_window_auth_3d_fcurve(&tt->fcurve_offset_u, "Offset U:", false); + if (tt->has_offset_v()) + data_view_auth_3d_window_auth_3d_fcurve(&tt->fcurve_offset_v, "Offset V:", false); + if (tt->has_rotate_frame()) + data_view_auth_3d_window_auth_3d_fcurve(&tt->fcurve_rotate_frame, "Rotate Frame:", false); + if (tt->has_rotate()) + data_view_auth_3d_window_auth_3d_fcurve(&tt->fcurve_rotate, "Rotate:", false); ImGui::TreePop(); } -static void data_view_auth_3d_window_auth_3d_point(auth_3d_point* p) { +static void data_view_auth_3d_window_auth_3d_point(auth_3d_detail::Point* p) { if (!p) return; @@ -995,8 +1055,8 @@ static void data_view_auth_3d_window_auth_3d_point(auth_3d_point* p) { ImGui::TreePop(); } -static void data_view_auth_3d_window_auth_3d_post_process(auth_3d_post_process* pp) { - if (!pp || !pp->flags) +static void data_view_auth_3d_window_auth_3d_post_process(auth_3d_detail::PostProcess* pp) { + if (!pp || !pp->flag) return; ImGuiTreeNodeFlags tree_node_flags = 0; @@ -1008,28 +1068,28 @@ static void data_view_auth_3d_window_auth_3d_post_process(auth_3d_post_process* if (!ImGui::TreeNodeEx(pp, tree_node_flags, "Post Process")) return; - if (pp->flags & AUTH_3D_POST_PROCESS_INTENSITY) - data_view_auth_3d_window_auth_3d_rgba(&pp->intensity, "intensity"); - - if (pp->flags & AUTH_3D_POST_PROCESS_LENS_FLARE) { + if (pp->flag & auth_3d_detail::PostProcess::FLAG_LENS_FLARE) { ImGui::Text("Lens Flare"); - data_view_auth_3d_window_auth_3d_key(&pp->lens_flare, 0, false); + data_view_auth_3d_window_auth_3d_fcurve(&pp->fcurve_lens_flare, 0, false); } - if (pp->flags & AUTH_3D_POST_PROCESS_LENS_GHOST) { + if (pp->flag & auth_3d_detail::PostProcess::FLAG_LENS_GHOST) { ImGui::Text("Lens Gghost"); - data_view_auth_3d_window_auth_3d_key(&pp->lens_ghost, 0, false); + data_view_auth_3d_window_auth_3d_fcurve(&pp->fcurve_lens_ghost, 0, false); } - if (pp->flags & AUTH_3D_POST_PROCESS_LENS_SHAFT) { + if (pp->flag & auth_3d_detail::PostProcess::FLAG_LENS_SHAFT) { ImGui::Text("Lens Shaft"); - data_view_auth_3d_window_auth_3d_key(&pp->lens_shaft, 0, false); + data_view_auth_3d_window_auth_3d_fcurve(&pp->fcurve_lens_shaft, 0, false); } - if (pp->flags & AUTH_3D_POST_PROCESS_RADIUS) - data_view_auth_3d_window_auth_3d_rgba(&pp->radius, "Radius"); + if (pp->flag & auth_3d_detail::PostProcess::FLAG_RADIUS) + data_view_auth_3d_window_auth_3d_fcurve_color4f(&pp->radius.fcurve_color, "Radius"); - if (pp->flags & AUTH_3D_POST_PROCESS_SCENE_FADE) - data_view_auth_3d_window_auth_3d_rgba(&pp->scene_fade, "Scene Fade"); + if (pp->flag & auth_3d_detail::PostProcess::FLAG_INTENSITY) + data_view_auth_3d_window_auth_3d_fcurve_color4f(&pp->intensity.fcurve_color, "intensity"); + + if (pp->flag & auth_3d_detail::PostProcess::FLAG_SCENE_FADE) + data_view_auth_3d_window_auth_3d_fcurve_color4f(&pp->scene_fade.fcurve_color, "Scene Fade"); ImGui::TreePop(); } diff --git a/src/ReDIVA/dw.cpp b/src/ReDIVA/dw.cpp index bf4b6864..d20c188d 100644 --- a/src/ReDIVA/dw.cpp +++ b/src/ReDIVA/dw.cpp @@ -4,6 +4,7 @@ */ #include "dw.hpp" +#include "../KKdLib/prj/algorithm.hpp" #include "../CRE/prj/memory_manager.hpp" #include "../CRE/app_system_detail.hpp" #include "../CRE/data.hpp" @@ -1033,15 +1034,8 @@ namespace dw { if (parent_comp) { Shell* parent_shell = dynamic_cast(parent_comp); - if (parent_shell) { - auto i = parent_shell->children.begin(); - auto i_end = parent_shell->children.end(); - while (i != i_end) - if (*i == this) { - parent_shell->children.erase(i); - break; - } - } + if (parent_shell) + prj::find_and_erase(parent_shell->children, this); } dw_gui_detail_display->RemoveShell(this); @@ -3867,7 +3861,7 @@ void dw_sys_menu_init(dw::Shell* shell) { } PrintWorkDebug::PrintWorkDebug() { - prio = spr::SPR_PRIO_29; + prio = spr::SPR_PRIO_DW; set_screen_mode(SCREEN_MODE_MAX); } @@ -3929,18 +3923,8 @@ namespace dw { } void DragBoundsData::RemoveDragBoundsListener(DragBoundsListener* value) { - if (!value) - return; - - auto i = drag_bounds_listeners.begin(); - auto i_end = drag_bounds_listeners.end(); - while (i != i_end) - if (*i == value) { - drag_bounds_listeners.erase(i); - break; - } - else - i++; + if (value) + prj::find_and_erase(drag_bounds_listeners, value); } // 0x1402E5020 @@ -4519,7 +4503,7 @@ void dw_gui_detail::Input::Draw() { else if (field_20 < 300) { spr::SprArgs args; args.id = 3343; - args.prio = spr::SPR_PRIO_29; + args.prio = spr::SPR_PRIO_DW; args.trans.x = mouse_pos.x; args.trans.y = mouse_pos.y; args.screen_trans = SCREEN_MODE_MAX; @@ -4809,7 +4793,6 @@ int32_t dw_gui_detail::Display::GetActiveShell() { active_shell->KeyCallback(key_callback_data); } else { - bool found = false; for (dw::Shell*& i : shells) if (i->GetDisp()) { @@ -4862,62 +4845,24 @@ void dw_gui_detail::Display::HideMenus() { } void dw_gui_detail::Display::MakeShellFirst(dw::Shell* value) { - if (!value) - return; - - auto i = shells.begin(); - auto i_end = shells.end(); - while (i != i_end) - if (*i == value) { - shells.erase(i); - shells.push_back(value); - break; - } - else - i++; + if (value && prj::find_and_erase(shells, value)) + shells.push_back(value); } void dw_gui_detail::Display::MakeShellLast(dw::Shell* value) { - if (!value) - return; - - auto i = shells.begin(); - auto i_end = shells.end(); - while (i != i_end) - if (*i == value) { - shells.erase(i); - shells.insert(shells.begin(), value); - break; - } - else - i++; + if (value && prj::find_and_erase(shells, value)) + shells.insert(shells.begin(), value); } void dw_gui_detail::Display::RemoveMenu(dw::Menu* value) { - auto i = menus.begin(); - auto i_end = menus.end(); - while (i != i_end) - if (*i == value) { - menus.erase(i); - break; - } - else - i++; + prj::find_and_erase(menus, value); if (active_menu == value) active_menu = 0; } void dw_gui_detail::Display::RemoveShell(dw::Shell* value) { - auto i = shells.begin(); - auto i_end = shells.end(); - while (i != i_end) - if (*i == value) { - shells.erase(i); - break; - } - else - i++; + prj::find_and_erase(shells, value); if (active_shell == value) { active_shell = 0; diff --git a/src/ReDIVA/dw_gui_user_detail.cpp b/src/ReDIVA/dw_gui_user_detail.cpp index e51fcc0c..7c70dcca 100644 --- a/src/ReDIVA/dw_gui_user_detail.cpp +++ b/src/ReDIVA/dw_gui_user_detail.cpp @@ -130,7 +130,7 @@ namespace dw_gui_user_detail { UpdateLayout(); } - + FontListWindow::~FontListWindow() { } diff --git a/src/ReDIVA/pv_game/pv_game.cpp b/src/ReDIVA/pv_game/pv_game.cpp index cb2f427d..3ff4eb34 100644 --- a/src/ReDIVA/pv_game/pv_game.cpp +++ b/src/ReDIVA/pv_game/pv_game.cpp @@ -1373,22 +1373,22 @@ void pv_game::change_field(size_t field, ssize_t dsc_time, ssize_t curr_time) { data.play_data.set_spr_set_back_id(next_field_data.spr_set_back_id); - std::vector auth_3d_end; + std::vector auth_3d_end; std::set_difference( curr_field_data.auth_3d_ids.begin(), curr_field_data.auth_3d_ids.end(), next_field_data.auth_3d_ids.begin(), next_field_data.auth_3d_ids.end(), std::back_inserter(auth_3d_end)); - std::vector auth_3d_start; + std::vector auth_3d_start; std::set_difference( next_field_data.auth_3d_ids.begin(), next_field_data.auth_3d_ids.end(), curr_field_data.auth_3d_ids.begin(), curr_field_data.auth_3d_ids.end(), std::back_inserter(auth_3d_start)); - std::vector auth_3d_cont; + std::vector auth_3d_cont; std::set_intersection( curr_field_data.auth_3d_ids.begin(), curr_field_data.auth_3d_ids.end(), next_field_data.auth_3d_ids.begin(), next_field_data.auth_3d_ids.end(), std::back_inserter(auth_3d_cont)); - for (auth_3d_id& i : auth_3d_end) { - i.set_visibility(false); - i.set_enable(false); + for (auth_3d_detail::Handle& i : auth_3d_end) { + i.set_visible(false); + i.set_enabled(false); } bool disp = true; @@ -1399,78 +1399,78 @@ void pv_game::change_field(size_t field, ssize_t dsc_time, ssize_t curr_time) { disp = field > pv_disp2d->title_end_3d_field; } - for (auth_3d_id& i : auth_3d_start) { - float_t req_frame = 0.0f; - float_t max_frame = -1.0f; + for (auth_3d_detail::Handle& i : auth_3d_start) { + float_t frame_req = 0.0f; + float_t frame_max = -1.0f; if (data.has_auth_3d_frame) { int32_t auth_3d_frame = get_field_auth_3d_frame(next_field_data, i.get_uid(), 0); - req_frame = pv_game::get_auth_3d_frame_max_frame(get_frame(auth_3d_frame, - dsc_time, curr_time), i.get_uid(), dsc_time, curr_time, 0, &max_frame); - req_frame = max_def(req_frame, 0.0f); + frame_req = pv_game::get_scene_frame_max_frame(get_frame(auth_3d_frame, + dsc_time, curr_time), i.get_uid(), dsc_time, curr_time, 0, &frame_max); + frame_req = max_def(frame_req, 0.0f); } - i.set_enable(true); - i.set_req_frame(req_frame); - i.set_max_frame(max_frame); - i.set_paused(false); - i.set_visibility(disp); + i.set_enabled(true); + i.set_frame_req(frame_req); + i.set_frame_max(frame_max); + i.set_pause(false); + i.set_visible(disp); } - for (auth_3d_id& i : auth_3d_cont) { - float_t max_frame = -1.0f; + for (auth_3d_detail::Handle& i : auth_3d_cont) { + float_t frame_max = -1.0f; if (data.has_auth_3d_frame) { int32_t auth_3d_frame = get_field_auth_3d_frame(next_field_data, i.get_uid(), 0); - float_t req_frame = get_auth_3d_frame_max_frame(get_frame_continue(auth_3d_frame), - i.get_uid(), dsc_time, curr_time, 0, &max_frame); - if (req_frame >= 0.0f) - i.set_req_frame(req_frame); + float_t frame_req = get_scene_frame_max_frame(get_frame_continue(auth_3d_frame), + i.get_uid(), dsc_time, curr_time, 0, &frame_max); + if (frame_req >= 0.0f) + i.set_frame_req(frame_req); } - i.set_max_frame(max_frame); + i.set_frame_max(frame_max); } if (next_field_data.light_auth_3d_id == curr_field_data.light_auth_3d_id) { - auth_3d_id& light_auth = next_field_data.light_auth_3d_id; - if (light_auth.check_not_empty()) { - float_t max_frame = -1.0f; + auth_3d_detail::Handle& light_auth = next_field_data.light_auth_3d_id; + if (light_auth.is_valid()) { + float_t frame_max = -1.0f; if (data.has_light_frame) { int32_t light_frame = get_field_auth_3d_frame(next_field_data, light_auth.get_uid(), 1); - float_t req_frame = get_auth_3d_frame_max_frame(get_frame_continue(light_frame), - light_auth.get_uid(), dsc_time, curr_time, 1, &max_frame); - if (req_frame >= 0.0f) - light_auth.set_req_frame(req_frame); + float_t frame_req = get_scene_frame_max_frame(get_frame_continue(light_frame), + light_auth.get_uid(), dsc_time, curr_time, 1, &frame_max); + if (frame_req >= 0.0f) + light_auth.set_frame_req(frame_req); } - light_auth.set_max_frame(max_frame); + light_auth.set_frame_max(frame_max); } } else { - auth_3d_id& prev_light_auth = curr_field_data.light_auth_3d_id; - if (prev_light_auth.check_not_empty()) { - prev_light_auth.set_visibility(false); - prev_light_auth.set_enable(false); + auth_3d_detail::Handle& prev_light_auth = curr_field_data.light_auth_3d_id; + if (prev_light_auth.is_valid()) { + prev_light_auth.set_visible(false); + prev_light_auth.set_enabled(false); } - auth_3d_id& next_light_auth = next_field_data.light_auth_3d_id; - if (next_light_auth.check_not_empty()) { - float_t req_frame = 0.0f; - float_t max_frame = -1.0f; + auth_3d_detail::Handle& next_light_auth = next_field_data.light_auth_3d_id; + if (next_light_auth.is_valid()) { + float_t frame_req = 0.0f; + float_t frame_max = -1.0f; if (data.has_light_frame) { int32_t light_frame = get_field_auth_3d_frame(next_field_data, next_light_auth.get_uid(), 1); - req_frame = get_auth_3d_frame_max_frame(get_frame(light_frame, - dsc_time, curr_time), next_light_auth.get_uid(), dsc_time, curr_time, 1, &max_frame); - req_frame = max_def(req_frame, 0.0f); + frame_req = get_scene_frame_max_frame(get_frame(light_frame, + dsc_time, curr_time), next_light_auth.get_uid(), dsc_time, curr_time, 1, &frame_max); + frame_req = max_def(frame_req, 0.0f); } - next_light_auth.set_enable(true); - next_light_auth.set_req_frame(req_frame); - next_light_auth.set_max_frame(req_frame); - next_light_auth.set_paused(false); - next_light_auth.set_visibility(true); + next_light_auth.set_enabled(true); + next_light_auth.set_frame_req(frame_req); + next_light_auth.set_frame_max(frame_max); + next_light_auth.set_pause(false); + next_light_auth.set_visible(true); } } @@ -1864,7 +1864,7 @@ int32_t pv_game::ctrl_end(float_t delta_time) { void pv_game::data_itmpv_disable() { for (auto& i : data.itmpv) for (auto& j : i) - j.second.first.set_enable(false); + j.second.first.set_enabled(false); } void pv_game::disp() { @@ -1942,16 +1942,16 @@ void pv_game::edit_effect_set(int32_t index, float_t speed, float_t delta_time) void pv_game::edit_instrument_reset() { for (pv_game_edit_instrument& i : data.edit_instrument) - for (auth_3d_id& j : i.auth_3d_ids) - j.set_enable(false); + for (auth_3d_detail::Handle& j : i.auth_3d_ids) + j.set_enabled(false); } void pv_game::edit_instrument_set_disp(int32_t rob_id, bool value) { pv_game_edit_instrument& v4 = data.edit_instrument[rob_id]; if (v4.index >= 0 && v4.auth_3d_ids.size()) { - auth_3d_id& id = v4.auth_3d_ids[v4.index]; - if (id.check_not_empty()) - id.set_visibility(value); + auth_3d_detail::Handle& id = v4.auth_3d_ids[v4.index]; + if (id.is_valid()) + id.set_visible(value); } } @@ -1979,11 +1979,11 @@ void pv_game::end(bool complete, bool set_fade) { } float_t pv_game::get_aet_frame_max_frame(int32_t aet_frame, int32_t aet_index, std::pair& aet_name_id, int64_t dsc_time, int64_t curr_time, float_t* max_frame) { - if (!max_frame) + std::string>& aet_name_id, int64_t dsc_time, int64_t curr_time, float_t* frame_max) { + if (!frame_max) return -1.0f; - *max_frame = -1.0f; + *frame_max = -1.0f; if (dsc_time < 0 || curr_time < 0) return 0.0f; @@ -1991,9 +1991,9 @@ float_t pv_game::get_aet_frame_max_frame(int32_t aet_frame, int32_t aet_index, s data.aet_time[aet_index].insert_or_assign(aet_name_id, dsc_time); if (!aet_frame) { - *max_frame = get_aet_frame_max_frame_change_field(aet_index, aet_name_id, dsc_time); - if (*max_frame < 0.0f) - *max_frame = get_next_aet_max_frame_change_field(aet_index, aet_name_id, dsc_time, curr_time); + *frame_max = get_aet_frame_max_frame_change_field(aet_index, aet_name_id, dsc_time); + if (*frame_max < 0.0f) + *frame_max = get_next_aet_max_frame_change_field(aet_index, aet_name_id, dsc_time, curr_time); } return 0.0f; } @@ -2007,19 +2007,19 @@ float_t pv_game::get_aet_frame_max_frame(int32_t aet_frame, int32_t aet_index, s } if (aet_frame == -1) { - *max_frame = get_aet_frame_max_frame_change_field(aet_index, aet_name_id, dsc_time); - if (*max_frame < 0.0f) - *max_frame = get_next_aet_max_frame_change_field(aet_index, aet_name_id, dsc_time, curr_time); + *frame_max = get_aet_frame_max_frame_change_field(aet_index, aet_name_id, dsc_time); + if (*frame_max < 0.0f) + *frame_max = get_next_aet_max_frame_change_field(aet_index, aet_name_id, dsc_time, curr_time); } return frame; } else if (!((aet_frame + 6) & ~4u) && aet_frame == -2) - *max_frame = get_aet_frame_max_frame_change_field(aet_index, aet_name_id, dsc_time); + *frame_max = get_aet_frame_max_frame_change_field(aet_index, aet_name_id, dsc_time); return -1.0f; } -void pv_game::get_aet_frame_max_frame_by_name(float_t& frame, float_t& max_frame, std::pair& aet_name_id) { - if (frame < 0.0f && max_frame < 0.0f || !data.pv_disp2d) +void pv_game::get_aet_frame_max_frame_by_name(float_t& frame, float_t& frame_max, std::pair& aet_name_id) { + if (frame < 0.0f && frame_max < 0.0f || !data.pv_disp2d) return; data_struct* aft_data = &data_list[DATA_AFT]; @@ -2038,10 +2038,10 @@ void pv_game::get_aet_frame_max_frame_by_name(float_t& frame, float_t& max_frame frame = end_frame; } - if (max_frame >= 0.0f) { - max_frame += start_frame; - if (end_frame >= 0.0f && max_frame > end_frame) - max_frame = end_frame; + if (frame_max >= 0.0f) { + frame_max += start_frame; + if (end_frame >= 0.0f && frame_max > end_frame) + frame_max = end_frame; } } @@ -2065,12 +2065,12 @@ int64_t pv_game::get_aet_time(int32_t aet_index, std::pair= 0) { frame = dsc_time_to_frame(curr_time - auth_3d_time); float_t dsc_frame = prj::roundf(dsc_time_to_frame(dsc_time - auth_3d_time)); @@ -2097,18 +2097,18 @@ float_t pv_game::get_auth_3d_frame_max_frame(int32_t auth_3d_frame, int32_t auth } if (auth_3d_frame == -1) { - *max_frame = get_auth_3d_frame_max_frame_change_field(auth_3d_uid, dsc_time, type); - if (*max_frame < 0.0f) - *max_frame = get_next_auth_3d_max_frame_change_field(auth_3d_uid, dsc_time, curr_time, type); + *frame_max = get_scene_frame_max_frame_change_field(auth_3d_uid, dsc_time, type); + if (*frame_max < 0.0f) + *frame_max = get_next_auth_3d_max_frame_change_field(auth_3d_uid, dsc_time, curr_time, type); } return frame; } else if (!((auth_3d_frame + 6) & ~4u) && auth_3d_frame == -2) - *max_frame = get_auth_3d_frame_max_frame_change_field(auth_3d_uid, dsc_time, type); + *frame_max = get_scene_frame_max_frame_change_field(auth_3d_uid, dsc_time, type); return -1.0f; } -float_t pv_game::get_auth_3d_frame_max_frame_change_field(uint32_t auth_3d_uid, int64_t time, uint8_t type) { +float_t pv_game::get_scene_frame_max_frame_change_field(uint32_t auth_3d_uid, int64_t time, uint8_t type) { if (time < 0) return -1.0f; @@ -2116,18 +2116,18 @@ float_t pv_game::get_auth_3d_frame_max_frame_change_field(uint32_t auth_3d_uid, ? data.pv_data.change_field_branch_fail : data.pv_data.change_field_branch_success; if (time == 10000LL * change_field.back().first) - return prj::roundf(dsc_time_to_frame(data.max_time - get_auth_3d_time(auth_3d_uid, type))) - 1.0f; + return prj::roundf(dsc_time_to_frame(data.max_time - get_scene_time(auth_3d_uid, type))) - 1.0f; return -1.0f; } -auth_3d_id pv_game::get_auth_3d_id(int32_t uid) { +auth_3d_detail::Handle pv_game::get_scene_id(int32_t uid) { auto elem = data.auth_3d.find(uid); if (elem != data.auth_3d.end()) return elem->second; return {}; } -int64_t pv_game::get_auth_3d_time(int32_t uid, uint8_t type) { +int64_t pv_game::get_scene_time(int32_t uid, uint8_t type) { switch (type) { case 0: { auto elem = data.auth_3d_time.find(uid); @@ -2164,7 +2164,7 @@ uint32_t pv_game::get_chreff_auth_3d_object_set(int32_t& uid) { } if (obj_set == -1 && uid >= 0 && uid < aft_auth_3d_db->uid.size()) { - std::string& category = aft_auth_3d_db->uid[uid].category; + const std::string& category = aft_auth_3d_db->uid[uid].category_name; if (!category.find("EFFCHRPV")) return aft_obj_db->get_object_set_id(category.c_str()); } @@ -2201,7 +2201,7 @@ int32_t pv_game::get_field_aet_frame_by_name_id(pv_game_field& field, int32_t pv_game::get_field_aet_index_by_name_id(pv_game_field& field, int32_t aet_index, std::pair& aet_name_id) { int32_t index = 0; - for (std::string& i : field.aet_names[aet_index]) { + for (const std::string& i : field.aet_names[aet_index]) { std::string* id = 0; if (index < field.aet_ids[aet_index].size()) id = &field.aet_ids[aet_index][index]; @@ -2263,18 +2263,18 @@ float_t pv_game::get_next_aet_max_frame_change_field(int32_t aet_index, std::pai aet_name_id, dsc_time, &max_time, curr_time, change_field); } - float_t max_frame_fail = get_next_aet_max_time_max_frame_change_field(aet_index, + float_t frame_max_fail = get_next_aet_max_time_max_frame_change_field(aet_index, aet_name_id, dsc_time, &max_time, curr_time, data.pv_data.change_field_branch_fail); - if (max_frame_fail < 0.0f) + if (frame_max_fail < 0.0f) return get_next_aet_max_time_max_frame_change_field(aet_index, aet_name_id, dsc_time, &max_time, curr_time, data.pv_data.change_field_branch_success); else if (max_time > data.pv_data.change_field_branch_time) { - float_t max_frame_success = get_next_aet_max_time_max_frame_change_field(aet_index, + float_t frame_max_success = get_next_aet_max_time_max_frame_change_field(aet_index, aet_name_id, dsc_time, &max_time, curr_time, data.pv_data.change_field_branch_success); - if (max_frame_success >= 0.0f && max_frame_success < max_frame_fail) - return max_frame_success; + if (frame_max_success >= 0.0f && frame_max_success < frame_max_fail) + return frame_max_success; } - return max_frame_fail; + return frame_max_fail; } float_t pv_game::get_next_aet_max_time_max_frame_change_field(int32_t aet_index, @@ -2308,18 +2308,18 @@ float_t pv_game::get_next_auth_3d_max_frame_change_field(uint32_t auth_3d_uid, dsc_time, &max_time, curr_time, change_field, type); } - float_t max_frame_fail = get_next_auth_3d_max_time_max_frame_change_field(auth_3d_uid, + float_t frame_max_fail = get_next_auth_3d_max_time_max_frame_change_field(auth_3d_uid, dsc_time, &max_time, curr_time, data.pv_data.change_field_branch_fail, type); - if (max_frame_fail < 0.0f) + if (frame_max_fail < 0.0f) return get_next_auth_3d_max_time_max_frame_change_field(auth_3d_uid, dsc_time, &max_time, curr_time, data.pv_data.change_field_branch_success, type); else if (max_time > data.pv_data.change_field_branch_time) { - float_t max_frame_success = get_next_auth_3d_max_time_max_frame_change_field(auth_3d_uid, + float_t frame_max_success = get_next_auth_3d_max_time_max_frame_change_field(auth_3d_uid, dsc_time, &max_time, curr_time, data.pv_data.change_field_branch_success, type); - if (max_frame_success >= 0.0f && max_frame_success < max_frame_fail) - return max_frame_success; + if (frame_max_success >= 0.0f && frame_max_success < frame_max_fail) + return frame_max_success; } - return max_frame_fail; + return frame_max_fail; } float_t pv_game::get_next_auth_3d_max_time_max_frame_change_field(uint32_t auth_3d_uid, int64_t dsc_time, @@ -2332,7 +2332,7 @@ float_t pv_game::get_next_auth_3d_max_time_max_frame_change_field(uint32_t auth_ if (time > dsc_time && i.second >= 0 && i.second < data.field_data.size() && ((get_field_auth_3d_frame(data.field_data[i.second], auth_3d_uid, type) + 5) & -6) == 0) { *max_time = time; - return prj::roundf(dsc_time_to_frame(time - get_auth_3d_time(auth_3d_uid, type))) - 1.0f; + return prj::roundf(dsc_time_to_frame(time - get_scene_time(auth_3d_uid, type))) - 1.0f; } } return -1.0f; @@ -2455,14 +2455,14 @@ bool pv_game::is_play_data_option_3() { void pv_game::itmpv_reset() { for (auto& i : data.itmpv) for (auto& j : i) { - auth_3d_id& id = j.second.first; - id.set_repeat(0); - id.set_enable(0); - id.set_camera_root_update(0); - id.set_visibility(1); - id.set_frame_rate(get_diva_pv_frame_rate()); + auth_3d_detail::Handle& id = j.second.first; + id.set_looped(false); + id.set_enabled(false);; + id.camera_set_enabled(false); + id.set_visible(true); + id.set_frame_rate_control(get_diva_pv_frame_rate()); id.set_shadow(true); - id.set_chara_id((int32_t)(&i - data.itmpv)); + id.assign_rob_id((int32_t)(&i - data.itmpv)); j.second.second = -1; } } @@ -2955,11 +2955,11 @@ bool pv_game::load() { chreff.src_auth_3d_uid = aft_auth_3d_db->get_uid(chreff.src_auth_3d.c_str()); chreff.dst_auth_3d_uid = aft_auth_3d_db->get_uid(chreff.dst_auth_3d.c_str()); - std::string& src_category = aft_auth_3d_db->uid[chreff.src_auth_3d_uid].category; + const std::string& src_category = aft_auth_3d_db->uid[chreff.src_auth_3d_uid].category_name; if (src_category.size()) chreff.src_auth_3d_category.assign(src_category); - std::string& dst_category = aft_auth_3d_db->uid[chreff.dst_auth_3d_uid].category; + const std::string& dst_category = aft_auth_3d_db->uid[chreff.dst_auth_3d_uid].category_name; if (dst_category.size()) chreff.dst_auth_3d_category.assign(dst_category); @@ -3041,8 +3041,8 @@ bool pv_game::load() { field.auth_3d_uids.push_back(auth_3d_uid); data.loaded_auth_3d_uids.push_back(auth_3d_uid); - if (aft_auth_3d_db->uid[auth_3d_uid].category.size()) - data.auth_3d_categories.push_back(aft_auth_3d_db->uid[auth_3d_uid].category); + if (aft_auth_3d_db->uid[auth_3d_uid].category_name.size()) + data.auth_3d_categories.push_back(aft_auth_3d_db->uid[auth_3d_uid].category_name); if (chreff_auth_3d_obj_set_id != -1) data.chreff_auth_3d_obj_set_ids.push_back(chreff_auth_3d_obj_set_id); @@ -3070,8 +3070,8 @@ bool pv_game::load() { if (i.light_frame_set) data.has_light_frame = true; - if (aft_auth_3d_db->uid[light_uid].category.size()) - data.auth_3d_categories.push_back(aft_auth_3d_db->uid[light_uid].category); + if (aft_auth_3d_db->uid[light_uid].category_name.size()) + data.auth_3d_categories.push_back(aft_auth_3d_db->uid[light_uid].category_name); size_t pos = i.light.find('_'); if (pos != -1) { @@ -3150,7 +3150,7 @@ bool pv_game::load() { data.field_data.push_back(field); } - prj::sort_unique(data.chreff_auth_3d_obj_set_ids); + prj::sort_and_erase_non_unique(data.chreff_auth_3d_obj_set_ids); for (uint32_t& i : data.chreff_auth_3d_obj_set_ids) objset_info_storage_load_set(aft_data, aft_obj_db, i); @@ -3174,7 +3174,7 @@ bool pv_game::load() { if (data.itmpv_auth_3d_uids.size()) { data.auth_3d_categories.push_back(data.itmpv_string); for (int32_t& i : data.itmpv_auth_3d_uids) - check_auth_replace_by_module(auth_3d_data_get_uid_name(i, aft_auth_3d_db), i); + check_auth_replace_by_module(auth_3d_detail::get_name_uid(i, aft_auth_3d_db), i); data.loaded_auth_3d_uids.insert(data.loaded_auth_3d_uids.end(), data.itmpv_auth_3d_uids.begin(), data.itmpv_auth_3d_uids.end()); @@ -3184,11 +3184,11 @@ bool pv_game::load() { for (int32_t i = 0; i < 3; i++) { v261 |= !!diff->field_228[i].size(); for (auto& j : diff->field_228[i]) - data.itmpv_uids.push_back(auth_3d_data_get_uid_name(j.second.second, aft_auth_3d_db)); + data.itmpv_uids.push_back(auth_3d_detail::get_name_uid(j.second.second, aft_auth_3d_db)); } if (v261) - for (std::string& i : data.itmpv_uids) + for (const std::string& i : data.itmpv_uids) data.auth_3d_categories.push_back(i); data.field_2D770.clear(); @@ -3196,7 +3196,7 @@ bool pv_game::load() { for (auto& j : diff->field_228[i]) data.field_2D770.push_back(j.second.first.set_id); - prj::sort_unique(data.field_2D770); + prj::sort_and_erase_non_unique(data.field_2D770); for (uint32_t& i : data.field_2D770) objset_info_storage_load_set(aft_data, aft_obj_db, i); @@ -3205,7 +3205,7 @@ bool pv_game::load() { for (const pv_db_pv_ex_song_ex_auth& j : i.ex_auth) { uint32_t uid = aft_auth_3d_db->get_uid(j.org_name.c_str()); data.loaded_auth_3d_uids.push_back(uid); - const char* category_name = aft_auth_3d_db->uid[uid].category.c_str(); + const char* category_name = aft_auth_3d_db->uid[uid].category_name.c_str(); if (category_name) { uint32_t obj_set_id = aft_obj_db->get_object_set_id(category_name); if (obj_set_id != -1) @@ -3213,11 +3213,11 @@ bool pv_game::load() { } } - prj::sort_unique(data.ex_song_ex_auth_obj_set_ids); + prj::sort_and_erase_non_unique(data.ex_song_ex_auth_obj_set_ids); for (uint32_t& i : data.ex_song_ex_auth_obj_set_ids) objset_info_storage_load_set(aft_data, aft_obj_db, i); - prj::sort_unique(data.stage_indices); + prj::sort_and_erase_non_unique(data.stage_indices); if (!data.stage_indices.size()) data.stage_indices.push_back(0); @@ -3238,7 +3238,7 @@ bool pv_game::load() { data.stgpvhrc_obj_set_ids.push_back(obj_set_id); } - prj::sort_unique(data.stgpvhrc_obj_set_ids); + prj::sort_and_erase_non_unique(data.stgpvhrc_obj_set_ids); for (uint32_t& i : data.stgpvhrc_obj_set_ids) objset_info_storage_load_set(aft_data, aft_obj_db, i); @@ -3271,38 +3271,38 @@ bool pv_game::load() { state = 2; } break; case 8: { - prj::sort_unique(data.spr_set_back_ids); + prj::sort_and_erase_non_unique(data.spr_set_back_ids); for (uint32_t& i : data.spr_set_back_ids) spr::request(i, std::string(data.pv->mdata.dir), aft_data, aft_spr_db); data.field_2D7E8 = true; - prj::sort_unique(data.auth_3d_categories); - for (std::string& i : data.auth_3d_categories) - auth_3d_data_load_category(i.c_str(), data.pv->mdata.dir.c_str()); + prj::sort_and_erase_non_unique(data.auth_3d_categories); + for (const std::string& i : data.auth_3d_categories) + auth_3d_detail::category_load_req(i.c_str(), data.pv->mdata.dir.c_str()); data.field_2DAC8 = true; - prj::sort_unique(data.loaded_auth_3d_uids); + prj::sort_and_erase_non_unique(data.loaded_auth_3d_uids); for (int32_t& i : data.loaded_auth_3d_uids) { - auth_3d_id id = auth_3d_id(i, aft_auth_3d_db); - if (!id.check_not_empty()) + auth_3d_detail::Handle id = auth_3d_detail::Handle::create(i, aft_auth_3d_db); + if (!id.is_valid()) continue; - id.set_enable(false); - id.set_repeat(true); - id.set_paused(false); + id.set_enabled(false); + id.set_looped(true); + id.set_pause(false); data.auth_3d.insert_or_assign(i, id); } for (pv_game_field& i : data.field_data) { for (int32_t& j : i.auth_3d_uids) { - auth_3d_id id = get_auth_3d_id(j); - if (!id.check_not_empty()) + auth_3d_detail::Handle id = get_scene_id(j); + if (!id.is_valid()) continue; for (pv_game_chreff& k : data.chreff_auth_3d_obj) if (k.dst_auth_3d_uid == j) { - id.set_src_dst_chara(k.src_chara_num, k.dst_chara_num); + id.replace_chara(k.src_chara_num, k.dst_chara_num); break; } @@ -3311,15 +3311,15 @@ bool pv_game::load() { prj::sort(i.auth_3d_ids); - auth_3d_id light_auth_3d_id = get_auth_3d_id(i.light_auth_3d_uid); - if (light_auth_3d_id.check_not_empty()) + auth_3d_detail::Handle light_auth_3d_id = get_scene_id(i.light_auth_3d_uid); + if (light_auth_3d_id.is_valid()) i.light_auth_3d_id = light_auth_3d_id; else i.light_auth_3d_id = {}; } for (int32_t& i : data.campv_auth_3d_uids) { - const char* name = auth_3d_data_get_uid_name(i, aft_auth_3d_db); + const char* name = auth_3d_detail::get_name_uid(i, aft_auth_3d_db); if (!name) continue; @@ -3329,17 +3329,17 @@ bool pv_game::load() { auto elem = data.auth_3d.find(i); if (elem != data.auth_3d.end()) { - auth_3d_id& id = elem->second; - id.set_camera_root_update(true); - id.set_repeat(false); - id.set_frame_rate(get_diva_pv_frame_rate()); + auth_3d_detail::Handle& id = elem->second; + id.camera_set_enabled(true); + id.set_looped(false); + id.set_frame_rate_control(get_diva_pv_frame_rate()); data.campv.insert_or_assign(cam_index, id); } } data.campv_index = 0; for (int32_t& i : data.itmpv_auth_3d_uids) { - const char* name = auth_3d_data_get_uid_name(i, aft_auth_3d_db); + const char* name = auth_3d_detail::get_name_uid(i, aft_auth_3d_db); if (!name) continue; @@ -3368,22 +3368,22 @@ bool pv_game::load() { auto elem = data.auth_3d.find(i); if (elem != data.auth_3d.end()) data.itmpv[chara_id].insert_or_assign(itm_index, - std::pair(elem->second, -1)); + std::pair(elem->second, -1)); } } itmpv_reset(); for (pv_game_edit_instrument& i : data.edit_instrument) { for (auto& j : i.data) { - auth_3d_id id = auth_3d_id(j.second, aft_auth_3d_db); - if (!id.check_not_empty()) + auth_3d_detail::Handle id = auth_3d_detail::Handle::create(j.second, aft_auth_3d_db); + if (!id.is_valid()) continue; - id.set_enable(false); - id.set_repeat(true); - id.set_paused(false); - id.set_camera_root_update(false); - //id.set_object_info(j.first); + id.set_enabled(false); + id.set_looped(true); + id.set_pause(false); + id.camera_set_enabled(false); + id.set_obj_uid(j.first); i.auth_3d_ids.push_back(id); } } @@ -3441,7 +3441,7 @@ bool pv_game::load() { if (itmpv_obj_set != -1) data.obj_set_itmpv.push_back(itmpv_obj_set); - prj::sort_unique(data.obj_set_itmpv); + prj::sort_and_erase_non_unique(data.obj_set_itmpv); for (uint32_t& i : data.obj_set_itmpv) objset_info_storage_load_set(aft_data, aft_obj_db, i); @@ -3465,7 +3465,7 @@ bool pv_game::load() { } } - prj::sort_unique(data.obj_set_handitem); + prj::sort_and_erase_non_unique(data.obj_set_handitem); for (uint32_t& i : data.obj_set_handitem) objset_info_storage_load_set(aft_data, aft_obj_db, i); @@ -3483,8 +3483,8 @@ bool pv_game::load() { if (spr::wait(i, aft_spr_db)) wait_load |= true; - for (std::string& i : data.auth_3d_categories) - if (!auth_3d_data_check_category_loaded(i.c_str())) + for (const std::string& i : data.auth_3d_categories) + if (!auth_3d_detail::category_load_is_done(i.c_str())) wait_load |= true; for (uint32_t& i : data.edit_effect.aet_set_ids) @@ -3528,11 +3528,11 @@ bool pv_game::load() { } break; case 10: { for (auto& i : data.auth_3d) - i.second.read_file(aft_auth_3d_db); + i.second.load_req(aft_auth_3d_db); for (pv_game_edit_instrument& i : data.edit_instrument) - for (auth_3d_id& j : i.auth_3d_ids) - j.read_file(aft_auth_3d_db); + for (auth_3d_detail::Handle& j : i.auth_3d_ids) + j.load_req(aft_auth_3d_db); if (Glitter::glt_particle_manager) { Glitter::counter.Reset(); @@ -3549,12 +3549,12 @@ bool pv_game::load() { bool wait_load = false; for (auto& i : data.auth_3d) - if (!i.second.check_loaded()) + if (!i.second.load_is_done()) wait_load |= true; for (pv_game_edit_instrument& i : data.edit_instrument) - for (auth_3d_id& j : i.auth_3d_ids) - if (!j.check_loaded()) + for (auth_3d_detail::Handle& j : i.auth_3d_ids) + if (!j.load_is_done()) wait_load |= true; if (!wait_load) @@ -3628,7 +3628,7 @@ bool pv_game::load() { } for (pv_game_field& j : data.field_data) - for (auth_3d_id& k : j.auth_3d_ids) + for (auth_3d_detail::Handle& k : j.auth_3d_ids) if (k.get_uid() == org_uid) { auto elem = data.auth_3d.find(uid); if (elem != data.auth_3d.end()) { @@ -3884,13 +3884,13 @@ bool pv_game::load() { } for (int32_t& i : data.campv_auth_3d_uids) { - const char* name = auth_3d_data_get_uid_name(i, aft_auth_3d_db); + const char* name = auth_3d_detail::get_name_uid(i, aft_auth_3d_db); if (!name || !check_chrcam(name, i)) continue; auto elem = data.auth_3d.find(i); if (elem != data.auth_3d.end()) - elem->second.set_enable(false); + elem->second.set_enabled(false); } itmpv_reset(); @@ -3899,18 +3899,18 @@ bool pv_game::load() { for (pv_game_field& i : data.field_data) { for (int32_t& j : i.auth_3d_uids) { - auth_3d_id id = get_auth_3d_id(j); - id.set_enable(false); - id.set_visibility(false); - id.set_paused(false); - id.set_req_frame(0.0f); + auth_3d_detail::Handle id = get_scene_id(j); + id.set_enabled(false); + id.set_visible(false); + id.set_pause(false); + id.set_frame_req(0.0f); } - if (i.light_auth_3d_id.check_not_empty()) { - i.light_auth_3d_id.set_enable(false); - i.light_auth_3d_id.set_visibility(false); - i.light_auth_3d_id.set_paused(false); - i.light_auth_3d_id.set_req_frame(0.0f); + if (i.light_auth_3d_id.is_valid()) { + i.light_auth_3d_id.set_enabled(false); + i.light_auth_3d_id.set_visible(false); + i.light_auth_3d_id.set_pause(false); + i.light_auth_3d_id.set_frame_req(0.0f); } } @@ -4235,11 +4235,11 @@ void pv_game::reset_field() { if (data.current_field) { pv_game_field& curr_field_data = data.field_data[data.current_field]; - for (auth_3d_id& i : curr_field_data.auth_3d_ids) - i.set_enable(false); + for (auth_3d_detail::Handle& i : curr_field_data.auth_3d_ids) + i.set_enabled(false); - if (curr_field_data.light_auth_3d_id.check_not_empty()) - curr_field_data.light_auth_3d_id.set_enable(false); + if (curr_field_data.light_auth_3d_id.is_valid()) + curr_field_data.light_auth_3d_id.set_enabled(false); data.current_field = 0; } @@ -4336,15 +4336,14 @@ void pv_game::restart() { auth_3d_database* aft_auth_3d_db = &aft_data->data_ft.auth_3d_db; for (int32_t& i : data.campv_auth_3d_uids) { - int32_t uid = i; - const char* name = auth_3d_data_get_uid_name(uid, aft_auth_3d_db); - if (!name) + const char* name = auth_3d_detail::get_name_uid(i, aft_auth_3d_db); continue; + int32_t uid = i; if (check_chrcam(name, uid)) { auto elem = data.auth_3d.find(uid); if (elem != data.auth_3d.end()) - elem->second.set_enable(false); + elem->second.set_enabled(false); } } @@ -4382,16 +4381,16 @@ void pv_game::set_data_campv(int32_t type, int32_t index, float_t frame) { if (campv_index) { auto elem = data.campv.find(campv_index); if (elem != data.campv.end()) - elem->second.set_enable(false); + elem->second.set_enabled(false); } data.campv_index = index; - auth_3d_id& id = elem->second; - id.set_enable(true); + auth_3d_detail::Handle& id = elem->second; + id.set_enabled(true); data.camera_auth_3d_uid = id.get_uid(); if (type == 0 || type == 1) { - id.set_req_frame(frame); - id.set_paused(false); + id.set_frame_req(frame); + id.set_pause(false); } } @@ -4400,15 +4399,15 @@ void pv_game::set_data_itmpv(int32_t rob_id, int32_t index, bool enable, int64_t if (elem == data.itmpv[rob_id].end()) return; - auth_3d_id& id = elem->second.first; + auth_3d_detail::Handle& id = elem->second.first; if (enable) { - id.set_enable(true); - id.set_paused(false); - id.set_req_frame(0.0f); + id.set_enabled(true); + id.set_pause(false); + id.set_frame_req(0.0f); elem->second.second = time; } else { - id.set_enable(false); + id.set_enabled(false); elem->second.second = -1; } } @@ -4416,35 +4415,35 @@ void pv_game::set_data_itmpv(int32_t rob_id, int32_t index, bool enable, int64_t void pv_game::set_data_itmpv_chara_id(int32_t rob_id, int32_t index, bool attach) { auto elem = data.itmpv[rob_id].find(index); if (elem != data.itmpv[rob_id].end()) - elem->second.first.set_chara_id(attach ? rob_id : ROB_ID_NULL); + elem->second.first.assign_rob_id(attach ? rob_id : ROB_ID_NULL); } void pv_game::set_data_itmpv_req_frame(int32_t rob_id, int32_t index, float_t value) { auto elem = data.itmpv[rob_id].find(index); if (elem != data.itmpv[rob_id].end()) - elem->second.first.set_req_frame(value); + elem->second.first.set_frame_req(value); } void pv_game::set_data_itmpv_max_frame(int32_t rob_id, float_t value) { for (auto& i : data.itmpv[rob_id]) - i.second.first.set_max_frame(value); + i.second.first.set_frame_max(value); } void pv_game::set_data_itmpv_max_frame(int32_t rob_id, int32_t index, float_t value) { auto elem = data.itmpv[rob_id].find(index); if (elem != data.itmpv[rob_id].end()) - elem->second.first.set_max_frame(value); + elem->second.first.set_frame_max(value); } void pv_game::set_data_itmpv_visibility(int32_t rob_id, bool value) { for (auto& i : data.itmpv[rob_id]) - i.second.first.set_visibility(value); + i.second.first.set_visible(value); } void pv_game::set_data_itmpv_visibility(int32_t rob_id, int32_t index, bool value) { auto elem = data.itmpv[rob_id].find(index); if (elem != data.itmpv[rob_id].end()) - elem->second.first.set_visibility(value); + elem->second.first.set_visible(value); } void pv_game::set_edit_instrument(int32_t rob_id, bool disp, int32_t index, float_t frame, float_t frame_speed) { @@ -4456,26 +4455,26 @@ void pv_game::set_edit_instrument(int32_t rob_id, bool disp, int32_t index, floa if (edit_instrument.index >= edit_instrument.auth_3d_ids.size()) return; - auth_3d_id& id = edit_instrument.auth_3d_ids[edit_instrument.index]; - id.set_enable(false); + auth_3d_detail::Handle& id = edit_instrument.auth_3d_ids[edit_instrument.index]; + id.set_enabled(false); } if (index >= 0) { if (index >= edit_instrument.auth_3d_ids.size()) return; - auth_3d_id& id = edit_instrument.auth_3d_ids[index]; - if (id.check_not_empty()) { - id.set_enable(true); - id.set_visibility(disp); - id.set_paused(false); - id.set_req_frame(frame); - id.set_chara_id(rob_id); - id.set_last_frame(id.get_play_control_size() - 1.0f); + auth_3d_detail::Handle& id = edit_instrument.auth_3d_ids[index]; + if (id.is_valid()) { + id.set_enabled(true); + id.set_visible(disp); + id.set_pause(false); + id.set_frame_req(frame); + id.assign_rob_id(rob_id); + id.set_frame_loop_end(id.get_frame_size() - 1.0f); FrameRateControl* sys_frame_rate = sys_frame_rate_get(rob_id); sys_frame_rate->set_frame_speed(frame_speed); - id.set_frame_rate(sys_frame_rate); + id.set_frame_rate_control(sys_frame_rate); } } edit_instrument.index = index; @@ -4765,15 +4764,15 @@ bool pv_game::unload() { data.enable_movie = true; for (auto& i : data.auth_3d) - i.second.unload(rctx_ptr); + i.second.destroy(rctx_ptr); for (auto& i : data.edit_instrument) for (auto& j : i.auth_3d_ids) - j.unload(rctx_ptr); + j.destroy(rctx_ptr); if (data.field_2DAC8) - for (std::string& i : data.auth_3d_categories) - auth_3d_data_unload_category(i.c_str()); + for (const std::string& i : data.auth_3d_categories) + auth_3d_detail::category_free(i.c_str()); data.camera_auth_3d_uid = -1; data.campv_string.clear(); @@ -5045,7 +5044,7 @@ void pv_game::chara_item_alpha_callback(void* data, ROB_ID rob_id, int32_t type, } for (auto& i : ((pv_game*)data)->data.itmpv[rob_id]) - i.second.first.set_alpha_obj_flags(alpha, flags); + i.second.first.set_trnsl(alpha, flags); } void pv_game::get_item_mask(pv_performer_type type, @@ -5266,7 +5265,7 @@ bool TaskPvGame::init() { #endif load(data); - //touch_util::touch_reaction_set_enable(false); + //touch_util::touch_reaction_set_enabled(false); return true; } @@ -5280,7 +5279,7 @@ bool TaskPvGame::dest() { set_next_frame_speed(1.0f); - //touch_util::touch_reaction_set_enable(true); + //touch_util::touch_reaction_set_enabled(true); return true; } diff --git a/src/ReDIVA/pv_game/pv_game.hpp b/src/ReDIVA/pv_game/pv_game.hpp index 8ec84f70..fb62e904 100644 --- a/src/ReDIVA/pv_game/pv_game.hpp +++ b/src/ReDIVA/pv_game/pv_game.hpp @@ -84,10 +84,10 @@ struct pv_game_edit_effect { struct pv_game_field { int32_t stage_index; std::vector auth_3d_uids; - std::vector auth_3d_ids; + std::vector auth_3d_ids; std::map auth_3d_frame_list; int32_t light_auth_3d_uid; - auth_3d_id light_auth_3d_id; + auth_3d_detail::Handle light_auth_3d_id; int32_t light_frame; std::vector aet_names[4]; std::vector aet_ids[4]; @@ -107,7 +107,7 @@ struct pv_game_field { struct pv_game_edit_instrument { prj::vector_pair data; - std::vector auth_3d_ids; + std::vector auth_3d_ids; int32_t index; pv_game_edit_instrument(); @@ -277,19 +277,19 @@ struct pv_game_data { std::map, int64_t> aet_time[4]; std::string campv_string; std::vector campv_auth_3d_uids; - std::map campv; + std::map campv; int32_t campv_index; int32_t field_2D954; std::string itmpv_string; std::vector itmpv_auth_3d_uids; - std::map> itmpv[ROB_ID_MAX]; + std::map> itmpv[ROB_ID_MAX]; std::vector itmpv_uids; pv_game_edit_instrument edit_instrument[3]; std::vector loaded_auth_3d_uids; bool field_2DAC8; int32_t field_2DACC; std::vector auth_3d_categories; - std::map auth_3d; + std::map auth_3d; std::vector chreff_auth_3d; std::vector chreff_auth_3d_obj; bool height_adjust; @@ -386,11 +386,11 @@ struct pv_game { float_t get_aet_frame_max_frame_change_field(int32_t aet_index, std::pair& aet_name_id, int64_t time); int64_t get_aet_time(int32_t aet_index, std::pair& aet_name_id); - float_t get_auth_3d_frame_max_frame(int32_t auth_3d_frame, int32_t auth_3d_uid, + float_t get_scene_frame_max_frame(int32_t auth_3d_frame, int32_t auth_3d_uid, int64_t dsc_time, int64_t curr_time, uint8_t type, float_t* max_frame); - float_t get_auth_3d_frame_max_frame_change_field(uint32_t auth_3d_uid, int64_t time, uint8_t type); - auth_3d_id get_auth_3d_id(int32_t uid); - int64_t get_auth_3d_time(int32_t uid, uint8_t type); + float_t get_scene_frame_max_frame_change_field(uint32_t auth_3d_uid, int64_t time, uint8_t type); + auth_3d_detail::Handle get_scene_id(int32_t uid); + int64_t get_scene_time(int32_t uid, uint8_t type); uint32_t get_chreff_auth_3d_object_set(int32_t& uid); int64_t get_data_itmpv_time(int32_t rob_id, int32_t index); float_t get_data_rival_percentage(); diff --git a/src/ReDIVA/pv_game/pv_game_camera.cpp b/src/ReDIVA/pv_game/pv_game_camera.cpp index 6394ba16..218bd382 100644 --- a/src/ReDIVA/pv_game/pv_game_camera.cpp +++ b/src/ReDIVA/pv_game/pv_game_camera.cpp @@ -43,8 +43,8 @@ extern render_context* rctx_ptr; pv_game_camera pv_game_camera_data; static float_t pv_game_camera_get_acceleration(); -static bool pv_game_camera_get_edit_camera(cam_struct* cam, float_t delta_time); -static bool pv_game_camera_get_move_camera(cam_struct* cam, float_t delta_time); +static bool pv_game_camera_get_edit_camera(CameraParam* cam, float_t delta_time); +static bool pv_game_camera_get_move_camera(CameraParam* cam, float_t delta_time); pv_game_camera::pv_game_camera() : enable(), follow_chara(), edit_camera(), duration(), curr_time(), start_distance(), end_distance(), fov(), min_dist(), rob_id(), chara_follow_point(), @@ -86,14 +86,14 @@ void pv_game_camera_ctrl(float_t delta_time) { return; bool in_transition; - cam_struct cam; + CameraParam cam; if (pv_game_camera_data.edit_camera) in_transition = pv_game_camera_get_edit_camera(&cam, delta_time); else in_transition = pv_game_camera_get_move_camera(&cam, delta_time); - cam.fov = pv_game_camera_data.fov * DEG_TO_RAD_FLOAT; - cam.min_distance = pv_game_camera_data.min_dist; + cam.v_fov = pv_game_camera_data.fov * DEG_TO_RAD_FLOAT; + cam.clip_near = pv_game_camera_data.min_dist; cam.set(rctx_ptr->camera); if (!in_transition) @@ -212,7 +212,7 @@ static float_t pv_game_camera_get_acceleration() { return min_def(acceleration, 1.0f); } -static bool pv_game_camera_get_edit_camera(cam_struct* cam, float_t delta_time) { +static bool pv_game_camera_get_edit_camera(CameraParam* cam, float_t delta_time) { if (!cam) return false; @@ -248,7 +248,7 @@ static bool pv_game_camera_get_edit_camera(cam_struct* cam, float_t delta_time) return in_transition; } -static bool pv_game_camera_get_move_camera(cam_struct* cam, float_t delta_time) { +static bool pv_game_camera_get_move_camera(CameraParam* cam, float_t delta_time) { if (!cam) return false; diff --git a/src/ReDIVA/pv_game/pv_game_pv_data.cpp b/src/ReDIVA/pv_game/pv_game_pv_data.cpp index 27745d64..30022de5 100644 --- a/src/ReDIVA/pv_game/pv_game_pv_data.cpp +++ b/src/ReDIVA/pv_game/pv_game_pv_data.cpp @@ -517,7 +517,7 @@ bool pv_game_pv_data::dsc_ctrl(float_t delta_time, int64_t curr_time, pv_expression_file_name.c_str(), rob_id, i.motion_id); if (!pv_game->data.pv->disable_calc_motfrm_limit) - set_motion_max_frame(rob_id, i.motion_index, i.dsc_time); + set_motion_frame_max(rob_id, i.motion_index, i.dsc_time); } playdata->set_motion.clear(); } @@ -641,7 +641,7 @@ bool pv_game_pv_data::dsc_ctrl(float_t delta_time, int64_t curr_time, pv_expression_file_name.c_str(), rob_id, motion_id); if (!pv_game->data.pv->disable_calc_motfrm_limit) - set_motion_max_frame(rob_id, motion_index, motion ? motion->time : 0); + set_motion_frame_max(rob_id, motion_index, motion ? motion->time : 0); } else { playdata->set_motion.clear(); @@ -701,7 +701,7 @@ bool pv_game_pv_data::dsc_ctrl(float_t delta_time, int64_t curr_time, pv_game->set_data_campv(0, index, frame); rctx_ptr->camera->set_fast_change_hist0(true); - set_camera_max_frame(data_camera[0].time); + set_camera_frame_max(data_camera[0].time); } break; case 1: { if (data_camera[1].index != index - 1) { @@ -726,7 +726,7 @@ bool pv_game_pv_data::dsc_ctrl(float_t delta_time, int64_t curr_time, pv_game->set_data_campv(1, index, frame); rctx_ptr->camera->set_fast_change_hist0(true); - set_camera_max_frame(data_camera[1].time); + set_camera_frame_max(data_camera[1].time); } break; case 2: { pv_game->set_data_campv(2, index, 0.0f); @@ -1658,12 +1658,12 @@ bool pv_game_pv_data::dsc_ctrl(float_t delta_time, int64_t curr_time, if (frame < dsc_frame) frame = dsc_frame; pv_game->set_data_itmpv_req_frame(rob_id, index, frame); - set_item_anim_max_frame(rob_id, index, time); + set_item_anim_frame_max(rob_id, index, time); } } else if (v290 >= 0) { pv_game->set_data_itmpv(rob_id, index, v290 != 0, dsc_time); - set_item_anim_max_frame(rob_id, index, dsc_time); + set_item_anim_frame_max(rob_id, index, dsc_time); } if (disp >= 0) @@ -2582,7 +2582,7 @@ void pv_game_pv_data::scene_fade_ctrl(float_t delta_time) { scene_fade.ctrl(delta_time); } -void pv_game_pv_data::set_camera_max_frame(int64_t time) { +void pv_game_pv_data::set_camera_frame_max(int64_t time) { std::vector& data_camera = branch_mode != 2 ? data_camera_branch_fail : data_camera_branch_success; @@ -2590,17 +2590,17 @@ void pv_game_pv_data::set_camera_max_frame(int64_t time) { if (10000LL * i <= dsc_time) continue; - float_t max_frame = prj::roundf(dsc_time_to_frame(10000LL * i - time)); + float_t frame_max = prj::roundf(dsc_time_to_frame(10000LL * i - time)); if (pv_game->data.camera_auth_3d_uid != -1) { - auth_3d_id id = pv_game->get_auth_3d_id(pv_game->data.camera_auth_3d_uid); - if (id.check_not_empty()) - id.set_max_frame(max_frame - 1.0f); + auth_3d_detail::Handle id = pv_game->get_scene_id(pv_game->data.camera_auth_3d_uid); + if (id.is_valid()) + id.set_frame_max(frame_max - 1.0f); } break; } } -void pv_game_pv_data::set_item_anim_max_frame(int32_t rob_id, int32_t index, int64_t time) { +void pv_game_pv_data::set_item_anim_frame_max(int32_t rob_id, int32_t index, int64_t time) { if (rob_id < 0 || rob_id >= ROB_ID_MAX || index < 0) return; @@ -2612,7 +2612,7 @@ void pv_game_pv_data::set_item_anim_max_frame(int32_t rob_id, int32_t index, int } } -void pv_game_pv_data::set_motion_max_frame(int32_t rob_id, int32_t motion_index, int64_t time) { +void pv_game_pv_data::set_motion_frame_max(int32_t rob_id, int32_t motion_index, int64_t time) { if (rob_id < 0 || rob_id >= ROB_ID_MAX || motion_index < 0) return; diff --git a/src/ReDIVA/pv_game/pv_game_pv_data.hpp b/src/ReDIVA/pv_game/pv_game_pv_data.hpp index 2c5be633..2f5e3ca7 100644 --- a/src/ReDIVA/pv_game/pv_game_pv_data.hpp +++ b/src/ReDIVA/pv_game/pv_game_pv_data.hpp @@ -344,7 +344,7 @@ struct pv_game_pv_data { void reset(); void reset_camera_post_process(); void scene_fade_ctrl(float_t delta_time); - void set_camera_max_frame(int64_t time); - void set_item_anim_max_frame(int32_t rob_id, int32_t index, int64_t time); - void set_motion_max_frame(int32_t rob_id, int32_t motion_index, int64_t time); + void set_camera_frame_max(int64_t time); + void set_item_anim_frame_max(int32_t rob_id, int32_t index, int64_t time); + void set_motion_frame_max(int32_t rob_id, int32_t motion_index, int64_t time); }; diff --git a/src/ReDIVA/x_pv_game.cpp b/src/ReDIVA/x_pv_game.cpp index ae638863..6683c814 100644 --- a/src/ReDIVA/x_pv_game.cpp +++ b/src/ReDIVA/x_pv_game.cpp @@ -503,9 +503,9 @@ static void x_pv_game_update_object_set(ObjsetInfo* info); static void x_pv_game_write_aet(uint32_t aet_set_id, const aet_database* aet_db, aet_database_file* x_pack_aet_db, const SprDbFile* x_pack_spr_db, const char* out_dir); -static bool x_pv_game_write_auth_3d(farc* f, auth_3d* auth, auth_3d_database_file* auth_3d_db, +static bool x_pv_game_write_auth_3d(farc* f, auth_3d_detail::Scene* in_scene, auth_3d_database_file* auth_3d_db, const char* category, std::vector& avail_uids, const char* out_dir); -static void x_pv_game_write_auth_3d_camera(auth_3d* auth, int32_t pv_id, +static void x_pv_game_write_auth_3d_camera(auth_3d_detail::Scene* in_scene, int32_t pv_id, auth_3d_database_file* auth_3d_db, std::vector& avail_uids, const char* out_dir); static void x_pv_game_write_auth_3d_category(const std::string& category, auth_3d_database_file* auth_3d_db, std::vector& avail_uids, const char* out_dir); @@ -542,7 +542,7 @@ static void replace_pv832(std::string& str); #endif #if BAKE_X_PACK -static bool get_replace_auth_name(char* name, size_t name_size, auth_3d* auth); +static bool get_replace_auth_name(char* name, size_t name_size, auth_3d_detail::Scene* in_scene); static void remove_auth_3d_category(auth_3d_database_file& auth_3d_db, std::vector& avail_uids, const char* category_name, const char* out_dir); static void replace_names(char* str); @@ -893,7 +893,7 @@ x_pv_game_song_effect_auth_3d::x_pv_game_song_effect_auth_3d() { } -x_pv_game_song_effect_auth_3d::x_pv_game_song_effect_auth_3d(auth_3d_id id) { +x_pv_game_song_effect_auth_3d::x_pv_game_song_effect_auth_3d(auth_3d_detail::Handle id) { this->id = id; } @@ -946,16 +946,16 @@ x_pv_game_camera::~x_pv_game_camera() { void x_pv_game_camera::ctrl(float_t curr_time) { switch (state) { case 10: { - if (!auth_3d_data_check_category_loaded(category.hash_murmurhash)) + if (!auth_3d_detail::category_load_is_done(category.hash_murmurhash)) break; - auth_3d_id id = auth_3d_id(file.hash_murmurhash, &data_list[DATA_X], 0, 0); - if (id.check_not_empty()) { - id.read_file_modern(); - id.set_enable(false); - id.set_repeat(false); - id.set_paused(false); - id.set_frame_rate(frame_rate_control); + auth_3d_detail::Handle id = auth_3d_detail::Handle::create(file.hash_murmurhash, &data_list[DATA_X], 0, 0); + if (id.is_valid()) { + id.load_req_modern(); + id.set_enabled(false); + id.set_looped(false); + id.set_pause(false); + id.set_frame_rate_control(frame_rate_control); } this->id = id; @@ -963,16 +963,16 @@ void x_pv_game_camera::ctrl(float_t curr_time) { state = 11; } break; case 11: { - if (id.check_not_empty() && id.check_loaded()) + if (id.is_valid() && id.load_is_done()) state = 20; } break; case 20: { - auth_3d_id& id = this->id; - id.set_enable(true); - id.set_repeat(false); - id.set_paused(false); - id.set_camera_root_update(true); - id.set_req_frame(curr_time * 60.0f); + auth_3d_detail::Handle& id = this->id; + id.set_enabled(true); + id.set_looped(false); + id.set_pause(false); + id.camera_set_enabled(true); + id.set_frame_req(curr_time * 60.0f); } break; } } @@ -995,7 +995,7 @@ void x_pv_game_camera::load_data() { if (state || !category.str.size()) return; - auth_3d_data_load_category(&data_list[DATA_X], category.c_str(), category.hash_murmurhash); + auth_3d_detail::category_load_req(&data_list[DATA_X], category.c_str(), category.hash_murmurhash); state = 10; } @@ -1007,8 +1007,8 @@ void x_pv_game_camera::reset() { } void x_pv_game_camera::stop() { - if (id.check_not_empty()) - id.set_enable(false); + if (id.is_valid()) + id.set_enabled(false); } void x_pv_game_camera::unload() { @@ -1019,8 +1019,8 @@ void x_pv_game_camera::unload_data() { if (state != 20) return; - id.unload(rctx_ptr); - auth_3d_data_unload_category(category.hash_murmurhash); + id.destroy(rctx_ptr); + auth_3d_detail::category_free(category.hash_murmurhash); state = 0; } @@ -1033,13 +1033,27 @@ x_pv_game_effect::~x_pv_game_effect() { } +void x_pv_game_effect::assign_rob_id(int32_t index, ROB_ID rob_id, bool chara_item) { + if (index < 0 || index >= song_effect.size()) + return; + + x_pv_game_song_effect& song_effect = this->song_effect[index]; + + for (x_pv_game_song_effect_auth_3d& i : song_effect.auth_3d) { + i.id.assign_rob_id(rob_id); + i.id.set_chara_item(chara_item); + } + + song_effect.rob_id = rob_id; +} + void x_pv_game_effect::ctrl(object_database* obj_db, texture_database* tex_db) { switch (state) { case 10: { bool wait_load = false; for (string_hash& i : pv_auth_3d) - if (!auth_3d_data_check_category_loaded(i.hash_murmurhash)) + if (!auth_3d_detail::category_load_is_done(i.hash_murmurhash)) wait_load |= true; for (string_hash& i : pv_obj_set) @@ -1059,16 +1073,16 @@ void x_pv_game_effect::ctrl(object_database* obj_db, texture_database* tex_db) { x_pv_game_song_effect& song_effect = this->song_effect[i]; pvpp_effect& effect = play_param->effect[i]; for (string_hash& j : effect.auth_3d) { - auth_3d_id id = auth_3d_id(j.hash_murmurhash, x_data, obj_db, tex_db); - if (!id.check_not_empty()) + auth_3d_detail::Handle id = auth_3d_detail::Handle::create(j.hash_murmurhash, x_data, obj_db, tex_db); + if (!id.is_valid()) continue; - id.read_file_modern(); - id.set_enable(false); - id.set_repeat(false); - id.set_paused(false); - id.set_visibility(false); - id.set_frame_rate(frame_rate_control); + id.load_req_modern(); + id.set_enabled(false); + id.set_looped(false); + id.set_pause(false); + id.set_visible(false); + id.set_frame_rate_control(frame_rate_control); song_effect.auth_3d.push_back(id); } } @@ -1079,7 +1093,7 @@ void x_pv_game_effect::ctrl(object_database* obj_db, texture_database* tex_db) { for (x_pv_game_song_effect& i : song_effect) for (x_pv_game_song_effect_auth_3d& j : i.auth_3d) - if (j.id.check_not_empty() && !j.id.check_loaded()) + if (j.id.is_valid() && !j.id.load_is_done()) wait_load |= true; for (string_hash& i : pv_glitter) @@ -1135,7 +1149,7 @@ void x_pv_game_effect::ctrl(object_database* obj_db, texture_database* tex_db) { for (x_pv_game_song_effect& i : song_effect) if (i.enable) for (x_pv_game_song_effect_auth_3d& j : i.auth_3d) - j.id.set_chara_id(i.rob_id); + j.id.assign_rob_id(i.rob_id); } break; } } @@ -1175,7 +1189,7 @@ void x_pv_game_effect::load_data(int32_t pv_id, object_database* obj_db, texture objset_info_storage_load_set_hash(x_data, i.hash_murmurhash); for (string_hash& i : pv_auth_3d) - auth_3d_data_load_category(x_data, i.c_str(), i.hash_murmurhash); + auth_3d_detail::category_load_req(x_data, i.c_str(), i.hash_murmurhash); size_t effect_count = play_param->effect.size(); for (size_t i = 0; i < effect_count; i++) { @@ -1211,20 +1225,6 @@ void x_pv_game_effect::reset() { frame_rate_control = 0; } -void x_pv_game_effect::set_chara_id(int32_t index, ROB_ID rob_id, bool chara_item) { - if (index < 0 || index >= song_effect.size()) - return; - - x_pv_game_song_effect& song_effect = this->song_effect[index]; - - for (x_pv_game_song_effect_auth_3d& i : song_effect.auth_3d) { - i.id.set_chara_id(rob_id); - i.id.set_chara_item(chara_item); - } - - song_effect.rob_id = rob_id; -} - void x_pv_game_effect::set_song_effect(int32_t index, int64_t time) { if (state && state != 20) return; @@ -1248,10 +1248,10 @@ void x_pv_game_effect::set_song_effect(int32_t index, int64_t time) { song_effect.rob_id = rob_id; for (x_pv_game_song_effect_auth_3d& i : song_effect.auth_3d) { - i.id.set_enable(true); - i.id.set_repeat(false); - i.id.set_req_frame(0.0f); - i.id.set_visibility(true); + i.id.set_enabled(true); + i.id.set_looped(false); + i.id.set_frame_req(0.0f); + i.id.set_visible(true); } #if !BAKE_VIDEO_ALPHA @@ -1270,7 +1270,7 @@ void x_pv_game_effect::set_song_effect(int32_t index, int64_t time) { set_song_effect_time_inner(index, time, false); for (x_pv_game_song_effect_auth_3d& i : song_effect.auth_3d) - i.id.set_chara_id(rob_id); + i.id.assign_rob_id(rob_id); } void x_pv_game_effect::set_song_effect_time(int32_t index, int64_t time, bool glitter) { @@ -1284,8 +1284,8 @@ void x_pv_game_effect::set_song_effect_time_inner(int32_t index, int64_t time, b x_pv_game_song_effect& song_effect = this->song_effect[index]; - float_t req_frame = (float_t)((double_t)std::abs(time - song_effect.time) * 0.000000001) * 60.0f; - float_t max_frame = -1.0f; + float_t frame_req = (float_t)((double_t)std::abs(time - song_effect.time) * 0.000000001) * 60.0f; + float_t frame_max = -1.0f; if (change_fields) { int64_t* key = change_fields->data(); @@ -1304,14 +1304,14 @@ void x_pv_game_effect::set_song_effect_time_inner(int32_t index, int64_t time, b next_change_field_time = *key; if (next_change_field_time >= 0) - max_frame = (float_t)((double_t)std::abs(next_change_field_time + frame_max = (float_t)((double_t)std::abs(next_change_field_time - song_effect.time) * 0.000000001) * 60.0f - 1.0f; } for (x_pv_game_song_effect_auth_3d& i : song_effect.auth_3d) { - i.id.set_req_frame(req_frame); - i.id.set_paused(false); - i.id.set_max_frame(max_frame); + i.id.set_frame_req(frame_req); + i.id.set_pause(false); + i.id.set_frame_max(frame_max); } if (glitter) @@ -1320,7 +1320,7 @@ void x_pv_game_effect::set_song_effect_time_inner(int32_t index, int64_t time, b continue; float_t frame = Glitter::glt_particle_manager->GetSceneFrameLifeTime(i.scene_counter, 0); - Glitter::glt_particle_manager->SetSceneEffectReqFrame(i.scene_counter, req_frame - frame); + Glitter::glt_particle_manager->SetSceneEffectFrameReq(i.scene_counter, frame_req - frame); } } @@ -1347,10 +1347,10 @@ void x_pv_game_effect::stop_song_effect(int32_t index, bool free_glitter) { x_pv_game_song_effect& song_effect = this->song_effect[index]; for (x_pv_game_song_effect_auth_3d& i : song_effect.auth_3d) { - auth_3d_id& id = i.id; - id.set_enable(false); - id.set_req_frame(0.0f); - id.set_visibility(false); + auth_3d_detail::Handle& id = i.id; + id.set_enabled(false); + id.set_frame_req(0.0f); + id.set_visible(false); } for (x_pv_game_song_effect_glitter& i : song_effect.glitter) @@ -1379,13 +1379,11 @@ void x_pv_game_effect::unload_data() { Glitter::glt_particle_manager->FreeScene(i.hash_murmurhash); for (x_pv_game_song_effect& i : song_effect) - for (x_pv_game_song_effect_auth_3d& j : i.auth_3d) { - j.id.unload(rctx_ptr); - j.id = {}; - } + for (x_pv_game_song_effect_auth_3d& j : i.auth_3d) + j.id.destroy(rctx_ptr); for (string_hash& i : pv_auth_3d) - auth_3d_data_unload_category(i.hash_murmurhash); + auth_3d_detail::category_free(i.hash_murmurhash); for (string_hash& i : pv_obj_set) objset_info_storage_unload_set(i.hash_murmurhash); @@ -1399,7 +1397,7 @@ void x_pv_game_effect::unload_data() { } x_pv_game_chara_effect_auth_3d::x_pv_game_chara_effect_auth_3d() - : field_0(), src_chara(), dst_chara(), objhrc_index(), node_mat() { + : field_0(), cn_src(), cn_dst(), objhrc_index(), node_mat() { id = {}; time = -1; reset(); @@ -1411,8 +1409,8 @@ x_pv_game_chara_effect_auth_3d::~x_pv_game_chara_effect_auth_3d() { void x_pv_game_chara_effect_auth_3d::reset() { field_0 = false; - src_chara = CN_MAX; - dst_chara = CN_MAX; + cn_src = CN_MAX; + cn_dst = CN_MAX; file.clear(); category.clear(); object_set.clear(); @@ -1441,7 +1439,7 @@ void x_pv_game_chara_effect::ctrl(int32_t pv_id, object_database* obj_db, textur if (!j.category.str.size()) continue; - if (!auth_3d_data_check_category_loaded(j.category.hash_murmurhash)) + if (!auth_3d_detail::category_load_is_done(j.category.hash_murmurhash)) wait_load |= true; if (objset_info_storage_get_objset_info(j.object_set.hash_murmurhash) @@ -1459,27 +1457,28 @@ void x_pv_game_chara_effect::ctrl(int32_t pv_id, object_database* obj_db, textur if (!j.category.str.size()) continue; - auth_3d_id id = auth_3d_id(j.file.hash_murmurhash, x_data, obj_db, tex_db); - if (!id.check_not_empty()) { + auth_3d_detail::Handle id = auth_3d_detail::Handle::create( + j.file.hash_murmurhash, x_data, obj_db, tex_db); + if (!id.is_valid()) { j.id = {}; continue; } - id.read_file_modern(); - id.set_enable(false); - id.set_repeat(false); - id.set_paused(true); - id.set_visibility(false); - id.set_frame_rate(frame_rate_control); + id.load_req_modern(); + id.set_enabled(false); + id.set_looped(false); + id.set_pause(true); + id.set_visible(false); + id.set_frame_rate_control(frame_rate_control); if (j.field_0) - id.set_src_dst_chara(j.src_chara, j.dst_chara); + id.replace_chara(j.cn_src, j.cn_dst); j.id = id; #if BAKE_PV826 if (pv_id == 826) - effchrpv_auth_3d_to_mot_add_chara_effect_auth_3d(j.file.hash_murmurhash, id.id); + effchrpv_auth_3d_to_mot_add_chara_effect_auth_3d(j.file.hash_murmurhash, id); #endif } @@ -1493,7 +1492,7 @@ void x_pv_game_chara_effect::ctrl(int32_t pv_id, object_database* obj_db, textur if (!j.category.str.size()) continue; - if (j.id.check_not_empty() && !j.id.check_loaded()) + if (j.id.is_valid() && !j.id.load_is_done()) wait_load |= true; } @@ -1517,20 +1516,20 @@ vec3 x_pv_game_chara_effect::get_node_translation(ROB_ID rob_id, return 0.0f; x_pv_game_chara_effect_auth_3d& chr_eff = chr_eff_auth[chara_effect]; - if (chr_eff.id.is_null()) + if (chr_eff.id.is_valid()) return 0.0f; - ::auth_3d* auth = chr_eff.id.get_auth_3d(); - if (!auth || objhrc_index < 0 || objhrc_index >= auth->object_hrc.size()) + auth_3d_detail::Scene* in_scene = chr_eff.id.get_scene(); + if (!in_scene || objhrc_index < 0 || objhrc_index >= in_scene->object_hrc_holder.size()) return 0.0f; if (!chr_eff.node_mat || chr_eff.objhrc_index != objhrc_index || chr_eff.node_name.compare(node_name)) { mat4* mat = 0; const uint64_t node_name_hash = hash_utf8_xxh3_64bits(node_name); - for (auth_3d_object_node& i : auth->object_hrc[objhrc_index].node) + for (auth_3d_detail::TransformNode & i : in_scene->object_hrc_holder[objhrc_index].node_list) if (hash_string_xxh3_64bits(i.name) == node_name_hash) { - mat = i.mat; + mat = i.mat_ptr; break; } @@ -1563,23 +1562,23 @@ void x_pv_game_chara_effect::load(int32_t pv_id, pvpp* play_param, pvpp_chara_effect& chara_effect = chara.chara_effect; - CHARA_NUM src_chara = (CHARA_NUM)chara_effect.base_chara; - CHARA_NUM dst_chara = charas[i]; - CHARA_NUM dst_chara_mei = dst_chara == CN_SAKINE ? CN_MEIKO : dst_chara; + CHARA_NUM cn_src = (CHARA_NUM)chara_effect.base_chara; + CHARA_NUM cn_dst = charas[i]; + CHARA_NUM cn_dst_mei = cn_dst == CN_SAKINE ? CN_MEIKO : cn_dst; - /*if (dst_chara == CHARA_EXTRA) - dst_chara = src_chara;*/ + /*if (cn_dst == CHARA_EXTRA) + cn_dst = cn_src;*/ - const char* src_chara_str = get_char_id_str(src_chara); - const char* dst_chara_str = get_char_id_str(dst_chara); - const char* dst_chara_mei_str = get_char_id_str(dst_chara_mei); + const char* cn_src_str = get_char_id_str(cn_src); + const char* cn_dst_str = get_char_id_str(cn_dst); + const char* cn_dst_mei_str = get_char_id_str(cn_dst_mei); #if BAKE_X_PACK if (pv_x_bake && pv_id == 814) { repeat: - dst_chara_mei = dst_chara == CN_SAKINE ? CN_MEIKO : dst_chara; - dst_chara_str = get_char_id_str(dst_chara); - dst_chara_mei_str = get_char_id_str(dst_chara_mei); + cn_dst_mei = cn_dst == CN_SAKINE ? CN_MEIKO : cn_dst; + cn_dst_str = get_char_id_str(cn_dst); + cn_dst_mei_str = get_char_id_str(cn_dst_mei); } #endif @@ -1588,22 +1587,22 @@ void x_pv_game_chara_effect::load(int32_t pv_id, pvpp* play_param, if (pv_id == 826 && !j.auth_3d.str.find("EFFCHRPV826")) { switch (&j - chara_effect.auth_3d.data()) { case 0: - src_chara = CN_RIN; + cn_src = CN_RIN; break; case 1: - src_chara = CN_LEN; + cn_src = CN_LEN; break; case 2: - src_chara = CN_LUKA; + cn_src = CN_LUKA; break; case 3: - src_chara = CN_KAITO; + cn_src = CN_KAITO; break; case 4: - src_chara = CN_MEIKO; + cn_src = CN_MEIKO; break; } - src_chara_str = get_char_id_str(src_chara); + cn_src_str = get_char_id_str(cn_src); } #endif @@ -1614,27 +1613,27 @@ void x_pv_game_chara_effect::load(int32_t pv_id, pvpp* play_param, else object_set.assign(file); - if (src_chara != dst_chara) { - if (src_chara_str) { - size_t pos = object_set.find(src_chara_str); + if (cn_src != cn_dst) { + if (cn_src_str) { + size_t pos = object_set.find(cn_src_str); if (pos != -1) - object_set.replace(pos, 3, dst_chara_str); - else if (dst_chara_mei_str) { - size_t pos = object_set.find(dst_chara_mei_str); + object_set.replace(pos, 3, cn_dst_str); + else if (cn_dst_mei_str) { + size_t pos = object_set.find(cn_dst_mei_str); if (pos != -1) - object_set.replace(pos, 3, src_chara_str); + object_set.replace(pos, 3, cn_src_str); } } if (!j.u00) - if (src_chara_str) { - size_t pos = file.find(src_chara_str); + if (cn_src_str) { + size_t pos = file.find(cn_src_str); if (pos != -1) - file.replace(pos, 3, dst_chara_str); - else if (dst_chara_mei_str) { - size_t pos = file.find(dst_chara_mei_str); + file.replace(pos, 3, cn_dst_str); + else if (cn_dst_mei_str) { + size_t pos = file.find(cn_dst_mei_str); if (pos != -1) - file.replace(pos, 3, src_chara_str); + file.replace(pos, 3, cn_src_str); } } } @@ -1654,8 +1653,8 @@ void x_pv_game_chara_effect::load(int32_t pv_id, pvpp* play_param, this->auth_3d[i].push_back({}); x_pv_game_chara_effect_auth_3d& auth_3d = this->auth_3d[i].back(); auth_3d.field_0 = j.u00; - auth_3d.src_chara = src_chara; - auth_3d.dst_chara = dst_chara; + auth_3d.cn_src = cn_src; + auth_3d.cn_dst = cn_dst; auth_3d.file.assign(file); auth_3d.category.assign(category); auth_3d.object_set.assign(object_set); @@ -1667,8 +1666,8 @@ void x_pv_game_chara_effect::load(int32_t pv_id, pvpp* play_param, } #if BAKE_X_PACK if (pv_x_bake && pv_id == 814) { - dst_chara = (CHARA_NUM)((int32_t)(dst_chara + 1)); - if (dst_chara != CN_MAX) + cn_dst = (CHARA_NUM)((int32_t)(cn_dst + 1)); + if (cn_dst != CN_MAX) goto repeat; } #endif @@ -1687,7 +1686,7 @@ void x_pv_game_chara_effect::load_data() { if (!j.category.str.size()) continue; - auth_3d_data_load_category(x_data, j.category.c_str(), j.category.hash_murmurhash); + auth_3d_detail::category_load_req(x_data, j.category.c_str(), j.category.hash_murmurhash); objset_info_storage_load_set_hash(x_data, j.object_set.hash_murmurhash); } @@ -1714,23 +1713,23 @@ void x_pv_game_chara_effect::set_chara_effect(ROB_ID rob_id, int32_t index, int6 if (index < 0 || index >= auth_3d.size()) return; - auth_3d_id& id = auth_3d[index].id; + auth_3d_detail::Handle& id = auth_3d[index].id; - if (!id.check_not_empty()) + if (!id.is_valid()) return; - if (id.get_enable()) - id.set_req_frame((float_t)((double_t)std::abs(time - auth_3d[index].time) * 0.000000001) * 60.0f); + if (id.is_finished()) + id.set_frame_req((float_t)((double_t)std::abs(time - auth_3d[index].time) * 0.000000001) * 60.0f); else { - id.set_enable(true); - id.set_paused(false); - id.set_repeat(false); - id.set_req_frame(0.0f); - id.set_visibility(true); + id.set_enabled(true); + id.set_pause(false); + id.set_looped(false); + id.set_frame_req(0.0f); + id.set_visible(true); auth_3d[index].time = time; } - float_t max_frame = -1.0f; + float_t frame_max = -1.0f; if (change_fields) { int64_t* key = change_fields->data(); size_t length = change_fields->size(); @@ -1748,11 +1747,11 @@ void x_pv_game_chara_effect::set_chara_effect(ROB_ID rob_id, int32_t index, int6 next_change_field_time = *key; if (next_change_field_time >= 0) - max_frame = (float_t)((double_t)std::abs(next_change_field_time + frame_max = (float_t)((double_t)std::abs(next_change_field_time - auth_3d[index].time) * 0.000000001) * 60.0f - 1.0f; } - id.set_max_frame(max_frame); + id.set_frame_max(frame_max); } void x_pv_game_chara_effect::set_chara_effect_time(ROB_ID rob_id, int32_t index, int64_t time) { @@ -1760,11 +1759,11 @@ void x_pv_game_chara_effect::set_chara_effect_time(ROB_ID rob_id, int32_t index, return; for (x_pv_game_chara_effect_auth_3d& i : auth_3d[rob_id]) { - if (!i.id.check_not_empty() || !i.id.get_enable()) + if (!i.id.is_valid() || !i.id.is_finished()) continue; - i.id.set_req_frame((float_t)((double_t)std::abs(time - i.time) * 0.000000001) * 60.0f); - i.id.set_paused(false); + i.id.set_frame_req((float_t)((double_t)std::abs(time - i.time) * 0.000000001) * 60.0f); + i.id.set_pause(false); } } @@ -1774,11 +1773,11 @@ void x_pv_game_chara_effect::set_time(int64_t time) { for (auto& i : auth_3d) for (x_pv_game_chara_effect_auth_3d& j : i) { - if (!j.id.check_not_empty() || !j.id.get_enable()) + if (!j.id.is_valid() || !j.id.is_finished()) continue; - j.id.set_req_frame((float_t)((double_t)std::abs(time - j.time) * 0.000000001) * 60.0f); - j.id.set_paused(false); + j.id.set_frame_req((float_t)((double_t)std::abs(time - j.time) * 0.000000001) * 60.0f); + j.id.set_pause(false); } } @@ -1788,8 +1787,8 @@ void x_pv_game_chara_effect::stop() { for (std::vector& i : auth_3d) for (x_pv_game_chara_effect_auth_3d& j : i) - if (j.id.check_not_empty()) - j.id.set_enable(false); + if (j.id.is_valid()) + j.id.set_enabled(false); } void x_pv_game_chara_effect::stop_chara_effect(ROB_ID rob_id, int32_t index) { @@ -1797,8 +1796,8 @@ void x_pv_game_chara_effect::stop_chara_effect(ROB_ID rob_id, int32_t index) { return; for (x_pv_game_chara_effect_auth_3d& i : auth_3d[rob_id]) - if (i.id.check_not_empty()) - i.id.set_enable(false); + if (i.id.is_valid()) + i.id.set_enabled(false); } void x_pv_game_chara_effect::unload() { @@ -1827,8 +1826,8 @@ void x_pv_game_chara_effect::unload_data() { if (!j.category.str.size()) continue; - j.id.unload(rctx_ptr); - auth_3d_data_unload_category(j.category.hash_murmurhash); + j.id.destroy(rctx_ptr); + auth_3d_detail::category_free(j.category.hash_murmurhash); objset_info_storage_unload_set(j.object_set.hash_murmurhash); } @@ -3770,7 +3769,7 @@ bool x_pv_game_pv_data::dsc_ctrl(float_t delta_time, int64_t curr_time, ROB_ID rob_id = (ROB_ID)data[1]; int32_t chara_item = data[2]; - pv_game->get_data().effect.set_chara_id(index, rob_id, !!chara_item); + pv_game->get_data().effect.assign_rob_id(index, rob_id, !!chara_item); } break; case DSC_X_LIGHT_AUTH: { @@ -5357,7 +5356,7 @@ void x_pv_game_stage::ctrl(float_t delta_time) { } for (string_hash& i : stage_auth_3d) - auth_3d_data_load_category(x_data, i.c_str(), i.hash_murmurhash); + auth_3d_detail::category_load_req(x_data, i.c_str(), i.hash_murmurhash); env.load(stage_id, stage_resource); state = 11; @@ -5369,7 +5368,7 @@ void x_pv_game_stage::ctrl(float_t delta_time) { bool wait_load = false; for (string_hash& i : stage_auth_3d) - if (!auth_3d_data_check_category_loaded(i.hash_murmurhash)) + if (!auth_3d_detail::category_load_is_done(i.hash_murmurhash)) wait_load |= true; for (uint32_t& i : stage_glitter) @@ -5408,19 +5407,19 @@ void x_pv_game_stage::ctrl(float_t delta_time) { auto elem = auth_3d_ids.find(stg_eff_auth_3d.name.hash_murmurhash); if (elem == auth_3d_ids.end()) { - auth_3d_id id = auth_3d_id(stg_eff_auth_3d - .name.hash_murmurhash, x_data, &obj_db, &tex_db); - if (!id.check_not_empty()) { + auth_3d_detail::Handle id = auth_3d_detail::Handle::create( + stg_eff_auth_3d.name.hash_murmurhash, x_data, &obj_db, &tex_db); + if (!id.is_valid()) { eff_auth_3d.id = {}; continue; } - id.read_file_modern(); - id.set_enable(false); - id.set_repeat(true); - id.set_paused(false); - id.set_visibility(false); - id.set_frame_rate(&bpm_frame_rate_control); + id.load_req_modern(); + id.set_enabled(false); + id.set_looped(true); + id.set_pause(false); + id.set_visible(false); + id.set_frame_rate_control(&bpm_frame_rate_control); eff_auth_3d.id = id; auth_3d_ids.insert({ stg_eff_auth_3d.name.hash_murmurhash, id }); @@ -5465,7 +5464,7 @@ void x_pv_game_stage::ctrl(float_t delta_time) { for (int32_t i = 0; i < X_PV_GAME_STAGE_EFFECT_COUNT; i++) { x_pv_game_stage_effect& eff = effect[i]; for (x_pv_game_stage_effect_auth_3d& j : eff.auth_3d) - if (j.id.check_not_empty() && !j.id.check_loaded()) + if (j.id.is_valid() && !j.id.load_is_done()) wait_load |= true; } @@ -5473,7 +5472,7 @@ void x_pv_game_stage::ctrl(float_t delta_time) { for (int32_t j = 0; j < X_PV_GAME_STAGE_EFFECT_COUNT; j++) { x_pv_game_stage_change_effect& chg_eff = change_effect[i][j]; for (x_pv_game_stage_effect_auth_3d& k : chg_eff.auth_3d) - if (k.id.check_not_empty() && !k.id.check_loaded()) + if (k.id.is_valid() && !k.id.load_is_done()) wait_load |= true; } @@ -5547,9 +5546,9 @@ void x_pv_game_stage::ctrl_inner() { else if (bar_beat->counter > 0) { std::vector& auth_3d = eff.auth_3d; for (x_pv_game_stage_effect_auth_3d& i : auth_3d) { - auth_3d_id& id = i.id; + auth_3d_detail::Handle& id = i.id; if (i.field_1) - id.set_repeat(false); + id.set_looped(false); } } } break; @@ -5608,19 +5607,19 @@ void x_pv_game_stage::ctrl_inner() { std::vector& auth_3d = eff.auth_3d; std::vector& glitter = eff.glitter; - bool stop = false; + bool is_finished = false; if (auth_3d.size()) - stop = auth_3d[eff.main_auth_3d_index].id.get_ended(); + is_finished = auth_3d[eff.main_auth_3d_index].id.is_finished(); - if (!stop) { + if (!is_finished) { for (x_pv_game_stage_effect_glitter& j : glitter) if (Glitter::glt_particle_manager->CheckSceneEnded(j.scene_counter)) { - stop = true; + is_finished = true; break; } } - if (stop) { + if (is_finished) { stop_stage_effect_auth_3d(i); stop_stage_effect_glitter(i); flags &= ~(1 << i); @@ -5687,19 +5686,19 @@ void x_pv_game_stage::load_change_effect(int32_t curr_stage_effect, int32_t next auto elem = auth_3d_ids.find(stg_chg_eff_auth_3d.name.hash_murmurhash); if (elem == auth_3d_ids.end()) { - auth_3d_id id = auth_3d_id(stg_chg_eff_auth_3d - .name.hash_murmurhash, x_data, &obj_db, &tex_db); - if (!id.check_not_empty()) { + auth_3d_detail::Handle id = auth_3d_detail::Handle::create( + stg_chg_eff_auth_3d.name.hash_murmurhash, x_data, &obj_db, &tex_db); + if (!id.is_valid()) { chg_eff_auth_3d.id = {}; continue; } - id.read_file_modern(); - id.set_enable(false); - id.set_repeat(false); - id.set_paused(false); - id.set_visibility(false); - id.set_frame_rate(&bpm_frame_rate_control); + id.load_req_modern(); + id.set_enabled(false); + id.set_looped(false); + id.set_pause(false); + id.set_visible(false); + id.set_frame_rate_control(&bpm_frame_rate_control); chg_eff_auth_3d.id = id; auth_3d_ids.insert({ stg_chg_eff_auth_3d.name.hash_murmurhash, id }); @@ -5814,19 +5813,19 @@ void x_pv_game_stage::set_change_effect_frame_part_2(float_t frame) { return; for (x_pv_game_stage_effect_auth_3d& i : chg_eff.auth_3d) { - auth_3d_id& id = i.id; - id.set_camera_root_update(false); + auth_3d_detail::Handle& id = i.id; + id.camera_set_enabled(false); #if BAKE_VIDEO_ALPHA - id.set_enable(false); + id.set_enabled(false); #else - id.set_enable(true); + id.set_enabled(true); #endif - id.set_repeat(i.repeat); - id.set_req_frame(frame); - id.set_max_frame(id.get_last_frame() - 1.0f); - id.set_paused(false); - id.set_visibility(!!(flags & 0x01)); - id.set_frame_rate(&bpm_frame_rate_control); + id.set_looped(i.repeat); + id.set_frame_req(frame); + id.set_frame_max(id.get_frame_size() - 1.0f); + id.set_pause(false); + id.set_visible(!!(flags & 0x01)); + id.set_frame_rate_control(&bpm_frame_rate_control); } #if !BAKE_VIDEO_ALPHA @@ -5840,7 +5839,7 @@ void x_pv_game_stage::set_change_effect_frame_part_2(float_t frame) { continue; Glitter::glt_particle_manager->SetSceneFrameRate(i.scene_counter, &bpm_frame_rate_control); - Glitter::glt_particle_manager->SetSceneEffectReqFrame(i.scene_counter, frame); + Glitter::glt_particle_manager->SetSceneEffectFrameReq(i.scene_counter, frame); } #endif } @@ -5878,9 +5877,9 @@ void x_pv_game_stage::set_stage_effect(int32_t stage_effect) { && curr_stage_effect >= 1 && curr_stage_effect <= 12) { std::vector& auth_3d = effect[curr_stage_effect - 1ULL].auth_3d; for (x_pv_game_stage_effect_auth_3d& i : auth_3d) { - auth_3d_id& id = i.id; + auth_3d_detail::Handle& id = i.id; if (i.field_1) - id.set_repeat(false); + id.set_looped(false); } } return; @@ -5909,26 +5908,27 @@ void x_pv_game_stage::set_stage_effect_auth_3d_frame(int32_t stage_effect, float std::vector& auth_3d = effect[stage_effect - 1ULL].auth_3d; for (x_pv_game_stage_effect_auth_3d& i : auth_3d) { - auth_3d_id& id = i.id; - id.set_camera_root_update(false); + auth_3d_detail::Handle& id = i.id; + id.camera_set_enabled(false); #if BAKE_VIDEO_ALPHA - id.set_enable(false); + id.set_enabled(false); #else - id.set_enable(true); + id.set_enabled(true); #endif - id.set_repeat(true); - float_t last_frame = id.get_last_frame(); - if (i.repeat && last_frame <= frame) { - int32_t frame_offset = (int32_t)id.get_frame_offset(); - int32_t _frame = frame_offset + (int32_t)(frame - (float_t)frame_offset) % (int32_t)last_frame; + id.set_looped(true); + float_t frame_loop_end = id.get_frame_loop_end(); + if (i.repeat && frame_loop_end <= frame) { + int32_t frame_loop_begin = (int32_t)id.get_frame_loop_begin(); + int32_t _frame = frame_loop_begin + + (int32_t)(frame - (float_t)frame_loop_begin) % (int32_t)frame_loop_end; frame = (float_t)_frame + (frame - prj::floorf(frame)); } - id.set_req_frame(frame); - id.set_max_frame(-1.0f); - id.set_paused(false); - id.set_visibility(true); - id.set_frame_rate(&bpm_frame_rate_control); + id.set_frame_req(frame); + id.set_frame_max(-1.0f); + id.set_pause(false); + id.set_visible(true); + id.set_frame_rate_control(&bpm_frame_rate_control); } } @@ -5957,10 +5957,10 @@ void x_pv_game_stage::set_stage_effect_glitter_frame(int32_t stage_effect, float float_t _life_time = (float_t)life_time; while (frame >= _life_time) frame -= _life_time; - Glitter::glt_particle_manager->SetSceneEffectReqFrame(i.scene_counter, frame); + Glitter::glt_particle_manager->SetSceneEffectFrameReq(i.scene_counter, frame); } else if (frame < (float_t)life_time) - Glitter::glt_particle_manager->SetSceneEffectReqFrame(i.scene_counter, frame); + Glitter::glt_particle_manager->SetSceneEffectFrameReq(i.scene_counter, frame); else Glitter::glt_particle_manager->FreeSceneEffect(i.scene_counter, false); @@ -5987,9 +5987,9 @@ void x_pv_game_stage::stop_stage_change_effect() { x_pv_game_stage_change_effect& chg_eff = change_effect[curr_stg_eff][next_stg_eff]; for (x_pv_game_stage_effect_auth_3d& i : chg_eff.auth_3d) { - auth_3d_id& id = i.id; - id.set_visibility(false); - id.set_enable(false); + auth_3d_detail::Handle& id = i.id; + id.set_visible(false); + id.set_enabled(false); } for (x_pv_game_stage_effect_glitter& i : chg_eff.glitter) @@ -6032,9 +6032,9 @@ void x_pv_game_stage::stop_stage_effect_auth_3d(int32_t stage_effect) { std::vector& auth_3d = effect[stage_effect - 1ULL].auth_3d; for (x_pv_game_stage_effect_auth_3d& i : auth_3d) { - auth_3d_id& id = i.id; - id.set_visibility(false); - id.set_enable(false); + auth_3d_detail::Handle& id = i.id; + id.set_visible(false); + id.set_enabled(false); } } @@ -6054,8 +6054,8 @@ void x_pv_game_stage::unload() { if (!stage_resource || !stage_id) return; - for (std::pair i : auth_3d_ids) - i.second.unload(rctx_ptr); + for (std::pair i : auth_3d_ids) + i.second.destroy(rctx_ptr); auth_3d_ids.clear(); @@ -6095,7 +6095,7 @@ void x_pv_game_stage::unload() { stage_glitter.clear(); for (string_hash& i : stage_auth_3d) - auth_3d_data_unload_category(i.hash_murmurhash); + auth_3d_detail::category_free(i.hash_murmurhash); stage_auth_3d.clear(); @@ -6265,7 +6265,7 @@ static video_packet_handler* nvenc_alpha_video_packets; #endif #if BAKE_DOF -static void a3da_key_rev(a3da_key& k, std::vector& values_src) { +static void a3da_key_rev(a3d::Fcurve& k, std::vector& values_src) { std::vector values; int32_t type = interpolate_chs_reverse_sequence(values_src, values); @@ -6273,17 +6273,17 @@ static void a3da_key_rev(a3da_key& k, std::vector& values_src) { switch (type) { case 0: default: - k.type = A3DA_KEY_NONE; + k.type = a3d::FC_TYPE_STATIC_0; return; case 1: k.value = values[0].value; - k.type = A3DA_KEY_STATIC; + k.type = a3d::FC_TYPE_STATIC_DATA; return; case 2: - k.type = A3DA_KEY_LINEAR; + k.type = a3d::FC_TYPE_LINEAR; break; case 3: - k.type = A3DA_KEY_HERMITE; + k.type = a3d::FC_TYPE_HERMITE; break; } @@ -6517,7 +6517,7 @@ bool x_pv_game::ctrl() { light_param_data_storage_data_set_pv_id(get_data().pv_id == 832 ? 800 : get_data().pv_id); - auth_3d_data_load_category(light_category.c_str()); + auth_3d_detail::category_load_req(light_category.c_str()); #if BAKE_X_PACK if (!pv_x_bake) { @@ -6605,7 +6605,7 @@ bool x_pv_game::ctrl() { case 7: { bool wait_load = false; - if (!auth_3d_data_check_category_loaded(light_category.c_str())) + if (!auth_3d_detail::category_load_is_done(light_category.c_str())) wait_load |= true; if (wait_load) @@ -6624,11 +6624,11 @@ bool x_pv_game::ctrl() { uint32_t light_auth_3d_hash = hash_utf8_murmurhash(buf); int32_t uid = aft_auth_3d_db->get_uid(buf); if (uid != -1) { - light_auth_3d_id = auth_3d_id(uid, aft_auth_3d_db); - if (light_auth_3d_id.check_not_empty()) { - light_auth_3d_id.read_file(aft_auth_3d_db); - light_auth_3d_id.set_enable(false); - light_auth_3d_id.set_visibility(false); + light_auth_3d_id = auth_3d_detail::Handle::create(uid, aft_auth_3d_db); + if (light_auth_3d_id.is_valid()) { + light_auth_3d_id.load_req(aft_auth_3d_db); + light_auth_3d_id.set_enabled(false); + light_auth_3d_id.set_visible(false); } else light_auth_3d_id = {}; @@ -6640,21 +6640,21 @@ bool x_pv_game::ctrl() { case 8: { bool wait_load = false; - if (light_auth_3d_id.check_not_empty() && !light_auth_3d_id.check_loaded()) + if (light_auth_3d_id.is_valid() && !light_auth_3d_id.load_is_done()) wait_load |= true; if (wait_load) break; - if (light_auth_3d_id.not_null()) { - auth_3d* light_auth_3d = light_auth_3d_id.get_auth_3d(); + if (light_auth_3d_id.is_valid()) { + auth_3d_detail::Scene* light_auth_3d = light_auth_3d_id.get_scene(); char path_buf[0x200]; sprintf_s(path_buf, sizeof(path_buf), "patch\\AFT\\auth_3d\\STGPV%03d_LT_POS.txt", 800 + stage_data.stage_id); - auth_3d_light* light = 0; - for (auth_3d_light& i : light_auth_3d->light) + auth_3d_detail::Light* light = 0; + for (auth_3d_detail::Light& i : light_auth_3d->light_list) if (i.id == LIGHT_CHARA) { light = &i; break; @@ -6662,9 +6662,9 @@ bool x_pv_game::ctrl() { if (light && path_check_file_exists(path_buf)) { prj::vector_pair values; - light->interpolate(0.0f); - values.push_back(0, light->position.translation_value); - light->interpolate(light_auth_3d->frame); + light->get(0.0f); + values.push_back(0, light->position.translation); + light->get(light_auth_3d->M_frame); file_stream lt_pos_fs; lt_pos_fs.open(path_buf, "rb"); @@ -6717,37 +6717,37 @@ bool x_pv_game::ctrl() { free_def(data); if (values.size() > 1) { - auto auth_3d_key_load = [](auth_3d_key* k, + auto auth_3d_fcurve_load = [](auth_3d_detail::Fcurve& fcv, const prj::vector_pair& values, const int32_t comp) { - k->type = AUTH_3D_KEY_HOLD; - k->value = 0.0f; + fcv.m_type = auth_3d_detail::FC_TYPE_NO_INTERPOLATION; + fcv.m_static_value = 0.0f; - k->ep_type_pre = AUTH_3D_EP_NONE; - k->ep_type_post = AUTH_3D_EP_NONE; + fcv.m_ep_type_pre = auth_3d_detail::EP_TYPE_CONSTANT; + fcv.m_ep_type_post = auth_3d_detail::EP_TYPE_CONSTANT; - size_t length = values.size(); - k->keys_vec.resize(length); - k->length = length; - k->keys = k->keys_vec.data(); + size_t key_data_size = values.size(); + fcv.m_key_data_list.resize(key_data_size); + fcv.m_key_data_size = key_data_size; + fcv.m_key_data_ptr = fcv.m_key_data_list.data(); - kft3* key = k->keys_vec.data(); - for (size_t i = length, j = 0; i; i--, j++) - *key++ = { + auth_3d_detail::Fcurve::KeyData* key_data = fcv.m_key_data_list.data(); + for (size_t i = key_data_size, j = 0; i; i--, j++) + *key_data++ = { (float_t)values.data()[j].first, ((float_t*)&values.data()[j].second)[comp] }; - kft3* first_key = &k->keys[0]; - kft3* last_key = &k->keys[length - 1]; - k->frame_delta = last_key->frame - first_key->frame; - k->value_delta = last_key->value - first_key->value; + const auth_3d_detail::Fcurve::KeyData* first_key = &fcv.m_key_data_ptr[0]; + const auth_3d_detail::Fcurve::KeyData* last_key = &fcv.m_key_data_ptr[key_data_size - 1]; + fcv.m_frame_delta = last_key->frame - first_key->frame; + fcv.m_value_delta = last_key->value - first_key->value; - k->interpolate(0.0f); + fcv.get(0.0f); }; - auth_3d_key_load(&light->position.translation.x, values, 0); - auth_3d_key_load(&light->position.translation.y, values, 1); - auth_3d_key_load(&light->position.translation.z, values, 2); + auth_3d_fcurve_load(light->position.fcurve_translation.x, values, 0); + auth_3d_fcurve_load(light->position.fcurve_translation.y, values, 1); + auth_3d_fcurve_load(light->position.fcurve_translation.z, values, 2); } } } @@ -7185,18 +7185,18 @@ bool x_pv_game::ctrl() { time_t t; srand((uint32_t)::time(&t)); - std::vector chara_effect_auth_3ds; - std::vector song_effect_auth_3ds; - std::vector stage_data_effect_auth_3ds; - std::vector stage_data_change_effect_auth_3ds; + std::vector chara_effect_auth_3ds; + std::vector song_effect_auth_3ds; + std::vector stage_data_effect_auth_3ds; + std::vector stage_data_change_effect_auth_3ds; - auto add_auth_3d = [](std::vector& auth_3ds, auth_3d_id id) { - if (!id.check_not_empty() || !id.check_loaded()) + auto add_auth_3d = [](std::vector& auth_3ds, auth_3d_detail::Handle id) { + if (!id.is_valid() || !id.load_is_done()) return; - auth_3d* auth = id.get_auth_3d(); - if (auth && (auth->object.size() || auth->object_hrc.size())) - auth_3ds.push_back(auth); + auth_3d_detail::Scene* in_scene = id.get_scene(); + if (in_scene && (in_scene->object_holder.size() || in_scene->object_hrc_holder.size())) + auth_3ds.push_back(in_scene); }; for (auto& i : pv_data.chara_effect.auth_3d) @@ -7220,23 +7220,13 @@ bool x_pv_game::ctrl() { add_auth_3d(stage_data_change_effect_auth_3ds, k.id); } - prj::sort_unique(chara_effect_auth_3ds); - prj::sort_unique(song_effect_auth_3ds); - prj::sort_unique(stage_data_effect_auth_3ds); - prj::sort_unique(stage_data_change_effect_auth_3ds); + prj::sort_and_erase_non_unique(chara_effect_auth_3ds); + prj::sort_and_erase_non_unique(song_effect_auth_3ds); + prj::sort_and_erase_non_unique(stage_data_effect_auth_3ds); + prj::sort_and_erase_non_unique(stage_data_change_effect_auth_3ds); - for (auth_3d*& i : stage_data_effect_auth_3ds) { - auto j_begin = stage_data_change_effect_auth_3ds.begin(); - auto j_end = stage_data_change_effect_auth_3ds.end(); - for (auto j = j_begin; j != j_end;) { - if (*j != i) - j++; - else { - j = stage_data_change_effect_auth_3ds.erase(j); - j_end = stage_data_change_effect_auth_3ds.end(); - } - } - } + for (auth_3d_detail::Scene* i : stage_data_effect_auth_3ds) + prj::find_and_erase(stage_data_change_effect_auth_3ds, i); std::vector pv_object_set_ids; std::vector stage_object_set_ids; @@ -7254,16 +7244,16 @@ bool x_pv_game::ctrl() { stage_object_set_ids.push_back(hash_utf8_murmurhash(name)); } - auto add_auth_3d_object_set_id = [](auth_3d* auth, std::vector& object_set_ids) { - object_set_ids.reserve(auth->object.size() + auth->object_hrc.size()); + auto add_auth_3d_object_set_id = [](auth_3d_detail::Scene* in_scene, std::vector& object_set_ids) { + object_set_ids.reserve(in_scene->object_holder.size() + in_scene->object_hrc_holder.size()); - for (auth_3d_object& i : auth->object) - if (i.object_info.not_null_modern()) - object_set_ids.push_back(i.object_info.set_id); + for (auth_3d_detail::Object& i : in_scene->object_holder) + if (i.obj_uid.not_null_modern()) + object_set_ids.push_back(i.obj_uid.set_id); - for (auth_3d_object_hrc& i : auth->object_hrc) - if (i.object_info.not_null_modern()) - object_set_ids.push_back(i.object_info.set_id); + for (auth_3d_detail::HierarchyObject& i : in_scene->object_hrc_holder) + if (i.obj_uid.not_null_modern()) + object_set_ids.push_back(i.obj_uid.set_id); }; auto add_glitter_object_set_id = [](uint32_t eff_group_hash, @@ -7281,17 +7271,17 @@ bool x_pv_game::ctrl() { } }; - for (auth_3d*& i : chara_effect_auth_3ds) - add_auth_3d_object_set_id(i, pv_object_set_ids); + for (auth_3d_detail::Scene* scene : chara_effect_auth_3ds) + add_auth_3d_object_set_id(scene, pv_object_set_ids); - for (auth_3d*& i : song_effect_auth_3ds) - add_auth_3d_object_set_id(i, pv_object_set_ids); + for (auth_3d_detail::Scene* scene : song_effect_auth_3ds) + add_auth_3d_object_set_id(scene, pv_object_set_ids); - for (auth_3d*& i : stage_data_effect_auth_3ds) - add_auth_3d_object_set_id(i, stage_object_set_ids); + for (auth_3d_detail::Scene* scene : stage_data_effect_auth_3ds) + add_auth_3d_object_set_id(scene, stage_object_set_ids); - for (auth_3d*& i : stage_data_change_effect_auth_3ds) - add_auth_3d_object_set_id(i, stage_object_set_ids); + for (auth_3d_detail::Scene* scene : stage_data_change_effect_auth_3ds) + add_auth_3d_object_set_id(scene, stage_object_set_ids); for (string_hash& i : pv_data.effect.pv_glitter) add_glitter_object_set_id(i.hash_murmurhash, pv_glitter_eff_groups, pv_object_set_ids); @@ -7303,14 +7293,14 @@ bool x_pv_game::ctrl() { for (uint32_t& i : stage_data.stage_glitter) add_glitter_object_set_id(i, stage_glitter_eff_groups, stage_object_set_ids); - prj::sort_unique(pv_object_set_ids); - prj::sort_unique(stage_object_set_ids); + prj::sort_and_erase_non_unique(pv_object_set_ids); + prj::sort_and_erase_non_unique(stage_object_set_ids); std::vector object_set_ids; object_set_ids.insert(object_set_ids.end(), pv_object_set_ids.begin(), pv_object_set_ids.end()); object_set_ids.insert(object_set_ids.end(), stage_object_set_ids.begin(), stage_object_set_ids.end()); - prj::sort_unique(object_set_ids); + prj::sort_and_erase_non_unique(object_set_ids); for (const uint32_t& i : object_set_ids) { ObjsetInfo* info = objset_info_storage_get_objset_info(i); @@ -7425,7 +7415,7 @@ bool x_pv_game::ctrl() { auth_3d_database_file& auth_3d_db = baker->aft.auth_3d_db; std::vector& avail_uids = baker->aft.avail_auth_3d_uids; - x_pv_game_write_auth_3d_camera(get_data().camera.id.get_auth_3d(), + x_pv_game_write_auth_3d_camera(get_data().camera.id.get_scene(), pv_data.pv_id, &auth_3d_db, avail_uids, x_pack_aft_out_dir); if (song_effect_auth_3ds.size()) { @@ -7439,15 +7429,15 @@ bool x_pv_game::ctrl() { effpv_farc->entry_padding = 0x01 + (rand() % 0x10); effpv_farc->header_padding = 0x01 + (rand() % 0x20); - for (auth_3d*& i : song_effect_auth_3ds) - x_pv_game_write_auth_3d(effpv_farc, i, &auth_3d_db, name, avail_uids, x_pack_aft_out_dir); + for (auth_3d_detail::Scene* scene : song_effect_auth_3ds) + x_pv_game_write_auth_3d(effpv_farc, scene, &auth_3d_db, name, avail_uids, x_pack_aft_out_dir); farc_compress_ptr->AddFarc(effpv_farc, sprintf_s_string("%s\\auth_3d\\%s", x_pack_aft_out_dir, name)); } - for (auth_3d*& i : chara_effect_auth_3ds) - x_pv_game_write_auth_3d(0, i, &auth_3d_db, 0, avail_uids, x_pack_aft_out_dir); + for (auth_3d_detail::Scene* scene : chara_effect_auth_3ds) + x_pv_game_write_auth_3d(0, scene, &auth_3d_db, 0, avail_uids, x_pack_aft_out_dir); char name[0x40]; sprintf_s(name, sizeof(name), "EFFSTGPV%03d", stage_data.stage_id); @@ -7461,22 +7451,22 @@ bool x_pv_game::ctrl() { for (stage_data_modern& i : stage_data.stage_data.stg_db.stage_modern) for (uint32_t& j : i.auth_3d_ids) { - auth_3d* auth = auth_3d_data_get_auth_3d(j); - if (auth) - x_pv_game_write_auth_3d(effstgpv_farc, auth, + auth_3d_detail::Scene* scene = auth_3d_detail::get_scene(j); + if (scene) + x_pv_game_write_auth_3d(effstgpv_farc, scene, &auth_3d_db, name, avail_uids, x_pack_aft_out_dir); } - for (auth_3d*& i : stage_data_effect_auth_3ds) - x_pv_game_write_auth_3d(effstgpv_farc, i, + for (auth_3d_detail::Scene* scene : stage_data_effect_auth_3ds) + x_pv_game_write_auth_3d(effstgpv_farc, scene, &auth_3d_db, name, avail_uids, x_pack_aft_out_dir); - for (auth_3d*& i : stage_data_change_effect_auth_3ds) - x_pv_game_write_auth_3d(effstgpv_farc, i, + for (auth_3d_detail::Scene* scene : stage_data_change_effect_auth_3ds) + x_pv_game_write_auth_3d(effstgpv_farc, scene, &auth_3d_db, name, avail_uids, x_pack_aft_out_dir); - if (light_auth_3d_id.check_not_empty()) - x_pv_game_write_auth_3d(effstgpv_farc, light_auth_3d_id.get_auth_3d(), + if (light_auth_3d_id.is_valid()) + x_pv_game_write_auth_3d(effstgpv_farc, light_auth_3d_id.get_scene(), &auth_3d_db, name, avail_uids, x_pack_aft_out_dir); if (effstgpv_farc->files.size()) @@ -7490,7 +7480,7 @@ bool x_pv_game::ctrl() { auth_3d_database_file& auth_3d_db = baker->mmp.auth_3d_db; std::vector& avail_uids = baker->mmp.avail_auth_3d_uids; - x_pv_game_write_auth_3d_camera(get_data().camera.id.get_auth_3d(), + x_pv_game_write_auth_3d_camera(get_data().camera.id.get_scene(), pv_data.pv_id, &auth_3d_db, avail_uids, x_pack_mmp_out_dir); if (song_effect_auth_3ds.size()) { @@ -7504,15 +7494,15 @@ bool x_pv_game::ctrl() { effpv_farc->entry_size = 0x11 + (rand() % 0x10); effpv_farc->header_size = 0x11 + (rand() % 0x20); - for (auth_3d*& i : song_effect_auth_3ds) - x_pv_game_write_auth_3d(effpv_farc, i, &auth_3d_db, name, avail_uids, x_pack_mmp_out_dir); + for (auth_3d_detail::Scene* scene : song_effect_auth_3ds) + x_pv_game_write_auth_3d(effpv_farc, scene, &auth_3d_db, name, avail_uids, x_pack_mmp_out_dir); farc_compress_ptr->AddFarc(effpv_farc, sprintf_s_string("%s\\auth_3d\\%s", x_pack_mmp_out_dir, name)); } - for (auth_3d*& i : chara_effect_auth_3ds) - x_pv_game_write_auth_3d(0, i, &auth_3d_db, 0, avail_uids, x_pack_mmp_out_dir); + for (auth_3d_detail::Scene* scene : chara_effect_auth_3ds) + x_pv_game_write_auth_3d(0, scene, &auth_3d_db, 0, avail_uids, x_pack_mmp_out_dir); char name[0x40]; sprintf_s(name, sizeof(name), "EFFSTGPV%03d", stage_data.stage_id); @@ -7526,22 +7516,22 @@ bool x_pv_game::ctrl() { for (stage_data_modern& i : stage_data.stage_data.stg_db.stage_modern) for (uint32_t& j : i.auth_3d_ids) { - auth_3d* auth = auth_3d_data_get_auth_3d(j); - if (auth) - x_pv_game_write_auth_3d(effstgpv_farc, auth, + auth_3d_detail::Scene* scene = auth_3d_detail::get_scene(j); + if (scene) + x_pv_game_write_auth_3d(effstgpv_farc, scene, &auth_3d_db, name, avail_uids, x_pack_mmp_out_dir); } - for (auth_3d*& i : stage_data_effect_auth_3ds) - x_pv_game_write_auth_3d(effstgpv_farc, i, + for (auth_3d_detail::Scene* scene : stage_data_effect_auth_3ds) + x_pv_game_write_auth_3d(effstgpv_farc, scene, &auth_3d_db, name, avail_uids, x_pack_mmp_out_dir); - for (auth_3d*& i : stage_data_change_effect_auth_3ds) - x_pv_game_write_auth_3d(effstgpv_farc, i, + for (auth_3d_detail::Scene* scene : stage_data_change_effect_auth_3ds) + x_pv_game_write_auth_3d(effstgpv_farc, scene, &auth_3d_db, name, avail_uids, x_pack_mmp_out_dir); - if (light_auth_3d_id.check_not_empty()) - x_pv_game_write_auth_3d(effstgpv_farc, light_auth_3d_id.get_auth_3d(), + if (light_auth_3d_id.is_valid()) + x_pv_game_write_auth_3d(effstgpv_farc, light_auth_3d_id.get_scene(), &auth_3d_db, name, avail_uids, x_pack_mmp_out_dir); if (effstgpv_farc->files.size()) @@ -7644,12 +7634,12 @@ bool x_pv_game::ctrl() { pv_data.ctrl(false, (float_t)(frame_float * (1.0 / 60.0)), 0.0f); - light_auth_3d_id.set_enable(true); - light_auth_3d_id.set_camera_root_update(false); - light_auth_3d_id.set_paused(false); - light_auth_3d_id.set_repeat(false); - light_auth_3d_id.set_visibility(true); - light_auth_3d_id.set_req_frame((float_t)frame_float); + light_auth_3d_id.set_enabled(true); + light_auth_3d_id.camera_set_enabled(false); + light_auth_3d_id.set_pause(false); + light_auth_3d_id.set_looped(false); + light_auth_3d_id.set_visible(true); + light_auth_3d_id.set_frame_req((float_t)frame_float); #if BAKE_PV826 if (get_data().pv_id == 826) @@ -7808,10 +7798,10 @@ bool x_pv_game::ctrl() { else sprintf_s(buf, sizeof(buf), "CAMPV%03d_BASE", pv_data.pv_id); - a3da a; + a3d::Scene scene; farc_file* ff = f->read_file(hash_utf8_murmurhash(buf)); if (ff) - a.read(ff->data, ff->size); + scene.read(ff->data, ff->size); delete f; if ((pv_data.pv_id % 100) >= 25 && (pv_data.pv_id % 100) <= 30 @@ -7821,28 +7811,28 @@ bool x_pv_game::ctrl() { sprintf_s(buf, sizeof(buf), "DOF\\auth_3d\\CAMPV%03d_BASE", pv_data.pv_id); replace_pv832(buf); - replace_pv832(a._file_name); + replace_pv832(scene._file_name); - a.ready = true; - a.compressed = true; - a.format = A3DA_FORMAT_AFT_X_PACK; - a.dof = {}; - a.dof.has_dof = true; + scene.ready = true; + scene.compressed = true; + scene.format = a3d::FORMAT_AFT_X_PACK; + scene.dof = {}; + scene.dof.has_dof = true; std::thread position_x(a3da_key_rev, - std::ref(a.dof.model_transform.translation.x), std::ref(dof_cam_data.position_x)); + std::ref(scene.dof.model_transform.translation.x), std::ref(dof_cam_data.position_x)); std::thread position_y(a3da_key_rev, - std::ref(a.dof.model_transform.translation.y), std::ref(dof_cam_data.position_y)); + std::ref(scene.dof.model_transform.translation.y), std::ref(dof_cam_data.position_y)); std::thread position_z(a3da_key_rev, - std::ref(a.dof.model_transform.translation.z), std::ref(dof_cam_data.position_z)); + std::ref(scene.dof.model_transform.translation.z), std::ref(dof_cam_data.position_z)); std::thread focus_range(a3da_key_rev, - std::ref(a.dof.model_transform.scale.x), std::ref(dof_cam_data.focus_range)); + std::ref(scene.dof.model_transform.scale.x), std::ref(dof_cam_data.focus_range)); //std::thread focus(a3da_key_rev, - // std::ref(a.dof.model_transform.scale.y), std::ref(dof_cam_data.focus)); + // std::ref(scene.dof.model_transform.scale.y), std::ref(dof_cam_data.focus)); std::thread fuzzing_range(a3da_key_rev, - std::ref(a.dof.model_transform.rotation.x), std::ref(dof_cam_data.fuzzing_range)); + std::ref(scene.dof.model_transform.rotation.x), std::ref(dof_cam_data.fuzzing_range)); std::thread ratio(a3da_key_rev, - std::ref(a.dof.model_transform.rotation.y), std::ref(dof_cam_data.ratio)); + std::ref(scene.dof.model_transform.rotation.y), std::ref(dof_cam_data.ratio)); SetThreadDescription((HANDLE)position_x.native_handle(), L"DoF A3DA Bake Thread: Position X"); SetThreadDescription((HANDLE)position_y.native_handle(), L"DoF A3DA Bake Thread: Position Y"); SetThreadDescription((HANDLE)position_z.native_handle(), L"DoF A3DA Bake Thread: Position Z"); @@ -7872,29 +7862,29 @@ bool x_pv_game::ctrl() { if (ratio.joinable()) ratio.join(); - a.dof.model_transform.translation.x.raw_data = true; - a.dof.model_transform.translation.y.raw_data = true; - a.dof.model_transform.translation.z.raw_data = true; + scene.dof.model_transform.translation.x.raw_data = true; + scene.dof.model_transform.translation.y.raw_data = true; + scene.dof.model_transform.translation.z.raw_data = true; - a3da_key& rot_z = a.dof.model_transform.rotation.z; + a3d::Fcurve& rot_z = scene.dof.model_transform.rotation.z; if (dof_cam_data.enable_frame.size() > 1) { - rot_z.type = A3DA_KEY_HOLD; + rot_z.type = a3d::FC_TYPE_NO_INTERPOLATION; rot_z.keys.reserve(dof_cam_data.enable_frame.size()); for (std::pair& i : dof_cam_data.enable_frame) rot_z.keys.push_back({ (float_t)i.first, i.second ? 1.00051f : 0.0f }); - rot_z.max_frame = a.play_control.size; + rot_z.max_frame = scene.play_control.size; } else if (dof_cam_data.enable_frame.size()) { - rot_z.type = A3DA_KEY_STATIC; + rot_z.type = a3d::FC_TYPE_STATIC_DATA; rot_z.value = dof_cam_data.enable_frame[0].second ? 1.00051f : 0.0f; } else - rot_z.type = A3DA_KEY_NONE; + rot_z.type = a3d::FC_TYPE_STATIC_0; - a.dof.model_transform.visibility.type = A3DA_KEY_STATIC; - a.dof.model_transform.visibility.value = 1.0f; + scene.dof.model_transform.visibility.type = a3d::FC_TYPE_STATIC_DATA; + scene.dof.model_transform.visibility.value = 1.0f; - a.write(buf); + scene.write(buf); dof_cam_data.reset(); } @@ -8269,11 +8259,9 @@ bool x_pv_game::unload() { i = ROB_ID_NULL; } - light_auth_3d_id.unload(rctx_ptr); + light_auth_3d_id.destroy(rctx_ptr); - light_auth_3d_id = {}; - - auth_3d_data_unload_category(light_category.c_str()); + auth_3d_detail::category_free(light_category.c_str()); light_category.clear(); light_category.shrink_to_fit(); @@ -10068,17 +10056,17 @@ static void x_pv_game_item_alpha_callback(void* data, ROB_ID rob_id, int32_t typ if (rob_id < 0 || rob_id >= pv_data.play_param->chara.size()) return; - mdl::ObjFlags flags; + mdl::ObjFlags state; switch (type) { case 0: default: - flags = mdl::OBJ_ALPHA_ORDER_POST_GLITTER; + state = mdl::OBJ_ALPHA_ORDER_POST_GLITTER; break; case 1: - flags = mdl::OBJ_ALPHA_ORDER_POST_TRANSLUCENT; + state = mdl::OBJ_ALPHA_ORDER_POST_TRANSLUCENT; break; case 2: - flags = mdl::OBJ_ALPHA_ORDER_POST_OPAQUE; + state = mdl::OBJ_ALPHA_ORDER_POST_OPAQUE; break; } @@ -10087,7 +10075,7 @@ static void x_pv_game_item_alpha_callback(void* data, ROB_ID rob_id, int32_t typ continue; for (x_pv_game_song_effect_auth_3d& j : i.auth_3d) - j.id.set_alpha_obj_flags(alpha, flags); + j.id.set_trnsl(alpha, state); for (x_pv_game_song_effect_glitter& j : i.glitter) Glitter::glt_particle_manager->SetSceneEffectExtColor(j.scene_counter, @@ -11544,27 +11532,54 @@ static void x_pv_game_write_aet(uint32_t aet_set_id, free_def(data); } -static bool x_pv_game_write_auth_3d(farc* f, auth_3d* auth, auth_3d_database_file* auth_3d_db, +static bool x_pv_game_write_auth_3d(farc* f, auth_3d_detail::Scene* in_scene, auth_3d_database_file* auth_3d_db, const char* category, std::vector& avail_uids, const char* out_dir) { char name[0x200]; - if (!get_replace_auth_name(name, sizeof(name), auth)) + if (!get_replace_auth_name(name, sizeof(name), in_scene)) return false; - a3da a; - float_t max_frame = auth->max_frame; - auth->max_frame = auth->play_control.size; - auth->store(&a); - auth->max_frame = max_frame; - a._converter_version.assign("20111019"); - a._file_name.assign(name); - a._file_name.append(".a3da"); - a._property_version.assign("20110526"); - a.ready = true; - a.compressed = true; - a.format = A3DA_FORMAT_AFT_X_PACK; + auth_3d_detail::SceneFile file; - for (a3da_m_object_hrc& i : a.m_object_hrc) { - for (a3da_object_instance& j : i.instance) { + float_t frame_max = in_scene->frame_max; + in_scene->frame_max = in_scene->play_control.size; + in_scene->M_storeToProperties(file); + in_scene->frame_max = frame_max; + + a3d::Scene& scene = file.prop; + scene._converter_version.assign("20111019"); + scene._file_name.assign(name); + scene._file_name.append(".a3da"); + scene._property_version.assign("20110526"); + scene.ready = true; + scene.compressed = true; + scene.format = a3d::FORMAT_AFT_X_PACK; + + for (a3d::Object& i : scene.object) { + replace_names(i.name); + replace_names(i.parent_name); + replace_names(i.uid_name); + + for (a3d::Texture& j : i.texture) + replace_names(j.name); + + for (a3d::TextureTransform& j : i.texture_transform) + replace_names(j.name); + } + + for (std::string& i : scene.object_list) + replace_names(i); + + for (a3d::ObjectHrc& i : scene.object_hrc) { + replace_names(i.name); + replace_names(i.parent_name); + replace_names(i.uid_name); + } + + for (std::string& i : scene.object_hrc_list) + replace_names(i); + + for (a3d::MObjectHrc& i : scene.m_object_hrc) { + for (a3d::ObjectInstance& j : i.instance) { replace_names(j.name); replace_names(j.uid_name); } @@ -11572,31 +11587,7 @@ static bool x_pv_game_write_auth_3d(farc* f, auth_3d* auth, auth_3d_database_fil replace_names(i.name); } - for (std::string& i : a.m_object_hrc_list) - replace_names(i); - - for (a3da_object& i : a.object) { - replace_names(i.name); - replace_names(i.parent_name); - replace_names(i.uid_name); - - for (a3da_object_texture_pattern& j : i.texture_pattern) - replace_names(j.name); - - for (a3da_object_texture_transform& j : i.texture_transform) - replace_names(j.name); - } - - for (a3da_object_hrc& i : a.object_hrc) { - replace_names(i.name); - replace_names(i.parent_name); - replace_names(i.uid_name); - } - - for (std::string& i : a.object_hrc_list) - replace_names(i); - - for (std::string& i : a.object_list) + for (std::string& i : scene.m_object_hrc_list) replace_names(i); bool own_farc = !f; @@ -11615,7 +11606,7 @@ static bool x_pv_game_write_auth_3d(farc* f, auth_3d* auth, auth_3d_database_fil farc_file* ff = f->add_file(name); ff->name.append(".a3da"); - a.write(&ff->data, &ff->size); + scene.write(&ff->data, &ff->size); if (own_farc) { farc_compress_ptr->AddFarc(f, sprintf_s_string("%s\\auth_3d\\%s", out_dir, name)); @@ -11648,15 +11639,15 @@ static bool x_pv_game_write_auth_3d(farc* f, auth_3d* auth, auth_3d_database_fil } auth_3d_database_uid_file& uid = auth_3d_db->uid.data()[uid_index]; - uid.flags = (auth_3d_database_uid_flags)(AUTH_3D_DATABASE_UID_SIZE | AUTH_3D_DATABASE_UID_ORG_UID); - uid.category.assign(own_farc ? name : category); - uid.size = auth->play_control.size; + uid.flag = auth_3d_database_uid_file::FLAG_ORG_UID | auth_3d_database_uid_file::FLAG_FRAME_SIZE; + uid.category_name.assign(own_farc ? name : category); + uid.frame_size = in_scene->play_control.size; uid.value.assign("A "); uid.value.append(name); return true; } -static void x_pv_game_write_auth_3d_camera(auth_3d* auth, int32_t pv_id, +static void x_pv_game_write_auth_3d_camera(auth_3d_detail::Scene* in_scene, int32_t pv_id, auth_3d_database_file* auth_3d_db, std::vector& avail_uids, const char* out_dir) { std::string category = sprintf_s_string("CAMPV%03d", pv_id); replace_names(category); @@ -11691,9 +11682,9 @@ static void x_pv_game_write_auth_3d_camera(auth_3d* auth, int32_t pv_id, } auth_3d_database_uid_file& uid = auth_3d_db->uid.data()[uid_index]; - uid.flags = (auth_3d_database_uid_flags)(AUTH_3D_DATABASE_UID_SIZE | AUTH_3D_DATABASE_UID_ORG_UID); - uid.category.assign(category); - uid.size = auth->play_control.size; + uid.flag = auth_3d_database_uid_file::FLAG_ORG_UID | auth_3d_database_uid_file::FLAG_FRAME_SIZE; + uid.category_name.assign(name); + uid.frame_size = in_scene->play_control.size; uid.value.assign("A "); uid.value.append(name); } @@ -11729,24 +11720,24 @@ static void x_pv_game_write_auth_3d_category(const std::string& category, size_t avail_uids_old_size = avail_uids.size(); for (auth_3d_database_uid_file& i : auth_3d_db->uid) { size_t index = &i - auth_3d_db->uid.data(); - if (!i.category.size() && prj::find(avail_uids, index)) + if (!i.category_name.size() && prj::find(avail_uids, index)) continue; - const uint64_t hash = hash_string_xxh3_64bits(i.category); + const uint64_t hash = hash_string_xxh3_64bits(i.category_name); if (hash == category_hash || itmpv && hash == itmpv_name_hash) { x_pv_game_baker_ptr->print_log(out_dir, "Clearing Auth 3D UID: %d" "; Former value: \"%s\"", i.org_uid, i.value.c_str()); - i.flags = AUTH_3D_DATABASE_UID_ORG_UID; - i.category.clear(); - i.size = 0.0f; + i.flag = auth_3d_database_uid_file::FLAG_ORG_UID; + i.category_name.clear(); + i.frame_size = 0.0f; i.value.clear(); avail_uids.push_back(index); } } if (avail_uids.size() != avail_uids_old_size) - prj::sort_unique(avail_uids); + prj::sort_and_erase_non_unique(avail_uids); } } @@ -11902,7 +11893,7 @@ static void x_pv_game_write_auth_3d_reflect(stream& s, auth_3d_database_file* au } } - names.sort_unique(); + names.sort_and_erase_non_unique(); for (auto& i : names) { i.second = ms.get_position(); @@ -12242,17 +12233,17 @@ static void x_pv_game_write_glitter(Glitter::EffectGroup* eff_group, const auth_ uint32_t file_name_hash = ext_anim->file_name_hash; uint32_t object_hash = ext_anim->object_hash; uint32_t instance_id = ext_anim->instance_id; - for (int32_t& i : auth_3d_data->loaded_ids) { + for (int32_t& i : auth_3d_detail::g_manager->handle_list) { if (i < 0 || (i & 0x7FFF) >= AUTH_3D_DATA_COUNT) continue; - auth_3d* auth = &auth_3d_data->data[i & 0x7FFF]; - if (auth->id != i) + auth_3d_detail::Scene* scene = &auth_3d_detail::g_manager->scene_buffer[i & 0x7FFF]; + if (scene->my_handle != i) continue; bool ret = false; if (file_name_hash != hash_murmurhash_empty) { - if (auth->hash != file_name_hash) + if (scene->hash != file_name_hash) continue; ret = true; @@ -12260,16 +12251,16 @@ static void x_pv_game_write_glitter(Glitter::EffectGroup* eff_group, const auth_ std::string uid_name; if (instance_id < 0) { - for (auth_3d_object& i : auth->object) - if (object_hash == i.object_hash) { + for (auth_3d_detail::Object& i : scene->object_holder) + if (object_hash == i.obj_hash) { uid_name.assign(i.uid_name); ret = false; break; } if (!uid_name.size()) - for (auth_3d_object_hrc& i : auth->object_hrc) - if (object_hash == i.object_hash) { + for (auth_3d_detail::HierarchyObject& i : scene->object_hrc_holder) + if (object_hash == i.obj_hash) { uid_name.assign(i.uid_name); ret = false; break; @@ -12277,8 +12268,8 @@ static void x_pv_game_write_glitter(Glitter::EffectGroup* eff_group, const auth_ } else { int32_t obj_instance = 0; - for (auth_3d_object& i : auth->object) - if (object_hash == i.object_hash) { + for (auth_3d_detail::Object& i : scene->object_holder) + if (object_hash == i.obj_hash) { if (obj_instance == instance_id) { uid_name.assign(i.uid_name); ret = false; @@ -12289,8 +12280,8 @@ static void x_pv_game_write_glitter(Glitter::EffectGroup* eff_group, const auth_ if (!uid_name.size()) { int32_t obj_hrc_instance = 0; - for (auth_3d_object_hrc& i : auth->object_hrc) - if (object_hash == i.object_hash) { + for (auth_3d_detail::HierarchyObject& i : scene->object_hrc_holder) + if (object_hash == i.obj_hash) { if (obj_hrc_instance == instance_id) { uid_name.assign(i.uid_name); ret = false; @@ -12320,7 +12311,7 @@ static void x_pv_game_write_glitter(Glitter::EffectGroup* eff_group, const auth_ } char auth_name[0x200]; - if (!get_replace_auth_name(auth_name, sizeof(auth_name), auth)) + if (!get_replace_auth_name(auth_name, sizeof(auth_name), scene)) goto End; ext_anim->file_name_hash = x_pack_auth_3d_db->get_uid(auth_name); @@ -12730,7 +12721,7 @@ static void x_pv_game_write_object_set(obj_set* obj_set, const std::string& name tex_ids->push_back(old_id, id); } - tex_ids->sort_unique(); + tex_ids->sort_and_erase_non_unique(); int32_t obj_num = set->obj_num; obj_set_info->object.reserve(obj_num); @@ -13450,14 +13441,14 @@ static void x_pv_game_write_stage_data(int32_t stage_id, const auth_3d_database* stage_data->auth_3d_ids.reserve(i.auth_3d_ids.size()); for (const uint32_t& j : i.auth_3d_ids) { - auth_3d* auth = auth_3d_data_get_auth_3d(j); - if (!auth) { + auth_3d_detail::Scene* scene = auth_3d_detail::get_scene(j); + if (!scene) { printf(""); continue; } char name[0x200]; - if (get_replace_auth_name(name, sizeof(name), auth)) { + if (get_replace_auth_name(name, sizeof(name), scene)) { int32_t uid = x_pack_auth_3d_db->get_uid(name); if (uid != -1) stage_data->auth_3d_ids.push_back(uid); @@ -13869,11 +13860,11 @@ inline static void replace_pv832(std::string& str) { #endif #if BAKE_X_PACK -static bool get_replace_auth_name(char* name, size_t name_size, auth_3d* auth) { +static bool get_replace_auth_name(char* name, size_t name_size, auth_3d_detail::Scene* in_scene) { if (!name) return false; - strcpy_s(name, name_size, auth->file_name.c_str()); + strcpy_s(name, name_size, in_scene->file_name.c_str()); const char* a3da_ext = ".a3da"; @@ -13896,15 +13887,15 @@ static void remove_auth_3d_category(auth_3d_database_file& auth_3d_db, size_t avail_uids_old_size = avail_uids.size(); for (auth_3d_database_uid_file& i : auth_3d_db.uid) { - if (i.category.size() < category_name_len || i.category.find(category_name) == -1) + if (i.category_name.size() < category_name_len || i.category_name.find(category_name) == -1) continue; x_pv_game_baker_ptr->print_log(out_dir, "Clearing Auth 3D UID: %d" "; Former value: \"%s\"", i.org_uid, i.value.c_str()); - i.flags = AUTH_3D_DATABASE_UID_ORG_UID; - i.category.clear(); - i.size = 0.0f; + i.flag = auth_3d_database_uid_file::FLAG_ORG_UID; + i.category_name.clear(); + i.frame_size = 0.0f; i.value.clear(); avail_uids.push_back(&i - auth_3d_db.uid.data()); } @@ -13924,7 +13915,7 @@ static void remove_auth_3d_category(auth_3d_database_file& auth_3d_db, i++; if (avail_uids.size() != avail_uids_old_size) - prj::sort_unique(avail_uids); + prj::sort_and_erase_non_unique(avail_uids); } static void replace_names(char* str) { diff --git a/src/ReDIVA/x_pv_game.hpp b/src/ReDIVA/x_pv_game.hpp index e6f1e494..564ddc9c 100644 --- a/src/ReDIVA/x_pv_game.hpp +++ b/src/ReDIVA/x_pv_game.hpp @@ -163,10 +163,10 @@ struct x_pv_play_data { }; struct x_pv_game_song_effect_auth_3d { - auth_3d_id id; + auth_3d_detail::Handle id; x_pv_game_song_effect_auth_3d(); - x_pv_game_song_effect_auth_3d(auth_3d_id id); + x_pv_game_song_effect_auth_3d(auth_3d_detail::Handle id); void reset(); }; @@ -200,7 +200,7 @@ struct x_pv_game_camera { int32_t state; string_hash category; string_hash file; - auth_3d_id id; + auth_3d_detail::Handle id; FrameRateControl* frame_rate_control; x_pv_game_camera(); @@ -229,11 +229,11 @@ struct x_pv_game_effect { x_pv_game_effect(); ~x_pv_game_effect(); + void assign_rob_id(int32_t index, ROB_ID rob_id, bool chara_scale); void ctrl(object_database* obj_db, texture_database* tex_db); void load(int32_t pv_id, pvpp* play_param, FrameRateControl* frame_rate_control); void load_data(int32_t pv_id, object_database* obj_db, texture_database* tex_db); void reset(); - void set_chara_id(int32_t index, ROB_ID rob_id, bool chara_scale); void set_song_effect(int32_t index, int64_t time); void set_song_effect_time(int32_t index, int64_t time, bool glitter); void set_song_effect_time_inner(int32_t index, int64_t time, bool glitter); @@ -246,12 +246,12 @@ struct x_pv_game_effect { struct x_pv_game_chara_effect_auth_3d { bool field_0; - CHARA_NUM src_chara; - CHARA_NUM dst_chara; + CHARA_NUM cn_src; + CHARA_NUM cn_dst; string_hash file; string_hash category; string_hash object_set; - auth_3d_id id; + auth_3d_detail::Handle id; int64_t time; std::string node_name; int32_t objhrc_index; @@ -570,7 +570,7 @@ public: }; struct x_pv_game_stage_env_data { - auth_3d_id light_auth_3d_id; + auth_3d_detail::Handle light_auth_3d_id; aet_obj_data data[5][8]; x_pv_game_stage_env_data(); @@ -620,7 +620,7 @@ struct x_pv_game_stage_env { struct x_pv_game_stage_effect_auth_3d { bool repeat; bool field_1; - auth_3d_id id; + auth_3d_detail::Handle id; x_pv_game_stage_effect_auth_3d(); @@ -716,7 +716,7 @@ struct x_pv_game_stage { object_database obj_db; texture_database tex_db; - std::map auth_3d_ids; + std::map auth_3d_ids; x_pv_game_stage(); ~x_pv_game_stage(); @@ -760,7 +760,7 @@ public: std::string light_category; - auth_3d_id light_auth_3d_id; + auth_3d_detail::Handle light_auth_3d_id; bool success; bool task_effect_init;