From b58700fc527bd657cb823b5afcb25b2dfb94b5e4 Mon Sep 17 00:00:00 2001 From: korenkonder Date: Sun, 17 May 2026 09:14:07 +0300 Subject: [PATCH] Overhaul of Object system --- src/CRE/Glitter/effect_group.cpp | 2 +- src/CRE/Glitter/effect_inst.cpp | 24 +- src/CRE/Glitter/file_reader.cpp | 4 +- src/CRE/Glitter/render_scene.cpp | 2 +- src/CRE/auth_3d.cpp | 48 +- src/CRE/config.hpp | 1 + src/CRE/effect.cpp | 10 +- src/CRE/mdl/disp_manager.cpp | 314 ++- src/CRE/mdl/disp_manager.hpp | 46 +- src/CRE/mdl/draw_object.cpp | 64 +- src/CRE/object.cpp | 3030 ++++++++++++----------- src/CRE/object.hpp | 190 +- src/CRE/ogl_buffer_object.cpp | 363 +++ src/CRE/ogl_buffer_object.hpp | 70 + src/CRE/render.cpp | 2 +- src/CRE/rob/ex_block.cpp | 54 +- src/CRE/rob/rob.cpp | 120 +- src/CRE/rob/rob.hpp | 5 +- src/CRE/rob/rob_item.cpp | 14 +- src/CRE/rob/skin_param.cpp | 6 +- src/CRE/stage.cpp | 18 +- src/CRE/stage_modern.cpp | 12 +- src/KKdLib/database/object.cpp | 10 + src/KKdLib/database/object.hpp | 1 + src/KKdLib/msgpack.cpp | 13 + src/KKdLib/msgpack.hpp | 2 + src/KKdLib/obj.cpp | 10 +- src/KKdLib/obj.hpp | 48 +- src/ReDIVA/app.cpp | 2 +- src/ReDIVA/data_edit/face_anim.cpp | 8 +- src/ReDIVA/data_edit/glitter_editor.cpp | 12 +- src/ReDIVA/data_initialize.cpp | 4 +- src/ReDIVA/data_test/auth_3d_test.cpp | 14 +- src/ReDIVA/data_test/motion_test.cpp | 12 +- src/ReDIVA/data_test/object_test.cpp | 86 +- src/ReDIVA/data_test/object_test.hpp | 8 +- src/ReDIVA/data_test/rob_osage_test.cpp | 4 +- src/ReDIVA/data_view/object.cpp | 12 +- src/ReDIVA/graphics/color_change.cpp | 20 +- src/ReDIVA/graphics/material.cpp | 42 +- src/ReDIVA/pv_game/pv_game.cpp | 36 +- src/ReDIVA/x_pv_game.cpp | 169 +- 42 files changed, 2697 insertions(+), 2215 deletions(-) create mode 100644 src/CRE/ogl_buffer_object.cpp create mode 100644 src/CRE/ogl_buffer_object.hpp diff --git a/src/CRE/Glitter/effect_group.cpp b/src/CRE/Glitter/effect_group.cpp index 172011d2..e7cf8d37 100644 --- a/src/CRE/Glitter/effect_group.cpp +++ b/src/CRE/Glitter/effect_group.cpp @@ -30,7 +30,7 @@ namespace Glitter { for (Mesh& i : meshes) if (i.object_set_hash != hash_murmurhash_empty) { - objset_info_storage_unload_set(i.object_set_hash); + free_objset(i.object_set_hash); i.load = false; } diff --git a/src/CRE/Glitter/effect_inst.cpp b/src/CRE/Glitter/effect_inst.cpp index b66fff05..9d2113ac 100644 --- a/src/CRE/Glitter/effect_inst.cpp +++ b/src/CRE/Glitter/effect_inst.cpp @@ -449,12 +449,10 @@ namespace Glitter { if (ext_anim->mesh_name) { if (ext_anim->mesh_index == -1) - ext_anim->mesh_index = objset_info_storage_get_obj_mesh_index( - ext_anim->object, ext_anim->mesh_name); + ext_anim->mesh_index = get_mesh_index(ext_anim->object, ext_anim->mesh_name); if (ext_anim->mesh_index != -1) { - obj_mesh* mesh = objset_info_storage_get_obj_mesh_by_index( - ext_anim->object, ext_anim->mesh_index); + obj_mesh* mesh = get_mesh(ext_anim->object, ext_anim->mesh_index); if (mesh) { mat4_mul(obj_mat, &mat, &mat); ext_anim->mat = mat; @@ -479,13 +477,11 @@ namespace Glitter { if (!ext_anim->mesh_name) return; - ext_anim->mesh_index = objset_info_storage_get_obj_mesh_index( - ext_anim->object, ext_anim->mesh_name); + ext_anim->mesh_index = get_mesh_index(ext_anim->object, ext_anim->mesh_name); } if (ext_anim->mesh_index != -1) { - obj_mesh* mesh = objset_info_storage_get_obj_mesh_by_index(ext_anim->object, - ext_anim->mesh_index); + obj_mesh* mesh = get_mesh(ext_anim->object, ext_anim->mesh_index); if (mesh) { ext_anim->translation = mesh->bounding_sphere.center; goto SetFlags; @@ -1149,12 +1145,10 @@ namespace Glitter { if (ext_anim->mesh_name) { if (ext_anim->mesh_index == -1) - ext_anim->mesh_index = objset_info_storage_get_obj_mesh_index_by_hash( - ext_anim->object_hash, ext_anim->mesh_name); + ext_anim->mesh_index = get_mesh_index_modern(ext_anim->object_hash, ext_anim->mesh_name); if (ext_anim->mesh_index != -1) { - obj_mesh* mesh = objset_info_storage_get_obj_mesh_by_object_hash_index( - ext_anim->object_hash, ext_anim->mesh_index); + obj_mesh* mesh = get_mesh_modern(ext_anim->object_hash, ext_anim->mesh_index); if (mesh) { vec3* trans = &mesh->bounding_sphere.center; SetExtAnim(&mat, obj_mat, trans, true); @@ -1170,13 +1164,11 @@ namespace Glitter { if (!ext_anim->mesh_name) return; - ext_anim->mesh_index = objset_info_storage_get_obj_mesh_index_by_hash( - ext_anim->object_hash, ext_anim->mesh_name); + ext_anim->mesh_index = get_mesh_index_modern(ext_anim->object_hash, ext_anim->mesh_name); } if (ext_anim->mesh_index != -1) { - obj_mesh* mesh = objset_info_storage_get_obj_mesh_by_object_hash_index( - ext_anim->object_hash, ext_anim->mesh_index); + obj_mesh* mesh = get_mesh_modern(ext_anim->object_hash, ext_anim->mesh_index); if (mesh) { vec3* trans = &mesh->bounding_sphere.center; SetExtAnim(0, 0, trans, true); diff --git a/src/CRE/Glitter/file_reader.cpp b/src/CRE/Glitter/file_reader.cpp index f33fd289..d085e046 100644 --- a/src/CRE/Glitter/file_reader.cpp +++ b/src/CRE/Glitter/file_reader.cpp @@ -231,7 +231,7 @@ namespace Glitter { if (type == Glitter::X) for (Mesh& i : effect_group->meshes) if (!i.ready && i.object_set_hash != hash_murmurhash_empty && i.object_set_hash != -1) - if (objset_info_storage_load_obj_set_check_not_read(i.object_set_hash, obj_db, tex_db)) + if (wait_objset(i.object_set_hash, obj_db, tex_db)) ret = true; else i.ready = true; @@ -388,7 +388,7 @@ namespace Glitter { if (type == Glitter::X) for (Mesh& i : eff_group->meshes) if (i.object_set_hash != hash_murmurhash_empty) { - objset_info_storage_load_set_hash(file_handler->ptr->ds, i.object_set_hash); + request_objset_modern(file_handler->ptr->ds, i.object_set_hash); i.load = true; } diff --git a/src/CRE/Glitter/render_scene.cpp b/src/CRE/Glitter/render_scene.cpp index 2dae811c..8d798ac2 100644 --- a/src/CRE/Glitter/render_scene.cpp +++ b/src/CRE/Glitter/render_scene.cpp @@ -2224,7 +2224,7 @@ namespace Glitter { object_info object_info; object_info.set_id = (uint32_t)particle->data.mesh.object_set_name_hash; object_info.id = (uint32_t)particle->data.mesh.object_name_hash; - obj* obj = objset_info_storage_get_obj(object_info); + obj* obj = get_object_header(object_info); if (!obj) return; diff --git a/src/CRE/auth_3d.cpp b/src/CRE/auth_3d.cpp index b39efac8..bd7c1ab9 100644 --- a/src/CRE/auth_3d.cpp +++ b/src/CRE/auth_3d.cpp @@ -2391,7 +2391,7 @@ namespace auth_3d_detail { // 0x1401CA530 void HierarchyObject::assign_object_skin() { - const obj_skin* skin = objset_info_storage_get_obj_skin(obj_uid); + const obj_skin* skin = get_object_skin(obj_uid); if (!skin) { std::string error_str = sprintf_s_string("%s skin data is not found", uid_name.c_str()); throw std::runtime_error(error_str.c_str()); @@ -3785,47 +3785,47 @@ namespace auth_3d_detail { sprintf_s(buf, sizeof(buf), "%.*s%03d", uid_name_length - 3, uid_name, i); object_info obj_uid = obj_db->get_object_info(buf); - ::obj* obj = objset_info_storage_get_obj(obj_uid); + ::obj* obj = get_object_header(obj_uid); if (!obj) continue; - obj_mesh_vertex_buffer* obj_vert_buf = objset_info_storage_get_obj_mesh_vertex_buffer(obj_uid); - obj_mesh_index_buffer* obj_index_buf = objset_info_storage_get_obj_mesh_index_buffer(obj_uid); + VertexBuffer* vbhn_array = get_object_vertex_buffer(obj_uid); + IndexBuffer* ibhn_array = get_object_index_buffer(obj_uid); - obj_mesh_vertex_buffer* obj_morph_vert_buf = 0; + VertexBuffer* morph_vbhn_array = 0; if (morph_obj_uid.set_id != -1) - obj_morph_vert_buf = objset_info_storage_get_obj_mesh_vertex_buffer(morph_obj_uid); + morph_vbhn_array = get_object_vertex_buffer(morph_obj_uid); for (int32_t i = 0; i < obj->num_mesh; i++) { const obj_mesh* mesh = &obj->mesh_array[i]; for (int32_t j = 0; j < mesh->num_submesh; j++) { const obj_sub_mesh* sub_mesh = &mesh->submesh_array[j]; - if (sub_mesh->attrib.m.cloth) + if (sub_mesh->attrib.m.hide) continue; obj_material_data* material = &obj->material_array[sub_mesh->material_index]; - GLuint morph_vertex_buffer = 0; - size_t morph_vertex_buffer_offset = 0; - if (obj_morph_vert_buf) { - morph_vertex_buffer = obj_morph_vert_buf[i].get_buffer(); - morph_vertex_buffer_offset = obj_morph_vert_buf[i].get_offset(); + GLuint morph_vb = 0; + uint32_t morph_vb_offset = 0; + if (morph_vbhn_array) { + morph_vb = morph_vbhn_array[i].get_glvb(); + morph_vb_offset = morph_vbhn_array[i].get_glvb_offset(); } - GLuint index_buffer = 0; - if (obj_index_buf) - index_buffer = obj_index_buf[i].buffer; + GLuint ib = 0; + if (ibhn_array) + ib = ibhn_array[i].ib; - GLuint vertex_buffer = 0; - size_t vertex_buffer_offset = 0; - if (obj_vert_buf) { - vertex_buffer = obj_vert_buf[i].get_buffer(); - vertex_buffer_offset = obj_vert_buf[i].get_offset(); + GLuint vb = 0; + uint32_t vb_offset = 0; + if (vbhn_array) { + vb = vbhn_array[i].get_glvb(); + vb_offset = vbhn_array[i].get_glvb_offset(); } - if (vertex_buffer && index_buffer && (!obj_morph_vert_buf || morph_vertex_buffer)) - rctx_ptr->disp_manager->add_vertex_array(mesh, sub_mesh, material, vertex_buffer, - vertex_buffer_offset, index_buffer, morph_vertex_buffer, morph_vertex_buffer_offset); + if (vb && ib && (!morph_vbhn_array || morph_vb)) + rctx_ptr->disp_manager->add_vertex_array(mesh, sub_mesh, material, + vb, vb_offset, ib, morph_vb, morph_vb_offset); } } } @@ -3956,7 +3956,7 @@ namespace auth_3d_detail { shadow = in_oi.shadow; motion_transform.load(in_file, in_oi.model_transform); - const obj_skin* skin = objset_info_storage_get_obj_skin(obj_uid); + const obj_skin* skin = get_object_skin(obj_uid); if (!skin) { std::string error_str = sprintf_s_string("%s skin data is not found", uid_name.c_str()); throw std::runtime_error(error_str.c_str()); diff --git a/src/CRE/config.hpp b/src/CRE/config.hpp index 754ddbca..9a9fcb7b 100644 --- a/src/CRE/config.hpp +++ b/src/CRE/config.hpp @@ -4,3 +4,4 @@ */ #define DISPLAY_IBL (0) +#define SHARED_OBJECT_BUFFER (1) diff --git a/src/CRE/effect.cpp b/src/CRE/effect.cpp index 658c0b24..0593b98d 100644 --- a/src/CRE/effect.cpp +++ b/src/CRE/effect.cpp @@ -5534,7 +5534,7 @@ bool EffectManager::load() { if (!modern) { bool wait_load = false; for (uint32_t i : obj_set_ids) - if (objset_info_storage_load_obj_set_check_not_read(i)) + if (wait_objset(i)) wait_load |= true; if (wait_load) @@ -5577,7 +5577,7 @@ bool EffectManager::load() { bool wait_load = false; for (uint32_t i : obj_set_ids) - if (objset_info_storage_load_obj_set_check_not_read(i, obj_db, tex_db)) + if (wait_objset(i, obj_db, tex_db)) wait_load = true; if (wait_load) @@ -5710,7 +5710,7 @@ void EffectManager::set_stage_hashes(const std::vector& stage_hashes) prj::sort_and_erase_non_unique(obj_set_ids); for (uint32_t i : obj_set_ids) - objset_info_storage_load_set_hash(data, i); + request_objset_modern(data, i); state = 1; } @@ -5746,7 +5746,7 @@ void EffectManager::set_stage_indices(const std::vector& stage_indices) prj::sort_and_erase_non_unique(obj_set_ids); for (uint32_t i : obj_set_ids) - objset_info_storage_load_set(aft_data, aft_obj_db, i); + request_objset(aft_data, aft_obj_db, i); state = 1; } @@ -5761,7 +5761,7 @@ bool EffectManager::unload() { return true; for (uint32_t& i : obj_set_ids) - objset_info_storage_unload_set(i); + free_objset(i); reset_data(); return false; diff --git a/src/CRE/mdl/disp_manager.cpp b/src/CRE/mdl/disp_manager.cpp index 8426540d..e036dfa5 100644 --- a/src/CRE/mdl/disp_manager.cpp +++ b/src/CRE/mdl/disp_manager.cpp @@ -9,6 +9,7 @@ #include "../prj/memory_manager.hpp" #include "../config.hpp" #include "../gl_state.hpp" +#include "../ogl_buffer_object.hpp" #include "../render_context.hpp" #include "../shader_ft.hpp" #include "draw_object.hpp" @@ -100,8 +101,8 @@ namespace mdl { int32_t slices, int32_t stacks, float_t radius); ObjSubMeshArgs::ObjSubMeshArgs() : sub_mesh(), mesh(), material(), textures(), mat_count(), mats(), - vertex_buffer(), vertex_buffer_offset(), index_buffer(), set_blend_color(), chara_color(), self_shadow(), - shadow(), morph_vertex_buffer(), morph_vertex_buffer_offset(), morph_weight(), texture_pattern_count(), + vb(), vb_offset(), ib(), set_blend_color(), chara_color(), self_shadow(), + shadow(), morph_vb(), morph_vb_offset(), morph_weight(), texture_pattern_count(), texture_transform_count(), instances_count(), instances_mat(), func(), func_data() { } @@ -302,9 +303,8 @@ namespace mdl { void ObjData::init_sub_mesh(DispManager* disp_manager, const mat4& mat, float_t radius, const obj_sub_mesh* sub_mesh, const obj_mesh* mesh, const obj_material_data* material, const std::vector* textures, - int32_t mat_count, const mat4* mats, GLuint vertex_buffer, size_t vertex_buffer_offset, - GLuint index_buffer, const vec4& blend_color, const vec4& emission, GLuint morph_vertex_buffer, - size_t morph_vertex_buffer_offset, + int32_t mat_count, const mat4* mats, GLuint vb, uint32_t vb_offset, GLuint ib, + const vec4& blend_color, const vec4& emission, GLuint morph_vb, uint32_t morph_vb_offset, int32_t instances_count, const mat4* instances_mat, draw_func func, const ObjSubMeshArgs* func_data) { kind = mdl::OBJ_KIND_NORMAL; this->mat = mat; @@ -318,11 +318,11 @@ namespace mdl { args->textures = textures; args->mat_count = mat_count; args->mats = mats; - args->vertex_buffer = vertex_buffer; - args->vertex_buffer_offset = vertex_buffer_offset; - args->index_buffer = index_buffer; - args->morph_vertex_buffer = morph_vertex_buffer; - args->morph_vertex_buffer_offset = morph_vertex_buffer_offset; + args->vb = vb; + args->vb_offset = vb_offset; + args->ib = ib; + args->morph_vb = morph_vb; + args->morph_vb_offset = morph_vb_offset; args->texture_pattern_count = disp_manager->texture_pattern_count; for (int32_t i = 0; i < disp_manager->texture_pattern_count && i < TEXTURE_PATTERN_COUNT; i++) @@ -361,8 +361,8 @@ namespace mdl { args->func = func; args->func_data = func_data; - disp_manager->add_vertex_array(mesh, sub_mesh, material, vertex_buffer, - vertex_buffer_offset, index_buffer, morph_vertex_buffer, morph_vertex_buffer_offset); + disp_manager->add_vertex_array(mesh, sub_mesh, material, vb, + vb_offset, ib, morph_vb, morph_vb_offset); } void ObjData::init_translucent(const mat4& mat, const ObjTranslucentArgs& translucent) { @@ -1081,9 +1081,9 @@ namespace mdl { } void DispManager::add_vertex_array(const obj_mesh* mesh, const obj_sub_mesh* sub_mesh, - const obj_material_data* material, GLuint vertex_buffer, size_t vertex_buffer_offset, - GLuint index_buffer, GLuint morph_vertex_buffer, size_t morph_vertex_buffer_offset) { - if (!vertex_buffer || !index_buffer) + const obj_material_data* material, GLuint vb, uint32_t vb_offset, + GLuint ib, GLuint morph_vb, uint32_t morph_vb_offset) { + if (!vb || !ib) return; int32_t texcoord_array[2] = { -1, -1 }; @@ -1108,11 +1108,11 @@ namespace mdl { obj_vertex_format vertex_format = mesh->vertex_format; for (DispManager::vertex_array& i : vertex_array_cache) - if (i.vertex_buffer == vertex_buffer - && i.vertex_buffer_offset == vertex_buffer_offset - && i.morph_vertex_buffer == morph_vertex_buffer - && i.morph_vertex_buffer_offset == morph_vertex_buffer_offset - && i.index_buffer == index_buffer && i.vertex_format == vertex_format + if (i.vb == vb + && i.vb_offset == vb_offset + && i.morph_vb == morph_vb + && i.morph_vb_offset == morph_vb_offset + && i.ib == ib && i.vertex_format == vertex_format && i.size_vertex == size_vertex && i.compression == compression && !memcmp(i.texcoord_array, texcoord_array, sizeof(texcoord_array))) return; @@ -1122,11 +1122,11 @@ namespace mdl { glGenVertexArrays(1, &vertex_array->vertex_array); - vertex_array->vertex_buffer = vertex_buffer; - vertex_array->vertex_buffer_offset = vertex_buffer_offset; - vertex_array->morph_vertex_buffer = morph_vertex_buffer; - vertex_array->morph_vertex_buffer_offset = morph_vertex_buffer_offset; - vertex_array->index_buffer = index_buffer; + vertex_array->vb = vb; + vertex_array->vb_offset = vb_offset; + vertex_array->morph_vb = morph_vb; + vertex_array->morph_vb_offset = morph_vb_offset; + vertex_array->ib = ib; vertex_array->vertex_format = vertex_format; vertex_array->size_vertex = size_vertex; vertex_array->compression = compression; @@ -1134,13 +1134,13 @@ namespace mdl { gl_state.bind_vertex_array(vertex_array->vertex_array, true); - gl_state.bind_array_buffer(vertex_buffer, true); - if (index_buffer) - gl_state.bind_element_array_buffer(index_buffer, true); + gl_state.bind_array_buffer(vb, true); + if (ib) + gl_state.bind_element_array_buffer(ib, true); bool vertex_attrib_array[16] = {}; - size_t offset = vertex_buffer_offset; + size_t offset = vb_offset; if (vertex_format & OBJ_VERTEX_POSITION) { glEnableVertexAttribArray(POSITION_INDEX); glVertexAttribPointer(POSITION_INDEX, @@ -1316,10 +1316,10 @@ namespace mdl { vertex_attrib_array[UNKNOWN_INDEX] = true; } - if (morph_vertex_buffer) { - gl_state.bind_array_buffer(morph_vertex_buffer, true); + if (morph_vb) { + gl_state.bind_array_buffer(morph_vb, true); - size_t offset = morph_vertex_buffer_offset; + size_t offset = morph_vb_offset; if (vertex_format & OBJ_VERTEX_POSITION) { glEnableVertexAttribArray(MORPH_POSITION_INDEX); glVertexAttribPointer(MORPH_POSITION_INDEX, @@ -1482,7 +1482,7 @@ namespace mdl { gl_state.bind_array_buffer(0); gl_state.bind_vertex_array(0); - if (index_buffer) + if (ib) gl_state.bind_element_array_buffer(0); } @@ -1526,18 +1526,18 @@ namespace mdl { for (ObjData*& i : obj[type]) { vec3 center = 0.0f; - bool v50 = false; + bool use_mat_center = false; switch (i->kind) { case OBJ_KIND_NORMAL: { mat4 mat = i->mat; - if (i->args.sub_mesh.mesh->attrib.m.billboard) + if (i->args.sub_mesh.mesh->attrib.m.billboard_view) model_mat_face_camera_view(cam, &mat, &mat); - else if (i->args.sub_mesh.mesh->attrib.m.billboard_y_axis) + else if (i->args.sub_mesh.mesh->attrib.m.billboard) model_mat_face_camera_position(cam, &mat, &mat); get_obj_center(mat, &i->args.sub_mesh, center); - v50 = !!i->args.sub_mesh.material->material.attrib.m.flag_30; + use_mat_center = i->args.sub_mesh.material->material.attrib.m.use_mat_center; i->radius = i->args.sub_mesh.mesh->bounding_sphere.radius; } break; case OBJ_KIND_ETC: @@ -1549,22 +1549,22 @@ namespace mdl { for (int32_t j = 0; j < i->args.translucent.count; j++) { vec3 _center = 0.0f; get_obj_center(i->mat, i->args.translucent.sub_mesh[j], _center); - if (i->args.translucent.sub_mesh[j]->material->material.attrib.m.flag_30) { - v50 = true; + if (i->args.translucent.sub_mesh[j]->material->material.attrib.m.use_mat_center) { + use_mat_center = true; break; } center_sum += _center; } - if (!v50) + if (!use_mat_center) center = center_sum * (1.0f / (float_t)i->args.translucent.count); break; } if (show_alpha_center && type == OBJ_TYPE_TRANSLUCENT) alpha_center.push_back(center); - if (show_mat_center && type == OBJ_TYPE_TRANSLUCENT && v50) + if (show_mat_center && type == OBJ_TYPE_TRANSLUCENT && use_mat_center) mat_center.push_back(center); mat4_transform_point(&cam.get_view_mat(), ¢er, ¢er); @@ -1603,18 +1603,18 @@ namespace mdl { void DispManager::calc_obj_radius(const cam_data& cam, ObjTypeScreen type) { for (ObjData*& i : obj_screen[type]) { vec3 center = 0.0f; - bool v50 = false; + bool use_mat_center = false; switch (i->kind) { case OBJ_KIND_NORMAL: { mat4 mat = i->mat; - if (i->args.sub_mesh.mesh->attrib.m.billboard) + if (i->args.sub_mesh.mesh->attrib.m.billboard_view) model_mat_face_camera_view(cam, &mat, &mat); - else if (i->args.sub_mesh.mesh->attrib.m.billboard_y_axis) + else if (i->args.sub_mesh.mesh->attrib.m.billboard) model_mat_face_camera_position(cam, &mat, &mat); get_obj_center(mat, &i->args.sub_mesh, center); - v50 = !!i->args.sub_mesh.material->material.attrib.m.flag_30; + use_mat_center = i->args.sub_mesh.material->material.attrib.m.use_mat_center; i->radius = i->args.sub_mesh.mesh->bounding_sphere.radius; } break; case OBJ_KIND_TRANSLUCENT: @@ -1622,15 +1622,15 @@ namespace mdl { for (int32_t j = 0; j < i->args.translucent.count; j++) { vec3 _center = 0.0f; get_obj_center(i->mat, i->args.translucent.sub_mesh[j], _center); - if (i->args.translucent.sub_mesh[j]->material->material.attrib.m.flag_30) { - v50 = true; + if (i->args.translucent.sub_mesh[j]->material->material.attrib.m.use_mat_center) { + use_mat_center = true; break; } center_sum += _center; } - if (!v50) + if (!use_mat_center) center = center_sum * (1.0f / (float_t)i->args.translucent.count); break; } @@ -1643,18 +1643,18 @@ namespace mdl { void DispManager::calc_obj_radius(const cam_data& cam, ObjTypeReflect type) { for (ObjData*& i : obj_reflect[type]) { vec3 center = 0.0f; - bool v50 = false; + bool use_mat_center = false; switch (i->kind) { case OBJ_KIND_NORMAL: { mat4 mat = i->mat; - if (i->args.sub_mesh.mesh->attrib.m.billboard) + if (i->args.sub_mesh.mesh->attrib.m.billboard_view) model_mat_face_camera_view(cam, &mat, &mat); - else if (i->args.sub_mesh.mesh->attrib.m.billboard_y_axis) + else if (i->args.sub_mesh.mesh->attrib.m.billboard) model_mat_face_camera_position(cam, &mat, &mat); get_obj_center(mat, &i->args.sub_mesh, center); - v50 = !!i->args.sub_mesh.material->material.attrib.m.flag_30; + use_mat_center = i->args.sub_mesh.material->material.attrib.m.use_mat_center; i->radius = i->args.sub_mesh.mesh->bounding_sphere.radius; } break; case OBJ_KIND_TRANSLUCENT: @@ -1662,15 +1662,15 @@ namespace mdl { for (int32_t j = 0; j < i->args.translucent.count; j++) { vec3 _center = 0.0f; get_obj_center(i->mat, i->args.translucent.sub_mesh[j], _center); - if (i->args.translucent.sub_mesh[j]->material->material.attrib.m.flag_30) { - v50 = true; + if (i->args.translucent.sub_mesh[j]->material->material.attrib.m.use_mat_center) { + use_mat_center = true; break; } center_sum += _center; } - if (!v50) + if (!use_mat_center) center = center_sum * (1.0f / (float_t)i->args.translucent.count); break; } @@ -2241,12 +2241,12 @@ namespace mdl { return obj_axis_aligned_bounding_box_check_visibility_default(aabb, cam, mat); } - bool DispManager::entry_obj(const ::obj* obj, const mat4& mat, obj_mesh_vertex_buffer* obj_vert_buf, - obj_mesh_index_buffer* obj_index_buf, const std::vector* textures, const vec4* blend_color, - const mat4* bone_mat, const ::obj* obj_morph, obj_mesh_vertex_buffer* obj_morph_vert_buf, + bool DispManager::entry_obj(const ::obj* obj, const mat4& mat, VertexBuffer* vbhn_array, + IndexBuffer* ibhn_array, const std::vector* textures, const vec4* blend_color, + const mat4* bone_mat, const ::obj* obj_morph, VertexBuffer* morph_vbhn_array, int32_t instances_count, const mat4* instances_mat, draw_func func, const ObjSubMeshArgs* func_data, bool enable_bone_mat) { - if (!obj_vert_buf || !obj_index_buf) { + if (!vbhn_array || !ibhn_array) { printf_debug("mdl::DispManager::entry_obj: no vertex or index object buffer to draw;\n"); printf_debug(" Object: %s\n", obj->name); return false; @@ -2265,8 +2265,8 @@ namespace mdl { for (int32_t i = 0; i < obj->num_mesh; i++) { const obj_mesh* mesh = &obj->mesh_array[i]; const obj_mesh* mesh_morph = 0; - if (obj_vert_buf && obj_morph_vert_buf) { - if (obj_vert_buf[i].get_size() != obj_morph_vert_buf[i].get_size()) + if (vbhn_array && morph_vbhn_array) { + if (vbhn_array[i].get_size() != morph_vbhn_array[i].get_size()) continue; if (obj_morph && i < obj_morph->num_mesh) @@ -2283,19 +2283,19 @@ namespace mdl { } culling.passed.meshes++; - ObjSubMeshArgs* translucent_priority[40]; - int32_t translucent_priority_count = 0; + ObjSubMeshArgs* alpha_prio[40]; + int32_t alpha_prio_count = 0; for (int32_t j = 0; j < mesh->num_submesh; j++) { const obj_sub_mesh* sub_mesh = &mesh->submesh_array[j]; const obj_sub_mesh* sub_mesh_morph = 0; - if (sub_mesh->attrib.m.cloth) + if (sub_mesh->attrib.m.hide) continue; if (object_culling && !instances_count && !bone_mat) { int32_t v32 = obj_bounding_sphere_check_visibility( sub_mesh->bounding_sphere, &culling, cam, mat); - if (v32 != 2 || (!mesh->attrib.m.billboard && !mesh->attrib.m.billboard_y_axis)) { + if (v32 != 2 || (!mesh->attrib.m.billboard_view && !mesh->attrib.m.billboard)) { if (v32 == 2) v32 = obj_axis_aligned_bounding_box_check_visibility( &sub_mesh->axis_aligned_bounding_box, &culling, cam, mat); @@ -2350,25 +2350,25 @@ namespace mdl { if (!data) continue; - GLuint morph_vertex_buffer = 0; - size_t morph_vertex_buffer_offset = 0; - if (obj_morph_vert_buf) { - morph_vertex_buffer = obj_morph_vert_buf[i].get_buffer(); - morph_vertex_buffer_offset = obj_morph_vert_buf[i].get_offset(); + GLuint morph_vb = 0; + uint32_t morph_vb_offset = 0; + if (morph_vbhn_array) { + morph_vb = morph_vbhn_array[i].get_glvb(); + morph_vb_offset = morph_vbhn_array[i].get_glvb_offset(); } - GLuint index_buffer = 0; - if (obj_index_buf) - index_buffer = obj_index_buf[i].buffer; + GLuint ib = 0; + if (ibhn_array) + ib = ibhn_array[i].get_glib(); - GLuint vertex_buffer = 0; - size_t vertex_buffer_offset = 0; - if (obj_vert_buf) { - vertex_buffer = obj_vert_buf[i].get_buffer(); - vertex_buffer_offset = obj_vert_buf[i].get_offset(); + GLuint vb = 0; + uint32_t vb_offset = 0; + if (vbhn_array) { + vb = vbhn_array[i].get_glvb(); + vb_offset = vbhn_array[i].get_glvb_offset(); } - if (!vertex_buffer || !index_buffer || obj_morph_vert_buf && !morph_vertex_buffer) { + if (!vb || !ib || morph_vbhn_array && !morph_vb) { printf_debug("mdl::DispManager::entry_obj: no vertex or index mesh buffer to draw;\n"); printf_debug(" Object: %s; Mesh: %s; Sub Mesh: %d\n", obj->name, mesh->name, j); continue; @@ -2446,8 +2446,8 @@ namespace mdl { } data->init_sub_mesh(this, mat, obj->bounding_sphere.radius, sub_mesh, mesh, material, textures, - num_bone_index, mats, vertex_buffer, vertex_buffer_offset, index_buffer, _blend_color, _emission, - morph_vertex_buffer, morph_vertex_buffer_offset, instances_count, instances_mat, func, func_data); + num_bone_index, mats, vb, vb_offset, ib, _blend_color, _emission, + morph_vb, morph_vb_offset, instances_count, instances_mat, func, func_data); if (obj_flags & mdl::OBJ_SHADOW_OBJECT) { entry_list((ObjType)(OBJ_TYPE_SHADOW_OBJECT_CHARA + shadow_group), data); @@ -2460,9 +2460,9 @@ namespace mdl { if ((obj_flags & mdl::OBJ_ALPHA_ORDER) && data->args.sub_mesh.blend_color.w < 1.0f) { if (!(obj_flags & mdl::OBJ_NO_TRANSLUCENCY)) { bool translucent = false; - if (!attrib.flag_28 && (!attrib.punch_through - && (attrib.alpha_texture || attrib.alpha_material) - || sub_mesh->attrib.m.translucent)) + if (!attrib.ignore_alpha && (!attrib.punch_through + && (attrib.alpha_tex || attrib.alpha_mat) + || sub_mesh->attrib.m.vertex_alpha)) translucent = true; if (translucent) { @@ -2496,19 +2496,19 @@ namespace mdl { } } } - else if (!attrib.flag_28 && (data->args.sub_mesh.blend_color.w < 1.0f - || !attrib.punch_through && attrib.alpha_texture | attrib.alpha_material - || sub_mesh->attrib.m.translucent)) { + else if (!attrib.ignore_alpha && (data->args.sub_mesh.blend_color.w < 1.0f + || !attrib.punch_through && attrib.alpha_tex | attrib.alpha_mat + || sub_mesh->attrib.m.vertex_alpha)) { if (!(obj_flags & mdl::OBJ_NO_TRANSLUCENCY)) { - if (!attrib.translucent_priority) - if (mesh->attrib.m.translucent_sort_by_radius + if (!attrib.alpha_prio) + if (mesh->attrib.m.around_obj || obj_flags & mdl::OBJ_TRANSLUCENT_SORT_BY_RADIUS) { entry_list(OBJ_TYPE_TRANSLUCENT_SORT_BY_RADIUS, data); } else entry_list(OBJ_TYPE_TRANSLUCENT, data); - else if (translucent_priority_count < 40) - translucent_priority[translucent_priority_count++] = &data->args.sub_mesh; + else if (alpha_prio_count < 40) + alpha_prio[alpha_prio_count++] = &data->args.sub_mesh; } } else { @@ -2571,15 +2571,15 @@ namespace mdl { entry_list(OBJ_TYPE_USER, data); } - if (translucent_priority_count <= 0) + if (alpha_prio_count <= 0) continue; ObjTranslucentArgs translucent_args; translucent_args.count = 0; for (int32_t j = 62; j; j--) - for (int32_t k = 0; k < translucent_priority_count; k++) { - ObjSubMeshArgs* sub_mesh = translucent_priority[k]; - if (sub_mesh->material->material.attrib.m.translucent_priority != j) + for (int32_t k = 0; k < alpha_prio_count; k++) { + ObjSubMeshArgs* sub_mesh = alpha_prio[k]; + if (sub_mesh->material->material.attrib.m.alpha_prio != j) continue; translucent_args.sub_mesh[translucent_args.count] = sub_mesh; @@ -2602,9 +2602,9 @@ namespace mdl { return true; } - bool DispManager::entry_obj_screen(const ::obj* obj, const mat4& mat, obj_mesh_vertex_buffer* obj_vert_buf, - obj_mesh_index_buffer* obj_index_buf, const std::vector* textures, const vec4* blend_color) { - if (!obj_vert_buf || !obj_index_buf) + bool DispManager::entry_obj_screen(const ::obj* obj, const mat4& mat, VertexBuffer* vbhn_array, + IndexBuffer* ibhn_array, const std::vector* textures, const vec4* blend_color) { + if (!vbhn_array || !ibhn_array) return false; culling.passed.objects++; @@ -2614,12 +2614,12 @@ namespace mdl { culling.passed.meshes++; - ObjSubMeshArgs* translucent_priority[40]; - int32_t translucent_priority_count = 0; + ObjSubMeshArgs* alpha_prio[40]; + int32_t alpha_prio_count = 0; for (int32_t j = 0; j < mesh->num_submesh; j++) { const obj_sub_mesh* sub_mesh = &mesh->submesh_array[j]; - if (sub_mesh->attrib.m.cloth) + if (sub_mesh->attrib.m.hide) continue; culling.passed.sub_meshes++; @@ -2629,18 +2629,18 @@ namespace mdl { if (!data) continue; - GLuint index_buffer = 0; - if (obj_index_buf) - index_buffer = obj_index_buf[i].buffer; + GLuint ib = 0; + if (ibhn_array) + ib = ibhn_array[i].get_glib(); - GLuint vertex_buffer = 0; - size_t vertex_buffer_offset = 0; - if (obj_vert_buf) { - vertex_buffer = obj_vert_buf[i].get_buffer(); - vertex_buffer_offset = obj_vert_buf[i].get_offset(); + GLuint vb = 0; + uint32_t vb_offset = 0; + if (vbhn_array) { + vb = vbhn_array[i].get_glvb(); + vb_offset = vbhn_array[i].get_glvb_offset(); } - if (!vertex_buffer || !index_buffer) + if (!vb || !ib) continue; vec4 _blend_color = 1.0f; @@ -2649,16 +2649,16 @@ namespace mdl { vec4 _emission = material->material.color.emission; data->init_sub_mesh(this, mat, obj->bounding_sphere.radius, sub_mesh, mesh, material, textures, - 0, 0, vertex_buffer, vertex_buffer_offset, index_buffer, _blend_color, _emission, + 0, 0, vb, vb_offset, ib, _blend_color, _emission, 0, 0, 0, 0, 0, 0); const obj_material_attrib_member attrib = material->material.attrib.m; if ((obj_flags & mdl::OBJ_ALPHA_ORDER) && data->args.sub_mesh.blend_color.w < 1.0f) { if (!(obj_flags & mdl::OBJ_NO_TRANSLUCENCY)) { bool translucent = false; - if (!attrib.flag_28 && (!attrib.punch_through - && (attrib.alpha_texture || attrib.alpha_material) - || sub_mesh->attrib.m.translucent)) + if (!attrib.ignore_alpha && (!attrib.punch_through + && (attrib.alpha_tex || attrib.alpha_mat) + || sub_mesh->attrib.m.vertex_alpha)) translucent = true; if (translucent) { @@ -2683,17 +2683,17 @@ namespace mdl { } } } - else if (!attrib.flag_28 && (data->args.sub_mesh.blend_color.w < 1.0f - || !attrib.punch_through && attrib.alpha_texture | attrib.alpha_material - || sub_mesh->attrib.m.translucent)) { + else if (!attrib.ignore_alpha && (data->args.sub_mesh.blend_color.w < 1.0f + || !attrib.punch_through && attrib.alpha_tex | attrib.alpha_mat + || sub_mesh->attrib.m.vertex_alpha)) { if (!(obj_flags & mdl::OBJ_NO_TRANSLUCENCY)) { - if (!attrib.translucent_priority) - if (mesh->attrib.m.translucent_sort_by_radius + if (!attrib.alpha_prio) + if (mesh->attrib.m.around_obj || obj_flags & mdl::OBJ_TRANSLUCENT_SORT_BY_RADIUS); else entry_list(OBJ_TYPE_SCREEN_TRANSLUCENT, data); - else if (translucent_priority_count < 40) - translucent_priority[translucent_priority_count++] = &data->args.sub_mesh; + else if (alpha_prio_count < 40) + alpha_prio[alpha_prio_count++] = &data->args.sub_mesh; } } else { @@ -2709,15 +2709,15 @@ namespace mdl { } } - if (translucent_priority_count <= 0) + if (alpha_prio_count <= 0) continue; ObjTranslucentArgs translucent_args; translucent_args.count = 0; for (int32_t j = 62; j; j--) - for (int32_t k = 0; k < translucent_priority_count; k++) { - ObjSubMeshArgs* sub_mesh = translucent_priority[k]; - if (sub_mesh->material->material.attrib.m.translucent_priority != j) + for (int32_t k = 0; k < alpha_prio_count; k++) { + ObjSubMeshArgs* sub_mesh = alpha_prio[k]; + if (sub_mesh->material->material.attrib.m.alpha_prio != j) continue; translucent_args.sub_mesh[translucent_args.count] = sub_mesh; @@ -2740,15 +2740,15 @@ namespace mdl { } void DispManager::entry_obj_by_obj(const mat4& mat, - const ::obj* obj, const std::vector* textures, obj_mesh_vertex_buffer* obj_vert_buf, - obj_mesh_index_buffer* obj_index_buf, const mat4* bone_mat, float_t alpha) { + const ::obj* obj, const std::vector* textures, VertexBuffer* vbhn_array, + IndexBuffer* ibhn_array, const mat4* bone_mat, float_t alpha) { if (!obj) return; vec4 blend_color = { 1.0f, 1.0f, 1.0f, alpha }; vec4* blend_color_ptr = alpha < 1.0f ? &blend_color : 0; - entry_obj(obj, mat, obj_vert_buf, obj_index_buf, textures, blend_color_ptr, + entry_obj(obj, mat, vbhn_array, ibhn_array, textures, blend_color_ptr, bone_mat, 0, 0, 0, 0, 0, 0, !!bone_mat); } @@ -2767,22 +2767,22 @@ namespace mdl { if (obj_info.id == -1 && obj_info.set_id == -1) return false; - ::obj* obj = objset_info_storage_get_obj(obj_info); + ::obj* obj = get_object_header(obj_info); if (!obj) return false; - std::vector* textures = objset_info_storage_get_obj_set_gentex(obj_info.set_id); - obj_mesh_vertex_buffer* obj_vert_buffer = objset_info_storage_get_obj_mesh_vertex_buffer(obj_info); - obj_mesh_index_buffer* obj_index_buffer = objset_info_storage_get_obj_mesh_index_buffer(obj_info); + std::vector* textures = get_objset_gen_textures_vec(obj_info.set_id); + VertexBuffer* obj_vert_buffer = get_object_vertex_buffer(obj_info); + IndexBuffer* ObjIB = get_object_index_buffer(obj_info); ::obj* obj_morph = 0; - obj_mesh_vertex_buffer* obj_morph_vert_buffer = 0; + VertexBuffer* obj_morph_vert_buffer = 0; if (morph.object.set_id != -1) { - obj_morph = objset_info_storage_get_obj(morph.object); - obj_morph_vert_buffer = objset_info_storage_get_obj_mesh_vertex_buffer(morph.object); + obj_morph = get_object_header(morph.object); + obj_morph_vert_buffer = get_object_vertex_buffer(morph.object); } - return entry_obj(obj, mat, obj_vert_buffer, obj_index_buffer, + return entry_obj(obj, mat, obj_vert_buffer, ObjIB, textures, blend_color, bone_mat, obj_morph, obj_morph_vert_buffer, instances_count, instances_mat, func, func_data, enable_bone_mat); } @@ -2791,15 +2791,15 @@ namespace mdl { if (obj_info.id == (uint16_t)-1 && obj_info.set_id == (uint16_t)-1) return false; - ::obj* obj = objset_info_storage_get_obj(obj_info); + ::obj* obj = get_object_header(obj_info); if (!obj) return false; - std::vector* textures = objset_info_storage_get_obj_set_gentex(obj_info.set_id); - obj_mesh_vertex_buffer* obj_vert_buffer = objset_info_storage_get_obj_mesh_vertex_buffer(obj_info); - obj_mesh_index_buffer* obj_index_buffer = objset_info_storage_get_obj_mesh_index_buffer(obj_info); + std::vector* textures = get_objset_gen_textures_vec(obj_info.set_id); + VertexBuffer* obj_vert_buffer = get_object_vertex_buffer(obj_info); + IndexBuffer* ObjIB = get_object_index_buffer(obj_info); - return entry_obj_screen(obj, mat, obj_vert_buffer, obj_index_buffer, textures, blend_color); + return entry_obj_screen(obj, mat, obj_vert_buffer, ObjIB, textures, blend_color); } bool DispManager::entry_obj_by_object_info(const mat4& mat, @@ -2844,7 +2844,7 @@ namespace mdl { const std::vector* texture_pattern, const RobSkinCol* skin_col, float_t alpha, const mat4* matrices, const mat4* ex_data_matrices, const mat4* mat, const mat4& global_mat) { - obj_skin* skin = objset_info_storage_get_obj_skin(obj_info); + obj_skin* skin = get_object_skin(obj_info); if (!skin) return; @@ -3032,13 +3032,13 @@ namespace mdl { const obj_sub_mesh* sub_mesh = args->sub_mesh; const obj_material_data* material = args->material; - GLuint vertex_buffer = args->vertex_buffer; - size_t vertex_buffer_offset = args->vertex_buffer_offset; - GLuint morph_vertex_buffer = args->morph_vertex_buffer; - size_t morph_vertex_buffer_offset = args->morph_vertex_buffer_offset; - GLuint index_buffer = args->index_buffer; + GLuint vb = args->vb; + uint32_t vb_offset = args->vb_offset; + GLuint morph_vb = args->morph_vb; + uint32_t morph_vb_offset = args->morph_vb_offset; + GLuint ib = args->ib; - if (!vertex_buffer || !index_buffer) + if (!vb || !ib) return 0; int32_t texcoord_array[2] = { -1, -1 }; @@ -3063,11 +3063,9 @@ namespace mdl { obj_vertex_format vertex_format = mesh->vertex_format; for (DispManager::vertex_array& i : vertex_array_cache) - if (i.vertex_buffer == vertex_buffer - && i.vertex_buffer_offset == vertex_buffer_offset - && i.morph_vertex_buffer == morph_vertex_buffer - && i.morph_vertex_buffer_offset == morph_vertex_buffer_offset - && i.index_buffer == index_buffer && i.vertex_format == vertex_format + if (i.vb == vb && i.vb_offset == vb_offset + && i.morph_vb == morph_vb && i.morph_vb_offset == morph_vb_offset + && i.ib == ib && i.vertex_format == vertex_format && i.size_vertex == size_vertex && i.compression == compression && !memcmp(i.texcoord_array, texcoord_array, sizeof(texcoord_array))) return i.vertex_array; @@ -3193,11 +3191,11 @@ namespace mdl { buffer_reset(); } - void DispManager::remove_index_buffer(GLuint buffer) { + void DispManager::remove_index_buffer(GLuint ib) { auto i_begin = vertex_array_cache.begin(); auto i_end = vertex_array_cache.end(); for (auto i = i_begin; i != i_end;) - if (i->index_buffer == buffer) { + if (i->ib == ib) { glDeleteVertexArrays(1, &i->vertex_array); i = vertex_array_cache.erase(i); i_end = vertex_array_cache.end(); @@ -3206,11 +3204,11 @@ namespace mdl { i++; } - void DispManager::remove_vertex_buffer(GLuint buffer) { + void DispManager::remove_vertex_buffer(GLuint vb) { auto i_begin = vertex_array_cache.begin(); auto i_end = vertex_array_cache.end(); for (auto i = i_begin; i != i_end;) - if (i->vertex_buffer == buffer || i->morph_vertex_buffer == buffer) { + if (i->vb == vb || i->morph_vb == vb) { glDeleteVertexArrays(1, &i->vertex_array); i = vertex_array_cache.erase(i); i_end = vertex_array_cache.end(); @@ -3779,7 +3777,7 @@ static void sub_140436760(const cam_data& cam) { const obj_sub_mesh* sub_mesh = i->args.sub_mesh.sub_mesh; const obj_axis_aligned_bounding_box* aabb = &sub_mesh->axis_aligned_bounding_box; - if (mesh->attrib.m.billboard_y_axis && aabb->size.y > 1.0f && aabb->size.y < 1.2f) { + if (mesh->attrib.m.billboard && aabb->size.y > 1.0f && aabb->size.y < 1.2f) { if (!strcmp(mesh->name, "STGD2NS064_EFF_WATESMOKE_A_BMZ_000")) i->view_z += sub_mesh->bounding_sphere.radius; continue; diff --git a/src/CRE/mdl/disp_manager.hpp b/src/CRE/mdl/disp_manager.hpp index 89b12518..d12e52c6 100644 --- a/src/CRE/mdl/disp_manager.hpp +++ b/src/CRE/mdl/disp_manager.hpp @@ -190,17 +190,17 @@ namespace mdl { const std::vector* textures; int32_t mat_count; const mat4* mats; - GLuint vertex_buffer; - size_t vertex_buffer_offset; - GLuint index_buffer; + GLuint vb; + uint32_t vb_offset; + GLuint ib; bool set_blend_color; bool chara_color; vec4 blend_color; vec4 emission; int32_t self_shadow; SHADOW_GROUP shadow; - GLuint morph_vertex_buffer; - size_t morph_vertex_buffer_offset; + GLuint morph_vb; + uint32_t morph_vb_offset; float_t morph_weight; int32_t texture_pattern_count; TexChange texture_pattern_array[TEXTURE_PATTERN_COUNT]; @@ -379,9 +379,8 @@ namespace mdl { void init_etc(DispManager* disp_manager, const mat4& mat, int32_t index, int32_t count, const EtcObj& etc); void init_sub_mesh(DispManager* disp_manager, const mat4& mat, float_t radius, const obj_sub_mesh* sub_mesh, const obj_mesh* mesh, const obj_material_data* material, const std::vector* textures, - int32_t mat_count, const mat4* mats, GLuint vertex_buffer, size_t vertex_buffer_offset, - GLuint index_buffer, const vec4& blend_color, const vec4& emission, GLuint morph_vertex_buffer, - size_t morph_vertex_buffer_offset, + int32_t mat_count, const mat4* mats, GLuint vb, uint32_t vb_offset, GLuint ib, + const vec4& blend_color, const vec4& emission, GLuint morph_vb, uint32_t morph_vb_offset, int32_t instances_count, const mat4* instances_mat, draw_func func, const ObjSubMeshArgs* func_data); void init_translucent(const mat4& mat, const ObjTranslucentArgs& translucent); void init_user(const mat4& mat, UserArgsFunc func, void* data); @@ -473,11 +472,11 @@ namespace mdl { struct DispManager { struct vertex_array { - GLuint vertex_buffer; - size_t vertex_buffer_offset; - GLuint morph_vertex_buffer; - size_t morph_vertex_buffer_offset; - GLuint index_buffer; + GLuint vb; + uint32_t vb_offset; + GLuint morph_vb; + uint32_t morph_vb_offset; + GLuint ib; GLuint vertex_array; obj_vertex_format vertex_format; GLsizei size_vertex; @@ -521,8 +520,7 @@ namespace mdl { ~DispManager(); void add_vertex_array(const obj_mesh* mesh, const obj_sub_mesh* sub_mesh, const obj_material_data* material, - GLuint vertex_buffer, size_t vertex_buffer_offset, GLuint index_buffer, - GLuint morph_vertex_buffer, size_t morph_vertex_buffer_offset); + GLuint vb, uint32_t vb_offset, GLuint ib, GLuint morph_vb, uint32_t morph_vb_offset); void* alloc_data(int32_t size); ObjData* alloc_obj_data(ObjKind kind); mat4* alloc_mat4_array(int32_t count); @@ -539,16 +537,16 @@ namespace mdl { void entry_list(ObjType type, ObjData* data); void entry_list(ObjTypeScreen type, ObjData* data); void entry_list(ObjTypeReflect type, ObjData* data); - bool entry_obj(const ::obj* obj, const mat4& mat, obj_mesh_vertex_buffer* obj_vert_buf, - obj_mesh_index_buffer* obj_index_buf, const std::vector* textures, const vec4* blend_color, - const mat4* bone_mat, const ::obj* obj_morph, obj_mesh_vertex_buffer* obj_morph_vert_buf, + bool entry_obj(const ::obj* obj, const mat4& mat, VertexBuffer* vbhn_array, + IndexBuffer* ibhn_array, const std::vector* textures, const vec4* blend_color, + const mat4* bone_mat, const ::obj* obj_morph, VertexBuffer* morph_vbhn_array, int32_t instances_count, const mat4* instances_mat, draw_func func, const ObjSubMeshArgs* func_data, bool enable_bone_mat); - bool entry_obj_screen(const ::obj* obj, const mat4& mat, obj_mesh_vertex_buffer* obj_vert_buf, - obj_mesh_index_buffer* obj_index_buf, const std::vector* textures, const vec4* blend_color); + bool entry_obj_screen(const ::obj* obj, const mat4& mat, VertexBuffer* vbhn_array, + IndexBuffer* ibhn_array, const std::vector* textures, const vec4* blend_color); void entry_obj_by_obj(const mat4& mat, - const ::obj* obj, const std::vector* textures, obj_mesh_vertex_buffer* obj_vert_buf, - obj_mesh_index_buffer* obj_index_buf, const mat4* bone_mat, float_t alpha); + const ::obj* obj, const std::vector* textures, VertexBuffer* vbhn_array, + IndexBuffer* ibhn_array, const mat4* bone_mat, float_t alpha); bool entry_obj_by_object_info(const mat4& mat, object_info obj_info); bool entry_obj_by_object_info(const mat4& mat, object_info obj_info, const mat4* bone_mat); bool entry_obj_by_object_info(const mat4& mat, object_info obj_info, const vec4* blend_color, @@ -595,8 +593,8 @@ namespace mdl { void obj_sort(render_data_context& rend_data_ctx, ObjTypeReflect type, int32_t compare_func, const cam_data& cam); void refresh(); - void remove_index_buffer(GLuint buffer); - void remove_vertex_buffer(GLuint buffer); + void remove_index_buffer(GLuint ib); + void remove_vertex_buffer(GLuint vb); void set_chara_color(bool value = false); void set_culling_func(bool(*func)(const obj_bounding_sphere*, const mat4*) = 0); void set_obj_flags(ObjFlags flags = (ObjFlags)0); diff --git a/src/CRE/mdl/draw_object.cpp b/src/CRE/mdl/draw_object.cpp index b16a5202..1786672c 100644 --- a/src/CRE/mdl/draw_object.cpp +++ b/src/CRE/mdl/draw_object.cpp @@ -143,9 +143,9 @@ namespace mdl { } else { mat4 _mat; - if (args->mesh->attrib.m.billboard) + if (args->mesh->attrib.m.billboard_view) model_mat_face_camera_view(cam, mat, &_mat); - else if (args->mesh->attrib.m.billboard_y_axis) + else if (args->mesh->attrib.m.billboard) model_mat_face_camera_position(cam, mat, &_mat); else _mat = *mat; @@ -177,8 +177,8 @@ namespace mdl { draw(rend_data_ctx, sub_mesh->primitive_type, sub_mesh->num_index, - sub_mesh->first_index, - sub_mesh->last_index, + sub_mesh->min_index, + sub_mesh->max_index, sub_mesh->index_format, sub_mesh->index_offset); @@ -199,8 +199,8 @@ namespace mdl { draw(rend_data_ctx, sub_mesh->primitive_type, sub_mesh->num_index, - sub_mesh->first_index, - sub_mesh->last_index, + sub_mesh->min_index, + sub_mesh->max_index, sub_mesh->index_format, sub_mesh->index_offset); @@ -224,8 +224,8 @@ namespace mdl { draw(rend_data_ctx, sub_mesh->primitive_type, sub_mesh->num_index, - sub_mesh->first_index, - sub_mesh->last_index, + sub_mesh->min_index, + sub_mesh->max_index, sub_mesh->index_format, sub_mesh->index_offset); @@ -258,8 +258,8 @@ namespace mdl { draw(rend_data_ctx, sub_mesh->primitive_type, sub_mesh->num_index, - sub_mesh->first_index, - sub_mesh->last_index, + sub_mesh->min_index, + sub_mesh->max_index, sub_mesh->index_format, sub_mesh->index_offset); } @@ -281,7 +281,7 @@ namespace mdl { if (rctx_ptr->draw_state->rend_data[rend_data_ctx.index].shader_index != -1) { rend_data_ctx.set_batch_material_color_emission(args->emission); draw_object_material_set_uniform(rend_data_ctx, material, false); - if (material->material.attrib.m.alpha_texture) + if (material->material.attrib.m.alpha_tex) rend_data_ctx.shader_flags.arr[U_TEXTURE_COUNT] = 0; rend_data_ctx.set_shader(rctx_ptr->draw_state->rend_data[rend_data_ctx.index].shader_index); } @@ -294,7 +294,7 @@ namespace mdl { GLuint tex_id = -1; int32_t tex_index = 0; - if (material->material.attrib.m.alpha_texture) { + if (material->material.attrib.m.alpha_tex) { const obj_material_texture_data* texdata = material->material.texdata; uint32_t texture_id = -1; if (!material->material.shader_compo.m.transparency) { @@ -308,7 +308,7 @@ namespace mdl { else { for (int32_t i = 0; i < 8; i++, texdata++) if (texdata->shader_info.m.tex_type == OBJ_MATERIAL_TEXTURE_TRANSPARENCY) { - if (texdata->attrib.m.flag_29) { + if (texdata->attrib.m.ignore) { texture_id = texdata->tex_index; } break; @@ -360,8 +360,8 @@ namespace mdl { draw(rend_data_ctx, sub_mesh->primitive_type, sub_mesh->num_index, - sub_mesh->first_index, - sub_mesh->last_index, + sub_mesh->min_index, + sub_mesh->max_index, sub_mesh->index_format, sub_mesh->index_offset); @@ -380,9 +380,9 @@ namespace mdl { void draw_sub_mesh_shadow(render_data_context& rend_data_ctx, const ObjSubMeshArgs* args, const cam_data& cam, const mat4* mat) { obj_material_attrib_member attrib = args->material->material.attrib.m; - if (!attrib.flag_28 && (args->blend_color.w < 1.0f - || (attrib.alpha_texture || attrib.alpha_material) && !attrib.punch_through - || args->sub_mesh->attrib.m.translucent) + if (!attrib.ignore_alpha && (args->blend_color.w < 1.0f + || (attrib.alpha_tex || attrib.alpha_mat) && !attrib.punch_through + || args->sub_mesh->attrib.m.vertex_alpha) || attrib.punch_through) { rend_data_ctx.shader_flags.arr[U_ALPHA_TEST] = 1; rend_data_ctx.set_batch_alpha_threshold(0.5f); @@ -397,9 +397,9 @@ namespace mdl { void draw_sub_mesh_sss(render_data_context& rend_data_ctx, const ObjSubMeshArgs* args, const cam_data& cam, const mat4* mat) { obj_material_attrib_member attrib = args->material->material.attrib.m; - rend_data_ctx.shader_flags.arr[U_ALPHA_TEST] = (!attrib.flag_28 && (args->blend_color.w < 1.0f - || (attrib.alpha_texture || attrib.alpha_material) && !attrib.punch_through - || args->sub_mesh->attrib.m.translucent) + rend_data_ctx.shader_flags.arr[U_ALPHA_TEST] = (!attrib.ignore_alpha && (args->blend_color.w < 1.0f + || (attrib.alpha_tex || attrib.alpha_mat) && !attrib.punch_through + || args->sub_mesh->attrib.m.vertex_alpha) || attrib.punch_through) ? 1 : 0; rend_data_ctx.shader_flags.arr[U_NPR_NORMAL] = 1; @@ -492,7 +492,7 @@ static bool draw_object_blend_set(render_data_context& rend_data_ctx, const obj_material_data* material = args->material; obj_material_attrib_member attrib = material->material.attrib.m; - if ((!attrib.alpha_texture && !attrib.alpha_material) || attrib.punch_through) + if ((!attrib.alpha_tex && !attrib.alpha_mat) || attrib.punch_through) return false; GLenum src_blend_factor = blend_factor_table[attrib.src_blend_factor]; @@ -552,8 +552,8 @@ static void draw_object_chara_color_fog_set(render_data_context& rend_data_ctx, } obj_material_attrib_member attrib = args->material->material.attrib.m; - if (!attrib.no_fog && !disable_fog) { - rend_data_ctx.shader_flags.arr[U_FOG_STAGE] = attrib.has_fog_height ? (attrib.fog_height ? 3 : 2) : 1; + if (!attrib.no_z_fog && !disable_fog) { + rend_data_ctx.shader_flags.arr[U_FOG_STAGE] = attrib.y_fog ? (attrib.y_fogmap ? 3 : 2) : 1; rend_data_ctx.shader_flags.arr[U_FOG_CHARA] = rctx_ptr->draw_state->fog_height ? 2 : 1; } } @@ -569,7 +569,7 @@ static void draw_object_material_reset_default( if (mat_data) { rend_data_ctx.state.enable_cull_face(); obj_material_attrib_member attrib = mat_data->material.attrib.m; - if ((attrib.alpha_texture || attrib.alpha_material) && !attrib.punch_through) + if ((attrib.alpha_tex || attrib.alpha_mat) && !attrib.punch_through) rend_data_ctx.state.set_blend_func(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } rend_data_ctx.reset_shader_flags(); @@ -663,7 +663,7 @@ static void draw_object_material_set_default(render_data_context& rend_data_ctx, if (!rctx_ptr->draw_state->rend_data[rend_data_ctx.index].shadow) rend_data_ctx.shader_flags.arr[U_STAGE_SHADOW] = 0; else if (!args->self_shadow) - rend_data_ctx.shader_flags.arr[U_STAGE_SHADOW] = args->sub_mesh->attrib.m.recieve_shadow ? 1 : 0; + rend_data_ctx.shader_flags.arr[U_STAGE_SHADOW] = args->sub_mesh->attrib.m.receive_shadow ? 1 : 0; else if (args->self_shadow != 1) rend_data_ctx.shader_flags.arr[U_STAGE_SHADOW] = 0; else @@ -702,7 +702,7 @@ static void draw_object_material_set_default(render_data_context& rend_data_ctx, if (tex_type == OBJ_MATERIAL_TEXTURE_COLOR) j++; - if (texdata->attrib.m.flag_29) { + if (texdata->attrib.m.ignore) { switch (tex_type) { case OBJ_MATERIAL_TEXTURE_NORMAL: rend_data_ctx.shader_flags.arr[U_NORMAL] = 0; @@ -950,7 +950,7 @@ static void draw_object_material_set_uniform(render_data_context& rend_data_ctx, rend_data_ctx.shader_flags.arr[U_TRANSLUCENCY] = 1; v4 |= 2; } - if (shader_compo.override_ibl) + if (shader_compo.env_cube) rend_data_ctx.shader_flags.arr[U_ENV_MAP] = 1; if (shader_info.aniso_direction != OBJ_MATERIAL_ANISO_DIRECTION_NORMAL) @@ -970,7 +970,7 @@ static void draw_object_vertex_attrib_reset_cheap( if (vertex_format & OBJ_VERTEX_BONE_DATA) rend_data_ctx.shader_flags.arr[U_SKINNING] = 0; - if (args->morph_vertex_buffer) { + if (args->morph_vb) { rend_data_ctx.shader_flags.arr[U_MORPH] = 0; rend_data_ctx.shader_flags.arr[U_MORPH_COLOR] = 0; } @@ -986,7 +986,7 @@ static void draw_object_vertex_attrib_reset_default( if (vertex_format & OBJ_VERTEX_BONE_DATA) rend_data_ctx.shader_flags.arr[U_SKINNING] = 0; - if (args->morph_vertex_buffer) { + if (args->morph_vb) { rend_data_ctx.shader_flags.arr[U_MORPH] = 0; rend_data_ctx.shader_flags.arr[U_MORPH_COLOR] = 0; } @@ -1025,7 +1025,7 @@ static void draw_object_vertex_attrib_set_cheap( else rend_data_ctx.shader_flags.arr[U_SKINNING] = 0; - if (args->morph_vertex_buffer) { + if (args->morph_vb) { rend_data_ctx.shader_flags.arr[U_MORPH] = 1; if (vertex_format & OBJ_VERTEX_COLOR0) @@ -1088,7 +1088,7 @@ static void draw_object_vertex_attrib_set_default( else rend_data_ctx.shader_flags.arr[U_SKINNING] = 0; - if (args->morph_vertex_buffer) { + if (args->morph_vb) { rend_data_ctx.shader_flags.arr[U_MORPH] = 1; if (vertex_format & OBJ_VERTEX_COLOR0) diff --git a/src/CRE/object.cpp b/src/CRE/object.cpp index 47a9439a..aef9e0a9 100644 --- a/src/CRE/object.cpp +++ b/src/CRE/object.cpp @@ -14,7 +14,7 @@ #include "../KKdLib/str_utils.hpp" #include "prj/memory_manager.hpp" #include "data.hpp" -#include "gl_state.hpp" +#include "ogl_buffer_object.hpp" #include "render_context.hpp" #include "shader_ft.hpp" #include @@ -23,618 +23,79 @@ #include #include -struct BufObjMgr { - int32_t vb_peak_size; - int32_t vb_all_size; - int32_t ib_peak_size; - int32_t ib_all_size; -}; +static int32_t align_val_32(int32_t value); // Added -static GLuint create_index_buffer(size_t size, const void* data); -static GLuint create_vertex_buffer(size_t size, const void* data, GL::BufferUsage usage = GL::BUFFER_USAGE_STATIC); -static void free_index_buffer(GLuint buffer); -static void free_vertex_buffer(GLuint buffer); +static void calc_aabb(obj_axis_aligned_bounding_box& aabb, obj_mesh& mesh, obj_sub_mesh& sub_mesh); -static int32_t remove_degenerate_triangle_indices( - uint32_t* dst_index_array, const int32_t num_index, uint32_t* src_index_array); +#if SHARED_OBJECT_BUFFER +static void calc_index_buffer(obj_sub_mesh& sub_mesh, int32_t& size); // Added -static void ObjsetInfo_calc_axis_aligned_bounding_box(ObjsetInfo* info); -static void ObjsetInfo_get_obj_shader_index_texture_index(ObjsetInfo* info, obj* obj); -static void ObjsetInfo_get_shader_index_texture_index(ObjsetInfo* info); -static bool ObjsetInfo_index_buffer_load(ObjsetInfo* info); -static void ObjsetInfo_index_buffer_free(ObjsetInfo* info); -static bool ObjsetInfo_load_textures(ObjsetInfo* info, const void* data, bool big_endian); -static bool ObjsetInfo_load_textures_modern(ObjsetInfo* info, +static void calc_mesh_index_buffer(obj_mesh& mesh, int32_t& size); // Added +static int32_t calc_mesh_vertex_buffer(obj_mesh& mesh); // Added + +static void calc_object_index_buffer(obj* obj, int32_t& size); // Added +static void calc_object_vertex_buffer(obj* obj, int32_t& size); // Added +#endif + +static void convert_objdata_tex_index(ObjsetInfo* info); +static void convert_objdata_tex_index_internal(ObjsetInfo* info, obj* obj); + +static void create_mesh_aabb(obj_mesh& mesh); + +static void create_object_aabb(obj* obj); +static bool create_object_index_buffer(ObjIB* objib, obj* obj); +static bool create_object_vertex_buffer(ObjVB* objvb, obj* obj); +#if SHARED_OBJECT_BUFFER +inline bool create_object_vertex_buffer(ObjVB* objvb, obj* obj, GLuint in_vb, uint32_t& offset); // Added +#endif + +static void create_objset_aabb(ObjsetInfo* info); + +static void fill_index_buffer(void* buf, obj_sub_mesh& sub_mesh, int32_t& offset); // Added + +static void fill_mesh_index_buffer(void* buf, obj_mesh& mesh, int32_t& offset); // Added +static int32_t fill_mesh_vertex_buffer(void* buf, obj_mesh& mesh); // Added + +#if SHARED_OBJECT_BUFFER +static void fill_object_index_buffer(void* buf, obj* obj, int32_t& offset); // Added +static void fill_object_vertex_buffer(void* buf, obj* obj, int32_t& offset); // Added +#endif + +static void free_objdata_indirect_table(ObjsetInfo* info); + +static void free_object_index_buffer(ObjIB* objib); +static void free_object_vertex_buffer(ObjVB* objvb); + +static void free_objset_texture(ObjsetInfo* info); + +static bool load_objset_texture(ObjsetInfo* info, const void* data, bool big_endian = false); +static bool load_objset_texture_modern(ObjsetInfo* info, const void* data, size_t size, const char* file, texture_database* tex_db); -static void ObjsetInfo_vertex_array_load(ObjsetInfo* info); -static bool ObjsetInfo_vertex_buffer_load(ObjsetInfo* info); -static void ObjsetInfo_vertex_buffer_free(ObjsetInfo* info); -static uint32_t obj_vertex_format_get_vertex_size(obj_vertex_format format); -static uint32_t obj_vertex_format_get_vertex_size_comp1(obj_vertex_format format); -static uint32_t obj_vertex_format_get_vertex_size_comp2(obj_vertex_format format); + +static void load_objset_vertex_array(ObjsetInfo* info); // Added + +static void make_objdata_indirect_table(ObjsetInfo* info); + +static int32_t rewrite_to_restart_index(uint32_t* new_indices, + const int32_t num_indices, const uint32_t* indices); std::map objset_info_storage_data; std::map objset_info_storage_data_modern; -BufObjMgr bufobj_mgr; - -obj_mesh_index_buffer::obj_mesh_index_buffer() : buffer() { - -} - -bool obj_mesh_index_buffer::load(obj_mesh& mesh) { - size_t num_index = 0; - for (int32_t i = 0; i < mesh.num_submesh; i++) - num_index += mesh.submesh_array[i].num_index; - - if (!num_index) { - buffer = 0; - return true; - } - - uint16_t* indices = force_malloc(num_index); - obj_mesh_index_buffer::fill_data(indices, mesh); - - bool ret = load_data(num_index * sizeof(uint16_t), indices); - free_def(indices); - return ret; -} - -bool obj_mesh_index_buffer::load_data(size_t size, const void* data) { - if (!size) - return false; - - buffer = create_index_buffer(size, data); - return true; -} - -void obj_mesh_index_buffer::unload() { - free_index_buffer(buffer); - buffer = 0; -} - -void* obj_mesh_index_buffer::fill_data(void* data, obj_mesh& mesh) { - uint16_t* indices = (uint16_t*)data; - for (int32_t i = 0; i < mesh.num_submesh; i++) { - obj_sub_mesh& sub_mesh = mesh.submesh_array[i]; - - if (sub_mesh.primitive_type == OBJ_PRIMITIVE_TRIANGLE_STRIP && !(sub_mesh.attrib.w & 0x80)){ - uint32_t* index_array = prj::MemoryManager::alloc(prj::MemCTemp, sub_mesh.num_index, "NEW INDICES"); - sub_mesh.num_index = remove_degenerate_triangle_indices( - index_array, sub_mesh.num_index, sub_mesh.index_array); - memmove(sub_mesh.index_array, index_array, sizeof(uint32_t) * sub_mesh.num_index); - prj::MemoryManager::free(prj::MemCTemp, index_array); - } - - uint32_t* index = sub_mesh.index_array; - for (int32_t j = sub_mesh.num_index; j > 0; j--, index++) - *indices++ = (uint16_t)*index; - } - - indices = (uint16_t*)data; - for (int32_t i = 0, offset = 0; i < mesh.num_submesh; i++) { - obj_sub_mesh& sub_mesh = mesh.submesh_array[i]; - - sub_mesh.first_index = 0; - sub_mesh.last_index = 0; - sub_mesh.index_offset = 0; - if (sub_mesh.index_format != OBJ_INDEX_U16) - continue; - - uint16_t first_index = 0xFFFF; - uint16_t last_index = 0; - for (int32_t j = sub_mesh.num_index; j > 0; j--) { - uint16_t index = *indices++; - if (index == 0xFFFF) - continue; - - if (first_index > index) - first_index = index; - if (last_index < index) - last_index = index; - } - - sub_mesh.first_index = first_index; - sub_mesh.last_index = last_index; - sub_mesh.index_offset = (int32_t)(offset * sizeof(uint16_t)); - offset += sub_mesh.num_index; - } - return (void*)indices; -} - +ObjsetInfo::ObjsetInfo() : obj_ready(), tex_ready(), obj_set(), tex_num(), textures(), +id(), objvb_num(), objvb(), objib_num(), objib(), req_cnt(), modern() { #if SHARED_OBJECT_BUFFER -obj_mesh_vertex_buffer::obj_mesh_vertex_buffer() : count(), buffers(), size(), offset(), index() { -#else -obj_mesh_vertex_buffer::obj_mesh_vertex_buffer() : count(), buffers(), size(), index() { + ib = 0; + vb = 0; #endif - -} - -void obj_mesh_vertex_buffer::cycle_index() { - if (++index >= count) - index = 0; -} - -GLuint obj_mesh_vertex_buffer::get_buffer() { - if (index < count) - return buffers[index]; - return 0; -} - -size_t obj_mesh_vertex_buffer::get_offset() { -#if SHARED_OBJECT_BUFFER - if (buffers[0]) - return offset; -#endif - return 0; -} - -GLsizeiptr obj_mesh_vertex_buffer::get_size() { - if (buffers[0]) - return size; - return 0; -} - -bool obj_mesh_vertex_buffer::load(obj_mesh& mesh, GL::BufferUsage usage) { - if (!mesh.num_vertex || !mesh.vertex_array) - return false; - - uint32_t size_vertex; - switch (mesh.attrib.m.compression) { - case 0: - default: - size_vertex = obj_vertex_format_get_vertex_size(mesh.vertex_format); - break; - case 1: - size_vertex = obj_vertex_format_get_vertex_size_comp1(mesh.vertex_format); - break; - case 2: - size_vertex = obj_vertex_format_get_vertex_size_comp2(mesh.vertex_format); - break; - } - - void* vertex = prj::MemoryManager::alloc(prj::MemCTemp, (size_t)size_vertex * mesh.num_vertex, "TMP_VTXBUF"); - obj_mesh_vertex_buffer::fill_data(vertex, mesh); - mesh.size_vertex = size_vertex; - - bool ret = load_data((size_t)size_vertex * mesh.num_vertex, - vertex, mesh.attrib.m.double_buffer ? 2 : 1, usage); - prj::MemoryManager::free(prj::MemCTemp, vertex); - return ret; -} - -bool obj_mesh_vertex_buffer::load_data(size_t size, const void* data, int32_t count, GL::BufferUsage usage) { - if (!size || count > 3) - return false; - - this->count = count; - this->size = (GLsizeiptr)size; -#if SHARED_OBJECT_BUFFER - offset = 0; -#endif - - for (int32_t i = 0; i < count; i++) { - buffers[i] = create_vertex_buffer(size, data, usage); - if (!buffers[i]) { - unload(); - return false; - } - } - return true; -} - -void obj_mesh_vertex_buffer::unload() { - for (int32_t i = 0; i < count; i++) { - free_vertex_buffer(buffers[i]); - buffers[i] = 0; - } - - count = 0; -#if SHARED_OBJECT_BUFFER - offset = 0; -#endif - size = 0; - index = 0; -} - -void* obj_mesh_vertex_buffer::fill_data(void* data, obj_mesh& mesh) { - obj_vertex_format vertex_format = mesh.vertex_format; - obj_vertex_data* vtx = mesh.vertex_array; - int32_t num_vertex = mesh.num_vertex; - size_t d = (size_t)data; - switch (mesh.attrib.m.compression) { - case 0: - default: - for (int32_t i = num_vertex; i > 0; i--, vtx++) { - if (vertex_format & OBJ_VERTEX_POSITION) { - *(vec3*)d = vtx->position; - d += 12; - } - - if (vertex_format & OBJ_VERTEX_NORMAL) { - *(vec3*)d = vtx->normal; - d += 12; - } - - if (vertex_format & OBJ_VERTEX_TANGENT) { - *(vec4*)d = vtx->tangent; - d += 16; - } - - if (vertex_format & OBJ_VERTEX_BINORMAL) { - *(vec3*)d = vtx->binormal; - d += 12; - } - - if (vertex_format & OBJ_VERTEX_TEXCOORD0) { - *(vec2*)d = vtx->texcoord0; - d += 8; - } - - if (vertex_format & OBJ_VERTEX_TEXCOORD1) { - *(vec2*)d = vtx->texcoord1; - d += 8; - } - - if (vertex_format & OBJ_VERTEX_TEXCOORD2) { - *(vec2*)d = vtx->texcoord2; - d += 8; - } - - if (vertex_format & OBJ_VERTEX_TEXCOORD3) { - *(vec2*)d = vtx->texcoord3; - d += 8; - } - - if (vertex_format & OBJ_VERTEX_COLOR0) { - *(vec4*)d = vtx->color0; - d += 16; - } - - if (vertex_format & OBJ_VERTEX_COLOR1) { - *(vec4*)d = vtx->color1; - d += 16; - } - - if (vertex_format & OBJ_VERTEX_BONE_DATA) { - *(vec4*)d = vtx->bone_weight; - d += 16; - *(vec4i16*)d = vtx->bone_index; - d += 8; - } - - if (vertex_format & OBJ_VERTEX_UNKNOWN) { - *(vec4*)d = vtx->unknown; - d += 16; - } - } - break; - case 1: - for (int32_t i = num_vertex; i > 0; i--, vtx++) { - if (vertex_format & OBJ_VERTEX_POSITION) { - *(vec3*)d = vtx->position; - d += 12; - } - - if (vertex_format & OBJ_VERTEX_NORMAL) { - vec3_to_vec3i16(vtx->normal * 32767.0f, *(vec3i16*)d); - *(int16_t*)(d + 6) = 0; - d += 8; - } - - if (vertex_format & OBJ_VERTEX_TANGENT) { - vec4_to_vec4i16(vtx->tangent * 32767.0f, *(vec4i16*)d); - d += 8; - } - - if (vertex_format & OBJ_VERTEX_TEXCOORD0) { - vec2_to_vec2h(vtx->texcoord0, *(vec2h*)d); - d += 4; - } - - if (vertex_format & OBJ_VERTEX_TEXCOORD1) { - vec2_to_vec2h(vtx->texcoord1, *(vec2h*)d); - d += 4; - } - - if (vertex_format & OBJ_VERTEX_TEXCOORD2) { - vec2_to_vec2h(vtx->texcoord2, *(vec2h*)d); - d += 4; - } - - if (vertex_format & OBJ_VERTEX_TEXCOORD3) { - vec2_to_vec2h(vtx->texcoord3, *(vec2h*)d); - d += 4; - } - - if (vertex_format & OBJ_VERTEX_COLOR0) { - vec4_to_vec4h(vtx->color0, *(vec4h*)d); - d += 8; - } - - if (vertex_format & OBJ_VERTEX_BONE_DATA) { - vec4_to_vec4u16(vtx->bone_weight * 65535.0f, *(vec4u16*)d); - d += 8; - - *(vec4i16*)d = vtx->bone_index; - d += 8; - } - } - break; - case 2: - for (int32_t i = num_vertex; i > 0; i--, vtx++) { - if (vertex_format & OBJ_VERTEX_POSITION) { - *(vec3*)d = vtx->position; - d += 12; - } - - if (vertex_format & OBJ_VERTEX_NORMAL) { - vec3i16 normal_int; - vec3_to_vec3i16(vtx->normal * 511.0f, normal_int); - *(uint32_t*)d = (((uint32_t)0 & 0x03) << 30) - | (((uint32_t)normal_int.z & 0x3FF) << 20) - | (((uint32_t)normal_int.y & 0x3FF) << 10) - | ((uint32_t)normal_int.x & 0x3FF); - d += 4; - } - - if (vertex_format & OBJ_VERTEX_TANGENT) { - vec4i16 tangent_int; - vec4_to_vec4i16(vtx->tangent * 511.0f, tangent_int); - *(uint32_t*)d = (((uint32_t)clamp_def(tangent_int.w, -1, 1) & 0x03) << 30) - | (((uint32_t)tangent_int.z & 0x3FF) << 20) - | (((uint32_t)tangent_int.y & 0x3FF) << 10) - | ((uint32_t)tangent_int.x & 0x3FF); - d += 4; - } - - if (vertex_format & OBJ_VERTEX_TEXCOORD0) { - vec2_to_vec2h(vtx->texcoord0, *(vec2h*)d); - d += 4; - } - - if (vertex_format & OBJ_VERTEX_TEXCOORD1) { - vec2_to_vec2h(vtx->texcoord1, *(vec2h*)d); - d += 4; - } - - if (vertex_format & OBJ_VERTEX_TEXCOORD2) { - vec2_to_vec2h(vtx->texcoord2, *(vec2h*)d); - d += 4; - } - - if (vertex_format & OBJ_VERTEX_TEXCOORD3) { - vec2_to_vec2h(vtx->texcoord3, *(vec2h*)d); - d += 4; - } - - if (vertex_format & OBJ_VERTEX_COLOR0) { - vec4_to_vec4h(vtx->color0, *(vec4h*)d); - d += 8; - } - - if (vertex_format & OBJ_VERTEX_BONE_DATA) { - vec4i16 bone_weight_int; - vec4_to_vec4i16(vtx->bone_weight * 1023.0f, bone_weight_int); - *(uint32_t*)d = (((uint32_t)0 & 0x03) << 30) - | (((uint32_t)bone_weight_int.z & 0x3FF) << 20) - | (((uint32_t)bone_weight_int.y & 0x3FF) << 10) - | ((uint32_t)bone_weight_int.x & 0x3FF); - d += 4; - - vec4i bone_index; - vec4i16_to_vec4i(vtx->bone_index, bone_index); - vec4i_to_vec4u8(bone_index, *(vec4u8*)d); - d += 4; - } - } - break; - } - return (void*)d; -} - -#if SHARED_OBJECT_BUFFER -obj_index_buffer::obj_index_buffer() : mesh_num(), mesh_data(), buffer() { -#else -obj_index_buffer::obj_index_buffer() : mesh_num(), mesh_data() { -#endif - -} - -bool obj_index_buffer::load(obj* obj) { - if (!obj) - return false; - - mesh_num = obj->num_mesh; - mesh_data = prj::MemoryManager::alloc(prj::MemCSystem, obj->num_mesh, "MESHIB"); - if (!mesh_data) - return false; - -#if SHARED_OBJECT_BUFFER - size_t buffer_size = 0; - for (int32_t i = 0; i < mesh_num; i++) { - obj_mesh& mesh = obj->mesh_array[i]; - size_t num_index = 0; - for (int32_t j = 0; j < mesh.num_submesh; j++) - num_index += mesh.submesh_array[j].num_index; - buffer_size += num_index * sizeof(uint16_t); - } - - void* index = force_malloc(buffer_size); - if (!index && buffer_size) { - buffer = 0; - unload(); - return false; - } - - void* data = index; - for (int32_t i = 0; i < mesh_num; i++) { - uint32_t offset = (uint32_t)((size_t)data - (size_t)index); - data = obj_mesh_index_buffer::fill_data(data, obj->mesh_array[i]); - - obj_mesh& mesh = obj->mesh_array[i]; - for (int32_t j = 0; j < mesh.num_submesh; j++) - mesh.submesh_array[j].index_offset += offset; - } - - buffer = create_index_buffer(buffer_size, index); - if (!buffer && buffer_size) { - free_def(index); - unload(); - return false; - } - - free_def(index); - - for (int32_t i = 0; i < mesh_num; i++) - mesh_data[i].buffer = buffer; -#else - for (int32_t i = 0; i < mesh_num; i++) - if (!mesh_data[i].load(obj->mesh_array[i])) - return false; -#endif - return true; -} - -void obj_index_buffer::unload() { - if (mesh_data) { -#if SHARED_OBJECT_BUFFER - free_index_buffer(buffer); - buffer = 0; -#else - for (int32_t i = 0; i < mesh_num; i++) - mesh_data[i].unload(); -#endif - prj::MemoryManager::free(prj::MemCSystem, mesh_data); - } - mesh_data = 0; - mesh_num = 0; -#if SHARED_OBJECT_BUFFER - buffer = 0; -#endif -} - -#if SHARED_OBJECT_BUFFER -obj_vertex_buffer::obj_vertex_buffer() : mesh_num(), mesh_data(), buffers() { -#else -obj_vertex_buffer::obj_vertex_buffer() : mesh_num(), mesh_data() { -#endif - -} - -bool obj_vertex_buffer::load(obj* obj) { - if (!obj) - return false; - - mesh_num = obj->num_mesh; - mesh_data = new obj_mesh_vertex_buffer[obj->num_mesh]; - if (!mesh_data) - return false; - -#if SHARED_OBJECT_BUFFER - size_t buffer_size = 0; - bool double_buffer = false; - for (int32_t i = 0; i < mesh_num; i++) { - obj_mesh& mesh = obj->mesh_array[i]; - if (!mesh.num_vertex || !mesh.vertex_array) - continue; - - uint32_t size_vertex; - switch (mesh.attrib.m.compression) { - case 0: - default: - size_vertex = obj_vertex_format_get_vertex_size(mesh.vertex_format); - break; - case 1: - size_vertex = obj_vertex_format_get_vertex_size_comp1(mesh.vertex_format); - break; - case 2: - size_vertex = obj_vertex_format_get_vertex_size_comp2(mesh.vertex_format); - break; - } - mesh.size_vertex = size_vertex; - - buffer_size += (size_t)size_vertex * mesh.num_vertex; - double_buffer |= !!mesh.attrib.m.double_buffer; - } - - int32_t count = double_buffer ? 2 : 1; - - void* vertex = prj::MemoryManager::alloc(prj::MemCTemp, buffer_size, "TMP_VTXBUF"); - if (!vertex && buffer_size) { - for (int32_t i = 0; i < count; i++) - buffers[i] = 0; - unload(); - return false; - } - - void* data = vertex; - for (int32_t i = 0; i < mesh_num; i++) { - obj_mesh_vertex_buffer& mesh_buffer = mesh_data[i]; - mesh_buffer.offset = (size_t)data - (size_t)vertex; - mesh_buffer.count = count; - mesh_buffer.size = (GLsizeiptr)buffer_size; - - data = obj_mesh_vertex_buffer::fill_data(data, obj->mesh_array[i]); - } - - for (int32_t i = 0; i < count; i++) { - buffers[i] = create_vertex_buffer(buffer_size, vertex); - if (!buffers[i] && buffer_size) { - prj::MemoryManager::free(prj::MemCTemp, vertex); - unload(); - return false; - } - } - - prj::MemoryManager::free(prj::MemCTemp, vertex); - - for (int32_t i = 0; i < mesh_num; i++) - memcpy(mesh_data[i].buffers, buffers, count * sizeof(GLuint)); -#else - for (int32_t i = 0; i < mesh_num; i++) - if (!mesh_data[i].load(obj->mesh_array[i])) - return false; -#endif - return true; -} - -void obj_vertex_buffer::unload() { - if (mesh_data) { -#if SHARED_OBJECT_BUFFER - if (mesh_num) - for (int32_t i = 0; i < mesh_data[0].count; i++) - free_vertex_buffer(buffers[i]); - else - for (int32_t i = 0; i < 3; i++) - free_vertex_buffer(buffers[i]); -#else - for (int32_t i = 0; i < mesh_num; i++) - mesh_data[i].unload(); -#endif - delete[] mesh_data; - } - mesh_data = 0; - mesh_num = 0; -#if SHARED_OBJECT_BUFFER - buffers[0] = 0; -#endif -} - -ObjsetInfo::ObjsetInfo() : obj_loaded(), tex_loaded(), obj_set(), -tex_num(), tex_data(), set_id(), objvb_num(), objvb(), -objib_num(), objib(), load_count(), modern() { - } ObjsetInfo::~ObjsetInfo() { - if (tex_data) { - texture_array_free(tex_data); - tex_data = 0; - } + free_objdata_indirect_table(this); + free_objset_texture(this); + free_objset_index_buffer(this); + free_objset_vertex_buffer(this); - ObjsetInfo_index_buffer_free(this); - ObjsetInfo_vertex_buffer_free(this); alloc_handler.reset(); while (tex_file_handler.ptr && tex_file_handler.ptr->count) tex_file_handler.reset(); @@ -683,6 +144,7 @@ inline int32_t obj_material_texture_type_get_texture_index( return -1; } +// 0x1405E9250 void obj_skin_set_matrix_buffer(const obj_skin* s, const mat4* matrices, const mat4* ex_data_matrices, mat4* matrix_buffer, const mat4* mat, const mat4& global_mat) { if (!s->num_bone) @@ -778,23 +240,73 @@ void object_material_msgpack_read(const char* path, const char* set_name, msgpack* shader_compo = material.read("shader_compo"); if (shader_compo) { - mat.shader_compo.m.color = shader_compo->read_bool("color") ? 1 : 0; - mat.shader_compo.m.color_a = shader_compo->read_bool("color_a") ? 1 : 0; - mat.shader_compo.m.color_l1 = shader_compo->read_bool("color_l1") ? 1 : 0; - mat.shader_compo.m.color_l1_a = shader_compo->read_bool("color_l1_a") ? 1 : 0; - mat.shader_compo.m.color_l2 = shader_compo->read_bool("color_l2") ? 1 : 0; - mat.shader_compo.m.color_l2_a = shader_compo->read_bool("color_l2_a") ? 1 : 0; - mat.shader_compo.m.transparency = shader_compo->read_bool("transparency") ? 1 : 0; - mat.shader_compo.m.specular = shader_compo->read_bool("specular") ? 1 : 0; - mat.shader_compo.m.normal_01 = shader_compo->read_bool("normal_01") ? 1 : 0; - mat.shader_compo.m.normal_02 = shader_compo->read_bool("normal_02") ? 1 : 0; - mat.shader_compo.m.envmap = shader_compo->read_bool("envmap") ? 1 : 0; - mat.shader_compo.m.color_l3 = shader_compo->read_bool("color_l3") ? 1 : 0; - mat.shader_compo.m.color_l3_a = shader_compo->read_bool("color_l3_a") ? 1 : 0; - mat.shader_compo.m.translucency = shader_compo->read_bool("translucency") ? 1 : 0; - mat.shader_compo.m.flag_14 = shader_compo->read_bool("flag_14") ? 1 : 0; - mat.shader_compo.m.override_ibl = shader_compo->read_bool("override_ibl") ? 1 : 0; - mat.shader_compo.m.dummy = shader_compo->read_uint32_t("dummy"); + msgpack* color = shader_compo->read("color"); + if (color) + mat.shader_compo.m.color = color->read_bool() ? 1 : 0; + + msgpack* color_a = shader_compo->read("color_a"); + if (color_a) + mat.shader_compo.m.color_a = color_a->read_bool() ? 1 : 0; + + msgpack* color_l1 = shader_compo->read("color_l1"); + if (color_l1) + mat.shader_compo.m.color_l1 = color_l1->read_bool() ? 1 : 0; + + msgpack* color_l1_a = shader_compo->read("color_l1_a"); + if (color_l1_a) + mat.shader_compo.m.color_l1_a = color_l1_a->read_bool() ? 1 : 0; + + msgpack* color_l2 = shader_compo->read("color_l2"); + if (color_l2) + mat.shader_compo.m.color_l2 = color_l2->read_bool() ? 1 : 0; + + msgpack* color_l2_a = shader_compo->read("color_l2_a"); + if (color_l2_a) + mat.shader_compo.m.color_l2_a = color_l2_a->read_bool() ? 1 : 0; + + msgpack* transparency = shader_compo->read("transparency"); + if (transparency) + mat.shader_compo.m.transparency = transparency->read_bool() ? 1 : 0; + + msgpack* specular = shader_compo->read("specular"); + if (specular) + mat.shader_compo.m.specular = specular->read_bool() ? 1 : 0; + + msgpack* normal_01 = shader_compo->read("normal_01"); + if (normal_01) + mat.shader_compo.m.normal_01 = normal_01->read_bool() ? 1 : 0; + + msgpack* normal_02 = shader_compo->read("normal_02"); + if (normal_02) + mat.shader_compo.m.normal_02 = normal_02->read_bool() ? 1 : 0; + + msgpack* envmap = shader_compo->read("envmap"); + if (envmap) + mat.shader_compo.m.envmap = envmap->read_bool() ? 1 : 0; + + msgpack* color_l3 = shader_compo->read("color_l3"); + if (color_l3) + mat.shader_compo.m.color_l3 = color_l3->read_bool() ? 1 : 0; + + msgpack* color_l3_a = shader_compo->read("color_l3_a"); + if (color_l3_a) + mat.shader_compo.m.color_l3_a = color_l3_a->read_bool() ? 1 : 0; + + msgpack* translucency = shader_compo->read("translucency"); + if (translucency) + mat.shader_compo.m.translucency = translucency->read_bool() ? 1 : 0; + + msgpack* env_sphere = shader_compo->read({ "env_sphere", "flag_14" }); + if (env_sphere) + mat.shader_compo.m.env_sphere = env_sphere->read_bool() ? 1 : 0; + + msgpack* env_cube = shader_compo->read({ "env_cube", "override_ibl" }); + if (env_cube) + mat.shader_compo.m.env_cube = env_cube->read_bool() ? 1 : 0; + + msgpack* dummy = shader_compo->read("dummy"); + if (dummy) + mat.shader_compo.m.dummy = dummy->read_uint32_t(); } msgpack* _shader_name = material.read("shader_name"); @@ -807,24 +319,66 @@ void object_material_msgpack_read(const char* path, const char* set_name, msgpack* shader_info = material.read("shader_info"); if (shader_info) { - mat.shader_info.m.vtx_trans_type = (obj_material_vertex_translation_type) - shader_info->read_uint32_t("vtx_trans_type"); - mat.shader_info.m.col_src = (obj_material_color_source_type)shader_info->read_uint32_t("col_src"); - mat.shader_info.m.is_lgt_diffuse = shader_info->read_bool("is_lgt_diffuse") ? 1 : 0; - mat.shader_info.m.is_lgt_specular = shader_info->read_bool("is_lgt_specular") ? 1 : 0; - mat.shader_info.m.is_lgt_per_pixel = shader_info->read_bool("is_lgt_per_pixel") ? 1 : 0; - mat.shader_info.m.is_lgt_double = shader_info->read_bool("is_lgt_double") ? 1 : 0; - mat.shader_info.m.bump_map_type = (obj_material_bump_map_type) - shader_info->read_uint32_t("bump_map_type"); - mat.shader_info.m.fresnel_type = shader_info->read_uint32_t("fresnel_type"); - mat.shader_info.m.line_light = shader_info->read_uint32_t("line_light"); - mat.shader_info.m.recieve_shadow = shader_info->read_bool("recieve_shadow") ? 1 : 0; - mat.shader_info.m.cast_shadow = shader_info->read_bool("cast_shadow") ? 1 : 0; - mat.shader_info.m.specular_quality = (obj_material_specular_quality) - shader_info->read_uint32_t("specular_quality"); - mat.shader_info.m.aniso_direction = (obj_material_aniso_direction) - shader_info->read_uint32_t("aniso_direction"); - mat.shader_info.m.dummy = shader_info->read_uint32_t("dummy"); + msgpack* vtx_trans_type = shader_info->read("vtx_trans_type"); + if (vtx_trans_type) + mat.shader_info.m.vtx_trans_type = (obj_material_vertex_translation_type) + vtx_trans_type->read_uint32_t(); + + msgpack* col_src = shader_info->read("col_src"); + if (col_src) + mat.shader_info.m.col_src + = (obj_material_color_source_type)col_src->read_uint32_t("col_src"); + + msgpack* is_lgt_diffuse = shader_info->read("is_lgt_diffuse"); + if (is_lgt_diffuse) + mat.shader_info.m.is_lgt_diffuse = is_lgt_diffuse->read_bool() ? 1 : 0; + + msgpack* is_lgt_specular = shader_info->read("is_lgt_specular"); + if (is_lgt_specular) + mat.shader_info.m.is_lgt_specular = is_lgt_specular->read_bool() ? 1 : 0; + + msgpack* is_lgt_per_pixel = shader_info->read("is_lgt_per_pixel"); + if (is_lgt_per_pixel) + mat.shader_info.m.is_lgt_per_pixel = is_lgt_per_pixel->read_bool() ? 1 : 0; + + msgpack* is_lgt_double = shader_info->read("is_lgt_double"); + if (is_lgt_double) + mat.shader_info.m.is_lgt_double = is_lgt_double->read_bool() ? 1 : 0; + + msgpack* bump_map_type = shader_info->read("bump_map_type"); + if (bump_map_type) + mat.shader_info.m.bump_map_type = (obj_material_bump_map_type) + bump_map_type->read_uint32_t(); + + msgpack* fresnel_type = shader_info->read("fresnel_type"); + if (fresnel_type) + mat.shader_info.m.fresnel_type = fresnel_type->read_uint32_t(); + + msgpack* line_light = shader_info->read("line_light"); + if (line_light) + mat.shader_info.m.line_light = line_light->read_uint32_t(); + + msgpack* receive_shadow = shader_info->read({ "receive_shadow", "recieve_shadow" }); + if (receive_shadow) + mat.shader_info.m.receive_shadow = receive_shadow->read_bool() ? 1 : 0; + + msgpack* cast_shadow = shader_info->read("cast_shadow"); + if (cast_shadow) + mat.shader_info.m.cast_shadow = cast_shadow->read_bool() ? 1 : 0; + + msgpack* specular_quality = shader_info->read("specular_quality"); + if (specular_quality) + mat.shader_info.m.specular_quality = (obj_material_specular_quality) + specular_quality->read_uint32_t(); + + msgpack* aniso_direction = shader_info->read("aniso_direction"); + if (aniso_direction) + mat.shader_info.m.aniso_direction = (obj_material_aniso_direction) + aniso_direction->read_uint32_t(); + + msgpack* dummy = shader_info->read("dummy"); + if (dummy) + mat.shader_info.m.dummy = dummy->read_uint32_t(); } int32_t num_of_textures = 0; @@ -840,20 +394,61 @@ void object_material_msgpack_read(const char* path, const char* set_name, msgpack* attrib = tex->read("attrib"); if (attrib) { - l.attrib.m.repeat_u = attrib->read_bool("repeat_u") ? 1 : 0; - l.attrib.m.repeat_v = attrib->read_bool("repeat_v") ? 1 : 0; - l.attrib.m.mirror_u = attrib->read_bool("mirror_u") ? 1 : 0; - l.attrib.m.mirror_v = attrib->read_bool("mirror_v") ? 1 : 0; - l.attrib.m.ignore_alpha = attrib->read_bool("ignore_alpha") ? 1 : 0; - l.attrib.m.blend = attrib->read_uint32_t("blend"); - l.attrib.m.alpha_blend = attrib->read_uint32_t("alpha_blend"); - l.attrib.m.border = attrib->read_bool("border") ? 1 : 0; - l.attrib.m.clamp2edge = attrib->read_bool("clamp2edge") ? 1 : 0; - l.attrib.m.filter = attrib->read_uint32_t("filter"); - l.attrib.m.mipmap = attrib->read_uint32_t("mipmap"); - l.attrib.m.mipmap_bias = attrib->read_uint32_t("mipmap_bias"); - l.attrib.m.flag_29 = attrib->read_bool("flag_29") ? 1 : 0; - l.attrib.m.anisotropic_filter = attrib->read_uint32_t("anisotropic_filter"); + msgpack* repeat_u = attrib->read("repeat_u"); + if (repeat_u) + l.attrib.m.repeat_u = repeat_u->read_bool() ? 1 : 0; + + msgpack* repeat_v = attrib->read("repeat_v"); + if (repeat_v) + l.attrib.m.repeat_v = repeat_v->read_bool() ? 1 : 0; + + msgpack* mirror_u = attrib->read("mirror_u"); + if (mirror_u) + l.attrib.m.mirror_u = mirror_u->read_bool() ? 1 : 0; + + msgpack* mirror_v = attrib->read("mirror_v"); + if (mirror_v) + l.attrib.m.mirror_v = mirror_v->read_bool() ? 1 : 0; + + msgpack* ignore_alpha = attrib->read("ignore_alpha"); + if (ignore_alpha) + l.attrib.m.ignore_alpha = ignore_alpha->read_bool() ? 1 : 0; + + msgpack* blend = attrib->read("blend"); + if (blend) + l.attrib.m.blend = blend->read_uint32_t(); + + msgpack* alpha_blend = attrib->read("alpha_blend"); + if (alpha_blend) + l.attrib.m.alpha_blend = alpha_blend->read_uint32_t(); + + msgpack* border = attrib->read("border"); + if (border) + l.attrib.m.border = border->read_bool() ? 1 : 0; + + msgpack* clamp2edge = attrib->read("clamp2edge"); + if (clamp2edge) + l.attrib.m.clamp2edge = clamp2edge->read_bool() ? 1 : 0; + + msgpack* filter = attrib->read("filter"); + if (filter) + l.attrib.m.filter = filter->read_uint32_t(); + + msgpack* mipmap = attrib->read("mipmap"); + if (mipmap) + l.attrib.m.mipmap = mipmap->read_uint32_t(); + + msgpack* mipmap_bias = attrib->read("mipmap_bias"); + if (mipmap_bias) + l.attrib.m.mipmap_bias = mipmap_bias->read_uint32_t(); + + msgpack* ignore = attrib->read({ "ignore", "flag_29" }); + if (ignore) + l.attrib.m.ignore = ignore->read_bool() ? 1 : 0; + + msgpack* aniso = attrib->read({ "aniso", "anisotropic_filter" }); + if (aniso) + l.attrib.m.aniso = aniso->read_uint32_t(); } msgpack* _tex_name = tex->read("tex_name"); @@ -939,24 +534,72 @@ void object_material_msgpack_read(const char* path, const char* set_name, msgpack* attrib = material.read("attrib"); if (attrib) { - mat.attrib.m.alpha_texture = attrib->read_bool("alpha_texture") ? 1 : 0; - mat.attrib.m.alpha_material = attrib->read_bool("alpha_material") ? 1 : 0; - mat.attrib.m.punch_through = attrib->read_bool("punch_through") ? 1 : 0; - mat.attrib.m.double_sided = attrib->read_bool("double_sided") ? 1 : 0; - mat.attrib.m.normal_dir_light = attrib->read_bool("normal_dir_light") ? 1 : 0; - mat.attrib.m.src_blend_factor = (obj_material_blend_factor) - attrib->read_uint32_t("src_blend_factor"); - mat.attrib.m.dst_blend_factor = (obj_material_blend_factor) - attrib->read_uint32_t("dst_blend_factor"); - mat.attrib.m.blend_operation = attrib->read_uint32_t("blend_operation"); - mat.attrib.m.zbias = attrib->read_uint32_t("zbias"); - mat.attrib.m.no_fog = attrib->read_bool("no_fog") ? 1 : 0; - mat.attrib.m.translucent_priority = attrib->read_uint32_t("translucent_priority"); - mat.attrib.m.has_fog_height = attrib->read_bool("has_fog_height") ? 1 : 0; - mat.attrib.m.flag_28 = attrib->read_bool("flag_28") ? 1 : 0; - mat.attrib.m.fog_height = attrib->read_bool("fog_height") ? 1 : 0; - mat.attrib.m.flag_30 = attrib->read_bool("flag_30") ? 1 : 0; - mat.attrib.m.flag_31 = attrib->read_bool("flag_31") ? 1 : 0; + + msgpack* alpha_tex = attrib->read({ "alpha_tex", "alpha_texture" }); + if (alpha_tex) + mat.attrib.m.alpha_tex = alpha_tex->read_bool() ? 1 : 0; + + msgpack* alpha_mat = attrib->read({ "alpha_mat", "alpha_material" }); + if (alpha_mat) + mat.attrib.m.alpha_mat = alpha_mat->read_bool() ? 1 : 0; + + msgpack* punch_through = attrib->read("punch_through"); + if (punch_through) + mat.attrib.m.punch_through = punch_through->read_bool() ? 1 : 0; + + msgpack* double_sided = attrib->read("double_sided"); + if (double_sided) + mat.attrib.m.double_sided = double_sided->read_bool() ? 1 : 0; + + msgpack* normal_dir_light = attrib->read("normal_dir_light"); + if (normal_dir_light) + mat.attrib.m.normal_dir_light = normal_dir_light->read_bool() ? 1 : 0; + + msgpack* src_blend_factor = attrib->read("src_blend_factor"); + if (src_blend_factor) + mat.attrib.m.src_blend_factor = (obj_material_blend_factor) + src_blend_factor->read_uint32_t(); + + msgpack* dst_blend_factor = attrib->read("dst_blend_factor"); + if (dst_blend_factor) + mat.attrib.m.dst_blend_factor = (obj_material_blend_factor) + dst_blend_factor->read_uint32_t(); + + msgpack* blend_operation = attrib->read("blend_operation"); + if (blend_operation) + mat.attrib.m.blend_operation = blend_operation->read_uint32_t(); + + msgpack* zbias = attrib->read("zbias"); + if (zbias) + mat.attrib.m.zbias = zbias->read_uint32_t(); + + msgpack* no_z_fog = attrib->read({ "no_z_fog", "no_fog" }); + if (no_z_fog) + mat.attrib.m.no_z_fog = no_z_fog->read_bool() ? 1 : 0; + + msgpack* alpha_prio = attrib->read({ "alpha_prio", "translucent_priority" }); + if (alpha_prio) + mat.attrib.m.alpha_prio = alpha_prio->read_uint32_t(); + + msgpack* y_fog = attrib->read({ "y_fog", "has_fog_height" }); + if (y_fog) + mat.attrib.m.y_fog = y_fog->read_bool() ? 1 : 0; + + msgpack* ignore_alpha = attrib->read({ "ignore_alpha", "flag_28" }); + if (ignore_alpha) + mat.attrib.m.ignore_alpha = ignore_alpha->read_bool() ? 1 : 0; + + msgpack* y_fogmap = attrib->read({ "y_fogmap", "fog_height" }); + if (y_fogmap) + mat.attrib.m.y_fogmap = y_fogmap->read_bool() ? 1 : 0; + + msgpack* use_mat_center = attrib->read({ "use_mat_center", "flag_30" }); + if (use_mat_center) + mat.attrib.m.use_mat_center = use_mat_center->read_bool() ? 1 : 0; + + msgpack* dummy = attrib->read({ "dummy", "flag_31" }); + if (dummy) + mat.attrib.m.dummy = dummy->read_bool() ? 1 : 0; } msgpack* color = material.read("color"); @@ -1170,17 +813,29 @@ void object_material_msgpack_read(const char* path, const char* set_name, msgpack* attrib = _sub_mesh.read("attrib"); if (attrib) { - msgpack* recieve_shadow = attrib->read("recieve_shadow"); - if (recieve_shadow) - sub_mesh.attrib.m.recieve_shadow = recieve_shadow->read_bool(); + msgpack* receive_shadow = attrib->read({ "receive_shadow", "recieve_shadow" }); + if (receive_shadow) + sub_mesh.attrib.m.receive_shadow = receive_shadow->read_bool(); msgpack* cast_shadow = attrib->read("cast_shadow"); if (cast_shadow) sub_mesh.attrib.m.cast_shadow = cast_shadow->read_bool(); - msgpack* translucent = attrib->read("translucent"); - if (translucent) - sub_mesh.attrib.m.translucent = translucent->read_bool(); + msgpack* vertex_alpha = attrib->read({ "vertex_alpha", "translucent" }); + if (vertex_alpha) + sub_mesh.attrib.m.vertex_alpha = vertex_alpha->read_bool(); + + msgpack* hide = attrib->read("hide"); + if (hide) + sub_mesh.attrib.m.hide = hide->read_bool(); + + msgpack* poly_offset = attrib->read("poly_offset"); + if (poly_offset) + sub_mesh.attrib.m.poly_offset = poly_offset->read_uint32_t(); + + msgpack* use_restart_index = attrib->read("use_restart_index"); + if (hide) + sub_mesh.attrib.m.use_restart_index = hide->read_bool(); } } break; @@ -1398,8 +1053,8 @@ void object_material_msgpack_write(const char* path, const char* set_name, uint3 shader_compo->append("color_l3", (bool)mat.shader_compo.m.color_l3); shader_compo->append("color_l3_a", (bool)mat.shader_compo.m.color_l3_a); shader_compo->append("translucency", (bool)mat.shader_compo.m.translucency); - shader_compo->append("flag_14", (bool)mat.shader_compo.m.flag_14); - shader_compo->append("override_ibl", (bool)mat.shader_compo.m.override_ibl); + shader_compo->append("env_sphere", (bool)mat.shader_compo.m.env_sphere); + shader_compo->append("env_cube", (bool)mat.shader_compo.m.env_cube); shader_compo->append("dummy", mat.shader_compo.m.dummy); } @@ -1416,7 +1071,7 @@ void object_material_msgpack_write(const char* path, const char* set_name, uint3 shader_info->append("bump_map_type", mat.shader_info.m.bump_map_type); shader_info->append("fresnel_type", mat.shader_info.m.fresnel_type); shader_info->append("line_light", mat.shader_info.m.line_light); - shader_info->append("recieve_shadow", (bool)mat.shader_info.m.recieve_shadow); + shader_info->append("receive_shadow", (bool)mat.shader_info.m.receive_shadow); shader_info->append("cast_shadow", (bool)mat.shader_info.m.cast_shadow); shader_info->append("specular_quality", mat.shader_info.m.specular_quality); shader_info->append("aniso_direction", mat.shader_info.m.aniso_direction); @@ -1447,8 +1102,8 @@ void object_material_msgpack_write(const char* path, const char* set_name, uint3 attrib->append("filter", k.attrib.m.filter); attrib->append("mipmap", k.attrib.m.mipmap); attrib->append("mipmap_bias", k.attrib.m.mipmap_bias); - attrib->append("flag_29", (bool)k.attrib.m.flag_29); - attrib->append("anisotropic_filter", k.attrib.m.anisotropic_filter); + attrib->append("ignore", (bool)k.attrib.m.ignore); + attrib->append("aniso", k.attrib.m.aniso); } tex.append("tex_name", tex_db->get_texture_name(k.tex_index)); @@ -1526,8 +1181,8 @@ void object_material_msgpack_write(const char* path, const char* set_name, uint3 msgpack* attrib = material.append("attrib", msgpack_map()); if (attrib) { - attrib->append("alpha_texture", (bool)mat.attrib.m.alpha_texture); - attrib->append("alpha_material", (bool)mat.attrib.m.alpha_material); + attrib->append("alpha_tex", (bool)mat.attrib.m.alpha_tex); + attrib->append("alpha_mat", (bool)mat.attrib.m.alpha_mat); attrib->append("punch_through", (bool)mat.attrib.m.punch_through); attrib->append("double_sided", (bool)mat.attrib.m.double_sided); attrib->append("normal_dir_light", (bool)mat.attrib.m.normal_dir_light); @@ -1535,13 +1190,13 @@ void object_material_msgpack_write(const char* path, const char* set_name, uint3 attrib->append("dst_blend_factor", mat.attrib.m.dst_blend_factor); attrib->append("blend_operation", mat.attrib.m.blend_operation); attrib->append("zbias", mat.attrib.m.zbias); - attrib->append("no_fog", (bool)mat.attrib.m.no_fog); - attrib->append("translucent_priority", mat.attrib.m.translucent_priority); - attrib->append("has_fog_height", (bool)mat.attrib.m.has_fog_height); - attrib->append("flag_28", (bool)mat.attrib.m.flag_28); - attrib->append("fog_height", (bool)mat.attrib.m.fog_height); - attrib->append("flag_30", (bool)mat.attrib.m.flag_30); - attrib->append("flag_31", (bool)mat.attrib.m.flag_31); + attrib->append("no_z_fog", (bool)mat.attrib.m.no_z_fog); + attrib->append("alpha_prio", mat.attrib.m.alpha_prio); + attrib->append("y_fog", (bool)mat.attrib.m.y_fog); + attrib->append("ignore_alpha", (bool)mat.attrib.m.ignore_alpha); + attrib->append("y_fogmap", (bool)mat.attrib.m.y_fogmap); + attrib->append("use_mat_center", (bool)mat.attrib.m.use_mat_center); + attrib->append("dummy", (bool)mat.attrib.m.dummy); } msgpack* color = material.append("color", msgpack_map()); @@ -1626,8 +1281,12 @@ void object_material_msgpack_write(const char* path, const char* set_name, uint3 { msgpack attrib = msgpack_map(); - attrib.append("recieve_shadow", (bool)sub_mesh.attrib.m.recieve_shadow); + attrib.append("receive_shadow", (bool)sub_mesh.attrib.m.receive_shadow); attrib.append("cast_shadow", (bool)sub_mesh.attrib.m.cast_shadow); + attrib.append("vertex_alpha", (bool)sub_mesh.attrib.m.vertex_alpha); + attrib.append("hide", (bool)sub_mesh.attrib.m.hide); + attrib.append("poly_offset", sub_mesh.attrib.m.poly_offset); + attrib.append("use_restart_index", (bool)sub_mesh.attrib.m.use_restart_index); _sub_mesh.append("attrib", attrib); } } @@ -1680,379 +1339,609 @@ void object_material_msgpack_write(const char* path, const char* set_name, uint3 inline void objset_info_storage_init(const object_database* obj_db) { for (const object_set_info& i : obj_db->object_set) { ObjsetInfo info; - info.set_id = i.id; + info.id = i.id; info.name.assign(i.name); objset_info_storage_data.insert({ i.id, info }); } objset_info_storage_data_modern.clear(); } -inline obj* objset_info_storage_get_obj(object_info obj_info) { - auto elem = objset_info_storage_data.find(obj_info.set_id); - if (elem != objset_info_storage_data.end()) { - obj_set* set = elem->second.obj_set; - if (!set) - return 0; - - auto elem_obj = elem->second.obj_id_data.find(obj_info.id); - if (elem_obj != elem->second.obj_id_data.end()) - return set->obj_data[elem_obj->second]; - return 0; - } - - auto elem_modern = objset_info_storage_data_modern.find(obj_info.set_id); - if (elem_modern != objset_info_storage_data_modern.end()) { - obj_set* set = elem_modern->second.obj_set; - if (!set) - return 0; - - auto elem_obj = elem_modern->second.obj_id_data.find(obj_info.id); - if (elem_obj != elem_modern->second.obj_id_data.end()) - return set->obj_data[elem_obj->second]; - return 0; - } - return 0; +inline void objset_info_storage_free() { + objset_info_storage_data.clear(); + objset_info_storage_data_modern.clear(); } -inline obj* objset_info_storage_get_obj_by_index(uint32_t set_id, int32_t index) { - auto elem = objset_info_storage_data.find(set_id); - if (elem != objset_info_storage_data.end()) { - obj_set* set = elem->second.obj_set; - if (!set) - return 0; - - if (index < elem->second.obj_set->obj_num) - return elem->second.obj_set->obj_data[index]; - return 0; - } - - auto elem_modern = objset_info_storage_data_modern.find(set_id); - if (elem_modern != objset_info_storage_data_modern.end()) { - obj_set* set = elem_modern->second.obj_set; - if (!set) - return 0; - - if (index < elem_modern->second.obj_set->obj_num) - return elem_modern->second.obj_set->obj_data[index]; - return 0; - } - return 0; +// 0x140457910 +inline bool check_objset_ready(uint32_t objset_index) { + ObjsetInfo* info = get_objset_info(objset_index); + if (info) + return info->obj_ready && info->tex_ready; + return false; } -inline ObjsetInfo* objset_info_storage_get_objset_info(uint32_t set_id) { - auto elem = objset_info_storage_data.find(set_id); - if (elem != objset_info_storage_data.end()) - return &elem->second; +// 0x140458040 +bool create_mesh_index_buffer(IndexBuffer& ibhn, obj_mesh& mesh) { + uint32_t size = 0; + for (int32_t i = 0; i < mesh.num_submesh; i++) { + obj_sub_mesh& sub_mesh = mesh.submesh_array[i]; + if (sub_mesh.index_format == OBJ_INDEX_U16) + size += align_val_32((int32_t)(sizeof(uint16_t) * sub_mesh.num_index)); + } - auto elem_modern = objset_info_storage_data_modern.find(set_id); - if (elem_modern != objset_info_storage_data_modern.end()) - return &elem_modern->second; - return 0; + if (!size) { + ibhn.ib = 0; + return true; + } + + void* buf = force_malloc(size); + int32_t offset = 0; + fill_mesh_index_buffer(buf, mesh, offset); + + ibhn.create(offset, buf); + free_def(buf); + return true; } -inline obj_mesh* objset_info_storage_get_obj_mesh(object_info obj_info, const char* mesh_name) { - auto elem = objset_info_storage_data.find(obj_info.set_id); - if (elem != objset_info_storage_data.end()) { - obj_set* set = elem->second.obj_set; - if (!set) - return 0; +#if SHARED_OBJECT_BUFFER +// Added +inline void create_mesh_index_buffer(IndexBuffer& ibhn, obj_mesh& mesh, GLuint in_ib) { + //ibhn.create(in_ib, size); +} +#endif - auto elem_obj = elem->second.obj_id_data.find(obj_info.id); - if (elem_obj != elem->second.obj_id_data.end()) - return set->obj_data[elem_obj->second]->get_obj_mesh(mesh_name); - return 0; - } +// 0x140458280 +bool create_mesh_vertex_buffer(VertexBuffer& vbhn, obj_mesh& mesh, GL::BufferUsage usage) { + if (!mesh.num_vertex || !mesh.vertex_array) + return false; - auto elem_modern = objset_info_storage_data_modern.find(obj_info.set_id); - if (elem_modern != objset_info_storage_data_modern.end()) { - obj_set* set = elem_modern->second.obj_set; - if (!set) - return 0; + uint32_t size_vertex = get_vertex_size(mesh.vertex_format, mesh.attrib.m.compression); + void* buf = prj::MemoryManager::alloc(prj::MemCTemp, (size_t)size_vertex * mesh.num_vertex, "TMP_VTXBUF"); + fill_mesh_vertex_buffer(buf, mesh); + mesh.size_vertex = size_vertex; - auto elem_obj = elem_modern->second.obj_id_data.find(obj_info.id); - if (elem_obj != elem_modern->second.obj_id_data.end()) - return set->obj_data[elem_obj->second]->get_obj_mesh(mesh_name); - return 0; - } - return 0; + bool ret = vbhn.create((size_t)size_vertex * mesh.num_vertex, + buf, mesh.attrib.m.soft_body ? 2 : 1, usage); + prj::MemoryManager::free(prj::MemCTemp, buf); + return ret; } -inline obj_mesh* objset_info_storage_get_obj_mesh_by_index(object_info obj_info, int32_t index) { - auto elem = objset_info_storage_data.find(obj_info.set_id); - if (elem != objset_info_storage_data.end()) { - obj_set* set = elem->second.obj_set; - if (!set) - return 0; +#if SHARED_OBJECT_BUFFER +// Added +inline void create_mesh_vertex_buffer(VertexBuffer& vbhn, + obj_mesh& mesh, GLuint in_vb, uint32_t& offset) { + if (!mesh.num_vertex || !mesh.vertex_array) + return; - auto elem_obj = elem->second.obj_id_data.find(obj_info.id); - if (elem_obj != elem->second.obj_id_data.end()) { - obj* obj = set->obj_data[elem_obj->second]; - if (index >= 0 && index < obj->num_mesh) - return &obj->mesh_array[index]; - } - return 0; + uint32_t size_vertex = get_vertex_size(mesh.vertex_format, mesh.attrib.m.compression); + mesh.size_vertex = size_vertex; + + uint32_t size = size_vertex * mesh.num_vertex; + vbhn.create(in_vb, size, offset); + offset += align_val_32(size); +} +#endif + +// 0x1404588F0 +bool create_objset_index_buffer(ObjsetInfo* info) { + obj_set* set = info->obj_set; + info->objib_num = set->obj_num; + info->objib = prj::MemoryManager::alloc(prj::MemCSystem, set->obj_num, "OBJIB"); + if (!info->objib) + return false; + +#if SHARED_OBJECT_BUFFER + for (int32_t i = 0; i < set->obj_num; i++) { + obj* obj = set->obj_data[i]; + ObjIB& objib = info->objib[i]; + + objib.num_ib = obj->num_mesh; + + IndexBuffer* ibhn_array = prj::MemoryManager::alloc(prj::MemCSystem, obj->num_mesh, "MESHIB"); + if (!ibhn_array) + return false; + + objib.ibhn_array = new (ibhn_array) IndexBuffer[obj->num_mesh]; } - auto elem_modern = objset_info_storage_data_modern.find(obj_info.set_id); - if (elem_modern != objset_info_storage_data_modern.end()) { - obj_set* set = elem_modern->second.obj_set; - if (!set) - return 0; + int32_t size = 0; + for (int32_t i = 0; i < set->obj_num; i++) + calc_object_index_buffer(set->obj_data[i], size); - auto elem_obj = elem_modern->second.obj_id_data.find(obj_info.id); - if (elem_obj != elem_modern->second.obj_id_data.end()) { - obj* obj = set->obj_data[elem_obj->second]; - if (index >= 0 && index < obj->num_mesh) - return &obj->mesh_array[index]; - } - return 0; + void* buf = prj::MemoryManager::alloc(prj::MemCTemp, size, "TMP_IDXBUF"); + memset(buf, 0, size); + if (!buf) + return false; + + int32_t fill_offset = 0; + for (int32_t i = 0; i < set->obj_num; i++) + fill_object_index_buffer(buf, set->obj_data[i], fill_offset); + + GLuint ib = 0; + if (fill_offset > 0) // size is bigger than filled buf + ib = create_index_buffer(fill_offset, buf); + info->ib = ib; + + if (buf) + prj::MemoryManager::free(prj::MemCTemp, buf); + + for (int32_t i = 0; i < set->obj_num; i++) { + obj* obj = set->obj_data[i]; + ObjIB& objib = info->objib[i]; + + objib.num_ib = obj->num_mesh; + for (int32_t j = 0; j < obj->num_mesh; j++) +#pragma warning(suppress: 6385) + objib.ibhn_array[j].create(ib); } - return 0; +#else + for (int32_t i = 0; i < set->obj_num; i++) + if (!create_object_index_buffer(&info->objib[i], set->obj_data[i])) + return false; +#endif + return true; } -inline obj_mesh* objset_info_storage_get_obj_mesh_by_object_hash(uint32_t hash, const char* mesh_name) { - for (auto& i : objset_info_storage_data) { - obj_set* set = i.second.obj_set; - if (!set) - continue; +// 0x1404589B0 +bool create_objset_vertex_buffer(ObjsetInfo* info) { + obj_set* set = info->obj_set; + info->objvb_num = set->obj_num; + info->objvb = prj::MemoryManager::alloc(prj::MemCSystem, set->obj_num, "OBJVB"); + if (!info->objvb) + return false; - for (int32_t j = 0; j < set->obj_num; j++) - if (set->obj_data[j]->hash == hash) - return set->obj_data[j]->get_obj_mesh(mesh_name); - } +#if SHARED_OBJECT_BUFFER + int32_t size = 0; + for (int32_t i = 0; i < set->obj_num; i++) + calc_object_vertex_buffer(set->obj_data[i], size); - for (auto& i : objset_info_storage_data_modern) { - obj_set* set = i.second.obj_set; - if (!set) - continue; + void* buf = prj::MemoryManager::alloc(prj::MemCTemp, size, "TMP_VTXBUF"); + memset(buf, 0, size); - for (int32_t j = 0; j < set->obj_num; j++) - if (set->obj_data[j]->hash == hash) - return set->obj_data[j]->get_obj_mesh(mesh_name); - } - return 0; + int32_t fill_offset = 0; + for (int32_t i = 0; i < set->obj_num; i++) + fill_object_vertex_buffer(buf, set->obj_data[i], fill_offset); + + GLuint vb = 0; + if (size > 0) + vb = create_vertex_buffer(size, buf); + info->vb = vb; + + if (buf) + prj::MemoryManager::free(prj::MemCTemp, buf); + + uint32_t offset = 0; + for (int32_t i = 0; i < set->obj_num; i++) + create_object_vertex_buffer(&info->objvb[i], set->obj_data[i], vb, offset); +#else + for (int32_t i = 0; i < set->obj_num; i++) + if (!info->objvb[i].load(set->obj_data[i])) + return false; +#endif + return true; } -inline obj_mesh* objset_info_storage_get_obj_mesh_by_object_hash_index(uint32_t hash, int32_t index) { - for (auto& i : objset_info_storage_data) { - obj_set* set = i.second.obj_set; - if (!set) - continue; +// 0x140459860 +inline bool find_objdata_index(ObjsetInfoObject& info_object, object_info obj_id) { + info_object.info = get_objset_info(obj_id.set_id); + if (!info_object.info) + return false; - for (int32_t j = 0; j < set->obj_num; j++) { - if (set->obj_data[j]->hash != hash) - continue; + auto elem = info_object.info->objdb_map.find(obj_id.id); + if (elem == info_object.info->objdb_map.end()) + return false; - obj* obj = set->obj_data[j]; - if (index >= 0 && index < obj->num_mesh) - return &obj->mesh_array[index]; - return 0; - } - } - - for (auto& i : objset_info_storage_data_modern) { - obj_set* set = i.second.obj_set; - if (!set) - continue; - - for (int32_t j = 0; j < set->obj_num; j++) { - if (set->obj_data[j]->hash != hash) - continue; - - obj* obj = set->obj_data[j]; - if (index >= 0 && index < obj->num_mesh) - return &obj->mesh_array[index]; - return 0; - } - } - return 0; + info_object.index = elem->second; + return true; } -inline int32_t objset_info_storage_get_obj_mesh_index(object_info obj_info, const char* mesh_name) { - auto elem = objset_info_storage_data.find(obj_info.set_id); - if (elem != objset_info_storage_data.end()) { - obj_set* set = elem->second.obj_set; - if (!set) - return -1; - - auto elem_obj = elem->second.obj_id_data.find(obj_info.id); - if (elem_obj != elem->second.obj_id_data.end()) - return set->obj_data[elem_obj->second]->get_obj_mesh_index(mesh_name); - return 0; +// 0x140459B40 +void free_objset_index_buffer(ObjsetInfo* info) { + if (info->objib) { + for (int32_t i = 0; i < info->objib_num; i++) + free_object_index_buffer(&info->objib[i]); + prj::MemoryManager::free(prj::MemCSystem, info->objib); } - auto elem_modern = objset_info_storage_data_modern.find(obj_info.set_id); - if (elem_modern != objset_info_storage_data_modern.end()) { - obj_set* set = elem_modern->second.obj_set; - if (!set) - return -1; + info->objib = 0; + info->objib_num = 0; - auto elem_obj = elem_modern->second.obj_id_data.find(obj_info.id); - if (elem_obj != elem_modern->second.obj_id_data.end()) - return set->obj_data[elem_obj->second]->get_obj_mesh_index(mesh_name); - return 0; - } - return -1; +#if SHARED_OBJECT_BUFFER + if (info->ib) + free_index_buffer(info->ib); + info->ib = 0; +#endif } -inline int32_t objset_info_storage_get_obj_mesh_index_by_hash(uint32_t hash, const char* mesh_name) { - for (auto& i : objset_info_storage_data) { - obj_set* set = i.second.obj_set; - if (!set) - continue; - - for (int32_t j = 0; j < set->obj_num; j++) - if (set->obj_data[j]->hash == hash) - return set->obj_data[j]->get_obj_mesh_index(mesh_name); +// 0x140459C70 +void free_objset_vertex_buffer(ObjsetInfo* info) { + if (info->objvb) { + for (int32_t i = 0; i < info->objvb_num; i++) + free_object_vertex_buffer(&info->objvb[i]); + prj::MemoryManager::free(prj::MemCSystem, info->objvb); } - for (auto& i : objset_info_storage_data_modern) { - obj_set* set = i.second.obj_set; - if (!set) - continue; + info->objvb = 0; + info->objvb_num = 0; - for (int32_t j = 0; j < set->obj_num; j++) - if (set->obj_data[j]->hash == hash) - return set->obj_data[j]->get_obj_mesh_index(mesh_name); - } - return -1; +#if SHARED_OBJECT_BUFFER + if (info->vb) + free_vertex_buffer(info->vb); + info->vb = 0; +#endif } -inline const char* objset_info_storage_get_obj_name(object_info obj_info) { - obj* obj = objset_info_storage_get_obj(obj_info); - if (obj) - return obj->name; - return 0; -} - -inline obj_set* objset_info_storage_get_obj_set(uint32_t set_id) { - auto elem = objset_info_storage_data.find(set_id); +// 0x140459EC0 +inline obj_set* get_obj_data_header(uint32_t objset_index) { + auto elem = objset_info_storage_data.find(objset_index); if (elem != objset_info_storage_data.end()) return elem->second.obj_set; - auto elem_modern = objset_info_storage_data_modern.find(set_id); + auto elem_modern = objset_info_storage_data_modern.find(objset_index); if (elem_modern != objset_info_storage_data_modern.end()) return elem_modern->second.obj_set; return 0; } -inline size_t objset_info_storage_get_obj_set_count() { - return objset_info_storage_data.size() + objset_info_storage_data_modern.size(); -} - -inline int32_t objset_info_storage_get_obj_storage_load_count(uint32_t set_id) { - auto elem = objset_info_storage_data.find(set_id); - if (elem != objset_info_storage_data.end()) - return elem->second.load_count; - - auto elem_modern = objset_info_storage_data_modern.find(set_id); - if (elem_modern != objset_info_storage_data_modern.end()) - return elem_modern->second.load_count; +// 0x14045A120 +inline obj_bounding_sphere* get_object_bsphere(object_info obj_id) { + obj* obj = get_object_header(obj_id); + if (obj) + return &obj->bounding_sphere; return 0; } -inline obj_skin* objset_info_storage_get_obj_skin(object_info obj_info) { - auto elem = objset_info_storage_data.find(obj_info.set_id); - if (elem != objset_info_storage_data.end()) { - obj_set* set = elem->second.obj_set; - if (!set) - return 0; - - auto elem_obj = elem->second.obj_id_data.find(obj_info.id); - if (elem_obj != elem->second.obj_id_data.end()) - return set->obj_data[elem_obj->second]->skin; - return 0; - } - - auto elem_modern = objset_info_storage_data_modern.find(obj_info.set_id); - if (elem_modern != objset_info_storage_data_modern.end()) { - obj_set* set = elem_modern->second.obj_set; - if (!set) - return 0; - - auto elem_obj = elem_modern->second.obj_id_data.find(obj_info.id); - if (elem_obj != elem_modern->second.obj_id_data.end()) - return set->obj_data[elem_obj->second]->skin; - return 0; +// 0x14045A140 +inline obj* get_object_header(object_info obj_id) { + ObjsetInfo* info = get_objset_info(obj_id.set_id); + if (info) { + obj_set* set = info->obj_set; + if (set) { + auto elem_obj = info->objdb_map.find(obj_id.id); + if (elem_obj != info->objdb_map.end()) + return set->obj_data[elem_obj->second]; + } } return 0; } -inline obj_skin_ex_data* objset_info_storage_get_obj_skin_ex_data(object_info obj_info) { - obj_skin* skin = objset_info_storage_get_obj_skin(obj_info); - if (skin) - return skin->ex_data; - return 0; -} - -inline obj_index_buffer* objset_info_storage_get_obj_index_buffers(uint32_t set_id) { - ObjsetInfo* info = objset_info_storage_get_objset_info(set_id); - if (info && info->objib) - return info->objib; - return 0; -} - -inline obj_mesh_index_buffer* objset_info_storage_get_obj_mesh_index_buffer(object_info obj_info) { - ObjsetInfo* info = objset_info_storage_get_objset_info(obj_info.set_id); +// 0x14045A250 +inline IndexBuffer* get_object_index_buffer(object_info obj_id) { + ObjsetInfo* info = get_objset_info(obj_id.set_id); if (info && info->obj_set && info->objib) { - auto elem = info->obj_id_data.find(obj_info.id); - if (elem != info->obj_id_data.end()) - return info->objib[elem->second].mesh_data; + auto elem = info->objdb_map.find(obj_id.id); + if (elem != info->objdb_map.end()) + return info->objib[elem->second].ibhn_array; } return 0; } -inline obj_vertex_buffer* objset_info_storage_get_obj_vertex_buffers(uint32_t set_id) { - ObjsetInfo* info = objset_info_storage_get_objset_info(set_id); - if (info && info->objvb) - return info->objvb; +// 0x14045A340 +inline const char* get_object_name(object_info obj_id) { + obj* obj = get_object_header(obj_id); + if (obj) + return obj->name; return 0; } -inline obj_mesh_vertex_buffer* objset_info_storage_get_obj_mesh_vertex_buffer(object_info obj_info) { - ObjsetInfo* info = objset_info_storage_get_objset_info(obj_info.set_id); - if (info && info->obj_set && info->objvb) { - auto elem = info->obj_id_data.find(obj_info.id); - if (elem != info->obj_id_data.end()) - return info->objvb[elem->second].mesh_data; - } - return 0; -} - -inline std::vector* objset_info_storage_get_obj_set_gentex(uint32_t set_id) { - ObjsetInfo* info = objset_info_storage_get_objset_info(set_id); - if (info) - return &info->gentex; - return 0; -} - -inline bool objset_info_storage_get_obj_set_loaded(uint32_t set_id) { - ObjsetInfo* info = objset_info_storage_get_objset_info(set_id); - if (info) - return info->obj_loaded && info->tex_loaded; - return false; -} - -inline uint32_t objset_info_storage_get_obj_set_obj_id(uint32_t set_id, int32_t obj_index) { - ObjsetInfo* info = objset_info_storage_get_objset_info(set_id); - if (!info) - return -1; - - obj_set* set = info->obj_set; - if (set && obj_index >= 0 && obj_index < set->obj_num) - return set->obj_data[obj_index]->id; - return -1; -} - -inline int32_t objset_info_storage_get_obj_set_obj_num(uint32_t set_id) { - obj_set* set = objset_info_storage_get_obj_set(set_id); +// 0x14045A3C0 +inline int32_t get_object_num(uint32_t objset_index) { + obj_set* set = get_obj_data_header(objset_index); if (set) return set->obj_num; return 0; } -inline uint32_t objset_info_storage_get_obj_set_tex_id(uint32_t set_id, int32_t tex_index) { - ObjsetInfo* info = objset_info_storage_get_objset_info(set_id); +// 0x14045A3E0 +inline obj_skin* get_object_skin(object_info obj_id) { + auto elem = objset_info_storage_data.find(obj_id.set_id); + if (elem != objset_info_storage_data.end()) { + obj_set* set = elem->second.obj_set; + if (!set) + return 0; + + auto elem_obj = elem->second.objdb_map.find(obj_id.id); + if (elem_obj != elem->second.objdb_map.end()) + return set->obj_data[elem_obj->second]->skin; + return 0; + } + + auto elem_modern = objset_info_storage_data_modern.find(obj_id.set_id); + if (elem_modern != objset_info_storage_data_modern.end()) { + obj_set* set = elem_modern->second.obj_set; + if (!set) + return 0; + + auto elem_obj = elem_modern->second.objdb_map.find(obj_id.id); + if (elem_obj != elem_modern->second.objdb_map.end()) + return set->obj_data[elem_obj->second]->skin; + return 0; + } + return 0; +} + +// 0x14045A460 +inline obj_skin_ex_data* get_object_skin_osage_header(object_info obj_id) { + obj_skin* skin = get_object_skin(obj_id); + if (skin) + return skin->ex_data; + return 0; +} + +// 0x14045A480 +inline VertexBuffer* get_object_vertex_buffer(object_info obj_id) { + ObjsetInfo* info = get_objset_info(obj_id.set_id); + if (info && info->obj_set && info->objvb) { + auto elem = info->objdb_map.find(obj_id.id); + if (elem != info->objdb_map.end()) + return info->objvb[elem->second].vbhn_array; + } + return 0; +} + +// 0x14045A750 +inline uint32_t get_objnum_idx2uid(uint32_t objset_index, int32_t obj_index, const object_database* obj_db) { + uint32_t set_id = obj_db->get_object_set_id(objset_index); + if (set_id != -1) { + ObjsetInfo* info = get_objset_info(set_id); + if (info) { + obj_set* set = info->obj_set; + if (set && obj_index >= 0 && obj_index < set->obj_num) + return set->obj_data[obj_index]->id; + } + } + return -1; +} + +// 0x14045A8F0 +inline GLuint get_objset_gen_textures_id(uint32_t objset_index, uint32_t uid) { + std::vector* gentex_vec = get_objset_gen_textures_vec(objset_index); + if (!gentex_vec) + return 0; + + ObjsetInfo* info = get_objset_info(objset_index); + if (!info) + return 0; + + auto elem = info->texidx_map.find(uid); + if (elem != info->texidx_map.end()) + return (*gentex_vec)[elem->second]; + return 0; +} + +// 0x14045A9E0 +inline std::vector* get_objset_gen_textures_vec(uint32_t objset_index) { + ObjsetInfo* info = get_objset_info(objset_index); + if (info) + return &info->gentex_vec; + return 0; +} + +// 0x14045AC00 +inline ObjsetInfo* get_objset_info(uint32_t objset_index) { + auto elem = objset_info_storage_data.find(objset_index); + if (elem != objset_info_storage_data.end()) + return &elem->second; + + auto elem_modern = objset_info_storage_data_modern.find(objset_index); + if (elem_modern != objset_info_storage_data_modern.end()) + return &elem_modern->second; + return 0; +} + +// 0x14045ADD0 +inline size_t get_objset_num() { + return objset_info_storage_data.size() + objset_info_storage_data_modern.size(); +} + +// 0x14045ADE0 +inline int32_t get_objset_num_textures(uint32_t objset_index) { + ObjsetInfo* info = get_objset_info(objset_index); + if (info) + return info->tex_num; + return 0; +} + +// 0x14045AE20 +inline texture** get_objset_textures(uint32_t objset_index) { + ObjsetInfo* info = get_objset_info(objset_index); + if (info) + return info->textures; + return 0; +} + +// 0x140459D90 +inline obj_mesh* get_mesh(object_info obj_id, const char* mesh_name) { + auto elem = objset_info_storage_data.find(obj_id.set_id); + if (elem != objset_info_storage_data.end()) { + obj_set* set = elem->second.obj_set; + if (!set) + return 0; + + auto elem_obj = elem->second.objdb_map.find(obj_id.id); + if (elem_obj != elem->second.objdb_map.end()) + return set->obj_data[elem_obj->second]->get_obj_mesh(mesh_name); + return 0; + } + + auto elem_modern = objset_info_storage_data_modern.find(obj_id.set_id); + if (elem_modern != objset_info_storage_data_modern.end()) { + obj_set* set = elem_modern->second.obj_set; + if (!set) + return 0; + + auto elem_obj = elem_modern->second.objdb_map.find(obj_id.id); + if (elem_obj != elem_modern->second.objdb_map.end()) + return set->obj_data[elem_obj->second]->get_obj_mesh(mesh_name); + return 0; + } + return 0; +} + +// 0x140459D40 +inline obj_mesh* get_mesh(object_info obj_id, int32_t mesh_index) { + auto elem = objset_info_storage_data.find(obj_id.set_id); + if (elem != objset_info_storage_data.end()) { + obj_set* set = elem->second.obj_set; + if (!set) + return 0; + + auto elem_obj = elem->second.objdb_map.find(obj_id.id); + if (elem_obj != elem->second.objdb_map.end()) { + obj* obj = set->obj_data[elem_obj->second]; + if (mesh_index >= 0 && mesh_index < obj->num_mesh) + return &obj->mesh_array[mesh_index]; + } + return 0; + } + + auto elem_modern = objset_info_storage_data_modern.find(obj_id.set_id); + if (elem_modern != objset_info_storage_data_modern.end()) { + obj_set* set = elem_modern->second.obj_set; + if (!set) + return 0; + + auto elem_obj = elem_modern->second.objdb_map.find(obj_id.id); + if (elem_obj != elem_modern->second.objdb_map.end()) { + obj* obj = set->obj_data[elem_obj->second]; + if (mesh_index >= 0 && mesh_index < obj->num_mesh) + return &obj->mesh_array[mesh_index]; + } + return 0; + } + return 0; +} + +// Added +inline obj_mesh* get_mesh_modern(uint32_t hash, const char* mesh_name) { + for (auto& i : objset_info_storage_data) { + obj_set* set = i.second.obj_set; + if (!set) + continue; + + for (int32_t j = 0; j < set->obj_num; j++) + if (set->obj_data[j]->hash == hash) + return set->obj_data[j]->get_obj_mesh(mesh_name); + } + + for (auto& i : objset_info_storage_data_modern) { + obj_set* set = i.second.obj_set; + if (!set) + continue; + + for (int32_t j = 0; j < set->obj_num; j++) + if (set->obj_data[j]->hash == hash) + return set->obj_data[j]->get_obj_mesh(mesh_name); + } + return 0; +} + +// Added +inline obj_mesh* get_mesh_modern(uint32_t hash, int32_t mesh_index) { + for (auto& i : objset_info_storage_data) { + obj_set* set = i.second.obj_set; + if (!set) + continue; + + for (int32_t j = 0; j < set->obj_num; j++) { + if (set->obj_data[j]->hash != hash) + continue; + + obj* obj = set->obj_data[j]; + if (mesh_index >= 0 && mesh_index < obj->num_mesh) + return &obj->mesh_array[mesh_index]; + return 0; + } + } + + for (auto& i : objset_info_storage_data_modern) { + obj_set* set = i.second.obj_set; + if (!set) + continue; + + for (int32_t j = 0; j < set->obj_num; j++) { + if (set->obj_data[j]->hash != hash) + continue; + + obj* obj = set->obj_data[j]; + if (mesh_index >= 0 && mesh_index < obj->num_mesh) + return &obj->mesh_array[mesh_index]; + return 0; + } + } + return 0; +} + +// 0x140459DE0 +inline int32_t get_mesh_index(object_info obj_id, const char* mesh_name) { + auto elem = objset_info_storage_data.find(obj_id.set_id); + if (elem != objset_info_storage_data.end()) { + obj_set* set = elem->second.obj_set; + if (!set) + return -1; + + auto elem_obj = elem->second.objdb_map.find(obj_id.id); + if (elem_obj != elem->second.objdb_map.end()) + return set->obj_data[elem_obj->second]->get_obj_mesh_index(mesh_name); + return 0; + } + + auto elem_modern = objset_info_storage_data_modern.find(obj_id.set_id); + if (elem_modern != objset_info_storage_data_modern.end()) { + obj_set* set = elem_modern->second.obj_set; + if (!set) + return -1; + + auto elem_obj = elem_modern->second.objdb_map.find(obj_id.id); + if (elem_obj != elem_modern->second.objdb_map.end()) + return set->obj_data[elem_obj->second]->get_obj_mesh_index(mesh_name); + return 0; + } + return -1; +} + +// Added +inline int32_t get_mesh_index_modern(uint32_t hash, const char* mesh_name) { + for (auto& i : objset_info_storage_data) { + obj_set* set = i.second.obj_set; + if (!set) + continue; + + for (int32_t j = 0; j < set->obj_num; j++) + if (set->obj_data[j]->hash == hash) + return set->obj_data[j]->get_obj_mesh_index(mesh_name); + } + + for (auto& i : objset_info_storage_data_modern) { + obj_set* set = i.second.obj_set; + if (!set) + continue; + + for (int32_t j = 0; j < set->obj_num; j++) + if (set->obj_data[j]->hash == hash) + return set->obj_data[j]->get_obj_mesh_index(mesh_name); + } + return -1; +} + +// 0x140459E10 +inline VertexBuffer* get_mesh_vertex_buffer(object_info obj_id, const char* mesh_name) { + int32_t mesh_index = get_mesh_index(obj_id, mesh_name); + if (mesh_index == -1) + return 0; + + ObjsetInfo* info = get_objset_info(obj_id.set_id); + if (!info) + return 0; + + auto elem_obj = info->objdb_map.find(obj_id.id); + if (elem_obj != info->objdb_map.end()) + return &info->objvb[elem_obj->second].vbhn_array[mesh_index]; + return 0; +} + +// 0x14045AFA0 +inline uint32_t get_texnum_idx2uid(uint32_t objset_index, int32_t tex_index) { + ObjsetInfo* info = get_objset_info(objset_index); if (!info) return -1; @@ -2062,85 +1951,18 @@ inline uint32_t objset_info_storage_get_obj_set_tex_id(uint32_t set_id, int32_t return -1; } -inline int32_t objset_info_storage_get_obj_set_tex_num(uint32_t set_id) { - ObjsetInfo* info = objset_info_storage_get_objset_info(set_id); - if (info) - return info->tex_num; - return 0; -} - -GLuint objset_info_storage_get_obj_set_texture(uint32_t set_id, uint32_t tex_id) { - std::vector* gentex = objset_info_storage_get_obj_set_gentex(set_id); - if (!gentex) - return 0; - - ObjsetInfo* info = objset_info_storage_get_objset_info(set_id); - if (!info) - return 0; - - auto elem = info->tex_id_data.find(tex_id); - if (elem != info->tex_id_data.end()) - return (*gentex)[elem->second]; - return 0; -} - -inline texture** objset_info_storage_get_obj_set_textures(uint32_t set_id) { - ObjsetInfo* info = objset_info_storage_get_objset_info(set_id); - if (info) - return info->tex_data; - return 0; -} - -int32_t objset_info_storage_load_set(void* data, const object_database* obj_db, const char* name) { - const object_set_info* set_info = obj_db->get_object_set_info(name); +// 0x14045C6A0 +int32_t request_objset(void* data, const object_database* obj_db, uint32_t objset_index) { + const object_set_info* set_info = obj_db->get_object_set_info(objset_index); if (!set_info) return 1; - ObjsetInfo* info = objset_info_storage_get_objset_info(set_info->id); + ObjsetInfo* info = get_objset_info(objset_index); if (!info) return 1; - if (info->load_count > 0) { - info->load_count++; - return 1; - } - - const std::string& archive_file_name = set_info->archive_file_name; - const std::string& object_file_name = set_info->object_file_name; - const std::string& texture_file_name = set_info->texture_file_name; - if (!object_file_name.size() || !texture_file_name.size()) - return 1; - - if (archive_file_name.size()) { - info->obj_file_handler.read_file(data, "rom/objset/", - archive_file_name.c_str(), object_file_name.c_str(), prj::MemCSystem, false); - info->tex_file_handler.read_file(data, "rom/objset/", - archive_file_name.c_str(), texture_file_name.c_str(), prj::MemCSystem, false); - } - else { - info->obj_file_handler.read_file(data, - "rom/objset/", object_file_name.c_str(), prj::MemCSystem); - info->tex_file_handler.read_file(data, - "rom/objset/", texture_file_name.c_str(), prj::MemCSystem); - } - - info->load_count = 1; - info->obj_loaded = false; - info->tex_loaded = false; - return 0; -} - -int32_t objset_info_storage_load_set(void* data, const object_database* obj_db, uint32_t set_id) { - const object_set_info* set_info = obj_db->get_object_set_info(set_id); - if (!set_info) - return 1; - - ObjsetInfo* info = objset_info_storage_get_objset_info(set_id); - if (!info) - return 1; - - if (info->load_count > 0) { - info->load_count++; + if (info->req_cnt > 0) { + info->req_cnt++; return 1; } @@ -2165,13 +1987,54 @@ int32_t objset_info_storage_load_set(void* data, const object_database* obj_db, "rom/objset/", texture_file_name.c_str(), prj::MemCSystem); } - info->load_count = 1; - info->obj_loaded = false; - info->tex_loaded = false; + info->req_cnt = 1; + info->obj_ready = false; + info->tex_ready = false; return 0; } -int32_t objset_info_storage_load_set_hash(void* data, uint32_t hash) { +// Added +int32_t request_objset(void* data, const object_database* obj_db, const char* name) { + const object_set_info* set_info = obj_db->get_object_set_info(name); + if (!set_info) + return 1; + + ObjsetInfo* info = get_objset_info(set_info->id); + if (!info) + return 1; + + if (info->req_cnt > 0) { + info->req_cnt++; + return 1; + } + + const std::string& archive_file_name = set_info->archive_file_name; + const std::string& object_file_name = set_info->object_file_name; + const std::string& texture_file_name = set_info->texture_file_name; + if (!object_file_name.size() || !texture_file_name.size()) + return 1; + + if (archive_file_name.size()) { + info->obj_file_handler.read_file(data, "rom/objset/", + archive_file_name.c_str(), object_file_name.c_str(), prj::MemCSystem, false); + info->tex_file_handler.read_file(data, "rom/objset/", + archive_file_name.c_str(), texture_file_name.c_str(), prj::MemCSystem, false); + } + else { + info->obj_file_handler.read_file(data, + "rom/objset/", object_file_name.c_str(), prj::MemCSystem); + info->tex_file_handler.read_file(data, + "rom/objset/", texture_file_name.c_str(), prj::MemCSystem); + } + + info->req_cnt = 1; + info->obj_ready = false; + info->tex_ready = false; + return 0; +} + +// Added +int32_t request_objset_modern(void* data, uint32_t hash) { if (!hash || hash == hash_murmurhash_empty) return 1; @@ -2179,14 +2042,14 @@ int32_t objset_info_storage_load_set_hash(void* data, uint32_t hash) { if (!((data_struct*)data)->get_file("root+/objset/", hash, ".farc", file)) return 1; - ObjsetInfo* info = objset_info_storage_get_objset_info(hash); + ObjsetInfo* info = get_objset_info(hash); if (!info) { info = &objset_info_storage_data_modern.insert({ hash, {} }).first->second; - info->set_id = hash; + info->id = hash; } - if (info->load_count > 0) { - info->load_count++; + if (info->req_cnt > 0) { + info->req_cnt++; return 1; } @@ -2194,20 +2057,20 @@ int32_t objset_info_storage_load_set_hash(void* data, uint32_t hash) { info->farc_file_handler.read_file(data, "root+/objset/", file.c_str(), prj::MemCSystem); - info->load_count = 1; - info->obj_loaded = false; - info->tex_loaded = false; + info->req_cnt = 1; + info->obj_ready = false; + info->tex_ready = false; return 0; } -bool objset_info_storage_load_obj_set_check_not_read(uint32_t set_id, - object_database* obj_db, texture_database* tex_db) { - ObjsetInfo* info = objset_info_storage_get_objset_info(set_id); +// 0x14045DA60 +bool wait_objset(uint32_t objset_index, object_database* obj_db, texture_database* tex_db) { + ObjsetInfo* info = get_objset_info(objset_index); if (!info) return true; if (!info->modern) { - if (!info->obj_loaded && !info->obj_file_handler.check_not_ready()) { + if (!info->obj_ready && !info->obj_file_handler.check_not_ready()) { const void* data = info->obj_file_handler.get_data(); size_t size = info->obj_file_handler.get_size(); if (!data || !size) @@ -2223,36 +2086,31 @@ bool objset_info_storage_load_obj_set_check_not_read(uint32_t set_id, return false; info->obj_file_handler.reset(); - info->obj_id_data.reserve(set->obj_num); - for (int32_t i = 0; i < set->obj_num; i++) - info->obj_id_data.push_back(set->obj_data[i]->id, i); - info->obj_id_data.sort(); + make_objdata_indirect_table(info); - if (!ObjsetInfo_vertex_buffer_load(info) - || !ObjsetInfo_index_buffer_load(info)) + if (!create_objset_vertex_buffer(info) + || !create_objset_index_buffer(info)) return false; - ObjsetInfo_vertex_array_load(info); - ObjsetInfo_calc_axis_aligned_bounding_box(info); - info->obj_loaded = true; + create_objset_aabb(info); + load_objset_vertex_array(info); + info->obj_ready = true; } - if (!info->obj_loaded) + if (!info->obj_ready) return true; - if (!info->tex_loaded && !info->tex_file_handler.check_not_ready()) { - if (!info->tex_file_handler.get_data()) - return false; - else if (ObjsetInfo_load_textures(info, - info->tex_file_handler.get_data(), false)) + if (!info->tex_ready && !info->tex_file_handler.check_not_ready()) { + if (!info->tex_file_handler.get_data() + || load_objset_texture(info, info->tex_file_handler.get_data())) return false; - ObjsetInfo_get_shader_index_texture_index(info); + convert_objdata_tex_index(info); info->tex_file_handler.reset(); - info->tex_loaded = true; + info->tex_ready = true; } } - else if (!info->obj_loaded && !info->farc_file_handler.check_not_ready()) { + else if (!info->obj_ready && !info->farc_file_handler.check_not_ready()) { const void* data = info->farc_file_handler.get_data(); size_t size = info->farc_file_handler.get_size(); if (!data || !size) @@ -2305,7 +2163,7 @@ bool objset_info_storage_load_obj_set_check_not_read(uint32_t set_id, object_set_info_file* set_info_file = 0; if (obj_db_file.ready) for (object_set_info_file& m : obj_db_file.object_set) - if (m.id == info->set_id) { + if (m.id == info->id) { set_info_file = &m; break; } @@ -2337,285 +2195,163 @@ bool objset_info_storage_load_obj_set_check_not_read(uint32_t set_id, object_material_msgpack_read("patch\\AFT\\objset", file.c_str(), set); info->obj_file_handler.reset(); - info->obj_id_data.reserve(set->obj_num); - for (int32_t i = 0; i < set->obj_num; i++) - info->obj_id_data.push_back(set->obj_data[i]->id, i); - info->obj_id_data.sort(); + make_objdata_indirect_table(info); - if (!ObjsetInfo_vertex_buffer_load(info) - || !ObjsetInfo_index_buffer_load(info)) + if (!create_objset_vertex_buffer(info) + || !create_objset_index_buffer(info)) return false; - ObjsetInfo_vertex_array_load(info); - ObjsetInfo_calc_axis_aligned_bounding_box(info); - info->obj_loaded = true; + create_objset_aabb(info); + load_objset_vertex_array(info); + info->obj_ready = true; - if (ObjsetInfo_load_textures_modern(info, txd->data, txd->size, file.c_str(), tex_db)) + if (load_objset_texture_modern(info, txd->data, txd->size, file.c_str(), tex_db)) return false; - ObjsetInfo_get_shader_index_texture_index(info); - info->tex_loaded = true; + convert_objdata_tex_index(info); + info->tex_ready = true; info->farc_file_handler.reset(); } - if (info->obj_loaded && info->tex_loaded) + if (info->obj_ready && info->tex_ready) return false; return true; } -inline void objset_info_storage_unload_set(const object_database* obj_db, const char* name) { - const object_set_info* set_info = obj_db->get_object_set_info(name); - if (!set_info) +// 0x1404599B0 +inline void free_objset(uint32_t objset_index) { + ObjsetInfo* info = get_objset_info(objset_index); + if (!info || info->req_cnt <= 0) return; - ObjsetInfo* info = objset_info_storage_get_objset_info(set_info->id); - if (!info || info->load_count <= 0) + if (--info->req_cnt > 0) return; - if (--info->load_count > 0) - return; + free_objdata_indirect_table(info); + free_objset_texture(info); + free_objset_index_buffer(info); + free_objset_vertex_buffer(info); - info->obj_id_data.clear(); - info->tex_id_data.clear(); - info->gentex.clear(); - - texture_array_free(info->tex_data); - info->tex_data = 0; - info->tex_num = 0; - - ObjsetInfo_index_buffer_free(info); - ObjsetInfo_vertex_buffer_free(info); - info->load_count = 0; - info->tex_loaded = false; - info->obj_loaded = false; - info->alloc_handler.reset(); - info->obj_set = 0; - info->tex_file_handler.reset(); - info->obj_file_handler.reset(); - info->farc_file_handler.reset(); -} - -inline void objset_info_storage_unload_set(uint32_t set_id) { - ObjsetInfo* info = objset_info_storage_get_objset_info(set_id); - if (!info || info->load_count <= 0) - return; - - if (--info->load_count > 0) - return; - - info->obj_id_data.clear(); - info->tex_id_data.clear(); - info->gentex.clear(); - - texture_array_free(info->tex_data); - info->tex_data = 0; - info->tex_num = 0; - - ObjsetInfo_index_buffer_free(info); - ObjsetInfo_vertex_buffer_free(info); - info->load_count = 0; - info->tex_loaded = false; - info->obj_loaded = false; + info->req_cnt = 0; + info->tex_ready = false; + info->obj_ready = false; info->alloc_handler.reset(); info->obj_set = 0; info->tex_file_handler.reset(); info->obj_file_handler.reset(); info->farc_file_handler.reset(); if (info->modern) - objset_info_storage_data_modern.erase(set_id); + objset_info_storage_data_modern.erase(objset_index); } -inline void objset_info_storage_free() { - objset_info_storage_data.clear(); - objset_info_storage_data_modern.clear(); -} - -static GLuint create_index_buffer(size_t size, const void* data) { - GLuint buffer = 0; - glGenBuffers(1, &buffer); - gl_state.bind_element_array_buffer(buffer); - if (GLAD_GL_VERSION_4_4) - glBufferStorage(GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)size, data, 0); - else - glBufferData(GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)size, data, GL_STATIC_DRAW); - gl_state.bind_element_array_buffer(0); - - if (glGetError()) { - glDeleteBuffers(1, &buffer); - return 0; - } - - bufobj_mgr.ib_all_size += (int32_t)size; - bufobj_mgr.ib_peak_size = max_def(bufobj_mgr.ib_peak_size, bufobj_mgr.ib_all_size); - return buffer; -} - -static GLuint create_vertex_buffer(size_t size, const void* data, GL::BufferUsage usage) { - GLuint buffer = 0; - glGenBuffers(1, &buffer); - gl_state.bind_array_buffer(buffer); - if (GLAD_GL_VERSION_4_4 && usage != GL::BUFFER_USAGE_STREAM) { - GLbitfield flags = usage == GL::BUFFER_USAGE_DYNAMIC - ? GL_DYNAMIC_STORAGE_BIT | GL_MAP_WRITE_BIT : 0; - glBufferStorage(GL_ARRAY_BUFFER, (GLsizeiptr)size, data, flags); - } - else - glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)size, data, BufferUsageToGLenum(usage)); - gl_state.bind_array_buffer(0); - - if (glGetError()) { - glDeleteBuffers(1, &buffer); - return 0; - } - - bufobj_mgr.vb_all_size += (int32_t)size; - bufobj_mgr.vb_peak_size = max_def(bufobj_mgr.vb_peak_size, bufobj_mgr.vb_all_size); - return buffer; -} - -static void free_index_buffer(GLuint buffer) { - if (!buffer) +// Added +inline void free_objset(const object_database* obj_db, const char* name) { + const object_set_info* set_info = obj_db->get_object_set_info(name); + if (!set_info) return; - extern render_context* rctx_ptr; - rctx_ptr->disp_manager->remove_index_buffer(buffer); - - GLint size = 0; - if (GLAD_GL_VERSION_4_5) - glGetNamedBufferParameteriv(buffer, GL_BUFFER_SIZE, &size); - else { - gl_state.bind_element_array_buffer(buffer); - glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &size); - gl_state.bind_element_array_buffer(0); - } - - bufobj_mgr.ib_all_size -= size; - - glDeleteBuffers(1, &buffer); - glGetError(); -} - -static void free_vertex_buffer(GLuint buffer) { - if (!buffer) + ObjsetInfo* info = get_objset_info(set_info->id); + if (!info || info->req_cnt <= 0) return; - extern render_context* rctx_ptr; - rctx_ptr->disp_manager->remove_vertex_buffer(buffer); + if (--info->req_cnt > 0) + return; - GLint size = 0; - if (GLAD_GL_VERSION_4_5) - glGetNamedBufferParameteriv(buffer, GL_BUFFER_SIZE, &size); - else { - gl_state.bind_array_buffer(buffer); - glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, &size); - gl_state.bind_array_buffer(0); - } + free_objdata_indirect_table(info); + free_objset_texture(info); + free_objset_index_buffer(info); + free_objset_vertex_buffer(info); - bufobj_mgr.vb_all_size -= size; - - glDeleteBuffers(1, &buffer); - glGetError(); + info->req_cnt = 0; + info->tex_ready = false; + info->obj_ready = false; + info->alloc_handler.reset(); + info->obj_set = 0; + info->tex_file_handler.reset(); + info->obj_file_handler.reset(); + info->farc_file_handler.reset(); } -static int32_t remove_degenerate_triangle_indices( - uint32_t* dst_index_array, const int32_t num_index, uint32_t* src_index_array) { - if (!num_index) - return 0; - - dst_index_array[0] = src_index_array[0]; - - int32_t src_index = 1; - int32_t dst_index = 1; - int32_t strip_length = 1; - while (src_index < num_index - 4) - if (src_index_array[src_index] != src_index_array[src_index + 1]) { - dst_index_array[dst_index++] = src_index_array[src_index]; - strip_length++; - src_index++; - } - else if (src_index_array[src_index + 3] == src_index_array[src_index + 4]) { - dst_index_array[dst_index++] = src_index_array[src_index]; - dst_index_array[dst_index++] = 0xFFFFFFFF; - dst_index_array[dst_index++] = src_index_array[src_index + 4]; - - if (strip_length % 2) { - dst_index_array[dst_index++] = src_index_array[src_index + 4]; - strip_length = 0; - } - else - strip_length = 1; - src_index += 5; - } - else if (src_index_array[src_index - 1] != src_index_array[src_index + 2] - || src_index_array[src_index + 1] != src_index_array[src_index + 4]) { - dst_index_array[dst_index++] = src_index_array[src_index]; - dst_index_array[dst_index++] = 0xFFFFFFFF; - dst_index_array[dst_index++] = src_index_array[src_index + 3]; - - if (!(strip_length % 2)) { - dst_index_array[dst_index++] = src_index_array[src_index + 3]; - strip_length = 0; - } - else - strip_length = 1; - src_index += 4; - } - else { - dst_index_array[dst_index++] = src_index_array[src_index]; - strip_length++; - src_index += 5; - } - - if (src_index < num_index) { - src_index_array += src_index; - dst_index_array += dst_index; - dst_index += num_index - src_index; - while (src_index++ < num_index) - *dst_index_array++ = *src_index_array++; - } - return dst_index; +// Added +static int32_t align_val_32(int32_t value) { + return value + (32 - value % 32) % 32; } -static void ObjsetInfo_calc_axis_aligned_bounding_box(ObjsetInfo* info) { +// 0x140457260 +static void calc_aabb(obj_axis_aligned_bounding_box& aabb, obj_mesh& mesh, obj_sub_mesh& sub_mesh) { + vec3 _min = 9999999.0f; + vec3 _max = -100000000.0f; + + uint32_t* index = sub_mesh.index_array; + int32_t num_index = sub_mesh.num_index; + obj_vertex_data* vertex_array = mesh.vertex_array; + if (sub_mesh.index_format == OBJ_INDEX_U16) + for (int32_t i = 0; i < num_index; i++, index++) { + if (*index == 0xFFFFFFFF) + continue; + + vec3 pos = vertex_array[*index].position; + _min = vec3::min(_min, pos); + _max = vec3::max(_max, pos); + } + else + for (int32_t l = 0; l < num_index; l++, index++) { + vec3 pos = vertex_array[*index].position; + _min = vec3::min(_min, pos); + _max = vec3::max(_max, pos); + } + + vec3 center = (_max + _min) * 0.5f; + vec3 size = _max - center; + aabb.center = center; + aabb.size = size; +} + +#if SHARED_OBJECT_BUFFER +// Added +inline static void calc_index_buffer(obj_sub_mesh& sub_mesh, int32_t& size) { + if (sub_mesh.index_format == OBJ_INDEX_U16) { + int32_t _size = sizeof(uint16_t) * sub_mesh.num_index; + size += align_val_32(_size); + } +} + +// Added +inline static void calc_mesh_index_buffer(obj_mesh& mesh, int32_t& size) { + for (int32_t i = 0; i < mesh.num_submesh; i++) + calc_index_buffer(mesh.submesh_array[i], size); +} + +// Added +inline static int32_t calc_mesh_vertex_buffer(obj_mesh& mesh) { + uint32_t vertex_size = get_vertex_size(mesh.vertex_format); + return mesh.num_vertex * vertex_size; +} + +// Added +inline static void calc_object_index_buffer(obj* obj, int32_t& size) { + for (int32_t i = 0; i < obj->num_mesh; i++) + calc_mesh_index_buffer(obj->mesh_array[i], size); +} + +// Added +inline static void calc_object_vertex_buffer(obj* obj, int32_t& size) { + for (int32_t i = 0; i < obj->num_mesh; i++) { + int32_t _size = calc_mesh_vertex_buffer(obj->mesh_array[i]); + size += align_val_32(_size); + } +} +#endif + +// 0x140457E40 +static void convert_objdata_tex_index(ObjsetInfo* info) { obj_set* set = info->obj_set; - for (int32_t i = 0; i < set->obj_num; i++) { - obj* obj = set->obj_data[i]; - for (int32_t j = 0; j < obj->num_mesh; j++) { - obj_mesh& mesh = obj->mesh_array[j]; - for (int32_t k = 0; k < mesh.num_submesh; k++) { - vec3 _min = 9999999.0f; - vec3 _max = -100000000.0f; - - obj_sub_mesh& sub_mesh = mesh.submesh_array[k]; - uint32_t* index = sub_mesh.index_array; - int32_t num_index = sub_mesh.num_index; - obj_vertex_data* vertex_array = mesh.vertex_array; - if (sub_mesh.index_format == OBJ_INDEX_U16) - for (int32_t l = 0; l < num_index; l++, index++) { - if (*index == 0xFFFFFFFF) - continue; - - vec3 pos = vertex_array[*index].position; - _min = vec3::min(_min, pos); - _max = vec3::max(_max, pos); - } - else - for (int32_t l = 0; l < num_index; l++, index++) { - vec3 pos = vertex_array[*index].position; - _min = vec3::min(_min, pos); - _max = vec3::max(_max, pos); - } - - vec3 center = (_max + _min) * 0.5f; - vec3 size = _max - center; - sub_mesh.axis_aligned_bounding_box.center = center; - sub_mesh.axis_aligned_bounding_box.size = size; - } - } - } + for (int32_t i = 0; i < set->obj_num; i++) + convert_objdata_tex_index_internal(info, set->obj_data[i]); } -static void ObjsetInfo_get_obj_shader_index_texture_index(ObjsetInfo* info, obj* obj) { +// 0x140457EA0 +static void convert_objdata_tex_index_internal(ObjsetInfo* info, obj* obj) { int32_t num_material = obj->num_material; for (int32_t i = 0; i < num_material; i++) { obj_material_data& material_data = obj->material_array[i]; @@ -2635,8 +2371,8 @@ static void ObjsetInfo_get_obj_shader_index_texture_index(ObjsetInfo* info, obj* texture.tex_index = -1; texture.texture_index = 0; - auto elem = info->tex_id_data.find(tex_index); - if (elem != info->tex_id_data.end()) { + auto elem = info->texidx_map.find(tex_index); + if (elem != info->texidx_map.end()) { texture.tex_index = tex_index; texture.texture_index = elem->second; } @@ -2644,37 +2380,385 @@ static void ObjsetInfo_get_obj_shader_index_texture_index(ObjsetInfo* info, obj* } } -static void ObjsetInfo_get_shader_index_texture_index(ObjsetInfo* info) { - obj_set* set = info->obj_set; - for (int32_t i = 0; i < set->obj_num; i++) - ObjsetInfo_get_obj_shader_index_texture_index(info, set->obj_data[i]); +// 0x140457FC0 +static void create_mesh_aabb(obj_mesh& mesh) { + for (int32_t i = 0; i < mesh.num_submesh; i++) + calc_aabb(mesh.submesh_array[i].axis_aligned_bounding_box, mesh, mesh.submesh_array[i]); } -static bool ObjsetInfo_index_buffer_load(ObjsetInfo* info) { - obj_set* set = info->obj_set; - info->objib_num = set->obj_num; - info->objib = prj::MemoryManager::alloc(prj::MemCSystem, set->obj_num, "OBJIB"); - if (!info->objib) - return true; +// 0x140458690 +static void create_object_aabb(obj* obj) { + for (int32_t i = 0; i < obj->num_mesh; i++) + create_mesh_aabb(obj->mesh_array[i]); +} - for (int32_t i = 0; i < set->obj_num; i++) - if (!info->objib[i].load(set->obj_data[i])) +// 0x1404586E0 +static bool create_object_index_buffer(ObjIB* objib, obj* obj) { + if (!obj) + return false; + + objib->num_ib = obj->num_mesh; + objib->ibhn_array = prj::MemoryManager::alloc(prj::MemCSystem, obj->num_mesh, "MESHIB"); + if (!objib->ibhn_array) + return false; + + for (int32_t i = 0; i < objib->num_ib; i++) + if (!create_mesh_index_buffer(objib->ibhn_array[i], obj->mesh_array[i])) return false; return true; } -static void ObjsetInfo_index_buffer_free(ObjsetInfo* info) { - if (info->objib) { - for (int32_t i = 0; i < info->objib_num; i++) - info->objib[i].unload(); - prj::MemoryManager::free(prj::MemCSystem, info->objib); - } +// 0x140458790 +static bool create_object_vertex_buffer(ObjVB* objvb, obj* obj) { + if (!obj) + return false; - info->objib = 0; - info->objib_num = 0; + objvb->num_vb = obj->num_mesh; + objvb->vbhn_array = new VertexBuffer[obj->num_mesh]; + if (!objvb->vbhn_array) + return false; + + for (int32_t i = 0; i < objvb->num_vb; i++) + if (!create_mesh_vertex_buffer(objvb->vbhn_array[i], obj->mesh_array[i])) + return false; + return true; } -static bool ObjsetInfo_load_textures(ObjsetInfo* info, const void* data, bool big_endian) { +#if SHARED_OBJECT_BUFFER +// Added +inline static bool create_object_vertex_buffer(ObjVB* objvb, obj* obj, GLuint in_vb, uint32_t& offset) { + if (!obj) + return false; + + objvb->num_vb = obj->num_mesh; + objvb->vbhn_array = new VertexBuffer[obj->num_mesh]; + if (!objvb->vbhn_array) + return false; + + for (int32_t i = 0; i < obj->num_mesh; i++) + create_mesh_vertex_buffer(objvb->vbhn_array[i], obj->mesh_array[i], in_vb, offset); + return true; +} +#endif + +// 0x1404588A0 +static void create_objset_aabb(ObjsetInfo* info) { + obj_set* set = info->obj_set; + for (int32_t i = 0; i < set->obj_num; i++) + create_object_aabb(set->obj_data[i]); +} + +// Added +inline static void fill_index_buffer(void* buf, obj_sub_mesh& sub_mesh, int32_t& offset) { + if (sub_mesh.primitive_type == OBJ_PRIMITIVE_TRIANGLE_STRIP && !sub_mesh.attrib.m.use_restart_index) { + uint32_t* index_array = prj::MemoryManager::alloc(prj::MemCTemp, sub_mesh.num_index, "NEW INDICES"); + sub_mesh.num_index = rewrite_to_restart_index( + index_array, sub_mesh.num_index, sub_mesh.index_array); + memmove(sub_mesh.index_array, index_array, sizeof(uint32_t) * sub_mesh.num_index); + prj::MemoryManager::free(prj::MemCTemp, index_array); + } + + sub_mesh.min_index = 0; + sub_mesh.max_index = 0; + sub_mesh.index_offset = 0; + if (sub_mesh.index_format != OBJ_INDEX_U16) + return; + + const uint32_t* index = sub_mesh.index_array; + uint16_t* indices = (uint16_t*)buf; + for (int32_t j = sub_mesh.num_index; j > 0; j--, index++) + *indices++ = (uint16_t)*index; + + uint16_t min_index = 0xFFFF; + uint16_t max_index = 0; + indices = (uint16_t*)buf; + for (int32_t j = sub_mesh.num_index; j > 0; j--) { + uint16_t index = *indices++; + if (index == 0xFFFF) + continue; + + if (min_index > index) + min_index = index; + if (max_index < index) + max_index = index; + } + + sub_mesh.min_index = min_index; + sub_mesh.max_index = max_index; + sub_mesh.index_offset = offset; + + int32_t size = sizeof(uint16_t) * sub_mesh.num_index; + offset += align_val_32(size); +} + +// Added +static void fill_mesh_index_buffer(void* buf, obj_mesh& mesh, int32_t& offset) { + for (int32_t i = 0; i < mesh.num_submesh; i++) + fill_index_buffer((uint8_t*)buf + offset, mesh.submesh_array[i], offset); +} + +// Added +static int32_t fill_mesh_vertex_buffer(void* buf, obj_mesh& mesh) { + uint32_t size_vertex = get_vertex_size(mesh.vertex_format, mesh.attrib.m.compression); + obj_vertex_format vertex_format = mesh.vertex_format; + obj_vertex_data* vtx = mesh.vertex_array; + int32_t num_vertex = mesh.num_vertex; + size_t d = (size_t)buf; + switch (mesh.attrib.m.compression) { + case 0: + default: + for (int32_t i = num_vertex; i > 0; i--, vtx++) { + if (vertex_format & OBJ_VERTEX_POSITION) { + *(vec3*)d = vtx->position; + d += 12; + } + + if (vertex_format & OBJ_VERTEX_NORMAL) { + *(vec3*)d = vtx->normal; + d += 12; + } + + if (vertex_format & OBJ_VERTEX_TANGENT) { + *(vec4*)d = vtx->tangent; + d += 16; + } + + if (vertex_format & OBJ_VERTEX_BINORMAL) { + *(vec3*)d = vtx->binormal; + d += 12; + } + + if (vertex_format & OBJ_VERTEX_TEXCOORD0) { + *(vec2*)d = vtx->texcoord0; + d += 8; + } + + if (vertex_format & OBJ_VERTEX_TEXCOORD1) { + *(vec2*)d = vtx->texcoord1; + d += 8; + } + + if (vertex_format & OBJ_VERTEX_TEXCOORD2) { + *(vec2*)d = vtx->texcoord2; + d += 8; + } + + if (vertex_format & OBJ_VERTEX_TEXCOORD3) { + *(vec2*)d = vtx->texcoord3; + d += 8; + } + + if (vertex_format & OBJ_VERTEX_COLOR0) { + *(vec4*)d = vtx->color0; + d += 16; + } + + if (vertex_format & OBJ_VERTEX_COLOR1) { + *(vec4*)d = vtx->color1; + d += 16; + } + + if (vertex_format & OBJ_VERTEX_BONE_DATA) { + *(vec4*)d = vtx->bone_weight; + d += 16; + *(vec4i16*)d = vtx->bone_index; + d += 8; + } + + if (vertex_format & OBJ_VERTEX_UNKNOWN) { + *(vec4*)d = vtx->unknown; + d += 16; + } + } + break; + case 1: + for (int32_t i = num_vertex; i > 0; i--, vtx++) { + if (vertex_format & OBJ_VERTEX_POSITION) { + *(vec3*)d = vtx->position; + d += 12; + } + + if (vertex_format & OBJ_VERTEX_NORMAL) { + vec3_to_vec3i16(vtx->normal * 32767.0f, *(vec3i16*)d); + *(int16_t*)(d + 6) = 0; + d += 8; + } + + if (vertex_format & OBJ_VERTEX_TANGENT) { + vec4_to_vec4i16(vtx->tangent * 32767.0f, *(vec4i16*)d); + d += 8; + } + + if (vertex_format & OBJ_VERTEX_TEXCOORD0) { + vec2_to_vec2h(vtx->texcoord0, *(vec2h*)d); + d += 4; + } + + if (vertex_format & OBJ_VERTEX_TEXCOORD1) { + vec2_to_vec2h(vtx->texcoord1, *(vec2h*)d); + d += 4; + } + + if (vertex_format & OBJ_VERTEX_TEXCOORD2) { + vec2_to_vec2h(vtx->texcoord2, *(vec2h*)d); + d += 4; + } + + if (vertex_format & OBJ_VERTEX_TEXCOORD3) { + vec2_to_vec2h(vtx->texcoord3, *(vec2h*)d); + d += 4; + } + + if (vertex_format & OBJ_VERTEX_COLOR0) { + vec4_to_vec4h(vtx->color0, *(vec4h*)d); + d += 8; + } + + if (vertex_format & OBJ_VERTEX_BONE_DATA) { + vec4_to_vec4u16(vtx->bone_weight * 65535.0f, *(vec4u16*)d); + d += 8; + + *(vec4i16*)d = vtx->bone_index; + d += 8; + } + } + break; + case 2: + for (int32_t i = num_vertex; i > 0; i--, vtx++) { + if (vertex_format & OBJ_VERTEX_POSITION) { + *(vec3*)d = vtx->position; + d += 12; + } + + if (vertex_format & OBJ_VERTEX_NORMAL) { + vec3i16 normal_int; + vec3_to_vec3i16(vtx->normal * 511.0f, normal_int); + *(uint32_t*)d = (((uint32_t)0 & 0x03) << 30) + | (((uint32_t)normal_int.z & 0x3FF) << 20) + | (((uint32_t)normal_int.y & 0x3FF) << 10) + | ((uint32_t)normal_int.x & 0x3FF); + d += 4; + } + + if (vertex_format & OBJ_VERTEX_TANGENT) { + vec4i16 tangent_int; + vec4_to_vec4i16(vtx->tangent * 511.0f, tangent_int); + *(uint32_t*)d = (((uint32_t)clamp_def(tangent_int.w, -1, 1) & 0x03) << 30) + | (((uint32_t)tangent_int.z & 0x3FF) << 20) + | (((uint32_t)tangent_int.y & 0x3FF) << 10) + | ((uint32_t)tangent_int.x & 0x3FF); + d += 4; + } + + if (vertex_format & OBJ_VERTEX_TEXCOORD0) { + vec2_to_vec2h(vtx->texcoord0, *(vec2h*)d); + d += 4; + } + + if (vertex_format & OBJ_VERTEX_TEXCOORD1) { + vec2_to_vec2h(vtx->texcoord1, *(vec2h*)d); + d += 4; + } + + if (vertex_format & OBJ_VERTEX_TEXCOORD2) { + vec2_to_vec2h(vtx->texcoord2, *(vec2h*)d); + d += 4; + } + + if (vertex_format & OBJ_VERTEX_TEXCOORD3) { + vec2_to_vec2h(vtx->texcoord3, *(vec2h*)d); + d += 4; + } + + if (vertex_format & OBJ_VERTEX_COLOR0) { + vec4_to_vec4h(vtx->color0, *(vec4h*)d); + d += 8; + } + + if (vertex_format & OBJ_VERTEX_BONE_DATA) { + vec4i16 bone_weight_int; + vec4_to_vec4i16(vtx->bone_weight * 1023.0f, bone_weight_int); + *(uint32_t*)d = (((uint32_t)0 & 0x03) << 30) + | (((uint32_t)bone_weight_int.z & 0x3FF) << 20) + | (((uint32_t)bone_weight_int.y & 0x3FF) << 10) + | ((uint32_t)bone_weight_int.x & 0x3FF); + d += 4; + + vec4i bone_index; + vec4i16_to_vec4i(vtx->bone_index, bone_index); + vec4i_to_vec4u8(bone_index, *(vec4u8*)d); + d += 4; + } + } + break; + } + return size_vertex * num_vertex; +} + +#if SHARED_OBJECT_BUFFER +// Added +inline static void fill_object_index_buffer(void* buf, obj* obj, int32_t& offset) { + for (int32_t i = 0; i < obj->num_mesh; i++) + fill_mesh_index_buffer(buf, obj->mesh_array[i], offset); +} + +// Added +inline static void fill_object_vertex_buffer(void* buf, obj* obj, int32_t& offset) { + for (int32_t i = 0; i < obj->num_mesh; i++) { + int32_t size = fill_mesh_vertex_buffer((uint8_t*)buf + offset, obj->mesh_array[i]); + offset += align_val_32(size); + } +} +#endif + +// 0x140459940 +static void free_objdata_indirect_table(ObjsetInfo* info) { + info->objdb_map.clear(); + info->texidx_map.clear(); + info->gentex_vec.clear(); +} + +// Inlined +inline static void free_object_index_buffer(ObjIB* objib) { + if (objib->ibhn_array) { +#if SHARED_OBJECT_BUFFER + for (int32_t i = 0; i < objib->num_ib; i++) + objib->ibhn_array[i].destroy_shared(); +#else + for (int32_t i = 0; i < objib->num_ib; i++) + objib->ibhn_array[i].destroy(); +#endif + prj::MemoryManager::free(prj::MemCSystem, objib->ibhn_array); + } + objib->ibhn_array = 0; + objib->num_ib = 0; +} + +// Inlined +inline static void free_object_vertex_buffer(ObjVB* objvb) { + if (objvb->vbhn_array) { +#if SHARED_OBJECT_BUFFER + for (int32_t i = 0; i < objvb->num_vb; i++) + objvb->vbhn_array[i].destroy_shared(); +#else + for (int32_t i = 0; i < num_vb; i++) + vbhn_array[i].destroy(); +#endif + delete[] objvb->vbhn_array; + } + objvb->vbhn_array = 0; + objvb->num_vb = 0; +} + +// 0x140459C40 +static void free_objset_texture(ObjsetInfo* info) { + texture_array_free(info->textures); + info->textures = 0; + info->tex_num = 0; +} + +// 0x14045B4F0 +static bool load_objset_texture(ObjsetInfo* info, const void* data, bool big_endian) { obj_set* set = info->obj_set; if (!set || !data) return true; @@ -2685,23 +2769,24 @@ static bool ObjsetInfo_load_textures(ObjsetInfo* info, const void* data, bool bi txp_set txp; txp.unpack_file(data, big_endian); info->tex_num = (int32_t)txp.textures.size(); - texture_txp_set_load(&txp, &info->tex_data, set->tex_id_data); + texture_txp_set_load(&txp, &info->textures, set->tex_id_data); } - info->tex_id_data.reserve(info->tex_num); - info->gentex.reserve(info->tex_num); + info->texidx_map.reserve(info->tex_num); + info->gentex_vec.reserve(info->tex_num); uint32_t* tex_id_data = set->tex_id_data; int32_t tex_num = info->tex_num; - texture** tex_data = info->tex_data; + texture** textures = info->textures; for (int32_t i = 0; i < tex_num; i++) { - info->tex_id_data.push_back(tex_id_data[i], i); - info->gentex.push_back(tex_data[i]->glid); + info->texidx_map.push_back(tex_id_data[i], i); + info->gentex_vec.push_back(textures[i]->glid); } - info->tex_id_data.sort(); + info->texidx_map.sort(); return false; } -static bool ObjsetInfo_load_textures_modern(ObjsetInfo* info, +// Added +static bool load_objset_texture_modern(ObjsetInfo* info, const void* data, size_t size, const char* file, texture_database* tex_db) { obj_set* set = info->obj_set; if (!set || !data || !size) @@ -2714,38 +2799,41 @@ static bool ObjsetInfo_load_textures_modern(ObjsetInfo* info, txp.unpack_file_modern(data, size, 'MTXD'); info->tex_num = (int32_t)txp.textures.size(); object_material_msgpack_read("patch\\AFT\\objset", file, &txp, tex_db, info); - texture_txp_set_load(&txp, &info->tex_data, set->tex_id_data); + texture_txp_set_load(&txp, &info->textures, set->tex_id_data); } - info->tex_id_data.reserve(info->tex_num); - info->gentex.reserve(info->tex_num); + info->texidx_map.reserve(info->tex_num); + info->gentex_vec.reserve(info->tex_num); uint32_t* tex_id_data = set->tex_id_data; int32_t tex_num = info->tex_num; - texture** tex_data = info->tex_data; + texture** textures = info->textures; for (int32_t i = 0; i < tex_num; i++) { - info->tex_id_data.push_back(tex_id_data[i], i); - info->gentex.push_back(tex_data[i]->glid); + info->texidx_map.push_back(tex_id_data[i], i); + info->gentex_vec.push_back(textures[i]->glid); } - info->tex_id_data.sort(); + info->texidx_map.sort(); return false; } -static void ObjsetInfo_vertex_array_load(ObjsetInfo* info) { +// Added +static void load_objset_vertex_array(ObjsetInfo* info) { obj_set* set = info->obj_set; - obj_vertex_buffer* obj_vert_buf = info->objvb; - obj_index_buffer* obj_index_buf = info->objib; + ObjVB* vbhn_array = info->objvb; + ObjIB* ibhn_array = info->objib; for (int32_t i = 0; i < set->obj_num; i++) { obj* obj = set->obj_data[i]; #if SHARED_OBJECT_BUFFER - bool double_buffer = false; + bool soft_body = false; for (int32_t i = 0; i < obj->num_mesh; i++) { obj_mesh& mesh = obj->mesh_array[i]; if (!mesh.num_vertex || !mesh.vertex_array) continue; - double_buffer |= !!mesh.attrib.m.double_buffer; + soft_body |= !!mesh.attrib.m.soft_body; } + + int32_t num_flip = soft_body ? 2 : 1; #endif for (int32_t j = 0; j < obj->num_mesh; j++) { @@ -2755,134 +2843,106 @@ static void ObjsetInfo_vertex_array_load(ObjsetInfo* info) { for (int32_t k = 0; k < mesh->num_submesh; k++) { obj_sub_mesh* sub_mesh = &mesh->submesh_array[k]; - if (sub_mesh->attrib.m.cloth) + if (sub_mesh->attrib.m.hide) continue; obj_material_data* material = &obj->material_array[sub_mesh->material_index]; -#if SHARED_OBJECT_BUFFER - for (int32_t l = 0; l < (double_buffer ? 2 : 1); l++) { -#else - for (int32_t l = 0; l < (mesh->attrib.m.double_buffer ? 2 : 1); l++) { +#if !SHARED_OBJECT_BUFFER + int32_t num_flip = mesh->attrib.m.soft_body ? 2 : 1; #endif - GLuint vertex_buffer = 0; - size_t vertex_buffer_offset = 0; - if (obj_vert_buf && obj_vert_buf[i].mesh_data) { - vertex_buffer = obj_vert_buf[i].mesh_data[j].get_buffer(); - vertex_buffer_offset = obj_vert_buf[i].mesh_data[j].get_offset(); + for (int32_t l = 0; l < num_flip; l++) { + GLuint vb = 0; + uint32_t vb_offset = 0; + if (vbhn_array && vbhn_array[i].vbhn_array) { + vb = vbhn_array[i].vbhn_array[j].get_glvb(); + vb_offset = vbhn_array[i].vbhn_array[j].get_glvb_offset(); } - GLuint index_buffer = 0; - if (obj_index_buf && obj_index_buf[i].mesh_data) - index_buffer = obj_index_buf[i].mesh_data[j].buffer; + GLuint ib = 0; + if (ibhn_array && ibhn_array[i].ibhn_array) + ib = ibhn_array[i].ibhn_array[j].ib; extern render_context* rctx_ptr; rctx_ptr->disp_manager->add_vertex_array(mesh, sub_mesh, material, - vertex_buffer, vertex_buffer_offset, index_buffer, 0, 0); + vb, vb_offset, ib, 0, 0); - if (obj_vert_buf && obj_vert_buf[i].mesh_data) - obj_vert_buf[i].mesh_data[j].cycle_index(); + if (vbhn_array && vbhn_array[i].vbhn_array) + vbhn_array[i].vbhn_array[j].flip(); } } } } } -static bool ObjsetInfo_vertex_buffer_load(ObjsetInfo* info) { +// 0x14045B8B0 +static void make_objdata_indirect_table(ObjsetInfo* info) { obj_set* set = info->obj_set; - info->objvb_num = set->obj_num; - info->objvb = prj::MemoryManager::alloc(prj::MemCSystem, set->obj_num, "OBJVB"); - if (!info->objvb) - return true; + if (!set) + return; + info->objdb_map.reserve(set->obj_num); for (int32_t i = 0; i < set->obj_num; i++) - if (!info->objvb[i].load(set->obj_data[i])) - return false; - return true; + info->objdb_map.push_back(set->obj_data[i]->id, i); + info->objdb_map.sort(); } -static void ObjsetInfo_vertex_buffer_free(ObjsetInfo* info) { - if (info->objvb) { - for (int32_t i = 0; i < info->objvb_num; i++) - info->objvb[i].unload(); - prj::MemoryManager::free(prj::MemCSystem, info->objvb); +// 0x14045D3B0 +static int32_t rewrite_to_restart_index(uint32_t* new_indices, + const int32_t num_indices, const uint32_t* indices) { + if (!num_indices) + return 0; + + new_indices[0] = indices[0]; + + int32_t src_index = 1; + int32_t dst_index = 1; + int32_t strip_length = 1; + while (src_index < num_indices - 4) + if (indices[src_index] != indices[src_index + 1]) { + new_indices[dst_index++] = indices[src_index]; + strip_length++; + src_index++; + } + else if (indices[src_index + 3] == indices[src_index + 4]) { + new_indices[dst_index++] = indices[src_index]; + new_indices[dst_index++] = 0xFFFFFFFF; + new_indices[dst_index++] = indices[src_index + 4]; + + if (strip_length % 2) { + new_indices[dst_index++] = indices[src_index + 4]; + strip_length = 0; + } + else + strip_length = 1; + src_index += 5; + } + else if (indices[src_index - 1] != indices[src_index + 2] + || indices[src_index + 1] != indices[src_index + 4]) { + new_indices[dst_index++] = indices[src_index]; + new_indices[dst_index++] = 0xFFFFFFFF; + new_indices[dst_index++] = indices[src_index + 3]; + + if (!(strip_length % 2)) { + new_indices[dst_index++] = indices[src_index + 3]; + strip_length = 0; + } + else + strip_length = 1; + src_index += 4; + } + else { + new_indices[dst_index++] = indices[src_index]; + strip_length++; + src_index += 5; + } + + if (src_index < num_indices) { + indices += src_index; + new_indices += dst_index; + dst_index += num_indices - src_index; + while (src_index++ < num_indices) + *new_indices++ = *indices++; } - - info->objvb = 0; - info->objvb_num = 0; -} - -inline static uint32_t obj_vertex_format_get_vertex_size(obj_vertex_format format) { - uint32_t size = 0; - if (format & OBJ_VERTEX_POSITION) - size += 12; - if (format & OBJ_VERTEX_NORMAL) - size += 12; - if (format & OBJ_VERTEX_TANGENT) - size += 16; - if (format & OBJ_VERTEX_BINORMAL) - size += 12; - if (format & OBJ_VERTEX_TEXCOORD0) - size += 8; - if (format & OBJ_VERTEX_TEXCOORD1) - size += 8; - if (format & OBJ_VERTEX_TEXCOORD2) - size += 8; - if (format & OBJ_VERTEX_TEXCOORD3) - size += 8; - if (format & OBJ_VERTEX_COLOR0) - size += 16; - if (format & OBJ_VERTEX_COLOR1) - size += 16; - if (format & OBJ_VERTEX_BONE_DATA) - size += 24; - if (format & OBJ_VERTEX_UNKNOWN) - size += 16; - return size; -} - -inline static uint32_t obj_vertex_format_get_vertex_size_comp1(obj_vertex_format format) { - uint32_t size = 0; - if (format & OBJ_VERTEX_POSITION) - size += 12; - if (format & OBJ_VERTEX_NORMAL) - size += 8; - if (format & OBJ_VERTEX_TANGENT) - size += 8; - if (format & OBJ_VERTEX_TEXCOORD0) - size += 4; - if (format & OBJ_VERTEX_TEXCOORD1) - size += 4; - if (format & OBJ_VERTEX_TEXCOORD2) - size += 4; - if (format & OBJ_VERTEX_TEXCOORD3) - size += 4; - if (format & OBJ_VERTEX_COLOR0) - size += 8; - if (format & OBJ_VERTEX_BONE_DATA) - size += 16; - return size; -} - -inline static uint32_t obj_vertex_format_get_vertex_size_comp2(obj_vertex_format format) { - uint32_t size = 0; - if (format & OBJ_VERTEX_POSITION) - size += 12; - if (format & OBJ_VERTEX_NORMAL) - size += 4; - if (format & OBJ_VERTEX_TANGENT) - size += 4; - if (format & OBJ_VERTEX_TEXCOORD0) - size += 4; - if (format & OBJ_VERTEX_TEXCOORD1) - size += 4; - if (format & OBJ_VERTEX_TEXCOORD2) - size += 4; - if (format & OBJ_VERTEX_TEXCOORD3) - size += 4; - if (format & OBJ_VERTEX_COLOR0) - size += 8; - if (format & OBJ_VERTEX_BONE_DATA) - size += 8; - return size; + return dst_index; } diff --git a/src/CRE/object.hpp b/src/CRE/object.hpp index b697a531..4d3fa8e5 100644 --- a/src/CRE/object.hpp +++ b/src/CRE/object.hpp @@ -14,90 +14,49 @@ #include "../KKdLib/txp.hpp" #include "../KKdLib/vec.hpp" #include "GL/buffer.hpp" +#include "config.hpp" #include "file_handler.hpp" #include "static_var.hpp" #include "texture.hpp" -#define SHARED_OBJECT_BUFFER (1) +struct IndexBuffer; +struct VertexBuffer; -struct obj_mesh_index_buffer { - GLuint buffer; - - obj_mesh_index_buffer(); - - bool load(obj_mesh& mesh); - bool load_data(size_t size, const void* data); - void unload(); - - static void* fill_data(void* data, obj_mesh& mesh); +struct ObjIB { + int32_t num_ib; + IndexBuffer* ibhn_array; }; -struct obj_mesh_vertex_buffer { - int32_t count; - GLuint buffers[3]; - GLsizeiptr size; -#if SHARED_OBJECT_BUFFER - size_t offset; -#endif - int32_t index; - - obj_mesh_vertex_buffer(); - - void cycle_index(); - GLuint get_buffer(); - size_t get_offset(); - GLsizeiptr get_size(); - bool load(obj_mesh& mesh, GL::BufferUsage usage = GL::BUFFER_USAGE_STATIC); - bool load_data(size_t size, const void* data, int32_t count, GL::BufferUsage usage = GL::BUFFER_USAGE_STATIC); - void unload(); - - static void* fill_data(void* data, obj_mesh& mesh); -}; - -struct obj_index_buffer { - int32_t mesh_num; - obj_mesh_index_buffer* mesh_data; -#if SHARED_OBJECT_BUFFER - GLuint buffer; -#endif - - obj_index_buffer(); - - bool load(obj* obj); - void unload(); -}; - -struct obj_vertex_buffer { - int32_t mesh_num; - obj_mesh_vertex_buffer* mesh_data; -#if SHARED_OBJECT_BUFFER - GLuint buffers[3]; -#endif - - obj_vertex_buffer(); - - bool load(obj* obj); - void unload(); +struct ObjVB { + int32_t num_vb; + VertexBuffer* vbhn_array; }; struct ObjsetInfo { p_file_handler obj_file_handler; - bool obj_loaded; + bool obj_ready; p_file_handler tex_file_handler; - bool tex_loaded; + bool tex_ready; prj::shared_ptr alloc_handler; obj_set* obj_set; - prj::vector_pair obj_id_data; + prj::vector_pair objdb_map; int32_t tex_num; - std::vector gentex; - prj::vector_pair tex_id_data; - texture** tex_data; - int32_t set_id; + std::vector gentex_vec; + prj::vector_pair texidx_map; + texture** textures; + int32_t id; int32_t objvb_num; - obj_vertex_buffer* objvb; + ObjVB* objvb; int32_t objib_num; - obj_index_buffer* objib; - int32_t load_count; + ObjIB* objib; + int32_t req_cnt; + + // Added +#if SHARED_OBJECT_BUFFER + GLuint vb; + GLuint ib; +#endif + std::string name; p_file_handler farc_file_handler; bool modern; @@ -106,6 +65,11 @@ struct ObjsetInfo { ~ObjsetInfo(); }; +struct ObjsetInfoObject { + ObjsetInfo* info; + int32_t index; +}; + extern int32_t obj_material_texture_type_get_texcoord_index( obj_material_texture_type type, int32_t index); extern int32_t obj_material_texture_type_get_texture_index( @@ -122,38 +86,62 @@ extern void object_material_msgpack_write(const char* path, const char* set_name obj_set* obj_set, txp_set* txp_set, texture_database* tex_db); extern void objset_info_storage_init(const object_database* obj_db); -extern obj* objset_info_storage_get_obj(object_info obj_info); -extern obj* objset_info_storage_get_obj_by_index(uint32_t set_id, int32_t index); -extern ObjsetInfo* objset_info_storage_get_objset_info(uint32_t set_id); -extern obj_mesh* objset_info_storage_get_obj_mesh(object_info obj_info, const char* mesh_name); -extern obj_mesh* objset_info_storage_get_obj_mesh_by_index(object_info obj_info, int32_t index); -extern obj_mesh* objset_info_storage_get_obj_mesh_by_object_hash(uint32_t hash, const char* mesh_name); -extern obj_mesh* objset_info_storage_get_obj_mesh_by_object_hash_index(uint32_t hash, int32_t index); -extern int32_t objset_info_storage_get_obj_mesh_index(object_info obj_info, const char* mesh_name); -extern int32_t objset_info_storage_get_obj_mesh_index_by_hash(uint32_t hash, const char* mesh_name); -extern const char* objset_info_storage_get_obj_name(object_info obj_info); -extern obj_set* objset_info_storage_get_obj_set(uint32_t set_id); -extern size_t objset_info_storage_get_obj_set_count(); -extern int32_t objset_info_storage_get_obj_storage_load_count(uint32_t set_id); -extern obj_skin* objset_info_storage_get_obj_skin(object_info obj_info); -extern obj_skin_ex_data* objset_info_storage_get_obj_skin_ex_data(object_info obj_info); -extern obj_index_buffer* objset_info_storage_get_obj_index_buffers(uint32_t set_id); -extern obj_mesh_index_buffer* objset_info_storage_get_obj_mesh_index_buffer(object_info obj_info); -extern obj_vertex_buffer* objset_info_storage_get_obj_vertex_buffers(uint32_t set_id); -extern obj_mesh_vertex_buffer* objset_info_storage_get_obj_mesh_vertex_buffer(object_info obj_info); -extern std::vector* objset_info_storage_get_obj_set_gentex(uint32_t set_id); -extern bool objset_info_storage_get_obj_set_loaded(uint32_t set_id); -extern uint32_t objset_info_storage_get_obj_set_obj_id(uint32_t set_id, int32_t obj_index); -extern int32_t objset_info_storage_get_obj_set_obj_num(uint32_t set_id); -extern uint32_t objset_info_storage_get_obj_set_tex_id(uint32_t set_id, int32_t tex_index); -extern int32_t objset_info_storage_get_obj_set_tex_num(uint32_t set_id); -extern GLuint objset_info_storage_get_obj_set_texture(uint32_t set_id, uint32_t tex_id); -extern texture** objset_info_storage_get_obj_set_textures(uint32_t set_id); -extern int32_t objset_info_storage_load_set(void* data, const object_database* obj_db, const char* name); -extern int32_t objset_info_storage_load_set(void* data, const object_database* obj_db, uint32_t set_id); -extern int32_t objset_info_storage_load_set_hash(void* data, uint32_t hash); -extern bool objset_info_storage_load_obj_set_check_not_read(uint32_t set_id, - object_database* obj_db = 0, texture_database* tex_db = 0); -extern void objset_info_storage_unload_set(const object_database* obj_db, const char* name); -extern void objset_info_storage_unload_set(uint32_t set_id); extern void objset_info_storage_free(); + +extern bool check_objset_ready(uint32_t objset_index); + +extern bool create_mesh_index_buffer(IndexBuffer& ibhn, obj_mesh& mesh); +#if SHARED_OBJECT_BUFFER +extern void create_mesh_index_buffer(IndexBuffer& ibhn, obj_mesh& mesh, GLuint in_ib); // Added +#endif +extern bool create_mesh_vertex_buffer(VertexBuffer& vbhn, + obj_mesh& mesh, GL::BufferUsage usage = GL::BUFFER_USAGE_STATIC); +#if SHARED_OBJECT_BUFFER +extern void create_mesh_vertex_buffer(VertexBuffer& vbhn, + obj_mesh& mesh, GLuint in_vb, uint32_t& offset); // Added +#endif + +extern bool create_objset_index_buffer(ObjsetInfo* info); +extern bool create_objset_vertex_buffer(ObjsetInfo* info); + +extern bool find_objdata_index(ObjsetInfoObject& info_object, object_info obj_id); + +extern void free_objset_index_buffer(ObjsetInfo* info); +extern void free_objset_vertex_buffer(ObjsetInfo* info); + +extern obj_set* get_obj_data_header(uint32_t objset_index); + +extern obj_bounding_sphere* get_object_bsphere(object_info obj_id); +inline obj* get_object_header(object_info obj_id); +extern IndexBuffer* get_object_index_buffer(object_info obj_id); +extern const char* get_object_name(object_info obj_id); +extern int32_t get_object_num(uint32_t objset_index); +extern obj_skin* get_object_skin(object_info obj_id); +extern obj_skin_ex_data* get_object_skin_osage_header(object_info obj_id); +extern VertexBuffer* get_object_vertex_buffer(object_info obj_id); + +extern uint32_t get_objnum_idx2uid(uint32_t objset_index, int32_t obj_index, const object_database* obj_db); + +extern GLuint get_objset_gen_textures_id(uint32_t objset_index, uint32_t uid); +extern std::vector* get_objset_gen_textures_vec(uint32_t objset_index); +extern ObjsetInfo* get_objset_info(uint32_t objset_index); +extern size_t get_objset_num(); +extern int32_t get_objset_num_textures(uint32_t objset_index); +extern texture** get_objset_textures(uint32_t objset_index); + +extern obj_mesh* get_mesh(object_info obj_id, const char* mesh_name); +extern obj_mesh* get_mesh(object_info obj_id, int32_t mesh_index); +extern obj_mesh* get_mesh_modern(uint32_t hash, const char* mesh_name); // Added +extern obj_mesh* get_mesh_modern(uint32_t hash, int32_t mesh_index); // Added +extern int32_t get_mesh_index(object_info obj_id, const char* mesh_name); +extern int32_t get_mesh_index_modern(uint32_t hash, const char* mesh_name);// Added +extern VertexBuffer* get_mesh_vertex_buffer(object_info obj_id, const char* mesh_name); + +extern uint32_t get_texnum_idx2uid(uint32_t objset_index, int32_t tex_index); + +extern int32_t request_objset(void* data, const object_database* obj_db, uint32_t objset_index); +extern int32_t request_objset(void* data, const object_database* obj_db, const char* name); // Added +extern int32_t request_objset_modern(void* data, uint32_t hash); // Added +extern bool wait_objset(uint32_t objset_index, object_database* obj_db = 0, texture_database* tex_db = 0); +extern void free_objset(uint32_t objset_index); +extern void free_objset(const object_database* obj_db, const char* name); // Added diff --git a/src/CRE/ogl_buffer_object.cpp b/src/CRE/ogl_buffer_object.cpp new file mode 100644 index 00000000..2ee6b86d --- /dev/null +++ b/src/CRE/ogl_buffer_object.cpp @@ -0,0 +1,363 @@ +/* + by korenkonder + GitHub/GitLab: korenkonder +*/ + +#include "ogl_buffer_object.hpp" +#include "../KKdLib/obj.hpp" +#include "gl_state.hpp" +#include "render_context.hpp" + +struct BufObjMgr { + int32_t vb_peak_size; + int32_t vb_all_size; + int32_t ib_peak_size; + int32_t ib_all_size; +}; + +BufObjMgr bufobj_mgr; + +// Added +IndexBuffer::IndexBuffer() : ib() { + +} + +// Added +bool IndexBuffer::create(uint32_t size, const void* buf) { + if (!size) + return false; + + ib = create_index_buffer(size, buf); + return true; +} + +#if SHARED_OBJECT_BUFFER +// Added +void IndexBuffer::create(GLuint in_ib) { + ib = in_ib; +} +#endif + +// Added +void IndexBuffer::destroy() { + free_index_buffer(ib); + ib = 0; +} + +#if SHARED_OBJECT_BUFFER +// Added +void IndexBuffer::destroy_shared() { + ib = 0; +} +#endif + +// Added +GLuint IndexBuffer::get_glib() const { + return ib; +} + +// 0x1404615C0 +#if SHARED_OBJECT_BUFFER +VertexBuffer::VertexBuffer() : num_flip_chain(), vb(), +flip_index(), target(GL_ARRAY_BUFFER), vb_size(), vb_offset() { +#else +VertexBuffer::VertexBuffer() : num_flip_chain(), vb(), +flip_index(), target(GL_ARRAY_BUFFER), vb_size() { +#endif + +} + +// 0x1404615E0 +VertexBuffer::~VertexBuffer() { + destroy(); +} + +// 0x140461650 +bool VertexBuffer::create(uint32_t size, const void* buf, uint32_t num_flip, GL::BufferUsage usage) { + if (!size || num_flip > VertexBuffer::NUM_FLIP_MAX) + return false; + + num_flip_chain = num_flip; + flip_index = 0; + vb_size = size; +#if SHARED_OBJECT_BUFFER + vb_offset = 0; +#endif + + for (uint32_t i = 0; i < num_flip; i++) { + vb[i] = create_vertex_buffer(size, buf, usage); + if (!vb[i]) { + destroy(); + return false; + } + } + return true; +} + +#if SHARED_OBJECT_BUFFER +// Added +void VertexBuffer::create(GLuint in_vb, uint32_t size, uint32_t offset) { + destroy_shared(); + + if (size) { + num_flip_chain = 1; + flip_index = 0; + vb[0] = in_vb; + vb_size = size; + vb_offset = offset; + + bufobj_mgr.vb_all_size += size; + bufobj_mgr.vb_peak_size = max_def(bufobj_mgr.vb_peak_size, bufobj_mgr.vb_all_size); + } +} +#endif + +// 0x140461870 +void VertexBuffer::destroy() { + for (uint32_t i = 0; i < num_flip_chain; i++) { + free_vertex_buffer(vb[i]); + vb[i] = 0; + } + + num_flip_chain = 0; + flip_index = 0; + vb_size = 0; +#if SHARED_OBJECT_BUFFER + vb_offset = 0; +#endif +} + +#if SHARED_OBJECT_BUFFER +// Added +void VertexBuffer::destroy_shared() { + for (uint32_t i = 0; i < num_flip_chain; i++) + vb[i] = 0; + + bufobj_mgr.vb_all_size -= vb_size; + + num_flip_chain = 0; + flip_index = 0; + vb_size = 0; + vb_offset = 0; +} +#endif + +// 0x1404618E0 +void VertexBuffer::flip() { + if (++flip_index >= num_flip_chain) + flip_index = 0; +} + +// 0x140461A20 +GLuint VertexBuffer::get_glvb() const { + if (flip_index < num_flip_chain) + return vb[flip_index]; + return 0; +} + +// Missing +GLuint VertexBuffer::get_glvb_at(uint32_t index) const { + if (index < num_flip_chain) + return vb[index]; + return 0; +} + +// Added +uint32_t VertexBuffer::get_glvb_offset() const { +#if SHARED_OBJECT_BUFFER + if (vb[0]) + return vb_offset; +#endif + return 0; +} + +// 0x140461A40 +uint32_t VertexBuffer::get_num_flip_chain(uint32_t index) const { + return num_flip_chain; +} + +// 0x140461A50 +uint32_t VertexBuffer::get_size() const { + if (vb[0]) + return vb_size; + return 0; +} + +// 0x140461AE0 +GLenum VertexBuffer::get_target() const { + return GL_ARRAY_BUFFER; +} + +// 0x1404616F0 +GLuint create_index_buffer(uint32_t size, const void* data) { + GLuint ib = 0; + glGenBuffers(1, &ib); + gl_state.bind_element_array_buffer(ib); + if (GLAD_GL_VERSION_4_4) + glBufferStorage(GL_ELEMENT_ARRAY_BUFFER, size, data, 0); + else + glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, data, GL_STATIC_DRAW); + gl_state.bind_element_array_buffer(0); + + if (glGetError()) { + glDeleteBuffers(1, &ib); + return 0; + } + + bufobj_mgr.ib_all_size += size; + bufobj_mgr.ib_peak_size = max_def(bufobj_mgr.ib_peak_size, bufobj_mgr.ib_all_size); + return ib; +} + +// 0x140461900 +void free_index_buffer(GLuint ib) { + if (!ib) + return; + + extern render_context* rctx_ptr; + rctx_ptr->disp_manager->remove_index_buffer(ib); + + GLint size = 0; + if (GLAD_GL_VERSION_4_5) + glGetNamedBufferParameteriv(ib, GL_BUFFER_SIZE, &size); + else { + gl_state.bind_element_array_buffer(ib); + glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &size); + gl_state.bind_element_array_buffer(0); + } + + bufobj_mgr.ib_all_size -= size; + + glDeleteBuffers(1, &ib); + glGetError(); +} + +// 0x1404617B0 +GLuint create_vertex_buffer(uint32_t size, const void* data, GL::BufferUsage usage) { + GLuint vb = 0; + glGenBuffers(1, &vb); + gl_state.bind_array_buffer(vb); + if (GLAD_GL_VERSION_4_4 && usage != GL::BUFFER_USAGE_STREAM) { + GLbitfield flags = usage == GL::BUFFER_USAGE_DYNAMIC + ? GL_DYNAMIC_STORAGE_BIT | GL_MAP_WRITE_BIT : 0; + glBufferStorage(GL_ARRAY_BUFFER, size, data, flags); + } + else + glBufferData(GL_ARRAY_BUFFER, size, data, BufferUsageToGLenum(usage)); + gl_state.bind_array_buffer(0); + + if (glGetError()) { + glDeleteBuffers(1, &vb); + return 0; + } + + bufobj_mgr.vb_all_size += size; + bufobj_mgr.vb_peak_size = max_def(bufobj_mgr.vb_peak_size, bufobj_mgr.vb_all_size); + return vb; +} + +// 0x140461990 +void free_vertex_buffer(GLuint vb) { + if (!vb) + return; + + extern render_context* rctx_ptr; + rctx_ptr->disp_manager->remove_vertex_buffer(vb); + + GLint size = 0; + if (GLAD_GL_VERSION_4_5) + glGetNamedBufferParameteriv(vb, GL_BUFFER_SIZE, &size); + else { + gl_state.bind_array_buffer(vb); + glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, &size); + gl_state.bind_array_buffer(0); + } + + bufobj_mgr.vb_all_size -= size; + + glDeleteBuffers(1, &vb); + glGetError(); +} + +// 0x140461AF0 +void get_vertex_buffer_memory_info(int32_t* vb_all_size, int32_t* vb_peak_size) { + if (vb_all_size) + *vb_all_size = bufobj_mgr.vb_all_size; + if (vb_peak_size) + *vb_peak_size = bufobj_mgr.vb_peak_size; +} + +// 0x140469640 +uint32_t get_vertex_size(uint32_t format, uint32_t compression) { + uint32_t size = 0; + switch (compression) { + case 0: + default: + if (format & OBJ_VERTEX_POSITION) + size += 12; + if (format & OBJ_VERTEX_NORMAL) + size += 12; + if (format & OBJ_VERTEX_TANGENT) + size += 16; + if (format & OBJ_VERTEX_BINORMAL) + size += 12; + if (format & OBJ_VERTEX_TEXCOORD0) + size += 8; + if (format & OBJ_VERTEX_TEXCOORD1) + size += 8; + if (format & OBJ_VERTEX_TEXCOORD2) + size += 8; + if (format & OBJ_VERTEX_TEXCOORD3) + size += 8; + if (format & OBJ_VERTEX_COLOR0) + size += 16; + if (format & OBJ_VERTEX_COLOR1) + size += 16; + if (format & OBJ_VERTEX_BONE_DATA) + size += 24; + if (format & OBJ_VERTEX_UNKNOWN) + size += 16; + break; + case 1: // Added + if (format & OBJ_VERTEX_POSITION) + size += 12; + if (format & OBJ_VERTEX_NORMAL) + size += 8; + if (format & OBJ_VERTEX_TANGENT) + size += 8; + if (format & OBJ_VERTEX_TEXCOORD0) + size += 4; + if (format & OBJ_VERTEX_TEXCOORD1) + size += 4; + if (format & OBJ_VERTEX_TEXCOORD2) + size += 4; + if (format & OBJ_VERTEX_TEXCOORD3) + size += 4; + if (format & OBJ_VERTEX_COLOR0) + size += 8; + if (format & OBJ_VERTEX_BONE_DATA) + size += 16; + break; + case 2: // Added + if (format & OBJ_VERTEX_POSITION) + size += 12; + if (format & OBJ_VERTEX_NORMAL) + size += 4; + if (format & OBJ_VERTEX_TANGENT) + size += 4; + if (format & OBJ_VERTEX_TEXCOORD0) + size += 4; + if (format & OBJ_VERTEX_TEXCOORD1) + size += 4; + if (format & OBJ_VERTEX_TEXCOORD2) + size += 4; + if (format & OBJ_VERTEX_TEXCOORD3) + size += 4; + if (format & OBJ_VERTEX_COLOR0) + size += 8; + if (format & OBJ_VERTEX_BONE_DATA) + size += 8; + break; + } + return size; +} diff --git a/src/CRE/ogl_buffer_object.hpp b/src/CRE/ogl_buffer_object.hpp new file mode 100644 index 00000000..c686b7a6 --- /dev/null +++ b/src/CRE/ogl_buffer_object.hpp @@ -0,0 +1,70 @@ +/* + by korenkonder + GitHub/GitLab: korenkonder +*/ + +#pragma once + +#include "../KKdLib/default.hpp" +#include "GL/buffer.hpp" +#include "config.hpp" +#include "gl.hpp" + +// Added +struct IndexBuffer { + GLuint ib; + + IndexBuffer(); + + bool create(uint32_t size, const void* buf); +#if SHARED_OBJECT_BUFFER + void create(GLuint in_ib); +#endif + void destroy(); +#if SHARED_OBJECT_BUFFER + void destroy_shared(); +#endif + GLuint get_glib() const; +}; + +struct VertexBuffer { + static const uint32_t NUM_FLIP_MAX = 3; + + uint32_t num_flip_chain; + GLuint vb[NUM_FLIP_MAX]; + uint32_t flip_index; + GLenum target; + uint32_t vb_size; // Added +#if SHARED_OBJECT_BUFFER + uint32_t vb_offset; // Added +#endif + + VertexBuffer(); + ~VertexBuffer(); + + bool create(uint32_t size, const void* buf, uint32_t num_flip, GL::BufferUsage usage = GL::BUFFER_USAGE_STATIC); +#if SHARED_OBJECT_BUFFER + void create(GLuint in_vb, uint32_t size, uint32_t offset); // Added +#endif + void destroy(); +#if SHARED_OBJECT_BUFFER + void destroy_shared(); // Added +#endif + void flip(); + GLuint get_glvb() const; + GLuint get_glvb_at(uint32_t index) const; + uint32_t get_glvb_offset() const; // Added + uint32_t get_num_flip_chain(uint32_t index) const; + uint32_t get_size() const; + GLenum get_target() const; +}; + +extern GLuint create_index_buffer(uint32_t size, const void* buf); +extern void free_index_buffer(GLuint ib); + +extern GLuint create_vertex_buffer(uint32_t size, const void* buf, GL::BufferUsage usage = GL::BUFFER_USAGE_STATIC); +extern void free_vertex_buffer(GLuint vb); + +extern void get_vertex_buffer_memory_info(int32_t* vb_all_size, int32_t* vb_peak_size); + +extern uint32_t get_vertex_size(uint32_t vertex_format, uint32_t compression = 0); diff --git a/src/CRE/render.cpp b/src/CRE/render.cpp index 26273fdb..865e1981 100644 --- a/src/CRE/render.cpp +++ b/src/CRE/render.cpp @@ -380,7 +380,7 @@ namespace rndr { if (!lens_flare_texture) return; - GLuint tex = objset_info_storage_get_obj_set_texture(5, 4549); + GLuint tex = get_objset_gen_textures_id(5, 4549); if (!tex) return; diff --git a/src/CRE/rob/ex_block.cpp b/src/CRE/rob/ex_block.cpp index 2dd4fdd5..691f8cb4 100644 --- a/src/CRE/rob/ex_block.cpp +++ b/src/CRE/rob/ex_block.cpp @@ -79,7 +79,7 @@ static void length_limit(vec3& p, const vec3& r, const float_t rr); static bool make_axis_matrix(mat4& mat, const vec3& axis, const skin_param_hinge* hinge, vec3* rot, const ROTTYPE& rottype); static void make_direction_matrix(mat4& mat, const vec3& v0, const vec3& v1); -static void modify_cloth_object(obj_mesh* mesh, obj_mesh_vertex_buffer* vb, +static void modify_cloth_object(obj_mesh* mesh, VertexBuffer* vb, CLOTH_VERTEX* vtxarg, float_t sgn, int32_t num_idx, uint16_t* idxtbl, bool do_ura); static const ExpFuncUnaryTbl exp_func_unary_tbl[] = { @@ -1215,8 +1215,8 @@ void RobCloth::disp_debug() { } void RobCloth::dest() { - vb[0].unload(); - vb[1].unload(); + vb[0].destroy(); + vb[1].destroy(); init(); local_mat = 0; skin_disp = 0; @@ -1745,16 +1745,16 @@ void RobCloth::ctrl(const float_t dt, bool init_flag) { // 0x14021B930 void RobCloth::disp(const mat4& mat, render_context* rctx) { - obj* obj = objset_info_storage_get_obj(skin_disp->obj_uid); + obj* obj = get_object_header(skin_disp->obj_uid); if (!obj) return; - std::vector* textures = objset_info_storage_get_obj_set_gentex(skin_disp->obj_uid.set_id); + std::vector* textures = get_objset_gen_textures_vec(skin_disp->obj_uid.set_id); vec3 center = (vtxarg.data()[0].pos + vtxarg.data()[width * height - 1].pos) * 0.5f; ::obj o = *obj; - o.num_mesh = ib[1].buffer != 0 ? 2 : 1; + o.num_mesh = ib[1].ib != 0 ? 2 : 1; o.mesh_array = mesh; o.bounding_sphere.center = center; o.bounding_sphere.radius *= 2.0f; @@ -1782,8 +1782,8 @@ void RobCloth::modify_obj() { calc_normal(); if (cloth_modify_flag & 0x02) { - obj_mesh* omote_mesh = objset_info_storage_get_obj_mesh(skin_disp->obj_uid, data->omote_name); - obj_mesh* ura_mesh = objset_info_storage_get_obj_mesh(skin_disp->obj_uid, data->ura_name); + obj_mesh* omote_mesh = get_mesh(skin_disp->obj_uid, data->omote_name); + obj_mesh* ura_mesh = get_mesh(skin_disp->obj_uid, data->ura_name); if (data->ura_name) { modify_cloth_object(omote_mesh, &vb[0], vtxarg.data(), 1.0f, data->num_omote_index, data->omote_index_array, false); @@ -1802,11 +1802,11 @@ void RobCloth::set_data(size_t w, size_t h, const obj_skin_ex_node_cloth_root * const RobSkinDisp* skin, const bone_database* bone_data) { skin_disp = skin; - obj* obj = objset_info_storage_get_obj(skin_disp->obj_uid); + obj* obj = get_object_header(skin_disp->obj_uid); if (!obj) return; - obj_mesh_index_buffer* ib = objset_info_storage_get_obj_mesh_index_buffer(skin_disp->obj_uid); + IndexBuffer* ib = get_object_index_buffer(skin_disp->obj_uid); uint32_t omotea_mesh_index = obj->get_obj_mesh_index(data->omote_name); uint32_t ura_mesh_index = obj->get_obj_mesh_index(data->ura_name); @@ -1820,25 +1820,25 @@ void RobCloth::set_data(size_t w, size_t h, const obj_skin_ex_node_cloth_root * for (int32_t j = 0; j < mesh[i].num_submesh; j++) { obj_sub_mesh& cloth_mesh = submesh[i][j]; cloth_mesh = mesh[i].submesh_array[j]; - cloth_mesh.attrib.m.cloth = 0; + cloth_mesh.attrib.m.hide = 0; cloth_mesh.bounding_sphere.radius = 1000.0f; cloth_mesh.axis_aligned_bounding_box.center = 0.0f; cloth_mesh.axis_aligned_bounding_box.size = { 1000.0f, 1000.0f, 1000.0f }; - mesh[i].submesh_array[j].attrib.m.cloth = 1; + mesh[i].submesh_array[j].attrib.m.hide = 1; } mesh[i].submesh_array = submesh[i]; mesh[i].bounding_sphere.radius = 1000.0f; } this->ib[0] = ib[omotea_mesh_index]; - if (!vb[0].load(mesh[0], GL::BUFFER_USAGE_STREAM)) + if (!create_mesh_vertex_buffer(vb[0], mesh[0], GL::BUFFER_USAGE_STREAM)) return; this->ib[1] = {}; if (data->ura_name && ura_mesh_index != -1) this->ib[1] = ib[ura_mesh_index]; - if (data->ura_name && !vb[1].load(mesh[1], GL::BUFFER_USAGE_STREAM)) + if (data->ura_name && !create_mesh_vertex_buffer(vb[1], mesh[1], GL::BUFFER_USAGE_STREAM)) return; flag.exec = 1; @@ -1887,7 +1887,7 @@ void RobCloth::set_data(size_t w, size_t h, const obj_skin_ex_node_cloth_root * for (size_t i = 0; i < data->num_omote_index; i++) index_array.data()[omote_index_array[i]] = i; - obj_mesh* mesh = objset_info_storage_get_obj_mesh(skin_disp->obj_uid, data->omote_name); + obj_mesh* mesh = get_mesh(skin_disp->obj_uid, data->omote_name); obj_vertex_format vertex_format = (obj_vertex_format)0; obj_vertex_data* vertex_array = 0; if (mesh) { @@ -1944,26 +1944,26 @@ void RobCloth::set_data(const obj_skin_ex_node_cloth* cldata, set_data(cldata->width, cldata->height, cldata->fix_point, cldata->move_point, cldata->mat_array, cldata->ring_flag, skin, bone_data); - obj* obj = objset_info_storage_get_obj(skin->obj_uid); + obj* obj = get_object_header(skin->obj_uid); if (!obj) return; for (int32_t i = 0; i < 2; i++) { - if (!mesh[i].num_vertex || !mesh[i].vertex_array || !ib[i].buffer) + if (!mesh[i].num_vertex || !mesh[i].vertex_array || !ib[i].ib) continue; - obj_mesh_vertex_buffer* obj_vert_buf = &vb[i]; - obj_mesh_index_buffer* obj_index_buf = &ib[i]; + VertexBuffer* vbhn_array = &vb[i]; + IndexBuffer* ibhn_array = &ib[i]; obj_mesh* mesh = &this->mesh[i]; for (int32_t j = 0; j < mesh->num_submesh; j++) { obj_material_data* material = &obj->material_array[mesh->submesh_array[j].material_index]; - for (int32_t k = 0; k < (mesh->attrib.m.double_buffer ? 2 : 1); k++) { + for (int32_t k = 0; k < (mesh->attrib.m.soft_body ? 2 : 1); k++) { extern render_context* rctx_ptr; rctx_ptr->disp_manager->add_vertex_array(mesh, &mesh->submesh_array[j], material, - obj_vert_buf->get_buffer(), obj_vert_buf->get_offset(), obj_index_buf->buffer, 0, 0); + vbhn_array->get_glvb(), vbhn_array->get_glvb_offset(), ibhn_array->ib, 0, 0); - obj_vert_buf->cycle_index(); + vbhn_array->flip(); } } } @@ -4324,15 +4324,15 @@ static void make_direction_matrix(mat4& mat, const vec3& v0, const vec3& v1) { mat4_set(&axis, -s, c, &mat); } -static void modify_cloth_object(obj_mesh* mesh, obj_mesh_vertex_buffer* vb, +static void modify_cloth_object(obj_mesh* mesh, VertexBuffer* vb, CLOTH_VERTEX* vtxarg, float_t sgn, int32_t num_idx, uint16_t* idxtbl, bool do_ura) { if (!mesh || !vb || (mesh->vertex_format & (OBJ_VERTEX_NORMAL | OBJ_VERTEX_POSITION)) != (OBJ_VERTEX_NORMAL | OBJ_VERTEX_POSITION)) return; - vb->cycle_index(); - GL::ArrayBuffer buffer = vb->get_buffer(); - size_t data = (size_t)buffer.MapMemory(gl_state); + vb->flip(); + GL::ArrayBuffer glvb = vb->get_glvb(); + size_t data = (size_t)glvb.MapMemory(gl_state); if (!data) return; @@ -4468,5 +4468,5 @@ static void modify_cloth_object(obj_mesh* mesh, obj_mesh_vertex_buffer* vb, break; } - buffer.UnmapMemory(gl_state); + glvb.UnmapMemory(gl_state); } diff --git a/src/CRE/rob/rob.cpp b/src/CRE/rob/rob.cpp index b19094b2..4088d17e 100644 --- a/src/CRE/rob/rob.cpp +++ b/src/CRE/rob/rob.cpp @@ -702,9 +702,7 @@ struct rob_chara_age_age_object_vertex { }; struct rob_chara_age_age_object { - ObjsetInfo* objset_info; - int32_t obj_index; - int32_t field_C; + ObjsetInfoObject info_object; int32_t num_vertex; int32_t num_index; ::obj obj; @@ -715,8 +713,8 @@ struct rob_chara_age_age_object { rob_chara_age_age_object_vertex* vertex_data; int32_t vertex_data_size; int32_t vertex_array_size; - obj_mesh_vertex_buffer obj_vert_buf; - obj_mesh_index_buffer obj_index_buf; + VertexBuffer vb; + IndexBuffer ib; vec3 pos[10]; int32_t disp_count; int32_t count; @@ -728,7 +726,6 @@ struct rob_chara_age_age_object { obj_mesh* mesh, const mat4& mat, float_t alpha); void disp(render_context* rctx, size_t id, bool npr, bool reflect, const vec3& a5, bool chara_color); - bool get_objset_info_obj_index(object_info obj_info); ::obj* get_obj_set_obj(); std::vector& get_obj_set_texture(); void load(object_info obj_info, int32_t count); @@ -13473,7 +13470,7 @@ void RobSkinDisp::set(object_info objuid, const RobNode* mot_node, matrix.clear(); dest_ex_node(); - obj_skin* skin = objset_info_storage_get_obj_skin(obj_uid); + obj_skin* skin = get_object_skin(obj_uid); if (!skin) return; @@ -15886,7 +15883,7 @@ void OpdMaker::Data::ReadOpdiFiles(rob_chara* rob_chr, std::vector& mo continue; object_info obj_info = skin_disp->obj_uid; - const char* object_name = objset_info_storage_get_obj_name(obj_info); + const char* object_name = get_object_name(obj_info); if (!object_name) continue; @@ -16216,7 +16213,7 @@ bool OpdMakeWorker::ctrl() { for (int32_t i = RPK_ITEM_BEGIN; i <= RPK_ITEM_END; i++) { const RobSkinDisp* skin_disp = rob_chr->disp->get_skin_work((ROB_PARTS_KIND)i); - if (!objset_info_storage_get_obj_name(skin_disp->obj_uid) && skin_disp->osage_nodes_count) + if (!get_object_name(skin_disp->obj_uid) && skin_disp->osage_nodes_count) continue; const object_info* body_obj_uid = &rob_data->body_obj_uid[RPK_BASE_BEGIN]; @@ -16742,7 +16739,7 @@ void opd_chara_data::encode_data() { continue; object_info obj_info = skin_disp->obj_uid; - const char* object_name = objset_info_storage_get_obj_name(obj_info); + const char* object_name = get_object_name(obj_info); if (!object_name) continue; @@ -16826,7 +16823,7 @@ void opd_chara_data::encode_init_data(uint32_t motnum) { continue; object_info obj_info = skin_disp->obj_uid; - const char* object_name = objset_info_storage_get_obj_name(obj_info); + const char* object_name = get_object_name(obj_info); if (!object_name) continue; @@ -16888,7 +16885,7 @@ void opd_chara_data::fs_copy_file() { continue; opdi[i].write_file(); - const char* object_name = objset_info_storage_get_obj_name(skin_disp->obj_uid); + const char* object_name = get_object_name(skin_disp->obj_uid); if (!object_name) continue; @@ -16973,7 +16970,7 @@ void opd_chara_data::open_opd_file() { if (!path_check_directory_exists(chara_dir.c_str())) path_create_directory(chara_dir.c_str()); - const char* object_name = objset_info_storage_get_obj_name(skin_disp->obj_uid); + const char* object_name = get_object_name(skin_disp->obj_uid); if (!object_name) continue; @@ -17002,7 +16999,7 @@ void opd_chara_data::open_opdi_file() { if (!path_check_directory_exists(chara_dir.c_str())) path_create_directory(chara_dir.c_str()); - const char* object_name = objset_info_storage_get_obj_name(skin_disp->obj_uid); + const char* object_name = get_object_name(skin_disp->obj_uid); if (!object_name) continue; @@ -17173,7 +17170,7 @@ void OsagePlayDataManager::LoadOpdFileList() { continue; } - const char* object_name = objset_info_storage_get_obj_name(i->first); + const char* object_name = get_object_name(i->first); if (object_name) { std::string obj_name_buf = string_to_lower(object_name); @@ -18067,9 +18064,8 @@ void rob_chara_age_age_data::reset() { alive = false; } -rob_chara_age_age_object::rob_chara_age_age_object() : objset_info(), -obj_index(), field_C(), num_vertex(), num_index(), vertex_data(), -vertex_data_size(), vertex_array_size(), disp_count(), count(), field_C3C() { +rob_chara_age_age_object::rob_chara_age_age_object() : info_object(), num_vertex(), num_index(), +vertex_data(), vertex_data_size(), vertex_array_size(), disp_count(), count(), field_C3C() { } @@ -18095,7 +18091,7 @@ void rob_chara_age_age_object::calc_vertex(rob_chara_age_age_object_vertex*& vtx void rob_chara_age_age_object::disp(render_context* rctx, size_t id, bool npr, bool reflect, const vec3& a5, bool chara_color) { int32_t disp_count = this->disp_count; - if (!objset_info || !disp_count) + if (!info_object.info || !disp_count) return; disp_count = min_def(disp_count, 10); @@ -18112,10 +18108,10 @@ void rob_chara_age_age_object::disp(render_context* rctx, size_t id, return a.first < b.first; }); - obj_vert_buf.cycle_index(); + vb.flip(); - GL::ArrayBuffer buffer = obj_vert_buf.get_buffer(); - size_t vtx_data = (size_t)buffer.MapMemory(gl_state); + GL::ArrayBuffer glvb = vb.get_glvb(); + size_t vtx_data = (size_t)glvb.MapMemory(gl_state); if (!vtx_data) return; @@ -18124,7 +18120,7 @@ void rob_chara_age_age_object::disp(render_context* rctx, size_t id, memmove((void*)(vtx_data + vertex_array_size * i), (void*)((size_t)vertex_data + vertex_array_size * v44[i].second), vertex_array_size); - buffer.UnmapMemory(gl_state); + glvb.UnmapMemory(gl_state); mesh.num_vertex = disp_count * num_vertex; sub_mesh.num_index = disp_count * num_index; @@ -18136,29 +18132,15 @@ void rob_chara_age_age_object::disp(render_context* rctx, size_t id, rctx->disp_manager->set_obj_flags(flags); rctx->disp_manager->set_chara_color(chara_color); rctx->disp_manager->set_shadow_group(id ? SHADOW_GROUP_STAGE : SHADOW_GROUP_CHARA); - rctx->disp_manager->entry_obj_by_obj(mat4_identity, &obj, - &get_obj_set_texture(), &obj_vert_buf, &obj_index_buf, 0, 1.0f); -} - -bool rob_chara_age_age_object::get_objset_info_obj_index(object_info obj_info) { - objset_info = objset_info_storage_get_objset_info(obj_info.set_id); - if (!objset_info) - return false; - - auto elem = objset_info->obj_id_data.find(obj_info.id); - if (elem == objset_info->obj_id_data.end()) - return false; - - obj_index = elem->second; - return true; + rctx->disp_manager->entry_obj_by_obj(mat4_identity, &obj, &get_obj_set_texture(), &vb, &ib, 0, 1.0f); } ::obj* rob_chara_age_age_object::get_obj_set_obj() { - return objset_info->obj_set->obj_data[obj_index]; + return info_object.info->obj_set->obj_data[info_object.index]; } std::vector& rob_chara_age_age_object::get_obj_set_texture() { - return objset_info->gentex; + return info_object.info->gentex_vec; } void rob_chara_age_age_object::load(object_info obj_info, int32_t count) { @@ -18169,22 +18151,22 @@ void rob_chara_age_age_object::load(object_info obj_info, int32_t count) { num_index = 0; disp_count = 0; - if (!get_objset_info_obj_index(obj_info)) { - obj_index = -1; - objset_info = 0; + if (!find_objdata_index(info_object, obj_info)) { + info_object.index = -1; + info_object.info = 0; return; } else { ::obj* o = get_obj_set_obj(); if (o->num_mesh != 1 || o->mesh_array[0].num_submesh != 1 || o->mesh_array[0].submesh_array[0].index_format != OBJ_INDEX_U16) { - obj_index = -1; - objset_info = 0; + info_object.index = -1; + info_object.info = 0; return; } } - if (!objset_info) + if (!info_object.info) return; ::obj* o = get_obj_set_obj(); @@ -18197,11 +18179,11 @@ void rob_chara_age_age_object::load(object_info obj_info, int32_t count) { int32_t num_index = sm->num_index; this->num_index = num_index; - size_t vertex_array_size = sizeof(rob_chara_age_age_object_vertex) * num_vertex; - this->vertex_array_size = (uint32_t)vertex_array_size; + uint32_t vertex_array_size = sizeof(rob_chara_age_age_object_vertex) * num_vertex; + this->vertex_array_size = vertex_array_size; - size_t vertex_data_size = vertex_array_size * count; - this->vertex_data_size = (uint32_t)vertex_data_size; + uint32_t vertex_data_size = vertex_array_size * count; + this->vertex_data_size = vertex_data_size; rob_chara_age_age_object_vertex* vtx_data = force_malloc(vertex_data_size); vertex_data = vtx_data; @@ -18215,7 +18197,7 @@ void rob_chara_age_age_object::load(object_info obj_info, int32_t count) { vtx_data->texcoord = vertex_array[k].texcoord0; } - obj_vert_buf.load_data(vertex_data_size, vertex_data, 2, GL::BUFFER_USAGE_STREAM); + vb.create(vertex_data_size, vertex_data, 2, GL::BUFFER_USAGE_STREAM); this->num_index = num_index + 1; int32_t num_idx_data = (int32_t)(count * (num_index + 1)); @@ -18233,13 +18215,13 @@ void rob_chara_age_age_object::load(object_info obj_info, int32_t count) { idx_data[l++] = 0xFFFF; index_offset += num_vertex; } - obj_index_buf.load_data(sizeof(uint16_t) * num_idx_data, idx_data); + ib.create(sizeof(uint16_t) * num_idx_data, idx_data); free_def(idx_data); material[0] = o->material_array[0]; material[1] = o->material_array[0]; - material[1].material.attrib.m.alpha_texture = 0; - material[1].material.attrib.m.alpha_material = 0; + material[1].material.attrib.m.alpha_tex = 0; + material[1].material.attrib.m.alpha_mat = 0; obj.bounding_sphere = o->bounding_sphere; obj.mesh_array = &mesh; @@ -18279,8 +18261,8 @@ void rob_chara_age_age_object::load(object_info obj_info, int32_t count) { sub_mesh.num_index = num_idx_data; sub_mesh.attrib = sm->attrib; sub_mesh.axis_aligned_bounding_box = sm->axis_aligned_bounding_box; - sub_mesh.first_index = 0; - sub_mesh.last_index = (uint16_t)((size_t)num_vertex * count); + sub_mesh.min_index = 0; + sub_mesh.max_index = (uint16_t)((size_t)num_vertex * count); sub_mesh.index_offset = 0; axis_aligned_bounding_box = sm->axis_aligned_bounding_box; @@ -18289,15 +18271,15 @@ void rob_chara_age_age_object::load(object_info obj_info, int32_t count) { for (int32_t i = 0; i < 2; i++) { extern render_context* rctx_ptr; rctx_ptr->disp_manager->add_vertex_array(&mesh, &sub_mesh, material, - obj_vert_buf.get_buffer(), obj_vert_buf.get_offset(), obj_index_buf.buffer, 0, 0); + vb.get_glvb(), vb.get_glvb_offset(), ib.ib, 0, 0); - obj_vert_buf.cycle_index(); + vb.flip(); } } void rob_chara_age_age_object::reset() { - obj_index_buf.unload(); - obj_vert_buf.unload(); + ib.destroy(); + vb.destroy(); if (vertex_data) { free(vertex_data); @@ -18307,12 +18289,12 @@ void rob_chara_age_age_object::reset() { vertex_data_size = 0; num_vertex = 0; num_index = 0; - objset_info = 0; - obj_index = -1; + info_object.info = 0; + info_object.index = -1; } void rob_chara_age_age_object::update(rob_chara_age_age_data* data, int32_t count, float_t alpha) { - if (!objset_info) + if (!info_object.info) return; ::obj* o = get_obj_set_obj(); @@ -19966,20 +19948,20 @@ bool TaskRobLoad::LoadCharaItemsCheckNotRead(CHARA_NUM cn, RobItemEquip* item_se bool TaskRobLoad::LoadCharaItemsCheckNotReadParent(CHARA_NUM cn, RobItemEquip* item_set) { return TaskRobLoad::LoadCharaItemsCheckNotRead(cn, item_set) || item_set->item_no[ROB_ITEM_EQUIP_SUB_ID_KAMI] == 649 - && objset_info_storage_load_obj_set_check_not_read(3291); + && wait_objset(3291); } void TaskRobLoad::LoadCharaItems(CHARA_NUM cn, RobItemEquip* item_set, void* data, const object_database* obj_db) { RobItem::s_req_obj_all(cn, item_set, data, obj_db); if (item_set->item_no[ROB_ITEM_EQUIP_SUB_ID_KAMI] == 649) - objset_info_storage_load_set(data, obj_db, 3291); + request_objset(data, obj_db, 3291); } void TaskRobLoad::LoadCharaObjSetMotionSet(CHARA_NUM cn, void* data, const object_database* obj_db, const motion_database* mot_db) { const RobData* rob_data = get_rob_data(cn); - objset_info_storage_load_set(data, obj_db, rob_data->objset); + request_objset(data, obj_db, rob_data->objset); motion_set_load_motion(cmn_set_id, "", mot_db); motion_set_load_mothead(cmn_set_id, "", mot_db); motion_set_load_motion(rob_data->motfile, "", mot_db); @@ -19987,7 +19969,7 @@ void TaskRobLoad::LoadCharaObjSetMotionSet(CHARA_NUM cn, bool TaskRobLoad::LoadCharaObjSetMotionSetCheck(CHARA_NUM cn) { const RobData* rob_data = get_rob_data(cn); - if (objset_info_storage_load_obj_set_check_not_read(rob_data->objset) + if (wait_objset(rob_data->objset) || motion_storage_check_mot_file_not_ready(cmn_set_id) || mothead_storage_check_mhd_file_not_ready(cmn_set_id)) return true; @@ -20010,13 +19992,13 @@ void TaskRobLoad::ResetReqDataObj() { void TaskRobLoad::UnloadCharaItems(CHARA_NUM cn, RobItemEquip* item_set) { if (item_set->item_no[ROB_ITEM_EQUIP_SUB_ID_KAMI] == 649) - objset_info_storage_unload_set(3291); + free_objset(3291); RobItem::s_free_obj_all(cn, item_set); } void TaskRobLoad::UnloadCharaObjSetMotionSet(CHARA_NUM cn) { const RobData* rob_data = get_rob_data(cn); - objset_info_storage_unload_set(rob_data->objset); + free_objset(rob_data->objset); motion_set_unload_motion(cmn_set_id); motion_set_unload_mothead(cmn_set_id); motion_set_unload_motion(rob_data->motfile); diff --git a/src/CRE/rob/rob.hpp b/src/CRE/rob/rob.hpp index 6ca72058..cb38e58d 100644 --- a/src/CRE/rob/rob.hpp +++ b/src/CRE/rob/rob.hpp @@ -19,6 +19,7 @@ #include "../item_table.hpp" #include "../render_context.hpp" #include "../object.hpp" +#include "../ogl_buffer_object.hpp" #include "../static_var.hpp" #include "rob_item.hpp" @@ -3245,8 +3246,8 @@ struct RobCloth : public CLOTH { bool osage_reset; obj_mesh mesh[2]; obj_sub_mesh submesh[2][4]; - obj_mesh_vertex_buffer vb[2]; - obj_mesh_index_buffer ib[2]; + VertexBuffer vb[2]; + IndexBuffer ib[2]; std::map, std::list> motion_reset_data; std::list* reset_data_list; diff --git a/src/CRE/rob/rob_item.cpp b/src/CRE/rob/rob_item.cpp index 30ff1972..694996be 100644 --- a/src/CRE/rob/rob_item.cpp +++ b/src/CRE/rob/rob_item.cpp @@ -545,7 +545,7 @@ void RobItem::disp_obj_internal(object_info obj_uid, mat4& mat, uint32_t item_no TexChange* texchg = 0; size_t num_texchg = 0; - obj_skin* skin = objset_info_storage_get_obj_skin(obj_uid); + obj_skin* skin = get_object_skin(obj_uid); auto elem = m_txhd_map.find(item_no); if (elem != m_txhd_map.end()) { @@ -723,7 +723,7 @@ void RobItem::req_obj(uint32_t item_no, void* data, const object_database* obj_d return; for (uint32_t i : *item_objset) - objset_info_storage_load_set(data, obj_db, i); + request_objset(data, obj_db, i); } // 0x14052D3D0 @@ -736,7 +736,7 @@ bool RobItem::wait_obj(uint32_t item_no) { return false; for (uint32_t i : *item_objset) - if (i != (uint32_t)-1 && objset_info_storage_load_obj_set_check_not_read(i)) + if (i != (uint32_t)-1 && wait_objset(i)) return true; return false; } @@ -751,7 +751,7 @@ void RobItem::free_obj(uint32_t item_no) { return; for (uint32_t i : *item_objset) - objset_info_storage_unload_set(i); + free_objset(i); free_copy_texture(item_no); } @@ -1259,7 +1259,7 @@ void RobItem::s_req_obj(CHARA_NUM cn, uint32_t item_no, void* data, const object for (uint32_t i : *item_objset) if (i != (uint32_t)-1) - objset_info_storage_load_set(data, obj_db, i); + request_objset(data, obj_db, i); } // 0x14052D4C0 @@ -1272,7 +1272,7 @@ bool RobItem::s_wait_obj(CHARA_NUM cn, uint32_t item_no) { return true; for (uint32_t i : *item_objset) - if (i != (uint32_t)-1 && objset_info_storage_load_obj_set_check_not_read(i)) + if (i != (uint32_t)-1 && wait_objset(i)) return true; return false; } @@ -1288,7 +1288,7 @@ void RobItem::s_free_obj(CHARA_NUM cn, uint32_t item_no) { for (uint32_t i : *item_objset) if (i != (uint32_t)-1) - objset_info_storage_unload_set(i); + free_objset(i); } // 0x14052B160 diff --git a/src/CRE/rob/skin_param.cpp b/src/CRE/rob/skin_param.cpp index 7bb0181f..9f0a6361 100644 --- a/src/CRE/rob/skin_param.cpp +++ b/src/CRE/rob/skin_param.cpp @@ -787,11 +787,11 @@ void SkinParamManager::AddFiles() { if (obj_uid.is_null()) continue; - const char* obj_name = objset_info_storage_get_obj_name(obj_uid); + const char* obj_name = get_object_name(obj_uid); if (!obj_name) continue; - obj_skin_ex_data* ex_data = objset_info_storage_get_obj_skin_ex_data(obj_uid); + obj_skin_ex_data* ex_data = get_object_skin_osage_header(obj_uid); if (!ex_data) continue; @@ -1235,7 +1235,7 @@ int32_t sp_skp_db::get_ext_skp_file(const osage_init_data& osage_init, } } - const char* obj_name = objset_info_storage_get_obj_name(obj_uid); + const char* obj_name = get_object_name(obj_uid); std::string skp_file = sprintf_s_string("ext_skp_%s.txt", obj_name); switch (type) { diff --git a/src/CRE/stage.cpp b/src/CRE/stage.cpp index 293b3e36..a75e41ca 100644 --- a/src/CRE/stage.cpp +++ b/src/CRE/stage.cpp @@ -594,12 +594,12 @@ static void stage_disp(stage* s) { if (s->stage_data->lens_flare_texture != -1 && s->lens_flare) { int32_t object_set_id = s->stage_data->object_set_id; rndr::Render* rend = &rctx_ptr->render; - rend->lens_flare_texture = objset_info_storage_get_obj_set_texture( + rend->lens_flare_texture = get_objset_gen_textures_id( object_set_id, s->stage_data->lens_flare_texture); if (rend->lens_flare_texture) { - rend->lens_shaft_texture = objset_info_storage_get_obj_set_texture( + rend->lens_shaft_texture = get_objset_gen_textures_id( object_set_id, s->stage_data->lens_shaft_texture); - rend->lens_ghost_texture = objset_info_storage_get_obj_set_texture( + rend->lens_ghost_texture = get_objset_gen_textures_id( object_set_id, s->stage_data->lens_ghost_texture); rend->lens_ghost_count = 16; rend->lens_shaft_inv_scale = s->stage_data->lens_shaft_inv_scale; @@ -668,9 +668,9 @@ static void stage_free(stage* s) { s->auth_3d_loaded = false; } - objset_info_storage_unload_set(s->stage_data->object_set_id); + free_objset(s->stage_data->object_set_id); if (s->obj_set != -1) - objset_info_storage_unload_set(s->obj_set); + free_objset(s->obj_set); s->obj_set = -1; s->index = -1; @@ -682,17 +682,17 @@ static void stage_load(stage* s) { if (s->state == 1) { data_struct* aft_data = &data_list[DATA_AFT]; object_database* aft_obj_db = &aft_data->data_ft.obj_db; - objset_info_storage_load_set(aft_data, aft_obj_db, s->obj_set); + request_objset(aft_data, aft_obj_db, s->obj_set); s->state = 2; } else if (s->state == 2) { - if (s->obj_set == -1 || !objset_info_storage_load_obj_set_check_not_read(s->obj_set)) + if (s->obj_set == -1 || !wait_objset(s->obj_set)) s->state = 3; } else if (s->state == 3) { data_struct* aft_data = &data_list[DATA_AFT]; object_database* aft_obj_db = &aft_data->data_ft.obj_db; - objset_info_storage_load_set(aft_data, aft_obj_db, s->stage_data->object_set_id); + request_objset(aft_data, aft_obj_db, s->stage_data->object_set_id); auth_3d_detail::category_load_req(s->stage_data->name.c_str()); auth_3d_detail::category_load_req(s->stage_data->auth_3d_name.c_str()); @@ -700,7 +700,7 @@ static void stage_load(stage* s) { s->state = 4; } else if (s->state == 4) { - if (objset_info_storage_load_obj_set_check_not_read(s->stage_data->object_set_id) + if (wait_objset(s->stage_data->object_set_id) || !auth_3d_detail::category_load_is_done(s->stage_data->name.c_str()) || !auth_3d_detail::category_load_is_done(s->stage_data->auth_3d_name.c_str())) return; diff --git a/src/CRE/stage_modern.cpp b/src/CRE/stage_modern.cpp index 80f16e8f..66ce103f 100644 --- a/src/CRE/stage_modern.cpp +++ b/src/CRE/stage_modern.cpp @@ -585,9 +585,9 @@ static void stage_modern_free(stage_modern* s) { s->auth_3d_loaded = false; } - objset_info_storage_unload_set(s->stage_data->hash); + free_objset(s->stage_data->hash); if (s->obj_set_hash != -1 && s->obj_set_hash != hash_murmurhash_empty) - objset_info_storage_unload_set(s->obj_set_hash); + free_objset(s->obj_set_hash); s->obj_set_hash = -1; s->hash = hash_murmurhash_empty; @@ -597,16 +597,16 @@ static void stage_modern_free(stage_modern* s) { static void stage_modern_load(stage_modern* s, void* data, object_database* obj_db, texture_database* tex_db) { if (s->state == 1) { - objset_info_storage_load_set_hash(data, s->obj_set_hash); + request_objset_modern(data, s->obj_set_hash); s->state = 2; } else if (s->state == 2) { if (s->obj_set_hash == -1 || s->obj_set_hash == hash_murmurhash_empty - || !objset_info_storage_load_obj_set_check_not_read(s->obj_set_hash, obj_db, tex_db)) + || !wait_objset(s->obj_set_hash, obj_db, tex_db)) s->state = 3; } else if (s->state == 3) { - objset_info_storage_load_set_hash(data, s->stage_data->hash); + request_objset_modern(data, s->stage_data->hash); auth_3d_detail::category_load_req(data, s->stage_data->auth_3d_name.c_str(), s->stage_data->auth_3d_name_hash); @@ -614,7 +614,7 @@ static void stage_modern_load(stage_modern* s, void* data, object_database* obj_ s->state = 4; } else if (s->state == 4) { - if (objset_info_storage_load_obj_set_check_not_read(s->stage_data->hash, obj_db, tex_db) + if (wait_objset(s->stage_data->hash, obj_db, tex_db) || !auth_3d_detail::category_load_is_done(s->stage_data->auth_3d_name_hash)) return; diff --git a/src/KKdLib/database/object.cpp b/src/KKdLib/database/object.cpp index 3df577a1..7a857e10 100644 --- a/src/KKdLib/database/object.cpp +++ b/src/KKdLib/database/object.cpp @@ -523,6 +523,16 @@ uint32_t object_database::get_object_set_id(uint32_t set_index) const { return set_index < obj_set_names.size() ? (uint32_t)obj_set_names.data()[set_index].second->id : -1; } +uint32_t object_database::get_object_set_index(uint32_t set_id) const { + uint32_t index = 0; + for (auto& i : obj_set_names) + if (i.second->id == set_id) + return index; + else + index++; + return -1; +} + static void object_database_file_classic_read_inner(object_database_file* obj_db, stream& s) { uint32_t object_set_count = s.read_uint32_t(); uint32_t max_object_set_id = s.read_uint32_t(); diff --git a/src/KKdLib/database/object.hpp b/src/KKdLib/database/object.hpp index 02ec95aa..15b0726c 100644 --- a/src/KKdLib/database/object.hpp +++ b/src/KKdLib/database/object.hpp @@ -170,4 +170,5 @@ struct object_database { const char* get_object_name(object_info obj_info) const; uint32_t get_object_set_count() const; uint32_t get_object_set_id(uint32_t set_index) const; + uint32_t get_object_set_index(uint32_t set_id) const; }; diff --git a/src/KKdLib/msgpack.cpp b/src/KKdLib/msgpack.cpp index fea01d68..b1529e56 100644 --- a/src/KKdLib/msgpack.cpp +++ b/src/KKdLib/msgpack.cpp @@ -111,6 +111,19 @@ _Ret_maybenull_ msgpack* msgpack::read(_In_opt_z_ const char* name) { return name ? get_by_name(name) : this; } +_Ret_maybenull_ msgpack* msgpack::read(const std::initializer_list& name) { + if (!this) + return 0; + + for (const char* i : name) + if (i) { + msgpack* m = get_by_name(i); + if (m) + return m; + } + return 0; +} + _Ret_maybenull_ msgpack* msgpack::read(_In_opt_z_ const char* name, _In_ msgpack_type type) { if (!this) return 0; diff --git a/src/KKdLib/msgpack.hpp b/src/KKdLib/msgpack.hpp index 092838d0..5b7a83ff 100644 --- a/src/KKdLib/msgpack.hpp +++ b/src/KKdLib/msgpack.hpp @@ -5,6 +5,7 @@ #pragma once +#include #include #include #include "default.hpp" @@ -63,6 +64,7 @@ struct msgpack { _Ret_maybenull_ msgpack* append(_In_z_ const char* name, _Inout_ msgpack& m); _Ret_maybenull_ msgpack* append(_In_z_ const char* name, _Inout_ msgpack&& m); _Ret_maybenull_ msgpack* read(_In_opt_z_ const char* name); + _Ret_maybenull_ msgpack* read(const std::initializer_list& name); _Ret_maybenull_ msgpack* read(_In_opt_z_ const char* name, _In_ msgpack_type type); _Ret_maybenull_ msgpack* read_array(_In_opt_z_ const char* name = 0); _Ret_maybenull_ msgpack* read_map(_In_opt_z_ const char* name = 0); diff --git a/src/KKdLib/obj.cpp b/src/KKdLib/obj.cpp index 5ef6c249..f6cffa10 100644 --- a/src/KKdLib/obj.cpp +++ b/src/KKdLib/obj.cpp @@ -371,7 +371,7 @@ obj_material_data::obj_material_data() : num_of_textures() { obj_sub_mesh::obj_sub_mesh() : flags(), bounding_sphere(), material_index(), uv_index(), num_bone_index(), bone_index_array(), bones_per_vertex(), primitive_type(), index_format(), num_index(), index_array(), -attrib(), axis_aligned_bounding_box(), first_index(), last_index(), index_offset() { +attrib(), axis_aligned_bounding_box(), min_index(), max_index(), index_offset() { } @@ -875,8 +875,8 @@ static void obj_move_data_sub_mesh(obj_sub_mesh* sub_mesh_dst, const obj_sub_mes sub_mesh_dst->attrib = sub_mesh_src->attrib; sub_mesh_dst->bounding_box = sub_mesh_src->bounding_box; - sub_mesh_dst->first_index = sub_mesh_src->first_index; - sub_mesh_dst->last_index = sub_mesh_src->last_index; + sub_mesh_dst->min_index = sub_mesh_src->min_index; + sub_mesh_dst->max_index = sub_mesh_src->max_index; sub_mesh_dst->index_offset = sub_mesh_src->index_offset; } @@ -1738,7 +1738,7 @@ static void obj_classic_read_model_mesh(obj_mesh* mesh, obj_classic_read_vertex(mesh, alloc, s, mh.vertex, base_offset, mh.num_vertex, mh.format); - obj_vertex_generate_tangents(mesh); + //obj_vertex_generate_tangents(mesh); } static void obj_classic_read_model_sub_mesh(obj_sub_mesh* sub_mesh, @@ -4997,7 +4997,7 @@ static void obj_modern_read_model_mesh(obj_mesh* mesh, obj_modern_read_vertex(mesh, alloc, *s_ovtx, mh.vertex, mh.vertex_format_index, mh.num_vertex, mh.size_vertex); - obj_vertex_generate_tangents(mesh); + //obj_vertex_generate_tangents(mesh); } static void obj_modern_read_model_sub_mesh(obj_sub_mesh* sub_mesh, diff --git a/src/KKdLib/obj.hpp b/src/KKdLib/obj.hpp index 5b74e34e..0ac99d90 100644 --- a/src/KKdLib/obj.hpp +++ b/src/KKdLib/obj.hpp @@ -183,8 +183,8 @@ struct obj_shader_compo_member { uint32_t color_l3 : 1; uint32_t color_l3_a : 1; uint32_t translucency : 1; - uint32_t flag_14 : 1; - uint32_t override_ibl : 1; + uint32_t env_sphere : 1; + uint32_t env_cube : 1; uint32_t dummy : 16; }; @@ -203,7 +203,7 @@ struct obj_material_shader_attrib_member { obj_material_bump_map_type bump_map_type : 2; uint32_t fresnel_type : 4; uint32_t line_light : 4; - uint32_t recieve_shadow : 1; + uint32_t receive_shadow : 1; uint32_t cast_shadow : 1; obj_material_specular_quality specular_quality : 1; obj_material_aniso_direction aniso_direction : 2; @@ -230,8 +230,8 @@ struct obj_texture_attrib_member { uint32_t filter : 3; uint32_t mipmap : 2; uint32_t mipmap_bias : 7; - uint32_t flag_29 : 1; - uint32_t anisotropic_filter : 2; + uint32_t ignore : 1; + uint32_t aniso : 2; }; union obj_texture_attrib { @@ -269,8 +269,8 @@ struct obj_material_texture_data { }; struct obj_material_attrib_member { - uint32_t alpha_texture : 1; - uint32_t alpha_material : 1; + uint32_t alpha_tex : 1; + uint32_t alpha_mat : 1; uint32_t punch_through : 1; uint32_t double_sided : 1; uint32_t normal_dir_light : 1; @@ -278,13 +278,13 @@ struct obj_material_attrib_member { obj_material_blend_factor dst_blend_factor : 4; uint32_t blend_operation : 3; uint32_t zbias : 4; - uint32_t no_fog : 1; - uint32_t translucent_priority : 6; - uint32_t has_fog_height : 1; - uint32_t flag_28 : 1; - uint32_t fog_height : 1; - uint32_t flag_30 : 1; - uint32_t flag_31 : 1; + uint32_t no_z_fog : 1; + uint32_t alpha_prio : 6; + uint32_t y_fog : 1; + uint32_t ignore_alpha : 1; + uint32_t y_fogmap : 1; + uint32_t use_mat_center : 1; + uint32_t dummy : 1; }; union obj_material_attrib { @@ -330,11 +330,13 @@ struct obj_material_data { }; struct obj_sub_mesh_attrib_member { - uint32_t recieve_shadow : 1; + uint32_t receive_shadow : 1; uint32_t cast_shadow : 1; - uint32_t translucent : 1; - uint32_t cloth : 1; - uint32_t dummy : 28; + uint32_t vertex_alpha : 1; + uint32_t hide : 1; + uint32_t poly_offset : 3; + uint32_t use_restart_index : 1; + uint32_t dummy : 24; }; union obj_sub_mesh_attrib { @@ -359,8 +361,8 @@ struct obj_sub_mesh { obj_axis_aligned_bounding_box axis_aligned_bounding_box; obj_bounding_box bounding_box; }; - uint16_t first_index; - uint16_t last_index; + uint16_t min_index; + uint16_t max_index; uint32_t index_offset; obj_sub_mesh(); @@ -385,10 +387,10 @@ struct obj_vertex_data { }; struct obj_mesh_attrib_member { - uint32_t double_buffer : 1; - uint32_t billboard_y_axis : 1; - uint32_t translucent_sort_by_radius : 1; + uint32_t soft_body : 1; uint32_t billboard : 1; + uint32_t around_obj : 1; + uint32_t billboard_view : 1; uint32_t dummy : 26; // 28 uint32_t compression : 2; // Own stuff }; diff --git a/src/ReDIVA/app.cpp b/src/ReDIVA/app.cpp index f70549c1..4a1dc2d2 100644 --- a/src/ReDIVA/app.cpp +++ b/src/ReDIVA/app.cpp @@ -1351,7 +1351,7 @@ static void render_context_dispose(render_context* rctx) { aet_database* aft_aet_db = &aft_data->data_ft.aet_db; SprDb* aft_spr_db = &aft_data->data_ft.spr_db; - objset_info_storage_unload_set(dbg_set_id); + free_objset(dbg_set_id); fontmap_data_unload(); aet_manager_unload_set(aet_gam_loadsc_set_id, aft_aet_db); spr::free(spr_gam_loadsc_set_id, aft_spr_db); diff --git a/src/ReDIVA/data_edit/face_anim.cpp b/src/ReDIVA/data_edit/face_anim.cpp index 192f7353..b128385f 100644 --- a/src/ReDIVA/data_edit/face_anim.cpp +++ b/src/ReDIVA/data_edit/face_anim.cpp @@ -265,7 +265,7 @@ void FaceAnim::Auth3D::patch() { void FaceAnim::Auth3D::reset() { auth_3d_detail::category_free(category.hash_murmurhash); id.destroy(rctx_ptr); - objset_info_storage_unload_set(object_set.hash_murmurhash); + free_objset(object_set.hash_murmurhash); category.clear(); file.clear(); @@ -310,14 +310,14 @@ bool FaceAnim::ctrl() { auth_3d.object_set.assign("EFFCHRPV826MIK001"); auth_3d_detail::category_load_req(x_data, auth_3d.category.c_str(), auth_3d.category.hash_murmurhash); - objset_info_storage_load_set_hash(x_data, auth_3d.object_set.hash_murmurhash); + request_objset_modern(x_data, auth_3d.object_set.hash_murmurhash); state = 2; } break; case 2: { if (!auth_3d_detail::category_load_is_done(auth_3d.category.hash_murmurhash) - || (objset_info_storage_get_objset_info(auth_3d.object_set.hash_murmurhash) - && objset_info_storage_load_obj_set_check_not_read( + || (get_objset_info(auth_3d.object_set.hash_murmurhash) + && wait_objset( auth_3d.object_set.hash_murmurhash, &auth_3d.obj_db, &auth_3d.tex_db))) break; diff --git a/src/ReDIVA/data_edit/glitter_editor.cpp b/src/ReDIVA/data_edit/glitter_editor.cpp index ac9ecbb4..10b3a289 100644 --- a/src/ReDIVA/data_edit/glitter_editor.cpp +++ b/src/ReDIVA/data_edit/glitter_editor.cpp @@ -4183,8 +4183,8 @@ static void glitter_editor_property_particle(GlitterEditor* glt_edt) { uint32_t set_id = (uint32_t)mesh->object_set_name_hash; uint32_t obj_id = (uint32_t)mesh->object_name_hash; - ObjsetInfo* set_info = objset_info_storage_get_objset_info(set_id); - ssize_t object_set_count = objset_info_storage_get_obj_set_count(); + ObjsetInfo* set_info = get_objset_info(set_id); + ssize_t objset_num = get_objset_num(); extern std::map objset_info_storage_data_modern; ImGui::StartPropertyColumn("Object Set"); @@ -4201,9 +4201,9 @@ static void glitter_editor_property_particle(GlitterEditor* glt_edt) { continue; ImGui::PushID(&i); - if (ImGui::Selectable(info->name.c_str(), info->set_id == set_id) + if (ImGui::Selectable(info->name.c_str(), info->id == set_id) || ImGui::ItemKeyPressed(ImGuiKey_Enter) - || (ImGui::IsItemFocused() && info->set_id != set_id)) + || (ImGui::IsItemFocused() && info->id != set_id)) set_info = info; ImGui::PopID(); } @@ -4211,7 +4211,7 @@ static void glitter_editor_property_particle(GlitterEditor* glt_edt) { if (!set_info) set_id = -1; else - set_id = set_info->set_id; + set_id = set_info->id; if (mesh->object_set_name_hash != set_id) { mesh->object_set_name_hash = set_id; @@ -4237,7 +4237,7 @@ static void glitter_editor_property_particle(GlitterEditor* glt_edt) { ImGui::StartPropertyColumn("Object"); if (ImGui::BeginCombo("##Object", obj ? obj->name : "None", 0)) { - if (set_id != -1 && set_info && set_info->set_id == set_id && set_info->obj_set) { + if (set_id != -1 && set_info && set_info->id == set_id && set_info->obj_set) { obj_set* set = set_info->obj_set; ::obj** obj_data = set->obj_data; ssize_t obj_index = -1; diff --git a/src/ReDIVA/data_initialize.cpp b/src/ReDIVA/data_initialize.cpp index 1f6f742e..a56018bd 100644 --- a/src/ReDIVA/data_initialize.cpp +++ b/src/ReDIVA/data_initialize.cpp @@ -102,7 +102,7 @@ bool TaskDataInit::ctrl() { // break; state = 8; case 8: - objset_info_storage_load_set(aft_data, aft_obj_db, dbg_set_id); + request_objset(aft_data, aft_obj_db, dbg_set_id); //bone_database_read(); item_table_handler_array_read(); sound_work_read_farc("rom/sound/se.farc"); @@ -136,7 +136,7 @@ bool TaskDataInit::ctrl() { state = 9; break; case 9: - if (!objset_info_storage_load_obj_set_check_not_read(dbg_set_id) + if (!wait_objset(dbg_set_id) //&& !bone_database_load() && !item_table_handler_array_load() && !sound_work_load_farc("rom/sound/se.farc") diff --git a/src/ReDIVA/data_test/auth_3d_test.cpp b/src/ReDIVA/data_test/auth_3d_test.cpp index 39fc8a26..849a9991 100644 --- a/src/ReDIVA/data_test/auth_3d_test.cpp +++ b/src/ReDIVA/data_test/auth_3d_test.cpp @@ -628,7 +628,7 @@ bool Auth3dTestTask::init() { data_event_listener.data.init(); task_stage_open("A3D_STAGE"); - objset_info_storage_load_set(aft_data, aft_obj_db, effcmn_obj_set); + request_objset(aft_data, aft_obj_db, effcmn_obj_set); return true; } @@ -642,7 +642,7 @@ bool Auth3dTestTask::ctrl() { data_event_listener.data.ctrl(); - if (effcmn_obj_set_state == 1 && !objset_info_storage_load_obj_set_check_not_read(effcmn_obj_set)) + if (effcmn_obj_set_state == 1 && !wait_objset(effcmn_obj_set)) effcmn_obj_set_state = 4; if (state == 1 && auth_3d_id.load_is_done()) @@ -706,7 +706,7 @@ bool Auth3dTestTask::ctrl() { bool Auth3dTestTask::dest() { aet_id_handle.destroy(); auth_3d_id.destroy(rctx_ptr); - objset_info_storage_unload_set(effcmn_obj_set); + free_objset(effcmn_obj_set); task_stage_close(); data_event_listener.data.dest(); auth_3d_test_window->Hide(); @@ -719,7 +719,7 @@ bool Auth3dTestTask::dest() { load_category.clear(); load_category.shrink_to_fit(); for (uint32_t& i : obj_sets) - objset_info_storage_unload_set(i); + free_objset(i); obj_sets.clear(); obj_sets.shrink_to_fit(); return true; @@ -755,7 +755,7 @@ void Auth3dTestTask::SetAuth3dId() { if (category.size()) { auth_3d_detail::category_free(category.c_str()); for (uint32_t& i : obj_sets) - objset_info_storage_unload_set(i); + free_objset(i); obj_sets.clear(); } auth_3d_detail::category_load_req(load_category.c_str()); @@ -775,13 +775,13 @@ void Auth3dTestTask::SetAuth3dId() { auth_3d_data_get_obj_sets_from_category(category, obj_sets, aft_auth_3d_db, aft_obj_db); for (uint32_t& i : obj_sets) - objset_info_storage_load_set(aft_data, aft_obj_db, i); + request_objset(aft_data, aft_obj_db, i); load_state = 2; } else if (load_state == 2) { bool wait_load = false; for (uint32_t& i : obj_sets) - if (objset_info_storage_load_obj_set_check_not_read(i)) + if (wait_objset(i)) wait_load = true; if (!wait_load) diff --git a/src/ReDIVA/data_test/motion_test.cpp b/src/ReDIVA/data_test/motion_test.cpp index 2689bfb5..cca0c559 100644 --- a/src/ReDIVA/data_test/motion_test.cpp +++ b/src/ReDIVA/data_test/motion_test.cpp @@ -715,7 +715,7 @@ bool DataTestMotA3d::ctrl() { object_database* aft_obj_db = &aft_data->data_ft.obj_db; for (uint32_t& i : obj_sets) - objset_info_storage_load_set(aft_data, aft_obj_db, i); + request_objset(aft_data, aft_obj_db, i); state = 3; } break; @@ -723,7 +723,7 @@ bool DataTestMotA3d::ctrl() { bool wait_load = false; for (uint32_t& i : obj_sets) - if (objset_info_storage_load_obj_set_check_not_read(i)) + if (wait_objset(i)) return false; if (wait_load) @@ -868,7 +868,7 @@ void DataTestMotA3d::Reset() { auth_3d_ids.clear(); for (uint32_t& i : obj_sets) - objset_info_storage_unload_set(i); + free_objset(i); obj_sets.clear(); } @@ -3033,7 +3033,7 @@ static void data_test_face_mot_dw_array_unload() { static bool motion_test_objset_check_not_read() { for (uint32_t i : motion_test_objset) - if (objset_info_storage_load_obj_set_check_not_read(i)) + if (wait_objset(i)) return true; return false; } @@ -3056,11 +3056,11 @@ static void motion_test_objset_load() { object_database* aft_obj_db = &aft_data->data_ft.obj_db; for (uint32_t i : motion_test_objset) - objset_info_storage_load_set(aft_data, aft_obj_db, i); + request_objset(aft_data, aft_obj_db, i); } static void motion_test_objset_unload() { for (uint32_t i : motion_test_objset) - objset_info_storage_unload_set(i); + free_objset(i); motion_test_objset.clear(); } diff --git a/src/ReDIVA/data_test/object_test.cpp b/src/ReDIVA/data_test/object_test.cpp index fc57d5c0..97e3e057 100644 --- a/src/ReDIVA/data_test/object_test.cpp +++ b/src/ReDIVA/data_test/object_test.cpp @@ -13,7 +13,7 @@ class DataTestObjectManager : public app::Task { public: - int32_t object_set_index; + int32_t objset_index; uint32_t object_set_id; int32_t obj_num; int32_t obj_index; @@ -34,8 +34,8 @@ public: int32_t get_obj_num(); const obj_bounding_sphere* get_object_bounding_sphere(int32_t obj_index); const char* get_object_name(int32_t obj_index); - void set_object_index(int32_t value); - void set_object_set_index(int32_t object_set_index); + void set_obj_index(int32_t value); + void set_objset_index(int32_t objset_index); void set_rotation(const vec3& value); void set_shadow(bool value); }; @@ -68,10 +68,10 @@ TaskDataTestObj* task_data_test_obj; static void data_test_obj_dw_init(); -TaskDataTestObj::Data::Data() : object_set_index(), curr_object_set_index(), obj_num(), +TaskDataTestObj::Data::Data() : objset_index(), curr_objset_index(), obj_num(), curr_obj_num(), cull_camera(), curr_cull_camera(), stage_index(), curr_stage_index(), stage_display() { - object_index = -1; - curr_object_index = -1; + obj_index = -1; + curr_obj_index = -1; shadow = 1; } @@ -97,11 +97,11 @@ bool TaskDataTestObj::init() { } bool TaskDataTestObj::ctrl() { - data_test_object_manager->set_object_set_index(data.object_set_index); + data_test_object_manager->set_objset_index(data.objset_index); - if (data.object_set_index != data.curr_object_set_index) { - data.curr_object_set_index = data.object_set_index; - data.object_index = -1; + if (data.objset_index != data.curr_objset_index) { + data.curr_objset_index = data.objset_index; + data.obj_index = -1; data_test_object_manager->close(); } @@ -115,16 +115,16 @@ bool TaskDataTestObj::ctrl() { data_test_obj_dw->AddID(data_test_object_manager->get_object_name(i)); } - if (data.object_index != data.curr_object_index) { - data.curr_object_index = data.object_index; - data_test_object_manager->set_object_index(data.object_index); + if (data.obj_index != data.curr_obj_index) { + data.curr_obj_index = data.obj_index; + data_test_object_manager->set_obj_index(data.obj_index); } if (data.cull_camera != data.curr_cull_camera) { data.curr_cull_camera = data.cull_camera; if (data.cull_camera) { - const obj_bounding_sphere* sphere = data_test_object_manager->get_object_bounding_sphere(data.object_index); + const obj_bounding_sphere* sphere = data_test_object_manager->get_object_bounding_sphere(data.obj_index); if (sphere) { camera* cam = rctx_ptr->camera; @@ -234,7 +234,7 @@ void object_test_free() { } DataTestObjectManager::DataTestObjectManager() : obj_num(), obj_flags(), state() { - object_set_index = -1; + objset_index = -1; object_set_id = -1; obj_index = -1; } @@ -251,17 +251,17 @@ bool DataTestObjectManager::init() { obj_index = -1; state = 2; - if (object_set_index < 0 || (int32_t)aft_obj_db->get_object_set_count() <= object_set_index) { + if (objset_index < 0 || (int32_t)aft_obj_db->get_object_set_count() <= objset_index) { state = 0; return true; } if (object_set_id != -1) { - objset_info_storage_load_set(aft_data, aft_obj_db, object_set_id); + request_objset(aft_data, aft_obj_db, object_set_id); state = 1; } - objset_info_storage_load_set(aft_data, aft_obj_db, aft_obj_db->get_object_set_id(object_set_index)); + request_objset(aft_data, aft_obj_db, aft_obj_db->get_object_set_id(objset_index)); return true; } @@ -271,13 +271,13 @@ bool DataTestObjectManager::ctrl() { switch (state) { case 1: - if (object_set_id == -1 || !objset_info_storage_load_obj_set_check_not_read(object_set_id)) + if (object_set_id == -1 || !wait_objset(object_set_id)) state = 2; break; case 2: { - uint32_t obj_set_id = aft_obj_db->get_object_set_id(object_set_index); - if (!objset_info_storage_load_obj_set_check_not_read(obj_set_id)) { - obj_num = objset_info_storage_get_obj_set(obj_set_id)->obj_num; + uint32_t obj_set_id = aft_obj_db->get_object_set_id(objset_index); + if (!wait_objset(obj_set_id)) { + obj_num = get_obj_data_header(obj_set_id)->obj_num; state = 3; } } break; @@ -289,22 +289,22 @@ bool DataTestObjectManager::dest() { data_struct* aft_data = &data_list[DATA_AFT]; object_database* aft_obj_db = &aft_data->data_ft.obj_db; - objset_info_storage_unload_set(aft_obj_db->get_object_set_id(object_set_index)); + free_objset(aft_obj_db->get_object_set_id(objset_index)); if (object_set_id != -1) - objset_info_storage_unload_set(object_set_id); + free_objset(object_set_id); return true; } void DataTestObjectManager::disp() { - if (state != 3 || obj_index < 0 || obj_index >= this->obj_num) + if (state != 3 || obj_index < 0 || obj_index >= obj_num) return; data_struct* aft_data = &data_list[DATA_AFT]; object_database* aft_obj_db = &aft_data->data_ft.obj_db; - uint32_t obj_set_id = aft_obj_db->get_object_set_id(object_set_index); - uint32_t obj_id = objset_info_storage_get_obj_by_index(obj_set_id, obj_index)->id; + uint32_t obj_set_id = aft_obj_db->get_object_set_id(objset_index); + uint32_t obj_id = get_objnum_idx2uid(objset_index, obj_index, aft_obj_db); rctx_ptr->disp_manager->set_obj_flags( (mdl::ObjFlags)(mdl::OBJ_SILHOUETTE_HIGH | mdl::OBJ_SILHOUETTE | obj_flags)); @@ -339,11 +339,9 @@ const obj_bounding_sphere* DataTestObjectManager::get_object_bounding_sphere(int data_struct* aft_data = &data_list[DATA_AFT]; object_database* aft_obj_db = &aft_data->data_ft.obj_db; - uint32_t obj_set_id = aft_obj_db->get_object_set_id(object_set_index); - const obj* obj = objset_info_storage_get_obj_by_index(obj_set_id, obj_index); - if (obj) - return &obj->bounding_sphere; - return 0; + uint32_t obj_set_id = aft_obj_db->get_object_set_id(objset_index); + uint32_t obj_id = get_objnum_idx2uid(objset_index, obj_index, aft_obj_db); + return get_object_bsphere({ obj_id, obj_set_id }); } const char* DataTestObjectManager::get_object_name(int32_t obj_index) { @@ -353,28 +351,28 @@ const char* DataTestObjectManager::get_object_name(int32_t obj_index) { data_struct* aft_data = &data_list[DATA_AFT]; object_database* aft_obj_db = &aft_data->data_ft.obj_db; - uint32_t obj_set_id = aft_obj_db->get_object_set_id(object_set_index); - const obj* obj = objset_info_storage_get_obj_by_index(obj_set_id, obj_index); - if (obj) - return obj->name; - return"NULL"; + uint32_t obj_set_id = aft_obj_db->get_object_set_id(objset_index); + uint32_t obj_id = get_objnum_idx2uid(objset_index, obj_index, aft_obj_db); + if (obj_index >= 0) + return ::get_object_name({ obj_id, obj_set_id }); + return "NULL"; } -void DataTestObjectManager::set_object_index(int32_t value) { +void DataTestObjectManager::set_obj_index(int32_t value) { obj_index = value; } -void DataTestObjectManager::set_object_set_index(int32_t object_set_index) { +void DataTestObjectManager::set_objset_index(int32_t objset_index) { if (check_alive()) return; data_struct* aft_data = &data_list[DATA_AFT]; object_database* aft_obj_db = &aft_data->data_ft.obj_db; - this->object_set_index = object_set_index; + this->objset_index = objset_index; object_set_id = -1; - uint32_t obj_set_id = aft_obj_db->get_object_set_id(object_set_index); + uint32_t obj_set_id = aft_obj_db->get_object_set_id(objset_index); std::string obj_set_name(aft_obj_db->get_object_set_name(obj_set_id)); if (!obj_set_name.find("STGPV")) obj_set_name.assign(obj_set_name.substr(0, 8)); @@ -410,7 +408,7 @@ DataTestObjDw::DataTestObjDw() { uint32_t obj_set_count = aft_obj_db->get_object_set_count(); for (uint32_t i = obj_set_count, j = 0; i; i--, j++) object_sets->AddItem(aft_obj_db->get_object_set_name(aft_obj_db->get_object_set_id(j))); - object_sets->SetItemIndex((uint32_t)obj_data->object_set_index); + object_sets->SetItemIndex((uint32_t)obj_data->objset_index); object_sets->AddSelectionListener(new dw::SelectionListenerOnHook(DataTestObjDw::ObjectSetCallback)); (new dw::Label(this))->SetText(" OBJECT "); @@ -484,14 +482,14 @@ void DataTestObjDw::ObjectCallback(dw::Widget* data) { TaskDataTestObj::Data* obj_data = task_data_test_obj->get_data(); dw::ListBox* list_box = dynamic_cast(data); if (list_box) - obj_data->object_index = (int32_t)list_box->list->selected_item; + obj_data->obj_index = (int32_t)list_box->list->selected_item; } void DataTestObjDw::ObjectSetCallback(dw::Widget* data) { TaskDataTestObj::Data* obj_data = task_data_test_obj->get_data(); dw::ListBox* list_box = dynamic_cast(data); if (list_box) - obj_data->object_set_index = (int32_t)list_box->list->selected_item; + obj_data->objset_index = (int32_t)list_box->list->selected_item; } void DataTestObjDw::ShadowCallback(dw::Widget* data) { diff --git a/src/ReDIVA/data_test/object_test.hpp b/src/ReDIVA/data_test/object_test.hpp index 6b7f3b8e..991218e5 100644 --- a/src/ReDIVA/data_test/object_test.hpp +++ b/src/ReDIVA/data_test/object_test.hpp @@ -12,12 +12,12 @@ class TaskDataTestObj : public app::Task { public: struct Data { - int32_t object_set_index; - int32_t curr_object_set_index; + int32_t objset_index; + int32_t curr_objset_index; int32_t obj_num; int32_t curr_obj_num; - int32_t object_index; - int32_t curr_object_index; + int32_t obj_index; + int32_t curr_obj_index; bool cull_camera; bool curr_cull_camera; int32_t stage_index; diff --git a/src/ReDIVA/data_test/rob_osage_test.cpp b/src/ReDIVA/data_test/rob_osage_test.cpp index ac01324e..a86bde9b 100644 --- a/src/ReDIVA/data_test/rob_osage_test.cpp +++ b/src/ReDIVA/data_test/rob_osage_test.cpp @@ -490,7 +490,7 @@ bool RobOsageTest::ctrl() { for (int32_t i = 0; i < RPK_MAX; i++) { RobSkinDisp* skin_disp = rob_disp->get_skin_work((ROB_PARTS_KIND)i); - ::obj* obj = objset_info_storage_get_obj(skin_disp->obj_uid); + ::obj* obj = get_object_header(skin_disp->obj_uid); if (!obj || !skin_disp->osage_blk.size() && !skin_disp->cloth.size()) continue; @@ -644,7 +644,7 @@ bool RobOsageTest::ctrl() { for (int32_t i = 0; i < RPK_MAX; i++) { RobSkinDisp* skin_disp = rob_disp->get_skin_work((ROB_PARTS_KIND)i); - ::obj* obj = objset_info_storage_get_obj(skin_disp->obj_uid); + ::obj* obj = get_object_header(skin_disp->obj_uid); if (!obj || !skin_disp->osage_blk.size() && !skin_disp->cloth.size()) continue; diff --git a/src/ReDIVA/data_view/object.cpp b/src/ReDIVA/data_view/object.cpp index 06e87496..5441201d 100644 --- a/src/ReDIVA/data_view/object.cpp +++ b/src/ReDIVA/data_view/object.cpp @@ -82,10 +82,10 @@ void DataViewObject::window() { if (!info->obj_set) continue; - ImGui::PushID(info->set_id); + ImGui::PushID(info->id); char buf[0x1000]; - sprintf_s(buf, sizeof(buf), "ID: 0x%08X; Load Count: %3d; Name: %s", - info->set_id, info->load_count, info->name.c_str()); + sprintf_s(buf, sizeof(buf), "ID: 0x%08X; Request Count: %3d; Name: %s", + info->id, info->req_cnt, info->name.c_str()); ImGui::Selectable(buf); ImGui::PopID(); } @@ -99,10 +99,10 @@ void DataViewObject::window() { if (!info->obj_set) continue; - ImGui::PushID(info->set_id); + ImGui::PushID(info->id); char buf[0x1000]; - sprintf_s(buf, sizeof(buf), "ID: 0x%08X; Load Count: %3d; Name: %s", - info->set_id, info->load_count, info->name.c_str()); + sprintf_s(buf, sizeof(buf), "ID: 0x%08X; Request Count: %3d; Name: %s", + info->id, info->req_cnt, info->name.c_str()); ImGui::Selectable(buf); ImGui::PopID(); } diff --git a/src/ReDIVA/graphics/color_change.cpp b/src/ReDIVA/graphics/color_change.cpp index 653f48e4..bb0a0f66 100644 --- a/src/ReDIVA/graphics/color_change.cpp +++ b/src/ReDIVA/graphics/color_change.cpp @@ -175,7 +175,7 @@ ColorChangeDw::ColorChangeDw() { texture_names = new dw::ListBox(texture_group, (dw::Flags)(dw::FLAG_800 | dw::VERTICAL | dw::MULTISELECT)); texture_names->SetText("listbox1"); - const int32_t tex_num = objset_info_storage_get_obj_set_tex_num(obj_set_id); + const int32_t tex_num = get_objset_num_textures(obj_set_id); for (int32_t i = 0; i < tex_num; i++) texture_names->AddItem(sprintf_s_string("%d", i)); @@ -479,8 +479,8 @@ const char* ColorChangeDw::GetItemTexChangeName() { } texture* ColorChangeDw::GetOrgTex() { - texture** textures = objset_info_storage_get_obj_set_textures(obj_set_id); - if (textures && color_change_index < objset_info_storage_get_obj_set_tex_num(obj_set_id)) + texture** textures = get_objset_textures(obj_set_id); + if (textures && color_change_index < get_objset_num_textures(obj_set_id)) return textures[color_change_index]; return 0; } @@ -511,9 +511,9 @@ void ColorChangeDw::GetTextureNames() { texture_names->ClearItems(); - const int32_t tex_num = objset_info_storage_get_obj_set_tex_num(obj_set_id); + const int32_t tex_num = get_objset_num_textures(obj_set_id); for (int32_t i = 0; i < tex_num; i++) { - uint32_t tex_id = objset_info_storage_get_obj_set_tex_id(obj_set_id, i); + uint32_t tex_id = get_texnum_idx2uid(obj_set_id, i); char buf[64]; sprintf_s(buf, sizeof(buf), "%s", aft_tex_db->get_texture_name(tex_id)); @@ -542,11 +542,11 @@ void ColorChangeDw::LoadItemNames() { bool ColorChangeDw::LoadTexture() { ResetTexture(); - texture** textures = objset_info_storage_get_obj_set_textures(obj_set_id); + texture** textures = get_objset_textures(obj_set_id); if (!textures) return false; - const int32_t tex_num = objset_info_storage_get_obj_set_tex_num(obj_set_id); + const int32_t tex_num = get_objset_num_textures(obj_set_id); for (int32_t i = 0; i < tex_num; i++) { texture* tex = 0; if (textures[i]->target == GL_TEXTURE_2D) { @@ -622,7 +622,7 @@ void ColorChangeDw::SetTextureName(const char* name) { void ColorChangeDw::UpdateData() { if (!set) ReloadData(); - else if (!objset_info_storage_get_obj_set_textures(obj_set_id)) + else if (!get_objset_textures(obj_set_id)) ResetData(); } @@ -859,8 +859,8 @@ void ColorChangeDw::ShowCallback(dw::Button* data) { void ColorChangeDw::TextureCallback(dw::ListBox* data) { int32_t index = (int32_t)data->list->selected_item; ColorChangeDw* color_change_dw = (ColorChangeDw*)data->callback_data.v64; - if (objset_info_storage_get_obj_set_textures(color_change_dw->obj_set_id) - && index < objset_info_storage_get_obj_set_tex_num(color_change_dw->obj_set_id)) + if (get_objset_textures(color_change_dw->obj_set_id) + && index < get_objset_num_textures(color_change_dw->obj_set_id)) color_change_dw->color_change_index = index; } diff --git a/src/ReDIVA/graphics/material.cpp b/src/ReDIVA/graphics/material.cpp index eaa66784..a952ebae 100644 --- a/src/ReDIVA/graphics/material.cpp +++ b/src/ReDIVA/graphics/material.cpp @@ -48,7 +48,7 @@ public: dw::Slider* aniso_filter; dw::Layout* vertical_layout; dw::Layout* horizontal_layout; - uint32_t obj_set_id; + uint32_t objset_index; int32_t obj_index; int32_t material_index; obj_material_data material_array[100]; @@ -118,7 +118,7 @@ MaterialDw::MaterialDw() { data_struct* aft_data = &data_list[DATA_AFT]; object_database* aft_obj_db = &aft_data->data_ft.obj_db; - obj_set_id = -1; + objset_index = -1; obj_index = 0; material_index = 0; @@ -154,7 +154,7 @@ MaterialDw::MaterialDw() { uint32_t obj_set_count = aft_obj_db->get_object_set_count(); for (uint32_t i = obj_set_count, j = 0; i; i--, j++) { uint32_t obj_set_id = aft_obj_db->get_object_set_id(j); - if (objset_info_storage_get_obj_set_loaded(obj_set_id)) + if (check_objset_ready(j)) object_sets->AddItem(aft_obj_db->get_object_set_name(obj_set_id)); } object_sets->AddSelectionListener(new dw::SelectionListenerOnHook( @@ -517,8 +517,9 @@ obj* MaterialDw::GetObj() { data_struct* aft_data = &data_list[DATA_AFT]; object_database* aft_obj_db = &aft_data->data_ft.obj_db; - uint32_t obj_id = objset_info_storage_get_obj_set_obj_id(obj_set_id, obj_index); - return objset_info_storage_get_obj({ obj_id, obj_set_id }); + uint32_t obj_set_id = aft_obj_db->get_object_set_id(objset_index); + uint32_t obj_id = get_objnum_idx2uid(objset_index, obj_index, aft_obj_db); + return get_object_header({ obj_id, obj_set_id }); } void MaterialDw::ResetMaterialArray() { @@ -565,7 +566,7 @@ void MaterialDw::SetValue(bool own) { dst_blend_factor->SetItemIndex(material.attrib.m.dst_blend_factor); zbias->SetValue((float_t)material.attrib.m.zbias); mipmap_bias->SetValue((float_t)material.texdata[0].attrib.m.mipmap_bias); - aniso_filter->SetValue((float_t)material.texdata[0].attrib.m.anisotropic_filter); + aniso_filter->SetValue((float_t)material.texdata[0].attrib.m.aniso); } void MaterialDw::UpdateObjectMeshes() { @@ -595,9 +596,10 @@ void MaterialDw::UpdateObjects() { objects->ClearItems(); - for (int32_t i = 0; i < objset_info_storage_get_obj_set_obj_num(obj_set_id); i++) { - uint32_t obj_id = objset_info_storage_get_obj_set_obj_id(obj_set_id, i); - objects->AddItem(objset_info_storage_get_obj_name({ obj_id, obj_set_id })); + uint32_t obj_set_id = aft_obj_db->get_object_set_id(objset_index); + for (int32_t i = 0; i < get_object_num(objset_index); i++) { + uint32_t obj_id = get_objnum_idx2uid(objset_index, i, aft_obj_db); + objects->AddItem(get_object_name({ obj_id, obj_set_id })); } objects->SetItemIndex(0); @@ -644,14 +646,14 @@ void MaterialDw::AnisoFilterCallback(dw::Slider* data) { MaterialDw* material_dw = (MaterialDw*)data->callback_data.v64; obj_material_data* material_data = material_dw->GetMaterial(); if (material_data) { - material_data->material.texdata[0].attrib.m.anisotropic_filter = (int32_t)data->GetValue(); - material_data->material.texdata[1].attrib.m.anisotropic_filter = (int32_t)data->GetValue(); - material_data->material.texdata[2].attrib.m.anisotropic_filter = (int32_t)data->GetValue(); - material_data->material.texdata[3].attrib.m.anisotropic_filter = (int32_t)data->GetValue(); - material_data->material.texdata[4].attrib.m.anisotropic_filter = (int32_t)data->GetValue(); - material_data->material.texdata[5].attrib.m.anisotropic_filter = (int32_t)data->GetValue(); - material_data->material.texdata[6].attrib.m.anisotropic_filter = (int32_t)data->GetValue(); - material_data->material.texdata[7].attrib.m.anisotropic_filter = (int32_t)data->GetValue(); + material_data->material.texdata[0].attrib.m.aniso = (int32_t)data->GetValue(); + material_data->material.texdata[1].attrib.m.aniso = (int32_t)data->GetValue(); + material_data->material.texdata[2].attrib.m.aniso = (int32_t)data->GetValue(); + material_data->material.texdata[3].attrib.m.aniso = (int32_t)data->GetValue(); + material_data->material.texdata[4].attrib.m.aniso = (int32_t)data->GetValue(); + material_data->material.texdata[5].attrib.m.aniso = (int32_t)data->GetValue(); + material_data->material.texdata[6].attrib.m.aniso = (int32_t)data->GetValue(); + material_data->material.texdata[7].attrib.m.aniso = (int32_t)data->GetValue(); } } @@ -793,7 +795,7 @@ void MaterialDw::ObjectSetCallback(dw::ListBox* data) { MaterialDw* material_dw = (MaterialDw*)data->callback_data.v64; std::string item = data->GetSelectedItemStr(); - material_dw->obj_set_id = aft_obj_db->get_object_set_id(item.c_str()); + material_dw->objset_index = aft_obj_db->get_object_set_id(item.c_str()); material_dw->UpdateObjects(); } @@ -816,7 +818,7 @@ void MaterialDw::RefreshCallback(dw::Widget* data) { uint32_t obj_set_count = aft_obj_db->get_object_set_count(); for (uint32_t i = obj_set_count, j = 0; i; i--, j++) { uint32_t obj_set_id = aft_obj_db->get_object_set_id(j); - if (objset_info_storage_get_obj_set_loaded(obj_set_id)) + if (check_objset_ready(obj_set_id)) object_sets->AddItem(aft_obj_db->get_object_set_name(obj_set_id)); } object_sets->SetItemIndex(0); @@ -871,7 +873,7 @@ void MaterialDw::ResetCallback(dw::Widget* data) { = (obj_material_blend_factor)material_dw->dst_blend_factor->list->selected_item; material.attrib.m.zbias = (int32_t)material_dw->zbias->GetValue(); material.texdata[0].attrib.m.mipmap_bias = (int32_t)material_dw->mipmap_bias->GetValue(); - material.texdata[0].attrib.m.anisotropic_filter = (int32_t)material_dw->aniso_filter->GetValue(); + material.texdata[0].attrib.m.aniso = (int32_t)material_dw->aniso_filter->GetValue(); } void MaterialDw::ShininessCallback(dw::Slider* data) { diff --git a/src/ReDIVA/pv_game/pv_game.cpp b/src/ReDIVA/pv_game/pv_game.cpp index 3ff4eb34..b2ef00ba 100644 --- a/src/ReDIVA/pv_game/pv_game.cpp +++ b/src/ReDIVA/pv_game/pv_game.cpp @@ -3152,7 +3152,7 @@ bool pv_game::load() { prj::sort_and_erase_non_unique(data.chreff_auth_3d_obj_set_ids); for (uint32_t& i : data.chreff_auth_3d_obj_set_ids) - objset_info_storage_load_set(aft_data, aft_obj_db, i); + request_objset(aft_data, aft_obj_db, i); char campv[0x40]; sprintf_s(campv, sizeof(campv), "CAMPV%03d", get_pv_db_pv()->id); @@ -3198,7 +3198,7 @@ bool pv_game::load() { prj::sort_and_erase_non_unique(data.field_2D770); for (uint32_t& i : data.field_2D770) - objset_info_storage_load_set(aft_data, aft_obj_db, i); + request_objset(aft_data, aft_obj_db, i); data.ex_song_ex_auth_obj_set_ids.clear(); for (const pv_db_pv_ex_song& i : get_pv_db_pv()->ex_song.data) @@ -3215,7 +3215,7 @@ bool pv_game::load() { prj::sort_and_erase_non_unique(data.ex_song_ex_auth_obj_set_ids); for (uint32_t& i : data.ex_song_ex_auth_obj_set_ids) - objset_info_storage_load_set(aft_data, aft_obj_db, i); + request_objset(aft_data, aft_obj_db, i); prj::sort_and_erase_non_unique(data.stage_indices); if (!data.stage_indices.size()) @@ -3240,7 +3240,7 @@ bool pv_game::load() { prj::sort_and_erase_non_unique(data.stgpvhrc_obj_set_ids); for (uint32_t& i : data.stgpvhrc_obj_set_ids) - objset_info_storage_load_set(aft_data, aft_obj_db, i); + request_objset(aft_data, aft_obj_db, i); data.has_frame_texture = false; for (const pv_db_pv_frame_texture& i : get_pv_db_pv()->frame_texture) @@ -3257,15 +3257,15 @@ bool pv_game::load() { return false; for (uint32_t& i : data.chreff_auth_3d_obj_set_ids) - if (objset_info_storage_load_obj_set_check_not_read(i)) + if (wait_objset(i)) return false; for (uint32_t& i : data.field_2D770) - if (objset_info_storage_load_obj_set_check_not_read(i)) + if (wait_objset(i)) return false; for (uint32_t& i : data.ex_song_ex_auth_obj_set_ids) - if (objset_info_storage_load_obj_set_check_not_read(i)) + if (wait_objset(i)) return false; state = 2; @@ -3443,7 +3443,7 @@ bool pv_game::load() { prj::sort_and_erase_non_unique(data.obj_set_itmpv); for (uint32_t& i : data.obj_set_itmpv) - objset_info_storage_load_set(aft_data, aft_obj_db, i); + request_objset(aft_data, aft_obj_db, i); data.obj_set_handitem.clear(); if (diff) { @@ -3467,7 +3467,7 @@ bool pv_game::load() { prj::sort_and_erase_non_unique(data.obj_set_handitem); for (uint32_t& i : data.obj_set_handitem) - objset_info_storage_load_set(aft_data, aft_obj_db, i); + request_objset(aft_data, aft_obj_db, i); skin_param_storage_load(hand_obj_infos, aft_data, aft_obj_db); } @@ -3496,19 +3496,19 @@ bool pv_game::load() { wait_load |= true; for (uint32_t& i : data.obj_set_itmpv) - if (objset_info_storage_load_obj_set_check_not_read(i)) { + if (wait_objset(i)) { wait_load |= true; break; } for (uint32_t& i : data.obj_set_handitem) - if (objset_info_storage_load_obj_set_check_not_read(i)) { + if (wait_objset(i)) { wait_load |= true; break; } for (uint32_t& i : data.stgpvhrc_obj_set_ids) - if (objset_info_storage_load_obj_set_check_not_read(i)) { + if (wait_objset(i)) { wait_load |= true; break; } @@ -4812,29 +4812,29 @@ bool pv_game::unload() { pv_param::post_process_data_clear_data(); for (uint32_t& i : data.obj_set_itmpv) - objset_info_storage_unload_set(i); + free_objset(i); data.obj_set_itmpv.clear(); for (uint32_t& i : data.obj_set_handitem) - objset_info_storage_unload_set(i); + free_objset(i); data.obj_set_handitem.clear(); skin_param_storage_reset(); for (uint32_t& i : data.chreff_auth_3d_obj_set_ids) - objset_info_storage_unload_set(i); + free_objset(i); data.chreff_auth_3d_obj_set_ids.clear(); for (uint32_t& i : data.field_2D770) - objset_info_storage_unload_set(i); + free_objset(i); data.field_2D770.clear(); for (uint32_t& i : data.stgpvhrc_obj_set_ids) - objset_info_storage_unload_set(i); + free_objset(i); data.stgpvhrc_obj_set_ids.clear(); for (uint32_t& i : data.ex_song_ex_auth_obj_set_ids) - objset_info_storage_unload_set(i); + free_objset(i); data.ex_song_ex_auth_obj_set_ids.clear(); for (uint64_t& i : data.effect_rs_list_hashes) diff --git a/src/ReDIVA/x_pv_game.cpp b/src/ReDIVA/x_pv_game.cpp index 6683c814..2d2bf471 100644 --- a/src/ReDIVA/x_pv_game.cpp +++ b/src/ReDIVA/x_pv_game.cpp @@ -1057,8 +1057,8 @@ void x_pv_game_effect::ctrl(object_database* obj_db, texture_database* tex_db) { wait_load |= true; for (string_hash& i : pv_obj_set) - if (objset_info_storage_get_objset_info(i.hash_murmurhash) - && objset_info_storage_load_obj_set_check_not_read(i.hash_murmurhash, obj_db, tex_db)) + if (get_objset_info(i.hash_murmurhash) + && wait_objset(i.hash_murmurhash, obj_db, tex_db)) wait_load |= true; if (wait_load) @@ -1186,7 +1186,7 @@ void x_pv_game_effect::load_data(int32_t pv_id, object_database* obj_db, texture data_struct* x_data = &data_list[DATA_X]; for (string_hash& i : pv_obj_set) - objset_info_storage_load_set_hash(x_data, i.hash_murmurhash); + request_objset_modern(x_data, i.hash_murmurhash); for (string_hash& i : pv_auth_3d) auth_3d_detail::category_load_req(x_data, i.c_str(), i.hash_murmurhash); @@ -1386,7 +1386,7 @@ void x_pv_game_effect::unload_data() { auth_3d_detail::category_free(i.hash_murmurhash); for (string_hash& i : pv_obj_set) - objset_info_storage_unload_set(i.hash_murmurhash); + free_objset(i.hash_murmurhash); for (string_hash& i : pv_glitter) Glitter::glt_particle_manager->UnloadEffectGroup(i.hash_murmurhash); @@ -1442,8 +1442,8 @@ void x_pv_game_chara_effect::ctrl(int32_t pv_id, object_database* obj_db, textur if (!auth_3d_detail::category_load_is_done(j.category.hash_murmurhash)) wait_load |= true; - if (objset_info_storage_get_objset_info(j.object_set.hash_murmurhash) - && objset_info_storage_load_obj_set_check_not_read(j.object_set.hash_murmurhash, obj_db, tex_db)) + if (get_objset_info(j.object_set.hash_murmurhash) + && wait_objset(j.object_set.hash_murmurhash, obj_db, tex_db)) wait_load |= true; } @@ -1687,7 +1687,7 @@ void x_pv_game_chara_effect::load_data() { continue; auth_3d_detail::category_load_req(x_data, j.category.c_str(), j.category.hash_murmurhash); - objset_info_storage_load_set_hash(x_data, j.object_set.hash_murmurhash); + request_objset_modern(x_data, j.object_set.hash_murmurhash); } state = 20; @@ -1828,7 +1828,7 @@ void x_pv_game_chara_effect::unload_data() { j.id.destroy(rctx_ptr); auth_3d_detail::category_free(j.category.hash_murmurhash); - objset_info_storage_unload_set(j.object_set.hash_murmurhash); + free_objset(j.object_set.hash_murmurhash); } state = 10; @@ -5146,8 +5146,8 @@ void x_pv_game_stage_data::ctrl(object_database* obj_db, texture_database* tex_d bool wait_load = false; for (uint32_t& i : objhrc_hash) - if (objset_info_storage_get_objset_info(i) - && objset_info_storage_load_obj_set_check_not_read(i, obj_db, tex_db)) + if (get_objset_info(i) + && wait_objset(i, obj_db, tex_db)) wait_load |= true; if (wait_load || task_stage_modern_check_not_loaded()) @@ -5207,7 +5207,7 @@ void x_pv_game_stage_data::load_objects(object_database* obj_db, texture_databas effect_manager_set_data(x_data, obj_db, tex_db, &stg_db); for (uint32_t& i : objhrc_hash) - objset_info_storage_load_set_hash(x_data, i); + request_objset_modern(x_data, i); state = 1; flags |= 0x01; @@ -5265,7 +5265,7 @@ void x_pv_game_stage_data::set_stage(uint32_t hash) { void x_pv_game_stage_data::unload() { for (uint32_t& i : objhrc_hash) - objset_info_storage_unload_set(i); + free_objset(i); task_stage_modern_close(); @@ -7303,7 +7303,7 @@ bool x_pv_game::ctrl() { prj::sort_and_erase_non_unique(object_set_ids); for (const uint32_t& i : object_set_ids) { - ObjsetInfo* info = objset_info_storage_get_objset_info(i); + ObjsetInfo* info = get_objset_info(i); if (!info) continue; @@ -7320,20 +7320,14 @@ bool x_pv_game::ctrl() { prj::shared_ptr& alloc = info->alloc_handler; - int32_t obj_num = set->obj_num; - obj** obj_data = set->obj_data; - - obj_vertex_buffer* objvb = info->objvb; - for (int32_t j = 0; j < obj_num; j++) - objvb[j].unload(); - - obj_index_buffer* objib = info->objib; - for (int32_t j = 0; j < obj_num; j++) - objib[j].unload(); + free_objset_index_buffer(info); + free_objset_vertex_buffer(info); x_pv_game_process_object(set); x_pv_game_process_object_reflect(set, reflect); + int32_t obj_num = set->obj_num; + obj** obj_data = set->obj_data; for (int32_t j = 0; j < obj_num; j++, obj_data++) { obj* obj = *obj_data; @@ -7359,20 +7353,15 @@ bool x_pv_game::ctrl() { submesh->num_index = (int32_t)meshopt_stripify(submesh->index_array, index_array, submesh->num_index, mesh->num_vertex, 0xFFFFFFFF); - submesh->first_index = 0; - submesh->last_index = 0; + submesh->min_index = 0; + submesh->max_index = 0; submesh->index_offset = 0; } } } - obj_data = set->obj_data; - - for (int32_t j = 0; j < obj_num; j++) - objvb[j].load(obj_data[j]); - - for (int32_t j = 0; j < obj_num; j++) - objib[j].load(obj_data[j]); + create_objset_vertex_buffer(info); + create_objset_index_buffer(info); x_pv_game_update_object_set(info); } @@ -7380,7 +7369,7 @@ bool x_pv_game::ctrl() { object_set_ids.clear(); for (uint32_t& i : pv_object_set_ids) { - ObjsetInfo* info = objset_info_storage_get_objset_info(i); + ObjsetInfo* info = get_objset_info(i); if (info) x_pv_game_write_object_set(info->obj_set, info->name, &baker->aft.obj_db, &pv_data.tex_db, &baker->aft.tex_db_base, &baker->aft.tex_db, @@ -7388,7 +7377,7 @@ bool x_pv_game::ctrl() { } for (uint32_t& i : stage_object_set_ids) { - ObjsetInfo* info = objset_info_storage_get_objset_info(i); + ObjsetInfo* info = get_objset_info(i); if (info) x_pv_game_write_object_set(info->obj_set, info->name, &baker->aft.obj_db, &stage_data.tex_db, &baker->aft.tex_db_base, &baker->aft.tex_db, @@ -7396,7 +7385,7 @@ bool x_pv_game::ctrl() { } for (uint32_t& i : pv_object_set_ids) { - ObjsetInfo* info = objset_info_storage_get_objset_info(i); + ObjsetInfo* info = get_objset_info(i); if (info) x_pv_game_write_object_set(info->obj_set, info->name, &baker->mmp.obj_db, &pv_data.tex_db, &baker->mmp.tex_db_base, &baker->mmp.tex_db, @@ -7404,7 +7393,7 @@ bool x_pv_game::ctrl() { } for (uint32_t& i : stage_object_set_ids) { - ObjsetInfo* info = objset_info_storage_get_objset_info(i); + ObjsetInfo* info = get_objset_info(i); if (info) x_pv_game_write_object_set(info->obj_set, info->name, &baker->mmp.obj_db, &stage_data.tex_db, &baker->mmp.tex_db_base, &baker->mmp.tex_db, @@ -10604,13 +10593,13 @@ static void x_pv_game_read_object_reflect(const char* path, const char* set_name if (translucency) mat->shader_compo.m.translucency = translucency->read_bool() ? 1 : 0; - msgpack* flag_14 = shader_compo->read("flag_14"); - if (flag_14) - mat->shader_compo.m.flag_14 = flag_14->read_bool() ? 1 : 0; + msgpack* env_sphere = shader_compo->read({ "env_sphere", "flag_14" }); + if (env_sphere) + mat->shader_compo.m.env_sphere = env_sphere->read_bool() ? 1 : 0; - msgpack* override_ibl = shader_compo->read("override_ibl"); - if (override_ibl) - mat->shader_compo.m.override_ibl = override_ibl->read_bool() ? 1 : 0; + msgpack* env_cube = shader_compo->read({ "env_cube", "override_ibl" }); + if (env_cube) + mat->shader_compo.m.env_cube = env_cube->read_bool() ? 1 : 0; msgpack* dummy = shader_compo->read("dummy"); if (dummy) @@ -10666,9 +10655,9 @@ static void x_pv_game_read_object_reflect(const char* path, const char* set_name if (line_light) mat->shader_info.m.line_light = line_light->read_uint32_t(); - msgpack* recieve_shadow = shader_info->read("recieve_shadow"); - if (recieve_shadow) - mat->shader_info.m.recieve_shadow = recieve_shadow->read_bool() ? 1 : 0; + msgpack* receive_shadow = shader_info->read({ "receive_shadow", "recieve_shadow" }); + if (receive_shadow) + mat->shader_info.m.receive_shadow = receive_shadow->read_bool() ? 1 : 0; msgpack* cast_shadow = shader_info->read("cast_shadow"); if (cast_shadow) @@ -10749,13 +10738,13 @@ static void x_pv_game_read_object_reflect(const char* path, const char* set_name if (mipmap_bias) l.attrib.m.mipmap_bias = mipmap_bias->read_uint32_t(); - msgpack* flag_29 = attrib->read("flag_29"); - if (flag_29) - l.attrib.m.flag_29 = flag_29->read_bool() ? 1 : 0; + msgpack* ignore = attrib->read({ "ignore", "flag_29" }); + if (ignore) + l.attrib.m.ignore = ignore->read_bool() ? 1 : 0; - msgpack* anisotropic_filter = attrib->read("anisotropic_filter"); - if (anisotropic_filter) - l.attrib.m.anisotropic_filter = anisotropic_filter->read_uint32_t(); + msgpack* aniso = attrib->read({ "aniso", "anisotropic_filter" }); + if (aniso) + l.attrib.m.aniso = aniso->read_uint32_t(); } msgpack* _tex_name = tex->read("tex_name"); @@ -10852,13 +10841,13 @@ static void x_pv_game_read_object_reflect(const char* path, const char* set_name msgpack* attrib = material.read("attrib"); if (attrib) { - msgpack* alpha_texture = attrib->read("alpha_texture"); - if (alpha_texture) - mat->attrib.m.alpha_texture = alpha_texture->read_bool() ? 1 : 0; + msgpack* alpha_tex = attrib->read({ "alpha_tex", "alpha_texture" }); + if (alpha_tex) + mat->attrib.m.alpha_tex = alpha_tex->read_bool() ? 1 : 0; - msgpack* alpha_material = attrib->read("alpha_material"); - if (alpha_material) - mat->attrib.m.alpha_material = alpha_material->read_bool() ? 1 : 0; + msgpack* alpha_mat = attrib->read({ "alpha_mat", "alpha_material" }); + if (alpha_mat) + mat->attrib.m.alpha_mat = alpha_mat->read_bool() ? 1 : 0; msgpack* punch_through = attrib->read("punch_through"); if (punch_through) @@ -10890,33 +10879,33 @@ static void x_pv_game_read_object_reflect(const char* path, const char* set_name if (zbias) mat->attrib.m.zbias = zbias->read_uint32_t(); - msgpack* no_fog = attrib->read("no_fog"); - if (no_fog) - mat->attrib.m.no_fog = no_fog->read_bool() ? 1 : 0; + msgpack* no_z_fog = attrib->read({ "no_z_fog", "no_fog" }); + if (no_z_fog) + mat->attrib.m.no_z_fog = no_z_fog->read_bool() ? 1 : 0; - msgpack* translucent_priority = attrib->read("translucent_priority"); - if (translucent_priority) - mat->attrib.m.translucent_priority = translucent_priority->read_uint32_t(); + msgpack* alpha_prio = attrib->read({ "alpha_prio", "translucent_priority" }); + if (alpha_prio) + mat->attrib.m.alpha_prio = alpha_prio->read_uint32_t(); - msgpack* has_fog_height = attrib->read("has_fog_height"); - if (has_fog_height) - mat->attrib.m.has_fog_height = has_fog_height->read_bool() ? 1 : 0; + msgpack* y_fog = attrib->read({ "y_fog", "has_fog_height" }); + if (y_fog) + mat->attrib.m.y_fog = y_fog->read_bool() ? 1 : 0; - msgpack* flag_28 = attrib->read("flag_28"); - if (flag_28) - mat->attrib.m.flag_28 = flag_28->read_bool() ? 1 : 0; + msgpack* ignore_alpha = attrib->read({ "ignore_alpha", "flag_28" }); + if (ignore_alpha) + mat->attrib.m.ignore_alpha = ignore_alpha->read_bool() ? 1 : 0; - msgpack* fog_height = attrib->read("fog_height"); - if (fog_height) - mat->attrib.m.fog_height = fog_height->read_bool() ? 1 : 0; + msgpack* y_fogmap = attrib->read({ "y_fogmap", "fog_height" }); + if (y_fogmap) + mat->attrib.m.y_fogmap = y_fogmap->read_bool() ? 1 : 0; - msgpack* flag_30 = attrib->read("flag_30"); - if (flag_30) - mat->attrib.m.flag_30 = flag_30->read_bool() ? 1 : 0; + msgpack* use_mat_center = attrib->read({ "use_mat_center", "flag_30" }); + if (use_mat_center) + mat->attrib.m.use_mat_center = use_mat_center->read_bool() ? 1 : 0; - msgpack* flag_31 = attrib->read("flag_31"); - if (flag_31) - mat->attrib.m.flag_31 = flag_31->read_bool() ? 1 : 0; + msgpack* dummy = attrib->read({ "dummy", "flag_31" }); + if (dummy) + mat->attrib.m.dummy = dummy->read_bool() ? 1 : 0; } msgpack* color = material.read("color"); @@ -11298,17 +11287,29 @@ static void x_pv_game_read_object_reflect(const char* path, const char* set_name msgpack* attrib = _sub_mesh.read("attrib"); if (attrib) { - msgpack* recieve_shadow = attrib->read("recieve_shadow"); - if (recieve_shadow) - sub_mesh_reflect.attrib.m.recieve_shadow = recieve_shadow->read_bool(); + msgpack* receive_shadow = attrib->read({ "receive_shadow", "recieve_shadow" }); + if (receive_shadow) + sub_mesh_reflect.attrib.m.receive_shadow = receive_shadow->read_bool(); msgpack* cast_shadow = attrib->read("cast_shadow"); if (cast_shadow) sub_mesh_reflect.attrib.m.cast_shadow = cast_shadow->read_bool(); - msgpack* translucent = attrib->read("translucent"); - if (translucent) - sub_mesh_reflect.attrib.m.translucent = translucent->read_bool(); + msgpack* vertex_alpha = attrib->read({ "vertex_alpha", "translucent" }); + if (vertex_alpha) + sub_mesh_reflect.attrib.m.vertex_alpha = vertex_alpha->read_bool(); + + msgpack* hide = attrib->read("hide"); + if (hide) + sub_mesh.attrib.m.hide = hide->read_bool(); + + msgpack* poly_offset = attrib->read("poly_offset"); + if (poly_offset) + sub_mesh.attrib.m.poly_offset = poly_offset->read_uint32_t(); + + msgpack* use_restart_index = attrib->read("use_restart_index"); + if (hide) + sub_mesh.attrib.m.use_restart_index = hide->read_bool(); } } }