From 3b4dee9cdc0a92f9372cd4a985f9d32d2f511729 Mon Sep 17 00:00:00 2001 From: korenkonder Date: Mon, 29 Jan 2024 17:16:20 +0300 Subject: [PATCH] Move auth_3d uid init --- src/CRE/auth_3d.cpp | 120 +++++++++++++------------- src/CRE/auth_3d.hpp | 5 +- src/CRE/effect.cpp | 4 +- src/ReDIVA/data_test/auth_3d_test.cpp | 2 +- src/ReDIVA/data_test/motion_test.cpp | 2 +- src/ReDIVA/pv_game/pv_game.cpp | 4 +- src/ReDIVA/x_pv_game.cpp | 13 ++- 7 files changed, 77 insertions(+), 73 deletions(-) diff --git a/src/CRE/auth_3d.cpp b/src/CRE/auth_3d.cpp index d8998551..c5e6eff7 100644 --- a/src/CRE/auth_3d.cpp +++ b/src/CRE/auth_3d.cpp @@ -2372,6 +2372,68 @@ auth_3d_uid_file_modern::~auth_3d_uid_file_modern() { } +auth_3d_id::auth_3d_id(uint32_t hash, void* data, object_database* obj_db, texture_database* tex_db) { + id = -1; + + int32_t index = 0; + while (auth_3d_data->data[index].uid != -1 || auth_3d_data->data[index].hash + != hash_murmurhash_empty && auth_3d_data->data[index].hash != -1) + if (++index >= AUTH_3D_DATA_COUNT) + return; + + auto elem = auth_3d_data->uid_files_modern.find(hash); + if (elem == auth_3d_data->uid_files_modern.end()) + elem = auth_3d_data->uid_files_modern.insert({ hash, {} }).first; + + auth_3d_uid_file_modern* uid_file = &elem->second; + uid_file->load_count = 0; + uid_file->hash = hash; + uid_file->file_name.clear(); + uid_file->file_name.shrink_to_fit(); + uid_file->state = 0; + uid_file->name.clear(); + uid_file->name.shrink_to_fit(); + uid_file->farc = 0; + uid_file->data = data; + uid_file->obj_db = obj_db; + uid_file->tex_db = tex_db; + + auth_3d_data->data[index].reset(); + + if (++auth_3d_load_counter < 0) + auth_3d_load_counter = 1; + + int32_t id = ((auth_3d_load_counter & 0x7FFF) << 16) | index & 0x7FFF; + auth_3d_data->data[index].hash = hash; + auth_3d_data->data[index].id = id; + auth_3d_data->loaded_ids.push_back(id); + this->id = id; +} + +auth_3d_id::auth_3d_id(int32_t uid, auth_3d_database* auth_3d_db) { + id = -1; + + if (uid >= auth_3d_db->uid.size() || !auth_3d_db->uid[uid].enabled) + return; + + 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; + + auth_3d_data->data[index].reset(); + + if (++auth_3d_load_counter < 0) + auth_3d_load_counter = 1; + + int32_t id = ((auth_3d_load_counter & 0x7FFF) << 16) | index & 0x7FFF; + auth_3d_data->data[index].uid = uid; + auth_3d_data->data[index].id = id; + auth_3d_data->loaded_ids.push_back(id); + this->id = id; +} + 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]; @@ -2950,64 +3012,6 @@ 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); } -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; - - auth_3d_uid_file_modern* uid_file = &elem->second; - uid_file->load_count = 0; - uid_file->hash = hash; - uid_file->file_name.clear(); - uid_file->file_name.shrink_to_fit(); - uid_file->state = 0; - uid_file->name.clear(); - uid_file->name.shrink_to_fit(); - uid_file->farc = 0; - uid_file->data = data; - uid_file->obj_db = obj_db; - uid_file->tex_db = tex_db; - - 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 auth_3d_id(); - - auth_3d_data->data[index].reset(); - - if (++auth_3d_load_counter < 0) - auth_3d_load_counter = 1; - - int32_t id = ((auth_3d_load_counter & 0x7FFF) << 16) | index & 0x7FFF; - auth_3d_data->data[index].hash = hash; - auth_3d_data->data[index].id = id; - auth_3d_data->loaded_ids.push_back(id); - return auth_3d_id(id); -} - -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 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 auth_3d_id(); - - auth_3d_data->data[index].reset(); - - if (++auth_3d_load_counter < 0) - auth_3d_load_counter = 1; - - int32_t id = ((auth_3d_load_counter & 0x7FFF) << 16) | index & 0x7FFF; - auth_3d_data->data[index].uid = uid; - auth_3d_data->data[index].id = id; - auth_3d_data->loaded_ids.push_back(id); - return auth_3d_id(id); -} - void auth_3d_data_unload_category(const char* category_name) { auth_3d_data_struct_unload_category(auth_3d_data, category_name); } diff --git a/src/CRE/auth_3d.hpp b/src/CRE/auth_3d.hpp index 716025f1..8f42a57e 100644 --- a/src/CRE/auth_3d.hpp +++ b/src/CRE/auth_3d.hpp @@ -798,6 +798,9 @@ struct auth_3d_id { this->id = id; } + auth_3d_id(uint32_t hash, void* data, object_database* obj_db, texture_database* tex_db); + auth_3d_id(int32_t uid, auth_3d_database* auth_3d_db); + inline bool is_null() { return id == -1; } @@ -1015,8 +1018,6 @@ extern const char* auth_3d_data_get_uid_name(int32_t uid, auth_3d_database* auth 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 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_free(); diff --git a/src/CRE/effect.cpp b/src/CRE/effect.cpp index ea1ad9b6..1c80dedd 100644 --- a/src/CRE/effect.cpp +++ b/src/CRE/effect.cpp @@ -1881,7 +1881,7 @@ void TaskEffectAuth3D::set_stage_hashes(const std::vector& stage_hashe if (stage.count == stage.max_count) break; - auth_3d_id id = auth_3d_data_load_hash(j, data, obj_db, tex_db); + auth_3d_id id = auth_3d_id(j, data, obj_db, tex_db); if (!id.check_not_empty()) break; @@ -1916,7 +1916,7 @@ void TaskEffectAuth3D::set_stage_indices(const std::vector& stage_indic if (stage.count == stage.max_count) break; - auth_3d_id id = auth_3d_data_load_uid(j, aft_auth_3d_db); + auth_3d_id id = auth_3d_id(j, aft_auth_3d_db); if (!id.check_not_empty()) break; diff --git a/src/ReDIVA/data_test/auth_3d_test.cpp b/src/ReDIVA/data_test/auth_3d_test.cpp index a3410496..6e9f3610 100644 --- a/src/ReDIVA/data_test/auth_3d_test.cpp +++ b/src/ReDIVA/data_test/auth_3d_test.cpp @@ -545,7 +545,7 @@ void Auth3dTestTask::SetAuth3dId() { auth_3d_database* aft_auth_3d_db = &aft_data->data_ft.auth_3d_db; auth_3d_id.unload(rctx_ptr); - auth_3d_id = auth_3d_data_load_uid(auth_3d_uid, aft_auth_3d_db); + auth_3d_id = ::auth_3d_id(auth_3d_uid, aft_auth_3d_db); if (auth_3d_id.check_not_empty()) { auth_3d_id.set_enable(false); auth_3d_id.read_file(aft_auth_3d_db); diff --git a/src/ReDIVA/data_test/motion_test.cpp b/src/ReDIVA/data_test/motion_test.cpp index a6c34c4e..60738357 100644 --- a/src/ReDIVA/data_test/motion_test.cpp +++ b/src/ReDIVA/data_test/motion_test.cpp @@ -824,7 +824,7 @@ void DataTestMotA3d::LoadAuth3d(std::string&& name) { if (uid == -1) return; - auth_3d_id id = auth_3d_data_load_uid(uid, aft_auth_3d_db); + auth_3d_id id = auth_3d_id(uid, aft_auth_3d_db); if (!id.check_not_empty()) return; diff --git a/src/ReDIVA/pv_game/pv_game.cpp b/src/ReDIVA/pv_game/pv_game.cpp index c7a0cb2e..5a0fd9f3 100644 --- a/src/ReDIVA/pv_game/pv_game.cpp +++ b/src/ReDIVA/pv_game/pv_game.cpp @@ -3197,7 +3197,7 @@ bool pv_game::load() { prj::sort_unique(data.loaded_auth_3d_uids); for (int32_t& i : data.loaded_auth_3d_uids) { - auth_3d_id id = auth_3d_data_load_uid(i, aft_auth_3d_db); + auth_3d_id id = auth_3d_id(i, aft_auth_3d_db); if (!id.check_not_empty()) continue; @@ -3289,7 +3289,7 @@ bool pv_game::load() { itmpv_reset(); for (struc_269& i : data.field_2DA08) { for (auto& j : i.data) { - auth_3d_id id = auth_3d_data_load_uid(j.second, aft_auth_3d_db); + auth_3d_id id = auth_3d_id(j.second, aft_auth_3d_db); if (!id.check_not_empty()) continue; diff --git a/src/ReDIVA/x_pv_game.cpp b/src/ReDIVA/x_pv_game.cpp index 09d5345c..14b3cd6b 100644 --- a/src/ReDIVA/x_pv_game.cpp +++ b/src/ReDIVA/x_pv_game.cpp @@ -820,7 +820,7 @@ void x_pv_game_camera::ctrl(float_t curr_time) { if (!auth_3d_data_check_category_loaded(category.hash_murmurhash)) break; - auth_3d_id id = auth_3d_data_load_hash(file.hash_murmurhash, &data_list[DATA_X], 0, 0); + auth_3d_id id = auth_3d_id(file.hash_murmurhash, &data_list[DATA_X], 0, 0); if (id.check_not_empty()) { id.read_file_modern(); id.set_enable(false); @@ -926,7 +926,7 @@ void x_pv_game_effect::ctrl(object_database* obj_db, texture_database* tex_db) { x_pv_game_song_effect& song_effect = this->song_effect[i]; pvpp_effect& effect = play_param->effect[i]; for (string_hash& j : effect.auth_3d) { - auth_3d_id id = auth_3d_data_load_hash(j.hash_murmurhash, x_data, obj_db, tex_db); + auth_3d_id id = auth_3d_id(j.hash_murmurhash, x_data, obj_db, tex_db); if (!id.check_not_empty()) continue; @@ -1323,7 +1323,7 @@ void x_pv_game_chara_effect::ctrl(object_database* obj_db, texture_database* tex if (!j.category.str.size()) continue; - auth_3d_id id = auth_3d_data_load_hash(j.file.hash_murmurhash, x_data, obj_db, tex_db); + auth_3d_id id = auth_3d_id(j.file.hash_murmurhash, x_data, obj_db, tex_db); if (!id.check_not_empty()) { j.id = {}; continue; @@ -4805,7 +4805,7 @@ void x_pv_game_stage::ctrl(float_t delta_time) { auto elem = auth_3d_ids.find(stg_eff_auth_3d.name.hash_murmurhash); if (elem == auth_3d_ids.end()) { - auth_3d_id id = auth_3d_data_load_hash(stg_eff_auth_3d + auth_3d_id id = auth_3d_id(stg_eff_auth_3d .name.hash_murmurhash, x_data, &obj_db, &tex_db); if (!id.check_not_empty()) { eff_auth_3d.id = {}; @@ -5083,7 +5083,7 @@ void x_pv_game_stage::load_change_effect(int32_t curr_stage_effect, int32_t next auto elem = auth_3d_ids.find(stg_chg_eff_auth_3d.name.hash_murmurhash); if (elem == auth_3d_ids.end()) { - auth_3d_id id = auth_3d_data_load_hash(stg_chg_eff_auth_3d + auth_3d_id id = auth_3d_id(stg_chg_eff_auth_3d .name.hash_murmurhash, x_data, &obj_db, &tex_db); if (!id.check_not_empty()) { chg_eff_auth_3d.id = {}; @@ -6051,8 +6051,7 @@ bool x_pv_game::ctrl() { uint32_t light_auth_3d_hash = hash_utf8_murmurhash(buf); for (auth_3d_database_uid& i : aft_auth_3d_db->uid) if (hash_string_murmurhash(i.name) == light_auth_3d_hash) { - light_auth_3d_id = auth_3d_data_load_uid( - (int32_t)(&i - aft_auth_3d_db->uid.data()), aft_auth_3d_db); + light_auth_3d_id = auth_3d_id((int32_t)(&i - aft_auth_3d_db->uid.data()), aft_auth_3d_db); if (!light_auth_3d_id.check_not_empty()) { light_auth_3d_id = {}; break;