From f0392bd1664d0a1bf9167b0d8a9930ab14191684 Mon Sep 17 00:00:00 2001 From: korenkonder Date: Sun, 1 Jan 2023 21:55:13 +0300 Subject: [PATCH] Adapt some findings --- src/CRE/Glitter/effect_inst.cpp | 14 +- src/CRE/auth_3d.cpp | 712 +++++++-------- src/CRE/auth_3d.hpp | 99 ++- src/CRE/data.hpp | 2 - src/CRE/draw_pass.cpp | 2 +- src/CRE/draw_task.cpp | 4 +- src/CRE/object.cpp | 20 +- src/CRE/post_process.cpp | 339 ++++++- src/CRE/post_process.hpp | 11 +- src/CRE/post_process/aa.cpp | 299 ++++--- src/CRE/post_process/dof.cpp | 18 +- src/CRE/post_process/exposure.cpp | 36 +- src/CRE/post_process/tone_map.cpp | 102 ++- src/CRE/post_process/tone_map.hpp | 6 +- src/CRE/pv_expression.cpp | 13 + src/CRE/pv_expression.hpp | 13 - src/CRE/render_context.hpp | 2 +- src/CRE/rob/ex_block.cpp | 977 ++++++++++----------- src/CRE/rob/rob.cpp | 114 ++- src/CRE/rob/rob.hpp | 155 ++-- src/CRE/stage.cpp | 18 +- src/CRE/stage.hpp | 2 +- src/CRE/stage_modern.cpp | 16 +- src/CRE/stage_modern.hpp | 2 +- src/CRE/task_effect.cpp | 64 +- src/CRE/task_effect.hpp | 6 +- src/KKdLib/a3da.cpp | 8 +- src/KKdLib/alloc_data.hpp | 5 +- src/KKdLib/interpolation.cpp | 36 +- src/KKdLib/mat.hpp | 14 +- src/KKdLib/mot.cpp | 388 ++++---- src/KKdLib/mot.hpp | 27 +- src/ReDIVA/classes/data_view/draw_task.cpp | 2 +- src/ReDIVA/config.hpp | 12 + src/ReDIVA/data_edit.cpp | 551 ++++++++++++ src/ReDIVA/data_edit.hpp | 59 ++ src/ReDIVA/data_test/auth_3d_test.cpp | 22 +- src/ReDIVA/game_state.cpp | 112 ++- src/ReDIVA/game_state.hpp | 27 +- src/ReDIVA/pv_game.cpp | 59 +- src/ReDIVA/pv_game.hpp | 6 +- src/ReDIVA/render.cpp | 35 +- src/ReDIVA/x_pv_game.cpp | 527 +++++------ src/ReDIVA/x_pv_game.hpp | 31 +- 44 files changed, 3144 insertions(+), 1823 deletions(-) create mode 100644 src/ReDIVA/config.hpp create mode 100644 src/ReDIVA/data_edit.cpp create mode 100644 src/ReDIVA/data_edit.hpp diff --git a/src/CRE/Glitter/effect_inst.cpp b/src/CRE/Glitter/effect_inst.cpp index 02a384dc..da1279aa 100644 --- a/src/CRE/Glitter/effect_inst.cpp +++ b/src/CRE/Glitter/effect_inst.cpp @@ -403,7 +403,7 @@ namespace Glitter { mat4 temp; mat4* obj_mat = 0; if (ext_anim->a3da_id != -1) - obj_mat = auth_3d_data_get_auth_3d_object_mat(ext_anim->a3da_id, + obj_mat = auth_3d_id(ext_anim->a3da_id).get_auth_3d_object_mat( ext_anim->object_index, ext_anim->object_is_hrc, &temp); if (!obj_mat) { @@ -413,14 +413,14 @@ namespace Glitter { return; ext_anim->mesh_index = -1; - obj_mat = auth_3d_data_get_auth_3d_object_mat(ext_anim->a3da_id, + obj_mat = auth_3d_id(ext_anim->a3da_id).get_auth_3d_object_mat( ext_anim->object_index, ext_anim->object_is_hrc, &temp); if (!obj_mat) return; } mat = mat4_identity; - chara_id = auth_3d_data_get_chara_id(ext_anim->a3da_id); + chara_id = auth_3d_id(ext_anim->a3da_id).get_chara_id(); if (chara_id >= 0 && chara_id < ROB_CHARA_COUNT) { rob_chara* rob_chr = rob_chara_array_get(chara_id); if (rob_chr) { @@ -929,7 +929,7 @@ namespace Glitter { ext_anim_scale.z = 0.0f; enum_or(flags, EFFECT_INST_HAS_EXT_ANIM_SCALE); - if (rob_chr->get_visibility() || !(data.ext_anim_x->flags & EFFECT_EXT_ANIM_NO_DRAW_IF_NO_DATA)) + if (rob_chr->is_visible() || !(data.ext_anim_x->flags & EFFECT_EXT_ANIM_NO_DRAW_IF_NO_DATA)) set_flags = true; else set_flags = false; @@ -947,7 +947,7 @@ namespace Glitter { mat4 temp; mat4* obj_mat = 0; if (ext_anim->a3da_id != -1) - obj_mat = auth_3d_data_get_auth_3d_object_mat(ext_anim->a3da_id, + obj_mat = auth_3d_id(ext_anim->a3da_id).get_auth_3d_object_mat( ext_anim->object_index, ext_anim->object_is_hrc, &temp); if (!obj_mat) { @@ -958,7 +958,7 @@ namespace Glitter { return; ext_anim->mesh_index = -1; - obj_mat = auth_3d_data_get_auth_3d_object_mat(ext_anim->a3da_id, + obj_mat = auth_3d_id(ext_anim->a3da_id).get_auth_3d_object_mat( ext_anim->object_index, ext_anim->object_is_hrc, &temp); if (!obj_mat) return; @@ -966,7 +966,7 @@ namespace Glitter { const mat4* mat = &mat4_identity; - int32_t chara_id = auth_3d_data_get_chara_id(ext_anim->a3da_id); + int32_t chara_id = auth_3d_id(ext_anim->a3da_id).get_chara_id(); if (chara_id >= 0 && chara_id < ROB_CHARA_COUNT) { rob_chara* rob_chr = rob_chara_array_get(chara_id); if (rob_chr) { diff --git a/src/CRE/auth_3d.cpp b/src/CRE/auth_3d.cpp index c7e047d4..f655b59d 100644 --- a/src/CRE/auth_3d.cpp +++ b/src/CRE/auth_3d.cpp @@ -2206,6 +2206,341 @@ auth_3d_uid_file_modern::~auth_3d_uid_file_modern() { } +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; +} + +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->chara_id; + } + return -1; +} + +mat4* auth_3d_id::get_auth_3d_object_mat(size_t index, bool hrc, mat4* mat) { + 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); + + if (index >= auth->object.size()) + return 0; + + *mat = auth->object[index].model_transform.mat; + return mat; +} + +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_left_right_reverse() { + if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { + auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; + if (auth->id == id) + return auth->left_right_reverse; + } + 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_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; + } +} + +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->chara_id = value; + } +} + +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; + } +} + +void auth_3d_id::set_draw_task_flags_alpha(draw_task_flags draw_task_flags, float_t alpha) { + if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { + auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; + if (auth->id == id) { + auth->draw_task_flags = draw_task_flags; + auth->alpha = alpha; + } + } +} + +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; + } +} + +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; + else + auth->frame_rate = &sys_frame_rate; + } +} + +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_left_right_reverse(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->left_right_reverse = 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_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_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; + } + } +} + +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; + } +} + +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; + } + } +} + +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; + } +} + +void auth_3d_id::unload_id(render_context* rctx) { + if (id < 0 || (id & 0x7FFF) >= AUTH_3D_DATA_COUNT) + return; + + auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; + if (!auth || auth->id != id) + return; + + for (auto i = auth_3d_data->loaded_ids.begin(); i != auth_3d_data->loaded_ids.end();) { + if (*i != id) { + i++; + continue; + } + + i = auth_3d_data->loaded_ids.erase(i); + auth->unload(rctx); + break; + } +} + auth_3d_data_struct::auth_3d_data_struct() { } @@ -2226,7 +2561,7 @@ Auth3dTestTask::Auth3dTestTask() { field_1CC = 10; field_1D0 = false; field_1D4 = 0; - auth_3d_id = -1; + auth_3d_id = {}; auth_3d_uid = -1; repeat = true; left_right_reverse = false; @@ -2262,7 +2597,7 @@ bool Auth3dTestTask::Init() { field_1D0 = false; field_1D4 = 0; - auth_3d_id = -1; + auth_3d_id = {}; auth_3d_uid = -1; repeat = true; left_right_reverse = false; @@ -2304,28 +2639,28 @@ bool Auth3dTestTask::Ctrl() { if (field_1EC == 1 && !object_storage_load_obj_set_check_not_read(effcmn_obj_set)) field_1EC = 4; - if (field_1D4 == 1 && auth_3d_data_check_id_loaded(auth_3d_id)) + if (field_1D4 == 1 && auth_3d_id.check_loaded()) field_1D4 = 2; if (field_1D4 == 2) { - auth_3d_data_set_enable(auth_3d_id, true); - auth_3d_data_set_paused(auth_3d_id, false); - auth_3d_data_set_repeat(auth_3d_id, repeat); - auth_3d_data_set_left_right_reverse(auth_3d_id, left_right_reverse); + auth_3d_id.set_enable(true); + auth_3d_id.set_paused(false); + auth_3d_id.set_repeat(repeat); + auth_3d_id.set_left_right_reverse(left_right_reverse); field_1D4 = 4; } - if (auth_3d_data_check_id_not_empty(auth_3d_id)) { + if (auth_3d_id.check_not_empty()) { mat4 mat; mat4_translate(&trans_value, &mat); mat4_rotate_y_mult(&mat, rot_y_value * DEG_TO_RAD_FLOAT, &mat); - auth_3d_data_set_mat(auth_3d_id, &mat); + auth_3d_id.set_mat(mat); } return false; } bool Auth3dTestTask::Dest() { - auth_3d_data_unload_id(auth_3d_id, rctx_ptr); + auth_3d_id.unload_id(rctx_ptr); object_storage_unload_set(effcmn_obj_set); task_stage_unload_task(); clear_color = color_black; @@ -2347,15 +2682,6 @@ void auth_3d_data_init() { auth_3d_data = new auth_3d_data_struct; } -bool auth_3d_data_check_id_not_empty(const int32_t& 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->id != -1; - } - return false; -} - bool auth_3d_data_check_category_loaded(const char* category_name) { return auth_3d_data_struct_check_category_loaded(auth_3d_data, category_name); } @@ -2364,33 +2690,6 @@ bool auth_3d_data_check_category_loaded(uint32_t category_hash) { return auth_3d_data_struct_check_category_loaded(auth_3d_data, category_hash); } -bool auth_3d_data_check_id_loading(const int32_t& 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->state == 1; - } - return false; -} - -bool auth_3d_data_check_id_loaded(const int32_t& 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->state == 2; - } - return true; -} - -auth_3d* auth_3d_data_get_auth_3d(const int32_t& id) { - int32_t index = 0; - while (auth_3d_data->data[index].id != id) - if (++index >= AUTH_3D_DATA_COUNT) - return 0; - - return &auth_3d_data->data[index]; -} - 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) @@ -2487,121 +2786,6 @@ int32_t auth_3d_data_get_auth_3d_id(uint32_t file_name_hash, uint32_t object_has return -1; } -int32_t auth_3d_data_get_chara_id(const int32_t& id) { - auth_3d* auth = auth_3d_data_get_auth_3d(id); - if (auth) - return auth->chara_id; - return -1; -} - -mat4* auth_3d_data_get_auth_3d_object_mat(const int32_t& id, size_t index, bool hrc, mat4* mat) { - 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); - - if (index >= auth->object.size()) - return 0; - - *mat = auth->object[index].model_transform.mat; - return mat; -} - -bool auth_3d_data_get_enable(const int32_t& 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->enable; - } - return false; -} - -bool auth_3d_data_get_ended(const int32_t& 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->ended; - } - return true; -} - -float_t auth_3d_data_get_frame(const int32_t& 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->frame; - } - return 0.0f; -} - -float_t auth_3d_data_get_frame_offset(const int32_t& 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->frame_offset; - } - return 0.0f; -} - -float_t auth_3d_data_get_last_frame(const int32_t& 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->last_frame; - } - return 0.0f; -} - -bool auth_3d_data_get_left_right_reverse(const int32_t& 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->left_right_reverse; - } - return false; -} - -float_t auth_3d_data_get_play_control_begin(const int32_t& 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->play_control.begin; - } - return 0.0f; -} - -float_t auth_3d_data_get_play_control_size(const int32_t& 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->play_control.size; - } - return 0.0f; -} - -bool auth_3d_data_get_paused(const int32_t& 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->paused; - } - return false; -} - -bool auth_3d_data_get_repeat(const int32_t& 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->repeat; - } - return false; -} - 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) { obj_sets.clear(); @@ -2676,15 +2860,6 @@ void auth_3d_data_get_obj_sets_from_category(std::string& name, std::vector= 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; -} - const char* auth_3d_data_get_uid_name(int32_t uid, auth_3d_database* auth_3d_db) { if (uid < 0 || uid > auth_3d_db->uid.size()) return 0; @@ -2719,7 +2894,7 @@ void auth_3d_data_load_category(void* data, const char* category_name, uint32_t auth_3d_data_struct_load_category(auth_3d_data, data, category_name, category_hash); } -int32_t auth_3d_data_load_hash(uint32_t hash, void* data, object_database* obj_db, texture_database* tex_db) { +auth_3d_id auth_3d_data_load_hash(uint32_t hash, void* data, object_database* obj_db, texture_database* tex_db) { 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; @@ -2741,7 +2916,7 @@ int32_t auth_3d_data_load_hash(uint32_t hash, void* data, object_database* obj_d 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 -1; + return auth_3d_id(); auth_3d_data->data[index].reset(); @@ -2752,18 +2927,18 @@ int32_t auth_3d_data_load_hash(uint32_t hash, void* data, object_database* obj_d auth_3d_data->data[index].hash = hash; auth_3d_data->data[index].id = id; auth_3d_data->loaded_ids.push_back(id); - return id; + return auth_3d_id(id); } -int32_t auth_3d_data_load_uid(int32_t uid, auth_3d_database* auth_3d_db) { +auth_3d_id auth_3d_data_load_uid(int32_t uid, auth_3d_database* auth_3d_db) { if (uid >= auth_3d_db->uid.size() || !auth_3d_db->uid[uid].enabled) - return -1; + return auth_3d_id(); 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 -1; + return auth_3d_id(); auth_3d_data->data[index].reset(); @@ -2774,160 +2949,7 @@ int32_t auth_3d_data_load_uid(int32_t uid, auth_3d_database* auth_3d_db) { auth_3d_data->data[index].uid = uid; auth_3d_data->data[index].id = id; auth_3d_data->loaded_ids.push_back(id); - return id; -} - -void auth_3d_data_read_file(const int32_t& id, 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_data_read_file_modern(const int32_t& id) { - 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_data_set_camera_root_update(const int32_t& id, 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; - } -} - -void auth_3d_data_set_chara_id(const int32_t& 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->chara_id = value; - } -} - -void auth_3d_data_set_chara_item(const int32_t& id, 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; - } -} - -void auth_3d_data_set_draw_task_flags_alpha(const int32_t& id, draw_task_flags draw_task_flags, float_t alpha) { - if (id >= 0 && ((id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (auth->id == id) { - auth->draw_task_flags = draw_task_flags; - auth->alpha = alpha; - } - } -} - -void auth_3d_data_set_enable(const int32_t& id, 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; - } -} - -void auth_3d_data_set_frame_rate(const int32_t& id, 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; - else - auth->frame_rate = &sys_frame_rate; - } -} - -void auth_3d_data_set_last_frame(const int32_t& id, 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_data_set_left_right_reverse(const int32_t& id, 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->left_right_reverse = value; - } -} - -void auth_3d_data_set_mat(const int32_t& id, 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_data_set_max_frame(const int32_t& id, 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_data_set_paused(const int32_t& id, 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_data_set_repeat(const int32_t& id, 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_data_set_req_frame(const int32_t& id, 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; - } - } -} - -void auth_3d_data_set_shadow(const int32_t& id, 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; - } -} - -void auth_3d_data_set_src_dst_chara(const int32_t& id, 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; - } - } -} - -void auth_3d_data_set_visibility(const int32_t& id, 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; - } + return auth_3d_id(id); } void auth_3d_data_unload_category(const char* category_name) { @@ -2938,26 +2960,6 @@ 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_unload_id(const int32_t& id, render_context* rctx) { - if (id < 0 || (id & 0x7FFF) >= AUTH_3D_DATA_COUNT) - return; - - auth_3d* auth = &auth_3d_data->data[id & 0x7FFF]; - if (!auth || auth->id != id) - return; - - for (auto i = auth_3d_data->loaded_ids.begin(); i != auth_3d_data->loaded_ids.end();) { - if (*i != id) { - i++; - continue; - } - - i = auth_3d_data->loaded_ids.erase(i); - auth->unload(rctx); - break; - } -} - void auth_3d_data_free() { delete auth_3d_data; } @@ -6490,7 +6492,7 @@ static size_t auth_3d_time_event_radix_index_func_time(auth_3d_time_event* data, static void Auth3dTestTask__SetAuth3dId(Auth3dTestTask* tt) { if (task_stage_check_not_loaded() || tt->auth_3d_uid == -1 - || !tt->load_category.size() || tt->auth_3d_uid == auth_3d_data_get_uid(tt->auth_3d_id)) + || !tt->load_category.size() || tt->auth_3d_uid == tt->auth_3d_id.get_uid()) return; if (tt->load_category.compare(tt->category)) { @@ -6534,11 +6536,11 @@ static void Auth3dTestTask__SetAuth3dId(Auth3dTestTask* tt) { data_struct* aft_data = &data_list[DATA_AFT]; auth_3d_database* aft_auth_3d_db = &aft_data->data_ft.auth_3d_db; - auth_3d_data_unload_id(tt->auth_3d_id, rctx_ptr); + tt->auth_3d_id.unload_id(rctx_ptr); tt->auth_3d_id = auth_3d_data_load_uid(tt->auth_3d_uid, aft_auth_3d_db); - if (auth_3d_data_check_id_not_empty(tt->auth_3d_id)) { - auth_3d_data_set_enable(tt->auth_3d_id, false); - auth_3d_data_read_file(tt->auth_3d_id, aft_auth_3d_db); + if (tt->auth_3d_id.check_not_empty()) { + tt->auth_3d_id.set_enable(false); + tt->auth_3d_id.read_file(aft_auth_3d_db); tt->field_1D4 = 1; } tt->auth_3d_uid = -1; diff --git a/src/CRE/auth_3d.hpp b/src/CRE/auth_3d.hpp index af34094f..96d90085 100644 --- a/src/CRE/auth_3d.hpp +++ b/src/CRE/auth_3d.hpp @@ -791,6 +791,63 @@ struct auth_3d_time_event { size_t event_index; }; +struct auth_3d_id { + int32_t id; + + inline auth_3d_id() { + id = -1; + } + + inline auth_3d_id(int32_t id) { + this->id = id; + } + + inline bool is_null() { + return id == -1; + } + + inline bool not_null() { + return id != -1; + } + + bool check_not_empty(); + bool check_loading(); + bool check_loaded(); + auth_3d* get_auth_3d(); + mat4* get_auth_3d_object_mat(size_t index, bool hrc, mat4* mat); + 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_left_right_reverse(); + 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_camera_root_update(bool value); + void set_chara_id(int32_t value); + void set_chara_item(bool value); + void set_draw_task_flags_alpha(draw_task_flags draw_task_flags, float_t alpha); + void set_enable(bool value); + void set_frame_rate(FrameRateControl* value); + void set_last_frame(float_t value); + void set_left_right_reverse(bool value); + void set_mat(const mat4& value); + void set_max_frame(float_t value); + void set_paused(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_id(render_context* rctx); +}; + struct auth_3d { int32_t uid; int32_t id; @@ -925,7 +982,7 @@ public: int32_t field_1CC; bool field_1D0; int32_t field_1D4; - int32_t auth_3d_id; + ::auth_3d_id auth_3d_id; int32_t auth_3d_uid; bool repeat; bool left_right_reverse; @@ -973,59 +1030,23 @@ extern auth_3d_data_struct* auth_3d_data; extern Auth3dTestTask* auth_3d_test_task; extern void auth_3d_data_init(); -extern bool auth_3d_data_check_id_not_empty(const int32_t& id); 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 bool auth_3d_data_check_id_loading(const int32_t& id); -extern bool auth_3d_data_check_id_loaded(const int32_t& id); -extern auth_3d* auth_3d_data_get_auth_3d(const int32_t& id); 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 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 instance = -1); -extern mat4* auth_3d_data_get_auth_3d_object_mat(const int32_t& id, size_t index, bool hrc, mat4* mat); -extern int32_t auth_3d_data_get_chara_id(const int32_t& id); -extern bool auth_3d_data_get_enable(const int32_t& id); -extern bool auth_3d_data_get_ended(const int32_t& id); -extern float_t auth_3d_data_get_frame(const int32_t& id); -extern float_t auth_3d_data_get_frame_offset(const int32_t& id); -extern float_t auth_3d_data_get_last_frame(const int32_t& id); -extern bool auth_3d_data_get_left_right_reverse(const int32_t& id); -extern bool auth_3d_data_get_paused(const int32_t& id); -extern float_t auth_3d_data_get_play_control_begin(const int32_t& id); -extern float_t auth_3d_data_get_play_control_size(const int32_t& id); -extern bool auth_3d_data_get_repeat(const int32_t& id); 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 int32_t auth_3d_data_get_uid(const int32_t& id); 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 int32_t auth_3d_data_load_hash(uint32_t hash, void* data, object_database* obj_db, texture_database* tex_db); -extern int32_t auth_3d_data_load_uid(int32_t uid, auth_3d_database* auth_3d_db); -extern void auth_3d_data_read_file(const int32_t& id, auth_3d_database* auth_3d_db); -extern void auth_3d_data_read_file_modern(const int32_t& id); -extern void auth_3d_data_set_camera_root_update(const int32_t& id, bool value); -extern void auth_3d_data_set_chara_id(const int32_t& id, int32_t value); -extern void auth_3d_data_set_chara_item(const int32_t& id, bool value); -extern void auth_3d_data_set_draw_task_flags_alpha(const int32_t& id, draw_task_flags draw_task_flags, float_t alpha); -extern void auth_3d_data_set_enable(const int32_t& id, bool value); -extern void auth_3d_data_set_frame_rate(const int32_t& id, FrameRateControl* value); -extern void auth_3d_data_set_last_frame(const int32_t& id, float_t value); -extern void auth_3d_data_set_left_right_reverse(const int32_t& id, bool value); -extern void auth_3d_data_set_mat(const int32_t& id, const mat4* value); -extern void auth_3d_data_set_max_frame(const int32_t& id, float_t value); -extern void auth_3d_data_set_paused(const int32_t& id, bool value); -extern void auth_3d_data_set_repeat(const int32_t& id, bool value); -extern void auth_3d_data_set_req_frame(const int32_t& id, float_t value); -extern void auth_3d_data_set_shadow(const int32_t& id, bool value); -extern void auth_3d_data_set_src_dst_chara(const int32_t& id, int32_t src_chara, int32_t dst_chara); -extern void auth_3d_data_set_visibility(const int32_t& id, bool value); +extern auth_3d_id auth_3d_data_load_hash(uint32_t hash, void* data, object_database* obj_db, texture_database* tex_db); +extern auth_3d_id auth_3d_data_load_uid(int32_t uid, auth_3d_database* auth_3d_db); extern void auth_3d_data_unload_category(const char* category_name); extern void auth_3d_data_unload_category(uint32_t category_hash); -extern void auth_3d_data_unload_id(const int32_t& id, render_context* rctx); extern void auth_3d_data_free(); extern void auth_3d_test_task_init(); diff --git a/src/CRE/data.hpp b/src/CRE/data.hpp index d56e79b3..21be54e3 100644 --- a/src/CRE/data.hpp +++ b/src/CRE/data.hpp @@ -122,8 +122,6 @@ struct data_struct { extern data_struct* data_list; -#define DATA_LOAD_FILE_FUNC(f) - extern void data_struct_init(); extern void data_struct_load(const char* path); extern void data_struct_load(const wchar_t* path); diff --git a/src/CRE/draw_pass.cpp b/src/CRE/draw_pass.cpp index 31fb1140..196e5a28 100644 --- a/src/CRE/draw_pass.cpp +++ b/src/CRE/draw_pass.cpp @@ -950,7 +950,7 @@ static void draw_pass_3d(render_context* rctx, draw_pass* a1) { if (a1->npr_param == 1) draw_pass_3d_contour(rctx, a1); - //post_process_draw_lens_flare(pp); + rctx->post_process.draw_lens_flare(rctx->camera); //star_catalog_data.draw(); draw_task_draw_objects_by_type_translucent(rctx, diff --git a/src/CRE/draw_task.cpp b/src/CRE/draw_task.cpp index 415e1eab..c33e7e45 100644 --- a/src/CRE/draw_task.cpp +++ b/src/CRE/draw_task.cpp @@ -160,7 +160,7 @@ void draw_task_draw_objects_by_type(render_context* rctx, draw_object_type type, task->data.preprocess.func(rctx, task->data.preprocess.data); } break; case DRAW_TASK_OBJECT_TRANSLUCENT: { - for (int32_t j = 0; j < task->data.object_translucent.count; j++) + for (uint32_t j = 0; j < task->data.object_translucent.count; j++) draw_object_draw(rctx, task->data.object_translucent.objects[j], &task->mat, draw_object_func, show_vector); } break; @@ -179,7 +179,7 @@ void draw_task_draw_objects_by_type(render_context* rctx, draw_object_type type, } } break; case DRAW_TASK_OBJECT_TRANSLUCENT: { - for (int32_t j = 0; j < task->data.object_translucent.count; j++) { + for (uint32_t j = 0; j < task->data.object_translucent.count; j++) { draw_object* object = task->data.object_translucent.objects[j]; int32_t a = (int32_t)(object->blend_color.w * 255.0f); a = clamp_def(a, 0, 255); diff --git a/src/CRE/object.cpp b/src/CRE/object.cpp index 88350d4f..659cb052 100644 --- a/src/CRE/object.cpp +++ b/src/CRE/object.cpp @@ -17,6 +17,7 @@ #include "../KKdLib/dds.hpp" #include "../KKdLib/hash.hpp" #include "../KKdLib/msgpack.hpp" +#include "../KKdLib/sort.hpp" #include "../KKdLib/str_utils.hpp" static void obj_set_handler_calc_axis_aligned_bounding_box(obj_set_handler* handler); @@ -1687,14 +1688,15 @@ GLuint obj_database_get_obj_set_texture(int32_t set, uint32_t tex_id) { size_t length = handler->tex_id_data.size(); size_t temp; while (length > 0) - if (tex_id < texture[temp = length / 2].first) + if (tex_id <= texture[temp = length / 2].first) length /= 2; else { texture += temp + 1; length -= temp + 1; } - if (texture != handler->tex_id_data.data() + handler->tex_id_data.size()) + if (texture != handler->tex_id_data.data() + handler->tex_id_data.size() + && tex_id == texture->first) return (*textures)[texture->second]; return -1; } @@ -1812,6 +1814,12 @@ int32_t object_storage_load_set_hash(void* data, uint32_t hash) { return 0; } +static int32_t obj_set_obj_id_data_sort(void const* src1, void const* src2) { + std::pair* p1 = (std::pair*)src1; + std::pair* p2 = (std::pair*)src2; + return (int32_t)(p1->first - p2->first); +} + bool object_storage_load_obj_set_check_not_read(uint32_t set_id, object_database* obj_db, texture_database* tex_db) { obj_set_handler* handler = object_storage_get_obj_set_handler(set_id); @@ -1839,6 +1847,9 @@ bool object_storage_load_obj_set_check_not_read(uint32_t set_id, for (uint32_t i = 0; i < set->obj_num; i++) handler->obj_id_data.push_back({ set->obj_data[i].id, i }); + quicksort_custom(handler->obj_id_data.data(), handler->obj_id_data.size(), + sizeof(std::pair), obj_set_obj_id_data_sort); + if (!obj_set_handler_vertex_buffer_load(handler) || !obj_set_handler_index_buffer_load(handler)) return false; @@ -2157,7 +2168,7 @@ static void obj_set_handler_index_buffer_free(obj_set_handler* handler) { static int32_t obj_set_tex_id_data_sort(void const* src1, void const* src2) { std::pair* p1 = (std::pair*)src1; std::pair* p2 = (std::pair*)src2; - return p1->first - p2->first; + return (int32_t)(p1->first - p2->first); } static bool obj_set_handler_load_textures(obj_set_handler* handler, const void* data, bool big_endian) { @@ -2183,6 +2194,9 @@ static bool obj_set_handler_load_textures(obj_set_handler* handler, const void* handler->tex_id_data.push_back({ tex_id_data[i], i }); handler->gentex.push_back(tex_data[i]->tex); } + + quicksort_custom(handler->tex_id_data.data(), handler->tex_id_data.size(), + sizeof(std::pair), obj_set_tex_id_data_sort); return false; } diff --git a/src/CRE/post_process.cpp b/src/CRE/post_process.cpp index ad4df8d8..ee83d7b8 100644 --- a/src/CRE/post_process.cpp +++ b/src/CRE/post_process.cpp @@ -4,6 +4,7 @@ */ #include "post_process.hpp" +#include "rob/rob.hpp" #include "fbo.hpp" #include "gl_state.hpp" #include "render_texture.hpp" @@ -15,12 +16,15 @@ extern bool task_stage_is_modern; +extern render_context* rctx_ptr; + post_process::post_process() : ssaa(), mlaa(), ss_alpha_mask(), aet_back_tex(), render_textures_data(), -movie_textures_data(), texture_counter(), lens_flare_texture(), lens_shaft_texture(), -lens_ghost_texture(), lens_flare_count(), lens_flare_pos(), lens_shaft_scale(), lens_shaft_inv_scale(), -lens_flare_power(), field_A10(), lens_flare_appear_power(), render_width(), render_height(), -view_point(), interest(), view_point_prev(), interest_prev(), reset_exposure(), sprite_width(), -sprite_height(), screen_x_offset(), screen_y_offset(), screen_width(), screen_height(), mag_filter() { +movie_textures_data(), texture_counter(), lens_shaft_query(), lens_flare_query(), lens_shaft_query_data(), +lens_flare_query_data(), lens_flare_query_index(), lens_flare_texture(), lens_shaft_texture(), +lens_ghost_texture(), lens_ghost_count(), lens_flare_pos(), lens_shaft_scale(), lens_shaft_inv_scale(), +lens_flare_power(), field_A10(), lens_flare_appear_power(), render_width(), render_height(), view_point(), +interest(), view_point_prev(), interest_prev(), reset_exposure(), sprite_width(), sprite_height(), +screen_x_offset(), screen_y_offset(), screen_width(), screen_height(), mag_filter() { static const char* query_vert_shader = "#version 430 core\n" "layout(location = 0) in vec4 a_position;\n" @@ -93,7 +97,7 @@ sprite_height(), screen_x_offset(), screen_y_offset(), screen_width(), screen_he glSamplerParameteri(samplers[1], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glSamplerParameteri(samplers[1], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - const float_t verts_quad[] = { + const float_t query_verts[] = { -1.0f, -1.0f, 0.15f, 0.15f, 1.0f, -1.0f, 0.85f, 0.15f, -1.0f, 1.0f, 0.15f, 0.85f, @@ -106,9 +110,45 @@ sprite_height(), screen_x_offset(), screen_y_offset(), screen_width(), screen_he glGenBuffers(1, &query_vbo); gl_state_bind_array_buffer(query_vbo, true); if (GLAD_GL_VERSION_4_4) - glBufferStorage(GL_ARRAY_BUFFER, sizeof(verts_quad), verts_quad, 0); + glBufferStorage(GL_ARRAY_BUFFER, sizeof(query_verts), query_verts, 0); else - glBufferData(GL_ARRAY_BUFFER, sizeof(verts_quad), verts_quad, GL_STATIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, sizeof(query_verts), query_verts, GL_STATIC_DRAW); + + glEnableVertexAttribArray(0); + glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 16, (void*)0); // Pos + glVertexAttrib4f(3, 1.0f, 1.0f, 1.0f, 1.0f); // Color0 + glVertexAttrib4f(4, 1.0f, 1.0f, 1.0f, 1.0f); // Color1 + glEnableVertexAttribArray(8); + glVertexAttribPointer(8, 2, GL_FLOAT, GL_FALSE, 16, (void*)8); // TexCoord0 + + glGenVertexArrays(1, &lens_ghost_vao); + gl_state_bind_vertex_array(lens_ghost_vao); + + const float_t lens_ghost_verts[] = { + -0.5f, -0.5f, 0.0f, 0.0f, + 0.5f, -0.5f, 0.5f, 0.0f, + -0.5f, 0.5f, 0.0f, 0.5f, + 0.5f, 0.5f, 0.5f, 0.5f, + -0.5f, -0.5f, 0.5f, 0.0f, + 0.5f, -0.5f, 1.0f, 0.0f, + -0.5f, 0.5f, 0.5f, 0.5f, + 0.5f, 0.5f, 1.0f, 0.5f, + -0.5f, -0.5f, 0.0f, 0.5f, + 0.5f, -0.5f, 0.5f, 0.5f, + -0.5f, 0.5f, 0.0f, 1.0f, + 0.5f, 0.5f, 0.5f, 1.0f, + -0.5f, -0.5f, 0.5f, 0.5f, + 0.5f, -0.5f, 1.0f, 0.5f, + -0.5f, 0.5f, 0.5f, 1.0f, + 0.5f, 0.5f, 1.0f, 1.0f, + }; + + glGenBuffers(1, &lens_ghost_vbo); + gl_state_bind_array_buffer(lens_ghost_vbo, true); + if (GLAD_GL_VERSION_4_4) + glBufferStorage(GL_ARRAY_BUFFER, sizeof(lens_ghost_verts), lens_ghost_verts, 0); + else + glBufferData(GL_ARRAY_BUFFER, sizeof(lens_ghost_verts), lens_ghost_verts, GL_STATIC_DRAW); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 16, (void*)0); // Pos @@ -128,6 +168,13 @@ sprite_height(), screen_x_offset(), screen_y_offset(), screen_width(), screen_he param.name = "Alpha Layer"; alpha_layer_shader.load(alpha_layer_vert_shader, alpha_layer_frag_shader, 0, ¶m); + + if (!lens_shaft_query[0]) + glGenQueries(3, lens_shaft_query); + + if (!lens_flare_query[0]) + glGenQueries(3, lens_flare_query); + reset(); } @@ -175,8 +222,28 @@ post_process::~post_process() { query_vbo = 0; } + if (lens_ghost_vao) { + glDeleteVertexArrays(1, &lens_ghost_vao); + lens_ghost_vao = 0; + } + + if (lens_ghost_vbo) { + glDeleteBuffers(1, &lens_ghost_vbo); + lens_ghost_vbo = 0; + } + query_shader.unload(); alpha_layer_shader.unload(); + + if (lens_shaft_query[0]) { + glDeleteQueries(3, lens_shaft_query); + lens_shaft_query[0] = 0; + } + + if (lens_flare_query[0]) { + glDeleteQueries(3, lens_flare_query); + lens_flare_query[0] = 0; + } } void post_process::apply(camera* cam, texture* light_proj_tex, int32_t npr_param) { @@ -189,6 +256,8 @@ void post_process::apply(camera* cam, texture* light_proj_tex, int32_t npr_param dof->apply(&rend_texture, &buf_texture, samplers, cam); + draw_lens_ghost(&rend_texture); + shaders_ft.state_matrix_set_mvp(mat4_identity, mat4_identity, mat4_identity); blur->get_blur(&rend_texture); @@ -197,7 +266,7 @@ void post_process::apply(camera* cam, texture* light_proj_tex, int32_t npr_param tone_map->apply(&rend_texture, light_proj_tex, (texture*)(aet_back ? aet_back_tex : 0), &rend_texture, &buf_texture,/* &sss_contour_texture,*/ blur->tex[0].color_texture->tex, - exposure->exposure.color_texture->tex, npr_param); + exposure->exposure.color_texture->tex, npr_param, this); if (mlaa) aa->apply_mlaa(&rend_texture, &buf_texture, samplers, ss_alpha_mask); @@ -298,6 +367,258 @@ void post_process::ctrl(camera* cam) { reset_exposure = true; } +void post_process::draw_lens_flare(camera* cam) { + static float_t flt_1411ACB84 = sinf(0.01365909819f); + static float_t flt_1411ACB8C = tanf(0.01365909819f) * 2.0f * 0.94f; + + if (!lens_flare_texture) + return; + + GLuint tex = obj_database_get_obj_set_texture(5, 4549); + if (tex == -1) + return; + + float_t v5 = tanf((float_t)(cam->get_fov() * DEG_TO_RAD) * 0.5f); + light_set* set = &rctx_ptr->light_set[LIGHT_SET_MAIN]; + light_data* data = &set->lights[LIGHT_SUN]; + + vec3 position; + vec4 v51; + if (data->get_type() == LIGHT_PARALLEL) { + data->get_position(position); + data->get_diffuse(v51); + } + else { + set->lights[LIGHT_STAGE].get_position(position); + position = vec3::normalize(position) * 500.0f; + set->lights[LIGHT_STAGE].get_ibl_specular(v51); + data->set_type(LIGHT_PARALLEL); + data->set_position(position); + data->set_diffuse(v51); + } + + vec4 v44; + *(vec3*)&v44 = position; + v44.w = 1.0f; + + mat4_mult_vec(&cam->view_projection, &v44, &v44); + + float_t v13 = 1.0f / v44.w; + float_t v14 = v44.x * v13; + float_t v15 = v44.y * v13; + float_t v16 = (float_t)render_width * 0.01f / (float_t)render_height; + v14 = clamp_def(v14, -0.99f, 0.99f); + v15 = clamp_def(v15, v16 - 1.0f, 1.0f - v16); + v44.x = v14 * v44.w; + v44.y = v15 * v44.w; + + mat4_mult_vec(&cam->inv_view_projection, &v44, &v44); + ((pos_scale*)&lens_flare_pos)->get_screen_pos_scale(cam->view_projection, position, false); + + float_t v17 = lens_flare_pos.x - (float_t)render_width * 0.5f; + float_t v19 = v5 / (float_t)render_height * 0.5f; + float_t v20 = lens_flare_pos.y - (float_t)render_height * 0.5f; + + float_t v22 = sqrtf(v17 * v19 * v17 * v19 + v20 * v19 * v20 * v19 + 1.0f); + float_t v23 = ((float_t)render_width * (flt_1411ACB8C / v5)) * (v22 * v22 * 0.5f) + * ((float_t)render_height * (flt_1411ACB8C / v5)); + float_t v24 = vec3::distance(position, view_point) * flt_1411ACB84; + v51 *= 1.0f / (float_t)(1.0f - cosf((float_t)(3.0 * DEG_TO_RAD))); + + shaders_ft.state_material_set_emission(false, v51); + gl_state_active_bind_texture_2d(0, tex); + shaders_ft.set(SHADER_FT_SUN); + gl_state_bind_vertex_array(query_vao); + + int32_t query_index = (lens_flare_query_index + 1) % 3; + lens_flare_query_index = query_index; + int32_t next_query_index = (query_index + 2) % 3; + + if (lens_shaft_query_data[next_query_index] == -1) + lens_shaft_query_data[next_query_index] = 0; + + if (lens_flare_query_data[next_query_index] == -1) + lens_flare_query_data[next_query_index] = 0; + + gl_state_set_color_mask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); + gl_state_set_depth_mask(GL_FALSE); + gl_state_disable_cull_face(); + + mat4 mat; + mat4_translate_mult(&cam->view, &position, &mat); + mat4_clear_rot(&mat, &mat); + mat4_scale_rot(&mat, v24 * 0.2f, &mat); + + glBeginQuery(GL_SAMPLES_PASSED, lens_shaft_query[next_query_index]); + shaders_ft.state_matrix_set_modelview(mat, true); + shaders_ft.draw_arrays(GL_TRIANGLE_STRIP, 0, 4); + glEndQuery(GL_SAMPLES_PASSED); + + mat4_translate_mult(&cam->view, (vec3*)&v44, &mat); + mat4_clear_rot(&mat, &mat); + mat4_scale_rot(&mat, v24 * 2.0f, &mat); + + glBeginQuery(GL_SAMPLES_PASSED, lens_flare_query[next_query_index]); + shaders_ft.state_matrix_set_modelview(mat, true); + shaders_ft.draw_arrays(GL_TRIANGLE_STRIP, 0, 4); + glEndQuery(GL_SAMPLES_PASSED); + + gl_state_set_color_mask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + gl_state_set_depth_mask(GL_TRUE); + gl_state_enable_cull_face(); + + if (lens_shaft_query_data[query_index] != -1) { + int32_t res = 0; + glGetQueryObjectiv(lens_shaft_query[query_index], GL_QUERY_RESULT_AVAILABLE, &res); + if (res) + glGetQueryObjectuiv(lens_shaft_query[query_index], GL_QUERY_RESULT, &lens_shaft_query_data[query_index]); + } + + if (lens_flare_query_data[query_index] != -1) { + int32_t res = 0; + glGetQueryObjectiv(lens_flare_query[query_index], GL_QUERY_RESULT_AVAILABLE, &res); + if (res) + glGetQueryObjectuiv(lens_flare_query[query_index], GL_QUERY_RESULT, &lens_flare_query_data[query_index]); + } + + if (v51.y + v51.x + v51.z > 0.0f) { + gl_state_enable_blend(); + gl_state_set_blend_func(GL_ONE, GL_ONE); + gl_state_set_depth_mask(GL_FALSE); + + mat4_translate_mult(&cam->view, &position, &mat); + mat4_clear_rot(&mat, &mat); + mat4_scale_rot(&mat, v24 * 1.1f, &mat); + + shaders_ft.state_matrix_set_modelview(mat, true); + shaders_ft.draw_arrays(GL_TRIANGLE_STRIP, 0, 4); + + gl_state_disable_blend(); + gl_state_set_blend_func(GL_ONE, GL_ZERO); + gl_state_set_depth_mask(GL_TRUE); + } + + gl_state_active_bind_texture_2d(0, 0); + gl_state_bind_vertex_array(0); + + if (lens_flare_appear_power <= 0.01f) + lens_flare_appear_power = 0.0; + else + lens_flare_appear_power *= 0.93f; + lens_shaft_scale = 100.0f; + lens_flare_power = 0.0f; + + float_t v34 = lens_flare_pos.x; + float_t v35 = lens_flare_pos.y; + float_t v32 = lens_flare_pos.z; + + float_t v33 = 0.0f; + if (v32 >= 0.0f + || v34 < (float_t)-render_width || v34 > (float_t)(2 * render_width) + || v35 < (float_t)-render_height || v35 > (float_t)(2 * render_height)) + lens_flare_texture = 0; + else { + for (GLuint& i : lens_flare_query_data) + if (i != -1) + v33 += min_def((float_t)i, v23); + v33 /= (v23 * 3.0f); + lens_flare_power = powf(v33, 0.7f); + + if (v33 > 0.0f && lens_shaft_query_data[query_index]) { + float_t v41 = max_def(v33 - 0.4f, 0.005f); + lens_shaft_scale = ((0.6f / v41) * lens_shaft_inv_scale) * (v5 * 3.4f); + } + } + + if (v32 >= 0.0f + || v34 < -12.0f || v34 > (float_t)(render_width + 12) + || v35 < -12.0f || v35 > (float_t)(render_height + 12)) { + field_A10 = 0.0f; + } + else if (v34 > -2.0f && v34 < (float_t)(render_width + 2) + && v35 > -2.0f && v35 < (float_t)(render_height + 2)) { + if (v33 > 0.4f && field_A10 == 0.0f && lens_flare_appear_power < 0.02f && !reset_exposure) + lens_flare_appear_power = 8.0f; + field_A10 = 1.0f; + } +} + +void post_process::draw_lens_ghost(render_texture* rt) { + static const float_t v13[16] = { + -0.70f, -0.30f, 0.35f, 0.50f, + -0.45f, -0.80f, 0.20f, 0.41f, + 0.17f, -0.10f, 0.06f, 0.10f, + 0.14f, 0.04f, -0.13f, -0.22f, + }; + + static const float_t v14[16] = { + 0.8f, 1.0f, 1.0f, 1.0f, + 0.4f, 0.5f, 0.8f, 0.8f, + 0.6f, 0.7f, 0.8f, 0.7f, + 0.8f, 0.7f, 0.6f, 0.8f, + }; + + static const float_t v15[16] = { + 1.3f, 1.5f, 1.00f, 1.1f, + 2.5f, 0.8f, 0.50f, 0.5f, + 0.7f, 0.4f, 0.35f, 0.5f, + 0.4f, 0.3f, 0.60f, 0.4f, + }; + + if (!lens_flare_texture || lens_ghost_count <= 0) + return; + + if (lens_ghost_count > 16) + lens_ghost_count = 16; + + const float_t aspect = (float_t)render_width / (float_t)render_height; + + const float_t v7 = (lens_flare_pos.x - (float_t)(render_width / 2)) / (float_t)render_width; + const float_t v8 = -((lens_flare_pos.y - (float_t)(render_height / 2)) / (float_t)render_height); + const float_t v9 = (float_t)((1.1 - sqrtf(v8 * v8 + v7 * v7)) * lens_flare_power); + if (v9 < 0.001f) + return; + + const float_t v9a = v9 * v9; + + float_t angle = atan2f(v8, v7) - (float_t)M_PI_2; + const float_t angle_sin = sinf(angle); + const float_t angle_cos = cosf(angle); + + glViewport(0, 0, rt->color_texture->width, rt->color_texture->height); + rt->bind(); + gl_state_enable_blend(); + gl_state_set_blend_func(GL_ONE, GL_ONE); + uniform_value[U_REDUCE] = 4; + shaders_ft.set(SHADER_FT_REDUCE); + + mat4 proj; + mat4_ortho(0.0, 1.0, 0.0, 1.0, 0.0, 1.0, &proj); + shaders_ft.state_matrix_set_projection(proj, false); + + gl_state_active_bind_texture_2d(0, lens_ghost_texture); + + gl_state_bind_vertex_array(lens_ghost_vao); + const float_t lens_ghost = tone_map->data.lens_ghost; + const int32_t lens_ghost_count = this->lens_ghost_count; + for (int32_t i = 0; i < lens_ghost_count; i++) { + shaders_ft.local_frag_set(3, 0.0f, 0.0f, 0.0f, v9 * v14[i] * lens_ghost); + + float_t scale = (v9a * 0.03f + 0.02f) * v15[i]; + + mat4 mat; + mat4_translate(v13[i] * v7 + 0.5f, v13[i] * v8 + 0.5f, 0.0f, &mat); + mat4_scale_rot(&mat, scale, scale * aspect, 1.0f, &mat); + mat4_rotate_z_mult_sin_cos(&mat, angle_sin, angle_cos, &mat); + shaders_ft.state_matrix_set_modelview(mat, true); + shaders_ft.draw_arrays(GL_TRIANGLE_STRIP, i % 4 * 4, 4); + } + gl_state_bind_vertex_array(0); + + gl_state_disable_blend(); + gl_state_set_blend_func(GL_ONE, GL_ZERO); +} + void post_process::draw_query_samples(GLuint query, float_t scale, mat4& mat) { glBeginQuery(GL_SAMPLES_PASSED, query); gl_state_bind_vertex_array(query_vao); diff --git a/src/CRE/post_process.hpp b/src/CRE/post_process.hpp index 7dc87ebc..7cdca910 100644 --- a/src/CRE/post_process.hpp +++ b/src/CRE/post_process.hpp @@ -52,12 +52,19 @@ struct post_process { shader_glsl query_shader; GLuint query_vao; GLuint query_vbo; + GLuint lens_ghost_vao; + GLuint lens_ghost_vbo; shader_glsl alpha_layer_shader; int32_t texture_counter; + GLuint lens_shaft_query[3]; + GLuint lens_flare_query[3]; + GLuint lens_shaft_query_data[3]; + GLuint lens_flare_query_data[3]; + int32_t lens_flare_query_index; GLuint lens_flare_texture; GLuint lens_shaft_texture; GLuint lens_ghost_texture; - int32_t lens_flare_count; + int32_t lens_ghost_count; vec3 lens_flare_pos; float_t lens_shaft_scale; float_t lens_shaft_inv_scale; @@ -86,6 +93,8 @@ struct post_process { void apply(camera* cam, texture* light_proj_tex, int32_t npr_param); void ctrl(camera* cam); + void draw_lens_flare(camera* cam); + void draw_lens_ghost(render_texture* rt); void draw_query_samples(GLuint query, float_t scale, mat4& mat); void init_fbo(int32_t render_width, int32_t render_height, int32_t sprite_width, int32_t sprite_height, int32_t screen_width, int32_t screen_height); diff --git a/src/CRE/post_process/aa.cpp b/src/CRE/post_process/aa.cpp index 29370f85..db600efa 100644 --- a/src/CRE/post_process/aa.cpp +++ b/src/CRE/post_process/aa.cpp @@ -9,30 +9,28 @@ #include "../post_process.hpp" #include "../shader_ft.hpp" -static void post_process_aa_calculate_area_texture_data(uint8_t* a1, int32_t a2, int32_t a3); -static void post_process_aa_calculate_area_texture_data_sub(float_t* a1, - float_t* a2, int32_t a3, int32_t a4, int32_t a5, int32_t a6); -static float_t post_process_aa_calculate_area_texture_data_sub_sub(int32_t a1, int32_t a2); +static void post_process_aa_generate_area_texture(post_process_aa* aa); +static void post_process_aa_calculate_area_texture_data(uint8_t* data, int32_t cross1, int32_t cross2); +static void post_process_aa_calculate_area_texture_data_area(float_t* val_left, + float_t* val_right, int32_t cross1, int32_t cross2, int32_t dleft, int32_t dright); +static float_t calc_area_tex_val(int32_t a1, int32_t a2); +#define MAX_EDGE_DETECTION_LEN (3) +#define GRID_SIDE_LEN (2 * MAX_EDGE_DETECTION_LEN + 1) +#define SIDE_LEN (5 * GRID_SIDE_LEN) post_process_aa::post_process_aa() : width(), height(), mlaa_area_texture() { - uint8_t pixels[35 * 35 * 2]; - for (int32_t i = 0; i < 5; i++) - for (int32_t j = 0; j < 5; j++) - post_process_aa_calculate_area_texture_data(pixels, j, i); - - glGenTextures(1, &mlaa_area_texture); - gl_state_bind_texture_2d(mlaa_area_texture); - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RG8, 35, 35, 0, GL_RG, GL_UNSIGNED_BYTE, pixels); - gl_state_bind_texture_2d(0); + post_process_aa_generate_area_texture(this); } post_process_aa::~post_process_aa() { if (!this) return; - glDeleteTextures(1, &mlaa_area_texture); + if (mlaa_area_texture) { + glDeleteTextures(1, &mlaa_area_texture); + mlaa_area_texture = 0; + } } void post_process_aa::apply_mlaa(render_texture* rt, @@ -54,7 +52,7 @@ void post_process_aa::apply_mlaa(render_texture* rt, //uniform_value[U_MLAA_SEARCH] = 2; //uniform_value[U_MLAA] = 1; //shaders_ft.set(SHADER_FT_MLAA); - uniform_value[U_MLAA_SEARCH] = 2; + uniform_value[U_MLAA_SEARCH] = 4; shaders_ft.set(SHADER_FT_MLAA_AREA); render_texture::draw_params(&shaders_ft, width, height); @@ -88,172 +86,211 @@ void post_process_aa::init_fbo(int32_t width, int32_t height) { mlaa_buffer[1].init(this->width, this->height, 0, GL_RGBA8, 0); } -static void post_process_aa_calculate_area_texture_data(uint8_t* a1, int32_t a2, int32_t a3) { - uint8_t* v7 = &a1[7 * 7 * 10 * a3 + 14 * a2]; - for (int32_t i = 0; i < 7; i++) { - for (int32_t j = 0; j < 7; j++) { - float_t v11 = 0.0f; - float_t v12 = 0.0f; - post_process_aa_calculate_area_texture_data_sub(&v11, &v12, a2, a3, j, i); - v7[0] = (uint8_t)(v11 * 255.89999f); - v7[1] = (uint8_t)(v12 * 255.89999f); - v7 += 2; +static void post_process_aa_generate_area_texture(post_process_aa* aa) { + if (aa->mlaa_area_texture) { + glDeleteTextures(1, &aa->mlaa_area_texture); + aa->mlaa_area_texture = 0; + } + + uint8_t* data = (uint8_t*)malloc(SIDE_LEN * SIDE_LEN * 2); + if (!data) + return; + + for (int32_t cross2 = 0; cross2 < 5; cross2++) + for (int32_t cross1 = 0; cross1 < 5; cross1++) + post_process_aa_calculate_area_texture_data(data, cross1, cross2); + + glGenTextures(1, &aa->mlaa_area_texture); + gl_state_bind_texture_2d(aa->mlaa_area_texture); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RG8, SIDE_LEN, SIDE_LEN, 0, GL_RG, GL_UNSIGNED_BYTE, data); + gl_state_bind_texture_2d(0); + free(data); +} + +static void post_process_aa_calculate_area_texture_data(uint8_t* data, int32_t cross1, int32_t cross2) { + uint8_t* _data = &data[(SIDE_LEN * GRID_SIDE_LEN * cross2 + GRID_SIDE_LEN * cross1) * 2]; + for (int32_t dright = 0; dright < GRID_SIDE_LEN; dright++) { + for (int32_t dleft = 0; dleft < GRID_SIDE_LEN; dleft++) { + float_t val_left = 0.0f; + float_t val_right = 0.0f; + post_process_aa_calculate_area_texture_data_area(&val_left, &val_right, cross1, cross2, dleft, dright); + _data[0] = (uint8_t)(val_left * 255.9f); + _data[1] = (uint8_t)(val_right * 255.9f); + _data += 2; } - v7 += 28 * 2; + _data += GRID_SIDE_LEN * 4 * 2; } } -static void post_process_aa_calculate_area_texture_data_sub(float_t* a2, - float_t* a3, int32_t a4, int32_t a5, int32_t a6, int32_t a7) { - float_t v8 = 0.0f; - float_t v10 = 0.0f; - int32_t v11 = a6 + a7 + 1; - v11 = min_def(v11, 7); - int32_t v12; - if (((a6 + a7 + 1) & 1) != 0) - v12 = (a6 + a7) / 2 + 1; - else - v12 = (a6 + a7 + 1) / 2; - - float_t v14; - int32_t v15; - switch (a5) { +static void post_process_aa_calculate_area_texture_data_area(float_t* val_left, + float_t* val_right, int32_t cross1, int32_t cross2, int32_t dleft, int32_t dright) { + int32_t dist = dleft + dright + 1; + float_t _val_left = 0.0f; + float_t _val_right = 0.0f; + switch (cross2) { case 0: - if (a4 == 1) - v10 = post_process_aa_calculate_area_texture_data_sub_sub(a6, v11); - else if (a4 == 3) - v8 = post_process_aa_calculate_area_texture_data_sub_sub(a6, v11); + switch (cross1) { + case 1: + _val_right = calc_area_tex_val(dleft, min_def(dist, GRID_SIDE_LEN)); + break; + case 3: + _val_left = calc_area_tex_val(dleft, min_def(dist, GRID_SIDE_LEN)); + break; + } break; case 1: - if (a4 == 0) - v10 = post_process_aa_calculate_area_texture_data_sub_sub(a7, v11); - else if (a4 == 1) { - if (((a6 + a7 + 1) & 1) == 0) { - v14 = -0.5f / (float_t)v12; - if (a6 >= v12) - v10 = ((float_t)(a7 * 2 + 1) * v14 + 1.0f) * 0.5f; + switch (cross1) { + case 0: + _val_right = calc_area_tex_val(dright, min_def(dist, GRID_SIDE_LEN)); + break; + case 1: + if (dist % 2) { + int32_t v12 = dist / 2 + 1; + int32_t v15 = dist / 2; + if (dleft < v15) + _val_right = calc_area_tex_val(dleft, v12); + else if (dright < v15) + _val_right = calc_area_tex_val(dright, v12); else - v10 = ((float_t)(a6 * 2 + 1) * v14 + 1.0f) * 0.5f; + _val_right = calc_area_tex_val(v15, v12) * 2.0f; } else { - v15 = v12 - 1; - if (a6 < v15) - v10 = post_process_aa_calculate_area_texture_data_sub_sub(a6, v12); - else if (a7 < v15) - v10 = post_process_aa_calculate_area_texture_data_sub_sub(a7, v12); + int32_t v12 = dist / 2; + float_t v14 = -0.5f / (float_t)v12; + if (dleft >= v12) + _val_right = ((float_t)(dright * 2 + 1) * v14 + 1.0f) * 0.5f; else - v10 = post_process_aa_calculate_area_texture_data_sub_sub(v15, v12) * 2.0f; + _val_right = ((float_t)(dleft * 2 + 1) * v14 + 1.0f) * 0.5f; } - } - else if (a4 == 3 || a4 == 4) { - if (((a6 + a7 + 1) & 1) == 0) { - v14 = -0.5f / (float_t)v12; - if (a6 < v12) - v8 = ((float_t)(a6 * 2 + 1) * v14 + 1.0f) * 0.5f; + break; + case 3: + case 4: + if (dist % 2) { + int32_t v12 = dist / 2 + 1; + int32_t v15 = dist / 2; + if (dleft < v15) + _val_left = calc_area_tex_val(dleft, v12); + else if (dright < v15) + _val_right = calc_area_tex_val(dright, v12); else - v10 = ((float_t)(a7 * 2 + 1) * v14 + 1.0f) * 0.5f; + _val_left = _val_right = calc_area_tex_val(v15, v12); } else { - v15 = v12 - 1; - if (a6 < v15) - v8 = post_process_aa_calculate_area_texture_data_sub_sub(a6, v12); - else if (a7 < v15) - v10 = post_process_aa_calculate_area_texture_data_sub_sub(a7, v12); + int32_t v12 = dist / 2; + float_t v14 = -0.5f / (float_t)v12; + if (dleft < v12) + _val_left = ((float_t)(dleft * 2 + 1) * v14 + 1.0f) * 0.5f; else - v8 = v10 = post_process_aa_calculate_area_texture_data_sub_sub(v15, v12); + _val_right = ((float_t)(dright * 2 + 1) * v14 + 1.0f) * 0.5f; } + break; } break; case 3: - if (a4 == 0) - v8 = post_process_aa_calculate_area_texture_data_sub_sub(a7, v11); - else if (a4 == 1 || a4 == 4) { - if (((a6 + a7 + 1) & 1) == 0) { - v14 = -0.5f / (float_t)v12; - if (a6 < v12) - v10 = ((float_t)(a6 * 2 + 1) * v14 + 1.0f) * 0.5f; + switch (cross1) { + case 0: + _val_left = calc_area_tex_val(dright, min_def(dist, GRID_SIDE_LEN)); + break; + case 1: + case 4: + if (dist % 2) { + int32_t v12 = dist / 2 + 1; + int32_t v15 = dist / 2; + if (dleft < v15) + _val_right = calc_area_tex_val(dleft, v12); + else if (dright < v15) + _val_left = calc_area_tex_val(dright, v12); else - v8 = ((float_t)(a7 * 2 + 1) * v14 + 1.0f) * 0.5f; + _val_left = _val_right = calc_area_tex_val(v15, v12); } else { - v15 = v12 - 1; - if (a6 < v15) - v10 = post_process_aa_calculate_area_texture_data_sub_sub(a6, v12); - else if (a7 < v15) - v8 = post_process_aa_calculate_area_texture_data_sub_sub(a7, v12); + int32_t v12 = dist / 2; + float_t v14 = -0.5f / (float_t)v12; + if (dleft < v12) + _val_right = ((float_t)(dleft * 2 + 1) * v14 + 1.0f) * 0.5f; else - v8 = v10 = post_process_aa_calculate_area_texture_data_sub_sub(v15, v12); + _val_left = ((float_t)(dright * 2 + 1) * v14 + 1.0f) * 0.5f; } - } - else if (a4 == 3) { - if (((a6 + a7 + 1) & 1) == 0) { - v14 = -0.5f / (float_t)v12; - if (a6 < v12) - v8 = ((float_t)(a6 * 2 + 1) * v14 + 1.0f) * 0.5f; + break; + case 3: + if (dist % 2){ + int32_t v12 = dist / 2 + 1; + int32_t v15 = dist / 2; + if (dleft < v15) + _val_left = calc_area_tex_val(dleft, v12); + else if (dright < v15) + _val_left = calc_area_tex_val(dright, v12); else - v8 = ((float_t)(a7 * 2 + 1) * v14 + 1.0f) * 0.5f; + _val_left = calc_area_tex_val(v15, v12) * 2.0f; } - else { - v15 = v12 - 1; - if (a6 < v15) - v8 = post_process_aa_calculate_area_texture_data_sub_sub(a6, v12); - else if (a7 < v15) - v8 = post_process_aa_calculate_area_texture_data_sub_sub(a7, v12); + else { + int32_t v12 = dist / 2; + float_t v14 = -0.5f / (float_t)v12; + if (dleft < v12) + _val_left = ((float_t)(dleft * 2 + 1) * v14 + 1.0f) * 0.5f; else - v8 = post_process_aa_calculate_area_texture_data_sub_sub(v15, v12) * 2.0f; + _val_left = ((float_t)(dright * 2 + 1) * v14 + 1.0f) * 0.5f; } + break; } break; case 4: - if (a4 == 1) { - if (((a6 + a7 + 1) & 1) == 0) { - v14 = -0.5f / (float_t)v12; - if (a6 < v12) - v10 = ((float_t)(a6 * 2 + 1) * v14 + 1.0f) * 0.5f; + switch (cross1) { + case 1: + if (dist % 2) { + int32_t v12 = dist / 2 + 1; + int32_t v15 = dist / 2; + if (dleft < v15) + _val_right = calc_area_tex_val(dleft, v12); + else if (dright < v15) + _val_left = calc_area_tex_val(dright, v12); else - v8 = ((float_t)(a7 * 2 + 1) * v14 + 1.0f) * 0.5f; + _val_left = _val_right = calc_area_tex_val(v15, v12); } else { - v15 = v12 - 1; - if (a6 < v15) - v10 = post_process_aa_calculate_area_texture_data_sub_sub(a6, v12); - else if (a7 < v15) - v8 = post_process_aa_calculate_area_texture_data_sub_sub(a7, v12); + int32_t v12 = dist / 2; + float_t v14 = -0.5f / (float_t)v12; + if (dleft < v12) + _val_right = ((float_t)(dleft * 2 + 1) * v14 + 1.0f) * 0.5f; else - v8 = v10 = post_process_aa_calculate_area_texture_data_sub_sub(v15, v12); + _val_left = ((float_t)(dright * 2 + 1) * v14 + 1.0f) * 0.5f; } - } - else if (a4 == 3) { - if (((a6 + a7 + 1) & 1) == 0) { - v14 = -0.5f / (float_t)v12; - if (a6 < v12) - v8 = ((float_t)(a6 * 2 + 1) * v14 + 1.0f) * 0.5f; + break; + case 3: + if (dist % 2) { + int32_t v12 = dist / 2 + 1; + int32_t v15 = dist / 2; + if (dleft < v15) + _val_left = calc_area_tex_val(dleft, v12); + else if (dright < v15) + _val_right = calc_area_tex_val(dright, v12); else - v10 = ((float_t)(a7 * 2 + 1) * v14 + 1.0f) * 0.5f; + _val_left = _val_right = calc_area_tex_val(v15, v12); } else { - v15 = v12 - 1; - if (a6 < v15) - v8 = post_process_aa_calculate_area_texture_data_sub_sub(a6, v12); - else if (a7 < v15) - v10 = post_process_aa_calculate_area_texture_data_sub_sub(a7, v12); + int32_t v12 = dist / 2; + float_t v14 = -0.5f / (float_t)v12; + if (dleft < v12) + _val_left = ((float_t)(dleft * 2 + 1) * v14 + 1.0f) * 0.5f; else - v8 = v10 = post_process_aa_calculate_area_texture_data_sub_sub(v15, v12); + _val_right = ((float_t)(dright * 2 + 1) * v14 + 1.0f) * 0.5f; } + break; } break; } - *a2 = v8; - *a3 = v10; + *val_left = _val_left; + *val_right = _val_right; return; } -static float_t post_process_aa_calculate_area_texture_data_sub_sub(int32_t a1, int32_t a2) { - float_t v2 = -0.5f / ((float_t)a2 - 0.5f); +static float_t calc_area_tex_val(int32_t a1, int32_t a2) { + float_t v2 = (float_t)(-0.5 / ((float_t)a2 - 0.5)); float_t v3 = (float_t)a1 * v2 + 0.5f; if (a1 >= a2 - 1) return (v3 * 0.5f) * 0.5f; else - return ((float_t)(a1 + 1) * v2 + v3 + 0.5f) * 0.5f; + return ((float_t)(a1 + 1) * v2 + 0.5f + v3) * 0.5f; } diff --git a/src/CRE/post_process/dof.cpp b/src/CRE/post_process/dof.cpp index 60a73f0e..53bedc9e 100644 --- a/src/CRE/post_process/dof.cpp +++ b/src/CRE/post_process/dof.cpp @@ -30,7 +30,7 @@ static const char* dof_vert_shader = static const char* dof_frag_shader_version = "#version 430 core\n"; -static const char* dof_frag_shader_render_tiles_part_2 = +static const char* dof_frag_shader_render_tile_part_2 = "#version 430 core\n" "layout(binding = 0) uniform sampler2D g_tile; //r=min_depth_m, g=max_coc_pixel\n" "\n" @@ -150,7 +150,7 @@ static const char* dof_frag_shader_shared = "}\n" "\n"; -static const char* dof_frag_shader_render_tiles_part_1 = +static const char* dof_frag_shader_render_tile_part_1 = "layout(binding = 0) uniform sampler2D g_depth;\n" "\n" "layout(location = 0) out vec4 result; //r=min_depth_m, g=max_coc_pixel\n" @@ -610,7 +610,7 @@ namespace renderer { GLuint depth_texture, float_t min_distance, float_t max_distance, float_t focus, float_t focal_length, float_t fov, float_t f_number); - static void render_tiles(post_process_dof* dof, + static void render_tile(post_process_dof* dof, GLuint* samplers, GLuint depth_texture, bool f2); static void downsample(post_process_dof* dof, GLuint* samplers, GLuint color_texture, GLuint depth_texture, bool f2); @@ -663,7 +663,7 @@ void post_process_dof::apply(render_texture* rt, render_texture* buf, GLuint* sa rob_chara* rob_chr = 0; for (int32_t i = 0; i < ROB_CHARA_COUNT; i++) { rob_chara* rob_chr = rob_chara_array_get(i); - if (!rob_chr->get_visibility()) + if (!rob_chr->is_visible()) continue; mat4 mat; @@ -852,7 +852,7 @@ static void post_process_dof_free_fbo(post_process_dof* dof) { static void post_process_dof_load_shaders(post_process_dof* dof) { char* frag_shader_string[9]; - frag_shader_string[0] = str_utils_copy(dof_frag_shader_render_tiles_part_2); + frag_shader_string[0] = str_utils_copy(dof_frag_shader_render_tile_part_2); for (int32_t i = 0; i < 2; i++) { char* t0; char* t1; @@ -861,7 +861,7 @@ static void post_process_dof_load_shaders(post_process_dof* dof) { t0 = str_utils_copy(dof_frag_shader_version); t1 = str_utils_add(t0, shared); - frag_shader_string[1 + i * 4] = str_utils_add(t1, dof_frag_shader_render_tiles_part_1); + frag_shader_string[1 + i * 4] = str_utils_add(t1, dof_frag_shader_render_tile_part_1); free_def(t0); free_def(t1); @@ -952,7 +952,7 @@ namespace renderer { fov, focus, 0.0f, 1.0f, focus_range, fuzzing_range, ratio); gl_state_bind_vertex_array(dof->vao); - render_tiles(dof, samplers, depth_texture, true); + render_tile(dof, samplers, depth_texture, true); downsample(dof, samplers, color_texture, depth_texture, true); apply_main_filter(dof, samplers, true); upsample(dof, rt, buf, samplers, color_texture, depth_texture, true); @@ -976,7 +976,7 @@ namespace renderer { fov, focus, focal_length, f_number, 0.0f, 0.1f, 0.0f); gl_state_bind_vertex_array(dof->vao); - render_tiles(dof, samplers, depth_texture, false); + render_tile(dof, samplers, depth_texture, false); downsample(dof, samplers, color_texture, depth_texture, false); apply_main_filter(dof, samplers, false); upsample(dof, rt, buf, samplers, color_texture, depth_texture, false); @@ -989,7 +989,7 @@ namespace renderer { gl_state_bind_vertex_array(0); } - void DOF3::render_tiles(post_process_dof* dof, + void DOF3::render_tile(post_process_dof* dof, GLuint* samplers, GLuint depth_texture, bool f2) { gl_state_bind_framebuffer(dof->fbo[0].buffer); glViewport(0, 0, dof->fbo[0].width, dof->fbo[0].height); diff --git a/src/CRE/post_process/exposure.cpp b/src/CRE/post_process/exposure.cpp index 7839c0d1..ea4d6a1a 100644 --- a/src/CRE/post_process/exposure.cpp +++ b/src/CRE/post_process/exposure.cpp @@ -46,7 +46,7 @@ void post_process_exposure::get_exposure(camera* cam, int32_t render_width, float_t v20 = powf(tanf((float_t)(cam->fov_rad * 0.5f)) * 3.4f, 2.0f); for (int32_t i = 0; i < ROB_CHARA_COUNT; i++, v6++) { rob_chara* rob_chr = rob_chara_array_get(i); - if (!rob_chr || !rob_chr->get_visibility()) + if (!rob_chr || !rob_chr->is_visible()) continue; vec4 v34 = { 0.05f, 0.0f, -0.04f, 1.0f }; @@ -176,20 +176,22 @@ void post_process_exposure::get_exposure(camera* cam, int32_t render_width, render_texture::draw_params(&shaders_ft, 1, 1); } -void post_process_exposure::get_exposure_chara_data(void* pp, camera* cam) { +void post_process_exposure::get_exposure_chara_data(void* pp_data, camera* cam) { shader::unbind(); + post_process* pp = (post_process*)pp_data; + gl_state_set_color_mask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); gl_state_set_depth_mask(GL_FALSE); gl_state_disable_cull_face(); - post_process_exposure_chara_data* v3 = chara_data; - int32_t v4 = (query_index + 1) % 3; - query_index = v4; - int32_t v7 = (v4 + 2) % 3; - for (int32_t i = 0; i < ROB_CHARA_COUNT; i++, v3++) { + post_process_exposure_chara_data* chara = chara_data; + int32_t query_index = (this->query_index + 1) % 3; + this->query_index = query_index; + int32_t next_query_index = (query_index + 2) % 3; + for (int32_t i = 0; i < ROB_CHARA_COUNT; i++, chara++) { rob_chara* rob_chr = rob_chara_array_get(i); - if (!rob_chr || !rob_chr->get_visibility()) + if (!rob_chr || !rob_chr->is_visible()) continue; float_t max_face_depth = rob_chr->get_max_face_depth(); @@ -201,18 +203,18 @@ void post_process_exposure::get_exposure_chara_data(void* pp, camera* cam) { mat4_clear_rot(&mat, &mat); mat4_mult(&mat, &cam->projection, &mat); - ((post_process*)pp)->draw_query_samples(v3->query[v7], 0.0035f, mat); + pp->draw_query_samples(chara->query[next_query_index], 0.0035f, mat); - if (v3->query_data[v7] == -1) - v3->query_data[v7] = 0; + if (chara->query_data[next_query_index] == -1) + chara->query_data[next_query_index] = 0; - if (v3->query_data[v4] != -1) { - int32_t v14 = 0; - glGetQueryObjectiv(v3->query[v4], GL_QUERY_RESULT_AVAILABLE, &v14); - if (v14) - glGetQueryObjectuiv(v3->query[v4], GL_QUERY_RESULT, v3->query_data); + if (chara->query_data[query_index] != -1) { + int32_t res = 0; + glGetQueryObjectiv(chara->query[query_index], GL_QUERY_RESULT_AVAILABLE, &res); + if (res) + glGetQueryObjectuiv(chara->query[query_index], GL_QUERY_RESULT, chara->query_data); else - v3->query_data[v4] = 0; + chara->query_data[query_index] = 0; } } diff --git a/src/CRE/post_process/tone_map.cpp b/src/CRE/post_process/tone_map.cpp index 40bc914b..9529e6b7 100644 --- a/src/CRE/post_process/tone_map.cpp +++ b/src/CRE/post_process/tone_map.cpp @@ -31,10 +31,15 @@ post_process_tone_map::~post_process_tone_map() { void post_process_tone_map::apply(render_texture* in_tex, texture* light_proj_tex, texture* back_2d_tex, render_texture* rt, render_texture* buf_rt,/* render_texture* contour_rt,*/ - GLuint in_tex_0, GLuint in_tex_1, int32_t npr_param) { + GLuint in_tex_0, GLuint in_tex_1, int32_t npr_param, void* pp_data) { if (!this) return; + post_process* pp = (post_process*)pp_data; + + set_lens_flare_power(pp->lens_flare_power); + set_lens_flare_appear_power(pp->lens_flare_appear_power); + if (data.update) { post_process_tone_map_calculate_data(this); data.update = false; @@ -55,13 +60,6 @@ void post_process_tone_map::apply(render_texture* in_tex, texture* light_proj_te data.update_tex = false; } - mat4 lens_flare_mat; - mat4 lens_shaft_mat; - mat4_scale(1.0f, (float_t)rt->color_texture->height - / (float_t)rt->color_texture->width, 1.0f, &lens_flare_mat); - mat4_scale(1.0f, (float_t)rt->color_texture->height - / (float_t)rt->color_texture->width, 1.0f, &lens_shaft_mat); - uniform_value[U_TONE_MAP] = (int32_t)data.tone_map_method; uniform_value[U_FLARE] = 0; uniform_value[U_SCENE_FADE] = data.scene_fade.w > 0.009999999f ? 1 : 0; @@ -69,18 +67,6 @@ void post_process_tone_map::apply(render_texture* in_tex, texture* light_proj_te uniform_value[U_LIGHT_PROJ] = 0; //uniform_value[U25] = 0; - glViewport(0, 0, rt->color_texture->width, rt->color_texture->height); - buf_rt->bind(); - shaders_ft.set(SHADER_FT_TONEMAP); - shaders_ft.state_matrix_set_texture(4, lens_flare_mat); - shaders_ft.state_matrix_set_texture(5, lens_shaft_mat); - shaders_ft.local_vert_set(1, shader_data.p_exposure); - shaders_ft.local_frag_set(1, shader_data.p_flare_coef); - shaders_ft.local_frag_set(2, shader_data.p_fade_color); - shaders_ft.local_frag_set(4, shader_data.p_tone_scale); - shaders_ft.local_frag_set(5, shader_data.p_tone_offset); - shaders_ft.local_frag_set(6, shader_data.p_fade_func); - shaders_ft.local_frag_set(7, shader_data.p_inv_tone); gl_state_active_bind_texture_2d(0, in_tex->color_texture->tex); gl_state_active_bind_texture_2d(1, in_tex_0); gl_state_active_bind_texture_2d(2, tone_map); @@ -96,6 +82,45 @@ void post_process_tone_map::apply(render_texture* in_tex, texture* light_proj_te uniform_value[U_LIGHT_PROJ] = 1; } + if (pp->lens_flare_texture) { + static const vec4 border_color = 0.0f; + + const float_t aspect = (float_t)pp->render_height / (float_t)pp->render_width; + + uniform_value[U_FLARE] = 1; + gl_state_active_bind_texture_2d(4, pp->lens_flare_texture); + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, (GLfloat*)&border_color); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); + mat4 mat; + mat4_translate(0.5f, 0.5f, 0.0f, &mat); + mat4_scale_rot(&mat, 0.75f, 0.75f, 1.0f, &mat); + mat4_rotate_z_mult(&mat, (pp->lens_flare_pos.x / (float_t)pp->render_width) + * 25.0f * DEG_TO_RAD_FLOAT, &mat); + mat4_translate_mult(&mat, -((1.0f / (float_t)pp->render_width) * pp->lens_flare_pos.x), + (pp->lens_flare_pos.y - (float_t)pp->render_height) + * (1.0f / (float_t)pp->render_width), 0.0f, &mat); + mat4_scale_rot(&mat, 1.0f, aspect, 1.0f, &mat); + shaders_ft.state_matrix_set_texture(4, mat); + + if (pp->lens_shaft_scale < 50.0f) { + uniform_value[U_FLARE] = 2; + gl_state_active_bind_texture_2d(5, pp->lens_shaft_texture); + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, (GLfloat*)&border_color); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); + mat4_translate(0.5f, 0.5f, 0.0f, &mat); + mat4_scale_rot(&mat, pp->lens_shaft_scale, pp->lens_shaft_scale, 1.0f, &mat); + mat4_rotate_z_mult(&mat, (pp->lens_flare_pos.x / (float_t)pp->render_width) + * 60.0f * DEG_TO_RAD_FLOAT, &mat); + mat4_translate_mult(&mat, -((1.0f / (float_t)pp->render_width) * pp->lens_flare_pos.x), + (pp->lens_flare_pos.y - (float_t)pp->render_height) + * (1.0f / (float_t)pp->render_width), 0.0f, &mat); + mat4_scale_rot(&mat, 1.0f, aspect, 1.0f, &mat); + shaders_ft.state_matrix_set_texture(5, mat); + } + } + if (npr_param == 1) { /*gl_state_active_bind_texture_2d(16, contour_rt->color_texture->tex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); @@ -107,6 +132,17 @@ void post_process_tone_map::apply(render_texture* in_tex, texture* light_proj_te glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); } + + glViewport(0, 0, rt->color_texture->width, rt->color_texture->height); + buf_rt->bind(); + shaders_ft.set(SHADER_FT_TONEMAP); + shaders_ft.local_vert_set(1, shader_data.p_exposure); + shaders_ft.local_frag_set(1, shader_data.p_flare_coef); + shaders_ft.local_frag_set(2, shader_data.p_fade_color); + shaders_ft.local_frag_set(4, shader_data.p_tone_scale); + shaders_ft.local_frag_set(5, shader_data.p_tone_offset); + shaders_ft.local_frag_set(6, shader_data.p_fade_func); + shaders_ft.local_frag_set(7, shader_data.p_inv_tone); render_texture::draw_custom(&shaders_ft); gl_state_active_bind_texture_2d(2, 0); @@ -234,19 +270,41 @@ float_t post_process_tone_map::get_lens_flare() { } void post_process_tone_map::set_lens_flare(float_t value) { - value = clamp_def(value, 0.0f, 1.0f); if (value != data.lens_flare) { data.lens_flare = value; data.update = true; } } +float_t post_process_tone_map::get_lens_flare_appear_power() { + return data.lens_flare_appear_power; +} + +void post_process_tone_map::set_lens_flare_appear_power(float_t value) { + if (value != data.lens_flare_appear_power) { + data.lens_flare_appear_power = value; + data.update = true; + } +} + +float_t post_process_tone_map::get_lens_flare_power() { + return data.lens_flare_power; +} + + +void post_process_tone_map::set_lens_flare_power(float_t value) { + if (value != data.lens_flare_power) { + data.lens_flare_power = value; + data.update = true; + } +} + float_t post_process_tone_map::get_lens_ghost() { return data.lens_ghost; } void post_process_tone_map::set_lens_ghost(float_t value) { - data.lens_ghost = clamp_def(value, 0.0f, 1.0f); + data.lens_ghost = value; } float_t post_process_tone_map::get_lens_shaft() { diff --git a/src/CRE/post_process/tone_map.hpp b/src/CRE/post_process/tone_map.hpp index 1a07e3a0..745c330d 100644 --- a/src/CRE/post_process/tone_map.hpp +++ b/src/CRE/post_process/tone_map.hpp @@ -57,7 +57,7 @@ struct post_process_tone_map { void apply(render_texture* in_tex, texture* light_proj_tex, texture* back_2d_tex, render_texture* rt, render_texture* buf_rt,/* render_texture* contour_rt,*/ - GLuint in_tex_0, GLuint in_tex_1, int32_t npr_param); + GLuint in_tex_0, GLuint in_tex_1, int32_t npr_param, void* pp); void init_fbo(); void initialize_data(float_t exposure, bool auto_exposure, float_t gamma, int32_t saturate_power, float_t saturate_coeff, @@ -78,6 +78,10 @@ struct post_process_tone_map { void set_gamma_rate(float_t value); float_t get_lens_flare(); void set_lens_flare(float_t value); + float_t get_lens_flare_appear_power(); + void set_lens_flare_appear_power(float_t value); + float_t get_lens_flare_power(); + void set_lens_flare_power(float_t value); float_t get_lens_ghost(); void set_lens_ghost(float_t value); float_t get_lens_shaft(); diff --git a/src/CRE/pv_expression.cpp b/src/CRE/pv_expression.cpp index 28000540..6608b0fd 100644 --- a/src/CRE/pv_expression.cpp +++ b/src/CRE/pv_expression.cpp @@ -11,6 +11,19 @@ #include "rob/rob.hpp" #include "render_context.hpp" +struct pv_expression_file { + p_file_handler file_handler; + pv_exp* data; + prj::shared_ptr alloc_handler; + int32_t load_count; + uint32_t hash; + + pv_expression_file(); + ~pv_expression_file(); + + static void load_file(pv_expression_file* handler, const void* data, size_t size); +}; + struct pv_expression { rob_chara* rob_chr; int32_t motion_id; diff --git a/src/CRE/pv_expression.hpp b/src/CRE/pv_expression.hpp index 7d1b9e59..85231688 100644 --- a/src/CRE/pv_expression.hpp +++ b/src/CRE/pv_expression.hpp @@ -9,19 +9,6 @@ #include "../KKdLib/pv_exp.hpp" #include "file_handler.hpp" -struct pv_expression_file { - p_file_handler file_handler; - pv_exp* data; - prj::shared_ptr alloc_handler; - int32_t load_count; - uint32_t hash; - - pv_expression_file(); - ~pv_expression_file(); - - static void load_file(pv_expression_file* handler, const void* data, size_t size); -}; - extern void pv_expression_array_ctrl(void* rob_chr); extern void pv_expression_array_reset(); extern bool pv_expression_array_reset_data(size_t chara_id, void* rob_chr, float_t frame_speed); diff --git a/src/CRE/render_context.hpp b/src/CRE/render_context.hpp index 2637b0d5..9f0ef4ed 100644 --- a/src/CRE/render_context.hpp +++ b/src/CRE/render_context.hpp @@ -407,7 +407,7 @@ struct draw_task_preprocess { }; struct draw_task_object_translucent { - int32_t count; + uint32_t count; draw_object* objects[40]; }; diff --git a/src/CRE/rob/ex_block.cpp b/src/CRE/rob/ex_block.cpp index ca523fe7..59b3d768 100644 --- a/src/CRE/rob/ex_block.cpp +++ b/src/CRE/rob/ex_block.cpp @@ -16,7 +16,7 @@ struct osage_setting { ~osage_setting(); void parse(key_val* kv); - rob_osage_parts parse_parts_string(std::string* s); + rob_osage_parts parse_parts_string(std::string& s); }; struct exp_func_op1 { @@ -74,6 +74,8 @@ static float_t exp_sqrt(float_t v1); static float_t exp_sub(float_t v1, float_t v2); static float_t exp_tan(float_t v1); +static void closest_pt_segment_segment(vec3& vec, const vec3& p0, const vec3& p1, const OsageCollision::Work* cls); + static const osage_setting_osg_cat* osage_setting_data_get_cat_value( object_info* obj_info, const char* root_node); @@ -100,14 +102,6 @@ static void sub_140482180(RobOsageNode* node, float_t a2); static void sub_140482300(vec3* a1, vec3* a2, vec3* a3, float_t osage_gravity_const, float_t weight); static void sub_140482490(RobOsageNode* node, float_t step, float_t a3); static void sub_140482F30(vec3* pos1, vec3* pos2, float_t length); -static int32_t sub_140483B30(vec3* a1, vec3* a2, osage_coli* a3, float_t radius); -static int32_t sub_140483DE0(vec3* a1, vec3* a2, vec3* a3, float_t radius); -static int32_t sub_140483EA0(vec3* a1, vec3* a2, osage_coli* a3, float_t radius); -static int32_t sub_140484540(vec3* a1, vec3* a2, osage_coli* coli, float_t radius); -static int32_t sub_140484780(vec3* a1, vec3* a2, vec3* a3, vec3* a4, float_t radius); -static int32_t sub_140485180(osage_coli* a1, vec3* a2, float_t& coli_r); -static int32_t sub_1404851C0(vec3* a1, float_t& coli_r, std::vector* a3, float_t* a4); -static int32_t sub_140485220(vec3* a1, float_t& coli_r, osage_coli* a3, float_t* a4); static void sub_14047D8C0(RobOsage* rob_osg, mat4* mat, vec3* parent_scale, float_t step, bool a5); static void sub_14047C750(RobOsage* rob_osg, mat4* mat, vec3* parent_scale, float_t step); static void sub_14047C770(RobOsage* rob_osg, mat4* mat, vec3* parent_scale, float_t step, bool a5); @@ -118,12 +112,6 @@ static void sub_140480260(RobOsage* rob_osg, mat4* mat, vec3* parent_scale, floa static void sub_140482100(struc_476* a1, opd_blend_data* a2, struc_477* a3); static void sub_140482DF0(struc_477* dst, struc_477* src0, struc_477* src1, float_t blend); static bool sub_140482FF0(mat4& mat, vec3& trans, skin_param_hinge* hinge, vec3* rot, int32_t& yz_order); -static int32_t sub_140484450(vec3* a1, vec3* a2, vec3* a3, vec3* a4, float_t radius); -static int32_t sub_1404844A0(vec3* a1, vec3* a2, vec3* a3, osage_coli* a4, float_t radius); -static int32_t sub_1404844F0(vec3* a1, vec3* a2, vec3* a3, osage_coli* a4, float_t radius); -static void sub_140484850(vec3* a1, vec3* a2, vec3* a3, osage_coli* coli); -static void sub_140484E10(vec3* a1, vec3* a2, vec3* a3, vec3* a4); -static int32_t sub_140485000(vec3* a1, vec3* a2, skin_param_osage_node* a3, osage_coli* a4); static void sub_14053CE30(RobOsageNodeDataNormalRef* normal_ref, mat4* a2); static bool sub_14053D1B0(vec3* l_trans, vec3* r_trans, vec3* u_trans, vec3* d_trans, vec3* a5, vec3* a6, vec3* a7); @@ -374,8 +362,10 @@ struc_476::struc_476() { } RobOsageNode::RobOsageNode() : length(), trans(), trans_orig(), trans_diff(), field_28(), -child_length(), bone_node_ptr(), bone_node_mat(), sibling_node(), max_distance(), field_94(), -reset_data(), field_C8(), field_CC(1.0f), external_force(), force(1.0f), mat(), field_1B0() { +child_length(), bone_node_ptr(), bone_node_mat(), sibling_node(), max_distance(), +field_94(), reset_data(), field_C8(), external_force(), mat(), field_1B0() { + field_CC = 1.0f; + force = 1.0f; data_ptr = &data; opd_data.resize(3); } @@ -411,12 +401,11 @@ void RobOsageNode::Reset() { mat = mat4_null; } -skin_param_osage_root_coli::skin_param_osage_root_coli() : type(), -bone0_index(), bone1_index(), radius(0.2f), bone0_pos(), bone1_pos() { - +SkinParam::CollisionParam::CollisionParam() : type(), node_idx(), pos() { + radius = 0.2f; } -skin_param_osage_root_coli::~skin_param_osage_root_coli() { +SkinParam::CollisionParam::~CollisionParam() { } @@ -436,9 +425,15 @@ skin_param_osage_root_boc::~skin_param_osage_root_boc() { } -skin_param_osage_root::skin_param_osage_root() : field_0(), force(), force_gain(), air_res(0.5f), -rot_y(), rot_z(), init_rot_y(), init_rot_z(), hinge_y(90.0f), hinge_z(90.0f), name("NO-PARAM"), -coli_r(), friction(1.0f), wind_afc(0.5f), yz_order(), coli_type(), stiffness(), move_cancel(-0.01f) { +skin_param_osage_root::skin_param_osage_root() : field_0(), force(), force_gain(), +rot_y(), rot_z(), init_rot_y(), init_rot_z(), coli_r(), yz_order(), coli_type(), stiffness() { + air_res = 0.5f; + hinge_y = 90.0f; + hinge_z = 90.0f; + name ="NO-PARAM"; + friction = 1.0f; + wind_afc = 0.5f; + move_cancel = -0.01f; coli.resize(13); } @@ -455,61 +450,364 @@ skin_param::~skin_param() { } -osage_coli::osage_coli() : type(), radius(), bone0_pos(), bone1_pos(), -bone_pos_diff(), bone_pos_diff_length(), bone_pos_diff_length_squared(), field_34() { +OsageCollision::Work::Work() : type(), radius(), pos(), +vec_center(), vec_center_length(), vec_center_length_squared(), friction() { } -osage_coli::~osage_coli() { +OsageCollision::Work::~Work() { } +// 0x140484FE0 +int32_t OsageCollision::Work::osage_capsule_cls(vec3& p0, vec3& p1, const float_t& cls_r) { + return OsageCollision::osage_capsule_cls(p0, p1, cls_r, this); +} -void osage_coli::set(osage_coli* coli, skin_param_osage_root_coli* skp_root_coli, mat4* mats) { - coli->type = (skin_param_osage_root_coli_type)0; - if (!skp_root_coli || !mats) +// 0x140485180 +int32_t OsageCollision::Work::osage_cls(vec3& p, const float_t& cls_r) { + return OsageCollision::osage_cls(p, cls_r, this, 0); +} + +void OsageCollision::Work::update_cls_work(OsageCollision::Work* cls, + SkinParam::CollisionParam* cls_param, mat4* transform) { + cls->type = SkinParam::CollisionTypeEnd; + if (!cls_param || !transform) return; - for (; skp_root_coli->type; coli++, skp_root_coli++) { - coli->type = skp_root_coli->type; - coli->radius = skp_root_coli->radius; - mat4_mult_vec3_trans(&mats[skp_root_coli->bone0_index], - &skp_root_coli->bone0_pos, &coli->bone0_pos); - if (skp_root_coli->type == SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_CYLINDER - || skp_root_coli->type == SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_ELLIPSE) { - mat4_mult_vec3_trans(&mats[skp_root_coli->bone1_index], - &skp_root_coli->bone1_pos, &coli->bone1_pos); - vec3_sub(coli->bone1_pos, coli->bone0_pos, coli->bone_pos_diff); - vec3_length_squared(coli->bone_pos_diff, coli->bone_pos_diff_length_squared); - coli->bone_pos_diff_length = sqrtf(coli->bone_pos_diff_length_squared); - if (coli->bone_pos_diff_length < 0.01f) - coli->type = SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_BALL; + for (; cls_param->type; cls++, cls_param++) { + cls->type = cls_param->type; + cls->radius = cls_param->radius; + mat4_mult_vec3_trans(&transform[cls_param->node_idx[0]], + &cls_param->pos[0], &cls->pos[0]); + + switch (cls->type) { + case SkinParam::CollisionTypeBall: + mat4_mult_vec3(&transform[cls_param->node_idx[1]], + &cls_param->pos[1], &cls->pos[1]); + break; + case SkinParam::CollisionTypeCapsulle: + case SkinParam::CollisionTypeEllipse: + mat4_mult_vec3_trans(&transform[cls_param->node_idx[1]], + &cls_param->pos[1], &cls->pos[1]); + cls->vec_center = cls->pos[1] - cls->pos[0]; + cls->vec_center_length_squared = vec3::length_squared(cls->vec_center); + cls->vec_center_length = sqrtf(cls->vec_center_length_squared); + if (cls->vec_center_length < 0.01f) + cls->type = SkinParam::CollisionTypeBall; + break; } - else if (skp_root_coli->type == SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_PLANE) - mat4_mult_vec3(&mats[skp_root_coli->bone0_index], - &skp_root_coli->bone1_pos, &coli->bone1_pos); } - coli->type = (skin_param_osage_root_coli_type)0; + cls->type = SkinParam::CollisionTypeEnd; } -void osage_coli::ring_set(osage_coli* coli, - std::vector& vec_skp_root_coli, mat4* mats) { - if (!vec_skp_root_coli.size()) { - coli->type = (skin_param_osage_root_coli_type)0; - coli->radius = 0.0f; - coli->bone0_pos = 0.0f; - coli->bone1_pos = 0.0f; - coli->bone_pos_diff = 0.0f; - coli->bone_pos_diff_length = 0.0f; - coli->bone_pos_diff_length_squared = 0.0f; - coli->field_34 = 1.0f; +void OsageCollision::Work::update_cls_work(OsageCollision::Work* cls, + std::vector& cls_list, mat4* mats) { + if (cls_list.size()) { + cls->type = SkinParam::CollisionTypeEnd; + cls->radius = 0.0f; + cls->pos[0] = 0.0f; + cls->pos[1] = 0.0f; + cls->vec_center = 0.0f; + cls->vec_center_length = 0.0f; + cls->vec_center_length_squared = 0.0f; + cls->friction = 1.0f; } else - set(coli, vec_skp_root_coli.data(), mats); + update_cls_work(cls, cls_list.data(), mats); } -osage_ring_data::osage_ring_data() : ring_rectangle_x(0.0f), ring_rectangle_y(0.0f), ring_rectangle_width(0.0f), -ring_rectangle_height(0.0f), ring_height(-1000.0f), ring_out_height(-1000.0f), field_18() { +OsageCollision::OsageCollision() { + +} + +OsageCollision::~OsageCollision() { + +} + +// 0x140483B30 +int32_t OsageCollision::cls_aabb_oidashi(vec3& vec, const vec3& p, const OsageCollision::Work* cls, const float_t r) { + vec3 v29; + vec3 v30; + for (int32_t i = 0; i < 3; i++) { + float_t v13 = ((float_t*)&p)[i]; + float_t v14 = ((float_t*)&cls->pos[0])[i] - v13; + ((float_t*)&v30)[i] = v14; + if (v14 > r) + return 0; + + float_t v15 = v13 - (((float_t*)&cls->pos[0])[i] + ((float_t*)&cls->pos[1])[i]); + ((float_t*)&v29)[i] = v15; + if (v15 > r) + return 0; + } + + vec3 v28 = 0.0f; + vec3 v32 = 0.0f; + vec3 v27 = 1.0f; + + float_t v16 = 0.0f; + for (int32_t i = 0; i < 3; i++) { + float_t v18 = ((float_t*)&v30)[i]; + float_t v19 = ((float_t*)&v29)[i]; + if (fabsf(v18) >= fabsf(v19)) { + ((float_t*)&v28)[i] = v19; + ((float_t*)&v27)[i] = 1.0f; + v18 = v19; + } + else { + ((float_t*)&v28)[i] = v18; + ((float_t*)&v27)[i] = -1.0f; + } + + if (v18 > 0.0f) { + float_t v20 = v18 * v18; + ((float_t*)&v32)[i] = v20; + v16 += v20; + } + } + + if (v16 > r * r) + return 0; + + if (v16 > 0.0f) + vec = v27 * v32 * (1.0f / v16) * (r - sqrtf(v16)); + else { + float_t v25 = ((float_t*)&v28)[0]; + int32_t v26 = 0; + for (int32_t i = 0; i < 3; i++) { + if (v25 < ((float_t*)&v28)[i]) { + v25 = ((float_t*)&v28)[i]; + v26 = i; + } + } + ((float_t*)&vec)[v26] -= ((float_t*)&v27)[v26] * (v25 - r); + } + return 1; +} + +// 0x140483DE0 +int32_t OsageCollision::cls_ball_oidashi(vec3& vec, const vec3& p, const vec3& center, const float_t r) { + float_t length = vec3::distance_squared(p, center); + if (length > 0.000001f && length < r * r) { + vec = (p - center) * (r / sqrtf(length) - 1.0f); + return 1; + } + return 0; +} + +// 0x140484540 +int32_t OsageCollision::cls_capsule_oidashi(vec3& vec, const vec3& p, const OsageCollision::Work* cls, const float_t r) { + vec3 v11 = p - cls->pos[0]; + + float_t v17 = vec3::dot(v11, cls->vec_center); + if (v17 < 0.0f) + return OsageCollision::cls_ball_oidashi(vec, p, cls->pos[0], r); + + float_t v19 = cls->vec_center_length_squared; + if (fabsf(v19) <= 0.000001f) + return OsageCollision::cls_ball_oidashi(vec, p, cls->pos[0], r); + if (v17 > v19) + return OsageCollision::cls_ball_oidashi(vec, p, cls->pos[1], r); + + float_t v20 = vec3::length_squared(v11); + float_t v22 = fabsf(v20 - v17 * v17 / v19); + if (v22 <= 0.000001f || v22 >= r * r) + return 0; + + vec = (v11 - cls->vec_center * (v17 / v19)) * (r / sqrtf(v22) - 1.0f); + return 1; +} + +// 0x140483EA0 +int32_t OsageCollision::cls_ellipse_oidashi(vec3& vec, const vec3& p, const OsageCollision::Work* cls, const float_t r) { + if (cls->vec_center_length <= 0.000001f) + return OsageCollision::cls_ball_oidashi(vec, p, cls->pos[0], r); + + float_t v61 = cls->vec_center_length * 0.5f; + float_t v13 = sqrtf(r * r + v61 * v61); + + vec3 v54 = p - cls->pos[0]; + float_t v20 = vec3::length(v54); + + vec3 v57 = p - cls->pos[1]; + float_t v21 = vec3::length(v57); + + if (v20 <= 0.000001f || v21 <= 0.000001f) + return 0; + + if (v20 != 0.0f) + v54 *= 1.0f / v20; + + if (v21 != 0.0f) + v57 *= 1.0f / v21; + + float_t v22 = v20 + v21; + if (v21 + v20 >= v13 * 2.0f) + return 0; + + float_t v25 = 1.0f / cls->vec_center_length; + + vec3 v63 = p - (cls->pos[0] + cls->pos[1]) * 0.5f; + + float_t v58 = vec3::length(v63); + if (v58 != 0.0f) + v63 *= 1.0f / v58; + + float_t v36 = vec3::dot(v63, cls->vec_center) * v25; + float_t v37 = v36 * v36; + v37 = min_def(v37, 1.0f); + v22 *= 0.5f; + float_t v38 = v22 * v22 - v61; + if (v38 < 0.0f) + return 0; + + float_t v39 = sqrtf(v38); + if (v39 <= 0.000001f) + return 0; + + float_t v42 = sqrtf(1.0f - v37); + v22 = (v13 / v22 - 1.0f) * v36 * v58; + v42 = (r / v39 - 1.0f) * v42 * v58; + float_t v43 = sqrtf(v42 * v42 + v22 * v22); + + vec = vec3::normalize(v54 + v57) * v43; + return 1; +} + +// 0x140484450 +int32_t OsageCollision::cls_line2ball_oidashi(vec3& vec, + const vec3& p0, const vec3& p1, const vec3& q, const float_t r) { + vec3 _vec; + OsageCollision::get_nearest_line2point(_vec, p0, p1, q); + return OsageCollision::cls_ball_oidashi(vec, _vec, q, r); +} + +// 0x1404844A0 +int32_t OsageCollision::cls_line2capsule_oidashi(vec3& vec, + const vec3& p0, const vec3& p1, const OsageCollision::Work* cls, const float_t r) { + vec3 _vec; + closest_pt_segment_segment(_vec, p0, p1, cls); + return OsageCollision::cls_capsule_oidashi(vec, _vec, cls, r); +} + +// 0x1404844F0 +int32_t OsageCollision::cls_line2ellipse_oidashi(vec3& vec, + const vec3& p0, const vec3& p1, const OsageCollision::Work* cls, const float_t r) { + vec3 _vec; + closest_pt_segment_segment(_vec, p0, p1, cls); + return OsageCollision::cls_ellipse_oidashi(vec, _vec, cls, r); +} + +// 0x140484780 +int32_t OsageCollision::cls_plane_oidashi(vec3& vec, const vec3& p, const vec3& p1, const vec3& p2, const float_t r) { + float_t v5 = vec3::dot(p, p2) - vec3::dot(p1, p2) - r; + if (v5 >= 0.0f) + return 0; + + vec = p2 * -v5; + return 1; +} + +// 0x140484E10 +void OsageCollision::get_nearest_line2point(vec3& nearest, const vec3& p0, const vec3& p1, const vec3& q) { + vec3 v6 = p1 - p0; + vec3 v7 = q - p0; + + float_t v8 = vec3::dot(v7, v6); + if (v8 < 0.0f) { + nearest = p0; + return; + } + + float_t v9 = vec3::length_squared(v6); + if (v9 <= 0.000001f) + nearest = p0; + else if (v8 <= v9) + nearest = p0 + v6 * (v8 / v9); + else + nearest = p1; +} + +// 0x140485000 +int32_t OsageCollision::osage_capsule_cls(vec3& p0, vec3& p1, const float_t& cls_r, const OsageCollision::Work* cls) { + if (!cls) + return 0; + + int32_t v8 = 0; + while (cls->type) { + int32_t type = cls->type; + vec3 vec = 0.0f; + switch (cls->type) { + case SkinParam::CollisionTypeBall: + v8 += OsageCollision::cls_line2ball_oidashi(vec, p0, p1, cls->pos[0], cls_r + cls->radius); + break; + case SkinParam::CollisionTypeCapsulle: + v8 += OsageCollision::cls_line2capsule_oidashi(vec, p0, p1, cls, cls_r + cls->radius); + break; + case SkinParam::CollisionTypeEllipse: + v8 += OsageCollision::cls_line2ellipse_oidashi(vec, p0, p1, cls, cls_r + cls->radius); + break; + } + + if (v8 > 0) { + p0 += vec; + p1 += vec; + } + cls++; + } + return v8; +} + +// 0x140485220 +int32_t OsageCollision::osage_cls(vec3& p, const float_t& cls_r, const OsageCollision::Work* cls, float_t* fric) { + if (!cls) + return 0; + + int32_t v8 = 0; + while (cls->type != SkinParam::CollisionTypeEnd) { + int32_t v11 = 0; + vec3 vec = 0.0f; + switch (cls->type) { + case SkinParam::CollisionTypeBall: + v11 = OsageCollision::cls_ball_oidashi(vec, p, cls->pos[0], cls->radius + cls_r); + break; + case SkinParam::CollisionTypeCapsulle: + v11 = OsageCollision::cls_capsule_oidashi(vec, p, cls, cls->radius + cls_r); + break; + case SkinParam::CollisionTypePlane: + v11 = OsageCollision::cls_plane_oidashi(vec, p, cls->pos[0], cls->pos[1], cls_r); + break; + case SkinParam::CollisionTypeEllipse: + v11 = OsageCollision::cls_ellipse_oidashi(vec, p, cls, cls->radius + cls_r); + break; + case SkinParam::CollisionTypeAABB: + v11 = OsageCollision::cls_aabb_oidashi(vec, p, cls, cls_r); + break; + } + + if (fric && v11 > 0) { + if (*fric > cls->friction) + *fric = cls->friction; + } + cls++; + v8 += v11; + p += vec; + } + return v8; +} + +// 0x1404851C0 +int32_t OsageCollision::osage_cls_work_list(vec3& p, const float_t& cls_r, const OsageCollision& coli, float_t* fric) { + if (coli.work_list.size() && coli.work_list.back().type != SkinParam::CollisionTypeEnd) + return OsageCollision::osage_cls(p, cls_r, coli.work_list.data(), fric); + return 0; +} + +osage_ring_data::osage_ring_data() : ring_rectangle_x(), ring_rectangle_y(), +ring_rectangle_width(), ring_rectangle_height(), field_18() { + ring_height = -1000.0f; + ring_out_height = -1000.0f; } osage_ring_data::~osage_ring_data() { @@ -669,8 +967,8 @@ void RobCloth::AddMotionResetData(int32_t motion_id, float_t frame) { void RobCloth::ColiSet(mat4* mats) { if (skin_param_ptr->coli.size()) - osage_coli::set(coli, skin_param_ptr->coli.data(), mats); - osage_coli::ring_set(coli_ring, ring.skp_root_coli, mats); + OsageCollision::Work::update_cls_work(coli, skin_param_ptr->coli.data(), mats); + OsageCollision::Work::update_cls_work(coli_ring, ring.skp_root_coli, mats); } void RobCloth::Disp(mat4* mat, render_context* rctx) { @@ -1358,8 +1656,8 @@ bool RobOsage::CheckPartsBits(rob_osage_parts_bit parts_bits) { void RobOsage::ColiSet(mat4* mats) { if (skin_param_ptr->coli.size()) - osage_coli::set(coli, skin_param_ptr->coli.data(), mats); - osage_coli::ring_set(coli_ring, ring.skp_root_coli, mats); + OsageCollision::Work::update_cls_work(coli, skin_param_ptr->coli.data(), mats); + OsageCollision::Work::update_cls_work(coli_ring, ring.skp_root_coli, mats); } RobOsageNode* RobOsage::GetNode(size_t index) { @@ -2655,19 +2953,19 @@ void skin_param_osage_root_parse(void* kv, const char* name, int32_t count; if (_kv->read("coli", "length", count)) { - std::vector& vc = skp_root.coli; + std::vector& vc = skp_root.coli; for (int32_t i = 0; i < count; i++) { if (!_kv->open_scope_fmt(i)) continue; - skin_param_osage_root_coli* c = &vc[i]; + SkinParam::CollisionParam* c = &vc[i]; int32_t type = 0; if (!_kv->read("type", type)) { _kv->close_scope(); break; } - c->type = (skin_param_osage_root_coli_type)type; + c->type = (SkinParam::CollisionType)type; float_t radius = 0; if (!_kv->read("radius", radius)) { @@ -2682,7 +2980,7 @@ void skin_param_osage_root_parse(void* kv, const char* name, break; } - c->bone0_index = bone_data->get_skeleton_object_bone_index( + c->node_idx[0] = bone_data->get_skeleton_object_bone_index( bone_database_skeleton_type_to_string(BONE_DATABASE_SKELETON_COMMON), bone0_name); vec3 bone0_pos = 0.0f; @@ -2693,11 +2991,11 @@ void skin_param_osage_root_parse(void* kv, const char* name, break; } - c->bone0_pos = bone0_pos; + c->pos[0] = bone0_pos; const char* bone1_name; if (_kv->read("bone.1.name", bone1_name)) { - c->bone1_index = bone_data->get_skeleton_object_bone_index( + c->node_idx[1] = bone_data->get_skeleton_object_bone_index( bone_database_skeleton_type_to_string(BONE_DATABASE_SKELETON_COMMON), bone1_name); vec3 bone1_pos = 0.0f; @@ -2708,7 +3006,7 @@ void skin_param_osage_root_parse(void* kv, const char* name, break; } - c->bone1_pos = bone1_pos; + c->pos[1] = bone1_pos; } _kv->close_scope(); } @@ -2733,7 +3031,7 @@ void skin_param_osage_root_parse(void* kv, const char* name, && ed_node < node_length) { skin_param_osage_root_boc b; b.st_node = st_node; - b.ed_root = ed_root; + b.ed_root.assign(ed_root); b.ed_node = ed_node; vb->push_back(b); } @@ -2744,7 +3042,7 @@ void skin_param_osage_root_parse(void* kv, const char* name, std::string colli_tgt_osg; if (_kv->read("colli_tgt_osg", colli_tgt_osg)) - skp_root.colli_tgt_osg = colli_tgt_osg; + skp_root.colli_tgt_osg.assign(colli_tgt_osg); if (_kv->read("normal_ref", "length", count)) { std::vector* vnr = &skp_root.normal_ref; @@ -2757,7 +3055,7 @@ void skin_param_osage_root_parse(void* kv, const char* name, std::string n; if (_kv->read("N", n)) { skin_param_osage_root_normal_ref nr; - nr.n = n; + nr.n.assign(n); _kv->read("U", nr.u); _kv->read("D", nr.d); _kv->read("L", nr.l); @@ -2812,7 +3110,7 @@ void osage_setting::parse(key_val* kv) { elem = cat.insert({ key, {} }).first; elem->second.exf = exf; - elem->second.parts = parse_parts_string(&parts); + elem->second.parts = parse_parts_string(parts); kv->close_scope(); } kv->close_scope(); @@ -2843,14 +3141,14 @@ void osage_setting::parse(key_val* kv) { } } -rob_osage_parts osage_setting::parse_parts_string(std::string* s) { +rob_osage_parts osage_setting::parse_parts_string(std::string& s) { static const char* parts_string_array[] = { "LEFT", "RIGHT", "CENTER", "LONG_C", "SHORT_L", "SHORT_R", "APPEND_L", "APPEND_R", "MUFFLER", "WHITE_ONE_L", "PONY", "ANGEL_L", "ANGEL_R", }; for (const char*& i : parts_string_array) - if (!s->compare(i)) + if (!s.compare(i)) return (rob_osage_parts)(&i - parts_string_array); return ROB_OSAGE_PARTS_NONE; } @@ -3055,6 +3353,61 @@ static float_t exp_tan(float_t v1) { return tanf(fmodf(v1, 360.0f) * DEG_TO_RAD_FLOAT); } +// 0x140484850 +static void closest_pt_segment_segment(vec3& vec, const vec3& p0, const vec3& p1, const OsageCollision::Work* cls) { + vec3 v56 = p1 - p0; + vec3 v60 = vec3::cross(v56, cls->vec_center); + float_t v46 = vec3::length_squared(v60); + if (v46 <= 0.000001f) { + vec3 v56; + vec3 v57; + vec3 v58; + vec3 v59; + OsageCollision::get_nearest_line2point(v59, cls->pos[0], cls->pos[1], p0); + OsageCollision::get_nearest_line2point(v58, cls->pos[0], cls->pos[1], p1); + OsageCollision::get_nearest_line2point(v57, p0, p1, cls->pos[0]); + OsageCollision::get_nearest_line2point(v56, p0, p1, cls->pos[1]); + + float_t v48 = vec3::distance_squared(p1, cls->pos[0]); + float_t v51 = vec3::distance_squared(cls->pos[0], v57); + float_t v52 = vec3::distance_squared(cls->pos[1], v56); + float_t v55 = vec3::distance_squared(p0, v59); + + vec = p0; + + if (v55 > v48) { + vec = p1; + v55 = v48; + } + + if (v55 > v51) { + vec = v57; + v55 = v51; + } + + if (v55 > v52) + vec = v56; + } + else { + float_t v25 = vec3::length(v56); + if (v25 != 0.0f) + v56 *= 1.0f / v25; + + float_t v30 = 1.0f / cls->vec_center_length; + vec3 v61 = cls->vec_center * v30; + float_t v34 = vec3::dot(v61, v56); + float_t v35 = vec3::dot(v61 * v34 - v56, cls->pos[0] - p0) + / (v34 * v34 - 1.0f); + if (v35 < 0.0f) + vec = p0; + else if (v35 <= v25) + vec = p0 + v56 * v35; + else + vec = p1; + + } +} + static const osage_setting_osg_cat* osage_setting_data_get_cat_value( object_info* obj_info, const char* root_node) { auto elem_obj = osage_setting_data.obj.find(*obj_info); @@ -3087,11 +3440,7 @@ static void sub_140218560(RobCloth* rob_cls, float_t step, bool a3) { for (size_t j = 1; j < nodes_count; j++, node += root_count) { vec3 v19; mat4_mult_vec3_trans(&mat, &node->reset_data.trans, &v19); - - vec3 v20; - vec3_sub(v19, node->trans, v20); - vec3_mult_scalar(v20, move_cancel, v20); - vec3_add(node->trans, v20, node->trans); + node->trans += (v19 - node->trans) * move_cancel; } } } @@ -3408,7 +3757,7 @@ void sub_14021AA60(RobCloth* rob_cls, float_t step, bool a3) { for (size_t i = 1; i < nodes_count; i++) { for (ssize_t j = 0; j < root_count; j++, node++) { - float_t v71 = (1.0f - rob_cls->field_44) * rob_cls->skin_param_ptr->friction; + float_t fric = (1.0f - rob_cls->field_44) * rob_cls->skin_param_ptr->friction; if (step != 1.0f) { vec3 v60; vec3_sub(node->trans, node->field_1C, v60); @@ -3423,9 +3772,10 @@ void sub_14021AA60(RobCloth* rob_cls, float_t step, bool a3) { } sub_140482F30(&node[0].trans, &node[-root_count].trans, node[0].dist_top); - int32_t v39 = sub_1404851C0(&node->trans, rob_cls->skin_param_ptr->coli_r, &rob_cls->ring.coli, &v71); - v39 += sub_140485180(rob_cls->coli_ring, &node->trans, rob_cls->skin_param_ptr->coli_r); - v39 += sub_140485180(rob_cls->coli, &node->trans, rob_cls->skin_param_ptr->coli_r); + int32_t v39 = OsageCollision::osage_cls_work_list(node->trans, + rob_cls->skin_param_ptr->coli_r, rob_cls->ring.coli, &fric); + v39 += rob_cls->coli_ring->osage_cls(node->trans, rob_cls->skin_param_ptr->coli_r); + v39 += rob_cls->coli->osage_cls(node->trans, rob_cls->skin_param_ptr->coli_r); if (v19 > node->trans.y && v19 < 1001.0) { node->trans.y = v19; @@ -3447,7 +3797,7 @@ void sub_14021AA60(RobCloth* rob_cls, float_t step, bool a3) { mat4_get_translation(&mat, &node->trans); if (v39) - vec3_mult_scalar(node->trans_diff, v71, node->trans_diff); + vec3_mult_scalar(node->trans_diff, fric, node->trans_diff); vec3 v44; vec3_sub(node->trans, node->field_1C, v44); @@ -3496,9 +3846,10 @@ static void sub_14021D480(RobCloth* rob_cls) { vec3_mult_scalar(v38, node->dist_top, v38); vec3_add(node[-root_count].trans, v38, node[0].trans); - sub_1404851C0(&node->trans, rob_cls->skin_param_ptr->coli_r, &rob_cls->ring.coli, 0); - sub_140485180(rob_cls->coli_ring, &node->trans, rob_cls->skin_param_ptr->coli_r); - sub_140485180(rob_cls->coli, &node->trans, rob_cls->skin_param_ptr->coli_r); + OsageCollision::osage_cls_work_list(node->trans, + rob_cls->skin_param_ptr->coli_r, rob_cls->ring.coli); + rob_cls->coli_ring->osage_cls(node->trans, rob_cls->skin_param_ptr->coli_r); + rob_cls->coli->osage_cls(node->trans, rob_cls->skin_param_ptr->coli_r); if (v10 > node->trans.y && v10 < 1001.0f) node->trans.y = v10; @@ -3784,15 +4135,10 @@ static void sub_1404803B0(RobOsage* rob_osg, mat4* mat, vec3* parent_scale, bool RobOsageNode* i_begin = rob_osg->nodes.data() + 1; RobOsageNode* i_end = rob_osg->nodes.data() + rob_osg->nodes.size(); for (RobOsageNode* i = i_begin; i != i_end; i++) { - mat4 parent_mat; vec3 v46; - parent_mat = rob_osg->parent_mat; - mat4_mult_vec3_inv_trans(&parent_mat, &i->trans, &v46); - parent_mat = *rob_osg->parent_mat_ptr; - mat4_mult_vec3_trans(&parent_mat, &v46, &v46); - vec3_sub(v46, i->trans, v46); - vec3_mult_scalar(v46, move_cancel, v46); - vec3_add(i->trans, v46, i->trans); + mat4_mult_vec3_inv_trans(&rob_osg->parent_mat, &i->trans, &v46); + mat4_mult_vec3_trans(rob_osg->parent_mat_ptr, &v46, &v46); + i->trans += (v46 - i->trans) * move_cancel; } } } @@ -3892,246 +4238,13 @@ static void sub_140482F30(vec3* pos1, vec3* pos2, float_t length) { } } -static int32_t sub_140483B30(vec3* a1, vec3* a2, osage_coli* a3, float_t radius) { - vec3 bone_pos_diff; - vec3_add(a3->bone0_pos, a3->bone1_pos, bone_pos_diff); - - vec3 v29; - vec3 v30; - for (int32_t i = 0; i < 3; i++) { - float_t v13 = ((float_t*)a2)[i]; - float_t v14 = ((float_t*)&a3->bone0_pos)[i] - v13; - ((float_t*)&v30)[i] = v14; - if (v14 > radius) - return 0; - - v14 = v13 - ((float_t*)&bone_pos_diff)[i]; - ((float_t*)&v29)[i] = v14; - if (v14 > radius) - return 0; - } - - vec3 v28 = 0.0f; - vec3 v32 = 0.0f; - vec3 v27 = 1.0f; - - float_t v16 = 0.0f; - for (int32_t i = 0; i < 3; i++) { - float_t v18 = ((float_t*)&v30)[i]; - float_t v19 = ((float_t*)&v29)[i]; - if (fabsf(v18) >= fabsf(v19)) { - ((float_t*)&v28)[i] = v19; - ((float_t*)&v27)[i] = 1.0f; - v18 = v19; - } - else { - ((float_t*)&v28)[i] = v18; - ((float_t*)&v27)[i] = -1.0f; - } - - if (v18 > 0.0f) { - float_t v20 = v18 * v18; - ((float_t*)&v32)[i] = v20; - v16 += v20; - } - } - - if (v16 > radius * radius) - return 0; - - if (v16 > 0.0f) { - vec3_mult(v27, v32, v32); - vec3_mult_scalar(v32, 1.0f / v16, v32); - vec3_mult_scalar(v32, radius - sqrtf(v16), *a1); - } - else { - float_t v25 = ((float_t*)&v28)[0]; - int32_t v26 = 0; - for (int32_t i = 0; i < 3; i++) { - if (((float_t*)&v28)[i] > v25) { - v25 = ((float_t*)&v28)[i]; - v26 = i; - } - } - ((float_t*)a1)[v26] -= ((float_t*)&v27)[v26] * (v25 - radius); - } - return 1; -} - -static int32_t sub_140483DE0(vec3* a1, vec3* a2, vec3* a3, float_t radius) { - vec3 v5; - float_t length; - vec3_sub(*a2, *a3, v5); - vec3_length_squared(v5, length); - if (length > 0.000001f && length < radius * radius) { - vec3_mult_scalar(v5, radius / sqrtf(length) - 1.0f, *a1); - return 1; - } - return 0; -} - -static int32_t sub_140483EA0(vec3* a1, vec3* a2, osage_coli* a3, float_t radius) { - if (a3->bone_pos_diff_length <= 0.000001f) - return sub_140483DE0(a1, a2, &a3->bone0_pos, radius); - - float_t v61 = a3->bone_pos_diff_length * 0.5f; - float_t v13 = sqrtf(radius * radius + v61 * v61); - - float_t v20; - vec3 v54; - vec3_sub(*a2, a3->bone0_pos, v54); - vec3_length(v54, v20); - - float_t v21; - vec3 v57; - vec3_sub(*a2, a3->bone1_pos, v57); - vec3_length(v57, v21); - - if (v20 <= 0.000001f || v21 <= 0.000001f) - return 0; - - float_t v22 = v20 + v21; - if (v21 + v20 >= v13 * 2.0f) - return 0; - - float_t v25 = 1.0f / a3->bone_pos_diff_length; - - vec3 v63; - vec3_add(a3->bone0_pos, a3->bone1_pos, v63); - vec3_mult_scalar(v63, 0.5f, v63); - vec3_sub(*a2, v63, v63); - - float_t v58; - vec3_length(v63, v58); - if (v58 != 0.0f) - vec3_mult_scalar(v63, 1.0f / v58, v63); - - float_t v36; - vec3_dot(v63, a3->bone_pos_diff, v36); - v36 *= v25; - float_t v37 = v36 * v36; - v37 = min_def(v37, 1.0f); - v22 *= 0.5f; - float_t v38 = v22 * v22 - v61; - if (v38 < 0.0f) - return 0; - - float_t v39 = sqrtf(v38); - if (v39 <= 0.000001f) - return 0; - - float_t v42 = sqrtf(1.0f - v37); - v22 = (v13 / v22 - 1.0f) * v36 * v58; - v42 = (radius / v39 - 1.0f) * v42 * v58; - float_t v43 = sqrtf(v42 * v42 + v22 * v22); - if (v20 != 0.0f) - vec3_mult_scalar(v54, 1.0f / v20, v54); - - if (v21 != 0.0f) - vec3_mult_scalar(v57, 1.0f / v21, v57); - - vec3 v48; - vec3_add(v54, v57, v48); - vec3_normalize(v48, v48); - vec3_mult_scalar(v48, v43, *a1); - return 1; -} - -static int32_t sub_140484540(vec3* a1, vec3* a2, osage_coli* coli, float_t radius) { - vec3 v11; - vec3_sub(*a2, coli->bone0_pos, v11); - - float_t v17; - vec3_dot(v11, coli->bone_pos_diff, v17); - if (v17 < 0.0f) - return sub_140483DE0(a1, a2, &coli->bone0_pos, radius); - - float_t v19 = coli->bone_pos_diff_length_squared; - if (fabsf(v19) <= 0.000001f) - return sub_140483DE0(a1, a2, &coli->bone0_pos, radius); - if (v17 > v19) - return sub_140483DE0(a1, a2, &coli->bone1_pos, radius); - - float_t v20; - vec3_length_squared(v11, v20); - float_t v22 = fabsf(v20 - v17 * v17 / v19); - if (v22 <= 0.000001f || v22 >= radius * radius) - return 0; - - vec3 v29; - vec3_mult_scalar(coli->bone_pos_diff, v17 / v19, v29); - vec3_sub(v11, v29, v29); - vec3_mult_scalar(v29, radius / sqrtf(v22) - 1.0f, *a1); - return 1; -} - -static int32_t sub_140484780(vec3* a1, vec3* a2, vec3* a3, vec3* a4, float_t radius) { - float_t v3; - vec3_dot(*a2, *a4, v3); - float_t v4; - vec3_dot(*a3, *a4, v4); - float_t v5 = v3 - v4 - radius; - if (v5 >= 0.0f) - return 0; - - vec3_mult_scalar(*a4, -v5, *a1); - return 1; -} - -static int32_t sub_140485180(osage_coli* a1, vec3* a2, float_t& coli_r) { - return sub_140485220(a2, coli_r, a1, 0); -} - -static int32_t sub_1404851C0(vec3* a1, float_t& coli_r, std::vector* a3, float_t* a4) { - if (!a3->size() || a3->back().type) - return 0; - return sub_140485220(a1, coli_r, a3->data(), a4); -} - -static int32_t sub_140485220(vec3* a1, float_t& coli_r, osage_coli* a3, float_t* a4) { - if (!a3) - return 0; - - int32_t v8 = 0; - while (a3->type) { - int32_t v11 = 0; - vec3 v31 = 0.0f; - switch (a3->type) { - case SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_BALL: - v11 = sub_140483DE0(&v31, a1, &a3->bone0_pos, a3->radius + coli_r); - break; - case SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_CYLINDER: - v11 = sub_140484540(&v31, a1, a3, a3->radius + coli_r); - break; - case SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_PLANE: - v11 = sub_140484780(&v31, a1, &a3->bone0_pos, &a3->bone1_pos, coli_r); - break; - case SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_ELLIPSE: - v11 = sub_140483EA0(&v31, a1, a3, a3->radius + coli_r); - break; - case SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_5: - v11 = sub_140483B30(&v31, a1, a3, coli_r); - break; - } - - if (a4 && v11 > 0) { - if (a3->field_34 < *a4) - *a4 = a3->field_34; - } - a3++; - v8 += v11; - vec3_add(*a1, v31, *a1); - } - return v8; -} - static void sub_14047D8C0(RobOsage* rob_osg, mat4* mat, vec3* parent_scale, float_t step, bool a5) { if (!rob_osg->osage_reset && step <= 0.0f) return; - osage_coli* coli = rob_osg->coli; - osage_coli* coli_ring = rob_osg->coli_ring; - std::vector* vec_ring_coli = &rob_osg->ring.coli; + OsageCollision::Work* coli = rob_osg->coli; + OsageCollision::Work* coli_ring = rob_osg->coli_ring; + OsageCollision& vec_ring_coli = rob_osg->ring.coli; float_t v9 = 0.0f; if (step > 0.0f) @@ -4179,7 +4292,7 @@ static void sub_14047D8C0(RobOsage* rob_osg, mat4* mat, vec3* parent_scale, floa RobOsageNode* v30_begin = v24->data() + 1; RobOsageNode* v30_end = v24->data() + v24->size(); for (RobOsageNode* v30 = v30_begin; v30 != v30_end; v30++) - sub_140483DE0(&v62, &v27->trans, &v30->trans, + OsageCollision::cls_ball_oidashi(v62, v27->trans, v30->trans, v27->data_ptr->skp_osg_node.coli_r + v30->data_ptr->skp_osg_node.coli_r); vec3_add(v27->trans, v62, v27->trans); } @@ -4192,11 +4305,11 @@ static void sub_14047D8C0(RobOsage* rob_osg, mat4* mat, vec3* parent_scale, floa float_t v37 = (1.0f - rob_osg->field_1EB4) * rob_osg->skin_param_ptr->friction; if (a5) { sub_140482490(&v35[0], step, parent_scale->x); - v35->field_C8 = (float_t)sub_1404851C0(&v35->trans, + v35->field_C8 = (float_t)OsageCollision::osage_cls_work_list(v35->trans, skp_osg_node->coli_r, vec_ring_coli, &v35->field_CC); if (!rob_osg->field_1F0F) { - v35->field_C8 += (float_t)sub_140485180(coli_ring, &v35->trans, skp_osg_node->coli_r); - v35->field_C8 += (float_t)sub_140485180(coli, &v35->trans, skp_osg_node->coli_r); + v35->field_C8 += (float_t)coli_ring->osage_cls(v35->trans, skp_osg_node->coli_r); + v35->field_C8 += (float_t)coli->osage_cls(v35->trans, skp_osg_node->coli_r); } sub_140482180(&v35[0], v60); } @@ -4236,7 +4349,7 @@ static void sub_14047D8C0(RobOsage* rob_osg, mat4* mat, vec3* parent_scale, floa vec3_mult_scalar(v62, v9, v35->trans_diff); if (v35->field_C8 > 0.0f) { - if (v35->field_CC < v37) + if (v37 > v35->field_CC) v37 = v35->field_CC; vec3_mult_scalar(v35->trans_diff, v37, v35->trans_diff); } @@ -4276,8 +4389,8 @@ static void sub_14047D620(RobOsage* rob_osg, float_t step) { std::vector& nodes = rob_osg->nodes; vec3 v7 = nodes.data()[0].trans; - osage_coli* coli = rob_osg->coli; - osage_coli* coli_ring = rob_osg->coli_ring; + OsageCollision::Work* coli = rob_osg->coli; + OsageCollision::Work* coli_ring = rob_osg->coli_ring; int32_t coli_type = rob_osg->skin_param_ptr->coli_type; RobOsageNode* i_begin = nodes.data() + 1; RobOsageNode* i_end = nodes.data() + nodes.size(); @@ -4285,16 +4398,16 @@ static void sub_14047D620(RobOsage* rob_osg, float_t step) { RobOsageNodeData* data = i->data_ptr; for (RobOsageNode*& j : data->boc) { float_t v17 = (float_t)( - sub_140485000(&i->trans, &j->trans, &data->skp_osg_node, coli) - + sub_140485000(&i->trans, &j->trans, &data->skp_osg_node, coli_ring)); + coli->osage_capsule_cls(i->trans, j->trans, data->skp_osg_node.coli_r) + + coli_ring->osage_capsule_cls(i->trans, j->trans, data->skp_osg_node.coli_r)); i->field_C8 += v17; j->field_C8 += v17; } if (coli_type && (coli_type != 1 || i != i_begin)) { float_t v20 = (float_t)( - sub_140485000(&i[0].trans, &i[-1].trans, &data->skp_osg_node, coli) - + sub_140485000(&i[0].trans, &i[-1].trans, &data->skp_osg_node, coli_ring)); + coli->osage_capsule_cls(i[0].trans, i[-1].trans, data->skp_osg_node.coli_r) + + coli_ring->osage_capsule_cls(i[0].trans, i[-1].trans, data->skp_osg_node.coli_r)); i[0].field_C8 += v20; i[-1].field_C8 += v20; } @@ -4306,25 +4419,26 @@ static void sub_14047ECA0(RobOsage* rob_osg, float_t step) { if (step <= 0.0f) return; - std::vector* vec_coli = &rob_osg->ring.coli; - osage_coli* coli_ring = rob_osg->coli_ring; - osage_coli* coli = rob_osg->coli; + OsageCollision& vec_coli = rob_osg->ring.coli; + OsageCollision::Work* coli_ring = rob_osg->coli_ring; + OsageCollision::Work* coli = rob_osg->coli; bool v11 = rob_osg->field_1F0F; RobOsageNode* i_begin = rob_osg->nodes.data() + 1; RobOsageNode* i_end = rob_osg->nodes.data() + rob_osg->nodes.size(); for (RobOsageNode* i = i_begin; i != i_end; i++) { RobOsageNodeData* data = i->data_ptr; - i->field_C8 += (float_t)sub_1404851C0(&i->trans, data->skp_osg_node.coli_r, vec_coli, &i->field_CC); + i->field_C8 += (float_t)OsageCollision::osage_cls_work_list(i->trans, + data->skp_osg_node.coli_r, vec_coli, &i->field_CC); if (v11) continue; for (RobOsageNode*& j : data->boc) { - j->field_C8 += (float_t)sub_140485180(coli_ring, &j->trans, data->skp_osg_node.coli_r); - j->field_C8 += (float_t)sub_140485180(coli, &j->trans, data->skp_osg_node.coli_r); + j->field_C8 += (float_t)coli_ring->osage_cls(j->trans, data->skp_osg_node.coli_r); + j->field_C8 += (float_t)coli->osage_cls(j->trans, data->skp_osg_node.coli_r); } - i->field_C8 += (float_t)sub_140485180(coli_ring, &i->trans, data->skp_osg_node.coli_r); - i->field_C8 += (float_t)sub_140485180(coli, &i->trans, data->skp_osg_node.coli_r); + i->field_C8 += (float_t)coli_ring->osage_cls(i->trans, data->skp_osg_node.coli_r); + i->field_C8 += (float_t)coli->osage_cls(i->trans, data->skp_osg_node.coli_r); } } @@ -4357,8 +4471,8 @@ static void sub_14047F990(RobOsage* rob_osg, mat4* a2, vec3* parent_scale, bool vec3 v60 = { 1.0f, 0.0f, 0.0f }; mat4_mult_vec3(&v78, &v60, &v60); - osage_coli* coli_ring = rob_osg->coli_ring; - osage_coli* coli = rob_osg->coli; + OsageCollision::Work* coli_ring = rob_osg->coli_ring; + OsageCollision::Work* coli = rob_osg->coli; float_t v25 = ring_height + coli_r; float_t v16 = parent_scale->x; RobOsageNode* i = rob_osg->nodes.data(); @@ -4372,8 +4486,8 @@ static void sub_14047F990(RobOsage* rob_osg, mat4* a2, vec3* parent_scale, bool sub_140482F30(&v74, &j->sibling_node->trans, j->max_distance); skin_param_osage_node* v38 = &j->data_ptr->skp_osg_node; - sub_140485180(coli_ring, &v74, v38->coli_r); - sub_140485180(coli, &v74, v38->coli_r); + coli_ring->osage_cls(v74, v38->coli_r); + coli->osage_cls(v74, v38->coli_r); float_t v39 = v25 + v38->coli_r; if (v74.y < v39 && v39 < 1001.0f) { @@ -4454,12 +4568,6 @@ static void sub_140482DF0(struc_477* dst, struc_477* src0, struc_477* src1, floa vec3_lerp_scalar(src0->rotation, src1->rotation, dst->rotation, blend); } -static int32_t sub_140484450(vec3* a1, vec3* a2, vec3* a3, vec3* a4, float_t radius) { - vec3 v8; - sub_140484E10(&v8, a2, a3, a4); - return sub_140483DE0(a1, &v8, a4, radius); -} - static bool sub_140482FF0(mat4& mat, vec3& trans, skin_param_hinge* hinge, vec3* rot, int32_t& yz_order) { bool clipped = false; float_t z_rot; @@ -4526,145 +4634,6 @@ static bool sub_140482FF0(mat4& mat, vec3& trans, skin_param_hinge* hinge, vec3* return clipped; } -static int32_t sub_1404844A0(vec3* a1, vec3* a2, vec3* a3, osage_coli* a4, float_t radius) { - vec3 v8; - sub_140484850(&v8, a2, a3, a4); - return sub_140484540(a1, &v8, a4, radius); -} - -static int32_t sub_1404844F0(vec3* a1, vec3* a2, vec3* a3, osage_coli* a4, float_t radius) { - vec3 v8; - sub_140484850(&v8, a2, a3, a4); - return sub_140483EA0(a1, &v8, a4, radius); -} - -static void sub_140484850(vec3* a1, vec3* a2, vec3* a3, osage_coli* coli) { - vec3 v56; - vec3_sub(*a3, *a2, v56); - - vec3 v60; - vec3_cross(v56, coli->bone_pos_diff, v60); - - float_t v46; - vec3_length_squared(v60, v46); - if (v46 <= 0.000001f) { - vec3 v56; - vec3 v57; - vec3 v58; - vec3 v59; - sub_140484E10(&v59, &coli->bone0_pos, &coli->bone1_pos, a2); - sub_140484E10(&v58, &coli->bone0_pos, &coli->bone1_pos, a3); - sub_140484E10(&v57, a2, a3, &coli->bone0_pos); - sub_140484E10(&v56, a2, a3, &coli->bone1_pos); - - float_t v48; - float_t v51; - float_t v52; - float_t v55; - vec3_distance_squared(*a3, coli->bone0_pos, v48); - vec3_distance_squared(coli->bone0_pos, v57, v51); - vec3_distance_squared(coli->bone1_pos, v56, v52); - vec3_distance_squared(*a2, v59, v55); - *a1 = *a2; - - if (v55 > v48) { - *a1 = *a3; - v55 = v48; - } - - if (v55 > v51) { - *a1 = v57; - v55 = v51; - } - - if (v55 > v52) - *a1 = v56; - } - else { - float_t v25; - vec3_length(v56, v25); - if (v25 != 0.0f) - vec3_mult_scalar(v56, 1.0f / v25, v56); - - float_t v30 = 1.0f / coli->bone_pos_diff_length; - vec3 v61; - float_t v34; - vec3_mult_scalar(coli->bone_pos_diff, v30, v61); - vec3_dot(v61, v56, v34); - vec3_mult_scalar(v61, v34, v61); - vec3_sub(v61, v56, v61); - vec3_sub(coli->bone0_pos, *a2, v60); - float_t v35; - vec3_dot(v61, v60, v35); - v35 /= (v34 * v34 - 1.0f); - if (v35 < 0.0f) - *a1 = *a2; - else if (v35 <= v25) { - vec3_mult_scalar(v56, v35, v56); - vec3_add(*a2, v56, *a1); - } - else - *a1 = *a3; - - } -} - -static void sub_140484E10(vec3* a1, vec3* a2, vec3* a3, vec3* a4) { - vec3 v6; - vec3_sub(*a3, *a2, v6); - - vec3 v7; - vec3_sub(*a4, *a2, v7); - - float_t v8; - vec3_dot(v7, v6, v8); - if (v8 < 0.0f) { - *a1 = *a2; - return; - } - - float_t v9; - vec3_length_squared(v6, v9); - if (v9 <= 0.000001f) - *a1 = *a2; - else if (v8 <= v9) { - float_t v10 = v8 / v9; - vec3_mult_scalar(v6, v8 / v9, v6); - vec3_add(*a2, v6, *a1); - } - else - *a1 = *a3; -} - -static int32_t sub_140485000(vec3* a1, vec3* a2, skin_param_osage_node* a3, osage_coli* a4) { - if (!a4) - return 0; - - int32_t v8 = 0; - while (a4->type) { - int32_t type = a4->type; - vec3 v21 = 0.0f; - switch (a4->type) { - case SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_BALL: - v8 += sub_140484450(&v21, a1, a2, &a4->bone0_pos, a3->coli_r + a4->radius); - break; - case SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_CYLINDER: - v8 += sub_1404844A0(&v21, a1, a2, a4, a3->coli_r + a4->radius); - break; - case SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_ELLIPSE: - v8 += sub_1404844F0(&v21, a1, a2, a4, a3->coli_r + a4->radius); - break; - } - - if (v8 > 0) { - vec3_add(*a1, v21, *a1); - vec3_add(*a2, v21, *a2); - } - a4++; - } - return v8; -} - static void sub_14053CE30(RobOsageNodeDataNormalRef* normal_ref, mat4* a2) { if (!normal_ref->field_0) return; diff --git a/src/CRE/rob/rob.cpp b/src/CRE/rob/rob.cpp index f11c6d75..500a9565 100644 --- a/src/CRE/rob/rob.cpp +++ b/src/CRE/rob/rob.cpp @@ -4379,7 +4379,7 @@ static void bone_data_parent_load_bone_indices_from_mot(bone_data_parent* a1, const char* skeleton_type_string = bone_database_skeleton_type_to_string(skeleton_type); std::string* bone_names = mot_db->bone_name.data(); - const mot_bone_info* bone_info = a2->bone_info.data(); + const mot_bone_info* bone_info = a2->bone_info_array; for (size_t key_set_offset = 0, i = 0; key_set_offset < key_set_count; i++) { motion_bone_index bone_index = (motion_bone_index)bone_data->get_skeleton_bone_index( skeleton_type_string, bone_names[bone_info[i].index].c_str()); @@ -4688,17 +4688,17 @@ static bool mot_load_file(mot* a1, const mot_data* a2) { a1->key_set_count = key_set_count; a1->field_4 = a2->info & 0x8000; - const mot_key_set_data* key_set_file = a2->key_set.data(); + const mot_key_set_data* key_set_file = a2->key_set_array; mot_key_set* key_set = a1->key_sets; for (int32_t i = 0; i < key_set_count; i++, key_set++, key_set_file++) { key_set->type = key_set_file->type; if (key_set->type == MOT_KEY_SET_STATIC) - key_set->values = key_set_file->values.data(); + key_set->values = key_set_file->values; else if (key_set->type != MOT_KEY_SET_NONE) { uint16_t keys_count = key_set_file->keys_count; - key_set->frames = key_set_file->frames.data(); - key_set->values = key_set_file->values.data(); + key_set->frames = key_set_file->frames; + key_set->values = key_set_file->values; key_set->keys_count = keys_count; key_set->current_key = 0; @@ -6791,7 +6791,7 @@ static void sub_14054BC70(RobSubAction* a1) { } if (a1->data.field_0) - a1->data.field_0->Field_10(a1->data.field_10); + a1->data.field_0->Field_10(a1->data.param); if (a1->data.field_18) delete a1->data.field_18; @@ -7598,12 +7598,12 @@ static void sub_140504710(rob_chara* rob_chr, motion_database* mot_db, sub_14041CA10(rob_chr->bone_data, &rob_chr->data.motion.field_140); sub_14041DA00(rob_chr->bone_data); - struc_405* v2 = &rob_chr->data.motion.field_150; + RobFaceMotion* v2 = &rob_chr->data.motion.field_150.face; if ((rob_chr->data.motion.field_29 & 0x04)) - v2 = &rob_chr->data.motion.field_3B0; - sub_14053F2C0(&v2->face); - rob_chara_bone_data_set_face_frame(rob_chr->bone_data, v2->face.data.frame); - rob_chara_bone_data_set_face_play_frame_step(rob_chr->bone_data, v2->face.data.play_frame_step); + v2 = &rob_chr->data.motion.field_3B0.face; + sub_14053F2C0(v2); + rob_chara_bone_data_set_face_frame(rob_chr->bone_data, v2->data.frame); + rob_chara_bone_data_set_face_play_frame_step(rob_chr->bone_data, v2->data.play_frame_step); RobHandMotion* v3 = &rob_chr->data.motion.field_150.hand_l; if (rob_chr->data.motion.field_29 & 0x08) @@ -10654,7 +10654,7 @@ static void sub_140505FB0(struc_209* a1) { for (struc_195& i : a1->field_1668) i = {}; - for (struc_210& i : a1->field_1AA0) + for (pos_scale& i : a1->field_1AA0) i = {}; for (float_t& i : a1->field_1BE4) @@ -11971,7 +11971,7 @@ static bool task_rob_load_check_load_req_data() { bool rob_chara_array_check_visibility(int32_t chara_id) { if (rob_chara_pv_data_array_check_chara_id(chara_id)) - return rob_chara_array[chara_id].get_visibility(); + return rob_chara_array[chara_id].is_visible(); return false; } @@ -12093,7 +12093,7 @@ int32_t rob_chara::get_rob_cmn_mottbl_motion_id(int32_t id) { return -1; } -bool rob_chara::get_visibility() { +bool rob_chara::is_visible() { return !!(data.field_0 & 0x01); } @@ -13863,7 +13863,7 @@ void SubActExecShakeHand::Field_20(rob_chara* rob_chr) { }; -RobSubAction::Data::Data() : field_0(), field_8(), field_10(), field_18() { +RobSubAction::Data::Data() : field_0(), field_8(), param(), field_18() { } @@ -13882,7 +13882,7 @@ RobSubAction::~RobSubAction() { void RobSubAction::Reset() { data.field_0 = 0; data.field_8 = 0; - data.field_10 = 0; + data.param = 0; data.field_18 = 0; data.cry.Field_8(); data.shake_hand.Field_8(); @@ -13891,6 +13891,17 @@ void RobSubAction::Reset() { data.laugh.Field_8(); } +void RobSubAction::SetSubActParam(SubActParam* value) { + if (!value) + return; + + if (data.param) { + delete data.param; + data.param = 0; + } + data.param = value; +} + RobPartialMotion::RobPartialMotion() { } @@ -13959,29 +13970,6 @@ void RobEyelidMotion::Reset() { data.Reset(); } -struc_405::struc_405() : field_1C0(), time() { - -} - -struc_405::~struc_405() { - -} - -void struc_405::Reset() { - face.Reset(); - hand_l.Reset(); - hand_r.Reset(); - mouth.Reset(); - eyes.Reset(); - eyelid.Reset(); - head_object = object_info(); - hand_l_object = object_info(); - hand_r_object = object_info(); - face_object = object_info(); - field_1C0 = 0; - time = 0.0f; -} - rob_chara_data_adjust::rob_chara_data_adjust() : enable(), frame(), transition_frame(), curr_force(), curr_strength(), motion_id(), set_frame(), force_duration(), type(), cycle_type(), ignore_gravity(), cycle(), phase(), force(), strength(), strength_transition() { @@ -14423,10 +14411,38 @@ struc_195::struc_195() : scale(), field_1C(), field_20(), field_24() { } -struc_210::struc_210() : scale() { +pos_scale::pos_scale() : scale() { } +void pos_scale::get_screen_pos_scale(mat4& mat, vec3& trans, bool apply_offset) { + vec4 v15; + *(vec3*)&v15 = trans; + v15.w = 1.0f; + mat4_mult_vec(&mat, &v15, &v15); + + if (fabsf(v15.w) >= 1.0e-10f) { + post_process* pp = &rctx_ptr->post_process; + if (apply_offset) { + float_t v11 = (1.0f + v15.x * (1.0f / v15.w)) * 0.5f * (float_t)pp->screen_width; + float_t v12 = (1.0f - v15.y * (1.0f / v15.w)) * 0.5f * (float_t)pp->screen_height; + v11 += (float_t)pp->screen_x_offset; + v12 += (float_t)pp->screen_y_offset; + pos = { v11, v12 }; + } + else{ + float_t v11 = (1.0f + v15.x * (1.0f / v15.w)) * 0.5f * (float_t)pp->render_width; + float_t v12 = (1.0f - v15.y * (1.0f / v15.w)) * 0.5f * (float_t)pp->render_height; + pos = { v11, v12 }; + } + scale = -v15.w; + } + else { + pos = 0.0f; + scale = 0.0f; + } +} + struc_209::struc_209() : field_0(), field_4(), field_8(), field_C(), field_10(), field_14(), field_18(), field_1C(), field_20(), field_24(), field_28(), field_2C(), field_30(), field_34(), field_38(), field_3C(), field_40(), field_44(), field_48(), field_4C(), field_50(), field_54(), field_58(), field_5C(), field_60(), @@ -14536,7 +14552,7 @@ inline const mot_data* motion_storage_get_mot_data(uint32_t motion_id, motion_da auto elem = motion_storage_data.find(set_id); if (elem != motion_storage_data.end()) - return &elem->second.mot_set->vec[motion_index]; + return &elem->second.mot_set->mot_data[motion_index]; return 0; } @@ -14689,10 +14705,8 @@ bool MotFile::CheckNotReady() { void MotFile::FreeData() { mot_set_info = 0; - if (mot_set) { - delete mot_set; - mot_set = 0; - } + alloc_handler.reset(); + mot_set = 0; file_handler.reset(); load_count = 0; } @@ -14728,8 +14742,12 @@ void MotFile::LoadFile(std::string* mdata_dir, uint32_t set) { } void MotFile::ParseFile(const void* data, size_t size) { - mot_set = new ::mot_set; - mot_set->unpack_file(data, size, false); + prj::shared_ptr& alloc = alloc_handler; + alloc = prj::shared_ptr(new alloc_data); + + ::mot_set* set = alloc->allocate<::mot_set>(); + mot_set = set; + set->unpack_file(alloc, data, size, false); } bool MotFile::Unload() { @@ -17487,7 +17505,7 @@ void TaskRobDisp::Disp() { if (pv_osage_manager_array_get_disp(&chara_id)) continue; - if (i->get_visibility() && i->data.field_3 >= 0) + if (i->is_visible() && i->data.field_3 >= 0) rob_disp_rob_chara_disp(i); } } diff --git a/src/CRE/rob/rob.hpp b/src/CRE/rob/rob.hpp index ce877fed..f92179f5 100644 --- a/src/CRE/rob/rob.hpp +++ b/src/CRE/rob/rob.hpp @@ -799,15 +799,6 @@ enum rob_osage_parts_bit { ROB_OSAGE_PARTS_ANGEL_R_BIT = 0x1000, }; -enum skin_param_osage_root_coli_type { - SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_NONE = 0x00, - SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_BALL = 0x01, - SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_CYLINDER = 0x02, - SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_PLANE = 0x03, - SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_ELLIPSE = 0x04, - SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_5 = 0x05, -}; - enum ExNodeType { EX_NONE = 0x00, EX_OSAGE = 0x01, @@ -836,6 +827,18 @@ enum SubActParamType { SUB_ACTION_PARAM_COUNT_NUM = 0x6, }; +namespace SkinParam { + enum CollisionType { + CollisionTypeEnd = 0x0, + CollisionTypeBall = 0x1, + CollisionTypeCapsulle = 0x2, + CollisionTypePlane = 0x3, + CollisionTypeEllipse = 0x4, + CollisionTypeAABB = 0x5, + CollisionTypeMax = 0x6, + }; +} + struct rob_chara; struct rob_chara_bone_data; @@ -1561,16 +1564,16 @@ struct RobOsageNode { void Reset(); }; -struct skin_param_osage_root_coli { - skin_param_osage_root_coli_type type; - int32_t bone0_index; - int32_t bone1_index; - float_t radius; - vec3 bone0_pos; - vec3 bone1_pos; +namespace SkinParam { + struct CollisionParam { + CollisionType type; + int32_t node_idx[2]; + float_t radius; + vec3 pos[2]; - skin_param_osage_root_coli(); - ~skin_param_osage_root_coli(); + CollisionParam(); + ~CollisionParam(); + }; }; struct skin_param_osage_root_normal_ref { @@ -1605,7 +1608,7 @@ struct skin_param_osage_root { float_t hinge_y; float_t hinge_z; const char* name; - std::vector coli; + std::vector coli; float_t coli_r; float_t friction; float_t wind_afc; @@ -1622,7 +1625,7 @@ struct skin_param_osage_root { }; struct skin_param { - std::vector coli; + std::vector coli; float_t friction; float_t wind_afc; float_t air_res; @@ -1659,22 +1662,48 @@ struct skin_param { } }; -struct osage_coli { - skin_param_osage_root_coli_type type; - float_t radius; - vec3 bone0_pos; - vec3 bone1_pos; - vec3 bone_pos_diff; - float_t bone_pos_diff_length; - float_t bone_pos_diff_length_squared; - float_t field_34; +struct OsageCollision { + struct Work { + SkinParam::CollisionType type; + float_t radius; + vec3 pos[2]; + vec3 vec_center; + float_t vec_center_length; + float_t vec_center_length_squared; + float_t friction; - osage_coli(); - ~osage_coli(); + Work(); + ~Work(); - static void set(osage_coli* coli, skin_param_osage_root_coli* skp_root_coli, mat4* mats); - static void ring_set(osage_coli* coli, - std::vector& vec_skp_root_coli, mat4* mats); + int32_t osage_capsule_cls(vec3& p0, vec3& p1, const float_t& cls_r); + int32_t osage_cls(vec3& p, const float_t& cls_r); + + static void update_cls_work(OsageCollision::Work* cls, + SkinParam::CollisionParam* cls_param, mat4* tranform); + static void update_cls_work(OsageCollision::Work* cls, + std::vector& cls_list, mat4* tranform); + }; + + std::vector work_list; + + OsageCollision(); + ~OsageCollision(); + + static int32_t cls_aabb_oidashi(vec3& vec, const vec3& p, const OsageCollision::Work* cls, const float_t r); + static int32_t cls_ball_oidashi(vec3& vec, const vec3& p, const vec3& center, const float_t r); + static int32_t cls_capsule_oidashi(vec3& vec, const vec3& p, const OsageCollision::Work* coli, const float_t r); + static int32_t cls_ellipse_oidashi(vec3& vec, const vec3& p, const OsageCollision::Work* cls, const float_t r); + static int32_t cls_line2ball_oidashi(vec3& vec, + const vec3& p0, const vec3& p1, const vec3& q, const float_t r); + static int32_t cls_line2capsule_oidashi(vec3& vec, + const vec3& p0, const vec3& p1, const OsageCollision::Work* cls, const float_t r); + static int32_t cls_line2ellipse_oidashi(vec3& vec, + const vec3& p0, const vec3& p1, const OsageCollision::Work* cls, const float_t r); + static int32_t cls_plane_oidashi(vec3& vec, const vec3& p, const vec3& p1, const vec3& p2, const float_t r); + static void get_nearest_line2point(vec3& nearest, const vec3& p0, const vec3& p1, const vec3& q); + static int32_t osage_capsule_cls(vec3& p0, vec3& p1, const float_t& cls_r, const OsageCollision::Work* cls); + static int32_t osage_cls(vec3& p, const float_t& cls_r, const OsageCollision::Work* cls, float_t* fric = 0); + static int32_t osage_cls_work_list(vec3& p, const float_t& cls_r, const OsageCollision& coli, float_t* fric = 0); }; struct osage_ring_data { @@ -1685,8 +1714,8 @@ struct osage_ring_data { float_t ring_height; float_t ring_out_height; bool field_18; - std::vector coli; - std::vector skp_root_coli; + OsageCollision coli; + std::vector skp_root_coli; osage_ring_data(); ~osage_ring_data(); @@ -1739,8 +1768,8 @@ struct CLOTH { std::vector field_58; skin_param* skin_param_ptr; skin_param skin_param; - osage_coli coli[64]; - osage_coli coli_ring[64]; + OsageCollision::Work coli[64]; + OsageCollision::Work coli_ring[64]; osage_ring_data ring; mat4* mats; @@ -1887,8 +1916,8 @@ struct RobOsage { bool field_2A0; bool field_2A1; float_t field_2A4; - osage_coli coli[64]; - osage_coli coli_ring[64]; + OsageCollision::Work coli[64]; + OsageCollision::Work coli_ring[64]; vec3 wind_direction; float_t field_1EB4; int32_t yz_order; @@ -2509,7 +2538,7 @@ struct RobSubAction { struct Data { SubActExec* field_0; SubActExec* field_8; - SubActParam* field_10; + SubActParam* param; SubActExec* field_18; SubActExecCry cry; SubActExecShakeHand shake_hand; @@ -2526,6 +2555,7 @@ struct RobSubAction { ~RobSubAction(); void Reset(); + void SetSubActParam(SubActParam* value); }; struct struc_389 { @@ -2630,6 +2660,7 @@ public: virtual void Reset() override; }; +template struct struc_405 { RobFaceMotion face; RobHandMotion hand_l; @@ -2641,13 +2672,31 @@ struct struc_405 { object_info hand_l_object; object_info hand_r_object; object_info face_object; - int32_t field_1C0; + T field_1C0; float_t time; - struc_405(); - ~struc_405(); + struc_405() : field_1C0(), time() { - void Reset(); + } + + ~struc_405() { + + } + + void Reset() { + face.Reset(); + hand_l.Reset(); + hand_r.Reset(); + mouth.Reset(); + eyes.Reset(); + eyelid.Reset(); + head_object = object_info(); + hand_l_object = object_info(); + hand_r_object = object_info(); + face_object = object_info(); + field_1C0 = {}; + time = 0.0f; + } }; struct rob_chara_data_adjust { @@ -2732,13 +2781,13 @@ struct rob_chara_motion { float_t field_13C; vec3 field_140; int32_t field_14C; - struc_405 field_150; + struc_405 field_150; float_t field_314; RobHandMotion hand_l; RobHandMotion hand_r; object_info hand_l_object; object_info hand_r_object; - struc_405 field_3B0; + struc_405 field_3B0; rob_chara_data_adjust parts_adjust[ROB_OSAGE_PARTS_MAX]; rob_chara_data_adjust parts_adjust_prev[ROB_OSAGE_PARTS_MAX]; rob_chara_data_adjust adjust_global; @@ -3082,11 +3131,13 @@ struct struc_195 { struc_195(); }; -struct struc_210 { - vec2 field_0; +struct pos_scale { + vec2 pos; float_t scale; - struc_210(); + pos_scale(); + + void get_screen_pos_scale(mat4& mat, vec3& trans, bool apply_offset); }; struct struc_267 { @@ -3133,7 +3184,7 @@ struct struc_209 { struc_195 field_DF8[27]; struc_195 field_1230[27]; struc_195 field_1668[27]; - struc_210 field_1AA0[27]; + pos_scale field_1AA0[27]; float_t field_1BE4[27]; std::vector> field_1C50; int64_t field_1C68; @@ -3304,7 +3355,7 @@ struct rob_chara { float_t get_frame_count(); float_t get_max_face_depth(); int32_t get_rob_cmn_mottbl_motion_id(int32_t id); - bool get_visibility(); + bool is_visible(); void load_motion(int32_t motion_id, bool a3, float_t frame, MotionBlendType blend_type, bone_database* bone_data, motion_database* mot_db); void reset_data(rob_chara_pv_data* pv_data, diff --git a/src/CRE/stage.cpp b/src/CRE/stage.cpp index 4b463306..41c8c090 100644 --- a/src/CRE/stage.cpp +++ b/src/CRE/stage.cpp @@ -471,12 +471,12 @@ static bool stage_ctrl(stage* s) { return true; } - for (int32_t& i : s->auth_3d_ids) { - auth_3d_data_set_repeat(i, true); - auth_3d_data_set_paused(i, false); - auth_3d_data_set_enable(i, true); - auth_3d_data_set_visibility(i, s->effect_display); - auth_3d_data_set_frame_rate(i, 0); + for (auth_3d_id& i : s->auth_3d_ids) { + i.set_repeat(true); + i.set_paused(false); + i.set_enable(true); + i.set_visibility(s->effect_display); + i.set_frame_rate(0); } return false; } @@ -530,7 +530,7 @@ static void stage_disp(stage* s) { object_set_id, s->stage_data->lens_shaft_texture); pp->lens_ghost_texture = obj_database_get_obj_set_texture( object_set_id, s->stage_data->lens_ghost_texture); - pp->lens_flare_count = 16; + pp->lens_ghost_count = 16; pp->lens_shaft_inv_scale = s->stage_data->lens_shaft_inv_scale; } } @@ -661,8 +661,8 @@ static void stage_reset(stage* s) { s->rot_y = 0.0; s->obj_set = -1; - for (int32_t& i : s->auth_3d_ids) - auth_3d_data_unload_id(i, rctx_ptr); + for (auth_3d_id& i : s->auth_3d_ids) + i.unload_id(rctx_ptr); s->auth_3d_ids.clear(); s->auth_3d_ids.shrink_to_fit(); s->effect_display = true; diff --git a/src/CRE/stage.hpp b/src/CRE/stage.hpp index 3ea8e007..cb84423b 100644 --- a/src/CRE/stage.hpp +++ b/src/CRE/stage.hpp @@ -27,7 +27,7 @@ struct stage { uint32_t obj_set; // Temp - std::vector auth_3d_ids; + std::vector auth_3d_ids; bool effect_display; stage(); diff --git a/src/CRE/stage_modern.cpp b/src/CRE/stage_modern.cpp index 46946bad..96424854 100644 --- a/src/CRE/stage_modern.cpp +++ b/src/CRE/stage_modern.cpp @@ -451,12 +451,12 @@ static bool stage_modern_ctrl(stage_modern* s, void* data, object_database* obj_ return true; } - for (int32_t& i : s->auth_3d_ids) { - auth_3d_data_set_repeat(i, true); - auth_3d_data_set_paused(i, false); - auth_3d_data_set_enable(i, true); - auth_3d_data_set_visibility(i, s->effect_display); - auth_3d_data_set_frame_rate(i, 0); + for (auth_3d_id& i : s->auth_3d_ids) { + i.set_repeat(true); + i.set_paused(false); + i.set_enable(true); + i.set_visibility(s->effect_display); + i.set_frame_rate(0); } return false; } @@ -617,8 +617,8 @@ static void stage_modern_reset(stage_modern* s) { s->rot_y = 0.0; s->obj_set_hash = hash_murmurhash_empty; - for (int32_t& i : s->auth_3d_ids) - auth_3d_data_unload_id(i, rctx_ptr); + for (auth_3d_id& i : s->auth_3d_ids) + i.unload_id(rctx_ptr); s->auth_3d_ids.clear(); s->auth_3d_ids.shrink_to_fit(); s->effect_display = true; diff --git a/src/CRE/stage_modern.hpp b/src/CRE/stage_modern.hpp index d5e9bfcb..f904aab5 100644 --- a/src/CRE/stage_modern.hpp +++ b/src/CRE/stage_modern.hpp @@ -25,7 +25,7 @@ struct stage_modern { uint32_t obj_set_hash; // Temp - std::vector auth_3d_ids; + std::vector auth_3d_ids; bool effect_display; stage_modern(); diff --git a/src/CRE/task_effect.cpp b/src/CRE/task_effect.cpp index 89641e4d..aea34add 100644 --- a/src/CRE/task_effect.cpp +++ b/src/CRE/task_effect.cpp @@ -365,7 +365,7 @@ struc_621::~struc_621() { TaskEffectAuth3D::Stage::Stage() : auth_3d_ids() { count = 0; max_count = TASK_STAGE_STAGE_COUNT; - for (int32_t& i : auth_3d_ids) + for (auth_3d_id& i : auth_3d_ids) i = -1; auth_3d_ids_ptr = auth_3d_ids; } @@ -388,15 +388,15 @@ bool TaskEffectAuth3D::Init() { if (stage.count) { for (int32_t i = 0; i < stage.count; i++) - if (!auth_3d_data_check_id_loaded(stage.auth_3d_ids_ptr[i])) + if (!stage.auth_3d_ids_ptr[i].check_loaded()) return false; } for (int32_t i = 0; i < stage.count; i++) { - int32_t& id = stage.auth_3d_ids_ptr[i]; - auth_3d_data_set_repeat(id, true); - auth_3d_data_set_paused(id, false); - auth_3d_data_set_enable(id, true); + auth_3d_id& id = stage.auth_3d_ids_ptr[i]; + id.set_repeat(true); + id.set_paused(false); + id.set_enable(true); } //if (field_158) @@ -458,20 +458,20 @@ void TaskEffectAuth3D::SetStageHashes(std::vector& stage_hashes, void* v30.stage_hash = i; if (stage.count != stage.max_count) { - int32_t id = -1; + auth_3d_id id = {}; for (uint32_t j : stg_data->auth_3d_ids) { - id = -1; + id = {}; if (stage.count == stage.max_count) break; id = auth_3d_data_load_hash(j, data, obj_db, tex_db); - if (auth_3d_data_check_id_not_empty(id)) + if (id.check_not_empty()) break; } - if (id != -1) { - auth_3d_data_read_file_modern(id); - auth_3d_data_set_visibility(id, false); + if (id.not_null()) { + id.read_file_modern(); + id.set_visibility(false); if (stage.count + 1 <= stage.max_count) stage.auth_3d_ids_ptr[stage.count++] = id; v30.auth_3d_ids.push_back(id); @@ -498,20 +498,20 @@ void TaskEffectAuth3D::SetStageIndices(std::vector& stage_indices) { v30.stage_index = i; if (stage.count != stage.max_count) { - int32_t id = -1; + auth_3d_id id = -1; for (int32_t j : stage_data->auth_3d_ids) { id = -1; if (stage.count == stage.max_count) break; id = auth_3d_data_load_uid(j, aft_auth_3d_db); - if (auth_3d_data_check_id_not_empty(id)) + if (id.check_not_empty()) break; } - if (id != -1) { - auth_3d_data_read_file(id, aft_auth_3d_db); - auth_3d_data_set_visibility(id, false); + if (id.not_null()) { + id.read_file(aft_auth_3d_db); + id.set_visibility(false); if (stage.count + 1 <= stage.max_count) stage.auth_3d_ids_ptr[stage.count++] = id; v30.auth_3d_ids.push_back(id); @@ -525,14 +525,14 @@ void TaskEffectAuth3D::SetStageIndices(std::vector& stage_indices) { void TaskEffectAuth3D::SetFrame(int32_t value) { double_t frame = (double_t)value; for (int32_t i = 0; i < stage.count; i++) { - int32_t& id = stage.auth_3d_ids_ptr[i]; - float_t play_control_size = auth_3d_data_get_play_control_size(id); + 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); else req_frame = 0.0f; - auth_3d_data_set_req_frame(id, req_frame); + id.set_req_frame(req_frame); } } @@ -556,24 +556,24 @@ void TaskEffectAuth3D::SetCurrentStageIndex(int32_t value) { void TaskEffectAuth3D::SetFrameRateControl(FrameRateControl* value) { for (int32_t i = 0; i < stage.count; i++) { - int32_t& id = stage.auth_3d_ids_ptr[i]; - auth_3d_data_set_frame_rate(id, value); + auth_3d_id& id = stage.auth_3d_ids_ptr[i]; + id.set_frame_rate(value); } } void TaskEffectAuth3D::Reset() { for (int32_t i = 0; i < stage.count; i++) { - int32_t& id = stage.auth_3d_ids_ptr[i]; - auth_3d_data_set_enable(id, true); - auth_3d_data_set_paused(id, false); - auth_3d_data_set_req_frame(id, 0.0f); + auth_3d_id& id = stage.auth_3d_ids_ptr[i]; + id.set_enable(true); + id.set_paused(false); + id.set_req_frame(0.0f); } } void TaskEffectAuth3D::ResetData() { for (int32_t i = 0; i < stage.count; i++) { - int32_t& id = stage.auth_3d_ids_ptr[i]; - auth_3d_data_unload_id(id, rctx_ptr); + auth_3d_id& id = stage.auth_3d_ids_ptr[i]; + id.unload_id(rctx_ptr); } stage.count = 0; enable = false; @@ -594,8 +594,8 @@ void TaskEffectAuth3D::SetVisibility(bool value) { if (i.stage_index != current_stage_index) continue; - for (int32_t& j : i.auth_3d_ids) - auth_3d_data_set_visibility(j, value); + for (auth_3d_id& j : i.auth_3d_ids) + j.set_visibility(value); break; } else if (current_stage_hash != -1 && current_stage_hash @@ -604,8 +604,8 @@ void TaskEffectAuth3D::SetVisibility(bool value) { if (i.stage_hash != current_stage_hash) continue; - for (int32_t& j : i.auth_3d_ids) - auth_3d_data_set_visibility(j, value); + for (auth_3d_id& j : i.auth_3d_ids) + j.set_visibility(value); break; } } diff --git a/src/CRE/task_effect.hpp b/src/CRE/task_effect.hpp index e1c91e58..c67c7c23 100644 --- a/src/CRE/task_effect.hpp +++ b/src/CRE/task_effect.hpp @@ -78,7 +78,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(); @@ -89,8 +89,8 @@ public: struct Stage { size_t count; size_t max_count; - int32_t* auth_3d_ids_ptr; - int32_t auth_3d_ids[TASK_STAGE_STAGE_COUNT]; + auth_3d_id* auth_3d_ids_ptr; + auth_3d_id auth_3d_ids[TASK_STAGE_STAGE_COUNT]; Stage(); } stage; diff --git a/src/KKdLib/a3da.cpp b/src/KKdLib/a3da.cpp index 7ffaa1b7..a0ff5c52 100644 --- a/src/KKdLib/a3da.cpp +++ b/src/KKdLib/a3da.cpp @@ -2304,7 +2304,7 @@ static bool key_val_read(key_val* kv, } switch (type) { - case 0: { + case KEY_FRAME_TYPE_0: { float_t f; if (sscanf_s(data, "%g", &f) == 1) k = { f, 0.0f, 0.0f, 0.0f }; @@ -2312,7 +2312,7 @@ static bool key_val_read(key_val* kv, k = { 0.0f, 0.0f, 0.0f, 0.0f }; value.keys.push_back(k); } break; - case 1: { + case KEY_FRAME_TYPE_1: { float_t f; float_t v; if (sscanf_s(data, "(%g,%g)", &f, &v) == 2) @@ -2321,7 +2321,7 @@ static bool key_val_read(key_val* kv, k = { 0.0f, 0.0f, 0.0f, 0.0f }; value.keys.push_back(k); } break; - case 2: { + case KEY_FRAME_TYPE_2: { float_t f; float_t v; float_t t; @@ -2331,7 +2331,7 @@ static bool key_val_read(key_val* kv, k = { 0.0f, 0.0f, 0.0f, 0.0f }; value.keys.push_back(k); } break; - case 3: { + case KEY_FRAME_TYPE_3: { float_t f; float_t v; float_t t1; diff --git a/src/KKdLib/alloc_data.hpp b/src/KKdLib/alloc_data.hpp index 068fcede..dc1fbfdf 100644 --- a/src/KKdLib/alloc_data.hpp +++ b/src/KKdLib/alloc_data.hpp @@ -35,7 +35,10 @@ struct alloc_data { if (!size) return 0; - return new((T*)allocate(sizeof(T) * size)) T; + T* arr = (T*)allocate(sizeof(T) * size); + for (size_t i = 0; i < size; i++) + new(&arr[i]) T(); + return arr; } template diff --git a/src/KKdLib/interpolation.cpp b/src/KKdLib/interpolation.cpp index c495e8bb..8e7da8b2 100644 --- a/src/KKdLib/interpolation.cpp +++ b/src/KKdLib/interpolation.cpp @@ -141,7 +141,7 @@ int32_t interpolate_chs_reverse_sequence(std::vector& values_src, std:: if (left_count > 1) { float_t _t2 = t2_old; for (size_t j = 0; j < left_count - 1; j++) { - values.push_back({ (float_t)(frame + j), a[j], _t2, 0.0f }); + values.push_back({ (float_t)(int32_t)(frame + j), a[j], _t2, 0.0f }); _t2 = 0.0f; } t2_old = 0.0f; @@ -174,7 +174,7 @@ int32_t interpolate_chs_reverse_sequence(std::vector& values_src, std:: t2 = (float_t)(tt2 / (double_t)(i - 2)); has_error = false; - for (size_t j = 1; j <= i - 1; j++) { + for (size_t j = 1; j < i; j++) { float_t val = interpolate_chs_value(a[0], a[i], t1, t2, 0.0f, (float_t)i, (float_t)j); if (fabsf(val - a[j]) > reverse_bias) { has_error = true; @@ -252,6 +252,36 @@ int32_t interpolate_chs_reverse_sequence(std::vector& values_src, std:: left_count -= c; } - values.push_back({ (float_t)(start_time + (count - 1)), arr[count - 1], t2_old, 0.0f }); + values.push_back({ (float_t)(int32_t)(start_time + (count - 1)), arr[count - 1], t2_old, 0.0f }); + + kft3* keys = values.data(); + size_t length = values.size(); + for (size_t i = 0; i < count; i++) { + float_t frame = (float_t)(int32_t)i; + + kft3* first_key = keys; + kft3* key = keys; + size_t _length = length; + size_t temp; + while (_length > 0) + if (frame < key[temp = _length / 2].frame) + _length = temp; + else { + key += temp + 1; + _length -= temp + 1; + } + + float_t val; + if (key == first_key) + val = first_key->value; + else if (key == &first_key[length]) + val = key[-1].value; + else + val = interpolate_linear_value(key[-1].value, key[0].value, + key[-1].frame, key[0].frame, frame); + + if (fabsf(val - arr[i]) > reverse_bias) + return 3; + } return 2; } diff --git a/src/KKdLib/mat.hpp b/src/KKdLib/mat.hpp index 0fdd5ded..c4a1ed25 100644 --- a/src/KKdLib/mat.hpp +++ b/src/KKdLib/mat.hpp @@ -180,6 +180,10 @@ inline void mat3_scale(const vec3* s, mat3* d) { mat3_scale(s->x, s->y, s->z, d); } +inline void mat3_scale_mult(const mat3* s, float_t y, mat3* d) { + mat3_scale_mult(s, y, y, y, d); +} + inline void mat3_scale_mult(const mat3* s, const vec3* y, mat3* d) { mat3_scale_mult(s, y->x, y->y, y->z, d); } @@ -196,10 +200,18 @@ inline void mat4_scale(const vec3* s, mat4* d) { mat4_scale(s->x, s->y, s->z, d); } -inline void mat4_scale_mult(const mat4* s, const vec4* y, mat4* d) { +inline void mat4_scale_mult(const mat4* s, float_t y, mat4* d) { + mat4_scale_mult(s, y, y, y, y, d); +} + +inline void mat4_scale_mult(const mat4* s, vec4* y, mat4* d) { mat4_scale_mult(s, y->x, y->y, y->z, y->w, d); } +inline void mat4_scale_rot(const mat4* s, const float_t y, mat4* d) { + mat4_scale_rot(s, y, y, y, d); +} + inline void mat4_scale_rot(const mat4* s, const vec3* y, mat4* d) { mat4_scale_rot(s, y->x, y->y, y->z, d); } diff --git a/src/KKdLib/mot.cpp b/src/KKdLib/mot.cpp index 6369d7ae..ae237d33 100644 --- a/src/KKdLib/mot.cpp +++ b/src/KKdLib/mot.cpp @@ -30,16 +30,14 @@ struct mot_header_modern { int32_t bone_info_count; }; -static void mot_classic_read_inner(mot_set* ms, stream& s); +static void mot_classic_read_inner(mot_set* ms, prj::shared_ptr& alloc, stream& s); static void mot_classic_write_inner(mot_set* ms, stream& s); -static void mot_modern_read_inner(mot_set* ms, stream& s); +static void mot_modern_read_inner(mot_set* ms, prj::shared_ptr& alloc, stream& s); static void mot_modern_write_inner(mot_set* ms, stream& s); +static const char* mot_read_utf8_string_null_terminated_offset( + prj::shared_ptr& alloc, stream& s, int64_t offset); -mot_bone_info::mot_bone_info() : index() { - -} - -mot_bone_info::~mot_bone_info() { +mot_bone_info::mot_bone_info() : name(), index() { } @@ -47,24 +45,12 @@ mot_key_set_data::mot_key_set_data() : type(), frames(), values(), keys_count(), } -mot_key_set_data::~mot_key_set_data() { +mot_data::mot_data() : info(), frame_count(), bone_info_count(), murmurhash(), +div_frames(), div_count(), name(), bone_info_array(), key_set_array() { } -mot_data::mot_data() : info(), frame_count(), bone_info_count(), -murmurhash(), div_frames(), div_count(), bone_info(), key_set() { - -} - -mot_data::~mot_data() { - -} - -mot_set::mot_set() : ready(), modern(), big_endian(), is_x() { - -} - -mot_set::~mot_set() { +mot_set::mot_set() : ready(), modern(), big_endian(), is_x(), name(), mot_data(), mot_num() { } @@ -81,16 +67,16 @@ void mot_set::pack_file(void** data, size_t* size) { s.copy(data, size); } -void mot_set::unpack_file(const void* data, size_t size, bool modern) { +void mot_set::unpack_file(prj::shared_ptr alloc, const void* data, size_t size, bool modern) { if (!data || !size) return; memory_stream s; s.open(data, size); if (!modern) - mot_classic_read_inner(this, s); + mot_classic_read_inner(this, alloc, s); else - mot_modern_read_inner(this, s); + mot_modern_read_inner(this, alloc, s); } inline static float_t interpolate_mot_value(float_t p1, float_t p2, @@ -156,6 +142,36 @@ inline static float_t mot_set_add_key(bool has_error, float_t* a, int32_t frame, } } +mot_key_set_type mot_set::fit_keys_into_curve(std::vector& values_src, + prj::shared_ptr alloc, uint16_t*& frames, float_t*& values, size_t& keys_count) { + std::vector _frames; + std::vector _values; + mot_key_set_type type = mot_set::fit_keys_into_curve(values_src, _frames, _values); + switch (type) { + case MOT_KEY_SET_NONE: + keys_count = 0; + frames = 0; + values = 0; + break; + case MOT_KEY_SET_STATIC: + keys_count = 1; + frames = 0; + values = alloc->allocate(_values.data(), 1); + break; + case MOT_KEY_SET_HERMITE: + keys_count = _frames.size(); + frames = alloc->allocate(_frames.data(), keys_count); + values = alloc->allocate(_values.data(), keys_count); + break; + case MOT_KEY_SET_HERMITE_TANGENT: + keys_count = _frames.size(); + frames = alloc->allocate(_frames.data(), keys_count); + values = alloc->allocate(_values.data(), keys_count * 2); + break; + } + return type; +} + mot_key_set_type mot_set::fit_keys_into_curve(std::vector& values_src, std::vector& frames, std::vector& values) { size_t count = values_src.size(); @@ -230,7 +246,7 @@ mot_key_set_type mot_set::fit_keys_into_curve(std::vector& values_src, t2 = (float_t)(tt2 / (double_t)(i - 2)); has_error = false; - for (size_t j = 1; j < i - 1; j++) { + for (size_t j = 1; j < i; j++) { float_t val = interpolate_mot_value(a[0], a[i], t1, t2, 0.0f, (float_t)i, (float_t)j); if (fabsf(val - a[j]) > reverse_bias) { has_error = true; @@ -295,10 +311,10 @@ mot_key_set_type mot_set::fit_keys_into_curve(std::vector& values_src, mot_set_add_key((uint16_t)(start_time + (count - 1)), arr[count - 1], 0.0f, frames, values); - count = values.size() / 2; + count = frames.size(); arr = values.data(); - for (size_t i = count; i; i--) - if (*arr++ != 0.0f) + for (size_t i = count; i; i--, arr += 2) + if (arr[1] != 0.0f) break; if (arr != values.data() + count) @@ -315,94 +331,100 @@ mot_key_set_type mot_set::fit_keys_into_curve(std::vector& values_src, return MOT_KEY_SET_HERMITE; } -static void mot_classic_read_inner(mot_set* ms, stream& s) { +static void mot_classic_read_inner(mot_set* ms, prj::shared_ptr& alloc, stream& s) { size_t count = 0; while (s.read_uint64_t() != 0) { s.read_uint64_t(); count++; } - if (count == 0) { + if (!count) { ms->ready = false; ms->modern = false; ms->big_endian = false; ms->is_x = false; + return; } + uint32_t mot_num = (uint32_t)count; + ::mot_data* mot_data = alloc->allocate<::mot_data>(mot_num); + ms->mot_data = mot_data; + ms->mot_num = mot_num; + s.set_position(0x00, SEEK_SET); - ms->vec.resize(count); - mot_header_classic* mh = force_malloc_s(mot_header_classic, count); - for (size_t i = 0; i < count; i++) { + mot_header_classic* mh = force_malloc_s(mot_header_classic, mot_num); + for (uint32_t i = 0; i < mot_num; i++) { mh[i].key_set_info_offset = s.read_uint32_t(); mh[i].key_set_types_offset = s.read_uint32_t(); mh[i].key_set_offset = s.read_uint32_t(); mh[i].bone_info_offset = s.read_uint32_t(); } - for (size_t i = 0; i < count; i++) { - mot_data* m = &ms->vec[i]; + for (size_t i = 0; i < mot_num; i++) { + ::mot_data* m = &ms->mot_data[i]; s.set_position(mh[i].bone_info_offset, SEEK_SET); - m->bone_info_count = 0; + uint32_t bone_info_count = 0; s.read_uint16_t(); do - m->bone_info_count++; + bone_info_count++; while (s.read_uint16_t() != 0 && s.get_position() < s.length); + m->bone_info_count = bone_info_count; + + mot_bone_info* bone_info_array = alloc->allocate(bone_info_count); + m->bone_info_array = bone_info_array; s.set_position(mh[i].bone_info_offset, SEEK_SET); - m->bone_info.resize(m->bone_info_count); for (size_t j = 0; j < m->bone_info_count; j++) - m->bone_info[j].index = s.read_uint16_t(); + bone_info_array[j].index = s.read_uint16_t(); s.set_position(mh[i].key_set_info_offset, SEEK_SET); m->info = s.read_uint16_t(); m->frame_count = s.read_uint16_t(); - m->key_set.resize(m->key_set_count); + uint32_t key_set_count = m->key_set_count; + mot_key_set_data* key_set_array = alloc->allocate(key_set_count); + m->key_set_array = key_set_array; + s.set_position(mh[i].key_set_types_offset, SEEK_SET); for (int32_t j = 0, b = 0; j < m->key_set_count; j++) { if (j % 8 == 0) b = s.read_uint16_t(); - m->key_set[j].type = (mot_key_set_type)((b >> (j % 8 * 2)) & 0x03); + key_set_array[j].type = (mot_key_set_type)((b >> (j % 8 * 2)) & 0x03); } s.set_position(mh[i].key_set_offset, SEEK_SET); for (int32_t j = 0; j < m->key_set_count; j++) { - mot_key_set_data* mks = &m->key_set[j]; - if (mks->type == MOT_KEY_SET_NONE) { - mks->keys_count = 0; - mks->frames.resize(0); - mks->values.resize(0); + mot_key_set_data* key_set = &key_set_array[j]; + if (key_set->type == MOT_KEY_SET_NONE) { + key_set->keys_count = 0; + key_set->frames = 0; + key_set->values = 0; } - else if (mks->type == MOT_KEY_SET_STATIC) { - mks->keys_count = 1; - mks->frames.resize(0); - mks->values.resize(1); - mks->values[0] = s.read_float_t(); + else if (key_set->type == MOT_KEY_SET_STATIC) { + key_set->keys_count = 1; + key_set->frames = 0; + key_set->values = alloc->allocate(1); + key_set->values[0] = s.read_float_t(); } else { - bool has_tangents = mks->type != MOT_KEY_SET_HERMITE; + bool has_tangents = key_set->type != MOT_KEY_SET_HERMITE; uint16_t keys_count = s.read_uint16_t(); - mks->keys_count = keys_count; + key_set->keys_count = keys_count; - mks->frames.resize(keys_count); - mks->values.resize(has_tangents ? keys_count * 2ULL : keys_count); + uint16_t* frames = alloc->allocate(keys_count); + float_t* values = alloc->allocate(has_tangents ? keys_count * 2ULL : keys_count); + key_set->frames = frames; + key_set->values = values; - uint16_t* frames = mks->frames.data(); - for (int32_t k = 0; k < keys_count; k++) - *frames++ = s.read_uint16_t(); + s.read(frames, sizeof(uint16_t) * keys_count); s.align_read(0x04); - float_t* values = mks->values.data(); if (!has_tangents) - for (int32_t k = 0; k < keys_count; k++) - *values++ = s.read_float_t(); + s.read(values, sizeof(float_t) * keys_count); else - for (int32_t k = 0; k < keys_count; k++) { - *values++ = s.read_float_t(); - *values++ = s.read_float_t(); - } + s.read(values, sizeof(float_t) * keys_count * 2ULL); } } } @@ -415,21 +437,26 @@ static void mot_classic_read_inner(mot_set* ms, stream& s) { } static void mot_classic_write_inner(mot_set* ms, stream& s) { - size_t count = ms->vec.size(); - s.set_position(count * 0x10 + 0x10, SEEK_SET); - mot_header_classic* mh = force_malloc_s(mot_header_classic, count); - for (size_t i = 0; i < count; i++) { - mot_data* m = &ms->vec[i]; + ::mot_data* mot_data = ms->mot_data; + uint32_t mot_num = ms->mot_num; + + s.set_position(mot_num * 0x10ULL + 0x10, SEEK_SET); + mot_header_classic* mh = force_malloc_s(mot_header_classic, mot_num); + for (size_t i = 0; i < mot_num; i++) { + ::mot_data* m = &mot_data[i]; mh[i].key_set_info_offset = (uint32_t)s.get_position(); s.write_uint16_t(m->info); s.write_uint16_t(m->frame_count); + uint16_t key_set_count = m->key_set_count; + mot_key_set_data* key_set_array = m->key_set_array; + mh[i].key_set_types_offset = (uint32_t)s.get_position(); uint16_t key_set_type_buf = 0; - for (int32_t j = 0; j < m->key_set_count; j++) { - mot_key_set_type type = m->key_set[j].type; - if (type == MOT_KEY_SET_STATIC && m->key_set[j].values[0] == 0.0f) + for (uint32_t j = 0; j < key_set_count; j++) { + mot_key_set_type type = key_set_array[j].type; + if (type == MOT_KEY_SET_STATIC && key_set_array[j].values[0] == 0.0f) type = MOT_KEY_SET_NONE; key_set_type_buf |= ((uint16_t)type & 0x03) << (j % 8 * 2); @@ -445,34 +472,37 @@ static void mot_classic_write_inner(mot_set* ms, stream& s) { s.align_write(0x04); mh[i].key_set_offset = (uint32_t)s.get_position(); - for (int32_t j = 0; j < m->key_set_count; j++) { - mot_key_set_data* mks = &m->key_set[j]; - if (mks->type == MOT_KEY_SET_STATIC) { - if (mks->values[0] != 0.0f) - s.write_float_t(mks->values[0]); + for (uint32_t j = 0; j < key_set_count; j++) { + mot_key_set_data* key_set = &key_set_array[j]; + if (key_set->type == MOT_KEY_SET_STATIC) { + if (key_set->values[0] != 0.0f) + s.write_float_t(key_set->values[0]); } - else if (mks->type != MOT_KEY_SET_NONE) { - bool has_tangents = mks->type != MOT_KEY_SET_HERMITE; - uint16_t keys_count = mks->keys_count; + else if (key_set->type != MOT_KEY_SET_NONE) { + bool has_tangents = key_set->type != MOT_KEY_SET_HERMITE; + uint16_t keys_count = key_set->keys_count; s.write_uint16_t(keys_count); - uint16_t* frames = mks->frames.data(); + uint16_t* frames = key_set->frames; s.write(frames, sizeof(uint16_t) * keys_count); s.align_write(0x04); - float_t* values = mks->values.data(); + float_t* values = key_set->values; if (!has_tangents) s.write(values, sizeof(float_t) * keys_count); else - s.write(values, sizeof(float_t) * keys_count * 2); + s.write(values, sizeof(float_t) * keys_count * 2ULL); } } s.align_write(0x04); + uint16_t bone_info_count = m->bone_info_count; + mot_bone_info* bone_info_array = m->bone_info_array; + mh[i].bone_info_offset = (uint32_t)s.get_position(); if (m->bone_info_count) - for (int32_t j = 0; j < m->bone_info_count; j++) - s.write_uint16_t(m->bone_info[j].index); + for (int32_t j = 0; j < bone_info_count; j++) + s.write_uint16_t(bone_info_array[j].index); else s.write_uint16_t(0x00); s.write_uint16_t(0x00); @@ -480,7 +510,7 @@ static void mot_classic_write_inner(mot_set* ms, stream& s) { s.align_write(0x10); s.set_position(0x00, SEEK_SET); - for (size_t i = 0; i < count; i++) { + for (size_t i = 0; i < mot_num; i++) { s.write_uint32_t(mh[i].key_set_info_offset); s.write_uint32_t(mh[i].key_set_types_offset); s.write_uint32_t(mh[i].key_set_offset); @@ -489,7 +519,7 @@ static void mot_classic_write_inner(mot_set* ms, stream& s) { free_def(mh); } -static void mot_modern_read_inner(mot_set* ms, stream& s) { +static void mot_modern_read_inner(mot_set* ms, prj::shared_ptr& alloc, stream& s) { f2_struct st; st.read(s); if (st.header.signature != reverse_endianness_uint32_t('MOTC') || !st.data.size()) { @@ -509,8 +539,11 @@ static void mot_modern_read_inner(mot_set* ms, stream& s) { s_motc.set_position(0x0C, SEEK_SET); bool is_x = s_motc.read_uint32_t_reverse_endianness() == 0; + ::mot_data* mot_data = alloc->allocate<::mot_data>(); + ms->mot_data = mot_data; + ms->mot_num = 1; + s_motc.set_position(0x00, SEEK_SET); - ms->vec.resize(1); mot_header_modern mh = {}; if (!is_x) { mh.hash = (uint32_t)s_motc.read_uint64_t_reverse_endianness(); @@ -533,23 +566,26 @@ static void mot_modern_read_inner(mot_set* ms, stream& s) { mh.bone_info_count = s_motc.read_int32_t_reverse_endianness(); } - mot_data* m = &ms->vec[0]; + ::mot_data* m = &mot_data[0]; m->div_frames = s_motc.read_uint16_t_reverse_endianness(); m->div_count = s_motc.read_uint8_t(); - m->name = s_motc.read_string_null_terminated_offset(mh.name_offset); + m->name = mot_read_utf8_string_null_terminated_offset(alloc, s_motc, mh.name_offset); + + uint32_t bone_info_count = mh.bone_info_count; + mot_bone_info* bone_info_array = alloc->allocate(bone_info_count); + m->bone_info_array = bone_info_array; + m->bone_info_count = bone_info_count; s_motc.set_position(mh.bone_info_offset, SEEK_SET); - m->bone_info_count = mh.bone_info_count; - m->bone_info.resize(m->bone_info_count); if (!is_x) for (size_t j = 0; j < mh.bone_info_count; j++) - m->bone_info[j].name = s_motc.read_string_null_terminated_offset( - s_motc.read_offset_f2(st.header.length)); + bone_info_array[j].name = mot_read_utf8_string_null_terminated_offset(alloc, + s_motc, s_motc.read_offset_f2(st.header.length)); else for (size_t j = 0; j < mh.bone_info_count; j++) - m->bone_info[j].name = s_motc.read_string_null_terminated_offset( - s_motc.read_offset_x()); + bone_info_array[j].name = mot_read_utf8_string_null_terminated_offset(alloc, + s_motc, s_motc.read_offset_x()); s_motc.set_position(mh.bone_hash_offset, SEEK_SET); for (size_t j = 0; j < mh.bone_info_count; j++) @@ -559,48 +595,52 @@ static void mot_modern_read_inner(mot_set* ms, stream& s) { m->info = s_motc.read_uint16_t_reverse_endianness(); m->frame_count = s_motc.read_uint16_t_reverse_endianness(); - m->key_set.resize(m->key_set_count); + uint32_t key_set_count = m->key_set_count; + mot_key_set_data* key_set_array = alloc->allocate(key_set_count); + m->key_set_array = key_set_array; + s_motc.set_position(mh.key_set_types_offset, SEEK_SET); - for (int32_t j = 0, b = 0; j < m->key_set_count; j++) { + for (uint32_t j = 0, b = 0; j < key_set_count; j++) { if (j % 8 == 0) b = s_motc.read_uint16_t_reverse_endianness(); - m->key_set[j].type = (mot_key_set_type)((b >> (j % 8 * 2)) & 0x03); + key_set_array[j].type = (mot_key_set_type)((b >> (j % 8 * 2)) & 0x03); } s_motc.set_position(mh.key_set_offset, SEEK_SET); - for (int32_t j = 0; j < m->key_set_count; j++) { - mot_key_set_data* mks = &m->key_set[j]; - if (mks->type == MOT_KEY_SET_NONE) { - mks->keys_count = 0; - mks->frames.resize(0); - mks->values.resize(0); + for (uint32_t j = 0; j < key_set_count; j++) { + mot_key_set_data* key_set = &key_set_array[j]; + if (key_set->type == MOT_KEY_SET_NONE) { + key_set->keys_count = 0; + key_set->frames = 0; + key_set->values = 0; } - else if (mks->type == MOT_KEY_SET_STATIC) { - mks->keys_count = 1; - mks->frames.resize(0); - mks->values.resize(1); - mks->values[0] = s_motc.read_float_t_reverse_endianness(); + else if (key_set->type == MOT_KEY_SET_STATIC) { + key_set->keys_count = 1; + key_set->frames = 0; + key_set->values = alloc->allocate(1); + key_set->values[0] = s.read_float_t(); } else { - bool has_tangents = mks->type != MOT_KEY_SET_HERMITE; + bool has_tangents = 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(); - mks->keys_count = keys_count; - mks->data_type = data_type; + key_set->keys_count = keys_count; + key_set->data_type = data_type; - mks->frames.resize(keys_count); - mks->values.resize(has_tangents ? keys_count * 2ULL : keys_count); + int16_t* frames = alloc->allocate(keys_count); + float_t* values = alloc->allocate(has_tangents ? 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) { - float_t* values = &mks->values[1]; + 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(); } - float_t* values = mks->values.data(); if (data_type == MOT_KEY_SET_DATA_F16) for (int32_t k = 0; k < keys_count; k++, values += step) *values = half_to_float(s_motc.read_half_t_reverse_endianness()); @@ -609,7 +649,6 @@ static void mot_modern_read_inner(mot_set* ms, stream& s) { *values = s_motc.read_float_t_reverse_endianness(); s_motc.align_read(0x04); - int16_t* frames = (int16_t*)mks->frames.data(); for (int32_t k = 0; k < keys_count; k++) *frames++ = s_motc.read_int16_t_reverse_endianness(); s_motc.align_read(0x04); @@ -628,6 +667,9 @@ static void mot_modern_write_inner(mot_set* ms, stream& s) { bool big_endian = ms->big_endian; bool is_x = ms->is_x; + ::mot_data* mot_data = ms->mot_data; + uint32_t mot_num = ms->mot_num; + memory_stream s_motc; s_motc.open(); s_motc.big_endian = big_endian; @@ -637,9 +679,9 @@ static void mot_modern_write_inner(mot_set* ms, stream& s) { enrs_entry ee; pof pof; uint32_t murmurhash = 0; - if (ms->vec.size() > 0) { + if (mot_num > 0) { mot_header_modern mh = {}; - mot_data* m = &ms->vec[0]; + ::mot_data* m = &mot_data[0]; if (!is_x) { ee = { 0, 3, 48, 1 }; @@ -663,31 +705,36 @@ static void mot_modern_write_inner(mot_set* ms, stream& s) { e.vec.push_back(ee); o = 4; - ee = { o, 1, (uint32_t)((m->key_set_count + 3ULL) / 4), 1 }; - ee.append(0, (uint32_t)((m->key_set_count + 7ULL) / 8), ENRS_WORD); + uint32_t key_set_count = m->key_set_count; + uint16_t bone_info_count = m->bone_info_count; + + mot_key_set_data* key_set_array = m->key_set_array; + + ee = { o, 1, (uint32_t)((key_set_count + 3ULL) / 4), 1 }; + ee.append(0, (uint32_t)((key_set_count + 7ULL) / 8), ENRS_WORD); e.vec.push_back(ee); - o = (m->key_set_count + 3) / 4; + o = (key_set_count + 3) / 4; o = align_val(o, 4); - for (int32_t j = 0; j < m->key_set_count; j++) { - mot_key_set_data* mks = &m->key_set[j]; - if (mks->type == MOT_KEY_SET_STATIC) { - if (mks->values[0] != 0.0f) { + for (uint32_t j = 0; j < key_set_count; j++) { + mot_key_set_data* key_set = &key_set_array[j]; + if (key_set->type == MOT_KEY_SET_STATIC) { + if (key_set->values[0] != 0.0f) { ee = { o, 1, 4, 1 }; ee.append(0, 1, ENRS_DWORD); e.vec.push_back(ee); o = 4; } } - else if (mks->type != MOT_KEY_SET_NONE) { - bool has_tangents = mks->type != MOT_KEY_SET_HERMITE; + else if (key_set->type != MOT_KEY_SET_NONE) { + bool has_tangents = key_set->type != MOT_KEY_SET_HERMITE; if (has_tangents) ee = { o, 1, 4, 1 }; else ee = { o, 1, 3, 1 }; - uint16_t keys_count = mks->keys_count; - mot_key_set_data_type data_type = mks->data_type; + uint16_t keys_count = key_set->keys_count; + mot_key_set_data_type data_type = key_set->data_type; o = 4; if (has_tangents) o += keys_count * 4; @@ -717,23 +764,23 @@ static void mot_modern_write_inner(mot_set* ms, stream& s) { o = align_val(o, 16); if (!is_x) { - ee = { o, 1, (uint32_t)(m->bone_info_count * 4ULL), 1 }; - ee.append(0, (uint32_t)m->bone_info_count, ENRS_DWORD); + ee = { o, 1, (uint32_t)(bone_info_count * 4ULL), 1 }; + ee.append(0, bone_info_count, ENRS_DWORD); e.vec.push_back(ee); o = m->bone_info_count * 4; } else { - ee = { o, 1, (uint32_t)(m->bone_info_count * 8ULL), 1 }; - ee.append(0, (uint32_t)m->bone_info_count, ENRS_QWORD); + ee = { o, 1, (uint32_t)(bone_info_count * 8ULL), 1 }; + ee.append(0, bone_info_count, ENRS_QWORD); e.vec.push_back(ee); o = m->bone_info_count * 8; } o = align_val(o, 16); - ee = { o, 1,(uint32_t)(m->bone_info_count * 8ULL), 1 }; - ee.append(0, (uint32_t)m->bone_info_count, ENRS_QWORD); + ee = { o, 1,(uint32_t)(bone_info_count * 8ULL), 1 }; + ee.append(0, bone_info_count, ENRS_QWORD); e.vec.push_back(ee); - o = m->bone_info_count * 8; + o = bone_info_count * 8; if (!is_x) { s_motc.write_uint64_t(0); @@ -768,9 +815,9 @@ static void mot_modern_write_inner(mot_set* ms, stream& s) { mh.key_set_types_offset = s_motc.get_position(); uint16_t key_set_type_buf = 0; - for (int32_t j = 0; j < m->key_set_count; j++) { - mot_key_set_type type = m->key_set[j].type; - if (type == MOT_KEY_SET_STATIC && m->key_set[j].values[0] == 0.0f) + for (uint32_t j = 0; j < key_set_count; j++) { + mot_key_set_type type = key_set_array[j].type; + if (type == MOT_KEY_SET_STATIC && key_set_array[j].values[0] == 0.0f) type = MOT_KEY_SET_NONE; key_set_type_buf |= ((uint16_t)type & 0x03) << (j % 8 * 2); @@ -787,26 +834,26 @@ static void mot_modern_write_inner(mot_set* ms, stream& s) { mh.key_set_offset = s_motc.get_position(); for (int32_t j = 0; j < m->key_set_count; j++) { - mot_key_set_data* mks = &m->key_set[j]; - if (mks->type == MOT_KEY_SET_STATIC) { - if (mks->values[0] != 0.0f) - s.write_float_t_reverse_endianness(mks->values[0]); + mot_key_set_data* key_set = &key_set_array[j]; + if (key_set->type == MOT_KEY_SET_STATIC) { + if (key_set->values[0] != 0.0f) + s.write_float_t_reverse_endianness(key_set->values[0]); } - else if (mks->type != MOT_KEY_SET_NONE) { - bool has_tangents = mks->type != MOT_KEY_SET_HERMITE; - uint16_t keys_count = mks->keys_count; - mot_key_set_data_type data_type = mks->data_type; + else if (key_set->type != MOT_KEY_SET_NONE) { + bool has_tangents = 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) { - float_t* values = &mks->values[1]; + 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); } - float_t* values = mks->values.data(); + float_t* values = key_set->values; if (data_type == MOT_KEY_SET_DATA_F16) for (int32_t k = 0; k < keys_count; k++, values += step) s_motc.write_half_t_reverse_endianness(float_to_half(*values)); @@ -815,7 +862,7 @@ static void mot_modern_write_inner(mot_set* ms, stream& s) { s_motc.write_float_t_reverse_endianness(*values); s_motc.align_write(0x04); - int16_t* frames = (int16_t*)mks->frames.data(); + int16_t* frames = (int16_t*)key_set->frames; for (int32_t k = 0; k < keys_count; k++) s_motc.write_int16_t_reverse_endianness(*frames++); s_motc.align_write(0x04); @@ -823,37 +870,39 @@ static void mot_modern_write_inner(mot_set* ms, stream& s) { } s_motc.align_write(0x10); - size_t* bone_info_offsets = force_malloc_s(size_t, m->bone_info_count); + mot_bone_info* bone_info_array = m->bone_info_array; + + size_t* bone_info_offsets = force_malloc_s(size_t, bone_info_count); mh.bone_info_offset = s_motc.get_position(); if (!is_x) - for (int32_t j = 0; j < m->bone_info_count; j++) + for (int32_t j = 0; j < bone_info_count; j++) io_write_offset_f2_pof_add(s_motc, 0, 0x40, &pof); else - for (int32_t j = 0; j < m->bone_info_count; j++) + for (int32_t j = 0; j < bone_info_count; j++) io_write_offset_x_pof_add(s_motc, 0, &pof); s_motc.align_write(0x10); mh.bone_hash_offset = s_motc.get_position(); - for (int32_t j = 0; j < m->bone_info_count; j++) - s_motc.write_uint64_t_reverse_endianness(hash_string_murmurhash(m->bone_info[j].name)); + for (int32_t j = 0; j < bone_info_count; j++) + s_motc.write_uint64_t_reverse_endianness(hash_string_murmurhash(bone_info_array[j].name)); s_motc.align_write(0x10); mh.name_offset = s_motc.get_position(); s_motc.write_string_null_terminated(m->name); - for (int32_t j = 0; j < m->bone_info_count; j++) { + for (int32_t j = 0; j < bone_info_count; j++) { bone_info_offsets[j] = s_motc.get_position(); - s_motc.write_string_null_terminated(m->bone_info[j].name); + s_motc.write_string_null_terminated(bone_info_array[j].name); } s_motc.align_write(0x10); s_motc.set_position(mh.bone_info_offset, SEEK_SET); - mh.bone_info_count = m->bone_info_count; + mh.bone_info_count = bone_info_count; if (!is_x) - for (int32_t j = 0; j < m->bone_info_count; j++) + for (int32_t j = 0; j < bone_info_count; j++) s_motc.write_offset_f2(bone_info_offsets[j], 0x40); else - for (int32_t j = 0; j < m->bone_info_count; j++) + for (int32_t j = 0; j < bone_info_count; j++) s_motc.write_offset_x(bone_info_offsets[j]); free_def(bone_info_offsets); @@ -908,3 +957,14 @@ static void mot_modern_write_inner(mot_set* ms, stream& s) { st.write(s, true, is_x); } + +inline static const char* mot_read_utf8_string_null_terminated_offset( + prj::shared_ptr& alloc, stream& s, int64_t offset) { + size_t len = s.read_utf8_string_null_terminated_offset_length(offset); + char* str = alloc->allocate(len + 1); + s.position_push(offset, SEEK_SET); + s.read(str, len); + s.position_pop(); + str[len] = 0; + return str; +} diff --git a/src/KKdLib/mot.hpp b/src/KKdLib/mot.hpp index 8fd97634..f55667dc 100644 --- a/src/KKdLib/mot.hpp +++ b/src/KKdLib/mot.hpp @@ -7,6 +7,8 @@ #include #include +#include "prj/shared_ptr.hpp" +#include "alloc_data.hpp" #include "default.hpp" #include "vec.hpp" @@ -23,22 +25,20 @@ enum mot_key_set_data_type { }; struct mot_bone_info { - std::string name; + const char* name; uint16_t index; mot_bone_info(); - ~mot_bone_info(); }; struct mot_key_set_data { mot_key_set_type type; - std::vector frames; - std::vector values; + uint16_t* frames; + float_t* values; uint16_t keys_count : 16; mot_key_set_data_type data_type : 16; mot_key_set_data(); - ~mot_key_set_data(); }; struct mot_data { @@ -56,12 +56,11 @@ struct mot_data { uint32_t murmurhash; uint16_t div_frames; uint8_t div_count; - std::string name; - std::vector bone_info; - std::vector key_set; + const char* name; + mot_bone_info* bone_info_array; + mot_key_set_data* key_set_array; mot_data(); - ~mot_data(); }; struct mot_set { @@ -70,15 +69,17 @@ struct mot_set { bool big_endian; bool is_x; - std::string name; - std::vector vec; + const char* name; + mot_data* mot_data; + uint32_t mot_num; mot_set(); - ~mot_set(); void pack_file(void** data, size_t* size); - void unpack_file(const void* data, size_t size, bool modern); + void unpack_file(prj::shared_ptr alloc, const void* data, size_t size, bool modern); + static mot_key_set_type fit_keys_into_curve(std::vector& values_src, + prj::shared_ptr alloc, uint16_t*& frames, float_t*& values, size_t& keys_count); static mot_key_set_type fit_keys_into_curve(std::vector& values_src, std::vector& frames, std::vector& values); }; diff --git a/src/ReDIVA/classes/data_view/draw_task.cpp b/src/ReDIVA/classes/data_view/draw_task.cpp index 8503d5ae..a53431c3 100644 --- a/src/ReDIVA/classes/data_view/draw_task.cpp +++ b/src/ReDIVA/classes/data_view/draw_task.cpp @@ -188,7 +188,7 @@ void data_view_draw_task_imgui(class_data* data) { } break; case DRAW_TASK_OBJECT_TRANSLUCENT: { draw_task_object_translucent* object_translucent = &task->data.object_translucent; - for (int32_t l = 0; l < 40 && l < object_translucent->count; l++) { + for (uint32_t l = 0; l < 40 && l < object_translucent->count; l++) { ImGui::PushID(l); if (ImGui::TreeNodeEx("", ImGuiTreeNodeFlags_DefaultOpen, "Data %2d", l)) { data_view_draw_task_imgui_draw_object(object_translucent->objects[l]); diff --git a/src/ReDIVA/config.hpp b/src/ReDIVA/config.hpp new file mode 100644 index 00000000..62713099 --- /dev/null +++ b/src/ReDIVA/config.hpp @@ -0,0 +1,12 @@ +/* + by korenkonder + GitHub/GitLab: korenkonder +*/ + +#if defined(ReDIVA_DEV) +#define BAKE_PNG (0) +#define BAKE_VIDEO (0) +#define BAKE_PV826 (0) + +#define DATA_EDIT (0) +#endif diff --git a/src/ReDIVA/data_edit.cpp b/src/ReDIVA/data_edit.cpp new file mode 100644 index 00000000..69de4cee --- /dev/null +++ b/src/ReDIVA/data_edit.cpp @@ -0,0 +1,551 @@ +/* + by korenkonder + GitHub/GitLab: korenkonder + + Some code is from LearnOpenGL +*/ + +#if defined(ReDIVA_DEV) +#include "data_edit.hpp" +#include "../CRE/rob/rob.hpp" +#include "../CRE/ogg_vorbis.hpp" +#include "../CRE/sound.hpp" +#include "../KKdLib/vec.hpp" +#include "imgui_helper.hpp" + +#if DATA_EDIT +DataEdit data_edit; + +extern render_context* rctx_ptr; + +DataEdit::Auth3D::Auth3D() { + +} + +DataEdit::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, const vec3 rotation, const vec3 scale, 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); +} + +void DataEdit::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(); + + set_data(nodes[ 0].model_transform, + vec3(0.0f, 0.0f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // OBJHRC_EFFCHRPV826MIK001_MOB + set_data(nodes[ 1].model_transform, + vec3(0.0f, 0.0f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // gblctr + set_data(nodes[ 2].model_transform, + vec3(0.0f, 1.055f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // n_hara + set_data(nodes[ 3].model_transform, + vec3(0.0f, 0.0f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // n_hara_y + set_data(nodes[ 4].model_transform, + vec3(0.0f, 0.0f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_hara_wj + set_data(nodes[ 5].model_transform, + vec3(0.0f, 0.0f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // n_kosi + set_data(nodes[ 6].model_transform, + vec3(0.0f, 0.11f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_mune_wj + set_data(nodes[ 7].model_transform, + vec3(0.0f, 0.0f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // n_mune_kl + set_data(nodes[ 8].model_transform, + vec3(0.0f, 0.0f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_mune_b_wj + set_data(nodes[ 9].model_transform, + vec3(0.0f, 0.145f, -0.044f), + vec3(-0.820574f, 0.0f, 0.24122f), + vec3(1.0f, 1.0f, 1.0f)); // j_kubi_wj + set_data(nodes[10].model_transform, + vec3(0.0f, 0.079f, 0.004f), + vec3(2.376704f, 0.175657f, -0.166183f), + vec3(1.0f, 1.0f, 1.0f)); // n_kao + set_data(nodes[11].model_transform, + vec3(0.0f, 0.0f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_kao_wj + set_data(nodes[12].model_transform, + vec3(0.111f, 0.18f, -0.062f), + vec3(0.0f, -1.570796f, 1.221731f), + vec3(1.0f, 1.0f, 1.0f)); // j_hair_twin_l_000_wj + set_data(nodes[13].model_transform, + vec3(0.0f, -0.222f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_hair_twin_l_001_wj + set_data(nodes[14].model_transform, + vec3(0.0f, -0.222f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_hair_twin_l_002_wj + set_data(nodes[15].model_transform, + vec3(0.0f, -0.222f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_hair_twin_l_003_wj + set_data(nodes[16].model_transform, + vec3(0.0f, -0.222f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_hair_twin_l_004_wj + set_data(nodes[17].model_transform, + vec3(0.0f, -0.222f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_hair_twin_l_005_wj + set_data(nodes[18].model_transform, + vec3(-0.111f, 0.18f, -0.062f), + vec3(0.0f, -1.570796f, -1.221731f), + vec3(1.0f, 1.0f, 1.0f)); // j_hair_twin_r_000_wj + set_data(nodes[19].model_transform, + vec3(0.0f, -0.222f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_hair_twin_r_001_wj + set_data(nodes[20].model_transform, + vec3(0.0f, -0.222f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_hair_twin_r_002_wj + set_data(nodes[21].model_transform, + vec3(0.0f, -0.222f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_hair_twin_r_003_wj + set_data(nodes[22].model_transform, + vec3(0.0f, -0.222f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_hair_twin_r_004_wj + set_data(nodes[23].model_transform, + vec3(0.0f, -0.222f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_hair_twin_r_005_wj + /*set_data(nodes[24].model_transform, + vec3(0.0f, 0.0f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_kao_normal_wj + set_data(nodes[25].model_transform, + vec3(0.0f, 0.0f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_kao_close_wj + set_data(nodes[26].model_transform, + vec3(0.0f, 0.0f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_kao_smile_wj + set_data(nodes[27].model_transform, + vec3(0.0f, 0.0f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_kao_close_half_wj + set_data(nodes[28].model_transform, + vec3(0.0f, 0.0f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_kao_smile_half_wj + set_data(nodes[29].model_transform, + vec3(0.0148f, -0.0018f, 0.079f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_kuti_l_wj + set_data(nodes[30].model_transform, + vec3(0.0f, 0.00048f, 0.088f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_kuti_u_wj + set_data(nodes[31].model_transform, + vec3(0.0f, -0.00672f, 0.082f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_kuti_d_wj + set_data(nodes[32].model_transform, + vec3(-0.0148f, -0.0018f, 0.079f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_kuti_r_wj + set_data(nodes[33].model_transform, + vec3(-0.027f, 0.061f, 0.015f), + vec3(-1.570796f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_eye_r_wj + set_data(nodes[34].model_transform, + vec3(0.027f, 0.061f, 0.015f), + vec3(-1.570796f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_eye_l_wj*/ + set_data(nodes[35].model_transform, + vec3(0.02f, 0.129f, -0.053f), + vec3(1.570796f, 0.0f, 1.570796f), + vec3(1.0f, 1.0f, 1.0f)); // n_waki_l + set_data(nodes[36].model_transform, + vec3(0.0f, 0.0f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_waki_l_wj + set_data(nodes[37].model_transform, + vec3(0.083002f, -0.009998f, 0.0f), + vec3(-0.037163f, -1.081817f, -3.108780f), + vec3(1.0f, 1.0f, 1.0f)); // n_kata_l + set_data(nodes[38].model_transform, + vec3(0.0f, 0.0f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_kata_l_wj + set_data(nodes[39].model_transform, + vec3(0.183625f, -0.09765f, -0.003205f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_ude_l_wj + set_data(nodes[40].model_transform, + vec3(0.18539f, -0.098589f, -0.003236f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_te_l_wj + set_data(nodes[41].model_transform, + vec3(0.0f, 0.0f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_te_sizen2_l_wj + set_data(nodes[42].model_transform, + vec3(0.0f, 0.0f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_te_close_l_wj + set_data(nodes[43].model_transform, + vec3(0.0f, 0.0f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_te_reset_l_wj + set_data(nodes[44].model_transform, + vec3(-0.02f, 0.129f, -0.053f), + vec3(1.570796f, 0.0f, 1.570796f), + vec3(1.0f, 1.0f, 1.0f)); // n_waki_r + set_data(nodes[45].model_transform, + vec3(0.0f, 0.0f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_waki_r_wj + set_data(nodes[46].model_transform, + vec3(-0.083002f, -0.009998f, 0.0f), + vec3(0.037163f, 1.081817f, -3.108780f), + vec3(1.0f, 1.0f, 1.0f)); // n_kata_r + set_data(nodes[47].model_transform, + vec3(0.0f, 0.0f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_kata_r_wj + set_data(nodes[48].model_transform, + vec3(-0.183625f, -0.09765f, -0.003205f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_ude_r_wj + set_data(nodes[49].model_transform, + vec3(-0.18539f, -0.098589f, -0.003236f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_te_r_wj + set_data(nodes[50].model_transform, + vec3(0.0f, 0.0f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_te_sizen2_r_wj + set_data(nodes[51].model_transform, + vec3(0.0f, 0.0f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_te_close_r_wj + set_data(nodes[52].model_transform, + vec3(0.0f, 0.0f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_te_reset_r_wj + set_data(nodes[53].model_transform, + vec3(0.0f, 0.0f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_te_one_r_wj + set_data(nodes[54].model_transform, + vec3(0.0f, 0.0f, 0.0f), + vec3(0.0f, 1.570796f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_kosi_wj + set_data(nodes[55].model_transform, + vec3(0.065f, -0.15f, -0.046f), + vec3(0.0f, 0.0f, -1.570796f), + vec3(1.0f, 1.0f, 1.0f)); // n_momo_l + set_data(nodes[56].model_transform, + vec3(0.0f, 0.0f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_momo_l_wj + set_data(nodes[57].model_transform, + vec3(0.0f, -0.39f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_sune_l_wj + set_data(nodes[58].model_transform, + vec3(0.0f, -0.38f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_asi_l_wj + set_data(nodes[59].model_transform, + vec3(-0.065f, -0.15f, -0.046f), + vec3(0.0f, 0.0f, -1.570796f), + vec3(1.0f, 1.0f, 1.0f)); // n_momo_r + set_data(nodes[60].model_transform, + vec3(0.0f, 0.0f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_momo_r_wj + set_data(nodes[61].model_transform, + vec3(0.0f, -0.39f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_sune_r_wj + set_data(nodes[62].model_transform, + vec3(0.0f, -0.38f, 0.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(1.0f, 1.0f, 1.0f)); // j_asi_r_wj + set_data(nodes[63].model_transform, + vec3(0.0f, -0.052047f, 0.060104f), + vec3(0.0f, 0.0f, -1.762782f), + vec3(1.0f, 1.0f, 1.0f)); // j_cloth_skirt_f_000_wj + set_data(nodes[64].model_transform, + vec3(0.05915f, -0.052048f, 0.04283f), + vec3(-0.368869f, -0.220518f, -1.784135f), + vec3(1.0f, 1.0f, 1.0f)); // j_cloth_skirt_l_02_000_wj + set_data(nodes[65].model_transform, + vec3(0.10962f, -0.052048f, -0.013f), + vec3(-1.710423f, -0.331613f, -1.588249f), + vec3(1.0f, 1.0f, 1.0f)); // j_cloth_skirt_l_04_000_wj + set_data(nodes[66].model_transform, + vec3(0.08239f, -0.052048f, -0.09275f), + vec3(-2.356194f, -0.314159f, -1.308997f), + vec3(1.0f, 1.0f, 1.0f)); // j_cloth_skirt_l_06_000_wj + set_data(nodes[67].model_transform, + vec3(-0.05915f, -0.052048f, 0.04283f), + vec3(0.368869f, 0.220518f, -1.784135f), + vec3(1.0f, 1.0f, 1.0f)); // j_cloth_skirt_r_02_000_wj + set_data(nodes[68].model_transform, + vec3(-0.10962f, -0.052048f, -0.013f), + vec3(1.710423f, 0.331613f, -1.588249f), + vec3(1.0f, 1.0f, 1.0f)); // j_cloth_skirt_r_04_000_wj + set_data(nodes[69].model_transform, + vec3(-0.08239f, -0.052048f, -0.09275f), + vec3(2.356194f, 0.314159f, -1.308997f), + vec3(1.0f, 1.0f, 1.0f)); // j_cloth_skirt_r_06_000_wj + set_data(nodes[70].model_transform, + vec3(0.0f, -0.052049f, -0.118331f), + vec3(-3.141592f, 0.0f, -1.186823f), + vec3(1.0f, 1.0f, 1.0f)); // j_cloth_skirt_b_000_wj + + objhrc->interpolate(0.0f); +} + +void DataEdit::Auth3D::Reset() { + auth_3d_data_unload_category(category.hash_murmurhash); + id.unload_id(rctx_ptr); + object_storage_unload_set(object_set.hash_murmurhash); + + category.clear(); + file.clear(); + object_set.clear(); + id = -1; + + obj_db.object_set.clear(); + obj_db.object_set.shrink_to_fit(); + tex_db.texture.clear(); + tex_db.texture.shrink_to_fit(); +} + +DataEdit::DataEdit() : state(), play(), sound_play(), frame(), frame_count() { + chara_id = -1; + mot_set_id = -1; + motion_id = -1; +} + +DataEdit::~DataEdit() { + +} + +bool DataEdit::Init() { + Reset(); + task_rob_manager_append_task(); + return true; +} + +bool DataEdit::Ctrl() { + 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; + + data_struct* x_data = &data_list[DATA_X]; + + switch (state) { + case 0: { + if (!task_rob_manager_check_task_ready()) + break; + + state = 1; + } break; + case 1: { + if (chara_id == -1) { + rob_chara_pv_data pv_data; + pv_data.chara_size_index = chara_init_data_get_chara_size_index(CHARA_MIKU); + chara_id = rob_chara_array_init_chara_index(CHARA_MIKU, &pv_data, 0, true); + } + + if (chara_id == -1 || !task_rob_manager_check_chara_loaded(chara_id)) + break; + + state = 2; + } break; + case 2: { + mot_set_id = aft_mot_db->get_motion_set_id("PV826"); + motion_id = aft_mot_db->get_motion_id("PV826_OST_P1_00"); + + motion_set_load_motion(mot_set_id, 0, aft_mot_db); + state = 3; + + auth_3d.category.assign("A3D_EFFCHRPV826MIK001"); + 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); + object_storage_load_set_hash(x_data, auth_3d.object_set.hash_murmurhash); + } break; + case 3: { + if (motion_storage_check_mot_file_not_ready(mot_set_id)) + break; + + if (!auth_3d_data_check_category_loaded(auth_3d.category.hash_murmurhash) + || (object_storage_get_obj_set_handler(auth_3d.object_set.hash_murmurhash) + && object_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_data_load_hash( + auth_3d.file.hash_murmurhash, x_data, &auth_3d.obj_db, &auth_3d.tex_db); + auth_3d.id.read_file_modern(); + + state = 4; + } break; + case 4: { + if (!auth_3d.id.check_not_empty() || !auth_3d.id.check_loaded()) + 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.Patch(); + + rob_chara* rob_chr = rob_chara_array_get(chara_id); + rob_chr->set_motion_id(motion_id, 0.0f, 0.0f, true, false, + MOTION_BLEND_CROSS, aft_bone_data, aft_mot_db); + rob_chr->set_visibility(true); + + rob_chr->set_mouth_mottbl_motion(0, mouth_anim_id_to_mottbl_index(8), 1.0f, + 0, 0.0f, 0.0f, 1.0f, -1, 0.0f, aft_mot_db); + + frame = 5000; + frame_count = (int32_t)rob_chr->get_frame_count(); + + 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 = 5; + } break; + case 5: { + const vec3 auth_trans = vec3(-0.25f, 0.0f, 0.0f); + const vec3 rob_trans = vec3( 0.25f, 0.0f, 0.0f); + + mat4 auth_mat; + mat4_translate(&auth_trans, &auth_mat); + auth_3d.id.set_req_frame((float_t)frame); + auth_3d.id.set_mat(auth_mat); + + rob_chara* rob_chr = rob_chara_array_get(chara_id); + rob_chr->set_frame((float_t)frame); + rob_chr->data.miku_rot.position = rob_trans; + + if (!play && sound_play) { + sound_work_release_stream(0); + sound_play = false; + } + else if (play && !sound_play) { + sound_work_play_stream(0, ogg_path.c_str(), (float_t)((double_t)frame / 60.0)); + sound_play = true; + } + + if (play) + frame++; + + if (frame >= frame_count) { + frame = 4808; + + sound_work_release_stream(0); + sound_work_play_stream(0, ogg_path.c_str(), (float_t)((double_t)frame / 60.0)); + } + } break; + } + return false; +} + +bool DataEdit::Dest() { + rob_chara_array_free_chara_id(chara_id); + task_rob_manager_free_task(); + Reset(); + return true; +} + +void DataEdit::Window() { + ImGuiIO& io = ImGui::GetIO(); + ImGuiStyle& style = ImGui::GetStyle(); + ImFont* font = ImGui::GetFont(); + + extern int32_t height; + extern int32_t width; + + float_t w = 200.0f; + float_t h = (float_t)height; + h = min_def(h, 232.0f); + + ImGui::SetNextWindowPos({ 0.0f, 0.0f }, ImGuiCond_Appearing); + ImGui::SetNextWindowSize({ w, h }, ImGuiCond_Always); + + ImGuiWindowFlags window_flags = 0; + window_flags |= ImGuiWindowFlags_NoResize; + + window_focus = false; + bool open = true; + if (!ImGui::Begin("Data Edit", &open, window_flags)) { + ImGui::End(); + return; + } + else if (!open) { + ImGui::End(); + return; + } + + if (ImGui::Button(play ? "Pause" : "Play")) + play ^= true; + + ImGui::Text("% 5d/% 5d", frame, frame_count); + ImGui::End(); +} + +void DataEdit::Reset() { + motion_set_unload_motion(mot_set_id); + + chara_id = -1; + state = 0; + mot_set_id = -1; + motion_id = -1; + auth_3d.Reset(); + ogg_path.clear(); + ogg_path.shrink_to_fit(); + play = false; + sound_play = false; + frame = 0; + frame_count = 0; +} +#endif +#endif diff --git a/src/ReDIVA/data_edit.hpp b/src/ReDIVA/data_edit.hpp new file mode 100644 index 00000000..5da7e31b --- /dev/null +++ b/src/ReDIVA/data_edit.hpp @@ -0,0 +1,59 @@ +/* + by korenkonder + GitHub/GitLab: korenkonder +*/ + +#if defined(ReDIVA_DEV) +#pragma once + +#include "config.hpp" +#include "../CRE/auth_3d.hpp" +#include "../KKdLib/database/object.hpp" +#include "../KKdLib/database/texture.hpp" +#include "../KKdLib/hash.hpp" +#include "task_window.hpp" + +#if DATA_EDIT +class DataEdit : public app::TaskWindow { +public: + struct Auth3D { + string_hash category; + string_hash file; + string_hash object_set; + auth_3d_id id; + + object_database obj_db; + texture_database tex_db; + + Auth3D(); + ~Auth3D(); + + void Patch(); + void Reset(); + }; + + int32_t chara_id; + int32_t state; + uint32_t mot_set_id; + uint32_t motion_id; + Auth3D auth_3d; + std::string ogg_path; + bool play; + bool sound_play; + int32_t frame; + int32_t frame_count; + + DataEdit(); + virtual ~DataEdit() override; + + virtual bool Init() override; + virtual bool Ctrl() override; + virtual bool Dest() override; + virtual void Window() override; + + void Reset(); +}; + +extern DataEdit data_edit; +#endif +#endif diff --git a/src/ReDIVA/data_test/auth_3d_test.cpp b/src/ReDIVA/data_test/auth_3d_test.cpp index d979c9f1..035751ff 100644 --- a/src/ReDIVA/data_test/auth_3d_test.cpp +++ b/src/ReDIVA/data_test/auth_3d_test.cpp @@ -161,13 +161,13 @@ void Auth3dTestWindow::Window() { return; } - auth_3d* auth = auth_3d_data_get_auth_3d(auth_3d_test_task->auth_3d_id); + auth_3d* auth = auth_3d_test_task->auth_3d_id.get_auth_3d(); if (auth) last_frame = auth->play_control.size; - if (auth_3d_data_check_id_not_empty(auth_3d_test_task->auth_3d_id)) { - enable = auth_3d_data_get_enable(auth_3d_test_task->auth_3d_id); - frame = auth_3d_data_get_frame(auth_3d_test_task->auth_3d_id); + if (auth_3d_test_task->auth_3d_id.check_not_empty()) { + enable = auth_3d_test_task->auth_3d_id.get_enable(); + frame = auth_3d_test_task->auth_3d_id.get_frame(); frame_changed = false; } @@ -365,16 +365,16 @@ void Auth3dTestWindow::Window() { ImGui::Checkbox("Link Stage Change", &auth_3d_test_task->window.stage_link_change); - if (auth_3d_data_check_id_not_empty(auth_3d_test_task->auth_3d_id)) { - auth_3d_data_set_enable(auth_3d_test_task->auth_3d_id, enable); - auth_3d_data_set_repeat(auth_3d_test_task->auth_3d_id, auth_3d_test_task->repeat); - auth_3d_data_set_left_right_reverse(auth_3d_test_task->auth_3d_id, auth_3d_test_task->left_right_reverse); + if (auth_3d_test_task->auth_3d_id.check_not_empty()) { + auth_3d_test_task->auth_3d_id.set_enable(enable); + auth_3d_test_task->auth_3d_id.set_repeat(auth_3d_test_task->repeat); + auth_3d_test_task->auth_3d_id.set_left_right_reverse(auth_3d_test_task->left_right_reverse); if (frame_changed) { - auth_3d_data_set_req_frame(auth_3d_test_task->auth_3d_id, frame); + auth_3d_test_task->auth_3d_id.set_req_frame(frame); frame_changed = false; } - auth_3d_data_set_paused(auth_3d_test_task->auth_3d_id, paused); - auth_3d_data_set_frame_rate(auth_3d_test_task->auth_3d_id, 0); + auth_3d_test_task->auth_3d_id.set_paused(paused); + auth_3d_test_task->auth_3d_id.set_frame_rate(0); } ImGui::End(); } diff --git a/src/ReDIVA/game_state.cpp b/src/ReDIVA/game_state.cpp index 1fd9742e..36be71d3 100644 --- a/src/ReDIVA/game_state.cpp +++ b/src/ReDIVA/game_state.cpp @@ -11,6 +11,7 @@ #include "data_test/auth_3d_test.hpp" #include "data_test/glitter_test.hpp" #include "data_test/stage_test.hpp" +#include "data_edit.hpp" #include "data_initialize.hpp" #include "pv_game.hpp" #include "system_startup.hpp" @@ -130,6 +131,20 @@ GameStateData game_state_data_array[] = { GAME_STATE_ADVERTISE, SUB_GAME_STATE_MAX, }, +#if DATA_EDIT + { // Added + GAME_STATE_DATA_EDIT, + GameState::DataEdit::Init, + GameState::DataEdit::Ctrl, + GameState::DataEdit::Dest, + { + SUB_GAME_STATE_DATA_EDIT, + SUB_GAME_STATE_MAX, + }, + GAME_STATE_ADVERTISE, + SUB_GAME_STATE_MAX, + }, +#endif { GAME_STATE_APP_ERROR, GameState::AppError::Init, @@ -425,6 +440,15 @@ SubGameStateData sub_game_state_data_array[] = { SubGameState::DataTestModeMain::Ctrl, SubGameState::DataTestModeMain::Dest, }, +#if DATA_EDIT + { // Added + SUB_GAME_STATE_DATA_EDIT, + 0, + SubGameState::DataEdit::Init, + SubGameState::DataEdit::Ctrl, + SubGameState::DataEdit::Dest, + }, +#endif { SUB_GAME_STATE_APP_ERROR, 0, @@ -440,6 +464,9 @@ const char* game_state_names[] = { "GAME", "DATA_TEST", "TEST_MODE", +#if DATA_EDIT + "DATA_EDIT", +#endif "APP_ERROR", "MAX", }; @@ -485,6 +512,9 @@ const char* sub_game_state_names[] = { "DATA_TEST_GRAPHICS", "DATA_TEST_COLLECTION_CARD", "TEST_MODE_MAIN", +#if DATA_EDIT + "DATA_EDIT", +#endif "APP_ERROR", "MAX", }; @@ -554,32 +584,6 @@ bool GameState::Game::Dest() { return true; } -bool GameState::TestMode::Init() { - test_mode_set(true); - return true; -} - -bool GameState::TestMode::Ctrl() { - return false; -} - -bool GameState::TestMode::Dest() { - test_mode_set(false); - return true; -} - -bool GameState::AppError::Init() { - return true; -} - -bool GameState::AppError::Ctrl() { - return false; -} - -bool GameState::AppError::Dest() { - return true; -} - bool GameState::DataTest::Init() { task_rob_manager_append_task(); return true; @@ -600,6 +604,46 @@ bool GameState::DataTest::Dest() { return true; } +bool GameState::TestMode::Init() { + test_mode_set(true); + return true; +} + +bool GameState::TestMode::Ctrl() { + return false; +} + +bool GameState::TestMode::Dest() { + test_mode_set(false); + return true; +} + +#if DATA_EDIT +bool GameState::DataEdit::Init() { // Added + return true; +} + +bool GameState::DataEdit::Ctrl() { // Added + return false; +} + +bool GameState::DataEdit::Dest() { // Added + return true; +} +#endif + +bool GameState::AppError::Init() { + return true; +} + +bool GameState::AppError::Ctrl() { + return false; +} + +bool GameState::AppError::Dest() { + return true; +} + bool SubGameState::DataInitialize::Init() { task_data_init_append_task(); task_auth_3d_append_task(); @@ -1143,6 +1187,22 @@ bool SubGameState::DataTestModeMain::Dest() { return true; } +#if DATA_EDIT +bool SubGameState::DataEdit::Init() { // Added + app::TaskWork::AppendTask(&data_edit, "DATA EDIT", 0); + return true; +} + +bool SubGameState::DataEdit::Ctrl() { // Added + return false; +} + +bool SubGameState::DataEdit::Dest() { // Added + data_edit.SetDest(); + return true; +} +#endif + bool SubGameState::DataTestAppError::Init() { return true; } diff --git a/src/ReDIVA/game_state.hpp b/src/ReDIVA/game_state.hpp index 14e806be..463fbefc 100644 --- a/src/ReDIVA/game_state.hpp +++ b/src/ReDIVA/game_state.hpp @@ -5,6 +5,7 @@ #pragma once +#include "config.hpp" #include "../KKdLib/default.hpp" enum GameStateEnum { @@ -13,6 +14,9 @@ enum GameStateEnum { GAME_STATE_GAME, GAME_STATE_DATA_TEST, GAME_STATE_TEST_MODE, +#if DATA_EDIT + GAME_STATE_DATA_EDIT, // Added +#endif GAME_STATE_APP_ERROR, GAME_STATE_MAX, }; @@ -58,6 +62,9 @@ enum SubGameStateEnum { SUB_GAME_STATE_DATA_TEST_GRAPHICS, SUB_GAME_STATE_DATA_TEST_COLLECTION_CARD, SUB_GAME_STATE_TEST_MODE_MAIN, +#if DATA_EDIT + SUB_GAME_STATE_DATA_EDIT, // Added +#endif SUB_GAME_STATE_APP_ERROR, SUB_GAME_STATE_MAX, }; @@ -88,19 +95,27 @@ struct GameState { static bool Dest(); }; + struct DataTest { + static bool Init(); + static bool Ctrl(); + static bool Dest(); + }; + struct TestMode { static bool Init(); static bool Ctrl(); static bool Dest(); }; - struct AppError { +#if DATA_EDIT + struct DataEdit { // Added static bool Init(); static bool Ctrl(); static bool Dest(); }; +#endif - struct DataTest { + struct AppError { static bool Init(); static bool Ctrl(); static bool Dest(); @@ -364,6 +379,14 @@ struct SubGameState { static bool Dest(); }; +#if DATA_EDIT + struct DataEdit { // Added + static bool Init(); + static bool Ctrl(); + static bool Dest(); + }; +#endif + struct DataTestAppError { static bool Init(); static bool Ctrl(); diff --git a/src/ReDIVA/pv_game.cpp b/src/ReDIVA/pv_game.cpp index 5530a6ff..8903e539 100644 --- a/src/ReDIVA/pv_game.cpp +++ b/src/ReDIVA/pv_game.cpp @@ -405,8 +405,8 @@ pv_game_old::pv_game_old() : state(), frame(), frame_float(), time(), rob_chara_ dsc_time(), dsc_data_ptr(), dsc_data_ptr_end(), play(), success(), chara_id(), pv_end(), playdata(), scene_rot_y(), branch_mode(), pause(), step_frame() { pv_id = -1; - light_auth_3d_id = -1; - camera_auth_3d_id = -1; + light_auth_3d_id = {}; + camera_auth_3d_id = {}; target_anim_fps = 60.0f; anim_frame_speed = 1.0f; scene_rot_mat = mat4_identity; @@ -480,32 +480,29 @@ bool pv_game_old::Ctrl() { } } - light_auth_3d_id = -1; + light_auth_3d_id = {}; { - data_struct* aft_data = &data_list[DATA_AFT]; - auth_3d_database* auth_3d_db = &aft_data->data_ft.auth_3d_db; - char buf[0x200]; sprintf_s(buf, sizeof(buf), "STGPV%03d_EFF_LT_000", pv_id); uint32_t light_auth_3d_uid = auth_3d_db->get_uid(buf); if (light_auth_3d_uid != -1) { light_auth_3d_id = auth_3d_data_load_uid(light_auth_3d_uid, auth_3d_db); - auth_3d_data_read_file(light_auth_3d_id, auth_3d_db); - auth_3d_data_set_enable(light_auth_3d_id, false); - auth_3d_data_set_visibility(light_auth_3d_id, false); + light_auth_3d_id.read_file(auth_3d_db); + light_auth_3d_id.set_enable(false); + light_auth_3d_id.set_visibility(false); break; } } - camera_auth_3d_id = -1; + camera_auth_3d_id = {}; { char buf[0x200]; sprintf_s(buf, sizeof(buf), "CAMPV%03d_BASE", pv_id); uint32_t camera_auth_3d_uid = auth_3d_db->get_uid(buf); camera_auth_3d_id = auth_3d_data_load_uid(camera_auth_3d_uid, auth_3d_db); - auth_3d_data_read_file_modern(camera_auth_3d_id); - auth_3d_data_set_enable(camera_auth_3d_id, false); - auth_3d_data_set_visibility(camera_auth_3d_id, false); + camera_auth_3d_id.read_file(auth_3d_db); + camera_auth_3d_id.set_enable(false); + camera_auth_3d_id.set_visibility(false); } state = 7; @@ -514,13 +511,13 @@ bool pv_game_old::Ctrl() { bool wait_load = false; for (auto i : pv_auth_3d_ids) - if (!auth_3d_data_check_id_loaded(i.second)) + if (!i.second.check_loaded()) wait_load = true; - if (!auth_3d_data_check_id_loaded(light_auth_3d_id)) + if (!light_auth_3d_id.check_loaded()) wait_load = true; - if (!auth_3d_data_check_id_loaded(camera_auth_3d_id)) + if (!camera_auth_3d_id.check_loaded()) wait_load = true; if (!wait_load) @@ -621,17 +618,17 @@ bool pv_game_old::Ctrl() { && pv_game_dsc_process(this, this->time)) dsc_data_ptr++; - auth_3d_data_set_enable(light_auth_3d_id, true); - auth_3d_data_set_camera_root_update(light_auth_3d_id, false); - auth_3d_data_set_paused(light_auth_3d_id, false); - auth_3d_data_set_repeat(light_auth_3d_id, false); - auth_3d_data_set_visibility(light_auth_3d_id, true); + 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); - auth_3d_data_set_enable(camera_auth_3d_id, true); - auth_3d_data_set_camera_root_update(camera_auth_3d_id, true); - auth_3d_data_set_paused(camera_auth_3d_id, false); - auth_3d_data_set_repeat(camera_auth_3d_id, false); - auth_3d_data_set_visibility(camera_auth_3d_id, true); + camera_auth_3d_id.set_enable(true); + camera_auth_3d_id.set_camera_root_update(true); + camera_auth_3d_id.set_paused(false); + camera_auth_3d_id.set_repeat(false); + camera_auth_3d_id.set_visibility(true); pause = true; } break; @@ -862,14 +859,14 @@ void pv_game_old::Unload() { } for (auto& i : pv_auth_3d_ids) - auth_3d_data_unload_id(i.second, rctx_ptr); + i.second.unload_id(rctx_ptr); - auth_3d_data_unload_id(light_auth_3d_id, rctx_ptr); - auth_3d_data_unload_id(camera_auth_3d_id, rctx_ptr); + light_auth_3d_id.unload_id(rctx_ptr); + camera_auth_3d_id.unload_id(rctx_ptr); pv_auth_3d_ids.clear(); - light_auth_3d_id = -1; - camera_auth_3d_id = -1; + light_auth_3d_id = {}; + camera_auth_3d_id = {}; for (std::string& i : category_load) auth_3d_data_unload_category(i.c_str()); diff --git a/src/ReDIVA/pv_game.hpp b/src/ReDIVA/pv_game.hpp index ca4c066d..9b511443 100644 --- a/src/ReDIVA/pv_game.hpp +++ b/src/ReDIVA/pv_game.hpp @@ -611,9 +611,9 @@ public: std::vector category_load; - std::map pv_auth_3d_ids; - int32_t light_auth_3d_id; - int32_t camera_auth_3d_id; + std::map pv_auth_3d_ids; + auth_3d_id light_auth_3d_id; + auth_3d_id camera_auth_3d_id; dsc dsc_m; dsc_data* dsc_data_ptr; diff --git a/src/ReDIVA/render.cpp b/src/ReDIVA/render.cpp index 26625e22..2b9e3cda 100644 --- a/src/ReDIVA/render.cpp +++ b/src/ReDIVA/render.cpp @@ -6,6 +6,7 @@ */ #include "render.hpp" +#include "config.hpp" #include "../CRE/Glitter/glitter.hpp" #include "../CRE/rob/rob.hpp" #include "../CRE/camera.hpp" @@ -57,7 +58,7 @@ #include #if defined(DEBUG) -#define OPENGL_DEBUG 1 +#define OPENGL_DEBUG 0 #endif #define CUBE_LINE_SIZE (0.0025f) @@ -1004,15 +1005,15 @@ static render_context* render_load() { cam->initialize(aspect, internal_3d_res.x, internal_3d_res.y, internal_2d_res.x, internal_2d_res.y); - //cam->set_position(cam, { 1.35542f, 1.41634f, 1.27852f }); - //cam->rotate(cam, { -45.0, -32.5 }); - //cam->set_position(cam, { -6.67555f, 4.68882f, -3.67537f }); - //cam->rotate(cam, { 136.5, -20.5 }); + //cam->set_position({ 1.35542f, 1.41634f, 1.27852f }); + //cam->rotate({ -45.0, -32.5 }); + //cam->set_position({ -6.67555f, 4.68882f, -3.67537f }); + //cam->rotate({ 136.5, -20.5 }); cam->set_view_point({ 0.0f, 1.0f, 3.45f }); cam->set_interest({ 0.0f, 1.0f, 0.0f }); - //cam->set_fov(cam, 70.0); - cam->set_view_point({ 0.0f, 1.375f, 1.0f }); - cam->set_interest({ 0.0f, 1.375f, 0.0f }); + //cam->set_fov(70.0); + cam->set_view_point({ 0.0f, 1.4f, 1.0f }); + cam->set_interest({ 0.0f, 1.4f, 0.0f }); imgui_context = ImGui::CreateContext(); imgui_context_lock = new lock_cs; @@ -1180,6 +1181,8 @@ static void render_ctrl(render_context* rctx) { cam->set_interest({ 0.0f, 1.0f, 0.0f }); //cam->set_fov(70.0); cam->set_fast_change_hist0(true); + cam->set_view_point({ 0.0f, 1.4f, 1.0f }); + cam->set_interest({ 0.0f, 1.4f, 0.0f }); } else { cam->rotate(input_rotate_x, input_rotate_y); @@ -1200,6 +1203,10 @@ static void render_ctrl(render_context* rctx) { else if (Input::IsKeyTapped(GLFW_KEY_F7)) game_state_set_game_state_next(GAME_STATE_TEST_MODE); else if (Input::IsKeyTapped(GLFW_KEY_F8)) +#if DATA_EDIT + game_state_set_game_state_next(GAME_STATE_DATA_EDIT); // Added + else if (Input::IsKeyTapped(GLFW_KEY_F9)) // Added +#endif game_state_set_game_state_next(GAME_STATE_APP_ERROR); classes_process_ctrl(classes, classes_count); @@ -1337,7 +1344,7 @@ static void render_disp(render_context* rctx) { continue; rob_chara* rob_chr = &rob_chara_array[i]; - if (!rob_chr->get_visibility()) + if (!rob_chr->is_visible()) continue; gl_state_bind_vertex_array(cube_line_vao); @@ -1478,7 +1485,7 @@ static void render_disp(render_context* rctx) { continue; rob_chara* rob_chr = &rob_chara_array[i]; - if (!rob_chr->get_visibility()) + if (!rob_chr->is_visible()) continue; std::vector> cube_line_points; @@ -1757,19 +1764,19 @@ static void render_imgui_context_menu(classes_data* classes, #pragma warning(disable:26117) for (size_t i = 0; i < classes_count; i++) { classes_data* c = &classes[i]; - if (!c->name || ~c->flags & CLASSES_IN_CONTEXT_MENU) + if (!c->name || !(c->flags & CLASSES_IN_CONTEXT_MENU)) continue; if (c->sub_classes && c->sub_classes_count) { - if (ImGui::BeginMenu(c->name, ~c->data.flags & CLASS_HIDDEN)) { + if (ImGui::BeginMenu(c->name, !(c->data.flags & CLASS_HIDDEN))) { render_imgui_context_menu(c->sub_classes, c->sub_classes_count, rctx); ImGui::EndMenu(); } } - else if (~c->data.flags & CLASS_HIDDEN) + else if (!(c->data.flags & CLASS_HIDDEN)) ImGui::MenuItem(c->name, 0, false, false); else if (ImGui::MenuItem(c->name, 0)) { - if (~c->data.flags & CLASS_INIT) { + if (!(c->data.flags & CLASS_INIT)) { c->data.lock = new lock_cs; if (c->data.lock->check_init() && c->init) { lock_lock(c->data.lock); diff --git a/src/ReDIVA/x_pv_game.cpp b/src/ReDIVA/x_pv_game.cpp index aa1a129d..c3619c4d 100644 --- a/src/ReDIVA/x_pv_game.cpp +++ b/src/ReDIVA/x_pv_game.cpp @@ -602,8 +602,8 @@ x_pv_game_a3da_to_mot_keys::~x_pv_game_a3da_to_mot_keys() { } -x_pv_game_a3da_to_mot::x_pv_game_a3da_to_mot(int32_t auth_3d_id) { - this->auth_3d_id = auth_3d_id; +x_pv_game_a3da_to_mot::x_pv_game_a3da_to_mot(auth_3d_id id) { + this->id = id; gblctr = -1; n_hara = -1; n_hara_y = -1; @@ -723,15 +723,15 @@ void x_pv_game_a3da_to_mot::get_bone_indices(auth_3d_object_hrc* oh) { #endif x_pv_game_song_effect_auth_3d::x_pv_game_song_effect_auth_3d() { - id = -1; + } -x_pv_game_song_effect_auth_3d::x_pv_game_song_effect_auth_3d(int32_t id) { +x_pv_game_song_effect_auth_3d::x_pv_game_song_effect_auth_3d(auth_3d_id id) { this->id = id; } void x_pv_game_song_effect_auth_3d::reset() { - id = -1; + id = {}; } x_pv_game_song_effect_glitter::x_pv_game_song_effect_glitter() : scene_counter(), field_8(), field_9() { @@ -778,31 +778,30 @@ void x_pv_game_camera::ctrl(float_t curr_time) { if (!auth_3d_data_check_category_loaded(category.hash_murmurhash)) break; - int32_t id = auth_3d_data_load_hash(file.hash_murmurhash, &data_list[DATA_X], 0, 0); - if (auth_3d_data_check_id_not_empty(id)) { - auth_3d_data_read_file_modern(id); - auth_3d_data_set_enable(id, false); - auth_3d_data_set_repeat(id, false); - auth_3d_data_set_paused(id, false); - auth_3d_data_set_frame_rate(id, frame_rate_control); + auth_3d_id id = auth_3d_data_load_hash(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_id = id; + this->id = id; rctx_ptr->camera->reset(); state = 11; } break; case 11: { - if (auth_3d_data_check_id_not_empty(auth_3d_id) - && auth_3d_data_check_id_loaded(auth_3d_id)) + if (id.check_not_empty() && id.check_loaded()) state = 20; } break; case 20: { - int32_t& id = auth_3d_id; - auth_3d_data_set_enable(id, 1u); - auth_3d_data_set_repeat(id, false); - auth_3d_data_set_paused(id, 0); - auth_3d_data_set_camera_root_update(id, true); - auth_3d_data_set_req_frame(id, curr_time * 60.0f); + 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); } break; } } @@ -833,19 +832,19 @@ void x_pv_game_camera::reset() { state = 0; category.clear(); file.clear(); - auth_3d_id = -1; + id = {}; } void x_pv_game_camera::stop() { - if (auth_3d_data_check_id_not_empty(auth_3d_id)) - auth_3d_data_set_enable(auth_3d_id, false); + if (id.check_not_empty()) + id.set_enable(false); } void x_pv_game_camera::unload() { if (state != 20) return; - auth_3d_data_unload_id(auth_3d_id, rctx_ptr); + id.unload_id(rctx_ptr); auth_3d_data_unload_category(category.hash_murmurhash); state = 0; } @@ -885,17 +884,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) { - int32_t id = auth_3d_data_load_hash(j.hash_murmurhash, x_data, obj_db, tex_db); - if (!auth_3d_data_check_id_not_empty(id)) { + auth_3d_id id = auth_3d_data_load_hash(j.hash_murmurhash, x_data, obj_db, tex_db); + if (!id.check_not_empty()) continue; - } - auth_3d_data_read_file_modern(id); - auth_3d_data_set_enable(id, false); - auth_3d_data_set_repeat(id, false); - auth_3d_data_set_paused(id, false); - auth_3d_data_set_visibility(id, false); - auth_3d_data_set_frame_rate(id, frame_rate_control); + 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); song_effect.auth_3d.push_back(id); } @@ -907,8 +905,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 (auth_3d_data_check_id_not_empty(j.id) - && !auth_3d_data_check_id_loaded(j.id)) + if (j.id.check_not_empty() && !j.id.check_loaded()) wait_load |= true; for (string_hash& i : pv_glitter) @@ -979,7 +976,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) - auth_3d_data_set_chara_id(j.id, i.chara_id); + j.id.set_chara_id(i.chara_id); } break; } } @@ -1062,8 +1059,8 @@ void x_pv_game_effect::set_chara_id(int32_t index, int32_t chara_id, bool chara_ 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_data_set_chara_id(i.id, chara_id); - auth_3d_data_set_chara_item(i.id, chara_item); + i.id.set_chara_id(chara_id); + i.id.set_chara_item(chara_item); } song_effect.chara_id = chara_id; @@ -1092,10 +1089,10 @@ void x_pv_game_effect::set_song_effect(int32_t index, int64_t time) { song_effect.chara_id = chara_id; for (x_pv_game_song_effect_auth_3d& i : song_effect.auth_3d) { - auth_3d_data_set_enable(i.id, true); - auth_3d_data_set_repeat(i.id, false); - auth_3d_data_set_req_frame(i.id, 0.0f); - auth_3d_data_set_visibility(i.id, true); + i.id.set_enable(true); + i.id.set_repeat(false); + i.id.set_req_frame(0.0f); + i.id.set_visibility(true); } for (x_pv_game_song_effect_glitter& i : song_effect.glitter) { @@ -1112,7 +1109,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) - auth_3d_data_set_chara_id(i.id, chara_id); + i.id.set_chara_id(chara_id); } void x_pv_game_effect::set_song_effect_time(int32_t index, int64_t time, bool glitter) { @@ -1146,9 +1143,9 @@ void x_pv_game_effect::set_song_effect_time_inner(int32_t index, int64_t time, b } for (x_pv_game_song_effect_auth_3d& i : song_effect.auth_3d) { - auth_3d_data_set_req_frame(i.id, req_frame); - auth_3d_data_set_paused(i.id, false); - auth_3d_data_set_max_frame(i.id, max_frame); + i.id.set_req_frame(req_frame); + i.id.set_paused(false); + i.id.set_max_frame(max_frame); } if (glitter) @@ -1177,10 +1174,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) { - int32_t& id = i.id; - auth_3d_data_set_enable(id, false); - auth_3d_data_set_req_frame(id, 0.0f); - auth_3d_data_set_visibility(id, false); + auth_3d_id& id = i.id; + id.set_enable(false); + id.set_req_frame(0.0f); + id.set_visibility(false); } for (x_pv_game_song_effect_glitter& i : song_effect.glitter) @@ -1206,8 +1203,8 @@ void x_pv_game_effect::unload() { for (x_pv_game_song_effect& i : song_effect) for (x_pv_game_song_effect_auth_3d& j : i.auth_3d) { - auth_3d_data_unload_id(j.id, rctx_ptr); - j.id = -1; + j.id.unload_id(rctx_ptr); + j.id = {}; } for (string_hash& i : pv_auth_3d) @@ -1230,7 +1227,7 @@ void x_pv_game_effect::unload() { } x_pv_game_chara_effect_auth_3d::x_pv_game_chara_effect_auth_3d() : field_0(), src_chara(), dst_chara() { - id = -1; + id = {}; time = -1; reset(); } @@ -1246,7 +1243,7 @@ void x_pv_game_chara_effect_auth_3d::reset() { file.clear(); category.clear(); object_set.clear(); - id = -1; + id = {}; time = -1; } @@ -1260,7 +1257,7 @@ x_pv_game_chara_effect::~x_pv_game_chara_effect() { #if BAKE_PV826 void x_pv_game_chara_effect::ctrl(object_database* obj_db, texture_database* tex_db, - int32_t pv_id, std::map* effchrpv_auth_3d_mot_ids) { + int32_t pv_id, std::map* effchrpv_auth_3d_mot_ids) { #else void x_pv_game_chara_effect::ctrl(object_database* obj_db, texture_database* tex_db) { #endif @@ -1291,21 +1288,21 @@ void x_pv_game_chara_effect::ctrl(object_database* obj_db, texture_database* tex if (!j.category.str.size()) continue; - int32_t id = auth_3d_data_load_hash(j.file.hash_murmurhash, x_data, obj_db, tex_db); - if (!auth_3d_data_check_id_not_empty(id)) { - j.id = -1; + auth_3d_id id = auth_3d_data_load_hash(j.file.hash_murmurhash, x_data, obj_db, tex_db); + if (!id.check_not_empty()) { + j.id = {}; continue; } - auth_3d_data_read_file_modern(id); - auth_3d_data_set_enable(id, false); - auth_3d_data_set_repeat(id, false); - auth_3d_data_set_paused(id, true); - auth_3d_data_set_visibility(id, false); - auth_3d_data_set_frame_rate(id, frame_rate_control); + 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); if (j.field_0) - auth_3d_data_set_src_dst_chara(id, j.src_chara, j.dst_chara); + id.set_src_dst_chara(j.src_chara, j.dst_chara); j.id = id; @@ -1325,8 +1322,7 @@ void x_pv_game_chara_effect::ctrl(object_database* obj_db, texture_database* tex if (!j.category.str.size()) continue; - if (auth_3d_data_check_id_not_empty(j.id) - && !auth_3d_data_check_id_loaded(j.id)) + if (j.id.check_not_empty() && !j.id.check_loaded()) wait_load |= true; } @@ -1356,8 +1352,8 @@ void x_pv_game_chara_effect::load(int32_t pv_id, pvpp* play_param, pvpp_chara_effect& chara_effect = chara.chara_effect; - ::chara_index src_chara = (::chara_index)chara_effect.base_chara; - ::chara_index dst_chara = charas[i]; + chara_index src_chara = (chara_index)chara_effect.base_chara; + chara_index dst_chara = charas[i]; /*if (dst_chara == CHARA_EXTRA) dst_chara = src_chara;*/ @@ -1474,21 +1470,19 @@ void x_pv_game_chara_effect::set_chara_effect(int32_t chara_id, int32_t index, i if (index < 0 || index >= auth_3d.size()) return; - int32_t& id = auth_3d[index].id; + auth_3d_id& id = auth_3d[index].id; - if (!auth_3d_data_check_id_not_empty(id)) + if (!id.check_not_empty()) return; - if (auth_3d_data_get_enable(id)) { - float_t req_frame = (float_t)((double_t)(time - auth_3d[index].time) * 0.000000001) * 60.0f; - auth_3d_data_set_req_frame(id, req_frame); - } + if (id.get_enable()) + id.set_req_frame((float_t)((double_t)(time - auth_3d[index].time) * 0.000000001) * 60.0f); else { - auth_3d_data_set_enable(id, true); - auth_3d_data_set_paused(id, false); - auth_3d_data_set_repeat(id, false); - auth_3d_data_set_req_frame(id, 0.0f); - auth_3d_data_set_visibility(id, true); + id.set_enable(true); + id.set_paused(false); + id.set_repeat(false); + id.set_req_frame(0.0f); + id.set_visibility(true); auth_3d[index].time = time; } @@ -1509,7 +1503,7 @@ void x_pv_game_chara_effect::set_chara_effect(int32_t chara_id, int32_t index, i max_frame = (float_t)((double_t)(*key - auth_3d[index].time) * 0.000000001) * 60.0f - 1.0f; } - auth_3d_data_set_max_frame(id, max_frame); + id.set_max_frame(max_frame); } void x_pv_game_chara_effect::set_chara_effect_time(int32_t chara_id, int32_t index, int64_t time) { @@ -1517,12 +1511,11 @@ void x_pv_game_chara_effect::set_chara_effect_time(int32_t chara_id, int32_t ind return; for (x_pv_game_chara_effect_auth_3d& i : auth_3d[chara_id]) { - if (!auth_3d_data_check_id_not_empty(i.id) || !auth_3d_data_get_enable(i.id)) + if (!i.id.check_not_empty() || !i.id.get_enable()) continue; - float_t req_frame = (float_t)((double_t)(time - i.time) * 0.000000001) * 60.0f; - auth_3d_data_set_req_frame(i.id, req_frame); - auth_3d_data_set_paused(i.id, 0); + i.id.set_req_frame((float_t)((double_t)(time - i.time) * 0.000000001) * 60.0f); + i.id.set_paused(false); } } @@ -1532,8 +1525,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 (auth_3d_data_check_id_not_empty(j.id)) - auth_3d_data_set_enable(j.id, false); + if (j.id.check_not_empty()) + j.id.set_enable(false); } void x_pv_game_chara_effect::stop_chara_effect(int32_t chara_id, int32_t index) { @@ -1541,8 +1534,8 @@ void x_pv_game_chara_effect::stop_chara_effect(int32_t chara_id, int32_t index) return; for (x_pv_game_chara_effect_auth_3d& i : auth_3d[chara_id]) - if (auth_3d_data_check_id_not_empty(i.id)) - auth_3d_data_set_enable(i.id, false); + if (i.id.check_not_empty()) + i.id.set_enable(false); } void x_pv_game_chara_effect::unload() { @@ -1555,7 +1548,7 @@ void x_pv_game_chara_effect::unload() { if (!j.category.str.size()) continue; - auth_3d_data_unload_id(j.id, rctx_ptr); + j.id.unload_id(rctx_ptr); auth_3d_data_unload_category(j.category.hash_murmurhash); object_storage_unload_set(j.object_set.hash_murmurhash); } @@ -1752,7 +1745,7 @@ x_pv_game_data::~x_pv_game_data() { #if BAKE_PV826 void x_pv_game_data::ctrl(float_t curr_time, float_t delta_time, - std::map* effchrpv_auth_3d_mot_ids) { + std::map* effchrpv_auth_3d_mot_ids) { #else void x_pv_game_data::ctrl(float_t curr_time, float_t delta_time) { #endif @@ -1965,7 +1958,7 @@ x_pv_game_stage_effect_auth_3d::x_pv_game_stage_effect_auth_3d() : repeat(), fie void x_pv_game_stage_effect_auth_3d::reset() { repeat = false; field_1 = true; - id = -1; + id = {}; } x_pv_game_stage_effect_glitter::x_pv_game_stage_effect_glitter() : @@ -2305,19 +2298,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()) { - int32_t id = auth_3d_data_load_hash(stg_eff_auth_3d + auth_3d_id id = auth_3d_data_load_hash(stg_eff_auth_3d .name.hash_murmurhash, x_data, &obj_db, &tex_db); - if (!auth_3d_data_check_id_not_empty(id)) { - eff_auth_3d.id = -1; + if (!id.check_not_empty()) { + eff_auth_3d.id = {}; continue; } - auth_3d_data_read_file_modern(id); - auth_3d_data_set_enable(id, false); - auth_3d_data_set_repeat(id, true); - auth_3d_data_set_paused(id, false); - auth_3d_data_set_visibility(id, false); - auth_3d_data_set_frame_rate(id, &bpm_frame_rate_control); + 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); eff_auth_3d.id = id; auth_3d_ids.insert({ stg_eff_auth_3d.name.hash_murmurhash, id }); @@ -2359,8 +2352,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 (auth_3d_data_check_id_not_empty(j.id) - && !auth_3d_data_check_id_loaded(j.id)) + if (j.id.check_not_empty() && !j.id.check_loaded()) wait_load |= true; } @@ -2368,8 +2360,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 (auth_3d_data_check_id_not_empty(k.id) - && !auth_3d_data_check_id_loaded(k.id)) + if (k.id.check_not_empty() && !k.id.check_loaded()) wait_load |= true; } @@ -2446,8 +2437,8 @@ 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) { - int32_t& id = i.id; - auth_3d_data_set_repeat(id, false); + auth_3d_id& id = i.id; + id.set_repeat(false); } } } break; @@ -2507,7 +2498,7 @@ void x_pv_game_stage::ctrl_inner() { bool stop = false; if (auth_3d.size()) - stop = auth_3d_data_get_ended(auth_3d[eff.main_auth_3d_index].id); + stop = auth_3d[eff.main_auth_3d_index].id.get_ended(); if (!stop) { for (x_pv_game_stage_effect_glitter& j : glitter) @@ -2584,19 +2575,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()) { - int32_t id = auth_3d_data_load_hash(stg_chg_eff_auth_3d + auth_3d_id id = auth_3d_data_load_hash(stg_chg_eff_auth_3d .name.hash_murmurhash, x_data, &obj_db, &tex_db); - if (!auth_3d_data_check_id_not_empty(id)) { - chg_eff_auth_3d.id = -1; + if (!id.check_not_empty()) { + chg_eff_auth_3d.id = {}; continue; } - auth_3d_data_read_file_modern(id); - auth_3d_data_set_enable(id, false); - auth_3d_data_set_repeat(id, false); - auth_3d_data_set_paused(id, false); - auth_3d_data_set_visibility(id, false); - auth_3d_data_set_frame_rate(id, &bpm_frame_rate_control); + 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); chg_eff_auth_3d.id = id; auth_3d_ids.insert({ stg_chg_eff_auth_3d.name.hash_murmurhash, id }); @@ -2709,15 +2700,15 @@ 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) { - int32_t& id = i.id; - auth_3d_data_set_camera_root_update(id, false); - auth_3d_data_set_enable(id, true); - auth_3d_data_set_repeat(id, i.repeat); - auth_3d_data_set_req_frame(id, frame); - auth_3d_data_set_max_frame(id, auth_3d_data_get_last_frame(id) - 1.0f); - auth_3d_data_set_paused(id, false); - auth_3d_data_set_visibility(id, !!(flags & 0x01)); - auth_3d_data_set_frame_rate(id, &bpm_frame_rate_control); + auth_3d_id& id = i.id; + id.set_camera_root_update(false); + id.set_enable(true); + 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); } for (x_pv_game_stage_effect_glitter& i : chg_eff.glitter) { @@ -2779,22 +2770,22 @@ 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) { - int32_t& id = i.id; - auth_3d_data_set_camera_root_update(id, false); - auth_3d_data_set_enable(id, true); - auth_3d_data_set_repeat(id, true); - if (i.repeat && auth_3d_data_get_last_frame(id) <= frame) { - int32_t frame_offset = (int32_t)auth_3d_data_get_frame_offset(id); - int32_t last_frame = (int32_t)auth_3d_data_get_last_frame(id); - int32_t _frame = frame_offset + (int32_t)(frame - (float_t)frame_offset) % last_frame; + auth_3d_id& id = i.id; + id.set_camera_root_update(false); + id.set_enable(true); + 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; frame = (float_t)_frame + (frame - (float_t)(int32_t)frame); } - auth_3d_data_set_req_frame(id, frame); - auth_3d_data_set_max_frame(id, -1.0f); - auth_3d_data_set_paused(id, false); - auth_3d_data_set_visibility(id, true); - auth_3d_data_set_frame_rate(id, &bpm_frame_rate_control); + 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); } } @@ -2852,9 +2843,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) { - int32_t& id = i.id; - auth_3d_data_set_visibility(id, false); - auth_3d_data_set_enable(id, false); + auth_3d_id& id = i.id; + id.set_visibility(false); + id.set_enable(false); } for (x_pv_game_stage_effect_glitter& i : chg_eff.glitter) @@ -2897,9 +2888,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) { - int32_t& id = i.id; - auth_3d_data_set_visibility(id, false); - auth_3d_data_set_enable(id, false); + auth_3d_id& id = i.id; + id.set_visibility(false); + id.set_enable(false); } } @@ -2919,8 +2910,8 @@ void x_pv_game_stage::unload() { if (!stage_resource || !stage_id) return; - for (std::pair i : auth_3d_ids) - auth_3d_data_unload_id(i.second, rctx_ptr); + for (std::pair i : auth_3d_ids) + i.second.unload_id(rctx_ptr); auth_3d_ids.clear(); @@ -2976,11 +2967,11 @@ void x_pv_game_stage::unload() { x_pv_game::x_pv_game() : state(), pv_count(), pv_index(), state_old(), frame(), frame_float(), time(), rob_chara_ids(), play(), success(), chara_id(), pv_end(), playdata(), scene_rot_y(), branch_mode(), task_effect_init(), pause(), step_frame(), pv_id(), stage_id(), charas(), modules() { - light_auth_3d_id = -1; + light_auth_3d_id = {}; target_anim_fps = 60.0f; anim_frame_speed = 1.0f; scene_rot_mat = mat4_identity; - for (::chara_index& i : charas) + for (chara_index& i : charas) i = CHARA_MAX; for (int32_t& i : modules) i = 0; @@ -3005,8 +2996,8 @@ FILE* pipe; #if DOF_BAKE static void a3da_key_rev(a3da_key& k, std::vector& values_src) { - std::vector value; - int32_t type = interpolate_chs_reverse_sequence(values_src, value); + std::vector values; + int32_t type = interpolate_chs_reverse_sequence(values_src, values); k = {}; switch (type) { @@ -3015,15 +3006,22 @@ static void a3da_key_rev(a3da_key& k, std::vector& values_src) { k.type = A3DA_KEY_NONE; return; case 1: - k.value = value[0].value; + k.value = values[0].value; k.type = A3DA_KEY_STATIC; - break; + return; case 2: + k.type = A3DA_KEY_LINEAR; + for (kft3& i : values) { + i.tangent1 = 0.0f; + i.tangent2 = 0.0f; + } + break; + case 3: + k.type = A3DA_KEY_HERMITE; break; } - k.type = A3DA_KEY_HERMITE; - k.keys = value; + k.keys.assign(values.begin(), values.end()); k.max_frame = (float_t)(values_src.size() + 1); } #endif @@ -3171,7 +3169,7 @@ bool x_pv_game::Ctrl() { data_struct* x_data = &data_list[DATA_X]; - light_auth_3d_id = -1; + light_auth_3d_id = {}; { data_struct* aft_data = &data_list[DATA_AFT]; auth_3d_database* auth_3d_db = &aft_data->data_ft.auth_3d_db; @@ -3184,14 +3182,14 @@ bool x_pv_game::Ctrl() { if (hash_string_murmurhash(i.name) == light_auth_3d_hash) { light_auth_3d_id = auth_3d_data_load_uid( (int32_t)(&i - auth_3d_db->uid.data()), auth_3d_db); - if (!auth_3d_data_check_id_not_empty(light_auth_3d_id)) { - light_auth_3d_id = -1; + if (!light_auth_3d_id.check_not_empty()) { + light_auth_3d_id = {}; break; } - auth_3d_data_read_file(light_auth_3d_id, auth_3d_db); - auth_3d_data_set_enable(light_auth_3d_id, false); - auth_3d_data_set_visibility(light_auth_3d_id, false); + light_auth_3d_id.read_file(auth_3d_db); + light_auth_3d_id.set_enable(false); + light_auth_3d_id.set_visibility(false); break; } } @@ -3201,8 +3199,7 @@ bool x_pv_game::Ctrl() { case 8: { bool wait_load = false; - if (auth_3d_data_check_id_not_empty(light_auth_3d_id) - && !auth_3d_data_check_id_loaded(light_auth_3d_id)) + if (light_auth_3d_id.check_not_empty() && !light_auth_3d_id.check_loaded()) wait_load |= true; if (wait_load) @@ -3550,11 +3547,10 @@ bool x_pv_game::Ctrl() { for (int32_t i = 0; i < X_PV_GAME_STAGE_EFFECT_COUNT; i++) { x_pv_game_stage_effect& eff = stage_data.effect[i]; for (x_pv_game_stage_effect_auth_3d& j : eff.auth_3d) { - if (!auth_3d_data_check_id_not_empty(j.id) - || !auth_3d_data_check_id_loaded(j.id)) + if (!j.id.check_not_empty() || !j.id.check_loaded()) continue; - auth_3d* auth = auth_3d_data_get_auth_3d(j.id); + auth_3d* auth = j.id.get_auth_3d(); if (!auth || !auth->material_list.size() || !auth->object_hrc.size()) continue; @@ -3571,11 +3567,10 @@ bool x_pv_game::Ctrl() { for (int32_t j = 0; j < X_PV_GAME_STAGE_EFFECT_COUNT; j++) { x_pv_game_stage_change_effect& chg_eff = stage_data.change_effect[i][j]; for (x_pv_game_stage_effect_auth_3d& k : chg_eff.auth_3d) { - if (!auth_3d_data_check_id_not_empty(k.id) - || !auth_3d_data_check_id_loaded(k.id)) + if (!k.id.check_not_empty() || !k.id.check_loaded()) continue; - auth_3d* auth = auth_3d_data_get_auth_3d(k.id); + auth_3d* auth = k.id.get_auth_3d(); if (!auth || !auth->material_list.size() || !auth->object_hrc.size()) continue; @@ -3610,12 +3605,12 @@ bool x_pv_game::Ctrl() { && x_pv_game_dsc_process(this, this->time)) pv_data[pv_index].dsc_data.dsc_data_ptr++; - auth_3d_data_set_enable(light_auth_3d_id, true); - auth_3d_data_set_camera_root_update(light_auth_3d_id, false); - auth_3d_data_set_paused(light_auth_3d_id, false); - auth_3d_data_set_repeat(light_auth_3d_id, false); - auth_3d_data_set_visibility(light_auth_3d_id, true); - auth_3d_data_set_req_frame(light_auth_3d_id, 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(0.0f); #if BAKE_PV826 if (pv_id == 826) { @@ -3645,18 +3640,18 @@ bool x_pv_game::Ctrl() { for (auto& i : effchrpv_auth_3d_rob_mot_ids) { x_pv_game_a3da_to_mot& a2m = i.second; - auth_3d* auth = auth_3d_data_get_auth_3d(a2m.auth_3d_id); + auth_3d* auth = a2m.id.get_auth_3d(); a2m.get_bone_indices(&auth->object_hrc[0]); } for (auto& i : effchrpv_auth_3d_mot_ids) { - int32_t& id = i.second; - auth_3d_data_set_repeat(id, false); - auth_3d_data_set_camera_root_update(id, false); - auth_3d_data_set_enable(id, true); - auth_3d_data_set_paused(id, false); - auth_3d_data_set_visibility(id, false); - auth_3d_data_set_req_frame(id, 0.0f); + 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(false); + id.set_req_frame(0.0f); } } #endif @@ -4085,7 +4080,7 @@ void x_pv_game::Window() { Basic(); } -void x_pv_game::Load(int32_t pv_id, int32_t stage_id, ::chara_index charas[6], int32_t modules[6]) { +void x_pv_game::Load(int32_t pv_id, int32_t stage_id, chara_index charas[6], int32_t modules[6]) { data_struct* aft_data = &data_list[DATA_AFT]; motion_database* aft_mot_db = &aft_data->data_ft.mot_db; @@ -4265,7 +4260,9 @@ bool mot_write_motion(void* data, const char* path, const char* file, uint32_t h std::string mot_file = "mot_" + set_info->name + ".bin"; - mot_set* mot_set = new ::mot_set; + prj::shared_ptr alloc = prj::shared_ptr(new alloc_data); + + ::mot_set* mot_set = alloc->allocate<::mot_set>(); { farc f; farc::load_file(&f, path, file, hash); @@ -4276,7 +4273,7 @@ bool mot_write_motion(void* data, const char* path, const char* file, uint32_t h return true; } - mot_set->unpack_file(ff->data, ff->size, false); + mot_set->unpack_file(alloc, ff->data, ff->size, false); } if (!mot_set->ready) { @@ -4297,7 +4294,7 @@ bool mot_write_motion(void* data, const char* path, const char* file, uint32_t h break; } - mot_data* mot_data = &mot_set->vec[motion_index]; + mot_data* mot_data = &mot_set->mot_data[motion_index]; uint16_t key_set_count = mot_data->key_set_count - 1; if (!key_set_count) @@ -4310,7 +4307,7 @@ bool mot_write_motion(void* data, const char* path, const char* file, uint32_t h continue; x_pv_game_a3da_to_mot& a2m = i.second; - const mot_bone_info* bone_info = mot_data->bone_info.data(); + const mot_bone_info* bone_info = mot_data->bone_info_array; for (size_t key_set_offset = 0, i = 0; key_set_offset < key_set_count; i++) { motion_bone_index bone_index = (motion_bone_index)aft_bone_data->get_skeleton_bone_index( name, bone_names[bone_info[i].index].c_str()); @@ -4334,28 +4331,31 @@ bool mot_write_motion(void* data, const char* path, const char* file, uint32_t h fix_rotation(keys.z); } - mot_key_set_data& key_set_data_x = mot_data->key_set[key_set_offset]; - key_set_data_x.frames.clear(); - key_set_data_x.values.clear(); - key_set_data_x.type = mot_set::fit_keys_into_curve(keys.x, - key_set_data_x.frames, key_set_data_x.values); - key_set_data_x.keys_count = (uint16_t)key_set_data_x.frames.size(); + mot_key_set_data& key_set_data_x = mot_data->key_set_array[key_set_offset]; + key_set_data_x.frames = 0; + key_set_data_x.values = 0; + size_t keys_x_count = 0; + key_set_data_x.type = mot_set::fit_keys_into_curve(keys.x, alloc, + key_set_data_x.frames, key_set_data_x.values, keys_x_count); + key_set_data_x.keys_count = (uint16_t)keys_x_count; key_set_data_x.data_type = MOT_KEY_SET_DATA_F32; - mot_key_set_data& key_set_data_y = mot_data->key_set[key_set_offset + 1]; - key_set_data_y.frames.clear(); - key_set_data_y.values.clear(); - key_set_data_y.type = mot_set::fit_keys_into_curve(keys.y, - key_set_data_y.frames, key_set_data_y.values); - key_set_data_y.keys_count = (uint16_t)key_set_data_y.frames.size(); + mot_key_set_data& key_set_data_y = mot_data->key_set_array[key_set_offset + 1]; + key_set_data_y.frames = 0; + key_set_data_y.values = 0; + size_t keys_y_count = 0; + key_set_data_y.type = mot_set::fit_keys_into_curve(keys.y, alloc, + key_set_data_y.frames, key_set_data_y.values, keys_y_count); + key_set_data_y.keys_count = (uint16_t)keys_y_count; key_set_data_y.data_type = MOT_KEY_SET_DATA_F32; - mot_key_set_data& key_set_data_z = mot_data->key_set[key_set_offset + 2]; - key_set_data_z.frames.clear(); - key_set_data_z.values.clear(); - key_set_data_z.type = mot_set::fit_keys_into_curve(keys.z, - key_set_data_z.frames, key_set_data_z.values); - key_set_data_z.keys_count = (uint16_t)key_set_data_z.frames.size(); + mot_key_set_data& key_set_data_z = mot_data->key_set_array[key_set_offset + 2]; + key_set_data_z.frames = 0; + key_set_data_z.values = 0; + size_t keys_z_count = 0; + key_set_data_z.type = mot_set::fit_keys_into_curve(keys.z, alloc, + key_set_data_z.frames, key_set_data_z.values, keys_z_count); + key_set_data_z.keys_count = (uint16_t)keys_z_count; key_set_data_z.data_type = MOT_KEY_SET_DATA_F32; } @@ -4367,73 +4367,77 @@ bool mot_write_motion(void* data, const char* path, const char* file, uint32_t h fix_rotation(keys.y); fix_rotation(keys.z); - mot_key_set_data& key_set_data_x = mot_data->key_set[key_set_offset + 3]; - key_set_data_x.frames.clear(); - key_set_data_x.values.clear(); - key_set_data_x.type = mot_set::fit_keys_into_curve(keys.x, - key_set_data_x.frames, key_set_data_x.values); - key_set_data_x.keys_count = (uint16_t)key_set_data_x.frames.size(); + mot_key_set_data& key_set_data_x = mot_data->key_set_array[key_set_offset + 3]; + key_set_data_x.frames = 0; + key_set_data_x.values = 0; + size_t keys_x_count = 0; + key_set_data_x.type = mot_set::fit_keys_into_curve(keys.x, alloc, + key_set_data_x.frames, key_set_data_x.values, keys_x_count); + key_set_data_x.keys_count = (uint16_t)keys_x_count; key_set_data_x.data_type = MOT_KEY_SET_DATA_F32; - mot_key_set_data& key_set_data_y = mot_data->key_set[key_set_offset + 4]; - key_set_data_y.frames.clear(); - key_set_data_y.values.clear(); - key_set_data_y.type = mot_set::fit_keys_into_curve(keys.y, - key_set_data_y.frames, key_set_data_y.values); - key_set_data_y.keys_count = (uint16_t)key_set_data_y.frames.size(); + mot_key_set_data& key_set_data_y = mot_data->key_set_array[key_set_offset + 4]; + key_set_data_y.frames = 0; + key_set_data_y.values = 0; + size_t keys_y_count = 0; + key_set_data_y.type = mot_set::fit_keys_into_curve(keys.y, alloc, + key_set_data_y.frames, key_set_data_y.values, keys_x_count); + key_set_data_y.keys_count = (uint16_t)keys_y_count; key_set_data_y.data_type = MOT_KEY_SET_DATA_F32; - mot_key_set_data& key_set_data_z = mot_data->key_set[key_set_offset + 5]; - key_set_data_z.frames.clear(); - key_set_data_z.values.clear(); - key_set_data_z.type = mot_set::fit_keys_into_curve(keys.z, - key_set_data_z.frames, key_set_data_z.values); - key_set_data_z.keys_count = (uint16_t)key_set_data_z.frames.size(); + mot_key_set_data& key_set_data_z = mot_data->key_set_array[key_set_offset + 5]; + key_set_data_z.frames = 0; + key_set_data_z.values = 0; + size_t keys_z_count = 0; + key_set_data_z.type = mot_set::fit_keys_into_curve(keys.z, alloc, + key_set_data_z.frames, key_set_data_z.values, keys_z_count); + key_set_data_z.keys_count = (uint16_t)keys_z_count; key_set_data_z.data_type = MOT_KEY_SET_DATA_F32; } if (bone_index == MOTION_BONE_KL_AGO_WJ) { - mot_key_set_data& key_set_data_x = mot_data->key_set[key_set_offset]; - key_set_data_x.frames.clear(); - key_set_data_x.values.clear(); - key_set_data_x.values.push_back(0.0491406508f); + mot_key_set_data& key_set_data_x = mot_data->key_set_array[key_set_offset]; + key_set_data_x.frames = 0; + key_set_data_x.values = alloc->allocate(1); + key_set_data_x.values[0] = 0.0491406508f; key_set_data_x.type = MOT_KEY_SET_STATIC; key_set_data_x.keys_count = 1; key_set_data_x.data_type = MOT_KEY_SET_DATA_F32; - mot_key_set_data& key_set_data_y = mot_data->key_set[key_set_offset + 1]; - key_set_data_y.frames.clear(); - key_set_data_y.values.clear(); + mot_key_set_data& key_set_data_y = mot_data->key_set_array[key_set_offset + 1]; + key_set_data_y.frames = 0; + key_set_data_y.values = 0; key_set_data_y.type = MOT_KEY_SET_NONE; key_set_data_y.keys_count = 0; key_set_data_y.data_type = MOT_KEY_SET_DATA_F32; - mot_key_set_data& key_set_data_z = mot_data->key_set[key_set_offset + 2]; - key_set_data_z.frames.clear(); - key_set_data_z.values.clear(); + mot_key_set_data& key_set_data_z = mot_data->key_set_array[key_set_offset + 2]; + key_set_data_z.frames = 0; + key_set_data_z.values = 0; key_set_data_z.type = MOT_KEY_SET_NONE; key_set_data_z.keys_count = 0; key_set_data_z.data_type = MOT_KEY_SET_DATA_F32; } else if (bone_index == MOTION_BONE_N_KUBI_WJ_EX) { - mot_key_set_data& key_set_data_x = mot_data->key_set[key_set_offset]; - key_set_data_x.frames.clear(); - key_set_data_x.values.clear(); + mot_key_set_data& key_set_data_x = mot_data->key_set_array[key_set_offset]; + key_set_data_x.frames = 0; + key_set_data_x.values = 0; key_set_data_x.type = MOT_KEY_SET_NONE; key_set_data_x.keys_count = 1; key_set_data_x.data_type = MOT_KEY_SET_DATA_F32; - mot_key_set_data& key_set_data_y = mot_data->key_set[key_set_offset + 1]; - key_set_data_y.frames.clear(); - key_set_data_y.values.clear(); - key_set_data_y.values.push_back(0.0331281610f); + mot_key_set_data& key_set_data_y = mot_data->key_set_array[key_set_offset + 1]; + key_set_data_y.frames = 0; + key_set_data_y.values = 0; + key_set_data_y.values = alloc->allocate(1); + key_set_data_y.values[0] = 0.0331281610f; key_set_data_y.type = MOT_KEY_SET_STATIC; key_set_data_y.keys_count = 0; key_set_data_y.data_type = MOT_KEY_SET_DATA_F32; - mot_key_set_data& key_set_data_z = mot_data->key_set[key_set_offset + 2]; - key_set_data_z.frames.clear(); - key_set_data_z.values.clear(); + mot_key_set_data& key_set_data_z = mot_data->key_set_array[key_set_offset + 2]; + key_set_data_z.frames = 0; + key_set_data_z.values = 0; key_set_data_z.type = MOT_KEY_SET_NONE; key_set_data_z.keys_count = 0; key_set_data_z.data_type = MOT_KEY_SET_DATA_F32; @@ -4456,8 +4460,6 @@ bool mot_write_motion(void* data, const char* path, const char* file, uint32_t h std::string mot_farc = "pv826\\mot_" + set_info->name; f.write(mot_farc.c_str(), FARC_COMPRESS_FArC, false); } - - delete mot_set; return true; } #endif @@ -4537,9 +4539,9 @@ bool x_pv_game::Unload() { i = -1; } - auth_3d_data_unload_id(light_auth_3d_id, rctx_ptr); + light_auth_3d_id.unload_id(rctx_ptr); - light_auth_3d_id = -1; + light_auth_3d_id = {}; auth_3d_data_unload_category(light_category.c_str()); @@ -4576,7 +4578,7 @@ bool x_pv_game::Unload() { pv_id = 0; stage_id = 0; - for (::chara_index& i : charas) + for (chara_index& i : charas) i = CHARA_MAX; for (int32_t& i : modules) i = 0; @@ -4699,6 +4701,9 @@ XPVGameSelector::XPVGameSelector() : charas(), modules(), start(), exit() { i = 0; #if BAKE_PV826 + pv_id = 826; + stage_id = 26; + charas[0] = CHARA_MIKU; charas[1] = CHARA_RIN; charas[2] = CHARA_LEN; @@ -4979,7 +4984,7 @@ static void x_pv_game_chara_item_alpha_callback(void* data, int32_t chara_id, in continue; for (x_pv_game_song_effect_auth_3d& j : i.auth_3d) - auth_3d_data_set_draw_task_flags_alpha(j.id, draw_task_flags, alpha); + j.id.set_draw_task_flags_alpha(draw_task_flags, alpha); for (x_pv_game_song_effect_glitter& j : i.glitter) Glitter::glt_particle_manager->SetSceneEffectExtColor(j.scene_counter, @@ -5792,7 +5797,7 @@ static bool x_pv_game_dsc_process(x_pv_game* a1, int64_t curr_time) { if (chara_size == 0) chara_size_index = chara_init_data_get_chara_size_index(rob_chr->chara_index); else if (chara_size == 1) { - chara_index chara_index = CHARA_MIKU; + ::chara_index chara_index = CHARA_MIKU; if (a1->chara_id < pv_data.play_param->chara.size()) chara_index = (::chara_index)a1->pv_data[a1->pv_index] .play_param->chara[a1->chara_id].chara_effect.base_chara; @@ -6352,7 +6357,7 @@ static void x_pv_game_map_auth_3d_to_mot(x_pv_game* xpvgm, bool add_keys) { for (auto& i : xpvgm->effchrpv_auth_3d_rob_mot_ids) { rob_chara* rob_chr = rob_chara_array_get(xpvgm->rob_chara_ids[i.first]); x_pv_game_a3da_to_mot& a2m = i.second; - auth_3d* auth = auth_3d_data_get_auth_3d(a2m.auth_3d_id); + auth_3d* auth = a2m.id.get_auth_3d(); auth_3d_object_hrc* oh = &auth->object_hrc[0]; float_t auth_frame = auth->frame; @@ -7036,8 +7041,8 @@ static void x_pv_game_split_auth_3d_hrc_material_list(x_pv_game* xpvgm, obj_skin_bone* bone_array = skin->bone_array; uint32_t num_bone = skin->num_bone; - for (std::pair k : xpvgm->stage_data.auth_3d_ids) { - auth_3d* auth = auth_3d_data_get_auth_3d(k.second); + for (std::pair k : xpvgm->stage_data.auth_3d_ids) { + auth_3d* auth = k.second.get_auth_3d(); if (!auth || !auth->object_hrc.size()) continue; @@ -7075,8 +7080,8 @@ static void x_pv_game_split_auth_3d_hrc_material_list(x_pv_game* xpvgm, } } - for (std::pair k : xpvgm->stage_data.auth_3d_ids) { - auth_3d* auth = auth_3d_data_get_auth_3d(k.second); + for (std::pair k : xpvgm->stage_data.auth_3d_ids) { + auth_3d* auth = k.second.get_auth_3d(); if (!auth || !auth->object_hrc.size()) continue; @@ -7104,8 +7109,8 @@ static void x_pv_game_split_auth_3d_hrc_material_list(x_pv_game* xpvgm, l = (auth_3d_object*)((size_t)l - object_base + object_new_base); } - for (std::pair l : xpvgm->stage_data.auth_3d_ids) { - auth_3d* auth = auth_3d_data_get_auth_3d(l.second); + for (std::pair l : xpvgm->stage_data.auth_3d_ids) { + auth_3d* auth = l.second.get_auth_3d(); if (!auth || !auth->object_hrc.size()) continue; @@ -7167,8 +7172,8 @@ static void x_pv_game_split_auth_3d_hrc_material_list(x_pv_game* xpvgm, } } - for (std::pair i : xpvgm->stage_data.auth_3d_ids) { - auth_3d* auth = auth_3d_data_get_auth_3d(i.second); + for (std::pair i : xpvgm->stage_data.auth_3d_ids) { + auth_3d* auth = i.second.get_auth_3d(); if (!auth || !auth->object_hrc.size()) continue; diff --git a/src/ReDIVA/x_pv_game.hpp b/src/ReDIVA/x_pv_game.hpp index 13cfe67d..f64e1f33 100644 --- a/src/ReDIVA/x_pv_game.hpp +++ b/src/ReDIVA/x_pv_game.hpp @@ -13,6 +13,7 @@ #include #include #include +#include "config.hpp" #include "../CRE/Glitter/glitter.hpp" #include "../CRE/rob/rob.hpp" #include "../CRE/auth_3d.hpp" @@ -25,10 +26,6 @@ #include "../KKdLib/pvsr.hpp" #include "task_window.hpp" -#define BAKE_PNG 0 -#define BAKE_VIDEO 0 -#define BAKE_PV826 0 - struct x_pv_bar_beat_data { int32_t bar; float_t bar_time; @@ -161,7 +158,7 @@ struct x_pv_game_a3da_to_mot_keys { }; struct x_pv_game_a3da_to_mot { - int32_t auth_3d_id; + auth_3d_id id; int32_t gblctr; int32_t n_hara; int32_t n_hara_y; @@ -215,7 +212,7 @@ struct x_pv_game_a3da_to_mot { std::map bone_keys; std::map sec_bone_keys; - x_pv_game_a3da_to_mot(int32_t auth_3d_id); + x_pv_game_a3da_to_mot(auth_3d_id id); ~x_pv_game_a3da_to_mot(); void get_bone_indices(auth_3d_object_hrc* oh); @@ -223,10 +220,10 @@ struct x_pv_game_a3da_to_mot { #endif struct x_pv_game_song_effect_auth_3d { - int32_t id; + auth_3d_id id; x_pv_game_song_effect_auth_3d(); - x_pv_game_song_effect_auth_3d(int32_t id); + x_pv_game_song_effect_auth_3d(auth_3d_id id); void reset(); }; @@ -259,7 +256,7 @@ struct x_pv_game_camera { int32_t state; string_hash category; string_hash file; - int32_t auth_3d_id; + auth_3d_id id; FrameRateControl* frame_rate_control; x_pv_game_camera(); @@ -307,7 +304,7 @@ struct x_pv_game_chara_effect_auth_3d { string_hash file; string_hash category; string_hash object_set; - int32_t id; + auth_3d_id id; int64_t time; x_pv_game_chara_effect_auth_3d(); @@ -328,7 +325,7 @@ struct x_pv_game_chara_effect { #if BAKE_PV826 void ctrl(object_database* obj_db, texture_database* tex_db, - int32_t pv_id = -1, std::map* effchrpv_auth_3d_mot_ids = 0); + int32_t pv_id = -1, std::map* effchrpv_auth_3d_mot_ids = 0); void load(int32_t pv_id, pvpp* play_param, FrameRateControl* frame_rate_control, chara_index charas[6], std::unordered_map* effchrpv_auth_3d_mot_names = 0); #else @@ -398,7 +395,7 @@ struct x_pv_game_data { #if BAKE_PV826 void ctrl(float_t curr_time, float_t delta_time, - std::map* effchrpv_auth_3d_mot_ids = 0); + std::map* effchrpv_auth_3d_mot_ids = 0); #else void ctrl(float_t curr_time, float_t delta_time); #endif @@ -418,7 +415,7 @@ struct x_pv_game_data { struct x_pv_game_stage_effect_auth_3d { bool repeat; bool field_1; - int32_t id; + auth_3d_id id; x_pv_game_stage_effect_auth_3d(); @@ -515,7 +512,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(); @@ -561,10 +558,10 @@ public: std::unordered_map effchrpv_auth_3d_mot_names; #endif - int32_t light_auth_3d_id; + auth_3d_id light_auth_3d_id; #if BAKE_PV826 - std::map effchrpv_auth_3d_mot_ids; + std::map effchrpv_auth_3d_mot_ids; std::vector effchrpv_rob_mot_ids; std::map effchrpv_auth_3d_rob_mot_ids; @@ -589,7 +586,7 @@ public: int32_t pv_id; int32_t stage_id; - ::chara_index charas[6]; + chara_index charas[6]; int32_t modules[6]; x_pv_game();